Skip to content

Commit b622e74

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: HFP_AG: Send subscriber number info
Handle AT command `AT+CNUM`. Add a callback function `subscriber_number` to notify the upper layer that the HF needs to get subscriber number information from the AG. If there is subscriber number information needs to be sent, the passed function `bt_hfp_ag_query_subscriber_func_t func` can be called for this purpose. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 5dd3036 commit b622e74

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

include/zephyr/bluetooth/classic/hfp_ag.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,33 @@ enum bt_hfp_ag_indicator {
4444
struct bt_hfp_ag;
4545
struct bt_hfp_ag_call;
4646

47+
/** @typedef bt_hfp_ag_query_subscriber_func_t
48+
* @brief Query subscriber number callback function
49+
*
50+
* When AG wants to send subscriber number information, all information
51+
* will be passed through the callback. And the subscriber number
52+
* information will be sent out in this function.
53+
*
54+
* @param ag HFP AG object.
55+
* @param number Subscriber number.
56+
* @param type Type of subscriber number specifies the format of the phone number provided,
57+
* and can be one of the following values:
58+
* - values 128-143: The phone number format may be a national or international
59+
* format, and may contain prefix and/or escape digits. No changes on the number
60+
* presentation are required.
61+
* - values 144-159: The phone number format is an international number, including
62+
* the country code prefix. If the plus sign ("+") is not included as part of the
63+
* number and shall be added by the AG as needed.
64+
* - values 160-175: National number. No prefix nor escape digits included.
65+
* @param service Service of subscriber number indicates which service this phone number relates
66+
* to. Shall be either 4 (voice) or 5 (fax).
67+
*
68+
* @return 0 if should continue to the next subscriber number information.
69+
* @return negative value to stop.
70+
*/
71+
typedef int (*bt_hfp_ag_query_subscriber_func_t)(struct bt_hfp_ag *ag, char *number, uint8_t type,
72+
uint8_t service);
73+
4774
/** @brief HFP profile AG application callback */
4875
struct bt_hfp_ag_cb {
4976
/** HF AG connected callback to application
@@ -349,6 +376,18 @@ struct bt_hfp_ag_cb {
349376
* @param code A specific DTMF code.
350377
*/
351378
void (*transmit_dtmf_code)(struct bt_hfp_ag *ag, char code);
379+
380+
/** Get subscriber number callback
381+
*
382+
* If this callback is provided it will be called whenever the
383+
* AT command `AT+CNUM` is received.
384+
*
385+
* @param ag HFP AG object.
386+
* @param func Query subscriber number callback.
387+
*
388+
* @return 0 in case of success or negative value in case of error.
389+
*/
390+
int (*subscriber_number)(struct bt_hfp_ag *ag, bt_hfp_ag_query_subscriber_func_t func);
352391
};
353392

354393
/** @brief Register HFP AG profile

subsys/bluetooth/host/classic/hfp_ag.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3046,6 +3046,35 @@ static int bt_hfp_ag_vts_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
30463046
return 0;
30473047
}
30483048

3049+
static int send_subscriber_number(struct bt_hfp_ag *ag, char *number,
3050+
uint8_t type, uint8_t service)
3051+
{
3052+
int err;
3053+
3054+
err = hfp_ag_send_data(ag, NULL, NULL, "\r\n+CNUM:,\"%s\",%d,,%d\r\n",
3055+
number, type, service);
3056+
if (err) {
3057+
LOG_ERR("Fail to send subscriber number :(%d)", err);
3058+
}
3059+
return err;
3060+
}
3061+
3062+
static int bt_hfp_ag_cnum_handler(struct bt_hfp_ag *ag, struct net_buf *buf)
3063+
{
3064+
int err;
3065+
3066+
if (!is_char(buf, '\r')) {
3067+
return -ENOTSUP;
3068+
}
3069+
3070+
if (bt_ag && bt_ag->subscriber_number) {
3071+
err = bt_ag->subscriber_number(ag, send_subscriber_number);
3072+
return err;
3073+
}
3074+
3075+
return 0;
3076+
}
3077+
30493078
static struct bt_hfp_ag_at_cmd_handler cmd_handlers[] = {
30503079
{"AT+BRSF", bt_hfp_ag_brsf_handler}, {"AT+BAC", bt_hfp_ag_bac_handler},
30513080
{"AT+CIND", bt_hfp_ag_cind_handler}, {"AT+CMER", bt_hfp_ag_cmer_handler},
@@ -3059,7 +3088,7 @@ static struct bt_hfp_ag_at_cmd_handler cmd_handlers[] = {
30593088
{"AT+VGS", bt_hfp_ag_vgs_handler}, {"AT+NREC", bt_hfp_ag_nrec_handler},
30603089
{"AT+BTRH", bt_hfp_ag_btrh_handler}, {"AT+CCWA", bt_hfp_ag_ccwa_handler},
30613090
{"AT+BVRA", bt_hfp_ag_bvra_handler}, {"AT+BINP", bt_hfp_ag_binp_handler},
3062-
{"AT+VTS", bt_hfp_ag_vts_handler},
3091+
{"AT+VTS", bt_hfp_ag_vts_handler}, {"AT+CNUM", bt_hfp_ag_cnum_handler},
30633092
};
30643093

30653094
static void hfp_ag_connected(struct bt_rfcomm_dlc *dlc)

0 commit comments

Comments
 (0)