* [PATCH 1/3] bluetooth: add HFP AG plugin
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
2011-02-15 17:10 ` Gustavo F. Padovan
2011-02-16 6:24 ` Denis Kenzior
2011-02-15 15:06 ` [PATCH 2/3] emulator: add HFP emulator type =?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
2 siblings, 2 replies; 10+ 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: 5453 bytes --]
---
Makefile.am | 3 +
plugins/hfp_ag.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 174 insertions(+), 0 deletions(-)
create mode 100644 plugins/hfp_ag.c
diff --git a/Makefile.am b/Makefile.am
index 1d7f32b..6657f4c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -324,6 +324,9 @@ builtin_sources += plugins/bluetooth.c plugins/bluetooth.h
builtin_modules += hfp
builtin_sources += plugins/hfp.c plugins/bluetooth.h
+builtin_modules += hfp_ag
+builtin_sources += plugins/hfp_ag.c plugins/bluetooth.h
+
builtin_sources += $(btio_sources)
builtin_cflags += @BLUEZ_CFLAGS@
builtin_libadd += @BLUEZ_LIBS@
diff --git a/plugins/hfp_ag.c b/plugins/hfp_ag.c
new file mode 100644
index 0000000..c43275b
--- /dev/null
+++ b/plugins/hfp_ag.c
@@ -0,0 +1,171 @@
+/*
+ * oFono - Open Source Telephony
+ *
+ * Copyright (C) 2010 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 <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <glib.h>
+#include <ofono.h>
+
+#define OFONO_API_SUBJECT_TO_CHANGE
+#include <ofono/plugin.h>
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <gdbus.h>
+
+#include "bluetooth.h"
+
+#define HFP_AG_CHANNEL 13
+
+static struct server *server;
+static guint modemwatch_id;
+static GList *modems;
+static guint channel_watch;
+
+static const gchar *hfp_ag_record =
+"<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
+<record> \
+ <attribute id=\"0x0001\"> \
+ <sequence> \
+ <uuid value=\"0x111F\"/> \
+ <uuid value=\"0x1203\"/> \
+ </sequence> \
+ </attribute> \
+ \
+ <attribute id=\"0x0004\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x0100\"/> \
+ </sequence> \
+ <sequence> \
+ <uuid value=\"0x0003\"/> \
+ <uint8 value=\"13\" name=\"channel\"/> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ \
+ <attribute id=\"0x0009\"> \
+ <sequence> \
+ <sequence> \
+ <uuid value=\"0x111E\"/> \
+ <uint16 value=\"0x0105\" name=\"version\"/> \
+ </sequence> \
+ </sequence> \
+ </attribute> \
+ \
+ <attribute id=\"0x0100\"> \
+ <text value=\"Hands-Free Audio Gateway\" name=\"name\"/> \
+ </attribute> \
+ \
+ <attribute id=\"0x0301\"> \
+ <uint8 value=\"0x01\" /> \
+ </attribute> \
+ \
+ <attribute id=\"0x0311\"> \
+ <uint16 value=\"0x0000\" /> \
+ </attribute> \
+</record>";
+
+static gboolean hfp_ag_disconnect_cb(GIOChannel *io, GIOCondition cond,
+ gpointer user_data)
+{
+ return FALSE;
+}
+
+static void hfp_ag_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
+{
+ DBG("");
+
+ if (err) {
+ DBG("%s", err->message);
+ goto failed;
+ }
+
+ channel_watch = g_io_add_watch(io, G_IO_NVAL | G_IO_HUP | G_IO_ERR,
+ hfp_ag_disconnect_cb, NULL);
+
+ return;
+
+failed:
+ g_io_channel_shutdown(io, TRUE, NULL);
+}
+
+static void voicecall_watch(struct ofono_atom *atom,
+ enum ofono_atom_watch_condition cond,
+ void *data)
+{
+ struct ofono_modem *modem = data;
+
+ if (cond == OFONO_ATOM_WATCH_CONDITION_REGISTERED) {
+ modems = g_list_append(modems, modem);
+
+ if (modems->next == NULL)
+ server = bluetooth_register_server(HFP_AG_CHANNEL,
+ hfp_ag_record,
+ hfp_ag_connect_cb,
+ NULL);
+ } else {
+ modems = g_list_remove(modems, modem);
+ if (modems == NULL && server != NULL) {
+ bluetooth_unregister_server(server);
+ server = NULL;
+ }
+ }
+}
+
+static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
+{
+ DBG("modem: %p, added: %d", modem, added);
+
+ if (added == FALSE)
+ return;
+
+ __ofono_modem_add_atom_watch(modem, OFONO_ATOM_TYPE_VOICECALL,
+ voicecall_watch, modem, NULL);
+}
+
+static void call_modemwatch(struct ofono_modem *modem, void *user)
+{
+ modem_watch(modem, TRUE, user);
+}
+
+static int hfp_ag_init()
+{
+ modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
+ __ofono_modem_foreach(call_modemwatch, NULL);
+
+ return 0;
+}
+
+static void hfp_ag_exit()
+{
+ __ofono_modemwatch_remove(modemwatch_id);
+
+ if (server) {
+ bluetooth_unregister_server(server);
+ server = NULL;
+ }
+}
+
+OFONO_PLUGIN_DEFINE(hfp_ag, "Hands-Free Audio Gateway Profile Plugins", VERSION,
+ OFONO_PLUGIN_PRIORITY_DEFAULT, hfp_ag_init, hfp_ag_exit)
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/3] bluetooth: add HFP AG plugin
2011-02-15 15:06 ` [PATCH 1/3] " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
@ 2011-02-15 17:10 ` Gustavo F. Padovan
2011-02-16 6:24 ` Denis Kenzior
1 sibling, 0 replies; 10+ messages in thread
From: Gustavo F. Padovan @ 2011-02-15 17:10 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 428 bytes --]
Hi Frédéric,
* Frédéric Danis <frederic.danis@linux.intel.com> [2011-02-15 16:06:31 +0100]:
> ---
> Makefile.am | 3 +
> plugins/hfp_ag.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 174 insertions(+), 0 deletions(-)
> create mode 100644 plugins/hfp_ag.c
Please also send a patches that renames hfp.c to hfp_hf.c
--
Gustavo F. Padovan
http://profusion.mobi
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] bluetooth: add HFP AG plugin
2011-02-15 15:06 ` [PATCH 1/3] " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-15 17:10 ` Gustavo F. Padovan
@ 2011-02-16 6:24 ` Denis Kenzior
1 sibling, 0 replies; 10+ messages in thread
From: Denis Kenzior @ 2011-02-16 6:24 UTC (permalink / raw)
To: ofono
[-- Attachment #1: Type: text/plain, Size: 341 bytes --]
Hi Frédéric.
On 02/15/2011 09:06 AM, Frédéric Danis wrote:
> ---
> Makefile.am | 3 +
> plugins/hfp_ag.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 174 insertions(+), 0 deletions(-)
> create mode 100644 plugins/hfp_ag.c
>
Patch has been applied, thanks.
Regards,
-Denis
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/3] emulator: add HFP emulator type
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 1/3] " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
@ 2011-02-15 15:06 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-16 6:25 ` Denis Kenzior
2011-02-15 15:06 ` [PATCH 3/3] emulator: add +CIND support =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2 siblings, 1 reply; 10+ 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: 2913 bytes --]
---
include/emulator.h | 1 +
plugins/hfp_ag.c | 17 +++++++++++++++++
src/emulator.c | 14 ++++++++++++--
src/ofono.h | 1 +
4 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/include/emulator.h b/include/emulator.h
index 2334e02..a080399 100644
--- a/include/emulator.h
+++ b/include/emulator.h
@@ -32,6 +32,7 @@ struct ofono_emulator;
enum ofono_emulator_type {
OFONO_EMULATOR_TYPE_DUN,
+ OFONO_EMULATOR_TYPE_HFP,
};
struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
diff --git a/plugins/hfp_ag.c b/plugins/hfp_ag.c
index c43275b..a45c8c1 100644
--- a/plugins/hfp_ag.c
+++ b/plugins/hfp_ag.c
@@ -94,6 +94,10 @@ static gboolean hfp_ag_disconnect_cb(GIOChannel *io, GIOCondition cond,
static void hfp_ag_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
{
+ struct ofono_modem *modem;
+ struct ofono_emulator *em;
+ int fd;
+
DBG("");
if (err) {
@@ -101,6 +105,19 @@ static void hfp_ag_connect_cb(GIOChannel *io, GError *err, gpointer user_data)
goto failed;
}
+ /* Pick the first voicecall capable modem */
+ modem = modems->data;
+ if (modem == NULL)
+ goto failed;
+ DBG("Picked modem %p for emulator", modem);
+
+ em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HFP);
+ if (em == NULL)
+ goto failed;
+
+ fd = g_io_channel_unix_get_fd(io);
+ ofono_emulator_register(em, fd);
+
channel_watch = g_io_add_watch(io, G_IO_NVAL | G_IO_HUP | G_IO_ERR,
hfp_ag_disconnect_cb, NULL);
diff --git a/src/emulator.c b/src/emulator.c
index c49283d..232b314 100644
--- a/src/emulator.c
+++ b/src/emulator.c
@@ -30,6 +30,7 @@
struct ofono_emulator {
struct ofono_atom *atom;
+ enum ofono_emulator_type type;
GAtServer *server;
};
@@ -92,16 +93,25 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
enum ofono_emulator_type type)
{
struct ofono_emulator *em;
+ enum ofono_atom_type atom_t;
DBG("modem: %p, type: %d", modem, type);
+ if (type == OFONO_EMULATOR_TYPE_DUN)
+ atom_t = OFONO_ATOM_TYPE_EMULATOR_DUN;
+ else if (type == OFONO_EMULATOR_TYPE_HFP)
+ atom_t = OFONO_ATOM_TYPE_EMULATOR_HFP;
+ else
+ return NULL;
+
em = g_try_new0(struct ofono_emulator, 1);
if (em == NULL)
return NULL;
- em->atom = __ofono_modem_add_atom(modem, OFONO_ATOM_TYPE_EMULATOR_DUN,
- emulator_remove, em);
+ em->type = type;
+
+ em->atom = __ofono_modem_add_atom(modem, atom_t, emulator_remove, em);
return em;
}
diff --git a/src/ofono.h b/src/ofono.h
index dbe1862..f52356e 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -129,6 +129,7 @@ enum ofono_atom_type {
OFONO_ATOM_TYPE_CDMA_VOICECALL_MANAGER,
OFONO_ATOM_TYPE_SIM_AUTH,
OFONO_ATOM_TYPE_EMULATOR_DUN,
+ OFONO_ATOM_TYPE_EMULATOR_HFP,
};
enum ofono_atom_watch_condition {
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ 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 ` [PATCH 1/3] " =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-15 15:06 ` [PATCH 2/3] emulator: add HFP emulator type =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
@ 2011-02-15 15:06 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2 siblings, 0 replies; 10+ 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] 10+ 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 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2011-02-22 18:39 ` Denis Kenzior
0 siblings, 1 reply; 10+ 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] 10+ 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; 10+ 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] 10+ 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; 10+ 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] 10+ messages in thread