IBM LoRa MAC in C (LMiC) mbed library port

Dependents:   lora-temperature LoRaWAN-lmic-app_HS LoRaWAN-lmic-app_huynh

LoRa WAN in C for sx1276 shield

Currently version 1.5


LoRaWAN network configuration for end-device

The following three pieces of information uniquely identifies end-device to network to allow over-the-air activation. These are stored in the end-device prior to join procedure.

AppEUI

Uniquely identifies application provider of end-device.

Least-significant byte first, 8 bytes, use reverse memcpy() to keep same order as shown on lora server.

example C code

static const u1_t APPEUI[8]  = { 0x01, 0x00, 0x01, 0x00, 0x00, 0x0C, 0x25, 0x00 };

This is copied into LMIC by os_getArtEui() callback function in application.

DevEUI

End-device ID, unique to each end-node.

Least-significant byte first, 8 bytes, use reverse memcpy() to keep same order as shown on lora server.

example C code

static const u1_t DEVEUI[8]  = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x0C, 0x25, 0x00 }; 

This is copied into LMIC by os_getDevEui() callback function in application.

AppKey (aka DevKey)

128-bit (16byte) AES key.

example C code

static const u1_t DEVKEY[16] = { 0xe4, 0x72, 0x71, 0xc5, 0xf5, 0x30, 0xa9, 0x9f, 0xcf, 0xc4, 0x0e, 0xab, 0xea, 0xd7, 0x19, 0x42 };

This is copied into LMIC by os_getDevKey() callback function in application.

Using over-the air activation, the end-device (LMIC) performs a join procedure every time it starts for first time, or has lost session context information. When join procedure has successfully completed, the end-device will have a network session key (NwkSKey) and an application session key (AppSKey), which are used for encryption and message integrity check.


US915 configuration with http://us01-iot.semtech.com/

  • log in to server
  • click on Applications
  • find your application and click it
  • go to configure motes
  • to create a mote, you may enter a new DevEUI
    • you may copy-paste the 16byte application key from an already existing mote, if you desire.
CHNL_HYBRID125KHz500KHz
defined valuechannelschannel
00 to 764
18 to 1565
216 to 2366
324 to 3167
432 to 3968
540 to 4769
648 to 5570
756 to 6371
undef0 to 6364 to 71
Revision:
1:d3b7bde3995c
Parent:
0:62d1edcc13d1
Child:
2:974cafbfb159
--- a/lorabase.h	Thu Jan 22 12:50:49 2015 +0000
+++ b/lorabase.h	Tue Mar 31 13:36:56 2015 +0000
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014 IBM Corporation.
+ * Copyright (c) 2014-2015 IBM Corporation.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -54,7 +54,7 @@
 enum { BCN_GUARD_us      = 3000000 };
 enum { BCN_SLOT_SPAN_us  =   30000 };
 
-#if CFG_eu868 // ==============================================
+#if defined(CFG_eu868) // ==============================================
 
 enum _dr_eu868_t { DR_SF12=0, DR_SF11, DR_SF10, DR_SF9, DR_SF8, DR_SF7, DR_SF7B, DR_FSK, DR_NONE };
 enum { DR_DFLTMIN = DR_SF7 };
@@ -84,17 +84,30 @@
 enum { DR_PING           = SF9 };       // default ping DR
 enum { CHNL_DNW2         = 5 };
 enum { FREQ_DNW2         = EU868_F6 };
-enum { DR_DNW2           = DR_SF9 };
+enum { DR_DNW2           = DR_SF9 };    // changed from LoRaWAN specification.
+                                        // Default value is DR_SF12
 enum { CHNL_BCN          = 5 };
 enum { FREQ_BCN          = EU868_F6 };
 enum { DR_BCN            = DR_SF9 };
-enum { AIRTIME_BCN       = 185344 };  // micros
+enum { AIRTIME_BCN       = 144384 };  // micros
 
-#elif CFG_us915  // =========================================
+enum {
+    // Beacon frame format EU SF9
+    OFF_BCN_NETID    = 0,         
+    OFF_BCN_TIME     = 3,
+    OFF_BCN_CRC1     = 7,
+    OFF_BCN_INFO     = 8,
+    OFF_BCN_LAT      = 9,
+    OFF_BCN_LON      = 12,
+    OFF_BCN_CRC2     = 15,
+    LEN_BCN          = 17
+};
+
+#elif defined(CFG_us915)  // =========================================
 
 enum _dr_us915_t { DR_SF10=0, DR_SF9, DR_SF8, DR_SF7, DR_SF8C, DR_NONE,
-           // Devices behind a router:
-           DR_SF12CR=8, DR_SF11CR, DR_SF10CR, DR_SF9CR, DR_SF8CR, DR_SF7CR };
+                   // Devices behind a router:
+                   DR_SF12CR=8, DR_SF11CR, DR_SF10CR, DR_SF9CR, DR_SF8CR, DR_SF7CR };
 enum { DR_DFLTMIN = DR_SF8C };
 enum { DR_PAGE = DR_PAGE_US915 };
 
@@ -109,33 +122,31 @@
 enum { US915_FREQ_MIN = 902000000,
        US915_FREQ_MAX = 928000000 };
 
-enum { CHNL_PING         = 2 };
+enum { CHNL_PING         = 0 }; // used only for default init of state (follows beacon - rotating)
 enum { FREQ_PING         = US915_500kHz_DNFBASE + CHNL_PING*US915_500kHz_DNFSTEP };  // default ping freq
 enum { DR_PING           = DR_SF10CR };       // default ping DR
