123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- #include "ble_gattc_conn.h"
- #include "conn_mw_ble_gattc.h"
- #include "ble_serialization.h"
- #if defined(BLE_GATT_MTU_SIZE_DEFAULT) && !defined(GATT_MTU_SIZE_DEFAULT)
- #define GATT_MTU_SIZE_DEFAULT BLE_GATT_MTU_SIZE_DEFAULT
- #endif
- #if defined(BLE_GATT_ATT_MTU_DEFAULT) && !defined(GATT_MTU_SIZE_DEFAULT)
- #define GATT_MTU_SIZE_DEFAULT BLE_GATT_ATT_MTU_DEFAULT
- #endif
- #define BLE_GATTC_WRITE_P_VALUE_LEN_MAX (247 - 3)
- #define BLE_GATTC_HANDLE_COUNT_LEN_MAX ((GATT_MTU_SIZE_DEFAULT - 1) / 2)
- uint32_t conn_mw_ble_gattc_primary_services_discover(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- uint16_t start_handle;
- ble_uuid_t srvc_uuid;
- ble_uuid_t * p_srvc_uuid = &srvc_uuid;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_primary_services_discover_req_dec(p_rx_buf,
- rx_buf_len,
- &conn_handle,
- &start_handle,
- &p_srvc_uuid);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_primary_services_discover(conn_handle, start_handle, p_srvc_uuid);
- err_code = ble_gattc_primary_services_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_relationships_discover(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- ble_gattc_handle_range_t handle_range;
- ble_gattc_handle_range_t * p_handle_range = &handle_range;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_relationships_discover_req_dec(p_rx_buf, rx_buf_len,
- &conn_handle, &p_handle_range);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_relationships_discover(conn_handle, p_handle_range);
- err_code = ble_gattc_relationships_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_characteristics_discover(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- ble_gattc_handle_range_t handle_range;
- ble_gattc_handle_range_t * p_handle_range = &handle_range;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_characteristics_discover_req_dec(p_rx_buf, rx_buf_len,
- &conn_handle, &p_handle_range);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_characteristics_discover(conn_handle, p_handle_range);
- err_code = ble_gattc_characteristics_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_descriptors_discover(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- ble_gattc_handle_range_t handle_range;
- ble_gattc_handle_range_t * p_handle_range = &handle_range;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_descriptors_discover_req_dec(p_rx_buf, rx_buf_len,
- &conn_handle, &p_handle_range);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_descriptors_discover(conn_handle, p_handle_range);
- err_code = ble_gattc_descriptors_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_char_value_by_uuid_read(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- ble_uuid_t uuid = {0};
- ble_uuid_t * p_uuid = &uuid;
- ble_gattc_handle_range_t handle_range;
- ble_gattc_handle_range_t * p_handle_range = &handle_range;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_char_value_by_uuid_read_req_dec(p_rx_buf, rx_buf_len,
- &conn_handle, &p_uuid, &p_handle_range);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_char_value_by_uuid_read(conn_handle, p_uuid, p_handle_range);
- err_code = ble_gattc_char_value_by_uuid_read_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_read(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- uint16_t * p_conn_handle = &conn_handle;
- uint16_t handle;
- uint16_t * p_handle = &handle;
- uint16_t offset;
- uint16_t * p_offset = &offset;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_read_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, p_handle, p_offset);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_read(conn_handle, handle, offset);
- err_code = ble_gattc_read_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_char_values_read(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- uint16_t * p_conn_handle = &conn_handle;
- uint16_t handles[BLE_GATTC_HANDLE_COUNT_LEN_MAX];
- uint16_t * p_handles = handles;
- uint16_t handle_count = BLE_GATTC_HANDLE_COUNT_LEN_MAX;
- uint16_t * p_handle_count = &handle_count;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_char_values_read_req_dec(p_rx_buf,
- rx_buf_len,
- p_conn_handle,
- &p_handles,
- p_handle_count);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_char_values_read(conn_handle, p_handles, handle_count);
- err_code = ble_gattc_char_values_read_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_write(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- uint16_t * p_conn_handle = &conn_handle;
- uint8_t value[BLE_GATTC_WRITE_P_VALUE_LEN_MAX];
- ble_gattc_write_params_t write_params = {0};
- ble_gattc_write_params_t * p_write_params = &write_params;
- p_write_params->len = BLE_GATTC_WRITE_P_VALUE_LEN_MAX;
- p_write_params->p_value = value;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_write_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, &p_write_params);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_write(conn_handle, p_write_params);
- err_code = ble_gattc_write_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_hv_confirm(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- uint16_t conn_handle;
- uint16_t * p_conn_handle = &conn_handle;
- uint16_t handle;
- uint16_t * p_handle = &handle;
- err_code = ble_gattc_hv_confirm_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, p_handle);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_hv_confirm(conn_handle, handle);
- err_code = ble_gattc_hv_confirm_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_attr_info_discover(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- uint16_t * p_conn_handle = &conn_handle;
- ble_gattc_handle_range_t range = {0};
- ble_gattc_handle_range_t * p_range = ⦥
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_attr_info_discover_req_dec(p_rx_buf, rx_buf_len, p_conn_handle, &p_range);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_attr_info_discover(conn_handle, p_range);
- err_code = ble_gattc_attr_info_discover_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
- uint32_t conn_mw_ble_gattc_exchange_mtu_request(uint8_t const * const p_rx_buf,
- uint32_t rx_buf_len,
- uint8_t * const p_tx_buf,
- uint32_t * const p_tx_buf_len)
- {
- SER_ASSERT_NOT_NULL(p_rx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf);
- SER_ASSERT_NOT_NULL(p_tx_buf_len);
- uint16_t conn_handle;
- uint16_t client_rx_mtu;
- uint32_t err_code = NRF_SUCCESS;
- uint32_t sd_err_code;
- err_code = ble_gattc_exchange_mtu_request_req_dec(p_rx_buf, rx_buf_len, &conn_handle, &client_rx_mtu);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- sd_err_code = sd_ble_gattc_exchange_mtu_request(conn_handle, client_rx_mtu);
- err_code = ble_gattc_exchange_mtu_request_rsp_enc(sd_err_code, p_tx_buf, p_tx_buf_len);
- SER_ASSERT(err_code == NRF_SUCCESS, err_code);
- return err_code;
- }
|