LoRaWAN MAC layer implementation

Dependents:   LoRa LoRa

Fork of LoRaWAN-lib by Semtech

Files at this revision

API Documentation at this revision

Comitter:
olav
Date:
Mon May 09 08:06:09 2016 +0000
Parent:
3:b9d87593a8ae
Commit message:
initial commit;

Changed in this revision

LoRaMac.cpp Show annotated file Show diff for this revision Revisions of this file
LoRaMac.h Show annotated file Show diff for this revision Revisions of this file
LoRaMacCrypto.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LoRaMac.cpp	Mon Mar 14 09:09:54 2016 +0000
+++ b/LoRaMac.cpp	Mon May 09 08:06:09 2016 +0000
@@ -2324,7 +2324,7 @@
     fCtrl.Bits.Ack           = false;
     fCtrl.Bits.AdrAckReq     = false;
     fCtrl.Bits.Adr           = AdrCtrlOn;
-
+    
     // Prepare the frame
     status = PrepareFrame( macHdr, &fCtrl, fPort, fBuffer, fBufferSize );
 
@@ -2338,7 +2338,7 @@
     McpsConfirm.NbRetries = 0;
     McpsConfirm.AckReceived = false;
     McpsConfirm.UpLinkCounter = UpLinkCounter;
-
+    
     status = ScheduleTx( );
 
     return status;
@@ -2374,10 +2374,12 @@
     if( dutyCycleTimeOff == 0 )
     {
         // Try to send now
+        printf("frame sent right away .. \r\n");
         return SendFrameOnChannel( Channels[Channel] );
     }
     else
     {
+        printf("frame was scheduled .. \r\n");
         // Send later - prepare timer
         LoRaMacState |= MAC_TX_DELAYED;
         TimerSetValue( &TxDelayedTimer, dutyCycleTimeOff );
@@ -2443,12 +2445,10 @@
             }
 
             fCtrl->Bits.AdrAckReq = AdrNextDr( fCtrl->Bits.Adr, true, &ChannelsDatarate );
-
             if( ValidatePayloadLength( fBufferSize, ChannelsDatarate, MacCommandsBufferIndex ) == false )
             {
                 return LORAMAC_STATUS_LENGTH_ERROR;
             }
-
             RxWindow1Delay = ReceiveDelay1 - RADIO_WAKEUP_TIME;
             RxWindow2Delay = ReceiveDelay2 - RADIO_WAKEUP_TIME;
 
@@ -2473,7 +2473,6 @@
                 if( ( MacCommandsBufferIndex <= LORA_MAC_COMMAND_MAX_LENGTH ) && ( MacCommandsInNextTx == true ) )
                 {
                     fCtrl->Bits.FOptsLen += MacCommandsBufferIndex;
-
                     // Update FCtrl field with new value of OptionsLength
                     LoRaMacBuffer[0x05] = fCtrl->Value;
                     for( i = 0; i < MacCommandsBufferIndex; i++ )
@@ -2493,7 +2492,6 @@
             }
             MacCommandsInNextTx = false;
             MacCommandsBufferIndex = 0;
-
             if( ( payload != NULL ) && ( payloadSize > 0 ) )
             {
                 LoRaMacBuffer[pktHeaderLen++] = framePort;
@@ -2516,9 +2514,7 @@
             LoRaMacBuffer[LoRaMacBufferPktLen + 1] = ( mic >> 8 ) & 0xFF;
             LoRaMacBuffer[LoRaMacBufferPktLen + 2] = ( mic >> 16 ) & 0xFF;
             LoRaMacBuffer[LoRaMacBufferPktLen + 3] = ( mic >> 24 ) & 0xFF;
-
             LoRaMacBufferPktLen += LORAMAC_MFR_LEN;
-
             break;
         case FRAME_TYPE_PROPRIETARY:
             if( ( fBuffer != NULL ) && ( fBufferSize > 0 ) )
--- a/LoRaMac.h	Mon Mar 14 09:09:54 2016 +0000
+++ b/LoRaMac.h	Mon May 09 08:06:09 2016 +0000
@@ -1675,6 +1675,8 @@
  */
 LoRaMacStatus_t LoRaMacMcpsRequest( McpsReq_t *mcpsRequest );
 
+void LoRaMacTestSetDutyCycleOn( bool enable );
+
 /*! \} defgroup LORAMAC */
 
 #endif // __LORAMAC_H__
--- a/LoRaMacCrypto.cpp	Mon Mar 14 09:09:54 2016 +0000
+++ b/LoRaMacCrypto.cpp	Mon May 09 08:06:09 2016 +0000
@@ -19,6 +19,7 @@
 */
 #include <stdlib.h>
 #include <stdint.h>
+#include <stdio.h>
 #include "utilities.h"
 
 #include "aes.h"
@@ -93,13 +94,9 @@
     MicBlockB0[15] = size & 0xFF;
 
     AES_CMAC_Init( AesCmacCtx );
-
     AES_CMAC_SetKey( AesCmacCtx, key );
-
     AES_CMAC_Update( AesCmacCtx, MicBlockB0, LORAMAC_MIC_BLOCK_B0_SIZE );
-    
     AES_CMAC_Update( AesCmacCtx, buffer, size & 0xFF );
-    
     AES_CMAC_Final( Mic, AesCmacCtx );
     
     *mic = ( uint32_t )( ( uint32_t )Mic[3] << 24 | ( uint32_t )Mic[2] << 16 | ( uint32_t )Mic[1] << 8 | ( uint32_t )Mic[0] );