# pc-bluetoothmanager from PC-BSD to FreeBSD



## sk8harddiefast (Sep 27, 2013)

HI. I thought to give a try to port somehow the pc-bluetoothmanager and pc-bluetoothtray from PC-BSD to FreeBSD. First I install from ports libpcbsd.


```
cd /usr/ports/sysutils/libpcbsd  && make install clean
```

After I download from GitHub the PC-BSD source.

https://codeload.github.com/pcbsd/pcbsd/zip/9.1-release

In the /src-qt4 folder I found pc-bluetoothmanager and pc-bluetoothtray folders with the executables. Now I am st*u*ck.

`sudo ./pc-bluetoothmanager` returns 


```
Shared object "libpcbsd-ui.so.0" not found, required by "pc-bluetoothmanager"
```

But nowhere I can find this library. Also `sudo ./pc-bluetoothtray` returns


```
Shared object "libQtSolutions_SingleApplication-head.so.1" not found, required by "pc-bluetoothtray"
```

If we could make it work, maybe was the first step to port the Bluetooth manager of PC-BSD to FreeBSD.

Update:

I Installed from ports devel/qt4-qtsolutions-singleapplication and now I get
`sudo ./pc-bluetoothtray`

```
Shared object "libpcbsd-utils.so.0" not found, required by "pc-bluetoothtray"
```

Also in the PC-BSD source tree in src-qt4 I finally found /libpcbsd/ui and /libpcbsd/utils . I should compile somehow the source with GCC to create the libraries libpcbsd-ui.so.0 and libpcbsd-utils.so.0

Update:

According http://blog.pcbsd.org/2012/02/call-for-testers-bluetooth-manager/ I went to  src-qt4 /libpcbsd, I ran `qmake-qt4 *.pro` and a Makefile was created. Then I ran `make` and the libraries just compiled 

And now just copy this libs in/lib /usr./lib/ usr/local/lib /usr/local/kde4/lib 
I also run
`qmake-qt4 *.pro
make`
on pc-bluetoothmanager and pc-bluetoothtray and insist that cannot find the libs

*I MADE IT WORK FINALLY.*

On folder /src-qt4 on folders
 pc-bluetoothmanager, pc-bluetoothtray and  pc-bsdutils
after `make`, I run `make install`
Now:

```
[ember@Unix /usr/home/ember]$ ls /usr/local/bin/pc-bluetooth*
/usr/local/bin/pc-bluetoothmanager	/usr/local/bin/pc-bluetoothtray
```
and:

```
[ember@Unix /usr/home/ember]$ ls /usr/local/lib/libpcbsd*
/usr/local/lib/libpcbsd-ui.so		/usr/local/lib/libpcbsd-utils.so.0.9
/usr/local/lib/libpcbsd-ui.so.0		/usr/local/lib/libpcbsd-utils.so.0.9.8
/usr/local/lib/libpcbsd-ui.so.0.9	/usr/local/lib/libpcbsd.so
/usr/local/lib/libpcbsd-ui.so.0.9.8	/usr/local/lib/libpcbsd.so.0
/usr/local/lib/libpcbsd-utils.so	/usr/local/lib/libpcbsd.so.8.0
/usr/local/lib/libpcbsd-utils.so.0
```

Now I will test if can make my Logitech bluetooth keyboard work!


----------



## sk8harddiefast (Sep 27, 2013)

Now tried to make my Logitech keyboard (k810) to make it finally work.
Here we are.
On /etc/rc.conf

```
vkbd_load="YES"
hcsecd_enable="YES"
sdpd_enable="YES"
bthidd_enable="YES"
bthidd_config="/etc/bluetooth/bthidd.conf"
```

my /etc/bluetooth/hcsecd.conf


```
device {
 bdaddr  00:1f:20:4d:f2:c5;
 name    "Logitech K810";
 key     nokey;
 pin     "1234";
}
```

