Linux Format - UK (2019-12)

(Antfer) #1
http://www.techradar.com/pro/linux December 2019 LXF256 53

Pi Bluetooth TUTORIALS


Master and Slave
tree structure.

BUGGED BLUETOOTH


discoverable mode. This can be automatic or enabled
on the SD using a button – you’re probably used to this
from Bluetooth mice and keyboards.
BlueZ is the name of an implementation of a
Bluetooth wireless standards specification in the Linux
kernel-based family of operating systems. It is an open
source project distributed under GNU General Public
Licence (GPL). The BlueZ kernel has been part of the
official Linux kernel since version 2.4.6. As of 2006, the
BlueZ stack supports all core Bluetooth protocols and
layers. In 2016, with the introduction of the Raspberry
Pi 3, Bluetooth was offered on Pi hardware: the
Raspbian OS version 2016-02-26 added support
for Wi-Fi and Bluetooth.

Toothy blueness
There is a console supported in Bluetooth used to
configure devices. It’s a command line application
named bluetoothctl. In the next portion of this article,
we’ll provide commands from bluetoothctl to help you
bridge from theory to the physical configuring of a
Bluetooth device.
As mentioned, for some SDs a physical button may
need to be pressed on the device for a specific time
interval to force the device into discoverable mode.
A discoverable device will respond to an MD inquiry and
attempt to establish a connection. When an MD has
discovered an SD and information has been exchanged,
the next step is to establish a connection between the
devices. In Bluetooth terminology this is referred to as
paging. During this phase, a passkey or PIN code, which
is usually four digits, is authenticated between the two
devices: pair <DEVICE MAC>.
During this phase a short-term key is generated after
the passkey has been successfully authenticated. The
authentication process varies and depends on the
capabilities of the devices. The short-term key will be
used throughout a session. Once the pairing has
occurred, data can be exchanged between the devices.
After a device has completed the paging process, it
enters the connection state: connect <DEVICE MAC>.
While connected, an SD can be in the following modes:
Active Mode: This is the regular connected mode,
where the device is actively communicating with others.
Sniff Mode: This is a power-saving mode and comes
on at regular intervals to listen for transmissions.
Hold Mode: The MD directs an SD to go into this
power-saving mode. The SD powers down for a
specified interval and then returns to active mode when
that interval has passed.
Park Mode: MD directs the SD to power down and
only powers up on a command from the MD.
Bonding is the exchange of long-term keys post-
pairing. The shared key enables the devices to work
together in the future: trust <DEVICE MAC>.

A bit about security
In any network, information security should be a
concern. In a Bluetooth piconet network, radio waves
are used to send information over wireless connections.
Wireless is susceptible to spying and remote access.
Bluetooth connections are so ubiquitous that we forget

about the technology being used and just make
connections. Bluetooth devices pull down radio wave
transmissions from the air. The technology is
susceptible to wireless network threats such as denial-
of-service attacks, eavesdropping and message
modification. If the plan is to send sensitive information
that you want to remain confidential over a wireless
connection like Bluetooth, you need to take precautions
to ensure the signals are not misappropriated.
For example: we have a Bluetooth-enabled Pi that
has internet capability. We want to share the Pi’s
internet, so a Bluetooth connection is made to a mobile
phone and the mobile phone establishes a dial-up
connection to the internet.
If you’re of the younger persuasion you might asking,
what is dial-up? A simpler example is using the
Bluetooth communication infrastructure to synchronise
data. We rarely consider the security implication when
information from contact lists and address books are
carried on Bluetooth radio waves between devices.
Bluetooth links make it easy to synchronise data across
multiple devices. Establishing some security controls
around this type of data is not such a bad idea. It is
done over a wired/wireless network, so why not
Bluetooth as well?

We discovered an anomaly in the BlueZ installation during the final
testing for this tutorial. The tarball file from the official site has an
additional software requirement when compared to the software
pulled from the mirror site.
The tarball from the official site has a json-c software requirement
that is not present in the mirror site’s software installation. In
addition, the ./configure attribute -enable-experimental from
the official sites results in a failure error when used with the official
site software release. In order to work it has be be changed to
-enable-mesh to succeed.
There is a Developer Study Guide: Deploying BlueZ v5.50 on
Raspberry Pi3 available at http://www.bluetooth.com/bluetooth-
resources that provides the details on the json-c requirements. The
installation for this tutorial used the tarball found on the Mirror Site
and not the Official Site.
The installation was successful as demonstrated by the use case
provided. The anomaly may be corrected before this goes to print. If
that’s not the case, you at least have what worked on the day this
tutorial was written!

REPLACE BUYING LXF AT A SHOP Subscribe now at http://bit.ly/LinuxFormat


BlueZ is the
official Linux
Bluetooth
protocol stack:
http://www.bluez.org/
download.

MD: Master device
SD: Slavedevice
MS: Master or Slave

MS


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


MD


5552Decmbr rb2c019gb09uidsy December 2019 LXF256 53


Pi Bluetooth TUTORIALS


Master and Slave
tree structure.

BUGGED BLUETOOTH


