All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v0 0/4] Reject SCO connection
@ 2013-01-29 20:38 Claudio Takahasi
  2013-01-29 20:38 ` [PATCH v0 1/4] hfp_hf_bluez5: Rename 'Address' modem property to 'Remote' Claudio Takahasi
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-29 20:38 UTC (permalink / raw)
  To: ofono

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

Remaining patches of "External HFP: Add SCO" patch series.
* Patches left of the last series:
hfp_hf_bluez5: Add rejecting SCO connection
hfp_hf_bluez5: Fix missing fd close

* Major changes:
- splits patch "hfp_hf_bluez5: Add rejecting SCO connection"
- Replaces bdaddr_t by string. Adapter address is now being
  stored as modem string

Claudio Takahasi (2):
  hfp_hf_bluez5: Add rejecting SCO connection
  hfp_hf_bluez5: Fix missing fd close

Vinicius Costa Gomes (2):
  hfp_hf_bluez5: Rename 'Address' modem property to 'Remote'
  hfp_hf_bluez5: Set the 'Remote' and 'Local' properties

 plugins/hfp_hf_bluez5.c | 111 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 88 insertions(+), 23 deletions(-)

-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v0 1/4] hfp_hf_bluez5: Rename 'Address' modem property to 'Remote'
  2013-01-29 20:38 [PATCH v0 0/4] Reject SCO connection Claudio Takahasi
@ 2013-01-29 20:38 ` Claudio Takahasi
  2013-01-29 21:59   ` Denis Kenzior
  2013-01-29 20:38 ` [PATCH v0 2/4] hfp_hf_bluez5: Set the 'Remote' and 'Local' properties Claudio Takahasi
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-29 20:38 UTC (permalink / raw)
  To: ofono

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

From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>

