From owner-freebsd-bluetooth@freebsd.org Sat Sep 12 14:26:57 2015 Return-Path: Delivered-To: freebsd-bluetooth@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2B2F5A02EE5 for ; Sat, 12 Sep 2015 14:26:57 +0000 (UTC) (envelope-from erdgeist@erdgeist.org) Received: from elektropost.org (elektropost.org [217.115.13.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 82E4F153D for ; Sat, 12 Sep 2015 14:26:55 +0000 (UTC) (envelope-from erdgeist@erdgeist.org) Received: (qmail 75605 invoked from network); 12 Sep 2015 14:26:54 -0000 Received: from elektropost.org (HELO elektropost.org) (erdgeist@erdgeist.org) by elektropost.org with ESMTPS (DHE-RSA-AES128-SHA encrypted); 12 Sep 2015 14:26:54 -0000 From: Dirk Engling Subject: Re: Apple Magic Mouse To: freebsd-bluetooth@freebsd.org References: <1437909200.57929.3.camel@yandex.com> Message-ID: <55F4362A.4050203@erdgeist.org> Date: Sat, 12 Sep 2015 16:26:50 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------000402030101070808000407" X-BeenThere: freebsd-bluetooth@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Using Bluetooth in FreeBSD environments List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Sep 2015 14:26:57 -0000 This is a multi-part message in MIME format. --------------000402030101070808000407 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit On 09.08.15 21:47, plunky at ogmig.net (Iain Hibbert) wrote: > I'd say that using the NetBSD driver (I am the author) is not really > possible on FreeBSD, since FreeBSD does things related to Bluetooth HIDs > differently. It should be simple enough to add the Magic Mouse handling to > the bthidd(8) daemon though, but I don't know how easy that would be, or a > separate daemon could be written instead. I've taken a look and there's several obstacles in the way. But first the good news, once I add if (fd == srv->ctrl) { static uint8_t rep[] = { 0x53, 0xd7, 0x01 }; write(new_fd, rep, 3 ); } to usr.sbin/bluetooth/bthidd/server.c:272, the hid_interrupt function in usr.sbin/bluetooth/bthidd/hid.c gets trackpad-events and mouse lift/drop from the magic mouse. My problem is now, that this feature report is hard coded and obviously not every device should be served this. But, > The way I worked the identification in NetBSD, was that when configuring a > HID device, I checked the descriptor as normal and also the > Manufacturer/Product ID via the PNP profile. When the latter matched the > Apple Magic Mouse, then it just attaches a different driver. it looks like the Manufacturer/Product ID is ignored on the hci level and thus not available at higher layers. Maybe I'm missing something here? > The Magic Mouse then needs an initialization command to be sent via the > standard HID protocol "SET_REPORT(FEATURE, 0xd7) = 0x01" once connected to > enable the special extra functionality that it provides. Also I noticed that the reports sent by the magic mouse are not reported in their hid descriptor. I get the following reports there (see attachment) 09 02 (LOCAL) USAGE Mouse (CA=Application Collection) 85 10 (GLOBAL) REPORT_ID 0x10 (16) 09 20 (LOCAL) USAGE Battery Strength 85 47 (GLOBAL) REPORT_ID 0x47 (71) 'G' 09 55 (LOCAL) USAGE 0xFF020055 85 55 (GLOBAL) REPORT_ID 0x55 (85) 'U' But when enabling the magic mouse modes as seen above, I see reports: HID Interrupt: A1 60 01 HID Interrupt: A1 61 01 Which is 0x60 and 0x61, corresponding with mouse surface lift and drop. When touching the trackpad area on the mouse, I get HID Interrupt: A1 29 00 00 80 D0 6B 9F E3 11 4D 16 83 80 32 which is report 0x29 and corresponds to the magic trackpad messages handled in the NetBSD [1] and Linux driver [2]. Problem is, that the bthidd code does not handle reports not announced in hid descriptors at all. So I would need to either manually inject the report id in hid_device->desc and add handler code, handle magic mouse in a completely different code path, or write my own driver. Maybe Maksim has some ideas, the daemon is his code, after all. Regards, erdgeist [1] http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/bluetooth/btmagic.c?rev=1.14&content-type=text/x-cvsweb-markup [2] http://lxr.free-electrons.com/source/drivers/hid/hid-magicmouse.c --------------000402030101070808000407 Content-Type: text/plain; charset=UTF-8; name="magic-mouse.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="magic-mouse.txt" Ly8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQovLyBEZWNvZGVkIEFwcGxpY2F0aW9uIENv bGxlY3Rpb24KLy8tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQoKLyoKMDUgMDEgICAgICAg IChHTE9CQUwpIFVTQUdFX1BBR0UgICAgICAgICAweDAwMDEgR2VuZXJpYyBEZXNrdG9wIFBh Z2UKMDkgMDIgICAgICAgIChMT0NBTCkgIFVTQUdFICAgICAgICAgICAgICAweDAwMDEwMDAy IE1vdXNlIChDQT1BcHBsaWNhdGlvbiBDb2xsZWN0aW9uKQpBMSAwMSAgICAgICAgKE1BSU4p ICAgQ09MTEVDVElPTiAgICAgICAgIDB4MDEgQXBwbGljYXRpb24gKFVzYWdlPTB4MDAwMTAw MDI6IFBhZ2U9R2VuZXJpYyBEZXNrdG9wIFBhZ2UsIFVzYWdlPU1vdXNlLCBUeXBlPUNBKQo4 NSAxMCAgICAgICAgICAoR0xPQkFMKSBSRVBPUlRfSUQgICAgICAgICAgMHgxMCAoMTYpCjA1 IDA5ICAgICAgICAgIChHTE9CQUwpIFVTQUdFX1BBR0UgICAgICAgICAweDAwMDkgQnV0dG9u IFBhZ2UKMTkgMDEgICAgICAgICAgKExPQ0FMKSAgVVNBR0VfTUlOSU1VTSAgICAgIDB4MDAw OTAwMDEgQnV0dG9u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OAo5NSA0MCAgICAgICAgICAoR0xPQkFMKSBSRVBPUlRfQ09VTlQgICAg ICAgMHg0MCAoNjQpIE51bWJlciBvZiBmaWVsZHMKQjEgQTIgICAgICAgICAgKE1BSU4pICAg RkVBVFVSRSAgICAgICAgICAgIDB4MDAwMDAwQTIgKDY0IGZpZWxkcyB4IDggYml0cykgMD1E YXRhIDE9VmFyaWFibGUgMD1BYnNvbHV0ZSAwPU5vV3JhcCAwPUxpbmVhciAxPU5vUHJlZlN0 YXRlIDA9Tm9OdWxsIDE9Vm9sYXRpbGUgMD1CaXRtYXAKQzAgICAgICAgICAgIChNQUlOKSAg IEVORF9DT0xMRUNUSU9OICAgICBBcHBsaWNhdGlvbgoqLwoKCg== --------------000402030101070808000407-- From owner-freebsd-bluetooth@freebsd.org Sat Sep 12 17:53:40 2015 Return-Path: Delivered-To: freebsd-bluetooth@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E6B93A02B05 for ; Sat, 12 Sep 2015 17:53:39 +0000 (UTC) (envelope-from maksim.yevmenkin@gmail.com) Received: from mail-wi0-x22d.google.com (mail-wi0-x22d.google.com [IPv6:2a00:1450:400c:c05::22d]) (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 7B0B71BA4 for ; Sat, 12 Sep 2015 17:53:39 +0000 (UTC) (envelope-from maksim.yevmenkin@gmail.com) Received: by wicfx3 with SMTP id fx3so95830472wic.1 for ; Sat, 12 Sep 2015 10:53:36 -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=3oGIeIXYtG+CPHU06eLzDVachQ0wkiHSYSwH0CF9HeY=; b=dLAe3+Neeu/NvLj5BQKSBlV3tjebmJ98plmtxGBaE98cIbjXgDDRHOvOzzm2hbsjrh x2sNJHGutLViIchkofb2gWipY+TibEnngP3qz+Dk43e+y5+vkB3QVKYqHxtQrGhxjIra y0eDfspWcWXEWIZc4OBWX/E2XpuOAL/UX12K9fUJtFSkjExXZtvr1n79gE11owZcjToS J67VN8nnG40kLMTtwhrIBX/pPE5KOzwOXTi0ZiekcJeCwPjCdWVSkthLpR3rY+2WPREo zxsuAeBns9cbuxWxaX2x5/pzVPoXt0jjEGgFbyTfcmk5eZ96eCJtYgic2gRdIC0kWhBX VPsA== MIME-Version: 1.0 X-Received: by 10.180.21.169 with SMTP id w9mr8473842wie.73.1442080416821; Sat, 12 Sep 2015 10:53:36 -0700 (PDT) Received: by 10.28.146.132 with HTTP; Sat, 12 Sep 2015 10:53:36 -0700 (PDT) In-Reply-To: <55F4362A.4050203@erdgeist.org> References: <1437909200.57929.3.camel@yandex.com> <55F4362A.4050203@erdgeist.org> Date: Sat, 12 Sep 2015 10:53:36 -0700 Message-ID: Subject: Re: Apple Magic Mouse From: Maksim Yevmenkin To: Dirk Engling Cc: "freebsd-bluetooth@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-bluetooth@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Using Bluetooth in FreeBSD environments List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Sep 2015 17:53:40 -0000 [...] > I've taken a look and there's several obstacles in the way. But first > the good news, once I add > > if (fd == srv->ctrl) { > static uint8_t rep[] = { 0x53, 0xd7, 0x01 }; > write(new_fd, rep, 3 ); > } > > to usr.sbin/bluetooth/bthidd/server.c:272, the hid_interrupt function in > usr.sbin/bluetooth/bthidd/hid.c gets trackpad-events and mouse lift/drop > from the magic mouse. > > My problem is now, that this feature report is hard coded and obviously > not every device should be served this. But, great! > it looks like the Manufacturer/Product ID is ignored on the hci level > and thus not available at higher layers. Maybe I'm missing something here? i think it should be possible to teach bthidd to make another sdp request to pull device id sdp record (if available). if apple mouse answers it then it should very easy to identify it and enable all the features. >> The Magic Mouse then needs an initialization command to be sent via the >> standard HID protocol "SET_REPORT(FEATURE, 0xd7) = 0x01" once connected to >> enable the special extra functionality that it provides. > > Also I noticed that the reports sent by the magic mouse are not reported > in their hid descriptor. I get the following reports there (see attachment) > > 09 02 (LOCAL) USAGE Mouse (CA=Application Collection) > 85 10 (GLOBAL) REPORT_ID 0x10 (16) > > 09 20 (LOCAL) USAGE Battery Strength > 85 47 (GLOBAL) REPORT_ID 0x47 (71) 'G' > > 09 55 (LOCAL) USAGE 0xFF020055 > 85 55 (GLOBAL) REPORT_ID 0x55 (85) 'U' > > But when enabling the magic mouse modes as seen above, I see reports: > > HID Interrupt: A1 60 01 > HID Interrupt: A1 61 01 > > Which is 0x60 and 0x61, corresponding with mouse surface lift and drop. > When touching the trackpad area on the mouse, I get > > HID Interrupt: A1 29 00 00 80 D0 6B 9F E3 11 4D 16 83 80 32 > > which is report 0x29 and corresponds to the magic trackpad messages > handled in the NetBSD [1] and Linux driver [2]. > > Problem is, that the bthidd code does not handle reports not announced > in hid descriptors at all. So I would need to either manually inject the > report id in hid_device->desc and add handler code, handle magic mouse > in a completely different code path, or write my own driver. > > Maybe Maksim has some ideas, the daemon is his code, after all. well... please read above. if its possible to identify apple mouse then its possible to implement completely different handling of reports (including extra ones) thanks, max