Skip to content

Commit afa0906

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: HFP_AG: Set signal strength
Add a function `bt_hfp_ag_signal_strength` to set the signal strength. Signed-off-by: Lyle Zhu <[email protected]>
1 parent b622e74 commit afa0906

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

include/zephyr/bluetooth/classic/hfp_ag.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,17 @@ int bt_hfp_ag_vre_state(struct bt_hfp_ag *ag, uint8_t state);
703703
int bt_hfp_ag_vre_textual_representation(struct bt_hfp_ag *ag, uint8_t state, const char *id,
704704
uint8_t type, uint8_t operation, const char *text);
705705

706+
/** @brief Set signal strength
707+
*
708+
* Set signal strength.
709+
*
710+
* @param ag HFP AG object.
711+
* @param strength Signal strength.
712+
*
713+
* @return 0 in case of success or negative value in case of error.
714+
*/
715+
int bt_hfp_ag_signal_strength(struct bt_hfp_ag *ag, uint8_t strength);
716+
706717
#ifdef __cplusplus
707718
}
708719
#endif

subsys/bluetooth/host/classic/hfp_ag.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@ static int hfp_ag_update_indicator(struct bt_hfp_ag *ag, enum bt_hfp_ag_indicato
376376
int err;
377377
uint8_t old_value;
378378

379+
if (index >= BT_HFP_AG_IND_MAX) {
380+
return -EINVAL;
381+
}
382+
383+
if ((ag_ind[index].max < value) || (ag_ind[index].min > value)) {
384+
return -EINVAL;
385+
}
386+
379387
hfp_ag_lock(ag);
380388
old_value = ag->indicator_value[index];
381389
if (value == old_value) {
@@ -4612,3 +4620,29 @@ int bt_hfp_ag_vre_textual_representation(struct bt_hfp_ag *ag, uint8_t state, co
46124620
return -ENOTSUP;
46134621
#endif /* CONFIG_BT_HFP_AG_VOICE_RECG_TEXT */
46144622
}
4623+
4624+
int bt_hfp_ag_signal_strength(struct bt_hfp_ag *ag, uint8_t strength)
4625+
{
4626+
int err;
4627+
4628+
LOG_DBG("");
4629+
4630+
if (ag == NULL) {
4631+
return -EINVAL;
4632+
}
4633+
4634+
hfp_ag_lock(ag);
4635+
if (ag->state != BT_HFP_CONNECTED) {
4636+
hfp_ag_unlock(ag);
4637+
return -ENOTCONN;
4638+
}
4639+
hfp_ag_unlock(ag);
4640+
4641+
err = hfp_ag_update_indicator(ag, BT_HFP_AG_SIGNAL_IND, strength,
4642+
NULL, NULL);
4643+
if (err) {
4644+
LOG_ERR("Fail to set signal strength err :(%d)", err);
4645+
}
4646+
4647+
return err;
4648+
}

0 commit comments

Comments
 (0)