Skip to content

Commit 2011dcb

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: HFP_HF: Activate/deactivate AG indicators
Add a function `bt_hfp_hf_indicator_status` to activate/deactivate AG indicators. Signed-off-by: Lyle Zhu <[email protected]>
1 parent f915f86 commit 2011dcb

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

include/zephyr/bluetooth/classic/hfp_hf.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,35 @@ int bt_hfp_hf_transmit_dtmf_code(struct bt_hfp_hf_call *call, char code);
848848
*/
849849
int bt_hfp_hf_query_subscriber(struct bt_hfp_hf *hf);
850850

851+
/* HFP HF Indicators */
852+
enum hfp_hf_ag_indicators {
853+
HF_SERVICE_IND = 0, /* AG service indicator */
854+
HF_CALL_IND, /* AG call indicator */
855+
HF_CALL_SETUP_IND, /* AG call setup indicator */
856+
HF_CALL_HELD_IND, /* AG call held indicator */
857+
HF_SINGNAL_IND, /* AG signal indicator */
858+
HF_ROAM_IND, /* AG roaming indicator */
859+
HF_BATTERY_IND /* AG battery indicator */
860+
};
861+
862+
/** @brief Handsfree HF set AG indicator activated/deactivated status
863+
*
864+
* It allows HF to issue the AT+BIA command if it needs to change the
865+
* activated/deactivated status of indicators in the AG.
866+
* The index of all indicators can be activated/deactivated are
867+
* defined in `enum hfp_hf_ag_indicators`.
868+
* The each bit of parameter `status` represents the indicator status
869+
* corresponding to the index. Such as, value 0b111110 of `status`
870+
* means the AG indicator `service` is required to be deactivated.
871+
* Others are required to be activated.
872+
*
873+
* @param hf HFP HF object.
874+
* @param status The activated/deactivated bitmap status of AG indicators.
875+
*
876+
* @return 0 in case of success or negative value in case of error.
877+
*/
878+
int bt_hfp_hf_indicator_status(struct bt_hfp_hf *hf, uint8_t status);
879+
851880
#ifdef __cplusplus
852881
}
853882
#endif

subsys/bluetooth/host/classic/hfp_hf.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,6 +2461,67 @@ int bt_hfp_hf_query_subscriber(struct bt_hfp_hf *hf)
24612461
return err;
24622462
}
24632463

2464+
static int bia_finish(struct at_client *hf_at, enum at_result result,
2465+
enum at_cme cme_err)
2466+
{
2467+
struct bt_hfp_hf *hf = CONTAINER_OF(hf_at, struct bt_hfp_hf, at);
2468+
2469+
LOG_DBG("AT+BIA (result %d) on %p", result, hf);
2470+
2471+
return 0;
2472+
}
2473+
2474+
int bt_hfp_hf_indicator_status(struct bt_hfp_hf *hf, uint8_t status)
2475+
{
2476+
int err;
2477+
size_t index;
2478+
char buffer[HF_MAX_AG_INDICATORS * 2 + 1];
2479+
char *bia_status;
2480+
2481+
LOG_DBG("");
2482+
2483+
if (!hf) {
2484+
LOG_ERR("No HF connection found");
2485+
return -ENOTCONN;
2486+
}
2487+
2488+
if (!atomic_test_bit(hf->flags, BT_HFP_HF_FLAG_CONNECTED)) {
2489+
LOG_ERR("SLC is not established on %p", hf);
2490+
return -ENOTCONN;
2491+
}
2492+
2493+
bia_status = &buffer[0];
2494+
for (index = 0; index < ARRAY_SIZE(hf->ind_table); index++) {
2495+
if ((hf->ind_table[index] != -1) && (index < NUM_BITS(sizeof(status)))) {
2496+
if (status & BIT(hf->ind_table[index])) {
2497+
*bia_status = '1';
2498+
} else {
2499+
*bia_status = '0';
2500+
}
2501+
bia_status++;
2502+
*bia_status = ',';
2503+
bia_status++;
2504+
} else {
2505+
break;
2506+
}
2507+
}
2508+
2509+
if (bia_status <= &buffer[0]) {
2510+
LOG_ERR("Not found valid AG indicator on %p", hf);
2511+
return -EINVAL;
2512+
}
2513+
2514+
bia_status--;
2515+
*bia_status = '\0';
2516+
2517+
err = hfp_hf_send_cmd(hf, NULL, bia_finish, "AT+BIA=%s", buffer);
2518+
if (err < 0) {
2519+
LOG_ERR("Fail to activated/deactivated AG indicators on %p", hf);
2520+
}
2521+
2522+
return err;
2523+
}
2524+
24642525
static int ata_finish(struct at_client *hf_at, enum at_result result,
24652526
enum at_cme cme_err)
24662527
{

subsys/bluetooth/host/classic/hfp_internal.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,6 @@ struct bt_hfp_hf {
262262
ATOMIC_DEFINE(flags, BT_HFP_HF_NUM_FLAGS);
263263
};
264264

265-
enum hfp_hf_ag_indicators {
266-
HF_SERVICE_IND,
267-
HF_CALL_IND,
268-
HF_CALL_SETUP_IND,
269-
HF_CALL_HELD_IND,
270-
HF_SINGNAL_IND,
271-
HF_ROAM_IND,
272-
HF_BATTERY_IND
273-
};
274-
275265
/* HFP call setup status */
276266
#define BT_HFP_CALL_SETUP_NONE 0
277267
#define BT_HFP_CALL_SETUP_INCOMING 1

0 commit comments

Comments
 (0)