In this article we explore the huge potential of CrisOs playing with bluetooth. All the stuff we need is:
WARNING: due to dbus compile error bluez-utils don't compile any more. Please refer to FAQ e NOTE for workaround
First at all we should install some utils on foxboard; simple type:
root@CrisOs:~# opkg update root@CrisOs:~# opkg install bluez-utils kmod-bluetooth
The former package implement a lot of bluetooth protocol; you can find some information using dmesg:
Bluetooth: HCI device and connection manager initialized Bluetooth: HCI socket layer initialized Bluetooth: L2CAP ver 2.8 Bluetooth: L2CAP socket layer initialized Bluetooth: SCO (Voice Link) ver 0.5 Bluetooth: SCO socket layer initialized Bluetooth: RFCOMM socket layer initialized Bluetooth: RFCOMM TTY layer initialized Bluetooth: RFCOMM ver 1.8 Bluetooth: BNEP (Ethernet Emulation) ver 1.2 Bluetooth: BNEP filters: protocol multicast Bluetooth: HCI UART driver ver 2.2 Bluetooth: HCI H4 protocol initialized Bluetooth: HCI BCSP protocol initialized Bluetooth: HCI USB driver ver 2.9
Now you need to configure the local pin used during connection. Simple edit /etc/bluetooth/givenpin and add pin like this example:
#!/bin/sh
# Write bluetooth PIN number here:
pin=000
if [ -z "$pin" ]; then
msg="Set bluetooth PIN in file $0"
logger -p user.err "$msg"
for i in /dev/pts/* ; do
[ -w $i ] && echo "$msg" > $i
done
else
echo "PIN:$pin"
fi
Hence move it to pin file:
# mv /etc/bluetooth/givepin /etc/bluetooth/pin
This paragraph describe how to link through a serial channel the linux box with remote foxboard.
We will use the RFCOMM protocol for this purpose, on remote foxboard we should type:
root@CrisOs:~# hcid root@CrisOs:~# sdpd root@CrisOs:~# rfcomm listen 0 1
On the linux box pc you can type hcitool scan, this should diplay something like:
$ hcitool scan Scanning ... 00:09:DD:50:05:D2 OpenWRT
Now we should connect to remote services typing:
$ rfcomm connect 0 00:09:DD:50:05:D2
Now you can transfer data over serial line tty using /dev/rfcomm0
This paragraph explain how to manage a bluetooth network between foxboard and remote linux boxes.
On CrisOs type:
# hcid # sdpd # pand --listen --role NAP --master -z
If we like to use dhcp configuration on network we should also use:
# brctl addbr br0 # brctl addif br0 bnep0 # ifconfig br0 192.168.5.1 up # dnsmasq --dhcp-range=192.168.5.45,192.168.5.56,255.255.255.0,12h -i br0 -d
Now we can connect from remote linux box simply using:
$ sudo pand -c 00:09:DD:50:05:D2 -z -n pand[6883]: Bluetooth PAN daemon version 3.26 pand[6883]: Connecting to 00:09:DD:50:05:D2 pand[6883]: bnep0 connected $ sudo dhclient bnep0
Now you can access foxboard service through bluetooth network, if do you like to do more you can simple enable nat on foxboard. Enabling nat allow you to use foxboard like a bluetooth access point sharing its internet connection.
On foxboard type:
# opkg install iptables-mod-nat # echo 1 > /proc/sys/net/ipv4/ip_forward # iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE