[PATCH] sim: fix crash in case of invalid sim password type
by Christophe Ronco
Hi,
I have an old Swedish SIM card here that I tried to put in my MC7304 modem.
My ofono version is 1.20 (with some additional patches).
It sometimes return an invalid SIM password type.
After that, ofono crashes. Here is an extract of debug traces when this happens.
Ofono is just starting, modem was here before ofono starts.
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_attributes() file id 0x6fb7 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/devinfo.c:string_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/devinfo.c:qmi_query_serial()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:get_file_attributes_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.err ofonod[1120]: Requested file structure differs from SIM: 6fb7
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/voicecall.c:ecc_g2_read_cb() 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_attributes() file id 0x6fb7 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/devinfo.c:get_ids_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:get_file_attributes_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_record() file id 0x6fb7 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/voicecall.c:ecc_g3_read_cb() 1
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_record() file id 0x6fb7 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/voicecall.c:ecc_g3_read_cb() 1
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_record() file id 0x6fb7 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/voicecall.c:ecc_g3_read_cb() 1
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_record() file id 0x6fb7 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/voicecall.c:ecc_g3_read_cb() 1
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_record() file id 0x6fb7 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/voicecall.c:ecc_g3_read_cb() 1
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_attributes() file id 0x2fe2 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:get_file_attributes_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_transparent() file id 0x2fe2 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/simfs.c:sim_fs_op_read_block_cb() bufoff: 0, dataoff: 0, tocopy: 10
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_attributes() file id 0x6f05 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:get_file_attributes_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_transparent() file id 0x6f05 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/simfs.c:sim_fs_op_read_block_cb() bufoff: 0, dataoff: 0, tocopy: 6
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_attributes() file id 0x2f05 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:get_file_attributes_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_read_transparent() file id 0x2f05 path len 0
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:read_generic_cb()
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/simfs.c:sim_fs_op_read_block_cb() bufoff: 0, dataoff: 0, tocopy: 6
Jun 27 15:28:41 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:qmi_query_passwd_state()
Jun 27 15:28:42 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:get_card_status() info1->app_state:0x6: OFONO_SIM_PASSWORD_INVALID
Jun 27 15:28:42 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/drivers/qmimodem/sim.c:query_passwd_state_cb() passwd state 16
Jun 27 15:28:42 klk-lpbs-0504B4 daemon.debug ofonod[1120]: ../git/src/sim.c:sim_pin_query_cb() sim->pin_type: 0, pin_type: 16
Jun 27 15:28:42 klk-lpbs-0504B4 daemon.err ofonod[1120]: Aborting (signal 11) [/usr/sbin/ofonod]
Problem is just that we don't have a string corresponding to this password type.
Christophe Ronco (1):
sim: fix crash in case of invalid sim password type
src/sim.c | 1 +
1 file changed, 1 insertion(+)
--
2.7.4
2 years, 9 months
ofono with sim5320 module
by David Ashley
Hello, I'm at my wits' end trying to get ofono working with the
sim5320 module. I'm using the plugins/sim900.c module as a starting
point. I think the issue has something to do with the difference
between the MUX functionality between the 900 and the 5320. The sim900
supports the elaborate parameters sent on the
AT+CMUX=0,x,x,x,x, etc.
but the SIM5320 only supports
AT+CMUX=0
There's that... but also the way the sim900 plugin creates a
SETUP_DLC, initiates muxing, then deletes the setup DLC and creates 4
new DLC's... it didn't work for the sim5320 until I remapped the DLC's
somewhat like this:
#define NUM_DLC 4
#define VOICE_DLC 2
#define NETREG_DLC 1
//#define SMS_DLC 2
#define GPRS_DLC 3
#define SETUP_DLC 0
static char *dlc_prefixes[NUM_DLC] = {
[VOICE_DLC]="Voice: ",
[NETREG_DLC]="Net: ",
// [SMS_DLC]= "SMS: ",
[GPRS_DLC]= "GPRS: " ,
[SETUP_DLC]= "Setup: ",
};
Note I have to eliminate the SMS_DLC usage later in sim5320_post_sim:
// ofono_sms_create(modem, OFONO_VENDOR_SIMCOM, "atmodem",
// data->dlcs[SMS_DLC]);
OK everything is *ALMOST* working. ofonod interacts fine with
connmand, connmand tells ofonod to activate the sim5320, which
actually establishes a ppp connection and sets up a ppp device:
ppp0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-0
inet addr:30.97.132.47 P-t-P:30.97.132.47 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 B) TX bytes:124 (124.0 B)
Here's the rub: No matter what I do, I never get any RX packets from
that ppp device, and even when it appears to TX packets (I'm trying to
ping out) the machine on the internet isn't actually receiving them.
I'm running on a beaglebone with a custom board with a sim5320 module on it.
I have no idea what to try... Any advice would be appreciated...
Thanks very much!!!!
-Dave
3 years, 1 month
[PATCH] sim-auth: Avoid using dbus_message_iter_get_element_count
by Slava Monich
It's the only thing in ofono that requires dbus 1.9.16 or later and it's
not worth it.
And don't leak DBusMessage on format error.
---
src/sim-auth.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/src/sim-auth.c b/src/sim-auth.c
index f9f74d4..7b65738 100644
--- a/src/sim-auth.c
+++ b/src/sim-auth.c
@@ -369,9 +369,7 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
struct ofono_sim_auth *sa = data;
DBusMessageIter iter;
DBusMessageIter array;
- int i;
uint8_t *aid;
- int rands;
if (sa->pending)
return __ofono_error_busy(msg);
@@ -381,27 +379,22 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
return __ofono_error_invalid_format(msg);
- rands = dbus_message_iter_get_element_count(&iter);
-
- if (rands > 3 || rands < 2)
- return __ofono_error_invalid_format(msg);
-
sa->pending = g_new0(struct auth_request, 1);
- sa->pending->msg = dbus_message_ref(msg);
- sa->pending->num_rands = rands;
dbus_message_iter_recurse(&iter, &array);
- for (i = 0; i < sa->pending->num_rands; i++) {
+ while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_ARRAY) {
int nelement;
DBusMessageIter in;
dbus_message_iter_recurse(&array, &in);
- if (dbus_message_iter_get_arg_type(&in) != DBUS_TYPE_BYTE)
+ if (dbus_message_iter_get_arg_type(&in) != DBUS_TYPE_BYTE ||
+ sa->pending->num_rands == SIM_AUTH_MAX_RANDS)
goto format_error;
- dbus_message_iter_get_fixed_array(&in, &sa->pending->rands[i],
+ dbus_message_iter_get_fixed_array(&in,
+ &sa->pending->rands[sa->pending->num_rands++],
&nelement);
if (nelement != 16)
@@ -410,12 +403,15 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
dbus_message_iter_next(&array);
}
+ if (sa->pending->num_rands < 2)
+ goto format_error;
+
/*
* retrieve session from SIM
*/
aid = find_aid_by_path(sa->aid_objects, dbus_message_get_path(msg));
sa->pending->session = __ofono_sim_get_session_by_aid(sa->sim, aid);
-
+ sa->pending->msg = dbus_message_ref(msg);
sa->pending->watch_id = __ofono_sim_add_session_watch(
sa->pending->session, get_session_cb, sa, NULL);
--
1.9.1
3 years, 1 month
[PATCH 1/2] include: Add storage.h
by Slava Monich
To expose ofono directories to dynamically loadable plugins.
---
Makefile.am | 3 ++-
include/storage.h | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
create mode 100644 include/storage.h
diff --git a/Makefile.am b/Makefile.am
index 903630b..f58cc92 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,7 +22,8 @@ pkginclude_HEADERS = include/log.h include/plugin.h include/history.h \
include/private-network.h include/cdma-netreg.h \
include/cdma-provision.h include/handsfree.h \
include/handsfree-audio.h include/siri.h \
- include/netmon.h include/lte.h include/ims.h
+ include/netmon.h include/lte.h include/ims.h \
+ include/storage.h
nodist_pkginclude_HEADERS = include/version.h
diff --git a/include/storage.h b/include/storage.h
new file mode 100644
index 0000000..243eb88
--- /dev/null
+++ b/include/storage.h
@@ -0,0 +1,32 @@
+/*
+ *
+ * oFono - Open Telephony stack for Linux
+ *
+ * Copyright (C) 2017 Jolla Ltd. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#ifndef __OFONO_STORAGE_H
+#define __OFONO_STORAGE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char *ofono_config_dir(void);
+const char *ofono_storage_dir(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_STORAGE_H */
--
1.9.1
3 years, 1 month
Problem setting up the context
by Nicolas ADELL
Hi,
I'm facing an issue with oFono when the application is trying to establish a ppp data connection.
The context is firstly activated by the application and kept until oFono gets an 'NW DETACH' event.
ofonod[758]: App: < \r\n+CGEV: NW DETACH\r\n
ofonod[758]: gprs.c:cgev_notify() event: NW DETACH
ofonod[758]: gprs.c:ofono_gprs_detached_notify()
ofonod[758]: gprs-context.c:at_gprs_detach_shutdown() cid 1
At that time, oFono attempts to close the link properly.
However, it takes few seconds before getting the state notified as 'CLOSED' and the 'pppcp_this_layer_finished()' function called.
During this interval, the Packet Domain network registration status is reported as registered:
ofonod[758]: gprs.c:cgreg_notify() 5
ofonod[758]: gprs.c:ofono_gprs_status_notify()
The 'ppp_disconnect()' function is not triggered yet, but the application attempts to re-activate the context anyway because the 'Attached' gprs property has been updated and signaled as TRUE.
Then 'ppp_disconnect()' is triggered.
ofonod[758]: gatppp.c:ppp_dead()
ofonod[758]: gprs-context.c:ppp_disconnect() Reason: 6
ofonod[758]: gprs.c:pri_activate_callback() 0x5508c8
ofonod[758]: gprs.c:pri_activate_callback() Activating context failed with error: Unknown error type
At this time the gprs context state equals to "Enabling", due to the latest appliction request => the 'pri_activate_callback()' callback is executed.
oFono gets a "NO CARRIER" from the modem, but it trigges the 'at_cgdcont_cb()' with error.
=> The pri_activate_callback() is called twice with error
ofonod[758]: gprs-context.c:ppp_disconnect()
ofonod[758]: gprs.c:pri_activate_callback() 0x19b7978
ofonod[758]: gprs.c:pri_activate_callback() Activating context failed with error: Unknown error type
ofonod[758]: gprs-context.c:at_cgdcont_cb() ok 0
ofonod[758]: gprs.c:pri_activate_callback() 0x19b7978
ofonod[758]: gprs.c:pri_activate_callback() Activating context failed with error: Unknown error type
Because the 'DBusMessage' has been already freed, oFono aborts.
Is there a proper way to prevent this unexpected situation ?
It already tried to catch the 'NO CARRIER' final response without sucess.
Regards,
Nicolas.
3 years, 2 months
[PATCH] watchlist: added macro for notifying with no args
by James Prestwood
The macros currently did not support notifying a watchlist with
no extra arguments.
---
src/watchlist.h | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/watchlist.h b/src/watchlist.h
index 737b80d..3d87810 100644
--- a/src/watchlist.h
+++ b/src/watchlist.h
@@ -2,7 +2,7 @@
*
* Wireless daemon for Linux
*
- * Copyright (C) 2016 Intel Corporation. All rights reserved.
+ * Copyright (C) 2016-2017 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -92,3 +92,19 @@ void __watchlist_prune_stale(struct watchlist *watchlist);
if ((watchlist)->stale_items) \
__watchlist_prune_stale(watchlist); \
} while (false)
+
+#define WATCHLIST_NOTIFY_NO_ARGS(watchlist, type) \
+ do { \
+ const struct l_queue_entry *entry = \
+ l_queue_get_entries((watchlist)->items);\
+ \
+ (watchlist)->in_notify = true; \
+ for (; entry; entry = entry->next) { \
+ struct watchlist_item *item = entry->data; \
+ type t = item->notify; \
+ t(item->notify_data); \
+ } \
+ (watchlist)->in_notify = false; \
+ if ((watchlist)->stale_items) \
+ __watchlist_prune_stale(watchlist); \
+ } while (false)
--
2.7.4
3 years, 2 months
[PATCH 1/3] simauth: remove driver API definitions from simauth include
by James Prestwood
---
include/sim-auth.h | 38 +-------------------------------------
1 file changed, 1 insertion(+), 37 deletions(-)
diff --git a/include/sim-auth.h b/include/sim-auth.h
index ccaa7f2..9f25cfa 100644
--- a/include/sim-auth.h
+++ b/include/sim-auth.h
@@ -32,44 +32,8 @@ extern "C" {
struct ofono_sim_auth;
-typedef void (*ofono_sim_list_apps_cb_t)(const struct ofono_error *error,
- const unsigned char *dataobj,
- int len, void *data);
+struct ofono_sim_auth *ofono_sim_auth_create(struct ofono_modem *modem);
-typedef void (*ofono_sim_open_channel_cb_t)(const struct ofono_error *error,
- int session_id, void *data);
-
-typedef void (*ofono_sim_close_channel_cb_t)(const struct ofono_error *error,
- void *data);
-
-typedef void (*ofono_logical_access_cb_t)(const struct ofono_error *error,
- const uint8_t *resp, uint16_t len, void *data);
-
-struct ofono_sim_auth_driver {
- const char *name;
- int (*probe)(struct ofono_sim_auth *sa, unsigned int vendor,
- void *data);
- void (*remove)(struct ofono_sim_auth *sa);
-
- void (*list_apps)(struct ofono_sim_auth *sa,
- ofono_sim_list_apps_cb_t cb, void *data);
- void (*open_channel)(struct ofono_sim_auth *sa, const uint8_t *aid,
- ofono_sim_open_channel_cb_t cb, void *data);
- void (*close_channel)(struct ofono_sim_auth *sa, int session_id,
- ofono_sim_close_channel_cb_t cb, void *data);
- void (*logical_access)(struct ofono_sim_auth *sa,
- int session_id, const uint8_t *pdu, uint16_t len,
- ofono_logical_access_cb_t cb, void *data);
-};
-
-int ofono_sim_auth_driver_register(const struct ofono_sim_auth_driver *d);
-void ofono_sim_auth_driver_unregister(const struct ofono_sim_auth_driver *d);
-
-struct ofono_sim_auth *ofono_sim_auth_create(struct ofono_modem *modem,
- unsigned int vendor,
- const char *driver, void *data);
-
-void ofono_sim_auth_register(struct ofono_sim_auth *sa);
void ofono_sim_auth_remove(struct ofono_sim_auth *sa);
void ofono_sim_auth_set_data(struct ofono_sim_auth *sa, void *data);
--
2.7.4
3 years, 2 months
[PATCH 1/6] atmodem: removed simauth init
by James Prestwood
---
drivers/atmodem/atmodem.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/drivers/atmodem/atmodem.c b/drivers/atmodem/atmodem.c
index 684b228..e0d5ab6 100644
--- a/drivers/atmodem/atmodem.c
+++ b/drivers/atmodem/atmodem.c
@@ -50,7 +50,6 @@ static int atmodem_init(void)
at_call_volume_init();
at_gprs_init();
at_gprs_context_init();
- at_sim_auth_init();
at_gnss_init();
at_lte_init();
@@ -59,7 +58,6 @@ static int atmodem_init(void)
static void atmodem_exit(void)
{
- at_sim_auth_exit();
at_stk_exit();
at_sim_exit();
at_sms_exit();
--
2.7.4
3 years, 2 months
[PATCH 1/4] simfs: Added support for ISim file systems
by James Prestwood
---
src/simfilesystem.cpp | 100 +++++++++++++++++++++++++++++++++++++++-----------
src/simfilesystem.h | 11 +++++-
2 files changed, 89 insertions(+), 22 deletions(-)
diff --git a/src/simfilesystem.cpp b/src/simfilesystem.cpp
index a23d0a0..0e5c2a9 100644
--- a/src/simfilesystem.cpp
+++ b/src/simfilesystem.cpp
@@ -133,7 +133,20 @@ static SimFileInfo const knownFiles[] =
{0, 0, 0, 0, FILE_TYPE_TRANSPARENT}
};
-SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
+static SimFileInfo const isimFiles[] =
+{
+ // TS 31.103
+ {"6F02", 0, "EFimpi", 0x14ff44, FILE_TYPE_TRANSPARENT},
+ {"6F03", 0, "EFdomain", 0x14ff44, FILE_TYPE_TRANSPARENT},
+ {"6FAD", 0, "EFad", 0x14ff44, FILE_TYPE_TRANSPARENT},
+ {"6F06", 0, "EFarr", 0x14ff44, FILE_TYPE_TRANSPARENT},
+ {"6F07", 0, "EFist", 0x14ff44, FILE_TYPE_TRANSPARENT},
+ {"6F09", 0, "EFpcscf", 0x14ff44, FILE_TYPE_TRANSPARENT},
+ {"6FD5", 0, "EFgbabp", 0x14ff44, FILE_TYPE_TRANSPARENT},
+ {0, 0, 0, 0, FILE_TYPE_TRANSPARENT}
+};
+
+SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e, enum file_system_type fstype )
: QObject( rules )
{
this->rules = rules;
@@ -141,7 +154,12 @@ SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
currentItem = rootItem;
// Create all of the standard directories.
- const SimFileInfo *info = knownFiles;
+ const SimFileInfo *info;
+ if (fstype == FILE_SYSTEM_TYPE_ISIM) {
+ info = isimFiles;
+ } else {
+ info = knownFiles;
+ }
SimFileItem *dirItem = 0;
while ( info->fileid ) {
QString fileid = info->fileid;
@@ -162,20 +180,33 @@ SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
QString fileid = resolveFileId( name );
int access = findItemAccess( name );
enum file_type type = findItemFileType( name );
- SimFileItem *parent = findItemParent( fileid );
- if ( parent ) {
- SimFileItem *item;
- item = findItem( fileid.right(4) );
- if ( !item )
- item = new SimFileItem( fileid.right(4), parent, access, type );
- else
- qDebug() << "File" << name << "defined multiple times";
- item->setContents( data );
- QString size = child->getAttribute( "recordsize" );
- if ( !size.isEmpty() )
- item->setRecordSize( size.toInt() );
+
+ if ( fstype == FILE_SYSTEM_TYPE_DEFAULT) {
+ SimFileItem *parent = findItemParent( fileid );
+ if ( parent ) {
+ SimFileItem *item;
+ item = findItem( fileid.right(4) );
+ if ( !item )
+ item = new SimFileItem( fileid.right(4), parent, access, type );
+ else
+ qDebug() << "File" << name << "defined multiple times";
+ item->setContents( data );
+ QString size = child->getAttribute( "recordsize" );
+ if ( !size.isEmpty() )
+ item->setRecordSize( size.toInt() );
+ } else {
+ qDebug() << "Could not find parent for" << name;
+ }
} else {
- qDebug() << "Could not find parent for" << name;
+ /*
+ * ISIM files wont have a parent dir set, so they are handled
+ * differently.
+ */
+ QString name = child->getAttribute( "name" );
+ QByteArray data = QAtUtils::fromHex( child->contents );
+ QString fileid = resolveISimFileId( name );
+ SimFileItem *item = new SimFileItem( fileid.right(4), rootItem, access, type);
+ item->setContents( data );
}
} else {
qDebug() << "Unknown filesystem command <" << child->tag << ">";
@@ -184,7 +215,8 @@ SimFileSystem::SimFileSystem( SimRules *rules, SimXmlNode& e )
}
/* Select DFgsm initially */
- currentItem = findItem("7F20");
+ if ( fstype == FILE_SYSTEM_TYPE_DEFAULT )
+ currentItem = findItem("7F20");
}
SimFileSystem::~SimFileSystem()
@@ -192,7 +224,7 @@ SimFileSystem::~SimFileSystem()
delete rootItem;
}
-void SimFileSystem::crsm( const QString& args )
+bool SimFileSystem::fileAccess( const QString& args, QString& resp )
{
// Extract the arguments to the command.
uint posn = 0;
@@ -428,13 +460,26 @@ void SimFileSystem::crsm( const QString& args )
// Send the response information.
if ( sw1 != 0 ) {
- QString resp;
- resp = "+CRSM: " + QString::number(sw1) + "," + QString::number(sw2);
+ resp = QString::number(sw1) + "," + QString::number(sw2);
if ( !response.isEmpty() )
resp += "," + response;
- rules->respond( resp );
}
- if ( ok )
+
+ return ok;
+}
+
+void SimFileSystem::crsm( const QString& args )
+{
+ bool ok;
+ QString crsm = "+CRSM: ";
+ QString resp;
+ ok = fileAccess( args, resp );
+
+ crsm += resp;
+
+ rules->respond( crsm );
+
+ if (ok)
rules->respond( "OK" );
else
rules->respond( "ERROR" );
@@ -526,6 +571,19 @@ QString SimFileSystem::resolveFileId( const QString& _fileid ) const
}
}
+QString SimFileSystem::resolveISimFileId( const QString& name ) const
+{
+ const SimFileInfo *info = (const SimFileInfo *)isimFiles;
+ while ( info->fileid ) {
+ if ( name == info->name ) {
+ QString fileid = info->fileid;
+ return fileid;
+ }
+ ++info;
+ }
+ return QString("");
+}
+
int SimFileSystem::findItemAccess( const QString& _fileid ) const
{
QString fileid = _fileid;
diff --git a/src/simfilesystem.h b/src/simfilesystem.h
index 150416f..477c6c7 100644
--- a/src/simfilesystem.h
+++ b/src/simfilesystem.h
@@ -24,6 +24,11 @@
class SimFileItem;
+enum file_system_type {
+ FILE_SYSTEM_TYPE_DEFAULT,
+ FILE_SYSTEM_TYPE_ISIM
+};
+
enum file_type {
FILE_TYPE_TRANSPARENT = 0,
FILE_TYPE_LINEAR_FIXED = 1,
@@ -52,12 +57,14 @@ class SimFileSystem : public QObject
{
Q_OBJECT
public:
- SimFileSystem( SimRules *rules, SimXmlNode& e );
+ SimFileSystem( SimRules *rules, SimXmlNode& e, enum file_system_type type = FILE_SYSTEM_TYPE_DEFAULT );
~SimFileSystem();
// Execute an AT+CRSM command against the filesystem.
void crsm( const QString& args );
+ bool fileAccess( const QString& args, QString& resp );
+
// Find an item with a specific id.
SimFileItem *findItem( const QString& fileid ) const;
@@ -77,6 +84,8 @@ public:
// Resolve a file identifier to its full path from the root directory.
QString resolveFileId( const QString& fileid ) const;
+ QString resolveISimFileId( const QString& _fileid ) const;
+
private:
SimRules *rules;
SimFileItem *rootItem;
--
2.7.4
3 years, 2 months
[PATCH] simauth: use new sim atom functionality for simauth
by James Prestwood
All the functionality for the simauth driver was moved
into the sim atom. This patch transitions the simauth
atom to using those API's instead of the simauth driver
API's.
With this change it made more sense to store each AID
as its own object structure so the AID and object path
could be re-used rather than generating it on the fly.
Renamed the simauth 'sim' variable to 'sa' to keep it
consistent now that the simauth structure references
the sim atom as 'sim'.
---
src/sim-auth.c | 400 +++++++++++++++++++++++++++++++++------------------------
1 file changed, 229 insertions(+), 171 deletions(-)
diff --git a/src/sim-auth.c b/src/sim-auth.c
index c0b2422..f5ae7b6 100644
--- a/src/sim-auth.c
+++ b/src/sim-auth.c
@@ -59,35 +59,41 @@ struct auth_request {
int cb_count;
void *autn;
uint8_t umts : 1;
+ unsigned int watch_id;
+ struct ofono_sim_aid_session *session;
+};
+
+struct aid_object {
+ uint8_t aid[16];
+ char *path;
+ enum sim_app_type type;
};
struct ofono_sim_auth {
+ struct ofono_sim *sim;
const struct ofono_sim_auth_driver *driver;
void *driver_data;
struct ofono_atom *atom;
- GSList *aid_list;
+ GSList *aid_objects;
uint8_t gsm_access : 1;
uint8_t gsm_context : 1;
struct auth_request *pending;
+ char *nai;
};
/*
* Find an application by path. 'path' should be a DBusMessage object path.
*/
-static struct sim_app_record *find_aid_by_path(GSList *aid_list,
+static uint8_t *find_aid_by_path(GSList *aid_objects,
const char *path)
{
- GSList *iter = aid_list;
- const char *aid = strrchr(path, '/') + 1;
+ GSList *iter = aid_objects;
while (iter) {
- struct sim_app_record *app = iter->data;
- char str[33];
-
- encode_hex_own_buf(app->aid, 16, 0, str);
+ struct aid_object *obj = iter->data;
- if (!strcmp(aid, str))
- return app;
+ if (!strcmp(path, obj->path))
+ return obj->aid;
iter = g_slist_next(iter);
}
@@ -103,23 +109,20 @@ static void free_apps(struct ofono_sim_auth *sa)
DBusConnection *conn = ofono_dbus_get_connection();
struct ofono_modem *modem = __ofono_atom_get_modem(sa->atom);
const char *path = __ofono_atom_get_path(sa->atom);
- GSList *iter = sa->aid_list;
+ GSList *iter = sa->aid_objects;
while (iter) {
- struct sim_app_record *app = iter->data;
- char object[strlen(path) + 33];
- int ret;
+ struct aid_object *obj = iter->data;
- ret = sprintf(object, "%s/", path);
- encode_hex_own_buf(app->aid, 16, 0, object + ret);
-
- if (app->type == SIM_APP_TYPE_USIM) {
- g_dbus_unregister_interface(conn, object,
+ if (obj->type == SIM_APP_TYPE_USIM)
+ g_dbus_unregister_interface(conn, obj->path,
OFONO_USIM_APPLICATION_INTERFACE);
- } else if (app->type == SIM_APP_TYPE_ISIM) {
- g_dbus_unregister_interface(conn, object,
+ else if (obj->type == SIM_APP_TYPE_ISIM)
+ g_dbus_unregister_interface(conn, obj->path,
OFONO_ISIM_APPLICATION_INTERFACE);
- }
+
+ g_free(obj->path);
+ g_free(obj);
iter = g_slist_next(iter);
}
@@ -130,7 +133,7 @@ static void free_apps(struct ofono_sim_auth *sa)
OFONO_SIM_AUTHENTICATION_INTERFACE);
- g_slist_free(sa->aid_list);
+ g_slist_free(sa->aid_objects);
}
int ofono_sim_auth_driver_register(const struct ofono_sim_auth_driver *d)
@@ -186,7 +189,7 @@ struct ofono_sim_auth *ofono_sim_auth_create(struct ofono_modem *modem,
if (driver == NULL)
return NULL;
- sa = g_try_new0(struct ofono_sim_auth, 1);
+ sa = g_new0(struct ofono_sim_auth, 1);
if (sa == NULL)
return NULL;
@@ -248,7 +251,7 @@ static void append_dict_byte_array(DBusMessageIter *iter, const char *key,
dbus_message_iter_close_container(iter, &keyiter);
}
-static void handle_umts(struct ofono_sim_auth *sim, const uint8_t *resp,
+static void handle_umts(struct ofono_sim_auth *sa, const uint8_t *resp,
uint16_t len)
{
DBusMessage *reply = NULL;
@@ -264,7 +267,7 @@ static void handle_umts(struct ofono_sim_auth *sim, const uint8_t *resp,
&auts, &kc))
goto umts_end;
- reply = dbus_message_new_method_return(sim->pending->msg);
+ reply = dbus_message_new_method_return(sa->pending->msg);
dbus_message_iter_init_append(reply, &iter);
@@ -285,17 +288,18 @@ static void handle_umts(struct ofono_sim_auth *sim, const uint8_t *resp,
umts_end:
if (!reply)
- reply = __ofono_error_not_supported(sim->pending->msg);
+ reply = __ofono_error_not_supported(sa->pending->msg);
- __ofono_dbus_pending_reply(&sim->pending->msg, reply);
+ __ofono_dbus_pending_reply(&sa->pending->msg, reply);
- sim->driver->close_channel(sim, sim->pending->session_id, NULL, NULL);
+ __ofono_sim_remove_session_watch(sa->pending->session,
+ sa->pending->watch_id);
- g_free(sim->pending);
- sim->pending = NULL;
+ g_free(sa->pending);
+ sa->pending = NULL;
}
-static void handle_gsm(struct ofono_sim_auth *sim, const uint8_t *resp,
+static void handle_gsm(struct ofono_sim_auth *sa, const uint8_t *resp,
uint16_t len)
{
DBusMessageIter iter;
@@ -306,130 +310,128 @@ static void handle_gsm(struct ofono_sim_auth *sim, const uint8_t *resp,
goto gsm_end;
/* initial iteration, setup the reply message */
- if (sim->pending->cb_count == 0) {
- sim->pending->reply = dbus_message_new_method_return(
- sim->pending->msg);
+ if (sa->pending->cb_count == 0) {
+ sa->pending->reply = dbus_message_new_method_return(
+ sa->pending->msg);
- dbus_message_iter_init_append(sim->pending->reply,
- &sim->pending->iter);
+ dbus_message_iter_init_append(sa->pending->reply,
+ &sa->pending->iter);
- dbus_message_iter_open_container(&sim->pending->iter,
- DBUS_TYPE_ARRAY, "a{say}", &sim->pending->dict);
+ dbus_message_iter_open_container(&sa->pending->iter,
+ DBUS_TYPE_ARRAY, "a{say}", &sa->pending->dict);
}
/* append the Nth sres/kc byte arrays */
- dbus_message_iter_open_container(&sim->pending->dict, DBUS_TYPE_ARRAY,
+ dbus_message_iter_open_container(&sa->pending->dict, DBUS_TYPE_ARRAY,
"{say}", &iter);
append_dict_byte_array(&iter, "SRES", sres, 4);
append_dict_byte_array(&iter, "Kc", kc, 8);
- dbus_message_iter_close_container(&sim->pending->dict, &iter);
+ dbus_message_iter_close_container(&sa->pending->dict, &iter);
- sim->pending->cb_count++;
+ sa->pending->cb_count++;
/* calculated the number of keys requested, close container */
- if (sim->pending->cb_count == sim->pending->num_rands) {
- dbus_message_iter_close_container(&sim->pending->iter,
- &sim->pending->dict);
+ if (sa->pending->cb_count == sa->pending->num_rands) {
+ dbus_message_iter_close_container(&sa->pending->iter,
+ &sa->pending->dict);
goto gsm_end;
}
return;
gsm_end:
- if (!sim->pending->reply)
- sim->pending->reply = __ofono_error_not_supported(
- sim->pending->msg);
+ if (!sa->pending->reply)
+ sa->pending->reply = __ofono_error_not_supported(
+ sa->pending->msg);
- __ofono_dbus_pending_reply(&sim->pending->msg, sim->pending->reply);
+ __ofono_dbus_pending_reply(&sa->pending->msg, sa->pending->reply);
- sim->driver->close_channel(sim, sim->pending->session_id, NULL, NULL);
+ __ofono_sim_remove_session_watch(sa->pending->session,
+ sa->pending->watch_id);
- g_free(sim->pending);
+ g_free(sa->pending);
- sim->pending = NULL;
+ sa->pending = NULL;
}
static void logical_access_cb(const struct ofono_error *error,
- const uint8_t *resp, uint16_t len, void *data)
+ const unsigned char *resp, unsigned int len, void *data)
{
- struct ofono_sim_auth *sim = data;
+ struct ofono_sim_auth *sa = data;
/* error must have occurred in a previous CB */
- if (!sim->pending)
+ if (!sa->pending)
return;
if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
- __ofono_dbus_pending_reply(&sim->pending->msg,
- __ofono_error_failed(sim->pending->msg));
- g_free(sim->pending);
- sim->pending = NULL;
+ __ofono_dbus_pending_reply(&sa->pending->msg,
+ __ofono_error_failed(sa->pending->msg));
+ g_free(sa->pending);
+ sa->pending = NULL;
return;
}
- if (sim->pending->umts)
- handle_umts(sim, resp, len);
+ if (sa->pending->umts)
+ handle_umts(sa, resp, len);
else
- handle_gsm(sim, resp, len);
+ handle_gsm(sa, resp, len);
}
-static void open_channel_cb(const struct ofono_error *error, int session_id,
+static void get_session_cb(ofono_bool_t active, int session_id,
void *data)
{
- struct ofono_sim_auth *sim = data;
+ struct ofono_sim_auth *sa = data;
int i;
- if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
- goto error;
-
- if (session_id == -1)
+ if (!active)
goto error;
/* save session ID for close_channel() */
- sim->pending->session_id = session_id;
+ sa->pending->session_id = session_id;
/*
* This will do the logical access num_rand times, providing a new
* RAND seed each time. In the UMTS case, num_rands should be 1.
*/
- for (i = 0; i < sim->pending->num_rands; i++) {
+ for (i = 0; i < sa->pending->num_rands; i++) {
uint8_t auth_cmd[40];
int len = 0;
- if (sim->pending->umts)
+ if (sa->pending->umts)
len = sim_build_umts_authenticate(auth_cmd, 40,
- sim->pending->rands[i],
- sim->pending->autn);
+ sa->pending->rands[i],
+ sa->pending->autn);
else
len = sim_build_gsm_authenticate(auth_cmd, 40,
- sim->pending->rands[i]);
+ sa->pending->rands[i]);
if (!len)
goto error;
- sim->driver->logical_access(sim, session_id, auth_cmd, len,
- logical_access_cb, sim);
+ ofono_sim_logical_access(sa->sim, session_id, auth_cmd, len,
+ logical_access_cb, sa);
}
return;
error:
- __ofono_dbus_pending_reply(&sim->pending->msg,
- __ofono_error_failed(sim->pending->msg));
- g_free(sim->pending);
- sim->pending = NULL;
+ __ofono_dbus_pending_reply(&sa->pending->msg,
+ __ofono_error_failed(sa->pending->msg));
+ g_free(sa->pending);
+ sa->pending = NULL;
}
static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct ofono_sim_auth *sim = data;
+ struct ofono_sim_auth *sa = data;
DBusMessageIter iter;
DBusMessageIter array;
int i;
- struct sim_app_record *app;
+ uint8_t *aid;
int rands;
- if (sim->pending)
+ if (sa->pending)
return __ofono_error_busy(msg);
dbus_message_iter_init(msg, &iter);
@@ -442,15 +444,13 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
if (rands > 3 || rands < 2)
return __ofono_error_invalid_format(msg);
- sim->pending = malloc(sizeof(struct auth_request));
- sim->pending->msg = dbus_message_ref(msg);
- sim->pending->umts = 0;
- sim->pending->cb_count = 0;
- sim->pending->num_rands = rands;
+ sa->pending = g_new0(struct auth_request, 1);
+ sa->pending->msg = dbus_message_ref(msg);
+ sa->pending->num_rands = rands;
dbus_message_iter_recurse(&iter, &array);
- for (i = 0; i < sim->pending->num_rands; i++) {
+ for (i = 0; i < sa->pending->num_rands; i++) {
int nelement;
DBusMessageIter in;
@@ -459,7 +459,7 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
if (dbus_message_iter_get_arg_type(&in) != DBUS_TYPE_BYTE)
goto format_error;
- dbus_message_iter_get_fixed_array(&in, &sim->pending->rands[i],
+ dbus_message_iter_get_fixed_array(&in, &sa->pending->rands[i],
&nelement);
if (nelement != 16)
@@ -468,15 +468,20 @@ static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
dbus_message_iter_next(&array);
}
- app = find_aid_by_path(sim->aid_list, dbus_message_get_path(msg));
+ /*
+ * retrieve session from SIM
+ */
+ aid = find_aid_by_path(sa->aid_objects, dbus_message_get_path(msg));
+ sa->pending->session = __ofono_sim_get_session_by_aid(sa->sim, aid);
- sim->driver->open_channel(sim, app->aid, open_channel_cb, sim);
+ sa->pending->watch_id = __ofono_sim_add_session_watch(
+ sa->pending->session, get_session_cb, sa, NULL);
return NULL;
format_error:
- g_free(sim->pending);
- sim->pending = NULL;
+ g_free(sa->pending);
+ sa->pending = NULL;
return __ofono_error_invalid_format(msg);
}
@@ -487,10 +492,10 @@ static DBusMessage *umts_common(DBusConnection *conn, DBusMessage *msg,
uint8_t *autn = NULL;
uint32_t rlen;
uint32_t alen;
- struct ofono_sim_auth *sim = data;
- struct sim_app_record *app;
+ struct ofono_sim_auth *sa = data;
+ uint8_t *aid;
- if (sim->pending)
+ if (sa->pending)
return __ofono_error_busy(msg);
/* get RAND/AUTN and setup handle args */
@@ -503,16 +508,21 @@ static DBusMessage *umts_common(DBusConnection *conn, DBusMessage *msg,
if (rlen != 16 || alen != 16)
return __ofono_error_invalid_format(msg);
- sim->pending = g_new0(struct auth_request, 1);
- sim->pending->msg = dbus_message_ref(msg);
- sim->pending->rands[0] = rand;
- sim->pending->num_rands = 1;
- sim->pending->autn = autn;
- sim->pending->umts = 1;
+ sa->pending = g_new0(struct auth_request, 1);
+ sa->pending->msg = dbus_message_ref(msg);
+ sa->pending->rands[0] = rand;
+ sa->pending->num_rands = 1;
+ sa->pending->autn = autn;
+ sa->pending->umts = 1;
- app = find_aid_by_path(sim->aid_list, dbus_message_get_path(msg));
+ /*
+ * retrieve session from SIM
+ */
+ aid = find_aid_by_path(sa->aid_objects, dbus_message_get_path(msg));
+ sa->pending->session = __ofono_sim_get_session_by_aid(sa->sim, aid);
- sim->driver->open_channel(sim, app->aid, open_channel_cb, sim);
+ sa->pending->watch_id = __ofono_sim_add_session_watch(
+ sa->pending->session, get_session_cb, sa, NULL);
return NULL;
}
@@ -520,10 +530,7 @@ static DBusMessage *umts_common(DBusConnection *conn, DBusMessage *msg,
static DBusMessage *get_applications(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct ofono_sim_auth *sim = data;
- const char *path = __ofono_atom_get_path(sim->atom);
- int ret;
- char object[strlen(path) + 33];
+ struct ofono_sim_auth *sa = data;
DBusMessage *reply;
DBusMessageIter iter;
DBusMessageIter array;
@@ -540,29 +547,28 @@ static DBusMessage *get_applications(DBusConnection *conn,
&array);
/* send empty array */
- if (!sim->aid_list)
+ if (!sa->aid_objects)
goto apps_end;
- aid_iter = sim->aid_list;
+ aid_iter = sa->aid_objects;
while (aid_iter) {
- struct sim_app_record *app = aid_iter->data;
+ struct aid_object *obj = aid_iter->data;
- ret = sprintf(object, "%s/", path);
- encode_hex_own_buf(app->aid, 16, 0, object + ret);
-
- switch (app->type) {
+ switch (obj->type) {
case SIM_APP_TYPE_ISIM:
dbus_message_iter_open_container(&array,
DBUS_TYPE_DICT_ENTRY, NULL, &dict);
- append_dict_application(&dict, object, "Ims", "ISim");
+ append_dict_application(&dict, obj->path, "Ims",
+ "ISim");
dbus_message_iter_close_container(&array, &dict);
break;
case SIM_APP_TYPE_USIM:
dbus_message_iter_open_container(&array,
DBUS_TYPE_DICT_ENTRY, NULL, &dict);
- append_dict_application(&dict, object, "Umts", "USim");
+ append_dict_application(&dict, obj->path, "Umts",
+ "USim");
dbus_message_iter_close_container(&array, &dict);
break;
@@ -579,6 +585,33 @@ apps_end:
return reply;
}
+static DBusMessage *get_sim_auth_properties(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct ofono_sim_auth *sa = data;
+ DBusMessage *reply;
+ DBusMessageIter iter;
+ DBusMessageIter dict;
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ OFONO_PROPERTIES_ARRAY_SIGNATURE,
+ &dict);
+
+ if (sa->nai)
+ ofono_dbus_dict_append(&dict, "NetworkAccessIdentity",
+ DBUS_TYPE_STRING, &sa->nai);
+
+ dbus_message_iter_close_container(&iter, &dict);
+
+ return reply;
+}
+
static DBusMessage *send_properties(DBusConnection *conn, DBusMessage *msg,
void *data, const char *type, const char *name)
{
@@ -632,6 +665,10 @@ static const GDBusMethodTable sim_authentication[] = {
NULL,
GDBUS_ARGS({"applications", "a{oa{sv}}"}),
get_applications) },
+ { GDBUS_METHOD("GetProperties",
+ NULL,
+ GDBUS_ARGS({"properties", "a{sv}"}),
+ get_sim_auth_properties) },
{ }
};
@@ -663,94 +700,115 @@ static const GDBusMethodTable sim_auth_isim_app[] = {
{ }
};
-static void discover_apps_cb(const struct ofono_error *error,
- const unsigned char *dataobj,
- int len, void *data)
+/*
+ * Build NAI according to TS 23.003. This should only be used as an NAI
+ * if the SimManager interface could not find an NAI from the ISim.
+ */
+static char *build_nai(const char *imsi)
{
- DBusConnection *conn = ofono_dbus_get_connection();
- struct ofono_sim_auth *sim = data;
- struct ofono_modem *modem = __ofono_atom_get_modem(sim->atom);
- const char *path = __ofono_atom_get_path(sim->atom);
- GSList *iter;
- char app_path[strlen(path) + 34];
- int ret;
+ char mcc[3];
+ char mnc[3];
+ char *nai;
- if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
- goto parse_error;
+ strncpy(mcc, imsi, 3);
- sim->aid_list = sim_parse_app_template_entries(dataobj, len);
+ if (strlen(imsi) == 16) {
+ strncpy(mnc, imsi + 3, 3);
+ } else {
+ mnc[0] = '0';
+ strncpy(mnc + 1, imsi + 3, 2);
+ }
+
+ nai = g_strdup_printf("%s(a)ims.mnc%.3s.mcc%.3s.3gppnetwork.org",
+ imsi, mnc, mcc);
- if (!sim->aid_list)
- goto parse_error;
+ return nai;
+}
+
+void ofono_sim_auth_register(struct ofono_sim_auth *sa)
+{
+ DBusConnection *conn = ofono_dbus_get_connection();
+ const char *path = __ofono_atom_get_path(sa->atom);
+ struct ofono_modem *modem = __ofono_atom_get_modem(sa->atom);
+ struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+ GSList *iter = __ofono_sim_get_aid_list(sim);
+ int ret;
- iter = sim->aid_list;
+ sa->sim = sim;
- ret = sprintf(app_path, "%s/", path);
+ if (!iter) {
+ DBG("No AID list");
+ return;
+ }
while (iter) {
- struct sim_app_record *app = iter->data;
+ struct sim_app_record *r = iter->data;
+ struct aid_object *new = g_new0(struct aid_object, 1);
- switch (app->type) {
+ new->type = r->type;
+
+ switch (r->type) {
case SIM_APP_TYPE_USIM:
- encode_hex_own_buf(app->aid, 16, 0, app_path + ret);
+ new->path = g_new0(char, strlen(path) + 34);
+
+ ret = sprintf(new->path, "%s/", path);
+
+ encode_hex_own_buf(r->aid, 16, 0, new->path + ret);
- g_dbus_register_interface(conn, app_path,
+ g_dbus_register_interface(conn, new->path,
OFONO_USIM_APPLICATION_INTERFACE,
sim_auth_usim_app, NULL, NULL,
- sim, NULL);
+ sa, NULL);
+
+ memcpy(new->aid, r->aid, 16);
+
break;
case SIM_APP_TYPE_ISIM:
- encode_hex_own_buf(app->aid, 16, 0, app_path + ret);
+ new->path = g_new0(char, strlen(path) + 34);
+
+ ret = sprintf(new->path, "%s/", path);
- g_dbus_register_interface(conn, app_path,
+ encode_hex_own_buf(r->aid, 16, 0, new->path + ret);
+
+ g_dbus_register_interface(conn, new->path,
OFONO_ISIM_APPLICATION_INTERFACE,
sim_auth_isim_app, NULL, NULL,
- sim, NULL);
+ sa, NULL);
+
+ memcpy(new->aid, r->aid, 16);
+
break;
default:
- DBG("Unknown SIM application '%04x'", app->type);
+ DBG("Unknown SIM application '%04x'", r->type);
/*
* If we get here, the SIM application was not ISIM
* or USIM, skip.
*/
+ g_free(new);
+
+ goto loop_end;
}
+ sa->aid_objects = g_slist_prepend(sa->aid_objects, new);
+
+loop_end:
iter = g_slist_next(iter);
}
- /*
- * Now SimAuthentication interface can be registered since app
- * discovery has completed
- */
+ /* if IMPI is not available, build the NAI */
+ if (!__ofono_sim_get_impi(sa->sim))
+ sa->nai = build_nai(ofono_sim_get_imsi(sa->sim));
+ else
+ sa->nai = g_strdup(__ofono_sim_get_impi(sa->sim));
+
g_dbus_register_interface(conn, path,
OFONO_SIM_AUTHENTICATION_INTERFACE,
sim_authentication, NULL, NULL,
- sim, NULL);
- ofono_modem_add_interface(modem,
- OFONO_SIM_AUTHENTICATION_INTERFACE);
-
- return;
-
-parse_error:
- /*
- * Something went wrong parsing the AID list, it can't be assumed that
- * any previously parsed AID's are valid so free them all.
- */
- DBG("Error parsing app list");
-}
-
-void ofono_sim_auth_register(struct ofono_sim_auth *sa)
-{
- struct ofono_modem *modem = __ofono_atom_get_modem(sa->atom);
- struct ofono_sim *sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+ sa, NULL);
+ ofono_modem_add_interface(modem, OFONO_SIM_AUTHENTICATION_INTERFACE);
__ofono_atom_register(sa->atom, sim_auth_unregister);
- /* Do SIM application discovery, the cb will register DBus ifaces */
- sa->driver->list_apps(sa, discover_apps_cb, sa);
-
- sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
-
sa->gsm_access = __ofono_sim_ust_service_available(sim,
SIM_UST_SERVICE_GSM_ACCESS);
sa->gsm_context = __ofono_sim_ust_service_available(sim,
--
2.7.4
3 years, 2 months