All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] voicecall: Limit tone string length per request.
@ 2010-10-25  5:51 Andrzej Zaborowski
  2010-10-25  5:51 ` [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication Andrzej Zaborowski
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Andrzej Zaborowski @ 2010-10-25  5:51 UTC (permalink / raw)
  To: ofono

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

Also change to avoid memcpying into a buffer.
---
 src/voicecall.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/voicecall.c b/src/voicecall.c
index 26cfb9a..bd64432 100644
--- a/src/voicecall.c
+++ b/src/voicecall.c
@@ -2472,7 +2472,7 @@ static gboolean tone_request_run(gpointer user_data)
 {
 	struct ofono_voicecall *vc = user_data;
 	struct tone_queue_entry *entry = g_queue_peek_head(vc->toneq);
-	char buf[256];
+	char final;
 	unsigned len;
 
 	vc->tone_source = 0;
@@ -2483,14 +2483,17 @@ static gboolean tone_request_run(gpointer user_data)
 	len = strcspn(entry->left, "pP");
 
 	if (len) {
-		if (len >= sizeof(buf))
-			len = sizeof(buf) - 1;
+		if (len > 8) /* Arbitrary length limit per request */
+			len = 8;
 
-		memcpy(buf, entry->left, len);
-		buf[len] = '\0';
-		entry->left += len;
+		/* Temporarily move the end of the string */
+		final = entry->left[len];
+		entry->left[len] = '\0';
+
+		vc->driver->send_tones(vc, entry->left, tone_request_cb, vc);
 
-		vc->driver->send_tones(vc, buf, tone_request_cb, vc);
+		entry->left += len;
+		entry->left[0] = final;
 	} else
 		tone_request_cb(NULL, vc);
 
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication.
  2010-10-25  5:51 [PATCH] voicecall: Limit tone string length per request Andrzej Zaborowski
@ 2010-10-25  5:51 ` Andrzej Zaborowski
  2010-10-25 22:27   ` Denis Kenzior
  2010-10-25  5:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
  2010-10-25 22:27 ` [PATCH] voicecall: Limit tone string length per request Denis Kenzior
  2 siblings, 1 reply; 6+ messages in thread
From: Andrzej Zaborowski @ 2010-10-25  5:51 UTC (permalink / raw)
  To: ofono

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

---
 src/stk.c |   61 ++++++++++++++++++++++++++-----------------------------------
 1 files changed, 26 insertions(+), 35 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index 82bc91e..ebd3801 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -437,6 +437,24 @@ static void stk_alpha_id_unset(struct ofono_stk *stk)
 	/* TODO */
 }
 
+static int duration_to_msecs(const struct stk_duration *duration)
+{
+	int msecs = duration->interval;
+
+	switch (duration->unit) {
+	case STK_DURATION_TYPE_MINUTES:
+		msecs *= 60;
+		/* Fall through.  */
+	case STK_DURATION_TYPE_SECONDS:
+		msecs *= 10;
+		/* Fall through.  */
+	case STK_DURATION_TYPE_SECOND_TENTHS:
+		msecs *= 100;
+	}
+
+	return msecs;
+}
+
 static DBusMessage *stk_get_properties(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -1000,23 +1018,14 @@ static gboolean handle_command_poll_interval(const struct stk_command *cmd,
 	struct ofono_modem *modem = __ofono_atom_get_modem(stk->atom);
 	int seconds;
 
-	switch (cmd->poll_interval.duration.unit) {
-	case STK_DURATION_TYPE_MINUTES:
-		seconds = cmd->poll_interval.duration.interval * 60;
-		break;
-	case STK_DURATION_TYPE_SECONDS:
-		seconds = cmd->poll_interval.duration.interval;
-		break;
-	case STK_DURATION_TYPE_SECOND_TENTHS:
-		seconds = (4 + cmd->poll_interval.duration.interval) / 10;
-		if (seconds < 1)
-			seconds = 1;
-		break;
-	default:
+	if (!cmd->poll_interval.duration.interval) {
 		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
 		return TRUE;
 	}
 
+	seconds = MAX(duration_to_msecs(&cmd->poll_interval.duration) / 1000,
+			1);
+
 	ofono_modem_set_integer(modem, "status-poll-interval", seconds);
 
 	if (seconds > 255) {
@@ -1219,17 +1228,8 @@ static gboolean handle_command_display_text(const struct stk_command *cmd,
 		return TRUE;
 	}
 
-	if (dt->duration.interval) {
-		timeout = dt->duration.interval;
-		switch (dt->duration.unit) {
-		case STK_DURATION_TYPE_MINUTES:
-			timeout *= 60;
-		case STK_DURATION_TYPE_SECONDS:
-			timeout *= 10;
-		case STK_DURATION_TYPE_SECOND_TENTHS:
-			timeout *= 100;
-		}
-	}
+	if (dt->duration.interval)
+		timeout = duration_to_msecs(&dt->duration);
 
 	err = stk_agent_display_text(stk->current_agent, text, &dt->icon_id,
 					priority, display_text_cb, stk,
@@ -1387,17 +1387,8 @@ static gboolean handle_command_get_inkey(const struct stk_command *cmd,
 		return TRUE;
 	}
 
-	if (gi->duration.interval) {
-		timeout = gi->duration.interval;
-		switch (gi->duration.unit) {
-		case STK_DURATION_TYPE_MINUTES:
-			timeout *= 60;
-		case STK_DURATION_TYPE_SECONDS:
-			timeout *= 10;
-		case STK_DURATION_TYPE_SECOND_TENTHS:
-			timeout *= 100;
-		}
-	}
+	if (gi->duration.interval)
+		timeout = duration_to_msecs(&gi->duration);
 
 	gettimeofday(&stk->get_inkey_start_ts, NULL);
 
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] stk: Handle the Play Tone proactive command.
  2010-10-25  5:51 [PATCH] voicecall: Limit tone string length per request Andrzej Zaborowski
  2010-10-25  5:51 ` [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication Andrzej Zaborowski
@ 2010-10-25  5:51 ` Andrzej Zaborowski
  2010-10-25 22:27   ` Denis Kenzior
  2010-10-25 22:27 ` [PATCH] voicecall: Limit tone string length per request Denis Kenzior
  2 siblings, 1 reply; 6+ messages in thread
From: Andrzej Zaborowski @ 2010-10-25  5:51 UTC (permalink / raw)
  To: ofono

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

---
 src/stk.c |  131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 131 insertions(+), 0 deletions(-)

diff --git a/src/stk.c b/src/stk.c
index ebd3801..24326ae 100644
--- a/src/stk.c
+++ b/src/stk.c
@@ -2081,6 +2081,132 @@ static gboolean handle_command_send_dtmf(const struct stk_command *cmd,
 	return FALSE;
 }
 
+static void play_tone_cb(enum stk_agent_result result, void *user_data)
+{
+	struct ofono_stk *stk = user_data;
+
+	stk->respond_on_exit = FALSE;
+
+	switch (result) {
+	case STK_AGENT_RESULT_OK:
+	case STK_AGENT_RESULT_TIMEOUT:
+		send_simple_response(stk, STK_RESULT_TYPE_SUCCESS);
+		break;
+
+	default:
+		send_simple_response(stk, STK_RESULT_TYPE_USER_TERMINATED);
+		break;
+	}
+}
+
+static gboolean handle_command_play_tone(const struct stk_command *cmd,
+						struct stk_response *rsp,
+						struct ofono_stk *stk)
+{
+	static int manufacturer_timeout = 10000; /* 10 seconds */
+	static const struct {
+		const char *name;
+		/* Continuous true/false according to 02.40 */
+		gboolean continuous;
+	} tone_infos[] = {
+		/* Default */
+		[0x00] = { "dial-tone", TRUE },
+
+		/* Standard */
+		[0x01] = { "dial-tone", TRUE },
+		[0x02] = { "busy", TRUE },
+		[0x03] = { "congestion", TRUE },
+		[0x04] = { "radio-path-acknowledge", FALSE },
+		[0x05] = { "radio-path-not-available", FALSE },
+		[0x06] = { "error", TRUE },
+		[0x07] = { "call-waiting", FALSE },
+		[0x08] = { "ringing-tone", TRUE },
+
+		/* Proprietary */
+		[0x10] = { "general-beep", FALSE },
+		[0x11] = { "positive-acknowledgement", FALSE },
+		[0x12] = { "negative-acknowledgement", FALSE },
+		[0x13] = { "user-ringing-tone", TRUE },
+		[0x14] = { "user-sms-alert", FALSE },
+		[0x15] = { "critical", FALSE },
+		[0x20] = { "vibrate", TRUE },
+
+		/* Themed */
+		[0x30] = { "happy", FALSE },
+		[0x31] = { "sad", FALSE },
+		[0x32] = { "urgent-action", FALSE },
+		[0x33] = { "question", FALSE },
+		[0x34] = { "message-received", FALSE },
+
+		/* Melody */
+		[0x40] = { "melody-1", FALSE },
+		[0x41] = { "melody-2", FALSE },
+		[0x42] = { "melody-3", FALSE },
+		[0x43] = { "melody-4", FALSE },
+		[0x44] = { "melody-5", FALSE },
+		[0x45] = { "melody-6", FALSE },
+		[0x46] = { "melody-7", FALSE },
+		[0x47] = { "melody-8", FALSE },
+	};
+
+	const struct stk_command_play_tone *pt = &cmd->play_tone;
+	uint8_t qualifier = stk->pending_cmd->qualifier;
+	gboolean vibrate = (qualifier & (1 << 0)) != 0;
+	char *text;
+	int timeout;
+	int err;
+
+	if (pt->tone > sizeof(tone_infos) / sizeof(*tone_infos) ||
+			!tone_infos[pt->tone].name) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+
+		return TRUE;
+	}
+
+	text = dbus_apply_text_attributes(pt->alpha_id ? pt->alpha_id : "",
+						&pt->text_attr);
+	if (!text) {
+		rsp->result.type = STK_RESULT_TYPE_DATA_NOT_UNDERSTOOD;
+
+		return TRUE;
+	}
+
+	if (pt->duration.interval)
+		timeout = duration_to_msecs(&pt->duration);
+	else
+		timeout = manufacturer_timeout;
+
+	if (!tone_infos[pt->tone].continuous)
+		/* Duration ignored */
+		err = stk_agent_play_tone(stk->current_agent, text,
+						&pt->icon_id, vibrate,
+						tone_infos[pt->tone].name,
+						play_tone_cb, stk, NULL,
+						stk->timeout * 1000);
+	else
+		err = stk_agent_loop_tone(stk->current_agent, text,
+						&pt->icon_id, vibrate,
+						tone_infos[pt->tone].name,
+						play_tone_cb, stk, NULL,
+						timeout);
+
+	g_free(text);
+
+	if (err < 0) {
+		/*
+		 * We most likely got an out of memory error, tell SIM
+		 * to retry
+		 */
+		rsp->result.type = STK_RESULT_TYPE_TERMINAL_BUSY;
+		return TRUE;
+	}
+
+	stk->respond_on_exit = TRUE;
+	stk->cancel_cmd = stk_request_cancel;
+
+	return FALSE;
+}
+
 static void stk_proactive_command_cancel(struct ofono_stk *stk)
 {
 	if (stk->immediate_response)
@@ -2258,6 +2384,11 @@ void ofono_stk_proactive_command_notify(struct ofono_stk *stk,
 							&rsp, stk);
 		break;
 
+	case STK_COMMAND_TYPE_PLAY_TONE:
+		respond = handle_command_play_tone(stk->pending_cmd,
+							&rsp, stk);
+		break;
+
 	default:
 		rsp.result.type = STK_RESULT_TYPE_COMMAND_NOT_UNDERSTOOD;
 		break;
-- 
1.7.1.86.g0e460.dirty


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] voicecall: Limit tone string length per request.
  2010-10-25  5:51 [PATCH] voicecall: Limit tone string length per request Andrzej Zaborowski
  2010-10-25  5:51 ` [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication Andrzej Zaborowski
  2010-10-25  5:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
@ 2010-10-25 22:27 ` Denis Kenzior
  2 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2010-10-25 22:27 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

On 10/25/2010 12:51 AM, Andrzej Zaborowski wrote:
> Also change to avoid memcpying into a buffer.
> ---
>  src/voicecall.c |   17 ++++++++++-------
>  1 files changed, 10 insertions(+), 7 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication.
  2010-10-25  5:51 ` [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication Andrzej Zaborowski
@ 2010-10-25 22:27   ` Denis Kenzior
  0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2010-10-25 22:27 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

On 10/25/2010 12:51 AM, Andrzej Zaborowski wrote:
> ---
>  src/stk.c |   61 ++++++++++++++++++++++++++-----------------------------------
>  1 files changed, 26 insertions(+), 35 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] stk: Handle the Play Tone proactive command.
  2010-10-25  5:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
@ 2010-10-25 22:27   ` Denis Kenzior
  0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2010-10-25 22:27 UTC (permalink / raw)
  To: ofono

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

Hi Andrew,

On 10/25/2010 12:51 AM, Andrzej Zaborowski wrote:
> ---
>  src/stk.c |  131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 131 insertions(+), 0 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-10-25 22:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-25  5:51 [PATCH] voicecall: Limit tone string length per request Andrzej Zaborowski
2010-10-25  5:51 ` [PATCH 1/2] stk: Add duration_to_msecs to reduce duplication Andrzej Zaborowski
2010-10-25 22:27   ` Denis Kenzior
2010-10-25  5:51 ` [PATCH 2/2] stk: Handle the Play Tone proactive command Andrzej Zaborowski
2010-10-25 22:27   ` Denis Kenzior
2010-10-25 22:27 ` [PATCH] voicecall: Limit tone string length per request Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.