From abf630be427e40426af172bf0eabd702697531b9 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 7 Feb 2024 17:08:13 +0530 Subject: [PATCH] Backport fixes for BLE 5.4 PTS Related Features and Fixes --- nimble/host/include/host/ble_gatt.h | 2 +- nimble/host/services/htp/src/ble_svc_htp.c | 1 + nimble/host/src/ble_gap.c | 2 + nimble/host/src/ble_gatts.c | 61 ++++++++++++---------- nimble/host/src/ble_l2cap_coc.c | 2 +- nimble/host/src/ble_sm_priv.h | 1 - nimble/include/nimble/hci_common.h | 5 ++ 7 files changed, 42 insertions(+), 32 deletions(-) diff --git a/nimble/host/include/host/ble_gatt.h b/nimble/host/include/host/ble_gatt.h index c5f9d761d..dd8a1f8d0 100644 --- a/nimble/host/include/host/ble_gatt.h +++ b/nimble/host/include/host/ble_gatt.h @@ -936,7 +936,7 @@ struct ble_gatt_cpfd { uint16_t unit; /** The name space of the description. */ - uint8_t namespace; + uint8_t name_space; /** The description of this characteristic. Depends on name space. */ uint16_t description; diff --git a/nimble/host/services/htp/src/ble_svc_htp.c b/nimble/host/services/htp/src/ble_svc_htp.c index 134e98035..d602b16ab 100644 --- a/nimble/host/services/htp/src/ble_svc_htp.c +++ b/nimble/host/services/htp/src/ble_svc_htp.c @@ -75,6 +75,7 @@ static const struct ble_gatt_svc_def ble_svc_htp_defs[] = { 0, } }, + .cpfd = NULL, }, { 0, /* No more characteristics in this service. */ } diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index bcf1cc9db..28e278274 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -6338,8 +6338,10 @@ ble_gap_ext_connect(uint8_t own_addr_type, const ble_addr_t *peer_addr, ble_conn_reattempt.own_addr_type = own_addr_type; if (peer_addr != NULL) { + ble_conn_reattempt.peer_addr_present = 1; memcpy(&ble_conn_reattempt.peer_addr, peer_addr, sizeof(ble_addr_t)); } else { + ble_conn_reattempt.peer_addr_present = 0; memset(&ble_conn_reattempt.peer_addr, 0, sizeof(ble_addr_t)); } diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c index 9e5587e6a..031f3595c 100644 --- a/nimble/host/src/ble_gatts.c +++ b/nimble/host/src/ble_gatts.c @@ -767,33 +767,6 @@ ble_gatts_clt_cfg_find(struct ble_gatts_clt_cfg_list *ble_gatts_clt_cfgs, } #else -static int -ble_gatts_cpfd_is_sane(const struct ble_gatt_cpfd *cpfd) -{ - /** As per Assigned Numbers Specification (2023-09-07) */ - if ((cpfd->format < 0x01) || (cpfd->format > 0x1C)) { - return 0; - } - - if ((cpfd->unit < 0x2700) || - ((cpfd->unit > 0x2707) && (cpfd->unit < 0x2710)) || - (cpfd->unit == 0x271F) || - ((cpfd->unit > 0x2735) && (cpfd->unit < 0x2740)) || - ((cpfd->unit > 0x2757) && (cpfd->unit < 0x2760)) || - ((cpfd->unit > 0x2768) && (cpfd->unit < 0x2780)) || - ((cpfd->unit > 0x2787) && (cpfd->unit < 0x27A0)) || - (cpfd->unit == 0x27BB) || - (cpfd->unit > 0x27C8)) { - return 0; - } - - if ((cpfd->namespace == BLE_GATT_CHR_NAMESPACE_BT_SIG) && (cpfd->description > 0x0110)) { - return 0; - } - - return 1; -} - static int ble_gatts_clt_cfg_find_idx(struct ble_gatts_clt_cfg *cfgs, uint16_t chr_val_handle) @@ -826,6 +799,33 @@ ble_gatts_clt_cfg_find(struct ble_gatts_clt_cfg *cfgs, } #endif +static int +ble_gatts_cpfd_is_sane(const struct ble_gatt_cpfd *cpfd) +{ + /** As per Assigned Numbers Specification (2023-09-07) */ + if ((cpfd->format < 0x01) || (cpfd->format > 0x1C)) { + return 0; + } + + if ((cpfd->unit < 0x2700) || + ((cpfd->unit > 0x2707) && (cpfd->unit < 0x2710)) || + (cpfd->unit == 0x271F) || + ((cpfd->unit > 0x2735) && (cpfd->unit < 0x2740)) || + ((cpfd->unit > 0x2757) && (cpfd->unit < 0x2760)) || + ((cpfd->unit > 0x2768) && (cpfd->unit < 0x2780)) || + ((cpfd->unit > 0x2787) && (cpfd->unit < 0x27A0)) || + (cpfd->unit == 0x27BB) || + (cpfd->unit > 0x27C8)) { + return 0; + } + + if ((cpfd->name_space == BLE_GATT_CHR_NAMESPACE_BT_SIG) && (cpfd->description > 0x0110)) { + return 0; + } + + return 1; +} + static void ble_gatts_subscribe_event(uint16_t conn_handle, uint16_t attr_handle, uint8_t reason, @@ -1066,7 +1066,7 @@ ble_gatts_cpfd_access(uint16_t conn_handle, uint16_t attr_handle, rc += os_mbuf_append(*om, &(cpfd->format), sizeof(cpfd->format)); rc += os_mbuf_append(*om, &(cpfd->exponent), sizeof(cpfd->exponent)); rc += os_mbuf_append(*om, &(cpfd->unit), sizeof(cpfd->unit)); - rc += os_mbuf_append(*om, &(cpfd->namespace), sizeof(cpfd->namespace)); + rc += os_mbuf_append(*om, &(cpfd->name_space), sizeof(cpfd->name_space)); rc += os_mbuf_append(*om, &(cpfd->description), sizeof(cpfd->description)); return ((rc == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES); @@ -2088,7 +2088,11 @@ ble_gatts_chr_updated(uint16_t chr_val_handle) * Consider using a "foreach" function to walk the connection list. */ conn = ble_hs_conn_find_by_idx(i); +#if MYNEWT_VAL(BLE_DYNAMIC_SERVICE) + if (conn == NULL) { +#else if (conn == NULL || conn->bhc_gatt_svr.clt_cfgs == NULL) { +#endif break; } @@ -2201,7 +2205,6 @@ ble_gatts_peer_cl_sup_feat_update(uint16_t conn_handle, struct os_mbuf *om) uint16_t len; int rc = 0; int i; - int rfu_mask = 7; BLE_HS_LOG(DEBUG, ""); diff --git a/nimble/host/src/ble_l2cap_coc.c b/nimble/host/src/ble_l2cap_coc.c index 2ae77a235..055632082 100644 --- a/nimble/host/src/ble_l2cap_coc.c +++ b/nimble/host/src/ble_l2cap_coc.c @@ -215,7 +215,7 @@ ble_l2cap_coc_rx_fn(struct ble_l2cap_chan *chan) BLE_HS_LOG(ERROR, "Payload larger than expected (%d>%d)\n", om_total, sdu_len + 2); /* Disconnect peer with invalid behaviour */ - rx_sdu = NULL; + rx->sdu = NULL; rx->data_offset = 0; ble_l2cap_disconnect(chan); return BLE_HS_EBADDATA; diff --git a/nimble/host/src/ble_sm_priv.h b/nimble/host/src/ble_sm_priv.h index f9c846638..788aa9631 100644 --- a/nimble/host/src/ble_sm_priv.h +++ b/nimble/host/src/ble_sm_priv.h @@ -432,7 +432,6 @@ int ble_sm_init(void); struct ble_l2cap_chan *ble_sm_create_chan(uint16_t handle); void *ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom); int ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom); -int ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len, uint8_t *out); #ifdef __cplusplus diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index b0981e19b..a99f5ae26 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -2069,6 +2069,7 @@ struct ble_hci_ev_le_subev_periodic_adv_resp_rep { #define BLE_HCI_VER_BCS_5_1 (10) #define BLE_HCI_VER_BCS_5_2 (11) #define BLE_HCI_VER_BCS_5_3 (12) +#define BLE_HCI_VER_BCS_5_4 (13) #define BLE_LMP_VER_BCS_1_0b (0) #define BLE_LMP_VER_BCS_1_1 (1) @@ -2083,6 +2084,7 @@ struct ble_hci_ev_le_subev_periodic_adv_resp_rep { #define BLE_LMP_VER_BCS_5_1 (10) #define BLE_LMP_VER_BCS_5_2 (11) #define BLE_LMP_VER_BCS_5_3 (12) +#define BLE_LMP_VER_BCS_5_4 (13) /* selected HCI and LMP version */ #if MYNEWT_VAL(BLE_VERSION) == 50 @@ -2094,6 +2096,9 @@ struct ble_hci_ev_le_subev_periodic_adv_resp_rep { #elif MYNEWT_VAL(BLE_VERSION) == 52 #define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_2 #define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_2 +#elif MYNEWT_VAL(BLE_VERSION) == 54 +#define BLE_HCI_VER_BCS BLE_HCI_VER_BCS_5_4 +#define BLE_LMP_VER_BCS BLE_LMP_VER_BCS_5_4 #endif