Skip to contentSkip to conversation

HSP profile implementation

PATCH Superseded Frédéric Dalleau 1 participant 6 messages Mar 14, 2011 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover HSP profile implementation

This patch will start providing an HSP profile implementation in oFono. This is work in progress, and based of what was done for HFP profile.
Next step is to add an audio connection it will be done in a separate patch since it must be discussed.

Frédéric Dalleau (5):
hsp_ag: Initial plugin commit
hsp_ag: add modem watch
hsp_ag: add hsp emulator type
hsp_ag: add hsp atom type
hsp_ag: change emulator type to hsp

 Makefile.am        |    3 +
 include/emulator.h |    1 +
 plugins/hsp_ag.c   |  199 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/emulator.c     |    4 +
 src/ofono.h        |    1 +
 5 files changed, 208 insertions(+), 0 deletions(-)
 create mode 100644 plugins/hsp_ag.c
#1 lore raw

PATCH 1/5 hsp_ag: Initial plugin commit

---
 Makefile.am      |    3 +
 plugins/hsp_ag.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 0 deletions(-)
 create mode 100644 plugins/hsp_ag.c
Makefile.am +3 -0
index a784636..d62224d 100644
@@ -335,6 +335,9 @@ builtin_sources += plugins/hfp_ag.c plugins/bluetooth.h
 builtin_modules += dun_gw
 builtin_sources += plugins/dun_gw.c plugins/bluetooth.h
 
+builtin_modules += hsp_ag
+builtin_sources += plugins/hsp_ag.c plugins/bluetooth.h
+
 builtin_sources += $(btio_sources)
 builtin_cflags += @BLUEZ_CFLAGS@
 builtin_libadd += @BLUEZ_LIBS@
plugins/hsp_ag.c new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/5 hsp_ag: add modem watch

In reply to Frédéric Dalleau
---
 plugins/hsp_ag.c |   96 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 90 insertions(+), 6 deletions(-)
plugins/hsp_ag.c +90 -6
index 34bf0a1..467b6b2 100644
@@ -48,6 +48,8 @@
 #define HSP_RFCOMM_CHAN 17
 
 static struct server *hsp;
+static unsigned int modemwatch_id;
+static GList *modems;
 
 static const gchar *hsp_record = 
 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
@@ -90,16 +92,95 @@ static const gchar *hsp_record =
 " </attribute>\n"
 "</record>\n";
 
