register HID with SDP error

Waitman Gobble gobble.wa at gmail.com
Sat Mar 21 19:00:53 UTC 2015


On Sat, Mar 21, 2015 at 11:16 AM, Waitman Gobble <gobble.wa at gmail.com> wrote:
> On Sat, Mar 21, 2015 at 11:02 AM, Maksim Yevmenkin
> <maksim.yevmenkin at gmail.com> 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


More information about the freebsd-bluetooth mailing list