Skip to contentSkip to conversation

Read EF-PNN, EF-OPL and override network names accordingly.

PATCH In review Andrzej Zaborowski 2 participants 4 messages Jul 5, 2009 – Jul 18, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Read EF-PNN, EF-OPL and override network names accordingly.

---
 src/driver.h  |    2 +
 src/network.c |   54 ++++++----
 src/sim.c     |  315 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/sim.h     |    4 +
 4 files changed, 345 insertions(+), 30 deletions(-)
src/driver.h +2 -0
index f324c1c..595c980 100644
@@ -84,6 +84,8 @@ struct ofono_network_operator {
 	char mnc[OFONO_MAX_MNC_LENGTH + 1];
 	int status;
 	int tech;
+
+	const char *override_name;
 };
 
 /* 27.007 Section 7.11 Call Forwarding */
src/network.c +34 -20

105 lines not on this page · raw message

src/sim.c +305 -10

404 lines not on this page · raw message

src/sim.h +4 -0
index 251a339..ecb809a 100644
@@ -31,3 +31,7 @@ int ofono_spn_update_notify_unregister(struct ofono_modem *modem,
 
 gboolean ofono_operator_in_spdi(struct ofono_modem *modem,
 				const struct ofono_network_operator *op);
+
+const char *ofono_operator_name_sim_override(struct ofono_modem *modem,
+						const char *mcc,
+						const char *mnc);
Signature · 1 line
1.6.0
#1 lore raw

Hi,

Patch has been applied. However, I've completely (juding by 40 or so commits) refactored how SIM filesystem is handled in oFono so I might have introduced some bugs. Could you test to make sure it is working as intended?

Can you submit some unit tests with sample PNN/OPL data?

Regards,
-Denis

#2 lore raw

2009/7/14 Denis Kenzior <[email protected]>:

Quoted 3 lines

Patch has been applied.  However, I've completely (juding by 40 or so commits) refactored how SIM filesystem is handled in oFono so I might have introduced some bugs.  Could you test to make sure it is working as intended?

Attaching some fixes for the new code, the test and a clean-up patch (feel free to drop parts). Note all the recent commits broke bisectability badly.

Wouldn't it be useful for the service provider name to be available as SimManager property?

Regards

From 2ccd0f29394d3e66bd553e19cf739a8ce5a8d700 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 18 Jul 2009 01:42:31 +0200
Subject: [PATCH] Make PNN / OPL work.

---
 src/network.c |    4 ++--
 src/simutil.c |   12 ++++++++----
 2 files changed, 10 insertions(+), 6 deletions(-)
src/network.c +2 -2
index 56ca924..969c637 100644
@@ -1206,12 +1206,12 @@ static void sim_opl_read_cb(struct ofono_modem *modem, int ok,
 	if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
 		return;
 
-	if (length < 8 || record_length < 8 || length < record_length)
+	if (record_length < 8 || length < record_length)
 		return;
 
 	total = length / record_length;
 
-	sim_eons_add_pnn_record(netreg->eons, record, data, record_length);
+	sim_eons_add_opl_record(netreg->eons, data, record_length);
 
 	if (record != total)
 		return;
src/simutil.c +8 -4
index 16fad16..26d1bad 100644
@@ -338,13 +338,17 @@ static struct sim_eons_operator_info *
 
 		for (i = 0; i < OFONO_MAX_MCC_LENGTH; i++)
 			if (mcc[i] != opl->mcc[i] &&
-					!(opl->mcc[i] == 'd' && mcc[i]))
-				continue;
+					!(opl->mcc[i] == 'b' && mcc[i]))
+				break;
+		if (i < OFONO_MAX_MCC_LENGTH)
+			continue;
 
 		for (i = 0; i < OFONO_MAX_MNC_LENGTH; i++)
 			if (mnc[i] != opl->mnc[i] &&
-					!(opl->mnc[i] == 'd' && mnc[i]))
-				continue;
+					!(opl->mnc[i] == 'b' && mnc[i]))
+				break;
+		if (i < OFONO_MAX_MNC_LENGTH)
+			continue;
 
 		if (opl->lac_tac_low == 0 && opl->lac_tac_high == 0xfffe)
 			break;
Signature · 1 line
1.6.0

From 4f14a94ffce861e5a0c412acf9440c6b9a6ff725 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 18 Jul 2009 01:42:54 +0200
Subject: [PATCH] Clean-up in sim.c.

