From owner-freebsd-bluetooth@FreeBSD.ORG Sat Mar 21 19:00:53 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 0AECE24C for ; Sat, 21 Mar 2015 19:00:53 +0000 (UTC) Received: from mail-we0-x22f.google.com (mail-we0-x22f.google.com [IPv6:2a00:1450:400c:c03::22f]) (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 769C2BF3 for ; Sat, 21 Mar 2015 19:00:52 +0000 (UTC) Received: by wetk59 with SMTP id k59so106276557wet.3 for ; Sat, 21 Mar 2015 12:00:50 -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=z/+MGy994CrV03YzntzUVI6yGKbfCtQ+/tmX8DiYbNM=; b=yF6Crx8rXP9d6lW7i9VEl/QoqrOfNxFLWx7L5NSHP6zinnkcdH+VAkx5NSN0VozkSZ YFf+yjNuuBwR0eVfsqe7bmjyWyBxGidsTP0lCG7zW9X5+SrkFCxc/k/6HoldRhkhi4ac +cGGAbBaMOgBbApriSlcbJoFUs6uBAUpOCs23hkmIrrq9GIirJ3XSE7SPeyS4Hj6g+6A QoZDo4qWeEaleAmT5pqizktOmyLciSSTxQo0vKVxTkenB6AtNWXFHdx3JkpujZOpKuRQ N0kNXQiAwgaEUCRQuBZTSSM2WPLdRIK5UcDKvEFCqv/5VNcBDJ6Qb/ubT5xqA/HOQRLF v4zw== MIME-Version: 1.0 X-Received: by 10.180.218.71 with SMTP id pe7mr6353573wic.70.1426964450788; Sat, 21 Mar 2015 12:00:50 -0700 (PDT) Received: by 10.27.214.136 with HTTP; Sat, 21 Mar 2015 12:00:50 -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:00:50 -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:00:53 -0000 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