Version of personalized IMPACT LoRa

Fork of LMiC-10secs by Alcatel-Lucent IoT Development

Files at this revision

API Documentation at this revision

Comitter:
pnysten
Date:
Fri Sep 23 09:09:37 2016 +0000
Parent:
9:c5820ce68bd6
Commit message:
Version of personalized IMPACT LoRa

Changed in this revision

lmic.cpp Show annotated file Show diff for this revision Revisions of this file
lmic.h Show annotated file Show diff for this revision Revisions of this file
diff -r c5820ce68bd6 -r 894167ed3d77 lmic.cpp
--- a/lmic.cpp	Tue Feb 23 08:41:36 2016 +0000
+++ b/lmic.cpp	Fri Sep 23 09:09:37 2016 +0000
@@ -1097,6 +1097,7 @@
         }
         // Replay of previous sequence number allowed only if
         // previous frame and repeated both requested confirmation
+        debug_str("Replay Conf\n\r");
         replayConf = 1;
     }
     else {
@@ -1289,7 +1290,7 @@
         
         //if( port >= 0  &&  pend-poff > 0 )
             //aes_cipher(port <= 0 ? LMIC.nwkKey : LMIC.artKey, LMIC.devaddr, seqno, /*dn*/1, d+poff, pend-poff);
-
+debug_str("HANDLING PAYLOAD...\r\n");
         if( port >= 0  && port != 1 &&  pend-poff > 0 )
         {
             debug_str("Payload decrypting...\r\n");
@@ -1855,12 +1856,20 @@
         }
         LMIC.frame[end] = LMIC.pendTxPort;
         os_copyMem(LMIC.frame+end+1, LMIC.pendTxData, dlen);
+
+//        debug_str("Data frame before encrypting: ");  
+        debug_buf(LMIC.frame, dlen);
+//        debug_str("Encrypting data frame\r\n");
         aes_cipher(LMIC.pendTxPort==0 ? LMIC.nwkKey : LMIC.artKey,
                    LMIC.devaddr, LMIC.seqnoUp-1,
                    /*up*/0, LMIC.frame+end+1, dlen);
+//        debug_str("Encrypted data frame: ");  
+        debug_buf(LMIC.frame, dlen);         
     }
     aes_appendMic(LMIC.nwkKey, LMIC.devaddr, LMIC.seqnoUp-1, /*up*/0, LMIC.frame, flen-4);
-
+//    debug_str("Frame to be sent: ");  
+    debug_buf(LMIC.frame, dlen);         
+ 
     EV(dfinfo, DEBUG, (e_.deveui  = MAIN::CDEV->getEui(),
                        e_.devaddr = LMIC.devaddr,
                        e_.seqno   = LMIC.seqnoUp-1,
@@ -2009,7 +2018,7 @@
 // ================================================================================
 
 static void processPingRx (xref2osjob_t osjob) {
-    //debug_str("processPingRx\r\n");
+    debug_str("processPingRx\r\n");
     if( LMIC.dataLen != 0 ) {
         LMIC.txrxFlags = TXRX_PING;
         if( decodeFrame() ) {
@@ -2023,7 +2032,7 @@
 
 
 static bit_t processDnData (void) {
-    //debug_str("processDnData\r\n");
+    debug_str("processDnData\r\n");
     ASSERT((LMIC.opmode & OP_TXRXPEND)!=0);
 
     if( LMIC.dataLen == 0 ) {
@@ -2082,7 +2091,9 @@
         }
         return 1;
     }
+    debug_str("processDnData - decodeFrame\r\n");
     if( !decodeFrame() ) {
+        debug_str("decode Frame deconne\r\n");
         if( (LMIC.txrxFlags & TXRX_DNW1) != 0 )
             return 0;
         goto norx;
@@ -2223,7 +2234,7 @@
             goto checkrx;
         }
         // Earliest possible time vs overhead to setup radio
-        /*PANYif( txbeg - (now + TX_RAMPUP) < 0 ) {PANY*/
+        if( txbeg - (now + TX_RAMPUP) < 0 ) {
             // We could send right now!
             debug_str("We could send right now!"); 
             debug_char( '\r' );
@@ -2270,7 +2281,7 @@
             updateTx(txbeg);
             os_radio(RADIO_TX);
             return;
-        /*PANY}PANY*/
+        }
         // Cannot yet TX
         if( (LMIC.opmode & OP_TRACK) == 0 )
         {
@@ -2425,14 +2436,17 @@
 
 
 //
-int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed) {
+int LMIC_setTxData2 (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed, int encrypted) {
     //debug_str("LMIC_setTxData2\r\n");
 /*    debug_val("Data Length: ", dlen);
     debug_val("Data Length: ", SIZEOFEXPR(LMIC.pendTxData));*/
+
     if( dlen > SIZEOFEXPR(LMIC.pendTxData) )
         return -2;
     if( data != (xref2u1_t)0 )
     {
+        if (encrypted == 1)
+            aes_cipher(port==0 ? LMIC.nwkKey : LMIC.artKey, LMIC.devaddr, LMIC.seqnoUp-1, 0, data, dlen);
         os_copyMem(LMIC.pendTxData, data, dlen);
     }
     //debug_str("Send Data\r\n");
diff -r c5820ce68bd6 -r 894167ed3d77 lmic.h
--- a/lmic.h	Tue Feb 23 08:41:36 2016 +0000
+++ b/lmic.h	Fri Sep 23 09:09:37 2016 +0000
@@ -44,18 +44,20 @@
        LINK_CHECK_INIT    = -12 ,    // UP frame count until we inc datarate
        LINK_CHECK_OFF     =-128 };   // link check disabled
 
-/*enum { TIME_RESYNC        =  6*128 }; // secs
+enum { TIME_RESYNC        =  6*128 }; // secs
 enum { TXRX_GUARD_ms      =  6000 };  // msecs - don't start TX-RX transaction before beacon
 enum { JOIN_GUARD_ms      =  9000 };  // msecs - don't start Join Req/Acc transaction before beacon
 enum { TXRX_BCNEXT_secs   =     2 };  // secs - earliest start after beacon time
-enum { RETRY_PERIOD_secs  =     3 };  // secs - random period for retrying a confirmed send*/
+enum { RETRY_PERIOD_secs  =     3 };  // secs - random period for retrying a confirmed send
 
 //PANY
+/*
 enum { TIME_RESYNC        =  6*128 }; // secs
 enum { TXRX_GUARD_ms      =  1000 };  // msecs - don't start TX-RX transaction before beacon
 enum { JOIN_GUARD_ms      =  1000 };  // msecs - don't start Join Req/Acc transaction before beacon
 enum { TXRX_BCNEXT_secs   =     1 };  // secs - earliest start after beacon time
 enum { RETRY_PERIOD_secs  =     1 };  // secs - random period for retrying a confirmed send
+*/
 //PANY
 #if defined(CFG_eu868) // EU868 spectrum ====================================================
 
@@ -263,7 +265,7 @@
 void  LMIC_reset        (void);
 void  LMIC_clrTxData    (void);
 void  LMIC_setTxData    (void);
-int   LMIC_setTxData2   (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed);
+int   LMIC_setTxData2   (u1_t port, xref2u1_t data, u1_t dlen, u1_t confirmed, int encrypted);
 void  LMIC_sendAlive    (void);
 
 bit_t LMIC_enableTracking  (u1_t tryBcnInfo);