From fc0bd89a364f96f091e0c70d7fc53aaf17b696ee Mon Sep 17 00:00:00 2001 From: "isha.pardikar@espressif.com" Date: Mon, 31 Oct 2022 15:48:12 +0530 Subject: [PATCH] NimBLE : Change GATT notify/indicate from gattc to gatts --- apps/blecsc/src/gatt_svr.c | 4 +- apps/blehr/src/main.c | 2 +- apps/blestress/src/rx_stress.c | 8 +-- apps/bttester/src/gatt.c | 4 +- nimble/host/include/host/ble_gatt.h | 21 +++++++ nimble/host/mesh/src/proxy.c | 4 +- nimble/host/services/ans/src/ble_svc_ans.c | 4 +- nimble/host/services/bleuart/src/bleuart.c | 2 +- nimble/host/src/ble_att_clt.c | 2 +- nimble/host/src/ble_gatt_priv.h | 2 +- nimble/host/src/ble_gattc.c | 66 +++++++++++++++----- nimble/host/src/ble_gatts.c | 10 +-- nimble/host/test/src/ble_gatt_conn_test.c | 4 +- nimble/host/test/src/ble_gatts_notify_test.c | 4 +- 14 files changed, 98 insertions(+), 39 deletions(-) diff --git a/apps/blecsc/src/gatt_svr.c b/apps/blecsc/src/gatt_svr.c index e66aa9a8b..0c178c0ca 100644 --- a/apps/blecsc/src/gatt_svr.c +++ b/apps/blecsc/src/gatt_svr.c @@ -264,7 +264,7 @@ gatt_svr_chr_access_sc_control_point(uint16_t conn_handle, } #endif - rc = ble_gattc_indicate_custom(conn_handle, csc_control_point_handle, + rc = ble_gatts_indicate_custom(conn_handle, csc_control_point_handle, om_indication); return rc; @@ -321,7 +321,7 @@ gatt_svr_chr_notify_csc_measurement(uint16_t conn_handle) om = ble_hs_mbuf_from_flat(data_buf, data_offset); - rc = ble_gattc_notify_custom(conn_handle, csc_measurement_handle, om); + rc = ble_gatts_notify_custom(conn_handle, csc_measurement_handle, om); return rc; } diff --git a/apps/blehr/src/main.c b/apps/blehr/src/main.c index bf0f3f302..e09349fa5 100644 --- a/apps/blehr/src/main.c +++ b/apps/blehr/src/main.c @@ -146,7 +146,7 @@ blehr_tx_hrate(struct os_event *ev) om = ble_hs_mbuf_from_flat(hrm, sizeof(hrm)); - rc = ble_gattc_notify_custom(conn_handle, hrs_hrm_handle, om); + rc = ble_gatts_notify_custom(conn_handle, hrs_hrm_handle, om); assert(rc == 0); blehr_tx_hrate_reset(); diff --git a/apps/blestress/src/rx_stress.c b/apps/blestress/src/rx_stress.c index 440966adc..f14028b96 100644 --- a/apps/blestress/src/rx_stress.c +++ b/apps/blestress/src/rx_stress.c @@ -1004,7 +1004,7 @@ rx_stress_12_gap_event(struct ble_gap_event *event, void *arg) rx_stress_ctx->begin_us = os_get_uptime_usec(); om = os_msys_get_pkthdr(om_len, 0); stress_fill_mbuf_with_pattern(om, om_len); - rc = ble_gattc_indicate_custom(rx_stress_ctx->conn_handle, hrs_hrm_handle, + rc = ble_gatts_indicate_custom(rx_stress_ctx->conn_handle, hrs_hrm_handle, om); assert(rc == 0); return 0; @@ -1069,7 +1069,7 @@ rx_stress_13_gap_event(struct ble_gap_event *event, void *arg) } om = ble_hs_mbuf_from_flat(test_6_pattern, 10); - rc = ble_gattc_notify_custom(rx_stress_ctx->conn_handle, + rc = ble_gatts_notify_custom(rx_stress_ctx->conn_handle, hrs_hrm_handle, om); assert(rc == 0); return 0; @@ -1127,7 +1127,7 @@ rx_stress_14_gap_event(struct ble_gap_event *event, void *arg) /* Notify data pattern */ om = ble_hs_mbuf_from_flat(test_6_pattern, bytes_num); - rc = ble_gattc_notify_custom(rx_stress_ctx->conn_handle, + rc = ble_gatts_notify_custom(rx_stress_ctx->conn_handle, hrs_hrm_handle, om); assert(rc == 0); @@ -1442,7 +1442,7 @@ rx_stress_main_task_fn(void *arg) if (i == 7 || i == 8 || i == 13) { /* 7,8: PHY update tests cause that the device during the next test * will stuck somewhere and will reset. Skip them for now. - * 13: Should work after fixing ble_gattc_notify_custom (nimble issue on GitHub)*/ + * 13: Should work after fixing ble_gatts_notify_custom (nimble issue on GitHub)*/ continue; } /* Start test. */ diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c index 2a8545b36..412227d8c 100644 --- a/apps/bttester/src/gatt.c +++ b/apps/bttester/src/gatt.c @@ -1978,12 +1978,12 @@ void notify_test(struct os_event *ev) om = ble_hs_mbuf_from_flat(ntf, sizeof(ntf)); if (notify_state) { - rc = ble_gattc_notify_custom(myconn_handle, notify_handle, om); + rc = ble_gatts_notify_custom(myconn_handle, notify_handle, om); assert(rc == 0); } if (indicate_state) { - rc = ble_gattc_indicate_custom(myconn_handle, notify_handle, om); + rc = ble_gatts_indicate_custom(myconn_handle, notify_handle, om); assert(rc == 0); } } diff --git a/nimble/host/include/host/ble_gatt.h b/nimble/host/include/host/ble_gatt.h index d5c3269f0..92a69ede9 100644 --- a/nimble/host/include/host/ble_gatt.h +++ b/nimble/host/include/host/ble_gatt.h @@ -470,6 +470,12 @@ int ble_gattc_write_reliable(uint16_t conn_handle, * * @return 0 on success; nonzero on failure. */ +int ble_gatts_notify_custom(uint16_t conn_handle, uint16_t att_handle, + struct os_mbuf *om); + +/** + * Deprecated. Should not be used. Use ble_gatts_notify_custom instead. + */ int ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle, struct os_mbuf *om); @@ -485,6 +491,11 @@ int ble_gattc_notify_custom(uint16_t conn_handle, uint16_t att_handle, * * @return 0 on success; nonzero on failure. */ +int ble_gatts_notify(uint16_t conn_handle, uint16_t chr_val_handle); + +/** + * Deprecated. Should not be used. Use ble_gatts_notify instead. + */ int ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle); /** @@ -501,6 +512,11 @@ int ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle); * * @return 0 on success; nonzero on failure. */ +int ble_gatts_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle, + struct os_mbuf *txom); +/** + * Deprecated. Should not be used. Use ble_gatts_indicate_custom instead. + */ int ble_gattc_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle, struct os_mbuf *txom); @@ -516,6 +532,11 @@ int ble_gattc_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle, * * @return 0 on success; nonzero on failure. */ +int ble_gatts_indicate(uint16_t conn_handle, uint16_t chr_val_handle); + +/** + * Deprecated. Should not be used. Use ble_gatts_indicate instead. + */ int ble_gattc_indicate(uint16_t conn_handle, uint16_t chr_val_handle); int ble_gattc_init(void); diff --git a/nimble/host/mesh/src/proxy.c b/nimble/host/mesh/src/proxy.c index 6d631b721..1f2d65ad4 100644 --- a/nimble/host/mesh/src/proxy.c +++ b/nimble/host/mesh/src/proxy.c @@ -997,7 +997,7 @@ static int proxy_send(uint16_t conn_handle, const void *data, uint16_t len) if (gatt_svc == MESH_GATT_PROXY) { om = ble_hs_mbuf_from_flat(data, len); assert(om); - err = ble_gattc_notify_custom(conn_handle, svc_handles.proxy_data_out_h, om); + err = ble_gatts_notify_custom(conn_handle, svc_handles.proxy_data_out_h, om); notify_complete(); } #endif @@ -1006,7 +1006,7 @@ static int proxy_send(uint16_t conn_handle, const void *data, uint16_t len) if (gatt_svc == MESH_GATT_PROV) { om = ble_hs_mbuf_from_flat(data, len); assert(om); - err = ble_gattc_notify_custom(conn_handle, svc_handles.prov_data_out_h, om); + err = ble_gatts_notify_custom(conn_handle, svc_handles.prov_data_out_h, om); notify_complete(); } #endif diff --git a/nimble/host/services/ans/src/ble_svc_ans.c b/nimble/host/services/ans/src/ble_svc_ans.c index 5b64f18c4..df1e0764a 100644 --- a/nimble/host/services/ans/src/ble_svc_ans.c +++ b/nimble/host/services/ans/src/ble_svc_ans.c @@ -390,7 +390,7 @@ ble_svc_ans_new_alert_notify(uint8_t cat_id, const char * info_str) memcpy(&ble_svc_ans_new_alert_val[2], info_str, info_str_len); } } - return ble_gattc_notify(ble_svc_ans_conn_handle, + return ble_gatts_notify(ble_svc_ans_conn_handle, ble_svc_ans_new_alert_val_handle); } @@ -407,7 +407,7 @@ ble_svc_ans_unr_alert_notify(uint8_t cat_id) { ble_svc_ans_unr_alert_stat[0] = cat_id; ble_svc_ans_unr_alert_stat[1] = ble_svc_ans_unr_alert_cnt[cat_id]; - return ble_gattc_notify(ble_svc_ans_conn_handle, + return ble_gatts_notify(ble_svc_ans_conn_handle, ble_svc_ans_unr_alert_val_handle); } diff --git a/nimble/host/services/bleuart/src/bleuart.c b/nimble/host/services/bleuart/src/bleuart.c index b664f36e8..866595ede 100644 --- a/nimble/host/services/bleuart/src/bleuart.c +++ b/nimble/host/services/bleuart/src/bleuart.c @@ -166,7 +166,7 @@ bleuart_uart_read(void) if (!om) { return; } - ble_gattc_notify_custom(g_console_conn_handle, + ble_gatts_notify_custom(g_console_conn_handle, g_bleuart_attr_read_handle, om); off = 0; break; diff --git a/nimble/host/src/ble_att_clt.c b/nimble/host/src/ble_att_clt.c index 1a7629751..a36cf3aa0 100644 --- a/nimble/host/src/ble_att_clt.c +++ b/nimble/host/src/ble_att_clt.c @@ -952,7 +952,7 @@ ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom) #endif /* No payload. */ - ble_gattc_rx_indicate_rsp(conn_handle); + ble_gatts_rx_indicate_rsp(conn_handle); return 0; } diff --git a/nimble/host/src/ble_gatt_priv.h b/nimble/host/src/ble_gatt_priv.h index 4a59635b8..2b1705a10 100644 --- a/nimble/host/src/ble_gatt_priv.h +++ b/nimble/host/src/ble_gatt_priv.h @@ -125,7 +125,7 @@ void ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status, uint16_t handle, uint16_t offset, struct os_mbuf **rxom); void ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, int status); -void ble_gattc_rx_indicate_rsp(uint16_t conn_handle); +void ble_gatts_rx_indicate_rsp(uint16_t conn_handle); void ble_gattc_rx_find_info_idata(uint16_t conn_handle, struct ble_att_find_info_idata *idata); void ble_gattc_rx_find_info_complete(uint16_t conn_handle, int status); diff --git a/nimble/host/src/ble_gattc.c b/nimble/host/src/ble_gattc.c index 74a2837ad..53a947c4f 100644 --- a/nimble/host/src/ble_gattc.c +++ b/nimble/host/src/ble_gattc.c @@ -232,7 +232,7 @@ static ble_gattc_err_fn ble_gattc_read_mult_err; static ble_gattc_err_fn ble_gattc_write_err; static ble_gattc_err_fn ble_gattc_write_long_err; static ble_gattc_err_fn ble_gattc_write_reliable_err; -static ble_gattc_err_fn ble_gattc_indicate_err; +static ble_gattc_err_fn ble_gatts_indicate_err; static ble_gattc_err_fn * const ble_gattc_err_dispatch[BLE_GATT_OP_CNT] = { [BLE_GATT_OP_MTU] = ble_gattc_mtu_err, @@ -249,7 +249,7 @@ static ble_gattc_err_fn * const ble_gattc_err_dispatch[BLE_GATT_OP_CNT] = { [BLE_GATT_OP_WRITE] = ble_gattc_write_err, [BLE_GATT_OP_WRITE_LONG] = ble_gattc_write_long_err, [BLE_GATT_OP_WRITE_RELIABLE] = ble_gattc_write_reliable_err, - [BLE_GATT_OP_INDICATE] = ble_gattc_indicate_err, + [BLE_GATT_OP_INDICATE] = ble_gatts_indicate_err, }; /** @@ -307,7 +307,7 @@ static ble_gattc_tmo_fn ble_gattc_read_mult_tmo; static ble_gattc_tmo_fn ble_gattc_write_tmo; static ble_gattc_tmo_fn ble_gattc_write_long_tmo; static ble_gattc_tmo_fn ble_gattc_write_reliable_tmo; -static ble_gattc_tmo_fn ble_gattc_indicate_tmo; +static ble_gattc_tmo_fn ble_gatts_indicate_tmo; static ble_gattc_tmo_fn * const ble_gattc_tmo_dispatch[BLE_GATT_OP_CNT] = { @@ -325,7 +325,7 @@ ble_gattc_tmo_dispatch[BLE_GATT_OP_CNT] = { [BLE_GATT_OP_WRITE] = ble_gattc_write_tmo, [BLE_GATT_OP_WRITE_LONG] = ble_gattc_write_long_tmo, [BLE_GATT_OP_WRITE_RELIABLE] = ble_gattc_write_reliable_tmo, - [BLE_GATT_OP_INDICATE] = ble_gattc_indicate_tmo, + [BLE_GATT_OP_INDICATE] = ble_gatts_indicate_tmo, }; /** @@ -4149,7 +4149,7 @@ done: *****************************************************************************/ int -ble_gattc_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle, +ble_gatts_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle, struct os_mbuf *txom) { #if !MYNEWT_VAL(BLE_GATT_NOTIFY) @@ -4199,8 +4199,18 @@ done: return rc; } +/** + * Deprecated. Should not be used. Use ble_gatts_notify_custom instead. + */ int -ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle) +ble_gattc_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle, + struct os_mbuf *txom) +{ + return ble_gatts_notify_custom(conn_handle, chr_val_handle, txom); +} + +int +ble_gatts_notify(uint16_t conn_handle, uint16_t chr_val_handle) { #if !MYNEWT_VAL(BLE_GATT_NOTIFY) return BLE_HS_ENOTSUP; @@ -4208,11 +4218,20 @@ ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle) int rc; - rc = ble_gattc_notify_custom(conn_handle, chr_val_handle, NULL); + rc = ble_gatts_notify_custom(conn_handle, chr_val_handle, NULL); return rc; } +/** + * Deprecated. Should not be used. Use ble_gatts_notify instead. + */ +int +ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle) +{ + return ble_gatts_notify(conn_handle, chr_val_handle); +} + /***************************************************************************** * $indicate * *****************************************************************************/ @@ -4224,7 +4243,7 @@ ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle) * error status to the application. */ static void -ble_gattc_indicate_err(struct ble_gattc_proc *proc, int status, +ble_gatts_indicate_err(struct ble_gattc_proc *proc, int status, uint16_t att_handle) { int rc; @@ -4248,7 +4267,7 @@ ble_gattc_indicate_err(struct ble_gattc_proc *proc, int status, } static void -ble_gattc_indicate_tmo(struct ble_gattc_proc *proc) +ble_gatts_indicate_tmo(struct ble_gattc_proc *proc) { BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task()); ble_gattc_dbg_assert_proc_not_inserted(proc); @@ -4262,7 +4281,7 @@ ble_gattc_indicate_tmo(struct ble_gattc_proc *proc) * proc. */ static void -ble_gattc_indicate_rx_rsp(struct ble_gattc_proc *proc) +ble_gatts_indicate_rx_rsp(struct ble_gattc_proc *proc) { int rc; @@ -4293,7 +4312,7 @@ ble_gatts_indicate_fail_notconn(uint16_t conn_handle) } int -ble_gattc_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle, +ble_gatts_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle, struct os_mbuf *txom) { #if !MYNEWT_VAL(BLE_GATT_INDICATE) @@ -4365,10 +4384,29 @@ done: return rc; } +/** + * Deprecated. Should not be used. Use ble_gatts_indicate_custom instead. + */ +int +ble_gattc_indicate_custom(uint16_t conn_handle, uint16_t chr_val_handle, + struct os_mbuf *txom) +{ + return ble_gatts_indicate_custom(conn_handle, chr_val_handle, txom); +} + +int +ble_gatts_indicate(uint16_t conn_handle, uint16_t chr_val_handle) +{ + return ble_gatts_indicate_custom(conn_handle, chr_val_handle, NULL); +} + +/** + * Deprecated. Should not be used. Use ble_gatts_indicate instead. + */ int ble_gattc_indicate(uint16_t conn_handle, uint16_t chr_val_handle) { - return ble_gattc_indicate_custom(conn_handle, chr_val_handle, NULL); + return ble_gatts_indicate(conn_handle, chr_val_handle); } /***************************************************************************** @@ -4739,7 +4777,7 @@ ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, int status) * active GATT procedure. */ void -ble_gattc_rx_indicate_rsp(uint16_t conn_handle) +ble_gatts_rx_indicate_rsp(uint16_t conn_handle) { #if !NIMBLE_BLE_ATT_CLT_INDICATE return; @@ -4750,7 +4788,7 @@ ble_gattc_rx_indicate_rsp(uint16_t conn_handle) proc = ble_gattc_extract_first_by_conn_op(conn_handle, BLE_GATT_OP_INDICATE); if (proc != NULL) { - ble_gattc_indicate_rx_rsp(proc); + ble_gatts_indicate_rx_rsp(proc); ble_gattc_process_status(proc, BLE_HS_EDONE); } } diff --git a/nimble/host/src/ble_gatts.c b/nimble/host/src/ble_gatts.c index e53cc116f..f1f5d89e2 100644 --- a/nimble/host/src/ble_gatts.c +++ b/nimble/host/src/ble_gatts.c @@ -1411,7 +1411,7 @@ ble_gatts_send_next_indicate(uint16_t conn_handle) return BLE_HS_ENOENT; } - rc = ble_gattc_indicate(conn_handle, chr_val_handle); + rc = ble_gatts_indicate(conn_handle, chr_val_handle); if (rc != 0) { return rc; } @@ -1649,11 +1649,11 @@ ble_gatts_tx_notifications_one_chr(uint16_t chr_val_handle) break; case BLE_ATT_OP_NOTIFY_REQ: - ble_gattc_notify(conn_handle, chr_val_handle); + ble_gatts_notify(conn_handle, chr_val_handle); break; case BLE_ATT_OP_INDICATE_REQ: - ble_gattc_indicate(conn_handle, chr_val_handle); + ble_gatts_indicate(conn_handle, chr_val_handle); break; default: @@ -1796,7 +1796,7 @@ ble_gatts_bonding_restored(uint16_t conn_handle) break; case BLE_ATT_OP_NOTIFY_REQ: - rc = ble_gattc_notify(conn_handle, cccd_value.chr_val_handle); + rc = ble_gatts_notify(conn_handle, cccd_value.chr_val_handle); if (rc == 0) { cccd_value.value_changed = 0; ble_store_write_cccd(&cccd_value); @@ -1804,7 +1804,7 @@ ble_gatts_bonding_restored(uint16_t conn_handle) break; case BLE_ATT_OP_INDICATE_REQ: - ble_gattc_indicate(conn_handle, cccd_value.chr_val_handle); + ble_gatts_indicate(conn_handle, cccd_value.chr_val_handle); break; default: diff --git a/nimble/host/test/src/ble_gatt_conn_test.c b/nimble/host/test/src/ble_gatt_conn_test.c index 8d95f7433..5cb94ce82 100644 --- a/nimble/host/test/src/ble_gatt_conn_test.c +++ b/nimble/host/test/src/ble_gatt_conn_test.c @@ -485,7 +485,7 @@ TEST_CASE_SELF(ble_gatt_conn_test_disconnect) 3, &attr, 1, ble_gatt_conn_test_write_rel_cb, &write_rel_arg); TEST_ASSERT_FATAL(rc == 0); - rc = ble_gattc_indicate(3, attr_handle); + rc = ble_gatts_indicate(3, attr_handle); TEST_ASSERT_FATAL(rc == 0); /*** Start the procedures. */ @@ -732,7 +732,7 @@ TEST_CASE_SELF(ble_gatt_conn_test_timeout) /*** Indication. */ ble_hs_test_util_create_conn(1, peer_addr, NULL, NULL); - rc = ble_gattc_indicate(1, attr_handle); + rc = ble_gatts_indicate(1, attr_handle); TEST_ASSERT_FATAL(rc == 0); ble_gatt_conn_test_util_timeout(1, NULL); diff --git a/nimble/host/test/src/ble_gatts_notify_test.c b/nimble/host/test/src/ble_gatts_notify_test.c index 6e04ac362..254ac4407 100644 --- a/nimble/host/test/src/ble_gatts_notify_test.c +++ b/nimble/host/test/src/ble_gatts_notify_test.c @@ -586,7 +586,7 @@ TEST_CASE_SELF(ble_gatts_notify_test_n) om = ble_hs_mbuf_from_flat(fourbytes, sizeof fourbytes); TEST_ASSERT_FATAL(om != NULL); - rc = ble_gattc_notify_custom(conn_handle, + rc = ble_gatts_notify_custom(conn_handle, ble_gatts_notify_test_chr_1_def_handle + 1, om); TEST_ASSERT_FATAL(rc == 0); @@ -675,7 +675,7 @@ TEST_CASE_SELF(ble_gatts_notify_test_i) om = ble_hs_mbuf_from_flat(fourbytes, sizeof fourbytes); TEST_ASSERT_FATAL(om != NULL); - rc = ble_gattc_indicate_custom(conn_handle, + rc = ble_gatts_indicate_custom(conn_handle, ble_gatts_notify_test_chr_1_def_handle + 1, om); TEST_ASSERT_FATAL(rc == 0);