Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable reception of socket CAN frames #30841

Closed
mejtejt opened this issue Dec 17, 2020 · 4 comments
Closed

How to disable reception of socket CAN frames #30841

mejtejt opened this issue Dec 17, 2020 · 4 comments

Comments

@mejtejt
Copy link

mejtejt commented Dec 17, 2020

Is your feature request related to a problem? Please describe.
I am using setsockopt function to subscribe to the messages I want tor receive on the CAN. The function is as follows:

setsockopt(socket_id, SOL_CAN_RAW, CAN_RAW_FILTER, &filter,
                       sizeof(filter));

And the code runs, I am receiving messages I want. After some time, I want to tell socket CAN "stop receiving those messages". I tried implementing it with the following function:

setsockopt(socket_id, SOL_CAN_RAW, CAN_RAW_FILTER, NULL,0);

But the function call fails, with a reason: Invalid argument. So, my question is: how can I tell socket CAN to stop receiving messages on a socket?

@jukkar
Copy link
Member

jukkar commented Dec 17, 2020

Indeed the code checks that option and size are correct.
See

if (optname == CAN_RAW_FILTER && optlen != sizeof(struct can_filter)) {
and few lines below for details.
If giving NULL option and/or 0 length would mean that the filter needs to be unregistered, then these checks should be changed. Would you be able to send patches for these?

@jukkar
Copy link
Member

jukkar commented Dec 17, 2020

BTW, have you checked how the filter is removed in Linux? We should probably do it similarly in Zephyr.

@mejtejt
Copy link
Author

mejtejt commented Dec 18, 2020

Setting optval to NULL, and optlen to 0 is exactly how I use it on Linux. The following is an excerpt from my Linux code:

image

And it works just like I want it to. This is part of the CAN_Open function, where I want to explicitly set that no messages are to be received before instructed to do so.

@github-actions
Copy link

github-actions bot commented Mar 8, 2021

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants