Skip to contentSkip to conversation

Add a parser to retrieve the CDMA network name

PATCH Superseded Philippe Nunes 2 participants 7 messages Nov 14, 2011 – Nov 15, 2011 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add a parser to retrieve the CDMA network name

A new API is introduced in mbpi plugin to parse the mobile broadband provider info' database in order to retrieve the serving network name from the System Identifier (SID).
Next step is precisely to retrieve the SID broadcasted by the CDMA modem

Philippe Nunes (3):
mbpi: mbpi_lookup becomes mbpi_lookup_apn
mbpi: Add mbpi_lookup_cdma_provider_name API
tools: Add utility for looking CDMA network name from database

 Makefile.am                  |    7 +-
 plugins/mbpi.c               |  214 +++++++++++++++++++++++++++++++++++------
 plugins/mbpi.h               |    4 +-
 plugins/provision.c          |    2 +-
 tools/lookup-apn.c           |    2 +-
 tools/lookup-provider-name.c |  104 ++++++++++++++++++++
 6 files changed, 297 insertions(+), 36 deletions(-)
 create mode 100644 tools/lookup-provider-name.c
#1 lore raw

PATCH 1/3 mbpi: mbpi_lookup becomes mbpi_lookup_apn

---
 plugins/mbpi.c      |   71 +++++++++++++++++++++++++--------------------------
 plugins/mbpi.h      |    2 +-
 plugins/provision.c |    2 +-
 tools/lookup-apn.c  |    2 +-
 4 files changed, 38 insertions(+), 39 deletions(-)
plugins/mbpi.c +35 -36
index 53d4b27..1e41ecb 100644
@@ -347,7 +347,7 @@ static const GMarkupParser gsm_parser = {
 	NULL,
 };
 
