From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH v2] netreg: add +COPS support for HFP emulator
Date: Mon, 21 Mar 2011 15:40:47 +0100 [thread overview]
Message-ID: <1300718447-8033-1-git-send-email-frederic.danis@linux.intel.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 4007 bytes --]
---
src/network.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/src/network.c b/src/network.c
index 2d0a9f8..76036a5 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,12 +1900,54 @@ static void sim_spn_spdi_changed(int id, void *userdata)
sim_spn_read_cb, netreg);
}
+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_watch(struct ofono_atom *atom,
enum ofono_atom_watch_condition cond,
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,
@@ -1904,6 +1956,9 @@ static void emulator_hfp_watch(struct ofono_atom *atom,
__ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP,
notify_emulator_strength,
GINT_TO_POINTER(netreg->signal_strength));
+
+ ofono_emulator_add_handler(em, "+COPS", emulator_cops_cb, data,
+ NULL);
}
}
@@ -1913,6 +1968,7 @@ void ofono_netreg_register(struct ofono_netreg *netreg)
struct ofono_modem *modem = __ofono_atom_get_modem(netreg->atom);
const char *path = __ofono_atom_get_path(netreg->atom);
struct ofono_atom *sim_atom;
+ struct ofono_atom *hfp_atom;
if (!g_dbus_register_interface(conn, path,
OFONO_NETWORK_REGISTRATION_INTERFACE,
@@ -1968,6 +2024,13 @@ 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);
+
+ hfp_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP);
+
+ if (hfp_atom && __ofono_atom_get_registered(hfp_atom))
+ emulator_hfp_watch(hfp_atom,
+ OFONO_ATOM_WATCH_CONDITION_REGISTERED,
+ netreg);
}
void ofono_netreg_remove(struct ofono_netreg *netreg)
--
1.7.1
next reply other threads:[~2011-03-21 14:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-21 14:40 =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2011-03-21 19:13 ` [PATCH v2] netreg: add +COPS support for HFP emulator Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1300718447-8033-1-git-send-email-frederic.danis@linux.intel.com \
--to=frederic.danis@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.