As we will need to also keep track of the Local address, we rename the
modem property to Remote, to keep names more consistent.
---
 plugins/hfp_hf_bluez5.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index aba62e2..c4a3f32 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -185,7 +185,7 @@ static struct ofono_modem *modem_register(const char *device,
 	if (modem == NULL)
 		return NULL;
 
-	ofono_modem_set_string(modem, "Address", device_address);
+	ofono_modem_set_string(modem, "Remote", device_address);
 
 	ofono_modem_set_name(modem, alias);
 	ofono_modem_register(modem);
@@ -243,7 +243,7 @@ static int hfp_disable(struct ofono_modem *modem)
 static void hfp_pre_sim(struct ofono_modem *modem)
 {
 	struct hfp *hfp = ofono_modem_get_data(modem);
-	char *address = (char *) ofono_modem_get_string(modem, "Address");
+	char *address = (char *) ofono_modem_get_string(modem, "Remote");
 
 	DBG("%p", modem);
 
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v0 2/4] hfp_hf_bluez5: Set the 'Remote' and 'Local' properties
  2013-01-29 20:38 [PATCH v0 0/4] Reject SCO connection Claudio Takahasi
  2013-01-29 20:38 ` [PATCH v0 1/4] hfp_hf_bluez5: Rename 'Address' modem property to 'Remote' Claudio Takahasi
@ 2013-01-29 20:38 ` Claudio Takahasi
  2013-01-29 20:38 ` [PATCH v0 3/4] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-29 20:38 UTC (permalink / raw)
  To: ofono

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

From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>

On modem registration, set both these properties so later on, the modem can be
fully indentified by both addresses. For example, if an incoming SCO connection
comes and do not match this pair, the connection will be rejected.
---
 plugins/hfp_hf_bluez5.c | 55 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 39 insertions(+), 16 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index c4a3f32..49a84c5 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -166,15 +166,22 @@ static int service_level_connection(struct ofono_modem *modem,
 	return -EINPROGRESS;
 }
 
-static struct ofono_modem *modem_register(const char *device,
-				const char *device_address, const char *alias)
+static struct ofono_modem *modem_register(const char *device, const char *local,
+				const char *remote, const char *alias)
 {
 	struct ofono_modem *modem;
 	char *path;
 
 	modem = g_hash_table_lookup(modem_hash, device);
-	if (modem != NULL)
+	if (modem != NULL) {
+		/*
+		 * When the modem is created, it may be created with
+		 * only the Remote property, in the case that the modem
+		 * was registered from a device proxy
+		 */
+		ofono_modem_set_string(modem, "Local", local);
 		return modem;
+	}
 
 	path = g_strconcat("hfp", device, NULL);
 
@@ -185,7 +192,9 @@ static struct ofono_modem *modem_register(const char *device,
 	if (modem == NULL)
 		return NULL;
 
-	ofono_modem_set_string(modem, "Remote", device_address);
+	/* The "Remote" property needs to be available before pre-sim */
+	ofono_modem_set_string(modem, "Local", local);
+	ofono_modem_set_string(modem, "Remote", remote);
 
 	ofono_modem_set_name(modem, alias);
 	ofono_modem_register(modem);
@@ -275,14 +284,15 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 {
 	struct hfp *hfp;
 	struct ofono_modem *modem;
+	struct sockaddr_rc laddr, raddr;
+	socklen_t alen;
 	DBusMessageIter iter;
 	GDBusProxy *proxy;
 	DBusMessageIter entry;
-	const char *device, *alias, *address;
+	const char *device, *alias;
+	char local[18], remote[18];
 	int fd, err;
 
-	DBG("Profile handler NewConnection");
-
 	if (dbus_message_iter_init(msg, &entry) == FALSE)
 		goto invalid;
 
@@ -301,11 +311,6 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 
 	dbus_message_iter_get_basic(&iter, &alias);
 
-	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
-		goto invalid;
-
-	dbus_message_iter_get_basic(&iter, &address);
-
 	dbus_message_iter_next(&entry);
 	if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_UNIX_FD)
 		goto invalid;
@@ -314,7 +319,25 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	if (fd < 0)
 		goto invalid;
 
-	modem = modem_register(device, address, alias);
+	memset(&laddr, 0, sizeof(laddr));
+	alen = sizeof(laddr);
+	if (getsockname(fd, (struct sockaddr *) &laddr, &alen) < 0) {
+		close(fd);
+		goto invalid;
+	}
+
+	memset(&raddr, 0, sizeof(raddr));
+	alen = sizeof(raddr);
+	if (getpeername(fd, (struct sockaddr *) &raddr, &alen) < 0) {
+		close(fd);
+		goto invalid;
+	}
+
+	bt_ba2str(&laddr.rc_bdaddr, local);
+	bt_ba2str(&raddr.rc_bdaddr, remote);
+	DBG("Profile handler NewConnection: %s", remote);
+
+	modem = modem_register(device, local, remote, alias);
 	if (modem == NULL) {
 		close(fd);
 		return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
@@ -479,7 +502,7 @@ static gboolean has_hfp_ag_uuid(DBusMessageIter *array)
 
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
-	const char *interface, *path, *alias, *address;
+	const char *interface, *path, *alias, *remote;
 	DBusMessageIter iter;
 
 	interface = g_dbus_proxy_get_interface(proxy);
@@ -507,9 +530,9 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
 	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
 		return;
 
-	dbus_message_iter_get_basic(&iter, &address);
+	dbus_message_iter_get_basic(&iter, &remote);
 
-	modem_register(path, address, alias);
+	modem_register(path, NULL, remote, alias);
 }
 
 static void proxy_removed(GDBusProxy *proxy, void *user_data)
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v0 3/4] hfp_hf_bluez5: Add rejecting SCO connection
  2013-01-29 20:38 [PATCH v0 0/4] Reject SCO connection Claudio Takahasi
  2013-01-29 20:38 ` [PATCH v0 1/4] hfp_hf_bluez5: Rename 'Address' modem property to 'Remote' Claudio Takahasi
  2013-01-29 20:38 ` [PATCH v0 2/4] hfp_hf_bluez5: Set the 'Remote' and 'Local' properties Claudio Takahasi
@ 2013-01-29 20:38 ` Claudio Takahasi
  2013-01-29 20:38 ` [PATCH v0 4/4] hfp_hf_bluez5: Fix missing fd close Claudio Takahasi
  2013-01-30 13:32 ` [PATCH v1 0/2] Reject SCO connection Claudio Takahasi
  4 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-29 20:38 UTC (permalink / raw)
  To: ofono

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

This patch rejects the SCO incoming connection if there isn't a service
level connection associated with the Bluetooth address pair.
---
 plugins/hfp_hf_bluez5.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 45 insertions(+), 5 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 49a84c5..28c57c3 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -63,11 +63,34 @@ struct hfp {
 	DBusMessage *msg;
 };
 
+struct address_pair {
+	char local[18];
+	char remote[18];
+};
+
 static GHashTable *modem_hash = NULL;
 static GHashTable *devices_proxies = NULL;
 static GDBusClient *bluez = NULL;
 static guint sco_watch = 0;
 
+static gboolean modem_cmp(gpointer key, gpointer value,
+						gpointer user_data)
+{
+	const struct address_pair *pair = user_data;
+	struct ofono_modem *modem = value;
+	const char *local, *remote;
+	int ret;
+
+	local = ofono_modem_get_string(modem, "Local");
+	remote = ofono_modem_get_string(modem, "Remote");
+
+	ret = g_strcmp0(pair->remote, remote);
+	if (ret != 0)
+		return FALSE;
+
+	return g_strcmp0(pair->local, local) == 0;
+}
+
 static void hfp_debug(const char *str, void *user_data)
 {
 	const char *prefix = user_data;
@@ -407,7 +430,9 @@ static const GDBusMethodTable profile_methods[] = {
 static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
-	struct sockaddr_sco saddr;
+	struct ofono_modem *modem;
+	struct sockaddr_sco laddr, raddr;
+	struct address_pair pair;
 	socklen_t alen;
 	int sk, nsk;
 
@@ -416,14 +441,29 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 
 	sk = g_io_channel_unix_get_fd(io);
 
-	memset(&saddr, 0, sizeof(saddr));
-	alen = sizeof(saddr);
+	memset(&raddr, 0, sizeof(raddr));
+	alen = sizeof(raddr);
 
-	nsk = accept(sk, (struct sockaddr *) &saddr, &alen);
+	nsk = accept(sk, (struct sockaddr *) &raddr, &alen);
 	if (nsk < 0)
 		return TRUE;
 
-	/* TODO: Verify if the device has a modem */
+	memset(&laddr, 0, sizeof(laddr));
+	alen = sizeof(laddr);
+	if (getsockname(nsk, (struct sockaddr *) &laddr, &alen) < 0) {
+		close(nsk);
+		return TRUE;
+	}
+
+	bt_ba2str(&laddr.sco_bdaddr, pair.local);
+	bt_ba2str(&raddr.sco_bdaddr, pair.remote);
+
+	modem = g_hash_table_find(modem_hash, modem_cmp, &pair);
+	if (modem == NULL) {
+		ofono_error("Rejecting SCO: SLC connection missing!");
+		close(nsk);
+		return TRUE;
+	}
 
 	return TRUE;
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v0 4/4] hfp_hf_bluez5: Fix missing fd close
  2013-01-29 20:38 [PATCH v0 0/4] Reject SCO connection Claudio Takahasi
                   ` (2 preceding siblings ...)
  2013-01-29 20:38 ` [PATCH v0 3/4] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
@ 2013-01-29 20:38 ` Claudio Takahasi
  2013-01-29 21:59   ` Denis Kenzior
  2013-01-30 13:32 ` [PATCH v1 0/2] Reject SCO connection Claudio Takahasi
  4 siblings, 1 reply; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-29 20:38 UTC (permalink / raw)
  To: ofono

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

This patch fix an unusual scenario, service_level_connection() fails if
GIOChannel or GAtChat memory allocation fails.
---
 plugins/hfp_hf_bluez5.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 28c57c3..ced5a20 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -369,10 +369,12 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	}
 
 	err = service_level_connection(modem, fd, HFP_VERSION_LATEST);
-	if (err < 0 && err != -EINPROGRESS)
+	if (err < 0 && err != -EINPROGRESS) {
+		close(fd);
 		return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
 					".Rejected",
 					"Not enough resources");
+	}
 
 	hfp = ofono_modem_get_data(modem);
 	hfp->msg = dbus_message_ref(msg);
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v0 1/4] hfp_hf_bluez5: Rename 'Address' modem property to 'Remote'
  2013-01-29 20:38 ` [PATCH v0 1/4] hfp_hf_bluez5: Rename 'Address' modem property to 'Remote' Claudio Takahasi
@ 2013-01-29 21:59   ` Denis Kenzior
  0 siblings, 0 replies; 14+ messages in thread
From: Denis Kenzior @ 2013-01-29 21:59 UTC (permalink / raw)
  To: ofono

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

On 01/29/2013 02:38 PM, Claudio Takahasi wrote:
> From: Vinicius Costa Gomes<vinicius.gomes@openbossa.org>
>
> As we will need to also keep track of the Local address, we rename the
> modem property to Remote, to keep names more consistent.
> ---
>   plugins/hfp_hf_bluez5.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v0 4/4] hfp_hf_bluez5: Fix missing fd close
  2013-01-29 20:38 ` [PATCH v0 4/4] hfp_hf_bluez5: Fix missing fd close Claudio Takahasi
@ 2013-01-29 21:59   ` Denis Kenzior
  0 siblings, 0 replies; 14+ messages in thread
From: Denis Kenzior @ 2013-01-29 21:59 UTC (permalink / raw)
  To: ofono

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

On 01/29/2013 02:38 PM, Claudio Takahasi wrote:
> This patch fix an unusual scenario, service_level_connection() fails if
> GIOChannel or GAtChat memory allocation fails.
> ---
>   plugins/hfp_hf_bluez5.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>

Patch has been applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v1 0/2] Reject SCO connection
  2013-01-29 20:38 [PATCH v0 0/4] Reject SCO connection Claudio Takahasi
                   ` (3 preceding siblings ...)
  2013-01-29 20:38 ` [PATCH v0 4/4] hfp_hf_bluez5: Fix missing fd close Claudio Takahasi
@ 2013-01-30 13:32 ` Claudio Takahasi
  2013-01-30 13:32   ` [PATCH v1 1/2] hfp_hf_bluez5: Add SLC hash table Claudio Takahasi
                     ` (2 more replies)
  4 siblings, 3 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-30 13:32 UTC (permalink / raw)
  To: ofono

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

Add service level connection hash table to track active connections
using the remote address as key, and the adapter address as value.
It is not supported the scenario that the host has multiple local adapters,
and the remote needs to establish more than one SLC to this host/oFono.

Rejects the incoming SCO connection if the address pair is not found in the
hash table.

Claudio Takahasi (2):
  hfp_hf_bluez5: Add SLC hash table
  hfp_hf_bluez5: Add rejecting SCO connection

 plugins/hfp_hf_bluez5.c | 75 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 61 insertions(+), 14 deletions(-)

-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v1 1/2] hfp_hf_bluez5: Add SLC hash table
  2013-01-30 13:32 ` [PATCH v1 0/2] Reject SCO connection Claudio Takahasi
@ 2013-01-30 13:32   ` Claudio Takahasi
  2013-01-30 13:32   ` [PATCH v1 2/2] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
  2013-02-01 17:51   ` [PATCH v2 0/3] Reject " Claudio Takahasi
  2 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-30 13:32 UTC (permalink / raw)
  To: ofono

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

This patch adds a service level connection hash table to track the
address of the active connections. For now, only one connection per
remote address is allowed. The remote address will be used as key,
and the local adapter address as hash entry value.
---
 plugins/hfp_hf_bluez5.c | 48 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 2aabdd2..45f4cdd 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -65,6 +65,7 @@ struct hfp {
 
 static GHashTable *modem_hash = NULL;
 static GHashTable *devices_proxies = NULL;
+static GHashTable *slc_hash = NULL;
 static GDBusClient *bluez = NULL;
 static guint sco_watch = 0;
 
@@ -96,6 +97,7 @@ static void slc_failed(gpointer userdata)
 	struct ofono_modem *modem = userdata;
 	struct hfp *hfp = ofono_modem_get_data(modem);
 	struct hfp_slc_info *info = &hfp->info;
+	const char *remote = ofono_modem_get_string(modem, "Remote");
 	DBusMessage *msg;
 
 	msg = g_dbus_create_error(hfp->msg, BLUEZ_ERROR_INTERFACE
@@ -111,6 +113,8 @@ static void slc_failed(gpointer userdata)
 
 	g_at_chat_unref(info->chat);
 	info->chat = NULL;
+
+	g_hash_table_remove(slc_hash, remote);
 }
 
 static void hfp_disconnected_cb(gpointer user_data)
@@ -118,6 +122,7 @@ static void hfp_disconnected_cb(gpointer user_data)
 	struct ofono_modem *modem = user_data;
 	struct hfp *hfp = ofono_modem_get_data(modem);
 	struct hfp_slc_info *info = &hfp->info;
+	const char *remote = ofono_modem_get_string(modem, "Remote");
 
 	DBG("HFP disconnected");
 
@@ -125,6 +130,8 @@ static void hfp_disconnected_cb(gpointer user_data)
 
 	g_at_chat_unref(info->chat);
 	info->chat = NULL;
+
+	g_hash_table_remove(slc_hash, remote);
 }
 
 static int service_level_connection(struct ofono_modem *modem,
@@ -212,6 +219,7 @@ static void hfp_remove(struct ofono_modem *modem)
 {
 	struct hfp *hfp = ofono_modem_get_data(modem);
 	struct hfp_slc_info *info = &hfp->info;
+	const char *remote = ofono_modem_get_string(modem, "Remote");
 
 	DBG("modem: %p", modem);
 
@@ -223,6 +231,8 @@ static void hfp_remove(struct ofono_modem *modem)
 	g_free(hfp);
 
 	ofono_modem_set_data(modem, NULL);
+
+	g_hash_table_remove(slc_hash, remote);
 }
 
 /* power up hardware */
@@ -275,14 +285,15 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 {
 	struct hfp *hfp;
 	struct ofono_modem *modem;
+	struct sockaddr_rc laddr, raddr;
+	socklen_t alen;
 	DBusMessageIter iter;
 	GDBusProxy *proxy;
 	DBusMessageIter entry;
-	const char *device, *alias, *address;
+	const char *device, *alias;
+	char local[18], remote[18];
 	int fd, err;
 
-	DBG("Profile handler NewConnection");
-
 	if (dbus_message_iter_init(msg, &entry) == FALSE)
 		goto invalid;
 
@@ -301,11 +312,6 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 
 	dbus_message_iter_get_basic(&iter, &alias);
 
-	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
-		goto invalid;
-
-	dbus_message_iter_get_basic(&iter, &address);
-
 	dbus_message_iter_next(&entry);
 	if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_UNIX_FD)
 		goto invalid;
@@ -314,7 +320,25 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	if (fd < 0)
 		goto invalid;
 
-	modem = modem_register(device, address, alias);
+	memset(&laddr, 0, sizeof(laddr));
+	alen = sizeof(laddr);
+	if (getsockname(fd, (struct sockaddr *) &laddr, &alen) < 0) {
+		close(fd);
+		goto invalid;
+	}
+
+	memset(&raddr, 0, sizeof(raddr));
+	alen = sizeof(raddr);
+	if (getpeername(fd, (struct sockaddr *) &raddr, &alen) < 0) {
+		close(fd);
+		goto invalid;
+	}
+
+	bt_ba2str(&laddr.rc_bdaddr, local);
+	bt_ba2str(&raddr.rc_bdaddr, remote);
+	DBG("Profile handler NewConnection: %s", remote);
+
+	modem = modem_register(device, remote, alias);
 	if (modem == NULL) {
 		close(fd);
 		return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
@@ -333,6 +357,8 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
 	hfp = ofono_modem_get_data(modem);
 	hfp->msg = dbus_message_ref(msg);
 
+	g_hash_table_insert(slc_hash, g_strdup(remote), g_strdup(local));
+
 	return NULL;
 
 invalid:
@@ -607,6 +633,9 @@ static int hfp_init(void)
 	devices_proxies = g_hash_table_new_full(g_str_hash, g_str_equal,
 				g_free, (GDestroyNotify) g_dbus_proxy_unref);
 
+	slc_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+								g_free);
+
 	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
 	g_dbus_client_set_proxy_handlers(bluez, proxy_added, proxy_removed,
 						property_changed, NULL);
@@ -626,6 +655,7 @@ static void hfp_exit(void)
 
 	g_hash_table_destroy(modem_hash);
 	g_hash_table_destroy(devices_proxies);
+	g_hash_table_destroy(slc_hash);
 
 	if (sco_watch > 0)
 		g_source_remove(sco_watch);
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v1 2/2] hfp_hf_bluez5: Add rejecting SCO connection
  2013-01-30 13:32 ` [PATCH v1 0/2] Reject SCO connection Claudio Takahasi
  2013-01-30 13:32   ` [PATCH v1 1/2] hfp_hf_bluez5: Add SLC hash table Claudio Takahasi
@ 2013-01-30 13:32   ` Claudio Takahasi
  2013-02-01 17:51   ` [PATCH v2 0/3] Reject " Claudio Takahasi
  2 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-01-30 13:32 UTC (permalink / raw)
  To: ofono

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

This patch rejects the SCO incoming connection if there isn't a service
level connection associated with the Bluetooth address pair.
---
 plugins/hfp_hf_bluez5.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 45f4cdd..7af2968 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -412,8 +412,10 @@ static const GDBusMethodTable profile_methods[] = {
 static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
-	struct sockaddr_sco saddr;
+	struct sockaddr_sco laddr, raddr;
 	socklen_t alen;
+	char local[18], remote[18];
+	const char *address;
 	int sk, nsk;
 
 	if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
@@ -421,14 +423,29 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 
 	sk = g_io_channel_unix_get_fd(io);
 
-	memset(&saddr, 0, sizeof(saddr));
-	alen = sizeof(saddr);
+	memset(&raddr, 0, sizeof(raddr));
+	alen = sizeof(raddr);
 
-	nsk = accept(sk, (struct sockaddr *) &saddr, &alen);
+	nsk = accept(sk, (struct sockaddr *) &raddr, &alen);
 	if (nsk < 0)
 		return TRUE;
 
-	/* TODO: Verify if the device has a modem */
+	memset(&laddr, 0, sizeof(laddr));
+	alen = sizeof(laddr);
+	if (getsockname(nsk, (struct sockaddr *) &laddr, &alen) < 0) {
+		close(nsk);
+		return TRUE;
+	}
+
+	bt_ba2str(&laddr.sco_bdaddr, local);
+	bt_ba2str(&raddr.sco_bdaddr, remote);
+
+	address = g_hash_table_lookup(slc_hash, remote);
+	if (g_strcmp0(address, local) != 0) {
+		ofono_error("Rejecting SCO: SLC connection missing!");
+		close(nsk);
+		return TRUE;
+	}
 
 	return TRUE;
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 0/3] Reject SCO connection
  2013-01-30 13:32 ` [PATCH v1 0/2] Reject SCO connection Claudio Takahasi
  2013-01-30 13:32   ` [PATCH v1 1/2] hfp_hf_bluez5: Add SLC hash table Claudio Takahasi
  2013-01-30 13:32   ` [PATCH v1 2/2] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
@ 2013-02-01 17:51   ` Claudio Takahasi
  2013-02-01 17:51     ` [PATCH v2 1/3] hfp_hf_bluez5: Add active SLC connections list Claudio Takahasi
                       ` (2 more replies)
  2 siblings, 3 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-02-01 17:51 UTC (permalink / raw)
  To: ofono

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

Another proposal implemeting SCO connection reject. As discussed via IRC,
this approach uses a list to track the modems with active service level
connections.

This approach assumes that the remote Bluetooth device will not support
multiple active connections with multiple Bluetooth adapters available
in the same host. Extend this approach to check for the local adapter address
can be added later easily.


Claudio Takahasi (3):
  hfp_hf_bluez5: Add active SLC connections list
  hfp_hf_bluez5: Add rejecting SCO connection
  hfp_hf_bluez5: Add SCO channel tracking

 plugins/hfp_hf_bluez5.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

-- 
1.7.11.7


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v2 1/3] hfp_hf_bluez5: Add active SLC connections list
  2013-02-01 17:51   ` [PATCH v2 0/3] Reject " Claudio Takahasi
@ 2013-02-01 17:51     ` Claudio Takahasi
  2013-02-01 17:51     ` [PATCH v2 2/3] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
  2013-02-01 17:51     ` [PATCH v2 3/3] hfp_hf_bluez5: Add SCO channel tracking Claudio Takahasi
  2 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-02-01 17:51 UTC (permalink / raw)
  To: ofono

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