-static void toplevel_start(GMarkupParseContext *context,
+static void toplevel_gsm_start(GMarkupParseContext *context,
 					const gchar *element_name,
 					const gchar **atribute_names,
 					const gchar **attribute_values,
@@ -362,7 +362,7 @@ static void toplevel_start(GMarkupParseContext *context,
 		g_markup_parse_context_push(context, &skip_parser, NULL);
 }
 
-static void toplevel_end(GMarkupParseContext *context,
+static void toplevel_gsm_end(GMarkupParseContext *context,
 					const gchar *element_name,
 					gpointer userdata, GError **error)
 {
@@ -371,42 +371,22 @@ static void toplevel_end(GMarkupParseContext *context,
 		g_markup_parse_context_pop(context);
 }
 
-static const GMarkupParser toplevel_parser = {
-	toplevel_start,
-	toplevel_end,
+static const GMarkupParser toplevel_gsm_parser = {
+	toplevel_gsm_start,
+	toplevel_gsm_end,
 	NULL,
 	NULL,
 	NULL,
 };
 
-static gboolean mbpi_parse(const char *data, ssize_t size,
-				struct gsm_data *gsm, GError **error)
-{
-	GMarkupParseContext *context;
-	gboolean ret;
-
-	context = g_markup_parse_context_new(&toplevel_parser,
-						G_MARKUP_TREAT_CDATA_AS_TEXT,
-						gsm, NULL);
-
-	ret = g_markup_parse_context_parse(context, data, size, error);
-
-	if (ret == TRUE)
-		g_markup_parse_context_end_parse(context, error);
-
-	g_markup_parse_context_free(context);
-
-	return ret;
-}
-
-GSList *mbpi_lookup(const char *mcc, const char *mnc,
-			gboolean allow_duplicates, GError **error)
+static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
+				GError **error)
 {
 	struct stat st;
 	char *db;
 	int fd;
-	struct gsm_data gsm;
-	GSList *l;
+	GMarkupParseContext *context;
+	gboolean ret;
 
 	fd = open(MBPI_DATABASE, O_RDONLY);
 	if (fd < 0) {
@@ -414,7 +394,7 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 				g_file_error_from_errno(errno),
 				"open(%s) failed: %s", MBPI_DATABASE,
 				g_strerror(errno));
-		return NULL;
+		return FALSE;
 	}
 
 	if (fstat(fd, &st) < 0) {
@@ -423,7 +403,7 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 				g_file_error_from_errno(errno),
 				"fstat(%s) failed: %s", MBPI_DATABASE,
 				g_strerror(errno));
-		return NULL;
+		return FALSE;
 	}
 
 	db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
@@ -433,15 +413,37 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 				g_file_error_from_errno(errno),
 				"mmap(%s) failed: %s", MBPI_DATABASE,
 				g_strerror(errno));
-		return NULL;
+		return FALSE;
 	}
 
+	context = g_markup_parse_context_new(parser,
+						G_MARKUP_TREAT_CDATA_AS_TEXT,
+						userdata, NULL);
+
+	ret = g_markup_parse_context_parse(context, db, st.st_size, error);
+
+	if (ret == TRUE)
+		g_markup_parse_context_end_parse(context, error);
+
+	munmap(db, st.st_size);
+	close(fd);
+	g_markup_parse_context_free(context);
+
+	return ret;
+}
+
+GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
+			gboolean allow_duplicates, GError **error)
+{
+	struct gsm_data gsm;
+	GSList *l;
+
 	memset(&gsm, 0, sizeof(gsm));
 	gsm.match_mcc = mcc;
 	gsm.match_mnc = mnc;
 	gsm.allow_duplicates = allow_duplicates;
 
-	if (mbpi_parse(db, st.st_size, &gsm, error) == FALSE) {
+	if (mbpi_parse(&toplevel_gsm_parser, &gsm, error) == FALSE) {
 		for (l = gsm.apns; l; l = l->next)
 			mbpi_ap_free(l->data);
 
@@ -449,8 +451,5 @@ GSList *mbpi_lookup(const char *mcc, const char *mnc,
 		gsm.apns = NULL;
 	}
 
-	munmap(db, st.st_size);
-	close(fd);
-
 	return gsm.apns;
 }
plugins/mbpi.h +1 -1
index 42e439b..6d34358 100644
@@ -23,5 +23,5 @@ const char *mbpi_ap_type(enum ofono_gprs_context_type type);
 
 void mbpi_ap_free(struct ofono_gprs_provision_data *data);
 
-GSList *mbpi_lookup(const char *mcc, const char *mnc,
+GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 			gboolean allow_duplicates, GError **error);
plugins/provision.c +1 -1
index 06cba6f..99c299e 100644
@@ -50,7 +50,7 @@ static int provision_get_settings(const char *mcc, const char *mnc,
 
 	DBG("Provisioning for MCC %s, MNC %s, SPN '%s'", mcc, mnc, spn);
 
-	apns = mbpi_lookup(mcc, mnc, FALSE, &error);
+	apns = mbpi_lookup_apn(mcc, mnc, FALSE, &error);
 	if (apns == NULL) {
 		if (error != NULL) {
 			ofono_error("%s", error->message);
tools/lookup-apn.c +1 -1
index b833b6c..884b32a 100644
@@ -42,7 +42,7 @@ static void lookup_apn(const char *match_mcc, const char *match_mnc,
 
 	g_print("Searching for info for network: %s%s\n", match_mcc, match_mnc);
 
-	apns = mbpi_lookup(match_mcc, match_mnc, allow_duplicates, &error);
+	apns = mbpi_lookup_apn(match_mcc, match_mnc, allow_duplicates, &error);
 
 	if (apns == NULL) {
 		if (error != NULL) {
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/3] mbpi: mbpi_lookup becomes mbpi_lookup_apn

Hi Philippe,

Quoted 7 lines · Philippe Nunes
---
 plugins/mbpi.c      |   71 +++++++++++++++++++++++++--------------------------
 plugins/mbpi.h      |    2 +-
 plugins/provision.c |    2 +-
 tools/lookup-apn.c  |    2 +-
 4 files changed, 38 insertions(+), 39 deletions(-)

Patch looks good to me and has been applied. I did however split it up into three commits, one for mbpi changes, one for provision updates and one for look-apn updates.

Regards,
-Denis

#3 lore raw

PATCH 2/3 mbpi: Add mbpi_lookup_cdma_provider_name API

In reply to Philippe Nunes
---
 plugins/mbpi.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/mbpi.h |    2 +
 2 files changed, 153 insertions(+), 0 deletions(-)
plugins/mbpi.c +151 -0
index 1e41ecb..14aa339 100644
@@ -58,6 +58,12 @@ struct gsm_data {
 	gboolean allow_duplicates;
 };
 
+struct cdma_data {
+	const char *match_sid;
+	char *provider_name;
+	gboolean match_found;
+};
+
 const char *mbpi_ap_type(enum ofono_gprs_context_type type)
 {
 	switch (type) {
@@ -281,6 +287,34 @@ static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm,
 	g_markup_parse_context_push(context, &apn_parser, ap);
 }
 
+static void sid_handler(GMarkupParseContext *context,
+				struct cdma_data *cdma,
+				const gchar **attribute_names,
+				const gchar **attribute_values,
+				GError **error)
+{
+	const char *sid = NULL;
+	int i;
+
+	if (cdma->match_found == TRUE)
+		return;
+
+	for (i = 0; attribute_names[i]; i++) {
+		if (g_str_equal(attribute_names[i], "value") == TRUE)
+			sid = attribute_values[i];
+	}
+
+	if (sid == NULL) {
+		mbpi_g_set_error(context, error, G_MARKUP_ERROR,
+					G_MARKUP_ERROR_MISSING_ATTRIBUTE,
+					"Missing attribute: sid");
+		return;
+	}
+
+	if (g_str_equal(sid, cdma->match_sid))
+		cdma->match_found = TRUE;
+}
+
 static void gsm_start(GMarkupParseContext *context, const gchar *element_name,
 			const gchar **attribute_names,
 			const gchar **attribute_values,
@@ -347,6 +381,74 @@ static const GMarkupParser gsm_parser = {
 	NULL,
 };
 
+static void cdma_start(GMarkupParseContext *context, const gchar *element_name,
+			const gchar **attribute_names,
+			const gchar **attribute_values,
+			gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "sid")) {
+		struct cdma_data *cdma = userdata;
+		/*
+		 * For entries with multiple sid elements, don't bother
+		 * searching if we already have a match
+		 */
+		if (cdma->match_found == TRUE)
+			return;
+
+		sid_handler(context, cdma, attribute_names, attribute_values,
+				error);
+	}
+}
+
+static const GMarkupParser cdma_parser = {
+	cdma_start,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+};
+
+static void provider_start(GMarkupParseContext *context,
+				const gchar *element_name,
+				const gchar **attribute_names,
+				const gchar **attribute_values,
+				gpointer userdata, GError **error)
+{
+	struct cdma_data *cdma = userdata;
+
+	if (g_str_equal(element_name, "name")) {
+		if ((cdma->match_found == FALSE) && (cdma->provider_name)) {
+			g_free(cdma->provider_name);
+			cdma->provider_name = NULL;
+		}
+
+		g_markup_parse_context_push(context, &text_parser,
+						&cdma->provider_name);
+	} else if (g_str_equal(element_name, "gsm"))
+		g_markup_parse_context_push(context, &skip_parser, NULL);
+	else if (g_str_equal(element_name, "cdma"))
+		g_markup_parse_context_push(context, &cdma_parser, userdata);
+}
+
+static void provider_end(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "name") ||
+				g_str_equal(element_name, "gsm") ||
+				g_str_equal(element_name, "cdma"))
+		g_markup_parse_context_pop(context);
+
+}
+
+static const GMarkupParser provider_parser = {
+	provider_start,
+	provider_end,
+	NULL,
+	NULL,
+	NULL,
+};
+
 static void toplevel_gsm_start(GMarkupParseContext *context,
 					const gchar *element_name,
 					const gchar **atribute_names,
@@ -379,6 +481,40 @@ static const GMarkupParser toplevel_gsm_parser = {
 	NULL,
 };
 
+static void toplevel_cdma_start(GMarkupParseContext *context,
+					const gchar *element_name,
+					const gchar **atribute_names,
+					const gchar **attribute_values,
+					gpointer userdata, GError **error)
+{
+	struct cdma_data *cdma = userdata;
+
+	if (g_str_equal(element_name, "provider")) {
+		if (cdma->match_found == TRUE)
+			g_markup_parse_context_push(context, &skip_parser,
+								NULL);
+		else
+			g_markup_parse_context_push(context, &provider_parser,
+								userdata);
+	}
+}
+
+static void toplevel_cdma_end(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "provider"))
+		g_markup_parse_context_pop(context);
+}
+
+static const GMarkupParser toplevel_cdma_parser = {
+	toplevel_cdma_start,
+	toplevel_cdma_end,
+	NULL,
+	NULL,
+	NULL,
+};
+
 static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
 				GError **error)
 {
@@ -453,3 +589,18 @@ GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 
 	return gsm.apns;
 }
+
+char *mbpi_lookup_cdma_provider_name(const char *sid, GError **error)
+{
+	struct cdma_data cdma;
+
+	memset(&cdma, 0, sizeof(cdma));
+	cdma.match_sid = sid;
+
+	if (mbpi_parse(&toplevel_cdma_parser, &cdma, error) == FALSE) {
+		g_free(cdma.provider_name);
+		cdma.provider_name = NULL;
+	}
+
+	return cdma.provider_name;
+}
plugins/mbpi.h +2 -0
index 6d34358..64b7ea5 100644
@@ -25,3 +25,5 @@ void mbpi_ap_free(struct ofono_gprs_provision_data *data);
 
 GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 			gboolean allow_duplicates, GError **error);
+
+char *mbpi_lookup_cdma_provider_name(const char *sid, GError **error);
Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH 2/3] mbpi: Add mbpi_lookup_cdma_provider_name API

Hi Philippe,

Quoted 27 lines · Philippe Nunes
---
 plugins/mbpi.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 plugins/mbpi.h |    2 +
 2 files changed, 153 insertions(+), 0 deletions(-)
plugins/mbpi.c +7 -0
index 1e41ecb..14aa339 100644
@@ -58,6 +58,12 @@ struct gsm_data {
 	gboolean allow_duplicates;
 };
 
+struct cdma_data {
+	const char *match_sid;
+	char *provider_name;
+	gboolean match_found;
+};
+
 const char *mbpi_ap_type(enum ofono_gprs_context_type type)
 {
 	switch (type) {
@@ -281,6 +287,34 @@ static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm,
 	g_markup_parse_context_push(context, &apn_parser, ap);
 }
 
+static void sid_handler(GMarkupParseContext *context,

plugins/mbpi.c static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm, · line 300

Quoted 10 lines
plugins/mbpi.c +10 -0
+				struct cdma_data *cdma,
+				const gchar **attribute_names,
+				const gchar **attribute_values,
+				GError **error)
+{
+	const char *sid = NULL;
+	int i;
+
+	if (cdma->match_found == TRUE)
+		return;

Why do you check this here, but also make the same exact check in cdma_start?

plugins/mbpi.c static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm, · line 304

Quoted 4 lines
plugins/mbpi.c +4 -0
+
+	for (i = 0; attribute_names[i]; i++) {
+		if (g_str_equal(attribute_names[i], "value") == TRUE)
+			sid = attribute_values[i];

Just a small nitpick, but you probably want to break from the loop once you find the value attribute. Also, the braces around the outer for loop are not really necessary in this case and the style preference is not to include them.

Quoted 47 lines
plugins/mbpi.c +40 -0
+	}
+
+	if (sid == NULL) {
+		mbpi_g_set_error(context, error, G_MARKUP_ERROR,
+					G_MARKUP_ERROR_MISSING_ATTRIBUTE,
+					"Missing attribute: sid");
+		return;
+	}
+
+	if (g_str_equal(sid, cdma->match_sid))
+		cdma->match_found = TRUE;
+}
+
 static void gsm_start(GMarkupParseContext *context, const gchar *element_name,
 			const gchar **attribute_names,
 			const gchar **attribute_values,
@@ -347,6 +381,74 @@ static const GMarkupParser gsm_parser = {
 	NULL,
 };
 
+static void cdma_start(GMarkupParseContext *context, const gchar *element_name,
+			const gchar **attribute_names,
+			const gchar **attribute_values,
+			gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "sid")) {
+		struct cdma_data *cdma = userdata;
+		/*
+		 * For entries with multiple sid elements, don't bother
+		 * searching if we already have a match
+		 */
+		if (cdma->match_found == TRUE)
+			return;
+
+		sid_handler(context, cdma, attribute_names, attribute_values,
+				error);
+	}
+}
+
+static const GMarkupParser cdma_parser = {
+	cdma_start,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+};
+

plugins/mbpi.c static const GMarkupParser gsm_parser = { · line 420

Quoted 10 lines
plugins/mbpi.c +10 -0
+static void provider_start(GMarkupParseContext *context,
+				const gchar *element_name,
+				const gchar **attribute_names,
+				const gchar **attribute_values,
+				gpointer userdata, GError **error)
+{
+	struct cdma_data *cdma = userdata;
+
+	if (g_str_equal(element_name, "name")) {
+		if ((cdma->match_found == FALSE) && (cdma->provider_name)) {

This is against our style guidelines, please get rid of the parens.

Also, do you ever expect this function to be called when match_found is not FALSE? The DTD is funny here, it says that several name tags can be provided. Not sure why anyone would do that or how we want to handle this. However, all name elements must be before any cdma or gsm tags.

Quoted 99 lines
plugins/mbpi.c +80 -0
+			g_free(cdma->provider_name);
+			cdma->provider_name = NULL;
+		}
+
+		g_markup_parse_context_push(context, &text_parser,
+						&cdma->provider_name);
+	} else if (g_str_equal(element_name, "gsm"))
+		g_markup_parse_context_push(context, &skip_parser, NULL);
+	else if (g_str_equal(element_name, "cdma"))
+		g_markup_parse_context_push(context, &cdma_parser, userdata);
+}
+
+static void provider_end(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "name") ||
+				g_str_equal(element_name, "gsm") ||
+				g_str_equal(element_name, "cdma"))
+		g_markup_parse_context_pop(context);
+
+}
+
+static const GMarkupParser provider_parser = {
+	provider_start,
+	provider_end,
+	NULL,
+	NULL,
+	NULL,
+};
+
 static void toplevel_gsm_start(GMarkupParseContext *context,
 					const gchar *element_name,
 					const gchar **atribute_names,
@@ -379,6 +481,40 @@ static const GMarkupParser toplevel_gsm_parser = {
 	NULL,
 };
 
+static void toplevel_cdma_start(GMarkupParseContext *context,
+					const gchar *element_name,
+					const gchar **atribute_names,
+					const gchar **attribute_values,
+					gpointer userdata, GError **error)
+{
+	struct cdma_data *cdma = userdata;
+
+	if (g_str_equal(element_name, "provider")) {
+		if (cdma->match_found == TRUE)
+			g_markup_parse_context_push(context, &skip_parser,
+								NULL);
+		else
+			g_markup_parse_context_push(context, &provider_parser,
+								userdata);
+	}
+}
+
+static void toplevel_cdma_end(GMarkupParseContext *context,
+					const gchar *element_name,
+					gpointer userdata, GError **error)
+{
+	if (g_str_equal(element_name, "provider"))
+		g_markup_parse_context_pop(context);
+}
+
+static const GMarkupParser toplevel_cdma_parser = {
+	toplevel_cdma_start,
+	toplevel_cdma_end,
+	NULL,
+	NULL,
+	NULL,
+};
+
 static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
 				GError **error)
 {
@@ -453,3 +589,18 @@ GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 
 	return gsm.apns;
 }
