Skip to contentSkip to conversation

sim: Use quoted string with AT+CRSM data parameter

PATCH Superseded Nicolas Bertrand 3 participants 3 messages Mar 21, 2012 – Mar 22, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 |   52 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 45 insertions(+), 7 deletions(-)
drivers/atmodem/sim.c +45 -7
index 8ee9822..f307708 100644
@@ -305,18 +305,38 @@ static void at_sim_update_binary(struct ofono_sim *sim, int fileid,
 {
 	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);
+	char *buf;
 	int len, ret;
+	int size = 36 + length * 2;
 
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
+		size += 2; /*Add quotes*/
+
+	buf = g_try_new(char, size);
 	if (buf == NULL)
 		goto error;
 
 	len = sprintf(buf, "AT+CRSM=214,%i,%i,%i,%i,", fileid,
 			start >> 8, start & 0xff, length);
 
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
+		sprintf(buf + len, "\"");
+
 	for (; length; length--)
 		len += sprintf(buf + len, "%02hhX", *value++);
 
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
+		sprintf(buf + len, "\"");
+
 	ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
 				at_crsm_update_cb, cbd, g_free);
 
@@ -342,7 +362,10 @@ static void at_sim_update_record(struct ofono_sim *sim, int fileid,
 	int len, ret;
 	int size = 36 + length * 2;
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
 		size += 2; /*Add quotes*/
 
 	buf = g_try_new(char, size);
@@ -352,13 +375,19 @@ static void at_sim_update_record(struct ofono_sim *sim, int fileid,
 	len = sprintf(buf, "AT+CRSM=220,%i,%i,4,%i,", fileid,
 			record, length);
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
 		len += sprintf(buf + len, "\"");
 
 	for (; length; length--)
 		len += sprintf(buf + len, "%02hhX", *value++);
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
 		sprintf(buf + len, "\"");
 
 	ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
@@ -385,7 +414,10 @@ static void at_sim_update_cyclic(struct ofono_sim *sim, int fileid,
 	int len, ret;
 	int size = 36 + length * 2;
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
 		size += 2; /* Add quotes */
 
 	buf = g_try_new(char, size);
@@ -394,13 +426,19 @@ static void at_sim_update_cyclic(struct ofono_sim *sim, int fileid,
 
 	len = sprintf(buf, "AT+CRSM=220,%i,0,3,%i,", fileid, length);
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
 		len += sprintf(buf + len, "\"");
 
 	for (; length; length--)
 		len += sprintf(buf + len, "%02hhX", *value++);
 
-	if (sd->vendor == OFONO_VENDOR_MBM)
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
 		sprintf(buf + len, "\"");
 
 	ret = g_at_chat_send(sd->chat, buf, crsm_prefix,
Signature · 1 line
1.7.5.4
#1 lore raw

Hi Nicolas,

Quoted 14 lines

Fix issue with some modems preventing to update elementary files (speedup, ZTE, huawei, MBM)

---
 drivers/atmodem/sim.c |   52 ++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 45 insertions(+), 7 deletions(-)
drivers/atmodem/sim.c +0 -0
index 8ee9822..f307708 100644
@@ -305,18 +305,38 @@ static void at_sim_update_binary(struct ofono_sim *sim, int fileid,
 {
 	struct sim_data *sd = ofono_sim_get_data(sim);
 	struct cb_data *cbd = cb_data_new(cb, data);

drivers/atmodem/sim.c static void at_sim_update_binary(struct ofono_sim *sim, int fileid, · line 316

Quoted 10 lines
drivers/atmodem/sim.c +7 -1
-	char *buf = g_try_new(char, 36 + length * 2);
+	char *buf;
 	int len, ret;
+	int size = 36 + length * 2;
 
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
+		size += 2; /*Add quotes*/

this is better done with a switch statement. And please fix the comment style to adhere to the coding style.

Quoted 4 lines
drivers/atmodem/sim.c +2 -0
+
+	buf = g_try_new(char, size);
 	if (buf == NULL)
 		goto error;

drivers/atmodem/sim.c static void at_sim_update_binary(struct ofono_sim *sim, int fileid, · line 330

Quoted 10 lines
drivers/atmodem/sim.c +6 -0
 
 	len = sprintf(buf, "AT+CRSM=214,%i,%i,%i,%i,", fileid,
 			start >> 8, start & 0xff, length);
 
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
+		sprintf(buf + len, "\"");
+

I am getting a little bit worried about spreading sd->vendor checks at many places here. Maybe this can be done smarter and cleaner.

Regards

Marcel

#2 lore raw

Hi,

Quoted 37 lines
Quoted 4 lines

Fix issue with some modems preventing to update elementary files (speedup, ZTE, huawei, MBM)

---
 drivers/atmodem/sim.c |   52

++++++++++++++++++++++++++++++++++++++++++------

Quoted 10 lines
 1 files changed, 45 insertions(+), 7 deletions(-)
drivers/atmodem/sim.c index renamed from drivers/atmodem/sim.c +0 -0

8ee9822..f307708 100644

drivers/atmodem/sim.c +0 -0
@@ -305,18 +305,38 @@ static void at_sim_update_binary(struct
 ofono_sim *sim, int fileid,  {
 	struct sim_data *sd = ofono_sim_get_data(sim);
 	struct cb_data *cbd = cb_data_new(cb, data);

drivers/atmodem/sim.c static void at_sim_update_binary(struct · line 316

Quoted 10 lines
drivers/atmodem/sim.c +7 -1
-	char *buf = g_try_new(char, 36 + length * 2);
+	char *buf;
 	int len, ret;
+	int size = 36 + length * 2;
 
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
+		size += 2; /*Add quotes*/

this is better done with a switch statement. And please fix the comment style to adhere to the coding style.

Quoted 8 lines
drivers/atmodem/sim.c +2 -0
+
+	buf = g_try_new(char, size);
 	if (buf == NULL)
 		goto error;
 
 	len = sprintf(buf, "AT+CRSM=214,%i,%i,%i,%i,", fileid,
 			start >> 8, start & 0xff, length);
 
Quoted 9 lines

drivers/atmodem/sim.c static void at_sim_update_binary(struct ofono_sim *sim, int fileid, · line 330

Quoted 6 lines
drivers/atmodem/sim.c +6 -0
+	if (sd->vendor == OFONO_VENDOR_MBM ||
+			sd->vendor == OFONO_VENDOR_ZTE ||
+			sd->vendor == OFONO_VENDOR_HUAWEI ||
+			sd->vendor == OFONO_VENDOR_SPEEDUP)
+		sprintf(buf + len, "\"");
+

I am getting a little bit worried about spreading sd->vendor checks at many places here. Maybe this can be done smarter and cleaner.

Maybe you can always add the 2 bytes for the memory allocation, whatever the modem is. The cost is not so high, and the memory is freed at the end of the function.

And then, you can create a small function that 'append' the hex value. So the modem check would be only in this function, instead of being in at_sim_update_binary, at_sim_update_binary and at_sim_update_cyclic.

Doing this, you will have 2 modem checks instead of 9.

Regards,

Bertrand
---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company) Registered headquarters: "Les Montalets"- 2, rue de Paris, 92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.