Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Mar 2015 11:16:03 -0700
From:      Waitman Gobble <gobble.wa@gmail.com>
To:        Maksim Yevmenkin <maksim.yevmenkin@gmail.com>
Cc:        "freebsd-bluetooth@freebsd.org" <freebsd-bluetooth@freebsd.org>, Iain Hibbert <plunky@ogmig.net>
Subject:   Re: register HID with SDP error
Message-ID:  <CAFuo_fxME%2B9-bA6KWG4pjokAZhfEeMGptMw-H3z=eb%2B9KHGhug@mail.gmail.com>
In-Reply-To: <CAFPOs6o7fSh=-Jossgo_nLLz5iPpZA%2BGX%2BvxH7bezdQSk1_j-w@mail.gmail.com>
References:  <CAFuo_fy9xRU2T3GUPY8116yZCUd8sL9pBQ9ixXnMwO56niJFog@mail.gmail.com> <CAFuo_fzdmB79qdoH8P5EcO_ZZoa=_id6h=eqFBXvP_a%2B3WMkLw@mail.gmail.com> <CAFuo_fzB3A5L3vivH7Z80OEoBtVEHftEYE4LUkhnrkguzL5GDA@mail.gmail.com> <CAFuo_fzrk%2BWLXivZrnTsGQD%2BS7mq%2BUSXB7Mn6%2BJT=y64JakGSw@mail.gmail.com> <CAFPOs6q3iVcNthF=S--UgTm=5wA0HM6coqB7AcmCKb=55OWdTQ@mail.gmail.com> <CAFuo_fxgBVKxmzbJs%2B-XDz%2Bu4tb2_i3eYXSa-oiOoU%2BQD6ApwQ@mail.gmail.com> <CAFPOs6r_D7bcGCMP_bP%2BQtZgKt7Oj5jRJ2v872RODekn%2B6xv1Q@mail.gmail.com> <CAFuo_fwPuaD4bYwfZou0RBswZsTmdtVZA1B2GqUdo3ZJJiWRQg@mail.gmail.com> <0AD7A2F7-37BE-4F6A-9FD6-F6C81B2CAF36@gmail.com> <CAFuo_fye5RWNtjsutHa%2BbXL0AYHYRpJxW-b=48o0iMwX227wdA@mail.gmail.com> <alpine.NEB.2.11.1503170658130.4414@galant.ogmig.net> <CAFuo_fx47uRC-eKD_KtsSsrMCQZauyHyCOgRxGbtp_WEZ49o_Q@mail.gmail.com> <CAFPOs6rYXOFPk5_nqXivToUvGRjXDMS=XL60RyKbMQm7nP8wFg@mail.gmail.com> <CAFuo_fw5-YtH_sj3Ft52hpfXEP8QCkweptJzT0eUSos9DoBZ%2BA@mail.gmail.com> <CAFuo_fzSMNvwewpkKxcLr9aHyTcwaVgcreLtexSo=FNzNhC6og@mail.gmail.com> <CAFPOs6rJ_SaKjmXrbr%2Bpa9BoVL2HtjkzoyBo015BFK1QB9ZVsQ@mail.gmail.com> <CAFuo_fxGgWYp5x=xWbFogj8F8ZMULFQw_HOWZiJ42=vDO7tXnQ@mail.gmail.com> <CAFPOs6o7jrULqF%2BVSbZ0ckFx3MqAbO-eHyL5FfToTL4xMxSBLQ@mail.gmail.com> <CAFuo_fxocC6KhHqXf2HWpMLFNMFo2tdmv4RMv1MYYBXkC=3FJg@mail.gmail.com> <CAFuo_fwp_Nb2kOk=7qKO6VV5%2Bu_MG5GwaKYkwKFDjUuVo%2BG-aw@mail.gmail.com> <CAFPOs6rNSqS=ZyZKZDWy2T437bkoXpfKEFn_Znpo7X6UgXMNVw@mail.gmail.com> <CAFuo_fzMaRu-VgP48GqETT6AfYT20eR6Ry13J=CiC=mibSvCig@mail.gmail.com> <CAFPOs6oBd4OagKixg6NH-uWzWCc4g%2B7U-uO1VdQY-UzzcZQBPA@mail.gmail.com> <CAFuo_fz-hZ9WXX1Uvc-vEwTMrPeyakGsStTkS6RGEzwMTh%2BsUw@mail.gmail.com> <77352B43-637C-4E0D-B4CC-B42D977551F6@gmail.com> <CAFuo_fyHmY%2BO6uN4DkBoHr99=X3PN2gzL0gZ6EyrZfkRL8MWBw@mail.gmail.com> <CAFPOs6o7fSh=-Jossgo_nLLz5iPpZA%2BGX%2BvxH7bezdQSk1_j-w@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Mar 21, 2015 at 11:02 AM, Maksim Yevmenkin
<maksim.yevmenkin@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFuo_fxME%2B9-bA6KWG4pjokAZhfEeMGptMw-H3z=eb%2B9KHGhug>