lw_state.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**************************************************************************
  2. Copyright (c) 2017 Theodor Tobias Rohde (tr@lobaro.com)
  3. Lobaro - Industrial IoT Solutions
  4. www.lobaro.com
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in all
  12. copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. SOFTWARE.
  20. *****************************************************************************/
  21. #ifndef _LW_STATE_H_
  22. #define _LW_STATE_H_
  23. #include <stdint.h>
  24. // LoRaWAN device config / state parameter
  25. // todo add LoRaWAN 1.1 functionality
  26. typedef struct {
  27. uint32_t DevAddr;
  28. // 128 Bit keys
  29. uint8_t nwkskey[16];
  30. uint8_t appskey[16];
  31. uint8_t appkey[16]; // OTAA only
  32. // EUIs (used for OTAA join only)
  33. // EUI are 8 bytes multi-octet fields and are transmitted as little endian. (LoRaWAN Specification)
  34. // -> if the EUI-64 is 70-B3-D5-7E-F0-00-48-9C it would be in the air as 9C-48-00...
  35. // LoRaWAN_MarshalPacket will take care of this (make the little endian conversion)
  36. uint8_t joinEUI[8]; // before LoRaWAN1.1 this was also called the appEUI
  37. uint8_t devEUI[8];
  38. // OTAA only:
  39. // used for/in join request msg (issued by client/sensor)
  40. uint16_t devnonce; // must be random for each join request
  41. // only used for/in join accept msg (issued by network server)
  42. uint32_t appnonce; // aka joinnonce in lorawan 1.1, If the device is susceptible of being power cycled the JoinNonce SHALL be persistent
  43. uint32_t netid;
  44. } Lorawan_devCfg_t;
  45. // LoRaWAN network control / state parameter
  46. typedef struct {
  47. uint32_t FCntUp;
  48. uint32_t AFCntDown; // used for all other ports when the device operates as a LoRaWAN 1.1 or for all communications on LoRaWAN 1.0.1
  49. // new in LoRaWAN 1.1 (not supported yet!)
  50. uint32_t NFCntDown; // used for MAC communication on port 0 and when the FPort field is missing (LoRaWAN 1.1 only)
  51. // In the two counters scheme the NFCntDown is managed by the Network Server, whereas
  52. // the AFCntDown is managed by the application server
  53. } Lorawan_fcnt_t;
  54. #endif