All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 01/11] simutil: Added app type to application parser
@ 2017-10-10 21:36 James Prestwood
  2017-10-10 21:36 ` [PATCHv2 02/11] simutil: Added authenticate builder/parser API James Prestwood
                   ` (10 more replies)
  0 siblings, 11 replies; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1525 bytes --]

Parsing a SIM application only copied the 16 byte AID
portion, which included the application type. Parsing out
the type makes sorting much easier for modules using the
parser.
---
 src/simutil.c |  2 ++
 src/simutil.h | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/src/simutil.c b/src/simutil.c
index 4731d3b..f43c2c2 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -1570,6 +1570,8 @@ GSList *sim_parse_app_template_entries(const unsigned char *buffer, int len)
 
 		memcpy(app.aid, aid, app.aid_len);
 
+		app.type = GUINT16_FROM_BE(*((unsigned short *)(app.aid + 5)));
+
 		/* Find the label (optional) */
 		label = ber_tlv_find_by_tag(dataobj, 0x50, dataobj_len,
 						&label_len);
diff --git a/src/simutil.h b/src/simutil.h
index 1faf948..9984b2c 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -261,6 +261,17 @@ enum sim_csp_entry {
 	SIM_CSP_ENTRY_INFORMATION_NUMBERS =	0xD5,
 };
 
+/* 101.220 Annex E */
+enum sim_app_type {
+	SIM_APP_TYPE_UICC =		0x1001,
+	SIM_APP_TYPE_USIM =		0x1002,
+	SIM_APP_TYPE_USIM_TOOLKIT =	0x1003,
+	SIM_APP_TYPE_ISIM =		0x1004,
+	SIM_APP_TYPE_USIM_API =		0x1005,
+	SIM_APP_TYPE_ISIM_API =		0x1006,
+	SIM_APP_TYPE_CONTACT_MGR =	0x1007
+};
+
 enum ber_tlv_data_type {
 	BER_TLV_DATA_TYPE_UNIVERSAL =		0,
 	BER_TLV_DATA_TYPE_APPLICATION =		1,
@@ -296,6 +307,7 @@ struct sim_app_record {
 	unsigned char aid[16];
 	int aid_len;
 	char *label;
+	enum sim_app_type type;
 };
 
 struct simple_tlv_iter {
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 02/11] simutil: Added authenticate builder/parser API
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-11 15:30   ` Denis Kenzior
  2017-10-10 21:36 ` [PATCHv2 03/11] unit: add gsm and umts parse/build unit tests James Prestwood
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3855 bytes --]

Used to compose/parse non-TLV formatted authenticate commands
for GSM and UMTS authentication.
---
 src/simutil.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/simutil.h |  14 +++++++
 2 files changed, 144 insertions(+)

diff --git a/src/simutil.c b/src/simutil.c
index f43c2c2..69783bd 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -1609,3 +1609,133 @@ error:
 
 	return NULL;
 }
+
+static int build_authenticate(unsigned char *buffer, const unsigned char *rand,
+		const unsigned char *autn)
+{
+	int pos = 0;
+
+	buffer[pos++] = 0x00;
+	buffer[pos++] = 0x88;
+	buffer[pos++] = 0x00;
+	buffer[pos++] = autn ? 0x81 : 0x80;
+	buffer[pos++] = autn ? 0x22 : 0x11;
+	buffer[pos++] = 0x10;
+	memcpy(buffer + pos, rand, 16);
+	pos += 16;
+
+	if (autn) {
+		buffer[pos++] = 0x10;
+		memcpy(buffer + pos, autn, 16);
+		pos += 16;
+		buffer[pos++] = 0x00;
+	}
+
+	return pos;
+}
+
+int sim_build_umts_authenticate(unsigned char *buffer, int len,
+		const unsigned char *rand, const unsigned char *autn)
+{
+	if (len < 40 || !rand || !autn)
+		return FALSE;
+
+	return build_authenticate(buffer, rand, autn);
+}
+
+int sim_build_gsm_authenticate(unsigned char *buffer, int len,
+		const unsigned char *rand)
+{
+	if (len < 22 || !rand)
+		return FALSE;
+
+	return build_authenticate(buffer, rand, NULL);
+}
+
+#include <stdio.h>
+
+gboolean sim_parse_umts_authenticate(const unsigned char *buffer,
+		int len, const unsigned char **res, const unsigned char **ck,
+		const unsigned char **ik, const unsigned char **auts,
+		const unsigned char **kc)
+{
+	if (len < 18 || !buffer)
+		return FALSE;
+
+	switch (buffer[0]) {
+	case 0xdb:
+		/* 'DB' + '08' + RES(16) + '10' + CK(32) + '10' + IK(32) = 43 */
+		if (len < 43)
+			goto umts_end;
+
+		/* success */
+		if (buffer[1] != 0x08)
+			goto umts_end;
+
+		*res = buffer + 2;
+
+		if (buffer[10] != 0x10)
+			goto umts_end;
+
+		*ck = buffer + 11;
+
+		if (buffer[27] != 0x10)
+			goto umts_end;
+
+		*ik = buffer + 28;
+
+		if (len >= 53 && kc) {
+			if (buffer[44] != 0x08)
+				goto umts_end;
+
+			*kc = buffer + 45;
+		} else {
+			*kc = NULL;
+		}
+
+		*auts = NULL;
+
+		break;
+	case 0xdc:
+		/* 'DB' + '10' + AUTS(16) = 18 */
+		if (len < 18)
+			goto umts_end;
+
+		/* sync error */
+		if (buffer[1] != 0x10)
+			goto umts_end;
+
+		*auts = buffer + 2;
+
+		break;
+	default:
+		goto umts_end;
+	}
+
+	return TRUE;
+
+umts_end:
+	return FALSE;
+}
+
+gboolean sim_parse_gsm_authenticate(const unsigned char *buffer, int len,
+		const unsigned char **sres, const unsigned char **kc)
+{
+	if (len < 14 || !buffer)
+		goto gsm_end;
+
+	if (buffer[0] != 0x04)
+		goto gsm_end;
+
+	*sres = buffer + 1;
+
+	if (buffer[5] != 0x08)
+		goto gsm_end;
+
+	*kc = buffer + 6;
+
+	return TRUE;
+
+gsm_end:
+	return FALSE;
+}
diff --git a/src/simutil.h b/src/simutil.h
index 9984b2c..ece5145 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -507,3 +507,17 @@ gboolean sim_cphs_is_active(unsigned char *service_cphs,
 				enum sim_cphs_service index);
 
 GSList *sim_parse_app_template_entries(const unsigned char *buffer, int len);
+
+int sim_build_umts_authenticate(unsigned char *buffer, int len,
+		const unsigned char *rand, const unsigned char *autn);
+
+int sim_build_gsm_authenticate(unsigned char *buffer, int len,
+		const unsigned char *rand);
+
+gboolean sim_parse_umts_authenticate(const unsigned char *buffer,
+		int len, const unsigned char **res, const unsigned char **ck,
+		const unsigned char **ik, const unsigned char **auts,
+		const unsigned char **kc);
+
+gboolean sim_parse_gsm_authenticate(const unsigned char *buffer, int len,
+		const unsigned char **sres, const unsigned char **kc);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 03/11] unit: add gsm and umts parse/build unit tests
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
  2017-10-10 21:36 ` [PATCHv2 02/11] simutil: Added authenticate builder/parser API James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-10 21:36 ` [PATCHv2 04/11] sim: new API to check for a UST service only James Prestwood
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4910 bytes --]

---
 unit/test-simutil.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 105 insertions(+)

diff --git a/unit/test-simutil.c b/unit/test-simutil.c
index 490e288..b45ae41 100644
--- a/unit/test-simutil.c
+++ b/unit/test-simutil.c
@@ -496,6 +496,110 @@ static void test_get_2g_path(void)
 	g_assert(!memcmp(path, path1, len));
 }
 