---
 src/sim.c |   26 +++++---------------------
 1 files changed, 5 insertions(+), 21 deletions(-)
src/sim.c +5 -21
index bd92836..86f2e98 100644
@@ -65,13 +65,6 @@ struct sim_manager_data {
 	GSList *ready_notify;
 	gboolean ready;
 	GQueue *simop_q;
-
-	GSList *spdi;
-
-	GSList *opl;
-	int opl_num;
-	int opl_size;
-	int opl_current;
 };
 
 static char **get_own_numbers(GSList *own_numbers)
@@ -127,18 +120,6 @@ static void sim_manager_destroy(gpointer userdata)
 		g_queue_free(data->simop_q);
 		data->simop_q = NULL;
 	}
-
-	if (data->spdi) {
-		g_slist_foreach(data->spdi, (GFunc)g_free, NULL);
-		g_slist_free(data->spdi);
-		data->spdi = NULL;
-	}
-
-	if (data->opl) {
-		g_slist_foreach(data->opl, (GFunc)g_free, NULL);
-		g_slist_free(data->opl);
-		data->opl = NULL;
-	}
 }
 
 static DBusMessage *sim_get_properties(DBusConnection *conn,
@@ -181,7 +162,10 @@ static GDBusMethodTable sim_manager_methods[] = {
 	{ }
 };
 
-static GDBusSignalTable sim_manager_signals[] = { { } };
+static GDBusSignalTable sim_manager_signals[] = {
+	{ "PropertyChanged",	"sv" },
+	{ }
+};
 
 
 static void sim_msisdn_read_cb(struct ofono_modem *modem, int ok,
@@ -202,7 +186,7 @@ static void sim_msisdn_read_cb(struct ofono_modem *modem, int ok,
 	if (structure != OFONO_SIM_FILE_STRUCTURE_FIXED)
 		return;
 
-	if (length < 14 || record_length < 14 || length < record_length)
+	if (record_length < 14 || length < record_length)
 		return;
 
 	total = length / record_length;
src/network.c +4 -4
index 1152b28..e264374 100644
@@ -89,7 +89,7 @@ static void registration_status_callback(const struct ofono_error *error,
 struct network_operator_data {
 	struct ofono_network_operator *info;
 	struct ofono_modem *modem;
-	struct sim_eons_operator_info *eons_info;
+	const struct sim_eons_operator_info *eons_info;
 };
 
 static inline const char *network_operator_status_to_string(int status)
@@ -427,11 +427,11 @@ static void set_network_operator_name(struct ofono_modem *modem,
 
 static void set_network_operator_eons_info(struct ofono_modem *modem,
 				struct network_operator_data *opd,
-				struct sim_eons_operator_info *eons_info)
+				const struct sim_eons_operator_info *eons_info)
 {
 	struct network_registration_data *netreg = modem->network_registration;
 	DBusConnection *conn = dbus_gsm_connection();
-	struct sim_eons_operator_info *old_eons_info = opd->eons_info;
+	const struct sim_eons_operator_info *old_eons_info = opd->eons_info;
 	const char *path;
 	const char *oldname;
 	const char *newname;
@@ -1226,7 +1226,7 @@ static void sim_opl_read_cb(struct ofono_modem *modem, int ok,
 
 	for (l = netreg->operator_list; l; l = l->next) {
 		struct network_operator_data *opd = l->data;
-		struct sim_eons_operator_info *eons_info;
+		const struct sim_eons_operator_info *eons_info;
 
 		eons_info = sim_eons_lookup(netreg->eons, opd->info->mcc,
 						opd->info->mnc);
src/simutil.c +17 -5
index 26d1bad..1430ec3 100644
@@ -32,6 +32,13 @@
 #include "util.h"
 #include "smsutil.h"
 
+struct sim_eons {
+	struct sim_eons_operator_info *pnn_list;
+	GSList *opl_list;
+	gboolean pnn_valid;
+	int pnn_max;
+};
+
 struct spdi_operator {
 	char mcc[OFONO_MAX_MCC_LENGTH + 1];
 	char mnc[OFONO_MAX_MNC_LENGTH + 1];
@@ -171,6 +178,10 @@ static gint spdi_operator_compare(gconstpointer a, gconstpointer b)
 	return strcmp(opa->mnc, opb->mnc);
 }
 
+struct sim_spdi {
+	GSList *operators;
+};
+
 struct sim_spdi *sim_spdi_new(const guint8 *tlv, int length)
 {
 	const guint8 *plmn_list;
@@ -290,11 +301,11 @@ static struct opl_operator *opl_operator_alloc(const guint8 *record)
 }
 
 void sim_eons_add_opl_record(struct sim_eons *eons,
-				const guint8 *tlv, int length)
+				const guint8 *contents, int length)
 {
 	struct opl_operator *oper;
 
-	oper = opl_operator_alloc(tlv);
+	oper = opl_operator_alloc(contents);
 
 	if (oper->id > eons->pnn_max) {
 		g_free(oper);
@@ -324,7 +335,7 @@ void sim_eons_free(struct sim_eons *eons)
 	g_free(eons);
 }
 
-static struct sim_eons_operator_info *
+static const struct sim_eons_operator_info *
 	sim_eons_lookup_common(struct sim_eons *eons,
 				const char *mcc, const char *mnc,
 				gboolean have_lac, guint16 lac)
@@ -372,14 +383,15 @@ static struct sim_eons_operator_info *
 	return &eons->pnn_list[opl->id - 1];
 }
 
-struct sim_eons_operator_info *sim_eons_lookup(struct sim_eons *eons,
+const struct sim_eons_operator_info *sim_eons_lookup(struct sim_eons *eons,
 						const char *mcc,
 						const char *mnc)
 {
 	return sim_eons_lookup_common(eons, mcc, mnc, FALSE, 0);
 }
 
-struct sim_eons_operator_info *sim_eons_lookup_with_lac(struct sim_eons *eons,
+const struct sim_eons_operator_info *sim_eons_lookup_with_lac(
+							struct sim_eons *eons,
 							const char *mcc,
 							const char *mnc,
 							guint16 lac)
src/simutil.h +7 -17
index fb0a1b8..d74706a 100644
@@ -30,10 +30,6 @@ enum sim_fileid {
 #define SIM_EFSPN_DC_HOME_PLMN_BIT 0x1
 #define SIM_EFSPN_DC_ROAMING_SPN_BIT 0x2
 
-struct sim_spdi {
-	GSList *operators;
-};
-
 struct sim_eons_operator_info {
 	char *longname;
 	gboolean long_ci;
@@ -42,25 +38,19 @@ struct sim_eons_operator_info {
 	char *info;
 };
 
-struct sim_eons {
-	struct sim_eons_operator_info *pnn_list;
-	GSList *opl_list;
-	gboolean pnn_valid;
-	int pnn_max;
-};
-
 struct sim_eons *sim_eons_new(int pnn_records);
 void sim_eons_add_pnn_record(struct sim_eons *eons, int record,
 				const guint8 *tlv, int length);
 gboolean sim_eons_pnn_is_empty(struct sim_eons *eons);
 void sim_eons_add_opl_record(struct sim_eons *eons,
-				const guint8 *tlv, int length);
+				const guint8 *contents, int length);
 void sim_eons_optimize(struct sim_eons *eons);
-struct sim_eons_operator_info *sim_eons_lookup_with_lac(struct sim_eons *eons,
-							const char *mcc,
-							const char *mnc,
-							guint16 lac);
-struct sim_eons_operator_info *sim_eons_lookup(struct sim_eons *eons,
+const struct sim_eons_operator_info *sim_eons_lookup_with_lac(
+						struct sim_eons *eons,
+						const char *mcc,
+						const char *mnc,
+						guint16 lac);
+const struct sim_eons_operator_info *sim_eons_lookup(struct sim_eons *eons,
 						const char *mcc,
 						const char *mnc);
 void sim_eons_free(struct sim_eons *eons);
Signature · 1 line
1.6.0

From b41395c24f29b0b68526fab348dce45d8838b7aa Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 18 Jul 2009 01:44:54 +0200
Subject: [PATCH] Don't dereference before the null check.

---
 src/network.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
src/network.c +4 -2
index 969c637..146b49f 100644
@@ -339,7 +339,7 @@ static char *get_operator_display_name(struct ofono_modem *modem)
 {
 	struct network_registration_data *netreg = modem->network_registration;
 	struct network_operator_data *current = netreg->current_operator;
-	struct ofono_network_operator *op = current->info;
+	struct ofono_network_operator *op;
 	const char *plmn;
 	static char name[1024];
 	int len = sizeof(name);
@@ -349,11 +349,13 @@ static char *get_operator_display_name(struct ofono_modem *modem)
 	 * PLMN or roaming and on configuration bits from the SIM, all
 	 * together there are four cases to consider.  */
 
-	if (!netreg->current_operator) {
+	if (!current) {
 		g_strlcpy(name, "", len);
 		return name;
 	}
 
+	op = current->info;
+
 	plmn = op->name;
 	if (current->eons_info && current->eons_info->longname)
 		plmn = current->eons_info->longname;
Signature · 1 line
1.6.0

From 9efef8f3481382e6ccd8c8f488d7b73bb6a54087 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 18 Jul 2009 01:45:22 +0200
Subject: [PATCH] Use registration status constants consistently.

---
 src/network.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
src/network.c +7 -3
index 146b49f..1152b28 100644
@@ -954,7 +954,8 @@ void ofono_network_registration_notify(struct ofono_modem *modem, int status,
 	if (netreg->technology != tech)
 		set_registration_technology(modem, tech);
 
-	if (netreg->status == 1 || netreg->status == 5) {
+	if (netreg->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
+		netreg->status == NETWORK_REGISTRATION_STATUS_ROAMING) {
 		if (netreg->ops->current_operator)
 			netreg->ops->current_operator(modem,
 					current_operator_callback, modem);
@@ -1142,13 +1143,16 @@ static void init_registration_status(const struct ofono_error *error,
 	/* Bootstrap our signal strength value without waiting for the
 	 * stack to report it
 	 */
-	if (netreg->status == 1 || netreg->status == 5) {
+	if (netreg->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
+		netreg->status == NETWORK_REGISTRATION_STATUS_ROAMING) {
 		if (netreg->ops->signal_strength)
 			netreg->ops->signal_strength(modem,
 					signal_strength_callback, modem);
 	}
 
-	if (AUTO_REGISTER && (status == 0 || status == 3))
+	if (AUTO_REGISTER &&
+		(status == NETWORK_REGISTRATION_STATUS_NOT_REGISTERED ||
+		 status == NETWORK_REGISTRATION_STATUS_DENIED))
 		netreg->ops->register_auto(modem, register_callback, modem);
 }
 
Signature · 1 line
1.6.0

From 4ad1330bb21c76a1902fec21be54422908ca88bc Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <[email protected]>
Date: Sat, 18 Jul 2009 03:29:57 +0200
Subject: [PATCH] Test EONS handling.

---
 unit/Makefile.am    |    5 ++-
 unit/test-simutil.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 1 deletions(-)
 create mode 100644 unit/test-simutil.c
unit/Makefile.am +4 -1
index a1c5510..d996465 100644
@@ -1,5 +1,5 @@
 
-noinst_PROGRAMS = test-common test-util test-sms
+noinst_PROGRAMS = test-common test-util test-sms test-simutil
 
 test_common_SOURCES = test-common.c $(top_srcdir)/src/common.c
 
@@ -8,6 +8,9 @@ test_util_SOURCES = test-util.c $(top_srcdir)/src/util.c
 test_sms_SOURCES = test-sms.c $(top_srcdir)/src/util.c \
 					$(top_srcdir)/src/smsutil.c
 
+test_simutil_SOURCES = test-simutil.c $(top_srcdir)/src/util.c \
+					$(top_srcdir)/src/simutil.c
+
 LDADD = @GLIB_LIBS@ @GTHREAD_LIBS@
 
 AM_CFLAGS = @GTHREAD_CFLAGS@ @GLIB_CFLAGS@
unit/test-simutil.c new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
1.6.0
#3 lore raw

Hi,

Quoted 9 lines

2009/7/14 Denis Kenzior <[email protected]>:

Quoted 4 lines

Patch has been applied. However, I've completely (juding by 40 or so commits) refactored how SIM filesystem is handled in oFono so I might have introduced some bugs. Could you test to make sure it is working as intended?

Attaching some fixes for the new code, the test and a clean-up patch (feel free to drop parts). Note all the recent commits broke bisectability badly.

Good catches. All five have been applied and pushed. Thanks.

Quoted 3 lines

Wouldn't it be useful for the service provider name to be available as SimManager property?

I really don't see any practical uses for it by the UI. Can you foresee anything that actually needs this? Remember, it is easier to add apis later than to modify or remove.

Regards,
-Denis