Bluetooth AccessPoint Linux using a Bluetooth USB device

Author: Carlos Guerra Alberti

Thanks to a Linux machine and a usb bluetooth device, it is possible to create a very good Bluetooth Accesspoint which could give coverage and connectivity to such new-age devices as PocketPCs, laptops, mobiles, etc cause all of them have already bluetooth integrated. Nowadays, the price of Bluetooth Usb devices has been reduced quite a lot and its possible to find with very good price, one bt-usb device with 100 meter around coverage.

Information and specification about usb devices can be found at http://www.holtmann.org/linux/bluetooth/features.html where is allocated a huge list.

Bluetooth was named after Harald Blatand (or Bluetooth), a tenth century Danish Viking king who had united and controlled large parts of Scandinavia which are today Denmark and Norway. And was the Swedish company Ericsson (SonyEricsson nowadays) in 1994 who started to develop what is today the bluetooth tecnology as a standard in communications.

Main Features of Bluetooth:
- Operates in the 2.4GHz frequency band without a license for wireless communication.
- Real-time data transfer usually possible between 10-100m.
- Close proximity not required as with infrared data (IrDA) communication devices as Bluetooth doesn’t suffer from interference from obstacles such as walls.
- Supports both point-to-point wireless connections without cables between mobile phones and personal computers, as well as point-to-multipoint connections to anable ad hoc local wireless networks.

The Operating System chosed for this purpose is Debian GNU/Linux (Sarge) with Linux Kernel 2.4.27 version and the bt-usb used is a Belkin F8T001.

BlueZ, The Official Linux Bluetooth protocol stack, provides support for the core Bluetooth layers and protocols. It is flexible, efficient and uses a modular implementation. It has many interesting features but the important for this project is that gives support to RFCOMM, BNEP, CMTP and HIDP kernel implementations and HCI UART, USB, PCMCIA and virtual device drivers fully needed for develop a network using Bluetooth.

The BlueZ kernel modules, libraries and utilities are known to be working prefect on many architectures supported by Linux.

Part 1: Kernel.

First of all is prepare our server to recognise that the usb that will be inserted is a Bluetooth device, so is more than obvious that our Kernel should have Usb support activated, so next options are needed to be activated as predefined or as module.

USB support —>

[*] USB verbose debug messages

— Miscellaneous USB options

[*] Preliminary USB device filesystem

[ ] Enforce USB bandwidth allocation (EXPERIMENTAL)

— USB Host Controller Drivers

EHCI HCD (USB 2.0) support (EXPERIMENTAL)

UHCI (Intel PIIX4, VIA, …) support

UHCI Alternate Driver (JE) support

OHCI (Compaq, iMacs, OPTi, SiS, ALi, …) support

— USB Human Interface Devices (HID)

USB Human Interface Device (full HID) support

[*] HID input layer support

The same is required for the Bluetooth section in the Kernel config menu.

Bluetooth support —>

Bluetooth subsystem support

L2CAP protocol support

SCO links support

RFCOMM protocol support

[*] RFCOMM TTY support

BNEP protocol support

[*] Multicast filter support

[*] Protocol filter support

Bluetooth device drivers —>

HCI USB driver

[ ] SCO (voice) support

HCI UART driver

[*] UART (H4) protocol support

[ ] BCSP protocol support

HCI BlueFRITZ! USB driver

HCI VHCI (Virtual HCI device) drive

Once finished, the Kernel should be compiled and the system should be reboot for apply the new changes.

Part 2: Instalation.

The Software used for controlling our bt-usb is as mentioned before, Bluez, this excellent team has their open project at SF: http://bluez.sourceforge.net/

As the Operating System running is debian, the software will be installed by, of course, the “apt-get install” so first, we need to add in the respository list: /etc/apt/sources.list the following line:

deb http://bluez.sourceforge.net/download/debian ./

In order to obtain the packages through the BlueZ respository. Even we can be sure that very soon will be included in official repositories.

We should update our repository list doing a apt-get update command.

And now system is ready to install the package, so for that we need to type:

apt-get install bluez-utils

Apt will install the package and will create the folder /etc/bluetooth wher we will find the configuration files.

Part 3: Configuration

In /etc/bluetooth/pin is the config file where the user will put his Personal Identification Number, after when the other devices will want to access the network, this PIN will be required. The PIN can be a 4 digits number.