This patch adds a list to track the address of the active connections.
The list element contains a reference to the modem with active SLC
connections. Instead of storing a simple structure to identity the
Bluetooth address peer, the modem pointer is stored in the list since
it will be necessary to keep a reference for the SCO channel established.

This approach assumes that the remote Bluetooth device will not support
multiple active connections with multiple Bluetooth adapters available
in the same host.
---
 plugins/hfp_hf_bluez5.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 2f4a89e..abeeb4a 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -64,6 +64,7 @@ struct hfp {
 };
 
 static GHashTable *modem_hash = NULL;
+static GSList *slc_list = NULL;		/* Modem with active SLC connection */
 static GDBusClient *bluez = NULL;
 static guint sco_watch = 0;
 
@@ -88,6 +89,8 @@ static void slc_established(gpointer userdata)
 	hfp->msg = NULL;
 
 	ofono_info("Service level connection established");
+
+	slc_list = g_slist_prepend(slc_list, modem);
 }
 
 static void slc_failed(gpointer userdata)
@@ -124,6 +127,8 @@ static void hfp_disconnected_cb(gpointer user_data)
 
 	g_at_chat_unref(info->chat);
 	info->chat = NULL;
+
+	slc_list = g_slist_remove(slc_list, modem);
 }
 
 static int service_level_connection(struct ofono_modem *modem,
@@ -612,6 +617,7 @@ static void hfp_exit(void)
 	ofono_modem_driver_unregister(&hfp_driver);
 	g_dbus_client_unref(bluez);
 
+	g_slist_free(slc_list);
 	g_hash_table_destroy(modem_hash);
 
 	if (sco_watch > 0)
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 2/3] hfp_hf_bluez5: Add rejecting SCO connection
  2013-02-01 17:51   ` [PATCH v2 0/3] Reject " Claudio Takahasi
  2013-02-01 17:51     ` [PATCH v2 1/3] hfp_hf_bluez5: Add active SLC connections list Claudio Takahasi
