diff --git a/_lo_ra_w_a_n_8h_source.html b/_lo_ra_w_a_n_8h_source.html index e4e9019e..1eb9c104 100644 --- a/_lo_ra_w_a_n_8h_source.html +++ b/_lo_ra_w_a_n_8h_source.html @@ -460,369 +460,367 @@ $(document).ready(function(){initNavTree('_lo_ra_w_a_n_8h_source.html',''); init
436 // supported bands
437 extern const LoRaWANBand_t EU868;
438 extern const LoRaWANBand_t US915;
-
439 extern const LoRaWANBand_t CN780;
-
440 extern const LoRaWANBand_t EU433;
-
441 extern const LoRaWANBand_t AU915;
-
442 extern const LoRaWANBand_t CN500;
-
443 extern const LoRaWANBand_t AS923;
-
444 extern const LoRaWANBand_t AS923_2;
-
445 extern const LoRaWANBand_t AS923_3;
-
446 extern const LoRaWANBand_t AS923_4;
-
447 extern const LoRaWANBand_t KR920;
-
448 extern const LoRaWANBand_t IN865;
-
449 
-
454 enum LoRaWANBandNum_t {
-
455  BandEU868,
-
456  BandUS915,
-
457  BandCN780,
-
458  BandEU433,
-
459  BandAU915,
-
460  BandCN500,
-
461  BandAS923,
-
462  BandAS923_2,
-
463  BandAS923_3,
-
464  BandAS923_4,
-
465  BandKR920,
-
466  BandIN865,
-
467  BandLast
-
468 };
-
469 
-
470 // provide easy access to the number of currently supported bands
-
471 #define RADIOLIB_LORAWAN_NUM_SUPPORTED_BANDS (BandLast - BandEU868)
-
472 
-
473 // array of currently supported bands
-
474 extern const LoRaWANBand_t* LoRaWANBands[];
-
475 
-
480 struct LoRaWANJoinEvent_t {
-
482  bool newSession = false;
-
483 
-
485  uint16_t devNonce = 0;
-
486 
-
488  uint32_t joinNonce = 0;
-
489 };
-
490 
-
495 struct LoRaWANEvent_t {
-
497  uint8_t dir;
-
498 
-
500  bool confirmed;
-
501 
-
504  bool confirming;
-
505 
-
507  uint8_t datarate;
-
508 
-
510  float freq;
-
511 
-
513  int16_t power;
-
514 
-
516  uint32_t fCnt;
-
517 
-
519  uint8_t fPort;
-
520 };
-
521 
-
526 class LoRaWANNode {
-
527  public:
-
528 
-
535  LoRaWANNode(PhysicalLayer* phy, const LoRaWANBand_t* band, uint8_t subBand = 0);
-
536 
-
540  void clearSession();
-
541 
-
546  uint8_t* getBufferNonces();
-
547 
-
553  int16_t setBufferNonces(uint8_t* persistentBuffer);
-
554 
-
559  uint8_t* getBufferSession();
-
560 
-
566  int16_t setBufferSession(uint8_t* persistentBuffer);
-
567 
-
575  void beginOTAA(uint64_t joinEUI, uint64_t devEUI, uint8_t* nwkKey, uint8_t* appKey);
-
576 
-
583  int16_t activateOTAA(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED, LoRaWANJoinEvent_t *joinEvent = NULL);
-
584 
-
594  void beginABP(uint32_t addr, uint8_t* fNwkSIntKey, uint8_t* sNwkSIntKey, uint8_t* nwkSEncKey, uint8_t* appSKey);
-
595 
-
602  int16_t activateABP(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);
-
603 
-
605  bool isActivated();
-
606 
-
613  int16_t setRx2Dr(uint8_t dr);
-
614 
-
622  int16_t sendMacCommandReq(uint8_t cid);
-
623 
-
624  #if defined(RADIOLIB_BUILD_ARDUINO)
-
634  int16_t uplink(String& str, uint8_t fPort, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
-
635  #endif
-
636 
-
646  int16_t uplink(const char* str, uint8_t fPort, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
-
647 
-
658  int16_t uplink(uint8_t* data, size_t len, uint8_t fPort, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
-
659 
-
660  #if defined(RADIOLIB_BUILD_ARDUINO)
-
668  int16_t downlink(String& str, LoRaWANEvent_t* event = NULL);
-
669  #endif
-
670 
-
679  int16_t downlink(uint8_t* data, size_t* len, LoRaWANEvent_t* event = NULL);
-
680 
-
687  int16_t downlink(LoRaWANEvent_t* event = NULL);
-
688 
-
689  #if defined(RADIOLIB_BUILD_ARDUINO)
-
702  int16_t sendReceive(String& strUp, uint8_t fPort, String& strDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
-
703  #endif
-
704 
-
718  int16_t sendReceive(const char* strUp, uint8_t fPort, uint8_t* dataDown, size_t* lenDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
-
719 
-
734  int16_t sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t fPort, uint8_t* dataDown, size_t* lenDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
-
735 
-
748  int16_t sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t fPort = 1, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
-
749 
-
755  void setDeviceStatus(uint8_t battLevel);
-
756 
-
761  uint32_t getFCntUp();
-
762 
-
767  uint32_t getNFCntDown();
-
768 
-
773  uint32_t getAFCntDown();
-
774 
-
780  void resetFCntDown();
-
781 
-
787  int16_t setDatarate(uint8_t drUp);
-
788 
-
793  void setADR(bool enable = true);
-
794 
-
801  void setDutyCycle(bool enable = true, RadioLibTime_t msPerHour = 0);
-
802 
-
810  RadioLibTime_t dutyCycleInterval(RadioLibTime_t msPerHour, RadioLibTime_t airtime);
-
811 
-
813  RadioLibTime_t timeUntilUplink();
-
814 
-
821  void setDwellTime(bool enable, RadioLibTime_t msPerUplink = 0);
-
822 
-
828  uint8_t maxPayloadDwellTime();
-
829 
-
835  int16_t setTxPower(int8_t txPower);
-
836 
-
845  int16_t getMacLinkCheckAns(uint8_t* margin, uint8_t* gwCnt);
-
846 
-
856  int16_t getMacDeviceTimeAns(uint32_t* gpsEpoch, uint8_t* fraction, bool returnUnix = true);
-
857 
-
862  uint64_t getDevAddr();
-
863 
-
868  RadioLibTime_t getLastToA();
-
869 
-
874  bool TS009 = false;
-
875 
-
876 #if !RADIOLIB_GODMODE
-
877  private:
-
878 #endif
-
879  PhysicalLayer* phyLayer = NULL;
-
880  const LoRaWANBand_t* band = NULL;
+
439 extern const LoRaWANBand_t EU433;
+
440 extern const LoRaWANBand_t AU915;
+
441 extern const LoRaWANBand_t CN500;
+
442 extern const LoRaWANBand_t AS923;
+
443 extern const LoRaWANBand_t AS923_2;
+
444 extern const LoRaWANBand_t AS923_3;
+
445 extern const LoRaWANBand_t AS923_4;
+
446 extern const LoRaWANBand_t KR920;
+
447 extern const LoRaWANBand_t IN865;
+
448 
+
453 enum LoRaWANBandNum_t {
+
454  BandEU868,
+
455  BandUS915,
+
456  BandEU433,
+
457  BandAU915,
+
458  BandCN500,
+
459  BandAS923,
+
460  BandAS923_2,
+
461  BandAS923_3,
+
462  BandAS923_4,
+
463  BandKR920,
+
464  BandIN865,
+
465  BandLast
+
466 };
+
467 
+
468 // provide easy access to the number of currently supported bands
+
469 #define RADIOLIB_LORAWAN_NUM_SUPPORTED_BANDS (BandLast - BandEU868)
+
470 
+
471 // array of currently supported bands
+
472 extern const LoRaWANBand_t* LoRaWANBands[];
+
473 
+
478 struct LoRaWANJoinEvent_t {
+
480  bool newSession = false;
+
481 
+
483  uint16_t devNonce = 0;
+
484 
+
486  uint32_t joinNonce = 0;
+
487 };
+
488 
+
493 struct LoRaWANEvent_t {
+
495  uint8_t dir;
+
496 
+
498  bool confirmed;
+
499 
+
502  bool confirming;
+
503 
+
505  uint8_t datarate;
+
506 
+
508  float freq;
+
509 
+
511  int16_t power;
+
512 
+
514  uint32_t fCnt;
+
515 
+
517  uint8_t fPort;
+
518 };
+
519 
+
524 class LoRaWANNode {
+
525  public:
+
526 
+
533  LoRaWANNode(PhysicalLayer* phy, const LoRaWANBand_t* band, uint8_t subBand = 0);
+
534 
+
538  void clearSession();
+
539 
+
544  uint8_t* getBufferNonces();
+
545 
+
551  int16_t setBufferNonces(uint8_t* persistentBuffer);
+
552 
+
557  uint8_t* getBufferSession();
+
558 
+
564  int16_t setBufferSession(uint8_t* persistentBuffer);
+
565 
+
573  void beginOTAA(uint64_t joinEUI, uint64_t devEUI, uint8_t* nwkKey, uint8_t* appKey);
+
574 
+
581  int16_t activateOTAA(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED, LoRaWANJoinEvent_t *joinEvent = NULL);
+
582 
+
592  void beginABP(uint32_t addr, uint8_t* fNwkSIntKey, uint8_t* sNwkSIntKey, uint8_t* nwkSEncKey, uint8_t* appSKey);
+
593 
+
600  int16_t activateABP(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);
+
601 
+
603  bool isActivated();
+
604 
+
611  int16_t setRx2Dr(uint8_t dr);
+
612 
+
620  int16_t sendMacCommandReq(uint8_t cid);
+
621 
+
622  #if defined(RADIOLIB_BUILD_ARDUINO)
+
632  int16_t uplink(String& str, uint8_t fPort, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
+
633  #endif
+
634 
+
644  int16_t uplink(const char* str, uint8_t fPort, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
+
645 
+
656  int16_t uplink(uint8_t* data, size_t len, uint8_t fPort, bool isConfirmed = false, LoRaWANEvent_t* event = NULL);
+
657 
+
658  #if defined(RADIOLIB_BUILD_ARDUINO)
+
666  int16_t downlink(String& str, LoRaWANEvent_t* event = NULL);
+
667  #endif
+
668 
+
677  int16_t downlink(uint8_t* data, size_t* len, LoRaWANEvent_t* event = NULL);
+
678 
+
685  int16_t downlink(LoRaWANEvent_t* event = NULL);
+
686 
+
687  #if defined(RADIOLIB_BUILD_ARDUINO)
+
700  int16_t sendReceive(String& strUp, uint8_t fPort, String& strDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
+
701  #endif
+
702 
+
716  int16_t sendReceive(const char* strUp, uint8_t fPort, uint8_t* dataDown, size_t* lenDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
+
717 
+
732  int16_t sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t fPort, uint8_t* dataDown, size_t* lenDown, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
+
733 
+
746  int16_t sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t fPort = 1, bool isConfirmed = false, LoRaWANEvent_t* eventUp = NULL, LoRaWANEvent_t* eventDown = NULL);
+
747 
+
753  void setDeviceStatus(uint8_t battLevel);
+
754 
+
759  uint32_t getFCntUp();
+
760 
+
765  uint32_t getNFCntDown();
+
766 
+
771  uint32_t getAFCntDown();
+
772 
+
778  void resetFCntDown();
+
779 
+
785  int16_t setDatarate(uint8_t drUp);
+
786 
+
791  void setADR(bool enable = true);
+
792 
+
799  void setDutyCycle(bool enable = true, RadioLibTime_t msPerHour = 0);
+
800 
+
808  RadioLibTime_t dutyCycleInterval(RadioLibTime_t msPerHour, RadioLibTime_t airtime);
+
809 
+
811  RadioLibTime_t timeUntilUplink();
+
812 
+
819  void setDwellTime(bool enable, RadioLibTime_t msPerUplink = 0);
+
820 
+
826  uint8_t maxPayloadDwellTime();
+
827 
+
833  int16_t setTxPower(int8_t txPower);
+
834 
+
843  int16_t getMacLinkCheckAns(uint8_t* margin, uint8_t* gwCnt);
+
844 
+
854  int16_t getMacDeviceTimeAns(uint32_t* gpsEpoch, uint8_t* fraction, bool returnUnix = true);
+
855 
+
860  uint64_t getDevAddr();
+
861 
+
866  RadioLibTime_t getLastToA();
+
867 
+
872  bool TS009 = false;
+
873 
+
874 #if !RADIOLIB_GODMODE
+
875  private:
+
876 #endif
+
877  PhysicalLayer* phyLayer = NULL;
+
878  const LoRaWANBand_t* band = NULL;
+
879 
+
880  static int16_t checkBufferCommon(uint8_t *buffer, uint16_t size);
881 
-
882  static int16_t checkBufferCommon(uint8_t *buffer, uint16_t size);
+
882  void activateCommon(uint8_t initialDr);
883 
-
884  void activateCommon(uint8_t initialDr);
-
885 
-
886  // a buffer that holds all LW base parameters that should persist at all times!
-
887  uint8_t bufferNonces[RADIOLIB_LORAWAN_NONCES_BUF_SIZE] = { 0 };
-
888 
-
889  // a buffer that holds all LW session parameters that preferably persist, but can be afforded to get lost
-
890  uint8_t bufferSession[RADIOLIB_LORAWAN_SESSION_BUF_SIZE] = { 0 };
-
891 
-
892  LoRaWANMacCommandQueue_t commandsUp = {
-
893  .numCommands = 0,
-
894  .len = 0,
-
895  .commands = { { .cid = 0, .payload = { 0 }, .len = 0, .repeat = 0, } },
-
896  };
-
897  LoRaWANMacCommandQueue_t commandsDown = {
-
898  .numCommands = 0,
-
899  .len = 0,
-
900  .commands = { { .cid = 0, .payload = { 0 }, .len = 0, .repeat = 0, } },
-
901  };
-
902 
-
903  uint16_t lwMode = RADIOLIB_LORAWAN_MODE_NONE;
-
904  uint8_t lwClass = RADIOLIB_LORAWAN_CLASS_A;
-
905  bool isActive = false;
-
906 
-
907  uint64_t joinEUI = 0;
-
908  uint64_t devEUI = 0;
-
909  uint8_t nwkKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
-
910  uint8_t appKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
-
911 
-
912  // the following is either provided by the network server (OTAA)
-
913  // or directly entered by the user (ABP)
-
914  uint32_t devAddr = 0;
-
915  uint8_t appSKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
-
916  uint8_t fNwkSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
-
917  uint8_t sNwkSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
-
918  uint8_t nwkSEncKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
-
919  uint8_t jSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
-
920 
-
921  uint16_t keyCheckSum = 0;
-
922 
-
923  // device-specific parameters, persistent through sessions
-
924  uint16_t devNonce = 0;
-
925  uint32_t joinNonce = 0;
-
926 
-
927  // session-specific parameters
-
928  uint32_t homeNetId = 0;
-
929  uint8_t adrLimitExp = RADIOLIB_LORAWAN_ADR_ACK_LIMIT_EXP;
-
930  uint8_t adrDelayExp = RADIOLIB_LORAWAN_ADR_ACK_DELAY_EXP;
-
931  uint8_t nbTrans = 1; // Number of allowed frame retransmissions
-
932  uint8_t txPowerSteps = 0;
-
933  uint8_t txPowerMax = 0;
-
934  uint32_t fCntUp = 0;
-
935  uint32_t aFCntDown = 0;
-
936  uint32_t nFCntDown = 0;
-
937  uint32_t confFCntUp = RADIOLIB_LORAWAN_FCNT_NONE;
-
938  uint32_t confFCntDown = RADIOLIB_LORAWAN_FCNT_NONE;
-
939  uint32_t adrFCnt = 0;
-
940 
-
941  // modulation of the currently configured channel
-
942  uint8_t modulation = RADIOLIB_LORAWAN_MODULATION_LORA;
-
943 
-
944  // ADR is enabled by default
-
945  bool adrEnabled = true;
-
946 
-
947  // duty cycle is set upon initialization and activated in regions that impose this
-
948  bool dutyCycleEnabled = false;
-
949  uint32_t dutyCycle = 0;
-
950 
-
951  // dwell time is set upon initialization and activated in regions that impose this
-
952  bool dwellTimeEnabledUp = false;
-
953  uint16_t dwellTimeUp = 0;
-
954  bool dwellTimeEnabledDn = false;
-
955  uint16_t dwellTimeDn = 0;
-
956 
-
957  // enable/disable CSMA for LoRaWAN
-
958  bool enableCSMA;
-
959 
-
960  // number of backoff slots to be decremented after DIFS phase. 0 to disable BO.
-
961  // A random BO avoids collisions in the case where two or more nodes start the CSMA
-
962  // process at the same time.
-
963  uint8_t backoffMax;
-
964 
-
965  // number of CADs to estimate a clear CH
-
966  uint8_t difsSlots;
-
967 
-
968  // available channel frequencies from list passed during OTA activation
-
969  LoRaWANChannel_t availableChannels[2][RADIOLIB_LORAWAN_NUM_AVAILABLE_CHANNELS];
-
970 
-
971  // currently configured channels for TX and RX1
-
972  LoRaWANChannel_t currentChannels[2] = { RADIOLIB_LORAWAN_CHANNEL_NONE, RADIOLIB_LORAWAN_CHANNEL_NONE };
-
973 
-
974  // currently configured datarates for TX and RX1
-
975  uint8_t dataRates[2] = { RADIOLIB_LORAWAN_DATA_RATE_UNUSED, RADIOLIB_LORAWAN_DATA_RATE_UNUSED };
-
976 
-
977  // Rx2 channel properties - may be changed by MAC command
-
978  LoRaWANChannel_t rx2 = RADIOLIB_LORAWAN_CHANNEL_NONE;
-
979 
-
980  // offset between TX and RX1 (such that RX1 has equal or lower DR)
-
981  uint8_t rx1DrOffset = 0;
-
982 
-
983  // LoRaWAN revision (1.0 vs 1.1)
-
984  uint8_t rev = 0;
-
985 
-
986  // Time on Air of last uplink
-
987  RadioLibTime_t lastToA = 0;
-
988 
-
989  // timestamp to measure the RX1/2 delay (from uplink end)
-
990  RadioLibTime_t rxDelayStart = 0;
-
991 
-
992  // timestamp when the Rx1/2 windows were closed (timeout or uplink received)
-
993  RadioLibTime_t rxDelayEnd = 0;
-
994 
-
995  // delays between the uplink and RX1/2 windows
-
996  RadioLibTime_t rxDelays[2] = { RADIOLIB_LORAWAN_RECEIVE_DELAY_1_MS, RADIOLIB_LORAWAN_RECEIVE_DELAY_2_MS };
-
997 
-
998  // device status - battery level
-
999  uint8_t battLevel = 0xFF;
-
1000 
-
1001  // indicates whether an uplink has MAC commands as payload
-
1002  bool isMACPayload = false;
-
1003 
-
1004  // save the selected sub-band in case this must be restored in ADR control
-
1005  uint8_t subBand = 0;
-
1006 
-
1007  // this will reset the device credentials, so the device starts completely new
-
1008  void clearNonces();
-
1009 
-
1010  // wait for, open and listen during Rx1 and Rx2 windows; only performs listening
-
1011  int16_t downlinkCommon();
-
1012 
-
1013  // method to generate message integrity code
-
1014  uint32_t generateMIC(uint8_t* msg, size_t len, uint8_t* key);
-
1015 
-
1016  // method to verify message integrity code
-
1017  // it assumes that the MIC is the last 4 bytes of the message
-
1018  bool verifyMIC(uint8_t* msg, size_t len, uint8_t* key);
-
1019 
-
1020  // configure the common physical layer properties (preamble, sync word etc.)
-
1021  // channels must be configured separately by setupChannelsDyn()!
-
1022  int16_t setPhyProperties(uint8_t dir);
-
1023 
-
1024  // setup uplink/downlink channel data rates and frequencies
-
1025  // for dynamic channels, there is a small set of predefined channels
-
1026  // in case of JoinRequest, add some optional extra frequencies
-
1027  int16_t setupChannelsDyn(bool joinRequest = false);
-
1028 
-
1029  // setup uplink/downlink channel data rates and frequencies
-
1030  // for fixed bands, we only allow one sub-band at a time to be selected
-
1031  int16_t setupChannelsFix(uint8_t subBand);
-
1032 
-
1033  // a join-accept can piggy-back a set of channels or channel masks
-
1034  int16_t processCFList(uint8_t* cfList);
-
1035 
-
1036  // select a set of random TX/RX channels for up- and downlink
-
1037  int16_t selectChannels();
-
1038 
-
1039  // find the first usable data rate for the given band
-
1040  int16_t findDataRate(uint8_t dr, DataRate_t* dataRate);
-
1041 
-
1042  // restore all available channels from persistent storage
-
1043  int16_t restoreChannels();
-
1044 
-
1045  // push MAC command to queue, done by copy
-
1046  int16_t pushMacCommand(LoRaWANMacCommand_t* cmd, LoRaWANMacCommandQueue_t* queue);
-
1047 
-
1048  // delete a specific MAC command from queue, indicated by the command ID
-
1049  // if a payload pointer is supplied, this returns the payload of the MAC command
-
1050  int16_t deleteMacCommand(uint8_t cid, LoRaWANMacCommandQueue_t* queue, uint8_t* payload = NULL);
-
1051 
-
1052  // execute mac command, return the number of processed bytes for sequential processing
-
1053  bool execMacCommand(LoRaWANMacCommand_t* cmd);
-
1054 
-
1055  // apply a channel mask to a set of readily defined channels (dynamic bands only)
-
1056  bool applyChannelMaskDyn(uint8_t chMaskCntl, uint16_t chMask);
-
1057 
-
1058  // define or delete channels from a fixed set of channels (fixed bands only)
-
1059  bool applyChannelMaskFix(uint8_t chMaskCntl, uint16_t chMask);
-
1060 
-
1061  // get the payload length for a specific MAC command
-
1062  uint8_t getMacPayloadLength(uint8_t cid);
-
1063 
-
1070  void setCSMA(uint8_t backoffMax, uint8_t difsSlots, bool enableCSMA = false);
-
1071 
-
1072  // Performs CSMA as per LoRa Alliance Technical Recommendation 13 (TR-013).
-
1073  void performCSMA();
-
1074 
-
1075  // perform a single CAD operation for the under SF/CH combination. Returns either busy or otherwise.
-
1076  bool performCAD();
-
1077 
-
1078  // function to encrypt and decrypt payloads
-
1079  void processAES(const uint8_t* in, size_t len, uint8_t* key, uint8_t* out, uint32_t fCnt, uint8_t dir, uint8_t ctrId, bool counter);
-
1080 
-
1081  // 16-bit checksum method that takes a uint8_t array of even length and calculates the checksum
-
1082  static uint16_t checkSum16(uint8_t *key, uint16_t keyLen);
-
1083 
-
1084  // network-to-host conversion method - takes data from network packet and converts it to the host endians
-
1085  template<typename T>
-
1086  static T ntoh(uint8_t* buff, size_t size = 0);
-
1087 
-
1088  // host-to-network conversion method - takes data from host variable and and converts it to network packet endians
-
1089  template<typename T>
-
1090  static void hton(uint8_t* buff, T val, size_t size = 0);
-
1091 };
-
1092 
-
1093 #endif
-
LoRaWANNode
LoRaWAN-compatible node (class A device).
Definition: LoRaWAN.h:526
+
884  // a buffer that holds all LW base parameters that should persist at all times!
+
885  uint8_t bufferNonces[RADIOLIB_LORAWAN_NONCES_BUF_SIZE] = { 0 };
+
886 
+
887  // a buffer that holds all LW session parameters that preferably persist, but can be afforded to get lost
+
888  uint8_t bufferSession[RADIOLIB_LORAWAN_SESSION_BUF_SIZE] = { 0 };
+
889 
+
890  LoRaWANMacCommandQueue_t commandsUp = {
+
891  .numCommands = 0,
+
892  .len = 0,
+
893  .commands = { { .cid = 0, .payload = { 0 }, .len = 0, .repeat = 0, } },
+
894  };
+
895  LoRaWANMacCommandQueue_t commandsDown = {
+
896  .numCommands = 0,
+
897  .len = 0,
+
898  .commands = { { .cid = 0, .payload = { 0 }, .len = 0, .repeat = 0, } },
+
899  };
+
900 
+
901  uint16_t lwMode = RADIOLIB_LORAWAN_MODE_NONE;
+
902  uint8_t lwClass = RADIOLIB_LORAWAN_CLASS_A;
+
903  bool isActive = false;
+
904 
+
905  uint64_t joinEUI = 0;
+
906  uint64_t devEUI = 0;
+
907  uint8_t nwkKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
+
908  uint8_t appKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
+
909 
+
910  // the following is either provided by the network server (OTAA)
+
911  // or directly entered by the user (ABP)
+
912  uint32_t devAddr = 0;
+
913  uint8_t appSKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
+
914  uint8_t fNwkSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
+
915  uint8_t sNwkSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
+
916  uint8_t nwkSEncKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
+
917  uint8_t jSIntKey[RADIOLIB_AES128_KEY_SIZE] = { 0 };
+
918 
+
919  uint16_t keyCheckSum = 0;
+
920 
+
921  // device-specific parameters, persistent through sessions
+
922  uint16_t devNonce = 0;
+
923  uint32_t joinNonce = 0;
+
924 
+
925  // session-specific parameters
+
926  uint32_t homeNetId = 0;
+
927  uint8_t adrLimitExp = RADIOLIB_LORAWAN_ADR_ACK_LIMIT_EXP;
+
928  uint8_t adrDelayExp = RADIOLIB_LORAWAN_ADR_ACK_DELAY_EXP;
+
929  uint8_t nbTrans = 1; // Number of allowed frame retransmissions
+
930  uint8_t txPowerSteps = 0;
+
931  uint8_t txPowerMax = 0;
+
932  uint32_t fCntUp = 0;
+
933  uint32_t aFCntDown = 0;
+
934  uint32_t nFCntDown = 0;
+
935  uint32_t confFCntUp = RADIOLIB_LORAWAN_FCNT_NONE;
+
936  uint32_t confFCntDown = RADIOLIB_LORAWAN_FCNT_NONE;
+
937  uint32_t adrFCnt = 0;
+
938 
+
939  // modulation of the currently configured channel
+
940  uint8_t modulation = RADIOLIB_LORAWAN_MODULATION_LORA;
+
941 
+
942  // ADR is enabled by default
+
943  bool adrEnabled = true;
+
944 
+
945  // duty cycle is set upon initialization and activated in regions that impose this
+
946  bool dutyCycleEnabled = false;
+
947  uint32_t dutyCycle = 0;
+
948 
+
949  // dwell time is set upon initialization and activated in regions that impose this
+
950  bool dwellTimeEnabledUp = false;
+
951  uint16_t dwellTimeUp = 0;
+
952  bool dwellTimeEnabledDn = false;
+
953  uint16_t dwellTimeDn = 0;
+
954 
+
955  // enable/disable CSMA for LoRaWAN
+
956  bool enableCSMA;
+
957 
+
958  // number of backoff slots to be decremented after DIFS phase. 0 to disable BO.
+
959  // A random BO avoids collisions in the case where two or more nodes start the CSMA
+
960  // process at the same time.
+
961  uint8_t backoffMax;
+
962 
+
963  // number of CADs to estimate a clear CH
+
964  uint8_t difsSlots;
+
965 
+
966  // available channel frequencies from list passed during OTA activation
+
967  LoRaWANChannel_t availableChannels[2][RADIOLIB_LORAWAN_NUM_AVAILABLE_CHANNELS];
+
968 
+
969  // currently configured channels for TX and RX1
+
970  LoRaWANChannel_t currentChannels[2] = { RADIOLIB_LORAWAN_CHANNEL_NONE, RADIOLIB_LORAWAN_CHANNEL_NONE };
+
971 
+
972  // currently configured datarates for TX and RX1
+
973  uint8_t dataRates[2] = { RADIOLIB_LORAWAN_DATA_RATE_UNUSED, RADIOLIB_LORAWAN_DATA_RATE_UNUSED };
+
974 
+
975  // Rx2 channel properties - may be changed by MAC command
+
976  LoRaWANChannel_t rx2 = RADIOLIB_LORAWAN_CHANNEL_NONE;
+
977 
+
978  // offset between TX and RX1 (such that RX1 has equal or lower DR)
+
979  uint8_t rx1DrOffset = 0;
+
980 
+
981  // LoRaWAN revision (1.0 vs 1.1)
+
982  uint8_t rev = 0;
+
983 
+
984  // Time on Air of last uplink
+
985  RadioLibTime_t lastToA = 0;
+
986 
+
987  // timestamp to measure the RX1/2 delay (from uplink end)
+
988  RadioLibTime_t rxDelayStart = 0;
+
989 
+
990  // timestamp when the Rx1/2 windows were closed (timeout or uplink received)
+
991  RadioLibTime_t rxDelayEnd = 0;
+
992 
+
993  // delays between the uplink and RX1/2 windows
+
994  RadioLibTime_t rxDelays[2] = { RADIOLIB_LORAWAN_RECEIVE_DELAY_1_MS, RADIOLIB_LORAWAN_RECEIVE_DELAY_2_MS };
+
995 
+
996  // device status - battery level
+
997  uint8_t battLevel = 0xFF;
+
998 
+
999  // indicates whether an uplink has MAC commands as payload
+
1000  bool isMACPayload = false;
+
1001 
+
1002  // save the selected sub-band in case this must be restored in ADR control
+
1003  uint8_t subBand = 0;
+
1004 
+
1005  // this will reset the device credentials, so the device starts completely new
+
1006  void clearNonces();
+
1007 
+
1008  // wait for, open and listen during Rx1 and Rx2 windows; only performs listening
+
1009  int16_t downlinkCommon();
+
1010 
+
1011  // method to generate message integrity code
+
1012  uint32_t generateMIC(uint8_t* msg, size_t len, uint8_t* key);
+
1013 
+
1014  // method to verify message integrity code
+
1015  // it assumes that the MIC is the last 4 bytes of the message
+
1016  bool verifyMIC(uint8_t* msg, size_t len, uint8_t* key);
+
1017 
+
1018  // configure the common physical layer properties (preamble, sync word etc.)
+
1019  // channels must be configured separately by setupChannelsDyn()!
+
1020  int16_t setPhyProperties(uint8_t dir);
+
1021 
+
1022  // setup uplink/downlink channel data rates and frequencies
+
1023  // for dynamic channels, there is a small set of predefined channels
+
1024  // in case of JoinRequest, add some optional extra frequencies
+
1025  int16_t setupChannelsDyn(bool joinRequest = false);
+
1026 
+
1027  // setup uplink/downlink channel data rates and frequencies
+
1028  // for fixed bands, we only allow one sub-band at a time to be selected
+
1029  int16_t setupChannelsFix(uint8_t subBand);
+
1030 
+
1031  // a join-accept can piggy-back a set of channels or channel masks
+
1032  int16_t processCFList(uint8_t* cfList);
+
1033 
+
1034  // select a set of random TX/RX channels for up- and downlink
+
1035  int16_t selectChannels();
+
1036 
+
1037  // find the first usable data rate for the given band
+
1038  int16_t findDataRate(uint8_t dr, DataRate_t* dataRate);
+
1039 
+
1040  // restore all available channels from persistent storage
+
1041  int16_t restoreChannels();
+
1042 
+
1043  // push MAC command to queue, done by copy
+
1044  int16_t pushMacCommand(LoRaWANMacCommand_t* cmd, LoRaWANMacCommandQueue_t* queue);
+
1045 
+
1046  // delete a specific MAC command from queue, indicated by the command ID
+
1047  // if a payload pointer is supplied, this returns the payload of the MAC command
+
1048  int16_t deleteMacCommand(uint8_t cid, LoRaWANMacCommandQueue_t* queue, uint8_t* payload = NULL);
+
1049 
+
1050  // execute mac command, return the number of processed bytes for sequential processing
+
1051  bool execMacCommand(LoRaWANMacCommand_t* cmd);
+
1052 
+
1053  // apply a channel mask to a set of readily defined channels (dynamic bands only)
+
1054  bool applyChannelMaskDyn(uint8_t chMaskCntl, uint16_t chMask);
+
1055 
+
1056  // define or delete channels from a fixed set of channels (fixed bands only)
+
1057  bool applyChannelMaskFix(uint8_t chMaskCntl, uint16_t chMask);
+
1058 
+
1059  // get the payload length for a specific MAC command
+
1060  uint8_t getMacPayloadLength(uint8_t cid);
+
1061 
+
1068  void setCSMA(uint8_t backoffMax, uint8_t difsSlots, bool enableCSMA = false);
+
1069 
+
1070  // Performs CSMA as per LoRa Alliance Technical Recommendation 13 (TR-013).
+
1071  void performCSMA();
+
1072 
+
1073  // perform a single CAD operation for the under SF/CH combination. Returns either busy or otherwise.
+
1074  bool performCAD();
+
1075 
+
1076  // function to encrypt and decrypt payloads
+
1077  void processAES(const uint8_t* in, size_t len, uint8_t* key, uint8_t* out, uint32_t fCnt, uint8_t dir, uint8_t ctrId, bool counter);
+
1078 
+
1079  // 16-bit checksum method that takes a uint8_t array of even length and calculates the checksum
+
1080  static uint16_t checkSum16(uint8_t *key, uint16_t keyLen);
+
1081 
+
1082  // network-to-host conversion method - takes data from network packet and converts it to the host endians
+
1083  template<typename T>
+
1084  static T ntoh(uint8_t* buff, size_t size = 0);
+
1085 
+
1086  // host-to-network conversion method - takes data from host variable and and converts it to network packet endians
+
1087  template<typename T>
+
1088  static void hton(uint8_t* buff, T val, size_t size = 0);
+
1089 };
+
1090 
+
1091 #endif
+
LoRaWANNode
LoRaWAN-compatible node (class A device).
Definition: LoRaWAN.h:524
LoRaWANNode::clearSession
void clearSession()
Clear an active session, so that the device will have to rejoin the network.
Definition: LoRaWAN.cpp:59
LoRaWANNode::setBufferNonces
int16_t setBufferNonces(uint8_t *persistentBuffer)
Fill the internal buffer that holds the LW base parameters with a supplied buffer.
Definition: LoRaWAN.cpp:75
LoRaWANNode::setDatarate
int16_t setDatarate(uint8_t drUp)
Set uplink datarate. This should not be used when ADR is enabled.
Definition: LoRaWAN.cpp:1999
@@ -837,7 +835,7 @@ $(document).ready(function(){initNavTree('_lo_ra_w_a_n_8h_source.html',''); init
LoRaWANNode::getAFCntDown
uint32_t getAFCntDown()
Returns the last application downlink's frame counter; also 0 if no application downlink occured yet.
Definition: LoRaWAN.cpp:1696
LoRaWANNode::getLastToA
RadioLibTime_t getLastToA()
Get the Time-on-air of the last uplink message.
Definition: LoRaWAN.cpp:2918
LoRaWANNode::activateABP
int16_t activateABP(uint8_t initialDr=RADIOLIB_LORAWAN_DATA_RATE_UNUSED)
Join network by restoring ABP session or performing over-the-air activation. In this procedure,...
Definition: LoRaWAN.cpp:791
-
LoRaWANNode::TS009
bool TS009
TS009 Protocol Specification Verification switch (allows FPort 224 and cuts off uplink payload instea...
Definition: LoRaWAN.h:874
+
LoRaWANNode::TS009
bool TS009
TS009 Protocol Specification Verification switch (allows FPort 224 and cuts off uplink payload instea...
Definition: LoRaWAN.h:872
LoRaWANNode::getBufferNonces
uint8_t * getBufferNonces()
Returns the pointer to the internal buffer that holds the LW base parameters.
Definition: LoRaWAN.cpp:67
LoRaWANNode::sendReceive
int16_t sendReceive(const char *strUp, uint8_t fPort, uint8_t *dataDown, size_t *lenDown, bool isConfirmed=false, LoRaWANEvent_t *eventUp=NULL, LoRaWANEvent_t *eventDown=NULL)
Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window.
Definition: LoRaWAN.cpp:1660
LoRaWANNode::getBufferSession
uint8_t * getBufferSession()
Returns the pointer to the internal buffer that holds the LW session parameters.
Definition: LoRaWAN.cpp:111
@@ -890,19 +888,19 @@ $(document).ready(function(){initNavTree('_lo_ra_w_a_n_8h_source.html',''); init
LoRaWANChannelSpan_t::drMax
uint8_t drMax
Maximum allowed datarate for all channels in this span (inclusive)
Definition: LoRaWAN.h:373
LoRaWANChannelSpan_t::freqStep
float freqStep
Frequency step between adjacent channels.
Definition: LoRaWAN.h:367
LoRaWANChannelSpan_t::drMin
uint8_t drMin
Minimum allowed datarate for all channels in this span.
Definition: LoRaWAN.h:370
-
LoRaWANEvent_t
Structure to save extra information about uplink/downlink event.
Definition: LoRaWAN.h:495
-
LoRaWANEvent_t::freq
float freq
Frequency in MHz.
Definition: LoRaWAN.h:510
-
LoRaWANEvent_t::confirmed
bool confirmed
Whether the event is confirmed or not (e.g., confirmed uplink sent by user application)
Definition: LoRaWAN.h:500
-
LoRaWANEvent_t::fPort
uint8_t fPort
Port number.
Definition: LoRaWAN.h:519
-
LoRaWANEvent_t::power
int16_t power
Transmit power in dBm for uplink, or RSSI for downlink.
Definition: LoRaWAN.h:513
-
LoRaWANEvent_t::confirming
bool confirming
Whether the event is confirming a previous request (e.g., server downlink reply to confirmed uplink s...
Definition: LoRaWAN.h:504
-
LoRaWANEvent_t::datarate
uint8_t datarate
Datarate.
Definition: LoRaWAN.h:507
-
LoRaWANEvent_t::dir
uint8_t dir
Event direction, one of RADIOLIB_LORAWAN_CHANNEL_DIR_*.
Definition: LoRaWAN.h:497
-
LoRaWANEvent_t::fCnt
uint32_t fCnt
The appropriate frame counter - for different events, different frame counters will be reported!
Definition: LoRaWAN.h:516
-
LoRaWANJoinEvent_t
Structure to save extra information about activation event.
Definition: LoRaWAN.h:480
-
LoRaWANJoinEvent_t::newSession
bool newSession
Whether a new session was started.
Definition: LoRaWAN.h:482
-
LoRaWANJoinEvent_t::joinNonce
uint32_t joinNonce
The received Join-Request JoinNonce value.
Definition: LoRaWAN.h:488
-
LoRaWANJoinEvent_t::devNonce
uint16_t devNonce
The transmitted Join-Request DevNonce value.
Definition: LoRaWAN.h:485
+
LoRaWANEvent_t
Structure to save extra information about uplink/downlink event.
Definition: LoRaWAN.h:493
+
LoRaWANEvent_t::freq
float freq
Frequency in MHz.
Definition: LoRaWAN.h:508
+
LoRaWANEvent_t::confirmed
bool confirmed
Whether the event is confirmed or not (e.g., confirmed uplink sent by user application)
Definition: LoRaWAN.h:498
+
LoRaWANEvent_t::fPort
uint8_t fPort
Port number.
Definition: LoRaWAN.h:517
+
LoRaWANEvent_t::power
int16_t power
Transmit power in dBm for uplink, or RSSI for downlink.
Definition: LoRaWAN.h:511
+
LoRaWANEvent_t::confirming
bool confirming
Whether the event is confirming a previous request (e.g., server downlink reply to confirmed uplink s...
Definition: LoRaWAN.h:502
+
LoRaWANEvent_t::datarate
uint8_t datarate
Datarate.
Definition: LoRaWAN.h:505
+
LoRaWANEvent_t::dir
uint8_t dir
Event direction, one of RADIOLIB_LORAWAN_CHANNEL_DIR_*.
Definition: LoRaWAN.h:495
+
LoRaWANEvent_t::fCnt
uint32_t fCnt
The appropriate frame counter - for different events, different frame counters will be reported!
Definition: LoRaWAN.h:514
+
LoRaWANJoinEvent_t
Structure to save extra information about activation event.
Definition: LoRaWAN.h:478
+
LoRaWANJoinEvent_t::newSession
bool newSession
Whether a new session was started.
Definition: LoRaWAN.h:480
+
LoRaWANJoinEvent_t::joinNonce
uint32_t joinNonce
The received Join-Request JoinNonce value.
Definition: LoRaWAN.h:486
+
LoRaWANJoinEvent_t::devNonce
uint16_t devNonce
The transmitted Join-Request DevNonce value.
Definition: LoRaWAN.h:483
LoRaWANMacCommand_t
Structure to save information about MAC command.
Definition: LoRaWAN.h:248
LoRaWANMacCommand_t::payload
uint8_t payload[RADIOLIB_LORAWAN_MAX_MAC_COMMAND_LEN_DOWN]
Payload buffer (5 bytes is the longest possible)
Definition: LoRaWAN.h:253
LoRaWANMacCommand_t::len
uint8_t len
Length of the payload.
Definition: LoRaWAN.h:256
diff --git a/_physical_layer_8h_source.html b/_physical_layer_8h_source.html index 05463a6d..e05e5c8b 100644 --- a/_physical_layer_8h_source.html +++ b/_physical_layer_8h_source.html @@ -306,7 +306,7 @@ $(document).ready(function(){initNavTree('_physical_layer_8h_source.html',''); i
BellClient
Client for Bell modem communication. The public interface is the same as Arduino Serial.
Definition: BellModem.h:57
FSK4Client
Client for FSK-4 communication. The public interface is the same as Arduino Serial.
Definition: FSK4.h:15
HellClient
Client for Hellschreiber transmissions.
Definition: Hellschreiber.h:90
-
LoRaWANNode
LoRaWAN-compatible node (class A device).
Definition: LoRaWAN.h:526
+
LoRaWANNode
LoRaWAN-compatible node (class A device).
Definition: LoRaWAN.h:524
Module
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition: Module.h:65
MorseClient
Client for Morse Code communication. The public interface is the same as Arduino Serial.
Definition: Morse.h:93
PagerClient
Client for Pager communication.
Definition: Pager.h:62