Skip to contentSkip to conversation

sim: Use quoted string with AT+CRSM data parameter

PATCH In review Nicolas Bertrand 2 participants 2 messages Mar 22, 2012 – Mar 23, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sim: Use quoted string with AT+CRSM data parameter

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(-)
drivers/atmodem/sim.c +41 -86
index 8ee9822..a75d51f 100644
@@ -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)
Signature · 1 line
1.7.5.4
#1 lore raw

Hi Nicolas,

Quoted 6 lines · Nicolas Bertrand

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(-)

Patch has been applied, but I had to fix up numerous coding style violations afterwards. Please re-read doc/coding-style.txt and pay extra attention next time.

Just one more comment:

drivers/atmodem/sim.c static void at_crsm_update_cb(gboolean ok, GAtResult *result, · line 335

Quoted 2 lines
drivers/atmodem/sim.c +1 -0
+	sprintf(buf + len, "%s", quote);

Something like this is really wasteful, you're invoking sprintf (which is quite a heavy hammer) just to put in a quote character. Use buf[len] = '\"' next time.

Regards,
-Denis