| 
															
																@@ -2,7 +2,7 @@ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																  * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
 
															 | 
															
															 | 
															
																  * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																  *
 
															 | 
															
															 | 
															
																  *
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																  * SPDX-License-Identifier: Apache-2.0
 
															 | 
															
															 | 
															
																  * SPDX-License-Identifier: Apache-2.0
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-*/
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+ */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #include "esp_log.h"
 
															 | 
															
															 | 
															
																 #include "esp_log.h"
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #include "nvs_flash.h"
 
															 | 
															
															 | 
															
																 #include "nvs_flash.h"
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -20,34 +20,56 @@ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 bool is_conn = false;
 
															 | 
															
															 | 
															
																 bool is_conn = false;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #ifdef CONFIG_PRE_ENC_OTA
 
															 | 
															
															 | 
															
																 #ifdef CONFIG_PRE_ENC_OTA
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define SECTOR_END_ID                       2
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define ENC_HEADER                          512
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define SECTOR_END_ID 2
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define ENC_HEADER 512
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 esp_decrypt_handle_t decrypt_handle_cmp;
 
															 | 
															
															 | 
															
																 esp_decrypt_handle_t decrypt_handle_cmp;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define BUF_LENGTH                          4096
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define OTA_IDX_NB                          4
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define CMD_ACK_LENGTH                      20
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define BUF_LENGTH 4096
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define OTA_IDX_NB 4
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define CMD_ACK_LENGTH 20
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define character_declaration_uuid          BLE_ATT_UUID_CHARACTERISTIC
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define character_client_config_uuid        BLE_ATT_UUID_CHARACTERISTIC
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define character_declaration_uuid BLE_ATT_UUID_CHARACTERISTIC
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define character_client_config_uuid BLE_ATT_UUID_CHARACTERISTIC
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define GATT_SVR_SVC_ALERT_UUID             0x1811
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define BLE_OTA_SERVICE_UUID                0x8018
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define GATT_SVR_SVC_ALERT_UUID 0x1811
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define BLE_OTA_SERVICE_UUID 0x8018
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define RECV_FW_UUID                        0x8020
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define OTA_BAR_UUID                        0x8021
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define COMMAND_UUID                        0x8022
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#define CUSTOMER_UUID                       0x8023
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define RECV_FW_UUID 0x8020
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define OTA_BAR_UUID 0x8021
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define COMMAND_UUID 0x8022
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#define CUSTOMER_UUID 0x8023
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
															
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 static uint8_t ext_adv_pattern[] = {
 
															 | 
															
															 | 
															
																 static uint8_t ext_adv_pattern[] = {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    0x02, 0x01, 0x06,
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    0x03, 0x03, 0xab, 0xcd,
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    0x03, 0x03, 0x18, 0x11,
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    0x0f, 0X09, 'n', 'i', 'm', 'b', 'l', 'e', '-', 'o', 't', 'a', '-', 'e', 'x', 't',
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x02,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x01,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x06,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x03,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x03,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0xab,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0xcd,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x03,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x03,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x18,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x11,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0x0f,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    0X09,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'n',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'i',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'm',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'b',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'l',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'e',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    '-',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'o',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    't',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'a',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    '-',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'e',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    'x',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    't',
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 };
 
															 | 
															
															 | 
															
																 };
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -64,8 +86,7 @@ static uint32_t ota_total_len = 0; 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 static uint32_t ota_block_size = BUF_LENGTH;
 
															 | 
															
															 | 
															
																 static uint32_t ota_block_size = BUF_LENGTH;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 esp_ble_ota_callback_funs_t ota_cb_fun_t = {
 
															 | 
															
															 | 
															
																 esp_ble_ota_callback_funs_t ota_cb_fun_t = {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    .recv_fw_cb = NULL
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-};
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    .recv_fw_cb = NULL};
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #ifndef CONFIG_OTA_WITH_PROTOCOMM
 
															 | 
															
															 | 
															
																 #ifndef CONFIG_OTA_WITH_PROTOCOMM
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 esp_ble_ota_notification_check_t ota_notification = {
 
															 | 
															
															 | 
															
																 esp_ble_ota_notification_check_t ota_notification = {
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -97,7 +118,7 @@ esp_ble_ota_notification_data(uint16_t conn_handle, uint16_t attr_handle, uint8_ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 /*----------------------------------------------------
 
															 | 
															
															 | 
															
																 /*----------------------------------------------------
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																- * Common api's 
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+ * Common api's
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																  *----------------------------------------------------*/
 
															 | 
															
															 | 
															
																  *----------------------------------------------------*/
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 void ble_store_config_init(void);
 
															 | 
															
															 | 
															
																 void ble_store_config_init(void);
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -119,7 +140,8 @@ esp_ble_ota_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     pargs.data_in_len = om->om_len - 3;
 
															 | 
															
															 | 
															
																     pargs.data_in_len = om->om_len - 3;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (SLIST_NEXT(om, om_next) != NULL) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (SLIST_NEXT(om, om_next) != NULL)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         struct os_mbuf *temp2 = SLIST_NEXT(om, om_next);
 
															 | 
															
															 | 
															
																         struct os_mbuf *temp2 = SLIST_NEXT(om, om_next);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         pargs.data_in_len += temp2->om_len;
 
															 | 
															
															 | 
															
																         pargs.data_in_len += temp2->om_len;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -127,12 +149,14 @@ esp_ble_ota_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     pargs.data_in = (const char *)malloc(pargs.data_in_len * sizeof(char *));
 
															 | 
															
															 | 
															
																     pargs.data_in = (const char *)malloc(pargs.data_in_len * sizeof(char *));
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     err = os_mbuf_copydata(om, 3, pargs.data_in_len, pargs.data_in);
 
															 | 
															
															 | 
															
																     err = os_mbuf_copydata(om, 3, pargs.data_in_len, pargs.data_in);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (om->om_data[2] == 0xff) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (om->om_data[2] == 0xff)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         pargs.data_in_len -= SECTOR_END_ID;
 
															 | 
															
															 | 
															
																         pargs.data_in_len -= SECTOR_END_ID;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     err = esp_encrypted_img_decrypt_data(decrypt_handle_cmp, &pargs);
 
															 | 
															
															 | 
															
																     err = esp_encrypted_img_decrypt_data(decrypt_handle_cmp, &pargs);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (err != ESP_OK && err != ESP_ERR_NOT_FINISHED) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (err != ESP_OK && err != ESP_ERR_NOT_FINISHED)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return;
 
															 | 
															
															 | 
															
																         return;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -140,22 +164,25 @@ esp_ble_ota_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     uint8_t cmd_ack[CMD_ACK_LENGTH] = {0x03, 0x00, 0x00, 0x00, 0x00,
 
															 | 
															
															 | 
															
																     uint8_t cmd_ack[CMD_ACK_LENGTH] = {0x03, 0x00, 0x00, 0x00, 0x00,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
															
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
															
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                                       0x00, 0x00, 0x00, 0x00, 0x00
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                                      };
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                                       0x00, 0x00, 0x00, 0x00, 0x00};
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     uint16_t crc16;
 
															 | 
															
															 | 
															
																     uint16_t crc16;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if ((om->om_data[0] + (om->om_data[1] * 256)) != cur_sector) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if ((om->om_data[0] + (om->om_data[1] * 256)) != cur_sector)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         // sector error
 
															 | 
															
															 | 
															
																         // sector error
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if ((om->om_data[0] == 0xff) && (om->om_data[1] == 0xff)) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if ((om->om_data[0] == 0xff) && (om->om_data[1] == 0xff))
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             // last sector
 
															 | 
															
															 | 
															
																             // last sector
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGD(TAG, "Last sector");
 
															 | 
															
															 | 
															
																             ESP_LOGD(TAG, "Last sector");
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             // sector error
 
															 | 
															
															 | 
															
																             // sector error
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGE(TAG, "%s - sector index error, cur: %" PRIu32 ", recv: %d", __func__,
 
															 | 
															
															 | 
															
																             ESP_LOGE(TAG, "%s - sector index error, cur: %" PRIu32 ", recv: %d", __func__,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                      cur_sector, (om->om_data[0] + (om->om_data[1] * 256)));
 
															 | 
															
															 | 
															
																                      cur_sector, (om->om_data[0] + (om->om_data[1] * 256)));
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             cmd_ack[0] = om->om_data[0];
 
															 | 
															
															 | 
															
																             cmd_ack[0] = om->om_data[0];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             cmd_ack[1] = om->om_data[1];
 
															 | 
															
															 | 
															
																             cmd_ack[1] = om->om_data[1];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            cmd_ack[2] = 0x02; //sector index error
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            cmd_ack[2] = 0x02; // sector index error
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             cmd_ack[3] = 0x00;
 
															 | 
															
															 | 
															
																             cmd_ack[3] = 0x00;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             cmd_ack[4] = cur_sector & 0xff;
 
															 | 
															
															 | 
															
																             cmd_ack[4] = cur_sector & 0xff;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             cmd_ack[5] = (cur_sector & 0xff00) >> 8;
 
															 | 
															
															 | 
															
																             cmd_ack[5] = (cur_sector & 0xff00) >> 8;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -168,11 +195,15 @@ esp_ble_ota_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (om->om_data[2] != cur_packet) { // packet seq error
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (om->om_data[2] == 0xff) { // last packet
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (om->om_data[2] != cur_packet)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    { // packet seq error
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (om->om_data[2] == 0xff)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        { // last packet
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGD(TAG, "last packet");
 
															 | 
															
															 | 
															
																             ESP_LOGD(TAG, "last packet");
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             goto write_ota_data;
 
															 | 
															
															 | 
															
																             goto write_ota_data;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        } else { // packet seq error
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        { // packet seq error
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGE(TAG, "%s - packet index error, cur: %" PRIu32 ", recv: %d", __func__,
 
															 | 
															
															 | 
															
																             ESP_LOGE(TAG, "%s - packet index error, cur: %" PRIu32 ", recv: %d", __func__,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                      cur_packet, om->om_data[2]);
 
															 | 
															
															 | 
															
																                      cur_packet, om->om_data[2]);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -180,7 +211,8 @@ esp_ble_ota_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 write_ota_data:
 
															 | 
															
															 | 
															
																 write_ota_data:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #ifdef CONFIG_PRE_ENC_OTA
 
															 | 
															
															 | 
															
																 #ifdef CONFIG_PRE_ENC_OTA
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if(pargs.data_out_len > 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (pargs.data_out_len > 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         memcpy(fw_buf + fw_buf_offset, pargs.data_out, pargs.data_out_len);
 
															 | 
															
															 | 
															
																         memcpy(fw_buf + fw_buf_offset, pargs.data_out, pargs.data_out_len);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         free(pargs.data_out);
 
															 | 
															
															 | 
															
																         free(pargs.data_out);
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -194,7 +226,8 @@ write_ota_data: 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     memcpy(fw_buf + fw_buf_offset, om->om_data + 3, om->om_len - 3);
 
															 | 
															
															 | 
															
																     memcpy(fw_buf + fw_buf_offset, om->om_data + 3, om->om_len - 3);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     fw_buf_offset += om->om_len - 3;
 
															 | 
															
															 | 
															
																     fw_buf_offset += om->om_len - 3;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (SLIST_NEXT(om, om_next) != NULL) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (SLIST_NEXT(om, om_next) != NULL)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         struct os_mbuf *temp = SLIST_NEXT(om, om_next);
 
															 | 
															
															 | 
															
																         struct os_mbuf *temp = SLIST_NEXT(om, om_next);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         memcpy(fw_buf + fw_buf_offset, temp->om_data, temp->om_len);
 
															 | 
															
															 | 
															
																         memcpy(fw_buf + fw_buf_offset, temp->om_data, temp->om_len);
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -206,21 +239,27 @@ write_ota_data: 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     ESP_LOGD(TAG, "DEBUG: Sector:%" PRIu32 ", total length:%" PRIu32 ", length:%d", cur_sector,
 
															 | 
															
															 | 
															
																     ESP_LOGD(TAG, "DEBUG: Sector:%" PRIu32 ", total length:%" PRIu32 ", length:%d", cur_sector,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																              fw_buf_offset, om->om_len - 3);
 
															 | 
															
															 | 
															
																              fw_buf_offset, om->om_len - 3);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (om->om_data[2] == 0xff) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (om->om_data[2] == 0xff)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         cur_packet = 0;
 
															 | 
															
															 | 
															
																         cur_packet = 0;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         cur_sector++;
 
															 | 
															
															 | 
															
																         cur_sector++;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGD(TAG, "DEBUG: recv %" PRIu32 " sector", cur_sector);
 
															 | 
															
															 | 
															
																         ESP_LOGD(TAG, "DEBUG: recv %" PRIu32 " sector", cur_sector);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         goto sector_end;
 
															 | 
															
															 | 
															
																         goto sector_end;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGD(TAG, "DEBUG: wait next packet");
 
															 | 
															
															 | 
															
																         ESP_LOGD(TAG, "DEBUG: wait next packet");
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         cur_packet++;
 
															 | 
															
															 | 
															
																         cur_packet++;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     return;
 
															 | 
															
															 | 
															
																     return;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 sector_end:
 
															 | 
															
															 | 
															
																 sector_end:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (fw_buf_offset < ota_block_size) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (fw_buf_offset < ota_block_size)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         esp_ble_ota_recv_fw_handler(fw_buf, fw_buf_offset);
 
															 | 
															
															 | 
															
																         esp_ble_ota_recv_fw_handler(fw_buf, fw_buf_offset);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         esp_ble_ota_recv_fw_handler(fw_buf, ota_block_size);
 
															 | 
															
															 | 
															
																         esp_ble_ota_recv_fw_handler(fw_buf, ota_block_size);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     fw_buf_offset = 0;
 
															 | 
															
															 | 
															
																     fw_buf_offset = 0;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -228,7 +267,7 @@ sector_end: 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     cmd_ack[0] = om->om_data[0];
 
															 | 
															
															 | 
															
																     cmd_ack[0] = om->om_data[0];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     cmd_ack[1] = om->om_data[1];
 
															 | 
															
															 | 
															
																     cmd_ack[1] = om->om_data[1];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    cmd_ack[2] = 0x00; //success
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    cmd_ack[2] = 0x00; // success
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     cmd_ack[3] = 0x00;
 
															 | 
															
															 | 
															
																     cmd_ack[3] = 0x00;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     crc16 = crc16_ccitt(cmd_ack, 18);
 
															 | 
															
															 | 
															
																     crc16 = crc16_ccitt(cmd_ack, 18);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     cmd_ack[18] = crc16 & 0xff;
 
															 | 
															
															 | 
															
																     cmd_ack[18] = crc16 & 0xff;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -244,13 +283,18 @@ static uint16_t crc16_ccitt(const unsigned char *buf, int len) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     uint16_t crc16 = 0;
 
															 | 
															
															 | 
															
																     uint16_t crc16 = 0;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     int32_t i;
 
															 | 
															
															 | 
															
																     int32_t i;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    while (len--) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    while (len--)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         crc16 ^= *buf++ << 8;
 
															 | 
															
															 | 
															
																         crc16 ^= *buf++ << 8;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        for (i = 0; i < 8; i++) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            if (crc16 & 0x8000) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        for (i = 0; i < 8; i++)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            if (crc16 & 0x8000)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 crc16 = (crc16 << 1) ^ 0x1021;
 
															 | 
															
															 | 
															
																                 crc16 = (crc16 << 1) ^ 0x1021;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 crc16 = crc16 << 1;
 
															 | 
															
															 | 
															
																                 crc16 = crc16 << 1;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             }
 
															 | 
															
															 | 
															
																             }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -272,7 +316,8 @@ unsigned int esp_ble_ota_get_fw_length(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 static esp_err_t
 
															 | 
															
															 | 
															
																 static esp_err_t
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 esp_ble_ota_recv_fw_handler(uint8_t *buf, uint32_t length)
 
															 | 
															
															 | 
															
																 esp_ble_ota_recv_fw_handler(uint8_t *buf, uint32_t length)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (ota_cb_fun_t.recv_fw_cb) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (ota_cb_fun_t.recv_fw_cb)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ota_cb_fun_t.recv_fw_cb(buf, length);
 
															 | 
															
															 | 
															
																         ota_cb_fun_t.recv_fw_cb(buf, length);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -286,7 +331,7 @@ esp_err_t esp_ble_ota_recv_fw_data_callback(esp_ble_ota_recv_fw_cb_t callback) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     return ESP_OK;
 
															 | 
															
															 | 
															
																     return ESP_OK;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 }
 
															 | 
															
															 | 
															
																 }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #else
 
															 | 
															
															 | 
															
																 #else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-esp_err_t esp_ble_ota_recv_fw_data_callback(esp_ble_ota_recv_fw_cb_t callback, 
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+esp_err_t esp_ble_ota_recv_fw_data_callback(esp_ble_ota_recv_fw_cb_t callback,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                             esp_decrypt_handle_t esp_decrypt_handle)
 
															 | 
															
															 | 
															
																                                             esp_decrypt_handle_t esp_decrypt_handle)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     decrypt_handle_cmp = esp_decrypt_handle;
 
															 | 
															
															 | 
															
																     decrypt_handle_cmp = esp_decrypt_handle;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -300,15 +345,13 @@ esp_err_t esp_ble_ota_recv_fw_data_callback(esp_ble_ota_recv_fw_cb_t callback, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																  *----------------------------------------------------*/
 
															 | 
															
															 | 
															
																  *----------------------------------------------------*/
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #ifdef CONFIG_OTA_WITH_PROTOCOMM
 
															 | 
															
															 | 
															
																 #ifdef CONFIG_OTA_WITH_PROTOCOMM
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-void
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-esp_ble_ota_set_sizes(size_t file_size, size_t block_size)
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+void esp_ble_ota_set_sizes(size_t file_size, size_t block_size)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     ota_total_len = file_size;
 
															 | 
															
															 | 
															
																     ota_total_len = file_size;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     ota_block_size = block_size;
 
															 | 
															
															 | 
															
																     ota_block_size = block_size;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 }
 
															 | 
															
															 | 
															
																 }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-void
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-esp_ble_ota_finish(void)
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+void esp_ble_ota_finish(void)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     ESP_LOGI(TAG, "Received OTA end command");
 
															 | 
															
															 | 
															
																     ESP_LOGI(TAG, "Received OTA end command");
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     start_ota = false;
 
															 | 
															
															 | 
															
																     start_ota = false;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -318,8 +361,7 @@ esp_ble_ota_finish(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     fw_buf = NULL;
 
															 | 
															
															 | 
															
																     fw_buf = NULL;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 }
 
															 | 
															
															 | 
															
																 }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-void
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-esp_ble_ota_write(uint8_t *file, size_t length)
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+void esp_ble_ota_write(uint8_t *file, size_t length)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     struct os_mbuf *om = ble_hs_mbuf_from_flat(file, length);
 
															 | 
															
															 | 
															
																     struct os_mbuf *om = ble_hs_mbuf_from_flat(file, length);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     esp_ble_ota_write_chr(om);
 
															 | 
															
															 | 
															
																     esp_ble_ota_write_chr(om);
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -336,12 +378,12 @@ ble_ota_start_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     uint8_t cmd_ack[CMD_ACK_LENGTH] = {0x03, 0x00, 0x00, 0x00, 0x00,
 
															 | 
															
															 | 
															
																     uint8_t cmd_ack[CMD_ACK_LENGTH] = {0x03, 0x00, 0x00, 0x00, 0x00,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
															
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
															
															 | 
															
																                                        0x00, 0x00, 0x00, 0x00, 0x00,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                                       0x00, 0x00, 0x00, 0x00, 0x00
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                                      };
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                                       0x00, 0x00, 0x00, 0x00, 0x00};
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     uint16_t crc16;
 
															 | 
															
															 | 
															
																     uint16_t crc16;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     esp_ble_ota_char_t ota_char = find_ota_char_and_desr_by_handle(attribute_handle);
 
															 | 
															
															 | 
															
																     esp_ble_ota_char_t ota_char = find_ota_char_and_desr_by_handle(attribute_handle);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if ((om->om_data[0] == 0x01) && (om->om_data[1] == 0x00)) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if ((om->om_data[0] == 0x01) && (om->om_data[1] == 0x00))
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         start_ota = true;
 
															 | 
															
															 | 
															
																         start_ota = true;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ota_total_len = (om->om_data[2]) + (om->om_data[3] * 256) +
 
															 | 
															
															 | 
															
																         ota_total_len = (om->om_data[2]) + (om->om_data[3] * 256) +
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -355,12 +397,15 @@ ble_ota_start_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         fw_buf = (uint8_t *)malloc(ota_block_size * sizeof(uint8_t));
 
															 | 
															
															 | 
															
																         fw_buf = (uint8_t *)malloc(ota_block_size * sizeof(uint8_t));
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #else
 
															 | 
															
															 | 
															
																 #else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																- fw_buf = (uint8_t *)heap_caps_malloc(ota_block_size * sizeof(uint8_t),MALLOC_CAP_8BIT|MALLOC_CAP_SPIRAM);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        fw_buf = (uint8_t *)heap_caps_malloc(ota_block_size * sizeof(uint8_t), MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (fw_buf == NULL) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (fw_buf == NULL)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGE(TAG, "%s -  malloc fail", __func__);
 
															 | 
															
															 | 
															
																             ESP_LOGE(TAG, "%s -  malloc fail", __func__);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             memset(fw_buf, 0x0, ota_block_size);
 
															 | 
															
															 | 
															
																             memset(fw_buf, 0x0, ota_block_size);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         cmd_ack[2] = 0x01;
 
															 | 
															
															 | 
															
																         cmd_ack[2] = 0x01;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -369,11 +414,14 @@ ble_ota_start_write_chr(struct os_mbuf *om) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         cmd_ack[18] = crc16 & 0xff;
 
															 | 
															
															 | 
															
																         cmd_ack[18] = crc16 & 0xff;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         cmd_ack[19] = (crc16 & 0xff00) >> 8;
 
															 | 
															
															 | 
															
																         cmd_ack[19] = (crc16 & 0xff00) >> 8;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         esp_ble_ota_notification_data(connection_handle, attribute_handle, cmd_ack, ota_char);
 
															 | 
															
															 | 
															
																         esp_ble_ota_notification_data(connection_handle, attribute_handle, cmd_ack, ota_char);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    } else if ((om->om_data[0] == 0x02) && (om->om_data[1] == 0x00)) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    else if ((om->om_data[0] == 0x02) && (om->om_data[1] == 0x00))
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         printf("\nCMD_CHAR -> 0 : %d, 1 : %d", om->om_data[0],
 
															 | 
															
															 | 
															
																         printf("\nCMD_CHAR -> 0 : %d, 1 : %d", om->om_data[0],
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                om->om_data[1]);
 
															 | 
															
															 | 
															
																                om->om_data[1]);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #ifdef CONFIG_PRE_ENC_OTA
 
															 | 
															
															 | 
															
																 #ifdef CONFIG_PRE_ENC_OTA
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (esp_encrypted_img_decrypt_end(decrypt_handle_cmp) != ESP_OK) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (esp_encrypted_img_decrypt_end(decrypt_handle_cmp) != ESP_OK)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGI(TAG, "Decryption end failed");
 
															 | 
															
															 | 
															
																             ESP_LOGI(TAG, "Decryption end failed");
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -396,7 +444,8 @@ gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     char buf[BLE_UUID_STR_LEN];
 
															 | 
															
															 | 
															
																     char buf[BLE_UUID_STR_LEN];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    switch (ctxt->op) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    switch (ctxt->op)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case BLE_GATT_REGISTER_OP_SVC:
 
															 | 
															
															 | 
															
																     case BLE_GATT_REGISTER_OP_SVC:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGD(TAG, "registered service %s with handle=%d\n",
 
															 | 
															
															 | 
															
																         ESP_LOGD(TAG, "registered service %s with handle=%d\n",
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
 
															 | 
															
															 | 
															
																                  ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -405,7 +454,7 @@ gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case BLE_GATT_REGISTER_OP_CHR:
 
															 | 
															
															 | 
															
																     case BLE_GATT_REGISTER_OP_CHR:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGD(TAG, "registering characteristic %s with "
 
															 | 
															
															 | 
															
																         ESP_LOGD(TAG, "registering characteristic %s with "
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                 "def_handle=%d val_handle=%d\n",
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                      "def_handle=%d val_handle=%d\n",
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
 
															 | 
															
															 | 
															
																                  ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  ctxt->chr.def_handle,
 
															 | 
															
															 | 
															
																                  ctxt->chr.def_handle,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  ctxt->chr.val_handle);
 
															 | 
															
															 | 
															
																                  ctxt->chr.val_handle);
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -432,7 +481,8 @@ ble_ota_gatt_handler(uint16_t conn_handle, uint16_t attr_handle, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     attribute_handle = attr_handle;
 
															 | 
															
															 | 
															
																     attribute_handle = attr_handle;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    switch (ctxt->op) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    switch (ctxt->op)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case BLE_GATT_ACCESS_OP_READ_CHR:
 
															 | 
															
															 | 
															
																     case BLE_GATT_ACCESS_OP_READ_CHR:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ota_char = find_ota_char_and_desr_by_handle(attr_handle);
 
															 | 
															
															 | 
															
																         ota_char = find_ota_char_and_desr_by_handle(attr_handle);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGI(TAG, "client read, ota_char: %d", ota_char);
 
															 | 
															
															 | 
															
																         ESP_LOGI(TAG, "client read, ota_char: %d", ota_char);
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -443,14 +493,19 @@ ble_ota_gatt_handler(uint16_t conn_handle, uint16_t attr_handle, 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ota_char = find_ota_char_and_desr_by_handle(attr_handle);
 
															 | 
															
															 | 
															
																         ota_char = find_ota_char_and_desr_by_handle(attr_handle);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGD(TAG, "client write; len = %d", ctxt->om->om_len);
 
															 | 
															
															 | 
															
																         ESP_LOGD(TAG, "client write; len = %d", ctxt->om->om_len);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (ota_char == RECV_FW_CHAR) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            if (start_ota) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (ota_char == RECV_FW_CHAR)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            if (start_ota)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 esp_ble_ota_write_chr(ctxt->om);
 
															 | 
															
															 | 
															
																                 esp_ble_ota_write_chr(ctxt->om);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 ESP_LOGE(TAG, "%s -  don't receive the start cmd", __func__);
 
															 | 
															
															 | 
															
																                 ESP_LOGE(TAG, "%s -  don't receive the start cmd", __func__);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             }
 
															 | 
															
															 | 
															
																             }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        } else if (ota_char == CMD_CHAR) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        else if (ota_char == CMD_CHAR)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ble_ota_start_write_chr(ctxt->om);
 
															 | 
															
															 | 
															
																             ble_ota_start_write_chr(ctxt->om);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         break;
 
															 | 
															
															 | 
															
																         break;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -466,36 +521,38 @@ static const struct ble_gatt_svc_def ota_gatt_db[] = { 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         /* OTA Service Declaration */
 
															 | 
															
															 | 
															
																         /* OTA Service Declaration */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         .type = BLE_GATT_SVC_TYPE_PRIMARY,
 
															 | 
															
															 | 
															
																         .type = BLE_GATT_SVC_TYPE_PRIMARY,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         .uuid = BLE_UUID16_DECLARE(BLE_OTA_SERVICE_UUID),
 
															 | 
															
															 | 
															
																         .uuid = BLE_UUID16_DECLARE(BLE_OTA_SERVICE_UUID),
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        .characteristics = (struct ble_gatt_chr_def[])
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        .characteristics = (struct ble_gatt_chr_def[]){
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             {
 
															 | 
															
															 | 
															
																             {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 /* Receive Firmware Characteristic */
 
															 | 
															
															 | 
															
																                 /* Receive Firmware Characteristic */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(RECV_FW_UUID),
 
															 | 
															
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(RECV_FW_UUID),
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
															
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .val_handle = &receive_fw_val,
 
															 | 
															
															 | 
															
																                 .val_handle = &receive_fw_val,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_WRITE,
 
															 | 
															
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_WRITE,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            }, {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            },
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 /* OTA Characteristic */
 
															 | 
															
															 | 
															
																                 /* OTA Characteristic */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(OTA_BAR_UUID),
 
															 | 
															
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(OTA_BAR_UUID),
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
															
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .val_handle = &ota_status_val,
 
															 | 
															
															 | 
															
																                 .val_handle = &ota_status_val,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_READ,
 
															 | 
															
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_READ,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            }, {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            },
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 /* Command Characteristic */
 
															 | 
															
															 | 
															
																                 /* Command Characteristic */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(COMMAND_UUID),
 
															 | 
															
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(COMMAND_UUID),
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
															
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .val_handle = &command_val,
 
															 | 
															
															 | 
															
																                 .val_handle = &command_val,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_WRITE,
 
															 | 
															
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_WRITE,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            }, {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            },
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 /* Customer characteristic */
 
															 | 
															
															 | 
															
																                 /* Customer characteristic */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(CUSTOMER_UUID),
 
															 | 
															
															 | 
															
																                 .uuid = BLE_UUID16_DECLARE(CUSTOMER_UUID),
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
															
															 | 
															
																                 .access_cb = ble_ota_gatt_handler,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .val_handle = &custom_val,
 
															 | 
															
															 | 
															
																                 .val_handle = &custom_val,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_WRITE,
 
															 | 
															
															 | 
															
																                 .flags = BLE_GATT_CHR_F_INDICATE | BLE_GATT_CHR_F_WRITE,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            }, {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            },
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 0, /* No more characteristics in this service */
 
															 | 
															
															 | 
															
																                 0, /* No more characteristics in this service */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            }
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        },
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            }},
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     },
 
															 | 
															
															 | 
															
																     },
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     {
 
															 | 
															
															 | 
															
																     {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         0, /* No more services */
 
															 | 
															
															 | 
															
																         0, /* No more services */
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -507,9 +564,12 @@ find_ota_char_and_desr_by_handle(uint16_t handle) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     esp_ble_ota_char_t ret = INVALID_CHAR;
 
															 | 
															
															 | 
															
																     esp_ble_ota_char_t ret = INVALID_CHAR;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    for (int i = 0; i < OTA_IDX_NB ; i++) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (handle == ota_handle_table[i]) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            switch (i) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    for (int i = 0; i < OTA_IDX_NB; i++)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (handle == ota_handle_table[i])
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            switch (i)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+            {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             case RECV_FW_CHAR_VAL_IDX:
 
															 | 
															
															 | 
															
																             case RECV_FW_CHAR_VAL_IDX:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 ret = RECV_FW_CHAR;
 
															 | 
															
															 | 
															
																                 ret = RECV_FW_CHAR;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                 break;
 
															 | 
															
															 | 
															
																                 break;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -540,24 +600,29 @@ esp_ble_ota_notification_data(uint16_t conn_handle, uint16_t attr_handle, uint8_ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     int rc;
 
															 | 
															
															 | 
															
																     int rc;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     txom = ble_hs_mbuf_from_flat(cmd_ack, CMD_ACK_LENGTH);
 
															 | 
															
															 | 
															
																     txom = ble_hs_mbuf_from_flat(cmd_ack, CMD_ACK_LENGTH);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    switch (ota_char) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    switch (ota_char)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case RECV_FW_CHAR:
 
															 | 
															
															 | 
															
																     case RECV_FW_CHAR:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (ota_notification.recv_fw_ntf_enable) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (ota_notification.recv_fw_ntf_enable)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             notify_enable = true;
 
															 | 
															
															 | 
															
																             notify_enable = true;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         break;
 
															 | 
															
															 | 
															
																         break;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case OTA_STATUS_CHAR:
 
															 | 
															
															 | 
															
																     case OTA_STATUS_CHAR:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (ota_notification.process_bar_ntf_enable) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (ota_notification.process_bar_ntf_enable)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             notify_enable = true;
 
															 | 
															
															 | 
															
																             notify_enable = true;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         break;
 
															 | 
															
															 | 
															
																         break;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case CMD_CHAR:
 
															 | 
															
															 | 
															
																     case CMD_CHAR:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (ota_notification.command_ntf_enable) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (ota_notification.command_ntf_enable)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             notify_enable = true;
 
															 | 
															
															 | 
															
																             notify_enable = true;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         break;
 
															 | 
															
															 | 
															
																         break;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case CUS_CHAR:
 
															 | 
															
															 | 
															
																     case CUS_CHAR:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (ota_notification.customer_ntf_enable) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (ota_notification.customer_ntf_enable)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             notify_enable = true;
 
															 | 
															
															 | 
															
																             notify_enable = true;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         break;
 
															 | 
															
															 | 
															
																         break;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -565,11 +630,15 @@ esp_ble_ota_notification_data(uint16_t conn_handle, uint16_t attr_handle, uint8_ 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         break;
 
															 | 
															
															 | 
															
																         break;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (notify_enable) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (notify_enable)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         rc = ble_gattc_notify_custom(conn_handle, attr_handle, txom);
 
															 | 
															
															 | 
															
																         rc = ble_gattc_notify_custom(conn_handle, attr_handle, txom);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (rc == 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (rc == 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGD(TAG, "Notification sent, attr_handle = %d", attr_handle);
 
															 | 
															
															 | 
															
																             ESP_LOGD(TAG, "Notification sent, attr_handle = %d", attr_handle);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ESP_LOGE(TAG, "Error in sending notification, rc = %d", rc);
 
															 | 
															
															 | 
															
																             ESP_LOGE(TAG, "Error in sending notification, rc = %d", rc);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         }
 
															 | 
															
															 | 
															
																         }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return rc;
 
															 | 
															
															 | 
															
																         return rc;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -618,7 +687,7 @@ esp_ble_ota_print_conn_desc(struct ble_gap_conn_desc *desc) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																              desc->peer_id_addr.type);
 
															 | 
															
															 | 
															
																              desc->peer_id_addr.type);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     print_addr(desc->peer_id_addr.val);
 
															 | 
															
															 | 
															
																     print_addr(desc->peer_id_addr.val);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     ESP_LOGI(TAG, " conn_itvl=%d conn_latency=%d supervision_timeout=%d "
 
															 | 
															
															 | 
															
																     ESP_LOGI(TAG, " conn_itvl=%d conn_latency=%d supervision_timeout=%d "
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-             "encrypted=%d authenticated=%d bonded=%d\n",
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                  "encrypted=%d authenticated=%d bonded=%d\n",
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																              desc->conn_itvl, desc->conn_latency,
 
															 | 
															
															 | 
															
																              desc->conn_itvl, desc->conn_latency,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																              desc->supervision_timeout,
 
															 | 
															
															 | 
															
																              desc->supervision_timeout,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																              desc->sec_state.encrypted,
 
															 | 
															
															 | 
															
																              desc->sec_state.encrypted,
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -641,11 +710,11 @@ esp_ble_ota_ext_advertise(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     int rc;
 
															 | 
															
															 | 
															
																     int rc;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* First check if any instance is already active */
 
															 | 
															
															 | 
															
																     /* First check if any instance is already active */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if(ble_gap_adv_active())
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (ble_gap_adv_active())
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return;
 
															 | 
															
															 | 
															
																         return;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* use defaults for non-set params */
 
															 | 
															
															 | 
															
																     /* use defaults for non-set params */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    memset (¶ms, 0, sizeof(params));
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    memset(¶ms, 0, sizeof(params));
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* enable connectable advertising */
 
															 | 
															
															 | 
															
																     /* enable connectable advertising */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     params.connectable = 1;
 
															 | 
															
															 | 
															
																     params.connectable = 1;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -655,7 +724,7 @@ esp_ble_ota_ext_advertise(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     params.primary_phy = BLE_HCI_LE_PHY_1M;
 
															 | 
															
															 | 
															
																     params.primary_phy = BLE_HCI_LE_PHY_1M;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     params.secondary_phy = BLE_HCI_LE_PHY_2M;
 
															 | 
															
															 | 
															
																     params.secondary_phy = BLE_HCI_LE_PHY_2M;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    //params.tx_power = 127;
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    // params.tx_power = 127;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     params.sid = 1;
 
															 | 
															
															 | 
															
																     params.sid = 1;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     params.itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
 
															 | 
															
															 | 
															
																     params.itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -664,7 +733,7 @@ esp_ble_ota_ext_advertise(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* configure instance 0 */
 
															 | 
															
															 | 
															
																     /* configure instance 0 */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL,
 
															 | 
															
															 | 
															
																     rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                                    esp_ble_ota_gap_event, NULL);
 
															 | 
															
															 | 
															
																                                    esp_ble_ota_gap_event, NULL);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    assert (rc == 0);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    assert(rc == 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* in this case only scan response is allowed */
 
															 | 
															
															 | 
															
																     /* in this case only scan response is allowed */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* get mbuf for scan rsp data */
 
															 | 
															
															 | 
															
																     /* get mbuf for scan rsp data */
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -676,11 +745,11 @@ esp_ble_ota_ext_advertise(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     assert(rc == 0);
 
															 | 
															
															 | 
															
																     assert(rc == 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_gap_ext_adv_set_data(instance, data);
 
															 | 
															
															 | 
															
																     rc = ble_gap_ext_adv_set_data(instance, data);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    assert (rc == 0);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    assert(rc == 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* start advertising */
 
															 | 
															
															 | 
															
																     /* start advertising */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_gap_ext_adv_start(instance, 0, 0);
 
															 | 
															
															 | 
															
																     rc = ble_gap_ext_adv_start(instance, 0, 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    assert (rc == 0);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    assert(rc == 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 }
 
															 | 
															
															 | 
															
																 }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #else
 
															 | 
															
															 | 
															
																 #else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 static void
 
															 | 
															
															 | 
															
																 static void
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -720,14 +789,14 @@ esp_ble_ota_advertise(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     fields.name_len = strlen(name);
 
															 | 
															
															 | 
															
																     fields.name_len = strlen(name);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     fields.name_is_complete = 1;
 
															 | 
															
															 | 
															
																     fields.name_is_complete = 1;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    fields.uuids16 = (ble_uuid16_t[]) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID)
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    };
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    fields.uuids16 = (ble_uuid16_t[]){
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID)};
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     fields.num_uuids16 = 1;
 
															 | 
															
															 | 
															
																     fields.num_uuids16 = 1;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     fields.uuids16_is_complete = 1;
 
															 | 
															
															 | 
															
																     fields.uuids16_is_complete = 1;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_gap_adv_set_fields(&fields);
 
															 | 
															
															 | 
															
																     rc = ble_gap_adv_set_fields(&fields);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (rc != 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (rc != 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGE(TAG, "error setting advertisement data; rc=%d\n", rc);
 
															 | 
															
															 | 
															
																         ESP_LOGE(TAG, "error setting advertisement data; rc=%d\n", rc);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return;
 
															 | 
															
															 | 
															
																         return;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -738,7 +807,8 @@ esp_ble_ota_advertise(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
 
															 | 
															
															 | 
															
																     adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
 
															 | 
															
															 | 
															
																     rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                            &adv_params, esp_ble_ota_gap_event, NULL);
 
															 | 
															
															 | 
															
																                            &adv_params, esp_ble_ota_gap_event, NULL);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (rc != 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (rc != 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGE(TAG, "error enabling advertisement; rc=%d\n", rc);
 
															 | 
															
															 | 
															
																         ESP_LOGE(TAG, "error enabling advertisement; rc=%d\n", rc);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return;
 
															 | 
															
															 | 
															
																         return;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -767,20 +837,24 @@ esp_ble_ota_gap_event(struct ble_gap_event *event, void *arg) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     int rc;
 
															 | 
															
															 | 
															
																     int rc;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     esp_ble_ota_char_t ota_char;
 
															 | 
															
															 | 
															
																     esp_ble_ota_char_t ota_char;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    switch (event->type) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    switch (event->type)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     case BLE_GAP_EVENT_CONNECT:
 
															 | 
															
															 | 
															
																     case BLE_GAP_EVENT_CONNECT:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         /* A new connection was established or a connection attempt failed. */
 
															 | 
															
															 | 
															
																         /* A new connection was established or a connection attempt failed. */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGI(TAG, "connection %s; status=%d ",
 
															 | 
															
															 | 
															
																         ESP_LOGI(TAG, "connection %s; status=%d ",
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  event->connect.status == 0 ? "established" : "failed",
 
															 | 
															
															 | 
															
																                  event->connect.status == 0 ? "established" : "failed",
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  event->connect.status);
 
															 | 
															
															 | 
															
																                  event->connect.status);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        if (event->connect.status == 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        if (event->connect.status == 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             is_conn = true;
 
															 | 
															
															 | 
															
																             is_conn = true;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
 
															 | 
															
															 | 
															
																             rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             assert(rc == 0);
 
															 | 
															
															 | 
															
																             assert(rc == 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             esp_ble_ota_print_conn_desc(&desc);
 
															 | 
															
															 | 
															
																             esp_ble_ota_print_conn_desc(&desc);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             connection_handle = event->connect.conn_handle;
 
															 | 
															
															 | 
															
																             connection_handle = event->connect.conn_handle;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        } else {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             /* Connection failed; resume advertising. */
 
															 | 
															
															 | 
															
																             /* Connection failed; resume advertising. */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
															
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             esp_ble_ota_ext_advertise();
 
															 | 
															
															 | 
															
																             esp_ble_ota_ext_advertise();
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -799,7 +873,7 @@ esp_ble_ota_gap_event(struct ble_gap_event *event, void *arg) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         /* Connection terminated; resume advertising. */
 
															 | 
															
															 | 
															
																         /* Connection terminated; resume advertising. */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
															
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         esp_ble_ota_ext_advertise();
 
															 | 
															
															 | 
															
																         esp_ble_ota_ext_advertise();
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#else       
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         esp_ble_ota_advertise();
 
															 | 
															
															 | 
															
																         esp_ble_ota_advertise();
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return 0;
 
															 | 
															
															 | 
															
																         return 0;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -837,7 +911,7 @@ esp_ble_ota_gap_event(struct ble_gap_event *event, void *arg) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGI(TAG, "client subscribe ble_gap_event, ota_char: %d", ota_char);
 
															 | 
															
															 | 
															
																         ESP_LOGI(TAG, "client subscribe ble_gap_event, ota_char: %d", ota_char);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGI(TAG, "subscribe event; conn_handle=%d attr_handle=%d "
 
															 | 
															
															 | 
															
																         ESP_LOGI(TAG, "subscribe event; conn_handle=%d attr_handle=%d "
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                 "reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+                      "reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  event->subscribe.conn_handle,
 
															 | 
															
															 | 
															
																                  event->subscribe.conn_handle,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  event->subscribe.attr_handle,
 
															 | 
															
															 | 
															
																                  event->subscribe.attr_handle,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  event->subscribe.reason,
 
															 | 
															
															 | 
															
																                  event->subscribe.reason,
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -846,7 +920,8 @@ esp_ble_ota_gap_event(struct ble_gap_event *event, void *arg) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  event->subscribe.prev_indicate,
 
															 | 
															
															 | 
															
																                  event->subscribe.prev_indicate,
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																                  event->subscribe.cur_indicate);
 
															 | 
															
															 | 
															
																                  event->subscribe.cur_indicate);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-        switch (ota_char) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        switch (ota_char)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+        {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         case RECV_FW_CHAR:
 
															 | 
															
															 | 
															
																         case RECV_FW_CHAR:
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             ota_notification.recv_fw_ntf_enable = true;
 
															 | 
															
															 | 
															
																             ota_notification.recv_fw_ntf_enable = true;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																             break;
 
															 | 
															
															 | 
															
																             break;
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -895,8 +970,7 @@ esp_ble_ota_gap_event(struct ble_gap_event *event, void *arg) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     return 0;
 
															 | 
															
															 | 
															
																     return 0;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 }
 
															 | 
															
															 | 
															
																 }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-int
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-ble_ota_gatt_svr_init(void)
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+int ble_ota_gatt_svr_init(void)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 {
 
															 | 
															
															 | 
															
																 {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     int rc;
 
															 | 
															
															 | 
															
																     int rc;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -904,12 +978,14 @@ ble_ota_gatt_svr_init(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     ble_svc_gatt_init();
 
															 | 
															
															 | 
															
																     ble_svc_gatt_init();
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_gatts_count_cfg(ota_gatt_db);
 
															 | 
															
															 | 
															
																     rc = ble_gatts_count_cfg(ota_gatt_db);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (rc != 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (rc != 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return rc;
 
															 | 
															
															 | 
															
																         return rc;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_gatts_add_svcs(ota_gatt_db);
 
															 | 
															
															 | 
															
																     rc = ble_gatts_add_svcs(ota_gatt_db);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (rc != 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (rc != 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return rc;
 
															 | 
															
															 | 
															
																         return rc;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -932,7 +1008,8 @@ esp_ble_ota_on_sync(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* Figure out address to use while advertising (no privacy for now) */
 
															 | 
															
															 | 
															
																     /* Figure out address to use while advertising (no privacy for now) */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_hs_id_infer_auto(0, &own_addr_type);
 
															 | 
															
															 | 
															
																     rc = ble_hs_id_infer_auto(0, &own_addr_type);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (rc != 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (rc != 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGE(TAG, "error determining address type; rc=%d\n", rc);
 
															 | 
															
															 | 
															
																         ESP_LOGE(TAG, "error determining address type; rc=%d\n", rc);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return;
 
															 | 
															
															 | 
															
																         return;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -946,10 +1023,9 @@ esp_ble_ota_on_sync(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* Begin advertising. */
 
															 | 
															
															 | 
															
																     /* Begin advertising. */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
															
															 | 
															
																 #if CONFIG_EXAMPLE_EXTENDED_ADV
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     esp_ble_ota_ext_advertise();
 
															 | 
															
															 | 
															
																     esp_ble_ota_ext_advertise();
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-#else       
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#else
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     esp_ble_ota_advertise();
 
															 | 
															
															 | 
															
																     esp_ble_ota_advertise();
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #endif
 
															 | 
															
															 | 
															
																 #endif
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 }
 
															 | 
															
															 | 
															
																 }
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 void esp_ble_ota_host_task(void *param)
 
															 | 
															
															 | 
															
																 void esp_ble_ota_host_task(void *param)
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -967,7 +1043,8 @@ esp_ble_ota_host_init(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     int rc;
 
															 | 
															
															 | 
															
																     int rc;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
 
															 | 
															
															 | 
															
																 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-    if (esp_nimble_init() != 0) {
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    if (esp_nimble_init() != 0)
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    {
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         ESP_LOGE(TAG, "nimble host init failed\n");
 
															 | 
															
															 | 
															
																         ESP_LOGE(TAG, "nimble host init failed\n");
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																         return ESP_FAIL;
 
															 | 
															
															 | 
															
																         return ESP_FAIL;
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     }
 
															 | 
															
															 | 
															
																     }
 
															 | 
														
													
												
											
												
													
														
															 | 
															
																@@ -990,25 +1067,24 @@ esp_ble_ota_host_init(void) 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_ota_gatt_svr_init();
 
															 | 
															
															 | 
															
																     rc = ble_ota_gatt_svr_init();
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     assert(rc == 0);
 
															 | 
															
															 | 
															
																     assert(rc == 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            #include "esp_mac.h"
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            char* device_name = (char*)malloc(sizeof("YC-OTA#")+4);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            memcpy(device_name,"YC-OTA#",sizeof("YC-OTA#"));
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            uint8_t macAddr[7];
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            char mac_5[4];
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            char mac_6[4];
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            esp_read_mac((uint8_t *)macAddr, ESP_MAC_WIFI_STA);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            ESP_LOG_BUFFER_HEX(TAG,&macAddr,6);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            itoa(macAddr[4],mac_5,16);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            itoa(macAddr[5],mac_6,16);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            strcat(device_name,mac_5);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            strcat(device_name,mac_6);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-            ESP_LOGW(TAG,"ble name[%s]",device_name);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+#include "esp_mac.h"
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    char *device_name = (char *)malloc(sizeof("YC-OTA#") + 4);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    memcpy(device_name, "YC-OTA#", sizeof("YC-OTA#"));
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    uint8_t macAddr[7];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    char mac_5[4];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    char mac_6[4];
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    esp_read_mac((uint8_t *)macAddr, ESP_MAC_WIFI_STA);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    ESP_LOG_BUFFER_HEX(TAG, &macAddr, 6);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    itoa(macAddr[4], mac_5, 16);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    itoa(macAddr[5], mac_6, 16);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    strcat(device_name, mac_5);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    strcat(device_name, mac_6);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    ESP_LOGW(TAG, "ble name[%s]", device_name);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* Set the default device name. */
 
															 | 
															
															 | 
															
																     /* Set the default device name. */
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     rc = ble_svc_gap_device_name_set(device_name);
 
															 | 
															
															 | 
															
																     rc = ble_svc_gap_device_name_set(device_name);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																-                free(device_name);
 
															 | 
															
															 | 
															
																 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
															 | 
															
															 | 
															
																+    free(device_name);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     assert(rc == 0);
 
															 | 
															
															 | 
															
																     assert(rc == 0);
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																 
 
															 | 
															
															 | 
															
																 
 
															 | 
														
													
												
													
														
															| 
															 | 
															
																     /* XXX Need to have template for store */
 
															 | 
															
															 | 
															
																     /* XXX Need to have template for store */
 
															 |