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

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to