@ 2013-02-01 17:51     ` Claudio Takahasi
  2013-02-01 17:51     ` [PATCH v2 3/3] hfp_hf_bluez5: Add SCO channel tracking Claudio Takahasi
  2 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-02-01 17:51 UTC (permalink / raw)
  To: ofono

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

This patch rejects the SCO incoming connection if there isn't a service
level connection associated with the Bluetooth remote device.
---
 plugins/hfp_hf_bluez5.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index abeeb4a..6a0f4a2 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -75,6 +75,15 @@ static void hfp_debug(const char *str, void *user_data)
 	ofono_info("%s%s", prefix, str);
 }
 
+static int modem_cmp(gconstpointer data, gconstpointer user_data)
+{
+	const char *address = user_data;
+	struct ofono_modem *modem = (struct ofono_modem *) data;
+	const char *remote = ofono_modem_get_string(modem, "Remote");
+
+	return g_strcmp0(address, remote);
+}
+
 static void slc_established(gpointer userdata)
 {
 	struct ofono_modem *modem = userdata;
@@ -369,7 +378,9 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
 	struct sockaddr_sco saddr;
+	GSList *l;
 	socklen_t alen;
+	char remote[18];
 	int sk, nsk;
 
 	if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
@@ -384,7 +395,16 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 	if (nsk < 0)
 		return TRUE;
 
-	/* TODO: Verify if the device has a modem */
+	bt_ba2str(&saddr.sco_bdaddr, remote);
+
+	l = g_slist_find_custom(slc_list, remote, modem_cmp);
+	if (l == NULL) {
+		ofono_error("Rejecting SCO: SLC connection missing!");
+		close(nsk);
+		return TRUE;
+	}
+
+	/* TODO: Store the SCO reference to update the Media Transports */
 
 	return TRUE;
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v2 3/3] hfp_hf_bluez5: Add SCO channel tracking
  2013-02-01 17:51   ` [PATCH v2 0/3] Reject " Claudio Takahasi
  2013-02-01 17:51     ` [PATCH v2 1/3] hfp_hf_bluez5: Add active SLC connections list Claudio Takahasi
  2013-02-01 17:51     ` [PATCH v2 2/3] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
@ 2013-02-01 17:51     ` Claudio Takahasi
  2 siblings, 0 replies; 14+ messages in thread
