Ubuntu Bluetooth
From Mulle development
Contents |
Setting up a Bluetooth NAP server on a Linux (version 3.5.0-17-generic) computer
Configuration:
Insert a Bluetooth dongle and verify that Bluetooth is correctly initialized:
user@host:~# sudo hciconfig hci0 up piscan user@host:~# hciconfig hci0 hci0: Type: BR/EDR Bus: USB BD Address: 00:09:DD:50:7F:99 ACL MTU: 310:10 SCO MTU: 64:8 UP RUNNING PSCAN ISCAN RX bytes:503 acl:0 sco:0 events:24 errors:0 TX bytes:830 acl:0 sco:0 commands:24 errors:0 user@host:~# hcitool dev Devices: hci0 00:22:43:AE:53:02
Normally, a Mulle only scans for LAN Access Points and mobile phones. When using a computer as access point, it is neccessary to either modify the Mulle source code to also scan for computers, or to set the Class of Device (CoD) to also indicate an access point on the computer. For some reasing, setting the "Local device class" in /etc/bluetooth/hcid.conf to 0x20300 doesn't work properly. Instead use the hcitconfig command and issue the following:
user@host:~# sudo hciconfig hci0 class 0x20300
Install the Software for Bluez and Bridge:
user@host:~# sudo apt-get install bluez-compat bridge-utils
Edit /etc/network/interfaces and add this section:
iface pan1 inet static address 192.168.150.1 netmask 255.255.255.0
Create the folder /etc/bluetooth/pan and the file /etc/bluetooth/pan/dev-up and enter the text below. This will bridge pan1 and all bnepX that are created for each individual connection, i.e. bnep0 will represent the first client, bnep1 the second, and so forth.
#!/bin/sh brctl addif pan1 $1 # $1 is the new if name, passed by 'pand' ifconfig $1 0.0.0.0
Important, also make the file dev-up executable by:
user@host:~# sudo chmod +x /etc/bluetooth/pan/dev-up
Note: there are serious issues with bluez security. The following twp steps enables a connection to be performed. First remove the comment before the line DisablePlugins in /etc/bluetooth/main.conf
# List of plugins that should not be loaded on bluetoothd startup DisablePlugins = network,input
Then remove the comment before DisableSecurity in /etc/bluetooth/network.conf
# Disable link encryption: default=false DisableSecurity=true
Before proceeding with the setup of PAN, we must start dbus:
user@host:~# sudo service dbus restart
Now it must be ready to initialize.
Initialization:
Run a script like this:
sudo brctl addbr pan1 sudo brctl setfd pan1 0 sudo brctl stp pan1 off sudo ifconfig pan1 192.168.150.1 netmask 255.255.255.0 sudo pand --listen -r NAP -n --devup /etc/bluetooth/pan/dev-up
Setting up a Bluetooth NAP server on a Linux (Ubuntu 10.10) computer
These instructions are valid for Bluez 3.26. It appears that newer versions of Bluez work in a different way, and may introduce a lot of problems.
Insert a Bluetooth dongle, and verify that Bluetooth (bluez, bluez-utils, bluez-compat) is installed and that we have the Bluetooth dongle correctly initialized:
user@host:~# hciconfig hci0 up user@host:~# hciconfig hci0 hci0: Type: BR/EDR Bus: USB BD Address: 00:09:DD:50:7F:99 ACL MTU: 310:10 SCO MTU: 64:8 UP RUNNING RX bytes:473 acl:0 sco:0 events:19 errors:0 TX bytes:317 acl:0 sco:0 commands:18 errors:0 user@host:~# hcitool dev Devices: hci0 00:22:43:AE:53:02 user@host:~# sudo hciconfig hci0 piscan
Normally, a Mulle only scans for LAN Access Points and mobile phones. When using a computer as access point, it is neccessary to either modify the Mulle source code to also scan for computers, or to set the Class of Device (CoD) to also indicate an access point on the computer. For some reasing, setting the "Local device class" in /etc/bluetooth/hcid.conf to 0x20300 doesn't work properly. Instead use the hcitconfig command and issue the following:
$ sudo hciconfig hci0 class 0x20300
The output should look like this:
hci0: Type USB
BD Address: 00:22:43:AE:53:02 ACL MTU 1021:8 SCO MTU: 64:1
Class: 0x020300
Service Classes: Networking
Device Class: LAN Access, Uncategorized
Now when the computer appears as an Access Point, it is time to make sure that the PAN deamon is installed:
$ pand Bluetooth PAN daemon version 4.69 Usage: pand <options> Options: --show --list -l Show active PAN connections --listen -s Listen for PAN connections --connect -c <bdaddr> Create PAN connection --autozap -z Disconnect automatically on exit --search -Q[duration] Search and connect --kill -k <bdaddr> Kill PAN connection --killall -K Kill all PAN connections --role -r <role> Local PAN role (PANU, NAP, GN) --service -d <role> Remote PAN service (PANU, NAP, GN) --ethernet -e <name> Network interface name --device -i <bdaddr> Source bdaddr --nosdp -D Disable SDP --auth -A Enable authentication --encrypt -E Enable encryption --secure -S Secure connection --master -M Become the master of a piconet --nodetach -n Do not become a daemon --persist -p[interval] Persist mode --cache -C[valid] Cache addresses --pidfile -P <pidfile> Create PID file user@host:~#
If pand is not installed, issue the command
user@host:~# apt-get install bluez-compat python-dbus
to install it.
Before proceeding with the configuration of PAN, we must start dbus and add a bridge interface, pan1. which will bridge all PAN interfaces together, and enable us to have listening services started without any connected slaves. First,start dbus:
$ sudo service dbus restart
the, get bridge-utils with this command:
$ sudo apt-get install bridge-utils
Edit /etc/network/interfaces and add this section:
iface pan1 inet static
address 192.168.150.1
netmask 255.255.255.0
Then add the bridge interface pan1 with the following command
$ sudo brctl addbr pan1 $ sudo brctl setfd pan1 0 $ sudo brctl stp pan1 off
Restart networking like this:
$ sudo /etc/init.d/networking restart
Check that the interface pan1 is available with the correct settings:
$ ifconfig pan1
Create /etc/bluetooth/pan/dev-up and enter the text below. This will bridge pan1 and all bnepX that are created for each individual connection, i.e. bnep0 will represent the first client, bnep1 the second, and so forth.
#!/bin/sh brctl addif pan1 $1 # $1 is the new if name, passed by 'pand' ifconfig $1 0.0.0.0
If the directory /etc/bluetooth/pan doesn't exist, simply create it
$ sudo mkdir /etc/bluetooth/pan
Important, also make the file dev-up executable by:
$ sudo chmod +x /etc/bluetooth/dev-up
Note: there are serious issues with bluez security. The following twp steps enables a connection to be performed. First remove the comment before the line DisablePlugins in /etc/bluetooth/main.conf
# List of plugins that should not be loaded on bluetoothd startup DisablePlugins = network,input
Then remove the comment before DisableSecurity in /etc/bluetooth/network.conf
# Disable link encryption: default=false DisableSecurity=true
Now, let's start the pand server:
user@host:~# pand --listen -r NAP -n --devup /etc/bluetooth/pan/dev-up pand[13664]: Bluetooth PAN daemon version 3.26
To test that everything is working, use a Mulle configured for PAN or another computer and try to connect to the newly installed access point computer. When using Intro 3A from LTU, the following is display by the Mulle (using Minicom on the development host)
Eistec platform Mulle started. visit http://www.eistec.se for more information Turning on power to Bluetooth module. Memory initialized TCP/IP initialized (compiled with gcc) Reseting BT module Bluetooth initialized. BT module reseted bt_ip_start Bluetooth interface is up! Successful HCI_RESET. Successful HCI_W_DEFAULT_LINK_POLICY. Successful HCI_READ_BUFFER_SIZE. Successful HCI_READ_BD_ADDR. Successful HCI_SET_EVENT_FILTER. Successful HCI_WRITE_COD. Successful HCI_CHANGE_LOCAL_NAME. Successful HCI_READ_AUTHENTICATION_ENABLE. Successful HCI_WRITE_PAGE_TIMEOUT. Initialization done. Discover other Bluetooth devices. Successful Inquiry Initiate L2CAP connection ires->psrm 0 ires->psm 0 ires->co 1530 ires->bdaddr 0x0:0x19:0x5b:0x5c:0x11:0x32 inquiry_complete: Allocated L2CAP pcb=0x l2cap_connected: L2CAP connected pcb=, pcb->state = 13348 l2cap_connected: SDP L2CAP configured. Result = 0 l2cap_connected: Using NAP profile sdp_attributes_recv: get_nap_cn: PSM=0x000f sdp_attributes_recv: NAP channel: 15 l2cap_disconnected_cfm: pcb=0x l2cap_connected: L2CAP connected pcb=, pcb->state = 13400 l2cap_connected: BNEP L2CAP configured. Result = 0 bnep_accept_ext(0):BNEP connection OK
After this we must of course setup a DHCP server, NTP server, and OLPv2 server for Mulles to be happy... See the Eisserver for more instructions on how to perform these steps. Remember to use the correct IP address of 192.168.150.x . Also install the NTP server for things to work.
An example of a configuration for the PAN network is shown below:
# This is a very basic subnet declaration.
subnet 192.168.150.0 netmask 255.255.255.0 {
range 192.168.150.10 192.168.150.20;
option routers 192.168.150.1;
}
Remember to add pan1 as an allowed interface to /etc/default/dhcp3-server
INTERFACES="pan1"
When a DHCP server is setup, the following lines are printed by the Mulle running Intro 3A (besides the ones display above before the DHCP server was started)
pan_netif_dhcp: (IP-address - 192.168.150.20)
Add user code here ...
192.168.150.20
See the file contrib/proj/eissensor/shared/lwbt_apps/bt_ip_panu.c , in function
err_t pan_netif_dhcp(struct netif *netif, err_t err) {
...
_printf("\n\nAdd user code here ...\n\n");
...
}
This is a good place to start communicating. A user can add code here to make a NTP request in order to synchronize the Mulle's RTC with an Internet NTP server, or make a OLPv2 connection towards the Mulle Public Server (MPS) or the eisserver software.
Note: When using a PAN enabled mobile phone, such as the Sony Ericsson flag ship, the XPERIA X1, in is neccessary to have the Mulle scan phones for PAN-NAP services as well. Just outcomment these line in the function err_t inquiry_complete(void *arg, struct hci_pcb *pcb, struct hci_inq_res *ires, u16_t result) in the file contrib/proj/eissensor/shared/lwbt_apps/bt_ip_panu.c
if ((ires->cod[1] & 0x1F) == 0x03) {
bt_ip_state.profile = LAP_PROFILE;
} else {
// LWIP_DEBUGF(BT_IP_DEBUG, ("Not an access point! try next...\n"));
// ires = ires->next;
// goto check_dev;
}
