* [PATCH v2 0/3] bluetooth: add CIND and CIEV support in HFP AG
@ 2011-02-22 15:40 =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 15:40 ` [PATCH 1/3] emulator: add indicator support API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 15:40 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 443 bytes --]
Add indicator support in emulator atom
Add CIND and CIEV support for HFP AG
Frédéric Danis (3):
emulator: add indicator support API
emulator: add support of indicators
emulator: add CIND support
include/emulator.h | 11 +++++
src/emulator.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/network.c | 74 ++++++++++++++++++++++++++++++-
3 files changed, 208 insertions(+), 1 deletions(-)
^ permalink raw reply [flat|nested] 8+ messages in thread* [PATCH 1/3] emulator: add indicator support API 2011-02-22 15:40 [PATCH v2 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 15:40 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 15:40 ` [PATCH 2/3] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 15:40 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2 siblings, 0 replies; 8+ messages in thread From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 15:40 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 1055 bytes --] --- include/emulator.h | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/include/emulator.h b/include/emulator.h index 12477f0..71b7c24 100644 --- a/include/emulator.h +++ b/include/emulator.h @@ -28,6 +28,14 @@ extern "C" { #include <ofono/types.h> +#define OFONO_EMULATOR_IND_BATTERY "battchg" +#define OFONO_EMULATOR_IND_CALL "call" +#define OFONO_EMULATOR_IND_CALLHELD "callheld" +#define OFONO_EMULATOR_IND_CALLSETUP "callsetup" +#define OFONO_EMULATOR_IND_ROAMING "roam" +#define OFONO_EMULATOR_IND_SERVICE "service" +#define OFONO_EMULATOR_IND_SIGNAL "signal" + struct ofono_emulator; struct ofono_emulator_request; @@ -82,6 +90,9 @@ const char *ofono_emulator_request_get_raw(struct ofono_emulator_request *req); enum ofono_emulator_request_type ofono_emulator_request_get_type( struct ofono_emulator_request *req); +void ofono_emulator_set_indicator(struct ofono_emulator *em, + const char *name, int value); + #ifdef __cplusplus } #endif -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] emulator: add support of indicators 2011-02-22 15:40 [PATCH v2 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 15:40 ` [PATCH 1/3] emulator: add indicator support API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 15:40 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 18:28 ` Denis Kenzior 2011-02-22 15:40 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2 siblings, 1 reply; 8+ messages in thread From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 15:40 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 7762 bytes --] --- src/emulator.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/network.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 1 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index b4a4c57..7a46d2a 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -24,6 +24,7 @@ #endif #include <stdio.h> +#include <string.h> #include <glib.h> @@ -42,8 +43,17 @@ struct ofono_emulator { GAtServer *server; GAtPPP *ppp; guint source; + GSList *indicators; }; +struct indicator { + const char *name; + int value; + int min; + int max; +}; + + static void emulator_debug(const char *str, void *data) { ofono_info("%s: %s\n", (char *)data, str); @@ -163,6 +173,25 @@ error: g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR); } +static void emulator_add_indicator(struct ofono_emulator *em, const char* name, + int min, int max, int dflt) +{ + struct indicator *ind; + + ind = g_try_new0(struct indicator, 1); + if (ind == NULL) { + ofono_error("Unable to allocate indicator structure"); + return; + } + + ind->name = name; + ind->min = min; + ind->max = max; + ind->value = dflt; + + em->indicators = g_slist_append(em->indicators, ind); +} + static void emulator_unregister(struct ofono_atom *atom) { struct ofono_emulator *em = __ofono_atom_get_data(atom); @@ -174,6 +203,10 @@ static void emulator_unregister(struct ofono_atom *atom) em->source = 0; } + g_slist_foreach(em->indicators, (GFunc) g_free, NULL); + g_slist_free(em->indicators); + em->indicators = NULL; + g_at_server_unref(em->server); em->server = NULL; } @@ -199,6 +232,13 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd) g_at_server_set_disconnect_function(em->server, emulator_disconnect, em); + if (em->type == OFONO_EMULATOR_TYPE_HFP) { + emulator_add_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0, 1, 0); + emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0); + emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0); + emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5); + } + __ofono_atom_register(em->atom, emulator_unregister); if (em->type == OFONO_EMULATOR_TYPE_DUN) @@ -397,3 +437,31 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type( { return req->type; } + +void ofono_emulator_set_indicator(struct ofono_emulator *em, + const char *name, int value) +{ + GSList *l; + int i; + char buf[20]; + + i = 1; + for (l = em->indicators; l; l = l->next) { + struct indicator *ind = l->data; + + if (!strcmp(ind->name, name)) { + if ((ind->value == value) || (value < ind->min) + || (value > ind->max)) + return; + + ind->value = value; + + sprintf(buf, "+CIEV: %d,%d", i, ind->value); + g_at_server_send_info(em->server, buf, TRUE); + + break; + } + + i++; + } +} diff --git a/src/network.c b/src/network.c index c059906..8124319 100644 --- a/src/network.c +++ b/src/network.c @@ -36,6 +36,7 @@ #include "simutil.h" #include "util.h" #include "storage.h" +#include "emulator.h" #define NETWORK_REGISTRATION_FLAG_HOME_SHOW_PLMN 0x1 #define NETWORK_REGISTRATION_FLAG_ROAMING_SHOW_SPN 0x2 @@ -82,6 +83,7 @@ struct ofono_netreg { const struct ofono_netreg_driver *driver; void *driver_data; struct ofono_atom *atom; + unsigned int hfp_watch; }; struct network_operator_data { @@ -1287,15 +1289,42 @@ static void signal_strength_callback(const struct ofono_error *error, ofono_netreg_strength_notify(netreg, strength); } +static void notify_emulator_status(struct ofono_atom *atom, void *data) +{ + struct ofono_emulator *em = __ofono_atom_get_data(atom); + + switch (GPOINTER_TO_INT(data)) { + case NETWORK_REGISTRATION_STATUS_REGISTERED: + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 1); + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0); + break; + case NETWORK_REGISTRATION_STATUS_ROAMING: + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 1); + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 1); + break; + default: + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0); + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0); + } +} + void ofono_netreg_status_notify(struct ofono_netreg *netreg, int status, int lac, int ci, int tech) { if (netreg == NULL) return; - if (netreg->status != status) + if (netreg->status != status) { + struct ofono_modem *modem; + set_registration_status(netreg, status); + modem = __ofono_atom_get_modem(netreg->atom); + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, + notify_emulator_status, + GINT_TO_POINTER(netreg->status)); + } + if (netreg->location != lac) set_registration_location(netreg, lac); @@ -1375,9 +1404,18 @@ static void init_registration_status(const struct ofono_error *error, } } +static void notify_emulator_strength(struct ofono_atom *atom, void *data) +{ + struct ofono_emulator *em = __ofono_atom_get_data(atom); + + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SIGNAL, + (GPOINTER_TO_INT(data) + 20) / 21); +} + void ofono_netreg_strength_notify(struct ofono_netreg *netreg, int strength) { DBusConnection *conn = ofono_dbus_get_connection(); + struct ofono_modem *modem; if (netreg->signal_strength == strength) return; @@ -1401,6 +1439,11 @@ void ofono_netreg_strength_notify(struct ofono_netreg *netreg, int strength) "Strength", DBUS_TYPE_BYTE, &strength); } + + modem = __ofono_atom_get_modem(netreg->atom); + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, + notify_emulator_strength, + GINT_TO_POINTER(netreg->signal_strength)); } static void sim_opl_read_cb(int ok, int length, int record, @@ -1656,6 +1699,14 @@ static void netreg_unregister(struct ofono_atom *atom) const char *path = __ofono_atom_get_path(atom); GSList *l; + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, + notify_emulator_status, + GINT_TO_POINTER(0)); + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, + notify_emulator_strength, GINT_TO_POINTER(0)); + + __ofono_modem_remove_atom_watch(modem, netreg->hfp_watch); + __ofono_watchlist_free(netreg->status_watches); netreg->status_watches = NULL; @@ -1837,6 +1888,23 @@ 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) +{ + struct ofono_netreg *netreg = data; + struct ofono_modem *modem = __ofono_atom_get_modem(netreg->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, + GINT_TO_POINTER(netreg->signal_strength)); + } +} + void ofono_netreg_register(struct ofono_netreg *netreg) { DBusConnection *conn = ofono_dbus_get_connection(); @@ -1894,6 +1962,10 @@ void ofono_netreg_register(struct ofono_netreg *netreg) } __ofono_atom_register(netreg->atom, netreg_unregister); + + netreg->hfp_watch = __ofono_modem_add_atom_watch(modem, + OFONO_ATOM_TYPE_EMULATOR_HFP, + emulator_hfp_watch, netreg, NULL); } void ofono_netreg_remove(struct ofono_netreg *netreg) -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/3] emulator: add support of indicators 2011-02-22 15:40 ` [PATCH 2/3] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 18:28 ` Denis Kenzior 0 siblings, 0 replies; 8+ messages in thread From: Denis Kenzior @ 2011-02-22 18:28 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 8761 bytes --] Hi Frédéric, On 02/22/2011 09:40 AM, Frédéric Danis wrote: > --- > src/emulator.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ > src/network.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 141 insertions(+), 1 deletions(-) > > diff --git a/src/emulator.c b/src/emulator.c > index b4a4c57..7a46d2a 100644 > --- a/src/emulator.c > +++ b/src/emulator.c > @@ -24,6 +24,7 @@ > #endif > > #include <stdio.h> > +#include <string.h> > > #include <glib.h> > > @@ -42,8 +43,17 @@ struct ofono_emulator { > GAtServer *server; > GAtPPP *ppp; > guint source; > + GSList *indicators; Let us use a GHashtable here > }; > > +struct indicator { > + const char *name; You can't actually do this safely, you should be strduping the string. > + int value; > + int min; > + int max; > +}; > + > + Why the double newline? > static void emulator_debug(const char *str, void *data) > { > ofono_info("%s: %s\n", (char *)data, str); > @@ -163,6 +173,25 @@ error: > g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR); > } > > +static void emulator_add_indicator(struct ofono_emulator *em, const char* name, > + int min, int max, int dflt) > +{ > + struct indicator *ind; > + > + ind = g_try_new0(struct indicator, 1); > + if (ind == NULL) { > + ofono_error("Unable to allocate indicator structure"); > + return; > + } > + > + ind->name = name; > + ind->min = min; > + ind->max = max; > + ind->value = dflt; > + > + em->indicators = g_slist_append(em->indicators, ind); > +} > + > static void emulator_unregister(struct ofono_atom *atom) > { > struct ofono_emulator *em = __ofono_atom_get_data(atom); > @@ -174,6 +203,10 @@ static void emulator_unregister(struct ofono_atom *atom) > em->source = 0; > } > > + g_slist_foreach(em->indicators, (GFunc) g_free, NULL); > + g_slist_free(em->indicators); > + em->indicators = NULL; > + > g_at_server_unref(em->server); > em->server = NULL; > } > @@ -199,6 +232,13 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd) > g_at_server_set_disconnect_function(em->server, > emulator_disconnect, em); > > + if (em->type == OFONO_EMULATOR_TYPE_HFP) { > + emulator_add_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0, 1, 0); > + emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0); > + emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0); > + emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5); > + } > + > __ofono_atom_register(em->atom, emulator_unregister); > > if (em->type == OFONO_EMULATOR_TYPE_DUN) > @@ -397,3 +437,31 @@ enum ofono_emulator_request_type ofono_emulator_request_get_type( > { > return req->type; > } > + > +void ofono_emulator_set_indicator(struct ofono_emulator *em, > + const char *name, int value) > +{ > + GSList *l; > + int i; > + char buf[20]; > + > + i = 1; > + for (l = em->indicators; l; l = l->next) { > + struct indicator *ind = l->data; > + > + if (!strcmp(ind->name, name)) { > + if ((ind->value == value) || (value < ind->min) > + || (value > ind->max)) > + return; > + > + ind->value = value; > + > + sprintf(buf, "+CIEV: %d,%d", i, ind->value); > + g_at_server_send_info(em->server, buf, TRUE); > + > + break; > + } > + > + i++; > + } > +} > diff --git a/src/network.c b/src/network.c > index c059906..8124319 100644 > --- a/src/network.c > +++ b/src/network.c > @@ -36,6 +36,7 @@ > #include "simutil.h" > #include "util.h" > #include "storage.h" > +#include "emulator.h" > > #define NETWORK_REGISTRATION_FLAG_HOME_SHOW_PLMN 0x1 > #define NETWORK_REGISTRATION_FLAG_ROAMING_SHOW_SPN 0x2 > @@ -82,6 +83,7 @@ struct ofono_netreg { > const struct ofono_netreg_driver *driver; > void *driver_data; > struct ofono_atom *atom; > + unsigned int hfp_watch; > }; > > struct network_operator_data { > @@ -1287,15 +1289,42 @@ static void signal_strength_callback(const struct ofono_error *error, > ofono_netreg_strength_notify(netreg, strength); > } > > +static void notify_emulator_status(struct ofono_atom *atom, void *data) > +{ > + struct ofono_emulator *em = __ofono_atom_get_data(atom); > + > + switch (GPOINTER_TO_INT(data)) { > + case NETWORK_REGISTRATION_STATUS_REGISTERED: > + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 1); > + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0); > + break; > + case NETWORK_REGISTRATION_STATUS_ROAMING: > + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 1); > + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 1); > + break; > + default: > + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0); > + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0); > + } > +} > + > void ofono_netreg_status_notify(struct ofono_netreg *netreg, int status, > int lac, int ci, int tech) > { > if (netreg == NULL) > return; > > - if (netreg->status != status) > + if (netreg->status != status) { > + struct ofono_modem *modem; > + > set_registration_status(netreg, status); > > + modem = __ofono_atom_get_modem(netreg->atom); > + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, > + notify_emulator_status, > + GINT_TO_POINTER(netreg->status)); > + } > + > if (netreg->location != lac) > set_registration_location(netreg, lac); > > @@ -1375,9 +1404,18 @@ static void init_registration_status(const struct ofono_error *error, > } > } > > +static void notify_emulator_strength(struct ofono_atom *atom, void *data) > +{ > + struct ofono_emulator *em = __ofono_atom_get_data(atom); > + > + ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_SIGNAL, > + (GPOINTER_TO_INT(data) + 20) / 21); > +} > + Please note that strength can actually be negative (e.g. unknown) so you should handle this case. Also, the scale seems assymetric to me. Shouldn't you do something like: value = strength > 0 ? (strength - 1) / 20 + 1 : 0? > void ofono_netreg_strength_notify(struct ofono_netreg *netreg, int strength) > { > DBusConnection *conn = ofono_dbus_get_connection(); > + struct ofono_modem *modem; > > if (netreg->signal_strength == strength) > return; > @@ -1401,6 +1439,11 @@ void ofono_netreg_strength_notify(struct ofono_netreg *netreg, int strength) > "Strength", DBUS_TYPE_BYTE, > &strength); > } > + > + modem = __ofono_atom_get_modem(netreg->atom); > + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, > + notify_emulator_strength, > + GINT_TO_POINTER(netreg->signal_strength)); > } > > static void sim_opl_read_cb(int ok, int length, int record, > @@ -1656,6 +1699,14 @@ static void netreg_unregister(struct ofono_atom *atom) > const char *path = __ofono_atom_get_path(atom); > GSList *l; > > + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, > + notify_emulator_status, > + GINT_TO_POINTER(0)); > + __ofono_modem_foreach_atom(modem, OFONO_ATOM_TYPE_EMULATOR_HFP, > + notify_emulator_strength, GINT_TO_POINTER(0)); > + > + __ofono_modem_remove_atom_watch(modem, netreg->hfp_watch); > + > __ofono_watchlist_free(netreg->status_watches); > netreg->status_watches = NULL; > > @@ -1837,6 +1888,23 @@ 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) > +{ > + struct ofono_netreg *netreg = data; > + struct ofono_modem *modem = __ofono_atom_get_modem(netreg->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, > + GINT_TO_POINTER(netreg->signal_strength)); > + } > +} > + > void ofono_netreg_register(struct ofono_netreg *netreg) > { > DBusConnection *conn = ofono_dbus_get_connection(); > @@ -1894,6 +1962,10 @@ void ofono_netreg_register(struct ofono_netreg *netreg) > } > > __ofono_atom_register(netreg->atom, netreg_unregister); > + > + netreg->hfp_watch = __ofono_modem_add_atom_watch(modem, > + OFONO_ATOM_TYPE_EMULATOR_HFP, > + emulator_hfp_watch, netreg, NULL); > } > > void ofono_netreg_remove(struct ofono_netreg *netreg) Otherwise looks good. Regards, -Denis ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] emulator: add CIND support 2011-02-22 15:40 [PATCH v2 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 15:40 ` [PATCH 1/3] emulator: add indicator support API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 15:40 ` [PATCH 2/3] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 15:40 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 18:39 ` Denis Kenzior 2 siblings, 1 reply; 8+ messages in thread From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 15:40 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 2684 bytes --] --- src/emulator.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+), 0 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index 7a46d2a..ece38ab 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -51,6 +51,7 @@ struct indicator { int value; int min; int max; + char separator; }; @@ -173,6 +174,58 @@ error: g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR); } +static void cind_cb(GAtServer *server, GAtServerRequestType type, + GAtResult *result, gpointer user_data) +{ + struct ofono_emulator *em = user_data; + GSList *l = em->indicators; + struct indicator *ind = l->data; + GString *gstr; + char *buf; + + switch (type) { + case G_AT_SERVER_REQUEST_TYPE_QUERY: + gstr = g_string_new("+CIND: "); + g_string_append_printf(gstr, "%d", ind->value); + + l = l->next; + while (l) { + ind = l->data; + g_string_append_printf(gstr, ",%d", ind->value); + l = l->next; + } + buf = g_string_free(gstr, FALSE); + + g_at_server_send_info(em->server, buf, FALSE); + g_free(buf); + g_at_server_send_final(server, G_AT_SERVER_RESULT_OK); + break; + + case G_AT_SERVER_REQUEST_TYPE_SUPPORT: + gstr = g_string_new("+CIND: "); + g_string_append_printf(gstr, "(\"%s\",(%d%c%d))", + ind->name, ind->min, ind->separator, ind->max); + + l = l->next; + while (l) { + ind = l->data; + g_string_append_printf(gstr, ",(\"%s\",(%d%c%d))", + ind->name, ind->min, ind->separator, ind->max); + l = l->next; + } + buf = g_string_free(gstr, FALSE); + + g_at_server_send_info(server, buf, FALSE); + g_free(buf); + g_at_server_send_final(server, G_AT_SERVER_RESULT_OK); + break; + + default: + g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR); + break; + } +} + static void emulator_add_indicator(struct ofono_emulator *em, const char* name, int min, int max, int dflt) { @@ -188,6 +241,7 @@ static void emulator_add_indicator(struct ofono_emulator *em, const char* name, ind->min = min; ind->max = max; ind->value = dflt; + ind->separator = ((max - min) == 1) ? ',' : '-'; em->indicators = g_slist_append(em->indicators, ind); } @@ -237,6 +291,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd) emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0); emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0); emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5); + + g_at_server_register(em->server, "+CIND", cind_cb, em, NULL); } __ofono_atom_register(em->atom, emulator_unregister); -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] emulator: add CIND support 2011-02-22 15:40 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-22 18:39 ` Denis Kenzior 0 siblings, 0 replies; 8+ messages in thread From: Denis Kenzior @ 2011-02-22 18:39 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 3419 bytes --] Hi Frédéric, On 02/22/2011 09:40 AM, Frédéric Danis wrote: > --- > src/emulator.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 files changed, 56 insertions(+), 0 deletions(-) > > diff --git a/src/emulator.c b/src/emulator.c > index 7a46d2a..ece38ab 100644 > --- a/src/emulator.c > +++ b/src/emulator.c > @@ -51,6 +51,7 @@ struct indicator { > int value; > int min; > int max; > + char separator; > }; > > > @@ -173,6 +174,58 @@ error: > g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR); > } > > +static void cind_cb(GAtServer *server, GAtServerRequestType type, > + GAtResult *result, gpointer user_data) > +{ > + struct ofono_emulator *em = user_data; > + GSList *l = em->indicators; > + struct indicator *ind = l->data; > + GString *gstr; > + char *buf; I prefer we do a simple pre-calculation of the space required. If it helps the implementation, limit the min and max values to something reasonable, e.g. 0-999. > + > + switch (type) { > + case G_AT_SERVER_REQUEST_TYPE_QUERY: > + gstr = g_string_new("+CIND: "); > + g_string_append_printf(gstr, "%d", ind->value); > + > + l = l->next; doc/coding-style.txt M1. > + while (l) { These style loops look more compact using a for loop, e.g.: for (l = em->indicators; l; l = l->next) { ... } > + ind = l->data; > + g_string_append_printf(gstr, ",%d", ind->value); > + l = l->next; > + } > + buf = g_string_free(gstr, FALSE); doc/coding-style.txt M1 > + > + g_at_server_send_info(em->server, buf, FALSE); > + g_free(buf); > + g_at_server_send_final(server, G_AT_SERVER_RESULT_OK); > + break; > + > + case G_AT_SERVER_REQUEST_TYPE_SUPPORT: > + gstr = g_string_new("+CIND: "); > + g_string_append_printf(gstr, "(\"%s\",(%d%c%d))", > + ind->name, ind->min, ind->separator, ind->max); doc/coding-style.txt M4 > + > + l = l->next; > + while (l) { > + ind = l->data; > + g_string_append_printf(gstr, ",(\"%s\",(%d%c%d))", > + ind->name, ind->min, ind->separator, ind->max); > + l = l->next; > + } > + buf = g_string_free(gstr, FALSE); > + > + g_at_server_send_info(server, buf, FALSE); > + g_free(buf); > + g_at_server_send_final(server, G_AT_SERVER_RESULT_OK); > + break; > + > + default: > + g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR); > + break; > + } > +} > + > static void emulator_add_indicator(struct ofono_emulator *em, const char* name, > int min, int max, int dflt) > { > @@ -188,6 +241,7 @@ static void emulator_add_indicator(struct ofono_emulator *em, const char* name, > ind->min = min; > ind->max = max; > ind->value = dflt; > + ind->separator = ((max - min) == 1) ? ',' : '-'; I prefer you do this magic inside cind_cb and avoid storing it inside the indicator structure. > > em->indicators = g_slist_append(em->indicators, ind); > } > @@ -237,6 +291,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd) > emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0); > emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0); > emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5); > + > + g_at_server_register(em->server, "+CIND", cind_cb, em, NULL); > } > > __ofono_atom_register(em->atom, emulator_unregister); Regards, -Denis ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v3 0/3] bluetooth: add CIND and CIEV support in HFP AG @ 2011-02-23 15:48 =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-23 15:48 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 0 siblings, 1 reply; 8+ messages in thread From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-23 15:48 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 439 bytes --] Add indicator support in emulator atom Add CIND and CIEV support for HFP AG Frédéric Danis (3): emulator: add indicator support API emulator: add support of indicators emulator: add CIND support include/emulator.h | 11 ++++ src/emulator.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/network.c | 77 +++++++++++++++++++++++++++- 3 files changed, 232 insertions(+), 1 deletions(-) ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] emulator: add CIND support 2011-02-23 15:48 [PATCH v3 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-23 15:48 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 0 siblings, 0 replies; 8+ messages in thread From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-23 15:48 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 2581 bytes --] --- src/emulator.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 73 insertions(+), 0 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index 77113e6..3c2154b 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -172,6 +172,77 @@ error: g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR); } +static void cind_cb(GAtServer *server, GAtServerRequestType type, + GAtResult *result, gpointer user_data) +{ + struct ofono_emulator *em = user_data; + GSList *l; + struct indicator *ind; + gsize size; + int len; + char *buf; + char *tmp; + + switch (type) { + case G_AT_SERVER_REQUEST_TYPE_QUERY: + size = 7 + (g_slist_length(em->indicators) * 4) + 1; + buf = g_try_malloc0(size); + if (buf == NULL) + goto fail; + + len = sprintf(buf, "+CIND: "); + tmp = buf + len; + + for (l = em->indicators; l; l = l->next) { + ind = l->data; + len = sprintf(tmp, "%s%d", + l == em->indicators ? "" : ",", + ind->value); + tmp = tmp + len; + } + + g_at_server_send_info(em->server, buf, FALSE); + g_free(buf); + g_at_server_send_final(server, G_AT_SERVER_RESULT_OK); + break; + + case G_AT_SERVER_REQUEST_TYPE_SUPPORT: + size = 8; + + for (l = em->indicators; l; l = l->next) { + ind = l->data; + size += strlen(ind->name) + 15; + } + + buf = g_try_malloc0(size); + if (buf == NULL) + goto fail; + + len = sprintf(buf, "+CIND: "); + tmp = buf + len; + + for (l = em->indicators; l; l = l->next) { + ind = l->data; + len = sprintf(tmp, "%s(\"%s\",(%d%c%d))", + l == em->indicators ? "" : ",", + ind->name, ind->min, + (ind->max - ind->min) == 1 ? ',' : '-', + ind->max); + tmp = tmp + len; + } + + g_at_server_send_info(server, buf, FALSE); + g_free(buf); + g_at_server_send_final(server, G_AT_SERVER_RESULT_OK); + break; + + default: +fail: + g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR); + break; + } +} + static void emulator_add_indicator(struct ofono_emulator *em, const char* name, int min, int max, int dflt) { @@ -241,6 +312,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd) emulator_add_indicator(em, OFONO_EMULATOR_IND_SIGNAL, 0, 5, 0); emulator_add_indicator(em, OFONO_EMULATOR_IND_ROAMING, 0, 1, 0); emulator_add_indicator(em, OFONO_EMULATOR_IND_BATTERY, 0, 5, 5); + + g_at_server_register(em->server, "+CIND", cind_cb, em, NULL); } __ofono_atom_register(em->atom, emulator_unregister); -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 0/3] bluetooth: add HFP AG plugin @ 2011-02-15 15:06 =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-15 15:06 ` [PATCH 3/3] emulator: add +CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 0 siblings, 1 reply; 8+ messages in thread From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-15 15:06 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 595 bytes --] Add the HFP AG plugin Add partial support for +CIND command: currently, only network registration part is suported (status and roaming) Frédéric Danis (3): bluetooth: add HFP AG plugin emulator: add HFP emulator type emulator: add +CIND support Makefile.am | 3 + include/emulator.h | 1 + plugins/hfp_ag.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/emulator.c | 132 ++++++++++++++++++++++++++++++++++++- src/ofono.h | 1 + 5 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 plugins/hfp_ag.c ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 3/3] emulator: add +CIND support 2011-02-15 15:06 [PATCH 0/3] bluetooth: add HFP AG plugin =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-15 15:06 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 0 siblings, 0 replies; 8+ messages in thread From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis @ 2011-02-15 15:06 UTC (permalink / raw) To: ofono [-- Attachment #1: Type: text/plain, Size: 4338 bytes --] currently, only network registration is supported (service, roaming) --- src/emulator.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 118 insertions(+), 0 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index 232b314..96c55d4 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -23,15 +23,21 @@ #include <config.h> #endif +#include <stdio.h> #include <glib.h> #include "ofono.h" +#include "common.h" #include "gatserver.h" struct ofono_emulator { struct ofono_atom *atom; enum ofono_emulator_type type; GAtServer *server; + struct ofono_netreg *netreg; + unsigned int netreg_watch; + unsigned int status_watch; + int netreg_status; }; static void emulator_debug(const char *str, void *data) @@ -39,6 +45,98 @@ static void emulator_debug(const char *str, void *data) ofono_info("%s: %s\n", (char *)data, str); } +static void cind_update(struct ofono_emulator *em, gboolean final) +{ + int status; + int roam; + char buf[30]; + + switch (em->netreg_status) { + case NETWORK_REGISTRATION_STATUS_REGISTERED: + status = 1; + roam = 0; + break; + case NETWORK_REGISTRATION_STATUS_ROAMING: + status = 1; + roam = 1; + break; + default: + status = 0; + roam = 0; + break; + } + + call = 0; + callsetup = 0; + callheld = 0; + signal = (em->netreg_signal + 20) / 21; + battchg = 0; + + sprintf(buf, "+CIND: %d,0,0,0,0,%d,0", status, roam); + g_at_server_send_info(em->server, buf, final); +} + +static void netreg_status_changed(int status, int lac, int ci, int tech, + const char *mcc, const char *mnc, + void *data) +{ + struct ofono_emulator *em = data; + + DBG("%d", status); + + if (em->netreg_status == status) + return; + + em->netreg_status = status; + + cind_update(em, TRUE); +} + +static void netreg_watch(struct ofono_atom *atom, + enum ofono_atom_watch_condition cond, + void *data) +{ + struct ofono_emulator *em = data; + + if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) { + em->status_watch = 0; + em->netreg_status = NETWORK_REGISTRATION_STATUS_NOT_REGISTERED; + return; + } + + em->netreg = __ofono_atom_get_data(atom); + em->netreg_status = ofono_netreg_get_status(em->netreg); + em->status_watch = __ofono_netreg_add_status_watch(em->netreg, + netreg_status_changed, em, NULL); + + cind_update(em, TRUE); +} + +static void at_cind_cb(GAtServerRequestType type, GAtResult *result, + gpointer user_data) +{ + struct ofono_emulator *em = user_data; + + switch (type) { + case G_AT_SERVER_REQUEST_TYPE_QUERY: + cind_update(em, FALSE); + g_at_server_send_final(em->server, G_AT_SERVER_RESULT_OK); + break; + + case G_AT_SERVER_REQUEST_TYPE_SUPPORT: + g_at_server_send_info(em->server, "+CIND: (\"service\",(0,1))" + ",(\"call\",(0,1)),(\"callsetup\",(0-3))" + ",(\"callheld\",(0-2)),(\"signal\",(0-5))" + ",(\"roam\",(0,1)),(\"battchg\",(0-5))", FALSE); + g_at_server_send_final(em->server, G_AT_SERVER_RESULT_OK); + break; + + default: + g_at_server_send_final(em->server, G_AT_SERVER_RESULT_ERROR); + break; + } +} + static void emulator_disconnect(gpointer user_data) { struct ofono_emulator *em = user_data; @@ -61,6 +159,8 @@ static void emulator_unregister(struct ofono_atom *atom) void ofono_emulator_register(struct ofono_emulator *em, int fd) { GIOChannel *io; + struct ofono_modem *modem; + struct ofono_atom *netreg_atom; DBG("%p, %d", em, fd); @@ -77,6 +177,24 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd) g_at_server_set_disconnect_function(em->server, emulator_disconnect, em); + if (em->type == OFONO_EMULATOR_TYPE_HFP) { + g_at_server_register(em->server, "+CIND", at_cind_cb, em, NULL); + + modem = __ofono_atom_get_modem(em->atom); + + em->netreg_watch = __ofono_modem_add_atom_watch(modem, + OFONO_ATOM_TYPE_NETREG, + netreg_watch, em, NULL); + + netreg_atom = __ofono_modem_find_atom(modem, + OFONO_ATOM_TYPE_NETREG); + + if (netreg_atom && __ofono_atom_get_registered(netreg_atom)) + netreg_watch(netreg_atom, + OFONO_ATOM_WATCH_CONDITION_REGISTERED, + em); + } + __ofono_atom_register(em->atom, emulator_unregister); } -- 1.7.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-02-23 15:48 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-22 15:40 [PATCH v2 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 15:40 ` [PATCH 1/3] emulator: add indicator support API =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 15:40 ` [PATCH 2/3] emulator: add support of indicators =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 18:28 ` Denis Kenzior 2011-02-22 15:40 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-22 18:39 ` Denis Kenzior -- strict thread matches above, loose matches on Subject: below -- 2011-02-23 15:48 [PATCH v3 0/3] bluetooth: add CIND and CIEV support in HFP AG =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-23 15:48 ` [PATCH 3/3] emulator: add CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-15 15:06 [PATCH 0/3] bluetooth: add HFP AG plugin =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis 2011-02-15 15:06 ` [PATCH 3/3] emulator: add +CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
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.