Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Apr 2015 22:34:00 -0700
From:      Waitman Gobble <gobble.wa@gmail.com>
To:        "freebsd-bluetooth@freebsd.org" <freebsd-bluetooth@freebsd.org>
Subject:   question about bthidd client.c
Message-ID:  <CAFuo_fzVganO6M07neAWBVqda1vzV9VNWurU6EsP_3Mc78-dMA@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
I notice that if bthidd is running, and bluetooth is not active, or
the configured host is out of range, the client_rescan() function
generates new vkbd devices every 20 seconds or so. I believe this will
eventually lock up the machine.

ie,



Apr 21 21:59:38 rpidev bthidd[521]: Opening outbound session for
00:1b:dc:06:94:d3 (new_device=0, reconnect_initiate=0)
Apr 21 21:59:38 rpidev kernel: kbd2 at vkbd14137
Apr 21 21:59:38 rpidev bthidd[521]: Could not open control channel to
00:1b:dc:06:94:d3. No route to host (65)
Apr 21 21:59:58 rpidev bthidd[521]: Opening outbound session for
00:1b:dc:06:94:d3 (new_device=0, reconnect_initiate=0)
Apr 21 21:59:58 rpidev kernel: kbd2 at vkbd14138
Apr 21 21:59:58 rpidev bthidd[521]: Could not open control channel to
00:1b:dc:06:94:d3. No route to host (65)
Apr 21 22:00:18 rpidev bthidd[521]: Opening outbound session for
00:1b:dc:06:94:d3 (new_device=0, reconnect_initiate=0)
Apr 21 22:00:18 rpidev kernel: kbd2 at vkbd14139
Apr 21 22:00:18 rpidev bthidd[521]: Could not open control channel to
00:1b:dc:06:94:d3. No route to host (65)
Apr 21 22:00:18 rpidev bthidd[521]: Got signal 15, total number of signals 1


# dmesg
...
kbd2 at vkbd14118
kbd2 at vkbd14119
kbd2 at vkbd14120
kbd2 at vkbd14121
kbd2 at vkbd14122
kbd2 at vkbd14123
kbd2 at vkbd14124
kbd2 at vkbd14125
kbd2 at vkbd14126
kbd2 at vkbd14127
kbd2 at vkbd14128
kbd2 at vkbd14129
kbd2 at vkbd14130
kbd2 at vkbd14131
kbd2 at vkbd14132
kbd2 at vkbd14133
kbd2 at vkbd14134
kbd2 at vkbd14135
kbd2 at vkbd14136
kbd2 at vkbd14137
kbd2 at vkbd14138
kbd2 at vkbd14139

# ls /dev/vkbdctl141*
/dev/vkbdctl141         /dev/vkbdctl14104       /dev/vkbdctl1411
 /dev/vkbdctl14115       /dev/vkbdctl14120       /dev/vkbdctl14126
  /dev/vkbdctl14131       /dev/vkbdctl14137       /dev/vkbdctl1417
/dev/vkbdctl1410        /dev/vkbdctl14105       /dev/vkbdctl14110
 /dev/vkbdctl14116       /dev/vkbdctl14121       /dev/vkbdctl14127
  /dev/vkbdctl14132       /dev/vkbdctl14138       /dev/vkbdctl1418
/dev/vkbdctl14100       /dev/vkbdctl14106       /dev/vkbdctl14111
 /dev/vkbdctl14117       /dev/vkbdctl14122       /dev/vkbdctl14128
  /dev/vkbdctl14133       /dev/vkbdctl14139       /dev/vkbdctl1419
/dev/vkbdctl14101       /dev/vkbdctl14107       /dev/vkbdctl14112
 /dev/vkbdctl14118       /dev/vkbdctl14123       /dev/vkbdctl14129
  /dev/vkbdctl14134       /dev/vkbdctl1414
/dev/vkbdctl14102       /dev/vkbdctl14108       /dev/vkbdctl14113
 /dev/vkbdctl14119       /dev/vkbdctl14124       /dev/vkbdctl1413
  /dev/vkbdctl14135       /dev/vkbdctl1415
/dev/vkbdctl14103       /dev/vkbdctl14109       /dev/vkbdctl14114
 /dev/vkbdctl1412        /dev/vkbdctl14125       /dev/vkbdctl14130
  /dev/vkbdctl14136       /dev/vkbdctl1416




Can we put a connect test in client_rescan before creating a new
device? I believe psm 1 needs to be available anyhow.

/usr/src/usr.sbin/bluetooth/bthidd/client.c

int32_t
client_rescan(bthid_server_p srv)
{
    static hid_device_p d;
    bthid_session_p s;

    assert(srv != NULL);
    if (connect_in_progress)
        return (0); /* another connect is still pending */

    /* check if we can connect to host on psm 1 */
    int testsock;
    struct sockaddr_l2cap l2addr;

    testsock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP);
    l2addr.l2cap_len = sizeof(l2addr);
    l2addr.l2cap_family = AF_BLUETOOTH;
    memcpy(&l2addr.l2cap_bdaddr, &s->bdaddr, sizeof(l2addr.l2cap_bdaddr));
    l2addr.l2cap_psm = htole16(0x1);

    if (bind(testsock, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0) {
        syslog(LOG_ERR, "Could not connect to host. " \
           "%s (%d)", strerror(errno), errno);
        return (-1);
    }

    d = get_next_hid_device(d);
    /* create vkbd, etc */
...


Or maybe there's a better way?

Thank you,

-- 
Waitman Gobble
Los Altos California USA
510-830-7975



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFuo_fzVganO6M07neAWBVqda1vzV9VNWurU6EsP_3Mc78-dMA>