arm studio build

Dependencies:   libxDot-mbed5

Revision:
12:7944e4dbe853
Parent:
9:cc23b2049639
Child:
13:1f3a8d0be511
--- a/src/wbit_util.cpp	Thu Oct 18 17:17:26 2018 +0000
+++ b/src/wbit_util.cpp	Thu Jan 17 14:21:33 2019 +0000
@@ -11,8 +11,16 @@
 
 //network keys
 //these are used as backup keys in case nvm memory is corrupted and we can't read the keys correctly
-uint8_t network_id[] = { 0x90, 0xF1, 0x47, 0x90, 0x6C, 0x48, 0x1D, 0x29 };   //static id not used anymore but don't comment out                                
-uint8_t network_key[] = { 0x0F, 0xF9, 0xA2, 0x90, 0x2E, 0xAA, 0x6B, 0x8C, 0x6A, 0x4E, 0xFD, 0x67, 0xF9, 0xA6, 0xF3, 0xD3 };   //OTAA appkey    
+uint8_t key_AppEUI[] = { 0x90, 0xF1, 0x47, 0x90, 0x6C, 0x48, 0x1D, 0x29 };   //AppEui                              
+uint8_t key_AppKey[] = { 0x0F, 0xF9, 0xA2, 0x90, 0x2E, 0xAA, 0x6B, 0x8C, 0x6A, 0x4E, 0xFD, 0x67, 0xF9, 0xA6, 0xF3, 0xD3 };   ////OTAA appkey    => loriot "Appkey" -> common to all nodes    
+
+
+//ADP keys: for xdot spoofer eui ---> need to be uploaded from proc, using EUI: 
+static uint8_t network_address[] =  { 0x01,0x48,0xF8,0x9A}; //0148F89A
+static uint8_t network_session_key[] = { 0x67, 0x9B, 0x67, 0x1F, 0x4B, 0xF4, 0x04, 0xD9, 0xD7, 0x1F, 0x9E, 0x00, 0xB3, 0x5D, 0x02, 0x48 };
+static uint8_t data_session_key[] =    { 0xB5, 0xB4, 0x2A, 0xB0, 0x2C, 0xC7, 0x8F, 0x5D, 0x83, 0x99, 0x73, 0xB7, 0x24, 0x63, 0x6B, 0xBC };
+
+
 
 //============================================================================
 // printRadioCfg
@@ -46,23 +54,43 @@
      if(verbose){
         pc.printf("\r\n************************************************************"); 
         pc.printf("\r\nnon-volatile memory (nvm):"); 
-        pc.printf("\r\nnetwork_id:");      
-        for (i = 0; i < sizeof(network_id);i++) 
-            pc.printf(" %x",pNvm->network_id[i]);
-        pc.printf("\r\nnetwork_key:"); 
-        for (i = 0 ; i < sizeof(network_key);i++)
-            pc.printf(" %x",pNvm->network_key[i]);        
+        pc.printf("\r\nkey_AppEUI:");      
+        for (i = 0; i < sizeof(key_AppEUI);i++) 
+            pc.printf(" %x",pNvm->key_AppEUI[i]);
+        pc.printf("\r\nkey_AppKey:"); 
+        for (i = 0 ; i < sizeof(key_AppKey);i++)
+            pc.printf(" %x",pNvm->key_AppKey[i]);        
         pc.printf("\r\nbLogOutputOn: %d ",pNvm->bLogOutputOn); 
 
         pc.printf("\r\n static backup keys:"); 
-        pc.printf("\r\nnetwork_id:");      
-        for (i = 0; i < sizeof(network_id);i++) 
-            pc.printf(" %x",network_id[i]);
-        pc.printf("\r\nnetwork_key:"); 
-        for (i = 0 ; i < sizeof(network_key);i++)
-            pc.printf(" %x",network_key[i]);        
+        pc.printf("\r\nkey_AppEUI:");      
+        for (i = 0; i < sizeof(key_AppEUI);i++) 
+            pc.printf(" %x",key_AppEUI[i]);
+        pc.printf("\r\nkey_AppKey:"); 
+        for (i = 0 ; i < sizeof(key_AppKey);i++)
+            pc.printf(" %x",key_AppKey[i]);        
      }  
      if(verbose)pc.printf("\r\n************************************************************\r\n"); 