+static void test_auth_build_parse(void)
+{
+	unsigned char auth_cmd[40];
+	const unsigned char rand[16] = { 0x00, 0x01, 0x02, 0x03, 0x04,0x05,
+			0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
+			0x0e, 0x0f };
+	const unsigned char sres[4] = { 0x00, 0x11, 0x22, 0x33 };
+	const unsigned char *sres_p;
+	const unsigned char kc[8] = { 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56,
+			0x78, 0x9a };
+	const unsigned char *kc_p;
+	const unsigned char gsm_success[] = { 0x04, 0x00, 0x11, 0x22, 0x33,
+			0x08,0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x9a };
+	const unsigned char autn[16] = { 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a,
+			0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02,
+			0x01, 0x00 };
+	const unsigned char res[8] = { 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa,
+			0x11, 0x22 };
+	const unsigned char *res_p;
+	const unsigned char ck[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
+			0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
+	const unsigned char *ck_p;
+	const unsigned char ik[16] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd,
+			0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
+	const unsigned char *ik_p;
+	const unsigned char auts[16] = { 0xde, 0xea, 0xbe, 0xef, 0xde, 0xea,
+			0xbe, 0xef, 0xde, 0xea, 0xbe, 0xef, 0xde, 0xea,
+			0xbe, 0xef };
+	const unsigned char *auts_p;
+
+	const unsigned char umts_success[] = { 0xdb, 0x08, 0xff, 0xee, 0xdd,
+			0xcc, 0xbb, 0xaa, 0x11, 0x22, 0x10, 0x00, 0x11, 0x22,
+			0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
+			0xcc, 0xdd, 0xee, 0xff, 0x10, 0x01, 0x23, 0x45, 0x67,
+			0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76,
+			0x54, 0x32, 0x10 };
+	const unsigned char umts_success_kc[] = { 0xdb, 0x08, 0xff, 0xee, 0xdd,
+			0xcc, 0xbb, 0xaa, 0x11, 0x22, 0x10, 0x00, 0x11, 0x22,
+			0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
+			0xcc, 0xdd, 0xee, 0xff, 0x10, 0x01, 0x23, 0x45, 0x67,
+			0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76,
+			0x54, 0x32, 0x10, 0x08, 0xab, 0xcd, 0xef, 0x12, 0x34,
+			0x56, 0x78, 0x9a };
+	const unsigned char umts_sync_failure[] = { 0xdc, 0x10, 0xde, 0xea,
+			0xbe, 0xef, 0xde, 0xea, 0xbe, 0xef, 0xde, 0xea, 0xbe,
+			0xef, 0xde, 0xea, 0xbe, 0xef };
+	int len = 0;
+
+	/* test GSM auth command */
+	len = sim_build_gsm_authenticate(auth_cmd, 40, rand);
+
+	g_assert(len == 22);
+	g_assert(auth_cmd[0] == 0x00);
+	g_assert(auth_cmd[1] == 0x88);
+	g_assert(auth_cmd[2] == 0x00);
+	g_assert(auth_cmd[3] == 0x80);
+	g_assert(auth_cmd[4] == 0x11);
+	g_assert(auth_cmd[5] == 0x10);
+	g_assert(!memcmp(auth_cmd + 6, rand, 16));
+
+	/* test UMTS auth command */
+	len = sim_build_umts_authenticate(auth_cmd, 40, rand, autn);
+
+	g_assert(len == 40);
+	g_assert(auth_cmd[0] == 0x00);
+	g_assert(auth_cmd[1] == 0x88);
+	g_assert(auth_cmd[2] == 0x00);
+	g_assert(auth_cmd[3] == 0x81);
+	g_assert(auth_cmd[4] == 0x22);
+	g_assert(auth_cmd[5] == 0x10);
+	g_assert(!memcmp(auth_cmd + 6, rand, 16));
+	g_assert(auth_cmd[22] == 0x10);
+	g_assert(!memcmp(auth_cmd + 23, autn, 16));
+
+	/* test GSM parse */
+	g_assert(sim_parse_gsm_authenticate(gsm_success, sizeof(gsm_success),
+			&sres_p, &kc_p));
+	g_assert(!memcmp(sres_p, sres, 4));
+	g_assert(!memcmp(kc_p, kc, 8));
+
+	/* test UMTS success parse, no kc */
+	g_assert(sim_parse_umts_authenticate(umts_success, sizeof(umts_success),
+			&res_p, &ck_p, &ik_p, &auts_p, &kc_p));
+	g_assert(!memcmp(res_p, res, 8));
+	g_assert(!memcmp(ck_p, ck, 16));
+	g_assert(!memcmp(ik_p, ik, 16));
+	g_assert(!auts_p && !kc_p);
+
+	/* test UMTS sync failure */
+	g_assert(sim_parse_umts_authenticate(umts_sync_failure, sizeof(umts_sync_failure),
+			&res_p, &ck_p, &ik_p, &auts_p, &kc_p));
+	g_assert(!memcmp(auts_p, auts, 16));
+
+	/* test UMTS success parse, with kc */
+	g_assert(sim_parse_umts_authenticate(umts_success_kc, sizeof(umts_success_kc),
+			&res_p, &ck_p, &ik_p, &auts_p, &kc_p));
+	g_assert(!memcmp(res_p, res, 8));
+	g_assert(!memcmp(ck_p, ck, 16));
+	g_assert(!memcmp(ik_p, ik, 16));
+	g_assert(!memcmp(kc_p, kc, 8));
+	g_assert(!auts_p);
+
+}
+
 int main(int argc, char **argv)
 {
 	g_test_init(&argc, &argv, NULL);
@@ -514,6 +618,7 @@ int main(int argc, char **argv)
 			test_application_entry_decode);
 	g_test_add_func("/testsimutil/3G path", test_get_3g_path);
 	g_test_add_func("/testsimutil/2G path", test_get_2g_path);
+	g_test_add_func("/testsimutil/auth build parse", test_auth_build_parse);
 
 	return g_test_run();
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 04/11] sim: new API to check for a UST service only
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
  2017-10-10 21:36 ` [PATCHv2 02/11] simutil: Added authenticate builder/parser API James Prestwood
  2017-10-10 21:36 ` [PATCHv2 03/11] unit: add gsm and umts parse/build unit tests James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-11 15:34   ` Denis Kenzior
  2017-10-10 21:36 ` [PATCHv2 05/11] sim-auth: prep simauth/dbus headers James Prestwood
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1486 bytes --]

The existing service check API takes both SST and UST services
and could inadvertently return success on a service if one
(SST or UST) service did not exist. This adds an API specifically
for checking for a UST service, and if the UST dir is not available
it will return FALSE, rather than possibly returning true on some
other SST service.
---
 src/ofono.h | 2 ++
 src/sim.c   | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/src/ofono.h b/src/ofono.h
index a797b7f..08de17e 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -369,6 +369,8 @@ unsigned short __ofono_sms_get_next_ref(struct ofono_sms *sms);
 
 #include <ofono/sim.h>
 
+ofono_bool_t __ofono_sim_ust_service_available(struct ofono_sim *sim,
+						int ust_service);
 ofono_bool_t __ofono_sim_service_available(struct ofono_sim *sim,
 						int ust_service,
 						int sst_service);
diff --git a/src/sim.c b/src/sim.c
index ac5b6fd..88c0421 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -2289,6 +2289,15 @@ const unsigned char *ofono_sim_get_cphs_service_table(struct ofono_sim *sim)
 	return sim->cphs_service_table;
 }
 
+ofono_bool_t __ofono_sim_ust_service_available(struct ofono_sim *sim,
+						int ust_service)
+{
+	if (sim->efust)
+		return sim_ust_is_available(sim->efust, sim->efust_length,
+						ust_service);
+	return FALSE;
+}
+
 ofono_bool_t __ofono_sim_service_available(struct ofono_sim *sim,
 						int ust_service,
 						int sst_service)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 05/11] sim-auth: prep simauth/dbus headers
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (2 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 04/11] sim: new API to check for a UST service only James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-11 15:39   ` Denis Kenzior
  2017-10-10 21:36 ` [PATCHv2 06/11] sim-auth: implementation of core sim-auth atom James Prestwood
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2829 bytes --]

Added new dbus interfaces for SimAuth module as well as
function prototype definitions to simauth header.

org.ofono.SimAuthentication:
   Interface to hold the auth object to type mapping property

org.ofono.USimApplication:
   Application with USim functionality (GSM/UMTS auth)

org.ofono.ISimApplication:
   Application with ISim functionality (IMS auth)
---
 include/dbus.h     |  3 +++
 include/sim-auth.h | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/include/dbus.h b/include/dbus.h
