Open Source Telephony
 help / color / mirror / Atom feed
From: =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis <frederic.danis@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCH 4/5] hfp_ag_bluez5: Add list of HFP AG emulators
Date: Tue, 05 Feb 2013 17:26:59 +0100	[thread overview]
Message-ID: <1360081620-19458-4-git-send-email-frederic.danis@linux.intel.com> (raw)
In-Reply-To: <1360081620-19458-1-git-send-email-frederic.danis@linux.intel.com>

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

This will be used to retrieve hfp_ag related to the incoming SCO
---
 plugins/hfp_ag_bluez5.c |   56 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/plugins/hfp_ag_bluez5.c b/plugins/hfp_ag_bluez5.c
index 80dd601..c6b858e 100644
--- a/plugins/hfp_ag_bluez5.c
+++ b/plugins/hfp_ag_bluez5.c
@@ -44,9 +44,29 @@
 
 #define HFP_AG_EXT_PROFILE_PATH   "/bluetooth/profile/hfp_ag"
 
+struct hfp_ag {
+	struct ofono_emulator *em;
+	bdaddr_t local;
+	bdaddr_t peer;
+};
+
 static guint modemwatch_id;
 static GList *modems;
 static GHashTable *sim_hash = NULL;
+static GSList *hfp_ags;
+
+static void free_hfp_ag(void *data)
+{
+	struct hfp_ag *hfp_ag = data;
+
+	DBG("");
+
+	if (hfp_ag == NULL)
+		return;
+
+	hfp_ags = g_slist_remove(hfp_ags, hfp_ag);
+	g_free(hfp_ag);
+}
 
 static DBusMessage *profile_new_connection(DBusConnection *conn,
 						DBusMessage *msg, void *data)
@@ -54,8 +74,13 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	DBusMessageIter entry;
 	const char *device;
 	int fd;
+	struct sockaddr_rc saddr;
+	bdaddr_t local;
+	bdaddr_t peer;
+	socklen_t optlen;
 	struct ofono_emulator *em;
 	struct ofono_modem *modem;
+	struct hfp_ag *hfp_ag;
 
 	DBG("Profile handler NewConnection");
 
@@ -79,6 +104,26 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 
 	DBG("%s", device);
 
+	memset(&saddr, 0, sizeof(saddr));
+	optlen = sizeof(saddr);
+	if (getsockname(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+		ofono_error("RFCOMM getsockname(): %s (%d)", strerror(errno),
+									errno);
+		goto error;
+	}
+
+	local = saddr.rc_bdaddr;
+
+	memset(&saddr, 0, sizeof(saddr));
+	optlen = sizeof(saddr);
+	if (getpeername(fd, (struct sockaddr *) &saddr, &optlen) < 0) {
+		ofono_error("RFCOMM getpeername(): %s (%d)", strerror(errno),
+									errno);
+		goto error;
+	}
+
+	peer = saddr.rc_bdaddr;
+
 	/* Pick the first voicecall capable modem */
 	modem = modems->data;
 	if (modem == NULL) {
@@ -100,8 +145,19 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 
 	ofono_emulator_register(em, fd);
 
+	hfp_ag = g_new0(struct hfp_ag, 1);
+	hfp_ag->em = em;
+	hfp_ag->local = local;
+	hfp_ag->peer = peer;
+	ofono_emulator_set_data(em, hfp_ag, free_hfp_ag);
+
+	hfp_ags = g_slist_append(hfp_ags, hfp_ag);
+
 	return dbus_message_new_method_return(msg);
 
+error:
+	close(fd);
+
 invalid:
 	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
 					"Invalid arguments in method call");
-- 
1.7.9.5


  parent reply	other threads:[~2013-02-05 16:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-05 16:26 [PATCH 1/5] bluez5: Add SCO server register/unregister =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2013-02-05 16:26 ` [PATCH 2/5] include: Add set/get data APIs to emulator =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2013-02-05 16:26 ` [PATCH 3/5] emulator: Add set/get data APIs =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis
2013-02-05 16:26 ` =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis [this message]
2013-02-05 16:27 ` [PATCH 5/5] hfp_ag_bluez5: Add SCO listen socket =?unknown-8bit?q?Fr=C3=A9d=C3=A9ric?= Danis

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=1360081620-19458-4-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox