LinuxBluetooth
From GumstixDocsWiki
Connecting to a Gumstix via Bluetooth under Linux.
This should help get some connectivity on a Linux machine to a 'straight from box' Gumstix.
Contents |
The Set up
Gumstix
Attach the Bluetooth antenna, and power-up the board.
Linux
You will need the following packages
- Bluez-utils
This should be installed by default otherwise under Ubuntu or Debian distros use
$apt-get bluez-utils
Finding the Gumstix
The first step is to connect to the Gumstix, Turn on your PC's Bluetooth connection and power up the Gumstix then scan for Bluetooth devices using hcitool scan. Hopefully you will find the Gumstix in the output. If you cant find the stick first time round, power the stick on and off. This sometimes solves the problem.
$ hcitool scan
Scanning ...
00:80:37:2E:32:39 Gumstix (0)
More information can be found using
$ sudo hcitool info 00:80:37:2E:32:39
Requesting information ...
BD Address: 00:80:37:2E:32:39
LMP Version: 2.0 (0x3) LMP Subversion: 0x62b9
Manufacturer: Infineon Technologies AG (9)
Features: 0xff 0xff 0x8f 0xfe 0x9b 0xf9 0x00 0x80
<3-slot packets> <5-slot packets> <encryption> <slot offset>
<timing accuracy> <role switch> <hold mode> <sniff mode>
.... snip
We need to make a note of the device address. Next check for connectivity. Note: l2ping starts with an 'L' (but lowercase)
sudo l2ping 00:80:37:2E:32:39 Ping: 00:80:37:2E:32:39 from 00:0A:94:13:CE:8D (data size 44) 44 bytes from 00:80:37:2E:32:39 id 0 time 161.51ms 44 bytes from 00:80:37:2E:32:39 id 1 time 272.85ms 44 bytes from 00:80:37:2E:32:39 id 2 time 242.57ms 3 sent, 3 received, 0% loss
Getting A Serial connection
Binding to Rfcomm
The next stage in our terminal finding mission is to bind the Bluetooth device to a rfcomm interface, This should create a serial line between the two devices. Rfcomm should be part of the Bluez package, if you encounter any errors a setup guide can be found here: http://www.holtmann.org/linux/bluetooth/rfcomm.html
Bind the Device and check for connectivity.
$sudo rfcomm bind 0 00:80:37:2E:32:39 1
$ rfcomm show 00:80:37:2E:32:39 rfcomm0: 00:80:37:2E:32:39 channel 1 clean
If this works nicely, all we have to do if fire up Kermit or your preferred serial communications tool and get going.
If you need kermit than do: sudo apt-get install ckermit
kermit -l /dev/rfcomm0
configure Kermit with
set carrier-watch off set speed 115200 set file type bin set reliable fast set flow-control none set rec pack 4096 set send pack 4096 set window 5 set prefixing all
Finally connect by issuing: connect. Hopefully you should have a functional serial terminal. Note: you may need to press enter a couple times to get the attention of the gumstix. Then the login screen should come up. The default username and password are root, and gumstix respectively.
Setting Up Bluetooth Networks
Having a serial connection is great, But it doesn't allow us to connect using ssh. Or have any real control over network connectivity. A Bluetooth PAN (Personal Area Network) with Ethernet emulation allows us to do this.
for more information on PAN networks look at http://en.wikipedia.org/wiki/Personal_area_network
Basic PAN Configuration
If we only have one stick we want to connect to, then setting up a simple PAND connection appears to be the way forward. This allows us to assign a standard IPv4 address to the stick, giving access to all the normal functions like SSH and SCP.
Slave
Your Gumstix should really be the slave, this means all communication in the network is handled by the PC master.
The First Step is to edit /etc/default/bluetooth To start the pand demon. Depending on your kernel version the default options may be 0/1 or True/False. Keep to the same system as they are not interchangeable. We need to modify the pand lines to read.
PAND_ENABLED = True PAND_OPTIONS = ="--connect [master address]"
This tells the stick that it should connect to the device listed at the master address. This can be found using the hcitool dev command at the master's command line and should be a 6pair hexadecimal number ie. 00:80:37:27:03:8C.
The Next step is to check /ect/bluetooth/hcid.conf for the line. This should exist in a fresh system but it pays to check as it allows the device to accept a link from another device
lm accept;
We also want to setup the bnep (Bluetooth Network Encapsulation Protocol) interface on the stick, edit /etc/network/interfaces to give our bluetooth connection an IP address. Although we could assign an address via DHCP it is easier in a simple network to use static addresses, This will mean we always know the IP address of the gumstix we are trying to contact.
auto bnep0 iface bnep0 inet static address 192.168.x.x netmask 255.255.255.0 network 192.168.x.0 broadcast 192.168.x.255
Finally Restart the Bluetooth networking.
#/etc/init.d/S30bluetooth stop #/etc/init.d/S30bluetooth start
Master
The Master configuration is simple enough, reasonably similar to that of the slave configuration.
First edit /etc/default/bluetooth to enable PAND
PAND_ENABLED=1 PAND_OPTIONS="--listen --role GN --devup /etc/default/bluetooth/pan/dev-up"
The options here tell the stick to listen for connections. If a connection is accepted adopt the GN (Group Network Controller) Role, The devup section calls the given script when a connection is made. This script can do many things but here we will just use it to bring up the bluetooth device
Then in /etc/bluetooth/hcid.conf
lm accept, master;
Finally the dep-up script itself. Create /etc/bluetooth/pan/dev-up <code> as it proberbly wont exist on you system, then add the follwing lines, using the IP address you have chosen for your Master conneciton
#!/bin/sh ifconfig bnep0 192.168.x.x
Make sure you give it executable permissions
chmod +x /etc/bluetooth/pan/dev-up
Finally Restart Bluetooth on the host machine.
$/etc/init.d/bluetooth restart
When a gumstix try s to connect to the host, The pand daemon resisters the link and starts the dev-up script. This puts the benp0 interface in a ready state with the IP address specified. As long as the gumstix bnep IP address is in the same network as the host's you will be able to use normal network commands to connect to your network.
Ethernet Bridging
The steps above create a connection each time, but each new bluetooth device that contacts the network creates its own bnep interface on the host. This means several things
1 Either the dev-up script gets long and complex, or we have to bring each benp interface up by hand on the host 2 We have to have multiple networks for bluetooth, as each interface is treated as a seperate network. 3 The chances of reaching maximum swearing are increased as we try to make sense of all these interfaces.
Unless we like herding cats, we can simplify this by setting up Ethernet bridging. which allows us to bind all of these bnep interfaces into one simple to use interface, allowing a much simpler way of accessing many nodes.
Slave configuration
None. As the bridging is done on the master (PC) the instructions above should allow bridging to work just fine.
Master Configuration
Required tools
The master will need the bridging utils packages installed. This gives access to the brctl commands. If you are using a Gumstix as a master, the bridge-utils package is available in the buildroot. On Ubuntu / Debian based systems this can be installed using.
$apt-get install bridge-utils
Creating the Bridge
We need to create a bridge to add the interfaces to. Either by hand, or by writing a script that is executed at system start-up before the Bluetooth network is created. I created a script that to run before activating the bluetooth device on my PC
#!/bin/sh brctl addbr pan0 ifconfig pan0 192.168.x.x
This creates a bridge called pan0 then assigns it the ip address 192.168.x.x The assigned ip address must be compatible with the addressing scheme used on the slave devices.
The Dev-Up Script
The Final Part of the setup is a modification to the dev-up script <code>/etc/bluetooth/pan/dev-up which should now read
#!/bin/sh brctl addif pan0 $1 ifconfig $1 0.0.0.0
When called now, Instead of starting the bnep interface, the script if given the interface id as a parameter. It then adds the interface to the pan0 bridge created earlier.
Hopefully that all makes sense. Any questions or problems ask on the mailing list and I should get back to you.
--Dan Goldsmith 15:09, 24 October 2007 (PDT)
Changelog
- Added Pand Information for only using one stick. Makes Life much easier.
- Much Nicer PAND configuration that still works. Less variables required means less scope for Bad Things(TM) to happen
- Seperated Bridging into its own Section.
--Dan Goldsmith 13:13, 21 October 2007 (PDT) Basic Rfcomm and Bridging info.