index a6519c7..b7d5d39 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -58,6 +58,9 @@ extern "C" {
 #define OFONO_LOCATION_REPORTING_INTERFACE OFONO_SERVICE ".LocationReporting"
 #define OFONO_GNSS_INTERFACE "org.ofono.AssistedSatelliteNavigation"
 #define OFONO_GNSS_POSR_AGENT_INTERFACE "org.ofono.PositioningRequestAgent"
+#define OFONO_USIM_APPLICATION_INTERFACE "org.ofono.USimApplication"
+#define OFONO_ISIM_APPLICATION_INTERFACE "org.ofono.ISimApplication"
+#define OFONO_SIM_AUTHENTICATION_INTERFACE "org.ofono.SimAuthentication"
 #define OFONO_HANDSFREE_INTERFACE OFONO_SERVICE ".Handsfree"
 #define OFONO_SIRI_INTERFACE OFONO_SERVICE ".Siri"
 #define OFONO_NETMON_INTERFACE OFONO_SERVICE ".NetworkMonitor"
diff --git a/include/sim-auth.h b/include/sim-auth.h
index 0a62adc..387a487 100644
--- a/include/sim-auth.h
+++ b/include/sim-auth.h
@@ -26,6 +26,8 @@
 extern "C" {
 #endif
 
+#include <stdint.h>
+
 #include <ofono/types.h>
 
 struct ofono_sim_auth;
@@ -34,6 +36,13 @@ typedef void (*ofono_sim_list_apps_cb_t)(const struct ofono_error *error,
 					const unsigned char *dataobj,
 					int len, void *data);
 
+typedef void (*ofono_sim_open_channel_cb_t)(int session_id, void *data);
+
+typedef void (*ofono_sim_close_channel_cb_t)(uint8_t success, void *data);
+
+typedef void (*ofono_logical_access_cb_t)(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,
@@ -41,7 +50,15 @@ struct ofono_sim_auth_driver {
 	void (*remove)(struct ofono_sim_auth *sa);
 
 	void (*list_apps)(struct ofono_sim_auth *sa,
-				ofono_sim_list_apps_cb_t cb, void *data);
+			ofono_sim_list_apps_cb_t cb, void *data);
+	void (*open_channel)(struct ofono_sim_auth *sa,
+			ofono_sim_open_channel_cb_t cb,
+			const void *channel, 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,
+			ofono_logical_access_cb_t cb, int session_id,
+			const uint8_t *pdu, uint16_t len, void *data);
 };
 
 int ofono_sim_auth_driver_register(const struct ofono_sim_auth_driver *d);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 06/11] sim-auth: implementation of core sim-auth atom
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (3 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 05/11] sim-auth: prep simauth/dbus headers James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-10 21:36 ` [PATCHv2 07/11] atmodem: implemented sim-auth functionality in atmodem James Prestwood
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 16982 bytes --]

The sim-auth module atom can now be used for SIM application discovery
and authentication. The atom will automatically discover SIM
applications available on the SIM and register a new DBus object under
the modem, whos name is the AID string e.g.

/modem1/A0000000871004FFFFFFFF8906190000

A list of discovered AID object paths and types can be found under the
modems (new) org.ofono.SimAuthentication interface "applications"
property in the format:

"a{o(ss)}" where

o = path (e.g. above)
s = type (Umts, Ims)
s = name (USim, ISim etc.)

The type signifies which interfaces the AID object will have:

Umts = org.ofono.USimApplication
Ims = org.ofono.ISimApplication

These interfaces will contain the supported USIM/ISIM authentication
algorithms. Where:

org.ofono.USimApplication has:
    GsmAuthenticate()
    UmtsAuthenticate()

org.ofono.ISimApplication has:
    ImsAuthenticate()
---
 src/sim-auth.c | 543 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 543 insertions(+)

diff --git a/src/sim-auth.c b/src/sim-auth.c
index 5d2f075..febdf06 100644
--- a/src/sim-auth.c
+++ b/src/sim-auth.c
@@ -28,19 +28,102 @@
 #include <glib.h>
 #include <errno.h>
 #include <unistd.h>
+#include <gdbus.h>
+#include <string.h>
+#include <stdio.h>
 
 #include "ofono.h"
 
 #include "simutil.h"
+#include "util.h"
+
+#define SIM_AUTH_MAX_RANDS	3
 
 static GSList *g_drivers = NULL;
 
+/*
+ * Temporary handle used for the command authentication sequence.
+ */
+struct auth_request {
+	/* DBus values for GSM authentication */
+	DBusMessage *msg;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	/* ID from open_channel */
+	int session_id;
+	/* list of rands to calculate key (1 if umts == 1) */
+	void *rands[SIM_AUTH_MAX_RANDS];
+	int num_rands;
+	/* number of keys that have been returned */
+	int cb_count;
+	void *autn;
+	uint8_t umts : 1;
+};
+
 struct ofono_sim_auth {
 	const struct ofono_sim_auth_driver *driver;
 	void *driver_data;
 	struct ofono_atom *atom;
+	GSList *aid_list;
+	struct ofono_sim *sim;
+	uint8_t gsm_access : 1;
+	uint8_t gsm_context : 1;
+	struct auth_request *pending;
 };
 
+/*
+ * Find an AID channel by the type of application
+ */
+static struct sim_app_record *find_channel(GSList *aid_list,
+		enum sim_app_type type)
+{
+	GSList *iter = aid_list;
+
+	while (iter) {
+		struct sim_app_record *app = iter->data;
+
+		if (app->type == type)
+			return app;
+
+		iter = g_slist_next(iter);
+	}
+
+	return NULL;
+}
+
+/*
+ * Free all discovered AID's
+ */
+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;
+
+
+	while (iter) {
+		struct sim_app_record *app = iter->data;
+
+		if (app->type == SIM_APP_TYPE_USIM) {
+			g_dbus_unregister_interface(conn, path,
+					OFONO_USIM_APPLICATION_INTERFACE);
+			ofono_modem_remove_interface(modem,
+					OFONO_USIM_APPLICATION_INTERFACE);
+		} else if (app->type == SIM_APP_TYPE_ISIM) {
+			g_dbus_unregister_interface(conn, path,
+					OFONO_ISIM_APPLICATION_INTERFACE);
+			ofono_modem_remove_interface(modem,
+					OFONO_USIM_APPLICATION_INTERFACE);
+		}
+
+		iter = g_slist_next(iter);
+	}
+
+	g_slist_free(sa->aid_list);
+}
+
 int ofono_sim_auth_driver_register(const struct ofono_sim_auth_driver *d)
 {
 	DBG("driver: %p, name: %s", d, d->name);
@@ -62,6 +145,9 @@ void ofono_sim_auth_driver_unregister(const struct ofono_sim_auth_driver *d)
 
 static void sim_auth_unregister(struct ofono_atom *atom)
 {
+	struct ofono_sim_auth *sa = __ofono_atom_get_data(atom);
+
+	free_apps(sa);
 }
 
 static void sim_auth_remove(struct ofono_atom *atom)
@@ -113,9 +199,466 @@ struct ofono_sim_auth *ofono_sim_auth_create(struct ofono_modem *modem,
 	return sa;
 }
 
+/*
+ * appends {o(ss)} into an existing dict array
+ */
+static void append_dict_application(DBusMessageIter *iter, const char *path,
+		const char *type, const char *name)
+{
+	DBusMessageIter keyiter;
+	DBusMessageIter variant;
+	DBusMessageIter struct1;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
+			&keyiter);
+	dbus_message_iter_append_basic(&keyiter, DBUS_TYPE_OBJECT_PATH, &path);
+	dbus_message_iter_open_container(&keyiter, DBUS_TYPE_VARIANT, "(ss)",
+			&variant);
+	dbus_message_iter_open_container(&variant, DBUS_TYPE_STRUCT, NULL,
+			&struct1);
+	dbus_message_iter_append_basic(&struct1, DBUS_TYPE_STRING, &type);
+	dbus_message_iter_append_basic(&struct1, DBUS_TYPE_STRING, &name);
+	dbus_message_iter_close_container(&variant, &struct1);
+	dbus_message_iter_close_container(&keyiter, &variant);
+	dbus_message_iter_close_container(iter, &keyiter);
+}
+
+/*
+ * appends {say} onto an existing dict array
+ */
+static void append_dict_byte_array(DBusMessageIter *iter, const char *key,
+		const void *arr, uint32_t len)
+{
+	DBusMessageIter keyiter;
+	DBusMessageIter valueiter;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_DICT_ENTRY, NULL,
+			&keyiter);
+	dbus_message_iter_append_basic(&keyiter, DBUS_TYPE_STRING, &key);
+	dbus_message_iter_open_container(&keyiter, DBUS_TYPE_ARRAY,
+			"y", &valueiter);
+	dbus_message_iter_append_fixed_array(&valueiter, DBUS_TYPE_BYTE, &arr,
+			len);
+	dbus_message_iter_close_container(&keyiter, &valueiter);
+	dbus_message_iter_close_container(iter, &keyiter);
+}
+
+static void handle_umts(struct ofono_sim_auth *sim, const uint8_t *resp,
+		uint16_t len)
+{
+	DBusMessage *reply = NULL;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+	const uint8_t *res = NULL;
+	const uint8_t *ck = NULL;
+	const uint8_t *ik = NULL;
+	const uint8_t *auts = NULL;
+	const uint8_t *kc = NULL;
+
+	if (!sim_parse_umts_authenticate(resp, len, &res, &ck, &ik,
+			&auts, &kc))
+		goto umts_end;
+
+	reply = dbus_message_new_method_return(sim->pending->msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+			"{say}", &dict);
+
+	if (auts) {
+		append_dict_byte_array(&dict, "auts", auts, 16);
+	} else {
+		append_dict_byte_array(&dict, "res", res, 8);
+		append_dict_byte_array(&dict, "ck", ck, 16);
+		append_dict_byte_array(&dict, "ik", ik, 16);
+		if (kc)
+			append_dict_byte_array(&dict, "kc", kc, 8);
+	}
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+umts_end:
+	if (!reply)
+		reply = __ofono_error_not_supported(sim->pending->msg);
+
+	__ofono_dbus_pending_reply(&sim->pending->msg, reply);
+
+	sim->driver->close_channel(sim, sim->pending->session_id, NULL, NULL);
+
+	g_free(sim->pending);
+	sim->pending = NULL;
+}
+
+static void handle_gsm(struct ofono_sim_auth *sim, const uint8_t *resp,
+		uint16_t len)
+{
+	const uint8_t *sres = NULL;
+	const uint8_t *kc = NULL;
+
+	if (!sim_parse_gsm_authenticate(resp, len, &sres, &kc))
+		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);
+
+		dbus_message_iter_init_append(sim->pending->reply,
+				&sim->pending->iter);
+
+		dbus_message_iter_open_container(&sim->pending->iter,
+				DBUS_TYPE_ARRAY, "{say}", &sim->pending->dict);
+	}
+
+	/* append the Nth sres/kc byte arrays */
+	append_dict_byte_array(&sim->pending->dict, "sres", sres, 4);
+	append_dict_byte_array(&sim->pending->dict, "kc", kc, 8);
+
+	sim->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);
+		goto gsm_end;
+	}
+
+	return;
+
+gsm_end:
+	if (!sim->pending->reply)
+		sim->pending->reply = __ofono_error_not_supported(
+				sim->pending->msg);
+
+	__ofono_dbus_pending_reply(&sim->pending->msg, sim->pending->reply);
+
+	sim->driver->close_channel(sim, sim->pending->session_id, NULL, NULL);
+
+	g_free(sim->pending);
+
+	sim->pending = NULL;
+}
+
+static void logical_access_cb(const uint8_t *resp, uint16_t len, void *data)
+{
+	struct ofono_sim_auth *sim = data;
+
+	if (sim->pending->umts)
+		handle_umts(sim, resp, len);
+	else
+		handle_gsm(sim, resp, len);
+}
+
+static void open_channel_cb(int session_id, void *data)
+{
+	struct ofono_sim_auth *sim = data;
+	int i;
+
+	if (session_id == -1)
+		goto error;
+
+	/* save session ID for close_channel() */
+	sim->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++) {
+		uint8_t auth_cmd[40];
+		int len = 0;
+
+		if (sim->pending->umts)
+			len = sim_build_umts_authenticate(auth_cmd, 40,
+					sim->pending->rands[i],
+					sim->pending->autn);
+		else
+			len = sim_build_gsm_authenticate(auth_cmd, 40,
+					sim->pending->rands[i]);
+
+		if (!len)
+			goto error;
+
+		sim->driver->logical_access(sim, logical_access_cb, session_id,
+				auth_cmd, len, sim);
+	}
+
+	return;
+
+error:
+	__ofono_dbus_pending_reply(&sim->pending->msg,
+			__ofono_error_failed(sim->pending->msg));
+	g_free(sim->pending);
+	sim->pending = NULL;
+}
+
+static DBusMessage *usim_gsm_authenticate(DBusConnection *conn,
+		DBusMessage *msg, void *data)
+{
+	struct ofono_sim_auth *sim = data;
+	DBusMessageIter iter;
+	DBusMessageIter array;
+	int i;
+	struct sim_app_record *app;
+
+	if (sim->pending)
+		return __ofono_error_busy(msg);
+
+	dbus_message_iter_init(msg, &iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return __ofono_error_not_supported(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 = dbus_message_iter_get_element_count(&iter);
+
+	dbus_message_iter_recurse(&iter, &array);
+
+	for (i = 0; i < sim->pending->num_rands; i++) {
+		int nelement;
+		DBusMessageIter in;
+
+		dbus_message_iter_recurse(&array, &in);
+
+		dbus_message_iter_get_fixed_array(&in, &sim->pending->rands[i],
+				&nelement);
+	}
+
+	app = find_channel(sim->aid_list, SIM_APP_TYPE_USIM);
+
+	if (app) {
+		sim->driver->open_channel(sim, open_channel_cb, app->aid, sim);
+	} else {
+		dbus_message_unref(sim->pending->msg);
+		g_free(sim->pending);
+		sim->pending = NULL;
+		return __ofono_error_not_supported(msg);
+	}
+
+	return NULL;
+}
+
+static DBusMessage *umts_common(DBusConnection *conn, DBusMessage *msg,
+					void *data, enum sim_app_type type)
+{
+	uint8_t *rand = NULL;
+	uint8_t *autn = NULL;
+	uint32_t rlen;
+	uint32_t alen;
+	struct ofono_sim_auth *sim = data;
+	struct sim_app_record *app;
+
+	if (sim->pending)
+		return __ofono_error_busy(msg);
+
+	/* get RAND/AUTN and setup handle args */
+	dbus_message_get_args(msg, NULL, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_BYTE, &rand, &rlen, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_BYTE, &autn, &alen,
+			DBUS_TYPE_INVALID);
+
+	sim->pending = malloc(sizeof(struct auth_request));
+	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;
+
+	app = find_channel(sim->aid_list, type);
+
+	if (app) {
+		sim->driver->open_channel(sim, open_channel_cb, app->aid, sim);
+	} else {
+		dbus_message_unref(sim->pending->msg);
+		g_free(sim->pending);
+		sim->pending = NULL;
+		return __ofono_error_not_supported(msg);
+	}
+
+	return NULL;
+}
+
+static DBusMessage *get_properties(DBusConnection *conn,
+		DBusMessage *msg, void *data)
+{
+	struct ofono_sim_auth *sim = data;
+	const char *path = __ofono_atom_get_path(sim->atom);
+	struct sim_app_record *app;
+	int ret;
+	char object[strlen(path) + 33];
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	DBusMessageIter dict;
+
+	if (!sim->aid_list)
+		return __ofono_error_busy(msg);
+
+	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, "{ov}", &dict);
+
+	app = find_channel(sim->aid_list, SIM_APP_TYPE_ISIM);
+
+	if (app) {
+		ret = sprintf(object, "%s/", path);
+		encode_hex_own_buf(app->aid, 16, 0, object + ret);
+
+		append_dict_application(&dict, object, "Ims", "ISim");
+	}
+
+	app = find_channel(sim->aid_list, SIM_APP_TYPE_USIM);
+
+	if (app) {
+		ret = sprintf(object, "%s/", path);
+		encode_hex_own_buf(app->aid, 16, 0, object + ret);
+
+		append_dict_application(&dict, object, "Umts", "USim");
+	}
+
+	dbus_message_iter_close_container(&iter, &dict);
+
+	return reply;
+}
+
+static DBusMessage *isim_ims_authenticate(DBusConnection *conn,
+		DBusMessage *msg, void *data)
+{
+	return umts_common(conn, msg, data, SIM_APP_TYPE_ISIM);
+}
+
+static DBusMessage *usim_umts_authenticate(DBusConnection *conn,
+		DBusMessage *msg, void *data)
+{
+	return umts_common(conn, msg, data, SIM_APP_TYPE_USIM);
+}
+
+static const GDBusMethodTable sim_authentication[] = {
+	{ GDBUS_METHOD("GetProperties",
+			NULL,
+			GDBUS_ARGS({"properties", "a{sv}"}),
+			get_properties) },
+	{ }
+};
+
+static const GDBusMethodTable sim_auth_usim_app[] = {
+	{ GDBUS_ASYNC_METHOD("GsmAuthenticate",
+			GDBUS_ARGS({"rands", "aay"}),
+			GDBUS_ARGS({"keys", "a{say}"}),
+			usim_gsm_authenticate) },
+	{ GDBUS_ASYNC_METHOD("UmtsAuthenticate",
+			GDBUS_ARGS({"rand", "ay"}, {"autn", "ay"}),
+			GDBUS_ARGS({"return", "a{sv}"}),
+			usim_umts_authenticate) },
+	{ }
+};
+
+static const GDBusMethodTable sim_auth_isim_app[] = {
+	{ GDBUS_ASYNC_METHOD("ImsAuthenticate",
+			GDBUS_ARGS({"rand", "ay"}, {"autn", "ay"}),
+			GDBUS_ARGS({"return", "a{sv}"}),
+			isim_ims_authenticate) },
+	{ }
+};
+
+static void discover_apps_cb(const struct ofono_error *error,
+		const unsigned char *dataobj,
+		int len, void *data)
+{
+	DBusConnection *conn = ofono_dbus_get_connection();
+	struct ofono_sim_auth *sim = data;
+	const char *path = __ofono_atom_get_path(sim->atom);
+	GSList *iter;
+	char app_path[strlen(path) + 34];
+	int ret;
+
+	sim->aid_list = sim_parse_app_template_entries(dataobj, len);
+
+	if (!sim->aid_list)
+		goto parse_error;
+
+	iter = sim->aid_list;
+
+	ret = sprintf(app_path, "%s/", path);
+
+	while (iter) {
+		struct sim_app_record *app = iter->data;
+
+		switch (app->type) {
+		case SIM_APP_TYPE_USIM:
+			encode_hex_own_buf(app->aid, 16, 0, app_path + ret);
+
+			app_path[ret + 32] = '\0';
+
+			g_dbus_register_interface(conn, app_path,
+					OFONO_USIM_APPLICATION_INTERFACE,
+					sim_auth_usim_app, NULL, NULL,
+					sim, NULL);
+			break;
+		case SIM_APP_TYPE_ISIM:
+			encode_hex_own_buf(app->aid, 16, 0, app_path + ret);
+
+			app_path[ret + 32] = '\0';
+
+			g_dbus_register_interface(conn, app_path,
+					OFONO_ISIM_APPLICATION_INTERFACE,
+					sim_auth_isim_app, NULL, NULL,
+					sim, NULL);
+			break;
+		default:
+			DBG("Unknown SIM application '%04x'", app->type);
+			/*
+			 * If we get here, the SIM application was not ISIM
+			 * or USIM, skip.
+			 */
+		}
+
+		iter = g_slist_next(iter);
+	}
+
+	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)
 {
+	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);
+
+	ofono_modem_add_interface(modem, OFONO_PHONEBOOK_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);
+
+	sa->sim = __ofono_atom_find(OFONO_ATOM_TYPE_SIM, modem);
+
+	sa->gsm_access = __ofono_sim_ust_service_available(sa->sim,
+			SIM_UST_SERVICE_GSM_ACCESS);
+	sa->gsm_context = __ofono_sim_ust_service_available(sa->sim,
+			SIM_UST_SERVICE_GSM_SECURITY_CONTEXT);
+
+	g_dbus_register_interface(conn, path,
+			OFONO_SIM_AUTHENTICATION_INTERFACE,
+			sim_authentication, NULL, NULL,
+			sa, NULL);
+	ofono_modem_add_interface(modem,
+			OFONO_SIM_AUTHENTICATION_INTERFACE);
 }
 
 void ofono_sim_auth_remove(struct ofono_sim_auth *sa)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 07/11] atmodem: implemented sim-auth functionality in atmodem
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (4 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 06/11] sim-auth: implementation of core sim-auth atom James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-10 21:36 ` [PATCHv2 08/11] xmm7xxx: add sim-auth driver to xmm7xxx plugin James Prestwood
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4693 bytes --]

Implemented the core API's needed for sim-auth:

list_apps: already implemented
open_channel: Opens a logical channel with +CCHO
close_channel: Closes logical channel with +CCHC
logical_access: Access an opened channel with +CGLA
---
 drivers/atmodem/sim-auth.c | 141 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 141 insertions(+)

diff --git a/drivers/atmodem/sim-auth.c b/drivers/atmodem/sim-auth.c
index 271ceed..1cb6f86 100644
--- a/drivers/atmodem/sim-auth.c
+++ b/drivers/atmodem/sim-auth.c
@@ -25,6 +25,7 @@
 
 #define _GNU_SOURCE
 #include <string.h>
+#include <stdio.h>
 
 #include <glib.h>
 
@@ -35,6 +36,7 @@
 #include "gatresult.h"
 #include "simutil.h"
 #include "vendor.h"
+#include "util.h"
 
 #include "atmodem.h"
 
@@ -44,6 +46,8 @@ struct sim_auth_data {
 };
 
 static const char *cuad_prefix[] = { "+CUAD:", NULL };
+static const char *ccho_prefix[] = { "+CCHO:", NULL };
+static const char *cgla_prefix[] = { "+CGLA:", NULL };
 
 static void at_discover_apps_cb(gboolean ok, GAtResult *result,
 				gpointer user_data)
@@ -110,6 +114,140 @@ static void at_discover_apps(struct ofono_sim_auth *sa,
 	CALLBACK_WITH_FAILURE(cb, NULL, 0, data);
 }
 
+static void at_open_channel_cb(gboolean ok, GAtResult *result,
+		gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	GAtResultIter iter;
+	ofono_sim_open_channel_cb_t cb = cbd->cb;
+	int session_id = -1;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+CCHO:"))
+		goto error;
+
+	if (!g_at_result_iter_next_number(&iter, &session_id))
+		goto error;
+
+	cb(session_id, cbd->data);
+
+	return;
+
+error:
+	cb(-1, cbd->data);
+}
+
+static void at_open_channel(struct ofono_sim_auth *sa,
+		ofono_sim_open_channel_cb_t cb, const void *channel,
+		void *data)
+{
+	struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char cmd[43];
+	int ret = 0;
+
+	strcpy(cmd, "AT+CCHO=\"");
+	ret += 9;
+
+	encode_hex_own_buf(channel, 16, 0, cmd + ret);
+	ret += 32;
+
+	strcpy(cmd + ret, "\"");
+
+	if (g_at_chat_send(sad->chat, cmd, ccho_prefix, at_open_channel_cb,
+			cbd, g_free) > 0)
+		return;
+
+	g_free(cbd);
+
+	cb(-1, data);
+}
+
+static void at_close_channel_cb(gboolean ok, GAtResult *result,
+		gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_sim_close_channel_cb_t cb = cbd->cb;
+
+	if (cb)
+		cb(ok, cbd->data);
+}
+
+static void at_close_channel(struct ofono_sim_auth *sa, int session_id,
+		ofono_sim_close_channel_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);
+	char cmd[15];
+
+	sprintf(cmd, "AT+CCHC=%d", session_id);
+
+	g_at_chat_send(sad->chat, cmd, NULL, at_close_channel_cb, cbd, g_free);
+}
+
+static void logical_access_cb(gboolean ok, GAtResult *result,
+		gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	ofono_logical_access_cb_t cb = cbd->cb;
+	const char *str_data;
+	uint8_t *raw;
+	gint len = 0;
+	GAtResultIter iter;
+
+	if (!ok)
+		goto error;
+
+	g_at_result_iter_init(&iter, result);
+
+	if (!g_at_result_iter_next(&iter, "+CGLA:"))
+		goto error;
+
+	if (!g_at_result_iter_next_number(&iter, &len))
+		goto error;
+
+	if (!g_at_result_iter_next_string(&iter, &str_data))
+		goto error;
+
+	raw = alloca(len / 2);
+
+	decode_hex_own_buf(str_data, len, NULL, 0, raw);
+
+	cb(raw, len / 2, cbd->data);
+
+	return;
+
+error:
+	cb(NULL, 0, cbd->data);
+}
+
+static void at_logical_access(struct ofono_sim_auth *sa,
+		ofono_logical_access_cb_t cb, int session_id,
+		const uint8_t *pdu, uint16_t len, void *data)
+
+{
+	struct sim_auth_data *sad = ofono_sim_auth_get_data(sa);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	int ret = 0;
+	char cmd[(len * 2) + 19];
+
+	ret = sprintf(cmd, "AT+CGLA=%d,%d,\"", session_id, len * 2);
+
+	encode_hex_own_buf(pdu, len, 0, cmd + ret);
+	ret += len * 2;
+
+	strcpy(cmd + ret, "\"");
+
+	if (g_at_chat_send(sad->chat, cmd, cgla_prefix, logical_access_cb,
+			cbd, g_free) > 0)
+		return;
+
+	g_free(cbd);
+
+	cb(NULL, 0, data);
+}
+
 static gboolean at_sim_auth_register(gpointer user)
 {
 	struct ofono_sim_auth *sa = user;
@@ -151,6 +289,9 @@ static struct ofono_sim_auth_driver driver = {
 	.probe		= at_sim_auth_probe,
 	.remove		= at_sim_auth_remove,
 	.list_apps	= at_discover_apps,
+	.open_channel	= at_open_channel,
+	.close_channel	= at_close_channel,
+	.logical_access = at_logical_access
 };
 
 void at_sim_auth_init(void)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 08/11] xmm7xxx: add sim-auth driver to xmm7xxx plugin
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (5 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 07/11] atmodem: implemented sim-auth functionality in atmodem James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-10 21:36 ` [PATCHv2 09/11] phonesim: Added sim-auth to phonesim plugin James Prestwood
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]

---
 plugins/xmm7xxx.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/plugins/xmm7xxx.c b/plugins/xmm7xxx.c
index 4443d4c..50ec3e3 100644
--- a/plugins/xmm7xxx.c
+++ b/plugins/xmm7xxx.c
@@ -48,6 +48,7 @@
 #include <ofono/gprs-context.h>
 #include <ofono/stk.h>
 #include <ofono/lte.h>
+#include <ofono/sim-auth.h>
 
 #include <drivers/atmodem/atutil.h>
 #include <drivers/atmodem/vendor.h>
@@ -60,6 +61,7 @@ struct xmm7xxx_data {
 	struct ofono_sim *sim;
 	ofono_bool_t have_sim;
 	ofono_bool_t sms_phonebook_added;
+	struct ofono_sim_auth *sim_auth;
 };
 
 static void xmm7xxx_debug(const char *str, void *user_data)
@@ -285,6 +287,7 @@ static void xmm7xxx_pre_sim(struct ofono_modem *modem)
 	ofono_devinfo_create(modem, OFONO_VENDOR_IFX, "atmodem", data->chat);
 	data->sim = ofono_sim_create(modem, OFONO_VENDOR_IFX, "atmodem",
 					data->chat);
+	data->sim_auth = ofono_sim_auth_create(modem, 0, "atmodem", data->chat);
 }
 
 static void set_online_cb(gboolean ok, GAtResult *result, gpointer user_data)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 09/11] phonesim: Added sim-auth to phonesim plugin
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (6 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 08/11] xmm7xxx: add sim-auth driver to xmm7xxx plugin James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-10 21:36 ` [PATCHv2 10/11] test: added tests for GSM/UMTS auth algorithms James Prestwood
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 977 bytes --]

