feat(nimble): Added some fixes to pass PTS cases

This commit is contained in:
Sumeet Singh
2025-02-12 17:55:05 +05:30
parent 0ea32c88c7
commit 7d06b1c8ca
20 changed files with 155 additions and 31 deletions
+1 -1
View File
@@ -216,7 +216,7 @@ static void
blecent_scan(void) blecent_scan(void)
{ {
uint8_t own_addr_type; uint8_t own_addr_type;
struct ble_gap_disc_params disc_params; struct ble_gap_disc_params disc_params = {0};
int rc; int rc;
/* Figure out address to use while advertising (no privacy for now) */ /* Figure out address to use while advertising (no privacy for now) */
+6
View File
@@ -344,6 +344,9 @@ struct ble_gap_ext_disc_params {
/** If passive scan should be used */ /** If passive scan should be used */
uint8_t passive:1; uint8_t passive:1;
/** If observation procedure is to be disabled. By default all advertisement reports are accepted */
uint8_t disable_observer_mode:1;
}; };
/** @brief Discovery parameters */ /** @brief Discovery parameters */
@@ -365,6 +368,9 @@ struct ble_gap_disc_params {
/** If enable duplicates filtering */ /** If enable duplicates filtering */
uint8_t filter_duplicates:1; uint8_t filter_duplicates:1;
/** If observation procedure is to be disabled. By default all advertisement reports are accepted */
uint8_t disable_observer_mode:1;
}; };
/** @brief Connection parameters update parameters */ /** @brief Connection parameters update parameters */
+14
View File
@@ -323,6 +323,17 @@ struct ble_hs_cfg {
*/ */
unsigned sm_sc_only:1; unsigned sm_sc_only:1;
/** @brief Security Manager - Security Mode 1 Level for GATT related operations
*
* Possible values are:
* 0: Default value, ignored
* 1: No security
* 2: Unauthenticated pairing with encryption
* 3. Authenticated pairing with encryption
* 4. Authenticated LE Secure Connections pairing with encryption using a 128-bit strength encryption key
*/
uint8_t sm_sec_lvl;
/** @brief Security Manager Key Press Notification flag /** @brief Security Manager Key Press Notification flag
* *
* Currently unsupported and should not be set. * Currently unsupported and should not be set.
@@ -344,6 +355,9 @@ struct ble_hs_cfg {
/** @brief Security Manager Remote Key Distribution Mask */ /** @brief Security Manager Remote Key Distribution Mask */
uint8_t sm_their_key_dist; uint8_t sm_their_key_dist;
/** @brief Weather to use GATT caching or not for discovery operations */
uint8_t gatt_use_cache;
/** @brief Stack reset callback /** @brief Stack reset callback
* *
* This callback is executed when the host resets itself and the controller * This callback is executed when the host resets itself and the controller
+1 -1
View File
@@ -217,7 +217,7 @@ int bt_mesh_scan_enable(void)
#if MYNEWT_VAL(BLE_EXT_ADV) #if MYNEWT_VAL(BLE_EXT_ADV)
struct ble_gap_ext_disc_params uncoded_params = struct ble_gap_ext_disc_params uncoded_params =
{ .itvl = MESH_SCAN_INTERVAL, .window = MESH_SCAN_WINDOW, { .itvl = MESH_SCAN_INTERVAL, .window = MESH_SCAN_WINDOW,
.passive = 1 }; .passive = 1, .disable_observer_mode = 0};
BT_DBG(""); BT_DBG("");
@@ -34,6 +34,7 @@ extern "C" {
#define BLE_SVC_GAP_CHR_UUID16_APPEARANCE 0x2a01 #define BLE_SVC_GAP_CHR_UUID16_APPEARANCE 0x2a01
#define BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS 0x2a04 #define BLE_SVC_GAP_CHR_UUID16_PERIPH_PREF_CONN_PARAMS 0x2a04
#define BLE_SVC_GAP_CHR_UUID16_CENTRAL_ADDRESS_RESOLUTION 0x2aa6 #define BLE_SVC_GAP_CHR_UUID16_CENTRAL_ADDRESS_RESOLUTION 0x2aa6
#define BLE_SVC_GAP_CHR_UUID16_RPA_ONLY 0x2AC9
#define BLE_SVC_GAP_CHR_UUID16_LE_GATT_SECURITY_LEVELS 0x2BF5 #define BLE_SVC_GAP_CHR_UUID16_LE_GATT_SECURITY_LEVELS 0x2BF5
#if MYNEWT_VAL(ENC_ADV_DATA) #if MYNEWT_VAL(ENC_ADV_DATA)
@@ -95,6 +95,13 @@ static const struct ble_gatt_svc_def ble_svc_gap_defs[] = {
.flags = BLE_GATT_CHR_F_READ, .flags = BLE_GATT_CHR_F_READ,
}, { }, {
#endif #endif
#if MYNEWT_VAL(BLE_SVC_GAP_RPA_ONLY)
/*** Characteristic: Resolvable Private Address Only. */
.uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_RPA_ONLY),
.access_cb = ble_svc_gap_access,
.flags = BLE_GATT_CHR_F_READ,
}, {
#endif
#if MYNEWT_VAL(ENC_ADV_DATA) #if MYNEWT_VAL(ENC_ADV_DATA)
.uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_KEY_MATERIAL), .uuid = BLE_UUID16_DECLARE(BLE_SVC_GAP_CHR_UUID16_KEY_MATERIAL),
.access_cb = ble_svc_gap_access, .access_cb = ble_svc_gap_access,
@@ -234,6 +241,15 @@ ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle,
htole16(MYNEWT_VAL(BLE_SVC_GAP_PPCP_SLAVE_LATENCY)), htole16(MYNEWT_VAL(BLE_SVC_GAP_PPCP_SLAVE_LATENCY)),
htole16(MYNEWT_VAL(BLE_SVC_GAP_PPCP_SUPERVISION_TMO)) htole16(MYNEWT_VAL(BLE_SVC_GAP_PPCP_SUPERVISION_TMO))
}; };
#endif
#if MYNEWT_VAL(BLE_SVC_GAP_RPA_ONLY)
/* As per Core Specification 6.0, Vol 3: Host, Part C: GAP, 12.5
* The only allowed value for the characteristic is zero.
* All other values are RFU.
* As such, the presence of the characteristic itself indicates that
* the device is RPA only
*/
uint8_t rpa_only = 0;
#endif #endif
int rc; int rc;
@@ -277,6 +293,13 @@ ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle,
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
#endif #endif
#if MYNEWT_VAL(BLE_SVC_GAP_RPA_ONLY)
case BLE_SVC_GAP_CHR_UUID16_RPA_ONLY:
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
rc = os_mbuf_append(ctxt->om, &rpa_only, sizeof(rpa_only));
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
#endif
#if MYNEWT_VAL(ENC_ADV_DATA) #if MYNEWT_VAL(ENC_ADV_DATA)
case BLE_SVC_GAP_CHR_UUID16_KEY_MATERIAL: case BLE_SVC_GAP_CHR_UUID16_KEY_MATERIAL:
rc = os_mbuf_append(ctxt->om, &(km.session_key), sizeof(km.session_key)); rc = os_mbuf_append(ctxt->om, &(km.session_key), sizeof(km.session_key));
@@ -65,6 +65,8 @@ struct ble_svc_hid_params{
unsigned int kbd_inp_present : 1; unsigned int kbd_inp_present : 1;
unsigned int kbd_out_present : 1; unsigned int kbd_out_present : 1;
unsigned int mouse_inp_present : 1; unsigned int mouse_inp_present : 1;
unsigned int kbd_inp_write_perm:1;
unsigned int mouse_inp_write_perm:1;
/* protocol mode char */ /* protocol mode char */
uint8_t proto_mode; uint8_t proto_mode;
uint16_t proto_mode_handle; uint16_t proto_mode_handle;
+24 -2
View File
@@ -180,10 +180,21 @@ void
fill_boot_kbd_inp(uint8_t instance) fill_boot_kbd_inp(uint8_t instance)
{ {
struct ble_gatt_chr_def *chr, demo_chr; struct ble_gatt_chr_def *chr, demo_chr;
uint16_t write_flags;
if (!hid_instances[instance].kbd_inp_present) { if (!hid_instances[instance].kbd_inp_present) {
return; return;
} }
write_flags = BLE_GATT_CHR_F_WRITE |
#if MYNEWT_VAL(BLE_SM_LVL) == 2
BLE_GATT_CHR_F_WRITE_ENC |
#elif MYNEWT_VAL(BLE_SM_LVL) == 3
BLE_GATT_CHR_F_WRITE_ENC | BLE_GATT_CHR_F_WRITE_AUTHEN
#endif
0;
write_flags = (hid_instances[instance].kbd_inp_write_perm ? write_flags : 0);
demo_chr = (struct ble_gatt_chr_def) { demo_chr = (struct ble_gatt_chr_def) {
/*** Report Map characteristic */ /*** Report Map characteristic */
.uuid = uuid_boot_kbd_inp, .uuid = uuid_boot_kbd_inp,
@@ -196,7 +207,7 @@ fill_boot_kbd_inp(uint8_t instance)
BLE_GATT_CHR_F_READ_AUTHEN | BLE_GATT_CHR_F_READ_AUTHEN |
BLE_GATT_CHR_F_READ_ENC | BLE_GATT_CHR_F_READ_ENC |
#endif #endif
0, write_flags,
}; };
chr = ble_svc_hid_get_chr_block(); chr = ble_svc_hid_get_chr_block();
@@ -236,10 +247,21 @@ void
fill_boot_mouse_inp(uint8_t instance) fill_boot_mouse_inp(uint8_t instance)
{ {
struct ble_gatt_chr_def *chr, demo_chr; struct ble_gatt_chr_def *chr, demo_chr;
uint16_t write_flags;
if (!hid_instances[instance].mouse_inp_present) { if (!hid_instances[instance].mouse_inp_present) {
return; return;
} }
write_flags = BLE_GATT_CHR_F_WRITE |
#if MYNEWT_VAL(BLE_SM_LVL) == 2
BLE_GATT_CHR_F_WRITE_ENC |
#elif MYNEWT_VAL(BLE_SM_LVL) == 3
BLE_GATT_CHR_F_WRITE_ENC | BLE_GATT_CHR_F_WRITE_AUTHEN
#endif
0;
write_flags = (hid_instances[instance].mouse_inp_write_perm ? write_flags : 0);
demo_chr = (struct ble_gatt_chr_def) { demo_chr = (struct ble_gatt_chr_def) {
/*** Report Map characteristic */ /*** Report Map characteristic */
.uuid = uuid_boot_mouse_inp, .uuid = uuid_boot_mouse_inp,
@@ -252,7 +274,7 @@ fill_boot_mouse_inp(uint8_t instance)
BLE_GATT_CHR_F_READ_AUTHEN | BLE_GATT_CHR_F_READ_AUTHEN |
BLE_GATT_CHR_F_READ_ENC | BLE_GATT_CHR_F_READ_ENC |
#endif #endif
0, write_flags,
}; };
chr = ble_svc_hid_get_chr_block(); chr = ble_svc_hid_get_chr_block();
@@ -134,7 +134,9 @@ void
ble_svc_lls_on_gap_disconnect(int reason) ble_svc_lls_on_gap_disconnect(int reason)
{ {
if (reason == BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) { if (reason == BLE_HS_HCI_ERR(BLE_ERR_CONN_SPVN_TMO)) {
if (ble_svc_lls_cb_fn != NULL) {
ble_svc_lls_cb_fn(ble_svc_lls_alert_level); ble_svc_lls_cb_fn(ble_svc_lls_alert_level);
}
} }
} }
@@ -27,6 +27,9 @@
#define BLE_SVC_SPS_CHR_UUID16_SCAN_ITVL_WINDOW 0x2A4F #define BLE_SVC_SPS_CHR_UUID16_SCAN_ITVL_WINDOW 0x2A4F
#define BLE_SVC_SPS_CHR_UUID16_SCAN_REFRESH 0x2A31 #define BLE_SVC_SPS_CHR_UUID16_SCAN_REFRESH 0x2A31
typedef int ble_svc_sps_event_fn(uint16_t scan_interval, uint16_t scan_window);
void ble_svc_sps_scan_refresh(void); void ble_svc_sps_scan_refresh(void);
void ble_svc_sps_init(uint16_t scan_itvl, uint16_t scan_window); void ble_svc_sps_init(uint16_t scan_itvl, uint16_t scan_window);
void ble_svc_sps_set_cb(ble_svc_sps_event_fn *cb);
#endif #endif
@@ -29,6 +29,7 @@ static uint8_t ble_scan_refresh;
static uint16_t ble_scan_itvl_handle; static uint16_t ble_scan_itvl_handle;
static uint16_t ble_scan_refresh_handle; static uint16_t ble_scan_refresh_handle;
static ble_svc_sps_event_fn *ble_svc_sps_cb_fn;
/* Access function */ /* Access function */
static int static int
@@ -104,6 +105,9 @@ ble_svc_sps_access(uint16_t conn_handle, uint16_t attr_handle,
ble_scan_itvl = (write_val & 0xffff0000) >> 16; ble_scan_itvl = (write_val & 0xffff0000) >> 16;
ble_scan_window = (write_val & 0x0000ffff); ble_scan_window = (write_val & 0x0000ffff);
} }
if (ble_svc_sps_cb_fn) {
ble_svc_sps_cb_fn(ble_scan_itvl, ble_scan_window);
}
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
case BLE_SVC_SPS_CHR_UUID16_SCAN_REFRESH: case BLE_SVC_SPS_CHR_UUID16_SCAN_REFRESH:
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR && conn_handle == BLE_HS_CONN_HANDLE_NONE); assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR && conn_handle == BLE_HS_CONN_HANDLE_NONE);
@@ -118,6 +122,11 @@ ble_svc_sps_access(uint16_t conn_handle, uint16_t attr_handle,
return 0; return 0;
} }
void
ble_svc_sps_set_cb(ble_svc_sps_event_fn *cb)
{
ble_svc_sps_cb_fn = cb;
}
/** /**
* Initialize the SPS package. * Initialize the SPS package.
+2 -2
View File
@@ -2983,7 +2983,7 @@ ble_att_svr_rx_notify(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxom)
/* All indications shall be confirmed, but only these with required /* All indications shall be confirmed, but only these with required
* security established shall be pass to application * security established shall be pass to application
*/ */
if (MYNEWT_VAL(BLE_SM_LVL) >= 2 && !sec_state.encrypted) { if (ble_hs_cfg.sm_sec_lvl >= 2 && !sec_state.encrypted) {
return 0; return 0;
} }
@@ -3135,7 +3135,7 @@ ble_att_svr_rx_indicate(uint16_t conn_handle, uint16_t cid, struct os_mbuf **rxo
/* All indications shall be confirmed, but only these with required /* All indications shall be confirmed, but only these with required
* security established shall be pass to application * security established shall be pass to application
*/ */
if (MYNEWT_VAL(BLE_SM_LVL) >= 2 && !sec_state.encrypted) { if (ble_hs_cfg.sm_sec_lvl >= 2 && !sec_state.encrypted) {
goto done; goto done;
} }
+6 -1
View File
@@ -199,6 +199,7 @@ struct ble_gap_master_state {
struct { struct {
uint8_t limited:1; uint8_t limited:1;
uint8_t observer:1;
} disc; } disc;
}; };
}; };
@@ -1880,7 +1881,7 @@ ble_gap_rx_adv_report_sanity_check(const uint8_t *adv_data, uint8_t adv_data_len
return -1; return -1;
} }
if (MYNEWT_VAL(BLE_ROLE_OBSERVER)) { if (ble_gap_master.disc.observer) {
/* Observer role is enabled; All adv reports regardless of /* Observer role is enabled; All adv reports regardless of
* Flags AD Type need to be discovered. * Flags AD Type need to be discovered.
*/ */
@@ -6211,6 +6212,7 @@ ble_gap_ext_disc(uint8_t own_addr_type, uint16_t duration, uint16_t period,
if (uncoded_params) { if (uncoded_params) {
ble_gap_ext_scan_params_to_hci(uncoded_params, &ucp); ble_gap_ext_scan_params_to_hci(uncoded_params, &ucp);
ble_gap_ext_disc_fill_dflts(limited, &ucp); ble_gap_ext_disc_fill_dflts(limited, &ucp);
ble_gap_master.disc.observer = !uncoded_params->disable_observer_mode;
/* XXX: We should do it only once */ /* XXX: We should do it only once */
if (!uncoded_params->passive) { if (!uncoded_params->passive) {
@@ -6224,6 +6226,7 @@ ble_gap_ext_disc(uint8_t own_addr_type, uint16_t duration, uint16_t period,
if (coded_params) { if (coded_params) {
ble_gap_ext_scan_params_to_hci(coded_params, &cp); ble_gap_ext_scan_params_to_hci(coded_params, &cp);
ble_gap_ext_disc_fill_dflts(limited, &cp); ble_gap_ext_disc_fill_dflts(limited, &cp);
ble_gap_master.disc.observer = !coded_params->disable_observer_mode;
/* XXX: We should do it only once */ /* XXX: We should do it only once */
if (!coded_params->passive) { if (!coded_params->passive) {
@@ -6337,6 +6340,7 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
p.itvl = disc_params->itvl; p.itvl = disc_params->itvl;
p.passive = disc_params->passive; p.passive = disc_params->passive;
p.window = disc_params->window; p.window = disc_params->window;
p.disable_observer_mode = disc_params->disable_observer_mode;
if (duration_ms == BLE_HS_FOREVER) { if (duration_ms == BLE_HS_FOREVER) {
duration_ms = 0; duration_ms = 0;
@@ -6393,6 +6397,7 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
} }
ble_gap_master.disc.limited = params.limited; ble_gap_master.disc.limited = params.limited;
ble_gap_master.disc.observer = !params.disable_observer_mode;
ble_gap_master.cb = cb; ble_gap_master.cb = cb;
ble_gap_master.cb_arg = cb_arg; ble_gap_master.cb_arg = cb_arg;
+19 -16
View File
@@ -35,6 +35,9 @@
#define CHECK_CACHE_CONN_STATE(cache_state, cb, cb_arg, opcode, \ #define CHECK_CACHE_CONN_STATE(cache_state, cb, cb_arg, opcode, \
s_handle, e_handle, p_uuid) \ s_handle, e_handle, p_uuid) \
if (ble_hs_cfg.gatt_use_cache == 0) { \
return BLE_HS_ENOTSUP; \
} \
op = &conn->pending_op; \ op = &conn->pending_op; \
switch(cache_state) { \ switch(cache_state) { \
case SVC_DISC_IN_PROGRESS: \ case SVC_DISC_IN_PROGRESS: \
@@ -829,7 +832,7 @@ ble_gattc_cache_conn_disc_complete(struct ble_gattc_cache_conn *peer, int rc)
} }
break; break;
case BLE_GATT_OP_DISC_SVC_UUID : case BLE_GATT_OP_DISC_SVC_UUID :
rc = ble_gattc_cache_conn_search_svc_by_uuid(peer->conn_handle, &op->uuid, op->cb, op->cb_arg); rc = ble_gattc_cache_conn_search_svc_by_uuid(peer->conn_handle, op->uuid, op->cb, op->cb_arg);
if (rc != 0) { if (rc != 0) {
BLE_HS_LOG(ERROR, "search service by uuid failed"); BLE_HS_LOG(ERROR, "search service by uuid failed");
} }
@@ -847,7 +850,7 @@ ble_gattc_cache_conn_disc_complete(struct ble_gattc_cache_conn *peer, int rc)
} }
break; break;
case BLE_GATT_OP_DISC_CHR_UUID : case BLE_GATT_OP_DISC_CHR_UUID :
rc = ble_gattc_cache_conn_search_chrs_by_uuid(peer->conn_handle, op->start_handle, op->end_handle, &op->uuid, op->cb, op->cb_arg); rc = ble_gattc_cache_conn_search_chrs_by_uuid(peer->conn_handle, op->start_handle, op->end_handle, op->uuid, op->cb, op->cb_arg);
if (rc != 0) { if (rc != 0) {
BLE_HS_LOG(ERROR, "search chars by uuid failed"); BLE_HS_LOG(ERROR, "search chars by uuid failed");
} }
@@ -1267,7 +1270,7 @@ ble_gattc_cache_conn_get_svc_changed_handle(uint16_t conn_handle)
BLE_UUID16_DECLARE(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16)); BLE_UUID16_DECLARE(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16));
if (chr == NULL) { if (chr == NULL) {
BLE_HS_LOG(ERROR, "Cannot find service change characteristic"); BLE_HS_LOG(DEBUG, "Cannot find service change characteristic");
return -1; return -1;
} }
return chr->chr.val_handle; return chr->chr.val_handle;
@@ -1299,12 +1302,12 @@ ble_gattc_cache_conn_init()
int max_dscs; int max_dscs;
void *storage_cb; void *storage_cb;
max_ble_gattc_cache_conns = MYNEWT_VAL(BLE_MAX_CONNECTIONS); max_ble_gattc_cache_conns = MYNEWT_VAL(BLE_GATT_CACHING_MAX_CONNS);
max_svcs = (MYNEWT_VAL(BLE_MAX_CONNECTIONS)) * max_svcs = (MYNEWT_VAL(BLE_GATT_CACHING_MAX_CONNS)) *
(MYNEWT_VAL(BLE_GATT_CACHING_MAX_SVCS)); (MYNEWT_VAL(BLE_GATT_CACHING_MAX_SVCS));
max_chrs = (MYNEWT_VAL(BLE_MAX_CONNECTIONS)) * max_chrs = (MYNEWT_VAL(BLE_GATT_CACHING_MAX_CONNS)) *
(MYNEWT_VAL(BLE_GATT_CACHING_MAX_CHRS)); (MYNEWT_VAL(BLE_GATT_CACHING_MAX_CHRS));
max_dscs = (MYNEWT_VAL(BLE_MAX_CONNECTIONS)) * max_dscs = (MYNEWT_VAL(BLE_GATT_CACHING_MAX_CONNS)) *
(MYNEWT_VAL(BLE_GATT_CACHING_MAX_DSCS)); (MYNEWT_VAL(BLE_GATT_CACHING_MAX_DSCS));
/* Free memory first in case this function gets called more than once. */ /* Free memory first in case this function gets called more than once. */
ble_gattc_cache_conn_free_mem(); ble_gattc_cache_conn_free_mem();
@@ -1470,7 +1473,7 @@ static void ble_gattc_cache_search_all_svcs_cb(struct ble_npl_event *ev)
static void ble_gattc_cache_conn_fill_op(struct ble_gattc_cache_conn_op *op, static void ble_gattc_cache_conn_fill_op(struct ble_gattc_cache_conn_op *op,
uint16_t start_handle, uint16_t start_handle,
uint16_t end_handle, uint16_t end_handle,
ble_uuid_t uuid, const ble_uuid_t *uuid,
void *cb, void *cb,
void *cb_arg, void *cb_arg,
uint8_t cb_type) uint8_t cb_type)
@@ -1505,7 +1508,7 @@ ble_gattc_cache_conn_search_all_svcs(uint16_t conn_handle,
} }
CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_SVCS, CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_SVCS,
0, 0, uuid); 0, 0, &uuid);
/* put the event in the queue to mimic the gattc behaviour */ /* put the event in the queue to mimic the gattc behaviour */
ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_search_all_svcs_cb, &conn->conn_handle); ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_search_all_svcs_cb, &conn->conn_handle);
ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev); ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev);
@@ -1534,7 +1537,7 @@ ble_gattc_cache_conn_search_svc_by_uuid_cb(struct ble_npl_event *ev)
op = &conn->pending_op; op = &conn->pending_op;
dcb = op->cb; dcb = op->cb;
SLIST_FOREACH(svc, &conn->svcs, next) { SLIST_FOREACH(svc, &conn->svcs, next) {
if (svc->type == BLE_GATT_SVC_TYPE_PRIMARY && ble_uuid_cmp(&svc->svc.uuid.u, &op->uuid) == 0) { if (svc->type == BLE_GATT_SVC_TYPE_PRIMARY && ble_uuid_cmp(&svc->svc.uuid.u, op->uuid) == 0) {
dcb(conn_handle, ble_gattc_cache_error(status, 0), &svc->svc, op->cb_arg); dcb(conn_handle, ble_gattc_cache_error(status, 0), &svc->svc, op->cb_arg);
} }
} }
@@ -1566,7 +1569,7 @@ ble_gattc_cache_conn_search_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *
} }
CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_SVC_UUID, CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_SVC_UUID,
0, 0, *uuid); 0, 0, uuid);
/* put the event in the queue to mimic the gattc behaviour */ /* put the event in the queue to mimic the gattc behaviour */
ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_svc_by_uuid_cb, &conn->conn_handle); ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_svc_by_uuid_cb, &conn->conn_handle);
ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev); ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev);
@@ -1629,7 +1632,7 @@ ble_gattc_cache_conn_search_inc_svcs(uint16_t conn_handle, uint16_t start_handle
} }
CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_CHRS, CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_CHRS,
start_handle, end_handle, uuid); start_handle, end_handle, &uuid);
/* put the event in the queue to mimic the gattc behaviour */ /* put the event in the queue to mimic the gattc behaviour */
ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_inc_svcs_cb, &conn->conn_handle); ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_inc_svcs_cb, &conn->conn_handle);
ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev); ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev);
@@ -1692,7 +1695,7 @@ ble_gattc_cache_conn_search_all_chrs(uint16_t conn_handle, uint16_t start_handle
} }
CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_CHRS, CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_CHRS,
start_handle, end_handle, uuid); start_handle, end_handle, &uuid);
/* put the event in the queue to mimic the gattc behaviour */ /* put the event in the queue to mimic the gattc behaviour */
ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_all_chrs_cb, &conn->conn_handle); ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_all_chrs_cb, &conn->conn_handle);
ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev); ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev);
@@ -1723,7 +1726,7 @@ ble_gattc_cache_conn_search_chrs_by_uuid_cb(struct ble_npl_event *ev)
svc = ble_gattc_cache_conn_svc_find_range(conn, op->start_handle); svc = ble_gattc_cache_conn_svc_find_range(conn, op->start_handle);
/* return all chrs */ /* return all chrs */
SLIST_FOREACH(chr, &svc->chrs, next) { SLIST_FOREACH(chr, &svc->chrs, next) {
if (ble_uuid_cmp(&chr->chr.uuid.u, &op->uuid) == 0) { if (ble_uuid_cmp(&chr->chr.uuid.u, op->uuid) == 0) {
dcb(conn_handle, ble_gattc_cache_error(status, 0), &chr->chr, op->cb_arg); dcb(conn_handle, ble_gattc_cache_error(status, 0), &chr->chr, op->cb_arg);
} }
} }
@@ -1756,7 +1759,7 @@ ble_gattc_cache_conn_search_chrs_by_uuid(uint16_t conn_handle, uint16_t start_ha
} }
CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_CHR_UUID, CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_CHR_UUID,
start_handle, end_handle, *uuid); start_handle, end_handle, uuid);
/* put the event in the queue to mimic the gattc behaviour */ /* put the event in the queue to mimic the gattc behaviour */
ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_chrs_by_uuid_cb, &conn->conn_handle); ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_chrs_by_uuid_cb, &conn->conn_handle);
ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev); ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev);
@@ -1820,7 +1823,7 @@ ble_gattc_cache_conn_search_all_dscs(uint16_t conn_handle, uint16_t start_handle
} }
CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_DSCS, CHECK_CACHE_CONN_STATE(conn->cache_state, cb, cb_arg, BLE_GATT_OP_DISC_ALL_DSCS,
start_handle, end_handle, uuid); start_handle, end_handle, &uuid);
/* put the event in the queue to mimic the gattc behaviour */ /* put the event in the queue to mimic the gattc behaviour */
ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_all_dscs_cb, &conn->conn_handle); ble_npl_event_init(&conn->disc_ev, ble_gattc_cache_conn_search_all_dscs_cb, &conn->conn_handle);
ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev); ble_npl_eventq_put((struct ble_npl_eventq *)ble_hs_evq_get(), &conn->disc_ev);
+1 -1
View File
@@ -96,7 +96,7 @@ struct ble_gattc_cache_conn_op {
request comes while the cache is building */ request comes while the cache is building */
uint16_t start_handle; uint16_t start_handle;
uint16_t end_handle; uint16_t end_handle;
ble_uuid_t uuid; const ble_uuid_t *uuid;
void *cb; void *cb;
void *cb_arg; void *cb_arg;
uint8_t cb_type; uint8_t cb_type;
+2
View File
@@ -28,8 +28,10 @@ struct ble_hs_cfg ble_hs_cfg = {
.sm_mitm = MYNEWT_VAL(BLE_SM_MITM), .sm_mitm = MYNEWT_VAL(BLE_SM_MITM),
.sm_sc = MYNEWT_VAL(BLE_SM_SC), .sm_sc = MYNEWT_VAL(BLE_SM_SC),
.sm_sc_only = MYNEWT_VAL(BLE_SM_SC_ONLY), .sm_sc_only = MYNEWT_VAL(BLE_SM_SC_ONLY),
.sm_sec_lvl = MYNEWT_VAL(BLE_SM_LVL),
.sm_keypress = MYNEWT_VAL(BLE_SM_KEYPRESS), .sm_keypress = MYNEWT_VAL(BLE_SM_KEYPRESS),
.sm_our_key_dist = MYNEWT_VAL(BLE_SM_OUR_KEY_DIST), .sm_our_key_dist = MYNEWT_VAL(BLE_SM_OUR_KEY_DIST),
.sm_their_key_dist = MYNEWT_VAL(BLE_SM_THEIR_KEY_DIST), .sm_their_key_dist = MYNEWT_VAL(BLE_SM_THEIR_KEY_DIST),
.eatt = MYNEWT_VAL(BLE_EATT_CHAN_NUM), .eatt = MYNEWT_VAL(BLE_EATT_CHAN_NUM),
.gatt_use_cache = MYNEWT_VAL(BLE_GATT_CACHING),
}; };
+33 -1
View File
@@ -428,6 +428,10 @@ ble_l2cap_sig_update_req_rx(uint16_t conn_handle,
return rc; return rc;
} }
if (OS_MBUF_PKTLEN(*om) != BLE_L2CAP_SIG_UPDATE_REQ_SZ) {
return BLE_HS_EBADDATA;
}
rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags); rc = ble_hs_atomic_conn_flags(conn_handle, &conn_flags);
if (rc != 0) { if (rc != 0) {
return rc; return rc;
@@ -506,6 +510,10 @@ ble_l2cap_sig_update_rsp_rx(uint16_t conn_handle,
goto done; goto done;
} }
if (OS_MBUF_PKTLEN(*om) != BLE_L2CAP_SIG_UPDATE_RSP_SZ) {
return BLE_HS_EBADDATA;
}
rsp = (struct ble_l2cap_sig_update_rsp *)(*om)->om_data; rsp = (struct ble_l2cap_sig_update_rsp *)(*om)->om_data;
switch (le16toh(rsp->result)) { switch (le16toh(rsp->result)) {
@@ -904,6 +912,10 @@ ble_l2cap_sig_credit_base_reconfig_rsp_rx(uint16_t conn_handle,
return rc; return rc;
} }
if (OS_MBUF_PKTLEN(*om) != sizeof(*rsp)) {
return BLE_HS_EBADDATA;
}
rsp = (struct ble_l2cap_sig_credit_base_reconfig_rsp *)(*om)->om_data; rsp = (struct ble_l2cap_sig_credit_base_reconfig_rsp *)(*om)->om_data;
ble_l2cap_sig_coc_reconfig_cb(proc, (rsp->result > 0) ? BLE_HS_EREJECT : 0); ble_l2cap_sig_coc_reconfig_cb(proc, (rsp->result > 0) ? BLE_HS_EREJECT : 0);
ble_l2cap_sig_proc_free(proc); ble_l2cap_sig_proc_free(proc);
@@ -1181,11 +1193,15 @@ ble_l2cap_sig_coc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
struct ble_hs_conn *conn; struct ble_hs_conn *conn;
uint16_t scid; uint16_t scid;
rc = ble_hs_mbuf_pullup_base(om, sizeof(req)); rc = ble_hs_mbuf_pullup_base(om, sizeof(*req));
if (rc != 0) { if (rc != 0) {
return rc; return rc;
} }
if (OS_MBUF_PKTLEN(*om) != sizeof(*req)) {
return BLE_HS_EBADDATA;
}
rsp = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_LE_CREDIT_CONNECT_RSP, rsp = ble_l2cap_sig_cmd_get(BLE_L2CAP_SIG_OP_LE_CREDIT_CONNECT_RSP,
hdr->identifier, sizeof(*rsp), &txom); hdr->identifier, sizeof(*rsp), &txom);
if (!rsp) { if (!rsp) {
@@ -1300,6 +1316,10 @@ ble_l2cap_sig_coc_rsp_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
goto done; goto done;
} }
if (OS_MBUF_PKTLEN(*om) != sizeof(*rsp)) {
return BLE_HS_EBADDATA;
}
rsp = (struct ble_l2cap_sig_le_con_rsp *)(*om)->om_data; rsp = (struct ble_l2cap_sig_le_con_rsp *)(*om)->om_data;
chan = proc->connect.chan[0]; chan = proc->connect.chan[0];
@@ -1592,6 +1612,10 @@ ble_l2cap_sig_disc_req_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
ble_hs_lock(); ble_hs_lock();
conn = ble_hs_conn_find_assert(conn_handle); conn = ble_hs_conn_find_assert(conn_handle);
if (OS_MBUF_PKTLEN(*om) != sizeof(*req)) {
return BLE_HS_EBADDATA;
}
req = (struct ble_l2cap_sig_disc_req *) (*om)->om_data; req = (struct ble_l2cap_sig_disc_req *) (*om)->om_data;
/* Let's find matching channel. Note that destination CID in the request /* Let's find matching channel. Note that destination CID in the request
@@ -1677,6 +1701,10 @@ ble_l2cap_sig_disc_rsp_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
goto done; goto done;
} }
if (OS_MBUF_PKTLEN(*om) != sizeof(*rsp)) {
return BLE_HS_EBADDATA;
}
chan = proc->disconnect.chan; chan = proc->disconnect.chan;
if (!chan) { if (!chan) {
goto done; goto done;
@@ -1752,6 +1780,10 @@ ble_l2cap_sig_le_credits_rx(uint16_t conn_handle, struct ble_l2cap_sig_hdr *hdr,
return 0; return 0;
} }
if (OS_MBUF_PKTLEN(*om) != sizeof(*req)) {
return BLE_HS_EBADDATA;
}
req = (struct ble_l2cap_sig_le_credits *) (*om)->om_data; req = (struct ble_l2cap_sig_le_credits *) (*om)->om_data;
/* Ignore when peer sends zero credits */ /* Ignore when peer sends zero credits */
+2 -2
View File
@@ -1838,7 +1838,7 @@ ble_sm_verify_auth_requirements(uint8_t cmd)
/* Fail if security level forces MITM protection and remote does not /* Fail if security level forces MITM protection and remote does not
* support it * support it
*/ */
if (MYNEWT_VAL(BLE_SM_LVL) >= 3 && !(cmd & BLE_SM_PAIR_AUTHREQ_MITM)) { if (ble_hs_cfg.sm_sec_lvl >= 3 && !(cmd & BLE_SM_PAIR_AUTHREQ_MITM)) {
return false; return false;
} }
return true; return true;
@@ -1922,7 +1922,7 @@ ble_sm_pair_req_rx(uint16_t conn_handle, struct os_mbuf **om,
if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) { if (conn->bhc_flags & BLE_HS_CONN_F_MASTER) {
res->sm_err = BLE_SM_ERR_CMD_NOT_SUPP; res->sm_err = BLE_SM_ERR_CMD_NOT_SUPP;
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CMD_NOT_SUPP); res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CMD_NOT_SUPP);
} else if (MYNEWT_VAL(BLE_SM_LVL) == 1) { } else if (ble_hs_cfg.sm_sec_lvl == 1) {
res->sm_err = BLE_SM_ERR_CMD_NOT_SUPP; res->sm_err = BLE_SM_ERR_CMD_NOT_SUPP;
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CMD_NOT_SUPP); res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_CMD_NOT_SUPP);
} else if (req->max_enc_key_size < BLE_SM_PAIR_KEY_SZ_MIN) { } else if (req->max_enc_key_size < BLE_SM_PAIR_KEY_SZ_MIN) {
+3 -3
View File
@@ -51,7 +51,7 @@ ble_hs_pvcy_test_util_all_gap_procs(int adv_status,
int conn_status, int conn_status,
int disc_status) int disc_status)
{ {
struct ble_gap_disc_params disc_params; struct ble_gap_disc_params disc_params = {0};
ble_addr_t peer_addr; ble_addr_t peer_addr;
int rc; int rc;
@@ -338,7 +338,7 @@ TEST_CASE_SELF(ble_hs_pvcy_test_case_add_irk_adv)
/*** Discovery active. */ /*** Discovery active. */
TEST_CASE_SELF(ble_hs_pvcy_test_case_add_irk_disc) TEST_CASE_SELF(ble_hs_pvcy_test_case_add_irk_disc)
{ {
struct ble_gap_disc_params disc_params; struct ble_gap_disc_params disc_params = {0};
int rc; int rc;
ble_hs_pvcy_test_util_init(); ble_hs_pvcy_test_util_init();
@@ -407,7 +407,7 @@ TEST_CASE_SELF(ble_hs_pvcy_test_case_add_irk_conn)
/*** Advertising and discovery active. */ /*** Advertising and discovery active. */
TEST_CASE_SELF(ble_hs_pvcy_test_case_add_irk_adv_disc) TEST_CASE_SELF(ble_hs_pvcy_test_case_add_irk_adv_disc)
{ {
struct ble_gap_disc_params disc_params; struct ble_gap_disc_params disc_params = {0};
int rc; int rc;
ble_hs_pvcy_test_util_init(); ble_hs_pvcy_test_util_init();
+1 -1
View File
@@ -193,7 +193,7 @@ ble_os_disc_test_cb(struct ble_gap_event *event, void *arg)
static void static void
ble_os_disc_test_task_handler(void *arg) ble_os_disc_test_task_handler(void *arg)
{ {
struct ble_gap_disc_params disc_params; struct ble_gap_disc_params disc_params = {0};
int cb_called; int cb_called;
int rc; int rc;