* [PATCH 1/5] Add SIM authentication atom's driver definitions.
@ 2011-01-17 17:38 Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 2/5] simutil: SIM applications directory decoding utils Andrzej Zaborowski
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Andrzej Zaborowski @ 2011-01-17 17:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 3458 bytes --]
Structures and function declarations for the SIM authentication
atom as proposed by Pekka Pessi, with just one method at the moment.
---
Makefile.am | 2 +-
include/sim-auth.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++
include/types.h | 6 +++++
3 files changed, 71 insertions(+), 1 deletions(-)
create mode 100644 include/sim-auth.h
diff --git a/Makefile.am b/Makefile.am
index ce4799e..ada0a51 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -15,7 +15,7 @@ include_HEADERS = include/log.h include/plugin.h include/history.h \
include/radio-settings.h include/stk.h \
include/audio-settings.h include/nettime.h \
include/ctm.h include/cdma-voicecall.h \
- include/cdma-sms.h
+ include/cdma-sms.h include/sim-auth.h
nodist_include_HEADERS = include/version.h
diff --git a/include/sim-auth.h b/include/sim-auth.h
new file mode 100644
index 0000000..98c3dfc
--- /dev/null
+++ b/include/sim-auth.h
@@ -0,0 +1,64 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2011 Intel Corporation. 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef __OFONO_SIM_AUTH_H
+#define __OFONO_SIM_AUTH_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <ofono/types.h>
+
+struct ofono_sim_auth;
+
+typedef void (*ofono_sim_list_apps_cb_t)(const struct ofono_error *error,
+ struct ofono_sim_app_record *list,
+ int count, 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);
+};
+
+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);
+void *ofono_sim_auth_get_data(struct ofono_sim_auth *sa);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __OFONO_SIM_AUTH_H */
diff --git a/include/types.h b/include/types.h
index 1b95eaa..7f3634e 100644
--- a/include/types.h
+++ b/include/types.h
@@ -122,6 +122,12 @@ struct ofono_uuid {
const char *ofono_uuid_to_str(const struct ofono_uuid *uuid);
+struct ofono_sim_app_record {
+ unsigned char aid[16];
+ int aid_len;
+ char *label;
+};
+
#ifdef __cplusplus
}
#endif
--
1.7.1.86.g0e460.dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] simutil: SIM applications directory decoding utils.
2011-01-17 17:38 [PATCH 1/5] Add SIM authentication atom's driver definitions Andrzej Zaborowski
@ 2011-01-17 17:38 ` Andrzej Zaborowski
2011-01-18 19:22 ` Denis Kenzior
2011-01-17 17:38 ` [PATCH 3/5] unit: Add a test for applications directory decoding utility Andrzej Zaborowski
` (3 subsequent siblings)
4 siblings, 1 reply; 8+ messages in thread
From: Andrzej Zaborowski @ 2011-01-17 17:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2290 bytes --]
---
src/simutil.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/simutil.h | 2 ++
2 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/src/simutil.c b/src/simutil.c
index 8abf3d5..b3e2f52 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -1465,3 +1465,60 @@ gboolean sim_sst_is_active(unsigned char *efsst, unsigned char len,
return (efsst[index / 4] >> (((index % 4) * 2) + 1)) & 1;
}
+
+GSList *sim_parse_app_template_entries(const unsigned char *buffer, int len)
+{
+ GSList *ret = NULL;
+ const unsigned char *dataobj;
+ int dataobj_len;
+
+ /* Find all the application entries */
+ while ((dataobj = ber_tlv_find_by_tag(buffer, 0x61, len,
+ &dataobj_len)) != NULL) {
+ struct ofono_sim_app_record app;
+ const unsigned char *aid, *label;
+ int label_len;
+
+ /* Find the aid (mandatory) */
+ aid = ber_tlv_find_by_tag(dataobj, 0x4f, dataobj_len,
+ &app.aid_len);
+ if (!aid || app.aid_len < 0x01 || app.aid_len > 0x10)
+ goto error;
+
+ memcpy(app.aid, aid, app.aid_len);
+
+ /* Find the label (optional) */
+ label = ber_tlv_find_by_tag(dataobj, 0x50, dataobj_len,
+ &label_len);
+ if (label) {
+ /*
+ * Label field uses the extra complicated
+ * encoding in 102.221 Annex A
+ */
+ app.label = sim_string_to_utf8(label, label_len);
+
+ if (app.label == NULL)
+ goto error;
+ } else
+ app.label = NULL;
+
+ ret = g_slist_prepend(ret, g_memdup(&app, sizeof(app)));
+
+ len -= (dataobj - buffer) + dataobj_len;
+ buffer = dataobj + dataobj_len;
+ }
+
+ return ret;
+
+error:
+ while (ret) {
+ GSList *t = ret;
+
+ g_free(((struct ofono_sim_app_record *) ret->data)->label);
+
+ ret = ret->next;
+ g_slist_free_1(t);
+ }
+
+ return NULL;
+}
diff --git a/src/simutil.h b/src/simutil.h
index ad84907..4418ec9 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -446,3 +446,5 @@ gboolean sim_sst_is_available(unsigned char *service_sst, unsigned char len,
enum sim_sst_service index);
gboolean sim_sst_is_active(unsigned char *service_sst, unsigned char len,
enum sim_sst_service index);
+
+GSList *sim_parse_app_template_entries(const unsigned char *buffer, int len);
--
1.7.1.86.g0e460.dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/5] unit: Add a test for applications directory decoding utility.
2011-01-17 17:38 [PATCH 1/5] Add SIM authentication atom's driver definitions Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 2/5] simutil: SIM applications directory decoding utils Andrzej Zaborowski
@ 2011-01-17 17:38 ` Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 4/5] Add the sim-auth atom Andrzej Zaborowski
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Andrzej Zaborowski @ 2011-01-17 17:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1744 bytes --]
---
unit/test-simutil.c | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/unit/test-simutil.c b/unit/test-simutil.c
index 7cb5c10..1f350f6 100644
--- a/unit/test-simutil.c
+++ b/unit/test-simutil.c
@@ -444,6 +444,36 @@ static void test_3g_status_data(void)
g_free(response);
}
+static char *at_cuad_response = "611B4F10A0000000871002FFFFFFFF8905080000"
+ "FFFFFFFFFFFFFFFFFFFFFFFFFF611F4F0CA000000063504B43532D"
+ "313550094D49445066696C657351043F007F80";
+
+static void test_application_entry_decode(void) {
+ unsigned char *ef_dir;
+ long len;
+ GSList *entries;
+ struct ofono_sim_app_record *app[2];
+
+ ef_dir = decode_hex(at_cuad_response, -1, &len, 0);
+ entries = sim_parse_app_template_entries(ef_dir, len);
+
+ g_assert(g_slist_length(entries) == 2);
+
+ app[0] = entries->next->data;
+ app[1] = entries->data;
+
+ g_assert(app[0]->aid_len == 0x10);
+ g_assert(!memcmp(app[0]->aid, &ef_dir[4], 0x10));
+ g_assert(app[0]->label == NULL);
+
+ g_assert(app[1]->aid_len == 0x0c);
+ g_assert(!memcmp(app[1]->aid, &ef_dir[37], 0x0c));
+ g_assert(app[1]->label != NULL);
+ g_assert(!strcmp(app[1]->label, "MIDPfiles"));
+
+ g_free(ef_dir);
+}
+
int main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
@@ -458,6 +488,8 @@ int main(int argc, char **argv)
g_test_add_func("/testsimutil/EONS Handling", test_eons);
g_test_add_func("/testsimutil/Elementary File DB", test_ef_db);
g_test_add_func("/testsimutil/3G Status response", test_3g_status_data);
+ g_test_add_func("/testsimutil/Application entries decoding",
+ test_application_entry_decode);
return g_test_run();
}
--
1.7.1.86.g0e460.dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/5] Add the sim-auth atom.
2011-01-17 17:38 [PATCH 1/5] Add SIM authentication atom's driver definitions Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 2/5] simutil: SIM applications directory decoding utils Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 3/5] unit: Add a test for applications directory decoding utility Andrzej Zaborowski
@ 2011-01-17 17:38 ` Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 5/5] atmodem: sim-auth atom driver Andrzej Zaborowski
2011-01-18 19:21 ` [PATCH 1/5] Add SIM authentication atom's driver definitions Denis Kenzior
4 siblings, 0 replies; 8+ messages in thread
From: Andrzej Zaborowski @ 2011-01-17 17:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 4618 bytes --]
Add dummy SIM authentication atom.
---
Makefile.am | 2 +-
src/ofono.h | 2 +
src/sim-auth.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 137 insertions(+), 1 deletions(-)
create mode 100644 src/sim-auth.c
diff --git a/Makefile.am b/Makefile.am
index ada0a51..a0b7264 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -349,7 +349,7 @@ src_ofonod_SOURCES = $(gdbus_sources) $(builtin_sources) src/ofono.ver \
src/nettime.c src/stkagent.c src/stkagent.h \
src/simfs.c src/simfs.h src/audio-settings.c \
src/smsagent.c src/smsagent.h src/ctm.c \
- src/cdma-voicecall.c
+ src/cdma-voicecall.c src/sim-auth.c
src_ofonod_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ \
@BLUEZ_LIBS@ -ldl
diff --git a/src/ofono.h b/src/ofono.h
index 77567c2..9179f61 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -127,6 +127,7 @@ enum ofono_atom_type {
OFONO_ATOM_TYPE_NETTIME = 21,
OFONO_ATOM_TYPE_CTM = 22,
OFONO_ATOM_TYPE_CDMA_VOICECALL_MANAGER = 23,
+ OFONO_ATOM_TYPE_SIM_AUTH = 24,
};
enum ofono_atom_watch_condition {
@@ -418,3 +419,4 @@ void __ofono_nettime_info_received(struct ofono_modem *modem,
struct ofono_network_time *info);
#include <ofono/cdma-voicecall.h>
+#include <ofono/sim-auth.h>
diff --git a/src/sim-auth.c b/src/sim-auth.c
new file mode 100644
index 0000000..5d2f075
--- /dev/null
+++ b/src/sim-auth.c
@@ -0,0 +1,134 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2011 Intel Corporation. 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+
+#include <glib.h>
+#include <errno.h>
+#include <unistd.h>
+
+#include "ofono.h"
+
+#include "simutil.h"
+
+static GSList *g_drivers = NULL;
+
+struct ofono_sim_auth {
+ const struct ofono_sim_auth_driver *driver;
+ void *driver_data;
+ struct ofono_atom *atom;
+};
+
+int ofono_sim_auth_driver_register(const struct ofono_sim_auth_driver *d)
+{
+ DBG("driver: %p, name: %s", d, d->name);
+
+ if (d->probe == NULL)
+ return -EINVAL;
+
+ g_drivers = g_slist_prepend(g_drivers, (void *) d);
+
+ return 0;
+}
+
+void ofono_sim_auth_driver_unregister(const struct ofono_sim_auth_driver *d)
+{
+ DBG("driver: %p, name: %s", d, d->name);
+
+ g_drivers = g_slist_remove(g_drivers, (void *) d);
+}
+
+static void sim_auth_unregister(struct ofono_atom *atom)
+{
+}
+
+static void sim_auth_remove(struct ofono_atom *atom)
+{
+ struct ofono_sim_auth *sa = __ofono_atom_get_data(atom);
+
+ DBG("atom: %p", atom);
+
+ if (sa == NULL)
+ return;
+
+ if (sa->driver && sa->driver->remove)
+ sa->driver->remove(sa);
+
+ g_free(sa);
+}
+
+struct ofono_sim_auth *ofono_sim_auth_create(struct ofono_modem *modem,
+ unsigned int vendor,
+ const char *driver, void *data)
+{
+ struct ofono_sim_auth *sa;
+ GSList *l;
+
+ if (driver == NULL)
+ return NULL;
+
+ sa = g_try_new0(struct ofono_sim_auth, 1);
+
+ if (sa == NULL)
+ return NULL;
+
+ sa->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_SIM_AUTH,
+ sim_auth_remove, sa);
+
+ for (l = g_drivers; l; l = l->next) {
+ const struct ofono_sim_auth_driver *drv = l->data;
+
+ if (g_strcmp0(drv->name, driver))
+ continue;
+
+ if (drv->probe(sa, vendor, data) < 0)
+ continue;
+
+ sa->driver = drv;
+ break;
+ }
+
+ return sa;
+}
+
+void ofono_sim_auth_register(struct ofono_sim_auth *sa)
+{
+ __ofono_atom_register(sa->atom, sim_auth_unregister);
+}
+
+void ofono_sim_auth_remove(struct ofono_sim_auth *sa)
+{
+ __ofono_atom_free(sa->atom);
+}
+
+void ofono_sim_auth_set_data(struct ofono_sim_auth *sa, void *data)
+{
+ sa->driver_data = data;
+}
+
+void *ofono_sim_auth_get_data(struct ofono_sim_auth *sa)
+{
+ return sa->driver_data;
+}
--
1.7.1.86.g0e460.dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/5] atmodem: sim-auth atom driver.
2011-01-17 17:38 [PATCH 1/5] Add SIM authentication atom's driver definitions Andrzej Zaborowski
` (2 preceding siblings ...)
2011-01-17 17:38 ` [PATCH 4/5] Add the sim-auth atom Andrzej Zaborowski
@ 2011-01-17 17:38 ` Andrzej Zaborowski
2011-01-18 19:30 ` Denis Kenzior
2011-01-18 19:21 ` [PATCH 1/5] Add SIM authentication atom's driver definitions Denis Kenzior
4 siblings, 1 reply; 8+ messages in thread
From: Andrzej Zaborowski @ 2011-01-17 17:38 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 5971 bytes --]
At the moment implementing only application discovery.
---
Makefile.am | 3 +-
drivers/atmodem/atmodem.c | 2 +
drivers/atmodem/atmodem.h | 3 +
drivers/atmodem/sim-auth.c | 173 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+), 1 deletions(-)
create mode 100644 drivers/atmodem/sim-auth.c
diff --git a/Makefile.am b/Makefile.am
index a0b7264..1397170 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -170,7 +170,8 @@ builtin_sources += $(gatchat_sources) \
drivers/atmodem/atutil.h \
drivers/atmodem/atutil.c \
drivers/atmodem/gprs.c \
- drivers/atmodem/gprs-context.c
+ drivers/atmodem/gprs-context.c \
+ drivers/atmodem/sim-auth.c
builtin_modules += nwmodem
builtin_sources += drivers/atmodem/atutil.h \
diff --git a/drivers/atmodem/atmodem.c b/drivers/atmodem/atmodem.c
index c88f6b2..e140281 100644
--- a/drivers/atmodem/atmodem.c
+++ b/drivers/atmodem/atmodem.c
@@ -51,12 +51,14 @@ static int atmodem_init(void)
at_call_volume_init();
at_gprs_init();
at_gprs_context_init();
+ at_sim_auth_init();
return 0;
}
static void atmodem_exit(void)
{
+ at_sim_auth_exit();
at_stk_exit();
at_sim_exit();
at_sms_exit();
diff --git a/drivers/atmodem/atmodem.h b/drivers/atmodem/atmodem.h
index c7f0eed..1b7cf67 100644
--- a/drivers/atmodem/atmodem.h
+++ b/drivers/atmodem/atmodem.h
@@ -71,3 +71,6 @@ extern void at_gprs_exit(void);
extern void at_gprs_context_init(void);
extern void at_gprs_context_exit(void);
+
+extern void at_sim_auth_init(void);
+extern void at_sim_auth_exit(void);
diff --git a/drivers/atmodem/sim-auth.c b/drivers/atmodem/sim-auth.c
new file mode 100644
index 0000000..a7a64ed
--- /dev/null
+++ b/drivers/atmodem/sim-auth.c
@@ -0,0 +1,173 @@
+/*
+ *
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2008-2011 Intel Corporation. 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <string.h>
+
+#include <glib.h>
+
+#include <ofono/modem.h>
+#include <ofono/sim-auth.h>
+
+#include "gatchat.h"
+#include "gatresult.h"
+#include "simutil.h"
+#include "vendor.h"
+
+#include "atmodem.h"
+
+struct sim_auth_data {
+ GAtChat *chat;
+ unsigned int vendor;
+};
+
+static const char *cuad_prefix[] = { "+CUAD:", NULL };
+
+static void at_discover_apps_cb(gboolean ok, GAtResult *result,
+ gpointer user_data)
+{
+ struct cb_data *cbd = user_data;
+ GAtResultIter iter;
+ ofono_sim_list_apps_cb_t cb = cbd->cb;
+ struct ofono_error error;
+ GSList *list = NULL, *i;
+ struct ofono_sim_app_record *buffer;
+ int j, n;
+
+ decode_at_error(&error, g_at_result_final_response(result));
+
+ if (!ok) {
+ cb(&error, NULL, 0, cbd->data);
+ return;
+ }
+
+ g_at_result_iter_init(&iter, result);
+
+ while (g_at_result_iter_next(&iter, "+CUAD:")) {
+ const guint8 *obj_str;
+ gint len;
+
+ if (!g_at_result_iter_next_hexstring(&iter, &obj_str, &len))
+ goto error;
+
+ i = sim_parse_app_template_entries(obj_str, len);
+ if (i == NULL)
+ goto error;
+
+ list = g_slist_concat(i, list);
+ }
+
+ n = g_slist_length(list);
+ buffer = g_new(struct ofono_sim_app_record, n);
+
+ for (i = list, j = n - 1; i != NULL; i = i->next, i--)
+ memcpy(&buffer[j], i->data, sizeof(*buffer));
+
+ cb(&error, buffer, n, cbd->data);
+
+ g_free(buffer);
+ goto done;
+
+error:
+ CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
+
+done:
+ while (list) {
+ i = list;
+ list = list->next;
+
+ g_free(((struct ofono_sim_app_record *) i->data)->label);
+ g_free(i->data);
+ g_slist_free_1(i);
+ }
+}
+
+static void at_discover_apps(struct ofono_sim_auth *sa,
+ ofono_sim_list_apps_cb_t cb,
+ void *data)
+{
+ struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
+ struct cb_data *cbd = cb_data_new(cb, data);
+
+ if (cbd && g_at_chat_send(sad->chat, "AT+CUAD", cuad_prefix,
+ at_discover_apps_cb, cbd, g_free) > 0)
+ return;
+
+ g_free(cbd);
+
+ CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
+}
+
+static gboolean at_sim_auth_register(gpointer user)
+{
+ struct ofono_sim_auth *sa = user;
+
+ ofono_sim_auth_register(sa);
+
+ return FALSE;
+}
+
+static int at_sim_auth_probe(struct ofono_sim_auth *sa, unsigned int vendor,
+ void *data)
+{
+ GAtChat *chat = data;
+ struct sim_auth_data *sad;
+
+ sad = g_new0(struct sim_auth_data, 1);
+ sad->chat = g_at_chat_clone(chat);
+ sad->vendor = vendor;
+
+ ofono_sim_auth_set_data(sa, sad);
+ g_idle_add(at_sim_auth_register, sa);
+
+ return 0;
+}
+
+static void at_sim_auth_remove(struct ofono_sim_auth *sa)
+{
+ struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
+
+ ofono_sim_auth_set_data(sa, NULL);
+
+ g_at_chat_unref(sad->chat);
+ g_free(sad);
+}
+
+static struct ofono_sim_auth_driver driver = {
+ .name = "atmodem",
+ .probe = at_sim_auth_probe,
+ .remove = at_sim_auth_remove,
+ .list_apps = at_discover_apps,
+};
+
+void at_sim_auth_init(void)
+{
+ ofono_sim_auth_driver_register(&driver);
+}
+
+void at_sim_auth_exit(void)
+{
+ ofono_sim_auth_driver_unregister(&driver);
+}
--
1.7.1.86.g0e460.dirty
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/5] Add SIM authentication atom's driver definitions.
2011-01-17 17:38 [PATCH 1/5] Add SIM authentication atom's driver definitions Andrzej Zaborowski
` (3 preceding siblings ...)
2011-01-17 17:38 ` [PATCH 5/5] atmodem: sim-auth atom driver Andrzej Zaborowski
@ 2011-01-18 19:21 ` Denis Kenzior
4 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2011-01-18 19:21 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 584 bytes --]
Hi Andrew,
> +typedef void (*ofono_sim_list_apps_cb_t)(const struct ofono_error *error,
> + struct ofono_sim_app_record *list,
> + int count, void *data);
So I've been thinking about this one. Was there a reason why you want
to pass the parsed list out of the driver instead of just returning the
hex_decoded CUAD response and length?
If we do that then:
> +struct ofono_sim_app_record {
> + unsigned char aid[16];
> + int aid_len;
> + char *label;
> +};
Can be easily hidden inside simutil.h and not exposed to the outside world.
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/5] simutil: SIM applications directory decoding utils.
2011-01-17 17:38 ` [PATCH 2/5] simutil: SIM applications directory decoding utils Andrzej Zaborowski
@ 2011-01-18 19:22 ` Denis Kenzior
0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2011-01-18 19:22 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 2221 bytes --]
Hi Andrew,
On 01/17/2011 11:38 AM, Andrzej Zaborowski wrote:
> ---
> src/simutil.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> src/simutil.h | 2 ++
> 2 files changed, 59 insertions(+), 0 deletions(-)
>
> diff --git a/src/simutil.c b/src/simutil.c
> index 8abf3d5..b3e2f52 100644
> --- a/src/simutil.c
> +++ b/src/simutil.c
> @@ -1465,3 +1465,60 @@ gboolean sim_sst_is_active(unsigned char *efsst, unsigned char len,
>
> return (efsst[index / 4] >> (((index % 4) * 2) + 1)) & 1;
> }
> +
> +GSList *sim_parse_app_template_entries(const unsigned char *buffer, int len)
> +{
> + GSList *ret = NULL;
> + const unsigned char *dataobj;
> + int dataobj_len;
> +
> + /* Find all the application entries */
> + while ((dataobj = ber_tlv_find_by_tag(buffer, 0x61, len,
> + &dataobj_len)) != NULL) {
> + struct ofono_sim_app_record app;
> + const unsigned char *aid, *label;
> + int label_len;
> +
> + /* Find the aid (mandatory) */
> + aid = ber_tlv_find_by_tag(dataobj, 0x4f, dataobj_len,
> + &app.aid_len);
> + if (!aid || app.aid_len < 0x01 || app.aid_len > 0x10)
> + goto error;
> +
> + memcpy(app.aid, aid, app.aid_len);
> +
> + /* Find the label (optional) */
> + label = ber_tlv_find_by_tag(dataobj, 0x50, dataobj_len,
> + &label_len);
> + if (label) {
> + /*
> + * Label field uses the extra complicated
> + * encoding in 102.221 Annex A
> + */
> + app.label = sim_string_to_utf8(label, label_len);
> +
> + if (app.label == NULL)
> + goto error;
> + } else
> + app.label = NULL;
> +
> + ret = g_slist_prepend(ret, g_memdup(&app, sizeof(app)));
> +
> + len -= (dataobj - buffer) + dataobj_len;
> + buffer = dataobj + dataobj_len;
> + }
> +
> + return ret;
> +
> +error:
> + while (ret) {
> + GSList *t = ret;
> +
> + g_free(((struct ofono_sim_app_record *) ret->data)->label);
Is there a memory leak here? I don't believe you are freeing the
ofono_sim_app_record structure itself. This might be the opportunity to
get rid of that nasty cast as well ;)
> +
> + ret = ret->next;
> + g_slist_free_1(t);
> + }
> +
> + return NULL;
> +}
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 5/5] atmodem: sim-auth atom driver.
2011-01-17 17:38 ` [PATCH 5/5] atmodem: sim-auth atom driver Andrzej Zaborowski
@ 2011-01-18 19:30 ` Denis Kenzior
0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2011-01-18 19:30 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 1889 bytes --]
Hi Andrew,
> +static void at_discover_apps_cb(gboolean ok, GAtResult *result,
> + gpointer user_data)
> +{
> + struct cb_data *cbd = user_data;
> + GAtResultIter iter;
> + ofono_sim_list_apps_cb_t cb = cbd->cb;
> + struct ofono_error error;
> + GSList *list = NULL, *i;
> + struct ofono_sim_app_record *buffer;
> + int j, n;
> +
> + decode_at_error(&error, g_at_result_final_response(result));
> +
> + if (!ok) {
> + cb(&error, NULL, 0, cbd->data);
> + return;
> + }
> +
> + g_at_result_iter_init(&iter, result);
> +
> + while (g_at_result_iter_next(&iter, "+CUAD:")) {
> + const guint8 *obj_str;
> + gint len;
> +
> + if (!g_at_result_iter_next_hexstring(&iter, &obj_str, &len))
> + goto error;
> +
> + i = sim_parse_app_template_entries(obj_str, len);
> + if (i == NULL)
> + goto error;
> +
> + list = g_slist_concat(i, list);
> + }
> +
Since we potentially multiple results, what do you think of using an
approach similar to how phonebook works. E.g. a simple:
typedef void (*ofono_sim_auth_cb_t)(const struct ofono_error *error,
void *data);
and ofono_sim_auth_app_record(struct ofono_sim_auth *sa, unsigned char
*record, int len);
This would work nicely even for drivers using CRSM I think...
> + n = g_slist_length(list);
> + buffer = g_new(struct ofono_sim_app_record, n);
> +
> + for (i = list, j = n - 1; i != NULL; i = i->next, i--)
> + memcpy(&buffer[j], i->data, sizeof(*buffer));
> +
> + cb(&error, buffer, n, cbd->data);
> +
> + g_free(buffer);
> + goto done;
> +
> +error:
> + CALLBACK_WITH_FAILURE(cb, NULL, 0, cbd->data);
> +
> +done:
> + while (list) {
> + i = list;
> + list = list->next;
> +
> + g_free(((struct ofono_sim_app_record *) i->data)->label);
> + g_free(i->data);
> + g_slist_free_1(i);
> + }
> +}
Regards,
-Denis
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-01-18 19:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-17 17:38 [PATCH 1/5] Add SIM authentication atom's driver definitions Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 2/5] simutil: SIM applications directory decoding utils Andrzej Zaborowski
2011-01-18 19:22 ` Denis Kenzior
2011-01-17 17:38 ` [PATCH 3/5] unit: Add a test for applications directory decoding utility Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 4/5] Add the sim-auth atom Andrzej Zaborowski
2011-01-17 17:38 ` [PATCH 5/5] atmodem: sim-auth atom driver Andrzej Zaborowski
2011-01-18 19:30 ` Denis Kenzior
2011-01-18 19:21 ` [PATCH 1/5] Add SIM authentication atom's driver definitions Denis Kenzior
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.