+
+char *mbpi_lookup_cdma_provider_name(const char *sid, GError **error)
+{
+	struct cdma_data cdma;
+
+	memset(&cdma, 0, sizeof(cdma));
+	cdma.match_sid = sid;
+
+	if (mbpi_parse(&toplevel_cdma_parser, &cdma, error) == FALSE) {
+		g_free(cdma.provider_name);
+		cdma.provider_name = NULL;
+	}
+
+	return cdma.provider_name;
+}
plugins/mbpi.h +0 -0
index 6d34358..64b7ea5 100644

plugins/mbpi.h void mbpi_ap_free(struct ofono_gprs_provision_data *data); · line 29

Quoted 5 lines
plugins/mbpi.h +2 -0
@@ -25,3 +25,5 @@ void mbpi_ap_free(struct ofono_gprs_provision_data *data);
 
 GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
 			gboolean allow_duplicates, GError **error);
+
+char *mbpi_lookup_cdma_provider_name(const char *sid, GError **error);

Regards,
-Denis

#5 lore raw

PATCH 3/3 tools: Add utility for looking CDMA network name from database

In reply to Philippe Nunes
---
 Makefile.am                  |    7 ++-
 tools/lookup-provider-name.c |  104 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 1 deletions(-)
 create mode 100644 tools/lookup-provider-name.c