From: Claudio Takahasi @ 2013-02-01 17:51 UTC (permalink / raw)
  To: ofono

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

This patch adds the SCO GIOChannel tracking. This is the initial step to
manage transport objects state changes and transport acquire.
---
 plugins/hfp_hf_bluez5.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
index 6a0f4a2..38643c6 100644
--- a/plugins/hfp_hf_bluez5.c
+++ b/plugins/hfp_hf_bluez5.c
@@ -60,6 +60,8 @@
 
 struct hfp {
 	struct hfp_slc_info info;
+	GIOChannel *sco_io;
+	guint sco_watch;
 	DBusMessage *msg;
 };
 
@@ -228,6 +230,12 @@ static void hfp_remove(struct ofono_modem *modem)
 
 	g_at_chat_unref(info->chat);
 
+	if (hfp->sco_watch > 0)
+		g_source_remove(hfp->sco_watch);
+
+	if (hfp->sco_io)
+		g_io_channel_unref(hfp->sco_io);
+
 	g_free(hfp);
 
 	ofono_modem_set_data(modem, NULL);
@@ -374,10 +382,27 @@ static const GDBusMethodTable profile_methods[] = {
 	{ }
 };
 
+static gboolean sco_channel_watch(GIOChannel *io, GIOCondition cond,
+							gpointer user_data)
+{
+	struct hfp *hfp = user_data;
+
+	hfp->sco_watch = 0;
+
+	g_io_channel_unref(hfp->sco_io);
+	hfp->sco_io = NULL;
+
+	/* TODO: Change transport state */
+
+	return FALSE;
+}
+
 static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 							gpointer user_data)
 {
 	struct sockaddr_sco saddr;
+	struct ofono_modem *modem;
+	struct hfp *hfp;
 	GSList *l;
 	socklen_t alen;
 	char remote[18];
@@ -404,7 +429,11 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
 		return TRUE;
 	}
 