---
 plugins/phonesim.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/plugins/phonesim.c b/plugins/phonesim.c
index 16bccd5..345c41e 100644
--- a/plugins/phonesim.c
+++ b/plugins/phonesim.c
@@ -61,6 +61,7 @@
 #include <ofono/gnss.h>
 #include <ofono/handsfree.h>
 #include <ofono/siri.h>
+#include <ofono/sim-auth.h>
 
 #include <drivers/atmodem/vendor.h>
 #include <drivers/atmodem/atutil.h>
@@ -84,6 +85,7 @@ struct phonesim_data {
 	unsigned int hfp_watch;
 	int batt_level;
 	struct ofono_sim *sim;
+	struct ofono_sim_auth *sim_auth;
 };
 
 struct gprs_context_data {
@@ -839,6 +841,8 @@ static void phonesim_pre_sim(struct ofono_modem *modem)
 		ofono_voicecall_create(modem, 0, "calypsomodem", data->chat);
 	else
 		ofono_voicecall_create(modem, 0, "atmodem", data->chat);
+
+	data->sim_auth = ofono_sim_auth_create(modem, 0, "atmodem", data->chat);
 }
 
 static void phonesim_post_sim(struct ofono_modem *modem)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 10/11] test: added tests for GSM/UMTS auth algorithms
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (7 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 09/11] phonesim: Added sim-auth to phonesim plugin James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-10 21:36 ` [PATCHv2 11/11] doc: documentation for SimAuth dbus interfaces James Prestwood
  2017-10-11 15:29 ` [PATCHv2 01/11] simutil: Added app type to application parser Denis Kenzior
  10 siblings, 0 replies; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2539 bytes --]

---
 test/run-isim-umts-auth | 38 ++++++++++++++++++++++++++++++++++++++
 test/run-usim-gsm-auth  | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)
 create mode 100755 test/run-isim-umts-auth
 create mode 100755 test/run-usim-gsm-auth

