diff --git a/drivers/bluetooth/nble/conn.c b/drivers/bluetooth/nble/conn.c index 3d0a4cb39fb..7d3e564317e 100644 --- a/drivers/bluetooth/nble/conn.c +++ b/drivers/bluetooth/nble/conn.c @@ -275,12 +275,6 @@ struct bt_conn *bt_conn_create_le(const bt_addr_le_t *peer, req.scan_params.interval = BT_GAP_SCAN_FAST_INTERVAL; req.scan_params.window = BT_GAP_SCAN_FAST_WINDOW; - /* Use passive scanning */ - req.scan_params.active = 0; - /* Do not use whitelist */ - req.scan_params.selective = 0; - /* Disable timeout */ - req.scan_params.timeout = 0; conn->state = BT_CONN_CONNECT; diff --git a/drivers/bluetooth/nble/gap.c b/drivers/bluetooth/nble/gap.c index fac927e151f..415aee539bb 100644 --- a/drivers/bluetooth/nble/gap.c +++ b/drivers/bluetooth/nble/gap.c @@ -144,7 +144,7 @@ static bool valid_adv_param(const struct bt_le_adv_param *param) return true; } -static int set_ad(struct bt_eir_data *eir, const struct bt_data *ad, +static int set_ad(struct nble_eir_data *eir, const struct bt_data *ad, size_t ad_len) { int i; @@ -291,10 +291,10 @@ int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb) return -EINVAL; } - nble_params.interval = param->interval; - nble_params.window = param->window; - nble_params.scan_type = param->type; - nble_params.use_whitelist = 0; + nble_params.scan_params.interval = param->interval; + nble_params.scan_params.window = param->window; + nble_params.scan_params.scan_type = param->type; + nble_params.scan_params.use_whitelist = 0; /* Check is scan already enabled */ @@ -350,19 +350,11 @@ void nble_log(const struct nble_log_s *param, char *format, uint8_t len) void on_nble_get_bda_rsp(const struct nble_get_bda_rsp *rsp) { - struct nble_gap_get_version_param params; - - if (rsp->status) { - BT_ERR("Read bdaddr failed, status %d", rsp->status); - return; - } - - bt_addr_le_copy(&nble.addr, &rsp->bd); + bt_addr_le_copy(&nble.addr, &rsp->bda); BT_DBG("Local bdaddr: %s", bt_addr_le_str(&nble.addr)); - params.cb = NULL; - nble_get_version_req(¶ms); + nble_get_version_req(NULL); } void on_nble_common_rsp(const struct nble_common_rsp *rsp) @@ -436,7 +428,7 @@ void on_nble_sm_config_rsp(struct nble_sm_config_rsp *rsp) BT_DBG("status %u", rsp->status); /* Get bdaddr queued after SM setup */ - nble_gap_read_bda_req(NULL); + nble_get_bda_req(NULL); } void on_nble_sm_common_rsp(const struct nble_sm_common_rsp *rsp) diff --git a/drivers/bluetooth/nble/gap_internal.h b/drivers/bluetooth/nble/gap_internal.h index f59c1141730..cc5d9e71ecf 100644 --- a/drivers/bluetooth/nble/gap_internal.h +++ b/drivers/bluetooth/nble/gap_internal.h @@ -61,7 +61,7 @@ struct nble_log_s { uint8_t param3; }; -void nble_log(const struct nble_log_s *par, char *buf, uint8_t buflen); +void nble_log(const struct nble_log_s *par, char *data, uint8_t len); void on_nble_up(void); @@ -70,6 +70,8 @@ struct nble_common_rsp { void *user_data; }; +void on_nble_common_rsp(const struct nble_common_rsp *rsp); + struct nble_version { uint8_t version; uint8_t major; @@ -81,17 +83,28 @@ struct nble_version { typedef void (*ble_get_version_cb_t)(const struct nble_version *ver); -struct nble_gap_get_version_param { - ble_get_version_cb_t cb; -}; +void nble_get_version_req(ble_get_version_cb_t cb); struct nble_get_version_rsp { - struct nble_gap_get_version_param params; + ble_get_version_cb_t cb; struct nble_version ver; }; +void on_nble_get_version_rsp(const struct nble_get_version_rsp *rsp); + +enum NBLE_GAP_SVC_ATTR_TYPE { + /* Device Name, UUID 0x2a00 */ + NBLE_GAP_SVC_ATTR_NAME = 0, + /* Appearance, UUID 0x2a01 */ + NBLE_GAP_SVC_ATTR_APPEARANCE, + /* Peripheral Preferred Connection Parameters (PPCP), UUID 0x2a04 */ + NBLE_GAP_SVC_ATTR_PPCP = 4, + /* Central Address Resolution (CAR), UUID 0x2aa6, BT 4.2 */ + NBLE_GAP_SVC_ATTR_CAR = 0xa6, +}; + struct nble_gap_device_name { - /* Security mode for writing device name */ + /* Security mode for writing device name, see BLE_GAP_SEC_MODES */ uint8_t sec_mode; /* 0: no authorization, 1: authorization required */ uint8_t authorization; @@ -100,16 +113,7 @@ struct nble_gap_device_name { uint8_t name_array[20]; }; -struct nble_gap_connection_values { - /* Connection interval (unit 1.25 ms) */ - uint16_t interval; - /* Connection latency (unit interval) */ - uint16_t latency; - /* Connection supervision timeout (unit 10ms)*/ - uint16_t supervision_to; -}; - -struct nble_gap_connection_params { +struct nble_conn_param { /* minimal connection interval: range 0x0006 to 0x0c80 (unit 1.25ms) */ uint16_t interval_min; /* maximum connection interval: range 0x0006 to 0x0c80 must be bigger then min! */ @@ -120,52 +124,30 @@ struct nble_gap_connection_params { uint16_t link_sup_to; }; -struct nble_gap_scan_parameters { - /* If 1, perform active scanning (scan requests). */ - uint8_t active; - /* If 1, ignore unknown devices (non whitelisted). */ - uint8_t selective; - /* Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */ - uint16_t interval; - /* Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */ - uint16_t window; - /* Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */ - uint16_t timeout; -}; - struct nble_gap_service_req { - /* GAP Characteristics attribute type @ref BLE_GAP_SVC_ATTR_TYPE */ + /* GAP Characteristics attribute type see NBLE_GAP_SVC_ATTR_TYPE */ uint16_t attr_type; union { struct nble_gap_device_name name; /* Appearance UUID */ uint16_t appearance; /* Preferred Peripheral Connection Parameters */ - struct nble_gap_connection_params conn_params; + struct nble_conn_param ppcp; /* Central Address Resolution support 0: no, 1: yes */ uint8_t car; }; }; -struct nble_get_bda_rsp { - int status; - /* If @ref status ok */ - bt_addr_le_t bd; - void *user_data; -}; +void nble_gap_service_req(const struct nble_gap_service_req *req); -struct nble_service_write_response { - int status; - /* GAP Characteristics attribute type @ref BLE_GAP_SVC_ATTR_TYPE */ - uint16_t attr_type; - void *user_data; -}; - -struct nble_debug_params { +struct nble_dbg_req { uint32_t u0; uint32_t u1; + void *user_data; }; +void nble_dbg_req(const struct nble_dbg_req *req); + struct nble_dbg_rsp { int status; uint32_t u0; @@ -173,6 +155,8 @@ struct nble_dbg_rsp { void *user_data; }; +void on_nble_dbg_rsp(const struct nble_dbg_rsp *rsp); + typedef void (*nble_set_bda_cb_t)(int status, void *user_data); struct nble_set_bda_req { @@ -181,24 +165,54 @@ struct nble_set_bda_req { void *user_data; }; +void nble_set_bda_req(const struct nble_set_bda_req *req); + struct nble_set_bda_rsp { nble_set_bda_cb_t cb; void *user_data; int status; }; -struct bt_eir_data { +void on_nble_set_bda_rsp(const struct nble_set_bda_rsp *rsp); + +typedef void (*nble_get_bda_cb_t)(const bt_addr_le_t *bda, void *user_data); + +struct nble_get_bda_req { + nble_get_bda_cb_t cb; + void *user_data; +}; + +void nble_get_bda_req(const struct nble_get_bda_req *req); + +struct nble_get_bda_rsp { + nble_get_bda_cb_t cb; + void *user_data; + bt_addr_le_t bda; +}; + +void on_nble_get_bda_rsp(const struct nble_get_bda_rsp *rsp); + +struct nble_eir_data { uint8_t len; uint8_t data[31]; }; +struct nble_gap_set_adv_data_req { + /* Advertisement data, maybe 0 (length) */ + struct nble_eir_data ad; + /* Scan response data, maybe 0 (length) */ + struct nble_eir_data sd; +}; + +void nble_gap_set_adv_data_req(struct nble_gap_set_adv_data_req *req); + struct nble_gap_set_adv_params_req { uint16_t timeout; /* min interval 0xffff: use default 0x0800 */ uint16_t interval_min; /* max interval 0xffff: use default 0x0800 */ uint16_t interval_max; - /* advertisement types @ref GAP_ADV_TYPES */ + /* advertisement types see GAP_ADV_TYPES */ uint8_t type; /* filter policy to apply with white list */ uint8_t filter_policy; @@ -206,72 +220,41 @@ struct nble_gap_set_adv_params_req { bt_addr_le_t peer_bda; }; -struct nble_gap_set_adv_data_req { - /* Advertisement data, maybe 0 (length) */ - struct bt_eir_data ad; - /* Scan response data, maybe 0 (length) */ - struct bt_eir_data sd; -}; - -void nble_gap_service_req(const struct nble_gap_service_req *); - -void on_nble_get_bda_rsp(const struct nble_get_bda_rsp *par); - -void nble_gap_dbg_req(const struct nble_debug_params *par, void *user_data); - -void on_nble_dbg_rsp(const struct nble_dbg_rsp *rsp); - -void on_nble_set_bda_rsp(const struct nble_set_bda_rsp *par); - -void nble_set_bda_req(const struct nble_set_bda_req *par); - -void nble_gap_set_adv_data_req(struct nble_gap_set_adv_data_req *ad_data_params); - -void nble_gap_set_adv_params_req(struct nble_gap_set_adv_params_req *adv_params); +void nble_gap_set_adv_params_req(struct nble_gap_set_adv_params_req *req); void nble_gap_start_adv_req(void); -void on_nble_gap_start_adv_rsp(const struct nble_common_rsp *params); +void on_nble_gap_start_adv_rsp(const struct nble_common_rsp *rsp); void nble_gap_stop_adv_req(void *user_data); -void nble_gap_read_bda_req(void *priv); - -struct nble_gap_irk_info { - uint8_t irk[BLE_GAP_SEC_MAX_KEY_LEN]; -}; - struct nble_gap_conn_update_req { uint16_t conn_handle; - struct nble_gap_connection_params params; + struct nble_conn_param params; }; -void nble_gap_conn_update_req(const struct nble_gap_conn_update_req *par); +void nble_gap_conn_update_req(const struct nble_gap_conn_update_req *req); -struct nble_gap_connect_req { - bt_addr_le_t bda; - struct nble_gap_connection_params conn_params; - struct nble_gap_scan_parameters scan_params; -}; +void on_nble_gap_conn_update_rsp(const struct nble_common_rsp *rsp); struct nble_gap_disconnect_req { uint16_t conn_handle; uint8_t reason; }; -void nble_gap_disconnect_req(const struct nble_gap_disconnect_req *); +void nble_gap_disconnect_req(const struct nble_gap_disconnect_req *req); struct nble_sm_config_req { - /* Security options (@ref BLE_GAP_SM_OPTIONS) */ + /* Security options (see BLE_GAP_SM_OPTIONS) */ uint8_t options; - /* I/O Capabilities to allow passkey exchange (@ref BLE_GAP_IO_CAPABILITIES) */ + /* I/O Capabilities (see BLE_GAP_IO_CAPABILITIES) */ uint8_t io_caps; /* Maximum encryption key size (7-16) */ uint8_t key_size; uint8_t oob_present; }; -void nble_sm_config_req(const struct nble_sm_config_req *par); +void nble_sm_config_req(const struct nble_sm_config_req *req); struct nble_sm_config_rsp { void *user_data; @@ -279,8 +262,10 @@ struct nble_sm_config_rsp { bool sm_bond_dev_avail; }; -struct nble_gap_sm_pairing_params { - /* authentication level see @ref BLE_GAP_SM_OPTIONS */ +void on_nble_sm_config_rsp(struct nble_sm_config_rsp *rsp); + +struct nble_sm_pairing_param { + /* authentication level see BLE_GAP_SM_OPTIONS */ uint8_t auth_level; }; @@ -288,13 +273,19 @@ struct nble_sm_security_req { struct bt_conn *conn; uint16_t conn_handle; /* Local authentication/bonding parameters */ - struct nble_gap_sm_pairing_params params; + struct nble_sm_pairing_param params; }; -void nble_sm_security_req(const struct nble_sm_security_req *par); +void nble_sm_security_req(const struct nble_sm_security_req *req); -struct nble_gap_sm_passkey { - uint8_t type; +enum NBLE_SM_PASSKEY_TYPE { + NBLE_SM_REJECT = 0, + NBLE_SM_PK_PASSKEY, + NBLE_SM_PK_OOB, +}; + +struct nble_sm_passkey { + uint8_t type; /* see NBLE_SM_PASSKEY_TYPE */ union { uint32_t passkey; uint8_t oob[16]; @@ -305,25 +296,27 @@ struct nble_gap_sm_passkey { struct nble_sm_passkey_reply_req { struct bt_conn *conn; uint16_t conn_handle; - struct nble_gap_sm_passkey params; + struct nble_sm_passkey params; }; -void nble_sm_passkey_reply_req(const struct nble_sm_passkey_reply_req *par); +void nble_sm_passkey_reply_req(const struct nble_sm_passkey_reply_req *req); struct nble_sm_clear_bonds_req { bt_addr_le_t addr; }; -void nble_sm_clear_bonds_req(const struct nble_sm_clear_bonds_req *par); +void nble_sm_clear_bonds_req(const struct nble_sm_clear_bonds_req *req); struct nble_sm_common_rsp { int status; struct bt_conn *conn; }; +void on_nble_sm_common_rsp(const struct nble_sm_common_rsp *rsp); + struct nble_gap_set_rssi_report_req { uint16_t conn_handle; - /* RSSI operation @ref BLE_GAP_RSSI_OPS */ + /* RSSI operation see NBLE_GAP_RSSI_OPS */ uint8_t op; /* Channel for RSSI enabling */ uint8_t channel; @@ -333,23 +326,35 @@ struct nble_gap_set_rssi_report_req { uint8_t min_count; }; -void nble_gap_set_rssi_report_req(const struct nble_gap_set_rssi_report_req *par, +void nble_gap_set_rssi_report_req(const struct nble_gap_set_rssi_report_req *req, void *user_data); -void on_nble_gap_set_rssi_report_rsp(const struct nble_common_rsp *par); +void on_nble_gap_set_rssi_report_rsp(const struct nble_common_rsp *rsp); -struct nble_gap_start_scan_req { +struct nble_scan_param { uint16_t interval; uint16_t window; + /* Unused for the connection request */ uint8_t scan_type; + /* Unused for the connection request */ uint8_t use_whitelist; }; -void nble_gap_start_scan_req(const struct nble_gap_start_scan_req *par); +struct nble_gap_start_scan_req { + struct nble_scan_param scan_params; +}; + +void nble_gap_start_scan_req(const struct nble_gap_start_scan_req *req); void nble_gap_stop_scan_req(void); -void on_nble_gap_scan_start_stop_rsp(const struct nble_common_rsp *par); +void on_nble_gap_scan_start_stop_rsp(const struct nble_common_rsp *rsp); + +struct nble_gap_connect_req { + bt_addr_le_t bda; + struct nble_conn_param conn_params; + struct nble_scan_param scan_params; +}; void nble_gap_connect_req(const struct nble_gap_connect_req *req, void *user_data); @@ -358,65 +363,66 @@ void on_nble_gap_connect_rsp(const struct nble_common_rsp *rsp); void nble_gap_cancel_connect_req(void *user_data); -void on_nble_gap_cancel_connect_rsp(const struct nble_common_rsp *par); - -enum BLE_GAP_SET_OPTIONS { - BLE_GAP_SET_CH_MAP = 0, -}; - -struct nble_gap_channel_map { - /* connection on which to change channel map */ - uint16_t conn_handle; - /* 37 bits are used of the 40 bits (LSB) */ - uint8_t map[5]; -}; +void on_nble_gap_cancel_connect_rsp(const struct nble_common_rsp *rsp); +/* Temporary patch: RSSI processing for UAS */ struct nble_uas_rssi_calibrate_req { float distance; }; -void nble_uas_rssi_calibrate_req(const struct nble_uas_rssi_calibrate_req *); +void nble_uas_rssi_calibrate_req(const struct nble_uas_rssi_calibrate_req *req); +/* Temporary patch: RSSI processing for UAS */ struct nble_uas_bucket_change { uint8_t distance; }; -void on_nble_uas_bucket_change(const struct nble_uas_bucket_change *); -void nble_get_version_req(const struct nble_gap_get_version_param *params); - -void on_nble_get_version_rsp(const struct nble_get_version_rsp *params); +void on_nble_uas_bucket_change(const struct nble_uas_bucket_change *par); void nble_gap_dtm_init_req(void *user_data); +void on_nble_gap_dtm_init_rsp(void *user_data); + struct nble_gap_set_tx_power_req { int8_t tx_power; }; -void nble_gap_tx_power_req(const struct nble_gap_set_tx_power_req *params); +void nble_gap_set_tx_power_req(const struct nble_gap_set_tx_power_req *req); + +void on_nble_gap_set_tx_power_rsp(const struct nble_common_rsp *rsp); + +struct nble_conn_values { + /* Connection interval (unit 1.25 ms) */ + uint16_t interval; + /* Connection latency (unit interval) */ + uint16_t latency; + /* Connection supervision timeout (unit 10ms)*/ + uint16_t supervision_to; +}; struct nble_gap_connect_evt { uint16_t conn_handle; - struct nble_gap_connection_values conn_values; + struct nble_conn_values conn_values; /* 0 if connected as master, otherwise as slave */ uint8_t role_slave; /* Address of peer device */ bt_addr_le_t peer_bda; }; -void on_nble_gap_connect_evt(const struct nble_gap_connect_evt *ev); +void on_nble_gap_connect_evt(const struct nble_gap_connect_evt *evt); struct nble_gap_disconnect_evt { uint16_t conn_handle; uint8_t hci_reason; }; -void on_nble_gap_disconnect_evt(const struct nble_gap_disconnect_evt *ev); +void on_nble_gap_disconnect_evt(const struct nble_gap_disconnect_evt *evt); struct nble_gap_conn_update_evt { uint16_t conn_handle; - struct nble_gap_connection_values conn_values; + struct nble_conn_values conn_values; }; -void on_nble_gap_conn_update_evt(const struct nble_gap_conn_update_evt *ev); +void on_nble_gap_conn_update_evt(const struct nble_gap_conn_update_evt *evt); struct nble_gap_adv_report_evt { bt_addr_le_t addr; @@ -424,6 +430,9 @@ struct nble_gap_adv_report_evt { uint8_t adv_type; }; +void on_nble_gap_adv_report_evt(const struct nble_gap_adv_report_evt *evt, + const uint8_t *data, uint8_t len); + struct nble_gap_dir_adv_timeout_evt { uint16_t conn_handle; uint16_t error; @@ -431,20 +440,21 @@ struct nble_gap_dir_adv_timeout_evt { void on_nble_gap_dir_adv_timeout_evt(const struct nble_gap_dir_adv_timeout_evt *evt); -#define BLE_GAP_RSSI_EVT_SIZE 32 +#define BLE_GAP_RSSI_EVT_SIZE 32 + struct nble_gap_rssi_evt { uint16_t conn_handle; int8_t rssi_data[BLE_GAP_RSSI_EVT_SIZE]; }; -void on_nble_gap_rssi_evt(const struct nble_gap_rssi_evt *ev); +void on_nble_gap_rssi_evt(const struct nble_gap_rssi_evt *evt); struct nble_sm_passkey_req_evt { uint16_t conn_handle; uint8_t key_type; }; -void on_nble_sm_passkey_req_evt(const struct nble_sm_passkey_req_evt *); +void on_nble_sm_passkey_req_evt(const struct nble_sm_passkey_req_evt *evt); struct nble_sm_passkey_disp_evt { uint16_t conn_handle; @@ -453,6 +463,13 @@ struct nble_sm_passkey_disp_evt { void on_nble_sm_passkey_disp_evt(const struct nble_sm_passkey_disp_evt *evt); +enum NBLE_SM_STATUS_EVT { + NBLE_SM_STATUS_START_PAIRING, + NBLE_SM_STATUS_BONDING_COMPLETE, + NBLE_SM_STATUS_LINK_ENCRYPTED, + NBLE_SM_STATUS_LINK_SECURITY_CHANGE, +}; + struct nble_link_sec { bt_security_t sec_level; uint8_t enc_size; @@ -460,16 +477,15 @@ struct nble_link_sec { struct nble_sm_status_evt { uint16_t conn_handle; - uint8_t evt_type; + uint8_t evt_type; /* see NBLE_SM_STATUS_EVT */ int status; struct nble_link_sec enc_link_sec; }; -void on_nble_sm_status_evt(const struct nble_sm_status_evt *ev); +void on_nble_sm_status_evt(const struct nble_sm_status_evt *evt); -struct nble_gap_sm_bond_info; - -typedef void (*ble_bond_info_cb_t)(const struct nble_gap_sm_bond_info *info, +struct nble_sm_bond_info; +typedef void (*ble_bond_info_cb_t)(const struct nble_sm_bond_info *info, const bt_addr_le_t *addr, uint16_t len, void *user_data); @@ -479,9 +495,9 @@ struct nble_sm_bond_info_req { bool include_bonded_addrs; }; -void nble_sm_bond_info_req(const struct nble_sm_bond_info_req *params); +void nble_sm_bond_info_req(const struct nble_sm_bond_info_req *req); -struct nble_gap_sm_bond_info { +struct nble_sm_bond_info { int err; uint8_t addr_count; uint8_t irk_count; @@ -490,9 +506,46 @@ struct nble_gap_sm_bond_info { struct nble_sm_bond_info_rsp { ble_bond_info_cb_t cb; void *user_data; - struct nble_gap_sm_bond_info info; + struct nble_sm_bond_info info; }; +void on_nble_sm_bond_info_rsp(const struct nble_sm_bond_info_rsp *rsp, + const bt_addr_le_t *peer_addr, uint16_t len); + + +/* + * The following functions are NOT RPC functions + */ + +void ble_gap_get_bonding_info(ble_bond_info_cb_t func, void *user_data, + bool include_bonded_addrs); + +void ble_gap_get_version(ble_get_version_cb_t func); + +enum NBLE_GAP_RSSI_OPS { + NBLE_GAP_RSSI_DISABLE_REPORT = 0, + NBLE_GAP_RSSI_ENABLE_REPORT +}; + +typedef void (*rssi_report_t)(const int8_t *rssi_data); + +typedef void (*rssi_report_resp_t)(int status); + +struct ble_rssi_report_params { + /* RSSI operation see NBLE_GAP_RSSI_OPS */ + uint8_t op; + /* Channel for RSSI enabling */ + uint8_t channel; + /* minimum RSSI dBm change to report a new RSSI value */ + uint8_t delta_dBm; + /* number of delta_dBm changes before sending a new RSSI report */ + uint8_t min_count; +}; + +void ble_gap_set_rssi_report(struct ble_rssi_report_params *par, + struct bt_conn *conn, + rssi_report_resp_t resp_cb, rssi_report_t evt_cb); + struct nble { /* Local Bluetooth LE Device Address */ bt_addr_le_t addr; diff --git a/drivers/bluetooth/nble/gatt.c b/drivers/bluetooth/nble/gatt.c index dc134afa86c..fc2bd660da6 100644 --- a/drivers/bluetooth/nble/gatt.c +++ b/drivers/bluetooth/nble/gatt.c @@ -139,7 +139,7 @@ int bt_gatt_register(struct bt_gatt_attr *attrs, size_t count) for (i = 0; i < count; i++) { struct bt_gatt_attr *attr = &attrs[i]; - struct nble_gatt_attr *att; + struct nble_gatts_attr *att; int err; if (attr_table_size + sizeof(*att) > sizeof(attr_table)) { @@ -466,7 +466,7 @@ static int notify(struct bt_conn *conn, const struct bt_gatt_attr *attr, BT_DBG(""); - notif.conn_handle = conn->handle; + notif.params.conn_handle = conn->handle; notif.params.attr = attr; notif.params.offset = 0; notif.cback = NULL; @@ -568,9 +568,9 @@ int bt_gatt_indicate(struct bt_conn *conn, } if (conn) { - ind.conn_handle = conn->handle; + ind.params.conn_handle = conn->handle; } else { - ind.conn_handle = 0xffff; + ind.params.conn_handle = 0xffff; } ind.params.attr = (void *)params->attr; @@ -930,7 +930,7 @@ int bt_gatt_read(struct bt_conn *conn, struct bt_gatt_read_params *params) } void on_nble_gattc_read_rsp(const struct nble_gattc_read_rsp *rsp, - uint8_t *data, uint8_t len, void *user_data) + uint8_t *data, uint8_t len) { struct bt_gatt_read_params *params = rsp->user_data; struct bt_conn *conn; @@ -1044,8 +1044,7 @@ static void gatt_write_ccc_rsp(struct bt_conn *conn, uint8_t err) /* TODO: Remove failed subscription */ } -void on_nble_gattc_write_rsp(const struct nble_gattc_write_rsp *rsp, - void *user_data) +void on_nble_gattc_write_rsp(const struct nble_gattc_write_rsp *rsp) { struct bt_conn *conn; void *private; @@ -1057,7 +1056,7 @@ void on_nble_gattc_write_rsp(const struct nble_gattc_write_rsp *rsp, return; } - BT_DBG("conn %p status %d user_data %p", conn, rsp->status, user_data); + BT_DBG("conn %p status %d", conn, rsp->status); private = gatt_get_private(conn); if (private == gatt_write_ccc_rsp) { diff --git a/drivers/bluetooth/nble/gatt_internal.h b/drivers/bluetooth/nble/gatt_internal.h index e691222b227..685f4a6c2b0 100644 --- a/drivers/bluetooth/nble/gatt_internal.h +++ b/drivers/bluetooth/nble/gatt_internal.h @@ -23,6 +23,23 @@ */ #define BLE_GATTS_MAX_SERVICES 10 +/* + * GATT Attribute stream structure. + * + * This structure is a "compressed" copy of bt_gatt_attr. + * UUID pointer and user_data pointer are used as offset into buffer itself. + * The offset is from the beginning of the buffer. therefore a value of 0 + * means that UUID or user_data is not present. + */ +struct nble_gatts_attr { + /* Attribute permissions */ + uint16_t perm; + /* Attribute variable data size */ + uint16_t data_size; + /* Attribute variable data: always starts with the UUID and data follows */ + uint8_t data[]; +}; + struct nble_gatts_register_req { /* Base address of the attribute table in the Quark mem space */ struct bt_gatt_attr *attr_base; @@ -30,6 +47,9 @@ struct nble_gatts_register_req { uint8_t attr_count; }; +void nble_gatts_register_req(const struct nble_gatts_register_req *req, + uint8_t *data, uint16_t len); + struct nble_gatts_register_rsp { int status; struct bt_gatt_attr *attr_base; @@ -37,6 +57,14 @@ struct nble_gatts_register_rsp { uint8_t attr_count; }; +struct nble_gatt_attr_handles { + uint16_t handle; +}; + +void on_nble_gatts_register_rsp(const struct nble_gatts_register_rsp *rsp, + const struct nble_gatt_attr_handles *attrs, + uint8_t len); + enum nble_gatt_wr_flag { NBLE_GATT_WR_FLAG_REPLY = 1, NBLE_GATT_WR_FLAG_PREP = 2, @@ -49,40 +77,55 @@ struct nble_gatts_write_evt { uint8_t flag; /* Cf. enum nble_gatt_wr_flag */ }; +void on_nble_gatts_write_evt(const struct nble_gatts_write_evt *evt, + const uint8_t *data, uint8_t len); + +struct nble_gatts_write_reply_req { + uint16_t conn_handle; + int32_t status; +}; + +void nble_gatts_write_reply_req(const struct nble_gatts_write_reply_req *req); + struct nble_gatts_write_exec_evt { uint16_t conn_handle; uint8_t flag; }; +void on_nble_gatts_write_exec_evt(const struct nble_gatts_write_exec_evt *evt); + struct nble_gatts_read_evt { struct bt_gatt_attr *attr; uint16_t conn_handle; uint16_t offset; }; +void on_nble_gatts_read_evt(const struct nble_gatts_read_evt *evt); + struct nble_gatts_read_reply_req { uint16_t conn_handle; uint16_t offset; int32_t status; }; -struct nble_gatts_write_reply_req { - uint16_t conn_handle; - int32_t status; -}; +void nble_gatts_read_reply_req(const struct nble_gatts_read_reply_req *req, + uint8_t *data, uint16_t len); -struct nble_gatt_notif_ind_params { +struct nble_gatts_value_change_param { const struct bt_gatt_attr *attr; + uint16_t conn_handle; uint16_t offset; }; struct nble_gatts_notify_req { /* Function to be invoked when buffer is freed */ bt_gatt_notify_func_t cback; - uint16_t conn_handle; - struct nble_gatt_notif_ind_params params; + struct nble_gatts_value_change_param params; }; +void nble_gatts_notify_req(const struct nble_gatts_notify_req *req, + const uint8_t *data, uint16_t len); + struct nble_gatts_notify_tx_evt { bt_gatt_notify_func_t cback; int status; @@ -90,25 +133,44 @@ struct nble_gatts_notify_tx_evt { struct bt_gatt_attr *attr; }; +void on_nble_gatts_notify_tx_evt(const struct nble_gatts_notify_tx_evt *evt); + struct nble_gatts_indicate_req { /* Function to be invoked when buffer is freed */ bt_gatt_indicate_func_t cback; - uint16_t conn_handle; - struct nble_gatt_notif_ind_params params; + struct nble_gatts_value_change_param params; }; +void nble_gatts_indicate_req(const struct nble_gatts_indicate_req *req, + const uint8_t *data, uint8_t len); + struct nble_gatts_indicate_rsp { bt_gatt_indicate_func_t cback; + struct bt_gatt_attr *attr; int status; uint16_t conn_handle; - struct bt_gatt_attr *attr; }; +void on_nble_gatts_indicate_rsp(const struct nble_gatts_indicate_rsp *rsp); + +#define DISCOVER_FLAGS_UUID_PRESENT 1 + struct nble_gatt_handle_range { uint16_t start_handle; uint16_t end_handle; }; +struct nble_gattc_discover_req { + void *user_data; + struct bt_uuid_128 uuid; + struct nble_gatt_handle_range handle_range; + uint16_t conn_handle; + uint8_t type; + uint8_t flags; +}; + +void nble_gattc_discover_req(const struct nble_gattc_discover_req *req); + struct nble_gattc_primary { uint16_t handle; struct nble_gatt_handle_range range; @@ -140,61 +202,8 @@ struct nble_gattc_discover_rsp { uint8_t type; }; -void nble_gatts_read_reply_req(const struct nble_gatts_read_reply_req *, - uint8_t *, uint16_t); - -void nble_gatts_write_reply_req(const struct nble_gatts_write_reply_req *req); - -void nble_gatts_register_req(const struct nble_gatts_register_req *req, - uint8_t *buf, uint16_t len); - -struct nble_gatt_attr_handles { - uint16_t handle; -}; - -void on_nble_gatts_register_rsp(const struct nble_gatts_register_rsp *par, - const struct nble_gatt_attr_handles *attr, - uint8_t len); - -void on_nble_gatts_write_evt(const struct nble_gatts_write_evt *ev, - const uint8_t *buf, uint8_t len); - -void nble_gatts_notify_req(const struct nble_gatts_notify_req *par, - const uint8_t *data, uint16_t length); - -void nble_gatts_indicate_req(const struct nble_gatts_indicate_req *par, - const uint8_t *data, uint8_t length); - -#define DISCOVER_FLAGS_UUID_PRESENT 1 - -struct nble_gattc_discover_req { - void *user_data; - struct bt_uuid_128 uuid; - struct nble_gatt_handle_range handle_range; - uint16_t conn_handle; - uint8_t type; - uint8_t flags; -}; - -void nble_gattc_discover_req(const struct nble_gattc_discover_req *req); - -/** GATT Attribute stream structure. - * - * This structure is a "compressed" copy of @ref bt_gatt_attr. - * UUID pointer and user_data pointer are used as offset into buffer itself. - * The offset is from the beginning of the buffer. therefore a value of 0 - * means that UUID or user_data is not present. */ -struct nble_gatt_attr { - /** Attribute permissions */ - uint16_t perm; - /** Attribute variable data size */ - uint16_t data_size; - /** - * Attribute variable data: always starts with the UUID and - * data follows - */ - uint8_t data[0]; -}; +void on_nble_gattc_discover_rsp(const struct nble_gattc_discover_rsp *rsp, + const uint8_t *data, uint8_t len); struct nble_gattc_read_req { void *user_data; @@ -203,10 +212,7 @@ struct nble_gattc_read_req { uint16_t offset; }; -struct nble_gattc_read_multi_req { - void *user_data; - uint16_t conn_handle; -}; +void nble_gattc_read_req(const struct nble_gattc_read_req *req); struct nble_gattc_read_rsp { int status; @@ -216,13 +222,26 @@ struct nble_gattc_read_rsp { uint16_t offset; }; -/* forward declaration */ -struct nble_gatt_write_params; +void on_nble_gattc_read_rsp(const struct nble_gattc_read_rsp *rsp, + uint8_t *data, uint8_t len); + +struct nble_gattc_read_multi_req { + void *user_data; + uint16_t conn_handle; +}; + +void nble_gattc_read_multi_req(const struct nble_gattc_read_multi_req *req, + const uint16_t *handles, uint16_t len); + +void on_nble_gattc_read_multi_rsp(const struct nble_gattc_read_rsp *rsp, + uint8_t *data, uint8_t len); + +struct nble_gattc_write_param; typedef void (*bt_att_func_t)(struct bt_conn *conn, uint8_t err, - const struct nble_gatt_write_params *wr_params); + const struct nble_gattc_write_param *par); -struct nble_gatt_write_params { +struct nble_gattc_write_param { /* Function invoked upon write response */ bt_att_func_t func; /* User specific data */ @@ -235,30 +254,37 @@ struct nble_gattc_write_req { uint16_t offset; /* different than 0 if response required */ uint8_t with_resp; - struct nble_gatt_write_params wr_params; + struct nble_gattc_write_param wr_params; }; +void nble_gattc_write_req(const struct nble_gattc_write_req *req, + const uint8_t *data, uint8_t len); + struct nble_gattc_write_rsp { - uint16_t conn_handle; int status; + uint16_t conn_handle; uint16_t handle; uint16_t len; - struct nble_gatt_write_params wr_params; + struct nble_gattc_write_param wr_params; }; -void nble_gattc_read_req(const struct nble_gattc_read_req *); - -void nble_gattc_write_req(const struct nble_gattc_write_req *params, - const uint8_t *buf, uint8_t len); - -void nble_gattc_read_multi_req(const struct nble_gattc_read_multi_req *params, - const uint16_t *data, uint16_t data_len); +void on_nble_gattc_write_rsp(const struct nble_gattc_write_rsp *rsp); +void bt_gatt_connected(struct bt_conn *conn); void bt_gatt_disconnected(struct bt_conn *conn); +enum NBLE_GATTC_EVT { + NBLE_GATTC_EVT_NOTIFICATION, + NBLE_GATTC_EVT_INDICATION, +}; + struct nble_gattc_value_evt { - uint16_t conn_handle; int status; + uint16_t conn_handle; uint16_t handle; + /* see NBLE_GATTC_VALUE_EVT */ uint8_t type; }; + +void on_nble_gattc_value_evt(const struct nble_gattc_value_evt *evt, + uint8_t *data, uint8_t len); diff --git a/drivers/bluetooth/nble/rpc_functions_to_ble_core.h b/drivers/bluetooth/nble/rpc_functions_to_ble_core.h index 6323c762f65..2511144bcdf 100644 --- a/drivers/bluetooth/nble/rpc_functions_to_ble_core.h +++ b/drivers/bluetooth/nble/rpc_functions_to_ble_core.h @@ -37,6 +37,7 @@ FN_SIG_S(nble_sm_clear_bonds_req, \ const struct nble_sm_clear_bonds_req *) \ FN_SIG_S(nble_set_bda_req, const struct nble_set_bda_req *) \ + FN_SIG_S(nble_get_bda_req, const struct nble_get_bda_req *) \ FN_SIG_S(nble_gap_conn_update_req, \ const struct nble_gap_conn_update_req *) \ FN_SIG_S(nble_gattc_discover_req, \ @@ -51,15 +52,15 @@ const struct nble_gap_disconnect_req *) \ FN_SIG_S(nble_gattc_read_req, \ const struct nble_gattc_read_req *) \ - FN_SIG_S(nble_gap_tx_power_req, \ + FN_SIG_S(nble_gap_set_tx_power_req, \ const struct nble_gap_set_tx_power_req *) \ - FN_SIG_S(nble_get_version_req, \ - const struct nble_gap_get_version_param *) + FN_SIG_S(nble_dbg_req, const struct nble_dbg_req *) + #define LIST_FN_SIG_P \ FN_SIG_P(nble_gap_dtm_init_req, void *) \ - FN_SIG_P(nble_gap_read_bda_req, void *) \ FN_SIG_P(nble_gap_stop_adv_req, void *) \ + FN_SIG_P(nble_get_version_req, ble_get_version_cb_t) \ FN_SIG_P(nble_gap_cancel_connect_req, void *) #define LIST_FN_SIG_S_B \ @@ -88,9 +89,7 @@ FN_SIG_S_P(nble_gap_connect_req, \ const struct nble_gap_connect_req *, void *) \ FN_SIG_S_P(nble_gap_set_rssi_report_req, \ - const struct nble_gap_set_rssi_report_req *, void *) \ - FN_SIG_S_P(nble_gap_dbg_req, const struct nble_debug_params *, \ - void *) + const struct nble_gap_set_rssi_report_req *, void *) #define LIST_FN_SIG_S_B_P