Free bluetooth low energy development course – Bluetooth & BLE Development: The Complete Developer’s Guide
Master Bluetooth Classic, BLE, A2DP, HFP, GATT, BlueZ, LE Audio & More — From Embedded to Linux Stack
What You’ll Learn in This Guide
Hello students welocme to the free bluetooth development course in This comprehensive Bluetooth development tutorial covers everything from the fundamentals of Bluetooth Low Energy (BLE) development to advanced topics like A2DP audio programming, HFP hands-free profile implementation, GATT server and client development, and BlueZ Linux Bluetooth stack internals. Whether you are a beginner exploring BLE protocol programming or an experienced engineer diving into LE Audio development, this guide is your single-stop resource.
This is a complete intorduction lecture where i will give you outline of the course from upcomming lecutres we will discuss more about the core concepts of bluetooth.
Bluetooth technology powers over 5 billion devices worldwide — from fitness trackers and medical sensors to car infotainment systems and industrial IoT nodes. Understanding the Bluetooth stack, profiles, and host controller interface (HCI) is an essential skill for any embedded software engineer or wireless developer.
Topics Covered in This Series
1. Bluetooth Low Energy (BLE) — Core Concepts for Developers
Bluetooth Low Energy (BLE), introduced in the Bluetooth 4.0 specification (2010), is a wireless personal area network technology designed for ultra-low power consumption. Unlike Bluetooth Classic, BLE is optimized for short, infrequent data bursts rather than continuous streaming. It operates on the 2.4 GHz ISM band using 40 RF channels (37 data channels + 3 advertising channels).
Key differences between BLE vs Bluetooth Classic:
- Power consumption: BLE can run on a coin cell battery for months or even years; Bluetooth Classic requires more frequent recharging.
- Data rate: BLE offers up to 2 Mbps (BT 5.0+) while Classic supports up to 3 Mbps (EDR).
- Latency: BLE connection setup takes as low as 3 ms; Classic can take 100+ ms.
- Use case: BLE suits sensors and IoT; Classic suits audio streaming (A2DP) and file transfer.
The BLE protocol stack is divided into three main sections: the Controller, the Host, and the Application. Understanding this layering is critical for any Bluetooth firmware developer or BLE software engineer.
Controller Layer:
- Physical Layer (PHY): Handles radio modulation. BT 5.0 added LE 2M PHY (2 Mbps) and LE Coded PHY (long range, 125 kbps / 500 kbps).
- Link Layer (LL): Manages device states (Standby, Advertising, Scanning, Initiating, Connection, Synchronization), CRC, encryption, and frequency hopping.
HCI (Host Controller Interface): The transport layer between the Controller and Host. It carries HCI Commands, HCI Events, and ACL/SCO data. HCI can run over UART (H4/H5), USB, or SDIO.
Host Layer:
- L2CAP: Logical Link Control and Adaptation Protocol — segmentation, reassembly, and channel multiplexing.
- ATT (Attribute Protocol): Client-server protocol for reading and writing attributes. The foundation of GATT.
- GATT (Generic Attribute Profile): Defines how attributes (Services, Characteristics, Descriptors) are organized and accessed.
- GAP (Generic Access Profile): Controls device discovery, advertising, and connection establishment.
- SMP (Security Manager Protocol): Handles BLE pairing, bonding, and encryption key distribution.
- SM (Security Manager): Works with SMP for LE Secure Connections and Legacy Pairing.
2. GAP — Generic Access Profile Programming
GAP (Generic Access Profile) defines the roles and procedures for BLE device discovery and BLE connection management. Every BLE device operates in one or more GAP roles:
- Broadcaster: Continuously sends advertising packets (no connections). Used in beacons, iBeacon, Eddystone.
- Observer: Passively scans for advertisers. Does not connect.
- Peripheral: Advertises and accepts connection requests. Typically a sensor or wearable.
- Central: Scans for peripherals and initiates connections. Typically a smartphone or gateway.
BLE Advertising Packet Types: ADV_IND (connectable undirected), ADV_DIRECT_IND (directed), ADV_NONCONN_IND (non-connectable), SCAN_IND, and in BT 5.0 — Extended Advertising with up to 255 bytes payload and Periodic Advertising.
Connection Parameters: Connection Interval (7.5 ms – 4 s), Slave Latency, Supervision Timeout. Tuning these is critical for BLE power optimization.
3. ATT & GATT — Attribute Protocol & Generic Attribute Profile
The ATT (Attribute Protocol) defines a client-server model where the ATT Server hosts a table of attributes and the ATT Client reads or writes them. Each attribute has:
- Handle: A 16-bit identifier (1×0001 – 0xFFFF) used to reference the attribute.
- Type (UUID): 16-bit (SIG assigned) or 128-bit (custom) UUID identifying what the attribute represents.
- Value: The actual data payload.
- Permissions: Readable, Writable, Notify, Indicate, and security requirements.
ATT Operations: Read Request/Response, Write Request/Response, Write Command (no ACK), Notifications (no ACK), Indications (ACK required), Prepare Write, Execute Write (for long attributes > MTU), Find Information, Read By Type, Read By Group Type.
The default ATT MTU is 23 bytes. Using MTU Exchange (ATT_EXCHANGE_MTU) you can negotiate up to 517 bytes, significantly improving throughput in BLE data transfer applications.
GATT (Generic Attribute Profile) builds on ATT to define how attributes are structured into meaningful Bluetooth Services and Characteristics.
GATT Hierarchy:
- Profile: A collection of services for a specific use case (e.g., Heart Rate Profile, Battery Profile).
- Service: A group of related characteristics. Example: Heart Rate Service (UUID 0x180D).
- Characteristic: A single data point with a value, properties, and descriptors. Example: Heart Rate Measurement (UUID 0x2A37).
- Descriptor: Metadata about a characteristic. The most important is the Client Characteristic Configuration Descriptor (CCCD, UUID 0x2902) — used to enable/disable notifications and indications.
In GATT server development, you define the attribute database statically or dynamically and handle Read/Write callbacks. In GATT client development, you perform Service Discovery (GATT Discovery) to find services and characteristics on the remote device, then subscribe to notifications via CCCD.
4. BlueZ — Linux Bluetooth Stack Development
BlueZ is the official Linux Bluetooth protocol stack. It has two major components:
- Kernel Space: HCI core, L2CAP, RFCOMM, BNEP (Bluetooth Network Encapsulation Protocol), and HIDP (HID Profile) are implemented as kernel modules. Key modules:
bluetooth.ko,hci_uart.ko,hci_usb.ko,btusb.ko. - User Space:
bluetoothd(the BlueZ daemon) manages device pairing, profiles, and exposes a D-Bus API for applications.
BlueZ D-Bus interfaces include:
org.bluez.Adapter1— Manage local BT adapters (power on/off, start discovery, set discoverable).org.bluez.Device1— Represent remote devices (connect, disconnect, pair, trust).org.bluez.GattManager1— Register custom GATT applications (servers).org.bluez.GattService1 / GattCharacteristic1 / GattDescriptor1— Define GATT hierarchy via D-Bus object paths.org.bluez.LEAdvertisingManager1— Register BLE advertisement data.org.bluez.MediaEndpoint1— For A2DP and LE Audio codec negotiation.org.bluez.HandsfreeGateway1 / Headset1— HFP/HSP profile interfaces.
Use bluetoothctl CLI for quick device management, and btmon for real-time HCI packet monitoring — an essential tool for Bluetooth debugging on Linux.
The most common way to implement a custom BLE GATT service on Linux is by registering a GATT application with bluetoothd via D-Bus. Here’s the workflow:
- Create D-Bus object paths following the BlueZ hierarchy:
/org/bluez/example/service0,/org/bluez/example/service0/char0 - Implement the
org.bluez.GattService1interface on the service object withUUIDandPrimaryproperties. - Implement
org.bluez.GattCharacteristic1withUUID,Service,Flags(read/write/notify), and callback methodsReadValue(),WriteValue(),StartNotify(),StopNotify(). - Call
RegisterApplication()onorg.bluez.GattManager1. - Register an advertisement via
LEAdvertisingManager1.RegisterAdvertisement().
This approach is used in BLE sensor development on Raspberry Pi, BeagleBone, and any embedded Linux platform running BlueZ.
5. A2DP — Advanced Audio Distribution Profile Development
A2DP (Advanced Audio Distribution Profile) enables high-quality stereo audio streaming over Bluetooth Classic. It is the profile behind wireless headphones, Bluetooth speakers, and car audio systems. A2DP relies on:
- AVDTP (Audio/Video Distribution Transport Protocol): Manages stream setup, codec negotiation (SEP — Stream End-Point discovery), and audio data transport over L2CAP.
- GAVDP (Generic Audio/Video Distribution Profile): Generic base for AVDTP.
- SBC (Sub-Band Codec): The mandatory A2DP codec — low complexity but moderate quality. Developers must understand SBC parameters: sampling frequency (44.1 / 48 kHz), channel mode (Mono, Stereo, Joint Stereo, Dual Channel), block length (4/8/12/16), subbands (4/8), bitpool range.
- AAC: Higher quality, mandatory on Apple devices.
- aptX / aptX HD / aptX Adaptive: Qualcomm codecs for lower latency and higher fidelity.
- LDAC: Sony’s codec for high-resolution audio (up to 990 kbps).
In BlueZ A2DP development, codec endpoints are registered via org.bluez.MediaEndpoint1. The SelectConfiguration() callback negotiates codec parameters. Audio data is typically routed through PipeWire or PulseAudio (using module-bluetooth-discover) for playback.
AVRCP (Audio/Video Remote Control Profile) works alongside A2DP to provide media control — play, pause, skip, volume, and metadata (track name, artist). Key AVRCP concepts for developers:
- AVRCP Roles: Controller (CT) — sends commands; Target (TG) — responds. A phone sending “Next Track” to headphones = CT.
- AVCTP (Audio/Video Control Transport Protocol): Carries AVRCP PDUs over L2CAP.
- AVRCP 1.3+: Introduced GetElementAttributes for metadata (title, artist, album, duration).
- AVRCP 1.4+: Added Browsing (MediaPlayer list, VFS browsing, search).
- AVRCP 1.6: Cover Art transfer via OBEX BIP.
In BlueZ, AVRCP is exposed via org.bluez.MediaPlayer1 and org.bluez.MediaControl1 D-Bus interfaces. Applications can send transport controls (Play/Pause/Next/Previous) and receive metadata updates through D-Bus signals.
6. HFP — Hands-Free Profile Development
HFP (Hands-Free Profile) enables voice calls over Bluetooth — used in car kits, headsets, and speakerphones. It is distinct from A2DP (music streaming) as it handles bidirectional narrow-band or wide-band voice audio.
Key HFP components:
- Roles: Audio Gateway (AG) — the phone or call source; Hands-Free Unit (HFU) — the headset or car kit.
- RFCOMM: HFP signalling runs over RFCOMM (a serial port emulation over L2CAP), using AT commands (AT+CIND, AT+CLCC, AT+BRSF, AT+CHLD, AT+VGS, AT+VGM, ATA, ATH, etc.).
- SCO/eSCO (Synchronous Connection Oriented): The audio transport for HFP voice. eSCO supports retransmissions for better quality.
- Codecs: CVSD (narrowband, 8 kHz) is mandatory. mSBC (modified SBC) is used for Wideband Speech (WBS) at 16 kHz — negotiated via HFP 1.6+ AT+BCS/AT+BCC.
- HFP 1.7: Added Super Wideband Speech with aptX Voice and LC3-SWB codecs.
In BlueZ HFP development, the org.bluez.HandsfreeGateway1 and org.bluez.Headset1 interfaces (deprecated in newer BlueZ, replaced by oFono integration) manage call state. Developers may also use oFono as the telephony daemon paired with BlueZ for complete HFP stack.
HSP (Headset Profile) is the simpler predecessor to HFP — supports basic call answer/hang-up and volume control but lacks multi-call handling, voice dial, and 3-way calling.
7. BLE Security — Pairing, Bonding, and Encryption
BLE Security is managed by the Security Manager Protocol (SMP) running over a dedicated L2CAP fixed channel (CID 0x0006). Key concepts:
- Pairing Methods:
- Just Works: No user interaction. Vulnerable to MITM attacks. Used for low-security scenarios.
- Passkey Entry: One device displays a 6-digit code; the other enters it. Provides MITM protection.
- Out Of Band (OOB): Uses NFC or another channel to exchange keys. High security.
- Numeric Comparison (LE Secure Connections only): Both devices display a 6-digit number and the user confirms they match.
- Legacy Pairing vs LE Secure Connections (LESC): LESC uses ECDH (Elliptic Curve Diffie-Hellman) for key exchange — significantly more secure than Legacy Pairing.
- Key Types: LTK (Long Term Key) for re-encryption, IRK (Identity Resolving Key) for resolving resolvable private addresses, CSRK (Connection Signature Resolving Key) for signed writes.
- Bonding: Storing keys persistently so the two devices can reconnect encrypted without re-pairing.
- Privacy: BLE devices can use Resolvable Private Addresses (RPA) that change periodically, preventing tracking. Only bonded devices with the IRK can resolve the address.
8. LE Audio — Next-Generation Bluetooth Audio Development
LE Audio (introduced in Bluetooth 5.2) is a revolutionary update to Bluetooth audio, moving from Classic BR/EDR to BLE for audio transport. It introduces:
- LC3 (Low Complexity Communication Codec): The new mandatory codec. Superior audio quality at lower bitrates compared to SBC. Supports 7.5 ms and 10 ms frame durations, multiple sampling rates (8–48 kHz), and bitrates from 16 to 320 kbps. Essential for hearing aids at 16 kbps.
- Isochronous Channels:
- CIS (Connected Isochronous Streams): Unicast audio between connected devices. Replaces A2DP + HFP for BLE-based headsets. Low latency (~10 ms round-trip possible).
- BIS (Broadcast Isochronous Streams): One-to-many audio broadcast. The foundation of Auracast.
- Auracast Broadcast Audio: Allows a single source (TV, public address system, gym) to broadcast audio to unlimited receivers. Receivers use Broadcast Audio Scan Service (BASS) to find and sync to BIS streams.
- New Profiles: PACS (Published Audio Capabilities Service), ASCS (Audio Stream Control Service), BASS, CAP (Common Audio Profile), TMAP (Telephony and Media Audio Profile), HAP (Hearing Access Profile), GMAP (Gaming Audio Profile).
- Multi-Stream Audio: Coordinated audio to left and right earbuds simultaneously — true wireless stereo with BLE.
In BlueZ LE Audio development, support is actively being upstreamed. The btmanager, pipewire-pulse, and new BlueZ DBUS objects (org.bluez.MediaTransport1 with ISO transport type) are the key integration points.
9. Essential Bluetooth Profiles for Embedded Developers
Beyond A2DP and HFP, embedded Bluetooth developers frequently encounter these profiles:
- SPP (Serial Port Profile): Emulates a serial RS-232 port over RFCOMM. Widely used in legacy BT modules for simple bidirectional data communication. Common in industrial equipment and GPS modules.
- HID (Human Interface Device Profile): For BT keyboards, mice, game controllers. Uses HID over GATT (HOGP) for BLE-based HID devices (keyboards, mice that use BLE). The HOGP protocol uses the HID Service (0x1812) with Report Characteristics.
- PBAP (Phone Book Access Profile): Allows car kits to download contacts and call history from a connected phone via OBEX. Uses RFCOMM + OBEX + vCard format.
- MAP (Message Access Profile): Allows car kits to access SMS, MMS, and email from a connected phone.
- OPP (Object Push Profile): Simple file sharing — push vCards, calendar entries, images.
- FTP (File Transfer Profile): Full file system browsing and transfer over OBEX.
- PAN (Personal Area Networking Profile): Bluetooth-based IP networking using BNEP. Supports NAP (Network Access Point), GN (Group Network), PANU (Personal Area Network User) roles.
- DID (Device ID Profile): Exposes Vendor ID, Product ID, and Version via SDP for device identification.
- GAP Profiles for IoT: Device Information Service (DIS, 0x180A), Battery Service (BAS, 0x180F), Current Time Service, Environmental Sensing Service — commonly used in IoT BLE device development.
10. HCI — Host Controller Interface Programming
The HCI (Host Controller Interface) is the standardized API between the Bluetooth Host software and the Controller hardware. Every Bluetooth operation — advertising, scanning, connection, pairing, data transfer — ultimately translates to HCI commands and events.
HCI Packet Types:
- HCI Command Packet (0x01): Sent from Host to Controller. E.g.,
LE_Set_Advertising_Data,LE_Create_Connection,LE_Set_Extended_Advertising_Parameters. - HCI ACL Data Packet (0x02): Asynchronous Connection-Less data (L2CAP payloads for ATT/GATT/SMP/RFCOMM).
- HCI SCO Data Packet (0x03): Synchronous audio data for HFP voice.
- HCI Event Packet (0x04): Controller notifies Host of events. E.g.,
LE_Meta_Eventfor BLE-specific events likeLE_Connection_Complete,LE_Advertising_Report. - HCI ISO Data Packet (0x05): Isochronous data for LE Audio CIS/BIS streams.
Debugging HCI on Linux: Use btmon to capture live HCI traffic. Output can be saved to a BTSnoop file and opened in Wireshark for protocol analysis. The filter bthci_cmd, bthci_evt, btle are your go-to Wireshark display filters for Bluetooth protocol analysis.
For raw HCI socket programming in C, use socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI) — useful for writing custom Bluetooth utilities and test tools.
11. BLE Mesh, Zephyr RTOS, and IoT Development
Bluetooth Mesh (Mesh Profile 1.0/1.1) enables a many-to-many network topology over BLE, ideal for smart lighting, building automation, and industrial IoT. Key concepts:
- Publish-Subscribe Model: Nodes publish messages to addresses; other nodes subscribed to those addresses receive them.
- Managed Flooding: Messages are relayed by Relay nodes. No single point of failure.
- Provisioning: Adding a new device to the mesh network using the Provisioning Protocol (PB-ADV or PB-GATT).
- Models: Generic On/Off, Generic Level, Light Lightness, Sensor, Scene, Time & Scheduler, Configuration, Health models.
- Security: Two layers — Network Key (NetKey) and Application Key (AppKey). Fully encrypted and authenticated.
Zephyr RTOS BLE Development: The Zephyr BLE stack is a fully open-source, standards-compliant BLE implementation. It supports BLE Mesh, GATT, GAP, SMP, LE Audio (CIS/BIS), and runs on platforms like nRF52, nRF53, STM32WB, and ESP32. It is the stack of choice for embedded BLE firmware development in RTOS environments.
Other popular stacks for embedded: NimBLE (Apache Mynewt / ESP-IDF), SoftDevice (Nordic), Mbed BLE (ARM).
12. Bluetooth Development Tools and Testing
Every Bluetooth developer’s toolkit should include:
- nRF Connect for Desktop / Mobile: Nordic’s all-in-one BLE tool. Scan, connect, discover GATT services, read/write characteristics, and test BLE over the air. Essential for BLE GATT testing.
- Wireshark + Ubertooth One: Open-source BLE packet sniffer. Ubertooth One is the hardware; Wireshark decodes BLE packets with
btledissectors. - Ellisys Bluetooth Explorer / Frontline BPA Low Energy: Professional Bluetooth protocol analyzers — capture full BLE + Classic traffic with time correlation. Industry-standard for Bluetooth certification testing.
- btgatt-client / btgatt-server: BlueZ example tools for GATT testing.
- hcitool / hciconfig (legacy): Command-line HCI tools. Deprecated in favor of
bluetoothctlbut still widely used for scripting. - gatttool (legacy): Command-line GATT client. Replaced by
bluetoothctl gattsubcommands. - BLE Scanner / LightBlue (mobile): Quick mobile-side scanning and GATT exploration.
- Bluetooth PTS (Profile Tuning Suite): Bluetooth SIG’s official certification test tool — required for Bluetooth qualification (QDID).
Start Your Bluetooth Development Journey
Free, structured courses on BLE, BlueZ, A2DP, HFP, GATT, LE Audio and more — no signup required.
