Remapping from BTSTACK 2.0 to 3.0 APIs
Scope and purpose
This document lists the specific changes that must be made in applications written on version < 3.0 to work on ver BTSTACK 3.0
1....... Remapping configuration
1.1.............. Security settings
1.2.............. Scan settings
1.3.............. Advert settings
1.4.............. Bluetooth LE settings
1.5.............. wiced_bt_cfg_l2cap_application_t wiced_app_cfg_l2cap
1.6.............. wiced_bt_cfg_gatt_t wiced_app_cfg_gatt
1.7.............. wiced_bt_cfg_rfcomm_t wiced_app_cfg_rfcomm
1.8.............. wiced_bt_cfg_avdt_t wiced_app_cfg_avdt
1.9.............. wiced_bt_cfg_avrc_t wiced_app_cfg_avrc
1.10............ wiced_bt_cfg_br_t
2....... Remapping the GATT server
2.1.............. Sending notifications, indications, multiple notifications
2.2.............. Remapping the client
2.3.............. Configure MTU
2.4.............. Send Read Req
2.5.............. Send Write Req
2.6.............. Send Execute Write
Old |
New |
wiced_bt_settings_t.security_requirement_mask; |
wiced_bt_settings_t.security_required; |
Old |
New |
wiced_bt_settings_t.ble_scan_cfg; |
wiced_bt_cfg_ble_scan_settings_t wiced_app_ble_scan_settings; |
Old |
New |
wiced_bt_settings_t.ble_advert_cfg; |
wiced_bt_cfg_ble_advert_settings_t wiced_app_ble_advert_settings; |
Old |
New |
wiced_bt_settings_t.max_simultaneous_links; |
wiced_bt_cfg_ble_t.ble_max_simultaneous_links |
wiced_bt_settings.l2cap_application.max_rx_mtu |
wiced_bt_cfg_ble_t.ble_max_rx_pdu_size |
wiced_bt_settings.appearance |
wiced_bt_cfg_ble_t.appearance |
wiced_bt_settings.rpa_refresh_timeout |
wiced_bt_cfg_ble_t.rpa_refresh_timeout |
wiced_bt_settings.addr_resolution_db_size |
wiced_bt_cfg_ble_t.host_addr_resolution_db_size |
|
wiced_bt_cfg_ble_t.p_ble_scan_cfg = &wiced_app_ble_scan_settings |
|
wiced_bt_cfg_ble_t.p_ble_advert_cfg = &wiced_app_ble_advert_settings |
wiced_bt_settings.default_ble_power_level; |
wiced_bt_cfg_ble_t.default_ble_power_level |
Old |
New |
wiced_bt_settings_t.l2cap_application.max_psm + wiced_bt_settings_t.l2cap_application.max_le_psm |
wiced_bt_cfg_l2cap_application_t.max_app_l2cap_psms |
wiced_bt_settings_t.l2cap_application.max_channels + wiced_bt_settings_t.l2cap_application.max_le_channels |
wiced_bt_cfg_l2cap_application_t.max_app_l2cap_channels |
wiced_bt_settings_t.l2cap_application.max_le_l2cap_fixed_channels; |
wiced_bt_cfg_l2cap_application_t.max_app_l2cap_le_fixed_channels |
wiced_bt_settings_t.l2cap_application.max_ertm_chnls; |
wiced_bt_cfg_l2cap_application_t.max_app_l2cap_br_edr_ertm_chnls |
wiced_bt_settings_t.l2cap_application.max_ertm_tx_win; |
wiced_bt_cfg_l2cap_application_t.max_app_l2cap_br_edr_ertm_tx_win |
Old |
New |
wiced_bt_settings_t.gatt_cfg.max_db_service_modules |
wiced_bt_cfg_gatt_t.max_db_service_modules |
wiced_bt_settings_t.gatt_cfg.max_gatt_bearers; |
wiced_bt_cfg_gatt_t.max_eatt_bearers |
Old |
New |
wiced_bt_settings_t.rfcomm_cfg.max_links |
wiced_bt_cfg_rfcomm_t.max_links |
wiced_bt_settings_t.rfcomm_cfg.max_ports |
wiced_bt_cfg_rfcomm_t.max_ports |
Old |
New |
wiced_bt_settings_t.avdt_cfg.max_links |
wiced_bt_cfg_avdt_t.max_links |
wiced_bt_settings_t.avdt_cfg.max_seps |
wiced_bt_cfg_avdt_t.max_seps |
Old |
New |
wiced_bt_settings_t.avrc_cfg.max_links |
wiced_bt_cfg_avrc_t.max_links |
Old |
New |
wiced_bt_settings_t.max_simultaneous_links; // was a shared setting in btstack2.0 |
wiced_bt_cfg_br_t.br_max_simultaneous_links |
wiced_bt_settings_t.gatt_cfg.l2cap_application.max_rx_pdu; // was a shared setting in btstack2.0 |
wiced_bt_cfg_br_t.br_max_rx_pdu_size |
wiced_bt_settings_t.device_class |
wiced_bt_cfg_br_t.device_class |
wiced_bt_settings_t.security_requirement_mask |
wiced_bt_cfg_br_t.security_requirement_mask |
|
wiced_bt_cfg_br_t.rfcomm_cfg = &wiced_bt_cfg_rfcomm |
|
wiced_bt_cfg_br_t.avdt_cfg = &wiced_bt_cfg_avdt |
|
wiced_bt_cfg_br_t.avrc_cfg = &wiced_bt_cfg_avrc |
Old server |
New Server |
Pre BTSTACK 3.0 server app switch(wiced_bt_gatt_attribute_request_t.request_type) { case GATTS_REQ_TYPE_READ : // handle wiced_bt_gatt_read_t // Return the response in // wiced_bt_gatt_read_t.p_val, wiced_bt_gatt_read_t.p_val_len break; case GATTS_REQ_TYPE_WRITE: // Called for GATT_REQ_WRITE, GATT_CMD_WRITE, GATT_CMD_SIGNED_WRITE // Application writes the data in wiced_bt_gatt_write_t.p_val of length // wiced_bt_gatt_write_t.val_len into the attribute handle and returns the // success or error code break; case GATTS_REQ_TYPE_WRITE_REQ: // Not used break; case GATTS_REQ_TYPE_PREP_WRITE: // Called for GATT_REQ_PREPARE_WRITE // Application queues up the data in wiced_bt_gatt_write_t.p_val of length // wiced_bt_gatt_write_t.val_len into the attribute handle and returns the // success or error code break; case GATTS_REQ_TYPE_WRITE_EXEC: // Called for GATT_REQ_EXEC_WRITE // Application executes the queueud writes based on the flag in wiced_bt_gatt_request_data_t.exec_write break; case GATTS_REQ_TYPE_MTU: // Called to inform application regarding the received mtu in wiced_bt_gatt_request_data.mtu break; case GATTS_REQ_TYPE_CONF: // Called to inform application regarding the received indication confirmation using // wiced_bt_gatt_request_data.handle break; case GATTS_REQ_TYPE_VALIDATE_READ: // Called to validate read operation on handle wiced_bt_gatt_request_data_t.handle break; } |
Post BTSTACK 3.0 server app switch(wiced_bt_gatt_attribute_request_t.opcode) { case GATT_REQ_MTU: // Application calls wiced_bt_gatt_server_send_mtu_rsp // with the desired mtu. break; case GATT_REQ_READ: case GATT_REQ_READ_BLOB: // structure used wiced_bt_gatt_attribute_request_t.data.read_req // Application calls wiced_bt_gatt_server_send_read_by_rsp, with a pointer at a offset // to the value of the requested attribute handle. // Ideally application does not need to allocate memory for this rsp since as a server // typically the handle has a value which can be read as a binary array. // The context in this case may be set to NULL, to avoid freeing the memory in the // GATT_APP_BUFFER_TRANSMITTED_EVT break; case GATT_REQ_READ_BY_TYPE: // structure used wiced_bt_gatt_attribute_request_t.data.read_by_type // Application allocates a // a) buffer of the size wiced_bt_gatt_attribute_request_t.len_requested // b) Set the s_handle to wiced_bt_gatt_read_by_type_t.s_handle // c) Use wiced_bt_gatt_find_by_type API to find the attr_handle for the // wiced_bt_gatt_read_by_type_t.uuid which lies between s_handle and // wiced_bt_gatt_read_by_type_t.e_handle // d) Call wiced_bt_gatt_put_read_by_type_rsp_in_stream to form the response // e) Set s_handle = attr_handle + 1 // f) Repeat (c) - (e) till the wiced_bt_gatt_put_read_by_type_rsp_in_stream returns 0. // g) Send the response with wiced_bt_gatt_server_send_read_by_type_rsp with valid length in // buffer else send an error response. // h) To free the allocated buffer sent in the success case, you can set the context to the // applicable free function, which are returned in the GATT_APP_BUFFER_TRANSMITTED_EVT break; case GATT_REQ_READ_MULTI: case GATT_REQ_READ_MULTI_VAR_LENGTH: // structure used wiced_bt_gatt_attribute_request_t.data.read_multiple_req // Application allocates a // a) buffer of the size wiced_bt_gatt_attribute_request_t.len_requested // b) Application loops through the handles received with wiced_bt_gatt_get_handle_from_stream // for upto wiced_bt_gatt_read_multiple_req_t.num_handles // c) for each handle, application gets the value of the handle and uses // wiced_bt_gatt_put_read_multi_rsp_in_stream to write response into allocated buffer // d) Once done, use wiced_bt_gatt_server_send_read_multi_rsp // e) To free the allocated buffer sent in the success case, you can set the context to the // applicable free function, which are returned in the GATT_APP_BUFFER_TRANSMITTED_EVT break; case GATT_REQ_WRITE: // Application writes the data in wiced_bt_gatt_write_t.p_val of length // wiced_bt_gatt_write_t.val_len into the attribute handle and // calls the wiced_bt_gatt_server_send_write_rsp in case of success else sends an error rsp break; case GATT_CMD_WRITE: case GATT_CMD_SIGNED_WRITE: // Application writes the data in wiced_bt_gatt_write_t.p_val of length // wiced_bt_gatt_write_t.val_len into the attribute handle and break; case GATT_REQ_PREPARE_WRITE: // Application queues up the data in wiced_bt_gatt_write_t.p_val of length // wiced_bt_gatt_write_t.val_len into the attribute handle and // calls the wiced_bt_gatt_server_send_prepare_write_rsp in case of success else sends an error rsp // Typically applications which support reliable writes are expected to have memory allocated for // queueing up writes upto the extent allowed for the specific handle. Hence it is advisable to // use the same memory for the response. Application may set the context to NULL to avoid a free // the buffer used in the response is returned using GATT_APP_BUFFER_TRANSMITTED_EVT break; case GATT_REQ_EXECUTE_WRITE: // Application executes the queued writes based on the flag in // wiced_bt_gatt_request_params_t_t.data.exec_flag // Application sends a success using wiced_bt_gatt_server_send_execute_write_rsp or // a failure using wiced_bt_gatt_server_send_error_rsp with the handle_in_error and status code. break; } |
Sending indications // Sending Indication. The stack allocates and copies the buffer p_val wiced_bt_gatt_status_t wiced_bt_gatt_send_indication (uint16_t conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t *p_val ); |
Sending indications // Sending Indication // Application passes the p_app_buffer in memory with the p_app_context // The buffer is returned to the app in the GATT_APP_BUFFER_TRANSMITTED_EVT wiced_bt_gatt_status_t wiced_bt_gatt_server_send_indication(uint16_t conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t *p_app_buffer, wiced_bt_gatt_app_context_t p_app_ctxt); |
Notifications, indications // Sending notification. The stack allocates and copies the buffer p_val wiced_bt_gatt_status_t wiced_bt_gatt_send_notification (uint16_t conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t *p_val ); |
Sending notifications // Sending notification // Application passes the p_app_buffer in memory with the p_app_context // The buffer is returned to the app in the GATT_APP_BUFFER_TRANSMITTED_EVT wiced_bt_gatt_status_t wiced_bt_gatt_server_send_notification(uint16_t conn_id, uint16_t attr_handle, uint16_t val_len, uint8_t *p_app_buffer, wiced_bt_gatt_app_context_t p_app_ctxt); |
Notifications, indications // Sending multiple notifications. The stack allocates and copies the data from the p_notifications wiced_bt_gatt_status_t wiced_bt_gatt_send_multiple_notifications (uint16_t conn_id, uint32_t num_notifications, wiced_bt_gatt_handle_length_value_t *p_notifications ); |
Sending multiple notifications // Sending multiple notification // The application allocates and forms the buffer with handle, length and data pairs. // Application passes the p_app_buffer in memory with the p_app_context // The buffer is returned to the app in the GATT_APP_BUFFER_TRANSMITTED_EVT wiced_bt_gatt_status_t wiced_bt_gatt_server_send_multi_notifications(uint16_t conn_id, uint16_t app_buffer_len, uint8_t *p_app_buffer, wiced_bt_gatt_app_context_t p_app_ctxt); |
Old client |
New client |
Events Handling Operation Complete events switch(wiced_bt_gatt_operation_complete_t.op) { case GATTC_OPTYPE_READ: // Read complete for GATT_REQ_READ, GATT_REQ_READ_BLOB, GATT_REQ_READ_BY_TYPE, // GATT_REQ_READ_MULTI, GATT_REQ_READ_MULTI_VAR_LEN // Event Data in wiced_bt_gatt_operation_complete_t.att_value // For GATT_REQ_READ_BY_TYPE & GATT_REQ_READ_MULTI_VAR_LEN the event is received multiple times // in the same context with wiced_bt_gatt_operation_complete_t.pending_events decrementing to 0. // // Application is expected to copy the incoming data to the specific handle break; case GATTC_OPTYPE_WRITE: // Write complete for GATT_REQ_WRITE, GATT_CMD_WRITE, GATT_CMD_SIGNED_WRITE, // and GATT_REQ_PREPRARE_WRITE initiated by the application // // Write Complete for GATT_REQ_WRITE and GATT_REQ_PREPRARE_WRITE is sent to the app after the // stack receives a response from the remote server // Write complete for GATT_CMD_WRITE, GATT_CMD_SIGNED_WRITE is sent immediately on transmission of // the command to the local controller. break; case GATTC_OPTYPE_EXE_WRITE: // Execute Write for execute write initiated from application break; case GATTC_OPTYPE_CONFIG: // Operation complete for wiced_bt_gatt_send_mtu. break; case GATTC_OPTYPE_NOTIFICATION: // Notification received from remote server, called for GATT_HANDLE_VALUE_NOTIF, GATT_HANDLE_VALUE_MULTI_NOTIF // // For GATT_HANDLE_VALUE_MULTI_NOTIF the event is received multiple times // in the same context with wiced_bt_gatt_operation_complete_t.pending_events decrementing to 0. // break; case GATTC_OPTYPE_INDICATION: // Indication received from remote server break; } |
Events Handling Operation Complete events switch(wiced_bt_gatt_operation_complete_t.op) { case GATTC_OPTYPE_READ_HANDLE: case GATTC_OPTYPE_READ_BY_TYPE: // Structure used: wiced_bt_gatt_operation_complete_rsp_t.att_value // Read complete for GATT_REQ_READ, GATT_REQ_READ_BLOB, // GATT_REQ_READ_BY_TYPE // // For GATT_REQ_READ_BY_TYPE & GATT_REQ_READ_MULTI_VAR_LEN the event is received multiple times // in the same context with wiced_bt_gatt_operation_complete_t.pending_events decrementing to 0. // // Application is expected to copy the incoming data to the specific handle break; case GATTC_OPTYPE_READ_MULTI: // Structure used: wiced_bt_gatt_operation_complete_rsp_t.multi_rsp; // Read complete for GATT_REQ_REQ_MULTI and GATT_REQ_READ_MULTI_VAR_LENGTH // // For GATT_REQ_READ_MULTI_VAR_LENGTH, the application invokes // wiced_bt_gatt_get_multi_handle_data_from_stream multiple times to get all the // data in the response. break; case GATTC_OPTYPE_WRITE_WITH_RSP: // Write complete for GATT_REQ_WRITE, GATT_REQ_PREPRARE_WRITE initiated by the application // // Write Complete for GATT_REQ_WRITE and GATT_REQ_PREPRARE_WRITE is sent to the app after the // stack receives a response from the remote server break; case GATTC_OPTYPE_WRITE_WITH_NO_RSP: // Write complete for GATT_CMD_WRITE, GATT_CMD_SIGNED_WRITE, // // Write complete for GATT_CMD_WRITE, GATT_CMD_SIGNED_WRITE is sent immediately on transmission of // the command to the local controller. break; case GATTC_OPTYPE_EXECUTE_WRITE: // Execute Write for execute write initiated from application break; case GATTC_OPTYPE_CONFIG_MTU: // Operation complete for wiced_bt_gatt_client_configure_mtu. break; case GATTC_OPTYPE_NOTIFICATION: // Notification received from remote server, GATT_HANDLE_VALUE_NOTIF, GATT_HANDLE_VALUE_MULTI_NOTIF // // For GATT_HANDLE_VALUE_MULTI_NOTIF the event is received multiple times // in the same context with wiced_bt_gatt_operation_complete_t.pending_events decrementing to 0. // break; case GATTC_OPTYPE_INDICATION: // Indication received from remote server break; } |
Send MTU Request // Send configure MTU wiced_bt_gatt_status_t wiced_bt_gatt_configure_mtu (uint16_t conn_id, uint16_t mtu); |
Send MTU Request // Sending Indication. The stack allocates and copies the buffer p_val wiced_bt_gatt_status_t wiced_bt_gatt_client_configure_mtu (uint16_t conn_id, uint16_t mtu); |
Send Read // Sending read. wiced_bt_gatt_status_t wiced_bt_gatt_send_read (uint16_t conn_id, wiced_bt_gatt_read_type_t type, wiced_bt_gatt_read_param_t *p_read); // To send GATT_REQ_READ,GATT_READ_BLOB set type = GATT_READ_BY_HANDLE, // To send GATT_REQ_READ_BY_TYPE, set type = GATT_READ_BY_TYPE // To send GATT_REQ_READ_MULTI, GATT_REQ_READ_MULTI_VAR_LEN, set type = GATT_READ_MULTIPLE |
Send Read // Sending read by handle wiced_bt_gatt_status_t wiced_bt_gatt_client_send_read_handle(uint16_t conn_id, uint16_t handle, uint16_t offset, uint8_t * p_read_buf, uint16_t len, wiced_bt_gatt_auth_req_t auth_req); // Sending read by type wiced_bt_gatt_status_t wiced_bt_gatt_client_send_read_by_type(uint16_t conn_id, uint16_t s_handle, uint16_t e_handle, wiced_bt_uuid_t *p_uuid, uint8_t *p_read_buf, uint16_t len, wiced_bt_gatt_auth_req_t auth_req); wiced_bt_gatt_status_t wiced_bt_gatt_client_send_read_multiple(uint16_t conn_id, wiced_bt_gatt_opcode_t opcode, int num_handles, uint8_t *p_handle_stream, wiced_bt_gatt_auth_req_t auth_req); |
Send MTU Request // Send Write The stack allocates and copies the buffer p_write->p_val // To send GATT_REQ_WRITE, set type = GATT_WRITE // To send GATT_CMD_WRITE, set type = GATT_WRITE_NO_RSP // To send GATT_SIGNED_WRITE, set type = GATT_WRITE_NO_RSP, and // p_write->auth = GATT_AUTH_REQ_SIGNED_NO_MITM or // p_write->auth = GATT_AUTH_REQ_SIGNED_MITM // To send GATT_REQ_PREPARE_WRITE, set type = GATT_WRITE_PREPARE wiced_bt_gatt_status_t wiced_bt_gatt_send_write (uint16_t conn_id, wiced_bt_gatt_write_type_t type, wiced_bt_gatt_value_t *p_write); |
Send Write // Sending Write. The stack sends the buffer in p_app_write_buffer // The buffer is returned to the application in the GATT_BUFFER_TRANSMITTED_EVT along with // p_app_ctxt, to allow application to free the data. // @note: wiced_bt_gatt_value ==> wiced_bt_gatt_write_hdr_t // To send GATT_REQ_WRITE, set opcode = GATT_REQ_WRITE // To send GATT_CMD_WRITE, set opcode = GATT_CMD_WRITE // To Send GATT_CMD_SIGNED_WRITE, set opcode = GATT_CMD_SIGNED_WRITE and // p_hdr->auth = GATT_AUTH_REQ_SIGNED_NO_MITM or // p_hdr->auth = GATT_AUTH_REQ_SIGNED_MITMp_hdr->auth = // To send GATT_REQ_PREPARE_WRITE, set opcode = GATT_REQ_PREPARE_WRITE wiced_bt_gatt_status_t wiced_bt_gatt_client_send_write(uint16_t conn_id, wiced_bt_gatt_opcode_t opcode, wiced_bt_gatt_write_hdr_t *p_hdr, uint8_t *p_app_write_buffer, wiced_bt_gatt_app_context_t p_app_ctxt); |
Send Execute Write // Send execute write wiced_bt_gatt_status_t wiced_bt_gatt_send_execute_write (uint16_t conn_id, wiced_bool_t is_execute); |
Send Execute Write // Send execute write wiced_bt_gatt_status_t wiced_bt_gatt_client_send_execute_write (uint16_t conn_id, wiced_bool_t is_execute); |
Attention:
Document version |
Date of release |
Description of changes |
1 |
2021-04-30 |
API Changes in BTSTACK3.0 |
|
|
|
|
|
|