In /etc/default/bluez-utils is the file where we will configure some parameters to adapt our bt-usb in a good bt-accesspoint. Fortunatly, this config file has been very good documented inside by the Bluez team, 3 ways of operates with the device are shown: HIDD, DUND, PAND. At this time and in this case, PAND is the option needed, as common in programation, we use 1 for active and 0 for leaving unactivated, so config file should remain as following: HIDD_ENABLED=0, DUND_ENABLED=0 y PAND_ENABLED=1 and inside PAND options we will include-listen –role NAP because that will allow as to work as a network access point.

PAND_ENABLED=1

PAND_OPTIONS=”–listen –role NAP”

Now we need to configure some options for the hci daemon who can be considered as a “device discover”, so we will modify the /etc/bluetooth/hcid.conf file as next:

options
{
autoinit yes;
security auto;
pairing multi;
pin_helper /usr/bin/bluez-pin;
}

device
{
name “%h-%d”;
class 0×108;
iscan enable;
pscan enable;
lm accept,master;
lp rswitch,hold,sniff,park;
auth enable;
}

Depending if the bt-usb device was inserted already in the computer or not, we can check by a lsmod command, we would need to load the modules compiled before:

modprobe l2cap #L2CAP module.
modprobe sco #SCO module.
modprobe rfcomm #RFCOMM module
modprobe bnep
modprobe hci_usb #HCI USB driver.
modprobe hci_uart #HCI UART driver.
modprobe hci_vhci #HCI Virtual device driver.

Part 4. Network configuration:

Bnep0 will be the name of the bluetooth ethernet device.

The initial idea of this feature is to tie separate layer 2 networks together into one new network. We make use of its ability to combine separate network interfaces into a (one) new one. So we will use bridging directives in order to link both networks.

Now its time to create a dhcpd service how will give to the clients an IP address automatically when the connection between them is established.

A very good dhcpd server is dhcpd3-server and is the one that will be used in this project, so again for installing we should make a:

apt-get install dhcp3-server

The dhcpd.conf inside /etc/dhcp3 should have this directives:

ddns-update-style none;

option domain-name “accesspoint”;

option domain-name-servers 217.75.248.5; # DNS server

default-lease-time 300;

max-lease-time 7200;

authoritative;

log-facility local7;

subnet 10.0.0.0 netmask 255.255.255.0

{

range 10.0.0.10 10.0.0.100;

option routers 10.0.0.1;

}

