Open Source Telephony
 help / color / mirror / Atom feed
From: Andrzej Zaborowski <andrew.zaborowski@intel.com>
To: ofono@ofono.org
Subject: [PATCH 03/13] atmodem: Handle pauses in DTMF string
Date: Wed, 13 Oct 2010 15:54:06 +0200	[thread overview]
Message-ID: <1286978056-16600-3-git-send-email-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <1286978056-16600-1-git-send-email-andrew.zaborowski@intel.com>

[-- Attachment #1: Type: text/plain, Size: 6593 bytes --]

---
 drivers/atmodem/voicecall.c |  163 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 135 insertions(+), 28 deletions(-)

diff --git a/drivers/atmodem/voicecall.c b/drivers/atmodem/voicecall.c
index b3c658f..54cbe4f 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,51 +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;") = 7 + initial AT + null */
-	buf = g_try_new(char, len * 9 + 3);
-	if (!buf)
-		goto error;
+	if (*tr->left == '\0') {
+		tone_request_finish(tr, NULL, 0);
+		return FALSE;
+	}
+
+	strcpy(buf, "AT");
+	i = buf + 2;
+
+	tr->delay = 0;
 
-	s = sprintf(buf, "AT+VTS=%c", dtmf[0]);
+	while (*tr->left && strchr(dtmf, *tr->left)) {
+		if (tr->delay)
+			*i++ = ';';
+		i += sprintf(i, "+VTS=%c", *tr->left++);
 
-	for (i = 1; i < len; i++)
-		s += sprintf(buf + s, ";+VTS=%c", dtmf[i]);
+		tr->delay += vd->tone_duration;
+	}
+
+	if (*tr->left && *tr->left != 'p') {
+		tone_request_finish(tr, NULL, EINVAL);
+		return FALSE;
+	}
 
-	s = g_at_chat_send(vd->chat, buf, none_prefix,
-				vts_cb, cbd, g_free);
+	/*
+	 * 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 == 'p') {
+		tr->left++;
+		tr->delay += 3000;
+	}
 
-	g_free(buf);
+	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;
+}
 
-	if (s > 0)
+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)
@@ -799,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)
 {
@@ -839,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);
 
@@ -858,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


  parent reply	other threads:[~2010-10-13 13:54 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-13 13:54 [PATCH 01/13] voicecall: __ofono_voicecall_send_tone internal api Andrzej Zaborowski
2010-10-13 13:54 ` [PATCH 02/13] stk: Handle the Send DTMF proactive command Andrzej Zaborowski
2010-10-14  8:55   ` Denis Kenzior
2010-10-13 13:54 ` Andrzej Zaborowski [this message]
2010-10-13 13:54 ` [PATCH 04/13] doc: Update property name to match code Andrzej Zaborowski
2010-10-14  5:56   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 05/13] doc: Add STK properties relevant for icons Andrzej Zaborowski
2010-10-14  8:08   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 06/13] stk: Pass icon IDs in stk agent request parameters Andrzej Zaborowski
2010-10-14  8:09   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 07/13] stk: Add icon ID information in stk_menu Andrzej Zaborowski
2010-10-14  8:09   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 08/13] stk: IdleModeIcon and MainMenuIcon properties Andrzej Zaborowski
2010-10-14  8:10   ` Denis Kenzior
2010-10-14  8:31     ` list-modems patch Alexander A Khryukin
2010-10-14  8:45       ` Marcel Holtmann
2010-10-14  9:17         ` Alexander A Khryukin
2010-10-14  9:34         ` Alexander A Khryukin
2010-10-14 10:13           ` Marcel Holtmann
2010-10-14 10:36             ` Alexander A Khryukin
2010-10-15  6:17               ` Marcel Holtmann
2010-10-13 13:54 ` [PATCH 09/13] stk: Simplify and add icon to alphaId api Andrzej Zaborowski
2010-10-14  8:56   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 10/13] stk: Apply STK text attributes as html Andrzej Zaborowski
2010-10-14  8:57   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 11/13] stkagent: Add PlayTone and LoopTone requests Andrzej Zaborowski
2010-10-14  9:02   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 12/13] stk: Handle the Play Tone proactive command Andrzej Zaborowski
2010-10-14  9:11   ` Denis Kenzior
2010-10-13 13:54 ` [PATCH 13/13] [RfC] API for STK driver to signal executed commands Andrzej Zaborowski
2010-10-14  9:17   ` Denis Kenzior
2010-10-14  8:47 ` [PATCH 01/13] voicecall: __ofono_voicecall_send_tone internal api Denis Kenzior
2010-10-19 14:10   ` Andrzej Zaborowski
2010-10-19 14:58     ` Denis Kenzior
2010-10-19 15:34       ` Andrzej Zaborowski
2010-10-19 15:59         ` Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1286978056-16600-3-git-send-email-andrew.zaborowski@intel.com \
    --to=andrew.zaborowski@intel.com \
    --cc=ofono@ofono.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox