-
Notifications
You must be signed in to change notification settings - Fork 2k
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
at86rf2xx: fix option setting #5227
Conversation
seems to me like you broke the code: if an option is set successfully, the |
That's the idea, so it jumps into https://github.com/RIOT-OS/RIOT/pull/5227/files#diff-148e890332a08fcca786b1e362e7f970R572. |
Ah wait, for some instances you are right. |
Okay, now I replaced the instances where the values are just invalid for the scope of the device with |
looks better :-) |
7eceddf
to
28ef573
Compare
Rebased to current master. |
@@ -433,7 +433,7 @@ static int _set(netdev2_t *netdev, netopt_t opt, void *val, size_t len) | |||
uint8_t chan = ((uint8_t *)val)[0]; | |||
if (chan < AT86RF2XX_MIN_CHANNEL || | |||
chan > AT86RF2XX_MAX_CHANNEL) { | |||
res = -ENOTSUP; | |||
res = -EINVAL; | |||
break; | |||
} | |||
at86rf2xx_set_chan(dev, chan); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I am confused, but something still seems off: initially, res
is set to -ENOTSUP
. If the given channel is invalid, we set it to -EINVAL
, so far so good. But if the channel is valid, we do not change res
, so when we get to the break below, res
is still set to -ENOTSUP
. This will trigger the call to netdev2_ieee802154_set(...)
at the end of the function. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know GitHub is blending it out, but it is commented on in the line below. This PR does not change this behavior since the chan
field in the netdev2_ieee802154_t struct still needs to be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think res
should be getting set here on a valid channel change, since netdev2_ieee802154_set()
doesn't handle NETOPT_CHANNEL
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. So perhaps this comment is redundant now: https://github.com/authmillenon/RIOT/blob/253dbe225366efcb6506ccc01a5fb19ab7557b47/drivers/netdev2_ieee802154/netdev2_ieee802154.c#L226
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Could I also suggest that, for this PR, we remove the existing code in the RIOT/drivers/at86rf2xx/at86rf2xx_getset.c Line 128 in ceab9bd
|
I'm all for it, but this is touching legacy code by @haukepetersen, that was intended to keep the driver independent from netdev. Are you alright with this change, @haukepetersen? |
Also, I think |
The documentation here needs updating too, given the previous commits: RIOT/drivers/include/net/netdev2/ieee802154.h Line 129 in d171c96
|
|
@haukepetersen what do you think about the PR in its current state? |
case NETOPT_CHANNEL: | ||
/* validity needs to be checked by device, since sub-GHz and 2.4 GHz | ||
* band radios have different legal values */ | ||
if (len > sizeof(dev->chan)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use assert
here instead...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the file doesn't use assert either yet. Let's do this in a seperate follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #5327
in general I am ok with this, though I think there is still a bug in the behavior: the the |
But there are some options for which calling |
exactly, and that is the problem of the current code. Just have a look at my WIP PR for the CC2420 driver https://github.com/RIOT-OS/RIOT/pull/5314/files#diff-9557a9fbe33e77bb84867da9d97c67c9R808. This way both are called, but the -ENOTSUP is only returned if none them know what to do with the data.. |
But that approach also has problems - what if an application tries to set an invalid channel, for example? Since only the driver can know if the requested channel is valid, it will be set to an invalid value in the Since some options cannot be dealt with at all by |
If I can be selfish for a second :) I'm really only interested in the changes to |
Ok, I see your needs. I didn't really want to go into the deeper architectural discussion here (as the hole concept is currently flawed as is). So for now, I would be fine with taking this PR as is, if we fix it, so that certain params (as address, pan id) are also passed to the |
They already are... |
Since |
ok, never mind, the issue I was referring to does not exist, so I am ok with this PR. |
something is off when setting a channel:
|
but the channel is actually set, so the return value is off? |
Fixed. Please retest. |
that did the job. Looks good now -> ACK once squashed and Murock gives a green |
4c774b9
to
0fa5b81
Compare
Done |
@authmillenon @haukepetersen there is no way this has been tested properly. You declare |
Yes, we tested it properly: |
The driver has to make sure the channel is in the correct range, as the comment states. |
But then if |
Or just declaring chan as uint8_t? |
Under the given test conditions
IEEE 802.15.4 isn't the only radio standard we support and apparently (pure conjecture, given that I did not define the type for that NETOPT) there are radio standards with channel value > 255. |
OK - I understand. It just seemed weird to require a 16-bit value, only to throw 8 bits of it away, especially on memory-constrained devices. Perhaps we could check if NETOPT_CHANNEL really does need to be 16-bit. |
Since this 16-bit value is typically allocated on the stack I would argue that keeping the variety of types in |
See devel mailing list