---
drivers/atmodem/voicecall.c | 162 +++++++++++++++++++++++++++++++++++--------
1 files changed, 134 insertions(+), 28 deletions(-)
diff --git a/drivers/atmodem/voicecall.c b/drivers/atmodem/voicecall.c
index 8b43865..cc75803 100644
--- a/drivers/atmodem/voicecall.c
+++ b/drivers/atmodem/voicecall.c
@@ -47,6 +47,9 @@
/* Amount of time we give for CLIP to arrive before we commence CLCC poll */
#define CLIP_INTERVAL 200
+ /* When +VTD returns 0, an unspecified manufacturer specific delay is used */
+#define TONE_DURATION 1000
+
static const char *clcc_prefix[] = { "+CLCC:", NULL };
static const char *none_prefix[] = { NULL };
@@ -59,6 +62,8 @@ struct voicecall_data {
unsigned int clcc_source;
GAtChat *chat;
unsigned int vendor;
+ struct tone_req *tr;
+ unsigned int tone_duration;
};
struct release_id_req {
@@ -75,7 +80,18 @@ struct change_state_req {
int affected_types;
};
+struct tone_req {
+ struct ofono_voicecall *vc;
+ ofono_voicecall_cb_t cb;
+ void *data;
+ char *tone_str;
+ char *left;
+ int delay;
+ guint source;
+};
+
static gboolean poll_clcc(gpointer user_data);
+static gboolean tone_request_run(gpointer user_data);
static int class_to_call_type(int cls)
{
@@ -522,52 +538,116 @@ static void at_deflect(struct ofono_voicecall *vc,
at_template(buf, vc, generic_cb, incoming_or_waiting, cb, data);
}
-static void vts_cb(gboolean ok, GAtResult *result, gpointer user_data)
+static void tone_request_finish(struct tone_req *tr, GAtResult *result, int err)
{
- struct cb_data *cbd = user_data;
- ofono_voicecall_cb_t cb = cbd->cb;
struct ofono_error error;
+ struct voicecall_data *vd = ofono_voicecall_get_data(tr->vc);
- decode_at_error(&error, g_at_result_final_response(result));
- cb(&error, cbd->data);
+ if (tr->source)
+ g_source_remove(tr->source);
+
+ if (result)
+ decode_at_error(&error, g_at_result_final_response(result));
+ else {
+ error.type = err ? OFONO_ERROR_TYPE_FAILURE :
+ OFONO_ERROR_TYPE_NO_ERROR;
+ error.error = err;
+ }
+
+ tr->cb(&error, tr->data);
+
+ g_free(vd->tr);
+ vd->tr = NULL;
}
-static void at_send_dtmf(struct ofono_voicecall *vc, const char *dtmf,
- ofono_voicecall_cb_t cb, void *data)
+static void vts_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
- struct voicecall_data *vd = ofono_voicecall_get_data(vc);
- struct cb_data *cbd = cb_data_new(cb, data);
- int len = strlen(dtmf);
+ struct tone_req *tr = user_data;
+
+ if (!ok) {
+ tone_request_finish(tr, result, 0);
+ return;
+ }
+
+ tr->source = g_timeout_add(tr->delay, tone_request_run, tr);
+}
+
+static gboolean tone_request_run(gpointer user_data)
+{
+ struct tone_req *tr = user_data;
+ struct voicecall_data *vd = ofono_voicecall_get_data(tr->vc);
+ static const char *dtmf = "0123456789#*ABCDabcd";
+ char buf[2048], *i;
int s;
- int i;
- char *buf;
- if (!cbd)
- goto error;
+ tr->source = 0;
- /* strlen("+VTS=\"T\";") = 9 + initial AT + null */
- buf = g_try_new(char, len * 9 + 3);
+ if (*tr->left == '\0') {
+ tone_request_finish(tr, NULL, 0);
+ return FALSE;
+ }
- if (!buf)
- goto error;
+ strcpy(buf, "AT");
+ i = buf + 2;
- s = sprintf(buf, "AT+VTS=\"%c\"", dtmf[0]);
+ tr->delay = 0;
- for (i = 1; i < len; i++)
- s += sprintf(buf + s, ";+VTS=\"%c\"", dtmf[i]);
+ while (*tr->left && strchr(dtmf, *tr->left)) {
+ if (tr->delay)
+ *i++ = ';';
+ i += sprintf(i, "+VTS=\"%c\"", *tr->left++);
- s = g_at_chat_send(vd->chat, buf, none_prefix,
- vts_cb, cbd, g_free);
+ tr->delay += vd->tone_duration;
+ }
- g_free(buf);
+ if (*tr->left && *tr->left != ',') {
+ tone_request_finish(tr, NULL, EINVAL);
+ return FALSE;
+ }
- if (s > 0)
+ /*
+ * Wait 3 seconds per PAUSE, same as for DTMF separator characters
+ * passed in a telephone number according to TS 22.101 A.21,
+ * although 27.007 claims this delay can be set using S8 and
+ * defaults to 2 seconds.
+ */
+ while (*tr->left == ',') {
+ tr->left++;
+ tr->delay += 3000;
+ }
+
+ if (i > buf + 2) {
+ s = g_at_chat_send(vd->chat, buf, none_prefix, vts_cb,
+ tr, NULL);
+
+ if (s <= 0)
+ tone_request_finish(tr, NULL, EIO);
+ } else
+ vts_cb(TRUE, NULL, tr);
+
+ return FALSE;
+}
+
+static void at_send_dtmf(struct ofono_voicecall *vc, const char *dtmf,
+ ofono_voicecall_cb_t cb, void *data)
+{
+ struct voicecall_data *vd = ofono_voicecall_get_data(vc);
+ struct tone_req *tr = g_try_new0(struct tone_req, 1);
+
+ if (!tr || vd->tr) {
+ CALLBACK_WITH_FAILURE(cb, data);
return;
+ }
-error:
- g_free(cbd);
+ tr->vc = vc;
+ tr->cb = cb;
+ tr->data = data;
+ tr->tone_str = g_strdup(dtmf);
+ tr->left = tr->tone_str;
- CALLBACK_WITH_FAILURE(cb, data);
+ vd->tr = tr;
+
+ tone_request_run(tr);
}
static void ring_notify(GAtResult *result, gpointer user_data)
@@ -800,6 +880,26 @@ static void busy_notify(GAtResult *result, gpointer user_data)
clcc_poll_cb, vc, NULL);
}
+static void vtd_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
+{
+ struct ofono_voicecall *vc = user_data;
+ struct voicecall_data *vd = ofono_voicecall_get_data(vc);
+ GAtResultIter iter;
+ int duration;
+
+ if (!ok)
+ return;
+
+ g_at_result_iter_init(&iter, result);
+ g_at_result_iter_next(&iter, "+VTD:");
+
+ if (!g_at_result_iter_next_number(&iter, &duration))
+ return;
+
+ if (duration)
+ vd->tone_duration = duration * 100;
+}
+
static void at_voicecall_initialized(gboolean ok, GAtResult *result,
gpointer user_data)
{
@@ -840,12 +940,15 @@ static int at_voicecall_probe(struct ofono_voicecall *vc, unsigned
int vendor,
vd->chat = g_at_chat_clone(chat);
vd->vendor = vendor;
+ vd->tone_duration = TONE_DURATION;
ofono_voicecall_set_data(vc, vd);
g_at_chat_send(vd->chat, "AT+CRC=1", NULL, NULL, NULL, NULL);
g_at_chat_send(vd->chat, "AT+CLIP=1", NULL, NULL, NULL, NULL);
g_at_chat_send(vd->chat, "AT+COLP=1", NULL, NULL, NULL, NULL);
+ g_at_chat_send(vd->chat, "AT+VTD?", NULL,
+ vtd_query_cb, vc, NULL);
g_at_chat_send(vd->chat, "AT+CCWA=1", NULL,
at_voicecall_initialized, vc, NULL);
@@ -859,6 +962,9 @@ static void at_voicecall_remove(struct ofono_voicecall *vc)
if (vd->clcc_source)
g_source_remove(vd->clcc_source);
+ if (vd->tr)
+ tone_request_finish(vd->tr, NULL, ESHUTDOWN);
+
g_slist_foreach(vd->calls, (GFunc) g_free, NULL);
g_slist_free(vd->calls);
--
1.7.1.86.g0e460.dirty