diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sim.c | 25 | ||||
-rw-r--r-- | src/simutil.c | 28 | ||||
-rw-r--r-- | src/simutil.h | 3 |
3 files changed, 36 insertions, 20 deletions
@@ -61,8 +61,6 @@ struct sim_file_op { struct sim_manager_data { struct ofono_sim_ops *ops; - int flags; - DBusMessage *pending; char *imsi; GSList *own_numbers; GSList *ready_notify; @@ -180,8 +178,6 @@ static void sim_msisdn_read_cb(struct ofono_modem *modem, int ok, struct sim_manager_data *sim = modem->sim_manager; int total; struct ofono_phone_number *ph; - int number_len; - int ton_npi; if (!ok) return; @@ -194,23 +190,12 @@ static void sim_msisdn_read_cb(struct ofono_modem *modem, int ok, total = length / record_length; - /* Skip Alpha-Identifier field */ - data += record_length - 14; - - number_len = *data++; - ton_npi = *data++; - - if (number_len > 11 || ton_npi == 0xff) - goto check; - ph = g_new(struct ofono_phone_number, 1); - ph->type = bit_field(ton_npi, 4, 3); - - /* BCD coded, however the TON/NPI is given by the first byte */ - number_len = (number_len - 1) * 2; - - extract_bcd_number(data, number_len, ph->number); + if (sim_adn_parse(data, record_length, ph) == FALSE) { + g_free(ph); + goto check; + } sim->own_numbers = g_slist_prepend(sim->own_numbers, ph); @@ -789,5 +774,5 @@ void ofono_sim_manager_exit(struct ofono_modem *modem) g_free(modem->sim_manager); - modem->sim_manager = 0; + modem->sim_manager = NULL; } diff --git a/src/simutil.c b/src/simutil.c index 1430ec32..51b1f5cc 100644 --- a/src/simutil.c +++ b/src/simutil.c @@ -398,3 +398,31 @@ const struct sim_eons_operator_info *sim_eons_lookup_with_lac( { return sim_eons_lookup_common(eons, mcc, mnc, TRUE, lac); } + +gboolean sim_adn_parse(const unsigned char *data, int length, + struct ofono_phone_number *ph) +{ + int number_len; + int ton_npi; + + if (length < 14) + return FALSE; + + /* Skip Alpha-Identifier field */ + data += length - 14; + + number_len = *data++; + ton_npi = *data++; + + if (number_len > 11 || ton_npi == 0xff) + return FALSE; + + ph->type = bit_field(ton_npi, 4, 3); + + /* BCD coded, however the TON/NPI is given by the first byte */ + number_len = (number_len - 1) * 2; + + extract_bcd_number(data, number_len, ph->number); + + return TRUE; +} diff --git a/src/simutil.h b/src/simutil.h index d6526fca..6572e72f 100644 --- a/src/simutil.h +++ b/src/simutil.h @@ -76,3 +76,6 @@ static inline enum sim_file_access file_access_condition_decode(int bcd) return SIM_FILE_ACCESS_ADM; return bcd; } + +gboolean sim_adn_parse(const unsigned char *data, int length, + struct ofono_phone_number *ph); |