2011-09-15 16:34:34 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* oFono - Open Source Telephony
|
|
|
|
*
|
2011-10-10 20:39:48 +00:00
|
|
|
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
|
2011-10-15 19:21:30 +00:00
|
|
|
* Copyright (C) 2011 BMW Car IT GmbH. All rights reserved.
|
2011-09-15 16:34:34 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gatchat.h>
|
|
|
|
#include <gatresult.h>
|
|
|
|
|
|
|
|
#include <ofono/log.h>
|
|
|
|
#include <ofono/modem.h>
|
|
|
|
#include <ofono/handsfree.h>
|
|
|
|
|
|
|
|
#include "hfpmodem.h"
|
2013-04-09 04:44:59 +00:00
|
|
|
#include "hfp.h"
|
2011-09-15 16:34:34 +00:00
|
|
|
#include "slc.h"
|
|
|
|
|
2011-10-12 12:35:30 +00:00
|
|
|
static const char *binp_prefix[] = { "+BINP:", NULL };
|
2011-10-21 16:51:28 +00:00
|
|
|
static const char *bvra_prefix[] = { "+BVRA:", NULL };
|
2015-03-24 16:04:25 +00:00
|
|
|
static const char *none_prefix[] = { NULL };
|
2011-10-12 12:35:30 +00:00
|
|
|
|
2011-09-15 16:34:34 +00:00
|
|
|
struct hf_data {
|
|
|
|
GAtChat *chat;
|
2011-10-12 12:35:26 +00:00
|
|
|
unsigned int ag_features;
|
2014-03-19 15:20:28 +00:00
|
|
|
unsigned int ag_chld_features;
|
2012-12-17 15:26:10 +00:00
|
|
|
int battchg_index;
|
2011-10-21 16:51:34 +00:00
|
|
|
guint register_source;
|
2011-09-15 16:34:34 +00:00
|
|
|
};
|
|
|
|
|
2011-10-21 16:51:28 +00:00
|
|
|
static void hf_generic_set_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_handsfree_cb_t cb = cbd->cb;
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
cb(&error, cbd->data);
|
|
|
|
}
|
|
|
|
|
2011-10-20 16:38:06 +00:00
|
|
|
static void bsir_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_handsfree *hf = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+BSIR:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &value))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ofono_handsfree_set_inband_ringing(hf, (ofono_bool_t) value);
|
|
|
|
}
|
|
|
|
|
2011-10-21 16:51:28 +00:00
|
|
|
static void bvra_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_handsfree *hf = user_data;
|
|
|
|
GAtResultIter iter;
|
|
|
|
int value;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+BVRA:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &value))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ofono_handsfree_voice_recognition_notify(hf, (ofono_bool_t) value);
|
|
|
|
}
|
|
|
|
|
2012-12-17 15:26:10 +00:00
|
|
|
static void ciev_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_handsfree *hf = user_data;
|
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
|
|
|
int index;
|
|
|
|
int value;
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+CIEV:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &index))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (index != hd->battchg_index)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &value))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ofono_handsfree_battchg_notify(hf, value);
|
|
|
|
}
|
|
|
|
|
2014-04-08 08:21:47 +00:00
|
|
|
static void cnum_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_handsfree_cnum_query_cb_t cb = cbd->cb;
|
|
|
|
GAtResultIter iter;
|
|
|
|
struct ofono_phone_number *list = NULL;
|
|
|
|
int num = 0;
|
|
|
|
struct ofono_error error;
|
|
|
|
|
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
if (!ok)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
while (g_at_result_iter_next(&iter, "+CNUM:"))
|
|
|
|
num++;
|
|
|
|
|
|
|
|
if (num == 0)
|
|
|
|
goto out;
|
|
|
|
|
2014-04-10 15:04:12 +00:00
|
|
|
list = g_new0(struct ofono_phone_number, num);
|
2014-04-08 08:21:47 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
for (num = 0; g_at_result_iter_next(&iter, "+CNUM:"); ) {
|
|
|
|
const char *number;
|
|
|
|
int service;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_skip_next(&iter))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_string(&iter, &number))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &type))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_skip_next(&iter))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &service))
|
|
|
|
continue;
|
|
|
|
|
2014-04-10 15:04:12 +00:00
|
|
|
/* We are only interested in Voice services */
|
|
|
|
if (service != 4)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
strncpy(list[num].number, number,
|
|
|
|
OFONO_MAX_PHONE_NUMBER_LENGTH);
|
|
|
|
list[num].number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0';
|
|
|
|
list[num].type = type;
|
|
|
|
|
|
|
|
DBG("cnum_notify:%s", list[num].number);
|
|
|
|
num++;
|
2014-04-08 08:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
cb(&error, num, list, cbd->data);
|
|
|
|
|
|
|
|
g_free(list);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-04-10 15:04:36 +00:00
|
|
|
static void hfp_cnum_query(struct ofono_handsfree *hf,
|
|
|
|
ofono_handsfree_cnum_query_cb_t cb, void *data)
|
2014-04-08 08:21:47 +00:00
|
|
|
{
|
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
2015-03-24 16:04:25 +00:00
|
|
|
if (g_at_chat_send(hd->chat, "AT+CNUM", none_prefix,
|
2014-04-08 08:21:47 +00:00
|
|
|
cnum_query_cb, cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, -1, NULL, data);
|
|
|
|
}
|
|
|
|
|
2014-01-27 17:56:33 +00:00
|
|
|
static void bind_notify(GAtResult *result, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_handsfree *hf = user_data;
|
|
|
|
int hf_indicator;
|
|
|
|
int active;
|
|
|
|
GAtResultIter iter;
|
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+BIND:"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &hf_indicator))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &active))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ofono_handsfree_hf_indicator_active_notify(hf, hf_indicator, active);
|
|
|
|
}
|
|
|
|
|
2011-09-15 16:34:34 +00:00
|
|
|
static gboolean hfp_handsfree_register(gpointer user_data)
|
|
|
|
{
|
|
|
|
struct ofono_handsfree *hf = user_data;
|
2011-10-12 12:35:26 +00:00
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
2011-09-15 16:34:34 +00:00
|
|
|
|
2011-10-21 16:51:34 +00:00
|
|
|
hd->register_source = 0;
|
|
|
|
|
2011-10-20 16:38:06 +00:00
|
|
|
g_at_chat_register(hd->chat, "+BSIR:", bsir_notify, FALSE, hf, NULL);
|
2011-10-21 16:51:28 +00:00
|
|
|
g_at_chat_register(hd->chat, "+BVRA:", bvra_notify, FALSE, hf, NULL);
|
2012-12-17 15:26:10 +00:00
|
|
|
g_at_chat_register(hd->chat, "+CIEV:", ciev_notify, FALSE, hf, NULL);
|
2014-01-27 17:56:33 +00:00
|
|
|
g_at_chat_register(hd->chat, "+BIND:", bind_notify, FALSE, hf, NULL);
|
2011-10-20 16:38:06 +00:00
|
|
|
|
2011-10-12 12:35:26 +00:00
|
|
|
if (hd->ag_features & HFP_AG_FEATURE_IN_BAND_RING_TONE)
|
|
|
|
ofono_handsfree_set_inband_ringing(hf, TRUE);
|
|
|
|
|
2011-10-21 16:51:31 +00:00
|
|
|
ofono_handsfree_set_ag_features(hf, hd->ag_features);
|
2014-03-19 15:20:28 +00:00
|
|
|
ofono_handsfree_set_ag_chld_features(hf, hd->ag_chld_features);
|
2011-10-13 18:06:35 +00:00
|
|
|
ofono_handsfree_register(hf);
|
|
|
|
|
2011-09-15 16:34:34 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hfp_handsfree_probe(struct ofono_handsfree *hf,
|
|
|
|
unsigned int vendor, void *data)
|
|
|
|
{
|
|
|
|
struct hfp_slc_info *info = data;
|
|
|
|
struct hf_data *hd;
|
2014-01-27 17:56:44 +00:00
|
|
|
unsigned int i;
|
2011-09-15 16:34:34 +00:00
|
|
|
|
|
|
|
DBG("");
|
|
|
|
hd = g_new0(struct hf_data, 1);
|
|
|
|
hd->chat = g_at_chat_clone(info->chat);
|
2011-10-12 12:35:26 +00:00
|
|
|
hd->ag_features = info->ag_features;
|
2014-03-19 15:20:28 +00:00
|
|
|
hd->ag_chld_features = info->ag_mpty_features;
|
2011-09-15 16:34:34 +00:00
|
|
|
|
|
|
|
ofono_handsfree_set_data(hf, hd);
|
|
|
|
|
2012-12-17 15:26:10 +00:00
|
|
|
hd->battchg_index = info->cind_pos[HFP_INDICATOR_BATTCHG];
|
|
|
|
ofono_handsfree_battchg_notify(hf,
|
|
|
|
info->cind_val[HFP_INDICATOR_BATTCHG]);
|
|
|
|
|
2014-01-27 17:56:44 +00:00
|
|
|
ofono_handsfree_set_hf_indicators(hf, info->hf_indicators,
|
|
|
|
info->num_hf_indicators);
|
|
|
|
|
|
|
|
for (i = 0; i < info->num_hf_indicators; i++)
|
|
|
|
ofono_handsfree_hf_indicator_active_notify(hf,
|
|
|
|
info->hf_indicators[i],
|
|
|
|
info->hf_indicator_active_map & (1 << i));
|
|
|
|
|
2011-10-21 16:51:34 +00:00
|
|
|
hd->register_source = g_idle_add(hfp_handsfree_register, hf);
|
2011-09-15 16:34:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_handsfree_remove(struct ofono_handsfree *hf)
|
|
|
|
{
|
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
|
|
|
|
2011-10-21 16:51:34 +00:00
|
|
|
if (hd->register_source != 0)
|
|
|
|
g_source_remove(hd->register_source);
|
|
|
|
|
2011-09-15 16:34:34 +00:00
|
|
|
ofono_handsfree_set_data(hf, NULL);
|
|
|
|
|
|
|
|
g_at_chat_unref(hd->chat);
|
|
|
|
g_free(hd);
|
|
|
|
}
|
|
|
|
|
2011-10-12 12:35:30 +00:00
|
|
|
static void hfp_request_phone_number_cb(gboolean ok, GAtResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
struct cb_data *cbd = user_data;
|
|
|
|
ofono_handsfree_phone_cb_t cb = cbd->cb;
|
|
|
|
GAtResultIter iter;
|
2011-10-13 18:47:56 +00:00
|
|
|
struct ofono_error error;
|
2011-10-12 12:35:30 +00:00
|
|
|
const char *num;
|
|
|
|
int type;
|
|
|
|
struct ofono_phone_number phone_number;
|
|
|
|
|
2011-10-13 18:47:56 +00:00
|
|
|
decode_at_error(&error, g_at_result_final_response(result));
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
cb(&error, NULL, cbd->data);
|
|
|
|
return;
|
|
|
|
}
|
2011-10-12 12:35:30 +00:00
|
|
|
|
|
|
|
g_at_result_iter_init(&iter, result);
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next(&iter, "+BINP:"))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_string(&iter, &num))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (!g_at_result_iter_next_number(&iter, &type))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
DBG("AT+BINP=1 response: %s %d", num, type);
|
|
|
|
|
|
|
|
strncpy(phone_number.number, num,
|
|
|
|
OFONO_MAX_PHONE_NUMBER_LENGTH);
|
|
|
|
phone_number.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0';
|
|
|
|
phone_number.type = type;
|
|
|
|
|
2011-10-13 18:47:56 +00:00
|
|
|
cb(&error, &phone_number, cbd->data);
|
2011-10-12 12:35:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
2011-10-13 18:47:56 +00:00
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
|
2011-10-12 12:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hfp_request_phone_number(struct ofono_handsfree *hf,
|
|
|
|
ofono_handsfree_phone_cb_t cb,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
|
|
|
|
if (g_at_chat_send(hd->chat, "AT+BINP=1", binp_prefix,
|
|
|
|
hfp_request_phone_number_cb,
|
|
|
|
cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, NULL, data);
|
|
|
|
}
|
|
|
|
|
2011-10-21 16:51:28 +00:00
|
|
|
static void hfp_voice_recognition(struct ofono_handsfree *hf,
|
|
|
|
ofono_bool_t enabled,
|
|
|
|
ofono_handsfree_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "AT+BVRA=%d",
|
|
|
|
(int)(enabled));
|
|
|
|
|
|
|
|
if (g_at_chat_send(hd->chat, buf, bvra_prefix,
|
|
|
|
hf_generic_set_cb,
|
|
|
|
cbd, g_free) > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2013-04-23 17:21:42 +00:00
|
|
|
static void hfp_disable_nrec(struct ofono_handsfree *hf,
|
|
|
|
ofono_handsfree_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
const char *buf = "AT+NREC=0";
|
|
|
|
|
2015-03-24 16:04:25 +00:00
|
|
|
if (g_at_chat_send(hd->chat, buf, none_prefix,
|
|
|
|
hf_generic_set_cb, cbd, g_free) > 0)
|
2013-04-23 17:21:42 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2014-01-22 16:16:01 +00:00
|
|
|
static void hfp_hf_indicator(struct ofono_handsfree *hf,
|
|
|
|
unsigned short indicator, unsigned int value,
|
|
|
|
ofono_handsfree_cb_t cb, void *data)
|
|
|
|
{
|
|
|
|
struct hf_data *hd = ofono_handsfree_get_data(hf);
|
|
|
|
struct cb_data *cbd = cb_data_new(cb, data);
|
|
|
|
char buf[128];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "AT+BIEV=%u,%u", indicator, value);
|
|
|
|
|
2015-03-24 16:04:25 +00:00
|
|
|
if (g_at_chat_send(hd->chat, buf, none_prefix,
|
|
|
|
hf_generic_set_cb, cbd, g_free) > 0)
|
2014-01-22 16:16:01 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
g_free(cbd);
|
|
|
|
|
|
|
|
CALLBACK_WITH_FAILURE(cb, data);
|
|
|
|
}
|
|
|
|
|
2018-10-17 13:36:10 +00:00
|
|
|
static const struct ofono_handsfree_driver driver = {
|
2011-09-15 16:34:34 +00:00
|
|
|
.name = "hfpmodem",
|
|
|
|
.probe = hfp_handsfree_probe,
|
|
|
|
.remove = hfp_handsfree_remove,
|
2014-04-10 15:04:36 +00:00
|
|
|
.cnum_query = hfp_cnum_query,
|
2011-10-12 12:35:30 +00:00
|
|
|
.request_phone_number = hfp_request_phone_number,
|
2011-10-21 16:51:28 +00:00
|
|
|
.voice_recognition = hfp_voice_recognition,
|
2013-04-23 17:21:42 +00:00
|
|
|
.disable_nrec = hfp_disable_nrec,
|
2014-01-22 16:16:01 +00:00
|
|
|
.hf_indicator = hfp_hf_indicator,
|
2011-09-15 16:34:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void hfp_handsfree_init(void)
|
|
|
|
{
|
|
|
|
ofono_handsfree_driver_register(&driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hfp_handsfree_exit(void)
|
|
|
|
{
|
|
|
|
ofono_handsfree_driver_unregister(&driver);
|
|
|
|
}
|