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

cc2420/gnrc_netif: Adds crc_valid to netif #8276

Closed
wants to merge 3 commits into from

Conversation

roberthartung
Copy link
Member

Provides a way to check CRC inside the application, by adding a crc_valid field to the netif hdr.

drivers/cc2420/cc2420.c Outdated Show resolved Hide resolved
@miri64 miri64 self-assigned this Dec 19, 2017
@miri64 miri64 added Area: drivers Area: Device drivers Area: network Area: Networking Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Dec 19, 2017
miri64
miri64 previously requested changes Feb 15, 2018
sys/include/net/gnrc/netif/hdr.h Outdated Show resolved Hide resolved
@miri64
Copy link
Member

miri64 commented Mar 15, 2018

Ping @roberthartung?

@roberthartung
Copy link
Member Author

Sorry -> Vacation. Still on it, but other tasks have higher priority ;)

@miri64
Copy link
Member

miri64 commented Aug 24, 2018

The crc_valid member can go into flags, IMHO.

@miri64
Copy link
Member

miri64 commented Aug 24, 2018

I took the liberty to that as a fixup ;-) (needs rebase btw)

@miri64 miri64 dismissed their stale review August 24, 2018 14:19

@bergzand @smlng @kYc0o since I now contributed, could you please review? Also I don't have a cc2420 to test.

@miri64
Copy link
Member

miri64 commented Oct 3, 2018

@bergzand ping?

@miri64 miri64 force-pushed the netif-crc-valid branch 2 times, most recently from 0658ffc to 9dfbed5 Compare October 3, 2018 17:33
@miri64
Copy link
Member

miri64 commented Nov 22, 2018

@bergzand @smlng @kYc0o since I now contributed, could you please review? Also I don't have a cc2420 to test.

Ping? I also rebased this PR.

@miri64
Copy link
Member

miri64 commented Dec 18, 2018

Rebased to current master. Can't push to @roberthartung's branch anymore :(

@miri64
Copy link
Member

miri64 commented Feb 26, 2019

Rebased to current master. Can't push to @roberthartung's branch anymore :(

Nope, was just stupid.

@miri64 miri64 requested a review from bergzand February 26, 2019 18:44
@roberthartung
Copy link
Member Author

@miri64 yeehaa :-) So what's our plan?

@miri64
Copy link
Member

miri64 commented Mar 12, 2019

That someone reviews this. @bergzand?

@miri64
Copy link
Member

miri64 commented Mar 12, 2019

In the meantime I simplified the code a bit and amended the doc.

@roberthartung
Copy link
Member Author

rebased, let's see what the checks say!

@bergzand
Copy link
Member

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).

@bergzand
Copy link
Member

Besides trying to compile this, are there any test instructions?

@miri64
Copy link
Member

miri64 commented Mar 12, 2019

rebased, let's see what the checks say!

arghs arghs arghs, did you make sure my latest changes were in it?

@miri64
Copy link
Member

miri64 commented Mar 12, 2019

rebased, let's see what the checks say!

arghs arghs arghs, did you make sure my latest changes were in it?

yes, they are :-). Thank you!

@miri64
Copy link
Member

miri64 commented Mar 12, 2019

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 (netdev, gnrc_netif_hdr, and cc2420), there should be a split-up of commits. At least the API changes should be distinct from the implementation example in the cc2420.

@@ -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) */
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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 ;-)

@miri64
Copy link
Member

miri64 commented Mar 12, 2019

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).

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.

@roberthartung
Copy link
Member Author

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).

Forward Error Correction is a regular use case.

@roberthartung
Copy link
Member Author

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).

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.

ACK. Very common use case to use dropped packets as a metric.

@miri64 miri64 changed the title WIP: Adds crc_valid to netif cc2420/gnrc_netif: Adds crc_valid to netif Jul 25, 2019
@@ -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 };
Copy link
Member

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.

Copy link
Member

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).

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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 ;-).

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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)

Copy link
Member

@PeterKietzmann PeterKietzmann Jul 25, 2019

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?

Copy link
Member

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 with 0? (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

@jia200x
Copy link
Member

jia200x commented Jul 25, 2019

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.

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

@stale
Copy link

stale bot commented Jan 26, 2020

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.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Jan 26, 2020
@stale stale bot closed this Feb 26, 2020
@jia200x
Copy link
Member

jia200x commented Apr 8, 2020

@fjmolinas this concept might still be interesting for #13824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: network Area: Networking State: stale State: The issue / PR has no activity for >185 days Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants