Open Source Telephony
 help / color / mirror / Atom feed
From: Nicolas Bertrand <nicolas.bertrand@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCHv2] sim: Use quoted string with AT+CRSM data parameter
Date: Thu, 22 Mar 2012 18:28:10 +0100	[thread overview]
Message-ID: <1332437290-31190-1-git-send-email-nicolas.bertrand@linux.intel.com> (raw)

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

Fix issue with some modems preventing to update elementary files
(speedup, ZTE, huawei, MBM)
---
 drivers/atmodem/sim.c |  127 ++++++++++++++++---------------------------------
 1 files changed, 41 insertions(+), 86 deletions(-)

diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index 8ee9822..a75d51f 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -298,71 +298,44 @@ static void at_crsm_update_cb(gboolean ok, GAtResult *result,
 	cb(&error, cbd->data);
 }
 
-static void at_sim_update_binary(struct ofono_sim *sim, int fileid,
-					int start, int length,
-					const unsigned char *value,
-					ofono_sim_write_cb_t cb, void *data)
-{
-	struct sim_data *sd = ofono_sim_get_data(sim);
-	struct cb_data *cbd = cb_data_new(cb, data);
-	char *buf = g_try_new(char, 36 + length * 2);
-	int len, ret;
-
-	if (buf == NULL)
-		goto error;
-
-	len = sprintf(buf, "AT+CRSM=214,%i,%i,%i,%i,", fileid,
-			start >> 8, start & 0xff, length);
-
-	for (; length; length--)
-		len += sprintf(buf + len, "%02hhX", *value++);
-
-	ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
-				at_crsm_update_cb, cbd, g_free);
-
-	g_free(buf);
-
-	if (ret > 0)
-		return;
-
-error:
-	g_free(cbd);
-
-	CALLBACK_WITH_FAILURE(cb, data);
-}
-
-static void at_sim_update_record(struct ofono_sim *sim, int fileid,
-					int record, int length,
-					const unsigned char *value,
-					ofono_sim_write_cb_t cb, void *data)
+static void at_sim_update_file(struct ofono_sim *sim, int cmd, int fileid,
+		int p1, int p2, int p3, const unsigned char *value,
+		ofono_sim_write_cb_t cb, void *data)
 {
 	struct sim_data *sd = ofono_sim_get_data(sim);
 	struct cb_data *cbd = cb_data_new(cb, data);
 	char *buf;
+	char *quote = "";
 	int len, ret;
-	int size = 36 + length * 2;
+	int size = 36 + p3 * 2;
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
-		size += 2; /*Add quotes*/
+	DBG("");
+
+	/* Add quotes */
+	switch (sd->vendor) {
+	case OFONO_VENDOR_MBM:
+	case OFONO_VENDOR_ZTE:
+	case OFONO_VENDOR_HUAWEI:
+	case OFONO_VENDOR_SPEEDUP:
+		quote = "\"";
+		size += 2;
+		break;
+	}
 
 	buf = g_try_new(char, size);
 	if (buf == NULL)
 		goto error;
 
-	len = sprintf(buf, "AT+CRSM=220,%i,%i,4,%i,", fileid,
-			record, length);
+	len = sprintf(buf, "AT+CRSM=%i,%i,%i,%i,%i,%s", cmd, fileid,
+			p1, p2, p3, quote);
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
-		len += sprintf(buf + len, "\"");
-
-	for (; length; length--)
+	for (; p3; p3--)
 		len += sprintf(buf + len, "%02hhX", *value++);
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
-		sprintf(buf + len, "\"");
+	sprintf(buf + len, "%s", quote);
 
 	ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
-				at_crsm_update_cb, cbd, g_free);
+			at_crsm_update_cb, cbd, g_free);
 
 	g_free(buf);
 
@@ -375,46 +348,28 @@ error:
 	CALLBACK_WITH_FAILURE(cb, data);
 }
 
-static void at_sim_update_cyclic(struct ofono_sim *sim, int fileid,
-					int length, const unsigned char *value,
-					ofono_sim_write_cb_t cb, void *data)
+static void at_sim_update_binary(struct ofono_sim *sim, int fileid,
+		int start, int length, const unsigned char *value,
+		ofono_sim_write_cb_t cb, void *data)
 {
-	struct sim_data *sd = ofono_sim_get_data(sim);
-	struct cb_data *cbd = cb_data_new(cb, data);
-	char *buf;
-	int len, ret;
-	int size = 36 + length * 2;
-
-	if (sd->vendor == OFONO_VENDOR_MBM)
-		size += 2; /* Add quotes */
-
-	buf = g_try_new(char, size);
-	if (buf == NULL)
-		goto error;
-
-	len = sprintf(buf, "AT+CRSM=220,%i,0,3,%i,", fileid, length);
-
-	if (sd->vendor == OFONO_VENDOR_MBM)
-		len += sprintf(buf + len, "\"");
-
-	for (; length; length--)
-		len += sprintf(buf + len, "%02hhX", *value++);
-
-	if (sd->vendor == OFONO_VENDOR_MBM)
-		sprintf(buf + len, "\"");
-
-	ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
-				at_crsm_update_cb, cbd, g_free);
-
-	g_free(buf);
-
-	if (ret > 0)
-		return;
+	at_sim_update_file(sim, 214, fileid, start >> 8, start & 0xff,
+			length, value, cb, data);
+}
 
-error:
-	g_free(cbd);
+static void at_sim_update_record(struct ofono_sim *sim, int fileid,
+		int record, int length, const unsigned char *value,
+		ofono_sim_write_cb_t cb, void *data)
+{
+	at_sim_update_file(sim, 220, fileid, record, 4,
+			length, value, cb, data);
+}
 
-	CALLBACK_WITH_FAILURE(cb, data);
+static void at_sim_update_cyclic(struct ofono_sim *sim, int fileid,
+		int length, const unsigned char *value,
+		ofono_sim_write_cb_t cb, void *data)
+{
+	at_sim_update_file(sim, 220, fileid, 0, 3,
+			length, value, cb, data);
 }
 
 static void at_cimi_cb(gboolean ok, GAtResult *result, gpointer user_data)
-- 
1.7.5.4


             reply	other threads:[~2012-03-22 17:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-22 17:28 Nicolas Bertrand [this message]
2012-03-23 13:39 ` [PATCHv2] sim: Use quoted string with AT+CRSM data parameter 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=1332437290-31190-1-git-send-email-nicolas.bertrand@linux.intel.com \
    --to=nicolas.bertrand@linux.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