Makefile.am +6 -1
index a28f790..337aeb7 100644
@@ -627,7 +627,8 @@ TESTS = $(unit_tests)
 
 if TOOLS
 noinst_PROGRAMS += tools/huawei-audio tools/auto-enable \
-			tools/get-location tools/lookup-apn
+			tools/get-location tools/lookup-apn \
+			tools/lookup-provider-name
 
 tools_huawei_audio_SOURCES = $(gdbus_sources) tools/huawei-audio.c
 tools_huawei_audio_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
@@ -640,6 +641,10 @@ tools_get_location_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
 
 tools_lookup_apn_SOURCES = plugins/mbpi.c plugins/mbpi.h tools/lookup-apn.c
 tools_lookup_apn_LDADD = @GLIB_LIBS@
+
+tools_lookup_provider_name_SOURCES = plugins/mbpi.c plugins/mbpi.h \
+				tools/lookup-provider-name.c
+tools_lookup_provider_name_LDADD = @GLIB_LIBS@
 endif
 
 noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
tools/lookup-provider-name.c new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
1.7.1
#6 lore raw

Re: [PATCH 3/3] tools: Add utility for looking CDMA network name from database

Hi Philippe,

Quoted 78 lines · Philippe Nunes
---
 Makefile.am                  |    7 ++-
 tools/lookup-provider-name.c |  104 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+), 1 deletions(-)
 create mode 100644 tools/lookup-provider-name.c
