fix(nimble): Fix issues found in review for nimble examples

This commit is contained in:
Rahul Tank
2026-07-24 15:19:38 +05:30
parent 0185451ed1
commit 46f3837611
74 changed files with 1298 additions and 612 deletions
@@ -113,7 +113,7 @@ void ble_receive_apple_notification_source(uint8_t *message, uint16_t message_le
uint8_t CategoryID = message[2];
char *Cidstr = CategoryID_to_String(CategoryID);
uint8_t CategoryCount = message[3];
uint32_t NotificationUID = (message[4]) | (message[5]<< 8) | (message[6]<< 16) | (message[7] << 24);
uint32_t NotificationUID = ((uint32_t)message[4]) | ((uint32_t)message[5] << 8) | ((uint32_t)message[6] << 16) | ((uint32_t)message[7] << 24);
ESP_LOGI(NimBLE_ANCS_TAG, "EventID:%s EventFlags:0x%x CategoryID:%s CategoryCount:%d NotificationUID:%" PRIu32, EventIDS, EventFlags, Cidstr, CategoryCount, NotificationUID);
}
@@ -131,14 +131,18 @@ void ble_receive_apple_data_source(uint8_t *message, uint16_t message_len)
message_len);
return;
}
uint32_t NotificationUID = (message[1]) | (message[2]<< 8) | (message[3]<< 16) | (message[4] << 24);
uint32_t NotificationUID = ((uint32_t)message[1]) | ((uint32_t)message[2] << 8) | ((uint32_t)message[3] << 16) | ((uint32_t)message[4] << 24);
uint32_t remain_attr_len = message_len - 5;
uint8_t *attrs = &message[5];
ESP_LOGI(NimBLE_ANCS_TAG, "recevice Notification Attributes response Command_id %d NotificationUID %" PRIu32, Command_id, NotificationUID);
while(remain_attr_len > 0) {
if (remain_attr_len < 3) {
ESP_LOGE(NimBLE_ANCS_TAG, "incomplete attribute header");
break;
}
uint8_t AttributeID = attrs[0];
uint16_t len = attrs[1] | (attrs[2] << 8);
if(len > (remain_attr_len -3)) {
if(len > (remain_attr_len - 3)) {
ESP_LOGE(NimBLE_ANCS_TAG, "data error");
break;
}
+22 -2
View File
@@ -344,7 +344,7 @@ ext_ble_ancs_advertise(void)
params.connectable = 1;
/* advertise using configured addr */
params.own_addr_type = BLE_OWN_ADDR_PUBLIC;
params.own_addr_type = own_addr_type;
params.primary_phy = BLE_HCI_LE_PHY_1M;
params.secondary_phy = BLE_HCI_LE_PHY_2M;
params.tx_power = 127;
@@ -413,11 +413,15 @@ ble_ancs_advertise(void)
fields.tx_pwr_lvl_is_present = 1;
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
#if CONFIG_BT_NIMBLE_GAP_SERVICE
name = ble_svc_gap_device_name();
fields.name = (uint8_t *)name;
fields.name_len = strlen(name);
fields.name_is_complete = 1;
#endif
static const ble_uuid16_t adv_uuids16[] = { BLE_UUID16_INIT(0x1811) };
fields.uuids16 = adv_uuids16;
fields.num_uuids16 = 1;
fields.uuids16_is_complete = 1;
@@ -485,6 +489,7 @@ ble_ancs_gap_event(struct ble_gap_event *event, void *arg)
#else
ble_ancs_advertise();
#endif
return 0;
}
/** Initiate security - It will perform
@@ -544,7 +549,11 @@ ble_ancs_gap_event(struct ble_gap_event *event, void *arg)
assert(rc == 0);
ble_ancs_print_conn_desc(&desc);
MODLOG_DFLT(INFO, "\n");
rc = ble_gattc_disc_svc_by_uuid(event->connect.conn_handle, &APPLE_NC_UUID.u,
if (event->enc_change.status != 0) {
MODLOG_DFLT(ERROR, "encryption failed; status=%d\n", event->enc_change.status);
return 0;
}
rc = ble_gattc_disc_svc_by_uuid(event->enc_change.conn_handle, &APPLE_NC_UUID.u,
ancs_service_discovered_cb, NULL);
if (rc != 0) {
return rc;
@@ -563,6 +572,10 @@ ble_ancs_gap_event(struct ble_gap_event *event, void *arg)
case BLE_GAP_EVENT_NOTIFY_RX:
/* Peer sent us a notification or indication. */
if (event->notify_rx.attr_handle == notification_source_handle) {
if (event->notify_rx.om == NULL || event->notify_rx.om->om_len < 8) {
MODLOG_DFLT(ERROR, "NOTIFY_RX: short or NULL notification source packet\n");
return 0;
}
ble_receive_apple_notification_source(event->notify_rx.om->om_data, event->notify_rx.om->om_len);
uint8_t *notificationUID = &event->notify_rx.om->om_data[4];
if (event->notify_rx.om->om_data[0] == EventIDNotificationAdded &&
@@ -773,6 +786,13 @@ app_main(void)
/* XXX Need to have template for store */
ble_store_config_init();
ret = esp_timer_create(&periodic_timer_args, &periodic_timer);
if (ret != ESP_OK) {
ESP_LOGE(tag, "Failed to create periodic timer: %d", ret);
nimble_port_deinit();
return;
}
nimble_port_freertos_init(ble_ancs_host_task);
}