From owner-freebsd-bluetooth@FreeBSD.ORG Sun Mar 22 15:19:29 2015 Return-Path: Delivered-To: freebsd-bluetooth@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8E31AA12 for ; Sun, 22 Mar 2015 15:19:29 +0000 (UTC) Received: from mail-wi0-x229.google.com (mail-wi0-x229.google.com [IPv6:2a00:1450:400c:c05::229]) (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 0D7A6BEC for ; Sun, 22 Mar 2015 15:19:29 +0000 (UTC) Received: by wibgn9 with SMTP id gn9so37086489wib.1 for ; Sun, 22 Mar 2015 08:19:27 -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; bh=MwuRxWIX3LsxSDbGcfPeKLBgWJ7FDfTIxJ5IdVPWWxA=; b=GvDi34PVUY6OTrDm2ufnfK4SqdbskcAjNvEfFvId9p9wUX6Qhs2/XXg5n3P7ZJFQtk oXOHG/EPYe8u96fNqImoj6o/kx91PAqDWM6ty93Z9Sy02NMXs86DcyKpXRqJMQbFSbI3 9Yj96piCEFazXWbC1s++k5DnxwPAOcWz+KpaJOEG+rfOxRI+ZdRGti9rmrQ5VNTn9wPn 9mawHk0qAKZRMq/pjEe/NE0nkLpqOlW88bGIWUUoS0YqkTLAc0Sw0bfiNDXdtuvDVj8Q v1TdplFNdpOExYdbSfxbUKWygd1vZzm6x0L1pAS0UiorvfPu+1nd3w1u15FwocbjqRU8 WAIg== MIME-Version: 1.0 X-Received: by 10.195.12.35 with SMTP id en3mr171270989wjd.129.1427037567605; Sun, 22 Mar 2015 08:19:27 -0700 (PDT) Received: by 10.27.214.136 with HTTP; Sun, 22 Mar 2015 08:19:27 -0700 (PDT) In-Reply-To: References: <0AD7A2F7-37BE-4F6A-9FD6-F6C81B2CAF36@gmail.com> Date: Sun, 22 Mar 2015 08:19:27 -0700 Message-ID: Subject: Re: register HID with SDP error From: Waitman Gobble To: Maksim Yevmenkin Content-Type: text/plain; charset=UTF-8 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: Sun, 22 Mar 2015 15:19:29 -0000 On Sat, Mar 21, 2015 at 8:41 PM, Waitman Gobble wrote: > On Thu, Mar 19, 2015 at 1:24 PM, Maksim Yevmenkin > wrote: >>> Hi, >>> >>> It's not for production use, but if someone comes across this post in >>> the future maybe save a few minutes when tinkering and >>> troubleshooting. >>> >>> I changed the Makefile so it will 'more easily' build as a standalone >>> outside /usr/src >>> I added the syslog line around ln 324 in server.c - just wanted to see >>> that data was coming in. >>> >>> do { >>> len = read(fd, &data, to_read); >>> syslog(LOG_ERR,"%s",data.b); >>> } while (len < 0 && errno == EINTR); >> >> ok, thanks. >> >> so, yes, please check your hid report format. >> >> this it the input report you should be using (this is taken from your >> hid descriptor) >> >> Input id=1 size=8 count=6 page=Keyboard >> usage=Reserved_(no_event_indicated), logical range 0..255 >> >> so, it means that on-the-wire packet should be 10 bytes >> >> byte 0: 0xA1 -- bluetooth header >> byte 1: 0x01 -- hid report id >> byte 2: 0xXX -- bitmask for modifier key pressed, i.e. ctrl, shift, alt, etc. >> byte 3: 0x00 -- padding >> byte 4: 0xXX -- key code pressed #1 >> byte 5: 0xXX -- key code pressed #2 >> byte 6: 0xXX -- key code pressed #3 >> byte 7: 0xXX -- key code pressed #4 >> byte 8: 0xXX -- key code pressed #5 >> byte 9: 0xXX -- key code pressed #6 >> >> hid repot should tell which keys (scan codes 1..6) are pressed >> currently, and, which modifier keys are pressed currently (byte 2). if >> no keys are pressed currently, then, 0x00 should be used. host should >> keep track of which keys were pressed previously, and, effectively >> build a press/release logic itself. meaning if hid report N had key >> code K, and, hid report N+1 did not have key code K, then it means >> that key code K was pressed and subsequently released. >> >> here is another example that my be easier to understand. suppose we >> start with no keys pressed. hid report will look like >> >> byte 0: 0xA1 >> byte 1: 0x01 >> byte 2: 0x00 >> byte 3: 0x00 >> byte 4: 0x00 >> byte 5: 0x00 >> byte 6: 0x00 >> byte 7: 0x00 >> byte 8: 0x00 >> byte 9: 0x00 >> >> now, suppose key 'a' was pressed and then released. two hid reports >> will go out, i.e. >> >> byte 0: 0xA1 >> byte 1: 0x01 >> byte 2: 0x00 >> byte 3: 0x00 >> byte 4: key code for 'a' key >> byte 5: 0x00 >> byte 6: 0x00 >> byte 7: 0x00 >> byte 8: 0x00 >> byte 9: 0x00 >> >> followed by >> >> byte 0: 0xA1 >> byte 1: 0x01 >> byte 2: 0x00 >> byte 3: 0x00 >> byte 4: 0x00 >> byte 5: 0x00 >> byte 6: 0x00 >> byte 7: 0x00 >> byte 8: 0x00 >> byte 9: 0x00 >> >> meaning key 'a' was released and no other keys were pressed. >> >> i hope it makes sense to you. >> >> thanks, >> max > > I finally have it working, except for some reason it's repeating last > character. ('1' in the following example) > > Sending 'ABEF010231' to FIFO buffer, the client "types" the following: > > ABEF010231111111111111111111111111111111111111111111111111111111111111 > > 1 forever, until i send another string of data to FIFO buffer, then it > again repeats the last key as if it were stuck. > > i have 'release' key defined as > > /* empty struct for key release */ > struct hidrep_keyb_t * releasekey = (void *)hidrep; > releasekey->btcode = 0xA1; > releasekey->rep_id = REPORTID_KEYBD; > releasekey->modify = 0x00; > releasekey->pad = 0x00; > releasekey->key[0] = 0x00; > releasekey->key[1] = 0x00; > releasekey->key[2] = 0x00; > releasekey->key[3] = 0x00; > releasekey->key[4] = 0x00; > releasekey->key[5] = 0x00; > > > here's the loop, for each character in FIFO buffer > > vkeyb->btcode = 0xA1; > vkeyb->rep_id = REPORTID_KEYBD; > vkeyb->modify = shiftkey(sfifo[i]); > vkeyb->pad = 0x00; > vkeyb->key[0] = retkey(sfifo[i]); /* key press */ > vkeyb->key[1] = 0x00; > vkeyb->key[2] = 0x00; > vkeyb->key[3] = 0x00; > vkeyb->key[4] = 0x00; > vkeyb->key[5] = 0x00; > send ( intrsockfd, vkeyb,sizeof(struct hidrep_keyb_t), MSG_NOSIGNAL ); > printf("sent data %d %lu\n",vkeyb->key[0],sizeof(struct hidrep_keyb_t)); > send ( intrsockfd, releasekey,sizeof(struct hidrep_keyb_t), MSG_NOSIGNAL ); > printf("sent release\n"); > fflush(stdout); > > it does 'shift' 0x2 modifier on A-Z > > > I think I'm missing something with the release key. > > Thank you, > > -- > Waitman Gobble > Los Altos California USA > 510-830-7975 Max, I solved the problem, I got rid of the 'release key' structure and change vkeyb->key[0] to 0, then send that as a key release. Its working now. I believe I just need to handle client disconnects, and re-connects, and I think it will be all good. Thanks for your help. -- Waitman Gobble Los Altos California USA 510-830-7975