At this time we need to activate as a module the bridge option in our Kernel [This was not mentioned before in Part 1: Kernel due to possible errors compiling the Kernel while there wasn't more devices included].

Networking options —>

….

802.1d Ethernet Bridging

…..

The bridge kernel module, however, requires an additional control SW package,

called “bridge utils” for installing we have just to type:

apt-get install bridge-utils

Setup bridge:

# brctl addbr pan0

# ifconfig pan0 10.0.0.1

# brctl setfd pan0 0

# brctl stp pan0 disable

# brctl addif pan0 eth0

The Bluetooth PAN feature offers IP support over Bluetooth ( L2CAP), comparable to Wireless LAN on a PC.

When this bnep will be activated, it will call a script that we will create in /etc/bluetooth/pan named dev-up, which will create the network only when there is a first call of first bluetooth device asking for joining the network.

The file /etc/bluetooth/pan/dev-up should have the following content:

#!/bin/sh

n=`ifconfig | grep pan0`

if ! test “$n”

then

brctl addbr pan0

ifconfig pan0 10.0.0.1

/usr/sbin/fw

/etc/init.d/dhcp3-server start # will start the dhcpd3

fi

brctl addif pan0 $1 # $1 is the new if name, passed by ‘pand’

ifconfig $1 0.0.0.0

Anexo: Connection log:

When the bt-usb is connected we obtain:

Apr 8 16:46:30 EW_AP kernel: BlueZ Core ver 2.4 Copyright (C) 2000,2001 Qualcomm Inc

Apr 8 16:46:30 EW_AP kernel: BlueZ HCI USB driver ver 2.7 Copyright (C) 2000,2001

Apr 8 16:46:30 EW_AP kernel: usb.c: registered new driver hci_usb

Apr 8 16:46:30 EW_AP kernel: uhci.c: USB Universal Host Controller Interface driver v1.1

Apr 8 16:46:47 EW_AP kernel: BlueZ L2CAP ver 2.3 Copyright (C) 2000,2001 Qualcomm Inc

Apr 8 16:46:47 EW_AP kernel: BlueZ RFCOMM ver 1.1

Apr 8 16:46:47 EW_AP kernel: Copyright (C) 2002 Marcel Holtmann

Apr 8 16:46:48 EW_AP kernel: BlueZ BNEP ver 1.2

Apr 8 16:46:47 EW_AP hcid[1026]: Bluetooth HCI daemon

Apr 8 16:46:47 EW_AP hcid[1026]: HCI dev 0 up

Apr 8 16:46:47 EW_AP hcid[1026]: Starting security manager 0

Apr 8 16:46:47 EW_AP sdpd[1028]: Bluetooth SDP daemon

Apr 8 16:46:47 EW_AP snmpd[991]: NET-SNMP version 5.1.2

Apr 8 16:46:48 EW_AP pand[1038]: Bluetooth PAN daemon

When a client wants to join the network:

Apr 8 17:15:51 EW_AP hcid[1026]: link_key_request (sba=00:03:C9:2D:CC:FD, dba=08:00:28:D3:3A:25)

Apr 8 17:15:51 EW_AP hcid[1026]: link_key_request (sba=00:03:C9:2D:CC:FD, dba=08:00:28:D3:3A:25)

Apr 8 17:15:52 EW_AP kernel: device bnep0 entered promiscuous mode

Apr 8 17:15:52 EW_AP kernel: pan0: port 1(bnep0) entering learning state

Apr 8 17:15:52 EW_AP pand[6403]: New connection from 08:00:28:D3:3A:25 bnep0

Apr 8 17:15:52 EW_AP kernel: device bnep0 entered promiscuous mode

Apr 8 17:15:52 EW_AP kernel: pan0: port 1(bnep0) entering learning state

Apr 8 17:15:52 EW_AP pand[6403]: New connection from 08:00:28:D3:3A:25 bnep0

Apr 8 12:34:06 EW_AP uptimed: moving up to position 2: 0 days, 00:02:50

Apr 8 12:34:24 EW_AP kernel: NET4: Ethernet Bridge 008 for NET4.0

Apr 8 12:34:27 EW_AP dhcpd: Internet Systems Consortium DHCP Server V3.0.1

Apr 8 12:34:27 EW_AP dhcpd: Copyright 2004 Internet Systems Consortium.

Apr 8 12:34:27 EW_AP dhcpd: All rights reserved.

Apr 8 12:34:27 EW_AP dhcpd: For info, please visit http://www.isc.org/sw/dhcp/

Apr 8 12:34:27 EW_AP dhcpd: Wrote 3 leases to leases file.

Apr 8 12:34:29 EW_AP kernel: device bnep0 entered promiscuous mode

Apr 8 12:34:29 EW_AP kernel: pan0: port 1(bnep0) entering learning state

Apr 8 12:34:44 EW_AP kernel: pan0: port 1(bnep0) entering forwarding state

Apr 8 12:34:44 EW_AP kernel: pan0: topology change detected, propagating

Apr 8 12:34:55 EW_AP dhcpd: DHCPDISCOVER from 08:00:28:d3:3a:25 via pan0

Apr 8 12:34:56 EW_AP dhcpd: DHCPOFFER on 10.0.0.97 to 08:00:28:d3:3a:25 (Paki45) via pan0

Apr 8 12:34:56 EW_AP dhcpd: DHCPREQUEST for 10.0.0.97 from 08:00:28:d3:3a:25 (Paki45) via pan0

Apr 8 12:34:56 EW_AP dhcpd: DHCPACK on 10.0.0.97 to 08:00:28:d3:3a:25 (Paki45) via pan0

17:17 [EW_AP~]# ping 10.0.0.97

PING 10.0.0.97 (10.0.0.97): 56 data bytes

64 bytes from 10.0.0.97: icmp_seq=0 ttl=128 time=62.5 ms
64 bytes from 10.0.0.97: icmp_seq=1 ttl=128 time=50.3 ms
64 bytes from 10.0.0.97: icmp_seq=2 ttl=128 time=47.1 ms

Carlos Guerra Alberti

mapache@carlosguerra.com

0 Responses to “Bluetooth AccessPoint Linux using a Bluetooth USB device”


  1. No Comments

Leave a Reply




Enlaces

Detalles

Tema: TripleK2 theme by JohnTP