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

cpu/cc2538: Enable CRC checking of received packets #5654

Merged
merged 1 commit into from
Jul 25, 2016

Conversation

aeneby
Copy link
Member

@aeneby aeneby commented Jul 17, 2016

Drop packets which have invalid CRC.

@OlegHahm OlegHahm modified the milestone: Release 2016.10 Jul 17, 2016
@OlegHahm OlegHahm added Area: network Area: Networking Area: drivers Area: Device drivers labels Jul 17, 2016
@aeneby aeneby force-pushed the check_crc_ok_v3 branch from b8375ce to 6d1d006 Compare July 18, 2016 08:42
@hexluthor
Copy link
Contributor

@aeneby I think you should be using rfcore_peek_rx_fifo(RFCORE_XREG_RXFIFOCNT) instead of rfcore_peek_rx_fifo(RFCORE_XREG_RXFIFOCNT - 1). But even better, consider using rfcore_peek_rx_fifo(pkt_len). RXFIFOCNT could change during the call to _recv(), but pkt_len won't.

@aeneby aeneby force-pushed the check_crc_ok_v3 branch from 6d1d006 to 0475b99 Compare July 20, 2016 22:09
@aeneby
Copy link
Member Author

aeneby commented Jul 20, 2016

@aeneby I think you should be using rfcore_peek_rx_fifo(RFCORE_XREG_RXFIFOCNT) instead of rfcore_peek_rx_fifo(RFCORE_XREG_RXFIFOCNT - 1)

You're right - RFCORE_XREG_RXFIFOCNT doesn't include the length byte itself. Fixed.

But even better, consider using rfcore_peek_rx_fifo(pkt_len)

Hmm, this might be a bad idea, since the length byte is not guaranteed to be correct (in case of interference, for example). We actually do a check for this condition in the if statement immediately following this CRC check.

@aeneby
Copy link
Member Author

aeneby commented Jul 21, 2016

I guess we could change the order of - or even combine - the checks, but the end result will be the the same.

@hexluthor
Copy link
Contributor

Your are right that the length byte may not be the same as transmitted in case of interference. But it will always indicate the length of the received frame (and hence the offset of the RSSI and LQI bytes).

Suppose that by the time _recv() is called the radio has already started receiving a second packet. If we check the RSSI/LQI bytes using RXFIFOCNT as a reference, we could be making decisions about the first packet using unrelated data from the second packet. We could also be incorrectly discarding a valid packet just because there are more bytes than we expected in the FIFO. Trusting pkt_len avoids these problems.

@aeneby aeneby force-pushed the check_crc_ok_v3 branch from 0475b99 to 07f51e3 Compare July 21, 2016 21:03
@aeneby
Copy link
Member Author

aeneby commented Jul 21, 2016

Your are right that the length byte may not be the same as transmitted in case of interference. But it will always indicate the length of the received frame (and hence the offset of the RSSI and LQI bytes).

I see what you mean. I guess the only case we have to watch for is when pkt_len is larger than the FIFO itself, since then we know it's full of garbage and can just flush it. See updated commit.

We could also be incorrectly discarding a valid packet just because there are more bytes than we expected in the FIFO.

True, this is something we need to consider. We shouldn't really be flushing the FIFO on failed CRC, but rather checking if there's another packet arrived and advancing the FIFO pointer to it or something. But perhaps that's outside the scope of this PR - there are likely other places we need to do this too.

@hexluthor
Copy link
Contributor

Thanks for making the tweaks @aeneby. Looks good on BOARD=cc2538dk. I'll merge soon if there are no objections. I agree about the extra FIFO flushes. There is some room for improvement there but in a future PR.

@hexluthor hexluthor merged commit 66b3639 into RIOT-OS:master Jul 25, 2016
@kYc0o
Copy link
Contributor

kYc0o commented Jul 25, 2016

didn't Murdock look at this one?

@hexluthor hexluthor added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 25, 2016
@hexluthor
Copy link
Contributor

@kYc0o sorry, my bad.

@aeneby aeneby deleted the check_crc_ok_v3 branch July 25, 2016 19:23
@aeneby
Copy link
Member Author

aeneby commented Jul 25, 2016

Cheers!

@kYc0o
Copy link
Contributor

kYc0o commented Jul 26, 2016

Uhmm... well, let's put more attention for the next ones and to explicitly say "ACK" when the PR is ready to be merged.

OlegHahm pushed a commit to OlegHahm/RIOT that referenced this pull request Aug 16, 2016
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 CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants