From owner-freebsd-bluetooth@FreeBSD.ORG Sat Mar 21 18:16:05 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 D0EEB886 for ; Sat, 21 Mar 2015 18:16:05 +0000 (UTC) Received: from mail-wi0-x233.google.com (mail-wi0-x233.google.com [IPv6:2a00:1450:400c:c05::233]) (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 4E27E77D for ; Sat, 21 Mar 2015 18:16:05 +0000 (UTC) Received: by wibgn9 with SMTP id gn9so18670387wib.1 for ; Sat, 21 Mar 2015 11:16:03 -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=ixMh1NHpl0IMRdSwhshjZTzuvNwTNkpo5SzsDXHuVws=; b=XvdijyOSw43B4FwC+SWP3I8pad5jkiEdJ2PBKwq5RRzFr/Tw6KSuAEDsns+bAbdP+y SjzZsLHEqcXSiPPM2cn1ZK8jM/Nj0iSM8lQ9anfq711kXBkK/mQdEeq3DDBA3tNRsFrP juPeNfZarGIgehGpM4muEb2JGf5bodwlSOTsYgcXjS11UGMlnyKyZMZAgQ7dszo+Nhr2 Vpt0E/M9+iMKBPw3g54uGcJJ55MQK7hyYNgEEA1KSPW2tkqFbFbnU5b/DZRnrh02CLkd 63yI+Ce0hc+WB0iLMzw1OLqdMRu8Ram0uqrMsuq33DTIvD6HFuppwbEfKqbUKIxrSW89 SjFQ== MIME-Version: 1.0 X-Received: by 10.194.237.34 with SMTP id uz2mr167735525wjc.157.1426961763650; Sat, 21 Mar 2015 11:16:03 -0700 (PDT) Received: by 10.27.214.136 with HTTP; Sat, 21 Mar 2015 11:16:03 -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 11:16:03 -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 18:16:05 -0000 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