Commit graph

9787 commits

Author SHA1 Message Date
Lyle Zhu
bbc0f1fa57 Bluetooth: HFP_HF: Code clean
Remove useless function `bt_hfp_hf_send_cmd`.
And related callback `cmd_complete_cb`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
17b5aad978 Bluetooth: HFP_AG: Handle AT+CCWA command
Add a flag `BT_HFP_AG_CCWA_ENABLE` to keep the status of `Call Waiting
Notification`.

Set/clear the flag according to the value of received command AT+CCWA.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
c91d0f6239 Bluetooth: HFP_AG: Support Enhanced call status
Add a configuration `CONFIG_BT_HFP_AG_ECS` to enable the supported
feature `Enhanced call status`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
3ac6bfeb4a Bluetooth: HFP_AG: Hold incoming call
Add a flag `BT_HFP_AG_INCOMING_HELD` to identify the incoming call is
held.

Add a function `bt_hfp_ag_hold_incoming` to put the incoming call on
hold.

Add a callback `incoming_held` to notify the application the incoming
is held.

Handle AT command `AT+BTRH=x` to hold/accept/reject the incoming call.

Improve function `bt_hfp_hf_accept` to accept the held incoming call.

Improve function `bt_hfp_hf_reject` to reject the held incoming call.

Improve function `bt_hfp_hf_terminate` to terminate the held incoming
call.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
754bc39b07 Bluetooth: HFP_HF: Hold incoming call
Add a flag `BT_HFP_HF_FLAG_INCOMING_HELD` to identify the incoming call
is held.

Add a function `bt_hfp_hf_hold_incoming` to put the incoming call on
hold.

Handle the response `+BTRH` to get the incoming call status.

Add a callback `incoming_held` to notify the application the incoming
is held.

Remove callback `call_setup`. Add callback `outgoing` for call_setup=1,
`incoming` for call_setup=2, and `remote_ringing` for call_setup=3.

Remove callback `call`. Add callback `accept`, `reject`, `terminate`,
and `incoming_held`.
`accept` is triggered if the call is active.
`reject` is triggered if the incoming/
outgoing is not accepted but call is terminated.
`terminate` is triggered if the accepted is terminated.
`incoming_held` is triggered if the incoming call is held.

Improve function `bt_hfp_hf_accept` to accept the held incoming call.

Improve function `bt_hfp_hf_reject` to reject the held incoming call.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
074b8ae409 Bluetooth: HFP_HF: Turn off AG's EC and NR
Add a configuration `CONFIG_BT_HFP_HF_ECNR` to enable "EC and/or NR
function" of HFP HF.

Add a function `bt_hfp_hf_turn_off_ecnr` to turn off AG's EC and NR.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
ee20fc31a3 Bluetooth: HFP_AG: Handle command AT+NREC=0
Add a configuration to support "EC and/or NR function" of HFP AG.

Add a callback `ecnr_turn_off` to notify the application that "EC and/
or NR function" has been turned off.

Handle AT command AT+NREC=0. Only if the feature enabled, and the
callback `ecnr_turn_off` provided, the result code `OK` will be
responded.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
43d048e695 Bluetooth: HFP_HF: Support last number recalling
Add a function `bt_hfp_hf_redial` to initiate outgoing voice calls by
recalling the last number dialed by the AG.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
aec1f563df Bluetooth: HFP_HF: Support memory dialing
Add a function `bt_hfp_hf_memory_dial` to initiate outgoing voice
calls using the memory dialing feature of the AG.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
8164620378 Bluetooth: HFP_HF: Support phone number calling
Add a function `bt_hfp_hf_number_call` to initiate outgoing voice calls
by providing the destination phone number to the AG.

Add a callback `dialing` to notify the application the result from AG.

Add a flag `BT_HFP_HF_FLAG_DIALING` to make sure there is only one
dialing call at the same time.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
c1a856c1bd Bluetooth: HFP_AG: Add number dialing callback
Add phone number dialing callback if the ATDNnnn AT command is
received from HFP HF.
If the callback is NULL, the ATDNnnn AT command cannot be
supported by the HFP AG.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
d074c6a42b Bluetooth: HFP_HF: Add a function to terminate the call
Add a function `bt_hfp_hf_terminate` to terminate the active call.

Add a flag BT_HFP_HF_FLAG_ACTIVE to identify the call is active. Set
the flag if the call value is 1.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
02bcfad64e Bluetooth: HFP_HF: Add a function to reject the call
Add a function `bt_hfp_hf_reject` to reject the incoming call.