and the problem:






















Pairing always was the problem 

FINALLY.

I ask from someone to help me

1) fix the problem and make my keyboard work
2) to create together a good tutorial to help users
3) to port somehow pc-bluetoothmanager on FreeBSD ports


----------



## sk8harddiefast (Sep 28, 2013)

Nobody can help here?


----------



## sossego (Sep 29, 2013)

Have you tried the porters handbook? 
http://www.freebsd.org/doc/en/books/porters-handbook/book.html
I'm studying that right now.
What I have done is taken over ports for a transitional period to make sure they received attention. The other part is I try to build natively on the machine before I even think of asking for it to be ported.
You did the second; and, you will need to add the patches. Basically, you've started porting the package by making it build on FreeBSD. If there is anything in the PC-BSD for you to copy, then do so. This is a KDE4 application and should be brought to the attention of Area51/FreeBSD-KDE mailing list. Thanks for the work you have done.


----------



## sk8harddiefast (Sep 29, 2013)

sysutils/libpcbsd port deleted and replaced with [sysutils/libpcbsd-utils and /sysutils/libpcbsd-utils-qt4.

Also first of all someone must help me to make my keyboard work. If my keyboard is not working, how can I be sure that problem is not on pc-bluetoothmanager? The GUI is up but I cannot pair my device, pc-bluetoothmanager bug, wrong settings? I must clear this up.

Second, I want to create a tutorial to make clear first of all in my mind what's exactly all the steps, one by one


----------



## sossego (Sep 29, 2013)

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/network-bluetooth.html

Look to see if the device is recognized.
comms/hcidump .

That may help.


----------



## sk8harddiefast (Sep 29, 2013)

The device is recognized. In the past, before go to vacations, I spoke using mail with Maksim witch is the Bluetooth developer of FreeBSD if I am right and we made a huge try to make my keyboard to work. Never made it.
Pairing as far as I remember was the problem. Could not connect.
My last mail I send to him was my `hcidump`

```
root@Unix:/home/ember # sudo hcidump -x
HCIDump - HCI packet analyzer ver 1.5

device: any snap_len: 65535 filter: 0xffffffffffffffff
> HCI Event: Connect Request(0x04) plen 10
  C5 F2 4D 20 1F 00 40 05 00 01
< HCI Command: Accept Connection Request(0x01|0x0009) plen 7
  C5 F2 4D 20 1F 00 00
> HCI Event: Command Status(0x0f) plen 4
  00 01 09 04
> HCI Event: Role Change(0x12) plen 8
  00 C5 F2 4D 20 1F 00 00
> HCI Event: Connect Complete(0x03) plen 11
  00 0B 00 C5 F2 4D 20 1F 00 01 00
< HCI Command: Write Link Policy Settings(0x02|0x000d) plen 4
  0B 00 05 00
> HCI Event: Command Complete(0x0e) plen 6
  01 0D 08 00 0B 00
> HCI Event: Link Key Request(0x17) plen 6
  C5 F2 4D 20 1F 00
< HCI Command: Link Key Request Negative Reply(0x01|0x000c) plen 6
  C5 F2 4D 20 1F 00
> HCI Event: Command Complete(0x0e) plen 10
  01 0C 04 00 C5 F2 4D 20 1F 00
> HCI Event: Disconn Complete(0x05) plen 4
  00 0B 00 13
> HCI Event: Connect Request(0x04) plen 10
  C5 F2 4D 20 1F 00 40 05 00 01
< HCI Command: Accept Connection Request(0x01|0x0009) plen 7
  C5 F2 4D 20 1F 00 00
> HCI Event: Command Status(0x0f) plen 4
  00 01 09 04
> HCI Event: Role Change(0x12) plen 8
  00 C5 F2 4D 20 1F 00 00
> HCI Event: Connect Complete(0x03) plen 11
  00 0C 00 C5 F2 4D 20 1F 00 01 00

< HCI Command: Write Link Policy Settings(0x02|0x000d) plen 4
  0C 00 05 00

> HCI Event: Link Key Request(0x17) plen 6
  C5 F2 4D 20 1F 00
> HCI Event: Command Complete(0x0e) plen 6
  01 0D 08 00 0C 00

< HCI Command: Link Key Request Negative Reply(0x01|0x000c) plen 6
  C5 F2 4D 20 1F 00
> HCI Event: Command Complete(0x0e) plen 10
  01 0C 04 00 C5 F2 4D 20 1F 00
> HCI Event: Disconn Complete(0x05) plen 4
  00 0C 00 13
```

As far I understood the problem is on pairing the device and somewhere I think I read that's a bug. Can someone confirm if this is FreeBSD's Bluetooth pairing bug?


----------



## sossego (Sep 29, 2013)

http://forums.freebsd.org/showthread.php?t=40779

http://forums.freebsd.org/showthread.php?t=39679

Try booting in verbose mode. In fact, be sure that verbose - if the flag is available - is enabled for all bluetooth applications.


----------



## sk8harddiefast (Sep 30, 2013)

So the problem is with the driver and we need a patch. Right?


----------



## sossego (Sep 30, 2013)

You need to follow the steps you did in the Logitech BT keyboard thread you started.

List the steps to follow in yourr tutorial
Contact the PC-BSD mailing list and see what they did to make it work including toolkit/qt4/KDE interface.
Apply any patches and submit to the mailing lists.

FreeBSD and PC-BSD should have similar Makefile(s). You also need to find someone with similar equipment - shouldn't be that hard - who is willing to test your software.


----------



## sk8harddiefast (Sep 30, 2013)

I had posted on forum and I got an answer: http://forums.pcbsd.org/showthread.php?t=20890
Now I build KDE4 just because I get bored with Xfce4 so I want to give it a second try and tomorrow, I am going to do that @beanpole said.


----------



## sk8harddiefast (Oct 6, 2013)

I just can't do it work. `pc-blutoothmanager` and `pc-bluetoothtray`, works. Bluetooth adapter scan and see my keyboard. I also made it to initiate pairing. But still keyboard cannot connect (the connection led is blinking and not stabilized) and of course is not writing. Here is all my work step by step until now.

My /etc/rc.conf

```
vkbd_load="YES"
hcsecd_enable="YES"
sdpd_enable="YES"
bthidd_enable="YES"
```

My /boot/loader.conf

```
ng_ubt_load="YES"
ng_l2cap_load="YES"
```

For libpcbsd-ui.so and libpcbsd-utils.so I build them from source. They exist on sysutils/pcbsd-utils-qt4 but comes with some PCBSD tools that I don't want.

`pc-bluetoothmanager`, `pc-bluetoothtray` and `pcbsd-utils`, build from here: https://github.com/pcbsd/pcbsd (Master)

Is not about only for me to make it work. Is about to have a GUI Bluetooth manager on FreeBSD and I need some help here.


----------



## sossego (Oct 6, 2013)

Run the application from a terminal with both debugging and verbose outputs. You will need to output the information to a text file with`$BIN_APPLICATION -$VERBOSE -$DEBUGGING >& $FILE.txt`. Use pastebinit and then attach it as a reply to the post at PC-BSD forums.


----------



## sk8harddiefast (Oct 6, 2013)

Verbose mode is that I get on terminal when I start the app from terminal? Right? Debugging output?


----------



## sossego (Oct 7, 2013)

Yes. You want to run the application in a terminal.
`$APPLICATION --help (or -help)` should give you the list of available commands.


----------



## sk8harddiefast (Oct 7, 2013)

Is not giving me available commands. `pc-bluetoothmanager --help` just open `pc-bluetoothmanager.` Also no manual.
But. Here is the process step by step. I am going to send it to PCBSD too. I hope maybe someone can understand what's happen. First of all I deleted all entries from /etc/bluetooth (I kept backup) to see what files `pc-bluetoothmanager` creates during my keyboard configuration.

Steps:
1: Powering Logitech keyboard k810.
2: Starting `pc-bluetoothmanager` application using `sudo`
3: I press connect button on the bottom of keyboard.
4: Now the 3 leds blinking so I press the third led which is the only available (Other two are paired on tablet and on iphone)
5: On program I go -> New devices tab ->Scan button and I see my keyboard. Logitech K810 (00:1F:20:4D:F2:C5)
6: Add device is not available for press. To be available I must go first to Saved Devices tab and then back to New Devices tab
7: Press Add device and a popup ask me for PIN CODE.
8: Try to write the PIN Code from my Bluetooth keyboard but is not writing.

On this procedure terminal return:

```
sudo pc-bluetoothmanager
Password:
Locale: "" 
Attempted to refresh an unknown tab number: -1 
Add new device: Cancelled
```

Add new device: Cancelled  is because I power off keyboard from the moment is not writing and I cant set the password.


----------



## sossego (Oct 7, 2013)

http://www.freebsd.org/cgi/man.cgi?query=hcsecd


----------



## sk8harddiefast (Oct 8, 2013)

```
Once a Link_Key_Request or PIN_Code_Request HCI event is received, the
     daemon scans the configuration file for a matching entry.	The remote
     device BD_ADDR is used as a key.  If no matching entry was found, the
     default entry will be used.  If no default entry was found then it is
     assumed that no link key and no PIN code exists.
```

I read the manual but I have some questions.  Isn't supposed that `pc-bluetoothmanager` must create hcsecd.conf file when I write the PIN? If I am going to write the PIN manually (create my own the hcsecd.conf file), then why I have again PIN request from `pc-bluetoothmanager`? Also, I deleted all files from /etc/bluetooth. So I have none entry. Is like I have no PIN code. Something like free to connect. And something else is that pc-bluetoothmanager, creates hcsecd.conf file but when on PIN code request, I write the pin from my native keyboard (Not the Bluetooth keyboard)


----------



## sossego (Oct 8, 2013)

You probably should ask @beanpole and whoever maintains the FreeBSD Bluetooth stack. I'm curious, what are the specifications of the machine you are using to do this? What is the device you are using for Bluetooth connection? That is, "Is it part of the system or is the Bluetooth connection an add-on?"


----------



## sk8harddiefast (Oct 9, 2013)

Is desktop computer. Not laptop with embedded Bluetooth chipset. This is my complete hardware:

Mobo: ASUS P5K3 DELUXE WIFI EDITION
CPU: Intel QuadCore Q6600 2,4GHz 8M cache
RAM: Kingston 16GB (4GB per slot, 4 slots) DDR3
GPU: NVIDIA GeForce 8800 GTX GDD3 768MB
HDD: WD 320GB 7200RPM
OS:

```
FreeBSD Unix 9.2-RELEASE FreeBSD 9.2-RELEASE #3 r256061: Sat Oct  5 10:34:07 EEST 2013     root@Unix:/usr/obj/usr/src/sys/GENERIC  amd64
```
Now for my Bluetooth. I bought this. A usb Belkin mini Bluetooth adapter v4.

And my Bluetooth keyboard: Logitech k810


----------



## sossego (Oct 9, 2013)

Have you thought about using a pci type device that has a fully supported driver?


----------



## sk8harddiefast (Oct 9, 2013)

Could be an option but  trying like this maybe I learn something. How to set it up right and where is the problem because in reality we don't know where exactly is the problem and still PCBSD forums didn't answer to me. To write a tutorial, first of all, I must know how to make my keyboard to work, why is not working and how to make it work. I don't like seeing my keyboard not functional but I always hope

PS: I send PM on PCBSD forums on @beanpole


----------

