All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] netreg: add +COPS support for HFP emulator
@ 2011-03-22 10:50 =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
  2011-03-30  2:54 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-03-22 10:50 UTC (permalink / raw)
  To: ofono

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

---
 src/network.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/src/network.c b/src/network.c
index 2d0a9f8..7df6786 100644
--- a/src/network.c
+++ b/src/network.c
@@ -1693,6 +1693,13 @@ void ofono_netreg_driver_unregister(const struct ofono_netreg_driver *d)
 	g_drivers = g_slist_remove(g_drivers, (void *) d);
 }
 
+static void emulator_remove_handler(struct ofono_atom *atom, void *data)
+{
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
+
+	ofono_emulator_remove_handler(em, data);
+}
+
 static void netreg_unregister(struct ofono_atom *atom)
 {
 	struct ofono_netreg *netreg = __ofono_atom_get_data(atom);
@@ -1707,6 +1714,9 @@ static void netreg_unregister(struct ofono_atom *atom)
 	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
 				notify_emulator_strength, GINT_TO_POINTER(0));
 
+	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+				emulator_remove_handler, "+COPS");
+
 	__ofono_modem_remove_atom_watch(modem, netreg->hfp_watch);
 
 	__ofono_watchlist_free(netreg->status_watches);
@@ -1890,21 +1900,65 @@ static void sim_spn_spdi_changed(int id, void *userdata)
 			sim_spn_read_cb, netreg);
 }
 
-static void emulator_hfp_watch(struct ofono_atom *atom,
-				enum ofono_atom_watch_condition cond,
-				void *data)
+static void emulator_cops_cb(struct ofono_emulator *em,
+			struct ofono_emulator_request *req, void *userdata)
+{
+	struct ofono_netreg *netreg = userdata;
+	struct ofono_error result;
+	int val;
+	char name[17];
+	char buf[32];
+
+	result.error = 0;
+
+	switch (ofono_emulator_request_get_type(req)) {
+	case OFONO_EMULATOR_REQUEST_TYPE_SET:
+		ofono_emulator_request_next_number(req, &val);
+		if (val != 3)
+			goto fail;
+
+		ofono_emulator_request_next_number(req, &val);
+		if (val != 0)
+			goto fail;
+
+		result.type = OFONO_ERROR_TYPE_NO_ERROR;
+		ofono_emulator_send_final(em, &result);
+		break;
+
+	case OFONO_EMULATOR_REQUEST_TYPE_QUERY:
+		strncpy(name, get_operator_display_name(netreg), 16);
+		name[16] = '\0';
+		sprintf(buf, "+COPS: %d,0,\"%s\"", netreg->mode, name);
+		ofono_emulator_send_info(em, buf, TRUE);
+		result.type = OFONO_ERROR_TYPE_NO_ERROR;
+		ofono_emulator_send_final(em, &result);
+		break;
+
+	default:
+fail:
+		result.type = OFONO_ERROR_TYPE_FAILURE;
+		ofono_emulator_send_final(em, &result);
+	};
+}
+
+static void emulator_hfp_init(struct ofono_atom *atom, void *data)
 {
 	struct ofono_netreg *netreg = data;
-	struct ofono_modem *modem = __ofono_atom_get_modem(netreg->atom);
+	struct ofono_emulator *em = __ofono_atom_get_data(atom);
 
-	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
-		__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
-				notify_emulator_status,
-				GINT_TO_POINTER(netreg->status));
-		__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
-				notify_emulator_strength,
+	notify_emulator_status(atom, GINT_TO_POINTER(netreg->status));
+	notify_emulator_strength(atom,
 				GINT_TO_POINTER(netreg->signal_strength));
-	}
+
+	ofono_emulator_add_handler(em, "+COPS", emulator_cops_cb, data, NULL);
+}
+
+static void emulator_hfp_watch(struct ofono_atom *atom,
+				enum ofono_atom_watch_condition cond,
+				void *data)
+{
+	if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED)
+		emulator_hfp_init(atom, data);
 }
 
 void ofono_netreg_register(struct ofono_netreg *netreg)
@@ -1968,6 +2022,9 @@ void ofono_netreg_register(struct ofono_netreg *netreg)
 	netreg->hfp_watch = __ofono_modem_add_atom_watch(modem,
 					OFONO_ATOM_TYPE_EMULATOR_HFP,
 					emulator_hfp_watch, netreg, NULL);
+
+	__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
+					emulator_hfp_init, netreg);
 }
 
 void ofono_netreg_remove(struct ofono_netreg *netreg)
-- 
1.7.1


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

end of thread, other threads:[~2011-03-30  2:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-22 10:50 [PATCH v3] netreg: add +COPS support for HFP emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-03-30  2:54 ` 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.