-enum { CHNL_DNW2         = 1 };
+enum { CHNL_DNW2         = 0 };
 enum { FREQ_DNW2         = US915_500kHz_DNFBASE + CHNL_DNW2*US915_500kHz_DNFSTEP };
-enum { DR_DNW2           = DR_SF10CR };
-enum { CHNL_BCN          = 0 };
-enum { FREQ_BCN          = US915_500kHz_DNFBASE + CHNL_BCN*US915_500kHz_DNFSTEP };
+enum { DR_DNW2           = DR_SF12CR };
+enum { CHNL_BCN          = 0 }; // used only for default init of state (rotating beacon scheme)
 enum { DR_BCN            = DR_SF10CR };
-enum { AIRTIME_BCN       = 82432 };  // micros
+enum { AIRTIME_BCN       = 72192 };  // micros
+
+enum {
+    // Beacon frame format US SF10
+    OFF_BCN_NETID    = 0,         
+    OFF_BCN_TIME     = 3,
+    OFF_BCN_CRC1     = 7,
+    OFF_BCN_INFO     = 9,
+    OFF_BCN_LAT      = 10,
+    OFF_BCN_LON      = 13,
+    OFF_BCN_RFU1     = 16,
+    OFF_BCN_CRC2     = 17,
+    LEN_BCN          = 19
+};
 
 #endif // ===================================================
 
-
-enum {
-    // Beacon frame format
-    OFF_BCN_RFU      = 0,
-    OFF_BCN_NETID    = 4,         
-    OFF_BCN_CMAP     = 7,
-    OFF_BCN_TIME     = 9,
-    OFF_BCN_CRC1     = 13,
-    OFF_BCN_INFO     = 15,
-    OFF_BCN_LAT      = 16,
-    OFF_BCN_LON      = 19,
-    OFF_BCN_CRC2     = 22,
-    LEN_BCN          = 24
-};
 enum {
     // Join Request frame format
     OFF_JR_HDR      = 0,
@@ -152,7 +163,9 @@
     OFF_JA_NETID    = 4,
     OFF_JA_DEVADDR  = 7,
     OFF_JA_RFU      = 11,
-    OFF_CFLIST      = 14,
+    OFF_JA_DLSET    = 11,
+    OFF_JA_RXDLY    = 12,
+    OFF_CFLIST      = 13,
     LEN_JA          = 17,
     LEN_JAEXT       = 17+16
 };
@@ -191,10 +204,14 @@
     FCT_ADREN  = 0x80,
     FCT_ADRARQ = 0x40,
     FCT_ACK    = 0x20,
-    FCT_MORE   = 0x10,
+    FCT_MORE   = 0x10,   // also in DN direction: Class B indicator
     FCT_OPTLEN = 0x0F,
 };
 enum {
+    // In UP direction: signals class B enabled
+    FCT_CLASSB = FCT_MORE
+};
+enum {
     NWKID_MASK = (int)0xFE000000,
     NWKID_BITS = 7
 };
@@ -225,10 +242,13 @@
     MCMD_SNCH_REQ = 0x07, // set new channel    : u1:chidx, u3:freq, u1:DRrange
     // Class B
     MCMD_PING_SET = 0x11, // set ping freq      : u3: freq
-    MCMD_BCNI_ANS = 0x12, // next beacon start  : u2: delay(10ms), u1:channel
+    MCMD_BCNI_ANS = 0x12, // next beacon start  : u2: delay(in TUNIT millis), u1:channel
 };
 
 enum {
+    MCMD_BCNI_TUNIT = 30  // time unit of delay value in millis
+};
+enum {
     MCMD_LADR_ANS_RFU    = 0xF8, // RFU bits
     MCMD_LADR_ANS_POWACK = 0x04, // 0=not supported power level
     MCMD_LADR_ANS_DRACK  = 0x02, // 0=unknown data rate
@@ -272,7 +292,7 @@
     MCMD_LADR_POW_MASK   = 0x0F,
     MCMD_LADR_DR_SHIFT   = 4,
     MCMD_LADR_POW_SHIFT  = 0,
-#if CFG_eu868
+#if defined(CFG_eu868)
     MCMD_LADR_SF12      = DR_SF12<<4,
     MCMD_LADR_SF11      = DR_SF11<<4,
     MCMD_LADR_SF10      = DR_SF10<<4,
@@ -288,7 +308,7 @@
     MCMD_LADR_8dBm      = 3,
     MCMD_LADR_5dBm      = 4,
     MCMD_LADR_2dBm      = 5,
-#elif CFG_us915
+#elif defined(CFG_us915)
     MCMD_LADR_SF10      = DR_SF10<<4,
     MCMD_LADR_SF9       = DR_SF9 <<4,
     MCMD_LADR_SF8       = DR_SF8 <<4,
@@ -318,15 +338,8 @@
 // Device address
 typedef u4_t devaddr_t;
 
-
 // RX quality (device)
 enum { RSSI_OFF=64, SNR_SCALEUP=4 };
-struct rxqu_t {
-    s1_t rssi;    // offset by RSSI_OFF, max physical RSSI range -198..+63
-    s1_t snr;     // scaled by SNR_SCALEUP, max physical SNR range -32..+31.75
-};
-TYPEDEF_xref2rxqu_t;
-
 
 inline sf_t  getSf   (rps_t params)            { return   (sf_t)(params &  0x7); }
 inline rps_t setSf   (rps_t params, sf_t sf)   { return (rps_t)((params & ~0x7) | sf); }