-
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
cc2420/gnrc_netif: Adds crc_valid to netif #8276
Conversation
Ping @roberthartung? |
Sorry -> Vacation. Still on it, but other tasks have higher priority ;) |
The |
I took the liberty to that as a fixup ;-) (needs rebase btw) |
@bergzand ping? |
0658ffc
to
9dfbed5
Compare
9dfbed5
to
6ba32fb
Compare
|
6ba32fb
to
1a9410f
Compare
Nope, was just stupid. |
@miri64 yeehaa :-) So what's our plan? |
That someone reviews this. @bergzand? |
In the meantime I simplified the code a bit and amended the doc. |
bec9ac5
to
02bde1e
Compare
rebased, let's see what the checks say! |
Out of curiosity, what's the use case for this? I can imagine the sniffer application as one, but for "regular" radio operation I'm assuming that most simply drop the frame if the CRC is invalid (so frames with invalid CRC are never going to reach the radio driver). |
Besides trying to compile this, are there any test instructions? |
arghs arghs arghs, did you make sure my latest changes were in it? |
yes, they are :-). Thank you! |
However, can you please have it according to the contribution guidelines and prefix the commit with the module you change? Also since you are touching at least 3 modules/APIs ( |
@@ -249,6 +249,7 @@ typedef enum { | |||
struct netdev_radio_rx_info { | |||
int16_t rssi; /**< RSSI of a received packet in dBm */ | |||
uint8_t lqi; /**< LQI of a received packet */ | |||
uint8_t crc_valid; /**< CRC was valid (when != 0) */ |
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.
Now this might be in the "premature optimization" area. Is there a use case for changing this to uint8_t flags;
and use it as a number of boolean flags for received frames, something like
NETDEV_RADIO_RX_CRC_VALID (0x01) /**< Set if the CRC was valid */
NETDEV_RADIO_RX_DATA_PEND (0x02) /**< Set if the received frame has the data pending bit set */
I don't want to stall this PR more than necessary with this idea. if we might need this in the future, having a bool netdev_radio_crc_valid(netdev_radio_rx_info_t *info)
getter for the crc status would prevent a migration to flags being a significant API change.
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.
Sounds valid to me, @miri64 what's your opinion?
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.
Agreed, however also see #11023 for pending data handling ;) (since that can be read from the MAC header at least in IEEE 802.15.4's case, I'm not sure it needs to be in the info struct ;-)
Not sure this is the intention, but apart from the experimental use-case you pointed out, I believe a MAC protocol might also benefit from this, e. g. if it wants to be notified that something was received, even is it was invalid. |
Forward Error Correction is a regular use case. |
ACK. Very common use case to use dropped packets as a metric. |
02bde1e
to
a2f1f20
Compare
@@ -90,7 +90,7 @@ static inline bool _already_received(gnrc_netif_t *netif, | |||
static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) | |||
{ | |||
netdev_t *dev = netif->dev; | |||
netdev_ieee802154_rx_info_t rx_info; | |||
netdev_ieee802154_rx_info_t rx_info = { .crc_valid = 0 }; |
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.
Why is crc_valid
set to 0? AFAIS this will be always set by the driver in this case.
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.
It is not guaranteed that the driver will set it. In that case not setting it to 0 would mean the value would be in an undefined state (as it is allocated on a dirty stack).
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 the driver should always set it. If the driver doesn't set it, it will be seen as invalid by the MAC layer.
If the radio doesn't support CRC calculation, this should be ignored via radio_caps (see #11473 ). If the driver doesn't provide a flag for the CRC (but does the calculations), it can be set to valid anyway.
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.
In this PR we can't assume that and we also should not. Otherwise this PR needs to touch all the drivers.
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.
It is also in general not save to assume the callee changes a value, so it should always be set if it is checked later. Just from a security perspective ;-).
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.
Most of the devices calculate the CRC themselves and don't (necessarily) expose it. Furthermore, oftentimes only frames with valid CRCs are even indicated by our drivers. In that case, .crc
needs to be set to a value !=0. Where does this happen? Or did I misunderstand something?
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.
In that case, .crc needs to be set to a value !=0. Where does this happen? Or did I misunderstand something?
It the drivers. However, this PR only ports the cc2420
. That's why I and @jia200x suggested that @roberthartung adds the big fat warning to the doc of that field. Requiring all the drivers to be ported in this PR would explode this PR.
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 initialization as used above does this implicitly
So you are saying that netdev_ieee802154_rx_info_t rx_info = { .crc_valid = 0 };
initializes the whole structure with 0
? (And I'm not talking about some smart compiler things going on in the background)
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.
Requiring all the drivers to be ported in this PR would explode this PR.
How about we wait until someone opens the follow-up PR and then we both consecutively?
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.
So you are saying that
netdev_ieee802154_rx_info_t rx_info = { .crc_valid = 0 };
initializes the whole structure with0
? (And I'm not talking about some smart compiler things going on in the background)
To say it semantically correct: struct foobar foo = { .field = x }
initializes field
with x
and all fields of foobar
that are not provided with 0. So in the case above, yes it initializes the whole struct with 0 (AFAIK in the background most compilers solve this by just implicitly calling memset()
though). See https://en.cppreference.com/w/c/language/struct_initialization for reference.
How about we wait until someone opens the follow-up PR and then we both consecutively?
See #9755 for at86rf2xx
There are even some radios that don't calculate CRC. This feature (together with #11473 ) would provide part of the IEEE802.15.4 PHY/MAC |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
@fjmolinas this concept might still be interesting for #13824 |
Provides a way to check CRC inside the application, by adding a crc_valid field to the netif hdr.