From owner-freebsd-bluetooth@FreeBSD.ORG Sat Mar 21 19:35:32 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 D583F66D for ; Sat, 21 Mar 2015 19:35:32 +0000 (UTC) Received: from mail-wi0-x234.google.com (mail-wi0-x234.google.com [IPv6:2a00:1450:400c:c05::234]) (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 5171AF13 for ; Sat, 21 Mar 2015 19:35:32 +0000 (UTC) Received: by wibg7 with SMTP id g7so14707513wib.1 for ; Sat, 21 Mar 2015 12:35:30 -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=nSHJMCwQZEqKokQMOHrd6gvBGoc0k9HKX54G9+BBQaM=; b=KBTSSbOfcb6dnNARqJDffVjTA4YotOjjZ5sJI+UesFtOQl3dW8BrBSbjoo9CJDtZBP BNWdmUw7BO4e8DOXBZopKm7K5EdlFsmgCRMMbjJ2SGHqLhuyKVUMv5RM4vOdVC9O+iGy HpiRT3KvSsPyBaYirjJS+y4ombqApPMHeU4P3Ebkhw1dAjaZgWkqQ5jDB+ua78kBPpRT LXGj/8NOq3dGRQdm0MZtO+ZkRTAZEdvNqgYGC4VOUNSLeEM78xexyWpJ4PZKf4x2RrwN nO3/nwMPUKcuZpfpn2SjM/HsCYMq+yN+zZZFa7lGYq3swPI7VpEqGU5+XFre4U+kJ/iS BnqA== MIME-Version: 1.0 X-Received: by 10.194.75.168 with SMTP id d8mr174204879wjw.87.1426966530745; Sat, 21 Mar 2015 12:35:30 -0700 (PDT) Received: by 10.27.214.136 with HTTP; Sat, 21 Mar 2015 12:35:30 -0700 (PDT) In-Reply-To: References: <0AD7A2F7-37BE-4F6A-9FD6-F6C81B2CAF36@gmail.com> <77352B43-637C-4E0D-B4CC-B42D977551F6@gmail.com> Date: Sat, 21 Mar 2015 12:35:30 -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: Sat, 21 Mar 2015 19:35:32 -0000 On Sat, Mar 21, 2015 at 12:00 PM, Waitman Gobble wrote: > On Sat, Mar 21, 2015 at 11:16 AM, Waitman Gobble wrote: >> On Sat, Mar 21, 2015 at 11:02 AM, Maksim Yevmenkin >> wrote: >>> [...] >>> >>>> Hey, that works! Thank you. >>>> >>>> hccontrol Write_Class_Of_Device 02:50:40 >>> >>> great! as i said, you can also automate it. please read >>> bluetooth.device.conf(5). in your case you will need to create >>> /etc/bluetooth/ubt0.conf and add >>> >>> class="02:50:40" >>> >>> this way class will be applied every time you start ubt0 device. >>> >>>> so now I have to figure out how to send the PIN that the connecting >>>> device demands to receive. I suppose it's sending 0000. But it appears >>>> there has to be a human action in this case. >>> >>> you have a couple of options here: >>> >>> (1) use hcsecd(8). since you want to pair with any host (because your >>> code implements device) you can use default entry. please read >>> hcsecd.conf(5) for more details. >>> >>> device { >>> bdaddr 00:00:00:00:00:00; >>> name "Default entry"; >>> key nokey; >>> pin "0000"; >>> } >>> >>> something like this might work; >>> >>> (2) write your own code. basically, you want to open raw HCI socket >>> and listen for PIN code and link key requests and events. hcsecd(8) >>> source code can be used as reference; >>> >>> thanks, >>> max >> >> Max, >> >> I modified hcsecd a little. if you set the pin to "PROMPT" in hcsecd >> it blocks on reading a FIFO at /tmp/pinprompt >> >> https://github.com/waitman/hcsecd >> >> >> echo "835753" > /tmp/pinprompt >> >> it adds "enter key" 0x0D at the end so that device will continue. >> Otherwise it sits there until the end of time, I think? I obviously >> didn't wait until the end of time, but my android phone went way past >> the timeout without the 'enter key' appended to the pin string. >> >> if you want PIN reply on some devices and PROMPT on others, that can >> be an issue. >> >> looks like it works,but only tested like 10 times. >> >> >> #define FIFO_NAME "/tmp/pinprompt" >> ... >> char newpin[16]; >> ... >> >> strncpy(newpin,pin,strlen(pin)); >> if (strcmp("PROMPT",pin)==0) >> { >> char sfifo[300]; >> int numfifo, fdfifo; >> mknod(FIFO_NAME, S_IFIFO | 0666, 0); >> fdfifo = open(FIFO_NAME, O_RDONLY); >> do { >> if ((numfifo = read(fdfifo, sfifo, 300)) == -1) >> { >> /* oh no */ >> } else { >> //syslog(LOG_DEBUG,"%s pincode entered",sfifo); >> } >> } while (numfifo>0); >> >> sfifo[strlen(sfifo)-1] = 0x0D; /* enter key */ >> sfifo[strlen(sfifo)-1] = '\0'; >> strncpy(newpin,sfifo,strlen(sfifo)); >> } >> ng_hci_pin_code_rep_cp *cp = NULL; >> >> cmd->opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, >> NG_HCI_OCF_PIN_CODE_REP)); >> cmd->length = sizeof(*cp); >> >> cp = (ng_hci_pin_code_rep_cp *)(cmd + 1); >> memcpy(&cp->bdaddr, bdaddr, sizeof(cp->bdaddr)); >> strncpy(cp->pin, newpin, strlen(newpin)); >> cp->pin_size = strlen((char const *) cp->pin); >> syslog(LOG_DEBUG, "Sending PIN_Code_Reply to '%s' " \ >> "for remote bdaddr %s", >> addr->hci_node, bt_ntoa(bdaddr, NULL)); >> >> >> >> -- >> Waitman Gobble >> Los Altos California USA >> 510-830-7975 > > > correction, should be newpin[32], or maybe more.. MS windows asks for > a longer pincode. > > -- > Waitman Gobble > Los Altos California USA > 510-830-7975 ok this is now tested to work on Android phone, bluedevil/KDE on a GNU/Linux machine, an MS Windows 8.1 machine and an Apple OS X machine. I don't have an Iphone but I suppose it should work. The problem was when pairing a bluetooth keyboard on Android, it demands to have the pin code entered 'manually' on the keyboard. Other systems it looks like this is an option. For example, on Apple OS X, pairing with the bt device on the FreeBSD machine, there is a prompt displayed to "enter a pin code that is displayed on the screen". "6450 3430" so on the FreeBSD machine, # echo "64503430" > /tmp/pinprompt Then the Apple machine pairs to the FreeBSD device. Maybe it's not so useful to have in FreeBSD source, but might be helpful to some people browsing the mailing list archives. -- Waitman Gobble Los Altos California USA 510-830-7975