SW encryption

Files at this revision

API Documentation at this revision

Comitter:
liamcox94
Date:
Tue Mar 19 16:06:19 2019 +0000
Parent:
47:b6d132f1079f
Child:
49:3b27f622a798
Commit message:
aes#1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-lora-radio-drv.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Jan 27 21:45:34 2019 +0000
+++ b/main.cpp	Tue Mar 19 16:06:19 2019 +0000
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 #include <stdio.h>
+#include <iostream>
 
 #include "lorawan/LoRaWANInterface.h"
 #include "lorawan/system/lorawan_data_structures.h"
@@ -25,13 +26,15 @@
 #include "trace_helper.h"
 #include "lora_radio_helper.h"
 
+#include "sha256.h"
+
 using namespace events;
 
 // Max payload size can be LORAMAC_PHY_MAXPAYLOAD.
 // This example only communicates with much shorter messages (<30 bytes).
 // If longer messages are used, these buffers must be changed accordingly.
-uint8_t tx_buffer[30];
-uint8_t rx_buffer[30];
+uint8_t tx_buffer[44];
+uint8_t rx_buffer[44];
 
 /*
  * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing
@@ -96,7 +99,7 @@
     setup_trace();
 
     // stores the status of a call to LoRaWAN protocol
-    lorawan_status_t retcode;
+    lorawan_status_t loraStatus;
 
     // Initialize LoRaWAN stack
     if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) {
@@ -128,15 +131,14 @@
 
     printf("\r\n Adaptive data  rate (ADR) - Enabled \r\n");
 
-    retcode = lorawan.connect();
+    loraStatus = lorawan.connect();
 
-    if (retcode == LORAWAN_STATUS_OK ||
-            retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
+    if (loraStatus == LORAWAN_STATUS_OK ||
+            loraStatus == LORAWAN_STATUS_CONNECT_IN_PROGRESS) {
     } else {
-        printf("\r\n Connection error, code = %d \r\n", retcode);
+        printf("\r\n Connection error, code = %d \r\n", loraStatus);
         return -1;
     }
-
     printf("\r\n Connection - In Progress ...\r\n");
 
     // make your event queue dispatching events forever
@@ -148,45 +150,46 @@
 /**
  * Sends a message to the Network Server
  */
-static void send_message()
-{
-    uint16_t packet_len;
-    int16_t retcode;
-    float sensor_value;
+static void send_message() {
+  uint16_t packet_cont;
+  int16_t loraStatus;
+  /*****************************************************************************************************/
+
+  uint8_t hash_content = 77;
+  char hash_str[] = "";
+  sprintf(hash_str, "%d", hash_content);
 
-    if (ds1820.begin()) {
-        ds1820.startConversion();
-        sensor_value = ds1820.read();
-        printf("\r\n Dummy Sensor Value = %3.1f \r\n", sensor_value);
-        ds1820.startConversion();
-    } else {
-        printf("\r\n No sensor found \r\n");
-        return;
-    }
+  static const unsigned char * hash_buffer = (const unsigned char * ) hash_str;
+  static const size_t hash_len = strlen(hash_str);
+  unsigned char output[32];
 
-    packet_len = sprintf((char *) tx_buffer, "Dummy Sensor Value is %3.1f",
-                         sensor_value);
+  mbedtls_sha256(hash_buffer, hash_len, output, 0);
+
+  const char * c = (const char * ) output;
+
+  /*****************************************************************************************************/
 
-    retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len,
-                           MSG_UNCONFIRMED_FLAG);
+  packet_cont = sprintf((char * ) tx_buffer, c);
 
-    if (retcode < 0) {
-        retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n")
-        : printf("\r\n send() - Error code %d \r\n", retcode);
+  loraStatus = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_cont,
+    MSG_UNCONFIRMED_FLAG);
+
+  if (loraStatus < 0) {
+    loraStatus == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n") :
+      printf("\r\n send() - Error code %d \r\n", loraStatus);
 
-        if (retcode == LORAWAN_STATUS_WOULD_BLOCK) {
-            //retry in 3 seconds
-            if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
-                ev_queue.call_in(3000, send_message);
-            }
-        }
-        return;
+    if (loraStatus == LORAWAN_STATUS_WOULD_BLOCK) {
+      //retry in 3 seconds
+      if (MBED_CONF_LORA_DUTY_CYCLE_ON) {
+        ev_queue.call_in(3000, send_message);
+      }
     }
+    return;
+  }
 
-    printf("\r\n %d bytes scheduled for transmission \r\n", retcode);
-    memset(tx_buffer, 0, sizeof(tx_buffer));
+  printf("\r\n %d bytes scheduled for transmission \r\n", loraStatus);
+  memset(tx_buffer, 0, sizeof(tx_buffer));
 }
-
 /**
  * Receive a message from the Network Server
  */
@@ -267,4 +270,4 @@
     }
 }
 
-// EOF
+// EOF
\ No newline at end of file
--- a/mbed-lora-radio-drv.lib	Sun Jan 27 21:45:34 2019 +0000
+++ b/mbed-lora-radio-drv.lib	Tue Mar 19 16:06:19 2019 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-semtech-lora-rf-drivers#16958f814d505cfbbedfa16d9bf8b9dff0e0442b
+https://github.com/ARMmbed/mbed-semtech-lora-rf-drivers/#16958f814d505cfbbedfa16d9bf8b9dff0e0442b
--- a/mbed_app.json	Sun Jan 27 21:45:34 2019 +0000
+++ b/mbed_app.json	Tue Mar 19 16:06:19 2019 +0000
@@ -2,7 +2,7 @@
     "config": {
         "lora-radio": {
             "help": "Which radio to use (options: SX1272,SX1276)",
-            "value": "SX1276"
+            "value": "SX1272"
         },
         "main_stack_size":     { "value": 4096 },
 
@@ -33,9 +33,9 @@
             "lora.over-the-air-activation": true,
             "lora.duty-cycle-on": true,
             "lora.phy": "EU868",
-            "lora.device-eui": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
-            "lora.application-eui": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }",
-            "lora.application-key": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }"
+            "lora.device-eui": "{ 0x00, 0x85, 0xA3, 0xA4, 0x84, 0x32, 0x12, 0xDD }",
+            "lora.application-eui": "{ 0x70, 0xB3, 0xD5, 0x7E, 0xD0, 0x01, 0x4C, 0x0D }",
+            "lora.application-key": "{ 0x1C, 0x75, 0xE1, 0xB1, 0x1D, 0xB0, 0xBD, 0x38, 0xDB, 0xEF, 0x2C, 0x6C, 0x0C, 0x6B, 0x62, 0x2D }"
         },
 
         "K64F": {