diff --git a/test/run-isim-umts-auth b/test/run-isim-umts-auth
new file mode 100755
index 0000000..b921085
--- /dev/null
+++ b/test/run-isim-umts-auth
@@ -0,0 +1,38 @@
+#!/usr/bin/python3
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+if len(sys.argv) == 4:
+	path = sys.argv[1]
+	rand = sys.argv[2]
+	autn = sys.argv[3]
+
+	sim_auth = dbus.Interface(bus.get_object('org.ofono', path),
+							'org.ofono.SimAuthentication')
+	props = sim_auth.GetProperties()
+	for i in props:
+		if props[i][0] == 'Ims':
+			ims_path = i
+
+	if not ims_path:
+		print("No Ims application found")
+		quit()
+
+	isim_auth = dbus.Interface(bus.get_object('org.ofono', ims_path),
+							'org.ofono.ISimApplication')
+	ret = isim_auth.ImsAuthenticate(bytearray.fromhex(rand),
+								bytearray.fromhex(autn))
+
+	if 'auts' in ret:
+		print('Sync Failure')
+		print('AUTS: ' + ''.join('%02x' % x for x in ret['auts']))
+	else:
+		print('Success')
+		print('RES: ' +  ''.join('%02x' % x for x in ret['res']))
+		print('CK: ' + ''.join('%02x' % x for x in ret['ck']))
+		print('IK: ' + ''.join('%02x' % x for x in ret['ik']))
+else:
+	print("./run-isim-umts-auth <modem> <rand> <autn>")
diff --git a/test/run-usim-gsm-auth b/test/run-usim-gsm-auth
new file mode 100755
index 0000000..1af2d7e
--- /dev/null
+++ b/test/run-usim-gsm-auth
@@ -0,0 +1,35 @@
+#!/usr/bin/python3
+
+import dbus
+import sys
+
+bus = dbus.SystemBus()
+
+if len(sys.argv) < 6 and len(sys.argv) > 2:
+	path = sys.argv[1]
+
+	rands = []
+	for i in sys.argv[2:]:
+		rands.append(bytearray.fromhex(i))
+
+	sim_auth = dbus.Interface(bus.get_object('org.ofono', path),
+							'org.ofono.SimAuthentication')
+	props = sim_auth.GetProperties()
+	for i in props:
+		if props[i][0] == 'Umts':
+			umts_path = i
+
+	if not umts_path:
+		print("No Umts application found")
+		quit()
+
+	umts = dbus.Interface(bus.get_object('org.ofono', umts_path),
+						'org.ofono.USimApplication')
+	av = umts.GsmAuthenticate(rands)
+
+	for i in av:
+		print('SRES: ' + ''.join('%02x' % x for x in i['sres']))
+		print('KC: ' + ''.join('%02x' % x for x in i['kc']))
+
+else:
+	print("./run-usim-gsm-auth <modem> <rands>...[up to 3]")
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCHv2 11/11] doc: documentation for SimAuth dbus interfaces
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (8 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 10/11] test: added tests for GSM/UMTS auth algorithms James Prestwood
@ 2017-10-10 21:36 ` James Prestwood
  2017-10-11 15:57   ` Denis Kenzior
  2017-10-11 15:29 ` [PATCHv2 01/11] simutil: Added app type to application parser Denis Kenzior
  10 siblings, 1 reply; 16+ messages in thread
From: James Prestwood @ 2017-10-10 21:36 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3079 bytes --]

---
 doc/sim-auth-api.txt | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 doc/sim-auth-api.txt

diff --git a/doc/sim-auth-api.txt b/doc/sim-auth-api.txt
new file mode 100644
index 0000000..089a325
--- /dev/null
+++ b/doc/sim-auth-api.txt
@@ -0,0 +1,78 @@
+SimAuth authentication heiarchy [experimental]
+===========================================
+
+Service		org.ofono
+Interface	org.ofono.SimAuthentication
+Object path	[variable prefix]/{modem0,modem1,...}
+
+Methods		array{object,dict} GetProperties()
+
+			Returns properties for SimAuthentication interface.
+
+Properties	array{object,dict} applications [readonly]
+
+			Array of all SIM applications found during discovery.
+			In the format "{o(ss)}" where 'o' is the object
+			path for the application, 's' is the type, and 's'
+			is the human readable name e.g.
+
+			o = "/modem1/A0000000871004FFFFFFFF8906190000"
+			s = "Ims"
+			s = "ISim"
+
+			For each application there will be a corresponding
+			object that matches the path (o). The type will
+			signify which interfaces are under that object (below).
+
+			type = Umts --> org.ofono.USimApplication
+			type = Ims  --> org.ofono.ISimApplication
+
+SimAuth USIM application heiarchy [experimental]
+===========================================
+
+Service		org.ofono
+Interface	org.ofono.USimApplication
+Object path	[variable prefix]/{modem0,modem1,...}/{AID name}
+
+Methods		array{string, dict} GsmAuthenticate(array{array{byte}} rands)
+
+			Run the USIM application GSM AUTHENTICATE algorithm
+			with N random challenges 'rands'. This should be an
+			array of an array of bytes ("aay").
+
+			Returns the derived Kc/SRES values as an array of
+			dictionaries. The index of each dictionary matches
+			the index of the rand value in the method call. The
+			keys for each dictionary are "kc" and "sres" and both
+			are arrays of bytes.
+
+			Possible Errors:
+				[service].Error.NotSupported
+				[service].Error.Busy
+
+		dict UmtsAuthenticate(array{byte} rand, array{byte} autn)
+
+			Run the UMTS AUTHENTICATE algorithm in the 3G
+			context with 'rand' and 'autn'. A dictionary will be
+			returned containing 'res', 'ck', 'ik' and possibly
+			'kc' if service 27 is available. If there was a
+			sync error 'auts' will be returned.
+
+			Possible Errors: [service].Error.NotSupported
+
+SimAuth ISIM application heiarchy [experimental]
+===========================================
+
+Service		org.ofono
+Interface	org.ofono.ISimApplication
+Object		[variable prefix]/{modem0,modem1,...}/{AID name}
+
+Methods		dict ImsAuthenticate(array{byte} rand, array{byte} autn)
+
+			Run the UMTS AUTHENTICATE algorithm in the IMS
+			context with 'rand' and 'autn'. A dictionary will be
+			returned containing 'res', 'ck', 'ik' and possibly
+			'kc' if service 27 is available. If there was a
+			sync error 'auts' will be returned.
+
+			Possible Errors: [service].Error.NotSupported
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCHv2 01/11] simutil: Added app type to application parser
  2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
                   ` (9 preceding siblings ...)
  2017-10-10 21:36 ` [PATCHv2 11/11] doc: documentation for SimAuth dbus interfaces James Prestwood
@ 2017-10-11 15:29 ` Denis Kenzior
  10 siblings, 0 replies; 16+ messages in thread
From: Denis Kenzior @ 2017-10-11 15:29 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 406 bytes --]

Hi James,

On 10/10/2017 04:36 PM, James Prestwood wrote:
> Parsing a SIM application only copied the 16 byte AID
> portion, which included the application type. Parsing out
> the type makes sorting much easier for modules using the
> parser.
> ---
>   src/simutil.c |  2 ++
>   src/simutil.h | 12 ++++++++++++
>   2 files changed, 14 insertions(+)
> 

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCHv2 02/11] simutil: Added authenticate builder/parser API
  2017-10-10 21:36 ` [PATCHv2 02/11] simutil: Added authenticate builder/parser API James Prestwood
@ 2017-10-11 15:30   ` Denis Kenzior
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Kenzior @ 2017-10-11 15:30 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 438 bytes --]

Hi James,

On 10/10/2017 04:36 PM, James Prestwood wrote:
> Used to compose/parse non-TLV formatted authenticate commands
> for GSM and UMTS authentication.
> ---
>   src/simutil.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   src/simutil.h |  14 +++++++
>   2 files changed, 144 insertions(+)
> 

<snip>

> +
> +#include <stdio.h>
> +

I silently took out this #include and applied this patch.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCHv2 04/11] sim: new API to check for a UST service only
  2017-10-10 21:36 ` [PATCHv2 04/11] sim: new API to check for a UST service only James Prestwood
@ 2017-10-11 15:34   ` Denis Kenzior
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Kenzior @ 2017-10-11 15:34 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

Hi James,

On 10/10/2017 04:36 PM, James Prestwood wrote:
> The existing service check API takes both SST and UST services
> and could inadvertently return success on a service if one
> (SST or UST) service did not exist. This adds an API specifically
> for checking for a UST service, and if the UST dir is not available
> it will return FALSE, rather than possibly returning true on some
> other SST service.
> ---
>   src/ofono.h | 2 ++
>   src/sim.c   | 9 +++++++++
>   2 files changed, 11 insertions(+)
> 

Patch 3 & 4 applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCHv2 05/11] sim-auth: prep simauth/dbus headers
  2017-10-10 21:36 ` [PATCHv2 05/11] sim-auth: prep simauth/dbus headers James Prestwood
@ 2017-10-11 15:39   ` Denis Kenzior
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Kenzior @ 2017-10-11 15:39 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3528 bytes --]

Hi James,

