Bluetooth в OpenWrt.

Let us consider the Bluetooth operation by the example of connecting a mobile phone to the router via the Bluetooth interface. I use the nokia 6230i phone, but I think that the model of phone is not important and the connection process is identical for all phone models.

On the stage of configuration the following modules are to be selected:
Utilities:
<M> bluez-utils
Kernel modules:
Other modules:
<M> kmod-bluetooth
Libraries:
<M> libusb
Filesystem:
<M> libfuse

Let's download 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
Installing libfuse (2.8.5-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/libfuse_2.8.5-1_brcm47xx.ipk.
Installing kmod-fuse (2.6.36.4-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-fuse_2.6.36.4-1_brcm47xx.ipk.
Configuring kmod-fuse.
Configuring libfuse.

root@OpenWrt:/# opkg install libusb
Installing libusb (0.1.12-2) to root...
Downloading ftp://ftp:ftp@192.168.0.9/libusb_0.1.12-2_brcm47xx.ipk.
Configuring libusb.

To gain an access to the file system of the mobile phone one ussaly use the applications openopbex, obexftp, obexfs. At the moment of this article writing, these applications are not included in openwrt. So we add them by ourself.

To add new packages in openwrt is quite simple. We need to create a directory with the package name in the directory openwrt / package. In the new directory we should create Makefile. It is simply to create the Makefile by using as a basis some sort of a similar file from the directory openwrt / package.

If you are interesting you can add the applications openopbex, obexftp, obexfs by yourself to openwrt. Or you can also take my versions from the section «Download».

After creating of the new directories in openwrt/package we start make menuconfig and select them for the building.

Let's continue installing of 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
Installing obexftp (0.22-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/obexftp_0.22-1_brcm47xx.ipk.
Configuring obexftp.

root@OpenWrt:/# opkg install obexfs
Installing obexfs (0.12-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/obexfs_0.12-1_brcm47xx.ipk.
Configuring obexfs.

Let's connect the Bluetooth and check the output dmesg:

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

For operating with Bluetooth the following utilities can be used. Let's consider some of them. The utility hciconfig is similar in some way to the utility ifconfig.

Let's execute 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

A device named hci0 was detected. It is in status down. By analogy with ifconfig we 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

Hcitool is one more useful utility. Let's activate the Bluetooth on the mobile phone and execute the following:

root@OpenWrt:/# hcitool scan
Scanning ...
00:13:FD:80:F9:F5 Nokia6230i

Now when we know the address of the phone, let's try to get an access to its file system. We use the utility obexfs. By executing of the utility you should specify the phone address and the directory where the file system of the mobile phone is be mounted to:

root@OpenWrt:/# obexfs -b00:13:FD:80:F9:F5 /mnt/nokia/

After executing of this command on your mobile phone you will be requested to connect your mobile phone to the router and to enter a Pin code. After entering of the pin code in your phone you should enter the same in the router . . . . How to do it, I do not know)))

To avoid this problem is very simly. Let's check the information content 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

It contains the system files which are responsible for Bluetooth connection. Let's add the file pincodes to this directory. In this file we specify the address and the appropriate pin code. I have the following: 00:13:FD:80:F9:F5 1

After creating of this file we don't need the pin code in router any more. Let's try again:

root@OpenWrt:/# obexfs -b00:13:FD:80:F9:F5 /mnt/nokia/
root@OpenWrt:/# ls -l /mnt/nokia/
GETDIR:Mem. card
GETDIR:Фото
GETDIR:Клипы
GETDIR:Музыка
GETDIR:Темы
GETDIR:Графика
GETDIR:Мелодии
GETDIR:Аудиозаписи
GETDIR:Ww
GETDIR:0017.GIF

We can unmount the file system in the following way:

root@OpenWrt:/# umount /mnt/nokia/



To buy a Bluetooth from us:

Bluetooth