+}
+//==============================================================================
+//printNvmABPData
+//==============================================================================
+void printNvmABPData(nvmABP *pNvmABP){
+     uint8_t i;         
+     if(verbose){
+        pc.printf("\r\n************************************************************"); 
+        pc.printf("\r\nnon-volatile memory (nvm) for ABP credendtials:"); 
+        pc.printf("\r\nnetworkSessionKey:");      
+        for (i = 0; i < 16;i++) 
+            pc.printf(" %x",pNvmABP->key_nsk[i]);
+        pc.printf("\r\n:appicationSessonKey"); 
+        for (i = 0; i < 16; i++)
+            pc.printf(" %x",pNvmABP->key_aps[i]);        
+        pc.printf("\r\n:DevAddr");             
+        for (i = 0 ; i < 8; i++)
+            pc.printf(" %x",pNvmABP->devAdr[i]);        
+     }  
+     if(verbose)pc.printf("\r\n************************************************************\r\n");      
 }                              
 //==============================================================================
 //getNvmChkSum
@@ -77,13 +105,36 @@
     return chksum;    
 }    
 //==============================================================================
+//getNvmADPChkSum
+//compute chksum for nvm data; don't include chksum byte in nvm struc
+// TODO: COMBINE TWO CHKSUM PROCEDURES
+//==============================================================================
+uint8_t getNvmABPChkSum(nvmABP *pNvmABP){
+    
+    uint8_t i;
+    uint8_t chksum= 0;   
+    uint8_t *pData = (uint8_t *)pNvmABP;
+    
+    for (i = 0 ; i < sizeof(nvmABP)-1;i++)chksum += pData[i];
+    return chksum;       
+}
+//==============================================================================
 //nvmWrite
 //write nvmData struc to nvm memory
 //==============================================================================
 bool nvmWrite(nvm *pNvm){   
    pNvm->chksum = getNvmChkSum(pNvm);
    printNmvData(pNvm);
-   return dot->nvmWrite(0,pNvm,sizeof(nvm));     
+   return dot->nvmWrite(NVM_ADDR_OTAA,pNvm,sizeof(nvm));     
+}
+//==============================================================================
+//nvmWriteABP
+//write nvmABPData struc to nvm memory   TODO: WRITE PROCEDUREES
+//==============================================================================
+bool nvmWriteABP(nvmABP *pNvmABP){   
+   pNvmABP->chksum = getNvmABPChkSum(pNvmABP);
+   printNvmABPData(pNvmABP);
+   return dot->nvmWrite(NVM_ADDR_OTAA,pNvmABP,sizeof(nvmABP));     
 }
 //==============================================================================
 //nvmRestorekeys
@@ -91,16 +142,16 @@
 //==============================================================================
 bool nvmRestore(nvm *pNvm){
     uint8_t i;
-    for (i = 0; i < sizeof(network_id);i++){
-        pNvm->network_id[i] = network_id[i];   
+    for (i = 0; i < sizeof(key_AppEUI);i++){
+        pNvm->key_AppEUI[i] = key_AppEUI[i];   
     }    
-    for (i = 0; i < sizeof(network_key);i++){
-        pNvm->network_key[i] = network_key[i];   
+    for (i = 0; i < sizeof(key_AppKey);i++){
+        pNvm->key_AppKey[i] = key_AppKey[i];   
     }
     pNvm->chksum = getNvmChkSum(pNvm);
     if(verbose)pc.printf("\r\n restoring backup keys:"); 
     printNmvData(pNvm);
-    return dot->nvmWrite(0,pNvm,sizeof(nvm));    
+    return dot->nvmWrite(NVM_ADDR_OTAA,pNvm,sizeof(nvm));    
 }       
 //==============================================================================
 //nvmRead
@@ -109,7 +160,7 @@
 //==============================================================================
 bool nvmRead(nvm *pNvm){     
    uint8_t i;  
-   dot->nvmRead(0,pNvm,sizeof(nvm));  
+   dot->nvmRead(NVM_ADDR_OTAA,pNvm,sizeof(nvm));  
    uint8_t chksum = getNvmChkSum(pNvm);
    
    if (chksum == pNvm->chksum){
@@ -118,6 +169,23 @@
    }    
    return false;
 }
+
+//==============================================================================
+//nvmReadABP
+//- read nvmDataABP struc from nvm memory
+//- if bad chksum then default to hard code network keys 
+//==============================================================================
+bool nvmReadABP(nvmABP *pNvmABP){     
+   uint8_t i;  
+   dot->nvmRead(NVM_ADDR_OTAA,pNvmABP,sizeof(nvmABP));  
+   uint8_t chksum = getNvmABPChkSum(pNvmABP);
+   
+   if (chksum == pNvmABP->chksum){
+       logInfo("nvmRead: chksum ok");           
+       return true;
+   }    
+   return false;   
+}
 //============================================================================
 
 uint8_t join_network_attempts_wbit() {