-	/* TODO: Store the SCO reference to update the Media Transports */
+	modem = l->data;
+	hfp = ofono_modem_get_data(modem);
+	hfp->sco_io = io;
+	hfp->sco_watch = g_io_add_watch(io, G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+						sco_channel_watch, hfp);
 
 	return TRUE;
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-02-01 17:51 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-29 20:38 [PATCH v0 0/4] Reject SCO connection Claudio Takahasi
2013-01-29 20:38 ` [PATCH v0 1/4] hfp_hf_bluez5: Rename 'Address' modem property to 'Remote' Claudio Takahasi
2013-01-29 21:59   ` Denis Kenzior
2013-01-29 20:38 ` [PATCH v0 2/4] hfp_hf_bluez5: Set the 'Remote' and 'Local' properties Claudio Takahasi
2013-01-29 20:38 ` [PATCH v0 3/4] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
2013-01-29 20:38 ` [PATCH v0 4/4] hfp_hf_bluez5: Fix missing fd close Claudio Takahasi
2013-01-29 21:59   ` Denis Kenzior
2013-01-30 13:32 ` [PATCH v1 0/2] Reject SCO connection Claudio Takahasi
2013-01-30 13:32   ` [PATCH v1 1/2] hfp_hf_bluez5: Add SLC hash table Claudio Takahasi
2013-01-30 13:32   ` [PATCH v1 2/2] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
2013-02-01 17:51   ` [PATCH v2 0/3] Reject " Claudio Takahasi
2013-02-01 17:51     ` [PATCH v2 1/3] hfp_hf_bluez5: Add active SLC connections list Claudio Takahasi
2013-02-01 17:51     ` [PATCH v2 2/3] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
2013-02-01 17:51     ` [PATCH v2 3/3] hfp_hf_bluez5: Add SCO channel tracking Claudio Takahasi

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.