mcci-catena / arduino-lmic

LoraWAN-MAC-in-C library, adapted to run under the Arduino environment
https://forum.mcci.io/c/device-software/arduino-lmic/
MIT License
648 stars 212 forks source link

Uplink with FPort 255 and invalid MIC! #950

Open mohsenmoqadam opened 1 year ago

mohsenmoqadam commented 1 year ago

Hello dears

The first question is: Why does UNO use 255? while the downlink port was 1.

Furthermore, the MIC of the uplink message isn't valid!

So the next question: In this scenario (FCtrlACK=true, and with no frame payload) which Key is used for generating MIC in the LMIC library? I read lmic.c but everything is okay and cont find any problem, can anyone guide me about this issue and how to fix it?

terrillmoore commented 1 year ago

The LMIC sends an ACK to the confirmed downlink message without a port number because there's no application payload. I guess that the Network service is not tested yet for this situation. Check https://github.com/mcci-catena/arduino-lmic/blob/master/doc/LoRaWAN-at-a-glance.pdf which correctly says: "FPort is present if any payload bytes are present" but forgets to say "if and only if". My guess is that the NS code is not anticipating this case, and is instead reading off the end of the buffer (and assuming the MIC starts one byte late).

Best regards, --Terry

mohsenmoqadam commented 1 year ago

Thanks, Terry. Based on your guidance if FramePayload is empty, then we must calculate MIC with: MHDR|DevAddr|FCtrl|FCnt|FOpts.

Now my problem is solved and all things are okay, again I would like to admire your subtlety and quick response