From: Marcel Holtmann <marcel@holtmann.org>
To: ofono@ofono.org
Subject: Re: [PATCH v0 8/9] hfp_hf_bluez5: Reject SCO if source doesn't match
Date: Mon, 28 Jan 2013 17:04:52 +0100 [thread overview]
Message-ID: <1359389092.16748.38.camel@aeonflux> (raw)
In-Reply-To: <1359384259-5384-9-git-send-email-claudio.takahasi@openbossa.org>
[-- Attachment #1: Type: text/plain, Size: 4882 bytes --]
Hi Claudio,
> This patch implements additional verification checking the Bluetooth
> source address instead of the remote address only.
> ---
> plugins/hfp_hf_bluez5.c | 64 ++++++++++++++++++++++++++++++++++---------------
> 1 file changed, 45 insertions(+), 19 deletions(-)
>
> diff --git a/plugins/hfp_hf_bluez5.c b/plugins/hfp_hf_bluez5.c
> index d79647b..504b0f3 100644
> --- a/plugins/hfp_hf_bluez5.c
> +++ b/plugins/hfp_hf_bluez5.c
> @@ -60,6 +60,12 @@
> struct hfp {
> struct hfp_slc_info info;
> DBusMessage *msg;
> + char adapter[18];
> +};
> +
> +struct bt_peer {
> + char adapter[18];
> + char device[18];
> };
I do not get this. I am really not sure what this is all about and why
having Bluetooth addresses as strings here is a good idea.
>
> static GHashTable *modem_hash = NULL;
> @@ -70,11 +76,18 @@ static guint sco_watch = 0;
> static gboolean modem_address_cmp(gpointer key, gpointer value,
> gpointer user_data)
> {
> - const char *dst = user_data;
> + const struct bt_peer *bt_peer = user_data;
> struct ofono_modem *modem = value;
> - const char *address = ofono_modem_get_string(modem, "Address");
> + const char *device = ofono_modem_get_string(modem, "Address");
> + struct hfp *hfp;
> + gboolean ret;
>
> - return g_strcmp0(address, dst) != 0 ? FALSE : TRUE;
> + ret = g_strcmp0(device, bt_peer->device);
> + if (ret != 0)
> + return FALSE;
> +
> + hfp = ofono_modem_get_data(modem);
> + return g_strcmp0(hfp->adapter, bt_peer->adapter) != 0 ? FALSE : TRUE;
> }
>
> static void hfp_debug(const char *str, void *user_data)
> @@ -284,14 +297,14 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
> {
> struct hfp *hfp;
> struct ofono_modem *modem;
> + struct sockaddr_rc src, dst;
> DBusMessageIter iter;
> GDBusProxy *proxy;
> DBusMessageIter entry;
> - const char *device, *alias, *address;
> + const char *device, *alias;
> + char device_address[18];
> int fd, err;
>
> - DBG("Profile handler NewConnection");
> -
> if (dbus_message_iter_init(msg, &entry) == FALSE)
> goto invalid;
>
> @@ -310,11 +323,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;
> @@ -323,7 +331,13 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
> if (fd < 0)
> goto invalid;
>
> - modem = modem_register(device, address, alias);
> + if (bt_getsockpeers(fd, (struct sockaddr *) &src,
> + (struct sockaddr *) &dst,
> + sizeof(struct sockaddr_rc)) < 0)
> + goto invalid;
> +
> + bt_ba2str(&dst.rc_bdaddr, device_address);
> + modem = modem_register(device, device_address, alias);
> if (modem == NULL) {
> close(fd);
> return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
> @@ -339,6 +353,9 @@ static DBusMessage *profile_new_connection(DBusConnection *conn,
>
> hfp = ofono_modem_get_data(modem);
> hfp->msg = dbus_message_ref(msg);
> + bt_ba2str(&src.rc_bdaddr, hfp->adapter);
> +
> + DBG("Profile handler NewConnection: %s", device_address);
>
> return NULL;
>
> @@ -394,9 +411,9 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
> gpointer user_data)
> {
> struct ofono_modem *modem;
> - struct sockaddr_sco saddr;
> + struct sockaddr_sco src, dst;
> + struct bt_peer bt_peer;
> socklen_t optlen;
> - char dst[18];
> int sk, nsk;
>
> if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
> @@ -404,15 +421,24 @@ static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
>
> sk = g_io_channel_unix_get_fd(io);
>
> - memset(&saddr, 0, sizeof(saddr));
> - optlen = sizeof(saddr);
> + memset(&dst, 0, sizeof(dst));
> + optlen = sizeof(dst);
>
> - nsk = accept(sk, (struct sockaddr *) &saddr, &optlen);
> + nsk = accept(sk, (struct sockaddr *) &dst, &optlen);
> if (nsk < 0)
> return TRUE;
>
> - bt_ba2str(&saddr.sco_bdaddr, dst);
> - modem = g_hash_table_find(modem_hash, modem_address_cmp, dst);
> + if (bt_getsockpeers(nsk, (struct sockaddr *) &src, NULL, optlen) < 0) {
> + close(nsk);
> + return TRUE;
> + }
> +
> + bt_ba2str(&src.sco_bdaddr, bt_peer.adapter);
> + bt_ba2str(&dst.sco_bdaddr, bt_peer.device);
> +
> + DBG("SCO: %s < %s", bt_peer.adapter, bt_peer.device);
> +
> + modem = g_hash_table_find(modem_hash, modem_address_cmp, &bt_peer);
You do realize that using a hash table if you have to iterate it is
pretty inefficient. Have you compared your find vs lookup operations?
Regards
Marcel
next prev parent reply other threads:[~2013-01-28 16:04 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-28 14:44 [PATCH v0 0/9] External HFP: Add SCO Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 1/9] bluez5: Add SCO socket declarations Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 2/9] bluez5: Add bt_bacpy() Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 3/9] hfp_hf_bluez5: Add SCO listen socket Claudio Takahasi
2013-01-28 15:59 ` Marcel Holtmann
2013-01-28 16:43 ` Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 4/9] bluez5: Add bt_ba2str() Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 5/9] bluez5: Add bt_getsockpeers() Claudio Takahasi
2013-01-28 15:32 ` Marcel Holtmann
2013-01-28 16:34 ` Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 6/9] bluez5: Add RFCOMM socket address declaration Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 7/9] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 8/9] hfp_hf_bluez5: Reject SCO if source doesn't match Claudio Takahasi
2013-01-28 16:04 ` Marcel Holtmann [this message]
2013-01-28 16:56 ` Claudio Takahasi
2013-01-28 14:44 ` [PATCH v0 9/9] hfp_hf_bluez5: Fix missing fd close Claudio Takahasi
2013-01-28 21:11 ` [PATCH v1 0/8] External HFP: Add SCO Claudio Takahasi
2013-01-28 21:11 ` [PATCH v1 1/8] bluez5: Add SCO socket declarations Claudio Takahasi
2013-01-29 14:55 ` Denis Kenzior
2013-01-28 21:11 ` [PATCH v1 2/8] bluez5: Add bt_bacpy() Claudio Takahasi
2013-01-29 14:55 ` Denis Kenzior
2013-01-28 21:11 ` [PATCH v1 3/8] hfp_hf_bluez5: Add SCO listen socket Claudio Takahasi
2013-01-29 15:02 ` Denis Kenzior
2013-01-28 21:11 ` [PATCH v1 4/8] bluez5: Add bt_ba2str() Claudio Takahasi
2013-01-29 15:03 ` Denis Kenzior
2013-01-28 21:11 ` [PATCH v1 5/8] bluez5: Add bt_bacmp() Claudio Takahasi
2013-01-29 15:03 ` Denis Kenzior
2013-01-28 21:11 ` [PATCH v1 6/8] bluez5: Add RFCOMM socket address declaration Claudio Takahasi
2013-01-29 15:04 ` Denis Kenzior
2013-01-28 21:11 ` [PATCH v1 7/8] hfp_hf_bluez5: Add rejecting SCO connection Claudio Takahasi
2013-01-29 15:27 ` Denis Kenzior
2013-01-29 16:17 ` Claudio Takahasi
2013-01-29 16:25 ` Denis Kenzior
2013-01-28 21:11 ` [PATCH v1 8/8] hfp_hf_bluez5: Fix missing fd close Claudio Takahasi
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=1359389092.16748.38.camel@aeonflux \
--to=marcel@holtmann.org \
--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