discoverable mode. This can be automatic or enabled
on the SD using a button – you’re probably used to this
from Bluetooth mice and keyboards.
BlueZ is the name of an implementation of a
Bluetooth wireless standards specification in the Linux
kernel-based family of operating systems. It is an open
source project distributed under GNU General Public
Licence (GPL). The BlueZ kernel has been part of the
official Linux kernel since version 2.4.6. As of 2006, the
BlueZ stack supports all core Bluetooth protocols and
layers. In 2016, with the introduction of the Raspberry
Pi3,BluetoothwasofferedonPihardware:the
RaspbianOSversion2016-02-26addedsupport
forWi-FiandBluetooth.


Toothyblueness
ThereisaconsolesupportedinBluetoothusedto
configuredevices.It’sacommandlineapplication
namedbluetoothctl.Inthenextportionofthisarticle,
we’llprovidecommandsfrombluetoothctltohelpyou
bridgefromtheorytothephysicalconfiguringofa
Bluetoothdevice.
Asmentioned,forsomeSDsaphysicalbuttonmay
needtobepressedonthedeviceforaspecifictime
intervaltoforcethedeviceintodiscoverablemode.
AdiscoverabledevicewillrespondtoanMDinquiryand
attempttoestablishaconnection.WhenanMDhas
discoveredanSDandinformationhasbeenexchanged,
thenextstepistoestablishaconnectionbetweenthe
devices.InBluetoothterminologythisisreferredtoas
paging.Duringthisphase,apasskeyorPINcode,which
isusuallyfourdigits,isauthenticatedbetweenthetwo
devices:pair.
Duringthisphaseashort-termkeyisgeneratedafter
thepasskeyhasbeensuccessfullyauthenticated.The
authenticationprocessvariesanddependsonthe
capabilitiesofthedevices.Theshort-termkeywillbe
usedthroughoutasession.Oncethepairinghas
occurred,datacanbeexchangedbetweenthedevices.
Afteradevicehascompletedthepagingprocess,it
enterstheconnectionstate: connect.
Whileconnected,anSDcanbeinthefollowingmodes:
ActiveMode:Thisistheregularconnectedmode,
wherethedeviceisactivelycommunicatingwithothers.
SniffMode:Thisisapower-savingmodeandcomes
onat regularintervalstolistenfortransmissions.
HoldMode:TheMDdirectsanSDtogointothis
power-savingmode.TheSDpowersdownfora
specifiedintervalandthenreturnstoactivemodewhen
thatintervalhaspassed.
Park Mode: MD directs the SD to power down and
only powers up on a command from the MD.
Bonding is the exchange of long-term keys post-
pairing. The shared key enables the devices to work
together in the future: trust .


A bit about security
In any network, information security should be a
concern. In a Bluetooth piconet network, radio waves
are used to send information over wireless connections.
Wireless is susceptible to spying and remote access.
Bluetooth connections are so ubiquitous that we forget


about the technology being used and just make
connections. Bluetooth devices pull down radio wave
transmissions from the air. The technology is
susceptible to wireless network threats such as denial-
of-service attacks, eavesdropping and message
modification. If the plan is to send sensitive information
that you want to remain confidential over a wireless
connection like Bluetooth, you need to take precautions
to ensure the signals are not misappropriated.
For example: we have a Bluetooth-enabled Pi that
has internet capability. We want to share the Pi’s
internet, so a Bluetooth connection is made to a mobile
phone and the mobile phone establishes a dial-up
connection to the internet.
If you’re of the younger persuasion you might asking,
what is dial-up? A simpler example is using the
Bluetooth communication infrastructure to synchronise
data. We rarely consider the security implication when
information from contact lists and address books are
carried on Bluetooth radio waves between devices.
Bluetooth links make it easy to synchronise data across
multiple devices. Establishing some security controls
around this type of data is not such a bad idea. It is
done over a wired/wireless network, so why not
Bluetooth as well?

We discovered an anomaly in the BlueZ installation during the final
testing for this tutorial. The tarball file from the official site has an
additional software requirement when compared to the software
pulled from the mirror site.
The tarball from the official site has a json-c software requirement
that is not present in the mirror site’s software installation. In
addition, the ./configure attribute -enable-experimental from
the official sites results in a failure error when used with the official
site software release. In order to work it has be be changed to
-enable-mesh to succeed.
There is a Developer Study Guide: Deploying BlueZ v5.50 on
Raspberry Pi3 available at http://www.bluetooth.com/bluetooth-
resources that provides the details on the json-c requirements. The
installation for this tutorial used the tarball found on the Mirror Site
and not the Official Site.
The installation was successful as demonstrated by the use case
provided. The anomaly may be corrected before this goes to print. If
that’s not the case, you at least have what worked on the day this
tutorial was written!

REPLACE BUYING LXF AT A SHOP Subscribe now at http://bit.ly/LinuxFormat


BlueZis the
officialLinux
Bluetooth
protocolstack:
http://www.bluez.org/
download.

MD: Master device
SD: Slavedevice
MS: Master or Slave

MS


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


SD


MD

Free download pdf