Bluetooth Classic
Bluedroid
The following Bluedroid APIs have been changed:
/bt/host/bluedroid/api/include/api/esp_hf_defs.h
Type
esp_hf_wbs_config_tis replaced byesp_hf_codec_mode_t. The new type identifies the negotiated codec (CVSD, mSBC, or LC3-SWB), not a Wideband Speech on/off flag.esp_hf_wbs_config_tis kept as a deprecated alias ofesp_hf_codec_mode_t.Enumerators are renamed. Numeric values 0 / 1 / 2 are unchanged. The old
ESP_HF_WBS_*names remain as macros that alias the new enumerators:
Old enumerator
New enumerator
Value
ESP_HF_WBS_NONE
ESP_HF_CODEC_NONE0
ESP_HF_WBS_NO
ESP_HF_CODEC_CVSD1
ESP_HF_WBS_YES
ESP_HF_CODEC_MSBC2
—
ESP_HF_CODEC_LC33
Existing
switchstatements and comparisons that useESP_HF_WBS_NOorESP_HF_WBS_YESstill compile. Prefer the new names in new code.
ESP_HF_CODEC_NONEmeans no codec has been negotiated, or the preference is reset to the stack default. It does not mean that CVSD is unavailable.ESP_HF_CODEC_CVSDis the selected narrowband codec, whether Wideband Speech is unsupported, disabled, or the link fell back from mSBC / LC3.
ESP_HF_CODEC_LC3is new. Code that indexes a three-entry table with the codec value must add an LC3 entry or a default branch.Do not use
esp_hf_codec_mode_tas a capability bitmap. Peer codec capabilities are reported separately asESP_HF_CODEC_CAP_CVSD/ESP_HF_CODEC_CAP_MSBC/ESP_HF_CODEC_CAP_LC3inESP_HF_BAC_RESPONSE_EVT.Audio connection state
ESP_HF_AUDIO_STATE_CONNECTED_LC3is added for an established LC3-SWB link, alongside the existingESP_HF_AUDIO_STATE_CONNECTED(CVSD) andESP_HF_AUDIO_STATE_CONNECTED_MSBCvalues.
ESP_HF_IND_TYPE_MAXandESP_HF_AT_RESPONSE_CODE_MAXare appended after the last defined enumerator. Existing values are unchanged. Aswitchon either enumeration that has nodefaultbranch fails to compile when-Werror=switchis enabled./bt/host/bluedroid/api/include/api/esp_hf_ag_api.h
esp_hf_ag_set_codec()now takesesp_hf_codec_mode_t. PassESP_HF_CODEC_CVSD,ESP_HF_CODEC_MSBC,ESP_HF_CODEC_LC3, orESP_HF_CODEC_NONEto restore the stack default.
ESP_HF_WBS_RESPONSE_EVT(wbs_rep): fieldcodecis nowesp_hf_codec_mode_t. The field namecodecis unchanged. Astatusfield (esp_bt_status_t) is added to report whether the request succeeded.
ESP_HF_BCS_RESPONSE_EVT(bcs_rep): fieldmodeis nowesp_hf_codec_mode_t. The field namemodeis unchanged.
esp_hf_ag_init()is deprecated. Useesp_hf_ag_init_with_cfg(). The old function still registers both HFP and HSP, which is the same asESP_HF_AG_INIT_CONFIG_DEFAULT().Set
service_masktoESP_HF_AG_SERVICE_HSPto register HSP only, orESP_HF_AG_SERVICE_HFPto register HFP only. A zero mask or any unknown bit returnsESP_ERR_INVALID_ARG. An HSP-only AG advertises Headset Audio Gateway (UUID0x1112). The peer must be an HSP Headset. The Bluedroid HF Client and thehfp_hfexample search only for Hands-Free AG (UUID0x111F) and will not connect.
ESP_HF_CONNECTION_STATE_EVT(conn_stat) addspeer_service. It isESP_HF_AG_SERVICE_HFPorESP_HF_AG_SERVICE_HSPfor the service that opened, and is reported again on SLC connected and disconnect. It is 0 when the open fails. When both services are registered, an outgoing connection can fall back from HFP to HSP, so the initialized mask does not identify the connected service.Call setup, call answer, call reject, call end, volume control, and audio connect or disconnect still apply on an HSP link. While handling those calls the stack may still submit HFP-only results such as indicator reports. Those results are dropped and a warning is logged. Ring and the SCO connection are unchanged.
The following calls apply to an HFP link only. On an HSP link the request is ignored and a warning is logged:
esp_hf_ag_ciev_report(),esp_hf_ag_cind_response(),esp_hf_ag_cops_response(),esp_hf_ag_clcc_response(), andesp_hf_ag_cnum_response().esp_hf_ag_set_codec()is also HFP only. On HSP,ESP_HF_WBS_RESPONSE_EVTreports failure.esp_hf_ag_vra_control()does not send+BVRAon an HSP link or when the peer does not support voice recognition, and a warning is logged. Audio is still connected or disconnected according to the requested state.
esp_hf_ag_register_callback()returnsESP_ERR_INVALID_ARGwhencallbackis NULL. It previously returnedESP_FAIL.
esp_hf_ag_vra_control()returnsESP_ERR_INVALID_ARGunlessvalueisESP_HF_VR_STATE_ENABLEDorESP_HF_VR_STATE_DISABLED.
esp_hf_ag_volume_control()returnsESP_ERR_INVALID_ARGunlesstypeisESP_HF_VOLUME_CONTROL_TARGET_SPKorESP_HF_VOLUME_CONTROL_TARGET_MIC. The volume range 0–15 is unchanged.
esp_hf_ag_cmee_send()returnsESP_ERR_INVALID_ARGwhenresponse_codeis outside[ESP_HF_AT_RESPONSE_CODE_OK, ESP_HF_AT_RESPONSE_CODE_MAX). Pass a definedesp_hf_cme_err_tvalue; that enumeration is sparse.
esp_hf_ag_unknown_at_send()still accepts a NULLunatand sends the default ERROR result.
esp_hf_ag_ciev_report()returnsESP_ERR_INVALID_ARGwhenind_typeis less thanESP_HF_IND_TYPE_CALLor greater than or equal toESP_HF_IND_TYPE_MAX.
esp_hf_ag_cind_response()returnsESP_ERR_INVALID_ARGwhen the call, call-setup, network, roaming, or call-held argument is outside its enumeration. Signal and battery level 0–5 were already rejected.Except for the NULL callback, the arguments above were previously forwarded and the call returned
ESP_OK./bt/host/bluedroid/api/include/api/esp_a2dp_api.h
ESP_A2D_MEDIA_CTRL_ACK_EVT(media_ctrl_stat) now includesconn_hdl, the A2DP connection handle of the command being acknowledged.Disconnect and media control can target a connection by handle. The handle is the
conn_hdlreported inESP_A2D_CONNECTION_STATE_EVT. The previous address-based and handle-less APIs remain, and are deprecated:
Deprecated API
Replacement
esp_a2d_sink_disconnect()
esp_a2d_sink_disconnect_by_handle()
esp_a2d_source_disconnect()
esp_a2d_source_disconnect_by_handle()
esp_a2d_media_ctrl()
esp_a2d_media_ctrl_by_handle()A handle that does not match a connected A2DP peer is not applied. Media control reports
ESP_A2D_MEDIA_CTRL_ACK_FAILURE. Disconnect is ignored.
esp_a2d_register_callback()returnsESP_ERR_INVALID_ARGwhencallbackis NULL. It previously returnedESP_FAIL.
esp_a2d_sink_disconnect()andesp_a2d_source_disconnect()returnESP_ERR_INVALID_ARGwhenremote_bdais NULL. They previously returnedESP_FAIL.
esp_a2d_sink_connect()andesp_a2d_source_connect()returnESP_ERR_INVALID_ARGwhenremote_bdais NULL. A NULL address was previously passed tomemcpy.
esp_a2d_sink_set_active_device()checks the stack status beforeconn_hdl. An invalid handle while the stack is disabled, or while deinitialization is in progress, returnsESP_ERR_INVALID_STATE. It previously returnedESP_ERR_INVALID_ARG./bt/host/bluedroid/api/include/api/esp_avrc_api.h
The
*_by_handleAVRCP Controller send APIs accept transaction labels0throughESP_USER_AVRC_TRANS_LABEL_MAX(13). Labels14and15are reserved for the stack (A2DP sink active-device Play/Pause). Passing 14 or 15 to those APIs returnsESP_ERR_INVALID_ARG. The deprecated send APIs still accept0throughESP_AVRC_TRANS_LABEL_MAX(15)./bt/host/bluedroid/api/include/api/esp_spp_api.h
esp_spp_write()inESP_SPP_MODE_CBcopies the whole buffer into the transmit buffer and returns immediately.ESP_OKmeans the data is queued, not that it has been sent. Iflencan never fit in the TX buffer, the call returnsESP_ERR_INVALID_SIZEand queues nothing. ForESP_ERR_INVALID_SIZE, waiting forESP_SPP_CONG_EVTdoes not help because the buffer never shrinks. Iflencan fit but the free space is smaller, the call returnsESP_ERR_NO_MEMand queues nothing. Retry that buffer only afterESP_SPP_CONG_EVTwithcongequal to false. AfterESP_OK, do not submit the same buffer again: a later failure inside the stack keeps the queued data and is not a reason to resend it.
ESP_SPP_CONG_EVTis only the uncongest edge of the TX buffer.congis always false. Becoming congested isESP_ERR_NO_MEMfromesp_spp_write(). Update code that waits forcong == true, or that treats everyESP_SPP_CONG_EVTas a signal to stop writing.
ESP_SPP_WRITE_EVTreports that one chunk, of at most the peer MTU, has been submitted to RFCOMM.statusisESP_SPP_SUCCESS. A failed submission is not reported through it.write.congcan still gate the next packet. Do not resend the same buffer from this event.
esp_spp_cb_param_t.write.congreports TX buffer congestion. It no longer reports RFCOMM congestion. Sending the next packet only afterESP_SPP_WRITE_EVTwithcongequal to false still works, but is not recommended. Prefer theesp_spp_write()return value andESP_SPP_CONG_EVT.
esp_spp_cfg_t::tx_buffer_sizemust be fromESP_SPP_MIN_TX_BUFFER_SIZE(100) toESP_SPP_MAX_TX_BUFFER_SIZE(ESP_SPP_MAX_MTU * 10). 0 is accepted in both modes:esp_spp_enhanced_init()usesESP_SPP_DEFAULT_TX_BUFFER_SIZEand logs a warning. Any other size outside this range returnsESP_ERR_INVALID_ARG.BT_SPP_DEFAULT_CONFIG()is VFS mode andBT_SPP_CB_MODE_DEFAULT_CONFIG()is callback mode. Both useESP_SPP_DEFAULT_TX_BUFFER_SIZE, which is currently equal to the maximum.Each open SPP connection allocates a transmit buffer of
tx_buffer_sizebytes inside Bluedroid.ESP_SPP_DEFAULT_TX_BUFFER_SIZEis currently 9900 bytes. With up to 8 connections, callback-mode applications have less internal RAM available than before, when this buffer was not allocated.
ESP_SPP_MODE_VFSwrite()still blocks until the data is queued. VFS applications do not handleESP_SPP_CONG_EVTorESP_SPP_WRITE_EVT.tx_buffer_size0 uses the default; any other value must be in the range above.bluetooth/bluedroid/classic_bt/bt_spp_initiator creates a task on
ESP_SPP_OPEN_EVTand loops onesp_spp_write().ESP_ERR_NO_MEMblocks that task untilESP_SPP_CONG_EVTwithcong == false.ESP_SPP_CLOSE_EVTstops the task, and the task deletes itself.// Before: the next write was started from ESP_SPP_WRITE_EVT, // and ESP_SPP_CONG_EVT reported both congested and uncongested. case ESP_SPP_WRITE_EVT: esp_spp_write(param->write.handle, len, data); break; case ESP_SPP_CONG_EVT: if (!param->cong.cong) { esp_spp_write(param->cong.handle, len, data); } break; // After: write from the application task. ESP_OK means queued. // ESP_ERR_NO_MEM waits for the uncongest event, then retries this buffer. esp_err_t err = esp_spp_write(handle, len, data); if (err == ESP_ERR_NO_MEM) { // block until ESP_SPP_CONG_EVT with cong == false } // ESP_SPP_WRITE_EVT only reports that a chunk was submitted to RFCOMM./bt/host/bluedroid/api/include/api/esp_hf_client_api.h
esp_hf_client_register_callback()returnsESP_ERR_INVALID_ARGwhencallbackis NULL. It previously returnedESP_FAIL.
esp_hf_client_volume_update()returnsESP_ERR_INVALID_ARGunlesstypeisESP_HF_VOLUME_CONTROL_TARGET_SPKorESP_HF_VOLUME_CONTROL_TARGET_MIC. The volume range 0–15 is unchanged.
esp_hf_client_dial_memory()returnsESP_ERR_INVALID_ARGwhenlocationis less than 1.
esp_hf_client_send_chld_cmd()returnsESP_ERR_INVALID_ARGwhenchldis outsideESP_HF_CHLD_TYPE_RELthroughESP_HF_CHLD_TYPE_PRIV_X, or whenidxis less than 1 forESP_HF_CHLD_TYPE_REL_XorESP_HF_CHLD_TYPE_PRIV_X.
esp_hf_client_send_btrh_cmd()returnsESP_ERR_INVALID_ARGwhenbtrhis outsideESP_HF_BTRH_CMD_HOLDthroughESP_HF_BTRH_CMD_REJECT.An invalid volume target, memory location, CHLD command, or BTRH command was previously accepted with
ESP_OKand then dropped in the stack./bt/host/bluedroid/api/include/api/esp_l2cap_bt_api.h
esp_bt_l2cap_register_callback()returnsESP_ERR_INVALID_ARGwhencallbackis NULL. It previously returnedESP_FAIL.
esp_bt_l2cap_connect()andesp_bt_l2cap_start_srv()returnESP_ERR_INVALID_ARGwhen(psm & 0x0101) != 0x0001(the PSM is even, or bit 8 is set).esp_bt_l2cap_connect()still returnsESP_ERR_INVALID_ARGfor a NULL peer address.esp_bt_l2cap_stop_srv()still forwards its PSM, and0still stops every server, the same asesp_bt_l2cap_stop_all_srv(). An invalid PSM on connect or start was previously forwarded and the call returnedESP_OK./bt/host/bluedroid/api/include/api/esp_spp_api.h
esp_spp_connect()returnsESP_ERR_INVALID_ARGwhenremote_scnis 0 or greater than or equal toESP_SPP_MAX_SCN(31), or whenroleis neitherESP_SPP_ROLE_MASTERnorESP_SPP_ROLE_SLAVE. A NULL peer address was already rejected.
esp_spp_start_srv()andesp_spp_start_srv_with_cfg()returnESP_ERR_INVALID_ARGwhenlocal_scnis greater than or equal toESP_SPP_MAX_SCN, or whenroleis neither master nor slave.local_scn0 still asks the stack to allocate a server channel. These values were previously forwarded and the call returnedESP_OK./bt/host/bluedroid/api/include/api/esp_sdp_api.h
esp_sdp_register_callback()returnsESP_ERR_INVALID_ARGwhencallbackis NULL. It previously returnedESP_FAIL.
esp_sdp_search_record()returnsESP_ERR_INVALID_ARGwhenbd_addris NULL, or whenuuid.lenis notESP_UUID_LEN_16,ESP_UUID_LEN_32, orESP_UUID_LEN_128. A NULL address previously faulted inmemcpy. An unsupported length was forwarded and the call returnedESP_OK./bt/host/bluedroid/api/include/api/esp_pbac_api.h
esp_pbac_register_callback()returnsESP_ERR_INVALID_ARGwhencallbackis NULL. It previously returnedESP_FAIL./bt/host/bluedroid/api/include/api/esp_gap_bt_api.h
esp_bt_gap_read_rssi_delta()andesp_bt_gap_read_acl_real_rssi()returnESP_ERR_INVALID_ARGwhenremote_addris NULL. A NULL address was previously passed tomemcpy.
esp_bt_gap_get_profile_status()checks the stack status beforeprofile_status. A NULLprofile_statuswhile the stack is disabled returnsESP_ERR_INVALID_STATE. It previously returnedESP_ERR_INVALID_ARG./bt/host/bluedroid/api/include/api/esp_bt_device.h
ESP_BT_DEV_COEX_TYPE_MAXis appended.ESP_BT_DEV_COEX_TYPE_BLEandESP_BT_DEV_COEX_TYPE_BTkeep their values. Aswitchwithout adefaultbranch needs the same treatment as the new HFP enumerators.
esp_bt_dev_coex_status_config()returnsESP_ERR_INVALID_ARGwhentypeis less thanESP_BT_DEV_COEX_TYPE_BLEor greater than or equal toESP_BT_DEV_COEX_TYPE_MAX. Those values were previously forwarded.
esp_bt_config_file_path_get()andesp_bt_config_file_path_update()returnESP_ERR_INVALID_ARGwhenfile_pathis NULL. They previously returnedESP_FAIL.esp_bt_config_file_path_update()still returnsESP_FAILwhen the path length is not less thanNVS_NS_NAME_MAX_SIZE./bt/host/bluedroid/api/include/api/esp_pan_api.h
ESP_PAN_OPENING_EVTand theopeningmember ofesp_pan_cb_param_tare removed. Acase ESP_PAN_OPENING_EVT:label no longer compiles. Remove that branch. The peer address and connection handle previously read fromparam->openingare reported onESP_PAN_OPEN_EVTasparam->open.remote_bdaandparam->open.handle.In ESP-IDF v6.2,
ESP_PAN_OPENING_EVTis 3 andESP_PAN_OPEN_EVTis 4. After the removal,ESP_PAN_OPEN_EVTis 3 and every later enumerator is one smaller. Code that switches on the numeric value 3 now handlesESP_PAN_OPEN_EVT. Switch on the enumerator names. The same shift applies toESP_PAN_CLOSE_EVTand every event after it.A connection that is still opening is no longer reported on its own. An open that does not complete is reported only as
ESP_PAN_OPEN_EVTwithstatusequal toESP_PAN_FAILURE.ESP_PAN_OPEN_EVTwithESP_PAN_SUCCESSis still reported when the connection completes.Function signatures are unchanged. An argument that was already valid still returns
ESP_OKwhen the request is sent. Code that only tests the result againstESP_OKdoes not need to change. Code that treats a NULL-pointer failure asESP_FAILmust acceptESP_ERR_INVALID_ARG.Suggested replacements:
// Before esp_hf_ag_set_codec(bda, ESP_HF_WBS_YES); if (param->bcs_rep.mode == ESP_HF_WBS_NO) { /* CVSD */ } // After esp_hf_ag_set_codec(bda, ESP_HF_CODEC_MSBC); if (param->bcs_rep.mode == ESP_HF_CODEC_CVSD) { /* CVSD */ } else if (param->bcs_rep.mode == ESP_HF_CODEC_LC3) { /* LC3-SWB */ } // Before esp_hf_ag_init(); // After: both services, same as the deprecated function esp_hf_ag_cfg_t cfg = ESP_HF_AG_INIT_CONFIG_DEFAULT(); esp_hf_ag_init_with_cfg(&cfg); // After: HSP only cfg.service_mask = ESP_HF_AG_SERVICE_HSP; esp_hf_ag_init_with_cfg(&cfg);