Skip to content

Conversation

@menschel
Copy link
Contributor

@menschel menschel commented May 16, 2021

This PR adds constants to socket module for IsoTp CAN protocol.

IsoTp CAN protocol is mainline since Kernel v5.10.
The basic socket constant for IsoTp has been available since Python 3.7 (August 2018),
so it could be used for default use-cases without having issues.

However several constants from isotp.h have not found their way into socket module yet.
When using advanced options like padding, this flaw becomes visible.
https://gitlab.com/Menschel/socketcan/-/blob/master/socketcan/socketcan.py#L18

This PR may be related to #23794.

https://bugs.python.org/issue42653

IsoTp CAN protocol is available since
Kernel v5.10 but several constants
from isotp.h have not found their
way into socket module.

This commit adds that header file if
configure finds it.

Signed-off-by: Patrick Menschel <[email protected]>
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

Recognized GitHub username

We couldn't find a bugs.python.org (b.p.o) account corresponding to the following GitHub usernames:

@menschel

This might be simply due to a missing "GitHub Name" entry in one's b.p.o account settings. This is necessary for legal reasons before we can look at this contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Use PyModule_AddIntMacro() to add all
constants from isotp.h .

Signed-off-by: Patrick Menschel <[email protected]>
menschel added 3 commits May 19, 2021 17:47
Signed-off-by: Patrick Menschel <[email protected]>
This one slipped by, sorry.

Signed-off-by: Patrick Menschel <[email protected]>
@menschel menschel changed the title Add constants to socket module for IsoTp CAN protocol bpo-42653: Add constants to socket module for IsoTp CAN protocol May 19, 2021
The issue number was found eventually.
Apparently there already was a PR with this topic.

Signed-off-by: Patrick Menschel <[email protected]>
@menschel
Copy link
Contributor Author

Dear Reviewer,
this PR apparently targets the same topic as #23794
Please advise.

@rumpelsepp
Copy link
Contributor

rumpelsepp commented May 20, 2021

My pullrequest seems to lack these *_DEFAULT_* constants. Are these new to the kernel module?

edit: Ah okay, these are part of the inclusion in the mainline kernel. I missed these.

@menschel
Copy link
Contributor Author

menschel commented May 20, 2021 via email

For unknown reason, HAVE_LINUX_CAN_ISOTP_H was not
set during build. After changing the order of items
in that particular line of configure.ac, it now works
as expected.

Signed-off-by: Patrick Menschel <[email protected]>
@menschel
Copy link
Contributor Author

Dear Reviewer the patch has been verified on a rpi3b.

Please also review my Unittest 1f7c2c5 . It did not fail during make run before 2f19691 .

Thanks.

This may not be necessary but it is clean.
Also normalize the comment line above.

Signed-off-by: Patrick Menschel <[email protected]>
@menschel
Copy link
Contributor Author

The patch also works on Python 3.9.5. This was build on a rpi0w.

$ python -i
Python 3.9.5 (heads/master-dirty:00ae35b, May 22 2021, 21:28:37) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.CAN_ISOTP_OPTS
1
>>> socket.SOL_CAN_ISOTP
106
>>> 

CAN_ISOTP_SF_BROADCAST is new and not always available.
This was the case on a recent RaspberryPi Kernel.
Therefore make it optional and exclude it from test.

Also add condition for testing the constants.

Signed-off-by: Patrick Menschel <[email protected]>
PyModule_AddIntMacro(m, CAN_ISOTP_WAIT_TX_DONE);
#ifdef CAN_ISOTP_SF_BROADCAST
/* This constant is new and not always available */
PyModule_AddIntMacro(m, CAN_ISOTP_SF_BROADCAST);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the version of the kernel could be checked on buildtime, couldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes, but there is no guarantee that this symbol really is there when the kernel version is above a specific version.
If you install the headers yourself with linux-headers-$(uname -r), the assumption works.

But if the installation of headers has been obscured, like with Raspberry Pi 's package raspberrypi-kernel-headers, this assumption no longer works. It just adds another assumption that the packages
raspberrypi-kernel-headers and raspberrypi-kernel are in sync.

Copy link
Contributor

@rumpelsepp rumpelsepp May 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I would argue that the mainline upstream kernel is the source of truth and this must be fixed downstream. No idea how the CPython project deals with these kinds of issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, lets wait for the Reviewer to comment on this. This should theoretically be @tiran.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aye.

@menschel
Copy link
Contributor Author

menschel commented Jun 19, 2021

BUMP.

This PR is stale for about a month now. Is there a way to accelerate this?

@MaxwellDupre
Copy link
Contributor

Need to re-target Doc/whatsnew/3.10.rst to 3.12.

@hartkopp
Copy link

Need to re-target Doc/whatsnew/3.10.rst to 3.12.

While you are at it:

Meanwhile another new constant CAN_ISOTP_CF_BROADCAST will hit the road in Linux 5.19 ...

pylessard/python-can-isotp#67 (comment)

@menschel
Copy link
Contributor Author

menschel commented May 18, 2022 via email

@hartkopp
Copy link

Be aware, these PRs have been stale for over a year. I consider them dead.

Yes but when @MaxwellDupre makes the zombie run again ... ;-)

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants