atmodem: Support CRSM with paths
authorDenis Kenzior <denkenz@gmail.com>
Fri, 23 Nov 2012 13:09:29 +0000 (07:09 -0600)
committerDenis Kenzior <denkenz@gmail.com>
Fri, 23 Nov 2012 13:22:25 +0000 (07:22 -0600)
For GET STATUS and READ BINARY variations, support appending of the
optional path in the CRSM command

drivers/atmodem/sim.c

index 4b4817c..4f241ac 100644 (file)
@@ -139,7 +139,8 @@ static void at_sim_read_info(struct ofono_sim *sim, int fileid,
 {
        struct sim_data *sd = ofono_sim_get_data(sim);
        struct cb_data *cbd;
-       char buf[64];
+       char buf[128];
+       unsigned int len;
 
        if (sd->vendor == OFONO_VENDOR_OPTION_HSO) {
                unsigned char access[3] = { 0x00, 0x00, 0x00 };
@@ -153,18 +154,34 @@ static void at_sim_read_info(struct ofono_sim *sim, int fileid,
 
        cbd = cb_data_new(cb, data);
 
-       snprintf(buf, sizeof(buf), "AT+CRSM=192,%i", fileid);
+       len = snprintf(buf, sizeof(buf), "AT+CRSM=192,%i", fileid);
 
        switch (sd->vendor) {
+       default:
+               if (path_len == 0)
+                       break;
+
+               /* Fall through */
        case OFONO_VENDOR_ZTE:
        case OFONO_VENDOR_HUAWEI:
        case OFONO_VENDOR_SIERRA:
        case OFONO_VENDOR_SPEEDUP:
        case OFONO_VENDOR_QUALCOMM_MSM:
-               strcat(buf, ",0,0,255"); /* Maximum possible length */
+               /* Maximum possible length */
+               len += sprintf(buf + len, ",0,0,255");
                break;
        }
 
+       if (path_len > 0) {
+               len += sprintf(buf + len, ",,\"");
+
+               for (; path_len; path_len--)
+                       len += sprintf(buf + len, "%02hhX", *path++);
+
+               buf[len++] = '\"';
+               buf[len] = '\0';
+       }
+
        if (g_at_chat_send(sd->chat, buf, crsm_prefix,
                                at_crsm_info_cb, cbd, g_free) > 0)
                return;
@@ -232,10 +249,23 @@ static void at_sim_read_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[64];
+       unsigned int len;
 
-       snprintf(buf, sizeof(buf), "AT+CRSM=176,%i,%i,%i,%i", fileid,
+       len = snprintf(buf, sizeof(buf), "AT+CRSM=176,%i,%i,%i,%i", fileid,
                        start >> 8, start & 0xff, length);
 
+       if (path_len > 0) {
+               buf[len++] = ',';
+               buf[len++] = ',';
+               buf[len++] = '\"';
+
+               for (; path_len; path_len--)
+                       len += sprintf(buf + len, "%02hhX", *path++);
+
+               buf[len++] = '\"';
+               buf[len] = '\0';
+       }
+
        if (g_at_chat_send(sd->chat, buf, crsm_prefix,
                                at_crsm_read_cb, cbd, g_free) > 0)
                return;
@@ -253,7 +283,7 @@ static void at_sim_read_record(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[64];
+       char buf[128];
 
        snprintf(buf, sizeof(buf), "AT+CRSM=178,%i,%i,4,%i", fileid,
                        record, length);