hfp_hf_bluez5: Ensure active SLC for SCO links
authorDenis Kenzior <denkenz@gmail.com>
Thu, 14 Feb 2013 02:40:30 +0000 (20:40 -0600)
committerDenis Kenzior <denkenz@gmail.com>
Thu, 14 Feb 2013 14:47:10 +0000 (08:47 -0600)
Whenever a SCO connection is attempted, ensure that the SLC link is
already active between us and the same remote peer.

plugins/hfp_hf_bluez5.c

index 6de5065eefd515d49a521211b00fa810c8629bd9..5de6188098cff2c7dfcd2e3e8874442c0a3487ad 100644 (file)
@@ -434,12 +434,28 @@ static const GDBusMethodTable profile_methods[] = {
        { }
 };
 
+static ofono_bool_t slc_match(struct ofono_modem *modem, void *userdata)
+{
+       const char *remote = userdata;
+       const char *value = ofono_modem_get_string(modem, "Remote");
+
+       if (value == NULL)
+               return FALSE;
+
+       /* Make sure SLC has been established */
+       if (ofono_modem_get_powered(modem) != TRUE)
+               return FALSE;
+
+       return g_str_equal(remote, value);
+}
+
 static gboolean sco_accept(GIOChannel *io, GIOCondition cond,
                                                        gpointer user_data)
 {
        struct sockaddr_sco saddr;
        socklen_t alen;
        int sk, nsk;
+       char remote[18];
 
        if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
                return FALSE;
@@ -453,7 +469,13 @@ 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);
+
+       if (ofono_modem_find(slc_match, remote) == NULL) {
+               ofono_error("Rejecting SCO: No SLC connection found!");
+               close(nsk);
+               return TRUE;
+       }
 
        return TRUE;
 }