Version of personalized IMPACT LoRa

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

Revision:
10:894167ed3d77
Parent:
9:c5820ce68bd6
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");