Add a flag BT_HFP_HF_FLAG_INCOMING to identify the incoming call.
Set the flag if the call_setup value is 1.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
28d8dc4376 Bluetooth: HFP_AG: Improve inband ringtone setting
Add a function `bt_hfp_ag_inband_ringtone` to enable/disable inband
ringtone.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
6307172cbb Bluetooth: HFP_HF: Improve codec negotiation
Add the configuration `BT_HFP_HF_CODEC_NEG` to configure the codec
negotiation feature.

Add a configuration `BT_HFP_HF_CODEC_MSBC` to support mSBC codec.

Add a configuration `BT_HFP_HF_CODEC_LC3_SWB` to support LC3 SWB codec.

Add a function `bt_hfp_hf_audio_connect` to trigger audio connection
sequence.

Add a function `bt_hfp_hf_select_codec` to response the codec
negotiation request.

Add a function `bt_hfp_hf_set_codecs` to notify the AG supported Codec
IDs of HF.

Handle unsolicited response `+BCS` sent from AG.

Send supported Codec IDs supported by HF if the SLC is established.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
7f791554a6 Bluetooth: HFP_AG: Improve codec negotiation
Add a configuration BT_HFP_AG_CODEC_NEG to configure the feature.

Add a function bt_hfp_ag_audio_connect to setup the codec negotiation
procedure.

Improve AT+BAC and AT+BCC handle.

Add callback codec_negotiate to notify the application of codec
negotiation result.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
62e652152e Bluetooth: HFP_AG: Improve extended error result codes
Add a configuration BT_HFP_AG_EXT_ERR for this feature.

If the feature is not set, response the ERROR to the peer if the AT
command AT+CMEE received.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
9b3013eee6 Bluetooth: HFP_AG: Add dedicated SDP features definition
Add a dedicated SDP features definition.

Set feature "Three-way calling" by default both in SDP features
definition and AT command features definition. Because it is set
by default in Spec.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
4a82422a66 Bluetooth: HFP_HF: Add a function to accept the call
Add a function `bt_hfp_hf_accept` to accept the incoming call.

Add a flag BT_HFP_HF_FLAG_INCOMING to identify the incoming call.
Set the flag if the call_setup value is 1.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
51c3b193cd Bluetooth: HFP_AG: Support network operator update
Expose a function to set the network operator and mode.

Response the AT+COPS? command with set mode and operator.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
4f74344959 Bluetooth: HHF_HF: Support read network operator
Add function `bt_hfp_hf_get_operator` to read the currently network
operator of AG.

Add callback `operator` to notify the application of the response.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
6a13044649 Bluetooth: HFP_HF: Send AT+VGM and AT+VGS after SLC established
Send AT command AT+VGM and AT+VGS after SLC established.

The `VGM` and `VGS` can be set by calling function `bt_hfp_hf_vgs` and
`bt_hfp_hf_vgs` in HF connection callback.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
be482f9555 Bluetooth: HFP_HF: Optimize initialization after SLC established
Add AT command sending structure to queue all AT commander needed to
be sent after the SLC established.

After the SLC established, send AT command line one by one.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
5e588fe3ad Bluetooth: at: support separator "="
Support separator "=".

If the separator is "=", only when result code is VGS" or "VGM", the
result code is valid.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
525e7b805c Bluetooth: HFP_AG: Support remote audio volume control
Handle AT commands AT+VGM and AT+VGS.

Add function to notify microphone and speaker gain.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
c6d2d0e817 Bluetooth: HFP_HF: Notify in-band ring setting
Handle the unsolicited result code +BSIR issued by the AG to indicate
to the HF that the in-band ring tone setting has been locally changed.

Add a callback `inband_ring` to notify the in-band ring tone setting.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
136bef7b36 Bluetooth: HFP_AG: Improve the call terminate
All set flags are cleared when call is terminated. But for case that
SLC is not disconnected, only call related flags should be cleared.

Just clear call related flags if the call is terminated.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
a5b12043bf Bluetooth: HFP_AG: Change log message to LOG_DBG
It is a debug log message. It should be logged by LOG_DBG instead of
LOG_ERR.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
b5f7fbe3a9 Bluetooth: HFP_AG: Fix AT+CLIP parse issue
The AT command `AT+CLIP=1` or `AT+CLIP=0` cannot be parsed correctly.

Check `=` before get AT command value.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
ee5acfe06c Bluetooth: HFP_HF: Add function to set vgm and vgs
Add function bt_hfp_hf_vgm to configure Gain of Microphone.

Add function bt_hfp_hf_vgs to configure Gain of Speaker.

These functions are controlled by configuration
`CONFIG_BT_HFP_HF_VOLUME`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
ad7fd30ecd Bluetooth: HFP_HF: handle unsolicited result code +VGS/+VGM
Handle the unsolicited result code +VGS and +VGM if the configuration
`CONFIG_BT_HFP_HF_VOLUME` is enabled.

