Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki(https://github.com/sevencore/BLEFOTA).

Dependencies:   mbed

Fork of mbed_fota by KIM HyoengJun

Bluetooth Low Energy based Firmware Over The Air with Mbed. Mbed part is a external processor of the IoT devices and communicate with a Bluetooth module. The Bluetooth module have to support BLE and implement BLE FOTA profile designed by ours. BLE FOTA profile specification is available from our GIT hub wiki.

Revision:
5:e11b23f9aacc
Parent:
4:60be78a172c2
Child:
6:8dd20294b2aa
diff -r 60be78a172c2 -r e11b23f9aacc dialog_fota/app.cpp
--- a/dialog_fota/app.cpp	Wed Jun 24 08:50:07 2015 +0000
+++ b/dialog_fota/app.cpp	Mon Jul 13 06:32:05 2015 +0000
@@ -2,14 +2,28 @@
 #include "gapm_task.h"
 #include "dialog_fota_config.h"
 #include "diss_task.h"
-
+#include "fota_server_task.h"
 
 namespace sevencore_fota{
+    
+struct app_env_tag app_env;
 
 void app_rst_gap(BleMsgHandler *BMH)
 {
     struct gapm_reset_cmd gm_cmd;
     gm_cmd.operation = GAPM_RESET;
+    
+    app_env.state = APP_IDLE;
+    app_env.num_of_devices = 0;
+    for (int i=0; i < MAX_SCAN_DEVICES; i++)
+    {
+        app_env.devices[i].free = true;
+        app_env.devices[i].adv_addr.addr[0] = '\0';
+        app_env.devices[i].data[0] = '\0';
+        app_env.devices[i].data_len = 0;
+        app_env.devices[i].rssi = 0;
+    }
+    
     uint8_t *msg;
     unsigned short msg_size = 1+sizeof(ble_hdr) + sizeof(gapm_reset_cmd);
     msg = new uint8_t[msg_size];
@@ -27,7 +41,7 @@
     // Add DIS in the database
     struct diss_create_db_req req;
     unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct diss_create_db_req);
-    req.features = APP_DIS_FEATURES;
+    req.features = 0x01FF;
     
     msg = new uint8_t[msg_size];
     
@@ -35,6 +49,20 @@
     BMH->BleSendMsg(msg,msg_size);
 }
 
+void app_fota_server_db_create(BleMsgHandler* BMH)
+{
+    uint8_t *msg;
+    // Add DIS in the database
+    struct fota_server_create_db_req req;
+    unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct fota_server_create_db_req);
+    req.features = 0x01FF;
+    
+    msg = new uint8_t[msg_size];
+    
+    BMH->BleMsgAlloc(FOTA_SERVER_CREATE_DB_REQ,TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_create_db_req),&req,msg);
+    BMH->BleSendMsg(msg,msg_size);
+}
+
 void app_adv_start(BleMsgHandler* BMH)
 {
     uint8_t device_name_length;
@@ -151,6 +179,8 @@
     // Device Name write permission requirements for peer device
     cmd.name_write_perm = GAPM_WRITE_DISABLE;
     // Peripheral only: *****************************************************************
+    // Maximum trasnimt unit size
+    //cmd.max_mtu = 16;
     // Slave preferred Minimum of connection interval
     cmd.con_intv_min = 8;         // 10ms (8*1.25ms)
     // Slave preferred Maximum of connection interval
@@ -169,4 +199,70 @@
 }
 
 
+void app_fota_server_enable(ble_dev *device,BleMsgHandler* BMH)
+{
+    uint8_t *msg;
+    struct fota_server_enable_req req;
+    unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(struct fota_server_enable_req);
+    req.conhdl = device->conhdl;
+    req.sec_lvl = 1;
+    
+    msg = new uint8_t[msg_size];
+
+    // Send the message
+    BMH->BleMsgAlloc(FOTA_SERVER_ENABLE_REQ, TASK_FOTA_SERVER, TASK_GTL,sizeof(struct fota_server_enable_req),&req,msg);
+    BMH->BleSendMsg(msg,msg_size);
+}
+
+void app_dis_enable(ble_dev *device,BleMsgHandler* BMH)
+{
+    uint8_t *msg;
+    // Allocate the message
+    struct diss_enable_req req;
+    unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(diss_enable_req);
+    // Fill in the parameter structure
+    req.conhdl             = device->conhdl;
+    req.sec_lvl            = 1;
+    req.con_type           = PRF_CON_DISCOVERY;
+
+    msg = new uint8_t[msg_size];
+    
+    // Send the message
+    BMH->BleMsgAlloc(DISS_ENABLE_REQ,TASK_DISS, TASK_GTL, sizeof(struct diss_enable_req),&req,msg);
+    BMH->BleSendMsg(msg,msg_size);
+}
+
+void app_connect_confirm(uint8_t auth,ble_dev *device,BleMsgHandler* BMH)
+{
+    uint8_t *msg;
+    // confirm connection
+    struct gapc_connection_cfm cfm;
+    unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(gapc_connection_cfm);
+    cfm.auth = auth;
+    cfm.authorize = GAP_AUTHZ_NOT_SET;
+    
+    msg = new uint8_t[msg_size];
+
+    // Send the message
+    BMH->BleMsgAlloc(GAPC_CONNECTION_CFM, KE_BUILD_ID(TASK_GAPC,device->conidx), TASK_GTL,sizeof (struct gapc_connection_cfm),&cfm,msg);
+    BMH->BleSendMsg(msg,msg_size);
+}
+
+void app_send_disconnect(uint16_t dst, uint16_t conhdl, uint8_t reason,BleMsgHandler* BMH)
+{
+    uint8_t *msg;
+    struct gapc_disconnect_ind disconnect_ind; 
+    unsigned short msg_size = 1 + sizeof(ble_hdr) + sizeof(gapc_disconnect_ind);
+    // fill parameters
+    disconnect_ind.conhdl   = conhdl;
+    disconnect_ind.reason   = reason;
+    
+    msg = new uint8_t[msg_size];
+
+    // send indication
+    BMH->BleMsgAlloc(GAPC_DISCONNECT_IND,dst, TASK_GTL,sizeof(struct gapc_disconnect_ind),&disconnect_ind,msg);
+    BMH->BleSendMsg(msg,msg_size);
+}
+
+
 }//namespace