Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2771 lines
71 KiB

  1. /*!
  2. * \file LoRaMac.h
  3. *
  4. * \brief LoRa MAC layer implementation
  5. *
  6. * \copyright Revised BSD License, see section \ref LICENSE.
  7. *
  8. * \code
  9. * ______ _
  10. * / _____) _ | |
  11. * ( (____ _____ ____ _| |_ _____ ____| |__
  12. * \____ \| ___ | (_ _) ___ |/ ___) _ \
  13. * _____) ) ____| | | || |_| ____( (___| | | |
  14. * (______/|_____)_|_|_| \__)_____)\____)_| |_|
  15. * (C)2013-2017 Semtech
  16. *
  17. * ___ _____ _ ___ _ _____ ___ ___ ___ ___
  18. * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __|
  19. * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _|
  20. * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
  21. * embedded.connectivity.solutions===============
  22. *
  23. * \endcode
  24. *
  25. * \author Miguel Luis ( Semtech )
  26. *
  27. * \author Gregory Cristian ( Semtech )
  28. *
  29. * \author Daniel Jaeckle ( STACKFORCE )
  30. *
  31. * \author Johannes Bruder ( STACKFORCE )
  32. *
  33. * \defgroup LORAMAC LoRa MAC layer implementation
  34. * This module specifies the API implementation of the LoRaMAC layer.
  35. * This is a placeholder for a detailed description of the LoRaMac
  36. * layer and the supported features.
  37. * \{
  38. *
  39. * \example periodic-uplink-lpp/B-L072Z-LRWAN1/main.c
  40. * LoRaWAN class A/B/C application example for the B-L072Z-LRWAN1.
  41. *
  42. * \example periodic-uplink-lpp/NAMote72/main.c
  43. * LoRaWAN class A/B/C application example for the NAMote72.
  44. *
  45. * \example periodic-uplink-lpp/NucleoL073/main.c
  46. * LoRaWAN class A/B/C application example for the NucleoL073.
  47. *
  48. * \example periodic-uplink-lpp/NucleoL152/main.c
  49. * LoRaWAN class A/B/C application example for the NucleoL152.
  50. *
  51. * \example periodic-uplink-lpp/NucleoL476/main.c
  52. * LoRaWAN class A/B/C application example for the NucleoL476.
  53. *
  54. * \example periodic-uplink-lpp/SAMR34/main.c
  55. * LoRaWAN class A/B/C application example for the SAMR34.
  56. *
  57. * \example periodic-uplink-lpp/SKiM880B/main.c
  58. * LoRaWAN class A/B/C application example for the SKiM880B.
  59. *
  60. * \example periodic-uplink-lpp/SKiM881AXL/main.c
  61. * LoRaWAN class A/B/C application example for the SKiM881AXL.
  62. *
  63. * \example periodic-uplink-lpp/SKiM980A/main.c
  64. * LoRaWAN class A/B/C application example for the SKiM980A.
  65. */
  66. #ifndef __LORAMAC_H__
  67. #define __LORAMAC_H__
  68. #ifdef __cplusplus
  69. extern "C"
  70. {
  71. #endif
  72. #include <stdint.h>
  73. #include <stdbool.h>
  74. #include "timer.h"
  75. #include "systime.h"
  76. #include "LoRaMacTypes.h"
  77. #include "RegionNvm.h"
  78. #include "LoRaMacCryptoNvm.h"
  79. #include "secure-element-nvm.h"
  80. #include "LoRaMacClassBNvm.h"
  81. /*!
  82. * Maximum number of times the MAC layer tries to get an acknowledge.
  83. */
  84. #define MAX_ACK_RETRIES 8
  85. /*!
  86. * Frame direction definition for up-link communications
  87. */
  88. #define UP_LINK 0
  89. /*!
  90. * Frame direction definition for down-link communications
  91. */
  92. #define DOWN_LINK 1
  93. /*!
  94. * LoRaMac MLME-Confirm queue length
  95. */
  96. #define LORA_MAC_MLME_CONFIRM_QUEUE_LEN 5
  97. /*!
  98. * Start value for multicast keys enumeration
  99. */
  100. #define LORAMAC_CRYPTO_MULTICAST_KEYS 127
  101. /*!
  102. * Maximum MAC commands buffer size
  103. */
  104. #define LORA_MAC_COMMAND_MAX_LENGTH 128
  105. /*!
  106. * Bitmap value
  107. */
  108. #define LORAMAC_NVM_NOTIFY_FLAG_NONE 0x00
  109. /*!
  110. * Bitmap value for the NVM group crypto.
  111. */
  112. #define LORAMAC_NVM_NOTIFY_FLAG_CRYPTO 0x01
  113. /*!
  114. * Bitmap value for the NVM group MAC 1.
  115. */
  116. #define LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP1 0x02
  117. /*!
  118. * Bitmap value for the NVM group MAC 2.
  119. */
  120. #define LORAMAC_NVM_NOTIFY_FLAG_MAC_GROUP2 0x04
  121. /*!
  122. * Bitmap value for the NVM group secure element.
  123. */
  124. #define LORAMAC_NVM_NOTIFY_FLAG_SECURE_ELEMENT 0x08
  125. /*!
  126. * Bitmap value for the NVM group 1 region.
  127. */
  128. #define LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP1 0x10
  129. /*!
  130. * Bitmap value for the NVM group 2 region.
  131. */
  132. #define LORAMAC_NVM_NOTIFY_FLAG_REGION_GROUP2 0x20
  133. /*!
  134. * Bitmap value for the NVM group class b.
  135. */
  136. #define LORAMAC_NVM_NOTIFY_FLAG_CLASS_B 0x40
  137. /*!
  138. * LoRaWAN compliance certification protocol port number.
  139. *
  140. * LoRaWAN Specification V1.x.x, chapter 4.3.2
  141. */
  142. #define LORAMAC_CERT_FPORT 224
  143. /*!
  144. * End-Device activation type
  145. */
  146. typedef enum eActivationType
  147. {
  148. /*!
  149. * None
  150. */
  151. ACTIVATION_TYPE_NONE = 0,
  152. /*!
  153. * Activation By Personalization (ACTIVATION_TYPE_ABP)
  154. */
  155. ACTIVATION_TYPE_ABP = 1,
  156. /*!
  157. * Over-The-Air Activation (ACTIVATION_TYPE_OTAA)
  158. */
  159. ACTIVATION_TYPE_OTAA = 2,
  160. }ActivationType_t;
  161. /*!
  162. * LoRaMAC receive window channel parameters
  163. */
  164. typedef struct sRxChannelParams
  165. {
  166. /*!
  167. * Frequency in Hz
  168. */
  169. uint32_t Frequency;
  170. /*!
  171. * Data rate
  172. *
  173. * LoRaWAN Regional Parameters V1.0.2rB
  174. *
  175. * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
  176. */
  177. uint8_t Datarate;
  178. }RxChannelParams_t;
  179. /*!
  180. * LoRaMAC receive window enumeration
  181. */
  182. typedef enum eLoRaMacRxSlot
  183. {
  184. /*!
  185. * LoRaMAC receive window 1
  186. */
  187. RX_SLOT_WIN_1,
  188. /*!
  189. * LoRaMAC receive window 2
  190. */
  191. RX_SLOT_WIN_2,
  192. /*!
  193. * LoRaMAC receive window 2 for class c - continuous listening
  194. */
  195. RX_SLOT_WIN_CLASS_C,
  196. /*!
  197. * LoRaMAC class c multicast downlink
  198. */
  199. RX_SLOT_WIN_CLASS_C_MULTICAST,
  200. /*!
  201. * LoRaMAC class b ping slot window
  202. */
  203. RX_SLOT_WIN_CLASS_B_PING_SLOT,
  204. /*!
  205. * LoRaMAC class b multicast slot window
  206. */
  207. RX_SLOT_WIN_CLASS_B_MULTICAST_SLOT,
  208. /*!
  209. * LoRaMAC no active receive window
  210. */
  211. RX_SLOT_NONE,
  212. }LoRaMacRxSlot_t;
  213. /*!
  214. * Global MAC layer parameters
  215. */
  216. typedef struct sLoRaMacParams
  217. {
  218. /*!
  219. * System overall timing error in milliseconds.
  220. * [-SystemMaxRxError : +SystemMaxRxError]
  221. * Default: +/-10 ms
  222. */
  223. uint32_t SystemMaxRxError;
  224. /*!
  225. * Minimum required number of symbols to detect an Rx frame
  226. * Default: 6 symbols
  227. */
  228. uint8_t MinRxSymbols;
  229. /*!
  230. * LoRaMac maximum time a reception window stays open
  231. */
  232. uint32_t MaxRxWindow;
  233. /*!
  234. * Receive delay 1
  235. */
  236. uint32_t ReceiveDelay1;
  237. /*!
  238. * Receive delay 2
  239. */
  240. uint32_t ReceiveDelay2;
  241. /*!
  242. * Join accept delay 1
  243. */
  244. uint32_t JoinAcceptDelay1;
  245. /*!
  246. * Join accept delay 1
  247. */
  248. uint32_t JoinAcceptDelay2;
  249. /*!
  250. * Number of uplink messages repetitions [1:15] (unconfirmed messages only)
  251. */
  252. uint8_t ChannelsNbTrans;
  253. /*!
  254. * Datarate offset between uplink and downlink on first window
  255. */
  256. uint8_t Rx1DrOffset;
  257. /*!
  258. * LoRaMAC 2nd reception window settings
  259. */
  260. RxChannelParams_t Rx2Channel;
  261. /*!
  262. * LoRaMAC continuous reception window settings
  263. */
  264. RxChannelParams_t RxCChannel;
  265. /*!
  266. * Uplink dwell time configuration. 0: No limit, 1: 400ms
  267. */
  268. uint8_t UplinkDwellTime;
  269. /*!
  270. * Downlink dwell time configuration. 0: No limit, 1: 400ms
  271. */
  272. uint8_t DownlinkDwellTime;
  273. /*!
  274. * Maximum possible EIRP
  275. */
  276. float MaxEirp;
  277. /*!
  278. * Antenna gain of the node
  279. */
  280. float AntennaGain;
  281. }LoRaMacParams_t;
  282. /*!
  283. * LoRaMAC data structure for a PingSlotInfoReq \ref MLME_PING_SLOT_INFO
  284. *
  285. * LoRaWAN Specification
  286. */
  287. typedef union uPingSlotInfo
  288. {
  289. /*!
  290. * Parameter for byte access
  291. */
  292. uint8_t Value;
  293. /*!
  294. * Structure containing the parameters for the PingSlotInfoReq
  295. */
  296. struct sInfoFields
  297. {
  298. /*!
  299. * Periodicity = 0: ping slot every second
  300. * Periodicity = 7: ping slot every 128 seconds
  301. */
  302. uint8_t Periodicity : 3;
  303. /*!
  304. * RFU
  305. */
  306. uint8_t RFU : 5;
  307. }Fields;
  308. }PingSlotInfo_t;
  309. /*!
  310. * LoRaMAC data structure for the \ref MLME_BEACON MLME-Indication
  311. *
  312. * LoRaWAN Specification
  313. */
  314. typedef struct sBeaconInfo
  315. {
  316. /*!
  317. * Timestamp in seconds since 00:00:00, Sunday 6th of January 1980
  318. * (start of the GPS epoch) modulo 2^32
  319. */
  320. SysTime_t Time;
  321. /*!
  322. * Frequency
  323. */
  324. uint32_t Frequency;
  325. /*!
  326. * Datarate
  327. */
  328. uint8_t Datarate;
  329. /*!
  330. * RSSI
  331. */
  332. int16_t Rssi;
  333. /*!
  334. * SNR
  335. */
  336. int8_t Snr;
  337. /*!
  338. * Param
  339. * | Bits | 7:2 | 1:0 |
  340. * |-------|-----|------|
  341. * | Param | RFU | Prec |
  342. *
  343. * Prec field is used to interpret the precision of beacon's transmit time
  344. * as 10^(-6+prec) and the default value is 0.
  345. * RFU will be set to Zero and Prec can take values between 0:3.
  346. */
  347. uint8_t Param;
  348. /*!
  349. * Data structure for the gateway specific part. The
  350. * content of the values may differ for each gateway
  351. */
  352. struct sGwSpecific
  353. {
  354. /*!
  355. * Info descriptor - can differ for each gateway
  356. */
  357. uint8_t InfoDesc;
  358. /*!
  359. * Info - can differ for each gateway
  360. */
  361. uint8_t Info[6];
  362. }GwSpecific;
  363. }BeaconInfo_t;
  364. /*!
  365. * Enumeration containing the status of the operation of a MAC service
  366. */
  367. typedef enum eLoRaMacEventInfoStatus
  368. {
  369. /*!
  370. * Service performed successfully
  371. */
  372. LORAMAC_EVENT_INFO_STATUS_OK = 0,
  373. /*!
  374. * An error occurred during the execution of the service
  375. */
  376. LORAMAC_EVENT_INFO_STATUS_ERROR,
  377. /*!
  378. * A Tx timeout occurred
  379. */
  380. LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT,
  381. /*!
  382. * An Rx timeout occurred on receive window 1
  383. */
  384. LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT,
  385. /*!
  386. * An Rx timeout occurred on receive window 2
  387. */
  388. LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT,
  389. /*!
  390. * An Rx error occurred on receive window 1
  391. */
  392. LORAMAC_EVENT_INFO_STATUS_RX1_ERROR,
  393. /*!
  394. * An Rx error occurred on receive window 2
  395. */
  396. LORAMAC_EVENT_INFO_STATUS_RX2_ERROR,
  397. /*!
  398. * An error occurred in the join procedure
  399. */
  400. LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL,
  401. /*!
  402. * A frame with an invalid downlink counter was received. The
  403. * downlink counter of the frame was equal to the local copy
  404. * of the downlink counter of the node.
  405. */
  406. LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED,
  407. /*!
  408. * The MAC could not retransmit a frame since the MAC decreased the datarate. The
  409. * payload size is not applicable for the datarate.
  410. */
  411. LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
  412. /*!
  413. * An address error occurred
  414. */
  415. LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL,
  416. /*!
  417. * Message integrity check failure
  418. */
  419. LORAMAC_EVENT_INFO_STATUS_MIC_FAIL,
  420. /*!
  421. * ToDo
  422. */
  423. LORAMAC_EVENT_INFO_STATUS_MULTICAST_FAIL,
  424. /*!
  425. * ToDo
  426. */
  427. LORAMAC_EVENT_INFO_STATUS_BEACON_LOCKED,
  428. /*!
  429. * ToDo
  430. */
  431. LORAMAC_EVENT_INFO_STATUS_BEACON_LOST,
  432. /*!
  433. * ToDo
  434. */
  435. LORAMAC_EVENT_INFO_STATUS_BEACON_NOT_FOUND,
  436. }LoRaMacEventInfoStatus_t;
  437. /*!
  438. * LoRaMac tx/rx operation state
  439. */
  440. typedef union eLoRaMacFlags_t
  441. {
  442. /*!
  443. * Byte-access to the bits
  444. */
  445. uint8_t Value;
  446. /*!
  447. * Structure containing single access to bits
  448. */
  449. struct sMacFlagBits
  450. {
  451. /*!
  452. * MCPS-Req pending
  453. */
  454. uint8_t McpsReq : 1;
  455. /*!
  456. * MCPS-Ind pending
  457. */
  458. uint8_t McpsInd : 1;
  459. /*!
  460. * MLME-Req pending
  461. */
  462. uint8_t MlmeReq : 1;
  463. /*!
  464. * MLME-Ind pending
  465. */
  466. uint8_t MlmeInd : 1;
  467. /*!
  468. * MLME-Ind to schedule an uplink pending
  469. */
  470. uint8_t MlmeSchedUplinkInd : 1;
  471. /*!
  472. * MAC cycle done
  473. */
  474. uint8_t MacDone : 1;
  475. /*!
  476. * Indicate if a NVM handling is required
  477. */
  478. uint8_t NvmHandle : 1;
  479. }Bits;
  480. }LoRaMacFlags_t;
  481. /*!
  482. * LoRaMAC region enumeration
  483. */
  484. typedef enum eLoRaMacRegion
  485. {
  486. /*!
  487. * AS band on 923MHz
  488. */
  489. LORAMAC_REGION_AS923,
  490. /*!
  491. * Australian band on 915MHz
  492. */
  493. LORAMAC_REGION_AU915,
  494. /*!
  495. * Chinese band on 470MHz
  496. */
  497. LORAMAC_REGION_CN470,
  498. /*!
  499. * Chinese band on 779MHz
  500. */
  501. LORAMAC_REGION_CN779,
  502. /*!
  503. * European band on 433MHz
  504. */
  505. LORAMAC_REGION_EU433,
  506. /*!
  507. * European band on 868MHz
  508. */
  509. LORAMAC_REGION_EU868,
  510. /*!
  511. * South korean band on 920MHz
  512. */
  513. LORAMAC_REGION_KR920,
  514. /*!
  515. * India band on 865MHz
  516. */
  517. LORAMAC_REGION_IN865,
  518. /*!
  519. * North american band on 915MHz
  520. */
  521. LORAMAC_REGION_US915,
  522. /*!
  523. * Russia band on 864MHz
  524. */
  525. LORAMAC_REGION_RU864,
  526. }LoRaMacRegion_t;
  527. typedef struct sLoRaMacNvmDataGroup1
  528. {
  529. /*!
  530. * Counts the number of missed ADR acknowledgements
  531. */
  532. uint32_t AdrAckCounter;
  533. /*!
  534. * Last transmission time.
  535. */
  536. TimerTime_t LastTxDoneTime;
  537. /*!
  538. * Aggregated time off.
  539. */
  540. TimerTime_t AggregatedTimeOff;
  541. /*!
  542. * Last received Message integrity Code (MIC)
  543. */
  544. uint32_t LastRxMic;
  545. /*!
  546. * Channels TX power
  547. */
  548. int8_t ChannelsTxPower;
  549. /*!
  550. * Channels data rate
  551. */
  552. int8_t ChannelsDatarate;
  553. /*!
  554. * If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates
  555. * if the ACK bit must be set for the next transmission
  556. */
  557. bool SrvAckRequested;
  558. /*!
  559. * CRC32 value of the MacGroup1 data structure.
  560. */
  561. uint32_t Crc32;
  562. }LoRaMacNvmDataGroup1_t;
  563. typedef struct sLoRaMacNvmDataGroup2
  564. {
  565. /*
  566. * LoRaMac region.
  567. */
  568. LoRaMacRegion_t Region;
  569. /*
  570. * LoRaMac parameters
  571. */
  572. LoRaMacParams_t MacParams;
  573. /*
  574. * LoRaMac default parameters
  575. */
  576. LoRaMacParams_t MacParamsDefaults;
  577. /*!
  578. * Channels TX power
  579. */
  580. int8_t ChannelsTxPowerDefault;
  581. /*!
  582. * Channels data rate
  583. */
  584. int8_t ChannelsDatarateDefault;
  585. /*
  586. * Network ID ( 3 bytes )
  587. */
  588. uint32_t NetID;
  589. /*
  590. * Mote Address
  591. */
  592. uint32_t DevAddr;
  593. /*!
  594. * Multicast channel list
  595. */
  596. MulticastCtx_t MulticastChannelList[LORAMAC_MAX_MC_CTX];
  597. /*
  598. * Actual device class
  599. */
  600. DeviceClass_t DeviceClass;
  601. /*
  602. * Indicates if the node is connected to
  603. * a private or public network
  604. */
  605. bool PublicNetwork;
  606. /*
  607. * LoRaMac ADR control status
  608. */
  609. bool AdrCtrlOn;
  610. /*
  611. * Maximum duty cycle
  612. * \remark Possibility to shutdown the device.
  613. */
  614. uint8_t MaxDCycle;
  615. /*
  616. * Enables/Disables duty cycle management (Test only)
  617. */
  618. bool DutyCycleOn;
  619. /*
  620. * Set to true, if the datarate was increased
  621. * with a link adr request.
  622. */
  623. bool ChannelsDatarateChangedLinkAdrReq;
  624. /*
  625. * The stack will set this variable to true, if a downlink has been received.
  626. */
  627. bool DownlinkReceived;
  628. /*
  629. * Enables/disable FPort 224 processing (certification port)
  630. */
  631. bool IsCertPortOn;
  632. /*
  633. * Aggregated duty cycle management
  634. */
  635. uint16_t AggregatedDCycle;
  636. /*
  637. * Stores the time at LoRaMac initialization.
  638. *
  639. * \remark Used for the BACKOFF_DC computation.
  640. */
  641. SysTime_t InitializationTime;
  642. /*
  643. * Current LoRaWAN Version
  644. */
  645. Version_t Version;
  646. /*
  647. * End-Device network activation
  648. */
  649. ActivationType_t NetworkActivation;
  650. /*!
  651. * CRC32 value of the MacGroup2 data structure.
  652. */
  653. uint32_t Crc32;
  654. }LoRaMacNvmDataGroup2_t;
  655. /*!
  656. * LoRaMAC data structure for non-volatile memory (NVM).
  657. * This structure contains data which must be stored in NVM.
  658. */
  659. typedef struct sLoRaMacNvmData
  660. {
  661. /*!
  662. * Parameters related to the crypto layer. Change with every TX/RX
  663. * procedure.
  664. */
  665. LoRaMacCryptoNvmData_t Crypto;
  666. /*!
  667. * Parameters related to the MAC which change with high probability after
  668. * every TX/RX procedure.
  669. */
  670. LoRaMacNvmDataGroup1_t MacGroup1;
  671. /*!
  672. * Parameters related to the MAC which do not change very likely with every
  673. * TX/RX procedure.
  674. */
  675. LoRaMacNvmDataGroup2_t MacGroup2;
  676. /*!
  677. * Parameters related to the secure-element.
  678. */
  679. SecureElementNvmData_t SecureElement;
  680. /*!
  681. * Parameters related to the regional implementation which change with high
  682. * probability after every TX/RX procedure.
  683. */
  684. RegionNvmDataGroup1_t RegionGroup1;
  685. /*!
  686. * Parameters related to the regional implementation which do not change
  687. * very likely with every TX/RX procedure.
  688. */
  689. RegionNvmDataGroup2_t RegionGroup2;
  690. /*!
  691. * Parameters related to class b.
  692. */
  693. LoRaMacClassBNvmData_t ClassB;
  694. }LoRaMacNvmData_t;
  695. /*!
  696. *
  697. * \brief LoRaMAC data services
  698. *
  699. * \details The following table list the primitives which are supported by the
  700. * specific MAC data service:
  701. *
  702. * Name | Request | Indication | Response | Confirm
  703. * --------------------- | :-----: | :--------: | :------: | :-----:
  704. * \ref MCPS_UNCONFIRMED | YES | YES | NO | YES
  705. * \ref MCPS_CONFIRMED | YES | YES | NO | YES
  706. * \ref MCPS_MULTICAST | NO | YES | NO | NO
  707. * \ref MCPS_PROPRIETARY | YES | YES | NO | YES
  708. *
  709. * The following table provides links to the function implementations of the
  710. * related MCPS primitives:
  711. *
  712. * Primitive | Function
  713. * ---------------- | :---------------------:
  714. * MCPS-Request | \ref LoRaMacMlmeRequest
  715. * MCPS-Confirm | MacMcpsConfirm in \ref LoRaMacPrimitives_t
  716. * MCPS-Indication | MacMcpsIndication in \ref LoRaMacPrimitives_t
  717. */
  718. typedef enum eMcps
  719. {
  720. /*!
  721. * Unconfirmed LoRaMAC frame
  722. */
  723. MCPS_UNCONFIRMED,
  724. /*!
  725. * Confirmed LoRaMAC frame
  726. */
  727. MCPS_CONFIRMED,
  728. /*!
  729. * Multicast LoRaMAC frame
  730. */
  731. MCPS_MULTICAST,
  732. /*!
  733. * Proprietary frame
  734. */
  735. MCPS_PROPRIETARY,
  736. }Mcps_t;
  737. /*!
  738. * Structure which defines return parameters for requests.
  739. */
  740. typedef struct sRequestReturnParam
  741. {
  742. /*!
  743. * This value reports the time in milliseconds which
  744. * an application must wait before its possible to send
  745. * the next uplink.
  746. */
  747. TimerTime_t DutyCycleWaitTime;
  748. }RequestReturnParam_t;
  749. /*!
  750. * LoRaMAC MCPS-Request for an unconfirmed frame
  751. */
  752. typedef struct sMcpsReqUnconfirmed
  753. {
  754. /*!
  755. * Frame port field. Must be set if the payload is not empty. Use the
  756. * application specific frame port values: [1...223]
  757. *
  758. * LoRaWAN Specification V1.0.2, chapter 4.3.2
  759. */
  760. uint8_t fPort;
  761. /*!
  762. * Pointer to the buffer of the frame payload
  763. */
  764. void* fBuffer;
  765. /*!
  766. * Size of the frame payload
  767. */
  768. uint16_t fBufferSize;
  769. /*!
  770. * Uplink datarate, if ADR is off
  771. */
  772. int8_t Datarate;
  773. }McpsReqUnconfirmed_t;
  774. /*!
  775. * LoRaMAC MCPS-Request for a confirmed frame
  776. */
  777. typedef struct sMcpsReqConfirmed
  778. {
  779. /*!
  780. * Frame port field. Must be set if the payload is not empty. Use the
  781. * application specific frame port values: [1...223]
  782. *
  783. * LoRaWAN Specification V1.0.2, chapter 4.3.2
  784. */
  785. uint8_t fPort;
  786. /*!
  787. * Pointer to the buffer of the frame payload
  788. */
  789. void* fBuffer;
  790. /*!
  791. * Size of the frame payload
  792. */
  793. uint16_t fBufferSize;
  794. /*!
  795. * Uplink datarate, if ADR is off
  796. */
  797. int8_t Datarate;
  798. }McpsReqConfirmed_t;
  799. /*!
  800. * LoRaMAC MCPS-Request for a proprietary frame
  801. */
  802. typedef struct sMcpsReqProprietary
  803. {
  804. /*!
  805. * Pointer to the buffer of the frame payload
  806. */
  807. void* fBuffer;
  808. /*!
  809. * Size of the frame payload
  810. */
  811. uint16_t fBufferSize;
  812. /*!
  813. * Uplink datarate, if ADR is off
  814. */
  815. int8_t Datarate;
  816. }McpsReqProprietary_t;
  817. /*!
  818. * LoRaMAC MCPS-Request structure
  819. */
  820. typedef struct sMcpsReq
  821. {
  822. /*!
  823. * MCPS-Request type
  824. */
  825. Mcps_t Type;
  826. /*!
  827. * MCPS-Request parameters
  828. */
  829. union uMcpsParam
  830. {
  831. /*!
  832. * MCPS-Request parameters for an unconfirmed frame
  833. */
  834. McpsReqUnconfirmed_t Unconfirmed;
  835. /*!
  836. * MCPS-Request parameters for a confirmed frame
  837. */
  838. McpsReqConfirmed_t Confirmed;
  839. /*!
  840. * MCPS-Request parameters for a proprietary frame
  841. */
  842. McpsReqProprietary_t Proprietary;
  843. }Req;
  844. /*!
  845. * MCPS-Request return parameters
  846. */
  847. RequestReturnParam_t ReqReturn;
  848. }McpsReq_t;
  849. /*!
  850. * LoRaMAC MCPS-Confirm
  851. */
  852. typedef struct sMcpsConfirm
  853. {
  854. /*!
  855. * Holds the previously performed MCPS-Request
  856. */
  857. Mcps_t McpsRequest;
  858. /*!
  859. * Status of the operation
  860. */
  861. LoRaMacEventInfoStatus_t Status;
  862. /*!
  863. * Uplink datarate
  864. */
  865. uint8_t Datarate;
  866. /*!
  867. * Transmission power
  868. */
  869. int8_t TxPower;
  870. /*!
  871. * Set if an acknowledgement was received
  872. */
  873. bool AckReceived;
  874. /*!
  875. * Provides the number of retransmissions
  876. */
  877. uint8_t NbTrans;
  878. /*!
  879. * The transmission time on air of the frame
  880. */
  881. TimerTime_t TxTimeOnAir;
  882. /*!
  883. * The uplink counter value related to the frame
  884. */
  885. uint32_t UpLinkCounter;
  886. /*!
  887. * The uplink channel related to the frame
  888. */
  889. uint32_t Channel;
  890. }McpsConfirm_t;
  891. /*!
  892. * LoRaMAC MCPS-Indication primitive
  893. */
  894. typedef struct sMcpsIndication
  895. {
  896. /*!
  897. * MCPS-Indication type
  898. */
  899. Mcps_t McpsIndication;
  900. /*!
  901. * Status of the operation
  902. */
  903. LoRaMacEventInfoStatus_t Status;
  904. /*!
  905. * Multicast
  906. */
  907. uint8_t Multicast;
  908. /*!
  909. * Application port
  910. */
  911. uint8_t Port;
  912. /*!
  913. * Downlink datarate
  914. */
  915. uint8_t RxDatarate;
  916. /*!
  917. * Frame pending status
  918. */
  919. uint8_t FramePending;
  920. /*!
  921. * Pointer to the received data stream
  922. */
  923. uint8_t* Buffer;
  924. /*!
  925. * Size of the received data stream
  926. */
  927. uint8_t BufferSize;
  928. /*!
  929. * Indicates, if data is available
  930. */
  931. bool RxData;
  932. /*!
  933. * Rssi of the received packet
  934. */
  935. int16_t Rssi;
  936. /*!
  937. * Snr of the received packet
  938. */
  939. int8_t Snr;
  940. /*!
  941. * Receive window
  942. */
  943. LoRaMacRxSlot_t RxSlot;
  944. /*!
  945. * Set if an acknowledgement was received
  946. */
  947. bool AckReceived;
  948. /*!
  949. * The downlink counter value for the received frame
  950. */
  951. uint32_t DownLinkCounter;
  952. /*!
  953. * The device address of the frame
  954. */
  955. uint32_t DevAddress;
  956. /*!
  957. * Set if a DeviceTimeAns MAC command was received.
  958. */
  959. bool DeviceTimeAnsReceived;
  960. /*!
  961. * Response timeout for a class b or c device when a
  962. * confirmed downlink has been received. In all other
  963. * cases this variable is 0.
  964. */
  965. TimerTime_t ResponseTimeout;
  966. }McpsIndication_t;
  967. /*!
  968. * \brief LoRaMAC management services
  969. *
  970. * \details The following table list the primitives which are supported by the
  971. * specific MAC management service:
  972. *
  973. * Name | Request | Indication | Response | Confirm
  974. * ---------------------------- | :-----: | :--------: | :------: | :-----:
  975. * \ref MLME_JOIN | YES | NO | NO | YES
  976. * \ref MLME_LINK_CHECK | YES | NO | NO | YES
  977. * \ref MLME_TXCW | YES | NO | NO | YES
  978. * \ref MLME_SCHEDULE_UPLINK | NO | YES | NO | NO
  979. * \ref MLME_DERIVE_MC_KE_KEY | YES | NO | NO | YES
  980. * \ref MLME_DERIVE_MC_KEY_PAIR | YES | NO | NO | YES
  981. *
  982. * The following table provides links to the function implementations of the
  983. * related MLME primitives.
  984. *
  985. * Primitive | Function
  986. * ---------------- | :---------------------:
  987. * MLME-Request | \ref LoRaMacMlmeRequest
  988. * MLME-Confirm | MacMlmeConfirm in \ref LoRaMacPrimitives_t
  989. * MLME-Indication | MacMlmeIndication in \ref LoRaMacPrimitives_t
  990. */
  991. typedef enum eMlme
  992. {
  993. /*!
  994. * An unknown MLME service
  995. */
  996. MLME_UNKNOWN,
  997. /*!
  998. * Initiates the Over-the-Air activation
  999. *
  1000. * LoRaWAN Specification V1.0.2, chapter 6.2
  1001. */
  1002. MLME_JOIN,
  1003. /*!
  1004. * Initiates sending a ReJoin-request type 0
  1005. *
  1006. * LoRaWAN Specification V1.1.0, chapter 6.2.4.1
  1007. */
  1008. MLME_REJOIN_0,
  1009. /*!
  1010. * Initiates sending a ReJoin-request type 1
  1011. *
  1012. * LoRaWAN Specification V1.1.0, chapter 6.2.4.2
  1013. */
  1014. MLME_REJOIN_1,
  1015. /*!
  1016. * LinkCheckReq - Connectivity validation
  1017. *
  1018. * LoRaWAN Specification V1.0.2, chapter 5, table 4
  1019. */
  1020. MLME_LINK_CHECK,
  1021. /*!
  1022. * Sets Tx continuous wave mode
  1023. *
  1024. * LoRaWAN end-device certification
  1025. */
  1026. MLME_TXCW,
  1027. /*!
  1028. * Indicates that the application shall perform an uplink as
  1029. * soon as possible.
  1030. */
  1031. MLME_SCHEDULE_UPLINK,
  1032. /*!
  1033. * Derives the McKEKey from the AppKey or NwkKey.
  1034. */
  1035. MLME_DERIVE_MC_KE_KEY,
  1036. /*!
  1037. * Derives a Multicast group key pair ( McAppSKey, McNwkSKey ) from McKey
  1038. */
  1039. MLME_DERIVE_MC_KEY_PAIR,
  1040. /*!
  1041. * Initiates a DeviceTimeReq
  1042. *
  1043. * LoRaWAN end-device certification
  1044. */
  1045. MLME_DEVICE_TIME,
  1046. /*!
  1047. * The MAC uses this MLME primitive to indicate a beacon reception
  1048. * status.
  1049. *
  1050. * LoRaWAN end-device certification
  1051. */
  1052. MLME_BEACON,
  1053. /*!
  1054. * Initiate a beacon acquisition. The MAC will search for a beacon.
  1055. * It will search for XX_BEACON_INTERVAL milliseconds.
  1056. *
  1057. * LoRaWAN end-device certification
  1058. */
  1059. MLME_BEACON_ACQUISITION,
  1060. /*!
  1061. * Initiates a PingSlotInfoReq
  1062. *
  1063. * LoRaWAN end-device certification
  1064. */
  1065. MLME_PING_SLOT_INFO,
  1066. /*!
  1067. * Initiates a BeaconTimingReq
  1068. *
  1069. * LoRaWAN end-device certification
  1070. */
  1071. MLME_BEACON_TIMING,
  1072. /*!
  1073. * Primitive which indicates that the beacon has been lost
  1074. *
  1075. * \remark The upper layer is required to switch the device class to ClassA
  1076. *
  1077. * LoRaWAN end-device certification
  1078. */
  1079. MLME_BEACON_LOST,
  1080. }Mlme_t;
  1081. /*!
  1082. * LoRaMAC MLME-Request for the join service
  1083. */
  1084. typedef struct sMlmeReqJoin
  1085. {
  1086. /*!
  1087. * LoRaWAN Network End-Device Activation ( ACTIVATION_TYPE_NONE, ACTIVATION_TYPE_ABP or OTTA )
  1088. *
  1089. * Related MIB type: \ref MIB_NETWORK_ACTIVATION
  1090. */
  1091. ActivationType_t NetworkActivation;
  1092. /*!
  1093. * Datarate used for join request.
  1094. */
  1095. uint8_t Datarate;
  1096. }MlmeReqJoin_t;
  1097. /*!
  1098. * LoRaMAC MLME-Request for Tx continuous wave mode
  1099. */
  1100. typedef struct sMlmeReqTxCw
  1101. {
  1102. /*!
  1103. * Time in seconds while the radio is kept in continuous wave mode
  1104. */
  1105. uint16_t Timeout;
  1106. /*!
  1107. * RF frequency to set (Only used with new way)
  1108. */
  1109. uint32_t Frequency;
  1110. /*!
  1111. * RF output power to set (Only used with new way)
  1112. */
  1113. int8_t Power;
  1114. }MlmeReqTxCw_t;
  1115. /*!
  1116. * LoRaMAC MLME-Request for the ping slot info service
  1117. */
  1118. typedef struct sMlmeReqPingSlotInfo
  1119. {
  1120. PingSlotInfo_t PingSlot;
  1121. }MlmeReqPingSlotInfo_t;
  1122. /*!
  1123. * LoRaMAC MLME-Request to derive the McKEKey from the AppKey or NwkKey
  1124. */
  1125. typedef struct sMlmeReqDeriveMcKEKey
  1126. {
  1127. /*!
  1128. * Key identifier of the root key to use to perform the derivation ( NwkKey or AppKey )
  1129. */
  1130. KeyIdentifier_t KeyID;
  1131. /*!
  1132. * Nonce value ( nonce <= 15)
  1133. */
  1134. uint16_t Nonce;
  1135. /*!
  1136. * DevEUI Value
  1137. */
  1138. uint8_t* DevEUI;
  1139. }MlmeReqDeriveMcKEKey_t;
  1140. /*!
  1141. * LoRaMAC MLME-Request to derive a Multicast group key pair ( McAppSKey, McNwkSKey ) from McKey
  1142. */
  1143. typedef struct sMlmeReqDeriveMcSessionKeyPair
  1144. {
  1145. /*!
  1146. * Address identifier to select the multicast group
  1147. */
  1148. AddressIdentifier_t GroupID;
  1149. }MlmeReqDeriveMcSessionKeyPair_t;
  1150. /*!
  1151. * LoRaMAC MLME-Request structure
  1152. */
  1153. typedef struct sMlmeReq
  1154. {
  1155. /*!
  1156. * MLME-Request type
  1157. */
  1158. Mlme_t Type;
  1159. /*!
  1160. * MLME-Request parameters
  1161. */
  1162. union uMlmeParam
  1163. {
  1164. /*!
  1165. * MLME-Request parameters for a join request
  1166. */
  1167. MlmeReqJoin_t Join;
  1168. /*!
  1169. * MLME-Request parameters for Tx continuous mode request
  1170. */
  1171. MlmeReqTxCw_t TxCw;
  1172. /*!
  1173. * MLME-Request parameters for a ping slot info request
  1174. */
  1175. MlmeReqPingSlotInfo_t PingSlotInfo;
  1176. /*!
  1177. * MLME-Request to derive the McKEKey from the AppKey or NwkKey
  1178. */
  1179. MlmeReqDeriveMcKEKey_t DeriveMcKEKey;
  1180. /*!
  1181. * MLME-Request to derive a Multicast group key pair ( McAppSKey, McNwkSKey ) from McKey
  1182. */
  1183. MlmeReqDeriveMcSessionKeyPair_t DeriveMcSessionKeyPair;
  1184. }Req;
  1185. /*!
  1186. * MLME-Request return parameters
  1187. */
  1188. RequestReturnParam_t ReqReturn;
  1189. }MlmeReq_t;
  1190. /*!
  1191. * LoRaMAC MLME-Confirm primitive
  1192. */
  1193. typedef struct sMlmeConfirm
  1194. {
  1195. /*!
  1196. * Holds the previously performed MLME-Request
  1197. */
  1198. Mlme_t MlmeRequest;
  1199. /*!
  1200. * Status of the operation
  1201. */
  1202. LoRaMacEventInfoStatus_t Status;
  1203. /*!
  1204. * The transmission time on air of the frame
  1205. */
  1206. TimerTime_t TxTimeOnAir;
  1207. /*!
  1208. * Demodulation margin. Contains the link margin [dB] of the last
  1209. * successfully received LinkCheckReq
  1210. */
  1211. uint8_t DemodMargin;
  1212. /*!
  1213. * Number of gateways which received the last LinkCheckReq
  1214. */
  1215. uint8_t NbGateways;
  1216. /*!
  1217. * Provides the number of retransmissions
  1218. */
  1219. uint8_t NbRetries;
  1220. /*!
  1221. * The delay which we have received through the
  1222. * BeaconTimingAns
  1223. */
  1224. TimerTime_t BeaconTimingDelay;
  1225. /*!
  1226. * The channel of the next beacon
  1227. */
  1228. uint8_t BeaconTimingChannel;
  1229. }MlmeConfirm_t;
  1230. /*!
  1231. * LoRaMAC MLME-Indication primitive
  1232. */
  1233. typedef struct sMlmeIndication
  1234. {
  1235. /*!
  1236. * MLME-Indication type
  1237. */
  1238. Mlme_t MlmeIndication;
  1239. /*!
  1240. * Status of the operation
  1241. */
  1242. LoRaMacEventInfoStatus_t Status;
  1243. /*!
  1244. * Beacon information. Only valid for \ref MLME_BEACON,
  1245. * status \ref LORAMAC_EVENT_INFO_STATUS_BEACON_LOCKED
  1246. */
  1247. BeaconInfo_t BeaconInfo;
  1248. }MlmeIndication_t;
  1249. /*!
  1250. * LoRa Mac Information Base (MIB)
  1251. *
  1252. * The following table lists the MIB parameters and the related attributes:
  1253. *
  1254. * Attribute | Get | Set
  1255. * ----------------------------------------------| :-: | :-:
  1256. * \ref MIB_DEVICE_CLASS | YES | YES
  1257. * \ref MIB_NETWORK_ACTIVATION | YES | YES
  1258. * \ref MIB_DEV_EUI | YES | YES
  1259. * \ref MIB_JOIN_EUI | YES | YES
  1260. * \ref MIB_SE_PIN | YES | YES
  1261. * \ref MIB_ADR | YES | YES
  1262. * \ref MIB_NET_ID | YES | YES
  1263. * \ref MIB_DEV_ADDR | YES | YES
  1264. * \ref MIB_APP_KEY | NO | YES
  1265. * \ref MIB_NWK_KEY | NO | YES
  1266. * \ref MIB_J_S_INT_KEY | NO | YES
  1267. * \ref MIB_J_S_ENC_KEY | NO | YES
  1268. * \ref MIB_F_NWK_S_INT_KEY | NO | YES
  1269. * \ref MIB_S_NWK_S_INT_KEY | NO | YES
  1270. * \ref MIB_NWK_S_ENC_KEY | NO | YES
  1271. * \ref MIB_APP_S_KEY | NO | YES
  1272. * \ref MIB_MC_KE_KEY | NO | YES
  1273. * \ref MIB_MC_KEY_0 | NO | YES
  1274. * \ref MIB_MC_APP_S_KEY_0 | NO | YES
  1275. * \ref MIB_MC_NWK_S_KEY_0 | NO | YES
  1276. * \ref MIB_MC_KEY_1 | NO | YES
  1277. * \ref MIB_MC_APP_S_KEY_1 | NO | YES
  1278. * \ref MIB_MC_NWK_S_KEY_1 | NO | YES
  1279. * \ref MIB_MC_KEY_2 | NO | YES
  1280. * \ref MIB_MC_APP_S_KEY_2 | NO | YES
  1281. * \ref MIB_MC_NWK_S_KEY_2 | NO | YES
  1282. * \ref MIB_MC_KEY_3 | NO | YES
  1283. * \ref MIB_MC_APP_S_KEY_3 | NO | YES
  1284. * \ref MIB_MC_NWK_S_KEY_3 | NO | YES
  1285. * \ref MIB_PUBLIC_NETWORK | YES | YES
  1286. * \ref MIB_CHANNELS | YES | NO
  1287. * \ref MIB_RX2_CHANNEL | YES | YES
  1288. * \ref MIB_RX2_DFAULT_CHANNEL | YES | YES
  1289. * \ref MIB_RXC_CHANNEL | YES | YES
  1290. * \ref MIB_RXC_DFAULT_CHANNEL | YES | YES
  1291. * \ref MIB_CHANNELS_MASK | YES | YES
  1292. * \ref MIB_CHANNELS_DEFAULT_MASK | YES | YES
  1293. * \ref MIB_CHANNELS_NB_TRANS | YES | YES
  1294. * \ref MIB_MAX_RX_WINDOW_DURATION | YES | YES
  1295. * \ref MIB_RECEIVE_DELAY_1 | YES | YES
  1296. * \ref MIB_RECEIVE_DELAY_2 | YES | YES
  1297. * \ref MIB_JOIN_ACCEPT_DELAY_1 | YES | YES
  1298. * \ref MIB_JOIN_ACCEPT_DELAY_2 | YES | YES
  1299. * \ref MIB_CHANNELS_DATARATE | YES | YES
  1300. * \ref MIB_CHANNELS_MIN_TX_DATARATE | YES | NO
  1301. * \ref MIB_CHANNELS_DEFAULT_DATARATE | YES | YES
  1302. * \ref MIB_CHANNELS_TX_POWER | YES | YES
  1303. * \ref MIB_CHANNELS_DEFAULT_TX_POWER | YES | YES
  1304. * \ref MIB_SYSTEM_MAX_RX_ERROR | YES | YES
  1305. * \ref MIB_MIN_RX_SYMBOLS | YES | YES
  1306. * \ref MIB_BEACON_INTERVAL | YES | YES
  1307. * \ref MIB_BEACON_RESERVED | YES | YES
  1308. * \ref MIB_BEACON_GUARD | YES | YES
  1309. * \ref MIB_BEACON_WINDOW | YES | YES
  1310. * \ref MIB_BEACON_WINDOW_SLOTS | YES | YES
  1311. * \ref MIB_PING_SLOT_WINDOW | YES | YES
  1312. * \ref MIB_BEACON_SYMBOL_TO_DEFAULT | YES | YES
  1313. * \ref MIB_BEACON_SYMBOL_TO_EXPANSION_MAX | YES | YES
  1314. * \ref MIB_PING_SLOT_SYMBOL_TO_EXPANSION_MAX | YES | YES
  1315. * \ref MIB_BEACON_SYMBOL_TO_EXPANSION_FACTOR | YES | YES
  1316. * \ref MIB_PING_SLOT_SYMBOL_TO_EXPANSION_FACTOR | YES | YES
  1317. * \ref MIB_MAX_BEACON_LESS_PERIOD | YES | YES
  1318. * \ref MIB_ANTENNA_GAIN | YES | YES
  1319. * \ref MIB_DEFAULT_ANTENNA_GAIN | YES | YES
  1320. * \ref MIB_NVM_CTXS | YES | YES
  1321. * \ref MIB_ABP_LORAWAN_VERSION | NO | YES
  1322. * \ref MIB_LORAWAN_VERSION | YES | NO
  1323. * \ref MIB_IS_CERT_FPORT_ON | YES | YES
  1324. *
  1325. * The following table provides links to the function implementations of the
  1326. * related MIB primitives:
  1327. *
  1328. * Primitive | Function
  1329. * ---------------- | :---------------------:
  1330. * MIB-Set | \ref LoRaMacMibSetRequestConfirm
  1331. * MIB-Get | \ref LoRaMacMibGetRequestConfirm
  1332. */
  1333. typedef enum eMib
  1334. {
  1335. /*!
  1336. * LoRaWAN device class
  1337. *
  1338. * LoRaWAN Specification V1.0.2
  1339. */
  1340. MIB_DEVICE_CLASS,
  1341. /*!
  1342. * LoRaWAN Network End-Device Activation
  1343. *
  1344. * LoRaWAN Specification V1.0.2
  1345. */
  1346. MIB_NETWORK_ACTIVATION,
  1347. /*!
  1348. * LoRaWAN device EUI
  1349. *
  1350. * LoRaWAN Specification V1.0.2
  1351. */
  1352. MIB_DEV_EUI,
  1353. /*!
  1354. * LoRaWAN join EUI
  1355. *
  1356. * LoRaWAN Specification V1.0.2
  1357. */
  1358. MIB_JOIN_EUI,
  1359. /*!
  1360. * Secure-element pin
  1361. */
  1362. MIB_SE_PIN,
  1363. /*!
  1364. * Adaptive data rate
  1365. *
  1366. * LoRaWAN Specification V1.0.2, chapter 4.3.1.1
  1367. *
  1368. * [true: ADR enabled, false: ADR disabled]
  1369. */
  1370. MIB_ADR,
  1371. /*!
  1372. * Network identifier
  1373. *
  1374. * LoRaWAN Specification V1.0.2, chapter 6.1.1
  1375. */
  1376. MIB_NET_ID,
  1377. /*!
  1378. * End-device address
  1379. *
  1380. * LoRaWAN Specification V1.0.2, chapter 6.1.1
  1381. */
  1382. MIB_DEV_ADDR,
  1383. /*!
  1384. * Application root key
  1385. *
  1386. * LoRaWAN Specification V1.1.0, chapter 6.1.1.3
  1387. */
  1388. MIB_APP_KEY,
  1389. /*!
  1390. * Network root key
  1391. *
  1392. * LoRaWAN Specification V1.1.0, chapter 6.1.1.3
  1393. */
  1394. MIB_NWK_KEY,
  1395. /*!
  1396. * Join session integrity key
  1397. *
  1398. * LoRaWAN Specification V1.1.0, chapter 6.1.1.4
  1399. */
  1400. MIB_J_S_INT_KEY,
  1401. /*!
  1402. * Join session encryption key
  1403. *
  1404. * LoRaWAN Specification V1.1.0, chapter 6.1.1.4
  1405. */
  1406. MIB_J_S_ENC_KEY,
  1407. /*!
  1408. * Forwarding Network session integrity key
  1409. *
  1410. * LoRaWAN Specification V1.1.0, chapter 6.1.2.2
  1411. */
  1412. MIB_F_NWK_S_INT_KEY,
  1413. /*!
  1414. * Serving Network session integrity key
  1415. *
  1416. * LoRaWAN Specification V1.1.0, chapter 6.1.2.3
  1417. */
  1418. MIB_S_NWK_S_INT_KEY,
  1419. /*!
  1420. * Network session encryption key
  1421. *
  1422. * LoRaWAN Specification V1.1.0, chapter 6.1.2.4
  1423. */
  1424. MIB_NWK_S_ENC_KEY,
  1425. /*!
  1426. * Application session key
  1427. *
  1428. * LoRaWAN Specification V1.1.0, chapter 6.1.1.3
  1429. */
  1430. MIB_APP_S_KEY,
  1431. /*!
  1432. * Multicast key encryption key
  1433. *
  1434. * LoRaWAN - Secure element specification v1
  1435. */
  1436. MIB_MC_KE_KEY,
  1437. /*!
  1438. * Multicast root key index 0
  1439. *
  1440. * LoRaWAN - Secure element specification v1
  1441. */
  1442. MIB_MC_KEY_0,
  1443. /*!
  1444. * Multicast Application session key index 0
  1445. *
  1446. * LoRaWAN - Secure element specification v1
  1447. */
  1448. MIB_MC_APP_S_KEY_0,
  1449. /*!
  1450. * Multicast Network session key index 0
  1451. *
  1452. * LoRaWAN - Secure element specification v1
  1453. */
  1454. MIB_MC_NWK_S_KEY_0,
  1455. /*!
  1456. * Multicast root key index 1
  1457. *
  1458. * LoRaWAN - Secure element specification v1
  1459. */
  1460. MIB_MC_KEY_1,
  1461. /*!
  1462. * Multicast Application session key index 1
  1463. *
  1464. * LoRaWAN - Secure element specification v1
  1465. */
  1466. MIB_MC_APP_S_KEY_1,
  1467. /*!
  1468. * Multicast Network session key index 1
  1469. *
  1470. * LoRaWAN - Secure element specification v1
  1471. */
  1472. MIB_MC_NWK_S_KEY_1,
  1473. /*!
  1474. * Multicast root key index 2
  1475. *
  1476. * LoRaWAN - Secure element specification v1
  1477. */
  1478. MIB_MC_KEY_2,
  1479. /*!
  1480. * Multicast Application session key index 2
  1481. *
  1482. * LoRaWAN - Secure element specification v1
  1483. */
  1484. MIB_MC_APP_S_KEY_2,
  1485. /*!
  1486. * Multicast Network session key index 2
  1487. *
  1488. * LoRaWAN - Secure element specification v1
  1489. */
  1490. MIB_MC_NWK_S_KEY_2,
  1491. /*!
  1492. * Multicast root key index 3
  1493. *
  1494. * LoRaWAN - Secure element specification v1
  1495. */
  1496. MIB_MC_KEY_3,
  1497. /*!
  1498. * Multicast Application session key index 3
  1499. *
  1500. * LoRaWAN - Secure element specification v1
  1501. */
  1502. MIB_MC_APP_S_KEY_3,
  1503. /*!
  1504. * Multicast Network session key index 3
  1505. *
  1506. * LoRaWAN - Secure element specification v1
  1507. */
  1508. MIB_MC_NWK_S_KEY_3,
  1509. /*!
  1510. * Set the network type to public or private
  1511. *
  1512. * LoRaWAN Regional Parameters V1.0.2rB
  1513. *
  1514. * [true: public network, false: private network]
  1515. */
  1516. MIB_PUBLIC_NETWORK,
  1517. /*!
  1518. * Communication channels. A get request will return a
  1519. * pointer which references the first entry of the channel list. The
  1520. * list is of size LORA_MAX_NB_CHANNELS
  1521. *
  1522. * LoRaWAN Regional Parameters V1.0.2rB
  1523. */
  1524. MIB_CHANNELS,
  1525. /*!
  1526. * Set receive window 2 channel
  1527. *
  1528. * LoRaWAN Specification V1.0.2, chapter 3.3.1
  1529. */
  1530. MIB_RX2_CHANNEL,
  1531. /*!
  1532. * Set receive window 2 channel
  1533. *
  1534. * LoRaWAN Specification V1.0.2, chapter 3.3.2
  1535. */
  1536. MIB_RX2_DEFAULT_CHANNEL,
  1537. /*!
  1538. * Set receive window C channel
  1539. *
  1540. * LoRaWAN Specification V1.0.2, chapter 3.3.1
  1541. */
  1542. MIB_RXC_CHANNEL,
  1543. /*!
  1544. * Set receive window C channel
  1545. *
  1546. * LoRaWAN Specification V1.0.2, chapter 3.3.2
  1547. */
  1548. MIB_RXC_DEFAULT_CHANNEL,
  1549. /*!
  1550. * LoRaWAN channels mask
  1551. *
  1552. * LoRaWAN Regional Parameters V1.0.2rB
  1553. */
  1554. MIB_CHANNELS_MASK,
  1555. /*!
  1556. * LoRaWAN default channels mask
  1557. *
  1558. * LoRaWAN Regional Parameters V1.0.2rB
  1559. */
  1560. MIB_CHANNELS_DEFAULT_MASK,
  1561. /*!
  1562. * Set the number of repetitions on a channel
  1563. *
  1564. * LoRaWAN Specification V1.0.2, chapter 5.2
  1565. */
  1566. MIB_CHANNELS_NB_TRANS,
  1567. /*!
  1568. * Maximum receive window duration in [ms]
  1569. *
  1570. * LoRaWAN Specification V1.0.2, chapter 3.3.3
  1571. */
  1572. MIB_MAX_RX_WINDOW_DURATION,
  1573. /*!
  1574. * Receive delay 1 in [ms]
  1575. *
  1576. * LoRaWAN Regional Parameters V1.0.2rB
  1577. */
  1578. MIB_RECEIVE_DELAY_1,
  1579. /*!
  1580. * Receive delay 2 in [ms]
  1581. *
  1582. * LoRaWAN Regional Parameters V1.0.2rB
  1583. */
  1584. MIB_RECEIVE_DELAY_2,
  1585. /*!
  1586. * Join accept delay 1 in [ms]
  1587. *
  1588. * LoRaWAN Regional Parameters V1.0.2rB
  1589. */
  1590. MIB_JOIN_ACCEPT_DELAY_1,
  1591. /*!
  1592. * Join accept delay 2 in [ms]
  1593. *
  1594. * LoRaWAN Regional Parameters V1.0.2rB
  1595. */
  1596. MIB_JOIN_ACCEPT_DELAY_2,
  1597. /*!
  1598. * Minimum Data rate of a channel
  1599. *
  1600. * LoRaWAN Regional Parameters V1.0.2rB
  1601. *
  1602. * The possible values are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
  1603. */
  1604. MIB_CHANNELS_MIN_TX_DATARATE,
  1605. /*!
  1606. * Default Data rate of a channel
  1607. *
  1608. * LoRaWAN Regional Parameters V1.0.2rB
  1609. *
  1610. * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
  1611. */
  1612. MIB_CHANNELS_DEFAULT_DATARATE,
  1613. /*!
  1614. * Data rate of a channel
  1615. *
  1616. * LoRaWAN Regional Parameters V1.0.2rB
  1617. *
  1618. * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
  1619. */
  1620. MIB_CHANNELS_DATARATE,
  1621. /*!
  1622. * Transmission power of a channel
  1623. *
  1624. * LoRaWAN Regional Parameters V1.0.2rB
  1625. *
  1626. * The allowed ranges are region specific. Please refer to \ref TX_POWER_0 to \ref TX_POWER_15 for details.
  1627. */
  1628. MIB_CHANNELS_TX_POWER,
  1629. /*!
  1630. * Transmission power of a channel
  1631. *
  1632. * LoRaWAN Regional Parameters V1.0.2rB
  1633. *
  1634. * The allowed ranges are region specific. Please refer to \ref TX_POWER_0 to \ref TX_POWER_15 for details.
  1635. */
  1636. MIB_CHANNELS_DEFAULT_TX_POWER,
  1637. /*!
  1638. * System overall timing error in milliseconds.
  1639. * [-SystemMaxRxError : +SystemMaxRxError]
  1640. * Default: +/-10 ms
  1641. */
  1642. MIB_SYSTEM_MAX_RX_ERROR,
  1643. /*!
  1644. * Minimum required number of symbols to detect an Rx frame
  1645. * Default: 6 symbols
  1646. */
  1647. MIB_MIN_RX_SYMBOLS,
  1648. /*!
  1649. * Antenna gain of the node. Default value is region specific.
  1650. * The antenna gain is used to calculate the TX power of the node.
  1651. * The formula is:
  1652. * radioTxPower = ( int8_t )floor( maxEirp - antennaGain )
  1653. *
  1654. * \remark The antenna gain value is referenced to the isotropic antenna.
  1655. * The value is in dBi.
  1656. * MIB_ANTENNA_GAIN[dBi] = measuredAntennaGain[dBd] + 2.15
  1657. */
  1658. MIB_ANTENNA_GAIN,
  1659. /*!
  1660. * Default antenna gain of the node. Default value is region specific.
  1661. * The antenna gain is used to calculate the TX power of the node.
  1662. * The formula is:
  1663. * radioTxPower = ( int8_t )floor( maxEirp - antennaGain )
  1664. *
  1665. * \remark The antenna gain value is referenced to the isotropic antenna.
  1666. * The value is in dBi.
  1667. * MIB_DEFAULT_ANTENNA_GAIN[dBi] = measuredAntennaGain[dBd] + 2.15
  1668. */
  1669. MIB_DEFAULT_ANTENNA_GAIN,
  1670. /*!
  1671. * Structure holding pointers to internal contexts and its size
  1672. */
  1673. MIB_NVM_CTXS,
  1674. /*!
  1675. * LoRaWAN MAC layer operating version when activated by ABP.
  1676. */
  1677. MIB_ABP_LORAWAN_VERSION,
  1678. /*!
  1679. * LoRaWAN MAC and regional parameter version.
  1680. */
  1681. MIB_LORAWAN_VERSION,
  1682. /*!
  1683. * Beacon interval in ms
  1684. */
  1685. MIB_BEACON_INTERVAL,
  1686. /*!
  1687. * Beacon reserved time in ms
  1688. */
  1689. MIB_BEACON_RESERVED,
  1690. /*!
  1691. * Beacon guard time in ms
  1692. */
  1693. MIB_BEACON_GUARD,
  1694. /*!
  1695. * Beacon window time in ms
  1696. */
  1697. MIB_BEACON_WINDOW,
  1698. /*!
  1699. * Beacon window time in number of slots
  1700. */
  1701. MIB_BEACON_WINDOW_SLOTS,
  1702. /*!
  1703. * Ping slot length time in ms
  1704. */
  1705. MIB_PING_SLOT_WINDOW,
  1706. /*!
  1707. * Default symbol timeout for beacons and ping slot windows
  1708. */
  1709. MIB_BEACON_SYMBOL_TO_DEFAULT,
  1710. /*!
  1711. * Maximum symbol timeout for beacons
  1712. */
  1713. MIB_BEACON_SYMBOL_TO_EXPANSION_MAX,
  1714. /*!
  1715. * Maximum symbol timeout for ping slots
  1716. */
  1717. MIB_PING_SLOT_SYMBOL_TO_EXPANSION_MAX,
  1718. /*!
  1719. * Symbol expansion value for beacon windows in case of beacon
  1720. * loss in symbols
  1721. */
  1722. MIB_BEACON_SYMBOL_TO_EXPANSION_FACTOR,
  1723. /*!
  1724. * Symbol expansion value for ping slot windows in case of beacon
  1725. * loss in symbols
  1726. */
  1727. MIB_PING_SLOT_SYMBOL_TO_EXPANSION_FACTOR,
  1728. /*!
  1729. * Maximum allowed beacon less time in ms
  1730. */
  1731. MIB_MAX_BEACON_LESS_PERIOD,
  1732. /*!
  1733. * Ping slot data rate
  1734. *
  1735. * LoRaWAN Regional Parameters V1.0.2rB
  1736. *
  1737. * The allowed ranges are region specific. Please refer to \ref DR_0 to \ref DR_15 for details.
  1738. */
  1739. MIB_PING_SLOT_DATARATE,
  1740. /*!
  1741. * LoRaWAN certification FPort handling state (ON/OFF)
  1742. */
  1743. MIB_IS_CERT_FPORT_ON,
  1744. }Mib_t;
  1745. /*!
  1746. * LoRaMAC MIB parameters
  1747. */
  1748. typedef union uMibParam
  1749. {
  1750. /*!
  1751. * LoRaWAN device class
  1752. *
  1753. * Related MIB type: \ref MIB_DEVICE_CLASS
  1754. */
  1755. DeviceClass_t Class;
  1756. /*!
  1757. * LoRaWAN Network End-Device Activation ( ACTIVATION_TYPE_NONE, ACTIVATION_TYPE_ABP or OTTA )
  1758. *
  1759. * Related MIB type: \ref MIB_NETWORK_ACTIVATION
  1760. */
  1761. ActivationType_t NetworkActivation;
  1762. /*!
  1763. * LoRaWAN device EUI
  1764. *
  1765. * Related MIB type: \ref MIB_DEV_EUI
  1766. */
  1767. uint8_t* DevEui;
  1768. /*!
  1769. * LoRaWAN Join server EUI
  1770. *
  1771. * Related MIB type: \ref MIB_JOIN_EUI
  1772. */
  1773. uint8_t* JoinEui;
  1774. /*!
  1775. * Secure-element pin
  1776. *
  1777. * Related MIB type: \ref MIB_SE_PIN
  1778. */
  1779. uint8_t* SePin;
  1780. /*!
  1781. * Activation state of ADR
  1782. *
  1783. * Related MIB type: \ref MIB_ADR
  1784. */
  1785. bool AdrEnable;
  1786. /*!
  1787. * Network identifier
  1788. *
  1789. * Related MIB type: \ref MIB_NET_ID
  1790. */
  1791. uint32_t NetID;
  1792. /*!
  1793. * End-device address
  1794. *
  1795. * Related MIB type: \ref MIB_DEV_ADDR
  1796. */
  1797. uint32_t DevAddr;
  1798. /*!
  1799. * Application root key
  1800. *
  1801. * Related MIB type: \ref MIB_APP_KEY
  1802. */
  1803. uint8_t* AppKey;
  1804. /*!
  1805. * Network root key
  1806. *
  1807. * Related MIB type: \ref MIB_NWK_KEY
  1808. */
  1809. uint8_t* NwkKey;
  1810. /*!
  1811. * Join session integrity key
  1812. *
  1813. * Related MIB type: \ref MIB_J_S_INT_KEY
  1814. */
  1815. uint8_t* JSIntKey;
  1816. /*!
  1817. * Join session encryption key
  1818. *
  1819. * Related MIB type: \ref MIB_J_S_ENC_KEY
  1820. */
  1821. uint8_t* JSEncKey;
  1822. /*!
  1823. * Forwarding Network session integrity key
  1824. *
  1825. * Related MIB type: \ref MIB_F_NWK_S_INT_KEY
  1826. */
  1827. uint8_t* FNwkSIntKey;
  1828. /*!
  1829. * Serving Network session integrity key
  1830. *
  1831. * Related MIB type: \ref MIB_S_NWK_S_INT_KEY
  1832. */
  1833. uint8_t* SNwkSIntKey;
  1834. /*!
  1835. * Network session encryption key
  1836. *
  1837. * Related MIB type: \ref MIB_NWK_S_ENC_KEY
  1838. */
  1839. uint8_t* NwkSEncKey;
  1840. /*!
  1841. * Application session key
  1842. *
  1843. * Related MIB type: \ref MIB_APP_S_KEY
  1844. */
  1845. uint8_t* AppSKey;
  1846. /*!
  1847. * Multicast key encryption key
  1848. *
  1849. * Related MIB type: \ref MIB_MC_KE_KEY
  1850. */
  1851. uint8_t* McKEKey;
  1852. /*!
  1853. * Multicast root key index 0
  1854. *
  1855. * Related MIB type: \ref MIB_MC_KEY_0
  1856. */
  1857. uint8_t* McKey0;
  1858. /*!
  1859. * Multicast Application session key index 0
  1860. *
  1861. * Related MIB type: \ref MIB_MC_APP_S_KEY_0
  1862. */
  1863. uint8_t* McAppSKey0;
  1864. /*!
  1865. * Multicast Network session key index 0
  1866. *
  1867. * Related MIB type: \ref MIB_MC_NWK_S_KEY_0
  1868. */
  1869. uint8_t* McNwkSKey0;
  1870. /*!
  1871. * Multicast root key index 0
  1872. *
  1873. * Related MIB type: \ref MIB_MC_KEY_0
  1874. */
  1875. uint8_t* McKey1;
  1876. /*!
  1877. * Multicast Application session key index 1
  1878. *
  1879. * Related MIB type: \ref MIB_MC_APP_S_KEY_1
  1880. */
  1881. uint8_t* McAppSKey1;
  1882. /*!
  1883. * Multicast Network session key index 1
  1884. *
  1885. * Related MIB type: \ref MIB_MC_NWK_S_KEY_1
  1886. */
  1887. uint8_t* McNwkSKey1;
  1888. /*!
  1889. * Multicast root key index 2
  1890. *
  1891. * Related MIB type: \ref MIB_MC_KEY_2
  1892. */
  1893. uint8_t* McKey2;
  1894. /*!
  1895. * Multicast Application session key index 2
  1896. *
  1897. * Related MIB type: \ref MIB_MC_APP_S_KEY_2
  1898. */
  1899. uint8_t* McAppSKey2;
  1900. /*!
  1901. * Multicast Network session key index 2
  1902. *
  1903. * Related MIB type: \ref MIB_MC_NWK_S_KEY_2
  1904. */
  1905. uint8_t* McNwkSKey2;
  1906. /*!
  1907. * Multicast root key index 2
  1908. *
  1909. * Related MIB type: \ref MIB_MC_KEY_2
  1910. */
  1911. uint8_t* McKey3;
  1912. /*!
  1913. * Multicast Application session key index 2
  1914. *
  1915. * Related MIB type: \ref MIB_MC_APP_S_KEY_2
  1916. */
  1917. uint8_t* McAppSKey3;
  1918. /*!
  1919. * Multicast Network session key index 2
  1920. *
  1921. * Related MIB type: \ref MIB_MC_NWK_S_KEY_2
  1922. */
  1923. uint8_t* McNwkSKey3;
  1924. /*!
  1925. * Enable or disable a public network
  1926. *
  1927. * Related MIB type: \ref MIB_PUBLIC_NETWORK
  1928. */
  1929. bool EnablePublicNetwork;
  1930. /*!
  1931. * LoRaWAN Channel
  1932. *
  1933. * Related MIB type: \ref MIB_CHANNELS
  1934. */
  1935. ChannelParams_t* ChannelList;
  1936. /*!
  1937. * Channel for the receive window 2
  1938. *
  1939. * Related MIB type: \ref MIB_RX2_CHANNEL
  1940. */
  1941. RxChannelParams_t Rx2Channel;
  1942. /*!
  1943. * Channel for the receive window 2
  1944. *
  1945. * Related MIB type: \ref MIB_RX2_DEFAULT_CHANNEL
  1946. */
  1947. RxChannelParams_t Rx2DefaultChannel;
  1948. /*!
  1949. * Channel for the receive window C
  1950. *
  1951. * Related MIB type: \ref MIB_RXC_CHANNEL
  1952. */
  1953. RxChannelParams_t RxCChannel;
  1954. /*!
  1955. * Channel for the receive window C
  1956. *
  1957. * Related MIB type: \ref MIB_RXC_DEFAULT_CHANNEL
  1958. */
  1959. RxChannelParams_t RxCDefaultChannel;
  1960. /*!
  1961. * Channel mask
  1962. *
  1963. * Related MIB type: \ref MIB_CHANNELS_MASK
  1964. */
  1965. uint16_t* ChannelsMask;
  1966. /*!
  1967. * Default channel mask
  1968. *
  1969. * Related MIB type: \ref MIB_CHANNELS_DEFAULT_MASK
  1970. */
  1971. uint16_t* ChannelsDefaultMask;
  1972. /*!
  1973. * Number of frame repetitions
  1974. *
  1975. * Related MIB type: \ref MIB_CHANNELS_NB_TRANS
  1976. */
  1977. uint8_t ChannelsNbTrans;
  1978. /*!
  1979. * Maximum receive window duration
  1980. *
  1981. * Related MIB type: \ref MIB_MAX_RX_WINDOW_DURATION
  1982. */
  1983. uint32_t MaxRxWindow;
  1984. /*!
  1985. * Receive delay 1
  1986. *
  1987. * Related MIB type: \ref MIB_RECEIVE_DELAY_1
  1988. */
  1989. uint32_t ReceiveDelay1;
  1990. /*!
  1991. * Receive delay 2
  1992. *
  1993. * Related MIB type: \ref MIB_RECEIVE_DELAY_2
  1994. */
  1995. uint32_t ReceiveDelay2;
  1996. /*!
  1997. * Join accept delay 1
  1998. *
  1999. * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_1
  2000. */
  2001. uint32_t JoinAcceptDelay1;
  2002. /*!
  2003. * Join accept delay 2
  2004. *
  2005. * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_2
  2006. */
  2007. uint32_t JoinAcceptDelay2;
  2008. /*!
  2009. * Channels minimum tx data rate
  2010. *
  2011. * Related MIB type: \ref MIB_CHANNELS_MIN_TX_DATARATE
  2012. */
  2013. int8_t ChannelsMinTxDatarate;
  2014. /*!
  2015. * Channels data rate
  2016. *
  2017. * Related MIB type: \ref MIB_CHANNELS_DEFAULT_DATARATE
  2018. */
  2019. int8_t ChannelsDefaultDatarate;
  2020. /*!
  2021. * Channels data rate
  2022. *
  2023. * Related MIB type: \ref MIB_CHANNELS_DATARATE
  2024. */
  2025. int8_t ChannelsDatarate;
  2026. /*!
  2027. * Channels TX power
  2028. *
  2029. * Related MIB type: \ref MIB_CHANNELS_DEFAULT_TX_POWER
  2030. */
  2031. int8_t ChannelsDefaultTxPower;
  2032. /*!
  2033. * Channels TX power
  2034. *
  2035. * Related MIB type: \ref MIB_CHANNELS_TX_POWER
  2036. */
  2037. int8_t ChannelsTxPower;
  2038. /*!
  2039. * Multicast channels
  2040. *
  2041. * Related MIB type: \ref MIB_MULTICAST_CHANNEL
  2042. */
  2043. McChannelParams_t MulticastChannel;
  2044. /*!
  2045. * System overall timing error in milliseconds.
  2046. *
  2047. * Related MIB type: \ref MIB_SYSTEM_MAX_RX_ERROR
  2048. */
  2049. uint32_t SystemMaxRxError;
  2050. /*!
  2051. * Minimum required number of symbols to detect an Rx frame
  2052. *
  2053. * Related MIB type: \ref MIB_MIN_RX_SYMBOLS
  2054. */
  2055. uint8_t MinRxSymbols;
  2056. /*!
  2057. * Antenna gain
  2058. *
  2059. * Related MIB type: \ref MIB_ANTENNA_GAIN
  2060. */
  2061. float AntennaGain;
  2062. /*!
  2063. * Default antenna gain
  2064. *
  2065. * Related MIB type: \ref MIB_DEFAULT_ANTENNA_GAIN
  2066. */
  2067. float DefaultAntennaGain;
  2068. /*!
  2069. * Returns a pointer to the structure holding all data which shall be stored
  2070. * in the NVM.
  2071. *
  2072. * Related MIB type: \ref MIB_NVM_CTXS
  2073. */
  2074. LoRaMacNvmData_t* Contexts;
  2075. /*
  2076. * LoRaWAN MAC layer operating version when activated by ABP.
  2077. *
  2078. * Related MIB type: \ref MIB_ABP_LORAWAN_VERSION
  2079. */
  2080. Version_t AbpLrWanVersion;
  2081. /*
  2082. * LoRaWAN MAC regional parameter version.
  2083. *
  2084. * Related MIB type: \ref MIB_LORAWAN_VERSION
  2085. */
  2086. struct sLrWanVersion
  2087. {
  2088. Version_t LoRaWan;
  2089. Version_t LoRaWanRegion;
  2090. }LrWanVersion;
  2091. /*!
  2092. * Beacon interval in ms
  2093. *
  2094. * Related MIB type: \ref MIB_BEACON_INTERVAL
  2095. */
  2096. uint32_t BeaconInterval;
  2097. /*!
  2098. * Beacon reserved time in ms
  2099. *
  2100. * Related MIB type: \ref MIB_BEACON_RESERVED
  2101. */
  2102. uint32_t BeaconReserved;
  2103. /*!
  2104. * Beacon guard time in ms
  2105. *
  2106. * Related MIB type: \ref MIB_BEACON_GUARD
  2107. */
  2108. uint32_t BeaconGuard;
  2109. /*!
  2110. * Beacon window time in ms
  2111. *
  2112. * Related MIB type: \ref MIB_BEACON_WINDOW
  2113. */
  2114. uint32_t BeaconWindow;
  2115. /*!
  2116. * Beacon window time in number of slots
  2117. *
  2118. * Related MIB type: \ref MIB_BEACON_WINDOW_SLOTS
  2119. */
  2120. uint32_t BeaconWindowSlots;
  2121. /*!
  2122. * Ping slot length time in ms
  2123. *
  2124. * Related MIB type: \ref MIB_PING_SLOT_WINDOW
  2125. */
  2126. uint32_t PingSlotWindow;
  2127. /*!
  2128. * Default symbol timeout for beacons and ping slot windows
  2129. *
  2130. * Related MIB type: \ref MIB_BEACON_SYMBOL_TO_DEFAULT
  2131. */
  2132. uint32_t BeaconSymbolToDefault;
  2133. /*!
  2134. * Maximum symbol timeout for beacons
  2135. *
  2136. * Related MIB type: \ref MIB_BEACON_SYMBOL_TO_EXPANSION_MAX
  2137. */
  2138. uint32_t BeaconSymbolToExpansionMax;
  2139. /*!
  2140. * Maximum symbol timeout for ping slots
  2141. *
  2142. * Related MIB type: \ref MIB_PING_SLOT_SYMBOL_TO_EXPANSION_MAX
  2143. */
  2144. uint32_t PingSlotSymbolToExpansionMax;
  2145. /*!
  2146. * Symbol expansion value for beacon windows in case of beacon
  2147. * loss in symbols
  2148. *
  2149. * Related MIB type: \ref MIB_BEACON_SYMBOL_TO_EXPANSION_FACTOR
  2150. */
  2151. uint32_t BeaconSymbolToExpansionFactor;
  2152. /*!
  2153. * Symbol expansion value for ping slot windows in case of beacon
  2154. * loss in symbols
  2155. *
  2156. * Related MIB type: \ref MIB_PING_SLOT_SYMBOL_TO_EXPANSION_FACTOR
  2157. */
  2158. uint32_t PingSlotSymbolToExpansionFactor;
  2159. /*!
  2160. * Maximum allowed beacon less time in ms
  2161. *
  2162. * Related MIB type: \ref MIB_MAX_BEACON_LESS_PERIOD
  2163. */
  2164. uint32_t MaxBeaconLessPeriod;
  2165. /*!
  2166. * Ping slots data rate
  2167. *
  2168. * Related MIB type: \ref MIB_PING_SLOT_DATARATE
  2169. */
  2170. int8_t PingSlotDatarate;
  2171. /*!
  2172. * LoRaWAN certification FPort handling state (ON/OFF)
  2173. *
  2174. * Related MIB type: \ref MIB_IS_CERT_FPORT_ON
  2175. */
  2176. bool IsCertPortOn;
  2177. }MibParam_t;
  2178. /*!
  2179. * LoRaMAC MIB-RequestConfirm structure
  2180. */
  2181. typedef struct eMibRequestConfirm
  2182. {
  2183. /*!
  2184. * MIB-Request type
  2185. */
  2186. Mib_t Type;
  2187. /*!
  2188. * MLME-RequestConfirm parameters
  2189. */
  2190. MibParam_t Param;
  2191. }MibRequestConfirm_t;
  2192. /*!
  2193. * LoRaMAC tx information
  2194. */
  2195. typedef struct sLoRaMacTxInfo
  2196. {
  2197. /*!
  2198. * Size of the application data payload which can be transmitted.
  2199. */
  2200. uint8_t MaxPossibleApplicationDataSize;
  2201. /*!
  2202. * The current maximum possible payload size without MAC commands
  2203. * which is dependent on the current datarate.
  2204. */
  2205. uint8_t CurrentPossiblePayloadSize;
  2206. }LoRaMacTxInfo_t;
  2207. /*!
  2208. * LoRaMAC Status
  2209. */
  2210. typedef enum eLoRaMacStatus
  2211. {
  2212. /*!
  2213. * Service started successfully
  2214. */
  2215. LORAMAC_STATUS_OK,
  2216. /*!
  2217. * Service not started - LoRaMAC is busy
  2218. */
  2219. LORAMAC_STATUS_BUSY,
  2220. /*!
  2221. * Service unknown
  2222. */
  2223. LORAMAC_STATUS_SERVICE_UNKNOWN,
  2224. /*!
  2225. * Service not started - invalid parameter
  2226. */
  2227. LORAMAC_STATUS_PARAMETER_INVALID,
  2228. /*!
  2229. * Service not started - invalid frequency
  2230. */
  2231. LORAMAC_STATUS_FREQUENCY_INVALID,
  2232. /*!
  2233. * Service not started - invalid datarate
  2234. */
  2235. LORAMAC_STATUS_DATARATE_INVALID,
  2236. /*!
  2237. * Service not started - invalid frequency and datarate
  2238. */
  2239. LORAMAC_STATUS_FREQ_AND_DR_INVALID,
  2240. /*!
  2241. * Service not started - the device is not in a LoRaWAN
  2242. */
  2243. LORAMAC_STATUS_NO_NETWORK_JOINED,
  2244. /*!
  2245. * Service not started - payload length error
  2246. */
  2247. LORAMAC_STATUS_LENGTH_ERROR,
  2248. /*!
  2249. * Service not started - the specified region is not supported
  2250. * or not activated with preprocessor definitions.
  2251. */
  2252. LORAMAC_STATUS_REGION_NOT_SUPPORTED,
  2253. /*!
  2254. * The application data was not transmitted
  2255. * because prioritized pending MAC commands had to be sent.
  2256. */
  2257. LORAMAC_STATUS_SKIPPED_APP_DATA,
  2258. /*!
  2259. * An MCPS or MLME request can return this status. In this case,
  2260. * the MAC cannot send the frame, as the duty cycle limits all
  2261. * available bands. When a request returns this value, the
  2262. * variable "DutyCycleWaitTime" in "ReqReturn" of the input
  2263. * parameters contains the remaining time to wait. If the
  2264. * value is constant and does not change, the expected time
  2265. * on air for this frame is exceeding the maximum permitted
  2266. * time according to the duty cycle time period, defined
  2267. * in Region.h, DUTY_CYCLE_TIME_PERIOD. By default this time
  2268. * is 1 hour, and a band with 1% duty cycle is then allowed
  2269. * to use an air time of 36 seconds.
  2270. */
  2271. LORAMAC_STATUS_DUTYCYCLE_RESTRICTED,
  2272. /*!
  2273. *
  2274. */
  2275. LORAMAC_STATUS_NO_CHANNEL_FOUND,
  2276. /*!
  2277. *
  2278. */
  2279. LORAMAC_STATUS_NO_FREE_CHANNEL_FOUND,
  2280. /*!
  2281. * ToDo
  2282. */
  2283. LORAMAC_STATUS_BUSY_BEACON_RESERVED_TIME,
  2284. /*!
  2285. * ToDo
  2286. */
  2287. LORAMAC_STATUS_BUSY_PING_SLOT_WINDOW_TIME,
  2288. /*!
  2289. * ToDo
  2290. */
  2291. LORAMAC_STATUS_BUSY_UPLINK_COLLISION,
  2292. /*!
  2293. * An error in the cryptographic module is occurred
  2294. */
  2295. LORAMAC_STATUS_CRYPTO_ERROR,
  2296. /*!
  2297. * An error in the frame counter handler module is occurred
  2298. */
  2299. LORAMAC_STATUS_FCNT_HANDLER_ERROR,
  2300. /*!
  2301. * An error in the MAC command module is occurred
  2302. */
  2303. LORAMAC_STATUS_MAC_COMMAD_ERROR,
  2304. /*!
  2305. * An error in the Class B module is occurred
  2306. */
  2307. LORAMAC_STATUS_CLASS_B_ERROR,
  2308. /*!
  2309. * An error in the Confirm Queue module is occurred
  2310. */
  2311. LORAMAC_STATUS_CONFIRM_QUEUE_ERROR,
  2312. /*!
  2313. * The multicast group doesn't exist
  2314. */
  2315. LORAMAC_STATUS_MC_GROUP_UNDEFINED,
  2316. /*!
  2317. * Undefined error occurred
  2318. */
  2319. LORAMAC_STATUS_ERROR
  2320. }LoRaMacStatus_t;
  2321. /*!
  2322. * LoRaMAC events structure
  2323. * Used to notify upper layers of MAC events
  2324. */
  2325. typedef struct sLoRaMacPrimitives
  2326. {
  2327. /*!
  2328. * \brief MCPS-Confirm primitive
  2329. *
  2330. * \param [OUT] MCPS-Confirm parameters
  2331. */
  2332. void ( *MacMcpsConfirm )( McpsConfirm_t* McpsConfirm );
  2333. /*!
  2334. * \brief MCPS-Indication primitive
  2335. *
  2336. * \param [OUT] MCPS-Indication parameters
  2337. */
  2338. void ( *MacMcpsIndication )( McpsIndication_t* McpsIndication );
  2339. /*!
  2340. * \brief MLME-Confirm primitive
  2341. *
  2342. * \param [OUT] MLME-Confirm parameters
  2343. */
  2344. void ( *MacMlmeConfirm )( MlmeConfirm_t* MlmeConfirm );
  2345. /*!
  2346. * \brief MLME-Indication primitive
  2347. *
  2348. * \param [OUT] MLME-Indication parameters
  2349. */
  2350. void ( *MacMlmeIndication )( MlmeIndication_t* MlmeIndication );
  2351. }LoRaMacPrimitives_t;
  2352. /*!
  2353. * LoRaMAC callback structure
  2354. */
  2355. typedef struct sLoRaMacCallback
  2356. {
  2357. /*!
  2358. * \brief Measures the battery level
  2359. *
  2360. * \retval Battery level [0: node is connected to an external
  2361. * power source, 1..254: battery level, where 1 is the minimum
  2362. * and 254 is the maximum value, 255: the node was not able
  2363. * to measure the battery level]
  2364. */
  2365. uint8_t ( *GetBatteryLevel )( void );
  2366. /*!
  2367. * \brief Measures the temperature level
  2368. *
  2369. * \retval Temperature level
  2370. */
  2371. float ( *GetTemperatureLevel )( void );
  2372. /*!
  2373. * \brief Will be called when an attribute has changed in one of the context.
  2374. *
  2375. * \param notifyFlags Bitmap that contains the modules which changed.
  2376. * Refer to \ref LoRaMacNvmData_t.
  2377. */
  2378. void ( *NvmDataChange )( uint16_t notifyFlags );
  2379. /*!
  2380. *\brief Will be called each time a Radio IRQ is handled by the MAC
  2381. * layer.
  2382. *
  2383. *\warning Runs in a IRQ context. Should only change variables state.
  2384. */
  2385. void ( *MacProcessNotify )( void );
  2386. }LoRaMacCallback_t;
  2387. /*!
  2388. * LoRaMAC Max EIRP (dBm) table
  2389. */
  2390. static const uint8_t LoRaMacMaxEirpTable[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21, 24, 26, 27, 29, 30, 33, 36 };
  2391. /*!
  2392. * \brief LoRaMAC layer initialization
  2393. *
  2394. * \details In addition to the initialization of the LoRaMAC layer, this
  2395. * function initializes the callback primitives of the MCPS and
  2396. * MLME services. Every data field of \ref LoRaMacPrimitives_t must be
  2397. * set to a valid callback function.
  2398. *
  2399. * \param [IN] primitives - Pointer to a structure defining the LoRaMAC
  2400. * event functions. Refer to \ref LoRaMacPrimitives_t.
  2401. *
  2402. * \param [IN] callbacks - Pointer to a structure defining the LoRaMAC
  2403. * callback functions. Refer to \ref LoRaMacCallback_t.
  2404. *
  2405. * \param [IN] region - The region to start.
  2406. *
  2407. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2408. * returns are:
  2409. * \ref LORAMAC_STATUS_OK,
  2410. * \ref LORAMAC_STATUS_PARAMETER_INVALID,
  2411. * \ref LORAMAC_STATUS_REGION_NOT_SUPPORTED.
  2412. */
  2413. LoRaMacStatus_t LoRaMacInitialization( LoRaMacPrimitives_t* primitives, LoRaMacCallback_t* callbacks, LoRaMacRegion_t region );
  2414. /*!
  2415. * \brief Starts LoRaMAC layer
  2416. *
  2417. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2418. * returns are:
  2419. * \ref LORAMAC_STATUS_OK,
  2420. */
  2421. LoRaMacStatus_t LoRaMacStart( void );
  2422. /*!
  2423. * \brief Stops LoRaMAC layer
  2424. *
  2425. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2426. * returns are:
  2427. * \ref LORAMAC_STATUS_OK,
  2428. */
  2429. LoRaMacStatus_t LoRaMacStop( void );
  2430. /*!
  2431. * \brief Returns a value indicating if the MAC layer is busy or not.
  2432. *
  2433. * \retval isBusy Mac layer is busy.
  2434. */
  2435. bool LoRaMacIsBusy( void );
  2436. /*!
  2437. * Processes the LoRaMac events.
  2438. *
  2439. * \remark This function must be called in the main loop.
  2440. */
  2441. void LoRaMacProcess( void );
  2442. /*!
  2443. * \brief Queries the LoRaMAC if it is possible to send the next frame with
  2444. * a given application data payload size. The LoRaMAC takes scheduled
  2445. * MAC commands into account and reports, when the frame can be send or not.
  2446. *
  2447. * \param [IN] size - Size of application data payload to be send next
  2448. *
  2449. * \param [OUT] txInfo - The structure \ref LoRaMacTxInfo_t contains
  2450. * information about the actual maximum payload possible
  2451. * ( according to the configured datarate or the next
  2452. * datarate according to ADR ), and the maximum frame
  2453. * size, taking the scheduled MAC commands into account.
  2454. *
  2455. * \retval LoRaMacStatus_t Status of the operation. When the parameters are
  2456. * not valid, the function returns \ref LORAMAC_STATUS_PARAMETER_INVALID.
  2457. * In case of a length error caused by the application data payload in combination
  2458. * with the MAC commands, the function returns \ref LORAMAC_STATUS_LENGTH_ERROR.
  2459. * In this case its recommended to send a frame without application data to flush
  2460. * the MAC commands. Otherwise the LoRaMAC will prioritize the MAC commands and
  2461. * if needed it will skip the application data. Please note that if MAC commands do
  2462. * not fit at all into the payload size on the related datarate, the LoRaMAC will
  2463. * automatically clip the MAC commands.
  2464. * In case the query is valid, and the LoRaMAC is able to send the frame,
  2465. * the function returns \ref LORAMAC_STATUS_OK.
  2466. */
  2467. LoRaMacStatus_t LoRaMacQueryTxPossible( uint8_t size, LoRaMacTxInfo_t* txInfo );
  2468. /*!
  2469. * \brief LoRaMAC channel add service
  2470. *
  2471. * \details Adds a new channel to the channel list and activates the id in
  2472. * the channel mask. Please note that this functionality is not available
  2473. * on all regions. Information about allowed ranges are available at the LoRaWAN Regional Parameters V1.0.2rB
  2474. *
  2475. * \param [IN] id - Id of the channel.
  2476. *
  2477. * \param [IN] params - Channel parameters to set.
  2478. *
  2479. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2480. * \ref LORAMAC_STATUS_OK,
  2481. * \ref LORAMAC_STATUS_BUSY,
  2482. * \ref LORAMAC_STATUS_PARAMETER_INVALID.
  2483. */
  2484. LoRaMacStatus_t LoRaMacChannelAdd( uint8_t id, ChannelParams_t params );
  2485. /*!
  2486. * \brief LoRaMAC channel remove service
  2487. *
  2488. * \details Deactivates the id in the channel mask.
  2489. *
  2490. * \param [IN] id - Id of the channel.
  2491. *
  2492. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2493. * \ref LORAMAC_STATUS_OK,
  2494. * \ref LORAMAC_STATUS_BUSY,
  2495. * \ref LORAMAC_STATUS_PARAMETER_INVALID.
  2496. */
  2497. LoRaMacStatus_t LoRaMacChannelRemove( uint8_t id );
  2498. /*!
  2499. * \brief LoRaMAC multicast channel setup service
  2500. *
  2501. * \details Sets up a multicast channel.
  2502. *
  2503. * \param [IN] channel - Multicast channel to set.
  2504. *
  2505. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2506. * \ref LORAMAC_STATUS_OK,
  2507. * \ref LORAMAC_STATUS_BUSY,
  2508. * \ref LORAMAC_STATUS_PARAMETER_INVALID,
  2509. * \ref LORAMAC_STATUS_MC_GROUP_UNDEFINED.
  2510. */
  2511. LoRaMacStatus_t LoRaMacMcChannelSetup( McChannelParams_t *channel );
  2512. /*!
  2513. * \brief LoRaMAC multicast channel removal service
  2514. *
  2515. * \details Removes/Disables a multicast channel.
  2516. *
  2517. * \param [IN] groupID - Multicast channel ID to be removed/disabled
  2518. *
  2519. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2520. * \ref LORAMAC_STATUS_OK,
  2521. * \ref LORAMAC_STATUS_BUSY,
  2522. * \ref LORAMAC_STATUS_MC_GROUP_UNDEFINED.
  2523. */
  2524. LoRaMacStatus_t LoRaMacMcChannelDelete( AddressIdentifier_t groupID );
  2525. /*!
  2526. * \brief LoRaMAC multicast channel get groupId from MC address.
  2527. *
  2528. * \param [IN] mcAddress - Multicast address to be checked
  2529. *
  2530. * \retval groupID Multicast channel ID associated to the address.
  2531. * Returns 0xFF if the address isn't found.
  2532. */
  2533. uint8_t LoRaMacMcChannelGetGroupId( uint32_t mcAddress );
  2534. /*!
  2535. * \brief LoRaMAC multicast channel Rx parameters setup service
  2536. *
  2537. * \details Sets up a multicast channel reception parameters.
  2538. *
  2539. * \param [IN] groupID - Multicast channel ID
  2540. * \param [IN] rxParams - Reception parameters
  2541. * \param [OUT] status - Status mask [UNDEF_ID | FREQ_ERR | DR_ERR | GROUP_ID]
  2542. *
  2543. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2544. * \ref LORAMAC_STATUS_OK,
  2545. * \ref LORAMAC_STATUS_BUSY,
  2546. * \ref LORAMAC_STATUS_PARAMETER_INVALID,
  2547. * \ref LORAMAC_STATUS_MC_GROUP_UNDEFINED.
  2548. */
  2549. LoRaMacStatus_t LoRaMacMcChannelSetupRxParams( AddressIdentifier_t groupID, McRxParams_t *rxParams, uint8_t *status );
  2550. /*!
  2551. * \brief LoRaMAC MIB-Get
  2552. *
  2553. * \details The mac information base service to get attributes of the LoRaMac
  2554. * layer.
  2555. *
  2556. * The following code-snippet shows how to use the API to get the
  2557. * parameter AdrEnable, defined by the enumeration type
  2558. * \ref MIB_ADR.
  2559. * \code
  2560. * MibRequestConfirm_t mibReq;
  2561. * mibReq.Type = MIB_ADR;
  2562. *
  2563. * if( LoRaMacMibGetRequestConfirm( &mibReq ) == LORAMAC_STATUS_OK )
  2564. * {
  2565. * // LoRaMAC updated the parameter mibParam.AdrEnable
  2566. * }
  2567. * \endcode
  2568. *
  2569. * \param [IN] mibRequest - MIB-GET-Request to perform. Refer to \ref MibRequestConfirm_t.
  2570. *
  2571. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2572. * \ref LORAMAC_STATUS_OK,
  2573. * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
  2574. * \ref LORAMAC_STATUS_PARAMETER_INVALID.
  2575. */
  2576. LoRaMacStatus_t LoRaMacMibGetRequestConfirm( MibRequestConfirm_t* mibGet );
  2577. /*!
  2578. * \brief LoRaMAC MIB-Set
  2579. *
  2580. * \details The mac information base service to set attributes of the LoRaMac
  2581. * layer.
  2582. *
  2583. * The following code-snippet shows how to use the API to set the
  2584. * parameter AdrEnable, defined by the enumeration type
  2585. * \ref MIB_ADR.
  2586. *
  2587. * \code
  2588. * MibRequestConfirm_t mibReq;
  2589. * mibReq.Type = MIB_ADR;
  2590. * mibReq.Param.AdrEnable = true;
  2591. *
  2592. * if( LoRaMacMibGetRequestConfirm( &mibReq ) == LORAMAC_STATUS_OK )
  2593. * {
  2594. * // LoRaMAC updated the parameter
  2595. * }
  2596. * \endcode
  2597. *
  2598. * \param [IN] mibRequest - MIB-SET-Request to perform. Refer to \ref MibRequestConfirm_t.
  2599. *
  2600. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2601. * \ref LORAMAC_STATUS_OK,
  2602. * \ref LORAMAC_STATUS_BUSY,
  2603. * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
  2604. * \ref LORAMAC_STATUS_PARAMETER_INVALID.
  2605. */
  2606. LoRaMacStatus_t LoRaMacMibSetRequestConfirm( MibRequestConfirm_t* mibSet );
  2607. /*!
  2608. * \brief LoRaMAC MLME-Request
  2609. *
  2610. * \details The Mac layer management entity handles management services. The
  2611. * following code-snippet shows how to use the API to perform a
  2612. * network join request. Please note that for a join request, the
  2613. * DevEUI and the JoinEUI must be set previously via the MIB. Please
  2614. * also refer to the sample implementations.
  2615. *
  2616. * \code
  2617. *
  2618. * MlmeReq_t mlmeReq;
  2619. * mlmeReq.Type = MLME_JOIN;
  2620. * mlmeReq.Req.Join.Datarate = LORAWAN_DEFAULT_DATARATE;
  2621. *
  2622. * if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
  2623. * {
  2624. * // Service started successfully. Waiting for the Mlme-Confirm event
  2625. * }
  2626. * \endcode
  2627. *
  2628. * \param [IN] mlmeRequest - MLME-Request to perform. Refer to \ref MlmeReq_t.
  2629. *
  2630. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2631. * \ref LORAMAC_STATUS_OK,
  2632. * \ref LORAMAC_STATUS_BUSY,
  2633. * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
  2634. * \ref LORAMAC_STATUS_PARAMETER_INVALID,
  2635. * \ref LORAMAC_STATUS_NO_NETWORK_JOINED,
  2636. * \ref LORAMAC_STATUS_LENGTH_ERROR,
  2637. */
  2638. LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest );
  2639. /*!
  2640. * \brief LoRaMAC MCPS-Request
  2641. *
  2642. * \details The Mac Common Part Sublayer handles data services. The following
  2643. * code-snippet shows how to use the API to send an unconfirmed
  2644. * LoRaMAC frame.
  2645. *
  2646. * \code
  2647. * uint8_t myBuffer[] = { 1, 2, 3 };
  2648. *
  2649. * McpsReq_t mcpsReq;
  2650. * mcpsReq.Type = MCPS_UNCONFIRMED;
  2651. * mcpsReq.Req.Unconfirmed.fPort = 1;
  2652. * mcpsReq.Req.Unconfirmed.fBuffer = myBuffer;
  2653. * mcpsReq.Req.Unconfirmed.fBufferSize = sizeof( myBuffer );
  2654. *
  2655. * if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK )
  2656. * {
  2657. * // Service started successfully. Waiting for the MCPS-Confirm event
  2658. * }
  2659. * \endcode
  2660. *
  2661. * \param [IN] mcpsRequest - MCPS-Request to perform. Refer to \ref McpsReq_t.
  2662. *
  2663. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2664. * \ref LORAMAC_STATUS_OK,
  2665. * \ref LORAMAC_STATUS_BUSY,
  2666. * \ref LORAMAC_STATUS_SERVICE_UNKNOWN,
  2667. * \ref LORAMAC_STATUS_PARAMETER_INVALID,
  2668. * \ref LORAMAC_STATUS_NO_NETWORK_JOINED,
  2669. * \ref LORAMAC_STATUS_LENGTH_ERROR,
  2670. */
  2671. LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t* mcpsRequest );
  2672. /*!
  2673. * \brief LoRaMAC deinitialization
  2674. *
  2675. * \details This function stops the timers, re-initializes MAC & regional parameters to default
  2676. * and sets radio into sleep state.
  2677. *
  2678. * \retval LoRaMacStatus_t Status of the operation. Possible returns are:
  2679. * \ref LORAMAC_STATUS_OK,
  2680. * \ref LORAMAC_STATUS_BUSY
  2681. */
  2682. LoRaMacStatus_t LoRaMacDeInitialization( void );
  2683. /*! \} defgroup LORAMAC */
  2684. #ifdef __cplusplus
  2685. }
  2686. #endif
  2687. #endif // __LORAMAC_H__