On 10/10/2017 04:36 PM, James Prestwood wrote:
> Added new dbus interfaces for SimAuth module as well as
> function prototype definitions to simauth header.
> 
> org.ofono.SimAuthentication:
>     Interface to hold the auth object to type mapping property
> 
> org.ofono.USimApplication:
>     Application with USim functionality (GSM/UMTS auth)
> 
> org.ofono.ISimApplication:
>     Application with ISim functionality (IMS auth)
> ---
>   include/dbus.h     |  3 +++
>   include/sim-auth.h | 19 ++++++++++++++++++-
>   2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/include/dbus.h b/include/dbus.h
> index a6519c7..b7d5d39 100644
> --- a/include/dbus.h
> +++ b/include/dbus.h
> @@ -58,6 +58,9 @@ extern "C" {
>   #define OFONO_LOCATION_REPORTING_INTERFACE OFONO_SERVICE ".LocationReporting"
>   #define OFONO_GNSS_INTERFACE "org.ofono.AssistedSatelliteNavigation"
>   #define OFONO_GNSS_POSR_AGENT_INTERFACE "org.ofono.PositioningRequestAgent"
> +#define OFONO_USIM_APPLICATION_INTERFACE "org.ofono.USimApplication"
> +#define OFONO_ISIM_APPLICATION_INTERFACE "org.ofono.ISimApplication"
> +#define OFONO_SIM_AUTHENTICATION_INTERFACE "org.ofono.SimAuthentication"
>   #define OFONO_HANDSFREE_INTERFACE OFONO_SERVICE ".Handsfree"
>   #define OFONO_SIRI_INTERFACE OFONO_SERVICE ".Siri"
>   #define OFONO_NETMON_INTERFACE OFONO_SERVICE ".NetworkMonitor"
> diff --git a/include/sim-auth.h b/include/sim-auth.h
> index 0a62adc..387a487 100644
> --- a/include/sim-auth.h
> +++ b/include/sim-auth.h
> @@ -26,6 +26,8 @@
>   extern "C" {
>   #endif
>   
> +#include <stdint.h>
> +
>   #include <ofono/types.h>
>   
>   struct ofono_sim_auth;
> @@ -34,6 +36,13 @@ typedef void (*ofono_sim_list_apps_cb_t)(const struct ofono_error *error,
>   					const unsigned char *dataobj,
>   					int len, void *data);
>   
> +typedef void (*ofono_sim_open_channel_cb_t)(int session_id, void *data);
> +
> +typedef void (*ofono_sim_close_channel_cb_t)(uint8_t success, void *data);
> +

Our callbacks always have const struct ofono_error *error as a first 
argument.  No sense in reinventing the wheel...

> +typedef void (*ofono_logical_access_cb_t)(const uint8_t *resp,
> +		uint16_t len, void *data);
> +

I think all these should be using ofono_error as the first argument. 
ofono_sim_list_apps_cb_t does this already...

>   struct ofono_sim_auth_driver {
>   	const char *name;
>   	int (*probe)(struct ofono_sim_auth *sa, unsigned int vendor,
> @@ -41,7 +50,15 @@ struct ofono_sim_auth_driver {
>   	void (*remove)(struct ofono_sim_auth *sa);
>   
>   	void (*list_apps)(struct ofono_sim_auth *sa,
> -				ofono_sim_list_apps_cb_t cb, void *data);
> +			ofono_sim_list_apps_cb_t cb, void *data);
> +	void (*open_channel)(struct ofono_sim_auth *sa,
> +			ofono_sim_open_channel_cb_t cb,
> +			const void *channel, void *data);

Why const void?  uint8_t *aid or unsigned char aid[] or...

> +	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,
> +			ofono_logical_access_cb_t cb, int session_id,
> +			const uint8_t *pdu, uint16_t len, void *data);

Customarily the callback and user data are provided last.  So for 
consistency the order should be:

session_id, pdu, len, cb, data

>   };
>   
>   int ofono_sim_auth_driver_register(const struct ofono_sim_auth_driver *d);
> 

Regards,
-Denis

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCHv2 11/11] doc: documentation for SimAuth dbus interfaces
  2017-10-10 21:36 ` [PATCHv2 11/11] doc: documentation for SimAuth dbus interfaces James Prestwood
@ 2017-10-11 15:57   ` Denis Kenzior
  0 siblings, 0 replies; 16+ messages in thread
From: Denis Kenzior @ 2017-10-11 15:57 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4449 bytes --]

Hi James,

On 10/10/2017 04:36 PM, James Prestwood wrote:
> ---
>   doc/sim-auth-api.txt | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 78 insertions(+)
>   create mode 100644 doc/sim-auth-api.txt
> 
> diff --git a/doc/sim-auth-api.txt b/doc/sim-auth-api.txt
> new file mode 100644
> index 0000000..089a325
> --- /dev/null
> +++ b/doc/sim-auth-api.txt
> @@ -0,0 +1,78 @@
> +SimAuth authentication heiarchy [experimental]

SimAuthentication hierarchy

> +===========================================
> +
> +Service		org.ofono
> +Interface	org.ofono.SimAuthentication
> +Object path	[variable prefix]/{modem0,modem1,...}
> +
> +Methods		array{object,dict} GetProperties()
> +
> +			Returns properties for SimAuthentication interface.
> +
> +Properties	array{object,dict} applications [readonly]

Actually lets not implement this as a property.  instead use 
array{object, dict} GetApplications().  This will be consistent with 
Manager.GetModems,  VoicecallManager.GetCalls, 
NetworkRegistration.GetOperators(), etc

> +
> +			Array of all SIM applications found during discovery.
> +			In the format "{o(ss)}" where 'o' is the object

This is inconsistent with how we generally handle this.  Usually the 
signature is a{oa{sv}}

o -> object path
a{sv} -> properties of the individual object

so a{sv} would contain
Name, 's' value inside the variant
Type, 's' value inside the variant

Look at how the GetFoo() methods above handle this.

> +			path for the application, 's' is the type, and 's'
> +			is the human readable name e.g.
> +
> +			o = "/modem1/A0000000871004FFFFFFFF8906190000"
> +			s = "Ims"
> +			s = "ISim"
> +
> +			For each application there will be a corresponding
> +			object that matches the path (o). The type will
> +			signify which interfaces are under that object (below).
> +
> +			type = Umts --> org.ofono.USimApplication
> +			type = Ims  --> org.ofono.ISimApplication
> +
> +SimAuth USIM application heiarchy [experimental]
> +===========================================
> +
> +Service		org.ofono
> +Interface	org.ofono.USimApplication
> +Object path	[variable prefix]/{modem0,modem1,...}/{AID name}
> +
> +Methods		array{string, dict} GsmAuthenticate(array{array{byte}} rands)
> +
> +			Run the USIM application GSM AUTHENTICATE algorithm
> +			with N random challenges 'rands'. This should be an
> +			array of an array of bytes ("aay").

Do you want to mention here that the array can be / should be of size n, 
where n = 2 or 3?

> +
> +			Returns the derived Kc/SRES values as an array of
> +			dictionaries. The index of each dictionary matches
> +			the index of the rand value in the method call. The
> +			keys for each dictionary are "kc" and "sres" and both
> +			are arrays of bytes.

Just a minor nitpick, but if the spec uses a particular capitalization 
for Kc/SRES, then use that as the dictionary key.  It is likely easier 
for readability and we are not limited to small caps.

> +
> +			Possible Errors:
> +				[service].Error.NotSupported
> +				[service].Error.Busy
> +
> +		dict UmtsAuthenticate(array{byte} rand, array{byte} autn)
> +
> +			Run the UMTS AUTHENTICATE algorithm in the 3G
> +			context with 'rand' and 'autn'. A dictionary will be
> +			returned containing 'res', 'ck', 'ik' and possibly
> +			'kc' if service 27 is available. If there was a
> +			sync error 'auts' will be returned.
> +
> +			Possible Errors: [service].Error.NotSupported

Just for API consistency, lets also add GetProperties() with 'Type' and 
'Name' as read-only properties.

> +
> +SimAuth ISIM application heiarchy [experimental]
> +===========================================
> +
> +Service		org.ofono
> +Interface	org.ofono.ISimApplication
> +Object		[variable prefix]/{modem0,modem1,...}/{AID name}
> +
> +Methods		dict ImsAuthenticate(array{byte} rand, array{byte} autn)
> +
> +			Run the UMTS AUTHENTICATE algorithm in the IMS
> +			context with 'rand' and 'autn'. A dictionary will be
> +			returned containing 'res', 'ck', 'ik' and possibly
> +			'kc' if service 27 is available. If there was a
> +			sync error 'auts' will be returned.

Same comments about capitalization of the dict keys as above

> +
> +			Possible Errors: [service].Error.NotSupported
> 

Add GetProperties() with 'Type' and 'Name' as read-only

Regards,
-Denis

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2017-10-11 15:57 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
2017-10-10 21:36 ` [PATCHv2 02/11] simutil: Added authenticate builder/parser API James Prestwood
2017-10-11 15:30   ` Denis Kenzior
2017-10-10 21:36 ` [PATCHv2 03/11] unit: add gsm and umts parse/build unit tests James Prestwood
2017-10-10 21:36 ` [PATCHv2 04/11] sim: new API to check for a UST service only James Prestwood
2017-10-11 15:34   ` Denis Kenzior
2017-10-10 21:36 ` [PATCHv2 05/11] sim-auth: prep simauth/dbus headers James Prestwood
2017-10-11 15:39   ` Denis Kenzior
2017-10-10 21:36 ` [PATCHv2 06/11] sim-auth: implementation of core sim-auth atom James Prestwood
2017-10-10 21:36 ` [PATCHv2 07/11] atmodem: implemented sim-auth functionality in atmodem James Prestwood
2017-10-10 21:36 ` [PATCHv2 08/11] xmm7xxx: add sim-auth driver to xmm7xxx plugin James Prestwood
2017-10-10 21:36 ` [PATCHv2 09/11] phonesim: Added sim-auth to phonesim plugin James Prestwood
2017-10-10 21:36 ` [PATCHv2 10/11] test: added tests for GSM/UMTS auth algorithms James Prestwood
2017-10-10 21:36 ` [PATCHv2 11/11] doc: documentation for SimAuth dbus interfaces James Prestwood
2017-10-11 15:57   ` Denis Kenzior
2017-10-11 15:29 ` [PATCHv2 01/11] simutil: Added app type to application parser 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.