Add a callback `vgm` to notify the application speaker microphone
notification if the configuration `CONFIG_BT_HFP_HF_VOLUME` is enabled.

Add a callback `vgs` to notify the application speaker gain
notification if the configuration `CONFIG_BT_HFP_HF_VOLUME` is enabled.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
c8c4c924dd Bluetooth: HFP_HF: Only send AT+CMEE=1 if AG supports
Only send AT command `AT+CMEE=1` if HFP_AG supports "Extended Error
result code".

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
ee2fddefcf Bluetooth: HFP_HF: Add function bt_hfp_hf_cli
Add tx pending queue to queue call AT commands.

Add a function bt_hfp_hf_cli to enable/disable CLI notification.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
8c61b9cea6 Bluetooth: HFP_HF: Support unsolicited result code +CLIP
Handle the unsolicited result code +CLIP.

Add a callback `clip` to notify the application if the configuration
`CONFIG_BT_HFP_HF_CLI` is enabled.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
e6d42cc37e Bluetooth: BR: at: add function at_get_string
Add a function at_get_string to get the string from the received AT
result code.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
db37676b41 Bluetooth: HFP_HF: Improve the feature configuration
Add Kconfig to configure the HF `CLI` and `VOLUME` features.

Add a macro `BT_HFP_HF_SDP_SUPPORTED_FEATURES` for SDP HF record.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-03 06:24:32 +02:00
Lyle Zhu
bfbe764cb3 Bluetooth: Classic: Check LK before clearing it
After SSP has been completed and before LK event notification, the
link key may be invalid when handling the ACL disconnection event.

Check `conn->br.link_key` before calling the function
`bt_keys_link_key_clear()` to clear it.

Fixes #87880.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-02 12:54:58 +02:00
Lyle Zhu
f9e8ecae26 Bluetooth: Classic: shell: Add command bonds
Add shell command `bonds` to list all the bonding information of
classic.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-01 22:18:40 +02:00
Lyle Zhu
8d819954e8 Bluetooth: Classic: Refactor query and deletion of bonding information
In current implementation, the bonding information of classic is
queried by calling the function `bt_foreach_bond()`. And the bonding
information of classic is deleted by calling `bt_unpair()`.

There are two issues if the LE and classic are bonded at same time for
dual mode peer device.
Issue 1, for the function `bt_foreach_bond()`, there are two bonding
information will be found. But there is no way to find which bonding
information belongs to LE or classic.
Issue 2, For the function `bt_unpair()`, all bonding information will
be deleted if the passed address is the public address. But there is
no way to delete the bonding information of LE or classic.

Remove the calling of function `bt_foreach_bond_br()` from the
function `bt_foreach_bond()`. And rename it to `bt_br_foreach_bond()`,
and public it as an API to query the bonding information of classic.

Remove the calling of function `bt_keys_link_key_clear_addr()` from
the function `bt_unpair()`. Add an API `bt_br_unpair()` to delete the
bonding information of classic.

Add a `br_bond_deleted` to structure `bt_conn_auth_info_cb` for
classic. The callback will be triggered if the bonding information has
been deleted by the function `bt_br_unpair()`.

Add a `clear` shell command for classic to delete the bonding
information.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-01 22:18:40 +02:00
Lyle Zhu
18beac9c57 Bluetooth: Classic: L2CAP: Support L2CAP_COMMAND_REJECT_RSP
In current implementation, when receiving the L2CAP frame
`L2CAP_COMMAND_REJECT_RSP` if the L2CAP is working as client role, the
L2CAP frame `L2CAP_COMMAND_REJECT_RSP` will be sent by the L2CAP
client incorrectly.

When the command response `L2CAP_COMMAND_REJECT_RSP` is received, find
the channel of the command request according to the received `ident`.
If the channel is found, try to disconnect the channel. If fail to
disconnect the channel, remove and delete the channel.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-01 22:14:15 +02:00
Lyle Zhu
384e31977f Bluetooth: Classic: L2CAP: Discard the response with a invalid ident
In current implementation, the `ident` of the command response is not
checked whether it is same as the `ident` sent by the L2CAP command.

Keep the `ident` of the command. If the received `ident` of the
command response is not aligned with the `ident` of the command,
discard the response silently. Or, clear the saved `ident`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-04-01 22:14:15 +02:00
Troels Nilsson
a3b8954ae9 Bluetooth: Controller: Fix assert when flushing multiple CISes
If more than one CIS in the same CIG was shutdown at the same time
(e.g. due to supervision timeout), the mayfly calling cis_tx_lll_flush
would be busy and the assert would be triggered

