mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-06-05 21:04:49 +00:00
feat(nimble): Support for sending NimBLE logs over SPI
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "services/ans/ble_svc_ans.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_ANS_SERVICE
|
||||
/* Max length of new alert info string */
|
||||
@@ -233,6 +234,7 @@ ble_svc_ans_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
&ble_svc_ans_alert_not_ctrl_pt,
|
||||
NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -335,10 +337,12 @@ ble_svc_ans_new_alert_add(uint8_t cat_id, const char * info_str)
|
||||
if (cat_id < BLE_SVC_ANS_CAT_NUM) {
|
||||
cat_bit_mask = (1 << cat_id);
|
||||
} else {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if ((cat_bit_mask & ble_svc_ans_new_alert_cat) == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -366,10 +370,12 @@ ble_svc_ans_unr_alert_add(uint8_t cat_id)
|
||||
if (cat_id < BLE_SVC_ANS_CAT_NUM) {
|
||||
cat_bit_mask = 1 << cat_id;
|
||||
} else {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if ((cat_bit_mask & ble_svc_ans_unr_alert_cat) == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "services/bas/ble_svc_bas.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_BAS_SERVICE
|
||||
/* Characteristic value handles */
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
* power.
|
||||
*/
|
||||
#include "../src/ble_hs_hci_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_AOA_AOD)
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "services/cts/ble_svc_cts.h"
|
||||
#include "time.h"
|
||||
#include <sys/time.h>
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_CTS_SERVICE
|
||||
static struct ble_svc_cts_cfg cts_cfg = {0};
|
||||
@@ -179,6 +180,7 @@ ble_svc_cts_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
}
|
||||
rc = ble_svc_cts_curr_time_validate(curr_time);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if(cts_cfg.set_time_cb == NULL) {
|
||||
@@ -222,6 +224,7 @@ ble_svc_cts_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
}
|
||||
rc = ble_svc_cts_local_time_info_validate(local_time_info);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "services/dis/ble_svc_dis.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_DIS_SERVICE
|
||||
|
||||
@@ -453,6 +454,7 @@ ble_svc_dis_init_dynamic(void)
|
||||
{
|
||||
ble_svc_dis_data_ptr = nimble_platform_mem_calloc(1, sizeof(*ble_svc_dis_data_ptr));
|
||||
if (!ble_svc_dis_data_ptr) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#include "os/endian.h"
|
||||
#include "esp_nimble_cfg.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
|
||||
@@ -237,6 +238,7 @@ ble_svc_gap_device_name_write_access(struct ble_gatt_access_ctxt *ctxt)
|
||||
|
||||
ble_hs_gap_svc_ctx->svc_gap_name = nimble_platform_mem_calloc(1, om_len + 1);
|
||||
if (!ble_hs_gap_svc_ctx->svc_gap_name) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -434,11 +436,13 @@ ble_svc_gap_device_name_set(const char *name)
|
||||
int len;
|
||||
|
||||
if (!name) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
len = strlen(name);
|
||||
if (len > BLE_SVC_GAP_NAME_MAX_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -447,6 +451,7 @@ ble_svc_gap_device_name_set(const char *name)
|
||||
ble_hs_gap_svc_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_hs_gap_svc_ctx));
|
||||
|
||||
if (!ble_hs_gap_svc_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -457,6 +462,7 @@ ble_svc_gap_device_name_set(const char *name)
|
||||
|
||||
ble_hs_gap_svc_ctx->svc_gap_name = nimble_platform_mem_calloc(1, len + 1);
|
||||
if (!ble_hs_gap_svc_ctx->svc_gap_name) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -489,6 +495,7 @@ ble_svc_gap_device_appearance_set(uint16_t appearance)
|
||||
if (!ble_hs_gap_svc_ctx) {
|
||||
int rc = ble_svc_gap_appearance_init();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -509,6 +516,7 @@ int
|
||||
ble_svc_gap_device_key_material_set(uint8_t *session_key, uint8_t *iv)
|
||||
{
|
||||
if (!session_key || !iv) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
memcpy(&ble_svc_gap_km.session_key, session_key, BLE_EAD_KEY_SIZE);
|
||||
@@ -526,6 +534,7 @@ ble_svc_gap_appearance_init(void)
|
||||
ble_hs_gap_svc_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_hs_gap_svc_ctx));
|
||||
|
||||
if (!ble_hs_gap_svc_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -539,6 +548,7 @@ static int
|
||||
ble_svc_gap_init_name(void)
|
||||
{
|
||||
if (!ble_hs_gap_svc_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -551,6 +561,7 @@ ble_svc_gap_init_name(void)
|
||||
|
||||
ble_hs_gap_svc_ctx->svc_gap_name = nimble_platform_mem_calloc(1, len + 1);
|
||||
if (!ble_hs_gap_svc_ctx->svc_gap_name) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "services/gatt/ble_svc_gatt.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS)
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
|
||||
#if MYNEWT_VAL(BLE_SVC_HID_SERVICE)
|
||||
@@ -202,6 +203,7 @@ fill_proto_mode(uint8_t instance)
|
||||
|
||||
chr = ble_svc_hid_get_chr_block();
|
||||
if (!chr) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memcpy(chr, &demo_chr, sizeof(struct ble_gatt_chr_def));
|
||||
@@ -245,6 +247,7 @@ fill_boot_kbd_inp(uint8_t instance)
|
||||
|
||||
chr = ble_svc_hid_get_chr_block();
|
||||
if (!chr) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memcpy(chr, &demo_chr, sizeof(struct ble_gatt_chr_def));
|
||||
@@ -278,6 +281,7 @@ fill_boot_kbd_out(uint8_t instance)
|
||||
|
||||
chr = ble_svc_hid_get_chr_block();
|
||||
if (!chr) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memcpy(chr, &demo_chr, sizeof(struct ble_gatt_chr_def));
|
||||
@@ -359,6 +363,7 @@ fill_rpt_map(uint8_t instance)
|
||||
this is done to indicate there are no more descriptors */
|
||||
dsc = ble_svc_hid_get_dsc(2);
|
||||
if (!dsc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memcpy(dsc, demo_dsc, 2 * sizeof(struct ble_gatt_dsc_def));
|
||||
@@ -366,6 +371,7 @@ fill_rpt_map(uint8_t instance)
|
||||
demo_chr.descriptors = dsc;
|
||||
chr = ble_svc_hid_get_chr_block();
|
||||
if (!chr) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memcpy(chr, &demo_chr, sizeof(struct ble_gatt_chr_def));
|
||||
@@ -400,6 +406,7 @@ fill_reports(uint8_t instance)
|
||||
this is done to indicate there are no more descriptors */
|
||||
dsc = ble_svc_hid_get_dsc(2);
|
||||
if (!dsc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
demo_dsc[0].arg = &hid_instances[instance].rpts[i].handle;
|
||||
@@ -432,6 +439,7 @@ fill_reports(uint8_t instance)
|
||||
|
||||
chr = ble_svc_hid_get_chr_block();
|
||||
if (!chr) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memcpy(chr, &demo_chr, sizeof(struct ble_gatt_chr_def));
|
||||
@@ -502,6 +510,7 @@ ble_svc_hid_end_chrs(void)
|
||||
struct ble_gatt_chr_def *chr;
|
||||
chr = ble_svc_hid_get_chr_block();
|
||||
if (chr == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memset(chr, 0, sizeof(struct ble_gatt_chr_def));
|
||||
@@ -797,6 +806,7 @@ ble_svc_hid_end(void)
|
||||
|
||||
svc = ble_svc_get_svc_block();
|
||||
if (svc == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memset(svc, 0, sizeof(struct ble_gatt_svc_def));
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "services/hr/ble_svc_hr.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_HR_SERVICE
|
||||
/* Characteristic values */
|
||||
@@ -179,12 +180,14 @@ ble_svc_hr_notify_measurement(void)
|
||||
txom = ble_hs_mbuf_from_flat(&ble_svc_hr_measurement,
|
||||
sizeof(ble_svc_hr_measurement));
|
||||
if (!txom) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
rc = ble_gatts_notify_custom(ble_svc_hr_conn_handle[i],
|
||||
ble_svc_hr_measurement_val_handle, txom);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "services/htp/ble_svc_htp.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_HTP_SERVICE
|
||||
/* Characteristic values */
|
||||
@@ -218,6 +219,9 @@ ble_svc_htp_notify(uint16_t conn_handle, float temp, bool temp_unit)
|
||||
|
||||
ble_gatts_chr_updated(ble_svc_htp_intr_temp_val_handle);
|
||||
err:
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -248,11 +252,15 @@ ble_svc_htp_indicate(uint16_t conn_handle, float temp, bool temp_unit)
|
||||
rc = os_mbuf_copyinto(txom, sizeof(flags), &temp, sizeof(temp));
|
||||
if (rc != 0) {
|
||||
os_mbuf_free_chain(txom);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_gatts_indicate_custom(conn_handle,
|
||||
ble_svc_htp_temp_measurement_val_handle, txom);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "services/ias/ble_svc_ias.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_IAS_SERVICE
|
||||
/* Callback function */
|
||||
@@ -112,6 +113,7 @@ ble_svc_ias_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
sizeof alert_level,
|
||||
&alert_level, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if (alert_level > BLE_SVC_IAS_ALERT_LEVEL_HIGH_ALERT) {
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "services/ipss/ble_svc_ipss.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_IPSS_SERVICE
|
||||
static const ble_uuid16_t uuid_svc_ipss = BLE_UUID16_INIT(BLE_SVC_IPSS_UUID16);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "services/lls/ble_svc_lls.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_LLS_SERVICE
|
||||
/* Callback function */
|
||||
@@ -176,6 +177,7 @@ int
|
||||
ble_svc_lls_alert_level_set(uint8_t alert_level)
|
||||
{
|
||||
if (alert_level > BLE_SVC_LLS_ALERT_LEVEL_HIGH_ALERT) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_gap.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#include "services/prox/ble_svc_prox.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_PROX_SERVICE
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "services/ras/ble_svc_ras.h"
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_cs.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#include "nimble/hci_common.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
@@ -320,6 +321,7 @@ static int gatt_svr_chr_access_ras_val(uint16_t conn_handle, uint16_t attr_handl
|
||||
sizeof(ble_svc_ras_cp_val),
|
||||
&ble_svc_ras_cp_val, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
MODLOG_DFLT(INFO, "ble_svc_gap_cp_val = %02x %02x %02x \n",ble_svc_ras_cp_val[0],ble_svc_ras_cp_val[1],ble_svc_ras_cp_val[2]);
|
||||
@@ -386,7 +388,6 @@ unknown:
|
||||
}
|
||||
|
||||
void ble_gatts_store_ranging_data(struct ble_cs_event ranging_subevent) {
|
||||
|
||||
struct ranging_buffer *buf = NULL;
|
||||
|
||||
/* Check if the subevent is already stored */
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "sysinit/sysinit.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "services/sps/ble_svc_sps.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
#include "esp_nimble_mem.h"
|
||||
#endif
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
* power.
|
||||
*/
|
||||
#include "../src/ble_hs_hci_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS) && CONFIG_BT_NIMBLE_TPS_SERVICE
|
||||
/* Access function */
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include "host/ble_aes_ccm.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_CRYPTO_STACK_MBEDTLS)
|
||||
#if CONFIG_MBEDTLS_VER_4_X_SUPPORT
|
||||
@@ -69,6 +70,7 @@ ble_aes_ccm_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *en
|
||||
status = psa_import_key(&attributes, key, 16, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
ESP_LOGE("ble_aes_ccm_encrypt_be", "psa_import_key failed with status %d", status);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -77,6 +79,7 @@ ble_aes_ccm_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *en
|
||||
if (status != PSA_SUCCESS || output_len != 16) {
|
||||
ESP_LOGE("ble_aes_ccm_encrypt_be", "psa_cipher_encrypt failed with status %d", status);
|
||||
psa_destroy_key(key_id);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -87,11 +90,13 @@ ble_aes_ccm_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *en
|
||||
|
||||
if (mbedtls_aes_setkey_enc(&s, key, 128) != 0) {
|
||||
mbedtls_aes_free(&s);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
if (mbedtls_aes_crypt_ecb(&s, MBEDTLS_AES_ENCRYPT, plaintext, enc_data) != 0) {
|
||||
mbedtls_aes_free(&s);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -109,10 +114,12 @@ ble_aes_ccm_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *en
|
||||
struct tc_aes_key_sched_struct s = {0};
|
||||
|
||||
if (tc_aes128_set_encrypt_key(&s, key) == TC_CRYPTO_FAIL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
if (tc_aes_encrypt(enc_data, plaintext, &s) == TC_CRYPTO_FAIL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -224,6 +231,7 @@ static int ble_aes_ccm_auth(const uint8_t key[16], uint8_t nonce[13],
|
||||
return err;
|
||||
}
|
||||
if (msg_len > 0xffff) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -306,11 +314,13 @@ int ble_aes_ccm_decrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t
|
||||
int rc;
|
||||
|
||||
if (aad_len >= 0xff00 || mic_size > sizeof(mic)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
/* Validate MIC size per RFC 3610 */
|
||||
if (mic_size < 4 || mic_size > 16 || (mic_size % 2) != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -321,11 +331,13 @@ int ble_aes_ccm_decrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t
|
||||
|
||||
rc = ble_aes_ccm_crypt(key_reversed, nonce, enc_msg, out_msg, msg_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_aes_ccm_auth(key_reversed, nonce, out_msg, msg_len, aad, aad_len, mic, mic_size);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -342,11 +354,13 @@ int ble_aes_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t
|
||||
|
||||
/* Unsupported AAD size */
|
||||
if (aad_len >= 0xff00 || mic_size > 16) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
/* Validate MIC size per RFC 3610 */
|
||||
if (mic_size < 4 || mic_size > 16 || (mic_size % 2) != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -358,12 +372,14 @@ int ble_aes_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13], const uint8_t
|
||||
/** Calculating MIC */
|
||||
int rc = ble_aes_ccm_auth(key_reversed, nonce, msg, msg_len, aad, aad_len, mic, mic_size);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/** Encrypting advertisement */
|
||||
rc = ble_aes_ccm_crypt(key_reversed, nonce, msg, out_msg, msg_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <errno.h>
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_att.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
|
||||
@@ -586,6 +587,7 @@ ble_att_rx_extended(uint16_t conn_handle, uint16_t cid, struct os_mbuf **om)
|
||||
|
||||
rc = os_mbuf_copydata(*om, 0, 1, &op);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
@@ -598,6 +600,7 @@ ble_att_rx_extended(uint16_t conn_handle, uint16_t cid, struct os_mbuf **om)
|
||||
BLE_HS_LOG(INFO, "ATT handler not found; op=0x%02x conn_handle=0x%04x "
|
||||
"cid=0x%04x; packet dropped\n", op, conn_handle, cid);
|
||||
ble_att_rx_handle_unknown_request(op, conn_handle, cid, om);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -611,6 +614,9 @@ ble_att_rx_extended(uint16_t conn_handle, uint16_t cid, struct os_mbuf **om)
|
||||
if (rc == BLE_HS_ENOTSUP) {
|
||||
ble_att_rx_handle_unknown_request(op, conn_handle, cid, om);
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -624,11 +630,13 @@ ble_att_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
|
||||
/* Validate mbuf in release builds */
|
||||
if (om == NULL || *om == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
conn_handle = ble_l2cap_get_conn_handle(chan);
|
||||
if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
@@ -649,9 +657,11 @@ ble_att_set_preferred_mtu(uint16_t mtu)
|
||||
int i;
|
||||
|
||||
if (mtu < BLE_ATT_MTU_DFLT) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (mtu > BLE_ATT_MTU_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -780,6 +790,7 @@ ble_att_set_default_bearer_using_cid(uint16_t conn_handle, uint16_t cid) {
|
||||
|
||||
return rc;
|
||||
#endif
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -812,11 +823,13 @@ ble_att_init(void)
|
||||
STATS_HDR(ble_att_stats), STATS_SIZE_INIT_PARMS(ble_att_stats,
|
||||
STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_att_stats), "ble_att");
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
|
||||
rc = ble_eatt_init(ble_att_rx_extended);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "host/ble_uuid.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
@@ -45,6 +46,7 @@ ble_att_clt_rx_error(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(rxom, sizeof(*rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -70,6 +72,7 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu)
|
||||
int rc;
|
||||
|
||||
if (mtu < BLE_ATT_MTU_DFLT) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -87,11 +90,13 @@ ble_att_clt_tx_mtu(uint16_t conn_handle, uint16_t mtu)
|
||||
ble_hs_unlock();
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_MTU_REQ, sizeof(*req), &txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -123,6 +128,7 @@ ble_att_clt_rx_mtu(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
|
||||
#if MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0
|
||||
if (ble_hs_cfg.eatt && cid != BLE_L2CAP_CID_ATT) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
#endif
|
||||
@@ -159,6 +165,7 @@ ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t cid, uint16_t start_hand
|
||||
uint16_t end_handle)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_FIND_INFO
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -166,11 +173,13 @@ ble_att_clt_tx_find_info(uint16_t conn_handle, uint16_t cid, uint16_t start_hand
|
||||
struct os_mbuf *txom;
|
||||
|
||||
if (start_handle == 0 || start_handle > end_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_FIND_INFO_REQ, sizeof(*req), &txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -197,11 +206,13 @@ ble_att_clt_parse_find_info_entry(struct os_mbuf **rxom, uint8_t rsp_format,
|
||||
break;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(rxom, entry_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -211,6 +222,7 @@ ble_att_clt_parse_find_info_entry(struct os_mbuf **rxom, uint8_t rsp_format,
|
||||
case BLE_ATT_FIND_INFO_RSP_FORMAT_16BIT:
|
||||
rc = ble_uuid_init_from_att_mbuf(&idata->uuid, *rxom, 2, 2);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
break;
|
||||
@@ -218,6 +230,7 @@ ble_att_clt_parse_find_info_entry(struct os_mbuf **rxom, uint8_t rsp_format,
|
||||
case BLE_ATT_FIND_INFO_RSP_FORMAT_128BIT:
|
||||
rc = ble_uuid_init_from_att_mbuf(&idata->uuid, *rxom, 2, 16);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
break;
|
||||
@@ -235,6 +248,7 @@ int
|
||||
ble_att_clt_rx_find_info(uint16_t conn_handle, uint16_t cid, struct os_mbuf **om)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_FIND_INFO
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -287,6 +301,7 @@ ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t cid,
|
||||
const void *attribute_value, int value_len)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_FIND_TYPE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -294,16 +309,19 @@ ble_att_clt_tx_find_type_value(uint16_t conn_handle, uint16_t cid,
|
||||
struct os_mbuf *txom;
|
||||
|
||||
if (start_handle == 0 || start_handle > end_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (value_len < 0 || (value_len > 0 && attribute_value == NULL)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_FIND_TYPE_VALUE_REQ, sizeof(*req) + value_len,
|
||||
&txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -326,6 +344,7 @@ ble_att_clt_parse_find_type_value_hinfo(
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, sizeof(*group));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -343,6 +362,7 @@ int
|
||||
ble_att_clt_rx_find_type_value(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_FIND_TYPE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -375,6 +395,7 @@ ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t cid, uint16_t start_hand
|
||||
uint16_t end_handle, const ble_uuid_t *uuid)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_TYPE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -382,12 +403,14 @@ ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t cid, uint16_t start_hand
|
||||
struct os_mbuf *txom;
|
||||
|
||||
if (start_handle == 0 || start_handle > end_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_READ_TYPE_REQ,
|
||||
sizeof(*req) + ble_uuid_length(uuid), &txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -403,6 +426,7 @@ int
|
||||
ble_att_clt_rx_read_type(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_TYPE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -461,6 +485,7 @@ int
|
||||
ble_att_clt_tx_read(uint16_t conn_handle, uint16_t cid, uint16_t handle)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -468,11 +493,13 @@ ble_att_clt_tx_read(uint16_t conn_handle, uint16_t cid, uint16_t handle)
|
||||
struct os_mbuf *txom;
|
||||
|
||||
if (handle == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_READ_REQ, sizeof(*req), &txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -485,6 +512,7 @@ int
|
||||
ble_att_clt_rx_read(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -501,6 +529,7 @@ int
|
||||
ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t cid, uint16_t handle, uint16_t offset)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_BLOB
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -508,11 +537,13 @@ ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t cid, uint16_t handle, ui
|
||||
struct os_mbuf *txom;
|
||||
|
||||
if (handle == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_READ_BLOB_REQ, sizeof(*req), &txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -526,6 +557,7 @@ int
|
||||
ble_att_clt_rx_read_blob(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_BLOB
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -542,6 +574,7 @@ ble_att_clt_tx_read_mult(uint16_t conn_handle, uint16_t cid,
|
||||
const uint16_t *handles, int num_handles, bool variable)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_MULT
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -551,6 +584,7 @@ ble_att_clt_tx_read_mult(uint16_t conn_handle, uint16_t cid,
|
||||
uint8_t op;
|
||||
|
||||
if (num_handles < 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -560,6 +594,7 @@ ble_att_clt_tx_read_mult(uint16_t conn_handle, uint16_t cid,
|
||||
sizeof(req->handles[0]) * num_handles,
|
||||
&txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -574,6 +609,7 @@ int
|
||||
ble_att_clt_rx_read_mult(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_MULT
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -586,6 +622,7 @@ int
|
||||
ble_att_clt_rx_read_mult_var(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_MULT_VAR
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -604,6 +641,7 @@ ble_att_clt_tx_read_group_type(uint16_t conn_handle, uint16_t cid,
|
||||
const ble_uuid_t *uuid)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -611,12 +649,14 @@ ble_att_clt_tx_read_group_type(uint16_t conn_handle, uint16_t cid,
|
||||
struct os_mbuf *txom;
|
||||
|
||||
if (start_handle == 0 || start_handle > end_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_READ_GROUP_TYPE_REQ,
|
||||
sizeof(*req) + ble_uuid_length(uuid), &txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -635,11 +675,13 @@ ble_att_clt_parse_read_group_type_adata(
|
||||
int rc;
|
||||
|
||||
if (data_len < BLE_ATT_READ_GROUP_TYPE_ADATA_BASE_SZ + 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -655,6 +697,7 @@ int
|
||||
ble_att_clt_rx_read_group_type(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -701,6 +744,7 @@ ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t cid, uint16_t handle,
|
||||
struct os_mbuf *txom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_WRITE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -710,6 +754,7 @@ ble_att_clt_tx_write_req(uint16_t conn_handle, uint16_t cid, uint16_t handle,
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_WRITE_REQ, sizeof(*req), &txom2);
|
||||
if (req == NULL) {
|
||||
os_mbuf_free_chain(txom);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -724,6 +769,7 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t cid,
|
||||
uint16_t handle, struct os_mbuf *txom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -748,6 +794,7 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle, uint16_t cid,
|
||||
cmd = ble_att_cmd_get(BLE_ATT_OP_WRITE_CMD, sizeof(*cmd), &txom2);
|
||||
if (cmd == NULL) {
|
||||
os_mbuf_free_chain(txom);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -761,6 +808,7 @@ int
|
||||
ble_att_clt_rx_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_WRITE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -902,6 +950,7 @@ ble_att_clt_tx_prep_write(uint16_t conn_handle, uint16_t cid, uint16_t handle,
|
||||
uint16_t offset, struct os_mbuf *txom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_PREP_WRITE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -953,6 +1002,7 @@ int
|
||||
ble_att_clt_rx_prep_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_PREP_WRITE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -991,6 +1041,7 @@ int
|
||||
ble_att_clt_tx_exec_write(uint16_t conn_handle, uint16_t cid, uint8_t flags)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_EXEC_WRITE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -999,6 +1050,7 @@ ble_att_clt_tx_exec_write(uint16_t conn_handle, uint16_t cid, uint8_t flags)
|
||||
|
||||
req = ble_att_cmd_get(BLE_ATT_OP_EXEC_WRITE_REQ, sizeof(*req), &txom);
|
||||
if (req == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1011,6 +1063,7 @@ int
|
||||
ble_att_clt_rx_exec_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_EXEC_WRITE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1029,6 +1082,7 @@ ble_att_clt_tx_notify(uint16_t conn_handle, uint16_t handle,
|
||||
struct os_mbuf *txom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_NOTIFY
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1070,6 +1124,7 @@ ble_att_clt_tx_indicate(uint16_t conn_handle, uint16_t cid,
|
||||
uint16_t handle, struct os_mbuf *txom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_INDICATE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1103,6 +1158,7 @@ int
|
||||
ble_att_clt_rx_indicate(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_INDICATE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1119,6 +1175,7 @@ int
|
||||
ble_att_clt_tx_notify_mult(uint16_t conn_handle, struct os_mbuf *txom)
|
||||
{
|
||||
#if !NIMBLE_BLE_ATT_CLT_NOTIFY_MULT
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1127,6 +1184,7 @@ ble_att_clt_tx_notify_mult(uint16_t conn_handle, struct os_mbuf *txom)
|
||||
int rc;
|
||||
|
||||
if (ble_att_cmd_get(BLE_ATT_OP_NOTIFY_MULTI_REQ, 0, &txom2) == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_att.h"
|
||||
#include "host/ble_uuid.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
void *
|
||||
@@ -106,6 +107,9 @@ ble_att_tx_with_conn(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan, stru
|
||||
if (is_request) {
|
||||
conn->client_att_busy = false;
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
@@ -130,6 +134,9 @@ ble_att_tx(uint16_t conn_handle, uint16_t cid, struct os_mbuf *txom)
|
||||
if (rc != 0) {
|
||||
ble_hs_unlock();
|
||||
os_mbuf_free_chain(txom);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "host/ble_uuid.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
#if MYNEWT_VAL(BLE_GATTS)
|
||||
@@ -103,6 +104,7 @@ ble_att_svr_ensure_ctx(void)
|
||||
|
||||
ble_att_svr_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_att_svr_ctx));
|
||||
if (ble_att_svr_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -177,6 +179,7 @@ ble_att_svr_register(const ble_uuid_t *uuid, uint8_t flags,
|
||||
|
||||
entry = ble_att_svr_entry_alloc();
|
||||
if (entry == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -362,6 +365,7 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
|
||||
"conn_handle=0x%04x attr_handle=0x%04x\n",
|
||||
conn_handle, entry->ha_handle_id);
|
||||
*out_att_err = BLE_ATT_ERR_READ_NOT_PERMITTED;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
|
||||
@@ -374,6 +378,7 @@ ble_att_svr_check_perms(uint16_t conn_handle, int is_read,
|
||||
"conn_handle=0x%04x attr_handle=0x%04x\n",
|
||||
conn_handle, entry->ha_handle_id);
|
||||
*out_att_err = BLE_ATT_ERR_WRITE_NOT_PERMITTED;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
|
||||
@@ -512,6 +517,7 @@ ble_att_svr_pkt(struct os_mbuf **rxom, struct os_mbuf **out_txom,
|
||||
*out_txom = *rxom;
|
||||
*rxom = NULL;
|
||||
*out_att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -610,11 +616,13 @@ ble_att_svr_read_handle(uint16_t conn_handle, uint16_t attr_handle,
|
||||
if (out_att_err != NULL) {
|
||||
*out_att_err = BLE_ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
rc = ble_att_svr_read(conn_handle, entry, offset, om, out_att_err);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -695,11 +703,13 @@ ble_att_svr_write_handle(uint16_t conn_handle, uint16_t attr_handle,
|
||||
if (out_att_err != NULL) {
|
||||
*out_att_err = BLE_ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
rc = ble_att_svr_write(conn_handle, entry, offset, om, out_att_err);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -718,6 +728,7 @@ ble_att_svr_tx_error_rsp(uint16_t conn_handle, uint16_t cid, struct os_mbuf *txo
|
||||
|
||||
rsp = ble_att_cmd_prepare(BLE_ATT_OP_ERROR_RSP, sizeof(*rsp), txom);
|
||||
if (rsp == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -858,6 +869,7 @@ ble_att_svr_rx_mtu(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
mtu = 0;
|
||||
|
||||
if (cid != BLE_L2CAP_CID_ATT) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -975,6 +987,7 @@ ble_att_svr_fill_info(uint16_t start_handle, uint16_t end_handle,
|
||||
|
||||
done:
|
||||
if (rc == 0 && num_entries == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
} else {
|
||||
return rc;
|
||||
@@ -1031,6 +1044,7 @@ int
|
||||
ble_att_svr_rx_find_info(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_FIND_INFO)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1122,11 +1136,13 @@ ble_att_svr_fill_type_value_entry(struct os_mbuf *om, uint16_t first,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAGAIN);
|
||||
return BLE_HS_EAGAIN;
|
||||
|
||||
fail:
|
||||
os_mbuf_adj(om, orig_len - OS_MBUF_PKTLEN(om));
|
||||
*out_att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1288,6 +1304,7 @@ done:
|
||||
BLE_ATT_FIND_TYPE_VALUE_RSP_BASE_SZ;
|
||||
if (rc == 0 && !any_entries) {
|
||||
*out_att_err = BLE_ATT_ERR_ATTR_NOT_FOUND;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
} else {
|
||||
return rc;
|
||||
@@ -1342,6 +1359,7 @@ int
|
||||
ble_att_svr_rx_find_type_value(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_FIND_TYPE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1577,6 +1595,7 @@ int
|
||||
ble_att_svr_rx_read_type(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_READ_TYPE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1689,6 +1708,7 @@ int
|
||||
ble_att_svr_rx_read(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_READ)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1752,6 +1772,7 @@ int
|
||||
ble_att_svr_rx_read_blob(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_READ_BLOB)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -1882,6 +1903,7 @@ int
|
||||
ble_att_svr_rx_read_mult(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_READ_MULT)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2017,6 +2039,7 @@ int
|
||||
ble_att_svr_rx_read_mult_var(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_READ_MULT)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2078,6 +2101,7 @@ ble_att_svr_service_uuid(struct ble_att_svr_entry *entry,
|
||||
rc = ble_att_svr_read_flat(BLE_HS_CONN_HANDLE_NONE, entry, 0, sizeof(val), val,
|
||||
&attr_len, out_att_err);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2114,11 +2138,13 @@ ble_att_svr_read_group_type_entry_write(struct os_mbuf *om, uint16_t mtu,
|
||||
len = BLE_ATT_READ_GROUP_TYPE_ADATA_SZ_128;
|
||||
}
|
||||
if (OS_MBUF_PKTLEN(om) + len > mtu) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
buf = os_mbuf_extend(om, len);
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -2307,6 +2333,7 @@ int
|
||||
ble_att_svr_rx_read_group_type(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_READ_GROUP_TYPE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2423,6 +2450,7 @@ int
|
||||
ble_att_svr_rx_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_WRITE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2490,6 +2518,7 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, uint16_t cid, struct os_mbuf *
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_WRITE_NO_RSP)
|
||||
os_mbuf_free_chain(*rxom);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2499,6 +2528,7 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, uint16_t cid, struct os_mbuf *
|
||||
!ble_att_svr_check_conn_aware(conn_handle)) {
|
||||
ble_hs_unlock();
|
||||
os_mbuf_free_chain(*rxom);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
ble_hs_unlock();
|
||||
@@ -2511,6 +2541,7 @@ ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, uint16_t cid, struct os_mbuf *
|
||||
|
||||
rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2529,6 +2560,7 @@ int
|
||||
ble_att_svr_rx_signed_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
if (MYNEWT_VAL(BLE_EATT_CHAN_NUM) > 0 && ble_hs_cfg.eatt) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -2565,6 +2597,7 @@ ble_att_svr_rx_signed_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf *
|
||||
|
||||
rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), &att_err);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2746,6 +2779,7 @@ ble_att_svr_prep_validate(struct ble_att_prep_entry_list *prep_list,
|
||||
/* Ensure attribute write starts at offset 0. */
|
||||
if (entry->bape_offset != 0) {
|
||||
*err_handle = entry->bape_handle;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INVALID_OFFSET);
|
||||
return BLE_ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
} else {
|
||||
@@ -2754,6 +2788,7 @@ ble_att_svr_prep_validate(struct ble_att_prep_entry_list *prep_list,
|
||||
entry->bape_offset) {
|
||||
|
||||
*err_handle = entry->bape_handle;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INVALID_OFFSET);
|
||||
return BLE_ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
}
|
||||
@@ -2762,6 +2797,7 @@ ble_att_svr_prep_validate(struct ble_att_prep_entry_list *prep_list,
|
||||
cur_len = entry->bape_offset + OS_MBUF_PKTLEN(entry->bape_value);
|
||||
if (cur_len > BLE_ATT_ATTR_MAX_LEN) {
|
||||
*err_handle = entry->bape_handle;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN);
|
||||
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
|
||||
}
|
||||
#endif
|
||||
@@ -2826,6 +2862,7 @@ ble_att_svr_prep_write(uint16_t conn_handle,
|
||||
/* First, validate the contents of the prepare queue. */
|
||||
rc = ble_att_svr_prep_validate(prep_list, err_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2865,6 +2902,7 @@ ble_att_svr_insert_prep_entry(uint16_t conn_handle,
|
||||
|
||||
prep_entry = ble_att_svr_prep_alloc(out_att_err);
|
||||
if (prep_entry == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
prep_entry->bape_handle = handle;
|
||||
@@ -2911,6 +2949,7 @@ int
|
||||
ble_att_svr_rx_prep_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_QUEUED_WRITE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3012,6 +3051,7 @@ int
|
||||
ble_att_svr_rx_exec_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_QUEUED_WRITE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3103,6 +3143,7 @@ int
|
||||
ble_att_svr_rx_notify(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_NOTIFY)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3113,6 +3154,7 @@ ble_att_svr_rx_notify(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
|
||||
rc = ble_att_svr_pullup_req_base(rxom, sizeof(*req), NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -3121,6 +3163,7 @@ ble_att_svr_rx_notify(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
handle = le16toh(req->banq_handle);
|
||||
|
||||
if (handle == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -3148,6 +3191,7 @@ int
|
||||
ble_att_svr_rx_notify_multi(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_NOTIFY_MULTI)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3220,6 +3264,7 @@ ble_att_clt_pkt(struct os_mbuf **rxom, struct os_mbuf **out_txom,
|
||||
*out_txom = *rxom;
|
||||
*rxom = NULL;
|
||||
*out_att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -3281,6 +3326,7 @@ int
|
||||
ble_att_svr_rx_indicate(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_ATT_SVR_INDICATE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3479,6 +3525,7 @@ ble_att_svr_start(void)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
rc = ble_att_svr_ensure_ctx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -3549,6 +3596,7 @@ ble_att_svr_init(void)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
rc = ble_att_svr_ensure_ctx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -3560,6 +3608,7 @@ ble_att_svr_init(void)
|
||||
sizeof(struct ble_att_prep_entry)) * sizeof(os_membuf_t);
|
||||
ble_att_svr_prep_entry_mem = (os_membuf_t *)nimble_platform_mem_calloc(1, mem_size);
|
||||
if (!ble_att_svr_prep_entry_mem) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif // !MYNEWT_VAL(MP_RUNTIME_ALLOC)
|
||||
@@ -3580,6 +3629,7 @@ ble_att_svr_init(void)
|
||||
sizeof(ble_att_svr_prep_entry_pool));
|
||||
#endif
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
}
|
||||
@@ -3618,6 +3668,7 @@ int ble_att_get_database_size(int *out_size)
|
||||
uuid->value == BLE_ATT_UUID_SECONDARY_SERVICE) {
|
||||
rc = ble_att_svr_service_uuid(entry, &service_uuid, &att_error);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
/* handle (2 bytes) + type(2 bytes) + uuid (variable) */
|
||||
@@ -3626,6 +3677,7 @@ int ble_att_get_database_size(int *out_size)
|
||||
else if(uuid->value == BLE_ATT_UUID_INCLUDE) {
|
||||
rc = ble_att_svr_service_uuid(entry, &service_uuid, &att_error);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3686,6 +3738,7 @@ int ble_att_fill_database_info(uint8_t *out_data)
|
||||
uuid->value == BLE_ATT_UUID_SECONDARY_SERVICE) {
|
||||
rc = ble_att_svr_service_uuid(entry, &service_uuid, &att_error);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
/* handle (2 bytes) + type(2 bytes) + uuid (variable) */
|
||||
@@ -3700,6 +3753,7 @@ int ble_att_fill_database_info(uint8_t *out_data)
|
||||
entry, 0, sizeof(val), val,
|
||||
&attr_len, &att_error);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3723,6 +3777,7 @@ int ble_att_fill_database_info(uint8_t *out_data)
|
||||
entry, 0, sizeof(val), val,
|
||||
&attr_len, &att_error);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
memcpy(data + 4, val, attr_len);
|
||||
@@ -3748,6 +3803,7 @@ int ble_att_fill_database_info(uint8_t *out_data)
|
||||
entry, 0, sizeof(val), val,
|
||||
&attr_len, &att_error);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
memcpy(data + 4, val, attr_len);
|
||||
|
||||
@@ -199,7 +199,6 @@ ble_cs_call_event_cb(struct ble_cs_event *event)
|
||||
static void
|
||||
ble_cs_call_procedure_complete_cb(uint16_t conn_handle, uint8_t status)
|
||||
{
|
||||
|
||||
struct ble_cs_event event;
|
||||
|
||||
memset(&event, 0, sizeof event);
|
||||
@@ -507,7 +506,6 @@ int
|
||||
ble_hs_hci_evt_le_cs_rd_rem_supp_cap_complete(uint8_t subevent, const void *data,
|
||||
unsigned int len)
|
||||
{
|
||||
|
||||
int rc;
|
||||
const struct ble_hci_ev_le_subev_cs_rd_rem_supp_cap_complete *ev = data;
|
||||
struct ble_cs_set_def_settings_cp set_cmd;
|
||||
@@ -517,6 +515,7 @@ ble_hs_hci_evt_le_cs_rd_rem_supp_cap_complete(uint8_t subevent, const void *data
|
||||
|
||||
if (len != sizeof(*ev) || ev->status) {
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -532,6 +531,7 @@ ble_hs_hci_evt_le_cs_rd_rem_supp_cap_complete(uint8_t subevent, const void *data
|
||||
uint16_t conn_handle = le16toh(ev->conn_handle);
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if (desc.role == BLE_GAP_ROLE_MASTER) {
|
||||
@@ -548,6 +548,9 @@ ble_hs_hci_evt_le_cs_rd_rem_supp_cap_complete(uint8_t subevent, const void *data
|
||||
if (rc) {
|
||||
BLE_HS_LOG(INFO, "Failed to set the default CS settings, err %d", rc);
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
BLE_HS_LOG(INFO, "Set default CS settings ");
|
||||
@@ -561,6 +564,9 @@ ble_hs_hci_evt_le_cs_rd_rem_supp_cap_complete(uint8_t subevent, const void *data
|
||||
BLE_HS_LOG(INFO, "Failed to read FAE table");
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -568,7 +574,6 @@ int
|
||||
ble_hs_hci_evt_le_cs_rd_rem_fae_complete(uint8_t subevent, const void *data,
|
||||
unsigned int len)
|
||||
{
|
||||
|
||||
struct ble_gap_conn_desc desc;
|
||||
const struct ble_hci_ev_le_subev_cs_rd_rem_fae_complete *ev = data;
|
||||
struct ble_cs_create_config_cp cmd;
|
||||
@@ -576,6 +581,7 @@ ble_hs_hci_evt_le_cs_rd_rem_fae_complete(uint8_t subevent, const void *data,
|
||||
int rc=0;
|
||||
|
||||
if (len != sizeof(*ev) || ev->status) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -607,6 +613,7 @@ ble_hs_hci_evt_le_cs_rd_rem_fae_complete(uint8_t subevent, const void *data,
|
||||
|
||||
rc = ble_gap_conn_find(cmd.conn_handle, &desc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -641,6 +648,9 @@ ble_hs_hci_evt_le_cs_rd_rem_fae_complete(uint8_t subevent, const void *data,
|
||||
BLE_HS_LOG(INFO, "Failed to create CS config");
|
||||
}
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -648,7 +658,6 @@ int
|
||||
ble_hs_hci_evt_le_cs_sec_enable_complete(uint8_t subevent, const void *data,
|
||||
unsigned int len)
|
||||
{
|
||||
|
||||
int rc;
|
||||
struct ble_cs_set_proc_params_cp cmd;
|
||||
struct ble_cs_set_proc_params_rp rsp;
|
||||
@@ -659,6 +668,7 @@ ble_hs_hci_evt_le_cs_sec_enable_complete(uint8_t subevent, const void *data,
|
||||
if (len != sizeof(*ev) || ev->status) {
|
||||
BLE_HS_LOG(INFO, "Failed to enable CS security BLE_HS_ECNOTEROLLER");
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -699,6 +709,9 @@ ble_hs_hci_evt_le_cs_sec_enable_complete(uint8_t subevent, const void *data,
|
||||
rc = ble_cs_set_proc_params(&cmd, &rsp);
|
||||
if (rc) {
|
||||
BLE_HS_LOG(INFO, "Failed to set CS procedure parameters");
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
BLE_HS_LOG(INFO, "CS procedure parameters set");
|
||||
@@ -711,6 +724,7 @@ ble_hs_hci_evt_le_cs_sec_enable_complete(uint8_t subevent, const void *data,
|
||||
uint16_t conn_handle = le16toh(ev->conn_handle);
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if (desc.role == BLE_GAP_ROLE_MASTER) {
|
||||
@@ -721,6 +735,9 @@ ble_hs_hci_evt_le_cs_sec_enable_complete(uint8_t subevent, const void *data,
|
||||
} else {
|
||||
BLE_HS_LOG(INFO, "CS procedure enabled");
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
@@ -737,6 +754,7 @@ ble_hs_hci_evt_le_cs_config_complete(uint8_t subevent, const void *data,
|
||||
// struct ble_hs_conn *conn;
|
||||
|
||||
if (len != sizeof(*ev) || ev->status) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -746,6 +764,7 @@ ble_hs_hci_evt_le_cs_config_complete(uint8_t subevent, const void *data,
|
||||
uint16_t conn_handle = le16toh(ev->conn_handle);
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -755,6 +774,9 @@ ble_hs_hci_evt_le_cs_config_complete(uint8_t subevent, const void *data,
|
||||
if (rc) {
|
||||
BLE_HS_LOG(DEBUG, "Failed to enable CS security");
|
||||
ble_cs_call_procedure_complete_cb(le16toh(ev->conn_handle), BLE_ERR_UNSPECIFIED);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -770,6 +792,7 @@ ble_hs_hci_evt_le_cs_proc_enable_complete(uint8_t subevent, const void *data,
|
||||
|
||||
if (len != sizeof(*ev) || ev->status) {
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -795,11 +818,13 @@ ble_hs_hci_evt_le_cs_subevent_result(uint8_t subevent, const void *data,
|
||||
while (steps_remaining > 0) {
|
||||
if ((uint8_t *)step_ptr + sizeof(struct cs_steps_data) > data_end) {
|
||||
MODLOG_DFLT(INFO, "Invalid step_ptr bounds");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
step_size = sizeof(struct cs_steps_data) + ((struct cs_steps_data *)step_ptr)->data_len;
|
||||
if ((uint8_t *)step_ptr + step_size > data_end || step_size <= 0) {
|
||||
MODLOG_DFLT(INFO, "Invalid step_size");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -810,6 +835,7 @@ ble_hs_hci_evt_le_cs_subevent_result(uint8_t subevent, const void *data,
|
||||
|
||||
if (len != expected_len) {
|
||||
MODLOG_DFLT(INFO, "ble_hs_hci_evt_le_cs_subevent_result\n len :%d expected_len : %d\n", len, expected_len);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -836,11 +862,13 @@ ble_hs_hci_evt_le_cs_subevent_result_continue(uint8_t subevent, const void *data
|
||||
/* Check bounds before dereferencing step_ptr */
|
||||
if ((uint8_t *)step_ptr + sizeof(struct cs_steps_data) > data_end) {
|
||||
MODLOG_DFLT(INFO, "Invalid step_ptr bounds in continue event");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
step_size = sizeof(struct cs_steps_data) + ((struct cs_steps_data *)step_ptr)->data_len;
|
||||
if ((uint8_t *)step_ptr + step_size > data_end || step_size <= 0) {
|
||||
MODLOG_DFLT(INFO, "Invalid step_size in continue event");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -851,6 +879,7 @@ ble_hs_hci_evt_le_cs_subevent_result_continue(uint8_t subevent, const void *data
|
||||
|
||||
if (len != expected_len) {
|
||||
MODLOG_DFLT(INFO, "ble_hs_hci_evt_le_cs_subevent_result_continue len: %d expected_len: %d\n", len, expected_len);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
ble_cs_call_result_continue_cb(event);
|
||||
@@ -864,6 +893,7 @@ ble_hs_hci_evt_le_cs_test_end_complete(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_cs_test_end_complete *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -874,7 +904,6 @@ ble_hs_hci_evt_le_cs_test_end_complete(uint8_t subevent, const void *data,
|
||||
int
|
||||
ble_cs_initiator_procedure_start(const struct ble_cs_initiator_procedure_start_params *params)
|
||||
{
|
||||
|
||||
struct ble_cs_rd_rem_supp_cap_cp cmd;
|
||||
int rc;
|
||||
|
||||
@@ -896,6 +925,9 @@ ble_cs_initiator_procedure_start(const struct ble_cs_initiator_procedure_start_p
|
||||
"err %d", rc);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <string.h>
|
||||
#include "host/ble_ead.h"
|
||||
#include "host/ble_aes_ccm.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(ENC_ADV_DATA)
|
||||
|
||||
@@ -17,6 +18,7 @@ static int ble_ead_rand(void *buf, int len)
|
||||
int rc;
|
||||
rc = ble_hs_hci_util_rand(buf, len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
@@ -43,6 +45,7 @@ static int ble_ead_generate_nonce(const uint8_t iv[BLE_EAD_IV_SIZE],
|
||||
const uint8_t *rand_src = randomizer;
|
||||
|
||||
if (iv == NULL || nonce == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -94,21 +97,25 @@ int ble_ead_encrypt(const uint8_t session_key[BLE_EAD_KEY_SIZE], const uint8_t i
|
||||
{
|
||||
if (session_key == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "session_key is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (iv == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "iv is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (payload == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "payload is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (encrypted_payload == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "encrypted_payload is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -119,6 +126,7 @@ int ble_ead_encrypt(const uint8_t session_key[BLE_EAD_KEY_SIZE], const uint8_t i
|
||||
|
||||
/* Ensure payload_size isn't too large to wrap around when adding overhead */
|
||||
if (payload_size > SIZE_MAX - (BLE_EAD_RANDOMIZER_SIZE + BLE_EAD_MIC_SIZE)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -134,6 +142,7 @@ static int ead_decrypt(const uint8_t session_key[BLE_EAD_KEY_SIZE], const uint8_
|
||||
|
||||
/* Defense-in-depth: Validate size to prevent underflow (size_t is unsigned) */
|
||||
if (encrypted_payload_size < BLE_EAD_RANDOMIZER_SIZE + BLE_EAD_MIC_SIZE) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -153,6 +162,7 @@ static int ead_decrypt(const uint8_t session_key[BLE_EAD_KEY_SIZE], const uint8_
|
||||
|
||||
if (err != 0) {
|
||||
BLE_HS_LOG(DEBUG, "Failed to decrypt the data");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAUTHEN);
|
||||
return BLE_HS_EAUTHEN;
|
||||
}
|
||||
|
||||
@@ -165,26 +175,31 @@ int ble_ead_decrypt(const uint8_t session_key[BLE_EAD_KEY_SIZE], const uint8_t i
|
||||
{
|
||||
if (session_key == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "session_key is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (iv == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "iv is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (encrypted_payload == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "encrypted_payload is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (payload == NULL) {
|
||||
BLE_HS_LOG(DEBUG, "payload is NULL");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (encrypted_payload_size < BLE_EAD_RANDOMIZER_SIZE + BLE_EAD_MIC_SIZE) {
|
||||
BLE_HS_LOG(DEBUG, "encrypted_payload_size is not large enough.");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
} else if (encrypted_payload_size == BLE_EAD_RANDOMIZER_SIZE + BLE_EAD_MIC_SIZE) {
|
||||
BLE_HS_LOG(WARN, "encrypted_payload_size not large enough to contain encrypted data.");
|
||||
|
||||
@@ -185,6 +185,7 @@ ble_eatt_prepare_rx_sdu(struct ble_l2cap_chan *chan)
|
||||
om = os_mbuf_get_pkthdr(&ble_eatt_sdu_os_mbuf_pool, 0);
|
||||
if (!om) {
|
||||
BLE_EATT_LOG_ERROR("eatt: no memory for sdu\n");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -194,6 +195,9 @@ ble_eatt_prepare_rx_sdu(struct ble_l2cap_chan *chan)
|
||||
chan->conn_handle, rc);
|
||||
os_mbuf_free_chain(om);
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -294,6 +298,7 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
|
||||
|
||||
eatt = ble_eatt_alloc();
|
||||
if (!eatt) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
eatt->conn_handle = event->accept.conn_handle;
|
||||
@@ -302,6 +307,9 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
|
||||
rc = ble_eatt_prepare_rx_sdu(event->accept.chan);
|
||||
if (rc) {
|
||||
ble_eatt_free(eatt);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
break;
|
||||
@@ -311,11 +319,13 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
|
||||
case BLE_L2CAP_EVENT_COC_DATA_RECEIVED:
|
||||
if (eatt->chan != event->receive.chan) {
|
||||
os_mbuf_free_chain(event->receive.sdu_rx);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
if (OS_MBUF_PKTLEN(event->receive.sdu_rx) < 1) {
|
||||
os_mbuf_free_chain(event->receive.sdu_rx);
|
||||
ble_l2cap_disconnect(eatt->chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
opcode = event->receive.sdu_rx->om_data[0];
|
||||
@@ -331,12 +341,14 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
|
||||
*/
|
||||
os_mbuf_free_chain(event->receive.sdu_rx);
|
||||
ble_l2cap_disconnect(eatt->chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
|
||||
if (ble_gap_conn_find(event->receive.conn_handle, &desc)) {
|
||||
os_mbuf_free_chain(event->receive.sdu_rx);
|
||||
ble_l2cap_disconnect(eatt->chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
/* As per BLE 5.4 Standard, Vol. 3, Part G, section 5.3.2
|
||||
@@ -350,6 +362,7 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
|
||||
if (!desc.sec_state.encrypted) {
|
||||
os_mbuf_free_chain(event->receive.sdu_rx);
|
||||
ble_l2cap_disconnect(eatt->chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
|
||||
@@ -362,6 +375,7 @@ ble_eatt_l2cap_event_fn(struct ble_l2cap_event *event, void *arg)
|
||||
if (rc) {
|
||||
/* Receiving L2CAP data is no longer possible, terminate connection */
|
||||
ble_l2cap_disconnect(eatt->chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
break;
|
||||
@@ -438,6 +452,7 @@ ble_gatt_eatt_read_cl_uuid_cb(uint16_t conn_handle,
|
||||
ble_gatt_eatt_write_cl_cb, NULL);
|
||||
BLE_EATT_LOG_DEBUG("eatt: %s , write rc = %d \n", __func__, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -455,17 +470,20 @@ ble_gatt_eatt_read_uuid_cb(uint16_t conn_handle,
|
||||
|
||||
if (error == NULL || (error->status != 0 && error->status != BLE_HS_EDONE)) {
|
||||
BLE_EATT_LOG_DEBUG("eatt: Cannot find Server Supported features on peer device\n");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (attr == NULL) {
|
||||
BLE_EATT_LOG_ERROR("eatt: Invalid attribute \n");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
rc = os_mbuf_copydata(attr->om, 0, 1, &supported_features);
|
||||
if (rc) {
|
||||
BLE_EATT_LOG_ERROR("eatt: Cannot read srv supported features \n");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -476,6 +494,7 @@ ble_gatt_eatt_read_uuid_cb(uint16_t conn_handle,
|
||||
ble_npl_eventq_put(ble_hs_evq_get(), ev);
|
||||
}
|
||||
}
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -623,11 +642,17 @@ ble_eatt_tx(uint16_t conn_handle, uint16_t cid, struct os_mbuf *txom)
|
||||
BLE_EATT_LOG_DEBUG("ble_eatt_tx: Eatt stalled");
|
||||
/* L2CAP owns the mbuf; COC_TX_UNSTALLED event will fire when ready */
|
||||
/* Do NOT re-queue - this would cause use-after-free */
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else if (rc == BLE_HS_EBUSY) {
|
||||
BLE_EATT_LOG_DEBUG("ble_eatt_tx: Message queued");
|
||||
STAILQ_INSERT_HEAD(&eatt->eatt_tx_q, OS_MBUF_PKTHDR(txom), omp_next);
|
||||
ble_npl_eventq_put(ble_hs_evq_get(), &eatt->wakeup_ev);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
BLE_EATT_LOG_ERROR("eatt: %s, ERROR %d ", __func__, rc);
|
||||
@@ -707,6 +732,7 @@ ble_eatt_init(ble_eatt_att_rx_fn att_rx_cb)
|
||||
if (!ble_eatt_ctx) {
|
||||
ble_eatt_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_eatt_ctx));
|
||||
if (!ble_eatt_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -720,6 +746,7 @@ ble_eatt_init(ble_eatt_att_rx_fn att_rx_cb)
|
||||
// free the allocated memory
|
||||
nimble_platform_mem_free(ble_eatt_ctx);
|
||||
ble_eatt_ctx = NULL;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -732,6 +759,7 @@ ble_eatt_init(ble_eatt_att_rx_fn att_rx_cb)
|
||||
nimble_platform_mem_free(ble_eatt_ctx);
|
||||
ble_eatt_conn_mem = NULL;
|
||||
ble_eatt_ctx = NULL;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "host/ble_eddystone.h"
|
||||
#include "host/ble_hs_adv.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#define BLE_EDDYSTONE_MAX_SVC_DATA_LEN 22
|
||||
#define BLE_EDDYSTONE_SVC_DATA_BASE_SZ 3
|
||||
@@ -78,15 +79,19 @@ ble_eddystone_set_adv_data_gen(struct ble_hs_adv_fields *adv_fields,
|
||||
int rc;
|
||||
|
||||
if (adv_fields->num_uuids16 > BLE_EDDYSTONE_MAX_UUIDS16) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (svc_data_len > (BLE_EDDYSTONE_MAX_SVC_DATA_LEN - BLE_EDDYSTONE_SVC_DATA_BASE_SZ)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (adv_fields->num_uuids16 > 0 && !adv_fields->uuids16_is_complete) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (adv_fields->svc_data_uuid16_len != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -96,6 +101,7 @@ ble_eddystone_set_adv_data_gen(struct ble_hs_adv_fields *adv_fields,
|
||||
/* Only copy if there are UUIDs and the pointer is valid */
|
||||
if (adv_fields->num_uuids16 > 0) {
|
||||
if (adv_fields->uuids16 == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
memcpy(ble_eddystone_uuids16 + 1, adv_fields->uuids16,
|
||||
@@ -111,6 +117,7 @@ ble_eddystone_set_adv_data_gen(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
rc = ble_gap_adv_set_fields(adv_fields);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -126,12 +133,15 @@ ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
/* Validate inputs before modifying global state */
|
||||
if (adv_fields == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (uid == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (measured_power < -127 || measured_power > 20) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -150,6 +160,7 @@ ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
rc = ble_eddystone_set_adv_data_gen(adv_fields, BLE_EDDYSTONE_UID_SVC_DATA_LEN);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -168,18 +179,23 @@ ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
/* Validate all inputs before modifying global state */
|
||||
if (adv_fields == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (url_body == NULL && url_body_len > 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (measured_power < -127 || measured_power > 20) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (url_scheme > BLE_EDDYSTONE_URL_SCHEME_HTTPS) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (url_suffix != BLE_EDDYSTONE_URL_SUFFIX_NONE && url_suffix > BLE_EDDYSTONE_URL_SUFFIX_GOV) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -188,6 +204,7 @@ ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,
|
||||
url_len++;
|
||||
}
|
||||
if (url_len < 1 || url_len > BLE_EDDYSTONE_URL_MAX_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -206,6 +223,7 @@ ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
rc = ble_eddystone_set_adv_data_gen(adv_fields, url_len + 2);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
+387
-15
File diff suppressed because it is too large
Load Diff
@@ -61,6 +61,7 @@
|
||||
#include "host/ble_gap.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_gattc_cache_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING)
|
||||
#include "host/ble_esp_gattc_cache.h"
|
||||
#endif
|
||||
@@ -396,6 +397,7 @@ ble_gattc_ensure_ctx(void)
|
||||
|
||||
ble_gattc_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_gattc_ctx));
|
||||
if (ble_gattc_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1719,6 +1721,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1783,6 +1788,7 @@ ble_gattc_disc_all_svcs_tx(struct ble_gattc_proc *proc)
|
||||
proc->disc_all_svcs.prev_handle + 1,
|
||||
0xffff, &uuid.u);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1799,6 +1805,9 @@ ble_gattc_disc_all_svcs_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_disc_all_svcs_cb(proc, rc, 0, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1869,6 +1878,7 @@ ble_gattc_disc_all_svcs_rx_adata(struct ble_gattc_proc *proc,
|
||||
done:
|
||||
cbrc = ble_gattc_disc_all_svcs_cb(proc, rc, 0, &service);
|
||||
if (rc != 0 || cbrc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -1888,18 +1898,21 @@ ble_gattc_disc_all_svcs_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
|
||||
if (status != 0) {
|
||||
ble_gattc_disc_all_svcs_cb(proc, status, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (proc->disc_all_svcs.prev_handle == 0xffff) {
|
||||
/* Service discovery complete. */
|
||||
ble_gattc_disc_all_svcs_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
/* Send follow-up request. */
|
||||
rc = ble_gattc_disc_all_svcs_resume(proc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -1911,6 +1924,7 @@ ble_gattc_disc_all_svcs(uint16_t conn_handle, ble_gatt_disc_svc_fn *cb,
|
||||
void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_DISC_ALL_SVCS)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2030,6 +2044,7 @@ ble_gattc_disc_svc_uuid_tx(struct ble_gattc_proc *proc)
|
||||
val,
|
||||
ble_uuid_length(&proc->disc_svc_uuid.service_uuid.u));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2046,6 +2061,9 @@ ble_gattc_disc_svc_uuid_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_disc_svc_uuid_cb(proc, rc, 0, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2101,6 +2119,7 @@ ble_gattc_disc_svc_uuid_rx_hinfo(struct ble_gattc_proc *proc,
|
||||
done:
|
||||
cbrc = ble_gattc_disc_svc_uuid_cb(proc, rc, 0, &service);
|
||||
if (rc != 0 || cbrc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -2120,18 +2139,21 @@ ble_gattc_disc_svc_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
|
||||
if (status != 0) {
|
||||
ble_gattc_disc_svc_uuid_cb(proc, status, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (proc->disc_svc_uuid.prev_handle == 0xffff) {
|
||||
/* Service discovery complete. */
|
||||
ble_gattc_disc_svc_uuid_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
/* Send follow-up request. */
|
||||
rc = ble_gattc_disc_svc_uuid_resume(proc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -2143,6 +2165,7 @@ ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid,
|
||||
ble_gatt_disc_svc_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_DISC_SVC_UUID)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2183,6 +2206,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2256,6 +2282,7 @@ ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc)
|
||||
proc->find_inc_svcs.prev_handle + 1,
|
||||
proc->find_inc_svcs.end_handle, &uuid.u);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@@ -2263,6 +2290,7 @@ ble_gattc_find_inc_svcs_tx(struct ble_gattc_proc *proc)
|
||||
rc = ble_att_clt_tx_read(proc->conn_handle, proc->cid,
|
||||
proc->find_inc_svcs.cur_start);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -2280,6 +2308,9 @@ ble_gattc_find_inc_svcs_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_find_inc_svcs_cb(proc, rc, 0, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2354,6 +2385,7 @@ ble_gattc_find_inc_svcs_rx_read_rsp(struct ble_gattc_proc *proc, int status,
|
||||
rc = ble_gattc_find_inc_svcs_cb(proc, 0, 0, &service);
|
||||
if (rc != 0) {
|
||||
/* Application has indicated that the procedure should be aborted. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -2369,6 +2401,7 @@ ble_gattc_find_inc_svcs_rx_read_rsp(struct ble_gattc_proc *proc, int status,
|
||||
|
||||
err:
|
||||
ble_gattc_find_inc_svcs_cb(proc, rc, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -2445,6 +2478,7 @@ done:
|
||||
}
|
||||
|
||||
if (rc != 0 || cbrc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -2464,18 +2498,21 @@ ble_gattc_find_inc_svcs_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
|
||||
if (status != 0) {
|
||||
ble_gattc_find_inc_svcs_cb(proc, status, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (proc->find_inc_svcs.prev_handle == 0xffff) {
|
||||
/* Procedure complete. */
|
||||
ble_gattc_find_inc_svcs_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
/* Send follow-up request. */
|
||||
rc = ble_gattc_find_inc_svcs_resume(proc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
return 0;
|
||||
@@ -2494,6 +2531,7 @@ ble_gattc_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
|
||||
#endif
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_FIND_INC_SVCS)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2534,6 +2572,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2598,6 +2639,7 @@ ble_gattc_disc_all_chrs_tx(struct ble_gattc_proc *proc)
|
||||
proc->disc_all_chrs.prev_handle + 1,
|
||||
proc->disc_all_chrs.end_handle, &uuid.u);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2614,6 +2656,9 @@ ble_gattc_disc_all_chrs_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_disc_all_chrs_cb(proc, rc, 0, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2686,6 +2731,7 @@ ble_gattc_disc_all_chrs_rx_adata(struct ble_gattc_proc *proc,
|
||||
done:
|
||||
cbrc = ble_gattc_disc_all_chrs_cb(proc, rc, 0, &chr);
|
||||
if (rc != 0 || cbrc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -2705,18 +2751,21 @@ ble_gattc_disc_all_chrs_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
|
||||
if (status != 0) {
|
||||
ble_gattc_disc_all_chrs_cb(proc, status, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (proc->disc_all_chrs.prev_handle == proc->disc_all_chrs.end_handle) {
|
||||
/* Characteristic discovery complete. */
|
||||
ble_gattc_disc_all_chrs_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
/* Send follow-up request. */
|
||||
rc = ble_gattc_disc_all_chrs_resume(proc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
return 0;
|
||||
@@ -2728,6 +2777,7 @@ ble_gattc_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
|
||||
void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_DISC_ALL_CHRS)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -2842,6 +2892,7 @@ ble_gattc_disc_chr_uuid_tx(struct ble_gattc_proc *proc)
|
||||
proc->disc_chr_uuid.prev_handle + 1,
|
||||
proc->disc_chr_uuid.end_handle, &uuid.u);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2858,6 +2909,9 @@ ble_gattc_disc_chr_uuid_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_disc_chr_uuid_cb(proc, rc, 0, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2941,6 +2995,7 @@ done:
|
||||
}
|
||||
|
||||
if (rc != 0 || cbrc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -2960,18 +3015,21 @@ ble_gattc_disc_chr_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
|
||||
if (status != 0) {
|
||||
ble_gattc_disc_chr_uuid_cb(proc, status, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (proc->disc_chr_uuid.prev_handle == proc->disc_chr_uuid.end_handle) {
|
||||
/* Characteristic discovery complete. */
|
||||
ble_gattc_disc_chr_uuid_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
/* Send follow-up request. */
|
||||
rc = ble_gattc_disc_chr_uuid_resume(proc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
return 0;
|
||||
@@ -2983,6 +3041,7 @@ ble_gattc_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
|
||||
ble_gatt_chr_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_DISC_CHR_UUID)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3024,6 +3083,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3087,6 +3149,7 @@ ble_gattc_disc_all_dscs_tx(struct ble_gattc_proc *proc)
|
||||
proc->disc_all_dscs.prev_handle + 1,
|
||||
proc->disc_all_dscs.end_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3103,6 +3166,9 @@ ble_gattc_disc_all_dscs_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_disc_all_dscs_cb(proc, rc, 0, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3156,6 +3222,7 @@ done:
|
||||
|
||||
cbrc = ble_gattc_disc_all_dscs_cb(proc, rc, 0, &dsc);
|
||||
if (rc != 0 || cbrc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
} else {
|
||||
return 0;
|
||||
@@ -3175,18 +3242,21 @@ ble_gattc_disc_all_dscs_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
|
||||
if (status != 0) {
|
||||
ble_gattc_disc_all_dscs_cb(proc, status, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (proc->disc_all_dscs.prev_handle == proc->disc_all_dscs.end_handle) {
|
||||
/* All descriptors discovered. */
|
||||
ble_gattc_disc_all_dscs_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
/* Send follow-up request. */
|
||||
rc = ble_gattc_disc_all_dscs_resume(proc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -3199,6 +3269,7 @@ ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t start_handle,
|
||||
ble_gatt_dsc_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_DISC_ALL_DSCS)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3258,6 +3329,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3265,8 +3339,10 @@ done:
|
||||
int ble_gattc_check_valid_param(uint16_t num, uint16_t offset)
|
||||
{
|
||||
if (num == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_ATTR_NOT_FOUND);
|
||||
return BLE_ATT_ERR_ATTR_NOT_FOUND;
|
||||
} else if (offset >= num) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INVALID_OFFSET);
|
||||
return BLE_ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
|
||||
@@ -3432,6 +3508,9 @@ int ble_gattc_get_service(uint16_t conn_handle,
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
ble_gattc_fill_gatt_db_conversion(count, svc_num, ESP_BLE_GATT_DB_PRIMARY_SERVICE, offset, (void *)result, db);
|
||||
@@ -3461,6 +3540,9 @@ int ble_gattc_get_all_char(uint16_t conn_handle,
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
ble_gattc_fill_gatt_db_conversion(count, char_num, ESP_BLE_GATT_DB_CHARACTERISTIC, offset, (void *)result, db);
|
||||
@@ -3489,6 +3571,9 @@ int ble_gattc_get_all_descr(uint16_t conn_handle,
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
ble_gattc_fill_gatt_db_conversion(count, descr_num, ESP_BLE_GATT_DB_DESCRIPTOR, offset, (void *)result, db);
|
||||
@@ -3519,6 +3604,9 @@ int ble_gattc_get_char_by_uuid(uint16_t conn_handle,
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
ble_gattc_fill_gatt_db_conversion(count, char_num, ESP_BLE_GATT_DB_CHARACTERISTIC, 0, (void *)result, db);
|
||||
@@ -3551,6 +3639,9 @@ int ble_gattc_get_descr_by_uuid(uint16_t conn_handle,
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
ble_gattc_fill_gatt_db_conversion(count, descr_num, ESP_BLE_GATT_DB_DESCRIPTOR, 0, (void *)result, db);
|
||||
@@ -3580,6 +3671,9 @@ int ble_gattc_get_descr_by_char_handle(uint16_t conn_handle,
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
ble_gattc_fill_gatt_db_conversion(count, descr_num, ESP_BLE_GATT_DB_DESCRIPTOR, 0, (void *)result, db);
|
||||
@@ -3612,6 +3706,9 @@ int ble_gattc_get_include_service(uint16_t conn_handle,
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
} else {
|
||||
ble_gattc_fill_gatt_db_conversion(count, incl_num, ESP_BLE_GATT_DB_INCLUDED_SERVICE, 0, (void *)result, db);
|
||||
@@ -3648,6 +3745,7 @@ int ble_gattc_get_db(uint16_t conn_handle,
|
||||
ble_gattc_get_cached_gatt_db(conn_handle, start_handle, end_handle, &db, &num, count);
|
||||
|
||||
if (num == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_ATTR_NOT_FOUND);
|
||||
return BLE_ATT_ERR_ATTR_NOT_FOUND;
|
||||
}
|
||||
if (db) {
|
||||
@@ -3745,6 +3843,7 @@ ble_gattc_read_rx_read_rsp(struct ble_gattc_proc *proc, int status,
|
||||
*om = attr.om;
|
||||
|
||||
/* The read operation only has a single request / response exchange. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -3755,6 +3854,7 @@ ble_gattc_read_tx(struct ble_gattc_proc *proc)
|
||||
|
||||
rc = ble_att_clt_tx_read(proc->conn_handle, proc->cid, proc->read.handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3766,6 +3866,7 @@ ble_gattc_read(uint16_t conn_handle, uint16_t attr_handle,
|
||||
ble_gatt_attr_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_READ)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3800,6 +3901,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3888,6 +3992,7 @@ ble_gattc_read_uuid_rx_adata(struct ble_gattc_proc *proc,
|
||||
os_mbuf_free_chain(attr.om);
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -3905,6 +4010,7 @@ ble_gattc_read_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
|
||||
if (status != 0) {
|
||||
ble_gattc_read_uuid_cb(proc, status, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -3912,6 +4018,7 @@ ble_gattc_read_uuid_rx_complete(struct ble_gattc_proc *proc, int status)
|
||||
* of multiple characteristics with identical UUIDs.
|
||||
*/
|
||||
ble_gattc_read_uuid_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -3930,6 +4037,7 @@ ble_gattc_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
|
||||
ble_gatt_attr_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_READ_UUID)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -3964,6 +4072,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4030,6 +4141,7 @@ ble_gattc_read_long_tx(struct ble_gattc_proc *proc)
|
||||
if (proc->read_long.offset == 0) {
|
||||
rc = ble_att_clt_tx_read(proc->conn_handle, proc->cid, proc->read_long.handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@@ -4037,6 +4149,7 @@ ble_gattc_read_long_tx(struct ble_gattc_proc *proc)
|
||||
proc->read_long.handle,
|
||||
proc->read_long.offset);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -4054,6 +4167,9 @@ ble_gattc_read_long_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_read_long_cb(proc, rc, 0, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4100,6 +4216,7 @@ ble_gattc_read_long_rx_read_rsp(struct ble_gattc_proc *proc, int status,
|
||||
*om = attr.om;
|
||||
|
||||
if (rc != 0 || status != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -4107,12 +4224,14 @@ ble_gattc_read_long_rx_read_rsp(struct ble_gattc_proc *proc, int status,
|
||||
mtu = ble_att_mtu_by_cid(proc->conn_handle, proc->cid);
|
||||
if (mtu == 0) {
|
||||
/* No longer connected. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
if (data_len < mtu - 1) {
|
||||
/* Response shorter than maximum allowed; read complete. */
|
||||
ble_gattc_read_long_cb(proc, BLE_HS_EDONE, 0, NULL);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -4120,6 +4239,7 @@ ble_gattc_read_long_rx_read_rsp(struct ble_gattc_proc *proc, int status,
|
||||
proc->read_long.offset += data_len;
|
||||
rc = ble_gattc_read_long_resume(proc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -4131,6 +4251,7 @@ ble_gattc_read_long(uint16_t conn_handle, uint16_t handle, uint16_t offset,
|
||||
ble_gatt_attr_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_READ_LONG)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -4165,6 +4286,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4344,6 +4468,7 @@ ble_gattc_read_mult_tx(struct ble_gattc_proc *proc)
|
||||
rc = ble_att_clt_tx_read_mult(proc->conn_handle, proc->cid, proc->read_mult.handles,
|
||||
proc->read_mult.num_handles, proc->read_mult.variable);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4358,6 +4483,7 @@ ble_gattc_read_mult_internal(uint16_t conn_handle, const uint16_t *handles,
|
||||
void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_READ_MULT)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -4401,6 +4527,9 @@ done:
|
||||
}
|
||||
|
||||
ble_gattc_process_status(proc, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4422,6 +4551,7 @@ ble_gattc_read_mult_var(uint16_t conn_handle, const uint16_t *handles,
|
||||
return ble_gattc_read_mult_internal(conn_handle, handles, num_handles,
|
||||
true, NULL, cb, cb_arg);
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -4435,6 +4565,7 @@ ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct os_mbuf *txom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_WRITE_NO_RSP)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -4452,6 +4583,9 @@ ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
|
||||
}
|
||||
ble_eatt_release_chan(conn_handle, BLE_GATT_OP_DUMMY);
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4464,11 +4598,13 @@ ble_gattc_write_no_rsp_flat(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
om = ble_hs_mbuf_from_flat(data, data_len);
|
||||
if (om == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
rc = ble_gattc_write_no_rsp(conn_handle, attr_handle, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4485,6 +4621,7 @@ ble_gattc_signed_write(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct os_mbuf *txom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_SIGNED_WRITE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -4606,6 +4743,7 @@ ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct os_mbuf *txom, ble_gatt_attr_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_WRITE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -4662,11 +4800,13 @@ ble_gattc_write_flat(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
om = ble_hs_mbuf_from_flat(data, data_len);
|
||||
if (om == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
rc = ble_gattc_write(conn_handle, attr_handle, om, cb, cb_arg);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4781,6 +4921,9 @@ ble_gattc_write_long_tx(struct ble_gattc_proc *proc)
|
||||
|
||||
done:
|
||||
os_mbuf_free_chain(om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4794,6 +4937,9 @@ ble_gattc_write_long_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_write_long_cb(proc, rc, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -4900,6 +5046,7 @@ ble_gattc_write_long_rx_prep(struct ble_gattc_proc *proc,
|
||||
err:
|
||||
/* XXX: Might need to cancel pending writes. */
|
||||
ble_gattc_write_long_cb(proc, rc, 0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -4918,10 +5065,12 @@ ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc, int status)
|
||||
/* Expecting an execute write response, not a prepare write
|
||||
* response.
|
||||
*/
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
ble_gattc_write_long_cb(proc, status, 0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -4931,6 +5080,7 @@ ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle,
|
||||
ble_gatt_attr_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_WRITE_LONG)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -5090,6 +5240,9 @@ ble_gattc_write_reliable_tx(struct ble_gattc_proc *proc)
|
||||
|
||||
done:
|
||||
os_mbuf_free_chain(om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -5103,6 +5256,9 @@ ble_gattc_write_reliable_resume(struct ble_gattc_proc *proc)
|
||||
rc = ble_gattc_process_resume_status(proc, status);
|
||||
if (rc != 0) {
|
||||
ble_gattc_write_reliable_cb(proc, rc, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -5194,6 +5350,7 @@ ble_gattc_write_reliable_rx_prep(struct ble_gattc_proc *proc,
|
||||
|
||||
err:
|
||||
ble_gattc_write_reliable_err(proc, rc, 0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -5206,6 +5363,7 @@ ble_gattc_write_reliable_rx_exec(struct ble_gattc_proc *proc, int status)
|
||||
{
|
||||
ble_gattc_dbg_assert_proc_not_inserted(proc);
|
||||
ble_gattc_write_reliable_cb(proc, status, 0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EDONE);
|
||||
return BLE_HS_EDONE;
|
||||
}
|
||||
|
||||
@@ -5216,6 +5374,7 @@ ble_gattc_write_reliable(uint16_t conn_handle,
|
||||
ble_gatt_reliable_attr_fn *cb, void *cb_arg)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_WRITE_RELIABLE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -5284,6 +5443,7 @@ static int ble_gatts_check_conn_aware(uint16_t conn_handle, bool *aware) {
|
||||
struct ble_hs_conn *conn;
|
||||
conn = ble_hs_conn_find(conn_handle);
|
||||
if(conn == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
*aware = conn->bhc_gatt_svr.aware_state;
|
||||
@@ -5297,6 +5457,7 @@ ble_gatts_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle,
|
||||
struct os_mbuf *txom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_NOTIFY)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING)
|
||||
@@ -5365,6 +5526,7 @@ ble_gatts_notify_multiple_custom(uint16_t conn_handle,
|
||||
struct ble_gatt_notif *tuples)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_NOTIFY_MULTIPLE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -5380,6 +5542,7 @@ ble_gatts_notify_multiple_custom(uint16_t conn_handle,
|
||||
|
||||
txom = ble_hs_mbuf_att_pkt();
|
||||
if (txom == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -5388,6 +5551,7 @@ ble_gatts_notify_multiple_custom(uint16_t conn_handle,
|
||||
if (conn == NULL) {
|
||||
ble_hs_unlock();
|
||||
os_mbuf_free_chain(txom);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
@@ -5571,6 +5735,7 @@ int ble_gattc_register_for_notification(uint16_t conn_handle, uint16_t char_val_
|
||||
/* Check if a GATT procedure is already active */
|
||||
if (gatt_proc_active) {
|
||||
BLE_HS_LOG(WARN, "Gatt procedure active; cannot start new process.");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBUSY);
|
||||
return BLE_HS_EBUSY;
|
||||
}
|
||||
|
||||
@@ -5591,6 +5756,9 @@ int ble_gattc_register_for_notification(uint16_t conn_handle, uint16_t char_val_
|
||||
nimble_platform_mem_free(cccd_reg_flag);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -5640,6 +5808,7 @@ int ble_gattc_unregister_for_notification(uint16_t conn_handle, uint16_t char_va
|
||||
{
|
||||
if (gatt_proc_active) {
|
||||
BLE_HS_LOG(WARN, "Gatt procedure active; cannot start new process");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBUSY);
|
||||
return BLE_HS_EBUSY;
|
||||
}
|
||||
|
||||
@@ -5661,6 +5830,9 @@ int ble_gattc_unregister_for_notification(uint16_t conn_handle, uint16_t char_va
|
||||
nimble_platform_mem_free(cccd_unreg_flag);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif //MYNEWT_VAL(BLE_STORE_MAX_CCCDS)
|
||||
@@ -5671,6 +5843,7 @@ int
|
||||
ble_gatts_notify(uint16_t conn_handle, uint16_t chr_val_handle)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_NOTIFY)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -5778,6 +5951,7 @@ ble_gatts_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle,
|
||||
struct os_mbuf *txom)
|
||||
{
|
||||
#if !MYNEWT_VAL(BLE_GATT_INDICATE)
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -6355,12 +6529,14 @@ ble_gattc_err_dispatch_init(void)
|
||||
{
|
||||
|
||||
if (ble_gattc_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
ble_gattc_err_dispatch = nimble_platform_mem_calloc(1, BLE_GATT_OP_CNT * sizeof(ble_gattc_err_fn *));
|
||||
|
||||
if (!ble_gattc_err_dispatch) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -6405,12 +6581,14 @@ static int
|
||||
ble_gattc_resume_dispatch_init(void)
|
||||
{
|
||||
if (ble_gattc_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
ble_gattc_resume_dispatch = nimble_platform_mem_calloc(1, BLE_GATT_OP_CNT * sizeof(ble_gattc_resume_fn *));
|
||||
|
||||
if (!ble_gattc_resume_dispatch) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
ble_gattc_resume_dispatch[BLE_GATT_OP_MTU] = NULL;
|
||||
@@ -6449,12 +6627,14 @@ static int
|
||||
ble_gattc_tmo_dispatch_init(void)
|
||||
{
|
||||
if (ble_gattc_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
ble_gattc_tmo_dispatch = nimble_platform_mem_calloc(1, BLE_GATT_OP_CNT * sizeof(ble_gattc_tmo_fn *));
|
||||
|
||||
if (!ble_gattc_tmo_dispatch) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -6504,6 +6684,7 @@ ble_gattc_init(void)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
rc = ble_gattc_ensure_ctx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -6524,6 +6705,7 @@ ble_gattc_init(void)
|
||||
if (ble_gattc_proc_mem == NULL) {
|
||||
ble_gattc_proc_mem = (os_membuf_t *)nimble_platform_mem_calloc(mem_bytes, sizeof(os_membuf_t));
|
||||
if (ble_gattc_proc_mem == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -6548,6 +6730,9 @@ ble_gattc_init(void)
|
||||
rc = ble_gattc_err_dispatch_init();
|
||||
if (rc != 0) {
|
||||
ble_gattc_deinit();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -6556,6 +6741,9 @@ ble_gattc_init(void)
|
||||
rc = ble_gattc_resume_dispatch_init();
|
||||
if (rc != 0) {
|
||||
ble_gattc_deinit();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -6563,12 +6751,16 @@ ble_gattc_init(void)
|
||||
rc = ble_gattc_tmo_dispatch_init();
|
||||
if (rc != 0) {
|
||||
ble_gattc_deinit();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -6578,11 +6770,13 @@ ble_gattc_init(void)
|
||||
STATS_HDR(ble_gattc_stats), STATS_SIZE_INIT_PARMS(ble_gattc_stats,
|
||||
STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_gattc_stats), "ble_gattc");
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "nimble/storage_port.h"
|
||||
#include "host/ble_gatt.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
#include "nvs.h"
|
||||
#endif
|
||||
@@ -122,12 +123,14 @@ cacheEraseItem(cache_handle_t handle, const char *key)
|
||||
if (cache_fn.erase_key_item) {
|
||||
rc = cache_fn.erase_key_item(handle,key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (cache_fn.commit) {
|
||||
rc = cache_fn.commit(handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -297,6 +300,7 @@ ble_gattc_cache_static_vars_init(void)
|
||||
|
||||
ble_gattc_cache_static_vars = nimble_platform_mem_calloc(1, sizeof(ble_gattc_cache_static_vars_t));
|
||||
if (ble_gattc_cache_static_vars == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -485,11 +489,13 @@ ble_gattc_cache_addr_save(uint8_t *out_index, ble_addr_t addr, uint8_t * hash_ke
|
||||
uint8_t *p_buf;
|
||||
|
||||
if (cache_env == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
p_buf = nimble_platform_mem_calloc(1,MAX_ADDR_LIST_CACHE_BUF);
|
||||
if (p_buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -506,6 +512,7 @@ ble_gattc_cache_addr_save(uint8_t *out_index, ble_addr_t addr, uint8_t * hash_ke
|
||||
/* Address not found - need to allocate a new slot */
|
||||
if(cache_env->num_addr >= MYNEWT_VAL(BLE_GATT_CACHING_MAX_CONNS)) {
|
||||
nimble_platform_mem_free(p_buf);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
BLE_HS_LOG(DEBUG, "BD addr not present");
|
||||
@@ -516,6 +523,7 @@ ble_gattc_cache_addr_save(uint8_t *out_index, ble_addr_t addr, uint8_t * hash_ke
|
||||
BLE_HS_LOG(DEBUG, "Hash key not present, saving new data");
|
||||
if(cache_env->num_addr >= MYNEWT_VAL(BLE_GATT_CACHING_MAX_CONNS)) {
|
||||
nimble_platform_mem_free(p_buf);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
insert_ind = cache_env->num_addr;
|
||||
@@ -661,6 +669,7 @@ ble_gattc_add_svc_from_cache(ble_addr_t peer_addr, struct ble_gatt_nv_attr nv_at
|
||||
|
||||
gatt_svc = (struct ble_gatt_svc *)nimble_platform_mem_calloc(1,sizeof(struct ble_gatt_svc));
|
||||
if (gatt_svc == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -682,6 +691,7 @@ ble_gattc_add_inc_from_cache(ble_addr_t peer_addr, struct ble_gatt_nv_attr nv_at
|
||||
|
||||
gatt_incl_svc = (struct ble_gatt_incl_svc *)nimble_platform_mem_calloc(1,sizeof(struct ble_gatt_incl_svc));
|
||||
if (gatt_incl_svc == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -703,6 +713,7 @@ ble_gattc_add_chr_from_cache(ble_addr_t peer_addr, struct ble_gatt_nv_attr nv_at
|
||||
int rc;
|
||||
gatt_chr = (struct ble_gatt_chr *)nimble_platform_mem_calloc(1,sizeof(struct ble_gatt_chr));
|
||||
if (gatt_chr == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -723,6 +734,7 @@ ble_gattc_add_dsc_from_cache(ble_addr_t peer_addr, struct ble_gatt_nv_attr nv_at
|
||||
int rc;
|
||||
gatt_dsc = (struct ble_gatt_dsc *)nimble_platform_mem_calloc(1,sizeof(struct ble_gatt_dsc));
|
||||
if (gatt_dsc == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -743,6 +755,7 @@ ble_gattc_cache_assoc_load(ble_addr_t src_addr, uint8_t src_index, ble_addr_t as
|
||||
|
||||
if (!cacheOpen(src_addr, true, &src_index)) {
|
||||
BLE_HS_LOG(INFO, "gattc cache open fail for src addr");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -788,6 +801,7 @@ ble_gattc_cache_assoc_load(ble_addr_t src_addr, uint8_t src_index, ble_addr_t as
|
||||
BLE_HS_LOG(DEBUG, "Successfully associated cache from src_addr to assoc_addr.");
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -833,12 +847,14 @@ ble_gattc_cache_load(ble_addr_t peer_addr)
|
||||
|
||||
if (!cacheOpen(peer_addr, true, &index)) {
|
||||
BLE_HS_LOG(INFO, "gattc cache open fail");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if ((nv_attr = ble_gattc_cache_load_nv_attr(index, &num_attr)) == NULL) {
|
||||
BLE_HS_LOG(INFO, "%s, gattc cache nv_attr load fail", __func__);
|
||||
cacheClose(peer_addr);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -938,6 +954,7 @@ ble_gattc_cache_init(void *storage_cb)
|
||||
int no_cached_blob = 0;
|
||||
rc = ble_gattc_cache_static_vars_init();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_gattc_cache_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING)
|
||||
/* Gatt Procedure macros */
|
||||
@@ -37,12 +38,14 @@
|
||||
#define CHECK_CACHE_CONN_STATE(cache_state, cb, cb_arg, opcode, \
|
||||
s_handle, e_handle, p_uuid) \
|
||||
if (ble_hs_cfg.gatt_use_cache == 0) { \
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP); \
|
||||
return BLE_HS_ENOTSUP; \
|
||||
} \
|
||||
op = &conn->pending_op; \
|
||||
switch(cache_state) { \
|
||||
case SVC_DISC_IN_PROGRESS: \
|
||||
if((void*)ble_gattc_cache_conn_svc_disced == cb) { \
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL); \
|
||||
return BLE_HS_EINVAL; \
|
||||
} \
|
||||
ble_gattc_cache_conn_fill_op(op, s_handle, e_handle, p_uuid, cb, \
|
||||
@@ -50,6 +53,7 @@
|
||||
return 0; \
|
||||
case CHR_DISC_IN_PROGRESS: \
|
||||
if((void*)ble_gattc_cache_conn_chr_disced == cb) { \
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL); \
|
||||
return BLE_HS_EINVAL; \
|
||||
} \
|
||||
ble_gattc_cache_conn_fill_op(op, s_handle, e_handle, p_uuid, cb, \
|
||||
@@ -57,6 +61,7 @@
|
||||
return 0; \
|
||||
case INC_DISC_IN_PROGRESS: \
|
||||
if((void *)ble_gattc_cache_conn_inc_disced == cb) { \
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL); \
|
||||
return BLE_HS_EINVAL; \
|
||||
} \
|
||||
ble_gattc_cache_conn_fill_op(op, s_handle, e_handle, p_uuid, cb, \
|
||||
@@ -64,6 +69,7 @@
|
||||
return 0; \
|
||||
case DSC_DISC_IN_PROGRESS: \
|
||||
if((void*)ble_gattc_cache_conn_dsc_disced == cb) { \
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL); \
|
||||
return BLE_HS_EINVAL; \
|
||||
} \
|
||||
ble_gattc_cache_conn_fill_op(op, s_handle, e_handle, p_uuid, cb, \
|
||||
@@ -317,6 +323,7 @@ ble_gattc_cache_conn_dsc_add(ble_addr_t peer_addr, uint16_t chr_val_handle,
|
||||
* happen.
|
||||
*/
|
||||
assert(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -332,6 +339,7 @@ ble_gattc_cache_conn_dsc_add(ble_addr_t peer_addr, uint16_t chr_val_handle,
|
||||
*/
|
||||
BLE_HS_LOG(ERROR, "Couldn't find characteristc for dsc handle = %d", gatt_dsc->handle);
|
||||
assert(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -345,6 +353,7 @@ ble_gattc_cache_conn_dsc_add(ble_addr_t peer_addr, uint16_t chr_val_handle,
|
||||
dsc = os_memblock_get(&ble_gattc_cache_conn_dsc_pool);
|
||||
if (dsc == NULL) {
|
||||
/* Out of memory. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memset(dsc, 0, sizeof * dsc);
|
||||
@@ -524,6 +533,7 @@ ble_gattc_cache_conn_chr_add(ble_addr_t peer_addr, uint16_t svc_start_handle,
|
||||
* happen.
|
||||
*/
|
||||
assert(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -536,6 +546,7 @@ ble_gattc_cache_conn_chr_add(ble_addr_t peer_addr, uint16_t svc_start_handle,
|
||||
chr = os_memblock_get(&ble_gattc_cache_conn_chr_pool);
|
||||
if (chr == NULL) {
|
||||
/* Out of memory. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memset(chr, 0, sizeof * chr);
|
||||
@@ -716,6 +727,7 @@ ble_gattc_cache_conn_inc_add(ble_addr_t peer_addr, const struct ble_gatt_svc *ga
|
||||
svc = os_memblock_get(&ble_gattc_cache_conn_svc_pool);
|
||||
if (svc == NULL) {
|
||||
/* Out of memory. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -750,6 +762,7 @@ ble_gattc_cache_conn_inc_add(ble_addr_t peer_addr, const struct ble_gatt_svc *ga
|
||||
*/
|
||||
BLE_HS_LOG(WARN, "Current Service is NULL.\n");
|
||||
assert(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -761,6 +774,7 @@ ble_gattc_cache_conn_inc_add(ble_addr_t peer_addr, const struct ble_gatt_svc *ga
|
||||
|
||||
incl_svc = os_memblock_get(&ble_gattc_cache_conn_incl_svc_pool);
|
||||
if (incl_svc == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -803,6 +817,7 @@ ble_gattc_cache_conn_svc_add(ble_addr_t peer_addr, const struct ble_gatt_svc *ga
|
||||
svc = os_memblock_get(&ble_gattc_cache_conn_svc_pool);
|
||||
if (svc == NULL) {
|
||||
/* Out of memory. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
memset(svc, 0, sizeof * svc);
|
||||
@@ -1699,6 +1714,9 @@ ble_gattc_cache_conn_inc_disced(uint16_t conn_handle, const struct ble_gatt_erro
|
||||
ble_gattc_cache_conn_disc_complete(peer, rc);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1736,6 +1754,9 @@ ble_gattc_cache_conn_svc_disced(uint16_t conn_handle, const struct ble_gatt_erro
|
||||
ble_gattc_cache_conn_disc_complete(peer, rc);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1802,6 +1823,7 @@ ble_gattc_cache_conn_create(uint16_t conn_handle, ble_addr_t ble_gattc_cache_con
|
||||
cache_conn = os_memblock_get(&ble_gattc_cache_conn_pool);
|
||||
if (cache_conn == NULL) {
|
||||
/* Out of memory. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1877,6 +1899,9 @@ ble_gattc_cache_conn_dsc_disced(uint16_t conn_handle, const struct ble_gatt_erro
|
||||
ble_gattc_cache_conn_disc_complete(peer, rc);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1959,6 +1984,9 @@ ble_gattc_cache_conn_chr_disced(uint16_t conn_handle, const struct ble_gatt_erro
|
||||
ble_gattc_cache_conn_disc_complete(peer, rc);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2069,6 +2097,7 @@ int ble_gattc_cache_refresh(ble_addr_t peer_addr)
|
||||
peer_addr.val[0], peer_addr.val[1], peer_addr.val[2],
|
||||
peer_addr.val[3], peer_addr.val[4], peer_addr.val[5]);
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
@@ -2079,6 +2108,7 @@ int ble_gattc_cache_refresh(ble_addr_t peer_addr)
|
||||
conn = ble_gattc_cache_conn_find_by_addr(peer_addr);
|
||||
if (conn == NULL) {
|
||||
BLE_HS_LOG(WARN, "GATT cache refresh: no cache entry found for peer.");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -2111,6 +2141,9 @@ ble_gattc_cache_conn_assoc_on_read(uint16_t conn_handle,
|
||||
rc = os_mbuf_copydata(attr->om, 0, sizeof(database_hash), database_hash);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(WARN, "Failed to copy database hash from attr->om (rc=%d)", rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
rc = ble_gattc_cache_find_source((struct ble_gattc_cache_conn *)arg, database_hash);
|
||||
@@ -2126,6 +2159,7 @@ int ble_gattc_cache_assoc(ble_addr_t peer_addr)
|
||||
cache_conn = ble_gattc_cache_conn_find_by_addr(peer_addr);
|
||||
if (cache_conn == NULL) {
|
||||
BLE_HS_LOG(WARN, "No cache entry found for peer.");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -2144,6 +2178,9 @@ int ble_gattc_cache_assoc(ble_addr_t peer_addr)
|
||||
|
||||
if (rc != 0) {
|
||||
cache_conn->cache_state = CACHE_INVALID;
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -2178,6 +2215,7 @@ int ble_gattc_cache_clean(ble_addr_t peer_addr)
|
||||
if (conn == NULL) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(WARN, "GATT cache clean: no cache entry found for peer.");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -2454,6 +2492,7 @@ static int ble_gattc_cache_conn_verify(struct ble_gattc_cache_conn *conn)
|
||||
ble_hs_unlock();
|
||||
|
||||
if (gap_conn == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
if (conn->cache_state == CACHE_LOADED) {
|
||||
@@ -2542,11 +2581,13 @@ ble_gattc_cache_conn_search_all_svcs(uint16_t conn_handle,
|
||||
BLE_HS_LOG(DEBUG, "No connection in the Cache"
|
||||
"HANDLE=%d\n",
|
||||
conn_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
rc = ble_gattc_cache_conn_verify(conn);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2603,11 +2644,13 @@ ble_gattc_cache_conn_search_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *
|
||||
BLE_HS_LOG(DEBUG, "No connection in the Cache"
|
||||
"HANDLE=%d\n",
|
||||
conn_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
rc = ble_gattc_cache_conn_verify(conn);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2696,11 +2739,13 @@ ble_gattc_cache_conn_search_inc_svcs(uint16_t conn_handle, uint16_t start_handle
|
||||
BLE_HS_LOG(DEBUG, "No connection in the Cache"
|
||||
"HANDLE=%d\n",
|
||||
conn_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
rc = ble_gattc_cache_conn_verify(conn);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2765,11 +2810,13 @@ ble_gattc_cache_conn_search_all_chrs(uint16_t conn_handle, uint16_t start_handle
|
||||
BLE_HS_LOG(DEBUG, "No connection in the Cache"
|
||||
"HANDLE=%d\n",
|
||||
conn_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
rc = ble_gattc_cache_conn_verify(conn);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2834,11 +2881,13 @@ ble_gattc_cache_conn_search_chrs_by_uuid(uint16_t conn_handle, uint16_t start_ha
|
||||
BLE_HS_LOG(DEBUG, "No connection in the Cache"
|
||||
"HANDLE=%d\n",
|
||||
conn_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
rc = ble_gattc_cache_conn_verify(conn);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2908,11 +2957,13 @@ ble_gattc_cache_conn_search_all_dscs(uint16_t conn_handle, uint16_t start_handle
|
||||
BLE_HS_LOG(DEBUG, "No connection in the Cache"
|
||||
"HANDLE=%d\n",
|
||||
conn_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
rc = ble_gattc_cache_conn_verify(conn);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "host/ble_store.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTS)
|
||||
|
||||
@@ -203,6 +204,7 @@ ble_gatts_ensure_ctx(void)
|
||||
ble_gatts_static_vars = nimble_platform_mem_calloc(1, sizeof(ble_gatts_static_vars_t));
|
||||
|
||||
if (!ble_gatts_static_vars) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -299,6 +301,7 @@ ble_gatts_svc_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
buf = os_mbuf_extend(*om, ble_uuid_length(svc->uuid));
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
@@ -324,6 +327,7 @@ ble_gatts_inc_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
buf = os_mbuf_extend(*om, 4);
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
put_le16(buf + 0, entry->handle);
|
||||
@@ -334,6 +338,7 @@ ble_gatts_inc_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
if (uuid16 != 0) {
|
||||
buf = os_mbuf_extend(*om, 2);
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
put_le16(buf, uuid16);
|
||||
@@ -465,6 +470,7 @@ ble_gatts_chr_def_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
buf = os_mbuf_extend(*om, 3);
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
@@ -475,6 +481,7 @@ ble_gatts_chr_def_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
buf = os_mbuf_extend(*om, ble_uuid_length(chr->uuid));
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
@@ -591,6 +598,7 @@ ble_gatts_val_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
new_om = 1;
|
||||
gatt_ctxt->om = ble_hs_mbuf_att_pkt();
|
||||
if (gatt_ctxt->om == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
}
|
||||
@@ -622,6 +630,7 @@ ble_gatts_val_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_UNLIKELY);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
}
|
||||
@@ -724,6 +733,7 @@ ble_gatts_calculate_hash(uint8_t *out_hash_key)
|
||||
/* data with all zeroes */
|
||||
rc = ble_att_get_database_size(&size);
|
||||
if(rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
buf = nimble_platform_mem_calloc(1,sizeof(uint8_t) * size);
|
||||
@@ -763,6 +773,7 @@ ble_gatts_register_inc(struct ble_gatts_svc_entry *entry)
|
||||
rc = ble_att_svr_register(uuid_inc, BLE_ATT_F_READ, 0, &handle,
|
||||
ble_gatts_inc_access, entry);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -851,12 +862,14 @@ ble_gatts_register_dsc(const struct ble_gatt_svc_def *svc,
|
||||
int rc;
|
||||
|
||||
if (!ble_gatts_dsc_is_sane(dsc)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
rc = ble_att_svr_register(dsc->uuid, dsc->att_flags, dsc->min_key_size,
|
||||
&dsc_handle, ble_gatts_dsc_access, (void *)dsc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1013,6 +1026,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
|
||||
chr_val_handle = attr_handle - 1;
|
||||
if (chr_val_handle > attr_handle) {
|
||||
/* Attribute handle wrapped somehow. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_UNLIKELY);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
||||
@@ -1024,6 +1038,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
|
||||
chr_val_handle);
|
||||
#endif
|
||||
if (clt_cfg == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_UNLIKELY);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
||||
@@ -1038,6 +1053,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
|
||||
STATS_INC(ble_gatts_stats, dsc_reads);
|
||||
buf = os_mbuf_extend(om, 2);
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
put_le16(buf, clt_cfg->flags & ~BLE_GATTS_CLT_CFG_F_RESERVED);
|
||||
@@ -1046,6 +1062,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
|
||||
case BLE_GATT_ACCESS_OP_WRITE_DSC:
|
||||
STATS_INC(ble_gatts_stats, dsc_writes);
|
||||
if (OS_MBUF_PKTLEN(om) != 2) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN);
|
||||
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
|
||||
}
|
||||
|
||||
@@ -1054,6 +1071,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
|
||||
|
||||
flags = get_le16(om->om_data);
|
||||
if ((flags & ~clt_cfg->allowed) != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_REQ_NOT_SUPPORTED);
|
||||
return BLE_ATT_ERR_REQ_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
@@ -1075,6 +1093,7 @@ ble_gatts_clt_cfg_access_locked(struct ble_hs_conn *conn, uint16_t attr_handle,
|
||||
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_UNLIKELY);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
||||
@@ -1108,6 +1127,7 @@ ble_gatts_clt_cfg_access(uint16_t conn_handle, uint16_t attr_handle,
|
||||
ble_hs_unlock();
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1139,6 +1159,7 @@ ble_gatts_register_clt_cfg_dsc(uint16_t *att_handle, uint8_t cccd_flags)
|
||||
rc = ble_att_svr_register(uuid_ccc, cccd_flags, 0,
|
||||
att_handle, ble_gatts_clt_cfg_access, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1217,6 +1238,7 @@ ble_gatts_register_cpfds(const struct ble_gatt_cpfd *cpfds)
|
||||
rc = ble_att_svr_register(uuid_cpf, BLE_ATT_F_READ, 0, &first_cpfd_handle,
|
||||
ble_gatts_cpfd_access, (void *)(cpfds + idx));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1231,6 +1253,7 @@ ble_gatts_register_cpfds(const struct ble_gatt_cpfd *cpfds)
|
||||
first_cpfd_handle -= (idx - 1);
|
||||
first_cpfd_entry = ble_att_svr_find_by_handle(first_cpfd_handle);
|
||||
if (first_cpfd_entry == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -1242,6 +1265,7 @@ ble_gatts_register_cpfds(const struct ble_gatt_cpfd *cpfds)
|
||||
rc = ble_att_svr_register(uuid_caf, BLE_ATT_F_READ, 0, NULL,
|
||||
ble_gatts_cafd_access, (void *)(first_cpfd_entry));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1266,12 +1290,14 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
|
||||
int rc;
|
||||
|
||||
if (!ble_gatts_chr_is_sane(chr)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (ble_gatts_chr_clt_cfg_allowed(chr) != 0) {
|
||||
#if !MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
if (ble_gatts_num_cfgable_chrs > ble_hs_max_client_configs) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -1284,6 +1310,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
|
||||
rc = ble_att_svr_register(uuid_chr, BLE_ATT_F_READ, 0, &def_handle,
|
||||
ble_gatts_chr_def_access, (void *)chr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1295,6 +1322,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
|
||||
&val_handle, ble_gatts_chr_val_access,
|
||||
(void *)chr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
BLE_HS_DBG_ASSERT(val_handle == def_handle + 1);
|
||||
@@ -1316,6 +1344,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
|
||||
att_flags = ble_gatts_chr_clt_cfg_flags_from_chr_flags(chr->flags);
|
||||
rc = ble_gatts_register_clt_cfg_dsc(&dsc_handle, att_flags);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
BLE_HS_DBG_ASSERT(dsc_handle == def_handle + 2);
|
||||
@@ -1324,6 +1353,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
|
||||
/* Register each Client Presentation Format Descriptor. */
|
||||
rc = ble_gatts_register_cpfds(chr->cpfd);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -1334,6 +1364,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
|
||||
rc = ble_gatts_register_dsc(svc, chr, dsc, def_handle, register_cb,
|
||||
cb_arg);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -1357,6 +1388,7 @@ ble_gatts_svc_type_to_uuid(uint8_t svc_type, const ble_uuid_t **uuid)
|
||||
return 0;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -1394,10 +1426,12 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
|
||||
int i;
|
||||
|
||||
if (!ble_gatts_svc_incs_satisfied(svc)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAGAIN);
|
||||
return BLE_HS_EAGAIN;
|
||||
}
|
||||
|
||||
if (!ble_gatts_svc_is_sane(svc)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1413,6 +1447,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
|
||||
rc = ble_att_svr_register(uuid, BLE_ATT_F_READ, 0, out_handle,
|
||||
ble_gatts_svc_access, (void *)svc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1438,6 +1473,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
|
||||
rc = ble_gatts_register_inc(ble_gatts_svc_entries + idx);
|
||||
#endif
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -1448,6 +1484,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
|
||||
for (chr = svc->characteristics; chr->uuid != NULL; chr++) {
|
||||
rc = ble_gatts_register_chr(svc, chr, register_cb, cb_arg);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -1494,6 +1531,9 @@ ble_gatts_register_round(int *out_num_registered, ble_gatt_register_fn *cb,
|
||||
break;
|
||||
|
||||
default:
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -1501,6 +1541,7 @@ ble_gatts_register_round(int *out_num_registered, ble_gatt_register_fn *cb,
|
||||
|
||||
if (*out_num_registered == 0) {
|
||||
/* There is a circular dependency. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1548,6 +1589,7 @@ ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
|
||||
#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE)
|
||||
entry = ble_gatts_svc_entry_alloc();
|
||||
if (entry == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
entry -> svc = svcs + i;
|
||||
@@ -1557,6 +1599,7 @@ ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
|
||||
#else
|
||||
idx = ble_gatts_num_svc_entries + i;
|
||||
if (idx >= ble_hs_max_services) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1574,6 +1617,7 @@ ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
|
||||
while (total_registered < num_svcs) {
|
||||
rc = ble_gatts_register_round(&cur_registered, cb, cb_arg);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
total_registered += cur_registered;
|
||||
@@ -2018,6 +2062,9 @@ done:
|
||||
}
|
||||
|
||||
ble_hs_unlock();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2078,6 +2125,7 @@ done:
|
||||
gatts_conn->clt_cfgs = os_memblock_get(&ble_gatts_clt_cfg_pool);
|
||||
|
||||
if (gatts_conn->clt_cfgs == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -2185,15 +2233,18 @@ ble_gatts_send_next_indicate(uint16_t conn_handle)
|
||||
ble_hs_unlock();
|
||||
|
||||
if (conn == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
if (chr_val_handle == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
rc = ble_gatts_indicate(conn_handle, chr_val_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2227,6 +2278,7 @@ ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle)
|
||||
if (clt_cfg_idx == -1) {
|
||||
#endif
|
||||
/* This characteristic does not have a CCCD. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -2235,6 +2287,7 @@ ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle)
|
||||
#endif
|
||||
if (!(clt_cfg->allowed & BLE_GATTS_CLT_CFG_F_INDICATE)) {
|
||||
/* This characteristic does not allow indications. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -2288,6 +2341,7 @@ ble_gatts_rx_indicate_ack(uint16_t conn_handle, uint16_t chr_val_handle)
|
||||
ble_hs_unlock();
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2427,6 +2481,7 @@ ble_gatts_peer_cl_sup_feat_get(uint16_t conn_handle, uint8_t *out_supported_feat
|
||||
int rc = 0;
|
||||
|
||||
if (out_supported_feat == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -2463,6 +2518,7 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
|
||||
BLE_HS_LOG(DEBUG, "");
|
||||
|
||||
if (!om) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_INSUFFICIENT_RES);
|
||||
return BLE_ATT_ERR_INSUFFICIENT_RES;
|
||||
}
|
||||
|
||||
@@ -2473,6 +2529,7 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om)
|
||||
}
|
||||
|
||||
if (os_mbuf_copydata(om, 0, len, feat) < 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ATT_ERR_UNLIKELY);
|
||||
return BLE_ATT_ERR_UNLIKELY;
|
||||
}
|
||||
|
||||
@@ -2922,11 +2979,13 @@ ble_gatts_find_svc_chr_attr(const ble_uuid_t *svc_uuid,
|
||||
svc_entry = ble_gatts_find_svc_entry(svc_uuid);
|
||||
#endif
|
||||
if (svc_entry == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
att_svc = ble_att_svr_find_by_handle(svc_entry->handle);
|
||||
if (att_svc == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -2934,12 +2993,14 @@ ble_gatts_find_svc_chr_attr(const ble_uuid_t *svc_uuid,
|
||||
while (1) {
|
||||
if (cur == NULL) {
|
||||
/* Reached end of attribute list without a match. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
next = STAILQ_NEXT(cur, ha_next);
|
||||
|
||||
if (cur->ha_handle_id == svc_entry->end_group_handle) {
|
||||
/* Reached end of service without a match. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -2971,6 +3032,7 @@ ble_gatts_find_svc(const ble_uuid_t *uuid, uint16_t *out_handle)
|
||||
entry = ble_gatts_find_svc_entry(uuid);
|
||||
#endif
|
||||
if (entry == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -2989,6 +3051,7 @@ ble_gatts_find_chr(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
|
||||
|
||||
rc = ble_gatts_find_svc_chr_attr(svc_uuid, chr_uuid, NULL, &att_chr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3014,6 +3077,7 @@ ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
|
||||
rc = ble_gatts_find_svc_chr_attr(svc_uuid, chr_uuid, &svc_entry,
|
||||
&att_chr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3021,17 +3085,20 @@ ble_gatts_find_dsc(const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid,
|
||||
while (1) {
|
||||
if (cur == NULL) {
|
||||
/* Reached end of attribute list without a match. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
if (cur->ha_handle_id > svc_entry->end_group_handle) {
|
||||
/* Reached end of service without a match. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
uuid16 = ble_uuid_u16(cur->ha_uuid);
|
||||
if (uuid16 == BLE_ATT_UUID_CHARACTERISTIC) {
|
||||
/* Reached end of characteristic without a match. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -3067,6 +3134,7 @@ static int ble_gatts_remove_clt_cfg(struct ble_gatts_clt_cfg_list *clt_cfgs, uin
|
||||
}
|
||||
|
||||
if (cfg == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -3222,6 +3290,7 @@ ble_gatts_deregister_svc(const ble_uuid_t *uuid) {
|
||||
entry = ble_gatts_find_svc_entry_by_uuid(uuid);
|
||||
if (entry == NULL) {
|
||||
/* no such service */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
rc = 0;
|
||||
@@ -3243,6 +3312,7 @@ ble_gatts_remove_svc_entry(const ble_uuid_t *uuid)
|
||||
}
|
||||
}
|
||||
if (entry == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
STAILQ_REMOVE(&ble_gatts_svc_entries, entry, ble_gatts_svc_entry, next);
|
||||
@@ -3396,6 +3466,7 @@ ble_gatts_svc_set_visibility(uint16_t handle, int visible)
|
||||
}
|
||||
}
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -3436,6 +3507,7 @@ ble_gatts_count_resources(const struct ble_gatt_svc_def *svcs,
|
||||
|
||||
if (!ble_gatts_svc_is_sane(svc)) {
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -3463,6 +3535,7 @@ ble_gatts_count_resources(const struct ble_gatt_svc_def *svcs,
|
||||
|
||||
if (!ble_gatts_chr_is_sane(chr)) {
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -3493,6 +3566,7 @@ ble_gatts_count_resources(const struct ble_gatt_svc_def *svcs,
|
||||
for (d = 0; chr->descriptors[d].uuid != NULL; d++) {
|
||||
if (!ble_gatts_dsc_is_sane(chr->descriptors + d)) {
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -3509,6 +3583,7 @@ ble_gatts_count_resources(const struct ble_gatt_svc_def *svcs,
|
||||
for (pf = 0; chr->cpfd[pf].format != 0; pf++) {
|
||||
if (!ble_gatts_cpfd_is_sane(chr->cpfd + pf)) {
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -3544,6 +3619,7 @@ ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs)
|
||||
|
||||
rc = ble_gatts_count_resources(defs, &res);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3613,6 +3689,7 @@ ble_gatts_reset(void)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_gatts_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -3656,6 +3733,7 @@ ble_gatts_init(void)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_gatts_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -3671,6 +3749,7 @@ ble_gatts_init(void)
|
||||
STATS_HDR(ble_gatts_stats), STATS_SIZE_INIT_PARMS(ble_gatts_stats,
|
||||
STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_gatts_stats), "ble_gatts");
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "console/console.h"
|
||||
#include "nimble/ble.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
static const ble_uuid_t *uuid_ccc =
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "nimble/nimble_npl.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#ifndef MYNEWT
|
||||
#include "nimble/nimble_port.h"
|
||||
#endif
|
||||
@@ -285,6 +286,9 @@ ble_hs_lock_nested(void)
|
||||
#endif
|
||||
|
||||
rc = ble_npl_mutex_pend(&ble_hs_mutex, 0xffffffff);
|
||||
if (rc != 0 && rc != OS_NOT_STARTED) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_HS_DEBUG)
|
||||
counter_lock++;
|
||||
@@ -323,6 +327,9 @@ ble_hs_unlock_nested(void)
|
||||
#endif
|
||||
|
||||
rc = ble_npl_mutex_release(&ble_hs_mutex);
|
||||
if (rc != 0 && rc != OS_NOT_STARTED) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
BLE_HS_DBG_ASSERT_EVAL(rc == 0 || rc == OS_NOT_STARTED);
|
||||
|
||||
}
|
||||
@@ -386,6 +393,7 @@ ble_hs_wakeup_tx_conn(struct ble_hs_conn *conn)
|
||||
* get transmitted next time around.
|
||||
*/
|
||||
STAILQ_INSERT_HEAD(&conn->bhc_tx_q, OS_MBUF_PKTHDR(om), omp_next);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAGAIN);
|
||||
return BLE_HS_EAGAIN;
|
||||
}
|
||||
}
|
||||
@@ -795,6 +803,7 @@ ble_hs_start(void)
|
||||
ble_hs_unlock();
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -813,6 +822,7 @@ ble_hs_start(void)
|
||||
#if MYNEWT_VAL(BLE_GATTS)
|
||||
rc = ble_gatts_start();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -855,6 +865,7 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
|
||||
rc = ble_mqueue_put(&ble_hs_rx_q, ble_hs_evq, om);
|
||||
if (rc != 0) {
|
||||
os_mbuf_free_chain(om);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "nimble/ble.h"
|
||||
#include "host/ble_hs_adv.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(ENC_ADV_DATA)
|
||||
#include "host/ble_ead.h"
|
||||
#endif
|
||||
@@ -65,6 +66,7 @@ ble_hs_adv_set_hdr(uint8_t type, uint8_t data_len, uint8_t max_len,
|
||||
data_len++;
|
||||
rc = os_mbuf_append(om, &data_len, sizeof(data_len));
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -73,6 +75,7 @@ ble_hs_adv_set_hdr(uint8_t type, uint8_t data_len, uint8_t max_len,
|
||||
|
||||
|
||||
if (*dst_len + 2 + data_len > max_len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
@@ -95,6 +98,7 @@ ble_hs_adv_set_flat_mbuf(uint8_t type, int data_len, const void *data,
|
||||
|
||||
rc = ble_hs_adv_set_hdr(type, data_len, max_len, dst, dst_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -113,6 +117,7 @@ ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data,
|
||||
uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
|
||||
{
|
||||
#if !NIMBLE_BLE_ADVERTISE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -130,12 +135,14 @@ ble_hs_adv_set_array_uuid16(uint8_t type, uint8_t num_elems,
|
||||
int i;
|
||||
|
||||
if (num_elems > 127) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
rc = ble_hs_adv_set_hdr(type, num_elems * 2, max_len, dst,
|
||||
dst_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -143,6 +150,7 @@ ble_hs_adv_set_array_uuid16(uint8_t type, uint8_t num_elems,
|
||||
if (om) {
|
||||
rc = ble_uuid_to_mbuf(&elems[i].u, om);
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@@ -165,12 +173,14 @@ ble_hs_adv_set_array_uuid32(uint8_t type, uint8_t num_elems,
|
||||
int i;
|
||||
|
||||
if ((uint16_t)num_elems * 4 > 255) { // Prevent truncation, actual AD field limited by BLE_HS_ADV_MAX_FIELD_SZ
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
rc = ble_hs_adv_set_hdr(type, num_elems * 4, max_len, dst,
|
||||
dst_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -183,6 +193,7 @@ ble_hs_adv_set_array_uuid32(uint8_t type, uint8_t num_elems,
|
||||
uuid_le = htole32(elems[i].value);
|
||||
rc = os_mbuf_append(om, &uuid_le, sizeof(uuid_le));
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@@ -204,12 +215,14 @@ ble_hs_adv_set_array_uuid128(uint8_t type, uint8_t num_elems,
|
||||
int i;
|
||||
|
||||
if (num_elems > 15) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
rc = ble_hs_adv_set_hdr(type, num_elems * 16, max_len, dst,
|
||||
dst_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -217,6 +230,7 @@ ble_hs_adv_set_array_uuid128(uint8_t type, uint8_t num_elems,
|
||||
if (om) {
|
||||
rc = ble_uuid_to_mbuf(&elems[i].u, om);
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@@ -238,12 +252,14 @@ ble_hs_adv_set_array16(uint8_t type, uint8_t num_elems, const uint16_t *elems,
|
||||
int i;
|
||||
|
||||
if (num_elems > 127) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
rc = ble_hs_adv_set_hdr(type, num_elems * sizeof *elems, max_len, dst,
|
||||
dst_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -252,6 +268,7 @@ ble_hs_adv_set_array16(uint8_t type, uint8_t num_elems, const uint16_t *elems,
|
||||
tmp = htole16(elems[i]);
|
||||
rc = os_mbuf_append(om, &tmp, sizeof(tmp));
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
} else {
|
||||
@@ -269,6 +286,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
struct os_mbuf *om)
|
||||
{
|
||||
#if !NIMBLE_BLE_ADVERTISE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -296,6 +314,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
max_len, om);
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -312,6 +331,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->uuids16, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -328,6 +348,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->uuids32, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -344,6 +365,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->uuids128, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -360,6 +382,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->name, dst, &dst_len_local, max_len,
|
||||
om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -373,6 +396,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
if (adv_fields->tx_pwr_lvl == BLE_HS_ADV_TX_PWR_LVL_AUTO) {
|
||||
rc = ble_hs_hci_util_read_adv_tx_pwr(&tx_pwr_lvl);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
} else
|
||||
@@ -384,6 +408,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
rc = ble_hs_adv_set_flat_mbuf(BLE_HS_ADV_TYPE_TX_PWR_LVL, 1,
|
||||
&tx_pwr_lvl, dst, &dst_len_local, max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -396,6 +421,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
max_len, om);
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -407,6 +433,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
&adv_fields->sm_oob_flag, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -419,6 +446,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->slave_itvl_range, dst,
|
||||
&dst_len_local, max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -431,6 +459,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->sol_uuids16, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -441,6 +470,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->sol_uuids128, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -454,6 +484,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->svc_data_uuid16, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -468,6 +499,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->public_tgt_addr, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -483,6 +515,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->random_tgt_addr, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -496,6 +529,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
&adv_fields->appearance, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -506,6 +540,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
&adv_fields->adv_itvl, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -523,6 +558,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
dev_addr_ad, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -533,6 +569,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
&adv_fields->le_role, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -544,6 +581,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->sol_uuids32, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -556,6 +594,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->svc_data_uuid32, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -567,6 +606,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->svc_data_uuid128, dst,
|
||||
&dst_len_local, max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -577,6 +617,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->uri, dst, &dst_len_local, max_len,
|
||||
om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -589,6 +630,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->le_supp_feat, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -600,6 +642,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
&adv_fields->adv_itvl_long, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -613,6 +656,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->enc_adv_data, dst, &dst_len_local,
|
||||
max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -626,6 +670,7 @@ adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
adv_fields->mfg_data,
|
||||
dst, &dst_len_local, max_len, om);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -647,6 +692,7 @@ ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
|
||||
uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
|
||||
{
|
||||
#if !NIMBLE_BLE_ADVERTISE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -658,6 +704,7 @@ ble_hs_adv_set_fields_mbuf(const struct ble_hs_adv_fields *adv_fields,
|
||||
struct os_mbuf *om)
|
||||
{
|
||||
#if !NIMBLE_BLE_ADVERTISE
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
return adv_set_fields(adv_fields, NULL, NULL, 0, om);
|
||||
@@ -674,6 +721,7 @@ ble_hs_adv_parse_uuids16(struct ble_hs_adv_fields *adv_fields,
|
||||
#endif
|
||||
|
||||
if (data_len % 2 != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -688,6 +736,7 @@ ble_hs_adv_parse_uuids16(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
if (uuid_cnt > free_slots) {
|
||||
/* not enough space to append */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
@@ -721,6 +770,7 @@ ble_hs_adv_parse_uuids32(struct ble_hs_adv_fields *adv_fields,
|
||||
#endif
|
||||
|
||||
if (data_len % 4 != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -736,6 +786,7 @@ ble_hs_adv_parse_uuids32(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
if (uuid_cnt > free_slots) {
|
||||
/* not enough space to append */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
/* Append new UUIDs to existing list */
|
||||
@@ -769,6 +820,7 @@ ble_hs_adv_parse_uuids128(struct ble_hs_adv_fields *adv_fields,
|
||||
#endif
|
||||
|
||||
if (data_len % 16 != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -784,6 +836,7 @@ ble_hs_adv_parse_uuids128(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
if (uuid_cnt > free_slots) {
|
||||
/* not enough space to append */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
/* Append new UUIDs to existing list */
|
||||
@@ -816,6 +869,7 @@ ble_hs_adv_uuids_alloc(void)
|
||||
}
|
||||
ble_hs_adv_uuids = nimble_platform_mem_calloc(1, sizeof(*ble_hs_adv_uuids));
|
||||
if (!ble_hs_adv_uuids) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
return 0;
|
||||
@@ -833,15 +887,18 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
int rc;
|
||||
|
||||
if (src_len < 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
*total_len = src[0] + 1;
|
||||
|
||||
if (*total_len < 2) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
if (src_len < *total_len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
@@ -850,12 +907,14 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
data_len = *total_len - 2;
|
||||
|
||||
if (data_len > BLE_HS_ADV_MAX_FIELD_SZ) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case BLE_HS_ADV_TYPE_FLAGS:
|
||||
if (data_len != BLE_HS_ADV_FLAGS_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->flags = *data;
|
||||
@@ -864,6 +923,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_INCOMP_UUIDS16:
|
||||
rc = ble_hs_adv_parse_uuids16(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
adv_fields->uuids16_is_complete = 0;
|
||||
@@ -872,6 +932,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_COMP_UUIDS16:
|
||||
rc = ble_hs_adv_parse_uuids16(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
adv_fields->uuids16_is_complete = 1;
|
||||
@@ -880,6 +941,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_INCOMP_UUIDS32:
|
||||
rc = ble_hs_adv_parse_uuids32(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
adv_fields->uuids32_is_complete = 0;
|
||||
@@ -888,6 +950,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_COMP_UUIDS32:
|
||||
rc = ble_hs_adv_parse_uuids32(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
adv_fields->uuids32_is_complete = 1;
|
||||
@@ -896,6 +959,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_INCOMP_UUIDS128:
|
||||
rc = ble_hs_adv_parse_uuids128(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
adv_fields->uuids128_is_complete = 0;
|
||||
@@ -904,6 +968,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_COMP_UUIDS128:
|
||||
rc = ble_hs_adv_parse_uuids128(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
adv_fields->uuids128_is_complete = 1;
|
||||
@@ -923,6 +988,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_TX_PWR_LVL:
|
||||
if (data_len != BLE_HS_ADV_TX_PWR_LVL_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->tx_pwr_lvl = *data;
|
||||
@@ -932,6 +998,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
#if MYNEWT_VAL(BLE_EXTRA_ADV_FIELDS)
|
||||
case BLE_HS_ADV_TYPE_SEC_MGR_TK_VALUE:
|
||||
if (data_len != 16) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->sm_tk_value = data;
|
||||
@@ -940,6 +1007,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_SEC_MGR_OOB_FLAG:
|
||||
if (data_len != 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->sm_oob_flag = *data;
|
||||
@@ -949,6 +1017,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_SLAVE_ITVL_RANGE:
|
||||
if (data_len != BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->slave_itvl_range = data;
|
||||
@@ -958,6 +1027,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_SOL_UUIDS16:
|
||||
rc = ble_hs_adv_parse_uuids16(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
break;
|
||||
@@ -965,6 +1035,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_SOL_UUIDS128:
|
||||
rc = ble_hs_adv_parse_uuids128(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
break;
|
||||
@@ -972,6 +1043,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_SVC_DATA_UUID16:
|
||||
if (data_len < BLE_HS_ADV_SVC_DATA_UUID16_MIN_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->svc_data_uuid16 = data;
|
||||
@@ -980,6 +1052,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_PUBLIC_TGT_ADDR:
|
||||
if (data_len % BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->public_tgt_addr = data;
|
||||
@@ -990,6 +1063,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
#if MYNEWT_VAL(BLE_EXTRA_ADV_FIELDS)
|
||||
case BLE_HS_ADV_TYPE_RANDOM_TGT_ADDR:
|
||||
if (data_len % BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->random_tgt_addr = data;
|
||||
@@ -1000,6 +1074,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_APPEARANCE:
|
||||
if (data_len != BLE_HS_ADV_APPEARANCE_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->appearance = get_le16(data);
|
||||
@@ -1009,6 +1084,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
#if MYNEWT_VAL(BLE_EXTRA_ADV_FIELDS)
|
||||
case BLE_HS_ADV_TYPE_DEVICE_ADDR:
|
||||
if (data_len != 7) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->device_addr = data;
|
||||
@@ -1017,6 +1093,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_LE_ROLE:
|
||||
if (data_len != 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->le_role = *data;
|
||||
@@ -1026,6 +1103,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_ADV_ITVL:
|
||||
if (data_len != BLE_HS_ADV_ADV_ITVL_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->adv_itvl = get_le16(data);
|
||||
@@ -1034,6 +1112,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_SVC_DATA_UUID32:
|
||||
if (data_len < BLE_HS_ADV_SVC_DATA_UUID32_MIN_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->svc_data_uuid32 = data;
|
||||
@@ -1042,6 +1121,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
|
||||
case BLE_HS_ADV_TYPE_SVC_DATA_UUID128:
|
||||
if (data_len < BLE_HS_ADV_SVC_DATA_UUID128_MIN_LEN) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
adv_fields->svc_data_uuid128 = data;
|
||||
@@ -1057,6 +1137,7 @@ ble_hs_adv_parse_one_field(struct ble_hs_adv_fields *adv_fields,
|
||||
case BLE_HS_ADV_TYPE_SOL_UUIDS32:
|
||||
rc = ble_hs_adv_parse_uuids32(adv_fields, data, data_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
break;
|
||||
@@ -1092,6 +1173,7 @@ ble_hs_adv_parse_fields(struct ble_hs_adv_fields *adv_fields,
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_adv_uuids_alloc() != 0) {
|
||||
ESP_LOGE(TAG, "Failed to allocate BLE adv UUIDs");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -1099,6 +1181,7 @@ ble_hs_adv_parse_fields(struct ble_hs_adv_fields *adv_fields,
|
||||
while (src_len > 0) {
|
||||
rc = ble_hs_adv_parse_one_field(adv_fields, &field_len, src, src_len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1119,6 +1202,7 @@ ble_hs_adv_parse(const uint8_t *data, uint8_t length,
|
||||
field = (const void *) data;
|
||||
|
||||
if (field->length >= length) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1139,6 +1223,7 @@ find_field_func(const struct ble_hs_adv_field *field, void *user_data)
|
||||
struct find_field_data *ffd = user_data;
|
||||
|
||||
if (field->type != ffd->type) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAGAIN);
|
||||
return BLE_HS_EAGAIN;
|
||||
}
|
||||
|
||||
@@ -1159,10 +1244,12 @@ ble_hs_adv_find_field(uint8_t type, const uint8_t *data, uint8_t length,
|
||||
|
||||
rc = ble_hs_adv_parse(data, length, find_field_func, &ffd);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (!ffd.field) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
int
|
||||
ble_hs_atomic_conn_delete(uint16_t conn_handle)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_hs_resolv_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
/** At least three channels required per connection (sig, att, sm). */
|
||||
#define BLE_HS_CONN_MIN_CHANS 3
|
||||
@@ -62,6 +63,7 @@ ble_hs_conn_ensure_ctx(void)
|
||||
|
||||
ble_hs_conn_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_hs_conn_ctx));
|
||||
if (ble_hs_conn_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -155,6 +157,7 @@ int
|
||||
ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
|
||||
{
|
||||
#if !NIMBLE_BLE_CONNECT
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
|
||||
@@ -164,6 +167,7 @@ ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
|
||||
prev = NULL;
|
||||
SLIST_FOREACH(cur, &conn->bhc_channels, next) {
|
||||
if (cur->scid == chan->scid) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EALREADY);
|
||||
return BLE_HS_EALREADY;
|
||||
}
|
||||
if (cur->scid > chan->scid) {
|
||||
@@ -656,6 +660,7 @@ ble_hs_conn_init(void)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
rc = ble_hs_conn_ensure_ctx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -668,6 +673,7 @@ ble_hs_conn_init(void)
|
||||
if (!ble_hs_conn_elem_mem) {
|
||||
nimble_platform_mem_free(ble_hs_conn_ctx);
|
||||
ble_hs_conn_ctx = NULL;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -691,6 +697,7 @@ ble_hs_conn_init(void)
|
||||
}
|
||||
memset(&ble_hs_conn_pool, 0, sizeof(ble_hs_conn_pool));
|
||||
#endif
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
#include "esp_nimble_mem.h"
|
||||
#endif
|
||||
@@ -122,6 +123,7 @@ ble_hs_flow_tx_num_comp_pkts(void)
|
||||
BLE_HCI_OCF_CB_HOST_NUM_COMP_PKTS),
|
||||
buf, sizeof(buf));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -211,6 +213,7 @@ ble_hs_flow_acl_free(struct os_mempool_ext *mpe, void *data, void *arg)
|
||||
/* Free the mbuf back to its pool. */
|
||||
rc = os_memblock_put_from_cb(&mpe->mpe_mp, data);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -295,6 +298,7 @@ ble_hs_flow_startup(void)
|
||||
BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC),
|
||||
&enable_cmd, sizeof(enable_cmd), NULL, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -306,6 +310,9 @@ ble_hs_flow_startup(void)
|
||||
ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_CTLR_BASEBAND,
|
||||
BLE_HCI_OCF_CB_SET_CTLR_TO_HOST_FC),
|
||||
&enable_cmd, sizeof(enable_cmd), NULL, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "nimble/transport.h"
|
||||
#include "bt_common.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if (BT_HCI_LOG_INCLUDED == TRUE)
|
||||
#include "hci_log/bt_hci_log.h"
|
||||
#include "host/ble_hs.h"
|
||||
@@ -386,6 +387,7 @@ int
|
||||
ble_hs_hci_set_buf_sz(uint16_t pktlen, uint16_t max_pkts)
|
||||
{
|
||||
if (pktlen == 0 || max_pkts == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -421,6 +423,7 @@ ble_hs_hci_rx_cmd_complete(const void *data, int len,
|
||||
|
||||
if (len < (int)sizeof(*ev)) {
|
||||
if (len < (int)sizeof(*nop)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -428,6 +431,7 @@ ble_hs_hci_rx_cmd_complete(const void *data, int len,
|
||||
|
||||
opcode = le16toh(nop->opcode);
|
||||
if (opcode != BLE_HCI_OPCODE_NOP) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -463,6 +467,7 @@ ble_hs_hci_rx_cmd_status(const void *data, int len,
|
||||
const struct ble_hci_ev_command_status *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -530,6 +535,9 @@ ble_hs_hci_process_ack(uint16_t expected_opcode,
|
||||
STATS_INC(ble_hs_stats, hci_invalid_ack);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -715,6 +723,7 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
|
||||
#else
|
||||
ble_transport_free(hci_ev);
|
||||
#endif
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
enqueue = (cmd_complete->opcode == BLE_HCI_OPCODE_NOP);
|
||||
@@ -738,6 +747,7 @@ ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg)
|
||||
#else
|
||||
ble_transport_free(hci_ev);
|
||||
#endif
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
enqueue = (cmd_status->opcode == BLE_HCI_OPCODE_NOP);
|
||||
@@ -889,6 +899,7 @@ ble_hs_hci_acl_tx_now(struct ble_hs_conn *conn, struct os_mbuf **om)
|
||||
#endif
|
||||
if (frag == NULL) {
|
||||
*om = txom;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAGAIN);
|
||||
return BLE_HS_EAGAIN;
|
||||
}
|
||||
|
||||
@@ -925,6 +936,7 @@ ble_hs_hci_acl_tx_now(struct ble_hs_conn *conn, struct os_mbuf **om)
|
||||
if (txom != NULL) {
|
||||
/* The controller couldn't accommodate some or all of the packet. */
|
||||
*om = txom;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAGAIN);
|
||||
return BLE_HS_EAGAIN;
|
||||
}
|
||||
|
||||
@@ -961,6 +973,7 @@ ble_hs_hci_acl_tx(struct ble_hs_conn *conn, struct os_mbuf **om)
|
||||
|
||||
/* If this conn is already backed up, don't even try to send. */
|
||||
if (STAILQ_FIRST(&conn->bhc_tx_q) != NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAGAIN);
|
||||
return BLE_HS_EAGAIN;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "nimble/hci_common.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "bt_common.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if (BT_HCI_LOG_INCLUDED == TRUE)
|
||||
#include "hci_log/bt_hci_log.h"
|
||||
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
|
||||
@@ -51,9 +52,11 @@ ble_hs_hci_cmd_transport(struct ble_hci_cmd *cmd)
|
||||
return 0;
|
||||
|
||||
case BLE_ERR_MEM_CAPACITY:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM_EVT);
|
||||
return BLE_HS_ENOMEM_EVT;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -67,6 +70,7 @@ ble_hs_hci_cmd_send(uint16_t opcode, uint8_t len, const void *cmddata)
|
||||
|
||||
cmd = (struct ble_hci_cmd *)ble_transport_alloc_cmd();
|
||||
if (cmd == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM_EVT);
|
||||
return BLE_HS_ENOMEM_EVT;
|
||||
}
|
||||
BLE_HS_DBG_ASSERT(cmd != NULL);
|
||||
@@ -121,10 +125,12 @@ ble_hs_hci_cmd_send_buf(uint16_t opcode, const void *buf, uint8_t buf_len)
|
||||
{
|
||||
switch (ble_hs_sync_state) {
|
||||
case BLE_HS_SYNC_STATE_BAD:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSYNCED);
|
||||
return BLE_HS_ENOTSYNCED;
|
||||
|
||||
case BLE_HS_SYNC_STATE_BRINGUP:
|
||||
if (!ble_hs_is_parent_task()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSYNCED);
|
||||
return BLE_HS_ENOTSYNCED;
|
||||
}
|
||||
break;
|
||||
@@ -134,6 +140,7 @@ ble_hs_hci_cmd_send_buf(uint16_t opcode, const void *buf, uint8_t buf_len)
|
||||
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_hs_resolv_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_ISO)
|
||||
#include "host/ble_hs_iso.h"
|
||||
#endif /* MYNEWT_VAL(BLE_ISO) */
|
||||
@@ -395,6 +396,7 @@ static int ble_hs_hci_ensure_ctx(void)
|
||||
ble_hci_ctx = nimble_platform_mem_calloc (1, sizeof(* ble_hci_ctx));
|
||||
|
||||
if (!ble_hci_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -468,6 +470,7 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
#endif
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -499,6 +502,7 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
*/
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_hci_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -550,6 +554,7 @@ ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
|
||||
#endif
|
||||
rc = ble_hs_atomic_conn_delete(ev->conn_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -597,6 +602,7 @@ ble_hs_hci_evt_encrypt_change(uint8_t event_code, const void *data,
|
||||
const struct ble_hci_ev_enrypt_chg *ev = data;
|
||||
|
||||
if (len != sizeof (*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -612,6 +618,7 @@ ble_hs_hci_evt_hw_error(uint8_t event_code, const void *data, unsigned int len)
|
||||
const struct ble_hci_ev_hw_error *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -628,6 +635,7 @@ ble_hs_hci_evt_enc_key_refresh(uint8_t event_code, const void *data,
|
||||
const struct ble_hci_ev_enc_key_refresh *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -647,10 +655,12 @@ ble_hs_hci_evt_num_completed_pkts(uint8_t event_code, const void *data,
|
||||
int i;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
if (len != sizeof(*ev) + (ev->count * sizeof(ev->completed[0]))) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -692,6 +702,7 @@ ble_hs_hci_evt_vs(uint8_t event_code, const void *data, unsigned int len)
|
||||
const struct ble_hci_ev_vs *ev = data;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -734,6 +745,7 @@ ble_hs_hci_evt_le_meta(uint8_t event_code, const void *data, unsigned int len)
|
||||
ble_hs_hci_evt_le_fn *fn;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -757,15 +769,18 @@ ble_hs_hci_evt_le_enh_conn_complete(uint8_t subevent, const void *data,
|
||||
#if MYNEWT_VAL(BLE_PERIODIC_ADV_WITH_RESPONSES)
|
||||
if (subevent == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) {
|
||||
if (len != sizeof(*ev) - 3) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
} else {
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
#endif
|
||||
@@ -811,6 +826,7 @@ ble_hs_hci_evt_le_enh_conn_complete(uint8_t subevent, const void *data,
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_hci_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -843,6 +859,7 @@ ble_hs_hci_evt_le_conn_complete(uint8_t subevent, const void *data,
|
||||
struct ble_gap_conn_complete evt;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -886,6 +903,7 @@ ble_hs_hci_evt_le_conn_complete(uint8_t subevent, const void *data,
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_hci_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -909,6 +927,7 @@ ble_hs_hci_evt_le_adv_rpt_first_pass(const void *data, unsigned int len)
|
||||
int i;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -917,18 +936,21 @@ ble_hs_hci_evt_le_adv_rpt_first_pass(const void *data, unsigned int len)
|
||||
|
||||
if (ev->num_reports < BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN ||
|
||||
ev->num_reports > BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
for (i = 0; i < ev->num_reports; i++) {
|
||||
/* extra byte for RSSI after adv data */
|
||||
if (len < sizeof(*rpt) + 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
rpt = data;
|
||||
|
||||
if (rpt->data_len > len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -939,6 +961,7 @@ ble_hs_hci_evt_le_adv_rpt_first_pass(const void *data, unsigned int len)
|
||||
|
||||
/* Make sure length was correct */
|
||||
if (len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -957,6 +980,7 @@ ble_hs_hci_evt_le_adv_rpt(uint8_t subevent, const void *data, unsigned int len)
|
||||
/* Validate the event is formatted correctly */
|
||||
rc = ble_hs_hci_evt_le_adv_rpt_first_pass(data, len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1024,6 +1048,7 @@ ble_hs_hci_evt_le_dir_adv_rpt(uint8_t subevent, const void *data, unsigned int l
|
||||
int i;
|
||||
|
||||
if (len < sizeof(*ev) || len != sizeof(*ev) + ev->num_reports * sizeof(ev->reports[0])) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1054,6 +1079,7 @@ ble_hs_hci_evt_le_rd_rem_used_feat_complete(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_rd_rem_used_feat *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1069,6 +1095,7 @@ ble_hs_hci_evt_rd_rem_ver_complete(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_rd_rem_ver_info_cmp *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1139,6 +1166,7 @@ ble_hs_hci_evt_le_cis_estab(uint8_t subevent, const void *data, unsigned int len
|
||||
const struct ble_hci_ev_le_subev_cis_established *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1157,6 +1185,7 @@ ble_hs_hci_evt_le_cis_request(uint8_t subevent, const void *data, unsigned int l
|
||||
const struct ble_hci_ev_le_subev_cis_request *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1175,11 +1204,13 @@ ble_hs_hci_evt_le_create_big_comp(uint8_t subevent, const void *data, unsigned i
|
||||
const struct ble_hci_ev_le_subev_create_big_complete *ev = data;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
if ((len != sizeof(*ev) + ev->num_bis * 2) ||
|
||||
(ev->num_bis > MYNEWT_VAL(BLE_ISO_BIS_PER_BIG))) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1198,6 +1229,7 @@ ble_hs_hci_evt_le_term_big_comp(uint8_t subevent, const void *data, unsigned int
|
||||
const struct ble_hci_ev_le_subev_terminate_big_complete *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1216,11 +1248,13 @@ ble_hs_hci_evt_le_big_sync_estab(uint8_t subevent, const void *data, unsigned in
|
||||
const struct ble_hci_ev_le_subev_big_sync_established *ev = data;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
if ((len != sizeof(*ev) + ev->num_bis * 2) ||
|
||||
(ev->num_bis > MYNEWT_VAL(BLE_ISO_BIS_PER_BIG))) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1239,6 +1273,7 @@ ble_hs_hci_evt_le_big_sync_lost(uint8_t subevent, const void *data, unsigned int
|
||||
const struct ble_hci_ev_le_subev_big_sync_lost *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1257,6 +1292,7 @@ ble_hs_hci_evt_le_biginfo_adv_rpt(uint8_t subevent, const void *data, unsigned i
|
||||
const struct ble_hci_ev_le_subev_biginfo_adv_report *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1276,6 +1312,7 @@ ble_hs_hci_evt_le_cis_estab_v2(uint8_t subevent, const void *data, unsigned int
|
||||
const struct ble_hci_ev_le_subev_cis_established_v2 *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1298,6 +1335,7 @@ ble_hs_hci_evt_le_ext_adv_rpt_first_pass(const void *data, unsigned int len)
|
||||
int i;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1306,17 +1344,20 @@ ble_hs_hci_evt_le_ext_adv_rpt_first_pass(const void *data, unsigned int len)
|
||||
|
||||
if (ev->num_reports < BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN ||
|
||||
ev->num_reports > BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
for (i = 0; i < ev->num_reports; i++) {
|
||||
if (len < sizeof(*report)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
report = data;
|
||||
|
||||
if (report->data_len > len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1326,6 +1367,7 @@ ble_hs_hci_evt_le_ext_adv_rpt_first_pass(const void *data, unsigned int len)
|
||||
|
||||
/* Make sure length was correct */
|
||||
if (len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1348,6 +1390,7 @@ ble_hs_hci_evt_le_ext_adv_rpt(uint8_t subevent, const void *data,
|
||||
|
||||
rc = ble_hs_hci_evt_le_ext_adv_rpt_first_pass(data, len);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1409,6 +1452,7 @@ ble_hs_hci_evt_le_periodic_adv_sync_estab(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_periodic_adv_sync_estab *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1426,6 +1470,7 @@ ble_hs_hci_evt_le_periodic_adv_rpt(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_periodic_adv_rpt *ev = data;
|
||||
|
||||
if (len < sizeof(*ev) || len != (sizeof(*ev) + ev->data_len)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1443,6 +1488,7 @@ ble_hs_hci_evt_le_periodic_adv_sync_lost(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_periodic_adv_sync_lost *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1460,6 +1506,7 @@ ble_hs_hci_evt_le_pathloss_threshold(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_path_loss_threshold *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1474,6 +1521,7 @@ ble_hs_hci_evt_le_transmit_power_report(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_transmit_power_report *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1491,6 +1539,7 @@ ble_hs_hci_evt_le_periodic_adv_sync_transfer(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_periodic_adv_sync_transfer *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1509,6 +1558,7 @@ ble_hs_hci_evt_le_biginfo_adv_report(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_biginfo_adv_report *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1527,6 +1577,7 @@ ble_hs_hci_evt_le_scan_timeout(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_scan_timeout *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1545,6 +1596,7 @@ ble_hs_hci_evt_le_adv_set_terminated(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_adv_set_terminated *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1552,6 +1604,7 @@ ble_hs_hci_evt_le_adv_set_terminated(uint8_t subevent, const void *data,
|
||||
* 0-BLE_ADV_INSTANCES range only
|
||||
*/
|
||||
if (ev->adv_handle >= BLE_ADV_INSTANCES) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1559,6 +1612,7 @@ ble_hs_hci_evt_le_adv_set_terminated(uint8_t subevent, const void *data,
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_hci_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -1582,6 +1636,7 @@ ble_hs_hci_evt_le_scan_req_rcvd(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_scan_req_rcvd *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1589,6 +1644,7 @@ ble_hs_hci_evt_le_scan_req_rcvd(uint8_t subevent, const void *data,
|
||||
* 0-BLE_ADV_INSTANCES range only
|
||||
*/
|
||||
if (ev->adv_handle >= BLE_ADV_INSTANCES) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1607,6 +1663,7 @@ ble_hs_hci_evt_le_subrate_change(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_subrate_change *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1624,10 +1681,12 @@ ble_hs_hci_evt_le_connless_iq_report(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_connless_iq_rpt *ev = data;
|
||||
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
if (len < sizeof(*ev) + (unsigned int)ev->sample_count * 2) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
ble_gap_rx_connless_iq_report(ev);
|
||||
@@ -1641,10 +1700,12 @@ ble_hs_hci_evt_le_conn_iq_report(uint8_t subevent, const void *data,
|
||||
{
|
||||
const struct ble_hci_ev_le_subev_conn_iq_rpt *ev = data;
|
||||
if (len < sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
if (len < sizeof(*ev) + ev->sample_count * 2) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1660,6 +1721,7 @@ ble_hs_hci_evt_le_cte_req_failed(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_cte_req_failed *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1677,6 +1739,7 @@ ble_hs_hci_evt_le_periodic_adv_subev_data_req(uint8_t subevent, const void *data
|
||||
const struct ble_hci_ev_le_subev_periodic_adv_subev_data_req *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1699,21 +1762,25 @@ ble_hs_hci_evt_le_periodic_adv_subev_resp_rep(uint8_t subevent, const void *data
|
||||
uint32_t size;
|
||||
|
||||
if (len < 5) { // minimum size for fixed fields
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
num_responses = ev_data[4]; // ev->num_responses
|
||||
offset = 5;
|
||||
for (uint8_t i = 0; i < num_responses; i++) {
|
||||
if (offset + 6 > len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
uint8_t data_length = ev_data[offset + 5]; // data_length field position
|
||||
if (offset + 6 + data_length > len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
offset += 6 + data_length;
|
||||
}
|
||||
if (offset != len) { // exact match
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1723,6 +1790,7 @@ ble_hs_hci_evt_le_periodic_adv_subev_resp_rep(uint8_t subevent, const void *data
|
||||
size += sizeof(struct periodic_adv_response) + ev->responses[i].data_length;
|
||||
}
|
||||
if (len < size) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1736,6 +1804,7 @@ ble_hs_hci_evt_le_periodic_adv_subev_resp_rep(uint8_t subevent, const void *data
|
||||
for (uint8_t i = 0; i < ev->num_responses; i++) {
|
||||
response = data;
|
||||
if (len < sizeof(*response) + response->data_length) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1765,6 +1834,7 @@ ble_hs_hci_evt_le_conn_upd_complete(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_conn_upd_complete *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1790,6 +1860,7 @@ ble_hs_hci_evt_le_lt_key_req(uint8_t subevent, const void *data, unsigned int le
|
||||
const struct ble_hci_ev_le_subev_lt_key_req *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1804,6 +1875,7 @@ ble_hs_hci_evt_le_conn_parm_req(uint8_t subevent, const void *data, unsigned int
|
||||
const struct ble_hci_ev_le_subev_rem_conn_param_req *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1829,6 +1901,7 @@ ble_hs_hci_evt_le_phy_update_complete(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_phy_update_complete *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1844,6 +1917,7 @@ ble_hs_hci_evt_le_data_len_change(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_data_len_chg *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1860,6 +1934,7 @@ ble_hs_hci_evt_le_rd_all_rem_feat(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_rd_all_rem_feat *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1911,6 +1986,7 @@ ble_hci_ev_le_subev_monitor_adv_report(uint8_t subevent, const void *data,
|
||||
const struct ble_hci_ev_le_subev_monitor_adv_report *ev = data;
|
||||
|
||||
if (len != sizeof(*ev)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1995,6 +2071,7 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
|
||||
rc = ble_hs_hci_util_data_hdr_strip(om, &hci_hdr);
|
||||
if (rc != 0) {
|
||||
os_mbuf_free_chain(om);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2012,6 +2089,7 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
|
||||
|
||||
if (hci_hdr.hdh_len != OS_MBUF_PKTHDR(om)->omp_len) {
|
||||
os_mbuf_free_chain(om);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "nimble/hci_common.h"
|
||||
#include "host/ble_hs_hci.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
@@ -45,6 +46,7 @@ ble_hs_hci_util_read_adv_tx_pwr(int8_t *out_tx_pwr)
|
||||
int rc;
|
||||
|
||||
if (out_tx_pwr == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -52,6 +54,7 @@ ble_hs_hci_util_read_adv_tx_pwr(int8_t *out_tx_pwr)
|
||||
BLE_HCI_OCF_LE_RD_ADV_CHAN_TXPWR),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -74,6 +77,7 @@ ble_hs_hci_util_rand(void *dst, int len)
|
||||
int rc;
|
||||
|
||||
if (len <= 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -82,6 +86,7 @@ ble_hs_hci_util_rand(void *dst, int len)
|
||||
rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_RAND),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -104,6 +109,7 @@ ble_hs_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi)
|
||||
int rc;
|
||||
|
||||
if (out_rssi == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -113,10 +119,12 @@ ble_hs_hci_util_read_rssi(uint16_t conn_handle, int8_t *out_rssi)
|
||||
BLE_HCI_OCF_RD_RSSI), &cmd, sizeof(cmd),
|
||||
&rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (le16toh(rsp.handle) != conn_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -131,6 +139,7 @@ ble_hs_hci_util_set_random_addr(const uint8_t *addr)
|
||||
struct ble_hci_le_set_rand_addr_cp cmd;
|
||||
|
||||
if (addr == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -151,11 +160,13 @@ ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
|
||||
|
||||
if (tx_octets < BLE_HCI_SET_DATALEN_TX_OCTETS_MIN ||
|
||||
tx_octets > BLE_HCI_SET_DATALEN_TX_OCTETS_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (tx_time < BLE_HCI_SET_DATALEN_TX_TIME_MIN ||
|
||||
tx_time > BLE_HCI_SET_DATALEN_TX_TIME_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -167,10 +178,12 @@ ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
|
||||
BLE_HCI_OCF_LE_SET_DATA_LEN),
|
||||
&cmd, sizeof(cmd), &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (le16toh(rsp.conn_handle) != conn_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -185,6 +198,7 @@ ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
|
||||
int rc;
|
||||
|
||||
if (out_sugg_max_tx_octets == NULL || out_sugg_max_tx_time == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -192,6 +206,7 @@ ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
|
||||
BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -221,11 +236,13 @@ ble_hs_hci_util_write_sugg_def_data_len(uint16_t sugg_max_tx_octets,
|
||||
|
||||
if (sugg_max_tx_octets < BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN ||
|
||||
sugg_max_tx_octets > BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (sugg_max_tx_time < BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN ||
|
||||
sugg_max_tx_time > BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -245,6 +262,7 @@ ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
|
||||
|
||||
rc = os_mbuf_copydata(om, 0, BLE_HCI_DATA_HDR_SZ, out_hdr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -265,6 +283,7 @@ ble_hs_hci_read_chan_map(uint16_t conn_handle, uint8_t *out_chan_map)
|
||||
int rc;
|
||||
|
||||
if (out_chan_map == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -274,10 +293,12 @@ ble_hs_hci_read_chan_map(uint16_t conn_handle, uint8_t *out_chan_map)
|
||||
BLE_HCI_OCF_LE_RD_CHAN_MAP),
|
||||
&cmd, sizeof(cmd), &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (le16toh(rsp.conn_handle) != conn_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -292,6 +313,7 @@ ble_hs_hci_set_chan_class(const uint8_t *chan_map)
|
||||
struct ble_hci_le_set_host_chan_class_cp cmd;
|
||||
|
||||
if (chan_map == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -396,6 +418,7 @@ ble_hs_hci_set_host_feature(uint8_t bit_num, uint8_t bit_val)
|
||||
struct ble_hci_le_set_host_feature_cp cmd;
|
||||
|
||||
if (bit_val > 0x01) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -416,6 +439,7 @@ ble_hs_hci_rd_all_local_supp_features(uint8_t* status, uint8_t* max_page,
|
||||
int rc;
|
||||
|
||||
if (status == NULL || max_page == NULL || le_features == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -424,6 +448,7 @@ ble_hs_hci_rd_all_local_supp_features(uint8_t* status, uint8_t* max_page,
|
||||
&rsp, sizeof(rsp));
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -441,6 +466,7 @@ ble_hs_hci_rd_all_remote_features(uint16_t conn_handle, uint8_t page_requested)
|
||||
struct ble_hci_le_rd_all_remote_feat_cp cmd;
|
||||
|
||||
if (page_requested > 0x0A) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -460,6 +486,7 @@ ble_hs_hci_add_monitor_adv_list(uint8_t addr_type, uint8_t *addr, int8_t rssi_lo
|
||||
struct ble_hci_le_add_monitor_adv_list_cp cmd;
|
||||
|
||||
if (addr == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -480,6 +507,7 @@ ble_hs_hci_rmv_monitor_adv_list(uint8_t addr_type, uint8_t *addr)
|
||||
struct ble_hci_le_rmv_monitor_adv_list_cp cmd;
|
||||
|
||||
if (addr == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -506,6 +534,7 @@ ble_hs_hci_read_monitor_adv_list_size(uint8_t *out_number)
|
||||
struct ble_hci_le_rd_monitor_adv_list_size_rp rsp;
|
||||
|
||||
if (out_number == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -514,6 +543,7 @@ ble_hs_hci_read_monitor_adv_list_size(uint8_t *out_number)
|
||||
&rsp, sizeof(rsp));
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <string.h>
|
||||
#include "host/ble_hs_id.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
|
||||
#include "ble_hs_resolv_priv.h"
|
||||
#endif
|
||||
@@ -54,6 +55,7 @@ ble_hs_id_ensure_ctx(void)
|
||||
ble_hs_id_ctx = nimble_platform_mem_calloc(1, sizeof(* ble_hs_id_ctx));
|
||||
|
||||
if (!ble_hs_id_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -88,6 +90,7 @@ ble_hs_id_set_pub(const uint8_t *pub_addr)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_id_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -106,6 +109,7 @@ ble_hs_id_gen_rnd(int nrpa, ble_addr_t *out_addr)
|
||||
|
||||
rc = ble_hs_hci_util_rand(out_addr->val, 6);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -135,12 +139,14 @@ ble_hs_id_set_nrpa_rnd(void)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_id_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
|
||||
rc = ble_hs_id_gen_rnd(1, &nrpa_addr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -180,6 +186,7 @@ ble_hs_id_set_pseudo_rnd(const uint8_t *rnd_addr)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_id_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -223,6 +230,7 @@ ble_hs_id_set_rnd(const uint8_t *rnd_addr)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_id_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
#endif
|
||||
@@ -308,10 +316,12 @@ ble_hs_id_addr(uint8_t id_addr_type, const uint8_t **out_id_addr,
|
||||
break;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (memcmp(id_addr, ble_hs_misc_null_addr, 6) == 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOADDR);
|
||||
return BLE_HS_ENOADDR;
|
||||
}
|
||||
|
||||
@@ -356,6 +366,7 @@ ble_hs_id_addr_type_usable(uint8_t own_addr_type)
|
||||
case BLE_OWN_ADDR_RANDOM:
|
||||
rc = ble_hs_id_addr(own_addr_type, NULL, NULL);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
break;
|
||||
@@ -365,14 +376,17 @@ ble_hs_id_addr_type_usable(uint8_t own_addr_type)
|
||||
id_addr_type = ble_hs_misc_own_addr_type_to_id(own_addr_type);
|
||||
rc = ble_hs_id_addr(id_addr_type, NULL, &nrpa);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if (nrpa) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOADDR);
|
||||
return BLE_HS_ENOADDR;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -386,6 +400,7 @@ ble_hs_id_use_addr(uint8_t own_addr_type)
|
||||
|
||||
rc = ble_hs_id_addr_type_usable(own_addr_type);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -395,9 +410,11 @@ ble_hs_id_use_addr(uint8_t own_addr_type)
|
||||
#if MYNEWT_VAL(BLE_HS_PVCY)
|
||||
rc = ble_hs_pvcy_ensure_started();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -17,40 +17,80 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "os/os.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
struct log ble_hs_log;
|
||||
|
||||
#define BLE_HS_LOG_HEX_BYTES_PER_LINE 10
|
||||
|
||||
static void
|
||||
ble_hs_log_debug_hex_chunk(const uint8_t *bytes, int len)
|
||||
{
|
||||
char hex_str[31] = {0}; // 10 bytes * 3 chars ("FF ") + 1 null = 31
|
||||
int offset = 0;
|
||||
|
||||
if (len <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (len > BLE_HS_LOG_HEX_BYTES_PER_LINE) {
|
||||
len = BLE_HS_LOG_HEX_BYTES_PER_LINE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
offset += snprintf(hex_str + offset, sizeof(hex_str) - offset, "%02x ", bytes[i]);
|
||||
}
|
||||
|
||||
BLE_HS_LOG(DEBUG, "%s", hex_str);
|
||||
}
|
||||
|
||||
void
|
||||
ble_hs_log_mbuf(const struct os_mbuf *om)
|
||||
{
|
||||
uint8_t u8;
|
||||
int i;
|
||||
uint8_t buf[BLE_HS_LOG_HEX_BYTES_PER_LINE];
|
||||
int total_len;
|
||||
int offset;
|
||||
int chunk_len;
|
||||
|
||||
if (om == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < OS_MBUF_PKTLEN(om); i++) {
|
||||
os_mbuf_copydata(om, i, 1, &u8);
|
||||
BLE_HS_LOG(DEBUG, "0x%02x ", u8);
|
||||
total_len = OS_MBUF_PKTLEN(om);
|
||||
|
||||
for (offset = 0; offset < total_len; offset += BLE_HS_LOG_HEX_BYTES_PER_LINE) {
|
||||
chunk_len = total_len - offset;
|
||||
if (chunk_len > BLE_HS_LOG_HEX_BYTES_PER_LINE) {
|
||||
chunk_len = BLE_HS_LOG_HEX_BYTES_PER_LINE;
|
||||
}
|
||||
|
||||
os_mbuf_copydata(om, offset, chunk_len, buf);
|
||||
ble_hs_log_debug_hex_chunk(buf, chunk_len);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ble_hs_log_flat_buf(const void *data, int len)
|
||||
{
|
||||
int offset;
|
||||
int chunk_len;
|
||||
const uint8_t *u8ptr;
|
||||
int i;
|
||||
|
||||
if (data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
u8ptr = data;
|
||||
for (i = 0; i < len; i++) {
|
||||
BLE_HS_LOG(DEBUG, "0x%02x ", u8ptr[i]);
|
||||
for (offset = 0; offset < len; offset += BLE_HS_LOG_HEX_BYTES_PER_LINE) {
|
||||
chunk_len = len - offset;
|
||||
if (chunk_len > BLE_HS_LOG_HEX_BYTES_PER_LINE) {
|
||||
chunk_len = BLE_HS_LOG_HEX_BYTES_PER_LINE;
|
||||
}
|
||||
|
||||
ble_hs_log_debug_hex_chunk(u8ptr + offset, chunk_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_hs_mbuf.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
/**
|
||||
* Allocates an mbuf for use by the nimble host.
|
||||
@@ -151,6 +152,7 @@ ble_hs_mbuf_to_flat(const struct os_mbuf *om, void *flat, uint16_t max_len,
|
||||
int rc;
|
||||
|
||||
if (om == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -162,6 +164,7 @@ ble_hs_mbuf_to_flat(const struct os_mbuf *om, void *flat, uint16_t max_len,
|
||||
|
||||
rc = os_mbuf_copydata(om, 0, copy_len, flat);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -181,15 +184,18 @@ int
|
||||
ble_hs_mbuf_pullup_base(struct os_mbuf **om, int base_len)
|
||||
{
|
||||
if (base_len <= 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (OS_MBUF_PKTLEN(*om) < base_len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
*om = os_mbuf_pullup(*om, base_len);
|
||||
if (*om == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <assert.h>
|
||||
#include "os/os.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
int
|
||||
ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
|
||||
@@ -64,6 +65,7 @@ ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
|
||||
|
||||
rc = ble_hs_misc_conn_chan_find(conn_handle, cid, &conn, &chan);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
int
|
||||
ble_mqueue_init(struct ble_mqueue *mq, ble_npl_event_fn *ev_fn, void *ev_arg)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "os/os.h"
|
||||
#include "host/ble_hs_id.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_PERIODIC_ADV)
|
||||
static SLIST_HEAD(, ble_hs_periodic_sync) g_ble_hs_periodic_sync_handles;
|
||||
@@ -228,6 +229,7 @@ ble_hs_periodic_sync_init(void)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
rc = ble_hs_periodic_sync_ensure_ctx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -238,6 +240,7 @@ ble_hs_periodic_sync_init(void)
|
||||
sizeof(struct ble_hs_periodic_sync), NULL,
|
||||
"ble_hs_periodic_disc_pool");
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
SLIST_INIT(&g_ble_hs_periodic_sync_handles);
|
||||
@@ -252,6 +255,7 @@ ble_hs_periodic_sync_init(void)
|
||||
sizeof(os_membuf_t));
|
||||
}
|
||||
if (!ble_hs_psync_elem_mem) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -273,6 +277,7 @@ ble_hs_periodic_sync_init(void)
|
||||
nimble_platform_mem_free(ble_hs_periodic_ctx);
|
||||
ble_hs_periodic_ctx = NULL;
|
||||
}
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -306,6 +311,7 @@ ble_hs_periodic_sync_init(void)
|
||||
ble_hs_psync_elem_mem = NULL;
|
||||
}
|
||||
#endif
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_hs_resolv_priv.h"
|
||||
#include "host/ble_hs_pvcy.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_HS_PVCY)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
@@ -79,6 +80,7 @@ ble_hs_pvcy_set_addr_timeout(uint16_t timeout)
|
||||
struct ble_hci_le_set_rpa_tmo_cp cmd;
|
||||
|
||||
if (timeout == 0 || timeout > BLE_MAX_RPA_TIMEOUT_VAL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ERR_INV_HCI_CMD_PARMS);
|
||||
return BLE_ERR_INV_HCI_CMD_PARMS;
|
||||
}
|
||||
|
||||
@@ -94,6 +96,7 @@ int ble_hs_set_rpa_timeout(uint16_t timeout)
|
||||
{
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_pvcy_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -183,6 +186,7 @@ ble_hs_pvcy_add_entry_hci(const uint8_t *addr, uint8_t addr_type,
|
||||
BLE_HS_DBG_ASSERT(irk != NULL);
|
||||
|
||||
if (addr_type > BLE_ADDR_RANDOM) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ERR_INV_HCI_CMD_PARMS);
|
||||
return BLE_ERR_INV_HCI_CMD_PARMS;
|
||||
}
|
||||
|
||||
@@ -196,6 +200,7 @@ ble_hs_pvcy_add_entry_hci(const uint8_t *addr, uint8_t addr_type,
|
||||
rc = ble_hs_resolv_list_add((uint8_t *) &cmd);
|
||||
ble_hs_unlock_nested();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -206,6 +211,7 @@ ble_hs_pvcy_add_entry_hci(const uint8_t *addr, uint8_t addr_type,
|
||||
BLE_HCI_OCF_LE_ADD_RESOLV_LIST),
|
||||
&cmd, sizeof(cmd), NULL, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -218,6 +224,7 @@ ble_hs_pvcy_add_entry_hci(const uint8_t *addr, uint8_t addr_type,
|
||||
memcpy(peer_addr.val, addr, sizeof peer_addr.val);
|
||||
rc = ble_hs_pvcy_set_mode(&peer_addr, BLE_GAP_PRIVATE_MODE_DEVICE);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -253,6 +260,9 @@ ble_hs_pvcy_add_entry(const uint8_t *addr, uint8_t addr_type,
|
||||
STATS_INC(ble_hs_stats, pvcy_add_entry_fail);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -264,6 +274,7 @@ ble_hs_pvcy_ensure_started(void)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_pvcy_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -288,6 +299,7 @@ ble_hs_pvcy_ensure_started(void)
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -387,6 +399,7 @@ ble_hs_pvcy_set_our_irk(const uint8_t *irk)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_pvcy_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
@@ -418,16 +431,19 @@ ble_hs_pvcy_set_our_irk(const uint8_t *irk)
|
||||
#else
|
||||
rc = ble_hs_pvcy_set_resolve_enabled(0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_hs_pvcy_clear_entries();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_hs_pvcy_set_resolve_enabled(1);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -445,6 +461,7 @@ ble_hs_pvcy_set_our_irk(const uint8_t *irk)
|
||||
memset(tmp_addr, 0, 6);
|
||||
rc = ble_hs_pvcy_add_entry(tmp_addr, 0, zero_irk);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -459,11 +476,13 @@ ble_hs_pvcy_our_irk(const uint8_t **out_irk)
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_hs_pvcy_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (out_irk == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -477,6 +496,7 @@ ble_hs_pvcy_set_mode(const ble_addr_t *addr, uint8_t priv_mode)
|
||||
struct ble_hci_le_set_privacy_mode_cp cmd;
|
||||
|
||||
if (addr == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -513,6 +533,7 @@ ble_hs_pvcy_rpa_config(uint8_t enable)
|
||||
if (enable != NIMBLE_HOST_DISABLE_PRIVACY) {
|
||||
rc = ble_hs_pvcy_ensure_started();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -547,6 +568,7 @@ ble_hs_pvcy_rpa_ah(const uint8_t irk[16], const uint8_t prand[3], uint8_t out[3]
|
||||
|
||||
rc = ble_sm_alg_encrypt(irk, plaintext, ciphertext);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_HOST_BASED_PRIVACY)
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -97,6 +98,7 @@ ble_rpa_remove_peer_dev_rec(struct ble_hs_dev_records *p_dev_rec)
|
||||
}
|
||||
|
||||
if (i >= ble_store_num_peer_dev_rec) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -237,6 +239,7 @@ ble_rpa_resolv_add_peer_rec(uint8_t *peer_addr)
|
||||
BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
|
||||
|
||||
if (ble_store_num_peer_dev_rec >= BLE_RESOLV_LIST_SIZE) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
p_dev_rec = &peer_dev_rec[ble_store_num_peer_dev_rec];
|
||||
@@ -373,6 +376,7 @@ ble_hs_rand_prand_get(uint8_t *prand)
|
||||
/* Get 24 bits of random data */
|
||||
rc = ble_hs_hci_util_rand(prand, 3);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -591,6 +595,7 @@ ble_hs_resolv_list_add(uint8_t *cmdbuf)
|
||||
|
||||
/* Check if we have any open entries */
|
||||
if (g_ble_hs_resolv_data.rl_cnt >= BLE_RESOLV_LIST_SIZE) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -598,6 +603,7 @@ ble_hs_resolv_list_add(uint8_t *cmdbuf)
|
||||
ident_addr = cmd->peer_id_addr;
|
||||
|
||||
if (ble_hs_is_on_resolv_list((uint8_t *)ident_addr, addr_type)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -757,11 +763,13 @@ ble_hs_resolv_set_rpa_tmo(uint16_t tmo_secs)
|
||||
* operations. Max RPA_TIMEOUT is ~11.5HRS (Spec v4.2, Vol 2, Part E,
|
||||
* section 7.8.45) */
|
||||
if (!((tmo_secs > 0) && (tmo_secs <= BLE_MAX_RPA_TIMEOUT_VAL))) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
ticks = ble_npl_time_ms_to_ticks32(tmo_secs * 1000);
|
||||
if (ticks > INT32_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -819,6 +827,7 @@ ble_hs_resolv_rpa(uint8_t *rpa, uint8_t *irk)
|
||||
struct ble_encryption_block ecb = {0};
|
||||
|
||||
if (!(is_irk_nonzero(irk))) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -834,6 +843,7 @@ ble_hs_resolv_rpa(uint8_t *rpa, uint8_t *irk)
|
||||
/* Send the data to ble_sm_alg_encrypt in little-endian style */
|
||||
rc = ble_sm_alg_encrypt(ecb.key, ecb.plain_text, ecb.cipher_text);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
swap_in_place(ecb.cipher_text, 16);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "os/mynewt.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
static struct ble_hs_stop_listener ble_hs_shutdown_stop_listener;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/ble_hs_hci.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_ISO)
|
||||
#include "host/ble_hs_iso.h"
|
||||
#endif /* MYNEWT_VAL(BLE_ISO) */
|
||||
@@ -37,6 +38,7 @@ ble_hs_startup_read_sup_f_tx(void)
|
||||
BLE_HCI_OCF_IP_RD_LOC_SUPP_FEAT),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -62,6 +64,7 @@ ble_hs_startup_read_local_ver_tx(void)
|
||||
BLE_HCI_OCF_IP_RD_LOCAL_VER),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -82,6 +85,7 @@ ble_hs_startup_read_sup_cmd_tx(void)
|
||||
BLE_HCI_OCF_IP_RD_LOC_SUPP_CMD),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -101,6 +105,7 @@ ble_hs_startup_le_read_sup_f_tx(void)
|
||||
BLE_HCI_OCF_LE_RD_LOC_SUPP_FEAT),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -122,6 +127,7 @@ ble_hs_startup_le_read_buf_sz_v2_tx(uint16_t *out_acl_pktlen, uint8_t *out_max_a
|
||||
BLE_HCI_OCF_LE_RD_BUF_SIZE_V2), NULL, 0,
|
||||
&rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -147,6 +153,7 @@ ble_hs_startup_le_read_buf_sz_tx(uint16_t *out_pktlen, uint8_t *out_max_pkts)
|
||||
BLE_HCI_OCF_LE_RD_BUF_SIZE), NULL, 0,
|
||||
&rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -167,6 +174,7 @@ ble_hs_startup_read_buf_sz_tx(uint16_t *out_pktlen, uint16_t *out_max_pkts)
|
||||
BLE_HCI_OCF_IP_RD_BUF_SIZE), NULL, 0,
|
||||
&rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -195,6 +203,7 @@ ble_hs_startup_read_buf_sz(void)
|
||||
rc = ble_hs_startup_le_read_buf_sz_tx(&le_pktlen, &le_max_pkts);
|
||||
#endif /* MYNEWT_VAL(BLE_ISO) */
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -204,12 +213,14 @@ ble_hs_startup_read_buf_sz(void)
|
||||
} else {
|
||||
rc = ble_hs_startup_read_buf_sz_tx(&pktlen, &max_pkts);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
rc = ble_hs_hci_set_buf_sz(pktlen, max_pkts);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -218,6 +229,7 @@ ble_hs_startup_read_buf_sz(void)
|
||||
rc = ble_hs_hci_set_iso_buf_sz(iso_pktlen, iso_max_pkts);
|
||||
ble_hs_unlock();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif /* MYNEWT_VAL(BLE_ISO) */
|
||||
@@ -236,11 +248,13 @@ ble_hs_startup_read_bd_addr(void)
|
||||
BLE_HCI_OCF_IP_RD_BD_ADDR),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_hs_id_set_pub(rsp.addr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
@@ -434,6 +448,7 @@ ble_hs_startup_le_set_evmask_tx(void)
|
||||
BLE_HCI_OCF_LE_SET_EVENT_MASK),
|
||||
&cmd, sizeof(cmd), NULL, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -468,6 +483,7 @@ ble_hs_startup_set_evmask_tx(void)
|
||||
BLE_HCI_OCF_CB_SET_EVENT_MASK),
|
||||
&cmd, sizeof(cmd), NULL, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -481,6 +497,7 @@ ble_hs_startup_set_evmask_tx(void)
|
||||
BLE_HCI_OCF_CB_SET_EVENT_MASK2),
|
||||
&cmd2, sizeof(cmd2), NULL, 0);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -505,17 +522,20 @@ ble_hs_startup_go(void)
|
||||
|
||||
rc = ble_hs_startup_reset_tx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_hs_startup_read_local_ver_tx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Read local supported commands. */
|
||||
rc = ble_hs_startup_read_sup_cmd_tx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -528,34 +548,40 @@ ble_hs_startup_go(void)
|
||||
|
||||
rc = ble_hs_startup_read_sup_f_tx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
rc = ble_hs_startup_set_evmask_tx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_hs_startup_le_set_evmask_tx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
|
||||
rc = ble_hs_startup_read_buf_sz();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
rc = ble_hs_startup_le_read_sup_f_tx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_hs_startup_read_bd_addr();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_stop.h"
|
||||
#include "nimble/nimble_npl.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#ifndef MYNEWT
|
||||
#include "nimble/nimble_port.h"
|
||||
#endif
|
||||
@@ -126,6 +127,9 @@ ble_hs_stop_terminate_all_periodic_sync(void)
|
||||
if (rc != 0 && rc != BLE_HS_ENOTCONN) {
|
||||
BLE_HS_LOG(ERROR, "failed to terminate periodic sync=0x%04x, rc=%d\n",
|
||||
sync_handle, rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -239,14 +243,17 @@ ble_hs_stop_begin(struct ble_hs_stop_listener *listener,
|
||||
if (listener != NULL) {
|
||||
ble_hs_stop_register_listener(listener, fn, arg);
|
||||
}
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBUSY);
|
||||
return BLE_HS_EBUSY;
|
||||
|
||||
case BLE_HS_ENABLED_STATE_OFF:
|
||||
/* Host already stopped. */
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EALREADY);
|
||||
return BLE_HS_EALREADY;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -269,6 +276,9 @@ ble_hs_stop(struct ble_hs_stop_listener *listener,
|
||||
return 0;
|
||||
|
||||
default:
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -281,6 +291,9 @@ ble_hs_stop(struct ble_hs_stop_listener *listener,
|
||||
rc = ble_hs_stop_terminate_all_periodic_sync();
|
||||
if (rc != 0) {
|
||||
ble_hs_stop_done(rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -289,6 +302,9 @@ ble_hs_stop(struct ble_hs_stop_listener *listener,
|
||||
ble_hs_stop_gap_event, NULL);
|
||||
if (rc != 0) {
|
||||
ble_hs_stop_done(rc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "host/ble_hs_adv.h"
|
||||
#include "host/ble_ibeacon.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#define BLE_IBEACON_MFG_DATA_SIZE 25
|
||||
|
||||
@@ -48,9 +49,11 @@ ble_ibeacon_set_adv_data(const void *uuid128, uint16_t major,
|
||||
|
||||
/* Validate inputs before any buffer writes */
|
||||
if (uuid128 == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
if (measured_power < -126 || measured_power > 20) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_l2cap_coc_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
_Static_assert(sizeof (struct ble_l2cap_hdr) == BLE_L2CAP_HDR_SZ,
|
||||
@@ -59,6 +60,7 @@ ble_l2cap_ensure_ctx(void)
|
||||
|
||||
ble_l2cap_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_l2cap_ctx));
|
||||
if (ble_l2cap_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -144,6 +146,7 @@ ble_l2cap_parse_hdr(struct os_mbuf *om, struct ble_l2cap_hdr *hdr)
|
||||
|
||||
rc = os_mbuf_copydata(om, 0, sizeof(*hdr), hdr);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EMSGSIZE);
|
||||
return BLE_HS_EMSGSIZE;
|
||||
}
|
||||
|
||||
@@ -199,6 +202,7 @@ int
|
||||
ble_l2cap_get_chan_info(struct ble_l2cap_chan *chan, struct ble_l2cap_chan_info *chan_info)
|
||||
{
|
||||
if (!chan || !chan_info) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -234,6 +238,7 @@ ble_l2cap_reconfig(struct ble_l2cap_chan *chans[], uint8_t num, uint16_t new_mtu
|
||||
uint16_t conn_handle;
|
||||
|
||||
if (num == 0 || !chans) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -256,6 +261,7 @@ ble_l2cap_reconfig_mtu_mps(struct ble_l2cap_chan *chans[], uint8_t num, uint16_t
|
||||
uint16_t conn_handle;
|
||||
|
||||
if (num == 0 || !chans) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -436,6 +442,7 @@ ble_l2cap_rx(uint16_t conn_handle, uint8_t pb, struct os_mbuf *om)
|
||||
if (!chan) {
|
||||
ble_l2cap_sig_reject_invalid_cid_tx(conn_handle, 0, 0, rx_cid);
|
||||
os_mbuf_free_chain(rx_frags);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -443,12 +450,14 @@ ble_l2cap_rx(uint16_t conn_handle, uint8_t pb, struct os_mbuf *om)
|
||||
chan->dcid <= BLE_L2CAP_COC_CID_END && rx_len > chan->my_coc_mps) {
|
||||
ble_l2cap_disconnect(chan);
|
||||
os_mbuf_free_chain(rx_frags);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
if (rx_len > ble_l2cap_get_mtu(chan)) {
|
||||
ble_l2cap_disconnect(chan);
|
||||
os_mbuf_free_chain(rx_frags);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -480,6 +489,7 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
|
||||
|
||||
txom = ble_l2cap_prepend_hdr(txom, chan->dcid, OS_MBUF_PKTLEN(txom));
|
||||
if (txom == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -496,6 +506,9 @@ ble_l2cap_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
|
||||
|
||||
default:
|
||||
/* Error. */
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -508,6 +521,7 @@ ble_l2cap_init(void)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
rc = ble_l2cap_ensure_ctx();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -520,6 +534,7 @@ ble_l2cap_init(void)
|
||||
if (ble_l2cap_chan_mem == NULL) {
|
||||
nimble_platform_mem_free(ble_l2cap_ctx);
|
||||
ble_l2cap_ctx = NULL;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -545,6 +560,7 @@ ble_l2cap_init(void)
|
||||
nimble_platform_mem_free(ble_l2cap_ctx);
|
||||
ble_l2cap_ctx = NULL;
|
||||
#endif
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EOS);
|
||||
return BLE_HS_EOS;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ble_l2cap_priv.h"
|
||||
#include "ble_l2cap_coc_priv.h"
|
||||
#include "ble_l2cap_sig_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0 && NIMBLE_BLE_CONNECT
|
||||
|
||||
@@ -106,6 +107,7 @@ ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
|
||||
struct ble_l2cap_coc_srv *srv;
|
||||
|
||||
if (cb == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -113,12 +115,14 @@ ble_l2cap_coc_create_server(uint16_t psm, uint16_t mtu,
|
||||
|
||||
if (ble_l2cap_coc_srv_find(psm) != NULL) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EALREADY);
|
||||
return BLE_HS_EALREADY;
|
||||
}
|
||||
|
||||
srv = ble_l2cap_coc_srv_alloc();
|
||||
if (!srv) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -251,6 +255,7 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, BLE_L2CAP_SDU_SIZE);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -266,6 +271,7 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
/* Disconnect peer with invalid behaviour */
|
||||
rx->data_offset = 0;
|
||||
ble_l2cap_disconnect(chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
if (sdu_len > rx->mtu) {
|
||||
@@ -274,6 +280,7 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
|
||||
/* Disconnect peer with invalid behaviour */
|
||||
ble_l2cap_disconnect(chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -287,6 +294,9 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "Could not append data rc=%d\n", rc);
|
||||
ble_l2cap_disconnect(chan);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -304,12 +314,16 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
rx->sdus[chan->coc_rx.current_sdu_idx] = NULL;
|
||||
rx->data_offset = 0;
|
||||
ble_l2cap_disconnect(chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
rc = os_mbuf_appendfrom(rx_sdu, *om, 0, om_total);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "Could not append data rc=%d\n", rc);
|
||||
ble_l2cap_disconnect(chan);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -317,6 +331,7 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
if (rx->credits == 0) {
|
||||
BLE_HS_LOG(ERROR, "RX credits underflow, disconnecting\n");
|
||||
ble_l2cap_disconnect(chan);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
rx->credits--;
|
||||
@@ -442,12 +457,14 @@ ble_l2cap_coc_create_srv_chan(struct ble_hs_conn *conn, uint16_t psm,
|
||||
/* Check if there is server registered on this PSM */
|
||||
srv = ble_l2cap_coc_srv_find(psm);
|
||||
if (!srv) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
*chan = ble_l2cap_coc_chan_alloc(conn, psm, srv->mtu, NULL, srv->cb,
|
||||
srv->cb_arg);
|
||||
if (!*chan) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -610,6 +627,7 @@ ble_l2cap_coc_continue_tx(struct ble_l2cap_chan *chan)
|
||||
/* Not complete SDU sent, wait for credits */
|
||||
tx->flags |= BLE_L2CAP_COC_FLAG_STALLED;
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTALLED);
|
||||
return BLE_HS_ESTALLED;
|
||||
}
|
||||
|
||||
@@ -680,6 +698,7 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
|
||||
struct ble_l2cap_chan *c;
|
||||
|
||||
if (!sdu_rx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -689,6 +708,7 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
|
||||
chan->coc_rx.next_sdu_alloc_idx == chan->coc_rx.current_sdu_idx &&
|
||||
BLE_L2CAP_SDU_BUFF_CNT != 1) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBUSY);
|
||||
return BLE_HS_EBUSY;
|
||||
}
|
||||
|
||||
@@ -699,6 +719,7 @@ ble_l2cap_coc_recv_ready(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_rx)
|
||||
c = ble_hs_conn_chan_find_by_scid(conn, chan->scid);
|
||||
if (!c) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -746,12 +767,14 @@ ble_l2cap_coc_send(struct ble_l2cap_chan *chan, struct os_mbuf *sdu_tx)
|
||||
tx = &chan->coc_tx;
|
||||
|
||||
if (OS_MBUF_PKTLEN(sdu_tx) > tx->mtu) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
ble_hs_lock();
|
||||
if (tx->sdus[0]) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBUSY);
|
||||
return BLE_HS_EBUSY;
|
||||
}
|
||||
tx->sdus[0] = sdu_tx;
|
||||
@@ -770,6 +793,7 @@ ble_l2cap_coc_init(void)
|
||||
if (ble_l2cap_coc_ctx == NULL) {
|
||||
ble_l2cap_coc_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_l2cap_coc_ctx));
|
||||
if (ble_l2cap_coc_ctx == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -782,6 +806,7 @@ ble_l2cap_coc_init(void)
|
||||
if (!ble_l2cap_coc_srv_mem) {
|
||||
nimble_platform_mem_free(ble_l2cap_coc_ctx);
|
||||
ble_l2cap_coc_ctx = NULL;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include "nimble/ble.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
/*****************************************************************************
|
||||
@@ -365,6 +366,7 @@ ble_l2cap_sig_rx_noop(uint16_t conn_handle,
|
||||
struct ble_l2cap_sig_hdr *hdr,
|
||||
struct os_mbuf **om)
|
||||
{
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -411,28 +413,33 @@ ble_l2cap_sig_check_conn_params(const struct ble_gap_upd_params *params)
|
||||
/* Check connection interval min */
|
||||
if ((params->itvl_min < BLE_HCI_CONN_ITVL_MIN) ||
|
||||
(params->itvl_min > BLE_HCI_CONN_ITVL_MAX)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ERR_INV_HCI_CMD_PARMS);
|
||||
return BLE_ERR_INV_HCI_CMD_PARMS;
|
||||
}
|
||||
/* Check connection interval max */
|
||||
if ((params->itvl_max < BLE_HCI_CONN_ITVL_MIN) ||
|
||||
(params->itvl_max > BLE_HCI_CONN_ITVL_MAX) ||
|
||||
(params->itvl_max < params->itvl_min)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ERR_INV_HCI_CMD_PARMS);
|
||||
return BLE_ERR_INV_HCI_CMD_PARMS;
|
||||
}
|
||||
|
||||
/* Check connection latency */
|
||||
if (params->latency > BLE_HCI_CONN_LATENCY_MAX) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ERR_INV_HCI_CMD_PARMS);
|
||||
return BLE_ERR_INV_HCI_CMD_PARMS;
|
||||
}
|
||||
|
||||
/* Check supervision timeout */
|
||||
if ((params->supervision_timeout < BLE_HCI_CONN_SPVN_TIMEOUT_MIN) ||
|
||||
(params->supervision_timeout > BLE_HCI_CONN_SPVN_TIMEOUT_MAX)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ERR_INV_HCI_CMD_PARMS);
|
||||
return BLE_ERR_INV_HCI_CMD_PARMS;
|
||||
}
|
||||
|
||||
/* Check connection event length */
|
||||
if (params->min_ce_len > params->max_ce_len) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_ERR_INV_HCI_CMD_PARMS);
|
||||
return BLE_ERR_INV_HCI_CMD_PARMS;
|
||||
}
|
||||
|
||||
@@ -457,21 +464,25 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, BLE_L2CAP_SIG_UPDATE_REQ_SZ);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (OS_MBUF_PKTLEN(*om) != BLE_L2CAP_SIG_UPDATE_REQ_SZ) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Only a master can process an update request. */
|
||||
sig_err = !(conn_flags & BLE_HS_CONN_F_MASTER);
|
||||
if (sig_err) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
}
|
||||
|
||||
@@ -654,24 +665,34 @@ ble_l2cap_sig_coc_err2ble_hs_err(uint16_t l2cap_coc_err)
|
||||
case BLE_L2CAP_COC_ERR_CONNECTION_SUCCESS:
|
||||
return 0;
|
||||
case BLE_L2CAP_COC_ERR_UNKNOWN_LE_PSM:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
case BLE_L2CAP_COC_ERR_NO_RESOURCES:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
case BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHEN:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAUTHEN);
|
||||
return BLE_HS_EAUTHEN;
|
||||
case BLE_L2CAP_COC_ERR_INSUFFICIENT_AUTHOR:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EAUTHOR);
|
||||
return BLE_HS_EAUTHOR;
|
||||
case BLE_L2CAP_COC_ERR_INSUFFICIENT_KEY_SZ:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EENCRYPT_KEY_SZ);
|
||||
return BLE_HS_EENCRYPT_KEY_SZ;
|
||||
case BLE_L2CAP_COC_ERR_INSUFFICIENT_ENC:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EENCRYPT);
|
||||
return BLE_HS_EENCRYPT;
|
||||
case BLE_L2CAP_COC_ERR_INVALID_SOURCE_CID:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EREJECT);
|
||||
return BLE_HS_EREJECT;
|
||||
case BLE_L2CAP_COC_ERR_SOURCE_CID_ALREADY_USED:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EALREADY);
|
||||
return BLE_HS_EALREADY;
|
||||
case BLE_L2CAP_COC_ERR_UNACCEPTABLE_PARAMETERS:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -819,6 +840,7 @@ ble_l2cap_sig_credit_base_reconfig_req_rx(uint16_t conn_handle,
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, hdr->length);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -996,6 +1018,7 @@ ble_l2cap_sig_credit_base_con_req_rx(uint16_t conn_handle,
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, hdr->length);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1287,10 +1310,12 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, sizeof(*req));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (OS_MBUF_PKTLEN(*om) != sizeof(*req)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1459,6 +1484,7 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
|
||||
int rc;
|
||||
|
||||
if (!sdu_rx || !cb) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1467,12 +1493,14 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
|
||||
|
||||
if (!conn) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
chan = ble_l2cap_coc_chan_alloc(conn, psm, mtu, sdu_rx, cb, cb_arg);
|
||||
if (!chan) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1480,6 +1508,7 @@ ble_l2cap_sig_coc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
|
||||
if (!proc) {
|
||||
ble_l2cap_chan_free(conn, chan);
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1537,6 +1566,7 @@ ble_l2cap_sig_ecoc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
|
||||
int j;
|
||||
|
||||
if (!sdu_rx || !cb) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -1545,12 +1575,14 @@ ble_l2cap_sig_ecoc_connect(uint16_t conn_handle, uint16_t psm, uint16_t mtu,
|
||||
|
||||
if (!conn) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
proc = ble_l2cap_sig_proc_alloc();
|
||||
if (!proc) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1627,12 +1659,14 @@ ble_l2cap_sig_coc_reconfig(uint16_t conn_handle, struct ble_l2cap_chan *chans[],
|
||||
|
||||
if (!conn) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
proc = ble_l2cap_sig_proc_alloc();
|
||||
if (!proc) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1703,6 +1737,7 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, sizeof(*req));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1721,6 +1756,7 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
|
||||
if (OS_MBUF_PKTLEN(*om) != sizeof(*req)) {
|
||||
os_mbuf_free_chain(txom);
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1849,6 +1885,7 @@ ble_l2cap_sig_disconnect(struct ble_l2cap_chan *chan)
|
||||
|
||||
proc = ble_l2cap_sig_proc_alloc();
|
||||
if (proc == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1892,6 +1929,7 @@ ble_l2cap_sig_le_credits_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
|
||||
}
|
||||
|
||||
if (OS_MBUF_PKTLEN(*om) != sizeof(*req)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -1918,6 +1956,7 @@ ble_l2cap_sig_le_credits(uint16_t conn_handle, uint16_t scid, uint16_t credits)
|
||||
ble_l2cap_sig_next_id(), sizeof(*cmd), &txom);
|
||||
|
||||
if (!cmd) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -1978,6 +2017,7 @@ ble_l2cap_sig_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
|
||||
rc = ble_hs_mbuf_pullup_base(om, BLE_L2CAP_SIG_HDR_SZ);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1991,6 +2031,7 @@ ble_l2cap_sig_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
ble_l2cap_sig_reject_tx(conn_handle, hdr.identifier,
|
||||
BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD, NULL, 0);
|
||||
}
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -2007,6 +2048,9 @@ ble_l2cap_sig_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2183,6 +2227,7 @@ ble_l2cap_sig_init(void)
|
||||
if (!ble_l2cap_sig_ctx) {
|
||||
ble_l2cap_sig_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_l2cap_sig_ctx));
|
||||
if (!ble_l2cap_sig_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -2197,6 +2242,7 @@ ble_l2cap_sig_init(void)
|
||||
// free the allocated memory
|
||||
nimble_platform_mem_free(ble_l2cap_sig_ctx);
|
||||
ble_l2cap_sig_ctx = NULL;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
/* this function consumes tx os_mbuf */
|
||||
@@ -65,6 +66,7 @@ ble_l2cap_sig_reject_tx(uint16_t conn_handle, uint8_t id, uint16_t reason,
|
||||
cmd = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_REJECT, id,
|
||||
sizeof(*cmd) + data_len, &txom);
|
||||
if (!cmd) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#include "ble_hs_resolv_priv.h"
|
||||
#include "../store/config/src/ble_store_config_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
|
||||
@@ -339,6 +340,7 @@ ble_sm_gen_pair_rand(uint8_t *pair_rand)
|
||||
|
||||
rc = ble_hs_hci_util_rand(pair_rand, 16);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -360,6 +362,7 @@ ble_sm_gen_ediv(struct ble_sm_master_id *master_id)
|
||||
|
||||
rc = ble_hs_hci_util_rand(&master_id->ediv, sizeof master_id->ediv);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -381,6 +384,7 @@ ble_sm_gen_master_id_rand(struct ble_sm_master_id *master_id)
|
||||
|
||||
rc = ble_hs_hci_util_rand(&master_id->rand_val, sizeof master_id->rand_val);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -403,6 +407,7 @@ ble_sm_gen_ltk(struct ble_sm_proc *proc, uint8_t *ltk)
|
||||
|
||||
rc = ble_hs_hci_util_rand(ltk, proc->key_size);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -428,6 +433,7 @@ ble_sm_gen_csrk(struct ble_sm_proc *proc, uint8_t *csrk)
|
||||
|
||||
rc = ble_hs_hci_util_rand(csrk, 16);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -961,6 +967,7 @@ ble_sm_read_bond(uint16_t conn_handle, struct ble_store_value_sec *out_bond)
|
||||
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1005,6 +1012,9 @@ ble_sm_chk_repeat_pairing(uint16_t conn_handle,
|
||||
case BLE_HS_ENOENT:
|
||||
return 0;
|
||||
default:
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1024,6 +1034,7 @@ ble_sm_chk_repeat_pairing(uint16_t conn_handle,
|
||||
|
||||
BLE_HS_LOG(DEBUG, "silently ignoring pair request from bonded peer");
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EALREADY);
|
||||
return BLE_HS_EALREADY;
|
||||
}
|
||||
|
||||
@@ -1177,6 +1188,7 @@ ble_sm_chk_store_overflow_by_type(int obj_type, uint16_t conn_handle)
|
||||
|
||||
rc = ble_store_util_count(obj_type, &count);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1195,6 +1207,7 @@ ble_sm_chk_store_overflow_by_type(int obj_type, uint16_t conn_handle)
|
||||
*/
|
||||
rc = ble_store_full_event(obj_type, conn_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1209,12 +1222,14 @@ ble_sm_chk_store_overflow(uint16_t conn_handle)
|
||||
rc = ble_sm_chk_store_overflow_by_type(BLE_STORE_OBJ_TYPE_PEER_SEC,
|
||||
conn_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_sm_chk_store_overflow_by_type(BLE_STORE_OBJ_TYPE_OUR_SEC,
|
||||
conn_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -1406,9 +1421,11 @@ ble_sm_retrieve_ltk(uint16_t ediv, uint64_t rand, uint8_t peer_addr_type,
|
||||
|
||||
rc = ble_store_read_our_sec(&key_sec, value_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if (value_sec->ediv != ediv || value_sec->rand_num != rand) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
return rc;
|
||||
@@ -1428,10 +1445,12 @@ ble_sm_ltk_req_reply_tx(uint16_t conn_handle, const uint8_t *ltk)
|
||||
BLE_HCI_OCF_LE_LT_KEY_REQ_REPLY),
|
||||
&cmd, sizeof(cmd), &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (le16toh(rsp.conn_handle) != conn_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -1450,10 +1469,12 @@ ble_sm_ltk_req_neg_reply_tx(uint16_t conn_handle)
|
||||
BLE_HCI_OCF_LE_LT_KEY_REQ_NEG_REPLY),
|
||||
&cmd, sizeof(cmd), &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (le16toh(rsp.conn_handle) != conn_handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ECONTROLLER);
|
||||
return BLE_HS_ECONTROLLER;
|
||||
}
|
||||
|
||||
@@ -2807,6 +2828,7 @@ ble_sm_incr_our_sign_counter(uint16_t conn_handle)
|
||||
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2815,23 +2837,28 @@ ble_sm_incr_our_sign_counter(uint16_t conn_handle)
|
||||
|
||||
rc = ble_store_read_our_sec(&key_sec, &value_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if (value_sec.csrk_present != 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
if (value_sec.sign_counter == (uint32_t)0xffffffff) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
rc = ble_store_delete_our_sec(&key_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
value_sec.sign_counter += 1;
|
||||
rc = ble_store_write_our_sec(&value_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2857,6 +2884,7 @@ ble_sm_incr_peer_sign_counter(uint16_t conn_handle)
|
||||
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2865,17 +2893,21 @@ ble_sm_incr_peer_sign_counter(uint16_t conn_handle)
|
||||
|
||||
rc = ble_store_read_peer_sec(&key_sec, &value_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
if (value_sec.csrk_present != 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
if (value_sec.sign_counter == (uint32_t)0xffffffff) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
rc = ble_store_delete_peer_sec(&key_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2891,6 +2923,7 @@ ble_sm_incr_peer_sign_counter(uint16_t conn_handle)
|
||||
value_sec.sign_counter += 1;
|
||||
rc = ble_store_write_peer_sec(&value_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -2951,6 +2984,7 @@ ble_sm_pair_initiate(uint16_t conn_handle)
|
||||
|
||||
if (proc != NULL) {
|
||||
res.app_status = BLE_HS_EALREADY;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EALREADY);
|
||||
return BLE_HS_EALREADY;
|
||||
}
|
||||
|
||||
@@ -2959,6 +2993,7 @@ ble_sm_pair_initiate(uint16_t conn_handle)
|
||||
*/
|
||||
rc = ble_sm_chk_store_overflow(conn_handle);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3095,11 +3130,13 @@ ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
|
||||
conn_handle = ble_l2cap_get_conn_handle(chan);
|
||||
if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
rc = os_mbuf_copydata(*om, 0, 1, &op);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EBADDATA);
|
||||
return BLE_HS_EBADDATA;
|
||||
}
|
||||
|
||||
@@ -3242,6 +3279,7 @@ ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey)
|
||||
* SMP state.
|
||||
*/
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3268,6 +3306,7 @@ ble_sm_state_dispatch_init(void)
|
||||
ble_sm_state_dispatch = nimble_platform_mem_calloc(1, BLE_SM_PROC_STATE_CNT * sizeof(ble_sm_state_fn *));
|
||||
|
||||
if (!ble_sm_state_dispatch) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -3309,6 +3348,7 @@ ble_sm_init(void)
|
||||
if (!ble_sm_ctx) {
|
||||
ble_sm_ctx = nimble_platform_mem_calloc(1, sizeof(*ble_sm_ctx));
|
||||
if (!ble_sm_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -3322,6 +3362,7 @@ ble_sm_init(void)
|
||||
/* free the allocated memory */
|
||||
nimble_platform_mem_free(ble_sm_ctx);
|
||||
ble_sm_ctx = NULL;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -3340,6 +3381,9 @@ ble_sm_init(void)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
ble_sm_deinit();
|
||||
#endif
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3348,6 +3392,9 @@ ble_sm_init(void)
|
||||
|
||||
if (rc != 0) {
|
||||
ble_sm_deinit();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -3395,11 +3442,13 @@ ble_sm_rx(struct ble_l2cap_chan *chan, struct os_mbuf **om)
|
||||
|
||||
handle = ble_l2cap_get_conn_handle(chan);
|
||||
if (!handle) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTCONN);
|
||||
return BLE_HS_ENOTCONN;
|
||||
}
|
||||
|
||||
cmd = ble_sm_cmd_get(BLE_SM_OP_PAIR_FAIL, sizeof(*cmd), &txom);
|
||||
if (cmd == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -3438,6 +3487,7 @@ ble_sm_configure_static_passkey(uint32_t passkey, bool enable)
|
||||
if (enable) {
|
||||
/* Validate passkey is 6 digits */
|
||||
if (passkey > 999999) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
/* Passkey authentication requires MITM; ensure it is enabled. */
|
||||
@@ -3458,6 +3508,7 @@ int
|
||||
ble_sm_get_static_passkey_config(uint32_t *passkey, bool *enabled)
|
||||
{
|
||||
if (passkey == NULL || enabled == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <string.h>
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "nimble/nimble_opt.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
#if NIMBLE_BLE_SM
|
||||
@@ -122,6 +123,7 @@ ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
|
||||
status = psa_import_key(&key_attributes, tmp, 16, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Failed to import AES key: %d", status);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
psa_reset_key_attributes(&key_attributes);
|
||||
@@ -134,6 +136,7 @@ ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
|
||||
if (status != PSA_SUCCESS || output_len != 16) {
|
||||
ESP_LOGE(TAG, "Encryption failed: %d", status);
|
||||
psa_destroy_key(key_id);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
psa_destroy_key(key_id);
|
||||
@@ -143,6 +146,7 @@ ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
|
||||
mbedtls_aes_init(&s);
|
||||
if (mbedtls_aes_setkey_enc(&s, tmp, 128) != 0) {
|
||||
mbedtls_aes_free(&s);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -150,6 +154,7 @@ ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
|
||||
|
||||
if (mbedtls_aes_crypt_ecb(&s, MBEDTLS_AES_ENCRYPT, tmp, enc_data) != 0) {
|
||||
mbedtls_aes_free(&s);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -159,12 +164,14 @@ ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
|
||||
struct tc_aes_key_sched_struct s;
|
||||
|
||||
if (tc_aes128_set_encrypt_key(&s, tmp) == TC_CRYPTO_FAIL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
swap_buf(tmp, plaintext, 16);
|
||||
|
||||
if (tc_aes_encrypt(enc_data, tmp, &s) == TC_CRYPTO_FAIL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
#endif
|
||||
@@ -194,6 +201,7 @@ ble_sm_alg_s1(const uint8_t *k, const uint8_t *r1, const uint8_t *r2,
|
||||
/* s1(k, r1 , r2) = e(k, r') */
|
||||
rc = ble_sm_alg_encrypt(k, out, out);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -306,6 +314,7 @@ ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
|
||||
status = psa_import_key(&key_attributes, key, 16, &key_id);
|
||||
if (status != PSA_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Failed to import key: %d", status);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
psa_reset_key_attributes(&key_attributes);
|
||||
@@ -315,6 +324,7 @@ ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
|
||||
if (status != PSA_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Failed to setup MAC sign operation: %d", status);
|
||||
psa_destroy_key(key_id);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -324,6 +334,7 @@ ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
|
||||
ESP_LOGE(TAG, "Failed to update MAC operation: %d", status);
|
||||
psa_mac_abort(&operation);
|
||||
psa_destroy_key(key_id);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -332,6 +343,7 @@ ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
|
||||
ESP_LOGE(TAG, "Failed to finish MAC sign operation: %d", status);
|
||||
psa_mac_abort(&operation);
|
||||
psa_destroy_key(key_id);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -370,6 +382,9 @@ exit:
|
||||
if (rc != 0) {
|
||||
rc = BLE_HS_EUNKNOWN;
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
#endif // CONFIG_MBEDTLS_VER_4_X_SUPPORT
|
||||
return 0;
|
||||
@@ -384,14 +399,17 @@ ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
|
||||
struct tc_cmac_struct state;
|
||||
|
||||
if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
if (tc_cmac_update(&state, in, len) == TC_CRYPTO_FAIL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
if (tc_cmac_final(out, &state) == TC_CRYPTO_FAIL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -442,6 +460,7 @@ ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
|
||||
|
||||
rc = ble_sm_alg_aes_cmac(xs, m, sizeof(m), out_enc_data);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -573,6 +592,7 @@ ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
|
||||
memset(ws, 0, sizeof(ws));
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -605,6 +625,7 @@ ble_sm_alg_g2(const uint8_t *u, const uint8_t *v, const uint8_t *x,
|
||||
/* reuse xs (key) as buffer for result */
|
||||
rc = ble_sm_alg_aes_cmac(xs, m, sizeof(m), xs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -835,6 +856,7 @@ exit:
|
||||
psa_destroy_key(key_id);
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
#else
|
||||
@@ -843,6 +865,7 @@ exit:
|
||||
if (!keypair_ptr) {
|
||||
keypair_ptr = nimble_platform_mem_calloc(1, sizeof(mbedtls_ecp_keypair));
|
||||
if (!keypair_ptr) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -915,6 +938,7 @@ ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
||||
|
||||
#if MYNEWT_VAL(BLE_CRYPTO_STACK_MBEDTLS)
|
||||
if (mbedtls_gen_keypair(pk, priv) != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
#if CONFIG_MBEDTLS_VER_4_X_SUPPORT
|
||||
@@ -927,6 +951,7 @@ ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
||||
#endif // CONFIG_MBEDTLS_VER_4_X_SUPPORT
|
||||
#else
|
||||
if (uECC_make_key(pk, priv, uECC_secp256r1()) != TC_CRYPTO_SUCCESS) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
// TinyCrypt/uECC: pk[0..31]=X, pk[32..63]=Y (no prefix)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "nimble/nimble_opt.h"
|
||||
#include "host/ble_sm.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
void *
|
||||
@@ -76,6 +77,7 @@ ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom)
|
||||
|
||||
return rc;
|
||||
#endif
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "nimble/nimble_opt.h"
|
||||
#include "host/ble_sm.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
#if MYNEWT_VAL(BLE_SM_LEGACY)
|
||||
@@ -117,6 +118,7 @@ ble_sm_lgcy_io_action(struct ble_sm_proc *proc, uint8_t *action)
|
||||
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -181,6 +183,7 @@ ble_sm_gen_stk(struct ble_sm_proc *proc)
|
||||
|
||||
rc = ble_sm_alg_s1(proc->tk, proc->rands, proc->randm, key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_sm_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
#if MYNEWT_VAL(BLE_SM_SC)
|
||||
@@ -113,6 +114,7 @@ ble_sm_sc_ensure_ctx (void)
|
||||
ble_sm_sc_ctx = nimble_platform_mem_calloc(1, sizeof(* ble_sm_sc_ctx));
|
||||
|
||||
if (!ble_sm_sc_ctx) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -213,6 +215,7 @@ ble_sm_sc_io_action(struct ble_sm_proc *proc, uint8_t *action)
|
||||
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -235,6 +238,7 @@ ble_sm_gen_pub_priv(uint8_t *pub, uint8_t *priv)
|
||||
|
||||
rc = ble_sm_alg_gen_key_pair(pub, priv);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -249,11 +253,13 @@ ble_sm_sc_ensure_keys_generated(void)
|
||||
if (!ble_sm_sc_keys_generated) {
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
if (ble_sm_sc_ensure_ctx()) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
#endif
|
||||
rc = ble_sm_gen_pub_priv(ble_sm_sc_pub_key, ble_sm_sc_priv_key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -330,6 +336,7 @@ ble_sm_sc_gen_ri(struct ble_sm_proc *proc)
|
||||
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
}
|
||||
@@ -456,6 +463,7 @@ ble_sm_sc_random_advance(struct ble_sm_proc *proc)
|
||||
proc->state = BLE_SM_PROC_STATE_CONFIRM;
|
||||
rc = ble_sm_gen_pair_rand(ble_sm_our_pair_rand(proc));
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -1008,17 +1016,20 @@ ble_sm_sc_oob_generate_data(struct ble_sm_sc_oob_data *oob_data)
|
||||
|
||||
rc = ble_sm_sc_ensure_keys_generated();
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_hs_hci_util_rand(oob_data->r, 16);
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_sm_alg_f4(ble_sm_sc_pub_key, ble_sm_sc_pub_key, oob_data->r, 0,
|
||||
oob_data->c);
|
||||
if (rc) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "host/ble_store.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
int
|
||||
ble_store_read(int obj_type, const union ble_store_key *key,
|
||||
@@ -42,6 +43,7 @@ ble_store_read(int obj_type, const union ble_store_key *key,
|
||||
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -57,6 +59,7 @@ ble_store_write(int obj_type, const union ble_store_value *val)
|
||||
|
||||
if (ble_hs_cfg.store_write_cb == NULL) {
|
||||
ble_hs_unlock();
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
|
||||
@@ -72,6 +75,7 @@ ble_store_write(int obj_type, const union ble_store_value *val)
|
||||
*/
|
||||
rc = ble_store_overflow_event(obj_type, val);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -79,10 +83,14 @@ ble_store_write(int obj_type, const union ble_store_value *val)
|
||||
break;
|
||||
|
||||
default:
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -106,6 +114,7 @@ ble_store_delete(int obj_type, const union ble_store_key *key)
|
||||
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -141,6 +150,7 @@ ble_store_overflow_event(int obj_type, const union ble_store_value *value)
|
||||
|
||||
return ble_store_status(&event);
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -159,6 +169,7 @@ ble_store_full_event(int obj_type, uint16_t conn_handle)
|
||||
return ble_store_status(&event);
|
||||
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -182,6 +193,7 @@ ble_store_read_our_sec(const struct ble_store_key_sec *key_sec,
|
||||
rc = ble_store_read(BLE_STORE_OBJ_TYPE_OUR_SEC, store_key, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -218,6 +230,7 @@ ble_store_write_our_sec(const struct ble_store_value_sec *value_sec)
|
||||
rc = ble_store_persist_sec(BLE_STORE_OBJ_TYPE_OUR_SEC, value_sec);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -234,6 +247,7 @@ ble_store_delete_our_sec(const struct ble_store_key_sec *key_sec)
|
||||
rc = ble_store_delete(BLE_STORE_OBJ_TYPE_OUR_SEC, store_key);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -249,6 +263,7 @@ ble_store_delete_peer_sec(const struct ble_store_key_sec *key_sec)
|
||||
rc = ble_store_delete(BLE_STORE_OBJ_TYPE_PEER_SEC, store_key);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -272,6 +287,7 @@ ble_store_read_peer_sec(const struct ble_store_key_sec *key_sec,
|
||||
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -285,6 +301,7 @@ ble_store_write_peer_sec(const struct ble_store_value_sec *value_sec)
|
||||
|
||||
rc = ble_store_persist_sec(BLE_STORE_OBJ_TYPE_PEER_SEC, value_sec);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -297,6 +314,7 @@ ble_store_write_peer_sec(const struct ble_store_value_sec *value_sec)
|
||||
value_sec->peer_addr.type,
|
||||
value_sec->irk);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -304,6 +322,7 @@ ble_store_write_peer_sec(const struct ble_store_value_sec *value_sec)
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -323,6 +342,7 @@ ble_store_read_cccd(const struct ble_store_key_cccd *key,
|
||||
rc = ble_store_read(BLE_STORE_OBJ_TYPE_CCCD, store_key, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -339,6 +359,7 @@ ble_store_write_cccd(const struct ble_store_value_cccd *value)
|
||||
rc = ble_store_write(BLE_STORE_OBJ_TYPE_CCCD, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -355,6 +376,7 @@ ble_store_delete_cccd(const struct ble_store_key_cccd *key)
|
||||
rc = ble_store_delete(BLE_STORE_OBJ_TYPE_CCCD, store_key);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -374,6 +396,7 @@ ble_store_read_csfc(const struct ble_store_key_csfc *key,
|
||||
rc = ble_store_read(BLE_STORE_OBJ_TYPE_CSFC, store_key, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -390,6 +413,7 @@ ble_store_write_csfc(const struct ble_store_value_csfc *value)
|
||||
rc = ble_store_write(BLE_STORE_OBJ_TYPE_CSFC, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -406,6 +430,7 @@ ble_store_delete_csfc(const struct ble_store_key_csfc *key)
|
||||
rc = ble_store_delete(BLE_STORE_OBJ_TYPE_CSFC, store_key);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -451,6 +476,7 @@ ble_store_read_ead(const struct ble_store_key_ead *key,
|
||||
rc = ble_store_read(BLE_STORE_OBJ_TYPE_ENC_ADV_DATA, store_key, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -467,6 +493,7 @@ ble_store_write_ead(const struct ble_store_value_ead *value)
|
||||
rc = ble_store_write(BLE_STORE_OBJ_TYPE_ENC_ADV_DATA, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -483,6 +510,7 @@ ble_store_delete_ead(const struct ble_store_key_ead *key)
|
||||
rc = ble_store_delete(BLE_STORE_OBJ_TYPE_ENC_ADV_DATA, store_key);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -514,6 +542,7 @@ ble_store_read_local_irk(const struct ble_store_key_local_irk *key,
|
||||
rc = ble_store_read(BLE_STORE_OBJ_TYPE_LOCAL_IRK, store_key, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -532,6 +561,7 @@ ble_store_write_local_irk(const struct ble_store_value_local_irk *value)
|
||||
rc = ble_store_write(BLE_STORE_OBJ_TYPE_LOCAL_IRK, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -549,6 +579,7 @@ ble_store_delete_local_irk(const struct ble_store_key_local_irk *key)
|
||||
rc = ble_store_delete(BLE_STORE_OBJ_TYPE_LOCAL_IRK, store_key);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -579,6 +610,7 @@ ble_store_read_rpa_rec(const struct ble_store_key_rpa_rec *key,
|
||||
rc = ble_store_read(BLE_STORE_OBJ_TYPE_PEER_ADDR, store_key, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -595,6 +627,7 @@ ble_store_write_rpa_rec(const struct ble_store_value_rpa_rec *value)
|
||||
rc = ble_store_write(BLE_STORE_OBJ_TYPE_PEER_ADDR, store_value);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -611,6 +644,7 @@ ble_store_delete_rpa_rec(const struct ble_store_key_rpa_rec *key)
|
||||
rc = ble_store_delete(BLE_STORE_OBJ_TYPE_PEER_ADDR, store_key);
|
||||
return rc;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -723,6 +757,7 @@ ble_store_iterate(int obj_type,
|
||||
break;
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -749,12 +784,16 @@ ble_store_iterate(int obj_type,
|
||||
|
||||
default:
|
||||
/* Read error. */
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
idx++;
|
||||
}
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -797,12 +836,16 @@ ble_store_clear(void)
|
||||
|
||||
/* BLE_HS_ENOENT means we deleted everything. */
|
||||
if (rc != BLE_HS_ENOENT) {
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "host/ble_store.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_hs_resolv_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
struct ble_store_util_peer_set {
|
||||
ble_addr_t *peer_id_addrs;
|
||||
@@ -73,6 +74,7 @@ ble_store_util_iter_unique_peer(int obj_type,
|
||||
break;
|
||||
default:
|
||||
BLE_HS_DBG_ASSERT(0);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
/* Use peer_addr in loop and assignment */
|
||||
@@ -85,6 +87,7 @@ ble_store_util_iter_unique_peer(int obj_type,
|
||||
if (set->num_peers >= set->max_peers) {
|
||||
/* Overflow; abort the iterate procedure. */
|
||||
set->status = BLE_HS_ENOMEM;
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -128,6 +131,7 @@ ble_store_util_bonded_peers(ble_addr_t *out_peer_id_addrs, int *out_num_peers,
|
||||
ble_store_util_iter_unique_peer,
|
||||
&set);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -140,6 +144,7 @@ ble_store_util_bonded_peers(ble_addr_t *out_peer_id_addrs, int *out_num_peers,
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -166,11 +171,13 @@ ble_store_util_delete_peer(const ble_addr_t *peer_id_addr)
|
||||
|
||||
rc = ble_store_util_delete_all(BLE_STORE_OBJ_TYPE_OUR_SEC, &key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_util_delete_all(BLE_STORE_OBJ_TYPE_PEER_SEC, &key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -179,6 +186,7 @@ ble_store_util_delete_peer(const ble_addr_t *peer_id_addr)
|
||||
|
||||
rc = ble_store_util_delete_all(BLE_STORE_OBJ_TYPE_CCCD, &key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -188,6 +196,7 @@ ble_store_util_delete_peer(const ble_addr_t *peer_id_addr)
|
||||
|
||||
rc = ble_store_util_delete_all(BLE_STORE_OBJ_TYPE_ENC_ADV_DATA, &key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -197,6 +206,7 @@ ble_store_util_delete_peer(const ble_addr_t *peer_id_addr)
|
||||
|
||||
rc = ble_store_util_delete_all(BLE_STORE_OBJ_TYPE_PEER_ADDR, &key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -205,6 +215,7 @@ ble_store_util_delete_peer(const ble_addr_t *peer_id_addr)
|
||||
|
||||
rc = ble_store_util_delete_all(BLE_STORE_OBJ_TYPE_CSFC, &key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -231,6 +242,7 @@ ble_store_util_delete_peer(const ble_addr_t *peer_id_addr)
|
||||
if (needs_unlock) {
|
||||
ble_hs_unlock();
|
||||
}
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
@@ -241,6 +253,7 @@ ble_store_util_delete_peer(const ble_addr_t *peer_id_addr)
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -266,11 +279,15 @@ ble_store_util_delete_all(int type, const union ble_store_key *key)
|
||||
} while (rc == 0);
|
||||
|
||||
if (rc != BLE_HS_ENOENT) {
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -304,11 +321,13 @@ ble_store_util_count(int type, int *out_count)
|
||||
ble_store_util_iter_count,
|
||||
out_count);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -326,6 +345,7 @@ ble_store_util_delete_oldest_peer(void)
|
||||
peer_id_addrs, &num_peers,
|
||||
sizeof peer_id_addrs / sizeof peer_id_addrs[0]);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -335,11 +355,13 @@ ble_store_util_delete_oldest_peer(void)
|
||||
|
||||
rc = ble_store_util_delete_peer(&peer_id_addrs[0]);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -379,6 +401,7 @@ ble_store_util_ead_peers(ble_addr_t *out_peer_id_addrs, int *out_num_peers,
|
||||
ble_store_util_iter_unique_peer,
|
||||
&set);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -389,6 +412,7 @@ ble_store_util_ead_peers(ble_addr_t *out_peer_id_addrs, int *out_num_peers,
|
||||
*out_num_peers = set.num_peers;
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -409,6 +433,7 @@ ble_store_util_delete_ead_oldest_peer(void)
|
||||
peer_id_addrs, &num_peers,
|
||||
sizeof peer_id_addrs / sizeof peer_id_addrs[0]);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -419,11 +444,13 @@ ble_store_util_delete_ead_oldest_peer(void)
|
||||
key.ead.peer_addr = peer_id_addrs[0];
|
||||
rc = ble_store_util_delete_all(BLE_STORE_OBJ_TYPE_ENC_ADV_DATA, &key);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -458,6 +485,7 @@ ble_store_util_status_rr(struct ble_store_status_event *event, void *arg)
|
||||
return ble_store_util_delete_ead_oldest_peer();
|
||||
#endif
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
@@ -468,6 +496,7 @@ ble_store_util_status_rr(struct ble_store_status_event *event, void *arg)
|
||||
return 0;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "nimble/ble.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "host/ble_uuid.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
#include "esp_nimble_mem.h"
|
||||
#endif
|
||||
@@ -61,6 +62,7 @@ hex2val(char c, uint8_t *value)
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
*value = c - 'A' + 10;
|
||||
} else {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
return 0;
|
||||
@@ -115,6 +117,7 @@ ble_uuid_init_from_buf(ble_uuid_any_t *uuid, const void *buf, size_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -206,6 +209,7 @@ ble_uuid_base_init(void)
|
||||
if (ble_uuid_base == NULL) {
|
||||
ble_uuid_base = nimble_platform_mem_calloc(1, sizeof(uint8_t) * 16);
|
||||
if (ble_uuid_base == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
}
|
||||
@@ -236,11 +240,13 @@ ble_uuid_from_str(ble_uuid_any_t *uuid, const char *str)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
int rc = ble_uuid_base_init();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((len < 4) || (len % 2 != 0)) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -253,6 +259,7 @@ ble_uuid_from_str(ble_uuid_any_t *uuid, const char *str)
|
||||
} else if (len <= BLE_UUID128_STR_MAX_LEN) {
|
||||
uuid->u.type = BLE_UUID_TYPE_128;
|
||||
} else {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -262,6 +269,7 @@ ble_uuid_from_str(ble_uuid_any_t *uuid, const char *str)
|
||||
int bytes_parsed = 0;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (hex2bin(str_ptr, u8p, 1) != 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
bytes_parsed++;
|
||||
@@ -281,6 +289,7 @@ ble_uuid_from_str(ble_uuid_any_t *uuid, const char *str)
|
||||
u8p++;
|
||||
}
|
||||
if (bytes_parsed != 16 || str_ptr != str) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -303,6 +312,7 @@ ble_uuid_from_str(ble_uuid_any_t *uuid, const char *str)
|
||||
case BLE_UUID_TYPE_32:
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (hex2bin(str_ptr, &tmp_rslt, 1) != 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
u32 |= ((uint32_t) tmp_rslt) << (i * 8);
|
||||
@@ -317,6 +327,7 @@ ble_uuid_from_str(ble_uuid_any_t *uuid, const char *str)
|
||||
case BLE_UUID_TYPE_16:
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (hex2bin(str_ptr, &tmp_rslt, 1) != 1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
u16 |= ((uint32_t) tmp_rslt) << (i * 8);
|
||||
@@ -329,6 +340,7 @@ ble_uuid_from_str(ble_uuid_any_t *uuid, const char *str)
|
||||
uuid->u16.value = u16;
|
||||
break;
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -354,11 +366,15 @@ ble_uuid_init_from_att_mbuf(ble_uuid_any_t *uuid, struct os_mbuf *om, int off,
|
||||
|
||||
rc = os_mbuf_copydata(om, off, len, val);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_uuid_init_from_att_buf(uuid, val, len);
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -400,6 +416,7 @@ ble_uuid_to_any(const ble_uuid_t *uuid, ble_uuid_any_t *uuid_any)
|
||||
memcpy(uuid_any->u128.value, BLE_UUID128(uuid)->value, 16);
|
||||
break;
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
@@ -423,6 +440,7 @@ ble_uuid_to_mbuf(const ble_uuid_t *uuid, struct os_mbuf *om)
|
||||
|
||||
buf = os_mbuf_extend(om, len);
|
||||
if (buf == NULL) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOMEM);
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -439,6 +457,7 @@ ble_uuid_flat(const ble_uuid_t *uuid, void *dst)
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
int rc = ble_uuid_base_init();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
@@ -455,6 +474,7 @@ ble_uuid_flat(const ble_uuid_t *uuid, void *dst)
|
||||
memcpy(dst, BLE_UUID128(uuid)->value, 16);
|
||||
break;
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EINVAL);
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "ble_store_config_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
#include "../src/ble_hs_priv.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_STATIC_TO_DYNAMIC)
|
||||
ble_store_config_vars_t * ble_store_config_vars = NULL;
|
||||
@@ -266,12 +267,14 @@ ble_store_config_read_our_sec(const struct ble_store_key_sec *key_sec,
|
||||
idx = ble_store_config_find_sec(key_sec, ble_store_config_our_secs,
|
||||
ble_store_config_num_our_secs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
*value_sec = ble_store_config_our_secs[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -295,6 +298,7 @@ ble_store_config_write_our_sec(const struct ble_store_value_sec *value_sec)
|
||||
if (ble_store_config_num_our_secs >= MYNEWT_VAL(BLE_STORE_MAX_BONDS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting our sec; too many entries "
|
||||
"(%d)\n", ble_store_config_num_our_secs);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -308,18 +312,21 @@ ble_store_config_write_our_sec(const struct ble_store_value_sec *value_sec)
|
||||
|
||||
rc = ble_store_config_persist_our_secs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (ble_store_config_our_bond_count > (UINT16_MAX - 5)) {
|
||||
rc = ble_restore_our_sec_nvs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -359,12 +366,14 @@ ble_store_config_delete_sec(const struct ble_store_key_sec *key_sec,
|
||||
|
||||
idx = ble_store_config_find_sec(key_sec, value_secs, *num_value_secs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
rc = ble_store_config_delete_obj(value_secs, sizeof *value_secs, idx,
|
||||
num_value_secs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -381,11 +390,13 @@ ble_store_config_delete_our_sec(const struct ble_store_key_sec *key_sec)
|
||||
rc = ble_store_config_delete_sec(key_sec, ble_store_config_our_secs,
|
||||
&ble_store_config_num_our_secs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_config_persist_our_secs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -400,11 +411,13 @@ ble_store_config_delete_peer_sec(const struct ble_store_key_sec *key_sec)
|
||||
rc = ble_store_config_delete_sec(key_sec, ble_store_config_peer_secs,
|
||||
&ble_store_config_num_peer_secs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_config_persist_peer_secs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
@@ -421,12 +434,14 @@ ble_store_config_read_peer_sec(const struct ble_store_key_sec *key_sec,
|
||||
idx = ble_store_config_find_sec(key_sec, ble_store_config_peer_secs,
|
||||
ble_store_config_num_peer_secs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
*value_sec = ble_store_config_peer_secs[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -450,6 +465,7 @@ ble_store_config_write_peer_sec(const struct ble_store_value_sec *value_sec)
|
||||
if (ble_store_config_num_peer_secs >= MYNEWT_VAL(BLE_STORE_MAX_BONDS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting peer sec; too many entries "
|
||||
"(%d)\n", ble_store_config_num_peer_secs);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -463,18 +479,21 @@ ble_store_config_write_peer_sec(const struct ble_store_value_sec *value_sec)
|
||||
|
||||
rc = ble_store_config_persist_peer_secs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (ble_store_config_peer_bond_count > (UINT16_MAX - 5)) {
|
||||
rc = ble_restore_peer_sec_nvs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -527,6 +546,7 @@ ble_store_config_delete_cccd(const struct ble_store_key_cccd *key_cccd)
|
||||
|
||||
idx = ble_store_config_find_cccd(key_cccd);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -535,15 +555,18 @@ ble_store_config_delete_cccd(const struct ble_store_key_cccd *key_cccd)
|
||||
idx,
|
||||
&ble_store_config_num_cccds);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_config_persist_cccds();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -557,12 +580,14 @@ ble_store_config_read_cccd(const struct ble_store_key_cccd *key_cccd,
|
||||
|
||||
idx = ble_store_config_find_cccd(key_cccd);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
*value_cccd = ble_store_config_cccds[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -581,6 +606,7 @@ ble_store_config_write_cccd(const struct ble_store_value_cccd *value_cccd)
|
||||
if (ble_store_config_num_cccds >= MYNEWT_VAL(BLE_STORE_MAX_CCCDS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting cccd; too many entries (%d)\n",
|
||||
ble_store_config_num_cccds);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -592,11 +618,13 @@ ble_store_config_write_cccd(const struct ble_store_value_cccd *value_cccd)
|
||||
|
||||
rc = ble_store_config_persist_cccds();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -641,6 +669,7 @@ ble_store_config_delete_ead(const struct ble_store_key_ead *key_ead)
|
||||
|
||||
idx = ble_store_config_find_ead(key_ead);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -649,11 +678,13 @@ ble_store_config_delete_ead(const struct ble_store_key_ead *key_ead)
|
||||
idx,
|
||||
&ble_store_config_num_eads);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_config_persist_eads();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -668,6 +699,7 @@ ble_store_config_read_ead(const struct ble_store_key_ead *key_ead,
|
||||
|
||||
idx = ble_store_config_find_ead(key_ead);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -689,6 +721,7 @@ ble_store_config_write_ead(const struct ble_store_value_ead *value_ead)
|
||||
if (ble_store_config_num_eads >= MYNEWT_VAL(BLE_STORE_MAX_EADS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting ead; too many entries (%d)\n",
|
||||
ble_store_config_num_eads);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -700,6 +733,7 @@ ble_store_config_write_ead(const struct ble_store_value_ead *value_ead)
|
||||
|
||||
rc = ble_store_config_persist_eads();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -747,6 +781,7 @@ ble_store_config_delete_local_irk(const struct ble_store_key_local_irk *key_irk)
|
||||
|
||||
idx = ble_store_config_find_local_irk(key_irk);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -755,15 +790,18 @@ ble_store_config_delete_local_irk(const struct ble_store_key_local_irk *key_irk)
|
||||
idx,
|
||||
&ble_store_config_num_local_irks);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_config_persist_local_irk();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -777,12 +815,14 @@ ble_store_config_read_local_irk(const struct ble_store_key_local_irk *key_irk,
|
||||
|
||||
idx = ble_store_config_find_local_irk(key_irk);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
*value_irk = ble_store_config_local_irks[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -804,6 +844,7 @@ ble_store_config_write_local_irk(const struct ble_store_value_local_irk *value_i
|
||||
if (ble_store_config_num_local_irks >= 1) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting local_irk; too many entries (%d)\n",
|
||||
ble_store_config_num_local_irks);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -821,11 +862,15 @@ ble_store_config_write_local_irk(const struct ble_store_value_local_irk *value_i
|
||||
if (appended) {
|
||||
ble_store_config_num_local_irks--;
|
||||
}
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
#endif
|
||||
}
|
||||
@@ -868,18 +913,19 @@ ble_store_config_read_rpa_rec(const struct ble_store_key_rpa_rec *key_rpa_rec,st
|
||||
|
||||
idx = ble_store_config_find_rpa_rec(key_rpa_rec);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
*value_rpa_rec = ble_store_config_rpa_recs[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
ble_store_config_write_rpa_rec(const struct ble_store_value_rpa_rec *value_rpa_rec){
|
||||
|
||||
#if MYNEWT_VAL(BLE_STORE_MAX_BONDS)
|
||||
struct ble_store_key_rpa_rec key_rpa_rec;
|
||||
int idx;
|
||||
@@ -891,6 +937,7 @@ ble_store_config_write_rpa_rec(const struct ble_store_value_rpa_rec *value_rpa_r
|
||||
if (ble_store_config_num_rpa_recs >= MYNEWT_VAL(BLE_STORE_MAX_BONDS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting peer addrr; too many entries (%d)\n",
|
||||
ble_store_config_num_rpa_recs);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -901,10 +948,12 @@ ble_store_config_write_rpa_rec(const struct ble_store_value_rpa_rec *value_rpa_r
|
||||
|
||||
rc = ble_store_config_persist_rpa_recs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -918,6 +967,7 @@ ble_store_config_delete_rpa_rec(const struct ble_store_key_rpa_rec *key_rpa_rec)
|
||||
|
||||
idx = ble_store_config_find_rpa_rec(key_rpa_rec);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -926,16 +976,19 @@ ble_store_config_delete_rpa_rec(const struct ble_store_key_rpa_rec *key_rpa_rec)
|
||||
idx,
|
||||
&ble_store_config_num_rpa_recs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_config_persist_rpa_recs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -981,6 +1034,7 @@ ble_store_config_delete_csfc(const struct ble_store_key_csfc *key_csfc)
|
||||
idx = ble_store_config_find_csfc(key_csfc, ble_store_config_csfcs,
|
||||
ble_store_config_num_csfcs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -989,16 +1043,19 @@ ble_store_config_delete_csfc(const struct ble_store_key_csfc *key_csfc)
|
||||
idx, &ble_store_config_num_csfcs);
|
||||
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ble_store_config_persist_csfcs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -1013,12 +1070,14 @@ ble_store_config_read_csfc(const struct ble_store_key_csfc *key_csfc,
|
||||
idx = ble_store_config_find_csfc(key_csfc, ble_store_config_csfcs,
|
||||
ble_store_config_num_csfcs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
*value_csfc = ble_store_config_csfcs[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -1038,6 +1097,7 @@ ble_store_config_write_csfc(const struct ble_store_value_csfc *value_csfc)
|
||||
if (ble_store_config_num_csfcs >= MYNEWT_VAL(BLE_STORE_MAX_CSFCS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting csfc; too many entries (%d)\n",
|
||||
ble_store_config_num_csfcs);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -1049,11 +1109,13 @@ ble_store_config_write_csfc(const struct ble_store_value_csfc *value_csfc)
|
||||
|
||||
rc = ble_store_config_persist_csfcs();
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -1117,6 +1179,7 @@ ble_store_config_read(int obj_type, const union ble_store_key *key,
|
||||
rc = ble_store_config_read_local_irk(&key->local_irk, &value->local_irk);
|
||||
return rc;
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
}
|
||||
@@ -1163,6 +1226,7 @@ ble_store_config_write(int obj_type, const union ble_store_value *val)
|
||||
return rc;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
}
|
||||
@@ -1205,6 +1269,7 @@ ble_store_config_delete(int obj_type, const union ble_store_key *key)
|
||||
return rc;
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_STORE_CONFIG_PERSIST)
|
||||
|
||||
@@ -161,6 +162,7 @@ get_nvs_peer_record(char *key_string, struct ble_hs_dev_records *p_dev_rec)
|
||||
err = nvs_open(NIMBLE_NVS_NAMESPACE, NVS_READWRITE, &nimble_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "NVS open operation failed");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -222,6 +224,7 @@ get_nvs_db_value(int obj_type, char *key_string, union ble_store_value *val)
|
||||
err = nvs_open(NIMBLE_NVS_NAMESPACE, NVS_READWRITE, &nimble_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "NVS open operation failed");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -386,12 +389,14 @@ ble_nvs_delete_value(int obj_type, int index)
|
||||
|
||||
if (index <= 0 || index > get_nvs_max_obj_value(obj_type)) {
|
||||
ESP_LOGE(TAG, "Invalid index provided to delete");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_EUNKNOWN);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
err = nvs_open(NIMBLE_NVS_NAMESPACE, NVS_READWRITE, &nimble_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "NVS open operation failed !!");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -411,6 +416,7 @@ ble_nvs_delete_value(int obj_type, int index)
|
||||
return 0;
|
||||
error:
|
||||
nvs_close(nimble_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -423,6 +429,7 @@ ble_nvs_write_key_value(char *key, const void *value, size_t required_size)
|
||||
err = nvs_open(NIMBLE_NVS_NAMESPACE, NVS_READWRITE, &nimble_handle);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "NVS open operation failed !!");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -443,6 +450,7 @@ ble_nvs_write_key_value(char *key, const void *value, size_t required_size)
|
||||
return 0;
|
||||
error:
|
||||
nvs_close(nimble_handle);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -460,12 +468,14 @@ ble_store_nvs_write(int obj_type, const union ble_store_value *val)
|
||||
write_key_index = get_nvs_db_attribute(obj_type, 1, NULL, 0);
|
||||
if (write_key_index == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed !!");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
} else if (write_key_index > get_nvs_max_obj_value(obj_type)) {
|
||||
|
||||
/* bare-bone config code will take care of capacity overflow event,
|
||||
* however another check added for consistency */
|
||||
ESP_LOGD(TAG, "NVS size overflow.");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -507,12 +517,14 @@ ble_store_nvs_peer_records(int obj_type, const struct ble_hs_dev_records *p_dev_
|
||||
write_key_index = get_nvs_db_attribute(obj_type, 1, NULL, 0);
|
||||
if (write_key_index == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed !!");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
} else if (write_key_index > get_nvs_max_obj_value(obj_type)) {
|
||||
|
||||
/* bare-bone config code will take care of capacity overflow event,
|
||||
* however another check added for consistency */
|
||||
ESP_LOGD(TAG, "NVS size overflow.");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -801,6 +813,7 @@ int ble_store_config_persist_cccds(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_CCCD, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting CCCD");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -816,6 +829,7 @@ int ble_store_config_persist_cccds(void)
|
||||
ble_store_config_cccds, ble_store_config_num_cccds);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for CCCD");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting CCCD, nvs idx = %d", nvs_idx);
|
||||
@@ -834,6 +848,7 @@ int ble_store_config_persist_csfcs(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_CSFC, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting CSFC");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -848,6 +863,7 @@ int ble_store_config_persist_csfcs(void)
|
||||
ble_store_config_csfcs, ble_store_config_num_csfcs);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for CSFC");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting CSFC, nvs idx = %d", nvs_idx);
|
||||
@@ -866,6 +882,7 @@ int ble_store_config_persist_eads(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_ENC_ADV_DATA, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting EAD");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -880,6 +897,7 @@ int ble_store_config_persist_eads(void)
|
||||
ble_store_config_eads, ble_store_config_num_eads);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for EAD");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting EAD, nvs idx = %d", nvs_idx);
|
||||
@@ -896,6 +914,7 @@ int ble_store_config_persist_local_irk(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_LOCAL_IRK, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting Local IRK");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -910,6 +929,7 @@ int ble_store_config_persist_local_irk(void)
|
||||
ble_store_config_local_irks, ble_store_config_num_local_irks);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for Local IRK");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting Local IRK, nvs idx = %d", nvs_idx);
|
||||
@@ -925,6 +945,7 @@ int ble_store_config_persist_rpa_recs(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_PEER_ADDR, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting RPA_RECS");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
if (nvs_count < ble_store_config_num_rpa_recs) {
|
||||
@@ -938,6 +959,7 @@ int ble_store_config_persist_rpa_recs(void)
|
||||
ble_store_config_rpa_recs, ble_store_config_num_rpa_recs);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for RPA_REC");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting RPA_REC, nvs idx = %d", nvs_idx);
|
||||
@@ -955,6 +977,7 @@ int ble_store_config_persist_peer_secs(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_PEER_SEC, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting peer sec");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -970,6 +993,7 @@ int ble_store_config_persist_peer_secs(void)
|
||||
ble_store_config_peer_secs, ble_store_config_num_peer_secs);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for peer sec");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting peer sec, nvs idx = %d", nvs_idx);
|
||||
@@ -986,6 +1010,7 @@ int ble_store_config_persist_our_secs(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_OUR_SEC, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting our sec");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -1001,6 +1026,7 @@ int ble_store_config_persist_our_secs(void)
|
||||
ble_store_config_our_secs, ble_store_config_num_our_secs);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for our sec");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting our sec, nvs idx = %d", nvs_idx);
|
||||
@@ -1020,6 +1046,7 @@ int ble_store_persist_peer_records(void)
|
||||
nvs_count = get_nvs_db_attribute(BLE_STORE_OBJ_TYPE_PEER_DEV_REC, 0, NULL, 0);
|
||||
if (nvs_count == -1) {
|
||||
ESP_LOGE(TAG, "NVS operation failed while persisting peer_dev_rec");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
|
||||
@@ -1036,6 +1063,7 @@ int ble_store_persist_peer_records(void)
|
||||
ble_store_num_peer_dev_rec);
|
||||
if (nvs_idx == -1) {
|
||||
ESP_LOGE(TAG, "NVS delete operation failed for peer records");
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_FAIL);
|
||||
return BLE_HS_ESTORE_FAIL;
|
||||
}
|
||||
ESP_LOGD(TAG, "Deleting peer record, nvs idx = %d", nvs_idx);
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "store/ram/ble_store_ram.h"
|
||||
#include "host/ble_hs_log.h"
|
||||
|
||||
#if !MYNEWT_VAL(BLE_USED_IN_IDF)
|
||||
#if MYNEWT_VAL(BLE_STORE_MAX_BONDS)
|
||||
@@ -147,12 +148,14 @@ ble_store_ram_read_our_sec(const struct ble_store_key_sec *key_sec,
|
||||
idx = ble_store_ram_find_sec(key_sec, ble_store_ram_our_secs,
|
||||
ble_store_ram_num_our_secs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
*value_sec = ble_store_ram_our_secs[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -175,6 +178,7 @@ ble_store_ram_write_our_sec(const struct ble_store_value_sec *value_sec)
|
||||
if (ble_store_ram_num_our_secs >= MYNEWT_VAL(BLE_STORE_MAX_BONDS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting our sec; too many entries "
|
||||
"(%d)\n", ble_store_ram_num_our_secs);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -186,6 +190,7 @@ ble_store_ram_write_our_sec(const struct ble_store_value_sec *value_sec)
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -226,12 +231,14 @@ ble_store_ram_delete_sec(const struct ble_store_key_sec *key_sec,
|
||||
|
||||
idx = ble_store_ram_find_sec(key_sec, value_secs, *num_value_secs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
rc = ble_store_ram_delete_obj(value_secs, sizeof *value_secs, idx,
|
||||
num_value_secs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -248,10 +255,12 @@ ble_store_ram_delete_our_sec(const struct ble_store_key_sec *key_sec)
|
||||
rc = ble_store_ram_delete_sec(key_sec, ble_store_ram_our_secs,
|
||||
&ble_store_ram_num_our_secs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -266,10 +275,12 @@ ble_store_ram_delete_peer_sec(const struct ble_store_key_sec *key_sec)
|
||||
rc = ble_store_ram_delete_sec(key_sec, ble_store_ram_peer_secs,
|
||||
&ble_store_ram_num_peer_secs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -285,12 +296,14 @@ ble_store_ram_read_peer_sec(const struct ble_store_key_sec *key_sec,
|
||||
idx = ble_store_ram_find_sec(key_sec, ble_store_ram_peer_secs,
|
||||
ble_store_ram_num_peer_secs);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
*value_sec = ble_store_ram_peer_secs[idx];
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -313,6 +326,7 @@ ble_store_ram_write_peer_sec(const struct ble_store_value_sec *value_sec)
|
||||
if (ble_store_ram_num_peer_secs >= MYNEWT_VAL(BLE_STORE_MAX_BONDS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting peer sec; too many entries "
|
||||
"(%d)\n", ble_store_ram_num_peer_secs);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -323,6 +337,7 @@ ble_store_ram_write_peer_sec(const struct ble_store_value_sec *value_sec)
|
||||
ble_store_ram_peer_secs[idx] = *value_sec;
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -377,6 +392,7 @@ ble_store_ram_delete_cccd(const struct ble_store_key_cccd *key_cccd)
|
||||
|
||||
idx = ble_store_ram_find_cccd(key_cccd);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -385,10 +401,12 @@ ble_store_ram_delete_cccd(const struct ble_store_key_cccd *key_cccd)
|
||||
idx,
|
||||
&ble_store_ram_num_cccds);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -403,6 +421,7 @@ ble_store_ram_read_cccd(const struct ble_store_key_cccd *key_cccd,
|
||||
|
||||
idx = ble_store_ram_find_cccd(key_cccd);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -410,6 +429,7 @@ ble_store_ram_read_cccd(const struct ble_store_key_cccd *key_cccd,
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -427,6 +447,7 @@ ble_store_ram_write_cccd(const struct ble_store_value_cccd *value_cccd)
|
||||
if (ble_store_ram_num_cccds >= MYNEWT_VAL(BLE_STORE_MAX_CCCDS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting cccd; too many entries (%d)\n",
|
||||
ble_store_ram_num_cccds);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -437,6 +458,7 @@ ble_store_ram_write_cccd(const struct ble_store_value_cccd *value_cccd)
|
||||
ble_store_ram_cccds[idx] = *value_cccd;
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
|
||||
@@ -485,6 +507,7 @@ ble_store_ram_delete_csfc(const struct ble_store_key_csfc *key_csfc)
|
||||
|
||||
idx = ble_store_ram_find_csfc(key_csfc);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -493,10 +516,12 @@ ble_store_ram_delete_csfc(const struct ble_store_key_csfc *key_csfc)
|
||||
idx,
|
||||
&ble_store_ram_num_csfcs);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -510,6 +535,7 @@ ble_store_ram_read_csfc(const struct ble_store_key_csfc *key_csfc,
|
||||
|
||||
idx = ble_store_ram_find_csfc(key_csfc);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -517,6 +543,7 @@ ble_store_ram_read_csfc(const struct ble_store_key_csfc *key_csfc,
|
||||
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -534,6 +561,7 @@ ble_store_ram_write_csfc(const struct ble_store_value_csfc *value_csfc)
|
||||
if (ble_store_ram_num_csfcs >= MYNEWT_VAL(BLE_STORE_MAX_CSFCS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting csfc; too many entries (%d)\n",
|
||||
ble_store_ram_num_csfcs);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -544,6 +572,7 @@ ble_store_ram_write_csfc(const struct ble_store_value_csfc *value_csfc)
|
||||
ble_store_ram_csfcs[idx] = *value_csfc;
|
||||
return 0;
|
||||
#else
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
#endif
|
||||
}
|
||||
@@ -588,6 +617,7 @@ ble_store_ram_delete_ead(const struct ble_store_key_ead *key_ead)
|
||||
|
||||
idx = ble_store_ram_find_ead(key_ead);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
rc = ble_store_ram_delete_obj(ble_store_ram_eads,
|
||||
@@ -595,6 +625,7 @@ ble_store_ram_delete_ead(const struct ble_store_key_ead *key_ead)
|
||||
idx,
|
||||
&ble_store_ram_num_eads);
|
||||
if (rc != 0) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, rc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -609,6 +640,7 @@ ble_store_ram_read_ead(const struct ble_store_key_ead *key_ead,
|
||||
|
||||
idx = ble_store_ram_find_ead(key_ead);
|
||||
if (idx == -1) {
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOENT);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
@@ -628,6 +660,7 @@ ble_store_ram_write_ead(const struct ble_store_value_ead *value_ead)
|
||||
if (ble_store_ram_num_eads >= MYNEWT_VAL(BLE_STORE_MAX_EADS)) {
|
||||
BLE_HS_LOG(DEBUG, "error persisting ead; too many entries (%d)\n",
|
||||
ble_store_ram_num_eads);
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ESTORE_CAP);
|
||||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
@@ -693,6 +726,7 @@ ble_store_ram_read(int obj_type, const union ble_store_key *key,
|
||||
#endif
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
}
|
||||
@@ -732,6 +766,7 @@ ble_store_ram_write(int obj_type, const union ble_store_value *val)
|
||||
#endif
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
}
|
||||
@@ -765,6 +800,7 @@ ble_store_ram_delete(int obj_type, const union ble_store_key *key)
|
||||
#endif
|
||||
|
||||
default:
|
||||
BLE_HS_LOG(ERROR, "%s rc=%d\n", __func__, BLE_HS_ENOTSUP);
|
||||
return BLE_HS_ENOTSUP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
#include "log/log.h"
|
||||
#include "log_common/log_common.h"
|
||||
|
||||
#if CONFIG_BLE_HOST_NIMBLE_COMPRESSED_LOG_ENABLE
|
||||
#include "nimble_log_index.h"
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_LOG_ENABLED
|
||||
#include "ble_log.h"
|
||||
#endif
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_log.h"
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "modlog/modlog.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#if CONFIG_BLE_LOG_ENABLED
|
||||
void MODLOG_INFO(int mod, char * msg, ...) {
|
||||
char buffer[1000];
|
||||
int len;
|
||||
va_list args;
|
||||
|
||||
memset(buffer, 0, 1000);
|
||||
va_start(args, msg);
|
||||
len = sprintf(buffer, args);
|
||||
va_end(args);
|
||||
|
||||
ble_log_write_hex(BLE_LOG_SRC_HOST, (uint8_t *)buffer, len);
|
||||
ble_log_flush();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user