From owner-freebsd-bluetooth@FreeBSD.ORG Thu Mar 19 04:35:54 2015 Return-Path: Delivered-To: freebsd-bluetooth@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4746FCC9 for ; Thu, 19 Mar 2015 04:35:54 +0000 (UTC) Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [IPv6:2a00:1450:400c:c05::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B953512A for ; Thu, 19 Mar 2015 04:35:53 +0000 (UTC) Received: by wifj2 with SMTP id j2so57839976wif.1 for ; Wed, 18 Mar 2015 21:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=k100TS4Z3W4AbE4SbnSZ1TNgc4UTuBSMNzkxle2/ydA=; b=QSdukdgoHu4qTjQiJjWFpcfuK1P17YSN5nb1tYkNTtQBWQQCv5VqejjMPKxmHCEhpa 53PwGfDZZjEEFf7N/xY4CVrTRWISQAWAYwkNUlmNi0LoNobskA3v4TsvqvLSpTlH3ftG s8UK81UIKU/BYL8FbhT752PtveGbvQAZgrPJqye8ErMtnidEpss7/3JmYWToeXpP9sCd EM/yGqSWMCYXN0v++um9cf+Agv/z7yELi8y6uAoHXpPyCnv1JWK6gmJEhqxNqoG/ostv L9HO3ETy29skQ8yKONh0DmPdOyvV/sozXHGmjQs7852I4t77+PB8RLPnCQierzWe7CLg qwSw== MIME-Version: 1.0 X-Received: by 10.194.237.34 with SMTP id uz2mr145438821wjc.157.1426739751558; Wed, 18 Mar 2015 21:35:51 -0700 (PDT) Received: by 10.27.214.136 with HTTP; Wed, 18 Mar 2015 21:35:51 -0700 (PDT) In-Reply-To: References: <0AD7A2F7-37BE-4F6A-9FD6-F6C81B2CAF36@gmail.com> Date: Wed, 18 Mar 2015 21:35:51 -0700 Message-ID: Subject: Re: register HID with SDP error From: Waitman Gobble To: Maksim Yevmenkin Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: "freebsd-bluetooth@freebsd.org" , Iain Hibbert X-BeenThere: freebsd-bluetooth@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Using Bluetooth in FreeBSD environments List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Mar 2015 04:35:54 -0000 On Wed, Mar 18, 2015 at 6:46 PM, Waitman Gobble wrote= : > On Wed, Mar 18, 2015 at 11:48 AM, Maksim Yevmenkin > wrote: >> [...] >> >>> I'm working on the hid code. It opens the l2cap control and interrupt >>> sockets then waits for client connect. When the client connects it >>> sends the key codes. >>> >>> very simply, >>> >>> struct sockaddr_l2cap l2addr, cli_addr; >>> >>> controlsock =3D socket(AF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2= CAP); >>> bind(controlsock, (struct sockaddr *) &l2addr, sizeof(l2addr)); >>> >>> intrsock =3D socket(AF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP= ); >>> bind(intrsock, (struct sockaddr *) &l2addr, sizeof(l2addr)); >>> >>> >>> clilen =3D sizeof(cli_addr); >>> newsockfd =3D accept(controlsock, (struct sockaddr *) &cli_addr, >>> &clilen); //blocks until client connect >> >> ok... are you also accepting connection on interrupt channel? please >> recall, i've mentioned that buetooth hid is modeled after usb hid. >> there are two channels: control and interrupt. >> >>> then loop while reading chars from FIFO: >>> >>> evkeyb->btcode =3D 0xA1; >>> evkeyb->rep_id =3D REPORTID_KEYBD; >>> evkeyb->key[0] =3D retkey(sfifo[i]); //translate to key code >>> send ( newsockfd, evkeyb,sizeof(struct hidrep_keyb_t),MSG_NOSIGNAL ); >> >> hmm.... i don't think its quite correct. all the hid reports should be >> sent on the interrupt channel (just like usb hid device uses interrupt >> transfer endpoint to send its reports back to host). if i'm reading >> your code correctly, newsockfd is an accepted connection on the >> control socket. i presume you have constructed correct hid report >> sequence to send too (as per hid descriptor you have given out to >> remote host via sdp). >> >> [...] >> >>> # ./hid_sppd >>> control socket created >>> interrupt socket created >>> waiting for connect >>> waiting for fifo.. press Control-C to exit. >>> sent data 38 "key 0" >>> sent data 29 "key 1" >>> sent data 30 "key 2" >>> sent data 31 "key 3" >>> sent data 32 "key 4" >>> ... >>> >>> ...and it's reading the fifo buffer and sending the keys through the >>> clientfd, but nothing useful is happening on client.. So I think I'm >>> either doing this wrong, or my SDP record is still incorrect. >> >> well, if remote host has connected then, presumably, it has found >> everything that it needed from sdp. so, i would guess that your sdp >> records are probably correct. i suspect that you need to sort out your >> hid reports format and send them via interrupt channel, not control. >> you also might want to take a look at USBHID(3), specifically >> hid_set_data(). >> >> you can use bthidd(8) code as an example of what host *might* be doing >> and how host *might* expect data. in fact, you can probably use >> bthidd(8) to test your virtual hid device. >> >> one thing to keep in mind is the initial "handshake" setup. when hid >> device is "unknown" to host, host must initiate connection to the >> device first. later, host must respect value of reconnect_initiate >> attribute, and, if its set, host must wait for hid device to >> re-connect. this way, say, keyboard may put itself to sleep, and, wake >> up and reconnect when user presses a button. >> >> thanks, >> max > > Thanks Max, that is super great help. Hopefully I can get it > straightened out tonight. > > -- > Waitman Gobble > Los Altos California USA > 510-830-7975 maybe getting closer. bthidd connects and opens control and interrupt channels, and i can see data on the interrupt line. # btsockstat Active raw HCI sockets Socket PCB Flags Recv-Q Send-Q Local address fffff8003a505000 fffff8011a6bd180 000003 0 0 * fffff801554418b8 fffff80004765780 000002 0 0 * Active L2CAP sockets PCB Recv-Q Send-Q Local address/PSM Foreign address CID Stat= e fffff80241338a00 3 0 00:1b:dc:06:94:d3/19 00:1b:dc:06:ae:4c 220 OPEN fffff8000d2d8d00 0 0 00:1b:dc:06:94:d3/17 00:1b:dc:06:ae:4c 219 OPEN fffff8000d059c00 0 0 * /19 * 0 LISTEN fffff8000d2d9100 0 0 * /17 * 0 LISTEN fffff8000d0a7b00 0 0 * /1 * 0 LISTEN # ./hid_sppd control socket created interrupt socket created waiting for connect waiting for fifo.. press Control-C to exit. ... send characters to FIFO # echo "ABEF010231" >> /tmp/ain ... sent data 3 sent data 4 sent data 7 sent data 8 sent data 38 sent data 29 sent data 38 sent data 30 sent data 31 sent data 29 this shows up on the client .. simple syslog(LOG_ERR,"%s",data.b); Mar 18 21:23:32 rpidev bthidd[4948]: Opening outbound session for 00:1b:dc:06:94:d3 (new_device=3D0, reconnect_initiate=3D0) Mar 18 21:23:32 rpidev kernel: kbd2 at vkbd16 Mar 18 21:23:35 rpidev bthidd[4948]: Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^C Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^D Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^G Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^H Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- & Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^] Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- & Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^^ Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^_ Mar 18 21:23:51 rpidev bthidd[4948]: =C2=A1^BM- ^] I'm guessing I'll have to hook up a display to that machine to see if the virtual keyboard device is working right. modified bthidd https://github.com/waitman/bthidd However, from Linux bluedevil client it opens both control and interrupt but closes interrupt # btsockstat Active raw HCI sockets Socket PCB Flags Recv-Q Send-Q Local address fffff8003a505000 fffff8011a6bd180 000003 0 0 * fffff801554418b8 fffff80004765780 000002 0 0 * Active L2CAP sockets PCB Recv-Q Send-Q Local address/PSM Foreign address CID Stat= e fffff8000d05be00 0 0 00:1b:dc:06:94:d3/19 00:10:60:af:5b:af 216 CLOSED fffff8000d0a6c00 0 0 00:1b:dc:06:94:d3/17 00:10:60:af:5b:af 215 OPEN fffff8000d2d6e00 0 0 * /19 * 0 LISTEN fffff8000d058e00 0 0 * /17 * 0 LISTEN fffff8000d0a7b00 0 0 * /1 * 0 LISTEN (using 'hcitool cc 00:1b:dc:06:94:d3' connects but doesn't open control or interrupt) Samsung S4 pairs but doesn't open control or interrupt. I have seen yt videos of hooking up 'generic' bluetooth keyboard so I believe the device is capable. I have a feeling that Android caches connection info so it's not seeing the HID. I might need to reboot the device. I'm going to have to go through everything from the beginning and make sure everything is correct. Here's what I did to generate bthidd.conf - maybe I can make a man page for bthidd.conf? There's a note on the bthidd man page about needing a bthidd.conf man page. (but maybe there's a better way than the way I did it?) https://gist.github.com/waitman/d77440b82dcb2463e5c3 also, I'll try the manual restart of bluetooth stack and let you know if that works. Thank you, --=20 Waitman Gobble Los Altos California USA 510-830-7975