add support for icons
cover add support for icons
This is still a wip, but I wanted to get your feedback on what I've got so far. The patch "allow partial reads of files" is still pretty much what I had before, so I haven't addressed any of your issues with it. It still doesn't do files > 256, and I'm just using the existing read functions with a couple modifications. I've got some outstanding questions that I noted in comments in the patches.
These patches do work with phonesim - so you can play with the test script if you feel like it.
Kristen Carlson Accardi (7):
simutil: add fileid for EFimg
stkutil: change uint32_t to guint32
sim: read EFimg
sim: allow partial reads of files
sim: read an image from an EFiidf
sim: implement GetIcon dbus interface
test: add get-icon script
include/sim.h | 11 +++ src/sim.c | 274 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/simutil.h | 1 + src/stkutil.h | 2 +- test/get-icon | 25 +++++ 5 files changed, 302 insertions(+), 11 deletions(-) create mode 100755 test/get-icon
PATCH 1/7 simutil: add fileid for EFimg
--- src/simutil.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
src/simutil.h +1 -0
@@ -22,6 +22,7 @@enum sim_fileid {SIM_EFPL_FILEID =0x2f05 ,SIM_EF_ICCID_FILEID =0x2fe2 , +SIM_EFIMG_FILEID =0x4F20 ,SIM_EFLI_FILEID =0x6f05 ,SIM_EF_CPHS_MWIS_FILEID =0x6f11 ,SIM_EF_CPHS_INFORMATION_FILEID =0x6f16 ,
Signature · 1 line
1.7.1.1
PATCH 2/7 stkutil: change uint32_t to guint32
In reply to Kristen Carlson AccardiThis helps avoid needing to include any extra header files if stkutil.h is included in sim.c
--- src/stkutil.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
src/stkutil.h +1 -1
@@ -852,7 +852,7 @@ struct stk_card_reader_id {struct stk_other_address {union {/* Network Byte Order */ -uint32_t ipv4; +guint32 ipv4;unsigned char ipv6[16 ]; } addr;enum stk_address_type type;
Signature · 1 line
1.7.1.1
PATCH 3/7 sim: read EFimg
In reply to Kristen Carlson AccardiRead EFimg when the sim is ready, and store it in memory.
--- src/sim.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 47 insertions(+), 0 deletions(-)
src/sim.c +47 -0
@@ -88,6 +88,8 @@ struct ofono_sim {unsigned char efmsisdn_records;unsigned char *efli;unsigned char efli_length; +unsigned char *efimg; +int efimg_length;enum ofono_sim_cphs_phase cphs_phase;unsigned char cphs_service_table[2 ];struct ofono_watchlist *state_watches;
@@ -1001,6 +1003,44 @@ static void sim_own_numbers_update(struct ofono_sim *sim) sim_msisdn_read_cb, sim); } +static void sim_efimg_read_cb (int ok,int length,int record, +const unsigned char *data, +int record_length,void *userdata) +{ +struct ofono_sim *sim = userdata; +unsigned char *efimg; +int num_records = length / record_length; + +if (!ok) +return ; + +/* +* EFimg descriptors are 9 bytes long. +* Byte 1 of the record is the number of descriptors per record. +*/ +if (record_length <10 ) +return ; + +if (sim->efimg ==NULL ) { + sim->efimg =g_try_malloc0 (num_records *9 ); + +if (sim->efimg ==NULL ) +return ; + + sim->efimg_length = num_records *9 ; + } + +/* +* TBD - if we have more than one descriptor per record, +* pick the nicest one. For now we use the first one. +*/ + +/* copy descriptor into slot for this record */ + efimg = &sim->efimg[(record -1 ) *9 ]; + +memcpy (efimg, &data[1 ],9 ); +} +static void sim_ready (void *user,enum ofono_sim_state new_state) {struct ofono_sim *sim = user;
@@ -1015,6 +1055,8 @@ static void sim_ready(void *user, enum ofono_sim_state new_state) sim_ad_read_cb, sim);ofono_sim_read (sim,SIM_EFSDN_FILEID ,OFONO_SIM_FILE_STRUCTURE_FIXED , sim_sdn_read_cb, sim); +ofono_sim_read (sim,SIM_EFIMG_FILEID ,OFONO_SIM_FILE_STRUCTURE_FIXED , + sim_efimg_read_cb, sim); } static void sim_cphs_information_read_cb(int ok, int length, int record,
@@ -1934,6 +1976,11 @@ static void sim_free_state(struct ofono_sim *sim)g_strfreev (sim->language_prefs); sim->language_prefs =NULL ; } + +if (sim->efimg) { +g_free (sim->efimg); + sim->efimg =NULL ; + } }void ofono_sim_inserted_notify (struct ofono_sim *sim,ofono_bool_t inserted)
Signature · 1 line
1.7.1.1
PATCH 4/7 sim: allow partial reads of files
In reply to Kristen Carlson Accardi--- include/sim.h | 5 +++++ src/sim.c | 54 ++++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 10 deletions(-)
include/sim.h +5 -0
@@ -198,6 +198,11 @@ int ofono_sim_read(struct ofono_sim *sim, int id,enum ofono_sim_file_structure expected, ofono_sim_file_read_cb_t cb, void *data); +int ofono_sim_read_bytes (struct ofono_sim *sim,int id, +enum ofono_sim_file_structure expected_type, +unsigned short offset,int num_bytes, +ofono_sim_file_read_cb_t cb,void *data); + int ofono_sim_write(struct ofono_sim *sim, int id, ofono_sim_file_write_cb_t cb, enum ofono_sim_file_structure structure, int record,
src/sim.c +44 -10
116 lines not on this page · raw message
Signature · 1 line
1.7.1.1
PATCH 5/7 sim: read an image from an EFiidf
In reply to Kristen Carlson Accardi--- include/sim.h | 6 +++ src/sim.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 0 deletions(-)
include/sim.h +6 -0
@@ -113,6 +113,9 @@ typedef void (*ofono_sim_lock_unlock_cb_t)(const struct ofono_error *error,typedef void (*ofono_sim_locked_cb_t )(const struct ofono_error *error,int locked,void *data); +typedef void (*ofono_sim_get_image_cb_t )(int ok,const char *xpm,int xpm_len, +void *userdata); +struct ofono_sim_driver {const char *name;int (*probe)(struct ofono_sim *sim,unsigned int vendor,void *data);
@@ -177,6 +180,9 @@ enum ofono_sim_phase ofono_sim_get_phase(struct ofono_sim *sim);enum ofono_sim_cphs_phase ofono_sim_get_cphs_phase (struct ofono_sim *sim);const unsigned char *ofono_sim_get_cphs_service_table (struct ofono_sim *sim); +void ofono_sim_get_image (struct ofono_sim *sim,unsigned char id, +ofono_sim_get_image_cb_t cb,gpointer user_data); +unsigned int ofono_sim_add_state_watch (struct ofono_sim *sim,ofono_sim_state_event_notify_cb_t cb,void *data,ofono_destroy_func destroy);
src/sim.c +127 -0
136 lines not on this page · raw message
Signature · 1 line
1.7.1.1
PATCH 6/7 sim: implement GetIcon dbus interface
In reply to Kristen Carlson Accardi--- src/sim.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-)
src/sim.c +46 -0
@@ -731,6 +731,50 @@ static DBusMessage *sim_enter_pin(DBusConnection *conn, DBusMessage *msg,return NULL ; } +static void ofono_sim_get_image_cb (int ok,const char *xpm,int xpm_len, +void *userdata) +{ +struct ofono_sim *sim = userdata; +DBusMessage *reply; + +if (!ok) + reply =__ofono_error_failed (sim->pending); +else { + reply =dbus_message_new_method_return (sim->pending); +dbus_message_append_args (reply,DBUS_TYPE_STRING , &xpm, +DBUS_TYPE_INVALID ); + } + +__ofono_dbus_pending_reply (&sim->pending, reply); +} + +static DBusMessage *sim_get_icon (DBusConnection *conn, +DBusMessage *msg,void *data) +{ +struct ofono_sim *sim = data; +int id; + +/* +* change the arg to be a byte +* Question: does the icon id start at zero or 1? +*/ +if (dbus_message_get_args (msg,NULL ,DBUS_TYPE_INT32 , &id, +DBUS_TYPE_INVALID ) == FALSE) +return __ofono_error_invalid_args (msg); + +if (sim->pending) +return __ofono_error_busy (msg); + +if (sim->efimg ==NULL ) +return __ofono_error_not_implemented (msg); + + sim->pending =dbus_message_ref (msg); + +ofono_sim_get_image (sim, id, ofono_sim_get_image_cb, sim); + +return NULL ; +} +static DBusMessage *sim_reset_pin (DBusConnection *conn,DBusMessage *msg,void *data) {
@@ -783,6 +827,8 @@ static GDBusMethodTable sim_methods[] = { G_DBUS_METHOD_FLAG_ASYNC }, {"UnlockPin" ,"ss" ,"" , sim_unlock_pin, G_DBUS_METHOD_FLAG_ASYNC }, + { "GetIcon", "i", "", sim_get_icon, + G_DBUS_METHOD_FLAG_ASYNC }, { } };
Signature · 1 line
1.7.1.1
PATCH 7/7 test: add get-icon script
In reply to Kristen Carlson Accardi--- test/get-icon | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) create mode 100755 test/get-icon
test/get-icon new file +25 -0
@@ -0,0 +1,25 @@ +#!/usr/bin/python + +import dbus +import sys + +bus = dbus.SystemBus() + +if len(sys.argv) == 3: + path = sys.argv[1] + id = int(sys.argv[2], 16) +elif len(sys.argv) == 2: + manager = dbus.Interface(bus.get_object('org.ofono', '/'), + 'org.ofono.Manager') + properties = manager.GetProperties() + path = properties["Modems"][0] + id = int(sys.argv[1], 16) +else: + print "%s [PATH] icon_id" % (sys.argv[0]) + +simmanager = dbus.Interface(bus.get_object('org.ofono', path), + 'org.ofono.SimManager') + +xpm = simmanager.GetIcon(id) + +print "Received xpm: %s" % (xpm)
Signature · 1 line
1.7.1.1