cis_tx_lll_flush now operates similar to cis_disabled_cb; Loop through
all CISes for a CIG and flush any marked as LLL_CIS_FLUSH_PENDING

Signed-off-by: Troels Nilsson <trnn@demant.com>
2025-04-01 22:14:03 +02:00
Johan Hedberg
39c2605930 Bluetooth: Fix deadlock with settings and bt_hci_cmd_send_sync()
We can't do synchronous HCI command sending in any settings commit()
callback, since we don't know what context the callback is being called
from. One particular deadlock can happen if settings_load() is called from
the preemptible main thread:

main()
 |--> settings_load() (aquire settings_lock mutex)
       |-->commit callback A that defers to system wq
       |-->commit callback B that calls bt_hci_cmd_send_sync()

system wq from the previous deferral from within settings_load():
 |--> work item
       |--> settings_save_one()
             |--> attempt to aquire settings_lock mutex

In the above scenario, the bt_hci_cmd_send_sync() call from the main thread
depends on the system workqueue being processed (since that's what does HCI
command processing by default), while at the same time holding the settings
subsystem's mutex. At the same time, a system wq item tries to store
something into settings, however it deadlocks waiting for the settings
mutex.

The actual scenario that we have in the Bluetooth subsystem is where
"commit callback A" is commit_settings() in host/settings.c, and "commit
callback B" is keys_commit() in host/keys.c.

The solution to the deadlock is to take advantage of deferred bt_id_add()
handling which already exists, i.e. set a flag and deferre the actual
adding to the system workqueue.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-04-01 16:28:00 +02:00
Ryan Chu
9ba60d3eb7 bluetooth: host: Apply callback changes of CS complete events
The CS complete callbacks provide both status and params.
In the case of errors, NULL pointer is passed to the params of callbacks.

Signed-off-by: Ryan Chu <ryan.chu@nordicsemi.no>
2025-04-01 16:26:58 +02:00
Ryan Chu
c9240cc99f bluetooth: host: Report status of Channel Sounding complete events
If the HCI status of a complete event is not BT_HCI_ERR_SUCCESS,
the remaining parameters could be invalid.

In this case, the params is passed as NULL pointer to the callbacks.
- LE CS Read Remote Supported Capabilities Complete event
- LE CS Read Remote FAE Table Complete event
- LE CS Config Complete event
- LE CS Security Enable Complete event
- LE CS Procedure Enable Complete event

This change avoids forwarding the invalid fileds to the applications.

Signed-off-by: Ryan Chu <ryan.chu@nordicsemi.no>
2025-04-01 16:26:58 +02:00
Sean Kyer
905aed99fa Bluetooth: Fixed null byte check in DIS UDI
Due to sizeof('\0') evaluating to 4 bytes instead of 1:
- Each UDI field had 4 instead of 1 'zero byte' appended
  (as specified by BLE spec).
- Any field of length 4 was being skipped entirely.

Signed-off-by: Sean Kyer <Sean.Kyer@analog.com>
2025-03-31 19:50:12 -04:00
Raúl Gotor
39c0c4f43c Bluetooth: Mesh: Shell: fixes publication period calculation
The publication period is defined by Steps and Resolution.
At BLE Mesh protocol level, the period is encoded in a byte
where first LSB 6 bits correspond to PerSteps and the last
two to PerRes. There is an issue on how the code at
`subsys/bluetooth/mesh/shell/cfg.c:model_pub_set` is encoding
these two values into the publication period byte.
This is commit fixes issue #87780

Signed-off-by: Raúl Gotor <raulgotor@gmail.com>
2025-03-31 19:48:10 -04:00
Troels Nilsson
c64494a32d Bluetooth: Controller: Fix return value for apto with illegal handles
If the connection handle given to a Read/Write Authenticated Payload
Timeout HCI command is a CIS or BIS handle, the error returned has to
be BT_HCI_ERR_CMD_DISALLOWED with the new TCRL

Fixes EBQ test failures in HCI/BIS/BI-14-C, HCI/BIS/BI-15-C,
HCI/CIS/BI-20-C and HCI/CIS/BI-22-C

Signed-off-by: Troels Nilsson <trnn@demant.com>
2025-03-31 22:01:46 +02:00
Aleksandr Khromykh
69c5c6f40e Bluetooth: Mesh: make corresponding group ID unique
Commit fixes bug when corresponding group ID was never
incremented for independent corresponding relationships.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2025-03-31 22:01:11 +02:00
Lyle Zhu
3bf18870f9 Bluetooth: Classic: SMP: Store derived LK if SMP_FLAG_BOND is set
When deriving the new LK, remove the old LK if it exists.

Store the derived LK if the flag `SMP_FLAG_BOND` of LE SMP is set.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-03-31 14:35:50 +02:00