3. Low Power
7.1. The Link Layer State Machine
7.1.6. Multiple State Machines
In an implementation of the Link Layer, it is possible to have multiple state machines; each state machine is separate. Using this configuration, a device can, for example, be a slave, advertise, and actively scan at the same time. Or, you could configure a device to be a
master, advertise, passively scan, and initiate a connection at the same time, as illustrated in Figure 7–7. The device could also have multiple master connections to slaves at the same time.
Figure 7–7. An example of multiple state machines
Be aware that there are some restrictions related to deployment that are important to understand.
7.1.6.1. Not Master and Slave
The Link Layer is an “autocracy”; if a device is a master, it cannot also be a slave at the same time. Similarly, if a device is a slave, it cannot be a master at the same time. This
implies that if a device is a master, it cannot advertise with a connectable advertising packet;
however, it can still advertise with nonconnectable or discoverable advertising packets.
Consequently, if a device is already a slave, it cannot initiate a connection to another device because doing so could cause it to become the master of that device. By making this restriction, there will be no point in time when it is nondeterministic as to what the device should be doing.
The deterministic nature of the Link Layer enables Bluetooth low energy devices to be implemented using very efficient scheduling algorithms. Any nondeterministic system that is maintaining synchronization with multiple time domains will need to have very complex scheduling algorithms. These algorithms, by virtue of being nondeterministic, will also require significant processing requirements implemented in general-purpose CPUs. This
does not fit in with the low-power goals for the technology. The deterministic design, therefore, allows for highly efficient algorithms that can be implemented by using discrete logic.
A device also cannot be a slave of two masters at the same time. If a device is a slave, it cannot advertise with a connectable advertising packet. Being a slave of two masters is actually a harder scenario than being a master and a slave at the time. In Bluetooth classic, this would be called scatternet. Bluetooth low energy does not support scatternets.
7.2. Packets
A packet is the fundamental building block of the Link Layer. A packet is really simple; it is a labeled piece of data that is transmitted by one device and received by one or more other devices. The label identifies the device that sent the data and which devices should listen to it.
Figure 7–8 shows the packet structure, which all packets share, regardless of what they’re used for. At the start of the packet is a short training sequence called the preamble. After that is an access address that is used by the receiver to distinguish this packet from the
background radio noise. After the access address are header and length bytes. Immediately after these is the packet’s payload, followed by a cyclic redundancy check (CRC), which ensures that the payload is correct.
Figure 7–8. Packet structure 7.2.1. Advertising and Data Packets
In Bluetooth low energy, there are two types of packets: advertising and data packets. These packets are used for two completely different purposes. Devices use advertising packets to find and connect to other devices. Data packets are used once a connection has been made.
The difference between advertising packets and data packets is that a data packet is understandable by only two devices, known as the master and slave devices; advertising packets, on the other hand, are sent by one device and can be either broadcast to any device listening or directed at a specific device.
Whether a packet is an advertising packet or a data packet is determined by the channel on which the packet is transmitted. There are 3 advertising channels and 37 data channels. If a packet is transmitted on one of the 3 advertising channels, then the packet is an advertising
packet; otherwise, it is a data packet.
7.2.2. Whitening
The interesting thing about frequency-shift keying (FSK) receivers is their lack of ability to receive a very long sequence of bits of the same value. (To learn more about FSK receivers, go to Chapter 5, The Physical Layer.) For example, when transmitting a string of bits such as
“000000000000”, the receiver will assume that the center frequency of the transmitter has moved to the left and it will therefore lose frequency lock. It then misses the next “1” bit and fails to receive the rest of the packet. To protect against this, a whitener is used to randomize the packets transmitted.
A whitener is typically a very short random number generator that outputs zeros and ones in a known order for a given packet (see Table 7–1). A receiver can then use the same
random number generator to recover the original bits. To keep the original information in the output sequence, the original data is combined with the random number whitener using an exclusive-or operation.
Table 7–1. Using a Whitener in an Exclusive-Or Operation
By using a random whitener combined with the original information in the packet, a string of identical bits in the original information will be converted into a sequence that is highly randomized. This reduces the chance that the receiver will lose frequency lock. If the long string of information bits were already random in nature, any further randomization will not hurt.
The whitening random number sequence is generated using a linear feedback shift
register, similar to one used to calculate a CRC. The polynomial used is shown in Equation 7-1.
In this equation, x is the shift register.
The value of the shift register is initially set with the Link Layer channel number on which this packet will be transmitted, with the high bit set. This means that even if a packet is whitened on one channel that causes the receiver to lose lock, when it is transmitted on another channel, it will use a different whitening sequence, and therefore the receiver will be able to receive it. This is a very rare occurrence, but one from which the whitener allows
recovery.
Table 7–2 shows how the whitener is used to stop long sequences of zeros or ones from being transmitted. This example shows the first 3 bytes of data being whitened when
transmitted on channel 23. This means that the binary sequence:
input = 00000000 : 00100000 : 00010000
Table 7–2. Whitener LFSR: Input Bits and Resultant Output Bits
combined with the whitener of:
whitener = 11110101 : 01000010 : 11011110 is converted to:
output = 11110101 : 01100010 : 11001110
You can see that the data has become randomized with the whitener. The original input data has long sequences of single digits: 10,1,8,1,4. The output data does not have these long sequences, and critically, the longest single digit sequence is just four digits:
4,1,1,1,1,1,2,3,1,1,2,2,3,1.