Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX127x sx12xx_hal TSL2561
LoRaMacSingle.h
00001 /*! 00002 */ 00003 #ifndef __LORAMAC_H__ 00004 #define __LORAMAC_H__ 00005 00006 // Includes board dependent definitions such as channels frequencies 00007 #include "LoRaMac-definitions.h" 00008 00009 using namespace std::chrono; 00010 /*! 00011 * Beacon interval in microseconds 00012 */ 00013 #define BEACON_INTERVAL_us 128000000 /*16000000*/ /*8000000*/ 00014 #define PPM_BEACON_INTERVAL (BEACON_INTERVAL_us / 5000) /* timer crystal max error accomidation */ 00015 00016 /*! 00017 * Class A&B receive delay 1 in us 00018 */ 00019 #define RECEIVE_DELAY_us 100000 00020 00021 #define JOIN_ACCEPT_DELAY_us 100000 00022 00023 /*! 00024 * Class A&B maximum receive window delay in ms 00025 */ 00026 #define MAX_RX_WINDOW 3000 00027 00028 /*! 00029 * Maximum allowed gap for the FCNT field 00030 */ 00031 #define MAX_FCNT_GAP 16384 00032 00033 /*! 00034 * ADR acknowledgement counter limit 00035 */ 00036 #define ADR_ACK_LIMIT 64 00037 00038 /*! 00039 * Number of ADR acknowledgement requests before returning to default datarate 00040 */ 00041 #define ADR_ACK_DELAY 32 00042 00043 /*! 00044 * Number of seconds after the start of the second reception window without 00045 * receiving an acknowledge. 00046 * AckTimeout = \ref ACK_TIMEOUT + Random( -\ref ACK_TIMEOUT_RND, \ref ACK_TIMEOUT_RND ) 00047 */ 00048 #define ACK_TIMEOUT_us 2000000 00049 00050 /*! 00051 * Random number of seconds after the start of the second reception window without 00052 * receiving an acknowledge 00053 * AckTimeout = \ref ACK_TIMEOUT + Random( -\ref ACK_TIMEOUT_RND, \ref ACK_TIMEOUT_RND ) 00054 */ 00055 #define ACK_TIMEOUT_RND_us 1000000 00056 00057 /*! 00058 * Check the Mac layer state every MAC_STATE_CHECK_TIMEOUT in us 00059 */ 00060 #define MAC_STATE_CHECK_TIMEOUT_us 1000000 00061 00062 /*! 00063 * Maximum number of times the MAC layer tries to get an acknowledge. 00064 */ 00065 #define MAX_ACK_RETRIES 8 00066 00067 /*! 00068 * RSSI free threshold [dBm] 00069 */ 00070 #define RSSI_FREE_TH ( int8_t )( -90 ) 00071 00072 /*! 00073 * Frame direction definition for up-link communications 00074 */ 00075 #define UP_LINK 0 00076 00077 /*! 00078 * Frame direction definition for down-link communications 00079 */ 00080 #define DOWN_LINK 1 00081 00082 /*! 00083 * Sets the length of the LoRaMAC footer field. 00084 * Mainly indicates the MIC field length 00085 */ 00086 #define LORAMAC_MFR_LEN 4 00087 00088 /*! 00089 * LoRaWAN devices classes definition 00090 */ 00091 typedef enum eDeviceClass 00092 { 00093 /*! 00094 * LoRaWAN device class A 00095 * 00096 * LoRaWAN Specification V1.0.1, chapter 3ff 00097 */ 00098 CLASS_A, 00099 /*! 00100 * LoRaWAN device class B 00101 * 00102 * LoRaWAN Specification V1.0.1, chapter 8ff 00103 */ 00104 CLASS_B, 00105 /*! 00106 * LoRaWAN device class C 00107 * 00108 * LoRaWAN Specification V1.0.1, chapter 17ff 00109 */ 00110 CLASS_D, 00111 }DeviceClass_t; 00112 00113 /*! 00114 * LoRaMAC channels parameters definition 00115 */ 00116 typedef union uDrRange 00117 { 00118 /*! 00119 * Byte-access to the bits 00120 */ 00121 int8_t Value ; 00122 /*! 00123 * Structure to store the minimum and the maximum datarate 00124 */ 00125 struct sFields 00126 { 00127 /*! 00128 * Minimum data rate 00129 * 00130 * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7] 00131 * 00132 * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4] 00133 */ 00134 int8_t Min : 4; 00135 /*! 00136 * Maximum data rate 00137 * 00138 * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7] 00139 * 00140 * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4] 00141 */ 00142 int8_t Max : 4; 00143 }Fields; 00144 }DrRange_t ; 00145 00146 /*! 00147 * LoRaMAC band parameters definition 00148 */ 00149 typedef struct sBand 00150 { 00151 /*! 00152 * Duty cycle 00153 */ 00154 uint16_t DCycle ; 00155 /*! 00156 * Maximum Tx power 00157 */ 00158 int8_t TxMaxPower ; 00159 /*! 00160 * Time stamp of the last Tx frame 00161 */ 00162 //TimerTime_t LastTxDoneTime; 00163 unsigned int last_tx_done_us ; 00164 /*! 00165 * Holds the time where the device is off 00166 */ 00167 //TimerTime_t TimeOff; 00168 }Band_t ; 00169 00170 /*! 00171 * LoRaMAC channel definition 00172 */ 00173 typedef struct sChannelParams 00174 { 00175 /*! 00176 * Frequency in Hz 00177 */ 00178 uint32_t Frequency ; 00179 /*! 00180 * Data rate definition 00181 */ 00182 DrRange_t DrRange ; 00183 /*! 00184 * Band index 00185 */ 00186 uint8_t Band ; 00187 }ChannelParams_t ; 00188 00189 #if 0 00190 /*! 00191 * LoRaMAC receive window 2 channel parameters 00192 */ 00193 typedef struct sRx2ChannelParams 00194 { 00195 /*! 00196 * Frequency in Hz 00197 */ 00198 uint32_t Frequency ; 00199 /*! 00200 * Data rate 00201 * 00202 * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7] 00203 * 00204 * US915 - [DR_8, DR_9, DR_10, DR_11, DR_12, DR_13] 00205 */ 00206 uint8_t Datarate ; 00207 }Rx2ChannelParams_t ; 00208 #endif /* #if 0 */ 00209 00210 /*! 00211 * Global MAC layer parameters 00212 */ 00213 typedef struct sLoRaMacParams 00214 { 00215 /*! 00216 * Channels TX power 00217 */ 00218 int8_t ChannelsTxPower ; 00219 /*! 00220 * Channels data rate 00221 */ 00222 int8_t ChannelsDatarate_fixed ; 00223 /*! 00224 * System overall timing error in milliseconds. 00225 * [-SystemMaxRxError : +SystemMaxRxError] 00226 * Default: +/-10 ms 00227 */ 00228 uint32_t SystemMaxRxError_ms ; 00229 /*! 00230 * Minimum required number of symbols to detect an Rx frame 00231 * Default: 6 symbols 00232 */ 00233 uint8_t MinRxSymbols ; 00234 /*! 00235 * LoRaMac maximum time a reception window stays open 00236 */ 00237 uint32_t MaxRxWindow ; 00238 00239 uint32_t JoinAcceptDelay_us; 00240 uint32_t ReceiveDelay_us; 00241 00242 /*! 00243 * Number of uplink messages repetitions [1:15] (unconfirmed messages only) 00244 */ 00245 uint8_t ChannelsNbRep ; 00246 /*! 00247 * Datarate offset between uplink and downlink on first window 00248 */ 00249 uint8_t Rx1DrOffset ; 00250 /*! 00251 * LoRaMAC 2nd reception window settings 00252 */ 00253 }LoRaMacParams_t ; 00254 00255 /*! 00256 * LoRaMAC multicast channel parameter 00257 */ 00258 typedef struct sMulticastParams 00259 { 00260 /*! 00261 * Address 00262 */ 00263 uint32_t Address ; 00264 /*! 00265 * Network session key 00266 */ 00267 uint8_t NwkSKey[16]; 00268 /*! 00269 * Application session key 00270 */ 00271 uint8_t AppSKey[16]; 00272 /*! 00273 * Downlink counter 00274 */ 00275 uint32_t DownLinkCounter ; 00276 /*! 00277 * Reference pointer to the next multicast channel parameters in the list 00278 */ 00279 struct sMulticastParams *Next ; 00280 }MulticastParams_t ; 00281 00282 /*! 00283 * LoRaMAC frame types 00284 * 00285 * LoRaWAN Specification V1.0.1, chapter 4.2.1, table 1 00286 */ 00287 typedef enum eLoRaMacFrameType 00288 { 00289 /*! 00290 * LoRaMAC join request frame 00291 */ 00292 FRAME_TYPE_JOIN_REQ = 0x00, 00293 /*! 00294 * LoRaMAC join accept frame 00295 */ 00296 FRAME_TYPE_JOIN_ACCEPT = 0x01, 00297 /*! 00298 * LoRaMAC unconfirmed up-link frame 00299 */ 00300 FRAME_TYPE_DATA_UNCONFIRMED_UP = 0x02, 00301 /*! 00302 * LoRaMAC unconfirmed down-link frame 00303 */ 00304 FRAME_TYPE_DATA_UNCONFIRMED_DOWN = 0x03, 00305 /*! 00306 * LoRaMAC confirmed up-link frame 00307 */ 00308 FRAME_TYPE_DATA_CONFIRMED_UP = 0x04, 00309 /*! 00310 * LoRaMAC confirmed down-link frame 00311 */ 00312 FRAME_TYPE_DATA_CONFIRMED_DOWN = 0x05, 00313 /*! 00314 * LoRaMAC RFU frame 00315 */ 00316 FRAME_TYPE_RFU = 0x06, 00317 /*! 00318 * LoRaMAC proprietary frame 00319 */ 00320 FRAME_TYPE_PROPRIETARY = 0x07, 00321 }LoRaMacFrameType_t; 00322 00323 /*! 00324 * LoRaMAC mote MAC commands 00325 * 00326 * LoRaWAN Specification V1.0.1, chapter 5, table 4 00327 */ 00328 typedef enum eLoRaMacMoteCmd 00329 { 00330 /*! 00331 * LinkCheckReq 00332 */ 00333 MOTE_MAC_LINK_CHECK_REQ = 0x02, 00334 /*! 00335 * RXParamSetupAns 00336 */ 00337 MOTE_MAC_RX_PARAM_SETUP_ANS = 0x05, 00338 /*! 00339 * DevStatusAns 00340 */ 00341 MOTE_MAC_DEV_STATUS_ANS = 0x06, 00342 /*! 00343 * NewChannelAns 00344 */ 00345 /*! 00346 * RXTimingSetupAns 00347 */ 00348 MOTE_MAC_RX_TIMING_SETUP_ANS = 0x08, 00349 }LoRaMacMoteCmd_t; 00350 00351 /*! 00352 * LoRaMAC server MAC commands 00353 * 00354 * LoRaWAN Specification V1.0.1 chapter 5, table 4 00355 */ 00356 typedef enum eLoRaMacSrvCmd 00357 { 00358 /*! 00359 * LinkCheckAns 00360 */ 00361 SRV_MAC_LINK_CHECK_ANS = 0x02, 00362 /*! 00363 * RXParamSetupReq 00364 */ 00365 //SRV_MAC_RX_PARAM_SETUP_REQ = 0x05, 00366 /*! 00367 * DevStatusReq 00368 */ 00369 SRV_MAC_DEV_STATUS_REQ = 0x06, 00370 /*! 00371 * NewChannelReq 00372 */ 00373 /*! 00374 * RXTimingSetupReq 00375 */ 00376 SRV_MAC_RX_TIMING_SETUP_REQ = 0x08, 00377 }LoRaMacSrvCmd_t; 00378 00379 /*! 00380 * LoRaMAC Battery level indicator 00381 */ 00382 typedef enum eLoRaMacBatteryLevel 00383 { 00384 /*! 00385 * External power source 00386 */ 00387 BAT_LEVEL_EXT_SRC = 0x00, 00388 /*! 00389 * Battery level empty 00390 */ 00391 BAT_LEVEL_EMPTY = 0x01, 00392 /*! 00393 * Battery level full 00394 */ 00395 BAT_LEVEL_FULL = 0xFE, 00396 /*! 00397 * Battery level - no measurement available 00398 */ 00399 BAT_LEVEL_NO_MEASURE = 0xFF, 00400 }LoRaMacBatteryLevel_t; 00401 00402 /*! 00403 * LoRaMAC header field definition (MHDR field) 00404 * 00405 * LoRaWAN Specification V1.0.1, chapter 4.2 00406 */ 00407 typedef union uLoRaMacHeader 00408 { 00409 /*! 00410 * Byte-access to the bits 00411 */ 00412 uint8_t Value ; 00413 /*! 00414 * Structure containing single access to header bits 00415 */ 00416 struct sHdrBits 00417 { 00418 /*! 00419 * Major version 00420 */ 00421 uint8_t Major : 2; 00422 /*! 00423 * RFU 00424 */ 00425 uint8_t RFU : 3; 00426 /*! 00427 * Message type 00428 */ 00429 uint8_t MType : 3; 00430 }Bits; 00431 }LoRaMacHeader_t ; 00432 00433 /*! 00434 * LoRaMAC frame control field definition (FCtrl) 00435 * 00436 * LoRaWAN Specification V1.0.1, chapter 4.3.1 00437 */ 00438 typedef union uLoRaMacFrameCtrl 00439 { 00440 /*! 00441 * Byte-access to the bits 00442 */ 00443 uint8_t Value ; 00444 /*! 00445 * Structure containing single access to bits 00446 */ 00447 struct sCtrlBits 00448 { 00449 /*! 00450 * Frame options length 00451 */ 00452 uint8_t FOptsLen : 4; 00453 /*! 00454 * Frame pending bit 00455 */ 00456 uint8_t FPending : 1; 00457 /*! 00458 * Message acknowledge bit 00459 */ 00460 uint8_t Ack : 1; 00461 /*! 00462 * ADR acknowledgment request bit 00463 */ 00464 uint8_t AdrAckReq : 1; 00465 /*! 00466 * ADR control in frame header 00467 */ 00468 uint8_t Adr : 1; 00469 }Bits; 00470 }LoRaMacFrameCtrl_t ; 00471 00472 /*! 00473 * Enumeration containing the status of the operation of a MAC service 00474 */ 00475 typedef enum eLoRaMacEventInfoStatus 00476 { 00477 /*! 00478 * Service performed successfully 00479 */ 00480 LORAMAC_EVENT_INFO_STATUS_OK = 0, 00481 /*! 00482 * An error occurred during the execution of the service 00483 */ 00484 LORAMAC_EVENT_INFO_STATUS_ERROR_RX_MTYPE, 00485 LORAMAC_EVENT_INFO_STATUS_ERROR_SEND, 00486 LORAMAC_EVENT_INFO_STATUS_ERROR_JOIN_ACCEPT, 00487 LORAMAC_EVENT_INFO_STATUS_ERROR_MLMEREQ, 00488 LORAMAC_EVENT_INFO_STATUS_ERROR_MCPSREQ, 00489 /*! 00490 * A Tx timeout occurred 00491 */ 00492 LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT, 00493 /*! 00494 * An Rx timeout occurred on receive window 2 00495 */ 00496 //LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT, 00497 LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT, 00498 /*! 00499 * An Rx error occurred on receive window 1 00500 */ 00501 //LORAMAC_EVENT_INFO_STATUS_RX1_ERROR, 00502 LORAMAC_EVENT_INFO_STATUS_RX_ERROR, 00503 /*! 00504 * An Rx error occurred on receive window 2 00505 */ 00506 //LORAMAC_EVENT_INFO_STATUS_RX2_ERROR, 00507 /*! 00508 * An error occurred in the join procedure 00509 */ 00510 LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL, 00511 /*! 00512 * A frame with an invalid downlink counter was received. The 00513 * downlink counter of the frame was equal to the local copy 00514 * of the downlink counter of the node. 00515 */ 00516 LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED, 00517 /*! 00518 * The MAC could not retransmit a frame since the MAC decreased the datarate. The 00519 * payload size is not applicable for the datarate. 00520 */ 00521 LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR, 00522 /*! 00523 * The node has lost MAX_FCNT_GAP or more frames. 00524 */ 00525 LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS, 00526 /*! 00527 * An address error occurred 00528 */ 00529 LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL, 00530 /*! 00531 * message integrity check failure 00532 */ 00533 LORAMAC_EVENT_INFO_STATUS_MIC_FAIL, 00534 /*! 00535 * ToDo 00536 */ 00537 LORAMAC_EVENT_INFO_STATUS_BEACON_LOCKED, 00538 /*! 00539 * ToDo 00540 */ 00541 LORAMAC_EVENT_INFO_STATUS_BEACON_LOST, 00542 /*! 00543 * ToDo 00544 */ 00545 LORAMAC_EVENT_INFO_STATUS_BEACON_NOT_FOUND, 00546 00547 LORAMAC_EVENT_INFO_STATUS_STOP 00548 } LoRaMacEventInfoStatus_t; 00549 00550 /*! 00551 * LoRaMac tx/rx operation state 00552 */ 00553 typedef union eLoRaMacFlags_t 00554 { 00555 /*! 00556 * Byte-access to the bits 00557 */ 00558 uint8_t Value ; 00559 /*! 00560 * Structure containing single access to bits 00561 */ 00562 struct sMacFlagBits 00563 { 00564 /*! 00565 * MCPS-Req pending 00566 */ 00567 uint16_t McpsReq : 1; // 0 00568 /*! 00569 * MCPS-Ind pending 00570 */ 00571 uint16_t McpsInd : 1; // 1 00572 /*! 00573 * MCPS-Ind pending. Skip indication to the application layer 00574 */ 00575 uint16_t McpsIndSkip : 1; // 2 00576 /*! 00577 * MLME-Req pending 00578 */ 00579 uint16_t MlmeReq : 1; // 3 00580 /*! 00581 * MAC cycle done 00582 */ 00583 uint16_t MacDone : 1; // 4 00584 /*! 00585 * MLME-Ind pending 00586 */ 00587 uint16_t MlmeInd : 1; // 5 00588 00589 uint16_t uplink_pending : 1; // 6 00590 00591 uint16_t IsLoRaMacNetworkJoined : 1; // 7 00592 uint16_t join_send : 1; // 8 00593 uint16_t send : 1; // 9 00594 uint16_t expecting_beacon : 1; // 10 00595 uint16_t reJoin : 1; // 11 00596 uint16_t NodeAckRequested : 1; // 12 00597 uint16_t SrvAckRequested : 1; // 13 00598 }Bits; 00599 } LoRaMacFlags_t ; 00600 00601 /*! 00602 * 00603 * \brief LoRaMAC data services 00604 * 00605 * \details The following table list the primitives which are supported by the 00606 * specific MAC data service: 00607 * 00608 * Name | Request | Indication | Response | Confirm 00609 * --------------------- | :-----: | :--------: | :------: | :-----: 00610 * \ref MCPS_UNCONFIRMED | YES | YES | NO | YES 00611 * \ref MCPS_CONFIRMED | YES | YES | NO | YES 00612 * \ref MCPS_MULTICAST | NO | YES | NO | NO 00613 * \ref MCPS_PROPRIETARY | YES | YES | NO | YES 00614 * 00615 * The following table provides links to the function implementations of the 00616 * related MCPS primitives: 00617 * 00618 * Primitive | Function 00619 * ---------------- | :---------------------: 00620 * MCPS-Request | \ref LoRaMacMlmeRequest 00621 * MCPS-Confirm | MacMcpsConfirm in \ref LoRaMacPrimitives_t 00622 * MCPS-Indication | MacMcpsIndication in \ref LoRaMacPrimitives_t 00623 */ 00624 typedef enum eMcps 00625 { 00626 /*! 00627 * Unconfirmed LoRaMAC frame 00628 */ 00629 MCPS_UNCONFIRMED, 00630 /*! 00631 * Confirmed LoRaMAC frame 00632 */ 00633 MCPS_CONFIRMED, 00634 /*! 00635 * Multicast LoRaMAC frame 00636 */ 00637 MCPS_MULTICAST, 00638 /*! 00639 * Proprietary frame 00640 */ 00641 MCPS_PROPRIETARY, 00642 }Mcps_t; 00643 00644 /*! 00645 * LoRaMAC MCPS-Request for an unconfirmed frame 00646 */ 00647 typedef struct sMcpsReqUnconfirmed 00648 { 00649 /*! 00650 * Frame port field. Must be set if the payload is not empty. Use the 00651 * application specific frame port values: [1...223] 00652 * 00653 * LoRaWAN Specification V1.0.1, chapter 4.3.2 00654 */ 00655 uint8_t fPort ; 00656 /*! 00657 * Pointer to the buffer of the frame payload 00658 */ 00659 void *fBuffer ; 00660 /*! 00661 * Size of the frame payload 00662 */ 00663 uint16_t fBufferSize ; 00664 /*! 00665 * Uplink datarate, if ADR is off 00666 */ 00667 //int8_t Datarate; 00668 }McpsReqUnconfirmed_t ; 00669 00670 /*! 00671 * LoRaMAC MCPS-Request for a confirmed frame 00672 */ 00673 typedef struct sMcpsReqConfirmed 00674 { 00675 /*! 00676 * Frame port field. Must be set if the payload is not empty. Use the 00677 * application specific frame port values: [1...223] 00678 * 00679 * LoRaWAN Specification V1.0.1, chapter 4.3.2 00680 */ 00681 uint8_t fPort ; 00682 /*! 00683 * Pointer to the buffer of the frame payload 00684 */ 00685 void *fBuffer ; 00686 /*! 00687 * Size of the frame payload 00688 */ 00689 uint16_t fBufferSize ; 00690 /*! 00691 * Uplink datarate, if ADR is off 00692 */ 00693 //int8_t Datarate; 00694 /*! 00695 * Number of trials to transmit the frame, if the LoRaMAC layer did not 00696 * receive an acknowledgment. The MAC performs a datarate adaptation, 00697 * according to the LoRaWAN Specification V1.0.1, chapter 19.4, according 00698 * to the following table: 00699 * 00700 * Transmission nb | Data Rate 00701 * ----------------|----------- 00702 * 1 (first) | DR 00703 * 2 | DR 00704 * 3 | max(DR-1,0) 00705 * 4 | max(DR-1,0) 00706 * 5 | max(DR-2,0) 00707 * 6 | max(DR-2,0) 00708 * 7 | max(DR-3,0) 00709 * 8 | max(DR-3,0) 00710 * 00711 * Note, that if NbTrials is set to 1 or 2, the MAC will not decrease 00712 * the datarate, in case the LoRaMAC layer did not receive an acknowledgment 00713 */ 00714 uint8_t NbTrials ; 00715 }McpsReqConfirmed_t ; 00716 00717 /*! 00718 * LoRaMAC MCPS-Request for a proprietary frame 00719 */ 00720 typedef struct sMcpsReqProprietary 00721 { 00722 /*! 00723 * Pointer to the buffer of the frame payload 00724 */ 00725 void *fBuffer ; 00726 /*! 00727 * Size of the frame payload 00728 */ 00729 uint16_t fBufferSize ; 00730 /*! 00731 * Uplink datarate, if ADR is off 00732 */ 00733 //int8_t Datarate; 00734 }McpsReqProprietary_t ; 00735 00736 /*! 00737 * LoRaMAC MCPS-Request structure 00738 */ 00739 typedef struct sMcpsReq 00740 { 00741 /*! 00742 * MCPS-Request type 00743 */ 00744 Mcps_t Type ; 00745 00746 /*! 00747 * MCPS-Request parameters 00748 */ 00749 union uMcpsParam 00750 { 00751 /*! 00752 * MCPS-Request parameters for an unconfirmed frame 00753 */ 00754 McpsReqUnconfirmed_t Unconfirmed ; 00755 /*! 00756 * MCPS-Request parameters for a confirmed frame 00757 */ 00758 McpsReqConfirmed_t Confirmed ; 00759 /*! 00760 * MCPS-Request parameters for a proprietary frame 00761 */ 00762 McpsReqProprietary_t Proprietary ; 00763 }Req; 00764 }McpsReq_t ; 00765 00766 /*! 00767 * LoRaMAC MCPS-Confirm 00768 */ 00769 typedef struct sMcpsConfirm 00770 { 00771 /*! 00772 * Holds the previously performed MCPS-Request 00773 */ 00774 Mcps_t McpsRequest ; 00775 /*! 00776 * Status of the operation 00777 */ 00778 LoRaMacEventInfoStatus_t Status ; 00779 /*! 00780 * Uplink datarate 00781 */ 00782 //uint8_t Datarate; 00783 /*! 00784 * Transmission power 00785 */ 00786 int8_t TxPower ; 00787 /*! 00788 * Set if an acknowledgement was received 00789 */ 00790 bool AckReceived ; 00791 /*! 00792 * Provides the number of retransmissions 00793 */ 00794 //uint8_t NbRetries; 00795 /*! 00796 * The transmission time on air of the frame 00797 * 00798 uint32_t TxTimeOnAir;*/ 00799 /*! 00800 * The uplink counter value related to the frame 00801 */ 00802 uint32_t UpLinkCounter ; 00803 /*! 00804 * The uplink frequency related to the frame 00805 */ 00806 uint32_t UpLinkFrequency ; 00807 }McpsConfirm_t ; 00808 00809 /*! 00810 * LoRaMAC MCPS-Indication primitive 00811 */ 00812 typedef struct sMcpsIndication 00813 { 00814 /*! 00815 * MCPS-Indication type 00816 */ 00817 Mcps_t McpsIndication ; 00818 /*! 00819 * Status of the operation 00820 */ 00821 LoRaMacEventInfoStatus_t Status ; 00822 /*! 00823 * Multicast 00824 */ 00825 uint8_t Multicast ; 00826 /*! 00827 * Application port 00828 */ 00829 uint8_t Port ; 00830 /*! 00831 * Downlink datarate 00832 */ 00833 uint8_t RxDatarate ; 00834 /*! 00835 * Frame pending status 00836 */ 00837 uint8_t FramePending ; 00838 /*! 00839 * Pointer to the received data stream 00840 */ 00841 uint8_t *Buffer ; 00842 /*! 00843 * Size of the received data stream 00844 */ 00845 uint8_t BufferSize ; 00846 /*! 00847 * Indicates, if data is available 00848 */ 00849 bool RxData ; 00850 /*! 00851 * Rssi of the received packet 00852 */ 00853 int16_t Rssi ; 00854 /*! 00855 * Snr of the received packet 00856 */ 00857 uint8_t Snr ; 00858 /*! 00859 * Receive window 00860 * 00861 * [0: Rx window 1, 1: Rx window 2] 00862 */ 00863 //uint8_t RxSlot; 00864 /*! 00865 * Set if an acknowledgement was received 00866 */ 00867 bool AckReceived ; 00868 /*! 00869 * The downlink counter value for the received frame 00870 */ 00871 uint32_t DownLinkCounter ; 00872 }McpsIndication_t ; 00873 00874 /*! 00875 * \brief LoRaMAC management services 00876 * 00877 * \details The following table list the primitives which are supported by the 00878 * specific MAC management service: 00879 * 00880 * Name | Request | Indication | Response | Confirm 00881 * --------------------- | :-----: | :--------: | :------: | :-----: 00882 * \ref MLME_JOIN | YES | NO | NO | YES 00883 * \ref MLME_LINK_CHECK | YES | NO | NO | YES 00884 * \ref MLME_TXCW | YES | NO | NO | YES 00885 * 00886 * The following table provides links to the function implementations of the 00887 * related MLME primitives. 00888 * 00889 * Primitive | Function 00890 * ---------------- | :---------------------: 00891 * MLME-Request | \ref LoRaMacMlmeRequest 00892 * MLME-Confirm | MacMlmeConfirm in \ref LoRaMacPrimitives_t 00893 */ 00894 typedef enum eMlme 00895 { 00896 /*! 00897 * Initiates the Over-the-Air activation 00898 * 00899 * LoRaWAN Specification V1.0.1, chapter 6.2 00900 */ 00901 MLME_JOIN, 00902 /*! 00903 * LinkCheckReq - Connectivity validation 00904 * 00905 * LoRaWAN Specification V1.0.1, chapter 5, table 4 00906 */ 00907 MLME_LINK_CHECK, 00908 /*! 00909 * Sets Tx continuous wave mode 00910 * 00911 * LoRaWAN end-device certification 00912 */ 00913 MLME_TXCW, 00914 /*! 00915 * Sets Tx continuous wave mode (new LoRa-Alliance CC definition) 00916 * 00917 * LoRaWAN end-device certification 00918 */ 00919 MLME_TXCW_1, 00920 00921 MLME_TXDONE, 00922 00923 MLME_BEACON 00924 }Mlme_t; 00925 00926 /*! 00927 * LoRaMAC MLME-Request for the join service 00928 */ 00929 typedef struct sMlmeReqJoin 00930 { 00931 /*! 00932 * Globally unique end-device identifier 00933 * 00934 * LoRaWAN Specification V1.0.1, chapter 6.2.1 00935 */ 00936 uint8_t *DevEui ; 00937 /*! 00938 * Application identifier 00939 * 00940 * LoRaWAN Specification V1.0.1, chapter 6.1.2 00941 */ 00942 uint8_t *AppEui ; 00943 /*! 00944 * AES-128 application key 00945 * 00946 * LoRaWAN Specification V1.0.1, chapter 6.2.2 00947 */ 00948 uint8_t *AppKey ; 00949 /*! 00950 * Number of trials for the join request. 00951 */ 00952 uint8_t NbTrials ; 00953 }MlmeReqJoin_t ; 00954 00955 /*! 00956 * LoRaMAC MLME-Request for Tx continuous wave mode 00957 */ 00958 typedef struct sMlmeReqTxCw 00959 { 00960 /*! 00961 * Time in seconds while the radio is kept in continuous wave mode 00962 */ 00963 uint16_t Timeout ; 00964 /*! 00965 * RF frequency to set (Only used with new way) 00966 */ 00967 uint32_t Frequency ; 00968 /*! 00969 * RF output power to set (Only used with new way) 00970 */ 00971 uint8_t Power ; 00972 }MlmeReqTxCw_t ; 00973 00974 /*! 00975 * LoRaMAC MLME-Request structure 00976 */ 00977 typedef struct sMlmeReq 00978 { 00979 /*! 00980 * MLME-Request type 00981 */ 00982 Mlme_t Type ; 00983 00984 /*! 00985 * MLME-Request parameters 00986 */ 00987 union uMlmeParam 00988 { 00989 /*! 00990 * MLME-Request parameters for a join request 00991 */ 00992 MlmeReqJoin_t Join ; 00993 /*! 00994 * MLME-Request parameters for Tx continuous mode request 00995 */ 00996 MlmeReqTxCw_t TxCw ; 00997 }Req; 00998 }MlmeReq_t ; 00999 01000 /*! 01001 * LoRaMAC MLME-Confirm primitive 01002 */ 01003 typedef struct sMlmeConfirm 01004 { 01005 /*! 01006 * Holds the previously performed MLME-Request 01007 */ 01008 Mlme_t MlmeRequest ; 01009 /*! 01010 * Status of the operation 01011 */ 01012 LoRaMacEventInfoStatus_t Status ; 01013 /*! 01014 * The transmission time on air of the frame 01015 * 01016 uint32_t TxTimeOnAir;*/ 01017 /*! 01018 * Demodulation margin. Contains the link margin [dB] of the last 01019 * successfully received LinkCheckReq 01020 */ 01021 uint8_t DemodMargin ; 01022 /*! 01023 * Number of gateways which received the last LinkCheckReq 01024 */ 01025 uint8_t NbGateways ; 01026 /*! 01027 * Provides the number of retransmissions 01028 */ 01029 //uint8_t NbRetries; 01030 }MlmeConfirm_t ; 01031 01032 typedef struct sMlmeIndication 01033 { 01034 /*! 01035 * Holds the previously performed MLME-Request 01036 */ 01037 Mlme_t MlmeIndication; 01038 /*! 01039 * Status of the operation 01040 */ 01041 LoRaMacEventInfoStatus_t Status; 01042 01043 //BeaconInfo_t BeaconInfo; 01044 }MlmeIndication_t; 01045 01046 /*! 01047 * LoRa Mac Information Base (MIB) 01048 * 01049 * The following table lists the MIB parameters and the related attributes: 01050 * 01051 * Attribute | Get | Set 01052 * --------------------------------- | :-: | :-: 01053 * \ref MIB_DEVICE_CLASS | YES | YES 01054 * \ref MIB_NETWORK_JOINED | YES | YES 01055 * \ref MIB_ADR | YES | YES 01056 * \ref MIB_NET_ID | YES | YES 01057 * \ref MIB_DEV_ADDR | YES | YES 01058 * \ref MIB_NWK_SKEY | YES | YES 01059 * \ref MIB_APP_SKEY | YES | YES 01060 * \ref MIB_PUBLIC_NETWORK | YES | YES 01061 * \ref MIB_REPEATER_SUPPORT | YES | YES 01062 * \ref MIB_CHANNELS | YES | NO 01063 * \ref MIB_RX2_CHANNEL | YES | YES 01064 * \ref MIB_CHANNELS_MASK | YES | YES 01065 * \ref MIB_CHANNELS_DEFAULT_MASK | YES | YES 01066 * \ref MIB_CHANNELS_NB_REP | YES | YES 01067 * \ref MIB_MAX_RX_WINDOW_DURATION | YES | YES 01068 * \ref MIB_RECEIVE_DELAY_1 | YES | YES 01069 * \ref MIB_RECEIVE_DELAY_2 | YES | YES 01070 * \ref MIB_JOIN_ACCEPT_DELAY_1 | YES | YES 01071 * \ref MIB_JOIN_ACCEPT_DELAY_2 | YES | YES 01072 * \ref MIB_CHANNELS_DATARATE | YES | YES 01073 * \ref MIB_CHANNELS_DEFAULT_DATARATE| YES | YES 01074 * \ref MIB_CHANNELS_TX_POWER | YES | YES 01075 * \ref MIB_CHANNELS_DEFAULT_TX_POWER| YES | YES 01076 * \ref MIB_UPLINK_COUNTER | YES | YES 01077 * \ref MIB_DOWNLINK_COUNTER | YES | YES 01078 * \ref MIB_MULTICAST_CHANNEL | YES | NO 01079 * \ref MIB_SYSTEM_MAX_RX_ERROR | YES | YES 01080 * \ref MIB_MIN_RX_SYMBOLS | YES | YES 01081 * 01082 * The following table provides links to the function implementations of the 01083 * related MIB primitives: 01084 * 01085 * Primitive | Function 01086 * ---------------- | :---------------------: 01087 * MIB-Set | \ref LoRaMacMibSetRequestConfirm 01088 * MIB-Get | \ref LoRaMacMibGetRequestConfirm 01089 */ 01090 typedef enum eMib 01091 { 01092 /*! 01093 * LoRaWAN device class 01094 * 01095 * LoRaWAN Specification V1.0.1 01096 */ 01097 //MIB_DEVICE_CLASS, 01098 /*! 01099 * LoRaWAN Network joined attribute 01100 * 01101 * LoRaWAN Specification V1.0.1 01102 */ 01103 MIB_NETWORK_JOINED, 01104 /*! 01105 * Adaptive data rate 01106 * 01107 * LoRaWAN Specification V1.0.1, chapter 4.3.1.1 01108 * 01109 * [true: ADR enabled, false: ADR disabled] 01110 */ 01111 /*! 01112 * Network identifier 01113 * 01114 * LoRaWAN Specification V1.0.1, chapter 6.1.1 01115 */ 01116 MIB_NET_ID, 01117 /*! 01118 * End-device address 01119 * 01120 * LoRaWAN Specification V1.0.1, chapter 6.1.1 01121 */ 01122 MIB_DEV_ADDR, 01123 /*! 01124 * Network session key 01125 * 01126 * LoRaWAN Specification V1.0.1, chapter 6.1.3 01127 */ 01128 MIB_NWK_SKEY, 01129 /*! 01130 * Application session key 01131 * 01132 * LoRaWAN Specification V1.0.1, chapter 6.1.4 01133 */ 01134 MIB_APP_SKEY, 01135 /*! 01136 * Set the network type to public or private 01137 * 01138 * LoRaWAN Specification V1.0.1, chapter 7 01139 * 01140 * [true: public network, false: private network] 01141 */ 01142 MIB_PUBLIC_NETWORK, 01143 /*! 01144 * Support the operation with repeaters 01145 * 01146 * LoRaWAN Specification V1.0.1, chapter 7 01147 * 01148 * [true: repeater support enabled, false: repeater support disabled] 01149 */ 01150 //MIB_REPEATER_SUPPORT, 01151 /*! 01152 * Communication channels. A get request will return a 01153 * pointer which references the first entry of the channel list. The 01154 * list is of size LORA_MAX_NB_CHANNELS 01155 * 01156 * LoRaWAN Specification V1.0.1, chapter 7 01157 */ 01158 //MIB_CHANNELS, 01159 /*! 01160 * Set receive window 2 channel 01161 * 01162 * LoRaWAN Specification V1.0.1, chapter 3.3.2 01163 */ 01164 /*! 01165 * Set receive window 2 channel 01166 * 01167 * LoRaWAN Specification V1.0.1, chapter 3.3.2 01168 */ 01169 /*! 01170 * LoRaWAN channels mask 01171 * 01172 * LoRaWAN Specification V1.0.1, chapter 7 01173 */ 01174 /*! 01175 * LoRaWAN default channels mask 01176 * 01177 * LoRaWAN Specification V1.0.1, chapter 7 01178 */ 01179 //MIB_CHANNELS_DEFAULT_MASK, 01180 /*! 01181 * Set the number of repetitions on a channel 01182 * 01183 * LoRaWAN Specification V1.0.1, chapter 5.2 01184 */ 01185 MIB_CHANNELS_NB_REP, 01186 /*! 01187 * Maximum receive window duration in [ms] 01188 * 01189 * LoRaWAN Specification V1.0.1, chapter 3.3.3 01190 */ 01191 MIB_MAX_RX_WINDOW_DURATION, 01192 /*! 01193 * Receive delay 1 in [ms] 01194 * 01195 * LoRaWAN Specification V1.0.1, chapter 7 01196 */ 01197 MIB_RECEIVE_DELAY_1, 01198 /*! 01199 * Receive delay 2 in [ms] 01200 * 01201 * LoRaWAN Specification V1.0.1, chapter 7 01202 */ 01203 /*! 01204 * Join accept delay 1 in [ms] 01205 * 01206 * LoRaWAN Specification V1.0.1, chapter 7 01207 */ 01208 MIB_JOIN_ACCEPT_DELAY_1, 01209 /*! 01210 * Join accept delay 2 in [ms] 01211 * 01212 * LoRaWAN Specification V1.0.1, chapter 7 01213 */ 01214 /*! 01215 * Default Data rate of a channel 01216 * 01217 * LoRaWAN Specification V1.0.1, chapter 7 01218 * 01219 * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7] 01220 * 01221 * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_8, DR_9, DR_10, DR_11, DR_12, DR_13] 01222 */ 01223 /*! 01224 * Data rate of a channel 01225 * 01226 * LoRaWAN Specification V1.0.1, chapter 7 01227 * 01228 * EU868 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_5, DR_6, DR_7] 01229 * 01230 * US915 - [DR_0, DR_1, DR_2, DR_3, DR_4, DR_8, DR_9, DR_10, DR_11, DR_12, DR_13] 01231 */ 01232 /*! 01233 * Transmission power of a channel 01234 * 01235 * LoRaWAN Specification V1.0.1, chapter 7 01236 * 01237 * EU868 - [TX_POWER_20_DBM, TX_POWER_14_DBM, TX_POWER_11_DBM, 01238 * TX_POWER_08_DBM, TX_POWER_05_DBM, TX_POWER_02_DBM] 01239 * 01240 * US915 - [TX_POWER_30_DBM, TX_POWER_28_DBM, TX_POWER_26_DBM, 01241 * TX_POWER_24_DBM, TX_POWER_22_DBM, TX_POWER_20_DBM, 01242 * TX_POWER_18_DBM, TX_POWER_14_DBM, TX_POWER_12_DBM, 01243 * TX_POWER_10_DBM] 01244 */ 01245 MIB_CHANNELS_TX_POWER, 01246 /*! 01247 * Transmission power of a channel 01248 * 01249 * LoRaWAN Specification V1.0.1, chapter 7 01250 * 01251 * EU868 - [TX_POWER_20_DBM, TX_POWER_14_DBM, TX_POWER_11_DBM, 01252 * TX_POWER_08_DBM, TX_POWER_05_DBM, TX_POWER_02_DBM] 01253 * 01254 * US915 - [TX_POWER_30_DBM, TX_POWER_28_DBM, TX_POWER_26_DBM, 01255 * TX_POWER_24_DBM, TX_POWER_22_DBM, TX_POWER_20_DBM, 01256 * TX_POWER_18_DBM, TX_POWER_14_DBM, TX_POWER_12_DBM, 01257 * TX_POWER_10_DBM] 01258 */ 01259 MIB_CHANNELS_DEFAULT_TX_POWER, 01260 /*! 01261 * LoRaWAN Up-link counter 01262 * 01263 * LoRaWAN Specification V1.0.1, chapter 4.3.1.5 01264 */ 01265 MIB_UPLINK_COUNTER, 01266 /*! 01267 * LoRaWAN Down-link counter 01268 * 01269 * LoRaWAN Specification V1.0.1, chapter 4.3.1.5 01270 */ 01271 MIB_DOWNLINK_COUNTER, 01272 /*! 01273 * Multicast channels. A get request will return a pointer to the first 01274 * entry of the multicast channel linked list. If the pointer is equal to 01275 * NULL, the list is empty. 01276 */ 01277 MIB_MULTICAST_CHANNEL, 01278 /*! 01279 * System overall timing error in milliseconds. 01280 * [-SystemMaxRxError : +SystemMaxRxError] 01281 * Default: +/-10 ms 01282 */ 01283 MIB_SYSTEM_MAX_RX_ERROR, 01284 /*! 01285 * Minimum required number of symbols to detect an Rx frame 01286 * Default: 6 symbols 01287 */ 01288 MIB_MIN_RX_SYMBOLS, 01289 }Mib_t; 01290 01291 /*! 01292 * LoRaMAC MIB parameters 01293 */ 01294 typedef union uMibParam 01295 { 01296 /*! 01297 * LoRaWAN device class 01298 * 01299 * Related MIB type: \ref MIB_DEVICE_CLASS 01300 */ 01301 DeviceClass_t Class ; 01302 /*! 01303 * LoRaWAN network joined attribute 01304 * 01305 * Related MIB type: \ref MIB_NETWORK_JOINED 01306 */ 01307 bool IsNetworkJoined ; 01308 /*! 01309 * Activation state of ADR 01310 * 01311 * Related MIB type: \ref MIB_ADR 01312 */ 01313 /*! 01314 * Network identifier 01315 * 01316 * Related MIB type: \ref MIB_NET_ID 01317 */ 01318 uint32_t NetID ; 01319 /*! 01320 * End-device address 01321 * 01322 * Related MIB type: \ref MIB_DEV_ADDR 01323 */ 01324 uint32_t DevAddr ; 01325 /*! 01326 * Network session key 01327 * 01328 * Related MIB type: \ref MIB_NWK_SKEY 01329 */ 01330 uint8_t *NwkSKey ; 01331 /*! 01332 * Application session key 01333 * 01334 * Related MIB type: \ref MIB_APP_SKEY 01335 */ 01336 uint8_t *AppSKey ; 01337 /*! 01338 * Enable or disable a public network 01339 * 01340 * Related MIB type: \ref MIB_PUBLIC_NETWORK 01341 */ 01342 bool EnablePublicNetwork ; 01343 /*! 01344 * Number of frame repetitions 01345 * 01346 * Related MIB type: \ref MIB_CHANNELS_NB_REP 01347 */ 01348 uint8_t ChannelNbRep ; 01349 /*! 01350 * Maximum receive window duration 01351 * 01352 * Related MIB type: \ref MIB_MAX_RX_WINDOW_DURATION 01353 */ 01354 uint32_t MaxRxWindow ; 01355 01356 uint32_t ReceiveDelay; 01357 uint32_t JoinAcceptDelay; 01358 01359 /*! 01360 * Channels data rate 01361 * 01362 * Related MIB type: \ref MIB_CHANNELS_DEFAULT_DATARATE 01363 */ 01364 //int8_t ChannelsDefaultDatarate; 01365 /*! 01366 * Channels data rate 01367 * 01368 * Related MIB type: \ref MIB_CHANNELS_DATARATE 01369 */ 01370 //int8_t ChannelsDatarate; 01371 /*! 01372 * Channels TX power 01373 * 01374 * Related MIB type: \ref MIB_CHANNELS_DEFAULT_TX_POWER 01375 */ 01376 int8_t ChannelsDefaultTxPower ; 01377 /*! 01378 * Channels TX power 01379 * 01380 * Related MIB type: \ref MIB_CHANNELS_TX_POWER 01381 */ 01382 int8_t ChannelsTxPower ; 01383 /*! 01384 * LoRaWAN Up-link counter 01385 * 01386 * Related MIB type: \ref MIB_UPLINK_COUNTER 01387 */ 01388 uint32_t UpLinkCounter ; 01389 /*! 01390 * LoRaWAN Down-link counter 01391 * 01392 * Related MIB type: \ref MIB_DOWNLINK_COUNTER 01393 */ 01394 uint32_t DownLinkCounter ; 01395 /*! 01396 * Multicast channel 01397 * 01398 * Related MIB type: \ref MIB_MULTICAST_CHANNEL 01399 */ 01400 MulticastParams_t * MulticastList ; 01401 /*! 01402 * System overall timing error in milliseconds. 01403 * 01404 * Related MIB type: \ref MIB_SYSTEM_MAX_RX_ERROR 01405 */ 01406 uint32_t SystemMaxRxError_ms ; 01407 /*! 01408 * Minimum required number of symbols to detect an Rx frame 01409 * 01410 * Related MIB type: \ref MIB_MIN_RX_SYMBOLS 01411 */ 01412 uint8_t MinRxSymbols ; 01413 }MibParam_t ; 01414 01415 /*! 01416 * LoRaMAC MIB-RequestConfirm structure 01417 */ 01418 typedef struct eMibRequestConfirm 01419 { 01420 /*! 01421 * MIB-Request type 01422 */ 01423 Mib_t Type ; 01424 01425 /*! 01426 * MLME-RequestConfirm parameters 01427 */ 01428 MibParam_t Param ; 01429 }MibRequestConfirm_t ; 01430 01431 /*! 01432 * LoRaMAC tx information 01433 */ 01434 typedef struct sLoRaMacTxInfo 01435 { 01436 /*! 01437 * Defines the size of the applicative payload which can be processed 01438 */ 01439 uint8_t MaxPossiblePayload ; 01440 /*! 01441 * The current payload size, dependent on the current datarate 01442 */ 01443 uint8_t CurrentPayloadSize ; 01444 }LoRaMacTxInfo_t ; 01445 01446 /*! 01447 * LoRaMAC Status 01448 */ 01449 typedef enum eLoRaMacStatus 01450 { 01451 /*! 01452 * Service started successfully 01453 */ 01454 LORAMAC_STATUS_OK, 01455 /*! 01456 * Service not started - LoRaMAC is busy 01457 */ 01458 LORAMAC_STATUS_BUSY, 01459 /*! 01460 * Service unknown 01461 */ 01462 LORAMAC_STATUS_SERVICE_UNKNOWN, 01463 /*! 01464 * Service not started - invalid parameter 01465 */ 01466 LORAMAC_STATUS_PARAMETER_INVALID, 01467 /*! 01468 * Service not started - invalid frequency 01469 */ 01470 LORAMAC_STATUS_FREQUENCY_INVALID, 01471 /*! 01472 * Service not started - invalid datarate 01473 */ 01474 LORAMAC_STATUS_DATARATE_INVALID, 01475 /*! 01476 * Service not started - invalid frequency and datarate 01477 */ 01478 LORAMAC_STATUS_FREQ_AND_DR_INVALID, 01479 /*! 01480 * Service not started - the device is not in a LoRaWAN 01481 */ 01482 LORAMAC_STATUS_NO_NETWORK_JOINED, 01483 /*! 01484 * Service not started - payload lenght error 01485 */ 01486 LORAMAC_STATUS_LENGTH_ERROR, 01487 /*! 01488 * Service not started - payload lenght error 01489 */ 01490 LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR, 01491 /*! 01492 * Service not started - the device is switched off 01493 */ 01494 LORAMAC_STATUS_DEVICE_OFF, 01495 } LoRaMacStatus_t; 01496 01497 /*! 01498 * LoRaMAC events structure 01499 * Used to notify upper layers of MAC events 01500 */ 01501 typedef struct sLoRaMacPrimitives 01502 { 01503 /*! 01504 * \brief MCPS-Confirm primitive 01505 * 01506 * \param [OUT] MCPS-Confirm parameters 01507 */ 01508 void ( *MacMcpsConfirm )( McpsConfirm_t *McpsConfirm ); 01509 /*! 01510 * \brief MCPS-Indication primitive 01511 * 01512 * \param [OUT] MCPS-Indication parameters 01513 */ 01514 void ( *MacMcpsIndication )( McpsIndication_t *McpsIndication ); 01515 /*! 01516 * \brief MLME-Confirm primitive 01517 * 01518 * \param [OUT] MLME-Confirm parameters 01519 */ 01520 void ( *MacMlmeConfirm )( MlmeConfirm_t *MlmeConfirm ); 01521 01522 /*! 01523 * \brief MLME-Indication primitive 01524 * 01525 * \param [OUT] MLME-Indication parameters 01526 */ 01527 void ( *MacMlmeIndication )( MlmeIndication_t *MlmeIndication ); 01528 }LoRaMacPrimitives_t ; 01529 01530 typedef struct sLoRaMacCallback 01531 { 01532 /*! 01533 * \brief Measures the battery level 01534 * 01535 * \retval Battery level [0: node is connected to an external 01536 * power source, 1..254: battery level, where 1 is the minimum 01537 * and 254 is the maximum value, 255: the node was not able 01538 * to measure the battery level] 01539 */ 01540 uint8_t ( *GetBatteryLevel )( void ); 01541 }LoRaMacCallback_t; 01542 01543 /*! 01544 * \brief LoRaMAC layer initialization 01545 * 01546 * \details In addition to the initialization of the LoRaMAC layer, this 01547 * function initializes the callback primitives of the MCPS and 01548 * MLME services. Every data field of \ref LoRaMacPrimitives_t must be 01549 * set to a valid callback function. 01550 * 01551 * \param [IN] events - Pointer to a structure defining the LoRaMAC 01552 * event functions. Refer to \ref LoRaMacPrimitives_t. 01553 * 01554 * \param [IN] events - Pointer to a structure defining the LoRaMAC 01555 * callback functions. Refer to \ref LoRaMacCallback_t. 01556 * 01557 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01558 * returns are: 01559 * \ref LORAMAC_STATUS_OK, 01560 * \ref LORAMAC_STATUS_PARAMETER_INVALID. 01561 */ 01562 LoRaMacStatus_t LoRaMacInitialization( LoRaMacPrimitives_t *primitives, LoRaMacCallback_t *callbacks ); 01563 01564 /*! 01565 * \brief Queries the LoRaMAC if it is possible to send the next frame with 01566 * a given payload size. The LoRaMAC takes scheduled MAC commands into 01567 * account and reports, when the frame can be send or not. 01568 * 01569 * \param [IN] size - Size of applicative payload to be send next 01570 * 01571 * \param [OUT] txInfo - The structure \ref LoRaMacTxInfo_t contains 01572 * information about the actual maximum payload possible 01573 * ( according to the configured datarate or the next 01574 * datarate according to ADR ), and the maximum frame 01575 * size, taking the scheduled MAC commands into account. 01576 * 01577 * \retval LoRaMacStatus_t Status of the operation. When the parameters are 01578 * not valid, the function returns \ref LORAMAC_STATUS_PARAMETER_INVALID. 01579 * In case of a length error caused by the applicative payload size, the 01580 * function returns LORAMAC_STATUS_LENGTH_ERROR. In case of a length error 01581 * due to additional MAC commands in the queue, the function returns 01582 * LORAMAC_STATUS_MAC_CMD_LENGTH_ERROR. In case the query is valid, and 01583 * the LoRaMAC is able to send the frame, the function returns LORAMAC_STATUS_OK. * 01584 */ 01585 LoRaMacStatus_t LoRaMacQueryTxPossible( uint8_t size, LoRaMacTxInfo_t * txInfo ); 01586 01587 /*! 01588 * \brief LoRaMAC channel add service 01589 * 01590 * \details Adds a new channel to the channel list and activates the id in 01591 * the channel mask. For the US915 band, all channels are enabled 01592 * by default. It is not possible to activate less than 6 125 kHz 01593 * channels. 01594 * 01595 * \param [IN] id - Id of the channel. Possible values are: 01596 * 01597 * 0-15 for EU868 01598 * 0-72 for US915 01599 * 01600 * \param [IN] params - Channel parameters to set. 01601 * 01602 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01603 * \ref LORAMAC_STATUS_OK, 01604 * \ref LORAMAC_STATUS_BUSY, 01605 * \ref LORAMAC_STATUS_PARAMETER_INVALID. 01606 */ 01607 LoRaMacStatus_t LoRaMacChannelAdd( uint8_t id, ChannelParams_t params ); 01608 01609 /*! 01610 * \brief LoRaMAC channel remove service 01611 * 01612 * \details Deactivates the id in the channel mask. 01613 * 01614 * \param [IN] id - Id of the channel. 01615 * 01616 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01617 * \ref LORAMAC_STATUS_OK, 01618 * \ref LORAMAC_STATUS_BUSY, 01619 * \ref LORAMAC_STATUS_PARAMETER_INVALID. 01620 */ 01621 LoRaMacStatus_t LoRaMacChannelRemove( uint8_t id ); 01622 01623 /*! 01624 * \brief LoRaMAC multicast channel link service 01625 * 01626 * \details Links a multicast channel into the linked list. 01627 * 01628 * \param [IN] channelParam - Multicast channel parameters to link. 01629 * 01630 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01631 * \ref LORAMAC_STATUS_OK, 01632 * \ref LORAMAC_STATUS_BUSY, 01633 * \ref LORAMAC_STATUS_PARAMETER_INVALID. 01634 */ 01635 LoRaMacStatus_t LoRaMacMulticastChannelLink( MulticastParams_t *channelParam ); 01636 01637 /*! 01638 * \brief LoRaMAC multicast channel unlink service 01639 * 01640 * \details Unlinks a multicast channel from the linked list. 01641 * 01642 * \param [IN] channelParam - Multicast channel parameters to unlink. 01643 * 01644 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01645 * \ref LORAMAC_STATUS_OK, 01646 * \ref LORAMAC_STATUS_BUSY, 01647 * \ref LORAMAC_STATUS_PARAMETER_INVALID. 01648 */ 01649 LoRaMacStatus_t LoRaMacMulticastChannelUnlink( MulticastParams_t *channelParam ); 01650 01651 /*! 01652 * \brief LoRaMAC MIB-Get 01653 * 01654 * \details The mac information base service to get attributes of the LoRaMac 01655 * layer. 01656 * 01657 * The following code-snippet shows how to use the API to get the 01658 * parameter AdrEnable, defined by the enumeration type 01659 * \ref MIB_ADR. 01660 * \code 01661 * MibRequestConfirm_t mibReq; 01662 * mibReq.Type = MIB_ADR; 01663 * 01664 * if( LoRaMacMibGetRequestConfirm( &mibReq ) == LORAMAC_STATUS_OK ) 01665 * { 01666 * // LoRaMAC updated the parameter mibParam.AdrEnable 01667 * } 01668 * \endcode 01669 * 01670 * \param [IN] mibRequest - MIB-GET-Request to perform. Refer to \ref MibRequestConfirm_t. 01671 * 01672 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01673 * \ref LORAMAC_STATUS_OK, 01674 * \ref LORAMAC_STATUS_SERVICE_UNKNOWN, 01675 * \ref LORAMAC_STATUS_PARAMETER_INVALID. 01676 */ 01677 LoRaMacStatus_t LoRaMacMibGetRequestConfirm( MibRequestConfirm_t *mibGet ); 01678 01679 /*! 01680 * \brief LoRaMAC MIB-Set 01681 * 01682 * \details The mac information base service to set attributes of the LoRaMac 01683 * layer. 01684 * 01685 * The following code-snippet shows how to use the API to set the 01686 * parameter AdrEnable, defined by the enumeration type 01687 * \ref MIB_ADR. 01688 * 01689 * \code 01690 * MibRequestConfirm_t mibReq; 01691 * mibReq.Type = MIB_ADR; 01692 * mibReq.Param.AdrEnable = true; 01693 * 01694 * if( LoRaMacMibGetRequestConfirm( &mibReq ) == LORAMAC_STATUS_OK ) 01695 * { 01696 * // LoRaMAC updated the parameter 01697 * } 01698 * \endcode 01699 * 01700 * \param [IN] mibRequest - MIB-SET-Request to perform. Refer to \ref MibRequestConfirm_t. 01701 * 01702 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01703 * \ref LORAMAC_STATUS_OK, 01704 * \ref LORAMAC_STATUS_BUSY, 01705 * \ref LORAMAC_STATUS_SERVICE_UNKNOWN, 01706 * \ref LORAMAC_STATUS_PARAMETER_INVALID. 01707 */ 01708 LoRaMacStatus_t LoRaMacMibSetRequestConfirm( MibRequestConfirm_t *mibSet ); 01709 01710 /*! 01711 * \brief LoRaMAC MLME-Request 01712 * 01713 * \details The Mac layer management entity handles management services. The 01714 * following code-snippet shows how to use the API to perform a 01715 * network join request. 01716 * 01717 * \code 01718 * static uint8_t DevEui[] = 01719 * { 01720 * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 01721 * }; 01722 * static uint8_t AppEui[] = 01723 * { 01724 * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 01725 * }; 01726 * static uint8_t AppKey[] = 01727 * { 01728 * 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 01729 * 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C 01730 * }; 01731 * 01732 * MlmeReq_t mlmeReq; 01733 * mlmeReq.Type = MLME_JOIN; 01734 * mlmeReq.Req.Join.DevEui = DevEui; 01735 * mlmeReq.Req.Join.AppEui = AppEui; 01736 * mlmeReq.Req.Join.AppKey = AppKey; 01737 * 01738 * if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK ) 01739 * { 01740 * // Service started successfully. Waiting for the Mlme-Confirm event 01741 * } 01742 * \endcode 01743 * 01744 * \param [IN] mlmeRequest - MLME-Request to perform. Refer to \ref MlmeReq_t. 01745 * 01746 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01747 * \ref LORAMAC_STATUS_OK, 01748 * \ref LORAMAC_STATUS_BUSY, 01749 * \ref LORAMAC_STATUS_SERVICE_UNKNOWN, 01750 * \ref LORAMAC_STATUS_PARAMETER_INVALID, 01751 * \ref LORAMAC_STATUS_NO_NETWORK_JOINED, 01752 * \ref LORAMAC_STATUS_LENGTH_ERROR, 01753 * \ref LORAMAC_STATUS_DEVICE_OFF. 01754 */ 01755 LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t *mlmeRequest ); 01756 01757 /*! 01758 * \brief LoRaMAC MCPS-Request 01759 * 01760 * \details The Mac Common Part Sublayer handles data services. The following 01761 * code-snippet shows how to use the API to send an unconfirmed 01762 * LoRaMAC frame. 01763 * 01764 * \code 01765 * uint8_t myBuffer[] = { 1, 2, 3 }; 01766 * 01767 * McpsReq_t mcpsReq; 01768 * mcpsReq.Type = MCPS_UNCONFIRMED; 01769 * mcpsReq.Req.Unconfirmed.fPort = 1; 01770 * mcpsReq.Req.Unconfirmed.fBuffer = myBuffer; 01771 * mcpsReq.Req.Unconfirmed.fBufferSize = sizeof( myBuffer ); 01772 * 01773 * if( LoRaMacMcpsRequest( &mcpsReq ) == LORAMAC_STATUS_OK ) 01774 * { 01775 * // Service started successfully. Waiting for the MCPS-Confirm event 01776 * } 01777 * \endcode 01778 * 01779 * \param [IN] mcpsRequest - MCPS-Request to perform. Refer to \ref McpsReq_t. 01780 * 01781 * \retval LoRaMacStatus_t Status of the operation. Possible returns are: 01782 * \ref LORAMAC_STATUS_OK, 01783 * \ref LORAMAC_STATUS_BUSY, 01784 * \ref LORAMAC_STATUS_SERVICE_UNKNOWN, 01785 * \ref LORAMAC_STATUS_PARAMETER_INVALID, 01786 * \ref LORAMAC_STATUS_NO_NETWORK_JOINED, 01787 * \ref LORAMAC_STATUS_LENGTH_ERROR, 01788 * \ref LORAMAC_STATUS_DEVICE_OFF. 01789 */ 01790 LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t *mcpsRequest ); 01791 01792 /*! \} defgroup LORAMAC */ 01793 01794 void loramac_print_status(void); 01795 01796 void LoRaMacBottomHalf(void); 01797 01798 #endif // __LORAMAC_H__
Generated on Wed Jul 13 2022 01:56:41 by
1.7.2