Add write/read operations for cyclic files in SIM.
authorAndrzej Zaborowski <andrew.zaborowski@intel.com>
Sun, 21 Jun 2009 01:30:14 +0000 (03:30 +0200)
committerDenis Kenzior <denkenz@gmail.com>
Mon, 22 Jun 2009 18:22:14 +0000 (13:22 -0500)
drivers/atmodem/sim.c
src/driver.h

index 620aefc..ab05a5b 100644 (file)
@@ -328,6 +328,39 @@ error:
        }
 }
 
+static void at_sim_update_cyclic(struct ofono_modem *modem, int fileid,
+                                       int length, const unsigned char *value,
+                                       ofono_generic_cb_t cb, void *data)
+{
+       struct at_data *at = ofono_modem_userdata(modem);
+       struct cb_data *cbd = cb_data_new(modem, cb, data);
+       char *buf = g_try_new(char, 36 + length * 2);
+       int len, ret;
+
+       if (!cbd || !buf)
+               goto error;
+
+       len = sprintf(buf, "AT+CRSM=220,%i,0,3,%i,", fileid, length);
+       for (; length; length--)
+               len += sprintf(buf + len, "%02hhx", *value++);
+       ret = g_at_chat_send(at->parser, buf, crsm_prefix,
+                               at_crsm_update_cb, cbd, g_free);
+
+       g_free(buf);
+
+       if (ret > 0)
+               return;
+
+error:
+       if (cbd)
+               g_free(cbd);
+
+       {
+               DECLARE_FAILURE(error);
+               cb(&error, data);
+       }
+}
+
 static void at_cimi_cb(gboolean ok, GAtResult *result, gpointer user_data)
 {
        struct cb_data *cbd = user_data;
@@ -383,8 +416,10 @@ static struct ofono_sim_ops ops = {
        .read_file_info         = at_sim_read_info,
        .read_file_transparent  = at_sim_read_binary,
        .read_file_linear       = at_sim_read_record,
+       .read_file_cyclic       = at_sim_read_record,
        .write_file_transparent = at_sim_update_binary,
        .write_file_linear      = at_sim_update_record,
+       .write_file_cyclic      = at_sim_update_cyclic,
        .read_imsi              = at_read_imsi,
 };
 
index 3eade28..f324c1c 100644 (file)
@@ -378,12 +378,18 @@ struct ofono_sim_ops {
        void (*read_file_linear)(struct ofono_modem *modem, int fileid,
                        int record, int length,
                        ofono_sim_read_cb_t cb, void *data);
+       void (*read_file_cyclic)(struct ofono_modem *modem, int fileid,
+                       int record, int length,
+                       ofono_sim_read_cb_t cb, void *data);
        void (*write_file_transparent)(struct ofono_modem *modem, int fileid,
                        int start, int length, const unsigned char *value,
                        ofono_generic_cb_t cb, void *data);
        void (*write_file_linear)(struct ofono_modem *modem, int fileid,
                        int record, int length, const unsigned char *value,
                        ofono_generic_cb_t cb, void *data);
+       void (*write_file_cyclic)(struct ofono_modem *modem, int fileid,
+                       int length, const unsigned char *value,
+                       ofono_generic_cb_t cb, void *data);
        void (*read_imsi)(struct ofono_modem *modem,
                        ofono_imsi_cb_t cb, void *data);
 };