2009/12/16 Denis Kenzior <[email protected]>: > Are the contents of EFcbmid ever sent down the modem?
I had first forgotten to do this and added it in the later patch. Now split EFcbmid handling into three patches and corrected the other problems you commented. The data download to sim isn't tested on real hardware due to obvious difficulties :) Regards
From 57a9e9bc9e0110ba960bdd72415e58886dc52f6f Mon Sep 17 00:00:00 2001 From: Andrzej Zaborowski <[email protected]> Date: Thu, 17 Dec 2009 18:22:05 +0100 Subject: [PATCH 1/3] Add utility for checking if CBS topic is in a range. --- src/smsutil.c | 22 +++++++++++++++++++++- src/smsutil.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletions(-) diff --git a/src/smsutil.c b/src/smsutil.c index c27e937..0323484 100644 --- a/src/smsutil.c +++ b/src/smsutil.c @@ -3509,7 +3509,7 @@ out: return TRUE; } -static GSList *cbs_optimize_ranges(GSList *ranges) +GSList *cbs_optimize_ranges(GSList *ranges) { struct cbs_topic_range *range; unsigned char bitmap[125]; @@ -3666,3 +3666,23 @@ char *cbs_topic_ranges_to_string(GSList *ranges) return ret; } + +static gint cbs_topic_compare(gconstpointer a, gconstpointer b) +{ + const struct cbs_topic_range *range = a; + unsigned short topic = GPOINTER_TO_UINT(b); + + if (topic >= range->min && topic <= range->max) + return 0; + + return 1; +} + +gboolean cbs_topic_in_range(unsigned int topic, GSList *ranges) +{ + if (!ranges) + return FALSE; + + return g_slist_find_custom(ranges, GUINT_TO_POINTER(topic), + cbs_topic_compare) != NULL; +} diff --git a/src/smsutil.h b/src/smsutil.h index 858fc84..10774dc 100644 --- a/src/smsutil.h +++ b/src/smsutil.h @@ -494,3 +494,5 @@ void cbs_assembly_location_changed(struct cbs_assembly *assembly, gboolean plmn, char *cbs_topic_ranges_to_string(GSList *ranges); GSList *cbs_extract_topic_ranges(const char *ranges); +GSList *cbs_optimize_ranges(GSList *ranges); +gboolean cbs_topic_in_range(unsigned int topic, GSList *ranges); -- 1.6.1
From 00682d7b61b82950d214669dfa6a1156636d72e0 Mon Sep 17 00:00:00 2001 From: Andrzej Zaborowski <[email protected]> Date: Thu, 17 Dec 2009 19:07:41 +0100 Subject: [PATCH 2/3] Add Envelope command for data downloads to sim. --- drivers/atmodem/sim.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ include/sim.h | 3 ++ 2 files changed, 84 insertions(+), 0 deletions(-) diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c index 92ae575..fca6f0f 100644 --- a/drivers/atmodem/sim.c +++ b/drivers/atmodem/sim.c @@ -704,6 +704,86 @@ error: CALLBACK_WITH_FAILURE(cb, -1, data); } +static void at_csim_envelope_cb(gboolean ok, GAtResult *result, + gpointer user_data) +{ + struct cb_data *cbd = user_data; + GAtResultIter iter; + ofono_sim_read_cb_t cb = cbd->cb; + struct ofono_error error; + const guint8 *response; + gint rlen, len; + + dump_response("at_csim_envelope_cb", ok, result); + decode_at_error(&error, g_at_result_final_response(result)); + + if (!ok) { + CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data); + return; + } + + g_at_result_iter_init(&iter, result); + + if (!g_at_result_iter_next(&iter, "+CSIM:")) { + CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data); + return; + } + + if (!g_at_result_iter_next_number(&iter, &rlen)) { + CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data); + return; + } + + if (!g_at_result_iter_next_hexstring(&iter, &response, &len)) { + CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data); + return; + } + + if (rlen != len * 2 || len < 2 || + response[len - 2] != 0x90 || response[len - 1] != 0) { + CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data); + return; + } + + ofono_debug("csim_envelope_cb: %i", len); + + cb(&error, response, len - 2, cbd->data); +} + +static void at_sim_envelope(struct ofono_sim *sim, int length, + const guint8 *command, + ofono_sim_read_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, 64 + length * 2); + int len, ret; + + if (!cbd || !buf) + goto error; + + len = sprintf(buf, "AT+CSIM=%i,a0c20000%02hhx", + 12 + length * 2, length); + + for (; length; length--) + len += sprintf(buf + len, "%02hhx", *command++); + sprintf(buf + len, "00"); + + ret = g_at_chat_send(sd->chat, buf, crsm_prefix, + at_csim_envelope_cb, cbd, g_free); + + g_free(buf); + + if (ret > 0) + return; + +error: + if (cbd) + g_free(cbd); + + CALLBACK_WITH_FAILURE(cb, NULL, 0, data); +} + static gboolean at_sim_register(gpointer user) { struct ofono_sim *sim = user; @@ -756,6 +836,7 @@ static struct ofono_sim_driver driver = { .lock = at_pin_enable, .change_passwd = at_change_passwd, .query_locked = at_pin_query_enabled, + .envelope = at_sim_envelope, }; void at_sim_init() diff --git a/include/sim.h b/include/sim.h index 40fd257..3f58372 100644 --- a/include/sim.h +++ b/include/sim.h @@ -135,6 +135,9 @@ struct ofono_sim_driver { void (*query_locked)(struct ofono_sim *sim, enum ofono_sim_password_type type, ofono_sim_locked_cb_t cb, void *data); + void (*envelope)(struct ofono_sim *sim, int length, + const guint8 *command, + ofono_sim_read_cb_t cb, void *data); }; int ofono_sim_driver_register(const struct ofono_sim_driver *d); -- 1.6.1
From 873135437cf2e983e6033a1db0e0a95f44d3bf44 Mon Sep 17 00:00:00 2001 From: Andrzej Zaborowski <[email protected]> Date: Thu, 17 Dec 2009 19:52:32 +0100 Subject: [PATCH 3/3] Handle EF-CBSMID contents. --- src/cbs.c | 29 ++++++++++++++++++++--------- src/ofono.h | 6 +++++- src/sim.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/cbs.c b/src/cbs.c index 42594c7..e088bfd 100644 --- a/src/cbs.c +++ b/src/cbs.c @@ -184,6 +184,11 @@ void ofono_cbs_notify(struct ofono_cbs *cbs, const unsigned char *pdu, return; } + if (cbs_topic_in_range(c.message_identifier, cbs->efcbmid_contents)) { + __ofono_cbs_sim_download(cbs->sim, pdu, pdu_len); + return; + } + if (!cbs_dcs_decode(c.dcs, &udhi, &cls, &charset, &comp, NULL, NULL)) { ofono_error("Unknown / Reserved DCS. Ignoring"); return; @@ -332,6 +337,10 @@ static DBusMessage *cbs_set_topics(struct ofono_cbs *cbs, const char *value, if (topics != NULL) etws_topics = g_slist_copy(topics); + if (cbs->efcbmid_contents != NULL) + etws_topics = g_slist_concat(etws_topics, + g_slist_copy(cbs->efcbmid_contents)); + etws_topics = g_slist_append(etws_topics, &etws_range); topic_str = cbs_topic_ranges_to_string(etws_topics); g_slist_free(etws_topics); @@ -437,6 +446,13 @@ static void cbs_unregister(struct ofono_atom *atom) cbs->new_topics = NULL; } + if (cbs->efcbmid_length) { + cbs->efcbmid_length = 0; + g_slist_foreach(cbs->efcbmid_contents, (GFunc)g_free, NULL); + g_slist_free(cbs->efcbmid_contents); + cbs->efcbmid_contents = NULL; + } + cbs->sim = NULL; if (cbs->reset_source) { @@ -627,6 +643,7 @@ static void sim_cbmid_read_cb(int ok, int length, int record, unsigned short mi; int i; char *str; + GSList *contents = NULL; if (!ok) return; @@ -648,23 +665,17 @@ static void sim_cbmid_read_cb(int ok, int length, int record, range->min = mi; range->max = mi; - cbs->efcbmid_contents = g_slist_prepend(cbs->efcbmid_contents, - range); + contents = g_slist_prepend(contents, range); } - if (cbs->efcbmid_contents == NULL) + if (contents == NULL) return; - cbs->efcbmid_contents = g_slist_reverse(cbs->efcbmid_contents); + cbs->efcbmid_contents = g_slist_reverse(contents); str = cbs_topic_ranges_to_string(cbs->efcbmid_contents); ofono_debug("Got cbmid: %s", str); g_free(str); - - cbs->efcbmid_length = 0; - g_slist_foreach(cbs->efcbmid_contents, (GFunc)g_free, NULL); - g_slist_free(cbs->efcbmid_contents); - cbs->efcbmid_contents = NULL; } static void cbs_got_imsi(struct ofono_cbs *cbs) diff --git a/src/ofono.h b/src/ofono.h index 31524b5..05d035e 100644 --- a/src/ofono.h +++ b/src/ofono.h @@ -167,11 +167,15 @@ void __ofono_atom_free(struct ofono_atom *atom); #include <ofono/devinfo.h> #include <ofono/phonebook.h> #include <ofono/sms.h> -#include <ofono/sim.h> #include <ofono/voicecall.h> #include <ofono/gprs.h> #include <ofono/gprs-context.h> +#include <ofono/sim.h> + +void __ofono_cbs_sim_download(struct ofono_sim *sim, + const guint8 *pdu, int pdu_len); + #include <ofono/ssn.h> typedef void (*ofono_ssn_mo_notify_cb)(int index, void *user); diff --git a/src/sim.c b/src/sim.c index 565f595..b7540a7 100644 --- a/src/sim.c +++ b/src/sim.c @@ -1743,6 +1743,40 @@ void ofono_sim_set_ready(struct ofono_sim *sim) } } +static void sim_cb_download_cb(const struct ofono_error *error, + const unsigned char *data, int len, void *user) +{ + if (error->type != OFONO_ERROR_TYPE_NO_ERROR) { + ofono_error("CellBroadcast download to UICC failed"); + return; + } + + ofono_debug("CellBroadcast download to UICC reported no error"); +} + +void __ofono_cbs_sim_download(struct ofono_sim *sim, + const guint8 *pdu, int pdu_len) +{ + guint8 tlv[pdu_len + 8]; + + if (sim->ready != TRUE) + return; + if (!sim->driver->envelope) + return; + + tlv[0] = 0xd2; /* Cell Broadcast Download */ + tlv[1] = 6 + pdu_len; + tlv[2] = 0x82; /* Device Identities */ + tlv[3] = 0x02; /* Device Identities length */ + tlv[4] = 0x83; /* Network */ + tlv[5] = 0x81; /* UICC */ + tlv[6] = 0x8c; /* Cell Broadcast page */ + tlv[7] = pdu_len; + memcpy(tlv + 8, pdu, pdu_len); + + sim->driver->envelope(sim, pdu_len + 8, tlv, sim_cb_download_cb, sim); +} + int ofono_sim_driver_register(const struct ofono_sim_driver *d) { DBG("driver: %p, name: %s", d, d->name); -- 1.6.1
_______________________________________________ ofono mailing list [email protected] http://lists.ofono.org/listinfo/ofono