-static void connect_cb(GIOChannel *channel, GError *err, gpointer user_data)
+static void connect_cb(GIOChannel *channel, GError *err, gpointer data)
 {
+	int fd;
+	struct ofono_emulator *em;
+	struct ofono_modem *modem;
+
+	/* Pick the first powered modem */
+	modem = modems->data;
+	DBG("Picked modem %p for emulator", modem);
+
+	em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_DUN);
+	if (em == NULL)
+		return;
+
+	fd = g_io_channel_unix_get_fd(channel);
+
+	ofono_emulator_register(em, fd);
+
+	g_io_channel_set_close_on_unref(channel, FALSE);
+}
+
+static void create_server()
+{
+	if(hsp == NULL)
+		hsp = bluetooth_register_server(HSP_RFCOMM_CHAN, hsp_record,
+					connect_cb, NULL);
+
+	DBG("Creating server: %p", hsp);
+}
+
+static void destroy_server()
+{
+	DBG("Removing server: %p", hsp);
+
+	if(hsp)
+		bluetooth_unregister_server(hsp);
+	hsp = NULL;
+}
+
+static void powered_watch(struct ofono_modem *modem, gboolean powered,
+				void *user)
+{
+	if (powered == FALSE) {
+		DBG("Removing modem %p from the list", modem);
+		modems = g_list_remove(modems, modem);
+
+		if (modems == NULL) {
+			destroy_server();
+		}
+	} else {
+		DBG("Adding modem %p to the list", modem);
+		modems = g_list_append(modems, modem);
+
+		if (modems->next == NULL)
+			create_server();
+	}
+}
+
+static void modem_watch(struct ofono_modem *modem, gboolean added, void *user)
+{
+	DBG("modem: %p, added: %d", modem, added);
+
+	if (added == FALSE) {
+		DBG("Removing modem %p from the list", modem);
+		modems = g_list_remove(modems, modem);
+		return;
+	}
+
+	if (ofono_modem_get_powered(modem) == TRUE) {
+		DBG("Adding modem %p to the list", modem);
+		modems = g_list_append(modems, modem);
+
+		if (modems->next == NULL)
+			create_server();
+	}
+
+	__ofono_modem_add_powered_watch(modem, powered_watch, NULL, NULL);
+}
+
+static void call_modemwatch(struct ofono_modem *modem, void *user)
+{
+	modem_watch(modem, TRUE, user);
 }
 
 static int hsp_ag_init(void)
 {
-	hsp = bluetooth_register_server(HSP_RFCOMM_CHAN, hsp_record, connect_cb, NULL);
+	modemwatch_id = __ofono_modemwatch_add(modem_watch, NULL, NULL);
 
-	if(!hsp)
-		return -1;
+	__ofono_modem_foreach(call_modemwatch, NULL);
 
 	DBG("HSP Gateway profile starting");
 	return 0;
@@ -107,8 +188,11 @@ static int hsp_ag_init(void)
 
 static void hsp_ag_exit(void)
 {
-	if(hsp)
-		bluetooth_unregister_server(hsp);
+	destroy_server();
+
+	__ofono_modemwatch_remove(modemwatch_id);
+
+	g_list_free(modems);
 }
 
 OFONO_PLUGIN_DEFINE(hsp_ag, "Headset Gateway Profile", VERSION,
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/5 hsp_ag: add hsp emulator type

In reply to Frédéric Dalleau
---
 include/emulator.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/emulator.h +1 -0
index 71b7c24..e010606 100644
@@ -42,6 +42,7 @@ struct ofono_emulator_request;
 enum ofono_emulator_type {
 	OFONO_EMULATOR_TYPE_DUN,
 	OFONO_EMULATOR_TYPE_HFP,
+	OFONO_EMULATOR_TYPE_HSP,
 };
 
 enum ofono_emulator_request_type {
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/5 hsp_ag: add hsp atom type

In reply to Frédéric Dalleau
---
 src/emulator.c |    4 ++++
 src/ofono.h    |    1 +
 2 files changed, 5 insertions(+), 0 deletions(-)
src/emulator.c +4 -0
index 20a575f..855235f 100644
@@ -470,6 +470,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 		g_at_server_register(em->server, "D", dial_cb, em, NULL);
 	else if (em->type == OFONO_EMULATOR_TYPE_HFP)
 		g_at_server_set_echo(em->server, FALSE);
+	else if (em->type == OFONO_EMULATOR_TYPE_HSP)
+		g_at_server_set_echo(em->server, FALSE);
 }
 
 static void emulator_remove(struct ofono_atom *atom)
@@ -493,6 +495,8 @@ struct ofono_emulator *ofono_emulator_create(struct ofono_modem *modem,
 		atom_t = OFONO_ATOM_TYPE_EMULATOR_DUN;
 	else if (type == OFONO_EMULATOR_TYPE_HFP)
 		atom_t = OFONO_ATOM_TYPE_EMULATOR_HFP;
+	else if (type == OFONO_EMULATOR_TYPE_HSP)
+		atom_t = OFONO_ATOM_TYPE_EMULATOR_HSP;
 	else
 		return NULL;
 
src/ofono.h +1 -0
index 1628df3..f294b87 100644
@@ -130,6 +130,7 @@ enum ofono_atom_type {
 	OFONO_ATOM_TYPE_SIM_AUTH,
 	OFONO_ATOM_TYPE_EMULATOR_DUN,
 	OFONO_ATOM_TYPE_EMULATOR_HFP,
+	OFONO_ATOM_TYPE_EMULATOR_HSP,
 	OFONO_ATOM_TYPE_LOCATION_REPORTING,
 };
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/5 hsp_ag: change emulator type to hsp

In reply to Frédéric Dalleau
---
 plugins/hsp_ag.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
plugins/hsp_ag.c +1 -1
index 467b6b2..4ace88e 100644
@@ -102,7 +102,7 @@ static void connect_cb(GIOChannel *channel, GError *err, gpointer data)
 	modem = modems->data;
 	DBG("Picked modem %p for emulator", modem);
 
-	em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_DUN);
+	em = ofono_emulator_create(modem, OFONO_EMULATOR_TYPE_HSP);
 	if (em == NULL)
 		return;
 
Signature · 1 line
1.7.1