Skip to content

Commit a3a1b40

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: HFP_HF: Transmit DTMF Code
Add a function `bt_hfp_hf_transmit_dtmf_code` to transmit DTMF Codes. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 43be8b8 commit a3a1b40

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

include/zephyr/bluetooth/classic/hfp_hf.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,20 @@ int bt_hfp_hf_ready_to_accept_audio(struct bt_hfp_hf *hf);
791791
*/
792792
int bt_hfp_hf_request_phone_number(struct bt_hfp_hf *hf);
793793

794+
/** @brief Handsfree HF Transmit A specific DTMF Code
795+
*
796+
* During an ongoing call, the HF transmits the AT+VTS command to
797+
* instruct the AG to transmit a specific DTMF code to its network
798+
* connection.
799+
* The set of the code is "0-9,#,*,A-D".
800+
*
801+
* @param call HFP HF call object.
802+
* @param code A specific DTMF code.
803+
*
804+
* @return 0 in case of success or negative value in case of error.
805+
*/
806+
int bt_hfp_hf_transmit_dtmf_code(struct bt_hfp_hf_call *call, char code);
807+
794808
#ifdef __cplusplus
795809
}
796810
#endif

subsys/bluetooth/host/classic/hfp_hf.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,59 @@ int bt_hfp_hf_request_phone_number(struct bt_hfp_hf *hf)
23342334
return err;
23352335
}
23362336

2337+
static int vts_finish(struct at_client *hf_at, enum at_result result,
2338+
enum at_cme cme_err)
2339+
{
2340+
struct bt_hfp_hf *hf = CONTAINER_OF(hf_at, struct bt_hfp_hf, at);
2341+
2342+
LOG_DBG("AT+VTS (result %d) on %p", result, hf);
2343+
2344+
return 0;
2345+
}
2346+
2347+
int bt_hfp_hf_transmit_dtmf_code(struct bt_hfp_hf_call *call, char code)
2348+
{
2349+
struct bt_hfp_hf *hf;
2350+
int err;
2351+
2352+
LOG_DBG("");
2353+
2354+
if (!call) {
2355+
LOG_ERR("Invalid call");
2356+
return -ENOTCONN;
2357+
}
2358+
2359+
hf = call->hf;
2360+
if (!hf) {
2361+
LOG_ERR("No HF connection found");
2362+
return -ENOTCONN;
2363+
}
2364+
2365+
if (!atomic_test_bit(hf->flags, BT_HFP_HF_FLAG_CONNECTED)) {
2366+
LOG_ERR("SLC is not established on %p", hf);
2367+
return -ENOTCONN;
2368+
}
2369+
2370+
if (!atomic_test_bit(call->flags, BT_HFP_HF_CALL_IN_USING) ||
2371+
(!(!atomic_test_bit(call->flags, BT_HFP_HF_CALL_INCOMING_HELD) &&
2372+
(atomic_get(call->state) == BT_HFP_HF_CALL_STATE_ACTIVE)))) {
2373+
LOG_ERR("Invalid call status");
2374+
return -EINVAL;
2375+
}
2376+
2377+
if (!IS_VALID_DTMF(code)) {
2378+
LOG_ERR("Invalid code");
2379+
return -EINVAL;
2380+
}
2381+
2382+
err = hfp_hf_send_cmd(hf, NULL, vts_finish, "AT+VTS=%c", code);
2383+
if (err < 0) {
2384+
LOG_ERR("Fail to tramsit DTMF Codes on %p", hf);
2385+
}
2386+
2387+
return err;
2388+
}
2389+
23372390
static int ata_finish(struct at_client *hf_at, enum at_result result,
23382391
enum at_cme cme_err)
23392392
{

subsys/bluetooth/host/classic/hfp_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,6 @@ enum hfp_hf_ag_indicators {
357357
#define BT_HFP_BVRA_STATE_SEND_AUDIO BIT(1)
358358
/* BVRA VRE state: the AG is processing the audio input */
359359
#define BT_HFP_BVRA_STATE_PROCESS_AUDIO BIT(2)
360+
361+
#define IS_VALID_DTMF(c) ((((c) >= '0') && ((c) <= '9')) || \
362+
(((c) >= 'A') && ((c) <= 'D')) || ((c) == '#') || ((c) == '*'))

0 commit comments

Comments
 (0)