Makefile.am +6 -1
index a28f790..337aeb7 100644
@@ -627,7 +627,8 @@ TESTS = $(unit_tests)
 
 if TOOLS
 noinst_PROGRAMS += tools/huawei-audio tools/auto-enable \
-			tools/get-location tools/lookup-apn
+			tools/get-location tools/lookup-apn \
+			tools/lookup-provider-name
 
 tools_huawei_audio_SOURCES = $(gdbus_sources) tools/huawei-audio.c
 tools_huawei_audio_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
@@ -640,6 +641,10 @@ tools_get_location_LDADD = @GLIB_LIBS@ @DBUS_LIBS@
 
 tools_lookup_apn_SOURCES = plugins/mbpi.c plugins/mbpi.h tools/lookup-apn.c
 tools_lookup_apn_LDADD = @GLIB_LIBS@
+
+tools_lookup_provider_name_SOURCES = plugins/mbpi.c plugins/mbpi.h \
+				tools/lookup-provider-name.c
+tools_lookup_provider_name_LDADD = @GLIB_LIBS@
 endif
 
 noinst_PROGRAMS += gatchat/gsmdial gatchat/test-server gatchat/test-qcdm
tools/lookup-provider-name.c new file +41 -0
new file mode 100644
index 0000000..dc91ae5
@@ -0,0 +1,104 @@
+/*
+ *
+ *  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
+
+#include <stdlib.h>
+
+#include <glib.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/modem.h>
+#include <ofono/gprs-provision.h>
+
+#include "plugins/mbpi.h"
+
+static void lookup_cdma_provider_name(const char *match_sid)
+{
+	GError *error = NULL;
+	char *name;
+
+	g_print("Searching for serving network name with SID: %s\n", match_sid);

tools/lookup-provider-name.c line 51

Quoted 10 lines
tools/lookup-provider-name.c new file +10 -0
+
+	name = mbpi_lookup_cdma_provider_name(match_sid, &error);
+
+	if (name == NULL) {
+		if (error != NULL) {
+			g_printerr("Lookup failed: %s\n", error->message);
+			g_error_free(error);
+		}
+		else
+			g_printerr("Not found\n");

Please re-read the kernel style guidelines with regard to placing of curly braces in compound statements. It should be on the same line as the else statement.

Quoted 7 lines
tools/lookup-provider-name.c new file +7 -0
+
+		return;
+	}
+
+	g_print("CDMA provider name: %s\n", name);
+
+	g_free(name);

tools/lookup-provider-name.c line 68

Quoted 10 lines
tools/lookup-provider-name.c new file +10 -0
+}
+
+static gboolean option_version = FALSE;
+static gboolean option_duplicates = FALSE;
+
+static GOptionEntry options[] = {
+	{ "version", 'v', 0, G_OPTION_ARG_NONE, &option_version,
+				"Show version information and exit" },
+	{ "allow-duplicates", 0, 0, G_OPTION_ARG_NONE, &option_duplicates,
+				"Allow duplicate access point types" },

Why exactly do we need this option?

Quoted 26 lines
tools/lookup-provider-name.c new file +26 -0
+	{ NULL },
+};
+
+int main(int argc, char **argv)
+{
+	GOptionContext *context;
+	GError *error = NULL;
+
+	context = g_option_context_new(NULL);
+	g_option_context_add_main_entries(context, options, NULL);
+
+	if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) {
+		if (error != NULL) {
+			g_printerr("%s\n", error->message);
+			g_error_free(error);
+		} else
+			g_printerr("An unknown error occurred\n");
+		exit(1);
+	}
+
+	g_option_context_free(context);
+
+	if (option_version == TRUE) {
+		g_print("%s\n", VERSION);
+		exit(0);
+	}

tools/lookup-provider-name.c line 104

Quoted 10 lines
tools/lookup-provider-name.c new file +10 -0
+
+	if (argc < 1) {
+		g_printerr("Missing parameters\n");
+		exit(1);
+	}
+
+	lookup_cdma_provider_name(argv[1]);
+
+	return 0;
+}

Regards,
-Denis