This adds the AT+COPS command. --- profiles/audio/hfp-hf.c | 48 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/profiles/audio/hfp-hf.c b/profiles/audio/hfp-hf.c index b49d40a43..ebe87d8db 100644 --- a/profiles/audio/hfp-hf.c +++ b/profiles/audio/hfp-hf.c @@ -107,6 +107,8 @@ HFP_HF_FEAT_ENHANCED_CALL_STATUS |\ HFP_HF_FEAT_ESCO_S4_T2) +#define MAX_OPERATOR_NAME_LEN 17 + enum hfp_indicator { HFP_INDICATOR_SERVICE = 0, HFP_INDICATOR_CALL, @@ -354,6 +356,49 @@ static void ciev_cb(struct hfp_context *context, void *user_data) } } +static void cops_cb(struct hfp_context *context, void *user_data) +{ + struct hfp_device *dev = user_data; + unsigned int format; + char name[MAX_OPERATOR_NAME_LEN]; + + DBG(""); + + /* Not interested in mode */ + hfp_context_skip_field(context); + + if (!hfp_context_get_number(context, &format)) + return; + + if (format != 0) { + warn("hf-client: Not correct string format in +COPS"); + return; + } + + if (!hfp_context_get_string(context, name, MAX_OPERATOR_NAME_LEN)) { + error("hf-client: incorrect +COPS response"); + return; + } + + telephony_set_operator_name(dev->telephony, name); +} + +static void cops_resp(enum hfp_result result, enum hfp_error cme_err, + void *user_data) +{ + struct hfp_device *dev = user_data; + + DBG(""); + + if (result != HFP_RESULT_OK) { + error("hf-client: COPS error: %d", result); + return; + } + + if (!hfp_hf_send_command(dev->hf, cmd_complete_cb, dev, "AT+COPS?")) + info("hf-client: Could not send AT+COPS?"); +} + static void slc_completed(struct hfp_device *dev) { int i; @@ -376,8 +421,9 @@ static void slc_completed(struct hfp_device *dev) /* TODO: register unsolicited results handlers */ hfp_hf_register(dev->hf, ciev_cb, "+CIEV", dev, NULL); + hfp_hf_register(dev->hf, cops_cb, "+COPS", dev, NULL); - if (!hfp_hf_send_command(dev->hf, cmd_complete_cb, NULL, "AT+COPS=3,0")) + if (!hfp_hf_send_command(dev->hf, cops_resp, dev, "AT+COPS=3,0")) info("hf-client: Could not send AT+COPS=3,0"); } -- 2.43.0