MKRWAN icon indicating copy to clipboard operation
MKRWAN copied to clipboard

32 bits frame counters

Open giampiero7 opened this issue 5 years ago • 9 comments

setFCU() and setFCD accept 16bits values. Why are 32bits values not supported? Thanks!

giampiero7 avatar Apr 30 '19 10:04 giampiero7

The counters are the ones defined by the LoRa standard which are 16 bit numbers used for frame identification. See 4.3.1 Frame header (FHDR) of the LoRaWan standard 1.0.3

flhofer avatar Jul 08 '21 15:07 flhofer

Hi, Old topic, but still relevant. Refer to 4.3.1.5 Frame counter (FCnt):

... The LoRaWAN allows the use of either 16-bits or 32-bits frame counters. ...

giampiero7 avatar Jul 09 '21 08:07 giampiero7

@giampiero7 right, but not really..

Note: Since the FCnt field carries only the least-significant 16 bits of the 32-bits frame counter, 
the server must infer the 16 most-significant bits of the frame counter from the observation of the traffic.

so it actually doesn't make any difference

flhofer avatar Jul 10 '21 09:07 flhofer

@flhofer Not really. The full 32-bits counters are used for frame encryption and integrity check (see 4.3.3 and 4.4). This is why the server must infer the 16 most-significant bits, to correctly decrypt and check the received frames. Otherwise the possibility to use 32-bits frame counters would make no sense, don't you think?

giampiero7 avatar Jul 10 '21 11:07 giampiero7

It seems mostly related to frame uniqueness though. I think they didn't consider it as the toy-MKR micro might never reach millions of frames without any reset and probably (I think) doesn't have servers running in strict mode.

Anyway, it seems that the firmware should handle it, so you can safely change the data types of getters and setters to uint32_t.

flhofer avatar Jul 10 '21 12:07 flhofer

Oh, and sorry @giampiero7 if I sounded rude. I'm a bit under pressure here as I'm using these toys for a project and this modem firmware is really driving me nuts. We're discussing replacement so if you have some other suggestions, please come forward.

flhofer avatar Jul 10 '21 12:07 flhofer

@flhofer Not at all, on the contrary, I appreciate you replaying to my issue :)

You may want to check out my company's products: https://www.sferalabs.cc/product/iono-mkr/ which are actually used in contexts where devices are possibly never reset and strict mode is very likely. The core is a standard MKR, so adapting your current code would require minimal or no modification at all, depending on what you are doing.

Also, you can check our version of the library in this application: https://github.com/sfera-labs/iono-mkr-lorawan/blob/master/IonoMkrLoRaWAN/MKRWAN.h where we've modified it exactly as you suggested.

Hope it helps!

giampiero7 avatar Jul 10 '21 13:07 giampiero7

Awesome nice tools :) Finally something not Pi-based. You might like to hear that I implemented a lot of patches and features for the firmware and the library. You can find them in the pull requests I submitted. Once I'm done with my pen- and performance testing, we might add final fixes and merge.

Btw, applied the change to my pull request :)

flhofer avatar Jul 10 '21 14:07 flhofer

Great, I'll check them out, thanks for your contribution. Good luck with your project!

giampiero7 avatar Jul 12 '21 08:07 giampiero7