bluez5 PAN Setup

NOTE: This information only applies to devices with Bluetooth using mLinux 4.x or higher which has bluez5. For devices using mLinux 3.x, refer to Bluetooth.

BlueZ includes a utility called  bluetoothctl.

bluetoothctl Tips

  • bluetoothctl is space sensitive. If you have two spaces between a command and its argument, it will fail as follows:
[bluetooth] trust  5C:F3:70:74:04:AF
Device 5C:F3:70:74:04:AF not available
  • To exit bluetoothctl, type “quit” followed by the enter key.

In this case, the hex value is is the BD_ADDR (Bluetooth Device Address, similar to an ethernet MAC address) of the remote bluetooth device. If you get the Device not available message, look closely to verify the syntax. Otherwise, try again.

Authorize service
[agent] Authorize service 0000000f-0000-1000-8000-00805f9b34fb (yes/no): yes
[bluetooth] default-agent

If you do not do the trust step, there is also a race condition between the client and issuing the message. The client may timeout before the Authorize service can be answered. So it is best to trust the bluetooth client device. Also, if bluetoothctl or some program to answer the authorization request is not running, the connection attempt will fail. Every time bluetoothctl is started, it is important to do the default-agent command.

Measuring bluetooth performance

You can discover the bytes sent with the /proc/net/dev kernel file.

mtcdt:~$ egrep 'pan0|Receive|fifo' /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  pan0:  336375    2905    0    0    0     0          0         0  3354937    3097    0    0    0     0       0          0

mLinux 4 with bluez5

You must configure the network settings for eth0 and pan0 by modifying the /etc/network/interfaces file. This includes setting up a NAT.

Set up eth0 (or wifi) to forward

In /etc/network/interfaces:

# Wired interface
auto eth0
iface eth0 inet static
post-up echo 1 >/proc/sys/net/ipv4/ip_forward
post-up iptables -F                                   
post-up iptables -t nat -F
post-up iptables -t mangle -F
post-up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Set up bridge node

In /etc/network/interfaces:

auto pan0
iface pan0 inet static
pre-up brctl addbr pan0
pre-up brctl setfd pan0 0
pre-up brctl stp pan0 off

Restart eth0 and bring up pan0

The nohup allows completion of the command if you are using eth0 to log into the device. If the eth0 address changes, and you are using eth0 to log into the device, you will lose your session.

$ sudo nohup bash -c "ifdown eth0 ; sleep 2; ifup eth0"

Set up bluetooth service


The file /etc/bluetooth/main.conf should be set up.

The main.conf file contains these sections:

General Section

Name = MTCDT-Bluez  # Some identifiable name
DiscoverableTimeout = 0 # Stay discoverable
AutoConnectTimeout = 0 # automatic connection timeout

Policy Section

Autoenable automatically powers up the bluetooth device on boot.



Set the enable line:


Start Bluetooth daemon

sudo /etc/init.d/bluetooth start

Enable and start pand

Pan should be enabled. Debug is optional.

Edit the file /etc/default/bt-pan:


Now start it up.

sudo /etc/init.d/bt-pan start

Set up dnsmasq


You must set ENABLED=”yes” in /etc/default/dnsmasq (default is no):



The following configuration lines must only appear once in all the configuration files in the directory /etc/dnsmasq.d:

    • dhcp-lease-max
    • dhcp-leasefile

Modify the file /etc/dnsmasq.d/dhcp.conf to match the following:


In another file called /etc/dnsmasq.d/dns.conf, include:


If you are not using a DHCP server from the device, set up /etc/network/resolv.conf.  (Do not use /etc/resolv.conf, as this file is a sym link to volatile storage and is created at boot.)

Edit the resolv.conf as required.



If you are using DHCP with eth0, /etc/resolv.conf is created automatically. In that case you should not edit /etc/resolv.conf, and it should be used in /etc/dnsmasq.d/dns.conf.

Start dnsmasq

sudo /etc/init.d/dnsmasq restart



Follow the steps for pairing with another bluetooth device.

Connect to pand

On the phone, select Internet access.

If you do not trust the phone (as shown previously), every time you select the PAN service, the system asks to approve the connection.

Without trust, you must have a program running on the device to do this (like bluetoothctl). For this example we are running bluetoothctl on the device.  Start bluetoothctl:

$ sudo -s bluetoothctl

On your device, you may see the following if you did not do the Trust step (type yes to authorize service and hit enter):

Authorize service
[agent] Authorize service 0000000f-0000-1000-8000-00805f9b34fb (yes/no): yes
[John Cell Phone]#
device bnep0 entered promiscuous mode
pan0: port 1(bnep0) entered forwarding state
pan0: port 1(bnep0) entered forwarding state

Windows with bluez5

To do this, you must have a bluetooth device on your PC. It could be a USB dongle. With some equipment, it is internal.

Set up pairing agent

[bluetooth] agent KeyboardOnly
Agent registered
[bluetooth] default-agent
Default agent request successful

Make discoverable in Windows

  1. From the lower right tray in the Windows OS, select the bluetooth icon.
  2. Click to get its menu. Select Show Bluetooth Devices.
  3. The Bluetooth Settings window displays. Click the Options tab.
  4. Check Allow Bluetooth devices to find this computer. Click OK.

Make the device discoverable and pairable if not already

[bluetooth] discoverable on
Changing discoverable on succeeded
[bluetooth] pairable on
Changing pairable on succeeded

Turn scan on and find Windows System

Device 5C:F3:70:74:04:AF CALMQUIST-L1

Scan Off and Pair

The pairing is initiated in mLinux on the device (not your PC) and time-limited. Follow these steps quickly or the pairing will fail:

  1. Enter the following command on mLinux to pair the device with your PC:
    [bluetooth] pair 5C:F3:70:74:04:AF
  2. Answer yes in mLinux on the device.
  3. On your PC, immediately click on the Windows bubble saying that a Bluetooth device is trying to connect.
  4. Quickly answer the prompt by clicking Next to add the device for the pairing request. (Otherwise, the pairing will fail.)
  5. Windows displays a success message if successful.

The resulting output (if successful) on the device should look like:

Attempting to pair with 5C:F3:70:74:04:AF
[CHG] Device 5C:F3:70:74:04:AF Connected: yes
Request confirmation
[agent] Confirm passkey 912097 (yes/no): yes
[CHG] Device 5C:F3:70:74:04:AF UUIDs: 00001000-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:F3:70:74:04:AF UUIDs: 00001115-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:F3:70:74:04:AF ServicesResolved: yes
[CHG] Device 5C:F3:70:74:04:AF Paired: yes
Pairing successful
[CHG] Device 5C:F3:70:74:04:AF ServicesResolved: no
[CHG] Device 5C:F3:70:74:04:AF Connected: no



Trust is needed so the client may connect without a response from the device. Enter the following command:

[bluetooth] trust 5C:F3:70:74:04:AF

The system confirms your change with:

[CHG] Device 5C:F3:70:74:04:AF Trusted: yes


On your PC, connect using access point by following these steps:

  1. Click on Start Menu > Devices and Printers > Bluetooth Personal Area Network Devices
  2. Right click on your device to display its menu.
  3. Select Connect using > Access point.

On your device, you may see the following if you did not do the Trust  step (type yes to authorize service and hit enter):

[agent] Authorize service 0000000f-0000-1000-8000-00805f9b34fb (yes/no): yes
[CHG] Device 54:93:2C:37:5C:95 RSSI: -85
[CHG] Device 54:93:2C:37:5C:95 RSSI: -69