We will examine the operation of the Bluetooth adapter using the example of connecting a mobile phone to a router via the Bluetooth interface. I will use a Nokia 6230i phone, but I believe the phone model does not matter and the connection process is the same for all devices.
During the configuration stage, you need to select the following modules:
Utilities:
<M> bluez-utils
Kernel modules:
Other modules:
<M> kmod-bluetooth
Libraries:
<M> libusb
Filesystem:
<M> libfuse
Boot up and install the packages:
| root@OpenWrt:/# opkg install kmod-bluetooth bluez-utils
Installing kmod-bluetooth (2.6.36.4-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-bluetooth_2.6.36.4-1_brcm47xx.ipk.
Installing kmod-crc16 (2.6.36.4-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-crc16_2.6.36.4-1_brcm47xx.ipk.
Installing kmod-hid (2.6.36.4-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-hid_2.6.36.4-1_brcm47xx.ipk.
Installing kmod-input-core (2.6.36.4-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-input-core_2.6.36.4-1_brcm47xx.ipk.
Installing kmod-rfkill (2.6.36.4-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-rfkill_2.6.36.4-1_brcm47xx.ipk.
Installing bluez-utils (3.36-7) to root...
Downloading ftp://ftp:ftp@192.168.0.9/bluez-utils_3.36-7_brcm47xx.ipk.
Installing bluez-libs (3.36-3) to root...
Downloading ftp://ftp:ftp@192.168.0.9/bluez-libs_3.36-3_brcm47xx.ipk.
Installing libpthread (0.9.32-68) to root...
Downloading ftp://ftp:ftp@192.168.0.9/libpthread_0.9.32-68_brcm47xx.ipk.
Installing dbus (1.2.4.6permissive-2) to root...
Downloading ftp://ftp:ftp@192.168.0.9/dbus_1.2.4.6permissive-2_brcm47xx.ipk.
Installing libexpat (2.0.1-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/libexpat_2.0.1-1_brcm47xx.ipk.
Installing libdbus (1.2.4.6permissive-2) to root...
Downloading ftp://ftp:ftp@192.168.0.9/libdbus_1.2.4.6permissive-2_brcm47xx.ipk.
Configuring libpthread.
Configuring libdbus.
Configuring kmod-input-core.
Configuring bluez-libs.
Configuring libexpat.
Configuring dbus.
Configuring kmod-crc16.
Configuring kmod-hid.
Configuring kmod-rfkill.
Configuring kmod-bluetooth.
Configuring bluez-utils.
root@OpenWrt:/# opkg install libfuse root@OpenWrt:/# opkg install libusb |
To access the mobile phone's file system, applications such as openobex, obexftp, and obexfs are typically used. At the time of writing this article, these applications were not included in OpenWrt. Therefore, we will add them manually.
Adding new packages to OpenWrt is quite simple. You need to create a directory named after the package in the openwrt/package directory. In the new directory, you must create a Makefile. It is convenient to create the Makefile by taking an existing similar one from the openwrt/package directory as a template.
If you are interested, you can add the openobex, obexftp, and obexfs applications to OpenWrt yourself. Or you can take my versions from the «Download» section.
After creating new directories in openwrt/package, run make menuconfig and mark them for subsequent compilation.
Let's install the new packages:
| root@OpenWrt:/# opkg install openobex
Installing openobex (1.3-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/openobex_1.3-1_brcm47xx.ipk.
Configuring openobex.
root@OpenWrt:/# opkg install obexftp root@OpenWrt:/# opkg install obexfs |
Connect the Bluetooth adapter and check the dmesg output:
| root@OpenWrt:/# dmesg Bluetooth: Core ver 2.15 NET: Registered protocol family 31 Bluetooth: HCI device and connection manager initialized Bluetooth: HCI socket layer initialized Bluetooth: L2CAP ver 2.15 Bluetooth: L2CAP socket layer initialized Bluetooth: SCO (Voice Link) ver 0.6 Bluetooth: SCO socket layer initialized Bluetooth: RFCOMM TTY layer initialized Bluetooth: RFCOMM socket layer initialized Bluetooth: RFCOMM ver 1.11 Bluetooth: BNEP (Ethernet Emulation) ver 1.3 Bluetooth: BNEP filters: protocol multicast Bluetooth: HIDP (Human Interface Emulation) ver 1.2 Bluetooth: HCI UART driver ver 2.2 Bluetooth: HCI H4 protocol initialized Bluetooth: HCI BCSP protocol initialized Bluetooth: Generic Bluetooth USB driver ver 0.6 usbcore: registered new interface driver btusb usb 1-1.4.3: new full speed USB device using ohci_hcd and address 5 |
There are specific utilities for working with Bluetooth adapters. Let's look at some of them. The hciconfig utility is somewhat similar to the ifconfig utility.
Let's run it:
| root@OpenWrt:/# hciconfig hci0: Type: USB BD Address: 00:00:00:00:00:00 ACL MTU: 0:0 SCO MTU: 0:0 DOWN RX bytes:0 acl:0 sco:0 events:0 errors:0 TX bytes:0 acl:0 sco:0 commands:0 errors:0 |
The hci0 device has been detected, which is in the down state. Similar to ifconfig, let's execute hciconfig hci0 up.
| root@OpenWrt:/# hciconfig hci0 up root@OpenWrt:/# hciconfig hci0: Type: USB BD Address: 00:0A:3A:5C:88:60 ACL MTU: 192:8 SCO MTU: 64:8 UP RUNNING RX bytes:340 acl:0 sco:0 events:11 errors:0 TX bytes:38 acl:0 sco:0 commands:11 errors:0 |
Another useful utility is hcitool. Turn on Bluetooth on your phone and execute:
| root@OpenWrt:/# hcitool scan Scanning ... 00:13:FD:80:F9:F5 Nokia 6230i |
Now that we know the phone's address, let's try to access its file system. We will use the obexfs utility. When calling it, you need to specify the phone's address and the directory where the mobile phone's file system will be mounted:
| root@OpenWrt:/# obexfs -b00:13:FD:80:F9:F5 /mnt/nokia/ |
After executing this command, a pairing request will appear on the phone, and you will need to enter a PIN code. After entering the PIN code on the phone, you must enter the same one on the router side... How to do this, I don't know )))
It is very easy to bypass this issue. Let's look at the contents of the following directory:
| root@OpenWrt:/# ls -l /var/lib/bluetooth/00\:0A\:3A\:5C\:88\:60/ -rw-r--r-- 1 root root 27 Jan 1 00:04 classes -rw-r--r-- 1 root root 26 Jan 1 01:40 config -rw-r--r-- 1 root root 38 Jan 1 00:02 did -rw-r--r-- 1 root root 35 Jan 1 00:02 features -rw-r--r-- 1 root root 42 Jan 1 00:10 lastseen -rw-r--r-- 1 root root 42 Jan 1 01:41 lastused -rw------- 1 root root 55 Jan 1 00:11 linkkeys -rw-r--r-- 1 root root 27 Jan 1 00:02 manufacturers -rw-r--r-- 1 root root 37 Jan 1 00:02 names -rw-r--r-- 1 root root 499 Jan 1 00:02 profiles -rw-r--r-- 1 root root 2658 Jan 1 00:02 sdp |
This directory contains system files responsible for the Bluetooth connection. Let's add a pincodes file to it, specifying the address and the corresponding PIN code. In my case, it looks like this: 00:13:FD:80:F9:F5 1
After creating this file, the router will no longer require a PIN code. Let's try again:
