+ All Categories
Home > Documents > IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2...

IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2...

Date post: 25-Apr-2019
Category:
Upload: vokhanh
View: 225 times
Download: 0 times
Share this document with a friend
430
VERSION 1.0 March 11, 2019 BTstack Manual Including Quickstart Guide Dr. sc. Milanka Ringwald Dr. sc. Matthias Ringwald [email protected]
Transcript
Page 1: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

VERSION 1.0March 11, 2019

BTstack ManualIncluding Quickstart Guide

Dr. sc. Milanka RingwaldDr. sc. Matthias Ringwald

[email protected]

Page 2: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

1

Contents

1. Welcome 22. Quick Start 22.1. General Tools 22.2. Getting BTstack from GitHub 22.3. Let’s Go 23. BTstack Architecture 33.1. Single threaded design 43.2. No blocking anywhere 43.3. No artificially limited buffers/pools 53.4. Statically bounded memory 54. How to configure Btstack 54.1. Configuration in btstack config.h 54.1.1. HAVE * directives 64.1.2. ENABLE * directives 64.1.3. HCI Controller to Host Flow Control 74.1.4. Memory configuration directives 84.1.5. Non-volatile memory (NVM) directives 104.2. Source tree structure 114.3. Run loop configuration 114.3.1. Run loop embedded 124.3.2. Run loop POSIX 124.3.3. Run loop CoreFoundation (OS X/iOS) 124.3.4. Run loop Windows 134.3.5. Run loop WICED 134.4. HCI Transport configuration 134.5. Services 144.6. Packet handlers configuration 154.7. Bluetooth HCI Packet Logs 164.8. Bluetooth Power Control 175. Protocols 185.1. HCI - Host Controller Interface 195.1.1. Defining custom HCI command templates 195.1.2. Sending HCI command based on a template 215.2. L2CAP - Logical Link Control and Adaptation Protocol 215.2.1. Access an L2CAP service on a remote device 215.2.2. Provide an L2CAP service 235.2.3. Sending L2CAP Data 245.2.4. LE Data Channels 245.3. RFCOMM - Radio Frequency Communication Protocol 255.3.1. No RFCOMM packet boundaries 255.3.2. RFCOMM flow control 255.3.3. Access an RFCOMM service on a remote device 255.3.4. Provide an RFCOMM service 275.3.5. Slowing down RFCOMM data reception 285.3.6. Sending RFCOMM data 29

Page 3: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

2

5.3.7. Optimized sending of RFCOMM data 305.4. SDP - Service Discovery Protocol 305.4.1. Create and announce SDP records 305.4.2. Query remote SDP service 315.5. BNEP - Bluetooth Network Encapsulation Protocol 325.5.1. Receive BNEP events 325.5.2. Access a BNEP service on a remote device 325.5.3. Provide BNEP service 335.5.4. Sending Ethernet packets 335.6. ATT - Attribute Protocol 335.7. SMP - Security Manager Protocol 335.7.1. LE Legacy Pairing and LE Secure Connections 335.7.2. Initialization 345.7.3. Configuration 345.7.4. Identity Resolving 355.7.5. User interaction 355.7.6. Keypress Notifications 355.7.7. Cross-transport Key Derivation for LE Secure Connections 355.7.8. Out-of-Band Data with LE Legacy Pairing 356. Profiles 366.1. GAP - Generic Access Profile: Classic 366.1.1. Become discoverable 366.1.2. Discover remote devices 366.1.3. Pairing of Devices 386.1.4. Dedicated Bonding 396.2. SPP - Serial Port Profile 396.2.1. Accessing an SPP Server on a remote device 396.2.2. Providing an SPP Server 396.3. PAN - Personal Area Networking Profile 396.3.1. Accessing a remote PANU service 406.3.2. Providing a PANU service 406.4. HSP - Headset Profile 406.5. HFP - Hands-Free Profile 406.6. GAP LE - Generic Access Profile for Low Energy 416.6.1. Private addresses. 416.6.2. Advertising and Discovery 416.7. GATT - Generic Attribute Profile 416.7.1. GATT Client 426.7.2. GATT Server 426.7.3. Implementing Standard GATT Services 447. Implemented GATT Services 467.0.1. Battery Service {#sec:BatteryService}} 467.0.2. Heart Rate Service {#sec:HeartRateService}} 468. Embedded Examples 478.1. led counter: Hello World: blinking LED without Bluetooth 498.1.1. Periodic Timer Setup 498.1.2. Main Application Setup 49

Page 4: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

3

8.2. gap inquiry: GAP Inquiry Example 508.2.1. Bluetooth Logic 508.2.2. Main Application Setup 508.3. sdp general query: Dump remote SDP Records 518.3.1. SDP Client Setup 518.3.2. SDP Client Query 518.3.3. Handling SDP Client Query Results 528.4. sdp bnep query: Dump remote BNEP PAN protocol UUID and

L2CAP PSM 538.4.1. SDP Client Setup 538.4.2. SDP Client Query 548.4.3. Handling SDP Client Query Result 548.5. spp counter: SPP Server - Heartbeat Counter over RFCOMM 568.5.1. SPP Service Setup 568.5.2. Periodic Timer Setup 578.5.3. Bluetooth Logic 588.6. spp flowcontrol: SPP Server - Flow Control 608.6.1. SPP Service Setup 608.6.2. Periodic Timer Setup 608.7. panu demo: PANU Demo 618.7.1. Main application configuration 618.7.2. SDP parser callback 628.7.3. Packet Handler 628.7.4. Network packet handler 648.8. hsp hs demo: HSP Headset Demo 658.8.1. Audio Transfer Setup 658.8.2. Main Application Setup 658.9. hsp ag demo: HSP Audio Gateway Demo 668.9.1. Audio Transfer Setup 668.9.2. Main Application Setup 668.10. hfp hs demo: HFP Hands-Free (HF) Demo 678.10.1. Main Application Setup 678.11. hfp ag demo: HFP Audio Gateway (AG) Demo 698.11.1. Main Application Setup 698.12. gap le advertisements: GAP LE Advertisements Dumper 708.12.1. GAP LE setup for receiving advertisements 708.12.2. GAP LE Advertising Data Dumper 718.12.3. HCI packet handler 748.13. gatt browser: GATT Client - Discovering primary services and

their characteristics 758.13.1. GATT client setup 758.13.2. HCI packet handler 768.13.3. GATT Client event handler 778.14. le counter: LE Peripheral - Heartbeat Counter over GATT 788.14.1. Main Application Setup 788.14.2. Heartbeat Handler 808.14.3. Packet Handler 81

Page 5: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

4

8.14.4. ATT Read 818.14.5. ATT Write 828.15. le streamer: LE Streamer - Stream data over GATT. 828.15.1. Main Application Setup 838.15.2. Track throughput 838.15.3. HCI Packet Handler 848.15.4. ATT Packet Handler 868.15.5. Streamer 878.15.6. ATT Write 888.16. spp and le counter: Dual mode example 898.16.1. Advertisements 898.16.2. Packet Handler 908.16.3. Heartbeat Handler 908.16.4. Main Application Setup 908.17. a2dp sink demo: Receive audio stream and control its playback. 928.17.1. Main Application Setup 928.17.2. Handle Media Data Packet 938.18. a2dp source demo: Serve audio stream and handle remote playback

control and queries. 938.18.1. Main Application Setup 938.19. hid keyboard demo: HID Keyboard (Server) Demo 958.19.1. Main Application Setup 958.20. hid mouse demo: HID Mouse (Server) Demo 978.20.1. Main Application Setup 978.21. hog keyboard demo: HID-over-GATT Keyboard 988.22. hog mouse demo: HID-over-GATT Mouse 988.23. sm pairing central: LE Peripheral - Test pairing combinations 988.23.1. GAP LE setup for receiving advertisements 988.23.2. HCI packet handler 998.24. sm pairing peripheral: LE Peripheral - Test pairing combinations 1028.24.1. Main Application Setup 1028.24.2. Packet Handler 1048.25. pbap client demo: Connect to Phonebook Server and get contacts.1058.26. le streamer: LE Streamer - Stream data over GATT. 1068.26.1. Main Application Setup 1068.26.2. Track throughput 1078.26.3. HCI Packet Handler 1078.26.4. ATT Packet Handler 1098.26.5. Streamer 1108.26.6. ATT Write 1118.27. le streamer client: Connects to ‘LE Streamer’ and subscribes to

test characteristic 1128.27.1. Track throughput 1128.28. spp streamer: Send test data via SPP as fast as possible. 1138.28.1. Track throughput 1138.28.2. Packet Handler 1148.28.3. Main Application Setup 114

Page 6: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

5

8.29. spp streamer client: Client for SPP Streamer 1158.29.1. Track throughput 1158.29.2. Packet Handler 1168.29.3. Main Application Setup 1168.30. dut mode classic: Enable Device Under Test (DUT) Mode for

BR/EDR 1178.30.1. Bluetooth Logic 1178.30.2. Main Application Setup 1179. Chipsets 1179.1. HCI Interface 1189.1.1. HCI H2 1189.1.2. HCI H4 1199.1.3. HCI H5 1199.1.4. BCSP 1199.1.5. eHCILL 1199.1.6. H4 over SPI 1199.1.7. HCI Shortcomings 1199.2. Documentation and Support 1209.3. Chipset Overview 1229.4. Atmel/Microchip 1229.5. Broadcom/Cypress Semiconductor 1239.6. CSR / Qualcomm Incorporated 1249.7. Dialog Semiconductor 1249.8. Espressif ESP32 1259.9. EM Microelectronic Marin 1259.10. Intel Dual Wireless 8260, 8265 1259.11. Nordic nRF5 series 1269.12. STMicroelectronics 1269.13. Texas Instruments CC256x series 1279.14. Toshiba 12810. Porting to Other Platforms 12810.1. Time Abstraction Layer 12910.1.1. Tick Hardware Abstraction 12910.1.2. Time MS Hardware Abstraction 12910.2. Bluetooth Hardware Control API 12910.3. HCI Transport Implementation 13010.3.1. HCI UART Transport Layer (H4) 13010.3.2. H4 with eHCILL support 13010.3.3. H5 13110.4. Persistent Storage APIs 13110.4.1. Link Key DB 13111. Existing Ports 13112. BTstack port for Ambiq Apollo2 with EM9304 13212.1. Hardware 13212.2. Software 13212.3. Create Example Projects 13212.4. Compile & Run Example Project 133

Page 7: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

6

12.5. Debug output 13313. TODO 13313.1. Setup 13313.2. Usage 13413.3. Old Make Versions 13413.4. Configuration 13413.5. Limitations 13413.5.1. Issues with the Bluetooth Controller Implementation 13413.5.2. Audio playback 13413.5.3. Multi-Threading 13513.5.4. Acknowledgments 13514. BTstack for iOS 13514.1. How to develop 13614.2. Compile Instructions for BTstack package 13614.3. Console Examples 13614.4. Wii Mote CoocaTouch example 13615. BTstack Port for POSIX Systems with libusb Library 13715.1. Compilation 13715.2. Environment 13715.3. Running the examples 13816. BTstack Port for POSIX Systems with Intel Wireless 8260/8265

Controllers 13916.1. Compilation 13916.2. Environment 13916.3. Running the examples 14017. BTstack Port for the Maxim MAX32630FTHR ARM Cortex-M4F 14017.1. Software 14117.2. Toolchain Setup 14117.3. Usage 14117.4. Build 14117.5. Eclipse 14117.6. Flashing Max32630 ARM Processor 14117.7. Debugging 14117.8. Debug output 14217.9. TODOs 14218. Experimental port of BTstack to Zephyr running on Nordic nRF5

Series 14218.1. Overview 14218.2. Status 14218.3. Getting Started 14218.4. TODO 14319. Experimental port for Nordic nRF5 Series 14319.1. Overview 14319.2. Status 14319.3. Getting Started 14320. BTstack Port for the Microchip PIC32 Harmony Platform 14320.1. Hardware 143

Page 8: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

7

20.2. Software 14320.3. Setup 14420.4. Usage 14420.4.1. Modifications to the GATT Database 14420.4.2. Compiler Warnings: 14421. BTstack Port for POSIX Systems with H4 Bluetooth Controller 14421.1. Configuration 14421.2. TI CC256x 14421.3. Broadcom BCM/CYW 43430 14421.4. Compilation 14421.5. Running the examples 14521.6. Compilation 14521.7. Usage 14521.8. Prepare Zephyr Controller 14721.9. Configure serial port 14721.10. Compile Examples 14721.11. Run example 14822. BTstack Port for Raspberry Pi 3 with BCM4343 Bluetooth/Wifi

Controller 14822.1. Raspberry Pi 3 / Zero W Setup 14822.1.1. Install Raspian Stretch Lite: 14822.1.2. Configure Wifi 14822.1.3. Enable SSH 14822.1.4. Boot 14822.1.5. Disable bluez 14922.2. Compilation 14922.2.1. Compile using Docker 14922.3. Running the examples 15022.4. Bluetooth Hardware Overview 15022.5. TODO 15022.6. Create Example Projects 15122.7. Compile Example 15122.8. Debug output 15122.9. TODOs 15122.10. Issues 15123. STM32 F103RB Nucleo with CC256x 15223.1. Hardware 15223.2. Software 15323.3. Create Example Projects 15323.4. Import Example Project 15323.5. Run Example Project 15323.6. Debug output 15323.7. GATT Database 15323.8. TODOs 15423.9. Maintainer Notes - Updating The Port 15423.9.1. Update cubemx-f4discovery-cc256x from STM32CubeMX project15423.9.2. Update local Eclipse project from cubemx-f4discovery-cc256x 154

Page 9: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

8

23.9.3. Update eclipse-template from local Eclipse project 15424. BTstack port for STM32 Nucleo-L053R8 Board with an EM9304

Shield - EM9304 DVK 15424.1. Hardware 15424.2. Software 15424.3. Debug output 15524.4. GATT Database 15524.5. Stability 15524.6. Multiple LE Peripheral/Central Roles 15524.7. Performace 15524.8. Image 15625. BTstack port for WICED platform 15725.1. Additional notes on the H5 port 15826. BTstack Port for Windows Systems with Bluetooth Controller

connected via Serial Port 15826.1. Toolchain 15826.2. Compilation 15926.3. Console Output 15927. BTstack port for Zephyr Controller with HCI UART Firmware

Connectected To POSIX System 15927.1. Prepare Zephyr Controller 15927.2. Configure serial port 16027.3. Compile Examples 16027.4. Run example 16028. BTstack port for Windows Systems using the WinUSB Driver 16028.1. Access to Bluetooth USB Dongle with Zadig 16028.2. Toolchain 16028.3. Compilation 16128.4. Console Output 16129. BTstack port for Windows Systems with Intel Wireless 8260/8265

Controllers 16129.1. Access to Bluetooth USB Dongle with Zadig 16129.2. Toolchain 16129.3. Compilation 16229.4. Console Output 16230. Integrating with Existing Systems 16230.1. Adapting BTstack for Single-Threaded Environments 16230.2. Adapting BTstack for Multi-Threaded Environments 16331. APIs 16531.1. BLE ANCS Client API 16531.2. BLE ATT Database API 16531.3. BLE ATT Server API 16731.4. BLE GATT Client API 16931.5. BLE Device Database API 18331.6. BLE Security Manager API 18631.7. BNEP API 19031.8. Link Key DB API 191

Page 10: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

9

31.9. HSP Headset API 19331.10. HSP Audio Gateway API 19531.11. HFP Hands-Free API 19731.12. HFP Audio Gateway API 20631.13. PAN API 21231.14. RFCOMM API 21331.15. SDP Client API 21731.16. SDP RFCOMM Query API 21831.17. SDP Server API 21931.18. SDP Utils API 21931.19. BLE Advertisements Parser API 22131.20. BTstack Chipset API 22231.21. BTstack Hardware Control API 22231.22. HCI Event Getter API 22231.23. BTstack Memory Management API 38431.24. BTstack Linked List API 38431.25. Run Loop API 38531.26. Common Utils API 38731.27. GAP API 39131.28. HCI API 40231.29. HCI Logging API 40531.30. HCI Transport API 40631.31. L2CAP API 40832. Events and Errors 41332.1. L2CAP Events 41432.2. RFCOMM Events 41432.3. Errors 41633. Migration to v1.0 41634. Changes 41634.1. Repository structure 41634.1.1. include/btstack folder 41634.1.2. Plural folder names 41634.1.3. ble and src folders 41634.1.4. platform and port folders 41634.1.5. Common file names 41634.2. Defines and event names 41734.3. Function names 41734.4. Packet Handlers 41734.5. Event Forwarding 41734.6. util folder 41734.7. btstack config.h 41734.8. Linked List 41834.9. Run Loop 41834.10. HCI Setup 41834.10.1. remote device db 41834.10.2. bt control 41834.11. HCI / GAP 418

Page 11: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

10

34.12. RFCOMM 41834.13. SPP Server 41834.14. SDP Client 41834.15. SDP Server 41834.16. Security Manager 41834.17. GATT Client 41934.18. ANCS Client 41934.19. Flow control / DAEMON EVENT HCI PACKET SENT 41934.20. Daemon 41934.21. Migration to v1.0 with a script 41934.21.1. Requirements 41934.21.2. Usage 42034.22. Migration to v1.0 with a Web Service 420

Page 12: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

11

1. Welcome

Thanks for checking out BTstack!In this manual, we first provide a ‘quick starter guide’ for common platforms

before highlighting BTstack’s main design choices and go over all implementedprotocols and profiles.

A series of examples show how BTstack can be used to implement commonuse cases.

Finally, we outline the basic steps when integrating BTstack into existingsingle-threaded or even multi-threaded environments.

2. Quick Start

2.1. General Tools. Most ports use a regular Makefile to build the examples.On Unix-based systems, git, make, and Python are usually installed. If not,

use the system’s packet manager to install them.On Windows, there is no packet manager, but it’s easy to download and install

all requires development packets quickly by hand. You’ll need:

• Python for Windows. When using the official installer, please confirmadding Python to the Windows Path.• MSYS2 is used to provide the bash shell and most standard POSIX com-

mand line tools.• MinGW64 GCC for Windows 64 & 32 bits incl. make. To install with

MSYS2: pacman -S mingw-w64-x86 64-gcc• git is used to download BTstack source code. To install with MSYS2:

pacman -S git• winpty a wrapper to allow for console input when running in MSYS2: To

install with MSYS2: pacman -S winpty

2.2. Getting BTstack from GitHub. Use git to clone the latest version:

g i t c l one https : // g i t hub . com/ b l u e k i t c h en / b t s t a c k . g i t

Alternatively, you can download it as a ZIP archive from BTstack’s page onGitHub.

2.3. Let’s Go. The easiest way to try BTstack is on a regular desktop setup likemacOS, Linux or Windows together with a standard USB Bluetooth Controller.Running BTstack on desktop speeds up the development cycle a lot and alsoprovides direct access to full packet log files in cases something doesn’t work asexpected. The same code can then later be run unmodified on an embeddedtarget.

For macOS and Linux, please see libusb port. For Windows, please seewindows-winusb port.

Or checkout the listofexistingportsports/existing ports.md)

Page 13: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

12

3. BTstack Architecture

As well as any other communication stack, BTstack is a collection of statemachines that interact with each other. There is one or more state machines foreach protocol and service that it implements. The rest of the architecture followsthese fundamental design guidelines:

• Single threaded design - BTstack does not use or require multi-threadingto handle data sources and timers. Instead, it uses a single run loop.• No blocking anywhere - If Bluetooth processing is required, its result will

be delivered as an event via registered packet handlers.• No artificially limited buffers/pools - Incoming and outgoing data packets

are not queued.• Statically bounded memory (optionally) - The number of maximum con-

nections/channels/services can be configured.

Figure {@fig:BTstackArchitecture} shows the general architecture of a BTstack-based single-threaded application that includes the BTstack run loop. The MainApplication contains the application logic, e.g., reading a sensor value and pro-viding it via the Communication Logic as a SPP Server. The CommunicationLogic is often modeled as a finite state machine with events and data comingfrom either the Main Application or from BTstack via registered packet handlers(PH). BTstack’s Run Loop is responsible for providing timers and processing in-coming data.

Page 14: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

13

BTstack  

Main  Applica/on  

Communica/on  Logic   PH  

Run  Loop  Data  Source  

Data  Source  

Data  Source  

Timeouts  

Bluetooth  Single/Dual  Mode  Chipset  

add data source

data source ready

Bluetooth  Stack  

HCI  

L2CAP  

SDP   RFCOMM   ATT  

LE  

H4  UART   eHCILL  UART     USB  …

add timer timer ready

{#fig:BTstackArchitecture}

3.1. Single threaded design. BTstack does not use or require multi-threading.It uses a single run loop to handle data sources and timers. Data sources representcommunication interfaces like an UART or an USB driver. Timers are usedby BTstack to implement various Bluetooth-related timeouts. For example, todisconnect a Bluetooth baseband channel without an active L2CAP channel after20 seconds. They can also be used to handle periodic events. During a run loopcycle, the callback functions of all registered data sources are called. Then, thecallback functions of timers that are ready are executed.

For adapting BTstack to multi-threaded environments check here.

3.2. No blocking anywhere. Bluetooth logic is event-driven. Therefore, allBTstack functions are non-blocking, i.e., all functions that cannot return im-mediately implement an asynchronous pattern. If the arguments of a functionare valid, the necessary commands are sent to the Bluetooth chipset and thefunction returns with a success value. The actual result is delivered later as anasynchronous event via registered packet handlers.

If a Bluetooth event triggers longer processing by the application, the process-ing should be split into smaller chunks. The packet handler could then schedulea timer that manages the sequential execution of the chunks.

Page 15: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

14

3.3. No artificially limited buffers/pools. Incoming and outgoing data pack-ets are not queued. BTstack delivers an incoming data packet to the applicationbefore it receives the next one from the Bluetooth chipset. Therefore, it relieson the link layer of the Bluetooth chipset to slow down the remote sender whenneeded.

Similarly, the application has to adapt its packet generation to the remotereceiver for outgoing data. L2CAP relies on ACL flow control between sender andreceiver. If there are no free ACL buffers in the Bluetooth module, the applicationcannot send. For RFCOMM, the mandatory credit-based flow-control limits thedata sending rate additionally. The application can only send an RFCOMMpacket if it has RFCOMM credits.

3.4. Statically bounded memory. BTstack has to keep track of services andactive connections on the various protocol layers. The number of maximum con-nections/channels/services can be configured. In addition, the non-persistentdatabase for remote device names and link keys needs memory and can be beconfigured, too. These numbers determine the amount of static memory alloca-tion.

4. How to configure Btstack

BTstack implements a set of Bluetooth protocols and profiles. To connect toother Bluetooth devices or to provide a Bluetooth services, BTstack has to beproperly configured.

The configuration of BTstack is done both at compile time as well as at runtime:

• compile time configuration:– adjust btstack config.h - this file describes the system configuration,

used functionality, and also the memory configuration– add necessary source code files to your project

• run time configuration of:– Bluetooth chipset– run loop– HCI transport layer– provided services– packet handlers

In the following, we provide an overview of the configuration that is necessaryto setup BTstack. From the point when the run loop is executed, the applicationruns as a finite state machine, which processes events received from BTstack.BTstack groups events logically and provides them via packet handlers. Weprovide their overview here. For the case that there is a need to inspect thedata exchanged between BTstack and the Bluetooth chipset, we describe how toconfigure packet logging mechanism. Finally, we provide an overview on powermanagement in Bluetooth in general and how to save energy in BTstack.

4.1. Configuration in btstack config.h. The file btstack config.h containsthree parts:

Page 16: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

15

• #define HAVE * directives listed here. These directives describe availablesystem properties, similar to config.h in a autoconf setup.• #define ENABLE * directives listed here. These directives list enabled

properties, most importantly ENABLE CLASSIC and ENABLE BLE.• other #define directives for BTstack configuration, most notably static

memory, see next section and NVM configuration.

4.1.1. HAVE * directives. System properties:

#define Description

HAVE MALLOC Use dynamic memoryHAVE AES128 Use platform AES128 engine - not

needed usuallyHAVE BTSTACK STDIN STDIN is available for CLI interfaceHAVE MBEDTLS ECC P256 mbedTLS provides NIST P-256

operations e.g. for LE SecureConnections

Embedded platform properties:

#define Description

HAVE EMBEDDED TIME MS System provides time in millisecondsHAVE EMBEDDED TICK System provides tick interrupt

POSIX platform properties:

#define Description

HAVE POSIX B300 MAPPED TO 2000000Workaround to use serial port with 2mbps

HAVE POSIX B600 MAPPED TO 3000000Workaround to use serial port with 3mpbs

HAVE POSIX FILE IO POSIX File i/o used for hci dumpHAVE POSIX TIME System provides time functionLINK KEY PATH Path to stored link keysLE DEVICE DB PATH Path to stored LE device information

4.1.2. ENABLE * directives. BTstack properties:

#define Description

ENABLE CLASSIC Enable Classic related code in HCI andL2CAP

ENABLE BLE Enable BLE related code in HCI andL2CAP

ENABLE EHCILL Enable eHCILL low power mode on TICC256x/WL18xx chipsets

Page 17: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

16

#define Description

ENABLE LOG DEBUG Enable log debug messagesENABLE LOG ERROR Enable log error messagesENABLE LOG INFO Enable log info messagesENABLE SCO OVER HCI Enable SCO over HCI for chipsets (if

supported)ENABLE HFP WIDE BAND SPEECHEnable support for mSBC codec used in

HFP profile for Wide-Band SpeechENBALE LE PERIPHERAL Enable support for LE Peripheral Role in

HCI and Security ManagerENBALE LE CENTRAL Enable support for LE Central Role in

HCI and Security ManagerENABLE LE SECURE CONNECTIONSEnable LE Secure ConnectionsENABLE LE CENTRAL AUTO ENCRYPTIONEnable automatic encryption for bonded

devices on re-connectENABLE GATT CLIENT PAIRINGEnable GATT Client to start pairing and

retry operation on security errorENABLE MICRO ECC FOR LE SECURE CONNECTIONSUse micro-ecc library for ECC operationsENABLE LE DATA CHANNELSEnable LE Data Channels in credit-based

flow control modeENABLE LE DATA LENGTH EXTENSIONEnable LE Data Length Extension supportENABLE LE SIGNED WRITE Enable LE Signed Writes in ATT/GATTENABLE ATT DELAYED RESPONSEEnable support for delayed ATT

operations, see GATT ServerENABLE L2CAP ENHANCED RETRANSMISSION MODEEnable L2CAP Enhanced Retransmission

Mode. Mandatory for AVRCP BrowsingENABLE HCI CONTROLLER TO HOST FLOW CONTROLEnable HCI Controller to Host Flow

Control, see belowENABLE CC256X BAUDRATE CHANGE FLOWCONTROL BUG WORKAROUNDEnable workaround for bug in CC256x

Flow Control during baud rate change, seechipset docs.

Notes: - ENABLE MICRO ECC FOR LE SECURE CONNECTIONS: Onlysome Bluetooth 4.2+ controllers (e.g., EM9304, ESP32) support the necessaryHCI commands for ECC. Other reason to enable the ECC software implementa-tions are if the Host is much faster or if the micro-ecc library is already provided(e.g., ESP32, WICED, or if the ECC HCI Commands are unreliable.

4.1.3. HCI Controller to Host Flow Control. In general, BTstack relies on flowcontrol of the HCI transport, either via Hardware CTS/RTS flow control forUART or regular USB flow control. If this is not possible, e.g on an SoC, BTstackcan use HCI Controller to Host Flow Control by defining ENABLE HCI CONTROLLER TO HOST FLOW CONTROL.If enabled, the HCI Transport implementation must be able to buffer the spec-ified packets. In addition, it also need to be able to buffer a few HCI Events.Using a low number of host buffers might result in less throughput.

Host buffer configuration for HCI Controller to Host Flow Control:

Page 18: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

17

#define Description

HCI HOST ACL PACKET NUM Max number of ACL packetsHCI HOST ACL PACKET LEN Max size of HCI Host ACL packetsHCI HOST SCO PACKET NUM Max number of ACL packetsHCI HOST SCO PACKET LEN Max size of HCI Host SCO packets

4.1.4. Memory configuration directives. The structs for services, active connec-tions and remote devices can be allocated in two different manners:

• statically from an individual memory pool, whose maximal number ofelements is defined in the btstack config.h file. To initialize the staticpools, you need to call at runtime btstack memory init function. Anexample of memory configuration for a single SPP service with a minimalL2CAP MTU is shown in Listing {@lst:memoryConfigurationSPP}.• dynamically using the malloc/free functions, if HAVE MALLOC is de-

fined in btstack config.h file.

For each HCI connection, a buffer of size HCI ACL PAYLOAD SIZE is re-served. For fast data transfer, however, a large ACL buffer of 1021 bytes isrecommend. The large ACL buffer is required for 3-DH5 packets to be used.

#define Description

HCI ACL PAYLOAD SIZEMax size ofHCI ACLpayloads

MAX NR BNEP CHANNELSMax numberof BNEPchannels

MAX NR BNEP SERVICESMax numberof BNEPservices

MAX NR BTSTACK LINK KEY DB MEMORY ENTRIESMax numberof link keyentriescached inRAM

MAX NR GATT CLIENTSMax numberof GATTclients

MAX NR HCI CONNECTIONSMax numberof HCIconnections

MAX NR HFP CONNECTIONSMax numberof HFPconnections

Page 19: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

18

#define Description

MAX NR L2CAP CHANNELSMax numberof L2CAPconnections

MAX NR L2CAP SERVICESMax numberof L2CAPservices

MAX NR RFCOMM CHANNELSMax numberofRFOMMMconnections

MAX NR RFCOMM MULTIPLEXERSMax numberof RFCOMMmultiplexers,with onemultiplexerper HCIconnection

MAX NR RFCOMM SERVICESMax numberof RFCOMMservices

MAX NR SERVICE RECORD ITEMSMax numberof SDPservicerecords

MAX NR SM LOOKUP ENTRIESMax numberof items inSecurityManagerlookup queue

MAX NR WHITELIST ENTRIESMax numberof items inGAP LEWhitelist toconnect to

MAX NR LE DEVICE DB ENTRIESMax numberof items inLE DeviceDB

The memory is set up by calling btstack memory init function:

btstack memory in i t ( ) ;

Here’s the memory configuration for a basic SPP server.

Page 20: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

19

#define HCI ACL PAYLOAD SIZE 52#define MAX NR HCI CONNECTIONS 1#define MAX NR L2CAP SERVICES 2#define MAX NR L2CAP CHANNELS 2#define MAX NR RFCOMM MULTIPLEXERS 1#define MAX NR RFCOMM SERVICES 1#define MAX NR RFCOMM CHANNELS 1#define MAX NR BTSTACK LINK KEY DB MEMORY ENTRIES 3

Listing: Memory configuration for a basic SPP server. {#lst:memoryConfigurationSPP}In this example, the size of ACL packets is limited to the minimum of 52 bytes,

resulting in an L2CAP MTU of 48 bytes. Only a singleHCI connection can beestablished at any time. On it, two L2CAP services are provided, which can beactive at the same time. Here, these two can be RFCOMM and SDP. Then,memory for one RFCOMM multiplexer is reserved over which one connectioncan be active. Finally, up to three link keys can be cached in RAM.

4.1.5. Non-volatile memory (NVM) directives. If implemented, bonding infor-mation is stored in Non-volatile memory. For Classic, a single link keys and itstype is stored. For LE, the bonding information contains various values (longterm key, random number, EDIV, signing counter, identity, . . . )Often, this im-plemented using Flash memory. Then, the number of stored entries are limitedby:

#define Description

NVM NUM LINK KEYS Max numberof ClassicLink Keysthat can bestored

NVM NUM DEVICE DB ENTRIESMax numberof LE DeviceDB entriesthat can bestored

NVN NUM GATT SERVER CCCMax numberof ‘ClientCharacteris-ticConfigura-tion’ valuesthat can bestored byGATT Server

Page 21: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

20

4.2. Source tree structure. The source tree has been organized to easily setupnew projects.

Path Description

chipset Support for individual Bluetooth chipsetsdoc Sources for BTstack documentationexample Example applications available for all portsplatform Support for special OSs and/or MCU architecturesport Complete port for a MCU + Chipset combinationssrc Bluetooth stack implementationtest Unit and PTS teststool Helper tools for BTstack

The core of BTstack, including all protocol and profiles, is in src/.Support for a particular platform is provided by the platform/ subfolder. For

most embedded ports, platform/embedded/ provides btstack run loop embeddedand the hci transport h4 embedded implementation that require hal cpu.h, hal led.h,and hal uart dma.h plus hal tick.h or hal time ms to be implemented by the user.

To accommodate a particular Bluetooth chipset, the chipset/ subfolders pro-vide various btstack chipset * implementations. Please have a look at the exist-ing ports in port/.

4.3. Run loop configuration. To initialize BTstack you need to initialize thememory and the run loop respectively, then setup HCI and all needed higherlevel protocols.

BTstack uses the concept of a run loop to handle incoming data and to schedulework. The run loop handles events from two different types of sources: datasources and timers. Data sources represent communication interfaces like anUART or an USB driver. Timers are used by BTstack to implement variousBluetooth-related timeouts. They can also be used to handle periodic events.

Data sources and timers are represented by the btstack data source t and bt-stack timer source t structs respectively. Each of these structs contain at leasta linked list node and a pointer to a callback function. All active timers anddata sources are kept in link lists. While the list of data sources is unsorted, thetimers are sorted by expiration timeout for efficient processing.

Timers are single shot: a timer will be removed from the timer list beforeits event handler callback is executed. If you need a periodic timer, you canre-register the same timer source in the callback function, as shown in Listing[PeriodicTimerHandler]. Note that BTstack expects to get called periodicallyto keep its time, see Section on time abstraction for more on the tick hardwareabstraction.

BTstack provides different run loop implementations that implement the bt-stack run loop t interface:

• Embedded: the main implementation for embedded systems, especiallywithout an RTOS.• POSIX: implementation for POSIX systems based on the select() call.• CoreFoundation: implementation for iOS and OS X applications

Page 22: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

21

• WICED: implementation for the Broadcom WICED SDK RTOS abstrac-tion that wraps FreeRTOS or ThreadX.• Windows: implementation for Windows based on Event objects and

WaitForMultipleObjects() call.

Depending on the platform, data sources are either polled (embedded), or theplatform provides a way to wait for a data source to become ready for read orwrite (POSIX, CoreFoundation, Windows), or, are not used as the HCI transportdriver and the run loop is implemented in a different way (WICED). In any case,the callbacks must be to explicitly enabled with the btstack run loop enable data source callbacks(..)function.

In your code, you’ll have to configure the run loop before you start it as shownin Listing [listing:btstackInit]. The application can register data sources as wellas timers, e.g., for periodical sampling of sensors, or for communication over theUART.

The run loop is set up by calling btstack run loop init function and providingan instance of the actual run loop. E.g. for the embedded platform, it is:

b t s t a c k r u n l o o p i n i t ( b t s tack run loop embedded ge t in s tance ( ) ) ;

The complete Run loop API is provided here.

4.3.1. Run loop embedded. In the embedded run loop implementation, data sourcesare constantly polled and the system is put to sleep if no IRQ happens duringthe poll of all data sources.

The complete run loop cycle looks like this: first, the callback function ofall registered data sources are called in a round robin way. Then, the callbackfunctions of timers that are ready are executed. Finally, it will be checked ifanother run loop iteration has been requested by an interrupt handler. If not,the run loop will put the MCU into sleep mode.

Incoming data over the UART, USB, or timer ticks will generate an interruptand wake up the microcontroller. In order to avoid the situation where a datasource becomes ready just before the run loop enters sleep mode, an interrupt-driven data source has to call the btstack run loop embedded trigger function.The call to btstack run loop embedded trigger sets an internal flag that is checkedin the critical section just before entering sleep mode causing another run loopcycle.

To enable the use of timers, make sure that you defined HAVE EMBEDDED TICKor HAVE EMBEDDED TIME MS in the config file.

4.3.2. Run loop POSIX. The data sources are standard File Descriptors. In therun loop execute implementation, select() call is used to wait for file descriptorsto become ready to read or write, while waiting for the next timeout.

To enable the use of timers, make sure that you defined HAVE POSIX TIMEin the config file.

4.3.3. Run loop CoreFoundation (OS X/iOS). This run loop directly maps BT-stack’s data source and timer source with CoreFoundation objects. It supports

Page 23: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

22

ready to read and write similar to the POSIX implementation. The call to bt-stack run loop execute() then just calls CFRunLoopRun().

To enable the use of timers, make sure that you defined HAVE POSIX TIMEin the config file.

4.3.4. Run loop Windows. The data sources are Event objects. In the run loopimplementation WaitForMultipleObjects() call is all is used to wait for the Eventobject to become ready while waiting for the next timeout.

4.3.5. Run loop WICED. WICED SDK API does not provide asynchronous readand write to the UART and no direct way to wait for one or more peripheralsto become ready. Therefore, BTstack does not provide direct support for datasources. Instead, the run loop provides a message queue that allows to schedulefunctions calls on its thread via btstack run loop wiced execute code on main thread().

The HCI transport H4 implementation then uses two lightweight threads todo the blocking read and write operations. When a read or write is complete onthe helper threads, a callback to BTstack is scheduled.

4.4. HCI Transport configuration. The HCI initialization has to adapt BT-stack to the used platform. The first call is to hci init() and requires informationabout the HCI Transport to use. The arguments are:

• HCI Transport implementation: On embedded systems, a Bluetooth mod-ule can be connected via USB or an UART port. On embedded, BTstackimplements HCI UART Transport Layer (H4) and H4 with eHCILL sup-port, a lightweight low-power variant by Texas Instruments. For POSIX,there is an implementation for HCI H4, HCI H5 and H2 libUSB, and forWICED HCI H4 WICED. These are accessed by linking the appropriatefile, e.g., platform/embedded/hci\_transport\_h4\_embedded.c andthen getting a pointer to HCI Transport implementation. For more in-formation on adapting HCI Transport to different environments, see here.

hci transport t ∗ t r anspor t = h c i t r a n s p o r t h 4 i n s t a n c e ( ) ;

• HCI Transport configuration: As the configuration of the UART used inthe H4 transport interface are not standardized, it has to be provided bythe main application to BTstack. In addition to the initial UART baudrate, the main baud rate can be specified. The HCI layer of BTstack willchange the init baud rate to the main one after the basic setup of theBluetooth module. A baud rate change has to be done in a coordinatedway at both HCI and hardware level. For example, on the CC256x, theHCI command to change the baud rate is sent first, then it is necessaryto wait for the confirmation event from the Bluetooth module. Only now,can the UART baud rate changed.

hci uart config t ∗ c o n f i g = &h c i u a r t c o n f i g ;

Page 24: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

23

After these are ready, HCI is initialized like this:

h c i i n i t ( t ransport , c o n f i g ) ;

In addition to these, most UART-based Bluetooth chipset require some speciallogic for correct initialization that is not covered by the Bluetooth specification.In particular, this covers:

• setting the baudrate• setting the BD ADDR for devices without an internal persistent storage• upload of some firmware patches.

This is provided by the various btstack chipset t implementation in the chipset/subfolders. As an example, the bstack chipset cc256x instance function returnsa pointer to a chipset struct suitable for the CC256x chipset.

b t s t a c k c h i p s e t t ∗ c h i p s e t = b t s t a c k c h i p s e t c c 2 5 6 x i n s t a n c e ( ) ;h c i s e t c h i p s e t ( c h i p s e t ) ;

In some setups, the hardware setup provides explicit control of Bluetoothpower and sleep modes. In this case, a btstack control t struct can be set withhci set control.

Finally, the HCI implementation requires some form of persistent storage forlink keys generated during either legacy pairing or the Secure Simple Pairing(SSP). This commonly requires platform specific code to access the MCU’s EEP-ROM of Flash storage. For the first steps, BTstack provides a (non) persistentstore in memory. For more see here.

btstack link key db t ∗ l i nk key db = &bts tack l ink key db memory ins tance ( ) ;

b t s t a c k s e t l i n k k e y d b ( l i nk key db ) ;

The higher layers only rely on BTstack and are initialized by calling the re-spective ** init* function. These init functions register themselves with theunderlying layer. In addition, the application can register packet handlers to getevents and data as explained in the following section.

4.5. Services. One important construct of BTstack is service. A service rep-resents a server side component that handles incoming connections. So far,BTstack provides L2CAP, BNEP, and RFCOMM services. An L2CAP servicehandles incoming connections for an L2CAP channel and is registered with itsprotocol service multiplexer ID (PSM). Similarly, an RFCOMM service handlesincoming RFCOMM connections and is registered with the RFCOMM channelID. Outgoing connections require no special registration, they are created by theapplication when needed.

Page 25: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

24

4.6. Packet handlers configuration. After the hardware and BTstack areset up, the run loop is entered. From now on everything is event driven. Theapplication calls BTstack functions, which in turn may send commands to theBluetooth module. The resulting events are delivered back to the application.Instead of writing a single callback handler for each possible event (as it is donein some other Bluetooth stacks), BTstack groups events logically and providesthem over a single generic interface. Appendix Events and Errors summarizesthe parameters and event codes of L2CAP and RFCOMM events, as well aspossible errors and the corresponding error codes.

Here is summarized list of packet handlers that an application might use:

• HCI event handler - allows to observer HCI, GAP, and general BTstackevents.• L2CAP packet handler - handles LE Connection parameter requeset up-

dates• L2CAP service packet handler - handles incoming L2CAP connections,

i.e., channels initiated by the remote.• L2CAP channel packet handler - handles outgoing L2CAP connections,

i.e., channels initiated internally.• RFCOMM service packet handler - handles incoming RFCOMM connec-

tions, i.e., channels initiated by the remote.• RFCOMM channel packet handler - handles outgoing RFCOMM connec-

tions, i.e., channels initiated internally.

These handlers are registered with the functions listed in Table 1.

Table 1: Functions for registering packet handlers.

Packet Handler Registering Function

HCI packet handler hci add event handlerL2CAP packet handler l2cap register packet handlerL2CAP service packet handler l2cap register serviceL2CAP channel packet handler l2cap create channelRFCOMM service packet handler rfcomm register service and rf-

comm register service with initial creditsRFCOMM channel packethandler

rfcomm create channel and rf-comm create channel with initial credits

HCI, GAP, and general BTstack events are delivered to the packet handlerspecified by hci add event handler function. In L2CAP, BTstack discriminatesincoming and outgoing connections, i.e., event and data packets are delivered todifferent packet handlers. Outgoing connections are used access remote services,incoming connections are used to provide services. For incoming connections,the packet handler specified by l2cap register service is used. For outgoing con-nections, the handler provided by l2cap create channel is used. RFCOMM andBNEP are similar.

The application can register a single shared packet handler for all protocolsand services, or use separate packet handlers for each protocol layer and service.

Page 26: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

25

A shared packet handler is often used for stack initialization and connectionmanagement.

Separate packet handlers can be used for each L2CAP service and outgoingconnection. For example, to connect with a Bluetooth HID keyboard, yourapplication could use three packet handlers: one to handle HCI events duringdiscovery of a keyboard registered by l2cap register packet handler ; one that willbe registered to an outgoing L2CAP channel to connect to keyboard and toreceive keyboard data registered by l2cap create channel ; after that keyboardcan reconnect by itself. For this, you need to register L2CAP services for theHID Control and HID Interrupt PSMs using l2cap register service. In this call,you’ll also specify a packet handler to accept and receive keyboard data.

All events names have the form MODULE EVENT NAME now, e.g., gap event -advertising report. To facilitate working with events and get rid of manuallycalculating offsets into packets, BTstack provides auto-generated getters for allfields of all events in src/hci event.h. All functions are defined as static inline,so they are not wasting any program memory if not used. If used, the mem-ory footprint should be identical to accessing the field directly via offsets intothe packet. For example, to access fields address type and address from thegap event advertising report event use following getters:

uint8 t address type = g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s t y p e( event ) ;

bd addr t address ;g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s ( event , address ) ;

4.7. Bluetooth HCI Packet Logs. If things don’t work as expected, havinga look at the data exchanged between BTstack and the Bluetooth chipset oftenhelps.

For this, BTstack provides a configurable packet logging mechanism via hci dump.h:

// formats : HCI DUMP BLUEZ, HCI DUMP PACKETLOGGER, HCI DUMP STDOUTvoid hci dump open ( const char ∗ f i l ename , hc i dump format t format ) ;

On POSIX systems, you can call hci dump open with a path and HCI DUMP BLUEZor HCI DUMP PACKETLOGGER in the setup, i.e., before entering the runloop. The resulting file can be analyzed with Wireshark or the Apple’s Packet-Logger tool.

On embedded systems without a file system, you still can call hci dump open(NULL,HCI DUMP STDOUT). It will log all HCI packets to the console via printf. Ifyou capture the console output, incl. your own debug messages, you can usethe create packet log.py tool in the tools folder to convert a text output into aPacketLogger file.

In addition to the HCI packets, you can also enable BTstack’s debug informa-tion by adding

Page 27: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

26

#define ENABLE LOG INFO#define ENABLE LOG ERROR

to the btstack config.h and recompiling your application.

4.8. Bluetooth Power Control. In most BTstack examples, the device is setto be discoverable and connectable. In this mode, even when there’s no activeconnection, the Bluetooth Controller will periodically activate its receiver inorder to listen for inquiries or connecting requests from another device. Theability to be discoverable requires more energy than the ability to be connected.Being discoverable also announces the device to anybody in the area. Therefore,it is a good idea to pause listening for inquiries when not needed. Other devicesthat have your Bluetooth address can still connect to your device.

To enable/disable discoverability, you can call:

/∗∗∗ @br ie f Al lows to con t r o l i f d ev i c e i s d i s c o v e r a b l e . OFF by

d e f a u l t .∗/

void g a p d i s c o v e r a b l e c o n t r o l ( uint8 t enable ) ;

If you don’t need to become connected from other devices for a longer periodof time, you can also disable the listening to connection requests.

To enable/disable connectability, you can call:

/∗∗∗ @br ie f Override page scan mode . Page scan mode enab led by l2cap

when s e r v i c e s are r e g i s t e r e d∗ @note Might be used to reduce power consumption wh i l e B lue too th

module s t a y s powered but no (new)∗ connec t ions are expec ted∗/

void g a p c o n n e c t a b l e c o n t r o l ( uint8 t enable ) ;

For Bluetooth Low Energy, the radio is periodically used to broadcast adver-tisements that are used for both discovery and connection establishment.

To enable/disable advertisements, you can call:

/∗∗∗ @br ie f Enable /Di sab l e Advert i sements . OFF by d e f a u l t .∗ @param enab led∗/

void gap adver t i s ement s enab l e ( int enabled ) ;

If a Bluetooth Controller is neither discoverable nor connectable, it does notneed to periodically turn on its radio and it only needs to respond to commands

Page 28: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

27

from the Host. In this case, the Bluetooth Controller is free to enter some kindof deep sleep where the power consumption is minimal.

Finally, if that’s not sufficient for your application, you could request BTstackto shutdown the Bluetooth Controller. For this, the “on” and “off” functions inthe btstack control t struct must be implemented. To shutdown the BluetoothController, you can call:

/∗∗∗ @br ie f Requests the change o f BTstack power mode .∗/

int h c i p o w e r c o n t r o l (HCI POWER MODE mode) ;

with mode set to HCI POWER OFF. When needed later, Bluetooth can bestarted again via by calling it with mode HCI POWER ON, as seen in all exam-ples.

5. Protocols

BTstack is a modular dual-mode Bluetooth stack, supporting both BluetoothBasic Rate/Enhanced Date Rate (BR/EDR) as well as Bluetooth Low Energy(LE). The BR/EDR technology, also known as Classic Bluetooth, provides arobust wireless connection between devices designed for high data rates. Incontrast, the LE technology has a lower throughput but also lower energy con-sumption, faster connection setup, and the ability to connect to more devices inparallel.

Whether Classic or LE, a Bluetooth device implements one or more Bluetoothprofiles. A Bluetooth profile specifies how one or more Bluetooth protocols areused to achieve its goals. For example, every Bluetooth device must implementthe Generic Access Profile (GAP), which defines how devices find each otherand how they establish a connection. This profile mainly make use of the HostController Interface (HCI) protocol, the lowest protocol in the stack hierarchywhich implements a command interface to the Bluetooth chipset.

In addition to GAP, a popular Classic Bluetooth example would be a peripheraldevices that can be connected via the Serial Port Profile (SPP). SPP basicallyspecifies that a compatible device should provide a Service Discovery Protocol(SDP) record containing an RFCOMM channel number, which will be used forthe actual communication.

Similarly, for every LE device, the Generic Attribute Profile (GATT) profilemust be implemented in addition to GAP. GATT is built on top of the AttributeProtocol (ATT), and defines how one device can interact with GATT Serviceson a remote device.

So far, the most popular use of BTstack is in peripheral devices that can beconnected via SPP (Android 2.0 or higher) and GATT (Android 4.3 or higher,and iOS 5 or higher). If higher data rates are required between a peripheral andiOS device, the iAP1 and iAP2 protocols of the Made for iPhone program canbe used instead of GATT. Please contact us directly for information on BTstackand MFi.

Page 29: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

28

Figure {@fig:BTstackProtocolArchitecture} depicts Bluetooth protocols andprofiles that are currently implemented by BTstack. In the following, we firstexplain how the various Bluetooth protocols are used in BTstack. In the nextchapter, we go over the profiles.

Profiles

Protocols

GAP PAN SDAP MFi HFP HSP SPP GATT

SMP ATT SDP BNEP RFCOMM

L2CAP L2CAP LE

HCI

Transport … H4 UART eHCILL UART H2 USB

Bluetooth Single/Dual Mode Chipset {#fig:BTstackProtocolArchitecture}

5.1. HCI - Host Controller Interface. The HCI protocol provides a com-mand interface to the Bluetooth chipset. In BTstack, the HCI implementationalso keeps track of all active connections and handles the fragmentation andre-assembly of higher layer (L2CAP) packets.

Please note, that an application rarely has to send HCI commands on its own.Instead, BTstack provides convenience functions in GAP and higher level proto-cols that use HCI automatically. E.g. to set the name, you call gap set local name()before powering up. The main use of HCI commands in application is during thestartup phase to configure special features that are not available via the GAPAPI yet. How to send a custom HCI command is explained in the followingsection.

5.1.1. Defining custom HCI command templates. Each HCI command is assigneda 2-byte OpCode used to uniquely identify different types of commands. TheOpCode parameter is divided into two fields, called the OpCode Group Field(OGF) and OpCode Command Field (OCF), see Bluetooth Specification - CoreVersion 4.0, Volume 2, Part E, Chapter 5.4.

Listing below shows the OGFs provided by BTstack in file src/hci.h:

#d e f i n e OGF LINK CONTROL 0x01#d e f i n e OGF LINK POLICY 0x02#d e f i n e OGF CONTROLLER BASEBAND 0x03#d e f i n e OGF INFORMATIONAL PARAMETERS 0x04#d e f i n e OGF LE CONTROLLER 0x08#d e f i n e OGF BTSTACK 0x3d#d e f i n e OGF VENDOR 0 x3f

Page 30: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

29

Listing 1. HCI OGFs provided by BTstack.

For all existing Bluetooth commands and their OCFs see Bluetooth Specifica-tion - Core Version 4.0, Volume 2, Part E, Chapter 7.

In a HCI command packet, the OpCode is followed by parameter total length,and the actual parameters. The OpCode of a command can be calculated usingthe OPCODE macro. BTstack provides the hci cmd t struct as a compact formatto define HCI command packets, see Listing below, and include/btstack/hci\

_cmd.h file in the source code.

// Ca l cu l a t e combined og f / oc f va lue .#d e f i n e OPCODE( ogf , o c f ) ( o c f | og f << 10)

// Compact HCI Command packe t d e s c r i p t i o n .typedef struct {

u i n t 1 6 t opcode ;const char ∗ format ;

} hc i cmd t ;

Listing 2. HCI command struct.

Listing below illustrates the hci write local name HCI command template fromlibrary:

// Se t s l o c a l B lue too th nameconst hc i cmd t h c i w r i t e l o c a l n a m e = {

OPCODE(OGF CONTROLLER BASEBAND, 0x13 ) , ”N”// Local name (UTF−8, Nu l l Terminated , max 248 o c t e t s )

} ;

Listing 3. HCI command example.

It uses OGF CONTROLLER BASEBAND as OGF, 0x13 as OCF, and has oneparameter with format “N” indicating a null terminated UTF-8 string. Table2 lists the format specifiers supported by BTstack. Check for other predefinedHCI commands and info on their parameters.

Table 2: Supported Format Specifiers of HCI CommandParameter.

Format Specifier Description1,2,3,4 one to four byte value

A 31 bytes advertising dataB Bluetooth Baseband AddressD 8 byte data blockE Extended Inquiry Information 240 octets

Page 31: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

30

H HCI connection handleN Name up to 248 chars, UTF8 string, null terminatedP 16 byte Pairing code, e.g. PIN code or link keyS Service Record (Data Element Sequence)

5.1.2. Sending HCI command based on a template. You can use the hci send cmdfunction to send HCI command based on a template and a list of parameters.However, it is necessary to check that the outgoing packet buffer is empty andthat the Bluetooth module is ready to receive the next command - most modernBluetooth modules only allow to send a single HCI command. This can be doneby calling hci can send command packet now() function, which returns true, ifit is ok to send.

Listing below illustrates how to manually set the device name with the HCIWrite Local Name command.

i f ( hc i can send packet now (HCI COMMAND DATA PACKET) ) {hci send cmd(& h c i w r i t e l o c a l n a m e , ”BTstack Demo” ) ;

}

Listing 4. Sending HCI command example.

Please note, that an application rarely has to send HCI commands on itsown. Instead, BTstack provides convenience functions in GAP and higher levelprotocols that use HCI automatically.

5.2. L2CAP - Logical Link Control and Adaptation Protocol. The L2CAPprotocol supports higher level protocol multiplexing and packet fragmentation.It provides the base for the RFCOMM and BNEP protocols. For all profiles thatare officially supported by BTstack, L2CAP does not need to be used directly.For testing or the development of custom protocols, it’s helpful to be able toaccess and provide L2CAP services however.

5.2.1. Access an L2CAP service on a remote device. L2CAP is based aroundthe concept of channels. A channel is a logical connection on top of a basebandconnection. Each channel is bound to a single protocol in a many-to-one fashion.Multiple channels can be bound to the same protocol, but a channel cannot bebound to multiple protocols. Multiple channels can share the same basebandconnection.

To communicate with an L2CAP service on a remote device, the application ona local Bluetooth device initiates the L2CAP layer using the l2cap init function,and then creates an outgoing L2CAP channel to the PSM of a remote deviceusing the l2cap create channel function. The l2cap create channel function willinitiate a new baseband connection if it does not already exist. The packet han-dler that is given as an input parameter of the L2CAP create channel functionwill be assigned to the new outgoing L2CAP channel. This handler receives theL2CAP EVENT CHANNEL OPENED and L2CAP EVENT CHANNEL CLOSEDevents and L2CAP data packets, as shown in Listing below.

Page 32: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

31

b t s t a c k p a c k e t h a n d l e r t l 2 cap packe t hand l e r ;

void l 2 cap packe t hand l e r ( u i n t 8 t packet type , u i n t 1 6 t channel ,u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {bd addr t event addr ;switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case L2CAP EVENT CHANNEL OPENED:l 2 c ap e ve n t c ha nn e l o pe ne d g e t ad dr e s s (

packet , &event addr ) ;psm =

l2cap event channe l opened get psm (packet ) ;

l o c a l c i d =l 2 c a p e v e n t c h a n n e l o p e n e d g e t l o c a l c i d( packet ) ;

handle =l2cap event channe l opened ge t hand l e (packet ) ;

i f ( l 2 c a p e v e n t c h a n n e l o p e n e d g e t s t a t u s (packet ) ) {p r i n t f ( ” Connection f a i l e d \n\ r ” ) ;

} elsep r i n t f ( ”Connected\n\ r ” ) ;

}break ;

case L2CAP EVENT CHANNEL CLOSED:break ;. . .

}case L2CAP DATA PACKET:

// handle L2CAP data packe tbreak ;

. . .}

}

void c r e a t e o u t g o i n g l 2 c a p c h a n n e l ( bd addr t address , u i n t 1 6 tpsm , u i n t 1 6 t mtu) {

l 2 c a p c r e a t e c h a n n e l (NULL, l2cap packe t hand l e r ,remote bd addr , psm , mtu) ;

}

void bt s ta ck s e tup ( ) {. . .l 2 c a p i n i t ( ) ;

}

Listing 5. Accessing an L2CAP service on a remote device.

Page 33: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

32

5.2.2. Provide an L2CAP service. To provide an L2CAP service, the applicationon a local Bluetooth device must init the L2CAP layer and register the servicewith l2cap register service. From there on, it can wait for incoming L2CAP con-nections. The application can accept or deny an incoming connection by callingthe l2cap accept connection and l2cap deny connection functions respectively.

If a connection is accepted and the incoming L2CAP channel gets successfullyopened, the L2CAP service can send and receive L2CAP data packets to theconnected device with l2cap send.

Listing below provides L2CAP service example code.

void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 t channel ,u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {bd addr t event addr ;switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case L2CAP EVENT INCOMING CONNECTION:l o c a l c i d =

l 2 c a p e v e n t i n c o m i n g c o n n e c t i o n g e t l o c a l c i d( packet ) ;

l 2 c a p a c c e p t c o n n e c t i o n ( l o c a l c i d ) ;break ;

case L2CAP EVENT CHANNEL OPENED:l 2 c ap e ve n t c ha nn e l o pe ne d g e t ad dr e s s (

packet , &event addr ) ;psm =

l2cap event channe l opened get psm (packet ) ;

l o c a l c i d =l 2 c a p e v e n t c h a n n e l o p e n e d g e t l o c a l c i d( packet ) ;

handle =l2cap event channe l opened ge t hand l e (packet ) ;

i f ( l 2 c a p e v e n t c h a n n e l o p e n e d g e t s t a t u s (packet ) ) {p r i n t f ( ” Connection f a i l e d \n\ r ” ) ;

} elsep r i n t f ( ”Connected\n\ r ” ) ;

}break ;

case L2CAP EVENT CHANNEL CLOSED:break ;. . .

}case L2CAP DATA PACKET:

// handle L2CAP data packe tbreak ;

. . .}

}

Page 34: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

33

void bt s ta ck s e tup ( ) {. . .l 2 c a p i n i t ( ) ;l 2 c a p r e g i s t e r s e r v i c e (NULL, packet handler , 0x11 , 1 0 0 ) ;

}

Listing 6. Providing an L2CAP service.

5.2.3. Sending L2CAP Data. Sending of L2CAP data packets may fail due toa full internal BTstack outgoing packet buffer, or if the ACL buffers in theBluetooth module become full, i.e., if the application is sending faster than thepackets can be transferred over the air.

Instead of directly calling l2cap send, it is recommended to call l2cap request can send now event(cahnnel id)which will trigger an L2CAP EVENT CAN SEND NOW as soon as possible. Itmight happen that the event is received via packet handler before the l2cap request can send now eventfunction returns. The L2CAP EVENT CAN SEND NOW indicates a channelID on which sending is possible.

Please note that the guarantee that a packet can be sent is only valid whenthe event is received. After returning from the packet handler, BTstack mightneed to send itself.

5.2.4. LE Data Channels. The full title for LE Data Channels is actually LEConnection-Oriented Channels with LE Credit-Based Flow-Control Mode. Inthis mode, data is sent as Service Data Units (SDUs) that can be larger than anindividual HCI LE ACL packet.

LE Data Channels are similar to Classic L2CAP Channels but also provide acredit-based flow control similar to RFCOMM Channels. Unless the LE DataPacket Extension of Bluetooth Core 4.2 specification is used, the maximumpacket size for LE ACL packets is 27 bytes. In order to send larger packets,each packet will be split into multiple ACL LE packets and recombined on thereceiving side.

Since multiple SDUs can be transmitted at the same time and the individualACL LE packets can be sent interleaved, BTstack requires a dedicated receivebuffer per channel that has to be passed when creating the channel or acceptingit. Similarly, when sending SDUs, the data provided to the l2cap le send datamust stay valid until the L2CAP EVENT LE PACKET SENT is received.

When creating an outgoing connection of accepting an incoming, the ini-tial credits allows to provide a fixed number of credits to the remote side. Furthercredits can be provided anytime with l2cap le provide credits. If L2CAP LE AUTOMATIC CREDITSis used, BTstack automatically provides credits as needed - effectively trading inthe flow-control functionality for convenience.

The remainder of the API is similar to the one of L2CAP:

• l2cap le register service and l2cap le unregister service are used to man-age local services.• l2cap le accept connection and l2cap le decline connection are used to ac-

cept or deny an incoming connection request.• l2cap le create channel creates an outgoing connections.

Page 35: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

34

• l2cap le can send now checks if a packet can be scheduled for transmis-sion now.• l2cap le request can send now event requests an L2CAP EVENT LE CAN SEND NOW

event as soon as possible.• l2cap le disconnect closes the connection.

5.3. RFCOMM - Radio Frequency Communication Protocol. The Ra-dio frequency communication (RFCOMM) protocol provides emulation of serialports over the L2CAP protocol and reassembly. It is the base for the SerialPort Profile and other profiles used for telecommunication like Head-Set Profile,Hands-Free Profile, Object Exchange (OBEX) etc.

5.3.1. No RFCOMM packet boundaries. As RFCOMM emulates a serial port, itdoes not preserve packet boundaries.

On most operating systems, RFCOMM/SPP will be modeled as a pipe thatallows to write a block of bytes. The OS and the Bluetooth Stack are free tobuffer and chunk this data in any way it seems fit. In your BTstack application,you will therefore receive this data in the same order, but there are no guaranteesas how it might be fragmented into multiple chunks.

If you need to preserve the concept of sending a packet with a specific sizeover RFCOMM, the simplest way is to prefix the data with a 2 or 4 byte lengthfield and then reconstruct the packet on the receiving side.

Please note, that due to BTstack’s ‘no buffers’ policy, BTstack will send outgo-ing RFCOMM data immediately and implicitly preserve the packet boundaries,i.e., it will send the data as a single RFCOMM packet in a single L2CAP packet,which will arrive in one piece. While this will hold between two BTstack in-stances, it’s not a good idea to rely on implementation details and rather prefixthe data as described.

5.3.2. RFCOMM flow control. RFCOMM has a mandatory credit-based flow-control. This means that two devices that established RFCOMM connection,use credits to keep track of how many more RFCOMM data packets can besent to each. If a device has no (outgoing) credits left, it cannot send anotherRFCOMM packet, the transmission must be paused. During the connectionestablishment, initial credits are provided. BTstack tracks the number of creditsin both directions. If no outgoing credits are available, the RFCOMM sendfunction will return an error, and you can try later. For incoming data, BTstackprovides channels and services with and without automatic credit managementvia different functions to create/register them respectively. If the management ofcredits is automatic, the new credits are provided when needed relying on ACLflow control - this is only useful if there is not much data transmitted and/oronly one physical connection is used. If the management of credits is manual,credits are provided by the application such that it can manage its receive buffersexplicitly.

5.3.3. Access an RFCOMM service on a remote device. To communicate with anRFCOMM service on a remote device, the application on a local Bluetooth deviceinitiates the RFCOMM layer using the rfcomm init function, and then createsan outgoing RFCOMM channel to a given server channel on a remote device

Page 36: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

35

using the rfcomm create channel function. The rfcomm create channel functionwill initiate a new L2CAP connection for the RFCOMM multiplexer, if it doesnot already exist. The channel will automatically provide enough credits to theremote side. To provide credits manually, you have to create the RFCOMMconnection by calling rfcomm create channel with initial credits - see Section onmanual credit assignement.

The packet handler that is given as an input parameter of the RFCOMM createchannel function will be assigned to the new outgoing channel. This handler re-ceives the RFCOMM EVENT CHANNEL OPENED and RFCOMM EVENT CHANNEL CLOSEDevents, and RFCOMM data packets, as shown in Listing below.

void r fcomm packet handler ( u i n t 8 t packet type , u i n t 1 6 t channel, u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case RFCOMM EVENT CHANNEL OPENED:i f (

r f comm event open channe l comple t e ge t s ta tus( packet ) ) {p r i n t f ( ” Connection f a i l e d \n\ r ” ) ;

} else {p r i n t f ( ”Connected\n\ r ” ) ;

}break ;

case RFCOMM EVENT CHANNEL CLOSED:break ;

. . .}break ;

case RFCOMM DATA PACKET:// handle RFCOMM data packe t sreturn ;

}}

void create r fcomm channe l ( u i n t 8 t packet type , u i n t 8 t ∗packet ,u i n t 1 6 t s i z e ) {r f comm create channe l ( r fcomm packet handler , addr ,

rfcomm channel ) ;}

void bt s ta ck s e tup ( ) {. . .l 2 c a p i n i t ( ) ;r f comm init ( ) ;

}

Listing 7. RFCOMM handler for outgoing RFCOMM channel.

Page 37: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

36

5.3.4. Provide an RFCOMM service. To provide an RFCOMM service, the ap-plication on a local Bluetooth device must first init the L2CAP and RFCOMMlayers and then register the service with rfcomm register service. From there on,it can wait for incoming RFCOMM connections. The application can acceptor deny an incoming connection by calling the rfcomm accept connection and rf-comm deny connection functions respectively. If a connection is accepted and theincoming RFCOMM channel gets successfully opened, the RFCOMM service cansend RFCOMM data packets to the connected device with rfcomm send and re-ceive data packets by the packet handler provided by the rfcomm register servicecall.

Listing below provides the RFCOMM service example code.

void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 t channel ,u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case RFCOMM EVENT INCOMING CONNECTION:rfcomm channel id =

r fcomm event incoming connect ion get r f comm cid( packet ) ;

r fcomm accept connect ion ( r fcomm channel id ) ;break ;

case RFCOMM EVENT CHANNEL OPENED:i f (

r f comm event open channe l comple t e ge t s ta tus( packet ) ) {p r i n t f ( ”RFCOMM channel open f a i l e d . ” ) ;break ;

}r fcomm channel id =

rfcomm event open channe l complete get r fcomm cid( packet ) ;

mtu =r fcomm event open channe l comple te get max f rame s i ze( packet ) ;

p r i n t f ( ”RFCOMM channel open succeeded , maxframe s i z e %u . ” , mtu) ;

break ;case RFCOMM EVENT CHANNEL CLOSED:

p r i n t f ( ”Channel c l o s e d . ” ) ;break ;

. . .}break ;

case RFCOMM DATA PACKET:// handle RFCOMM data packe t sreturn ;

. . .}

Page 38: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

37

. . .}

void bt s ta ck s e tup ( ) {. . .l 2 c a p i n i t ( ) ;r f comm init ( ) ;r f c o m m r e g i s t e r s e r v i c e ( packet handler , rfcomm channel nr ,

mtu) ;}

Listing 8. Providing an RFCOMM service.

5.3.5. Slowing down RFCOMM data reception. RFCOMM’s credit-based flow-control can be used to adapt, i.e., slow down the RFCOMM data to your process-ing speed. For incoming data, BTstack provides channels and services with andwithout automatic credit management. If the management of credits is auto-matic, new credits are provided when needed relying on ACL flow control. Thisis only useful if there is not much data transmitted and/or only one physicalconnection is used. See Listing below.

void bt s ta ck s e tup (void ) {. . .// i n i t RFCOMMr f comm init ( ) ;r f c o m m r e g i s t e r s e r v i c e ( packet handler , rfcomm channel nr ,

100) ;}

Listing 9. RFCOMM service with automatic credit management.

If the management of credits is manual, credits are provided by the applicationsuch that it can manage its receive buffers explicitly, see Listing below.

Manual credit management is recommended when received RFCOMM datacannot be processed immediately. In the SPP flow control example, delayedprocessing of received data is simulated with the help of a periodic timer. Toprovide new credits, you call the rfcomm grant credits function with the RF-COMM channel ID and the number of credits as shown in Listing below.

void bt s ta ck s e tup (void ) {. . .// i n i t RFCOMMr f comm init ( ) ;// re se rved channel , mtu=100, 1 c r e d i tr f c o m m r e g i s t e r s e r v i c e w i t h i n i t i a l c r e d i t s ( packet handler ,

rfcomm channel nr , 100 , 1) ;}

Listing 10. RFCOMM service with manual credit management.

Page 39: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

38

void p r o c e s s i n g ( ) {// proces s incoming data packe t. . .// prov ide new c r e d i tr f comm grant c r ed i t s ( r fcomm channel id , 1) ;

}

Listing 11. Granting RFCOMM credits.

Please note that providing single credits effectively reduces the credit-based(sliding window) flow control to a stop-and-wait flow-control that limits the datathroughput substantially. On the plus side, it allows for a minimal memoryfootprint. If possible, multiple RFCOMM buffers should be used to avoid pauseswhile the sender has to wait for a new credit.

5.3.6. Sending RFCOMM data. Outgoing packets, both commands and data,are not queued in BTstack. This section explains the consequences of this designdecision for sending data and why it is not as bad as it sounds.

Independent from the number of output buffers, packet generation has to beadapted to the remote receiver and/or maximal link speed. Therefore, a packetcan only be generated when it can get sent. With this assumption, the singleoutput buffer design does not impose additional restrictions. In the following,we show how this is used for adapting the RFCOMM send rate.

When there is a need to send a packet, call rcomm request can send now andwait for the reception of the RFCOMM EVENT CAN SEND NOW event tosend the packet, as shown in Listing below.

Please note that the guarantee that a packet can be sent is only valid whenthe event is received. After returning from the packet handler, BTstack mightneed to send itself.

void prepare data ( u i n t 1 6 t r fcomm channel id ) {. . .// prepare data in d a t a b u f f e rr fcomm request can send now event ( r fcomm channel id ) ;

}

void send data ( u i n t 1 6 t r fcomm channel id ) {rfcomm send ( rfcomm channel id , da ta bu f f e r , da ta l en ) ;// packe t i s handed over to BTstack , we can prepare the next

oneprepare data ( r fcomm channel id ) ;

}

void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 t channel ,u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

Page 40: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

39

. . .case RFCOMM EVENT CAN SEND NOW:

rfcomm channel id =rfcomm event can send now get r fcomm cid( packet ) ;

send data ( r fcomm channel id ) ;break ;

. . .}. . .

}}

}

Listing 12. Preparing and sending data.

5.3.7. Optimized sending of RFCOMM data. When sending RFCOMM data viarfcomm send, BTstack needs to copy the data from the user provided buffer intothe outgoing buffer. This requires both an additional buffer for the user data aswell requires a copy operation.

To avoid this, it is possible to directly write the user data into the outgoingbuffer.

When get the RFCOMM CAN SEND NOW event, you call rfcomm reserve packet bufferto lock the buffer for your send operation. Then, you can ask how many bytesyou can send with rfcomm get max frame size and get a pointer to BTstack’sbuffer with rfcomm get outgoing buffer. Now, you can fill that buffer and finallysend the data with rfcomm send prepared.

5.4. SDP - Service Discovery Protocol. The SDP protocol allows to an-nounce services and discover services provided by a remote Bluetooth device.

5.4.1. Create and announce SDP records. BTstack contains a complete SDPserver and allows to register SDP records. An SDP record is a list of SDPAttribute {ID, Value} pairs that are stored in a Data Element Sequence (DES).The Attribute ID is a 16-bit number, the value can be of other simple types likeintegers or strings or can itself contain other DES.

To create an SDP record for an SPP service, you can call spp create sdp recordfrom with a pointer to a buffer to store the record, the server channel number,and a record name.

For other types of records, you can use the other functions in, using the dataelement de functions. Listing [sdpCreate] shows how an SDP record containingtwo SDP attributes can be created. First, a DES is created and then the ServiceRecord Handle and Service Class ID List attributes are added to it. The ServiceRecord Handle attribute is added by calling the de add number function twice:the first time to add 0x0000 as attribute ID, and the second time to add theactual record handle (here 0x1000) as attribute value. The Service Class IDList attribute has ID 0x0001, and it requires a list of UUIDs as attribute value.To create the list, de push sequence is called, which “opens” a sub-DES. Thereturned pointer is used to add elements to this sub-DES. After adding all UUIDs,the sub-DES is “closed” with de pop sequence.

Page 41: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

40

To register an SDP record, you call sdp register service with a pointer to it.The SDP record can be stored in FLASH since BTstack only stores the pointer.Please note that the buffer needs to persist (e.g. global storage, dynamicallyallocated from the heap or in FLASH) and cannot be used to create anotherSDP record.

5.4.2. Query remote SDP service. BTstack provides an SDP client to querySDP services of a remote device. The SDP Client API is shown in here. Thesdp client query function initiates an L2CAP connection to the remote SDPserver. Upon connect, a Service Search Attribute request with a Service SearchPattern and a Attribute ID List is sent. The result of the Service Search Attributequery contains a list of Service Records, and each of them contains the requestedattributes. These records are handled by the SDP parser. The parser deliversSDP PARSER ATTRIBUTE VALUE and SDP PARSER COMPLETE eventsvia a registered callback. The SDP PARSER ATTRIBUTE VALUE event de-livers the attribute value byte by byte.

On top of this, you can implement specific SDP queries. For example, BT-stack provides a query for RFCOMM service name and channel number. Thisinformation is needed, e.g., if you want to connect to a remote SPP service.The query delivers all matching RFCOMM services, including its name and thechannel number, as well as a query complete event via a registered callback, asshown in Listing below.

bd addr t remote = {0x04 , 0 x0C , 0xCE, 0 xE4 , 0 x85 , 0 xD3} ;

void packet hand le r (void ∗ connect ion , u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {i f ( packet type != HCI EVENT PACKET) return ;

u i n t 8 t event = packet [ 0 ] ;switch ( event ) {

case BTSTACK EVENT STATE:// b t s t a c k ac t i v a t ed , g e t s t a r t e di f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) ==

HCI STATE WORKING) {sdp c l i en t query r f comm channe l and name fo r uu id

( remote , 0x0003 ) ;}break ;

default :break ;

}}

stat ic void bt s ta ck s e tup ( ) {. . .// i n i t L2CAPl 2 c a p i n i t ( ) ;l 2 c a p r e g i s t e r p a c k e t h a n d l e r ( packet hand le r ) ;

Page 42: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

41

}

void handle query r fcomm event ( sdp que ry event t ∗ event , void ∗context ) {s d p c l i e n t q u e r y r f c o m m s e r v i c e e v e n t t ∗ ve ;

switch ( event−>type ) {case SDP EVENT QUERY RFCOMM SERVICE:

ve = ( s d p c l i e n t q u e r y r f c o m m s e r v i c e e v e n t t ∗)event ;

p r i n t f ( ” S e r v i c e name : ’%s ’ , RFCOMM port %u\n” , ve−>serv ice name , ve−>channe l nr ) ;

break ;case SDP EVENT QUERY COMPLETE:

r e p o r t f o u n d s e r v i c e s ( ) ;p r i n t f ( ” C l i en t query response done with s t a t u s %d . \

n” , ce−>s t a t u s ) ;break ;

}}

int main (void ) {hw setup ( ) ;b t s t a ck s e tup ( ) ;

// r e g i s t e r c a l l b a c k to r e c e i v e matching RFCOMM Serv i c e s and// query complete events d p c l i e n t q u e r y r f c o m m r e g i s t e r c a l l b a c k (

handle query rfcomm event , NULL) ;

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;// go !b t s t a c k r u n l o o p e x e c u t e ( ) ;return 0 ;

}

Listing 13. Searching RFCOMM services on a remote device.

5.5. BNEP - Bluetooth Network Encapsulation Protocol. The BNEPprotocol is used to transport control and data packets over standard networkprotocols such as TCP, IPv4 or IPv6. It is built on top of L2CAP, and it specifiesa minimum L2CAP MTU of 1691 bytes.

5.5.1. Receive BNEP events. To receive BNEP events, please register a packethandler with bnep register packet handler.

5.5.2. Access a BNEP service on a remote device. To connect to a remote BNEPservice, you need to know its UUID. The set of available UUIDs can be queried bya SDP query for the PAN profile. Please see section on PAN profile for details.With the remote UUID, you can create a connection using the bnep connectfunction. You’ll receive a BNEP EVENT CHANNEL OPENED on success orfailure.

Page 43: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

42

After the connection was opened successfully, you can send and receive Ether-net packets. Before sending an Ethernet frame with bnep send, bnep can send packet nowneeds to return true. Ethernet frames are received via the registered packet han-dler with packet type BNEP DATA PACKET.

BTstack BNEP implementation supports both network protocol filter andmulticast filters with bnep set net type filter and bnep set multicast filter respec-tively.

Finally, to close a BNEP connection, you can call bnep disconnect.

5.5.3. Provide BNEP service. To provide a BNEP service, call bnep register servicewith the provided service UUID and a max frame size.

A BNEP EVENT INCOMING CONNECTION event will mark that an in-coming connection is established. At this point you can start sending and re-ceiving Ethernet packets as described in the previous section.

5.5.4. Sending Ethernet packets. Similar to L2CAP and RFOMM, directly send-ing an Ethernet packet via BNEP might fail, if the outgoing packet buffer or theACL buffers in the Bluetooth module are full.

When there’s a need to send an Ethernet packet, call bnep request can send nowand send the packet when the BNEP EVENT CAN SEND NOW event gets re-ceived.

5.6. ATT - Attribute Protocol. The ATT protocol is used by an ATT clientto read and write attribute values stored on an ATT server. In addition, theATT server can notify the client about attribute value changes. An attributehas a handle, a type, and a set of properties.

The Generic Attribute (GATT) profile is built upon ATT and provides higherlevel organization of the ATT attributes into GATT Services and GATT Char-acteristics. In BTstack, the complete ATT client functionality is included withinthe GATT Client. See GATT client for more.

On the server side, one ore more GATT profiles are converted ahead of timeinto the corresponding ATT attribute database and provided by the att serverimplementation. The constant data are automatically served by the ATT serverupon client request. To receive the dynamic data, such is characteristic value, theapplication needs to register read and/or write callback. In addition, notificationsand indications can be sent. Please see Section on GATT server for more.

5.7. SMP - Security Manager Protocol. The SMP protocol allows to setupauthenticated and encrypted LE connection. After initialization and configura-tion, SMP handles security related functions on its own but emits events whenfeedback from the main app or the user is required. The two main tasks of theSMP protocol are: bonding and identity resolving.

5.7.1. LE Legacy Pairing and LE Secure Connections. The original pairing algo-rithm introduced in Bluetooth Core V4.0 does not provide security in case of anattacker present during the initial pairing. To fix this, the Bluetooth Core V4.2specification introduced the new LE Secure Connections method, while referringto the original method as LE Legacy Pairing.

Page 44: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

43

BTstack supports both pairing methods. To enable the more secure LE Se-cure Connections method, ENABLE LE SECURE CONNECTIONS needs to bedefined in btstack config.h.

LE Secure Connections are based on Elliptic Curve Diffie-Hellman (ECDH)algorithm for the key exchange. On start, a new public/private key pair isgenerated. During pairing, the Long Term Key (LTK) is generated based onthe local keypair and the remote public key. To facilitate the creation of such akeypairs and the calculation of the LTK, the Bluetooth Core V4.2 specificationintroduced appropriate commands for the Bluetooth controller.

As an alternative for controllers that don’t provide these primitives, BTstackprovides the relevant cryptographic functions in software via the BSD-2-Clauselicensed micro-ecc library.

When using using LE Secure Connections, the Peripheral must store LTK innon-volatile memory.

5.7.2. Initialization. To activate the security manager, call sm init().If you’re creating a product, you should also call sm set ir() and sm set er()

with a fixed random 16 byte number to create the IR and ER key seeds. Ifpossible use a unique random number per device instead of deriving it from theproduct serial number or something similar. The encryption key generated by theBLE peripheral will be ultimately derived from the ER key seed. See BluetoothSpecification - Bluetooth Core V4.0, Vol 3, Part G, 5.2.2 for more details onderiving the different keys. The IR key is used to identify a device if private,resolvable Bluetooth addresses are used.

5.7.3. Configuration. To receive events from the Security Manager, a callbackis necessary. How to register this packet handler depends on your applicationconfiguration.

When att server is used to provide a GATT/ATT service, att server registersitself as the Security Manager packet handler. Security Manager events are thenreceived by the application via the att server packet handler.

If att server is not used, you can directly register your packet handler withthe security manager by calling sm register packet handler.

The default SMP configuration in BTstack is to be as open as possible:

• accept all Short Term Key (STK) Generation methods,• accept encryption key size from 7..16 bytes,• expect no authentication requirements,• don’t support LE Secure Connections, and• IO Capabilities set to IO CAPABILITY NO INPUT NO OUTPUT.

You can configure these items by calling following functions respectively:

• sm set accepted stk generation methods• sm set encryption key size range• sm set authentication requirements : add SM AUTHREQ SECURE CONNECTION

flag to enable LE Secure Connections• sm set io capabilities

Page 45: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

44

5.7.4. Identity Resolving. Identity resolving is the process of matching a private,resolvable Bluetooth address to a previously paired device using its Identity Re-solving (IR) key. After an LE connection gets established, BTstack automaticallytries to resolve the address of this device. During this lookup, BTstack will emitthe following events:

• SM EVENT IDENTITY RESOLVING STARTED to mark the start ofa lookup,

and later:

• SM EVENT IDENTITY RESOLVING SUCCEEDED on lookup success,or• SM EVENT IDENTITY RESOLVING FAILED on lookup failure.

5.7.5. User interaction. Depending on the authentication requirements, IO capa-bilities, available OOB data, and the enabled STK generation methods, BTstackwill request feedback from the app in the form of an event:

• SM EVENT JUST WORKS REQUEST : request a user to accept a JustWorks pairing• SM EVENT PASSKEY INPUT NUMBER: request user to input a passkey• SM EVENT PASSKEY DISPLAY NUMBER: show a passkey to the user• SM EVENT NUMERIC COMPARISON REQUEST : show a passkey to

the user and request confirmation

To stop the bonding process, sm bonding decline should be called. Otherwise,sm just works confirm or sm passkey input can be called.

After the bonding process, SM EVENT JUST WORKS CANCEL, SM EVENT PASSKEY DISPLAY CANCEL,or SM EVENT NUMERIC COMPARISON CANCEL is emitted to update theuser interface if an Just Works request or a passkey has been shown before.

5.7.6. Keypress Notifications. As part of Bluetooth Core V4.2 specification, adevice with a keyboard but no display can send keypress notifications to pro-vide better user feedback. In BTstack, the sm keypress notification() functionis used for sending notifications. Notifications are received by BTstack via theSM EVENT KEYPRESS NOTIFICATION event.

5.7.7. Cross-transport Key Derivation for LE Secure Connections. In a dual-mode configuration, BTstack automatically generates an BR/EDR Link Keyfrom the LE LTK via the Link Key Conversion function h6. It is then stored inthe link key db.

To derive an LE LTK from a BR/EDR link key, the Bluetooth controller needsto support Secure Connections via NIST P-256 elliptic curves and the LE SecureConnections needs to get established via the LE Transport. BTstack does notsupport LE Secure Connections via LE Transport currently.

5.7.8. Out-of-Band Data with LE Legacy Pairing. LE Legacy Pairing can bemade secure by providing a way for both devices to acquire a pre-shared secret16 byte key by some fancy method. In most cases, this is not an option, especiallysince popular OS like iOS don’t provide a way to specify it. In some applications,where both sides of a Bluetooth link are developed together, this could providea viable option.

Page 46: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

45

To provide OOB data, you can register an OOB data callback with sm register oob data callback.

6. Profiles

In the following, we explain how the various Bluetooth profiles are used inBTstack.

6.1. GAP - Generic Access Profile: Classic. The GAP profile defines howdevices find each other and establish a secure connection for other profiles. Asmentioned before, the GAP functionality is split between and . Please checkboth.

6.1.1. Become discoverable. A remote unconnected Bluetooth device must be setas “discoverable” in order to be seen by a device performing the inquiry scan.To become discoverable, an application can call gap discoverable control withinput parameter 1. If you want to provide a helpful name for your device, theapplication can set its local name by calling gapsetlocalname. To save energy,you may set the device as undiscoverable again, once a connection is established.See Listing below for an example.

int main (void ) {. . .// make d i s c o v e r a b l eg a p d i s c o v e r a b l e c o n t r o l (1 ) ;b t s t a c k r u n l o o p e x e c u t e ( ) ;return 0 ;

}void packet hand le r ( u i n t 8 t packet type , u i n t 8 t ∗packet ,

u i n t 1 6 t s i z e ) {. . .switch ( s t a t e ) {

case W4 CHANNEL COMPLETE:// i f connect ion i s s u c c e s s f u l , make dev i c e

und i s cov e rab l eg a p d i s c o v e r a b l e c o n t r o l (0 ) ;

. . .}

}

Listing 14. Setting discoverable mode.

6.1.2. Discover remote devices. To scan for remote devices, the hci inquiry com-mand is used. Found remote devices are reported as a part of:

• HCI EVENT INQUIRY RESULT,• HCI EVENT- INQUIRY RESULT WITH RSSI, or• HCI EVENT EXTENDED INQUIRY RESPONSE events.

Each response contains at least the Bluetooth address, the class of device, thepage scan repetition mode, and the clock offset of found device. The latter eventsadd information about the received signal strength or provide the ExtendedInquiry Result (EIR). A code snippet is shown in Listing below.

Page 47: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

46

void p r i n t i n q u i r y r e s u l t s ( u i n t 8 t ∗packet ) {int event = packet [ 0 ] ;int numResponses =

h c i e v e n t i n q u i r y r e s u l t g e t n u m r e s p o n s e s ( packet ) ;u i n t 1 6 t c lassOfDev ice , c l o c k O f f s e t ;u i n t 8 t r s s i , pageScanRepetitionMode ;for ( i =0; i<numResponses ; i++){

b t f l i p a d d r ( addr , &packet [3+ i ∗6 ] ) ;pageScanRepetitionMode = packet [ 3 + numResponses∗6 + i

] ;i f ( event == HCI EVENT INQUIRY RESULT) {

c la s sOfDev i ce = l i t t l e e n d i a n r e a d 2 4 ( packet , 3 +numResponses∗(6+1+1+1) + i ∗3) ;

c l o c k O f f s e t = l i t t l e e n d i a n r e a d 1 6 ( packet , 3 +numResponses∗(6+1+1+1+3) + i ∗2) & 0 x 7 f f f ;

r s s i = 0 ;} else {

c la s sOfDev i ce = l i t t l e e n d i a n r e a d 2 4 ( packet , 3 +numResponses∗(6+1+1) + i ∗3) ;

c l o c k O f f s e t = l i t t l e e n d i a n r e a d 1 6 ( packet , 3 +numResponses∗(6+1+1+3) + i ∗2) & 0 x 7 f f f ;

r s s i = packet [ 3 + numResponses∗(6+1+1+3+2) + i ∗ 1 ] ;}p r i n t f ( ” Device found : %s with COD: 0x%06x , pageScan %u ,

c l o ck o f f s e t 0x%04x , r s s i 0x%02x\n” , b d a d d r t o s t r (addr ) , c lassOfDevice , pageScanRepetitionMode ,c l o ckOf f s e t , r s s i ) ;

}}

void packet hand le r ( u i n t 8 t packet type , u i n t 8 t ∗packet ,u i n t 1 6 t s i z e ) {. . .switch ( event ) {

case HCI STATE WORKING:hci send cmd(& hc i wr i t e inqu i ry mode , 0x01 ) ; // wi th

RSSIbreak ;

case HCI EVENT COMMAND COMPLETE:i f (COMMAND COMPLETE EVENT( packet ,

h c i wr i t e i nqu i ry mode ) ) {s t a r t s c a n ( ) ;

}case HCI EVENT COMMAND STATUS:

i f (COMMAND STATUS EVENT( packet ,h c i wr i t e i nqu i ry mode ) ) {p r i n t f ( ” Ignor ing e r r o r (0 x%x ) from

hc i wr i t e i nqu i ry mode .\n” , packet [ 2 ] ) ;hc i send cmd(& h c i i n q u i r y , HCI INQUIRY LAP ,

INQUIRY INTERVAL, 0) ;}break ;

Page 48: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

47

case HCI EVENT INQUIRY RESULT:case HCI EVENT INQUIRY RESULT WITH RSSI :

p r i n t i n q u i r y r e s u l t s ( packet ) ;break ;

. . .}

}

Listing 15. Discover remote devices.

By default, neither RSSI values nor EIR are reported. If the Bluetooth de-vice implements Bluetooth Specification 2.1 or higher, the hci write inquiry modecommand enables reporting of this advanced features (0 for standard results, 1for RSSI, 2 for RSSI and EIR).

A complete GAP inquiry example is provided here.

6.1.3. Pairing of Devices. By default, Bluetooth communication is not authen-ticated, and any device can talk to any other device. A Bluetooth device (forexample, cellular phone) may choose to require authentication to provide a par-ticular service (for example, a Dial-Up service). The process of establishingauthentication is called pairing. Bluetooth provides two mechanism for this.

On Bluetooth devices that conform to the Bluetooth v2.0 or older specification,a PIN code (up to 16 bytes ASCII) has to be entered on both sides. This isn’toptimal for embedded systems that do not have full I/O capabilities. To supportpairing with older devices using a PIN, see Listing below.

void packet hand le r ( u i n t 8 t packet type , u i n t 8 t ∗packet ,u i n t 1 6 t s i z e ) {. . .switch ( event ) {

case HCI EVENT PIN CODE REQUEST:// inform about pin code r e que s tp r i n t f ( ”Pin code reque s t − us ing ’0000 ’\n\ r ” ) ;h c i e v e n t p i n c o d e r e q u e s t g e t b d a d d r ( packet ,

bd addr ) ;

// baseband address , pin l eng th , PIN : c−s t r i n ghci send cmd(& h c i p i n c o d e r e q u e s t r e p l y , &bd addr ,

4 , ”0000” ) ;break ;

. . .}

}

Listing 16. PIN code request.

The Bluetooth v2.1 specification introduces Secure Simple Pairing (SSP),which is a better approach as it both improves security and is better adapted toembedded systems. With SSP, the devices first exchange their IO Capabilitiesand then settle on one of several ways to verify that the pairing is legitimate.If the Bluetooth device supports SSP, BTstack enables it by default and even

Page 49: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

48

automatically accepts SSP pairing requests. Depending on the product in whichBTstack is used, this may not be desired and should be replaced with code tointeract with the user.

Regardless of the authentication mechanism (PIN/SSP), on success, both de-vices will generate a link key. The link key can be stored either in the Bluetoothmodule itself or in a persistent storage, see here. The next time the deviceconnects and requests an authenticated connection, both devices can use thepreviously generated link key. Please note that the pairing must be repeated ifthe link key is lost by one device.

6.1.4. Dedicated Bonding. Aside from the regular bonding, Bluetooth also pro-vides the concept of “dedicated bonding”, where a connection is established forthe sole purpose of bonding the device. After the bonding process is over, theconnection will be automatically terminated. BTstack supports dedicated bond-ing via the gap dedicated bonding function.

6.2. SPP - Serial Port Profile. The SPP profile defines how to set up virtualserial ports and connect two Bluetooth enabled devices. Please keep in mindthat a serial port does not preserve packet boundaries if you try to send data aspackets and read about RFCOMM packet boundaries.

6.2.1. Accessing an SPP Server on a remote device. To access a remote SPPserver, you first need to query the remote device for its SPP services. Sectionon querying remote SDP service shows how to query for all RFCOMM channels.For SPP, you can do the same but use the SPP UUID 0x1101 for the query. Afteryou have identified the correct RFCOMM channel, you can create an RFCOMMconnection as shown here.

6.2.2. Providing an SPP Server. To provide an SPP Server, you need to providean RFCOMM service with a specific RFCOMM channel number as explained insection on RFCOMM service. Then, you need to create an SDP record for it andpublish it with the SDP server by calling sdp register service. BTstack providesthe spp create sdp record function in that requires an empty buffer of approxi-mately 200 bytes, the service channel number, and a service name. Have a lookat the [SPP Counter example](examples/generated/#sec:sppcounterExample].

6.3. PAN - Personal Area Networking Profile. The PAN profile uses BNEPto provide on-demand networking capabilities between Bluetooth devices. ThePAN profile defines the following roles:

• PAN User (PANU)• Network Access Point (NAP)• Group Ad-hoc Network (GN)

PANU is a Bluetooth device that communicates as a client with GN, or NAP,or with another PANU Bluetooth device, through a point-to-point connection.Either the PANU or the other Bluetooth device may terminate the connectionat anytime.

NAP is a Bluetooth device that provides the service of routing network packetsbetween PANU by using BNEP and the IP routing mechanism. A NAP can also

Page 50: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

49

act as a bridge between Bluetooth networks and other network technologies byusing the Ethernet packets.

The GN role enables two or more PANUs to interact with each other througha wireless network without using additional networking hardware. The devicesare connected in a piconet where the GN acts as a master and communicateseither point-to-point or a point-to-multipoint with a maximum of seven PANUslaves by using BNEP.

Currently, BTstack supports only PANU.

6.3.1. Accessing a remote PANU service. To access a remote PANU service, youfirst need perform an SDP query to get the L2CAP PSM for the requestedPANU UUID. With these two pieces of information, you can connect BNEP tothe remote PANU service with the bnep connect function. The Section on PANUDemo example shows how this is accomplished.

6.3.2. Providing a PANU service. To provide a PANU service, you need to pro-vide a BNEP service with the service UUID, e.g. the PANU UUID, and a maximalethernet frame size, as explained in Section on BNEP service. Then, you needto create an SDP record for it and publish it with the SDP server by callingsdp register service. BTstack provides the pan create panu sdp record functionin src/pan.c that requires an empty buffer of approximately 200 bytes, a descrip-tion, and a security description.

6.4. HSP - Headset Profile. The HSP profile defines how a Bluetooth-enabledheadset should communicate with another Bluetooth enabled device. It relies onSCO for audio encoded in 64 kbit/s CVSD and a subset of AT commands fromGSM 07.07 for minimal controls including the ability to ring, answer a call, hangup and adjust the volume.

The HSP defines two roles: - Audio Gateway (AG) - a device that acts as thegateway of the audio, typically a mobile phone or PC. - Headset (HS) - a devicethat acts as the AG’s remote audio input and output control.

There are following restrictions: - The CVSD is used for audio transmission.- Between headset and audio gateway, only one audio connection at a time issupported. - The profile offers only basic interoperability – for example, handlingof multiple calls at the audio gateway is not included. - The only assumptionon the headset’s user interface is the possibility to detect a user initiated action(e.g. pressing a button).

%TODO: audio paths

6.5. HFP - Hands-Free Profile. The HFP profile defines how a Bluetooth-enabled device, e.g. a car kit or a headset, can be used to place and receivecalls via a audio gateway device, typically a mobile phone. It relies on SCO foraudio encoded in 64 kbit/s CVSD and a bigger subset of AT commands fromGSM 07.07 then HSP for controls including the ability to ring, to place andreceive calls, join a conference call, to answer, hold or reject a call, and adjustthe volume.

The HFP defines two roles: - Audio Gateway (AG) – a device that acts asthe gateway of the audio,, typically a mobile phone. - Hands-Free Unit (HF) –a device that acts as the AG’s remote audio input and output control.

Page 51: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

50

%TODO: audio paths

6.6. GAP LE - Generic Access Profile for Low Energy. As with GAPfor Classic, the GAP LE profile defines how to discover and how to connect toa Bluetooth Low Energy device. There are several GAP roles that a Bluetoothdevice can take, but the most important ones are the Central and the Peripheralrole. Peripheral devices are those that provide information or can be controlled.Central devices are those that consume information or control the peripherals.Before the connection can be established, devices are first going through anadvertising process.

6.6.1. Private addresses. To better protect privacy, an LE device can choose touse a private i.e. random Bluetooth address. This address changes at a user-specified rate. To allow for later reconnection, the central and peripheral deviceswill exchange their Identity Resolving Keys (IRKs) during bonding. The IRK isused to verify if a new address belongs to a previously bonded device.

To toggle privacy mode using private addresses, call the gap random address set modefunction. The update period can be set with gap random address set update period.

After a connection is established, the Security Manager will try to resolve thepeer Bluetooth address as explained in Section on SMP.

6.6.2. Advertising and Discovery. An LE device is discoverable and connectable,only if it periodically sends out Advertisements. An advertisement contains up to31 bytes of data. To configure and enable advertisement broadcast, the followingGAP functions can be used:

• gap advertisements set data• gap advertisements set params• gap advertisements enable

In addition to the Advertisement data, a device in the peripheral role can alsoprovide Scan Response data, which has to be explicitly queried by the centraldevice. It can be set with gap scan response set data.

Please have a look at the SPP and LE Counter example.The scan parameters can be set with gap set scan parameters. The scan can

be started/stopped with gap start scan/gap stop scan.Finally, if a suitable device is found, a connection can be initiated by calling

gap connect. In contrast to Bluetooth classic, there is no timeout for an LEconnection establishment. To cancel such an attempt, gap connect cancel has bebe called.

By default, a Bluetooth device stops sending Advertisements when it gets intothe Connected state. However, it does not start broadcasting advertisementson disconnect again. To re-enable it, please send the hci le set advertise enableagain .

6.7. GATT - Generic Attribute Profile. The GATT profile uses ATT At-tributes to represent a hierarchical structure of GATT Services and GATT Char-acteristics. Each Service has one or more Characteristics. Each Characteristichas meta data attached like its type or its properties. This hierarchy of Charac-teristics and Services are queried and modified via ATT operations.

Page 52: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

51

GATT defines both a server and a client role. A device can implement one orboth GATT roles.

6.7.1. GATT Client. The GATT Client is used to discover services, and theircharacteristics and descriptors on a peer device. It can also subscribe for noti-fications or indications that the characteristic on the GATT server has changedits value.

To perform GATT queries, provides a rich interface. Before calling queries,the GATT client must be initialized with gatt client init once.

To allow for modular profile implementations, GATT client can be used inde-pendently by multiple entities.

To use it by a GATT client, you register a packet handler with gatt client register packethandler. The return value of that is a GATT client ID which has to be providedin all queries.

After an LE connection was created using the GAP LE API, you can queryfor the connection MTU with gatt client get mtu.

GATT queries cannot be interleaved. Therefore, you can check if you canperform a GATT query on a particular connection using gatt client is ready.As a result to a GATT query, zero to many le events are returned before aGATT EVENT QUERY COMPLETE event completes the query.

For more details on the available GATT queries, please consult GATT ClientAPI.

6.7.2. GATT Server. The GATT server stores data and accepts GATT clientrequests, commands and confirmations. The GATT server sends responses torequests and when configured, sends indication and notifications asynchronouslyto the GATT client.

To save on both code space and memory, BTstack does not provide a GATTServer implementation. Instead, a textual description of the GATT profile isdirectly converted into a compact internal ATT Attribute database by a GATTprofile compiler. The ATT protocol server - implemented by and - answersincoming ATT requests based on information provided in the compiled databaseand provides read- and write-callbacks for dynamic attributes.

GATT profiles are defined by a simple textual comma separated value (.csv)representation. While the description is easy to read and edit, it is compact andcan be placed in ROM.

The current format is shown in Listing below.

// import serv ice name#import <serv ice name . gatt>

PRIMARY SERVICE, {SERVICE UUID}CHARACTERISTIC, {ATTRIBUTE TYPE UUID} , {PROPERTIES} , {VALUE}CHARACTERISTIC, {ATTRIBUTE TYPE UUID} , {PROPERTIES} , {VALUE}. . .

PRIMARY SERVICE, {SERVICE UUID}CHARACTERISTIC, {ATTRIBUTE TYPE UUID} , {PROPERTIES} , {VALUE}. . .

Page 53: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

52

Listing 17. GATT profile.

UUIDs are either 16 bit (1800) or 128 bit (00001234-0000-1000-8000-00805F9B34FB).Value can either be a string (“this is a string”), or, a sequence of hex bytes

(e.g. 01 02 03).Properties can be a list of properties combined using ‘|’Reads/writes to a Characteristic that is defined with the DYNAMIC flag, are

forwarded to the application via callback. Otherwise, the Characteristics cannotbe written and it will return the specified constant value.

Adding NOTIFY and/or INDICATE automatically creates an addition ClientConfiguration Characteristic.

Property Meaning

READ Characteristic can be readWRITE Characteristic can be written using Write RequestWRITE WITHOUT RESPONSE Characteristic can be written using Write CommandNOTIFY Characteristic allows notifications by serverINDICATE Characteristic allows indication by serverDYNAMIC Read or writes to Characteristic are handled by application

To require encryption or authentication before a Characteristic can be ac-cessed, you can add one or more of the following properties:

Property Meaning

AUTHENTICATION REQUIRED Read and Write operatsions require AuthenticationREAD ENCRYPTED Read operations require EncryptionREAD AUTHENTICATED Read operations require AuthenticationWRITE ENCRYPTED Write operations require EncryptionWRITE AUTHENTICATED Write operations require AuthenticationENCRYPTION KEY SIZE X Require encryption size >= X, with W in [7..16]

To use already implemented GATT Services, you can import it using the#import <service name.gatt> command. See list of provided services.

BTstack only provides an ATT Server, while the GATT Server logic is mainlyprovided by the GATT compiler. While GATT identifies Characteristics byUUIDs, ATT uses Handles (16 bit values). To allow to identify a Characteristicwithout hard-coding the attribute ID, the GATT compiler creates a list of definesin the generated *.h file.

Similar to other protocols, it might be not possible to send any time. Tosend a Notification, you can call att server request can send now to receive aATT EVENT CAN SEND NOW event.

If your application cannot handle an ATT Read Request in the att read callbackin some situations, you can enable support for this by adding ENABLE ATT DELAYED RESPONSEto btstack config.h. Now, you can store the requested attribute handle and re-turn ATT READ RESPONSE PENDING instead of the length of the provided

Page 54: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

53

data when you don’t have the data ready. For ATT operations that read morethan one attribute, your att read callback might get called multiple times aswell. To let you know that all necessary attribute handles have been ‘requested’by the att server, you’ll get a final att read callback with the attribute handle ofATT READ RESPONSE PENDING. When you’ve got the data for all requestedattributes ready, you can call att server response ready, which will trigger pro-cessing of the current request. Please keep in mind that there is only one activeATT operation and that it has a 30 second timeout after which the ATT serveris considered defunct by the GATT Client.

6.7.3. Implementing Standard GATT Services. Implementation of a standardGATT Service consists of the following 4 steps:

1. Identify full Service Name2. Use Service Name to fetch XML definition at Bluetooth SIG site and

convert into generic .gatt file3. Edit .gatt file to set constant values and exclude unwanted Characteristics4. Implement Service server, e.g., battery service server.c

Step 1:To facilitate the creation of .gatt files for standard profiles defined by the

Bluetooth SIG, the tool/convert gatt service.py script can be used. When runwithout a parameter, it queries the Bluetooth SIG website and lists the availableServices by their Specification Name, e.g., org.bluetooth.service.battery service.

$ t o o l / c o n v e r t g a t t s e r v i c e . pyFetching l i s t o f s e r v i c e s from https : //www. b l u e t o o t h . com/

s p e c i f i c a t i o n s / g a t t / s e r v i c e s

S p e c i f i c a t i o n Type |S p e c i f i c a t i o n Name | UUID

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−+−−−−−−−−−−−

org . b luetooth . s e r v i c e . a l e r t n o t i f i c a t i o n | Aler tN o t i f i c a t i o n S e r v i c e | 0x1811

org . b luetooth . s e r v i c e . automat ion io | AutomationIO | 0x1815

org . b luetooth . s e r v i c e . b a t t e r y s e r v i c e | BatteryS e r v i c e | 0x180F

. . .org . b luetooth . s e r v i c e . w e i g h t s c a l e | Weight

Sca l e | 0x181D

To convert a s e r v i c e in to a . gat t f i l e template , p l e a s e c a l l thes c r i p t again with the reques ted S p e c i f i c a t i o n Type and theoutput f i l e name

Usage : t o o l / c o n v e r t g a t t s e r v i c e . py SPECIFICATION TYPE [ serv ice name. gat t ]

Step 2:

Page 55: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

54

To convert service into .gatt file, call *tool/convert gatt service.py with therequested Specification Type and the output file name.

$ t o o l / c o n v e r t g a t t s e r v i c e . py org . b luetooth . s e r v i c e . b a t t e r y s e r v i c eb a t t e r y s e r v i c e . gat t

Fetching org . b luetooth . s e r v i c e . b a t t e r y s e r v i c e fromhttps : //www. b l u e t o o t h . com/api / g a t t / xm l f i l e ?xmlFileName=org . b l u e t o o t h

. s e r v i c e . b a t t e r y s e r v i c e . xml

S e r v i c e Battery S e r v i c e− C h a r a c t e r i s t i c Battery Level − p r o p e r t i e s [ ’ Read ’ , ’ Not i fy ’ ]−− Desc r ip to r C h a r a c t e r i s t i c Pre senta t i on Format − TODO:

Please s e t va lue s−− Desc r ip to r C l i en t C h a r a c t e r i s t i c Conf igurat ion

S e r v i c e s u c c e s s f u l l y converted in to b a t t e r y s e r v i c e . gat tPlease check for TODOs in the . gat t f i l e

Step 3:In most cases, you will need to customize the .gatt file. Please pay attention

to the tool output and have a look at the generated .gatt file.E.g. in the generated .gatt file for the Battery Service

// Sp e c i f i c a t i o n Type org . b l u e t o o t h . s e r v i c e . b a t t e r y s e r v i c e// h t t p s ://www. b l u e t o o t h . com/api / g a t t / xm l f i l e ?xmlFileName=org .

b l u e t o o t h . s e r v i c e . b a t t e r y s e r v i c e . xml

// Bat tery Serv i c e 180FPRIMARY SERVICE, ORG BLUETOOTH SERVICE BATTERY SERVICECHARACTERISTIC, ORG BLUETOOTH CHARACTERISTIC BATTERY LEVEL, DYNAMIC

| READ | NOTIFY,// TODO: Cha r a c t e r i s t i c Presen ta t ion Format : p l e a s e s e t va l u e s#TODO CHARACTERISTIC FORMAT, READ, format , exponent , un i t ,

name space , d e s c r i p t i o nCLIENT CHARACTERISTIC CONFIGURATION, READ | WRITE,

you could delete the line regarding the CHARACTERISTIC FORMAT, sinceit’s not required if there is a single instance of the service. Please compare the.gatt file against the Adopted Specifications.

Step 4:As described above all read/write requests are handled by the application. To

implement the new services as a reusable module, it’s neccessary to get accessto all read/write requests related to this service.

For this, the ATT DB allows to register read/write callbacks for a specifichandle range with att server register can send now callback().

Since the handle range depends on the application’s .gatt file, the handle rangefor Primary and Secondary Services can be queried with gatt server get get handle range for service with uuid16.

Page 56: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

55

Similarly, you will need to know the attribute handle for particular Charac-teristics to handle Characteristic read/writes requests. You can get the attributevalue handle for a Characteristics gatt server get value handle for characteristic with uuid16().

In addition to the attribute value handle, the handle for the Client Characteris-tic Configuration is needed to support Indications/Notifications. You can get thisattribute handle with gatt server get client configuration handle for characteristic with uuid16()

Finally, in order to send Notifications and Indications independently fromthe main application, att server register can send now callback can be used torequest a callback when it’s possible to send a Notification or Indication.

To see how this works together, please check out the Battery Service Server insrc/ble/battery service server.c.

7. Implemented GATT Services

BTstack allows to implement and use GATT Services in a modular way.To use an already implemented GATT Service, you only have to add it to your

application’s GATT file with:

• #import <service name.gatt> for .gatt files located in src/ble/gatt-service• #import ”service name.gatt” for .gatt files located in the same folder as your

application’s .gatt file.

Each service will have an API at src/ble/gatt-service/service name server.h.To activate it, you need to call service name init(..)*. Please see the .h file fordetails.

7.0.1. Battery Service {#sec:BatteryService}}. The Battery Service allows toquery your device’s battery level in a standardized way.

To use with your application, add #import <batery service.gatt> to your .gattfile. After adding it to your .gatt file, you call battery service server init(value)with the current value of your battery. The valid range for the battery level is0-100.

If the battery level changes, you can call battery service server set battery value(value).The service supports sending Notifications if the client enables them.

7.0.2. Heart Rate Service {#sec:HeartRateService}}. The heart rate service serverprovides heart rate measurements via notifications.

Each notification reports the heart rate measurement in beats per minute, andif enabled, the total energy expended in kilo Joules, as well as RR-intervals in1/1024 seconds resolution.

The Energy Expended field represents the accumulated energy expended inkilo Joules since the last time it was reset. If the maximum value of 65535 kiloJoules is reached, it will remain at this value, until a reset command from theclient is received.

The RR-Interval represents the time between two consecutive R waves in anElectrocardiogram (ECG) waveform. If needed, the RR-Intervals are sent inmultiple notifications.

To use with your application, add #import <heart rate service.gatt> to your .gattfile. After adding it to your .gatt file, you call heart rate server init(body sensor location,

Page 57: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

56

energy expended supported) with the intended sensor location, and a flag indicat-ing if energy expanded is supported.

If heart rate measurement changes, you can call heart rate service server update heart rate values(heart rate bpm,service sensor contact status, rr interval count, rr intervals). This function willtrigger sending Notifications if the client enables them.

If energy expanded is supported, you can call heart rate service add energy expended(energy expended kJ)with the newly expanded energy. The accumulated energy expended value willbe emitted with the next heart rate measurement.

8. Embedded Examples

In this section, we will describe a number of examples from the example folder.To allow code-reuse with different platforms as well as with new ports, the low-level initialization of BTstack and the hardware configuration has been extractedto the various platforms/PLATFORM/main.c files. The examples only containthe platform-independent Bluetooth logic. But let’s have a look at the commoninit code.

Listing below shows a minimal platform setup for an embedded system witha Bluetooth chipset connected via UART.

int main ( ) {// . . . hardware i n i t : watchdoch , IOs , t imers , e t c . . .

// se tup BTstack memory poo l sbtstack memory in i t ( ) ;

// s e l e c t embedded run loopb t s t a c k r u n l o o p i n i t ( b t s tack run loop embedded ge t in s tance ( )

) ;

// use l o g g e r : format HCI DUMP PACKETLOGGER, HCI DUMP BLUEZ orHCI DUMP STDOUT

hci dump open (NULL, HCI DUMP STDOUT) ;

// i n i t HCIh c i t r a n s p o r t t ∗ t r anspor t = h c i t r a n s p o r t h 4 i n s t a n c e ( ) ;h c i i n i t ( t ransport , NULL) ;

// se tup examplebtstack main ( argc , argv ) ;

// gob t s t a c k r u n l o o p e x e c u t e ( ) ;

}

Listing 18. Minimal platform setup for an embedded system

First, BTstack’s memory pools are setup up. Then, the standard run loopimplementation for embedded systems is selected.

Page 58: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

57

The call to hci dump open configures BTstack to output all Bluetooth packetsand it’s own debug and error message via printf. The Python script tools/cre-ate packet log.py can be used to convert the console output into a BluetoothPacketLogger format that can be opened by the OS X PacketLogger tool as wellas by Wireshark for further inspection. When asking for help, please alwaysinclude a log created with HCI dump.

The hci init function sets up HCI to use the HCI H4 Transport implementa-tion. It doesn’t provide a special transport configuration nor a special implemen-tation for a particular Bluetooth chipset. It makes use of the remote device db memoryimplementation that allows for re-connects without a new pairing but doesn’tpersist the bonding information.

Finally, it calls btstack main() of the actual example before executing the runloop.

• Hello World example:– led counter: Hello World: blinking LED without Bluetooth.

• GAP example:– gap inquiry: GAP Inquiry Example.

• SDP Queries examples:– sdp general query: Dump remote SDP Records.– sdp bnep query: Dump remote BNEP PAN protocol UUID and

L2CAP PSM.• SPP Server examples:

– spp counter: SPP Server - Heartbeat Counter over RFCOMM.– spp flowcontrol: SPP Server - Flow Control.

• BNEP/PAN example:– panu demo: PANU Demo.

• HSP examples:– hsp hs demo: HSP Headset Demo.– hsp ag demo: HSP Audio Gateway Demo.

• HFP examples:– hfp hf demo: HFP Hands-Free (HF) Demo.– hfp ag demo: HFP Audio Gateway (AG) Demo.

• Low Energy examples:– gap le advertisements: GAP LE Advertisements Dumper.– gatt browser: GATT Client - Discovering primary services and their

characteristics.– le counter: LE Peripheral - Heartbeat Counter over GATT.– le streamer: LE Streamer - Stream data over GATT..

• Dual Mode example:– spp and le counter: Dual mode example.

• Audio examples:– a2dp sink demo: Receive audio stream and control its playback..– a2dp source demo: Serve audio stream and handle remote playback

control and queries..• HID examples:

– hid keyboard demo: HID Keyboard (Server) Demo.– hid mouse demo: HID Mouse (Server) Demo.

Page 59: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

58

– hog keyboard demo: HID-over-GATT Keyboard.– hog mouse demo: HID-over-GATT Mouse.

• LE Pairing examples:– sm pairing central: LE Peripheral - Test pairing combinations.– sm pairing peripheral: LE Peripheral - Test pairing combinations.

• Phone Book Access example:– pbap client demo: Connect to Phonebook Server and get contacts..

• Performance examples:– le streamer: LE Streamer - Stream data over GATT..– le streamer client: Connects to ‘LE Streamer’ and subscribes to test

characteristic.– spp streamer: Send test data via SPP as fast as possible..– spp streamer client: Client for SPP Streamer.

• Testing example:– dut mode classic: Enable Device Under Test (DUT) Mode for BR/EDR.

8.1. led counter: Hello World: blinking LED without Bluetooth. Theexample demonstrates how to provide a periodic timer to toggle an LED andsend debug messages to the console as a minimal BTstack test.

8.1.1. Periodic Timer Setup. As timers in BTstack are single shot, the peri-odic counter is implemented by re-registering the timer source in the heartbeathandler callback function. Listing here shows heartbeat handler adapted to pe-riodically toggle an LED and print number of toggles.

stat ic void hear tbea t hand l e r ( b t s t a c k t i m e r s o u r c e t ∗ t s ) {UNUSED( t s ) ;

// increment counterchar l i n e B u f f e r [ 3 0 ] ;s p r i n t f ( l i n e B u f f e r , ”BTstack counter %04u\n\ r ” , ++counter ) ;puts ( l i n e B u f f e r ) ;

// t o g g l e LEDh a l l e d t o g g l e ( ) ;

// re−r e g i s t e r t imerb t s t a c k r u n l o o p s e t t i m e r (&heartbeat , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer (&heartbeat ) ;

}

Listing 19. Periodic counter

8.1.2. Main Application Setup. Listing here shows main application code. Itconfigures the heartbeat tier and adds it to the run loop.

Page 60: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

59

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

// s e t one−sho t t imerheartbeat . p roc e s s = &hear tbea t hand l e r ;b t s t a c k r u n l o o p s e t t i m e r (&heartbeat , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer (&heartbeat ) ;

p r i n t f ( ”Running . . . \ n\ r ” ) ;return 0 ;

}

Listing 20. Setup heartbeat timer

8.2. gap inquiry: GAP Inquiry Example. The Generic Access Profile (GAP)defines how Bluetooth devices discover and establish a connection with eachother. In this example, the application discovers surrounding Bluetooth devicesand collects their Class of Device (CoD), page scan mode, clock offset, and RSSI.After that, the remote name of each device is requested. In the following sectionwe outline the Bluetooth logic part, i.e., how the packet handler handles theasynchronous events and data packets.

8.2.1. Bluetooth Logic. The Bluetooth logic is implemented as a state machinewithin the packet handler. In this example, the following states are passedsequentially: INIT, and ACTIVE.

In INIT, an inquiry scan is started, and the application transits to ACTIVEstate.

In ACTIVE, the following events are processed:

• GAP Inquiry result event: BTstack provides a unified inquiry result thatcontain Class of Device (CoD), page scan mode, clock offset. RSSI andname (from EIR) are optional.• Inquiry complete event: the remote name is requested for devices with-

out a fetched name. The state of a remote name can be one of the fol-lowing: REMOTE NAME REQUEST, REMOTE NAME INQUIRED,or REMOTE NAME FETCHED.• Remote name request complete event: the remote name is stored in the

table and the state is updated to REMOTE NAME FETCHED. Thequery of remote names is continued.

For more details on discovering remote devices, please see Section on GAP.

8.2.2. Main Application Setup. Listing here shows main application code. Itregisters the HCI packet handler and starts the Bluetooth stack.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;

Page 61: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

60

(void ) argv ;

// enab led EIRh c i s e t i n q u i r y m o d e (INQUIRY MODE RSSI AND EIR) ;

h c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;

return 0 ;}

Listing 21. Setup packet handler for GAP inquiry

8.3. sdp general query: Dump remote SDP Records. The example showshow the SDP Client is used to get a list of service records on a remote device.

8.3.1. SDP Client Setup. SDP is based on L2CAP. To receive SDP query eventsyou must register a callback, i.e. query handler, with the SPD parser, as shownin Listing here. Via this handler, the SDP client will receive the following events:

• SDP EVENT QUERY ATTRIBUTE VALUE containing the results ofthe query in chunks,• SDP EVENT QUERY COMPLETE indicating the end of the query and

the status

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void h a n d l e s d p c l i e n t q u e r y r e s u l t ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void s d p c l i e n t i n i t (void ) {// i n i t L2CAPl 2 c a p i n i t ( ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

}

Listing 22. SDP client setup

8.3.2. SDP Client Query. To trigger an SDP query to get the a list of servicerecords on a remote device, you need to call sdp client query uuid16() with theremote address and the UUID of the public browse group, as shown in Listinghere. In this example we used fixed address of the remote device shown inListing here. Please update it with the address of a device in your vicinity, e.g.,one reported by the GAP Inquiry example in the previous section.

Page 62: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

61

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

i f ( packet type != HCI EVENT PACKET) return ;u i n t 8 t event = h c i e v e n t p a c k e t g e t t y p e ( packet ) ;

switch ( event ) {case BTSTACK EVENT STATE:

// BTstack ac t i v a t ed , g e t s t a r t e di f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) ==

HCI STATE WORKING) {p r i n t f ( ” Connecting to %s \n” , b d a d d r t o s t r ( remote addr )

) ;s d p c l i e n t q u e r y u u i d 1 6 (& h a n d l e s d p c l i e n t q u e r y r e s u l t ,

remote addr , BLUETOOTH PROTOCOL L2CAP) ;}break ;

default :break ;

}}

Listing 23. Querying a list of service records on a remote device.

8.3.3. Handling SDP Client Query Results. The SDP Client returns the resultsof the query in chunks. Each result packet contains the record ID, the AttributeID, and a chunk of the Attribute value. In this example, we append new chunksfor the same Attribute ID in a large buffer, see Listing here.

To save memory, it’s also possible to process these chunks directly by a customstream parser, similar to the way XML files are parsed by a SAX parser. Have alook at src/sdp client rfcomm.c which retrieves the RFCOMM channel numberand the service name.

stat ic void h a n d l e s d p c l i e n t q u e r y r e s u l t ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( packet type ) ;UNUSED( channel ) ;UNUSED( s i z e ) ;

switch ( packet [ 0 ] ) {case SDP EVENT QUERY ATTRIBUTE VALUE:

// handle new recordi f ( s d p e v e n t q u e r y a t t r i b u t e b y t e g e t r e c o r d i d ( packet )

!= r e c o r d i d ) {

Page 63: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

62

r e c o r d i d = s d p e v e n t q u e r y a t t r i b u t e b y t e g e t r e c o r d i d( packet ) ;

p r i n t f ( ”\n−−−\nRecord nr . %u\n” , r e c o r d i d ) ;}

a s s e r t B u f f e r (s d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e l e n g t h (packet ) ) ;

a t t r i b u t e v a l u e [s d p e v e n t q u e r y a t t r i b u t e b y t e g e t d a t a o f f s e t ( packet )] = s d p e v e n t q u e r y a t t r i b u t e b y t e g e t d a t a ( packet ) ;

i f ( ( u i n t 1 6 t ) (s d p e v e n t q u e r y a t t r i b u t e b y t e g e t d a t a o f f s e t ( packet )+1) ==s d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e l e n g t h (packet ) ) {p r i n t f ( ” Att r ibute 0x%04x : ” ,

s d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e i d (packet ) ) ;

de dump data element ( a t t r i b u t e v a l u e ) ;}break ;

case SDP EVENT QUERY COMPLETE:i f ( s d p e v e n t q u e r y c o m p l e t e g e t s t a t u s ( packet ) ) {

p r i n t f ( ”SDP query f a i l e d 0x%02x\n” ,s d p e v e n t q u e r y c o m p l e t e g e t s t a t u s ( packet ) ) ;

break ;}p r i n t f ( ”SDP query done .\n” ) ;break ;

}}

Listing 24. Handling query result chunks.

8.4. sdp bnep query: Dump remote BNEP PAN protocol UUID andL2CAP PSM. The example shows how the SDP Client is used to get all BNEPservice records from a remote device. It extracts the remote BNEP PAN protocolUUID and the L2CAP PSM, which are needed to connect to a remote BNEPservice.

8.4.1. SDP Client Setup. As with the previous example, you must register acallback, i.e. query handler, with the SPD parser, as shown in Listing here. Viathis handler, the SDP client will receive events:

• SDP EVENT QUERY ATTRIBUTE VALUE containing the results ofthe query in chunks,• SDP EVENT QUERY COMPLETE reporting the status and the end of

the query.

Page 64: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

63

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void h a n d l e s d p c l i e n t q u e r y r e s u l t ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void s d p c l i e n t i n i t (void ) {// i n i t L2CAPl 2 c a p i n i t ( ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

}

Listing 25. SDP client setup

8.4.2. SDP Client Query.

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

i f ( packet type != HCI EVENT PACKET) return ;u i n t 8 t event = h c i e v e n t p a c k e t g e t t y p e ( packet ) ;

switch ( event ) {case BTSTACK EVENT STATE:

// BTstack ac t i v a t ed , g e t s t a r t e di f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) ==

HCI STATE WORKING) {p r i n t f ( ” Star t SDP BNEP query .\n” ) ;s d p c l i e n t q u e r y u u i d 1 6 (& h a n d l e s d p c l i e n t q u e r y r e s u l t ,

remote , BLUETOOTH PROTOCOL BNEP) ;}break ;

default :break ;

}}

Listing 26. Querying the a list of service records on a remote device.

8.4.3. Handling SDP Client Query Result. The SDP Client returns the result ofthe query in chunks. Each result packet contains the record ID, the AttributeID, and a chunk of the Attribute value, see Listing here. Here, we show how toparse the Service Class ID List and Protocol Descriptor List, as they contain theBNEP Protocol UUID and L2CAP PSM respectively.

Page 65: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

64

stat ic void h a n d l e s d p c l i e n t q u e r y r e s u l t ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( packet type ) ;UNUSED( channel ) ;UNUSED( s i z e ) ;

. . .

switch ( s d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e i d (packet ) ) {

// 0x0001 ” Serv i c e Class ID L i s t ”case BLUETOOTH ATTRIBUTE SERVICE CLASS ID LIST :

i f ( de ge t e l ement type ( a t t r i b u t e v a l u e ) != DE DES)break ;

for ( d e s i t e r a t o r i n i t (& d e s l i s t i t , a t t r i b u t e v a l u e) ; d e s i t e r a t o r h a s m o r e (& d e s l i s t i t ) ;d e s i t e r a t o r n e x t (& d e s l i s t i t ) ) {

u i n t 8 t ∗ element = d e s i t e r a t o r g e t e l e m e n t (&d e s l i s t i t ) ;

i f ( de ge t e l ement type ( element ) != DE UUID)continue ;

u i n t 3 2 t uuid = de get uu id32 ( element ) ;switch ( uuid ) {

case BLUETOOTH SERVICE CLASS PANU:case BLUETOOTH SERVICE CLASS NAP:case BLUETOOTH SERVICE CLASS GN:

p r i n t f ( ” ∗∗ Attr ibute 0x%04x : BNEP PANpro to co l UUID: %04x\n” ,s d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e i d( packet ) , ( int ) uuid ) ;

break ;default :

break ;}

}break ;

. . .case BLUETOOTH ATTRIBUTE PROTOCOL DESCRIPTOR LIST:{

p r i n t f ( ” ∗∗ Attr ibute 0x%04x : ” ,s d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e i d( packet ) ) ;

u i n t 1 6 t l2cap psm = 0 ;u i n t 1 6 t bnep ver s ion = 0 ;for ( d e s i t e r a t o r i n i t (& d e s l i s t i t ,

a t t r i b u t e v a l u e ) ; d e s i t e r a t o r h a s m o r e (&d e s l i s t i t ) ; d e s i t e r a t o r n e x t (& d e s l i s t i t ) ){

i f ( d e s i t e r a t o r g e t t y p e (& d e s l i s t i t ) !=DE DES) continue ;

u i n t 8 t ∗ des e l ement = d e s i t e r a t o r g e t e l e m e n t(& d e s l i s t i t ) ;

d e s i t e r a t o r i n i t (& p r o t i t , des e l ement ) ;

Page 66: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

65

u i n t 8 t ∗ element = d e s i t e r a t o r g e t e l e m e n t (&p r o t i t ) ;

i f ( de ge t e l ement type ( element ) != DE UUID)continue ;

u i n t 3 2 t uuid = de get uu id32 ( element ) ;d e s i t e r a t o r n e x t (& p r o t i t ) ;switch ( uuid ) {

case BLUETOOTH PROTOCOL L2CAP:i f ( ! d e s i t e r a t o r h a s m o r e (& p r o t i t ) )

continue ;d e e l ement ge t u in t16 (

d e s i t e r a t o r g e t e l e m e n t (& p r o t i t ) , &l2cap psm ) ;

break ;case BLUETOOTH PROTOCOL BNEP:

i f ( ! d e s i t e r a t o r h a s m o r e (& p r o t i t ) )continue ;

d e e l ement ge t u in t16 (d e s i t e r a t o r g e t e l e m e n t (& p r o t i t ) , &bnep ver s ion ) ;

break ;default :

break ;}

}p r i n t f ( ” l2cap psm 0x%04x , bnep ver s ion 0x%04x\n” ,

l2cap psm , bnep ver s ion ) ;}break ;

. . .}

Listing 27. Extracting BNEP Protcol UUID and L2CAP PSM

The Service Class ID List is a Data Element Sequence (DES) of UUIDs. TheBNEP PAN protocol UUID is within this list.

The Protocol Descriptor List is DES which contains one DES for each protocol.For PAN serivces, it contains a DES with the L2CAP Protocol UUID and a PSM,and another DES with the BNEP UUID and the the BNEP version.

8.5. spp counter: SPP Server - Heartbeat Counter over RFCOMM.The Serial port profile (SPP) is widely used as it provides a serial port overBluetooth. The SPP counter example demonstrates how to setup an SPP service,and provide a periodic timer over RFCOMM.

Note: To test, please run the spp counter example, and then pair from aremote device, and open the Virtual Serial Port.

8.5.1. SPP Service Setup. To provide an SPP service, the L2CAP, RFCOMM,and SDP protocol layers are required. After setting up an RFCOMM service withchannel nubmer RFCOMM SERVER CHANNEL, an SDP record is created andregistered with the SDP server. Example code for SPP service setup is provided

Page 67: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

66

in Listing here. The SDP record created by function spp create sdp record con-sists of a basic SPP definition that uses the provided RFCOMM channel ID andservice name. For more details, please have a look at it in src/sdp_util.c.The SDP record is created on the fly in RAM and is deterministic. To preservevaluable RAM, the result could be stored as constant data inside the ROM.

stat ic void s p p s e r v i c e s e t u p (void ) {

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

l 2 c a p i n i t ( ) ;

r f comm init ( ) ;r f c o m m r e g i s t e r s e r v i c e ( packet handler , RFCOMM SERVER CHANNEL,

0 x f f f f ) ; // re se rved channel , mtu l im i t e d by l2cap

// i n i t SDP, c r ea t e record f o r SPP and r e g i s t e r wi th SDPs d p i n i t ( ) ;memset ( s p p s e r v i c e b u f f e r , 0 , s izeof ( s p p s e r v i c e b u f f e r ) ) ;s p p c r e a t e s d p r e c o r d ( s p p s e r v i c e b u f f e r , 0x10001 ,

RFCOMM SERVER CHANNEL, ”SPP Counter” ) ;s d p r e g i s t e r s e r v i c e ( s p p s e r v i c e b u f f e r ) ;p r i n t f ( ”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n (

s p p s e r v i c e b u f f e r ) ) ;}

Listing 28. SPP service setup

8.5.2. Periodic Timer Setup. The heartbeat handler increases the real counterevery second, and sends a text string with the counter value, as shown in Listinghere.

stat ic b t s t a c k t i m e r s o u r c e t heartbeat ;stat ic char l i n e B u f f e r [ 3 0 ] ;stat ic void hear tbea t hand l e r ( struct b t s t a c k t i m e r s o u r c e ∗ t s ) {

stat ic int counter = 0 ;

i f ( r fcomm channel id ) {s p r i n t f ( l i n e B u f f e r , ”BTstack counter %04u\n” , ++counter ) ;p r i n t f ( ”%s ” , l i n e B u f f e r ) ;

r f comm request can send now event ( r fcomm channel id ) ;}

b t s t a c k r u n l o o p s e t t i m e r ( ts , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer ( t s ) ;

Page 68: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

67

}

stat ic void on e sh o t t i me r s e tu p (void ) {// s e t one−sho t t imerheartbeat . p roc e s s = &hear tbea t hand l e r ;b t s t a c k r u n l o o p s e t t i m e r (&heartbeat , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer (&heartbeat ) ;

}

Listing 29. Periodic Counter

8.5.3. Bluetooth Logic. The Bluetooth logic is implemented within the packethandler, see Listing here. In this example, the following events are passed se-quentially:

• BTSTACK EVENT STATE,• HCI EVENT PIN CODE REQUEST (Standard pairing) or• HCI EVENT USER CONFIRMATION REQUEST (Secure Simple Pair-

ing),• RFCOMM EVENT INCOMING CONNECTION,• RFCOMM EVENT CHANNEL OPENED,• RFCOMM EVENT CHANNEL CLOSED

Upon receiving HCI EVENT PIN CODE REQUEST event, we need to handleauthentication. Here, we use a fixed PIN code “0000”.

When HCI EVENT USER CONFIRMATION REQUEST is received, the userwill be asked to accept the pairing request. If the IO capability is set toSSP IO CAPABILITY DISPLAY YES NO, the request will be automaticallyaccepted.

The RFCOMM EVENT INCOMING CONNECTION event indicates an in-coming connection. Here, the connection is accepted. More logic is need, ifyou want to handle connections from multiple clients. The incoming RFCOMMconnection event contains the RFCOMM channel number used during the SPPsetup phase and the newly assigned RFCOMM channel ID that is used by allBTstack commands and events.

If RFCOMM EVENT CHANNEL OPENED event returns status greater then0, then the channel establishment has failed (rare case, e.g., client crashes). Onsuccessful connection, the RFCOMM channel ID and MTU for this channel aremade available to the heartbeat counter. After opening the RFCOMM chan-nel, the communication between client and the application takes place. In thisexample, the timer handler increases the real counter every second.

RFCOMM EVENT CAN SEND NOW indicates that it’s possible to send anRFCOMM packet on the rfcomm cid that is include

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;

Page 69: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

68

. . .case HCI EVENT PIN CODE REQUEST:

// inform about pin code r e que s tp r i n t f ( ”Pin code reque s t − us ing ’0000 ’\n” ) ;h c i e v e n t p i n c o d e r e q u e s t g e t b d a d d r ( packet ,

event addr ) ;gap p in code r e sponse ( event addr , ”0000” ) ;break ;

case HCI EVENT USER CONFIRMATION REQUEST:// ssp : inform about user conf i rmat ion r e que s tp r i n t f ( ”SSP User Conf irmation Request with numeric

va lue ’%06”PRIu32” ’\n” , l i t t l e e n d i a n r e a d 3 2 (packet , 8) ) ;

p r i n t f ( ”SSP User Conf irmation Auto accept \n” ) ;break ;

case RFCOMM EVENT INCOMING CONNECTION:// data : event (8) , l en (8) , address (48) , channel (8) ,

rfcomm cid (16)r f comm event incoming connect ion get bd addr ( packet ,

event addr ) ;r fcomm channel nr =

r f comm event incoming connec t i on ge t s e rve r channe l( packet ) ;

r fcomm channel id =r fcomm event incoming connect ion get r f comm cid (packet ) ;

p r i n t f ( ”RFCOMM channel %u reques ted f o r %s \n” ,rfcomm channel nr , b d a d d r t o s t r ( event addr ) ) ;

r fcomm accept connect ion ( r fcomm channel id ) ;break ;

case RFCOMM EVENT CHANNEL OPENED:// data : event (8) , l en (8) , s t a t u s (8) , address (48) ,

s e r v e r channel (8) , rfcomm cid (16) , max frame s i z e(16)

i f ( r f comm event channe l opened get s ta tus ( packet ) ) {p r i n t f ( ”RFCOMM channel open f a i l e d , s t a t u s %u\n” ,

r f comm event channe l opened get s ta tus ( packet ) ) ;} else {

r fcomm channel id =rfcomm event channe l opened get r fcomm cid (packet ) ;

mtu = rfcomm event channe l opened get max f rame s i ze( packet ) ;

p r i n t f ( ”RFCOMM channel open succeeded . New RFCOMMChannel ID %u , max frame s i z e %u\n” ,r fcomm channel id , mtu) ;

}break ;

case RFCOMM EVENT CAN SEND NOW:rfcomm send ( rfcomm channel id , ( u i n t 8 t ∗) l i n e B u f f e r ,

s t r l e n ( l i n e B u f f e r ) ) ;

Page 70: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

69

break ;

. . .}

Listing 30. SPP Server - Heartbeat Counter over RFCOMM

8.6. spp flowcontrol: SPP Server - Flow Control. This example adds ex-plicit flow control for incoming RFCOMM data to the SPP heartbeat counterexample. We will highlight the changes compared to the SPP counter example.

8.6.1. SPP Service Setup. Listing here shows how to provide one initial creditduring RFCOMM service initialization. Please note that providing a single crediteffectively reduces the credit-based (sliding window) flow control to a stop-and-wait flow control that limits the data throughput substantially.

stat ic void s p p s e r v i c e s e t u p (void ) {

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// i n i t L2CAPl 2 c a p i n i t ( ) ;

// i n i t RFCOMMr f comm init ( ) ;// re se rved channel , mtu l im i t e d by l2cap , 1 c r e d i tr f c o m m r e g i s t e r s e r v i c e w i t h i n i t i a l c r e d i t s (&packet handler ,

RFCOMM SERVER CHANNEL, 0 x f f f f , 1) ;

// i n i t SDP, c r ea t e record f o r SPP and r e g i s t e r wi th SDPs d p i n i t ( ) ;memset ( s p p s e r v i c e b u f f e r , 0 , s izeof ( s p p s e r v i c e b u f f e r ) ) ;s p p c r e a t e s d p r e c o r d ( s p p s e r v i c e b u f f e r , 0x10001 , 1 , ”SPP

Counter” ) ;s d p r e g i s t e r s e r v i c e ( s p p s e r v i c e b u f f e r ) ;p r i n t f ( ”SDP s e r v i c e b u f f e r s i z e : %u\n\ r ” , ( u i n t 1 6 t )

d e g e t l e n ( s p p s e r v i c e b u f f e r ) ) ;}

Listing 31. Providing one initial credit during RFCOMM service initialization

8.6.2. Periodic Timer Setup. Explicit credit management is recommended whenreceived RFCOMM data cannot be processed immediately. In this example,delayed processing of received data is simulated with the help of a periodic timeras follows. When the packet handler receives a data packet, it does not provide anew credit, it sets a flag instead, see Listing here. If the flag is set, a new creditwill be granted by the heartbeat handler, introducing a delay of up to 1 second.The heartbeat handler code is shown in Listing here.

Page 71: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

70

stat ic void hear tbea t hand l e r ( struct b t s t a c k t i m e r s o u r c e ∗ t s ) {i f ( r f comm send cred i t ) {

r f comm grant c r ed i t s ( r fcomm channel id , 1) ;r f comm send cred i t = 0 ;

}b t s t a c k r u n l o o p s e t t i m e r ( ts , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer ( t s ) ;

}

Listing 32. Heartbeat handler with manual credit management

// Blue too th l o g i cstat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 t

channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {. . .

case RFCOMM DATA PACKET:for ( i =0; i<s i z e ; i++){

putchar ( packet [ i ] ) ;} ;putchar ( ’ \n ’ ) ;r f comm send cred i t = 1 ;break ;

. . .}

Listing 33. Packet handler with manual credit management

8.7. panu demo: PANU Demo. This example implements both a PANUclient and a server. In server mode, it sets up a BNEP server and registersa PANU SDP record and waits for incoming connections. In client mode, itconnects to a remote device, does an SDP Query to identify the PANU serviceand initiates a BNEP connection.

Note: currently supported only on Linux and Mac.

8.7.1. Main application configuration. In the application configuration, L2CAPand BNEP are initialized and a BNEP service, for server mode, is registered,before the Bluetooth stack gets started, as shown in Listing here.

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void h a n d l e s d p c l i e n t q u e r y r e s u l t ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void network send packe t ca l l back ( const u i n t 8 t ∗ packet ,u i n t 1 6 t s i z e ) ;

Page 72: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

71

stat ic void panu setup (void ) {

// I n i t i a l i z e L2CAPl 2 c a p i n i t ( ) ;

// I n i t i a l i s e BNEPb n e p i n i t ( ) ;

// Minimum L2CAP MTU for bnep i s 1691 by t e sb n e p r e g i s t e r s e r v i c e ( packet handler ,

BLUETOOTH SERVICE CLASS PANU, 1691) ;

// i n i t SDP, c r ea t e record f o r PANU and r e g i s t e r wi th SDPs d p i n i t ( ) ;memset ( panu sdpp record , 0 , s izeof ( panu sdpp record ) ) ;u i n t 1 6 t network packet types [ ] = { NETWORK TYPE IPv4,

NETWORK TYPE ARP, 0} ; // 0 as end o f l i s tpan crea te panu sdp reco rd ( panu sdpp record ,

s d p c r e a t e s e r v i c e r e c o r d h a n d l e ( ) , network packet types ,NULL, NULL, BNEP SECURITY NONE) ;

p r i n t f ( ”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n ( ( u i n t 8 t ∗)panu sdpp record ) ) ;

// I n i t i a l i z e network i n t e r f a c eb t s t a c k n e t w o r k i n i t (& network send packe t ca l l back ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

}

Listing 34. Panu setup

8.7.2. SDP parser callback. The SDP parsers retrieves the BNEP PAN UUID asexplained in Section [on SDP BNEP Query example](#sec:sdpbnepqueryExample}.

8.7.3. Packet Handler. The packet handler responds to various HCI Events.

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e )

{. . .

switch ( packet type ) {case HCI EVENT PACKET:

event = h c i e v e n t p a c k e t g e t t y p e ( packet ) ;switch ( event ) {

case BTSTACK EVENT STATE:i f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) ==

HCI STATE WORKING) {p r i n t f ( ” Star t SDP BNEP query f o r remote PAN Network

Access Point (NAP) .\n” ) ;

Page 73: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

72

s d p c l i e n t q u e r y u u i d 1 6 (&h a n d l e s d p c l i e n t q u e r y r e s u l t , remote addr ,BLUETOOTH SERVICE CLASS NAP) ;

}break ;

. . .

case BNEP EVENT CHANNEL OPENED:i f ( bnep event channe l opened ge t s ta tu s ( packet ) ) {

p r i n t f ( ”BNEP channel open f a i l e d , s t a t u s %02x\n” ,bnep event channe l opened ge t s ta tu s ( packet ) ) ;

} else {bnep c id = bnep event channe l opened get bnep c id (

packet ) ;uu id source =

bnep event channe l opened ge t source uu id ( packet) ;

uu id des t =bnep even t channe l opened ge t de s t i na t i on uu id (packet ) ;

mtu = bnep event channe l opened get mtu ( packet ) ;memcpy(&event addr , &packet [ 1 1 ] , s izeof ( bd addr t ) ) ;p r i n t f ( ”BNEP connect ion open succeeded to %s source

UUID 0x%04x dest UUID: 0x%04x , max frame s i z e %u\n” , b d a d d r t o s t r ( event addr ) , uu id source ,uu id dest , mtu) ;

gap l o ca l bd addr ( l o c a l a d d r ) ;btstack network up ( l o c a l a d d r ) ;p r i n t f ( ”Network I n t e r f a c e %s ac t i va t ed \n” ,

btstack network get name ( ) ) ;}

break ;

case BNEP EVENT CHANNEL TIMEOUT:p r i n t f ( ”BNEP channel t imeout ! Channel w i l l be c l o s e d \n

” ) ;break ;

case BNEP EVENT CHANNEL CLOSED:p r i n t f ( ”BNEP channel c l o s e d \n” ) ;btstack network down ( ) ;break ;

case BNEP EVENT CAN SEND NOW:i f ( n e t w o r k b u f f e r l e n > 0) {

bnep send ( bnep cid , ( u i n t 8 t ∗) network buf f e r ,n e t w o r k b u f f e r l e n ) ;

n e t w o r k b u f f e r l e n = 0 ;b t s tack ne twork packe t s en t ( ) ;

}break ;

default :

Page 74: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

73

break ;}break ;

case BNEP DATA PACKET:// Write out the e t h e rne t frame to the network i n t e r f a c ebt s ta ck ne twork proce s s packe t ( packet , s i z e ) ;break ;

default :break ;

}}

Listing 35. Packet Handler

When BTSTACK EVENT STATE with state HCI STATE WORKING is re-ceived and the example is started in client mode, the remote SDP BNEP queryis started.

BNEP EVENT CHANNEL OPENED is received after a BNEP connectionwas established or or when the connection fails. The status field returns theerror code.

The TAP network interface is then configured. A data source is set up andregistered with the run loop to receive Ethernet packets from the TAP interface.

The event contains both the source and destination UUIDs, as well as theMTU for this connection and the BNEP Channel ID, which is used for sendingEthernet packets over BNEP.

If there is a timeout during the connection setup, BNEP EVENT CHANNEL TIMEOUTwill be received and the BNEP connection will be closed

BNEP EVENT CHANNEL CLOSED is received when the connection getsclosed.

BNEP EVENT CAN SEND NOW indicates that a new packet can be send.This triggers the send of a stored network packet. The tap datas source can beenabled again

Ethernet packets from the remote device are received in the packet handlerwith type BNEP DATA PACKET. It is forwarded to the TAP interface.

8.7.4. Network packet handler. A pointer to the network packet is stored and aBNEP EVENT CAN SEND NOW requested

stat ic void network send packe t ca l l back ( const u i n t 8 t ∗ packet ,u i n t 1 6 t s i z e ) {

network bu f f e r = packet ;n e t w o r k b u f f e r l e n = s i z e ;bnep request can send now event ( bnep c id ) ;

}

Listing 36. Network Packet Handler

Page 75: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

74

8.8. hsp hs demo: HSP Headset Demo. This example implements a HSPHeadset device that sends and receives audio signal over HCI SCO. It demon-strates how to receive an output from a remote audio gateway (AG), and, ifHAVE BTSTACK STDIN is defined, how to control the AG.

8.8.1. Audio Transfer Setup. A pre-computed sine wave (160Hz) is used as theinput audio signal. 160 Hz. To send and receive an audio signal, ENABLE SCO OVER HCIhas to be defined.

Tested working setups:

• Ubuntu 14 64-bit, CC2564B connected via FTDI USB-2-UART adapter,921600 baud• Ubuntu 14 64-bit, CSR USB dongle• OS X 10.11, CSR USB dongle

8.8.2. Main Application Setup. Listing here shows main application code. Torun a HSP Headset service you need to initialize the SDP, and to create andregister HSP HS record with it. In this example, the SCO over HCI is used toreceive and send an audio signal.

Two packet handlers are registered:

• The HCI SCO packet handler receives audio data.• The HSP HS packet handler is used to trigger sending of audio data and

commands to the AG. It also receives the AG’s answers.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

s co demo in i t ( ) ;s co demo set codec (HFP CODEC CVSD) ;

l 2 c a p i n i t ( ) ;

s d p i n i t ( ) ;memset ( h s p s e r v i c e b u f f e r , 0 , s izeof ( h s p s e r v i c e b u f f e r ) ) ;h s p h s c r e a t e s d p r e c o r d ( h s p s e r v i c e b u f f e r , 0x10001 ,

rfcomm channel nr , hsp hs serv i ce name , 0) ;s d p r e g i s t e r s e r v i c e ( h s p s e r v i c e b u f f e r ) ;

r f comm init ( ) ;

h s p h s i n i t ( r fcomm channel nr ) ;

// r e g i s t e r f o r HCI even t s and SCO packe t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;h c i r e g i s t e r s c o p a c k e t h a n d l e r (&packet hand le r ) ;

// r e g i s t e r f o r HSP even t s

Page 76: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

75

h s p h s r e g i s t e r p a c k e t h a n d l e r ( packet hand le r ) ;

#i f d e f HAVE BTSTACK STDINb t s t a c k s t d i n s e t u p ( s t d i n p r o c e s s ) ;

#e n d i f

gap s e t l o ca l name ( ”HSP HS Demo 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;g a p d i s c o v e r a b l e c o n t r o l (1 ) ;g a p s s p s e t i o c a p a b i l i t y (SSP IO CAPABILITY DISPLAY YES NO) ;g a p s e t c l a s s o f d e v i c e (0 x240404 ) ;

// Parse human readab l e B lue too th address .s s can f bd addr ( d e v i c e a d d r s t r i n g , dev i c e addr ) ;

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;return 0 ;

}

Listing 37. Setup HSP Headset

8.9. hsp ag demo: HSP Audio Gateway Demo. This example implementsa HSP Audio Gateway device that sends and receives audio signal over HCI SCO.It demonstrates how to receive an output from a remote headset (HS), and, ifHAVE BTSTACK STDIN is defined, how to control the HS.

8.9.1. Audio Transfer Setup. A pre-computed sine wave (160Hz) is used as theinput audio signal. 160 Hz. To send and receive an audio signal, ENABLE SCO OVER HCIhas to be defined.

Tested working setups:

• Ubuntu 14 64-bit, CC2564B connected via FTDI USB-2-UART adapter,921600 baud• Ubuntu 14 64-bit, CSR USB dongle• OS X 10.11, CSR USB dongle

8.9.2. Main Application Setup. Listing here shows main application code. Torun a HSP Audio Gateway service you need to initialize the SDP, and to createand register HSP AG record with it. In this example, the SCO over HCI is usedto receive and send an audio signal.

Two packet handlers are registered:

• The HCI SCO packet handler receives audio data.• The HSP AG packet handler is used to trigger sending of audio data and

commands to the HS. It also receives the AG’s answers.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

Page 77: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

76

s co demo in i t ( ) ;s co demo set codec (HFP CODEC CVSD) ;

l 2 c a p i n i t ( ) ;

s d p i n i t ( ) ;

memset ( ( u i n t 8 t ∗) h s p s e r v i c e b u f f e r , 0 , s izeof (h s p s e r v i c e b u f f e r ) ) ;

h s p a g c r e a t e s d p r e c o r d ( h s p s e r v i c e b u f f e r , 0x10001 ,rfcomm channel nr , hsp ag se rv i ce name ) ;

p r i n t f ( ”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n (h s p s e r v i c e b u f f e r ) ) ;

s d p r e g i s t e r s e r v i c e ( h s p s e r v i c e b u f f e r ) ;

r f comm init ( ) ;

h s p a g i n i t ( r fcomm channel nr ) ;h s p a g r e g i s t e r p a c k e t h a n d l e r (&packet hand le r ) ;

// r e g i s t e r f o r SCO packe t sh c i r e g i s t e r s c o p a c k e t h a n d l e r (&packet hand le r ) ;

// parse human readab l e B lue too th addresss s can f bd addr ( d e v i c e a d d r s t r i n g , dev i c e addr ) ;

#i f d e f HAVE BTSTACK STDINb t s t a c k s t d i n s e t u p ( s t d i n p r o c e s s ) ;

#e n d i f

gap s e t l o ca l name ( device name ) ;g a p d i s c o v e r a b l e c o n t r o l (1 ) ;g a p s s p s e t i o c a p a b i l i t y (SSP IO CAPABILITY DISPLAY YES NO) ;g a p s e t c l a s s o f d e v i c e (0 x400204 ) ;

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;return 0 ;

}

Listing 38. Setup HSP Audio Gateway

8.10. hfp hs demo: HFP Hands-Free (HF) Demo. This HFP Hands-Freeexample demonstrates how to receive an output from a remote HFP audio gate-way (AG), and, if HAVE BTSTACK STDIN is defined, how to control the HFPAG.

8.10.1. Main Application Setup. Listing here shows main application code. Torun a HFP HF service you need to initialize the SDP, and to create and registerHFP HF record with it. The packet handler is used for sending commands tothe HFP AG. It also receives the HFP AG’s answers. The stdin process callbackallows for sending commands to the HFP AG. At the end the Bluetooth stack isstarted.

Page 78: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

77

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

s co demo in i t ( ) ;

g a p d i s c o v e r a b l e c o n t r o l (1 ) ;g a p s e t c l a s s o f d e v i c e (0 x200408 ) ;gap s e t l o ca l name ( ”HFP HF Demo 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;

// i n i t L2CAPl 2 c a p i n i t ( ) ;

u i n t 1 6 t h f s u p p o r t e d f e a t u r e s =(1<<HFP HFSF ESCO S4) |(1<<HFP HFSF CLI PRESENTATION CAPABILITY) |(1<<HFP HFSF HF INDICATORS) |(1<<HFP HFSF CODEC NEGOTIATION) |(1<<HFP HFSF ENHANCED CALL STATUS) |(1<<HFP HFSF REMOTE VOLUME CONTROL) ;

int wide band speech = 1 ;

r fcomm init ( ) ;h f p h f i n i t ( r fcomm channel nr ) ;h f p h f i n i t s u p p o r t e d f e a t u r e s ( h f s u p p o r t e d f e a t u r e s ) ;h f p h f i n i t h f i n d i c a t o r s ( s izeof ( i n d i c a t o r s ) / s izeof ( u i n t 1 6 t ) ,

i n d i c a t o r s ) ;h f p h f i n i t c o d e c s ( s izeof ( codecs ) , codecs ) ;

s d p i n i t ( ) ;memset ( h f p s e r v i c e b u f f e r , 0 , s izeof ( h f p s e r v i c e b u f f e r ) ) ;h f p h f c r e a t e s d p r e c o r d ( h f p s e r v i c e b u f f e r , 0x10001 ,

rfcomm channel nr , h fp h f s e rv i c e name ,h f s u p p o r t e d f e a t u r e s , wide band speech ) ;

p r i n t f ( ”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n (h f p s e r v i c e b u f f e r ) ) ;

s d p r e g i s t e r s e r v i c e ( h f p s e r v i c e b u f f e r ) ;

// r e g i s t e r f o r HCI even t s and SCO packe t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;h c i r e g i s t e r s c o p a c k e t h a n d l e r (&packet hand le r ) ;h c i r e g i s t e r s c o p a c k e t h a n d l e r (&packet hand le r ) ;

// r e g i s t e r f o r HFP even t sh f p h f r e g i s t e r p a c k e t h a n d l e r ( packet hand le r ) ;

#i f d e f HAVE BTSTACK STDIN// parse human readab l e B lue too th addresss s can f bd addr ( d e v i c e a d d r s t r i n g , dev i c e addr ) ;

Page 79: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

78

b t s t a c k s t d i n s e t u p ( s t d i n p r o c e s s ) ;#e n d i f

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;return 0 ;

}

Listing 39. Setup HFP Hands-Free unit

8.11. hfp ag demo: HFP Audio Gateway (AG) Demo. This HFP AudioGateway example demonstrates how to receive an output from a remote HFPHands-Free (HF) unit, and, if HAVE BTSTACK STDIN is defined, how to con-trol the HFP HF.

8.11.1. Main Application Setup. Listing here shows main application code. Torun a HFP AG service you need to initialize the SDP, and to create and registerHFP AG record with it. The packet handler is used for sending commands tothe HFP HF. It also receives the HFP HF’s answers. The stdin process callbackallows for sending commands to the HFP HF. At the end the Bluetooth stack isstarted.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

s co demo in i t ( ) ;

gap s e t l o ca l name ( ”HFP AG Demo 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;g a p d i s c o v e r a b l e c o n t r o l (1 ) ;

// L2CAPl 2 c a p i n i t ( ) ;

u i n t 1 6 t s u p p o r t e d f e a t u r e s =(1<<HFP AGSF ESCO S4) |(1<<HFP AGSF HF INDICATORS) |(1<<HFP AGSF CODEC NEGOTIATION) |(1<<HFP AGSF EXTENDED ERROR RESULT CODES) |(1<<HFP AGSF ENHANCED CALL CONTROL) |(1<<HFP AGSF ENHANCED CALL STATUS) |(1<<HFP AGSF ABILITY TO REJECT A CALL) |(1<<HFP AGSF IN BAND RING TONE) |(1<<HFP AGSF VOICE RECOGNITION FUNCTION) |(1<<HFP AGSF THREE WAY CALLING) ;

int wide band speech = 1 ;

// HFPr f comm init ( ) ;h f p a g i n i t ( r fcomm channel nr ) ;

Page 80: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

79

h f p a g i n i t s u p p o r t e d f e a t u r e s ( s u p p o r t e d f e a t u r e s ) ;h f p a g i n i t c o d e c s ( s izeof ( codecs ) , codecs ) ;h f p a g i n i t a g i n d i c a t o r s ( a g i n d i c a t o r s n r , a g i n d i c a t o r s ) ;h f p a g i n i t h f i n d i c a t o r s ( h f i n d i c a t o r s n r , h f i n d i c a t o r s ) ;h f p a g i n i t c a l l h o l d s e r v i c e s ( c a l l h o l d s e r v i c e s n r ,

c a l l h o l d s e r v i c e s ) ;h fp ag s e t subc r i b e r number in f o rmat i on (&subscr iber number , 1)

;

// SDP Servers d p i n i t ( ) ;memset ( h f p s e r v i c e b u f f e r , 0 , s izeof ( h f p s e r v i c e b u f f e r ) ) ;h f p a g c r e a t e s d p r e c o r d ( h f p s e r v i c e b u f f e r , 0x10001 ,

rfcomm channel nr , h fp ag se rv i ce name , 0 ,suppor t ed f ea tu r e s , wide band speech ) ;

p r i n t f ( ”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n (h f p s e r v i c e b u f f e r ) ) ;

s d p r e g i s t e r s e r v i c e ( h f p s e r v i c e b u f f e r ) ;

// r e g i s t e r f o r HCI even t s and SCO packe t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;h c i r e g i s t e r s c o p a c k e t h a n d l e r (&packet hand le r ) ;

// r e g i s t e r f o r HFP even t sh f p a g r e g i s t e r p a c k e t h a n d l e r (&packet hand le r ) ;

// parse humand readab l e B lue too th addresss s can f bd addr ( d e v i c e a d d r s t r i n g , dev i c e addr ) ;

#i f d e f HAVE BTSTACK STDINb t s t a c k s t d i n s e t u p ( s t d i n p r o c e s s ) ;

#e n d i f// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;return 0 ;

}

Listing 40. Setup HFP Audio Gateway

8.12. gap le advertisements: GAP LE Advertisements Dumper. Thisexample shows how to scan and parse advertisements.

8.12.1. GAP LE setup for receiving advertisements. GAP LE advertisements arereceived as custom HCI events of the GAP EVENT ADVERTISING REPORTtype. To receive them, you’ll need to register the HCI packet handler, as shownin Listing here.

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 t channel, u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

Page 81: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

80

stat ic void g a p l e a d v e r t i s e m e n t s s e t u p (void ) {// Act ive scanning , 100% ( scan i n t e r v a l = scan window )gap se t s can paramete r s (1 , 48 ,48 ) ;g a p s t a r t s c a n ( ) ;

h c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

}

Listing 41. Setting up GAP LE client for receiving advertisements

8.12.2. GAP LE Advertising Data Dumper. Here, we use the definition of ad-vertising data types and flags as specified in Assigned Numbers GAP and Sup-plement to the Bluetooth Core Specification, v4.

stat ic const char ∗ ad types [ ] = {”” ,” Flags ” ,” Incomplete L i s t o f 16−b i t S e r v i c e Class UUIDs” ,”Complete L i s t o f 16−b i t S e r v i c e Class UUIDs” ,” Incomplete L i s t o f 32−b i t S e r v i c e Class UUIDs” ,”Complete L i s t o f 32−b i t S e r v i c e Class UUIDs” ,” Incomplete L i s t o f 128−b i t S e r v i c e Class UUIDs” ,”Complete L i s t o f 128−b i t S e r v i c e Class UUIDs” ,” Shortened Local Name” ,”Complete Local Name” ,”Tx Power Level ” ,”” ,”” ,” Class o f Device ” ,” Simple Pa i r ing Hash C” ,” Simple Pa i r ing Randomizer R” ,” Device ID” ,” Secur i ty Manager TK Value” ,” Slave Connection I n t e r v a l Range” ,”” ,” L i s t o f 16−b i t S e r v i c e S o l i c i t a t i o n UUIDs” ,” L i s t o f 128−b i t S e r v i c e S o l i c i t a t i o n UUIDs” ,” S e r v i c e Data” ,” Publ ic Target Address ” ,”Random Target Address ” ,”Appearance” ,” Adver t i s ing I n t e r v a l ”

} ;

stat ic const char ∗ f l a g s [ ] = {”LE Limited Di scoverab l e Mode” ,”LE General D i s cove rab l e Mode” ,”BR/EDR Not Supported ” ,” Simultaneous LE and BR/EDR to Same Device Capable ( C o n t r o l l e r

) ” ,

Page 82: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

81

” Simultaneous LE and BR/EDR to Same Device Capable ( Host ) ” ,” Reserved ” ,” Reserved ” ,” Reserved ”

} ;

Listing 42. Advertising data types and flags

BTstack offers an iterator for parsing sequence of advertising data (AD) struc-tures, see BLE advertisements parser API. After initializing the iterator, eachAD structure is dumped according to its type.

stat ic void dump advertisement data ( const u i n t 8 t ∗ adv data ,u i n t 8 t a d v s i z e ) {

ad con t ex t t context ;bd addr t address ;u i n t 8 t uuid 128 [ 1 6 ] ;for ( a d i t e r a t o r i n i t (&context , adv s i z e , ( u i n t 8 t ∗) adv data )

; a d i t e r a t o r h a s m o r e (&context ) ; a d i t e r a t o r n e x t (&context ) ) {

u i n t 8 t data type = a d i t e r a t o r g e t d a t a t y p e (&context ) ;u i n t 8 t s i z e = a d i t e r a t o r g e t d a t a l e n (&context ) ;const u i n t 8 t ∗ data = a d i t e r a t o r g e t d a t a (&context ) ;

i f ( data type > 0 && data type < 0x1B) {p r i n t f ( ” %s : ” , ad types [ data type ] ) ;

}int i ;// Assigned Numbers GAP

switch ( data type ) {case BLUETOOTH DATA TYPE FLAGS:

// show only f i r s t oc t e t , i gnore r e s tfor ( i =0; i <8; i++){

i f ( data [ 0 ] & (1<< i ) ) {p r i n t f ( ”%s ; ” , f l a g s [ i ] ) ;

}

}break ;

caseBLUETOOTH DATA TYPE INCOMPLETE LIST OF 16 BIT SERVICE CLASS UUIDS:

caseBLUETOOTH DATA TYPE COMPLETE LIST OF 16 BIT SERVICE CLASS UUIDS:

caseBLUETOOTH DATA TYPE LIST OF 16 BIT SERVICE SOLICITATION UUIDS:

for ( i =0; i<s i z e ; i +=2){p r i n t f ( ”%02X ” , l i t t l e e n d i a n r e a d 1 6 ( data , i ) ) ;

}

Page 83: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

82

break ;case

BLUETOOTH DATA TYPE INCOMPLETE LIST OF 32 BIT SERVICE CLASS UUIDS:

caseBLUETOOTH DATA TYPE COMPLETE LIST OF 32 BIT SERVICE CLASS UUIDS:

caseBLUETOOTH DATA TYPE LIST OF 32 BIT SERVICE SOLICITATION UUIDS:

for ( i =0; i<s i z e ; i +=4){p r i n t f ( ”%04”PRIX32 , l i t t l e e n d i a n r e a d 3 2 ( data , i ) ) ;

}break ;

caseBLUETOOTH DATA TYPE INCOMPLETE LIST OF 128 BIT SERVICE CLASS UUIDS:

caseBLUETOOTH DATA TYPE COMPLETE LIST OF 128 BIT SERVICE CLASS UUIDS:

caseBLUETOOTH DATA TYPE LIST OF 128 BIT SERVICE SOLICITATION UUIDS:

r e v e r s e 1 2 8 ( data , uuid 128 ) ;p r i n t f ( ”%s ” , u u i d 1 2 8 t o s t r ( uuid 128 ) ) ;break ;

case BLUETOOTH DATA TYPE SHORTENED LOCAL NAME:case BLUETOOTH DATA TYPE COMPLETE LOCAL NAME:

for ( i =0; i<s i z e ; i++){p r i n t f ( ”%c” , (char ) ( data [ i ] ) ) ;

}break ;

case BLUETOOTH DATA TYPE TX POWER LEVEL:p r i n t f ( ”%d dBm” , ∗( i n t 8 t ∗) data ) ;break ;

case BLUETOOTH DATA TYPE SLAVE CONNECTION INTERVAL RANGE:p r i n t f ( ” Connection I n t e r v a l Min = %u ms , Max = %u ms” ,

l i t t l e e n d i a n r e a d 1 6 ( data , 0) ∗ 5/4 ,l i t t l e e n d i a n r e a d 1 6 ( data , 2) ∗ 5/4) ;

break ;case BLUETOOTH DATA TYPE SERVICE DATA:

printf hexdump ( data , s i z e ) ;break ;

case BLUETOOTH DATA TYPE PUBLIC TARGET ADDRESS:case BLUETOOTH DATA TYPE RANDOM TARGET ADDRESS:

r eve r s e bd addr ( data , address ) ;p r i n t f ( ”%s ” , b d a d d r t o s t r ( address ) ) ;break ;

case BLUETOOTH DATA TYPE APPEARANCE:// h t t p s :// deve l ope r . b l u e t o o t h . org / g a t t / c h a r a c t e r i s t i c s /

Pages/Charac t e r i s t i cV iewer . aspx?u=org . b l u e t o o t h .c h a r a c t e r i s t i c . gap . appearance . xml

p r i n t f ( ”%02X” , l i t t l e e n d i a n r e a d 1 6 ( data , 0) ) ;break ;

Page 84: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

83

case BLUETOOTH DATA TYPE ADVERTISING INTERVAL:p r i n t f ( ”%u ms” , l i t t l e e n d i a n r e a d 1 6 ( data , 0) ∗ 5/8 ) ;break ;

case BLUETOOTH DATA TYPE 3D INFORMATION DATA:printf hexdump ( data , s i z e ) ;break ;

case BLUETOOTH DATA TYPE MANUFACTURER SPECIFIC DATA: //Manufacturer S p e c i f i c Data

break ;case BLUETOOTH DATA TYPE CLASS OF DEVICE:case BLUETOOTH DATA TYPE SIMPLE PAIRING HASH C:case BLUETOOTH DATA TYPE SIMPLE PAIRING RANDOMIZER R:case BLUETOOTH DATA TYPE DEVICE ID:case

BLUETOOTH DATA TYPE SECURITY MANAGER OUT OF BAND FLAGS:

default :p r i n t f ( ” Adver t i s ing Data Type 0x%2x not handled yet ” ,

data type ) ;break ;

}p r i n t f ( ”\n” ) ;

}p r i n t f ( ”\n” ) ;

}

Listing 43. Parsing advertising data

8.12.3. HCI packet handler. The HCI packet handler has to start the scanning,and to handle received advertisements. Advertisements are received as HCI eventpackets of the GAP EVENT ADVERTISING REPORT type, see Listing here.

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 t channel, u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

i f ( packet type != HCI EVENT PACKET) return ;

switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {case GAP EVENT ADVERTISING REPORT:{

bd addr t address ;g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s ( packet , address ) ;u i n t 8 t event type =

g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d v e r t i s i n g e v e n t t y p e( packet ) ;

u i n t 8 t addre s s type =g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s t y p e ( packet ) ;

i n t 8 t r s s i = g a p e v e n t a d v e r t i s i n g r e p o r t g e t r s s i ( packet) ;

Page 85: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

84

u i n t 8 t l ength =g a p e v e n t a d v e r t i s i n g r e p o r t g e t d a t a l e n g t h ( packet ) ;

const u i n t 8 t ∗ data =g a p e v e n t a d v e r t i s i n g r e p o r t g e t d a t a ( packet ) ;

p r i n t f ( ” Advertisement event : evt−type %u , addr−type %u ,addr %s , r s s i %d , data [%u ] ” , event type ,address type , b d a d d r t o s t r ( address ) , r s s i , l ength ) ;

printf hexdump ( data , l ength ) ;dump advertisement data ( data , l ength ) ;break ;

}default :

break ;}

}

Listing 44. Scanning and receiving advertisements

8.13. gatt browser: GATT Client - Discovering primary services andtheir characteristics. This example shows how to use the GATT Client APIto discover primary services and their characteristics of the first found devicethat is advertising its services.

The logic is divided between the HCI and GATT client packet handlers. TheHCI packet handler is responsible for finding a remote device, connecting to it,and for starting the first GATT client query. Then, the GATT client packethandler receives all primary services and requests the characteristics of the lastone to keep the example short.

8.13.1. GATT client setup. In the setup phase, a GATT client must register theHCI and GATT client packet handlers, as shown in Listing here. Additionally,the security manager can be setup, if signed writes, or encrypted, or authen-ticated connection are required, to access the characteristics, as explained inSection on SMP.

// Handles connect , d i sconnect , and a d v e r t i s i n g repor t events ,// s t a r t s the GATT c l i e n t , and sends the f i r s t query .stat ic void ha nd l e hc i ev en t ( u i n t 8 t packet type , u i n t 1 6 t

channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

// Handles GATT c l i e n t query r e s u l t s , sends que r i e s and the// GAP disconnec t command when the query ing i s done .stat ic void h a n d l e g a t t c l i e n t e v e n t ( u i n t 8 t packet type ,

u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void g a t t c l i e n t s e t u p (void ) {

// I n i t i a l i z e L2CAP and r e g i s t e r HCI event hand lerl 2 c a p i n i t ( ) ;

Page 86: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

85

// I n i t i a l i z e GATT c l i e n tg a t t c l i e n t i n i t ( ) ;

// Opt inoa l l y , Setup s e c u r i t y managers m i n i t ( ) ;s m s e t i o c a p a b i l i t i e s (IO CAPABILITY NO INPUT NO OUTPUT) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &han d l e hc i ev en t ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

}

Listing 45. Setting up GATT client

8.13.2. HCI packet handler. The HCI packet handler has to start the scanning,to find the first advertising device, to stop scanning, to connect to and later to dis-connect from it, to start the GATT client upon the connection is completed, andto send the first query - in this case the gatt client discover primary services()is called, see Listing here.

stat ic void ha nd l e hc i ev en t ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

i f ( packet type != HCI EVENT PACKET) return ;a d v e r t i s i n g r e p o r t t r epo r t ;

u i n t 8 t event = h c i e v e n t p a c k e t g e t t y p e ( packet ) ;switch ( event ) {

case BTSTACK EVENT STATE:// BTstack ac t i v a t ed , g e t s t a r t e di f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) !=

HCI STATE WORKING) break ;i f ( cmdl ine addr found ) {

p r i n t f ( ” Trying to connect to %s \n” , b d a d d r t o s t r (cmdl ine addr ) ) ;

gap connect ( cmdline addr , 0) ;break ;

}p r i n t f ( ”BTstack act ivated , s t a r t scanning !\n” ) ;gap se t s can paramete r s (0 ,0 x0030 , 0x0030 ) ;g a p s t a r t s c a n ( ) ;break ;

case GAP EVENT ADVERTISING REPORT:f i l l a d v e r t i s i n g r e p o r t f r o m p a c k e t (&report , packet ) ;dump adver t i s ing repor t (& repor t ) ;

// s top scanning , and connect to the dev i c egap s top scan ( ) ;

Page 87: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

86

gap connect ( r epo r t . address , r epor t . addre s s type ) ;break ;

case HCI EVENT LE META:// wai t f o r connect ion completei f ( h c i e v e n t l e m e t a g e t s u b e v e n t c o d e ( packet ) !=

HCI SUBEVENT LE CONNECTION COMPLETE) break ;c onnec t i on hand l e r =

h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ;

// query primary s e r v i c e sg a t t c l i e n t d i s c o v e r p r i m a r y s e r v i c e s (

h a n d l e g a t t c l i e n t e v e n t , connec t i on hand l e r ) ;break ;

case HCI EVENT DISCONNECTION COMPLETE:p r i n t f ( ”\nGATT browser − DISCONNECTED\n” ) ;break ;

default :break ;

}}

Listing 46. Connecting and disconnecting from the GATT client

8.13.3. GATT Client event handler. Query results and further queries are han-dled by the GATT client packet handler, as shown in Listing here. Here, upon re-ceiving the primary services, the gatt client discover characteristics for service()query for the last received service is sent. After receiving the characteristics forthe service, gap disconnect is called to terminate the connection. Upon discon-nect, the HCI packet handler receives the disconnect complete event.

stat ic int s e a r c h s e r v i c e s = 1 ;

stat ic void h a n d l e g a t t c l i e n t e v e n t ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( packet type ) ;UNUSED( channel ) ;UNUSED( s i z e ) ;

g a t t c l i e n t s e r v i c e t s e r v i c e ;g a t t c l i e n t c h a r a c t e r i s t i c t c h a r a c t e r i s t i c ;switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case GATT EVENT SERVICE QUERY RESULT:\g a t t e v e n t s e r v i c e q u e r y r e s u l t g e t s e r v i c e ( packet , &

s e r v i c e ) ;dump service(& s e r v i c e ) ;s e r v i c e s [ s e r v i c e c o u n t ++] = s e r v i c e ;break ;

case GATT EVENT CHARACTERISTIC QUERY RESULT:g a t t e v e n t c h a r a c t e r i s t i c q u e r y r e s u l t g e t c h a r a c t e r i s t i c (

packet , &c h a r a c t e r i s t i c ) ;dump charac t e r i s t i c (& c h a r a c t e r i s t i c ) ;

Page 88: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

87

break ;case GATT EVENT QUERY COMPLETE:

i f ( s e a r c h s e r v i c e s ) {// GATT EVENTQUERYCOMPLETE of search s e r v i c e ss e r v i c e i n d e x = 0 ;p r i n t f ( ”\nGATT browser − CHARACTERISTIC f o r SERVICE %s \n

” , u u i d 1 2 8 t o s t r ( s e r v i c e . uuid128 ) ) ;s e a r c h s e r v i c e s = 0 ;g a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c s f o r s e r v i c e (

h a n d l e g a t t c l i e n t e v e n t , connect ion hand le r , &s e r v i c e s [ s e r v i c e i n d e x ] ) ;

} else {// GATT EVENTQUERYCOMPLETE of search c h a r a c t e r i s t i c si f ( s e r v i c e i n d e x < s e r v i c e c o u n t ) {

s e r v i c e = s e r v i c e s [ s e r v i c e i n d e x ++];p r i n t f ( ”\nGATT browser − CHARACTERISTIC f o r SERVICE %s

, [ 0 x%04x−0x%04x ]\n” ,u u i d 1 2 8 t o s t r ( s e r v i c e . uuid128 ) , s e r v i c e .

s ta r t g roup hand l e , s e r v i c e . end group handle ) ;g a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c s f o r s e r v i c e (

h a n d l e g a t t c l i e n t e v e n t , connect ion hand le r , &s e r v i c e ) ;

break ;}s e r v i c e i n d e x = 0 ;gap d i s connect ( connec t i on hand l e r ) ;

}break ;

default :break ;

}}

Listing 47. Handling of the GATT client queries

8.14. le counter: LE Peripheral - Heartbeat Counter over GATT. Allnewer operating systems provide GATT Client functionality. The LE Counterexamples demonstrates how to specify a minimal GATT Database with a customGATT Service and a custom Characteristic that sends periodic notifications.

8.14.1. Main Application Setup. Listing here shows main application code. Itinitializes L2CAP, the Security Manager and configures the ATT Server withthe pre-compiled ATT Database generated from lecounter.gatt. Additionally,it enables the Battery Service Server with the current battery level. Finally, itconfigures the advertisements and the heartbeat handler and boots the Bluetoothstack. In this example, the Advertisement contains the Flags attribute andthe device name. The flag 0x06 indicates: LE General Discoverable Mode andBR/EDR not supported.

stat ic int l e n o t i f i c a t i o n e n a b l e d ;

Page 89: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

88

stat ic b t s t a c k t i m e r s o u r c e t heartbeat ;stat ic b t s t a c k p a c k e t c a l l b a c k r e g i s t r a t i o n t

h c i e v e n t c a l l b a c k r e g i s t r a t i o n ;stat ic h c i c o n h a n d l e t con handle ;stat ic u i n t 8 t bat te ry = 100 ;

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic u i n t 1 6 t a t t r e a d c a l l b a c k ( h c i c o n h a n d l e t con handle ,u i n t 1 6 t at t hand le , u i n t 1 6 t o f f s e t , u i n t 8 t ∗ bu f f e r ,u i n t 1 6 t b u f f e r s i z e ) ;

stat ic int a t t w r i t e c a l l b a c k ( h c i c o n h a n d l e t con handle ,u i n t 1 6 t at t hand le , u i n t 1 6 t transact ion mode , u i n t 1 6 to f f s e t , u i n t 8 t ∗ bu f f e r , u i n t 1 6 t b u f f e r s i z e ) ;

stat ic void hear tbea t hand l e r ( struct b t s t a c k t i m e r s o u r c e ∗ t s ) ;stat ic void beat (void ) ;

const u i n t 8 t adv data [ ] = {// Flags genera l d i s c o v e ra b l e , BR/EDR not suppor ted0x02 , BLUETOOTH DATA TYPE FLAGS, 0x06 ,// Name0x0b , BLUETOOTH DATA TYPE COMPLETE LOCAL NAME, ’L ’ , ’E ’ , ’ ’ ,

’C ’ , ’ o ’ , ’ u ’ , ’ n ’ , ’ t ’ , ’ e ’ , ’ r ’ ,// Incomplete L i s t o f 16− b i t Se rv i c e Class UUIDs −− FF10 −

only v a l i d f o r t e s t i n g !0x03 ,

BLUETOOTH DATA TYPE INCOMPLETE LIST OF 16 BIT SERVICE CLASS UUIDS, 0x10 , 0 x f f ,

} ;const u i n t 8 t adv data l en = s izeof ( adv data ) ;

stat ic void l e c o u n t e r s e t u p (void ) {

l 2 c a p i n i t ( ) ;

// se tup l e dev i c e dbl e d e v i c e d b i n i t ( ) ;

// se tup SM: Disp lay on lys m i n i t ( ) ;

// se tup ATT serve ra t t s e r v e r i n i t ( p r o f i l e d a t a , a t t r e a d c a l l b a c k ,

a t t w r i t e c a l l b a c k ) ;

// se tup b a t t e r y s e r v i c eb a t t e r y s e r v i c e s e r v e r i n i t ( bat te ry ) ;

// se tup adver t i s ement su i n t 1 6 t adv int min = 0x0030 ;u i n t 1 6 t adv int max = 0x0030 ;u i n t 8 t adv type = 0 ;bd addr t nu l l add r ;memset ( nu l l addr , 0 , 6) ;

Page 90: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

89

gap adver t i s ements se t params ( adv int min , adv int max ,adv type , 0 , nu l l addr , 0x07 , 0x00 ) ;

gap adve r t i s ement s s e t da ta ( adv data len , ( u i n t 8 t ∗) adv data );

gap adver t i s ement s enab l e (1 ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// r e g i s t e r f o r ATT eventa t t s e r v e r r e g i s t e r p a c k e t h a n d l e r ( packet hand le r ) ;

// s e t one−sho t t imerheartbeat . p roc e s s = &hear tbea t hand l e r ;b t s t a c k r u n l o o p s e t t i m e r (&heartbeat , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer (&heartbeat ) ;

// bea t oncebeat ( ) ;

}

Listing 48. Init L2CAP SM ATT Server and start heartbeat timer

8.14.2. Heartbeat Handler. The heartbeat handler updates the value of the singleCharacteristic provided in this example, and request a ATT EVENT CAN SEND NOWto send a notification if enabled see Listing here.

stat ic int counter = 0 ;stat ic char c o u n t e r s t r i n g [ 3 0 ] ;stat ic int c o u n t e r s t r i n g l e n ;

stat ic void beat (void ) {counter++;c o u n t e r s t r i n g l e n = s p r i n t f ( c o u n t e r s t r i n g , ”BTstack counter

%04u” , counter ) ;puts ( c o u n t e r s t r i n g ) ;

}

stat ic void hear tbea t hand l e r ( struct b t s t a c k t i m e r s o u r c e ∗ t s ) {i f ( l e n o t i f i c a t i o n e n a b l e d ) {

beat ( ) ;a t t s e r v e r r e q u e s t c a n s e n d n o w e v e n t ( con handle ) ;

}

// s imu la t e b a t t e r y drainbattery−−;i f ( bat te ry < 50) {

batte ry = 100 ;}b a t t e r y s e r v i c e s e r v e r s e t b a t t e r y v a l u e ( bat te ry ) ;

Page 91: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

90

b t s t a c k r u n l o o p s e t t i m e r ( ts , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer ( t s ) ;

}

Listing 49. Hearbeat Handler

8.14.3. Packet Handler. The packet handler is used to:

• stop the counter after a disconnect• send a notification when the requested ATT EVENT CAN SEND NOW

is received

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

switch ( packet type ) {case HCI EVENT PACKET:

switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {case HCI EVENT DISCONNECTION COMPLETE:

l e n o t i f i c a t i o n e n a b l e d = 0 ;break ;

case ATT EVENT CAN SEND NOW:a t t s e r v e r n o t i f y ( con handle ,

ATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE, ( u i n t 8 t ∗) c o u n t e r s t r i n g , c o u n t e r s t r i n g l e n ) ;

break ;}break ;

}}

Listing 50. Packet Handler

8.14.4. ATT Read. The ATT Server handles all reads to constant data. Fordynamic data like the custom characteristic, the registered att read callback iscalled. To handle long characteristics and long reads, the att read callback isfirst called with buffer == NULL, to request the total value length. Then it willbe called again requesting a chunk of the value. See Listing here.

// ATT Cl i en t Read Ca l l back f o r Dynamic Data// − i f b u f f e r == NULL, don ’ t copy data , j u s t re turn s i z e o f

va lue// − i f b u f f e r != NULL, copy data and re turn number by t e s copied// @param o f f s e t d e f i n e s s t a r t o f a t t r i b u t e va lue

Page 92: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

91

stat ic u i n t 1 6 t a t t r e a d c a l l b a c k ( h c i c o n h a n d l e tconnect ion handle , u i n t 1 6 t at t hand le , u i n t 1 6 t o f f s e t ,u i n t 8 t ∗ bu f f e r , u i n t 1 6 t b u f f e r s i z e ) {

UNUSED( connect ion hand le ) ;

i f ( a t t hand l e ==ATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE) {

return a t t r e a d c a l l b a c k h a n d l e b l o b ( ( const u i n t 8 t ∗)c o u n t e r s t r i n g , b u f f e r s i z e , o f f s e t , bu f f e r , b u f f e r s i z e) ;

}return 0 ;

}

Listing 51. ATT Read

8.14.5. ATT Write. The only valid ATT write in this example is to the ClientCharacteristic Configuration, which configures notification and indication. If theATT handle matches the client configuration handle, the new configuration valueis stored and used in the heartbeat handler to decide if a new value should besent. See Listing here.

stat ic int a t t w r i t e c a l l b a c k ( h c i c o n h a n d l e t connect ion handle, u i n t 1 6 t at t hand le , u i n t 1 6 t transact ion mode , u i n t 1 6 to f f s e t , u i n t 8 t ∗ bu f f e r , u i n t 1 6 t b u f f e r s i z e ) {

UNUSED( transact ion mode ) ;UNUSED( o f f s e t ) ;UNUSED( b u f f e r s i z e ) ;

i f ( a t t hand l e !=ATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE) return 0 ;

l e n o t i f i c a t i o n e n a b l e d = l i t t l e e n d i a n r e a d 1 6 ( bu f f e r , 0) ==GATT CLIENT CHARACTERISTICS CONFIGURATION NOTIFICATION;

con handle = connect ion hand le ;return 0 ;

}

Listing 52. ATT Write

8.15. le streamer: LE Streamer - Stream data over GATT.. All neweroperating systems provide GATT Client functionality. This example shows howto get a maximal throughput via BLE:

• send whenever possible,• use the max ATT MTU.

In theory, we should also update the connection parameters, but we alreadyget a connection interval of 30 ms and there’s no public way to use a shorterinterval with iOS (if we’re not implementing an HID device).

Page 93: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

92

Note: To start the streaming, run the example. On remote device use someGATT Explorer, e.g. LightBlue, BLExplr to enable notifications.

8.15.1. Main Application Setup. Listing here shows main application code. Itinitializes L2CAP, the Security Manager, and configures the ATT Server withthe pre-compiled ATT Database generated from lestreamer.gatt. Finally, itconfigures the advertisements and boots the Bluetooth stack.

stat ic void l e s t r e a m e r s e t u p (void ) {

l 2 c a p i n i t ( ) ;

// se tup l e dev i c e dbl e d e v i c e d b i n i t ( ) ;

// se tup SM: Disp lay on lys m i n i t ( ) ;

// se tup ATT serve ra t t s e r v e r i n i t ( p r o f i l e d a t a , NULL, a t t w r i t e c a l l b a c k ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &h c i p a c k e t h a n d l e r

;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// r e g i s t e r f o r ATT even t sa t t s e r v e r r e g i s t e r p a c k e t h a n d l e r ( a t t p a c k e t h a n d l e r ) ;

// se tup adver t i s ement su i n t 1 6 t adv int min = 0x0030 ;u i n t 1 6 t adv int max = 0x0030 ;u i n t 8 t adv type = 0 ;bd addr t nu l l add r ;memset ( nu l l addr , 0 , 6) ;gap adver t i s ements se t params ( adv int min , adv int max ,

adv type , 0 , nu l l addr , 0x07 , 0x00 ) ;gap adve r t i s ement s s e t da ta ( adv data len , ( u i n t 8 t ∗) adv data )

;gap adver t i s ement s enab l e (1 ) ;

// i n i t c l i e n t s t a t ei n i t c o n n e c t i o n s ( ) ;

}

Listing 53. Init L2CAP, SM, ATT Server, and enable advertisements

8.15.2. Track throughput. We calculate the throughput by setting a start timeand measuring the amount of data sent. After a configurable REPORT INTERVAL MS,we print the throughput in kB/s and reset the counter and start time.

Page 94: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

93

stat ic void t e s t r e s e t ( l e s t r e a m e r c o n n e c t i o n t ∗ context ) {context−>t e s t d a t a s t a r t = bt s ta ck run l oop ge t t ime ms ( ) ;context−>t e s t d a t a s e n t = 0 ;

}

stat ic void t e s t t r a c k s e n t ( l e s t r e a m e r c o n n e c t i o n t ∗ context ,int b y t e s s e n t ) {

context−>t e s t d a t a s e n t += b y t e s s e n t ;// eva l ua t eu i n t 3 2 t now = bt s ta ck run l oop ge t t ime ms ( ) ;u i n t 3 2 t t ime passed = now − context−>t e s t d a t a s t a r t ;i f ( t ime passed < REPORT INTERVAL MS) return ;// p r i n t speedint byte s pe r s e cond = context−>t e s t d a t a s e n t ∗ 1000 /

t ime passed ;p r i n t f ( ”%c : %”PRIu32” bytes sent−> %u.%03u kB/ s \n” , context−>

name , context−>t e s t d a t a s e n t , by t e s pe r s e cond / 1000 ,by t e s pe r s e cond % 1000) ;

// r e s t a r tcontext−>t e s t d a t a s t a r t = now ;context−>t e s t d a t a s e n t = 0 ;

}

Listing 54. Tracking throughput

8.15.3. HCI Packet Handler. The packet handler is used track incoming connec-tions and to stop notifications on disconnect It is also a good place to requestthe connection parameter update as indicated in the commented code block.

stat ic void h c i p a c k e t h a n d l e r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

u i n t 1 6 t c o n n i n t e r v a l ;l e s t r e a m e r c o n n e c t i o n t ∗ context ;switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case BTSTACK EVENT STATE:// BTstack ac t i v a t ed , g e t s t a r t e di f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) ==

HCI STATE WORKING) {

Page 95: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

94

p r i n t f ( ”To s t a r t the streaming , p l e a s e run thel e s t r e a m e r c l i e n t example on other device , oruse some GATT Explorer , e . g . LightBlue , BLExplr.\n” ) ;

}break ;

case HCI EVENT DISCONNECTION COMPLETE:context = connec t i on f o r conn hand l e (

h c i e v e n t d i s c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ) ;

i f ( ! context ) break ;// f r e e connect ionp r i n t f ( ”%c : Disconnect , reason %02x\n” , context−>name ,

h c i e v e n t d i s c o n n e c t i o n c o m p l e t e g e t r e a s o n (packet ) ) ;

context−>l e n o t i f i c a t i o n e n a b l e d = 0 ;context−>connect ion hand le = HCI CON HANDLE INVALID;break ;

case HCI EVENT LE META:switch ( h c i e v e n t l e m e t a g e t s u b e v e n t c o d e ( packet ) ) {

case HCI SUBEVENT LE CONNECTION COMPLETE:// se tup newcontext = connec t i on f o r conn hand l e (

HCI CON HANDLE INVALID) ;i f ( ! context ) break ;context−>counter = ’A ’ ;context−>t e s t d a t a l e n = ATT DEFAULT MTU − 3 ;context−>connect ion hand le =

h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ;

// p r i n t connect ion parameters ( wi thou t us ingf l o a t opera t i ons )

c o n n i n t e r v a l =h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n i n t e r v a l( packet ) ;

p r i n t f ( ”%c : Connection I n t e r v a l : %u.%02u ms ,l a t ency %u\n” , context−>name , c o n n i n t e r v a l ∗125 / 100 ,

25 ∗ ( c o n n i n t e r v a l & 3) ,h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n l a t e n c y( packet ) ) ;

// r e que s t min con i n t e r v a l 15 ms f o r iOS 11+// gap reques t connec t i on paramete r upda t e ( contex t−>connect ion hand le , 12 , 12 , 0 , 0x0048 ) ;

break ;case HCI SUBEVENT LE CONNECTION UPDATE COMPLETE:

// p r i n t connect ion parameters ( wi thou t us ingf l o a t opera t i ons )

context = connec t i on f o r conn hand l e (h c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ) ;

i f ( ! context ) break ;

Page 96: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

95

c o n n i n t e r v a l =h c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n i n t e r v a l( packet ) ;

p r i n t f ( ”%c : Connection I n t e r v a l : %u.%02u ms ,l a t ency %u\n” , context−>name , c o n n i n t e r v a l ∗125 / 100 ,

25 ∗ ( c o n n i n t e r v a l & 3) ,h c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n l a t e n c y( packet ) ) ;

break ;default :

break ;}break ;

default :break ;

}}

}

Listing 55. Packet Handler

8.15.4. ATT Packet Handler. The packet handler is used to track the ATT MTUExchange and trigger ATT send

stat ic void a t t p a c k e t h a n d l e r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

int mtu ;l e s t r e a m e r c o n n e c t i o n t ∗ context ;switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case ATT EVENT MTU EXCHANGE COMPLETE:mtu = att event mtu exchange complete get MTU ( packet )− 3 ;

context = connec t i on f o r conn hand l e (a t t event mtu exchange comple te ge t hand l e ( packet )) ;

i f ( ! context ) break ;context−>t e s t d a t a l e n = btstack min (mtu − 3 , s izeof (

context−>t e s t d a t a ) ) ;p r i n t f ( ”%c : ATT MTU = %u => use t e s t data o f l en %u\n”

, context−>name , mtu , context−>t e s t d a t a l e n ) ;break ;

case ATT EVENT CAN SEND NOW:streamer ( ) ;break ;

default :

Page 97: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

96

break ;}break ;

default :break ;

}}

Listing 56. Packet Handler

8.15.5. Streamer. The streamer function checks if notifications are enabled andif a notification can be sent now. It creates some test data - a single letter thatgets increased every time - and tracks the data sent.

stat ic void streamer (void ) {

// f i nd next a c t i v e streaming connect ionint o l d c o n n e c t i o n i n d e x = connec t i on index ;while (1 ) {

// a c t i v e found?i f ( ( l e s t r e a m e r c o n n e c t i o n s [ connec t i on index ] .

connect ion hand le != HCI CON HANDLE INVALID) &&( l e s t r e a m e r c o n n e c t i o n s [ connec t i on index ] .

l e n o t i f i c a t i o n e n a b l e d ) ) break ;

// check nextnext connec t i on index ( ) ;

// none foundi f ( connec t i on index == o l d c o n n e c t i o n i n d e x ) return ;

}

l e s t r e a m e r c o n n e c t i o n t ∗ context = &l e s t r e a m e r c o n n e c t i o n s [connec t i on index ] ;

// crea t e t e s t datacontext−>counter++;i f ( context−>counter > ’Z ’ ) context−>counter = ’A ’ ;memset ( context−>t e s t da ta , context−>counter , context−>

t e s t d a t a l e n ) ;

// senda t t s e r v e r n o t i f y ( context−>connect ion handle , context−>

value handle , ( u i n t 8 t ∗) context−>t e s t da ta , context−>t e s t d a t a l e n ) ;

// t rackt e s t t r a c k s e n t ( context , context−>t e s t d a t a l e n ) ;

// r e que s t next send event

Page 98: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

97

a t t s e r v e r r e q u e s t c a n s e n d n o w e v e n t ( context−>connect ion hand le ) ;

// check nextnext connec t i on index ( ) ;

}

Listing 57. Streaming code

8.15.6. ATT Write. The only valid ATT write in this example is to the ClientCharacteristic Configuration, which configures notification and indication. Ifthe ATT handle matches the client configuration handle, the new configurationvalue is stored. If notifications get enabled, an ATT EVENT CAN SEND NOWis requested. See Listing here.

stat ic int a t t w r i t e c a l l b a c k ( h c i c o n h a n d l e t con handle ,u i n t 1 6 t at t hand le , u i n t 1 6 t transact ion mode , u i n t 1 6 to f f s e t , u i n t 8 t ∗ bu f f e r , u i n t 1 6 t b u f f e r s i z e ) {

UNUSED( o f f s e t ) ;

// p r i n t f (” a t t w r i t e c a l l b a c k a t t h and l e %04x , t r an sac t i onmode %u\n” , a t t hand l e , t ransact ion mode ) ;

i f ( t ransact ion mode != ATT TRANSACTION MODE NONE) return 0 ;l e s t r e a m e r c o n n e c t i o n t ∗ context =

connec t i on f o r conn hand l e ( con handle ) ;switch ( a t t hand l e ) {

caseATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

caseATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

context−>l e n o t i f i c a t i o n e n a b l e d = l i t t l e e n d i a n r e a d 1 6 (bu f f e r , 0) ==GATT CLIENT CHARACTERISTICS CONFIGURATION NOTIFICATION;

p r i n t f ( ”%c : N o t i f i c a t i o n s enabled %u\n” , context−>name ,context−>l e n o t i f i c a t i o n e n a b l e d ) ;

i f ( context−>l e n o t i f i c a t i o n e n a b l e d ) {switch ( a t t hand l e ) {

caseATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

context−>va lue hand le =ATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE;

break ;case

ATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

Page 99: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

98

context−>va lue hand le =ATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE;

break ;default :

break ;}a t t s e r v e r r e q u e s t c a n s e n d n o w e v e n t ( context−>

connect ion hand le ) ;}t e s t r e s e t ( context ) ;break ;

caseATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE:

caseATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE:

t e s t t r a c k s e n t ( context , b u f f e r s i z e ) ;break ;

default :p r i n t f ( ”Write to 0x%04x , l en %u\n” , at t hand le ,

b u f f e r s i z e ) ;}return 0 ;

}

Listing 58. ATT Write

8.16. spp and le counter: Dual mode example. The SPP and LE Counterexample combines the Bluetooth Classic SPP Counter and the Bluetooth LECounter into a single application.

In this Section, we only point out the differences to the individual examplesand how the stack is configured.

Note: To test, please run the example, and then:

• for SPP pair from a remote device, and open the Virtual Serial Port,• for LE use some GATT Explorer, e.g. LightBlue, BLExplr, to enable

notifications.

8.16.1. Advertisements. The Flags attribute in the Advertisement Data indicatesif a device is in dual-mode or not. Flag 0x06 indicates LE General Discoverable,BR/EDR not supported although we’re actually using BR/EDR. In the past,there have been problems with Anrdoid devices when the flag was not set. Settingit should prevent the remote implementation to try to use GATT over LE/EDR,which is not implemented by BTstack. So, setting the flag seems like the saferchoice (while it’s technically incorrect).

const u i n t 8 t adv data [ ] = {// Flags genera l d i s c o v e ra b l e , BR/EDR not suppor ted

Page 100: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

99

0x02 , BLUETOOTH DATA TYPE FLAGS, 0x06 ,// Name0x0b , BLUETOOTH DATA TYPE COMPLETE LOCAL NAME, ’L ’ , ’E ’ , ’ ’ ,

’C ’ , ’ o ’ , ’ u ’ , ’ n ’ , ’ t ’ , ’ e ’ , ’ r ’ ,// Incomplete L i s t o f 16− b i t Se rv i c e Class UUIDs −− FF10 −

only v a l i d f o r t e s t i n g !0x03 ,

BLUETOOTH DATA TYPE INCOMPLETE LIST OF 16 BIT SERVICE CLASS UUIDS, 0x10 , 0 x f f ,

} ;

Listing 59. Advertisement data: Flag 0x06 indicates LE-only device

8.16.2. Packet Handler. The packet handler of the combined example is just thecombination of the individual packet handlers.

8.16.3. Heartbeat Handler. Similar to the packet handler, the heartbeat handleris the combination of the individual ones. After updating the counter, it requestsan ATT EVENT CAN SEND NOW and/or RFCOMM EVENT CAN SEND NOW

stat ic void hear tbea t hand l e r ( struct b t s t a c k t i m e r s o u r c e ∗ t s ) {

i f ( r fcomm channel id | | l e n o t i f i c a t i o n e n a b l e d ) {beat ( ) ;

}

i f ( r fcomm channel id ) {r fcomm request can send now event ( r fcomm channel id ) ;

}

i f ( l e n o t i f i c a t i o n e n a b l e d ) {a t t s e r v e r r e q u e s t c a n s e n d n o w e v e n t ( a t t con hand l e ) ;

}

b t s t a c k r u n l o o p s e t t i m e r ( ts , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer ( t s ) ;

}

Listing 60. Combined Heartbeat handler

8.16.4. Main Application Setup. As with the packet and the heartbeat handlers,the combined app setup contains the code from the individual example setups.

int btstack main (void ) ;int btstack main (void ){

l 2 c a p i n i t ( ) ;

Page 101: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

100

r f comm init ( ) ;r f c o m m r e g i s t e r s e r v i c e ( packet handler , RFCOMM SERVER CHANNEL,

0 x f f f f ) ;

// i n i t SDP, c r ea t e record f o r SPP and r e g i s t e r wi th SDPs d p i n i t ( ) ;memset ( s p p s e r v i c e b u f f e r , 0 , s izeof ( s p p s e r v i c e b u f f e r ) ) ;s p p c r e a t e s d p r e c o r d ( s p p s e r v i c e b u f f e r , 0x10001 ,

RFCOMM SERVER CHANNEL, ”SPP Counter” ) ;s d p r e g i s t e r s e r v i c e ( s p p s e r v i c e b u f f e r ) ;p r i n t f ( ”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n (

s p p s e r v i c e b u f f e r ) ) ;

gap s e t l o ca l name ( ”SPP and LE Counter 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;g a p s s p s e t i o c a p a b i l i t y (SSP IO CAPABILITY DISPLAY YES NO) ;g a p d i s c o v e r a b l e c o n t r o l (1 ) ;

// se tup l e dev i c e dbl e d e v i c e d b i n i t ( ) ;

// se tup SM: Disp lay on lys m i n i t ( ) ;

// se tup ATT serve ra t t s e r v e r i n i t ( p r o f i l e d a t a , a t t r e a d c a l l b a c k ,

a t t w r i t e c a l l b a c k ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// r e g i s t e r f o r ATT even t sa t t s e r v e r r e g i s t e r p a c k e t h a n d l e r ( packet hand le r ) ;

// se tup adver t i s ement su i n t 1 6 t adv int min = 0x0030 ;u i n t 1 6 t adv int max = 0x0030 ;u i n t 8 t adv type = 0 ;bd addr t nu l l add r ;memset ( nu l l addr , 0 , 6) ;gap adver t i s ements se t params ( adv int min , adv int max ,

adv type , 0 , nu l l addr , 0x07 , 0x00 ) ;gap adve r t i s ement s s e t da ta ( adv data len , ( u i n t 8 t ∗) adv data )

;gap adver t i s ement s enab l e (1 ) ;

// s e t one−sho t t imerheartbeat . p roc e s s = &hear tbea t hand l e r ;b t s t a c k r u n l o o p s e t t i m e r (&heartbeat , HEARTBEAT PERIOD MS) ;b t s t a ck run l oop add t imer (&heartbeat ) ;

// bea t oncebeat ( ) ;

Page 102: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

101

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;

return 0 ;}

Listing 61. Init L2CAP RFCOMM SDO SM ATT Server andstart heartbeat timer

8.17. a2dp sink demo: Receive audio stream and control its playback.This A2DP Sink example demonstrates how to use the A2DP Sink service toreceive an audio data stream from a remote A2DP Source device. In addition,the AVRCP Controller is used to get information on currently played media,such are title, artist and album, as well as to control the playback, i.e. to play,stop, repeat, etc.

@test To test with a remote device, e.g. a mobile phone, pair from the remotedevice with the demo, then start playing music on the remote device. Alterna-tively, set the device addr string to the Bluetooth address of your remote devicein the code, and call connect from the UI.

@test To controll the playback, tap SPACE on the console to show the availableAVRCP commands.

8.17.1. Main Application Setup. The Listing here shows how to setup AD2PSink and AVRCP controller services. To announce A2DP Sink and AVRCPController services, you need to create corresponding SDP records and registerthem with the SDP service. You’ll also need to register several packet handlers:

• a2dp sink packet handler - handles events on stream connection status(established, released), the media codec configuration, and, the status ofthe stream itself (opened, paused, stopped).• handle l2cap media data packet - used to receive streaming data. If STORE TO WAV FILE

directive (check btstack config.h) is used, the SBC decoder will be usedto decode the SBC data into PCM frames. The resulting PCM framesare then processed in the SBC Decoder callback.• stdin process callback - used to trigger AVRCP commands to the A2DP

Source device, such are get now playing info, start, stop, volume control.Requires HAVE BTSTACK STDIN.• avrcp controller packet handler - used to receive answers for AVRCP

commands,

Note, currently only the SBC codec is supported. If you want to store the audiodata in a file, you’ll need to define STORE TO WAV FILE. If STORE TO WAV FILEdirective is defined, the SBC decoder needs to get initialized when a2dp sink packet handlerreceives event A2DP SUBEVENT STREAM STARTED. The initialization ofthe SBC decoder requires a callback that handles PCM data:

• handle pcm data - handles PCM audio frames. Here, they are stored ain wav file if STORE TO WAV FILE is defined, and/or played using theaudio library.

Page 103: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

102

˜˜ {#lst:a2dpsinkdemoMainConfiguration .c caption=“{Setup Audio Sink andAVRCP Controller services}”}

8.17.2. Handle Media Data Packet.

8.18. a2dp source demo: Serve audio stream and handle remote play-back control and queries. Media data packets, in this case the audio data,are received through the handle l2cap media data packet callback. Currently,only the SBC media codec is supported. Hence, the media data consists of themedia packet header and the SBC packet. The SBC frame will be stored in aring buffer for later processing (instead of decoding it to PCM right away whichwould require a much larger buffer) If the audio stream wasn’t started alreadyand there are enough SBC frames in the ring buffer, start playback.

This A2DP Source example demonstrates how to send an audio data stream toa remote A2DP Sink device and how to switch between two audio data sources.In addition, the AVRCP Target is used to answer queries on currently playedmedia, as well as to handle remote playback control, i.e. play, stop, repeat, etc.

@test To test with a remote device, e.g. a Bluetooth speaker, set the de-vice addr string to the Bluetooth address of your remote device in the code, anduse the UI to connect and start playback. Tap SPACE on the console to showthe available commands.

8.18.1. Main Application Setup. The Listing here shows how to setup AD2PSource and AVRCP Target services.

stat ic void a2dp source packe t hand l e r ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗ event , u i n t 1 6 t e v e n t s i z e ) ;

stat ic void a v r c p t a r g e t p a c k e t h a n d l e r ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void a v r c p c o n t r o l l e r p a c k e t h a n d l e r ( u i n t 8 t packet type ,u i n t 1 6 t channel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

#i f d e f HAVE BTSTACK STDINstat ic void s t d i n p r o c e s s (char cmd) ;#e n d i f

stat ic int a 2 d p s o u r c e a n d a v r c p s e r v i c e s i n i t (void ) {

l 2 c a p i n i t ( ) ;// I n i t i a l i z e A2DP Source .a 2 d p s o u r c e i n i t ( ) ;a 2 d p s o u r c e r e g i s t e r p a c k e t h a n d l e r (&

a2dp source packe t hand l e r ) ;

// Create stream endpoint .avdtp st ream endpo int t ∗ l o c a l s t r e a m e n d p o i n t =

a2dp sourc e c r ea t e s t r eam endpo in t (AVDTP AUDIO,AVDTP CODEC SBC, m e d i a s b c c o d e c c a p a b i l i t i e s , s izeof (m e d i a s b c c o d e c c a p a b i l i t i e s ) ,med ia sbc codec con f i gu ra t i on , s izeof (m e d i a s b c c o d e c c o n f i g u r a t i o n ) ) ;

Page 104: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

103

i f ( ! l o c a l s t r e a m e n d p o i n t ) {p r i n t f ( ”A2DP Source : not enough memory to c r e a t e l o c a l

stream endpoint \n” ) ;return 1 ;

}media t racker . l o c a l s e i d = a v d t p l o c a l s e i d (

l o c a l s t r e a m e n d p o i n t ) ;

// I n i t i a l i z e AVRCP Target .a v r c p t a r g e t i n i t ( ) ;a v r c p t a r g e t r e g i s t e r p a c k e t h a n d l e r (&

a v r c p t a r g e t p a c k e t h a n d l e r ) ;// I n i t i a l i z e AVRCP Con t ro l l e ra v r c p c o n t r o l l e r i n i t ( ) ;a v r c p c o n t r o l l e r r e g i s t e r p a c k e t h a n d l e r (&

a v r c p c o n t r o l l e r p a c k e t h a n d l e r ) ;

// I n i t i a l i z e SDP,s d p i n i t ( ) ;

// Create A2DP Source s e r v i c e record and r e g i s t e r i t wi th SDP.

memset ( s d p a 2 d p s o u r c e s e r v i c e b u f f e r , 0 , s izeof (s d p a 2 d p s o u r c e s e r v i c e b u f f e r ) ) ;

a 2 d p s o u r c e c r e a t e s d p r e c o r d ( s d p a 2 d p s o u r c e s e r v i c e b u f f e r ,0x10002 , 1 , NULL, NULL) ;

s d p r e g i s t e r s e r v i c e ( s d p a 2 d p s o u r c e s e r v i c e b u f f e r ) ;

// Create AVRCP t a r g e t s e r v i c e record and r e g i s t e r i t wi th SDP.

memset ( s d p a v r c p t a r g e t s e r v i c e b u f f e r , 0 , s izeof (s d p a v r c p t a r g e t s e r v i c e b u f f e r ) ) ;

u i n t 1 6 t s u p p o r t e d f e a t u r e s = (1 <<AVRCP TARGET SUPPORTED FEATURE CATEGORY PLAYER OR RECORDER) ;

#i f d e f AVRCP BROWSING ENABLEDs u p p o r t e d f e a t u r e s |= (1 <<

AVRCP TARGET SUPPORTED FEATURE BROWSING) ;#e n d i f

a v r c p t a r g e t c r e a t e s d p r e c o r d ( s d p a v r c p t a r g e t s e r v i c e b u f f e r, 0x10001 , suppor t ed f ea tu r e s , NULL, NULL) ;

s d p r e g i s t e r s e r v i c e ( s d p a v r c p t a r g e t s e r v i c e b u f f e r ) ;

// se tup AVRCP Con t ro l l e rmemset ( s d p a v r c p c o n t r o l l e r s e r v i c e b u f f e r , 0 , s izeof (

s d p a v r c p c o n t r o l l e r s e r v i c e b u f f e r ) ) ;u i n t 1 6 t c o n t r o l l e r s u p p o r t e d f e a t u r e s = (1 <<

AVRCP CONTROLLER SUPPORTED FEATURE CATEGORY MONITOR OR AMPLIFIER) ;

a v r c p c o n t r o l l e r c r e a t e s d p r e c o r d (s d p a v r c p c o n t r o l l e r s e r v i c e b u f f e r , 0x10002 ,c o n t r o l l e r s u p p o r t e d f e a t u r e s , NULL, NULL) ;

s d p r e g i s t e r s e r v i c e ( s d p a v r c p c o n t r o l l e r s e r v i c e b u f f e r ) ;

Page 105: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

104

// Set l o c a l name with a temp la te B lue too th address , t h a t w i l lbe au t oma t i c a l l y

// rep l aced wi th a ac t ua l address once i t i s a v a i l a b l e , i . e .when BTstack boo t s

// up and s t a r t s t a l k i n g to a Blue too th module .gap s e t l o ca l name ( ”A2DP Source 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;g a p d i s c o v e r a b l e c o n t r o l (1 ) ;g a p s e t c l a s s o f d e v i c e (0 x200408 ) ;

// Reg i s t e r f o r HCI even t s .h c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &

a2dp source packe t hand l e r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

h x c m o d i n i t i a l i z e d = hxcmod init (&mod context ) ;i f ( h x c m o d i n i t i a l i z e d ) {

hxcmod setcfg(&mod context , A2DP SAMPLE RATE, 16 , 1 , 1 , 1) ;hxcmod load(&mod context , (void ∗) &mod data , mod len ) ;p r i n t f ( ” loaded mod ’%s ’ , s i z e %u\n” , mod name , mod len ) ;

}

// Parse human readab l e B lue too th address .s s can f bd addr ( d e v i c e a d d r s t r i n g , dev i c e addr ) ;

#i f d e f HAVE BTSTACK STDINb t s t a c k s t d i n s e t u p ( s t d i n p r o c e s s ) ;

#e n d i freturn 0 ;

}

Listing 62. Setup Audio Source and AVRCP Target services

8.19. hid keyboard demo: HID Keyboard (Server) Demo. This HID De-vice example demonstrates how to implement an HID keyboard. Without aHAVE BTSTACK STDIN, a fixed demo text is sent If HAVE BTSTACK STDINis defined, you can type from the terminal

Status: Basic implementation. HID Request from Host are not answered yet.Works with iOS.

8.19.1. Main Application Setup. Listing here shows main application code. Torun a HID Device service you need to initialize the SDP, and to create andregister HID Device record with it. At the end the Bluetooth stack is started.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

g a p d i s c o v e r a b l e c o n t r o l (1 ) ;g a p s e t c l a s s o f d e v i c e (0 x2540 ) ;

Page 106: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

105

gap s e t l o ca l name ( ”HID Keyboard Demo 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;

// L2CAPl 2 c a p i n i t ( ) ;

// SDP Servers d p i n i t ( ) ;memset ( h i d s e r v i c e b u f f e r , 0 , s izeof ( h i d s e r v i c e b u f f e r ) ) ;// hid s e v i c e s u b c l a s s 2540 Keyboard , h id counntry code 33 US,

hid v i r t u a l c a b l e o f f , h id reconnect i n i t i a t e o f f , h idboot dev i c e o f f

h i d c r e a t e s d p r e c o r d ( h i d s e r v i c e b u f f e r , 0x10001 , 0x2540 , 33 ,0 , 0 , h id boot dev i c e , h id descr iptor keyboard boot mode ,s izeof ( h id desc r ip tor keyboard boot mode ) ,

h id device name ) ;p r i n t f ( ”HID s e r v i c e record s i z e : %u\n” , d e g e t l e n (

h i d s e r v i c e b u f f e r ) ) ;s d p r e g i s t e r s e r v i c e ( h i d s e r v i c e b u f f e r ) ;

// See h t t p s ://www. b l u e t o o t h . com/ s p e c i f i c a t i o n s / ass igned−numbers/company− i d e n t i f i e r s i f you don ’ t have a USB VendorID and need a Blue too th Vendor ID

// dev i c e i n f o : BlueKitchen GmbH, product 1 , v e r s i on 1d e v i c e i d c r e a t e s d p r e c o r d ( d e v i c e i d s d p s e r v i c e b u f f e r , 0

x10003 , DEVICE ID VENDOR ID SOURCE BLUETOOTH,BLUETOOTH COMPANY ID BLUEKITCHEN GMBH, 1 , 1) ;

p r i n t f ( ” Device ID SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n ( (u i n t 8 t ∗) d e v i c e i d s d p s e r v i c e b u f f e r ) ) ;

s d p r e g i s t e r s e r v i c e ( d e v i c e i d s d p s e r v i c e b u f f e r ) ;

// HID Deviceh i d d e v i c e i n i t ( h id boot dev i c e , s izeof (

h id desc r ip tor keyboard boot mode ) ,h id desc r ip tor keyboard boot mode ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// r e g i s t e r f o r HID even t sh i d d e v i c e r e g i s t e r p a c k e t h a n d l e r (&packet hand le r ) ;

#i f d e f HAVE BTSTACK STDINsscan f bd addr ( d e v i c e a d d r s t r i n g , dev i c e addr ) ;b t s t a c k s t d i n s e t u p ( s t d i n p r o c e s s ) ;

#e n d i f// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;return 0 ;

}

Listing 63. Setup HID Device

Page 107: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

106

8.20. hid mouse demo: HID Mouse (Server) Demo. This HID Device ex-ample demonstrates how to implement an HID keyboard. Without a HAVE BTSTACK STDIN,a fixed demo text is sent If HAVE BTSTACK STDIN is defined, you can typefrom the terminal

Status: Basic implementation. HID Request from Host are not answered yet.Works with iOS.

8.20.1. Main Application Setup. Listing here shows main application code. Torun a HID Device service you need to initialize the SDP, and to create andregister HID Device record with it. At the end the Bluetooth stack is started.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

g a p d i s c o v e r a b l e c o n t r o l (1 ) ;g a p s e t c l a s s o f d e v i c e (0 x2540 ) ;gap s e t l o ca l name ( ”HID Mouse Demo 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;

// L2CAPl 2 c a p i n i t ( ) ;

// SDP Servers d p i n i t ( ) ;memset ( h i d s e r v i c e b u f f e r , 0 , s izeof ( h i d s e r v i c e b u f f e r ) ) ;// hid s e v i c e s u b c l a s s 2540 Keyboard , h id counntry code 33 US,

hid v i r t u a l c a b l e o f f , h id reconnect i n i t i a t e o f f , h idboot dev i c e o f f

h i d c r e a t e s d p r e c o r d ( h i d s e r v i c e b u f f e r , 0x10001 , 0x2540 , 33 ,0 , 0 , h id boot dev i c e , h id descr iptor mouse boot mode ,

s izeof ( h id descr iptor mouse boot mode ) , h id device name ) ;p r i n t f ( ”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n (

h i d s e r v i c e b u f f e r ) ) ;s d p r e g i s t e r s e r v i c e ( h i d s e r v i c e b u f f e r ) ;

// HID Deviceh i d d e v i c e i n i t ( h id boot dev i c e , s izeof (

h id descr iptor mouse boot mode ) ,h id descr iptor mouse boot mode ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// r e g i s t e r f o r HIDh i d d e v i c e r e g i s t e r p a c k e t h a n d l e r (&packet hand le r ) ;

#i f d e f HAVE BTSTACK STDINb t s t a c k s t d i n s e t u p ( s t d i n p r o c e s s ) ;

#e n d i f

Page 108: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

107

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;return 0 ;

}

Listing 64. Setup HID Device

8.21. hog keyboard demo: HID-over-GATT Keyboard.

8.22. hog mouse demo: HID-over-GATT Mouse.

8.23. sm pairing central: LE Peripheral - Test pairing combinations.Depending on the Authentication requiremens and IO Capabilities, the pairingprocess uses different short and long term key generation method. This examplehelps explore the different options incl. LE Secure Connections. It scans foradvertisements and connects to the first device that lists a random service.

8.23.1. GAP LE setup for receiving advertisements. GAP LE advertisements arereceived as custom HCI events of the GAP EVENT ADVERTISING REPORTtype. To receive them, you’ll need to register the HCI packet handler, as shownin Listing here.

stat ic void h c i p a c k e t h a n d l e r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void sm packet handler ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

stat ic void s m p a i r i n g c e n t r a l s e t u p (void ) {l 2 c a p i n i t ( ) ;

// se tup l e dev i c e dbl e d e v i c e d b i n i t ( ) ;

// se tup SM: Disp lay on lys m i n i t ( ) ;

// se tup ATT serve ra t t s e r v e r i n i t ( p r o f i l e d a t a , NULL, NULL) ;

/∗∗∗ Choose ONE of the f o l l ow i n g con f i g u r a t i on s∗ Bonding i s d i s a b l e d to a l l ow fo r repea ted t e s t i n g . I t can

be enab led wi th SM AUTHREQ BONDING

// r e g i s t e r hand lerh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &hc i p a c k e t h and l e r

;h c i a dd e v en t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

sm e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &sm packe t hand ler ;sm add event hand ler (& sm e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

Page 109: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

108

// LE Legacy Pairing , Jus t Works// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY YES NO) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (SM AUTHREQ NO BONDING) ;

// LE Legacy Pairing , Passkey entry i n i t i a t o r enter , responder( us ) d i s p l a y s

// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY ONLY) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQMITM PROTECTION) ;// sm u s e f i x e d p a s s k e y i n d i s p l a y r o l e (FIXED PASSKEY) ;

#i f d e f ENABLE LE SECURE CONNECTIONS// LE Secure Connetions , Jus t Works// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY YES NO) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQ SECURE CONNECTION) ;

// LE Secure Connections , Numeric Comparison// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY KEYBOARD ONLY) ;sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY YES NO) ;sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQ SECURE CONNECTION |SM AUTHREQMITM PROTECTION) ;

// LE Legacy Pairing , Passkey entry i n i t i a t o r enter , responder( us ) d i s p l a y s

// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY ONLY) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQ SECURE CONNECTION |SM AUTHREQMITM PROTECTION) ;// sm u s e f i x e d p a s s k e y i n d i s p l a y r o l e (FIXED PASSKEY) ;

#end i f}

Listing 65. Setting up GAP LE client for receiving advertisements

8.23.2. HCI packet handler. The HCI packet handler has to start the scanning,and to handle received advertisements. Advertisements are received as HCI eventpackets of the GAP EVENT ADVERTISING REPORT type, see Listing here.

### HCI packet handler

stat ic void h c i p a c k e t h a n d l e r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

i f ( packet type != HCI EVENT PACKET) return ;h c i c o n h a n d l e t con handle ;

Page 110: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

109

switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {case BTSTACK EVENT STATE:

// BTstack ac t i v a t ed , g e t s t a r t e di f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) ==

HCI STATE WORKING) {p r i n t f ( ” Star t scan ing !\n” ) ;gap se t s can paramete r s (1 ,0 x0030 , 0x0030 ) ;g a p s t a r t s c a n ( ) ;

}break ;

case GAP EVENT ADVERTISING REPORT:{bd addr t address ;g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s ( packet , address ) ;u i n t 8 t addre s s type =

g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s t y p e ( packet ) ;u i n t 8 t l ength =

g a p e v e n t a d v e r t i s i n g r e p o r t g e t d a t a l e n g t h ( packet ) ;const u i n t 8 t ∗ data =

g a p e v e n t a d v e r t i s i n g r e p o r t g e t d a t a ( packet ) ;// p r i n t f (” Advert isement event : addr−type %u , addr %s ,

data [%u ] ” ,// addres s type , b d a d d r t o s t r ( address ) , l e n g t h ) ;// pr int f hexdump ( data , l e n g t h ) ;i f ( ! ad data conta in s uu id16 ( length , ( u i n t 8 t ∗) data ,

REMOTE SERVICE) ) break ;p r i n t f ( ”Found remote with UUID %04x , connect ing . . . \ n” ,

REMOTE SERVICE) ;gap s top scan ( ) ;gap connect ( address , addre s s type ) ;break ;

}case HCI EVENT LE META:

// wai t f o r connect ion completei f ( h c i e v e n t l e m e t a g e t s u b e v e n t c o d e ( packet ) !=

HCI SUBEVENT LE CONNECTION COMPLETE) break ;con handle =

h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ;

p r i n t f ( ” Connection complete \n” ) ;// s t a r t pa i r i n gs m r e q u e s t p a i r i n g ( con handle ) ;break ;

case HCI EVENT ENCRYPTION CHANGE:con handle =

h c i e v e n t e n c r y p t i o n c h a n g e g e t c o n n e c t i o n h a n d l e (packet ) ;

p r i n t f ( ” Connection encrypted : %u\n” ,h c i e v e n t e n c r y p t i o n c h a n g e g e t e n c r y p t i o n e n a b l e d (packet ) ) ;

break ;default :

break ;}

}

Page 111: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

110

stat ic void sm packet handler ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

i f ( packet type != HCI EVENT PACKET) return ;

switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {case SM EVENT JUST WORKS REQUEST:

p r i n t f ( ” Just works reques ted \n” ) ;sm jus t works con f i rm (

s m e v e n t j u s t w o r k s r e q u e s t g e t h a n d l e ( packet ) ) ;break ;

case SM EVENT NUMERIC COMPARISON REQUEST:p r i n t f ( ” Confirming numeric comparison : %”PRIu32”\n” ,

sm event numer i c compar i son reques t ge t pas skey ( packet) ) ;

sm numeric comparison conf i rm (sm event pas skey d i sp lay number get hand le ( packet ) ) ;

break ;case SM EVENT PASSKEY DISPLAY NUMBER:

p r i n t f ( ” Display Passkey : %”PRIu32”\n” ,sm event pas skey d i sp lay number ge t pas skey ( packet ) ) ;

break ;case SM EVENT PASSKEY INPUT NUMBER:

p r i n t f ( ” Passkey Input reques ted \n” ) ;p r i n t f ( ” Sending f i x e d passkey %”PRIu32”\n” , FIXED PASSKEY)

;sm passkey input ( sm event passkey input number get handle (

packet ) , FIXED PASSKEY) ;break ;

case SM EVENT PAIRING COMPLETE:switch ( s m e v e n t p a i r i n g c o m p l e t e g e t s t a t u s ( packet ) ) {

case ERROR CODE SUCCESS:p r i n t f ( ” Pa i r ing complete , s u c c e s s \n” ) ;break ;

case ERROR CODE CONNECTION TIMEOUT:p r i n t f ( ” Pa i r ing f a i l e d , t imeout \n” ) ;break ;

case ERROR CODE REMOTE USER TERMINATED CONNECTION:p r i n t f ( ” Pa i r ing f a i l e e d , d i s connected \n” ) ;break ;

case ERROR CODE AUTHENTICATION FAILURE:p r i n t f ( ” Pa i r ing f a i l e d , reason = %u\n” ,

s m e v e n t p a i r i n g c o m p l e t e g e t r e a s o n ( packet ) ) ;break ;

default :break ;

}break ;

Page 112: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

111

default :break ;

}}

Listing 66. Scanning and receiving advertisements

The SM packet handler receives Security Manager Events required for pairing.It also receives events generated during Identity Resolving see Listing here.

8.24. sm pairing peripheral: LE Peripheral - Test pairing combina-tions. Depending on the Authentication requiremens and IO Capabilities, thepairing process uses different short and long term key generation method. Thisexample helps explore the different options incl. LE Secure Connections.

8.24.1. Main Application Setup. Listing here shows main application code. Itinitializes L2CAP, the Security Manager and configures the ATT Server withthe pre-compiled ATT Database generated from smpairingperipheral.gatt. Fi-nally, it configures the advertisements and boots the Bluetooth stack. In thisexample, the Advertisement contains the Flags attribute, the device name, anda 16-bit (test) service 0x1111 The flag 0x06 indicates: LE General DiscoverableMode and BR/EDR not supported. Various examples for IO Capabilites andAuthentication Requirements are given below.

stat ic b t s t a c k p a c k e t c a l l b a c k r e g i s t r a t i o n ts m e v e n t c a l l b a c k r e g i s t r a t i o n ;

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) ;

const u i n t 8 t adv data [ ] = {// Flags genera l d i s c o v e ra b l e , BR/EDR not suppor ted0x02 , BLUETOOTH DATA TYPE FLAGS, 0x06 ,// Name0x0b , BLUETOOTH DATA TYPE COMPLETE LOCAL NAME, ’S ’ , ’M’ , ’ ’ ,

’P ’ , ’ a ’ , ’ i ’ , ’ r ’ , ’ i ’ , ’ n ’ , ’ g ’ ,// Incomplete L i s t o f 16− b i t Se rv i c e Class UUIDs −− 1111 −

only v a l i d f o r t e s t i n g !0x03 ,

BLUETOOTH DATA TYPE INCOMPLETE LIST OF 16 BIT SERVICE CLASS UUIDS, 0x11 , 0x11 ,

} ;const u i n t 8 t adv data l en = s izeof ( adv data ) ;

stat ic void sm pe r iphe ra l s e tup (void ) {

l 2 c a p i n i t ( ) ;

// se tup l e dev i c e dbl e d e v i c e d b i n i t ( ) ;

Page 113: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

112

// se tup SM: Disp lay on lys m i n i t ( ) ;

/∗∗∗ Choose ONE of the f o l l ow i n g con f i g u r a t i on s∗ Bonding i s d i s a b l e d to a l l ow fo r repea ted t e s t i n g . I t can

be enab led wi th SM AUTHREQ BONDING

// LE Legacy Pairing , Jus t Works// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY NO INPUT NO OUTPUT) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (SM AUTHREQ BONDING) ;

// LE Legacy Pairing , Passkey entry i n i t i a t o r enter , responder( us ) d i s p l a y s

// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY ONLY) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQMITM PROTECTION) ;// sm u s e f i x e d p a s s k e y i n d i s p l a y r o l e (123456) ;

#i f d e f ENABLE LE SECURE CONNECTIONS// LE Secure Connetions , Jus t Works// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY YES NO) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQ SECURE CONNECTION) ;

// LE Secure Connections , Numeric Comparisonsm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY ONLY) ;sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQ SECURE CONNECTION |SM AUTHREQMITM PROTECTION) ;

// LE Legacy Pairing , Passkey entry i n i t i a t o r enter , responder( us ) d i s p l a y s

// sm s e t i o c a p a b i l i t i e s (IO CAPABILITY DISPLAY ONLY) ;// sm se t au t h en t i c a t i on r e qu i r emen t s (

SM AUTHREQ SECURE CONNECTION |SM AUTHREQMITM PROTECTION) ;// sm u s e f i x e d p a s s k e y i n d i s p l a y r o l e (123456) ;

#end i f

// se tup ATT serve ra t t s e r v e r i n i t ( p r o f i l e d a t a , NULL, NULL) ;

// se tup adver t i s ement su i n t 1 6 t adv in t min = 0x0030 ;u i n t 1 6 t adv int max = 0x0030 ;u i n t 8 t adv type = 0;bd add r t nu l l a dd r ;memset ( nu l l addr , 0 , 6) ;gap adver t i s ement s s e t params ( adv int min , adv int max ,

adv type , 0 , nu l l addr , 0x07 , 0x00 ) ;g ap ad v e r t i s emen t s s e t d a t a ( adv da ta l en , ( u i n t 8 t ∗) adv data )

;gap adve r t i s emen t s enab l e (1) ;

// r e g i s t e r f o r SM even t s

Page 114: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

113

sm e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packe t hand l e r ;sm add event hand ler (& sm e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// r e g i s t e r f o r ATTa t t s e r v e r r e g i s t e r p a c k e t h a n d l e r ( packe t hand l e r ) ;

}

Listing 67. Setup stack to advertise

8.24.2. Packet Handler. The packet handler is used to:

• report connect/disconnect• handle Security Manager events

stat ic void packet hand le r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;h c i c o n h a n d l e t con handle ;bd addr t addr ;switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case HCI EVENT LE META:switch ( h c i e v e n t l e m e t a g e t s u b e v e n t c o d e ( packet ) ) {

case HCI SUBEVENT LE CONNECTION COMPLETE:// se tup new

p r i n t f ( ” Connection complete \n” ) ;con handle =

h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ;

s m s e n d s e c u r i t y r e q u e s t ( con handle ) ;break ;

default :break ;

}break ;

case SM EVENT JUST WORKS REQUEST:p r i n t f ( ” Just Works reques ted \n” ) ;sm jus t works con f i rm (

s m e v e n t j u s t w o r k s r e q u e s t g e t h a n d l e ( packet ) ) ;break ;

case SM EVENT NUMERIC COMPARISON REQUEST:p r i n t f ( ” Confirming numeric comparison : %”PRIu32”\n” ,

sm event numer i c compar i son reques t ge t pas skey (packet ) ) ;

sm numeric comparison conf i rm (sm event pas skey d i sp lay number get hand le ( packet )) ;

break ;case SM EVENT PASSKEY DISPLAY NUMBER:

Page 115: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

114

p r i n t f ( ” Display Passkey : %”PRIu32”\n” ,sm event pas skey d i sp lay number ge t pas skey ( packet) ) ;

break ;case SM EVENT IDENTITY CREATED:

s m e v e n t i d e n t i t y c r e a t e d g e t i d e n t i t y a d d r e s s ( packet ,addr ) ;

p r i n t f ( ” I d e n t i t y c reated : type %u address %s \n” ,s m e v e n t i d e n t i t y c r e a t e d g e t i d e n t i t y a d d r t y p e (packet ) , b d a d d r t o s t r ( addr ) ) ;

break ;case SM EVENT IDENTITY RESOLVING SUCCEEDED:

s m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t i d e n t i t y a d d r e s s( packet , addr ) ;

p r i n t f ( ” I d e n t i t y r e s o l v e d : type %u address %s \n” ,s m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t i d e n t i t y a d d r t y p e( packet ) , b d a d d r t o s t r ( addr ) ) ;

break ;case SM EVENT IDENTITY RESOLVING FAILED:

s m e v e n t i d e n t i t y c r e a t e d g e t a d d r e s s ( packet , addr ) ;p r i n t f ( ” I d e n t i t y r e s o l v i n g f a i l e d \n” ) ;break ;

case SM EVENT PAIRING COMPLETE:switch ( s m e v e n t p a i r i n g c o m p l e t e g e t s t a t u s ( packet ) ) {

case ERROR CODE SUCCESS:p r i n t f ( ” Pa i r ing complete , s u c c e s s \n” ) ;break ;

case ERROR CODE CONNECTION TIMEOUT:p r i n t f ( ” Pa i r ing f a i l e d , t imeout \n” ) ;break ;

case ERROR CODE REMOTE USER TERMINATED CONNECTION:p r i n t f ( ” Pa i r ing f a i l e e d , d i s connected \n” ) ;break ;

case ERROR CODE AUTHENTICATION FAILURE:p r i n t f ( ” Pa i r ing f a i l e d , reason = %u\n” ,

s m e v e n t p a i r i n g c o m p l e t e g e t r e a s o n ( packet ) ) ;break ;

default :break ;

}break ;

default :break ;

}break ;

}}

Listing 68. Packet Handler

8.25. pbap client demo: Connect to Phonebook Server and get con-tacts. Note: The Bluetooth address of the remote Phonbook server is hard-coded. Change it before running example, then use the UI to connect to it, toset and query contacts.

Page 116: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

115

8.26. le streamer: LE Streamer - Stream data over GATT.. All neweroperating systems provide GATT Client functionality. This example shows howto get a maximal throughput via BLE:

• send whenever possible,• use the max ATT MTU.

In theory, we should also update the connection parameters, but we alreadyget a connection interval of 30 ms and there’s no public way to use a shorterinterval with iOS (if we’re not implementing an HID device).

Note: To start the streaming, run the example. On remote device use someGATT Explorer, e.g. LightBlue, BLExplr to enable notifications.

8.26.1. Main Application Setup. Listing here shows main application code. Itinitializes L2CAP, the Security Manager, and configures the ATT Server withthe pre-compiled ATT Database generated from lestreamer.gatt. Finally, itconfigures the advertisements and boots the Bluetooth stack.

stat ic void l e s t r e a m e r s e t u p (void ) {

l 2 c a p i n i t ( ) ;

// se tup l e dev i c e dbl e d e v i c e d b i n i t ( ) ;

// se tup SM: Disp lay on lys m i n i t ( ) ;

// se tup ATT serve ra t t s e r v e r i n i t ( p r o f i l e d a t a , NULL, a t t w r i t e c a l l b a c k ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &h c i p a c k e t h a n d l e r

;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// r e g i s t e r f o r ATT even t sa t t s e r v e r r e g i s t e r p a c k e t h a n d l e r ( a t t p a c k e t h a n d l e r ) ;

// se tup adver t i s ement su i n t 1 6 t adv int min = 0x0030 ;u i n t 1 6 t adv int max = 0x0030 ;u i n t 8 t adv type = 0 ;bd addr t nu l l add r ;memset ( nu l l addr , 0 , 6) ;gap adver t i s ements se t params ( adv int min , adv int max ,

adv type , 0 , nu l l addr , 0x07 , 0x00 ) ;gap adve r t i s ement s s e t da ta ( adv data len , ( u i n t 8 t ∗) adv data )

;gap adver t i s ement s enab l e (1 ) ;

Page 117: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

116

// i n i t c l i e n t s t a t ei n i t c o n n e c t i o n s ( ) ;

}

Listing 69. Init L2CAP, SM, ATT Server, and enable advertisements

8.26.2. Track throughput. We calculate the throughput by setting a start timeand measuring the amount of data sent. After a configurable REPORT INTERVAL MS,we print the throughput in kB/s and reset the counter and start time.

stat ic void t e s t r e s e t ( l e s t r e a m e r c o n n e c t i o n t ∗ context ) {context−>t e s t d a t a s t a r t = bt s ta ck run l oop ge t t ime ms ( ) ;context−>t e s t d a t a s e n t = 0 ;

}

stat ic void t e s t t r a c k s e n t ( l e s t r e a m e r c o n n e c t i o n t ∗ context ,int b y t e s s e n t ) {

context−>t e s t d a t a s e n t += b y t e s s e n t ;// eva l ua t eu i n t 3 2 t now = bt s ta ck run l oop ge t t ime ms ( ) ;u i n t 3 2 t t ime passed = now − context−>t e s t d a t a s t a r t ;i f ( t ime passed < REPORT INTERVAL MS) return ;// p r i n t speedint byte s pe r s e cond = context−>t e s t d a t a s e n t ∗ 1000 /

t ime passed ;p r i n t f ( ”%c : %”PRIu32” bytes sent−> %u.%03u kB/ s \n” , context−>

name , context−>t e s t d a t a s e n t , by t e s pe r s e cond / 1000 ,by t e s pe r s e cond % 1000) ;

// r e s t a r tcontext−>t e s t d a t a s t a r t = now ;context−>t e s t d a t a s e n t = 0 ;

}

Listing 70. Tracking throughput

8.26.3. HCI Packet Handler. The packet handler is used track incoming connec-tions and to stop notifications on disconnect It is also a good place to requestthe connection parameter update as indicated in the commented code block.

stat ic void h c i p a c k e t h a n d l e r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

u i n t 1 6 t c o n n i n t e r v a l ;l e s t r e a m e r c o n n e c t i o n t ∗ context ;

Page 118: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

117

switch ( packet type ) {case HCI EVENT PACKET:

switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {case BTSTACK EVENT STATE:

// BTstack ac t i v a t ed , g e t s t a r t e di f ( b t s t a c k e v e n t s t a t e g e t s t a t e ( packet ) ==

HCI STATE WORKING) {p r i n t f ( ”To s t a r t the streaming , p l e a s e run the

l e s t r e a m e r c l i e n t example on other device , oruse some GATT Explorer , e . g . LightBlue , BLExplr.\n” ) ;

}break ;

case HCI EVENT DISCONNECTION COMPLETE:context = connec t i on f o r conn hand l e (

h c i e v e n t d i s c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ) ;

i f ( ! context ) break ;// f r e e connect ionp r i n t f ( ”%c : Disconnect , reason %02x\n” , context−>name ,

h c i e v e n t d i s c o n n e c t i o n c o m p l e t e g e t r e a s o n (packet ) ) ;

context−>l e n o t i f i c a t i o n e n a b l e d = 0 ;context−>connect ion hand le = HCI CON HANDLE INVALID;break ;

case HCI EVENT LE META:switch ( h c i e v e n t l e m e t a g e t s u b e v e n t c o d e ( packet ) ) {

case HCI SUBEVENT LE CONNECTION COMPLETE:// se tup newcontext = connec t i on f o r conn hand l e (

HCI CON HANDLE INVALID) ;i f ( ! context ) break ;context−>counter = ’A ’ ;context−>t e s t d a t a l e n = ATT DEFAULT MTU − 3 ;context−>connect ion hand le =

h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ;

// p r i n t connect ion parameters ( wi thou t us ingf l o a t opera t i ons )

c o n n i n t e r v a l =h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n i n t e r v a l( packet ) ;

p r i n t f ( ”%c : Connection I n t e r v a l : %u.%02u ms ,l a t ency %u\n” , context−>name , c o n n i n t e r v a l ∗125 / 100 ,

25 ∗ ( c o n n i n t e r v a l & 3) ,h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n l a t e n c y( packet ) ) ;

// r e que s t min con i n t e r v a l 15 ms f o r iOS 11+// gap reques t connec t i on paramete r upda t e ( contex t−>connect ion hand le , 12 , 12 , 0 , 0x0048 ) ;

break ;case HCI SUBEVENT LE CONNECTION UPDATE COMPLETE:

Page 119: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

118

// p r i n t connect ion parameters ( wi thou t us ingf l o a t opera t i ons )

context = connec t i on f o r conn hand l e (h c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n e c t i o n h a n d l e( packet ) ) ;

i f ( ! context ) break ;c o n n i n t e r v a l =

h c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n i n t e r v a l( packet ) ;

p r i n t f ( ”%c : Connection I n t e r v a l : %u.%02u ms ,l a t ency %u\n” , context−>name , c o n n i n t e r v a l ∗125 / 100 ,

25 ∗ ( c o n n i n t e r v a l & 3) ,h c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n l a t e n c y( packet ) ) ;

break ;default :

break ;}break ;

default :break ;

}}

}

Listing 71. Packet Handler

8.26.4. ATT Packet Handler. The packet handler is used to track the ATT MTUExchange and trigger ATT send

stat ic void a t t p a c k e t h a n d l e r ( u i n t 8 t packet type , u i n t 1 6 tchannel , u i n t 8 t ∗packet , u i n t 1 6 t s i z e ) {

UNUSED( channel ) ;UNUSED( s i z e ) ;

int mtu ;l e s t r e a m e r c o n n e c t i o n t ∗ context ;switch ( packet type ) {

case HCI EVENT PACKET:switch ( h c i e v e n t p a c k e t g e t t y p e ( packet ) ) {

case ATT EVENT MTU EXCHANGE COMPLETE:mtu = att event mtu exchange complete get MTU ( packet )− 3 ;

context = connec t i on f o r conn hand l e (a t t event mtu exchange comple te ge t hand l e ( packet )) ;

i f ( ! context ) break ;context−>t e s t d a t a l e n = btstack min (mtu − 3 , s izeof (

context−>t e s t d a t a ) ) ;

Page 120: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

119

p r i n t f ( ”%c : ATT MTU = %u => use t e s t data o f l en %u\n”, context−>name , mtu , context−>t e s t d a t a l e n ) ;

break ;case ATT EVENT CAN SEND NOW:

streamer ( ) ;break ;

default :break ;

}break ;

default :break ;

}}

Listing 72. Packet Handler

8.26.5. Streamer. The streamer function checks if notifications are enabled andif a notification can be sent now. It creates some test data - a single letter thatgets increased every time - and tracks the data sent.

stat ic void streamer (void ) {

// f i nd next a c t i v e streaming connect ionint o l d c o n n e c t i o n i n d e x = connec t i on index ;while (1 ) {

// a c t i v e found?i f ( ( l e s t r e a m e r c o n n e c t i o n s [ connec t i on index ] .

connect ion hand le != HCI CON HANDLE INVALID) &&( l e s t r e a m e r c o n n e c t i o n s [ connec t i on index ] .

l e n o t i f i c a t i o n e n a b l e d ) ) break ;

// check nextnext connec t i on index ( ) ;

// none foundi f ( connec t i on index == o l d c o n n e c t i o n i n d e x ) return ;

}

l e s t r e a m e r c o n n e c t i o n t ∗ context = &l e s t r e a m e r c o n n e c t i o n s [connec t i on index ] ;

// crea t e t e s t datacontext−>counter++;i f ( context−>counter > ’Z ’ ) context−>counter = ’A ’ ;memset ( context−>t e s t da ta , context−>counter , context−>

t e s t d a t a l e n ) ;

// send

Page 121: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

120

a t t s e r v e r n o t i f y ( context−>connect ion handle , context−>value handle , ( u i n t 8 t ∗) context−>t e s t da ta , context−>t e s t d a t a l e n ) ;

// t rackt e s t t r a c k s e n t ( context , context−>t e s t d a t a l e n ) ;

// r e que s t next send eventa t t s e r v e r r e q u e s t c a n s e n d n o w e v e n t ( context−>

connect ion hand le ) ;

// check nextnext connec t i on index ( ) ;

}

Listing 73. Streaming code

8.26.6. ATT Write. The only valid ATT write in this example is to the ClientCharacteristic Configuration, which configures notification and indication. Ifthe ATT handle matches the client configuration handle, the new configurationvalue is stored. If notifications get enabled, an ATT EVENT CAN SEND NOWis requested. See Listing here.

stat ic int a t t w r i t e c a l l b a c k ( h c i c o n h a n d l e t con handle ,u i n t 1 6 t at t hand le , u i n t 1 6 t transact ion mode , u i n t 1 6 to f f s e t , u i n t 8 t ∗ bu f f e r , u i n t 1 6 t b u f f e r s i z e ) {

UNUSED( o f f s e t ) ;

// p r i n t f (” a t t w r i t e c a l l b a c k a t t h and l e %04x , t r an sac t i onmode %u\n” , a t t hand l e , t ransact ion mode ) ;

i f ( t ransact ion mode != ATT TRANSACTION MODE NONE) return 0 ;l e s t r e a m e r c o n n e c t i o n t ∗ context =

connec t i on f o r conn hand l e ( con handle ) ;switch ( a t t hand l e ) {

caseATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

caseATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

context−>l e n o t i f i c a t i o n e n a b l e d = l i t t l e e n d i a n r e a d 1 6 (bu f f e r , 0) ==GATT CLIENT CHARACTERISTICS CONFIGURATION NOTIFICATION;

p r i n t f ( ”%c : N o t i f i c a t i o n s enabled %u\n” , context−>name ,context−>l e n o t i f i c a t i o n e n a b l e d ) ;

i f ( context−>l e n o t i f i c a t i o n e n a b l e d ) {switch ( a t t hand l e ) {

caseATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

Page 122: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

121

context−>va lue hand le =ATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE;

break ;case

ATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 CLIENT CONFIGURATION HANDLE:

context−>va lue hand le =ATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE;

break ;default :

break ;}a t t s e r v e r r e q u e s t c a n s e n d n o w e v e n t ( context−>

connect ion hand le ) ;}t e s t r e s e t ( context ) ;break ;

caseATT CHARACTERISTIC 0000FF11 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE:

caseATT CHARACTERISTIC 0000FF12 0000 1000 8000 00805F9B34FB 01 VALUE HANDLE:

t e s t t r a c k s e n t ( context , b u f f e r s i z e ) ;break ;

default :p r i n t f ( ”Write to 0x%04x , l en %u\n” , at t hand le ,

b u f f e r s i z e ) ;}return 0 ;

}

Listing 74. ATT Write

8.27. le streamer client: Connects to ‘LE Streamer’ and subscribes totest characteristic.

8.27.1. Track throughput. We calculate the throughput by setting a start timeand measuring the amount of data sent. After a configurable REPORT INTERVAL MS,we print the throughput in kB/s and reset the counter and start time.

#d e f i n e TEST MODE WRITE WITHOUT RESPONSE 1#d e f i n e TEST MODE ENABLE NOTIFICATIONS 2#d e f i n e TEST MODE DUPLEX 3

// con f i gu r e t e s t mode : send only , r e c e i v e only , f u l l dup lex#d e f i n e TEST MODE TEST MODE DUPLEX

Page 123: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

122

#d e f i n e REPORT INTERVAL MS 3000

// suppor t f o r mu l t i p l e c l i e n t stypedef struct {

char name ;int l e n o t i f i c a t i o n e n a b l e d ;int counter ;char t e s t d a t a [ 2 0 0 ] ;int t e s t d a t a l e n ;u i n t 3 2 t t e s t d a t a s e n t ;u i n t 3 2 t t e s t d a t a s t a r t ;

} l e s t r e a m e r c o n n e c t i o n t ;

stat ic l e s t r e a m e r c o n n e c t i o n t l e s t r e a m e r c o n n e c t i o n ;

stat ic void t e s t r e s e t ( l e s t r e a m e r c o n n e c t i o n t ∗ context ) {context−>t e s t d a t a s t a r t = bt s ta ck run l oop ge t t ime ms ( ) ;context−>t e s t d a t a s e n t = 0 ;

}

stat ic void t e s t t r a c k d a t a ( l e s t r e a m e r c o n n e c t i o n t ∗ context ,int b y t e s s e n t ) {

context−>t e s t d a t a s e n t += b y t e s s e n t ;// eva l ua t eu i n t 3 2 t now = bt s ta ck run l oop ge t t ime ms ( ) ;u i n t 3 2 t t ime passed = now − context−>t e s t d a t a s t a r t ;i f ( t ime passed < REPORT INTERVAL MS) return ;// p r i n t speedint byte s pe r s e cond = context−>t e s t d a t a s e n t ∗ 1000 /

t ime passed ;p r i n t f ( ”%c : %”PRIu32” bytes −> %u.%03u kB/ s \n” , context−>name ,

context−>t e s t d a t a s e n t , by t e s pe r s e cond / 1000 ,by t e s pe r s e cond % 1000) ;

// r e s t a r tcontext−>t e s t d a t a s t a r t = now ;context−>t e s t d a t a s e n t = 0 ;

}

Listing 75. Tracking throughput

8.28. spp streamer: Send test data via SPP as fast as possible. AfterRFCOMM connections gets open, request a RFCOMM EVENT CAN SEND NOWvia rfcomm request can send now event().

When we get the RFCOMM EVENT CAN SEND NOW, send data and re-quest another one.

Note: To test, run the example, pair from a remote device, and open theVirtual Serial Port.

8.28.1. Track throughput. We calculate the throughput by setting a start timeand measuring the amount of data sent. After a configurable REPORT INTERVAL MS,we print the throughput in kB/s and reset the counter and start time.

Page 124: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

123

#d e f i n e REPORT INTERVAL MS 3000stat ic u i n t 3 2 t t e s t d a t a t r a n s f e r r e d ;stat ic u i n t 3 2 t t e s t d a t a s t a r t ;

stat ic void t e s t r e s e t (void ) {t e s t d a t a s t a r t = bt s ta ck run l oop ge t t ime ms ( ) ;t e s t d a t a t r a n s f e r r e d = 0 ;

}

stat ic void t e s t t r a c k t r a n s f e r r e d ( int b y t e s s e n t ) {t e s t d a t a t r a n s f e r r e d += b y t e s s e n t ;// eva l ua t eu i n t 3 2 t now = bt s ta ck run l oop ge t t ime ms ( ) ;u i n t 3 2 t t ime passed = now − t e s t d a t a s t a r t ;i f ( t ime passed < REPORT INTERVAL MS) return ;// p r i n t speedint byte s pe r s e cond = t e s t d a t a t r a n s f e r r e d ∗ 1000 /

t ime passed ;p r i n t f ( ”%u bytes −> %u.%03u kB/ s \n” , ( int )

t e s t d a t a t r a n s f e r r e d , ( int ) by t e s pe r s e cond / 1000 ,by t e s pe r s e cond % 1000) ;

// r e s t a r tt e s t d a t a s t a r t = now ;t e s t d a t a t r a n s f e r r e d = 0 ;

}

Listing 76. Tracking throughput

8.28.2. Packet Handler. The packet handler of the combined example is just thecombination of the individual packet handlers.

8.28.3. Main Application Setup. As with the packet and the heartbeat handlers,the combined app setup contains the code from the individual example setups.

int btstack main ( int argc , const char ∗ argv [ ] ){

(void ) argc ;(void ) argv ;

l 2 c a p i n i t ( ) ;

r f comm init ( ) ;r f c o m m r e g i s t e r s e r v i c e ( packet handler , RFCOMM SERVER CHANNEL,

0 x f f f f ) ;

#i f d e f ENABLE L2CAP ENHANCED RETRANSMISSION MODE FOR RFCOMM// se tup ERTM managementr fcomm enable l2cap ertm(&rfcomm ertm request handler , &

r fcomm ertm re l eased hand le r ) ;

Page 125: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

124

#e n d i f

// i n i t SDP, c r ea t e record f o r SPP and r e g i s t e r wi th SDPs d p i n i t ( ) ;memset ( s p p s e r v i c e b u f f e r , 0 , s izeof ( s p p s e r v i c e b u f f e r ) ) ;s p p c r e a t e s d p r e c o r d ( s p p s e r v i c e b u f f e r , 0x10001 ,

RFCOMM SERVER CHANNEL, ”SPP Streamer ” ) ;s d p r e g i s t e r s e r v i c e ( s p p s e r v i c e b u f f e r ) ;// p r i n t f (”SDP s e r v i c e record s i z e : %u\n” , d e g e t l e n (

s p p s e r v i c e b u f f e r ) ) ;

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// short−cut to f i nd o ther SPP Streamerg a p s e t c l a s s o f d e v i c e (TEST COD) ;

g a p s s p s e t i o c a p a b i l i t y (SSP IO CAPABILITY DISPLAY YES NO) ;gap s e t l o ca l name ( ”SPP Streamer 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 ” ) ;g a p d i s c o v e r a b l e c o n t r o l (1 ) ;

s p p c r e a t e t e s t d a t a ( ) ;

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;

return 0 ;}

Listing 77. Init L2CAP RFCOMM SDP SPP

8.29. spp streamer client: Client for SPP Streamer. Note: The SPPStreamer Client scans for and connects to SPP Streamer, and measures thethroughput.

8.29.1. Track throughput. We calculate the throughput by setting a start timeand measuring the amount of data sent. After a configurable REPORT INTERVAL MS,we print the throughput in kB/s and reset the counter and start time.

#d e f i n e REPORT INTERVAL MS 3000stat ic u i n t 3 2 t t e s t d a t a t r a n s f e r r e d ;stat ic u i n t 3 2 t t e s t d a t a s t a r t ;

stat ic void t e s t r e s e t (void ) {t e s t d a t a s t a r t = bt s ta ck run l oop ge t t ime ms ( ) ;t e s t d a t a t r a n s f e r r e d = 0 ;

}

stat ic void t e s t t r a c k t r a n s f e r r e d ( int b y t e s s e n t ) {t e s t d a t a t r a n s f e r r e d += b y t e s s e n t ;

Page 126: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

125

// eva l ua t eu i n t 3 2 t now = bt s ta ck run l oop ge t t ime ms ( ) ;u i n t 3 2 t t ime passed = now − t e s t d a t a s t a r t ;i f ( t ime passed < REPORT INTERVAL MS) return ;// p r i n t speedint byte s pe r s e cond = t e s t d a t a t r a n s f e r r e d ∗ 1000 /

t ime passed ;p r i n t f ( ”%u bytes −> %u.%03u kB/ s \n” , ( int )

t e s t d a t a t r a n s f e r r e d , ( int ) by t e s pe r s e cond / 1000 ,by t e s pe r s e cond % 1000) ;

// r e s t a r tt e s t d a t a s t a r t = now ;t e s t d a t a t r a n s f e r r e d = 0 ;

}

Listing 78. Tracking throughput

8.29.2. Packet Handler. The packet handler of the combined example is just thecombination of the individual packet handlers.

8.29.3. Main Application Setup. As with the packet and the heartbeat handlers,the combined app setup contains the code from the individual example setups.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

UNUSED( argc ) ;(void ) argv ;

l 2 c a p i n i t ( ) ;

r f comm init ( ) ;r f c o m m r e g i s t e r s e r v i c e ( packet handler , RFCOMM SERVER CHANNEL,

0 x f f f f ) ;

#i f d e f ENABLE L2CAP ENHANCED RETRANSMISSION MODE FOR RFCOMM// se tup ERTM managementr fcomm enable l2cap ertm(&rfcomm ertm request handler , &

r fcomm ertm re l eased hand le r ) ;#e n d i f

// r e g i s t e r f o r HCI even t sh c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// i n i t SDPg a p s s p s e t i o c a p a b i l i t y (SSP IO CAPABILITY DISPLAY YES NO) ;

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;

return 0 ;

Page 127: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

126

}

Listing 79. Init L2CAP RFCOMM SDO SM ATT Server andstart heartbeat timer

8.30. dut mode classic: Enable Device Under Test (DUT) Mode forBR/EDR. DUT mode can be used for production testing. This example justconfigures the Bluetooth Controller for DUT mode.

8.30.1. Bluetooth Logic. When BTstack is up and running, send Enable DeviceUnder Test Mode Command and print its result.

For more details on discovering remote devices, please see Section on GAP.

8.30.2. Main Application Setup. Listing here shows main application code. Itregisters the HCI packet handler and starts the Bluetooth stack.

int btstack main ( int argc , const char ∗ argv [ ] ) ;int btstack main ( int argc , const char ∗ argv [ ] ) {

(void ) argc ;(void ) argv ;

// make dev i c e connec tab l e// @note : g ap conne c t a b l e c on t r o l w i l l be enab led when an

L2CAP s e r v i c e// ( e . g . RFCOMM) i s i n i t i a l i z e d ) . Therefore , i t ’ s not needed

in r e gu l a r a p p l i c a t i o n sg a p c o n n e c t a b l e c o n t r o l (1 ) ;

// make dev i c e d i s c o v e r a b l eg a p d i s c o v e r a b l e c o n t r o l (1 ) ;

h c i e v e n t c a l l b a c k r e g i s t r a t i o n . c a l l b a c k = &packet hand le r ;h c i add even t hand l e r (& h c i e v e n t c a l l b a c k r e g i s t r a t i o n ) ;

// turn on !h c i p o w e r c o n t r o l (HCI POWER ON) ;

return 0 ;}

Listing 80. Setup packet handler

9. Chipsets

In this chapter, we first explain how Bluetooth chipsets are connected phys-ically and then provide information about popular Bluetooth chipset and theiruse with BTstack.

Page 128: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

127

9.1. HCI Interface. The communication between a Host (a computer or anMCU) and a Host Controller (the actual Bluetooth chipset) follows the HostController Interface (HCI), see 1. HCI defines how commands, events, asynchro-nous and synchronous data packets are exchanged. Asynchronous packets (ACL)are used for data transfer, while synchronous packets (SCO) are used for Voicewith the Headset and the Hands-Free Profiles.

Figure 1. Host Controller to Host connection

9.1.1. HCI H2. On desktop-class computers incl. laptops, USB is mainly usedas HCI transport layer. For USB Bluetooth chipsets, there is little variation:most USB dongles on the market currently contain a Broadcom BCM20702 or aCSR 851x chipset. It is also called H2.

On embedded systems, UART connections are used instead, although USBcould be used as well.

For UART connections, different transport layer variants exist.

Page 129: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

128

9.1.2. HCI H4. The most common one is the official “UART Transport”, alsocalled H4. It requires hardware flow control via the CTS/RTS lines and assumesno errors on the UART lines.

9.1.3. HCI H5. The “Three-Wire UART Transport”, also called H5, makes useof the SLIP protocol to transmit a packet and can deal with packet loss andbit-errors by retransmission. While it is possible to use H5 really with “threewires” without hardware handshake, we recommend to use a full UART withhardware handshake. If your design lacks the hardware handshake, H5 is youronly option.

9.1.4. BCSP. The predecessor of H5. The main difference to H5 is that EvenParity is used for BCSP. To use BCSP with BTstack, you use the H5 transportand can call hci transport h5 enable bcsp mode

9.1.5. eHCILL. Finally, Texas Instruments extended H4 to create the “eHCILLtransport” layer that allows both sides to enter sleep mode without loosing syn-chronisation. While it is easier to implement than H5, it it is only supported byTI chipsets and cannot handle packet loss or bit-errors.

9.1.6. H4 over SPI. Chipsets from Dialog Semiconductor and EM Marin allowto send H4 formatted HCI packets via SPI. SPI has the benefit of a simplerimplementation for both Host Controller and Host as it does not require anexact clock. The SPI Master, here the Host, provides the SPI Clock and theSPI Slave (Host Controller) only has to read and update it’s data lines when theclock line changes. The EM9304 supports an SPI clock of up to 8 Mhz. However,an additional protocol is needed to let the Host know when the Host Controllerhas HCI packet for it. Often, an additional GPIO is used to signal this.

9.1.7. HCI Shortcomings. Unfortunately, the HCI standard misses a few relevantdetails:

• For UART based connections, the initial baud rate isn’t defined but mostBluetooth chipsets use 115200 baud. For better throughput, a higherbaud rate is necessary, but there’s no standard HCI command to changeit. Instead, each vendor had to come up with their own set of vendor-specific commands. Sometimes, additional steps, e.g. doing a warm reset,are necessary to activate the baud rate change as well.• Some Bluetooth chipsets don’t have a unique MAC address. On start,

the MAC address needs to be set, but there’s no standard HCI commandto set it.• SCO data for Voice can either be transmitted via the HCI interface or

via an explicit PCM/I2S interface on the chipset. Most chipsets defaultto the PCM/I2S interface. To use it via USB or for Wide-Band Speech inthe Hands-Free Profile, the data needs to be delivered to the host MCU.Newer Bluetooth standards define a HCI command to configure the SCOrouting, but it is not implemented in the chipsets we’ve tested so far.Instead, this is configured in a vendor-specific way as well.

Page 130: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

129

• In addition, most vendors allow to patch or configure their chipsets atrun time by sending custom commands to the chipset. Obviously, this isalso vendor dependent.

9.2. Documentation and Support. The level of developer documentation andsupport varies widely between the various Bluetooth chipset providers.

From our experience, only Texas Instruments and EM Microelectronics provideall relevant information directly on their website. Nordic Semiconductor does notofficially have Bluetooth chipsets with HCI interface, but their the documentationon their nRF5 series is complete and very informative. TI and Nordic also provideexcellent support via their respective web forum.

Broadcom, whose Bluetooth + Wifi division has been acquired by the CypressSemiconductor Corporation, provides developer documentation only to large cus-tomers as far as we know. It’s possible to join their Community forum anddownload the WICED SDK. The WICED SDK is targeted at Wifi + BluetoothCombo chipsets and contains the necessary chipset patch files.

CSR, which has been acquired by Qualcomm, provides all relevant informationon their Support website after signing an NDA.

Chipset TypeHCITransport

BD ADDR(1)

SCOoverHCI (2)

LEDLE

MultipleLE Roles

BTstackfolder Comment

AtmelATWILC3000

LE H4 Yes Don’tknow

No No atwilc3000BLEFirmwaresize:60kB

BroadcomUART

Dualmode

H4, H5 Rarely Probably(2)

No Maybe(3)

bcm MaxUARTbau-drate2mbps

BroadcomUSBDongles

Dualmode

USB Yes Yes No No bcm

CSRUART

Dualmode

H4,H5,BCSP

Rarely No(didn’twork)

No No csr

CSRUSBDongles

Dualmode

USB Mostly Yes No No csr

CypressCYW20704

Dualmode

H4,H5,USB

Don’tknow

Probably(2)

Yes Yes bcm

Page 131: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

130

Chipset TypeHCITransport

BD ADDR(1)

SCOoverHCI (2)

LEDLE

MultipleLE Roles

BTstackfolder Comment

DialogDA14581

LE H4,SPI

No n.a. No No da14581 OfficialHCIfirmwarein-cludedinBTstack

DialogDA14585

LE H4,SPI

No n.a. Yes Yes da14581 OfficialHCIfirmwarein-cludedinBTstack

EspressifESP32

Dualmode

VHCI Yes Not yet Yes Yes SoCwithBlue-toothandWifi

EM9301

LE SPI,H4

No n.a. No No em9301 CustomHCISPIimplementation

EM9304

LE SPI,H4

Yes n.a. Yes Yes em9301 CustomHCISPIimplementation

IntelDualWireless8260,8265

Dualmode

USB Yes Probably Don’tknow

Don’tknow

intel Firmwaresize:400kB

NordicnRF

LE H4 FixedRandom

n.a. Yes Yes RequiresHCIfirmware

Page 132: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

131

Chipset TypeHCITransport

BD ADDR(1)

SCOoverHCI (2)

LEDLE

MultipleLE Roles

BTstackfolder Comment

STMSTLC2500D

ClassicH4 No No(didn’ttry)

n.a n.a. stlc2500dCustomdeepsleepman-age-mentnotsupported

ToshibaTC35661

Dualmode

H4 No No No No tc3566 Only-007/009mod-elspro-videfullHCI.Seebelow

TICC256x,WL183x

Dualmode

H4,H5,eHCILL

Yes Yes No Yes forCC256XC

cc256x AlsoWL185x,WL187x,andWL189x

9.3. Chipset Overview. Notes:

1. BD ADDR: Indiates if Bluetooth chipset compes with its own valid MACAddess. Better Broadcom and CSR dongles usually come with a MACaddress from the dongle manufacturer, but cheaper ones might come withidentical addresses.

2. SCO over HCI: All Bluetooth Classic chipsets support SCO over HCI,for those that are marked with No, we either didn’t try or didn’t foundenough information to configure it correctly.

3. Multiple LE Roles: Apple uses Broadcom Bluetooth+Wifi in their iOSdevices and newer iOS versions support multiple concurrent LE roles, soat least some Broadcom models support multiple concurrent LE roles.

9.4. Atmel/Microchip. The ATILC3000 Bluetooth/Wifi combo controller hasbeen used with Linux on embedded devices by Atmel/Microchip. Drivers anddocumentation are available from a GitHub repository. The ATWILC3000 hasa basic HCI implementation stored in ROM and requires a firmware image to beuploaded before it can be used. The BLE Controller is qualified as QDID 99659.

Page 133: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

132

Please note: the BLE firmware is around 60 kB. It might need a separate Wififirmware as well.

BD Addr can be set with vendor-specific command although all chipsets havean official address stored. The BD ADDR lookup results in “Newport MediaInc.” which was acquired by Atmel in 2014.

Baud rate can be set with a custom command.BTstack integration: btstack chipset atwilc3000.c contains the code to down-

load the Bluetooth firmware image into the RAM of the ATWILC3000. Afterthat, it can be normally used by BTstack.

9.5. Broadcom/Cypress Semiconductor. Before the Broadcom Wifi+Bluetoothdivision was taken over by Cypress Semiconductor, it was not possible to buyBroadcom chipset in low quantities. Nevertheless, module manufacturers likeAmpak created modules that contained Broadcom BCM chipsets (Bluetooth aswell as Bluetooth+Wifi combos) that might already have been pre-tested forFCC and similar certifications.

A popular example is the Ampak AP6212A module that contains an BCM43438A1 and is used on the Raspberry Pi 3, the RedBear Duo, and the RedBearIoT pHAT for older Raspberry Pi models.

The CYW20704 A2 controller supports both DLE as well as multiple LE rolesand is available e.g. from LairdTech as UART module (BT860), USB module(BT850), and USB dongle.

The best source for documentation on vendor specific commands so far hasbeen the source code for blueZ and the Bluedroid Bluetooth stack from Android.

Broadcom USB dongles do not require special configuration, however SCOdata is not routed over USB by default.

Init scripts: For UART connected chipsets, an init script has to be up-loaded after power on. For Bluetooth chipsets that are used in BroadcomWifi+Bluetooth combos, this file often can be found as a binary file in Linuxdistributions with the ending ‘.hcd’ or as part of the WICED SDK as C sourcefile that contains the init script as a data array for use without a file system.

To find the correct file, Broadcom chipsets return their model number whenasked for their local name.

BTstack supports uploading of the init script in two variants: using .hcd fileslooked up by name in the posix-h4 port and by linking against the init script inthe WICED port. While the init script is processed, the chipsets RTS line goeshigh, but only 2 ms after the command complete event for the last command fromthe init script was sent. BTstack waits for 10 ms after receiving the commandcomplete event for the last command to avoid sending before RTS goes high andthe command fails.

BD Addr can be set with a custom command. A fixed address is providedon some modules, e.g. the AP6212A, but not on others.

SCO data can be configured with a custom command found in the bluezsources. It works with USB chipsets. The chipsets don’t implement the SCOFlow Control that is used by BTstack for UART connected devices. A forumsuggests to send SCO packets as fast as they are received since both directionshave the same constant speed.

Page 134: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

133

Baud rate can be set with custom command. The baud rate resets during thewarm start after uploading the init script. So, the overall scheme is this: startat default baud rate, get local version info, send custom Broadcom baud ratechange command, wait for response, set local UART to high baud rate, and thensend init script. After sending the last command from the init script, reset thelocal UART. Finally, send custom baud rate change command, wait for response,and set local UART to high baud rate.

BTstack integration: The common code for all Broadcom chipsets is pro-vided by btstack chipset bcm.c. During the setup, btstack chipset bcm instancefunction is used to get a btstack chipset t instance and passed to hci init function.

SCO Data can be routed over HCI for both USB dongles and UART connec-tions, however BTstack does not support flow control for UART connections.HSP and HFP Narrow Band Speech is supported via I2C/PCM pins.

9.6. CSR / Qualcomm Incorporated. CSR plc has been acquired by Qual-comm Incorporated in August 2015.

Similar to Broadcom, the best source for documentation is the source code forblueZ.

CSR USB dongles do not require special configuration and SCO data is routedover USB by default.

CSR chipset do not require an actual init script in general, but they allow toconfigure the chipset via so-called PSKEYs. After setting one or more PSKEYs,a warm reset activates the new setting.

BD Addr can be set via PSKEY. A fixed address can be provided if thechipset has some kind of persistent memory to store it. Most USB Bluetoothdongles have a fixed BD ADDR.

SCO data can be configured via a set of PSKEYs. We haven’t been able toroute SCO data over HCI for UART connections yet.

Baud rate can be set as part of the initial configuration and gets actived bythe warm reset.

BTstack integration: The common code for all Broadcom chipsets is pro-vided by btstack chipset csr.c. During the setup, btstack chipset csr instancefunction is used to get a btstack chipset t instance and passed to hci init function.The baud rate is set during the general configuration.

SCO Data is routed over HCI for USB dongles, but not for UART connections.HSP and HFP Narrow Band Speech is supported via I2C/PCM pins.

9.7. Dialog Semiconductor. Dialog Semiconductor offers the DA14581, anLE-only SoC that can be programmed with an HCI firmware. The HCI firmwarecan be uploaded on boot into SRAM or stored in the OTP (One-time pro-grammable) memory, or in an external SPI.

It does not implement the Data Length Extension or supports multiple con-current roles.

The newer DA14585 uses the same firmware upload mechanism as the 581model. In addition, it supports both Data Length Extension as well as multipleconcurrent roles.

BD Addr fixed to 80:EA:CA:00:00:01. No command in HCI firmware to setit differently. Random addresses could be used instead.

Page 135: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

134

Baud rate: The baud rate is fixed at 115200 with the provided firmware.A higher baud rate could be achieved by re-compiling the HCI firmware usingDialog’s HCI SDK.

BTstack integration: btstack chipset da14581.c contains the code to down-load the provided HCI firmware into the SRAM of the DA14581. After that, itcan be used as any other HCI chipset.

9.8. Espressif ESP32. The ESP32 is a SoC with a built-in Dual mode Blue-tooth and Wifi radio. The HCI Controller is implemented in software and ac-cessed via a so called Virtual HCI (VHCI) interface. It supports both LE DataLength Extensions (DLE) as well as multiple LE roles. SCO isn’t supportedcurrently, but Espressif is working on it.

Bluetooth/Wifi Co-existance didn’t work until recently and seems to have beenfixed

9.9. EM Microelectronic Marin. For a long time, the EM9301 has been theonly Bluetooth Single-Mode LE chipset with an HCI interface. The EM9301 canbe connected via SPI or UART. The UART interface does not support hardwareflow control and is not recommended for use with BTstack. The SPI mode usesa proprietary but documented extension to implement flow control and signal ifthe EM9301 has data to send.

In December 2016, EM released the new EM9304 that also features an HCImode and adds support for optional Bluetooth 4.2. features. It supports theData Length Extension and up to 8 LE roles. The EM9304 is a larger MCU thatallows to run custom code on it. For this, an advanced mechanism to uploadconfiguration and firmware to RAM or into an One-Time-Programmable area of128 kB is supported. It supports a superset of the vendor specific commands ofthe EM9301.

EM9304 is used by the ‘stm32-l053r8-em9304’ port in BTstack. The port.cfile also contains an IRQ+DMA-driven implementation of the SPI H4 protocolspecified in the datasheet.

BD Addr must be set during startup for EM9301 since it does not have astored fix address. The EM9304 comes with an valid address stored in OTP.

SCO data is not supported since it is LE only.Baud rate can be set for UART mode. For SPI, the master controls the speed

via the SPI Clock line. With 3.3V, 16 Mhz is supported.Init scripts are not required although it is possible to upload small firmware

patches to RAM or the OTP memory (EM9304 only).BTstack integration: The common code for the EM9304 is provided by bt-

stack chipset em9301.c. During the setup, btstack chipset em9301 instance func-tion is used to get a btstack chipset t instance and passed to hci init function.It enables to set the BD Addr during start.

9.10. Intel Dual Wireless 8260, 8265. Wifi/Bluetooth combo cards mainlyused in mobile computers. The Bluetooth part requires the upload of a firmwarefile and a configuration file. SCO, DLE, Multiple roles not tested.

Page 136: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

135

9.11. Nordic nRF5 series. The Single-Mode LE chipsets from the NordicnRF5 series chipsets usually do not have an HCI interface. Instead, they providean LE Bluetooth Stack as a binary library, the so-called SoftDevices. Developercan write their Bluetooth application on top of this library. Since the chipset canbe programmed, it can also be loaded with a firmware that provides a regularHCI H4 interface for a Host.

An interesting feature of the nRF5 chipsets is that they can support multipleLE roles at the same time, e.g. being Central in one connection and a Peripheralin another connection. Also, the nRF52 SoftDevice implementation supports theBluetooth 4.2 Data Length Extension.

Both nRF5 series, the nRF51 and the nRF52, can be used with an HCIfirmware. The nRF51 does not support encrypted connections at the moment(November 18th, 2016) although this might become supported as well.

BD ADDR is not set automatically. However, during production, a 64-bitrandom number is stored in the each chip. Nordic uses this random number asa random static address in their SoftDevice implementation.

SCO data is not supported since it is LE only.Baud rate is fixed to 115200 by the patch although the firmware could be

extended to support a baud rate change.Init script is not required.BTstack integration: Support for a nRF5 chipset with the Zephyr Con-

troller is provided by btstack chipset zephyr.c. It queries the static random ad-dress during init.

To use these chipsets with BTstack, you need to install an arm-none-eabi gcctoolchain and the nRF5x Command Line Tools incl. the J-Link drivers, checkoutthe Zephyr project, apply a minimal patch to help with using a random staticaddress, and flash it onto the chipset:

• Install J-Link Software and documentation pack.• Get nrfjprog as part of the nRFx-Command-Line-Tools. Click on Down-

loads tab on the top and look for your OS.• Checkout Zephyr and install toolchain. We recommend using the arm-

non-eabi gcc binaries instead of compiling it yourself. At least on OS X,this failed for us.• In samples/bluetooth/hci uart compile the firmware for nRF52 Dev Kit

$ make BOARD=nrf52 pca10040

• Upload the firmware$ ./flash nrf52 pca10040.sh

• For the nRF51 Dev Kit, use make BOARD=nrf51 pca10028 and ./ flash nrf51 10028

.sh with the nRF51 kit.• The nRF5 dev kit acts as an LE HCI Controller with H4 interface.

9.12. STMicroelectronics. STMicroelectronics offers the Bluetooth V2.1 +EDR chipset STLC2500D that supports SPI and UART H4 connection.

Page 137: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

136

BD Addr can be set with custom command although all chipsets have anofficial address stored.

SCO data might work. We didn’t try.Baud rate can be set with custom command. The baud rate change of the

chipset happens within 0.5 seconds. At least on BTstack, knowning exactly whenthe command was fully sent over the UART is non-trivial, so BTstack switchesto the new baud rate after 100 ms to expect the command response on the newspeed.

Init scripts are not required although it is possible to upload firmware patches.BTstack integration: Support for the STLC2500C is provided by btstack chipset stlc.c.

During the setup, btstack chipset stlc2500d instance function is used to get a bt-stack chipset t instance and passed to hci init function. It enables higher UARTbaud rate and to set the BD Addr during startup.

9.13. Texas Instruments CC256x series. The Texas Instruments CC256xseries is currently in its fourth iteration and provides a Classic-only (CC2560), aDual-mode (CC2564), and a Classic + ANT (CC2567) model. A variant of theDual-mode chipset is also integrated into TI’s WiLink 8 Wifi+Bluetooth combomodules of the WL183x, WL185x, WL187x, and WL189x series. Some of thelatter support ANT as well.

The CC256x chipset is connected via an UART connection and supports theH4, H5 (since third iteration), and eHCILL.

The latest generation CC256xC chipsets support multiple LE roles in parallel.The different CC256x chipset can be identified by the LMP Subversion re-

turned by the hci read local version information command. TI also uses a nu-meric way (AKA) to identify their chipsets. The table shows the LMP Subversionand AKA number for the CC256x and the WL18xx series.

Chipset LMP Subversion AKA

CC2560 0x191f 6.2.31CC2560A, CC2564, CC2567 0x1B0F 6.6.15CC256xB 0x1B90 6.7.16CC256xC 0x9a1a 6.12.26WL18xx 0xac20 11.8.32

SCO data is routed to the I2S/PCM interface but can be configured with theHCI VS Write SCO Configuration command.

Baud rate can be set with HCI VS Update UART HCI Baudrate. The chipsetconfirms the change with a command complete event after which the local UARTis set to the new speed. Oddly enough, the CC256x chipsets ignore the incomingCTS line during this particular command complete response.

If you’ve implemented the hal uart dma.h without an additional ring buffer(as recommended!) and you have a bit of delay, e.g. because of thread switchingon a RTOS, this could cause a UART overrun. If this happens, BTstack providesa workaround in the HCI H4 transport implementation by adding #define EN-ABLE CC256X BAUDRATE CHANGE FLOWCONTROL BUG WORKAROUNDto your btstack config.h. If this is enabled, the H4 transport layer will resort to

Page 138: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

137

“deep packet inspection” to first check if its a TI controller and then wait for theHCI VS Update UART HCI Baudrate. When detected, it will tweak the nextUART read to expect the HCI Command Complete event.

BD Addr can be set with HCI VS Write BD Addr although all chipsets havean official address stored.

Init Scripts. In order to use the CC256x chipset an initialization script mustbe obtained and converted into a C file for use with BTstack. For newer revisions,TI provides a main.bts and a ble add on.bts that need to be combined.

The Makefile at chipset/cc256x/Makefile.inc is able to automatically downloadand convert the requested file. It does this by:

• Downloading one or more BTS files for your chipset.• Running the Python script:

. / c o n v e r t b t s i n i t s c r i p t s . py main . bts [ b l e add on . bts ] o u t p u t f i l e .c

BTstack integration: The common code for all CC256x chipsets is providedby btstack chipset cc256x.c. During the setup, btstack chipset cc256x instancefunction is used to get a btstack chipset t instance and passed to hci init func-tion. btstack chipset cc256x lmp subversion provides the LMP Subversion for theselected init script.

SCO Data can be routed over HCI, so HFP Wide-Band Speech is supported.

9.14. Toshiba. The Toshiba TC35661 Dual-Mode chipset is available in threevariants: standalone incl. binary Bluetooth stack, as a module with embeddedstack or with a regular HCI interface. The HCI variant has the model numberTC35661–007 resp TC35561-009 for the newer silicon.

We first tried their USB Evaluation Stick that contains an USB-to-UARTadapter and the PAN1026 module that contains the TC35661 -501. While it doessupport the HCI interface and Bluetooth Classic operations worked as expected,LE HCI Commands are not supported. With the -007 and the -009 models,everything works as expected.

SCO data does not seem to be supported.Baud rate can be set with custom command.BD Addr must be set with custom command. It does not have a stored

valid public BD Addr.Init Script is not required. A patch file might be uploaded.BTstack integration: Support for the TC35661 series is provided by bt-

stack chipset tc3566x.c. During the setup, btstack chipset tc3566x instance func-tion is used to get a btstack chipset t instance and passed to hci init function.It enables higher UART baud rate and sets the BD Addr during startup.

10. Porting to Other Platforms

In this section, we highlight the BTstack components that need to be adjustedfor different hardware platforms.

Page 139: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

138

10.1. Time Abstraction Layer. BTstack requires a way to learn about passingtime. btstack run loop embedded.c supports two different modes: system ticks ora system clock with millisecond resolution. BTstack’s timing requirements arequite low as only Bluetooth timeouts in the second range need to be handled.

10.1.1. Tick Hardware Abstraction. If your platform doesn’t require a systemclock or if you already have a system tick (as it is the default with CMSIS onARM Cortex devices), you can use that to implement BTstack’s time abstractionin include/btstack/hal tick.h>.

For this, you need to define HAVE EMBEDDED TICK in btstack config.h:

#define HAVE EMBEDDED TICK

Then, you need to implement the functions hal tick init and hal tick set handler,which will be called during the initialization of the run loop.

void h a l t i c k i n i t (void ) ;void h a l t i c k s e t h a n d l e r (void (∗ t i c k h a n d l e r ) (void ) ) ;int h a l t i c k g e t t i c k p e r i o d i n m s (void ) ;

After BTstack calls hal tick init() and hal tick set handler(tick handler), it ex-pects that the tick handler gets called every hal tick get tick period in ms() ms.

10.1.2. Time MS Hardware Abstraction. If your platform already has a systemclock or it is more convenient to provide such a clock, you can use the Time MSHardware Abstraction in include/btstack/hal time ms.h.

For this, you need to define HAVE EMBEDDED TIME MS in btstack config.h:

#define HAVE EMBEDDED TIME MS

Then, you need to implement the function hal time ms(), which will be calledfrom BTstack’s run loop and when setting a timer for the future. It has to returnthe time in milliseconds.

uint32 t hal t ime ms (void ) ;

10.2. Bluetooth Hardware Control API. The Bluetooth hardware controlAPI can provide the HCI layer with a custom initialization script, a vendor-specific baud rate change command, and system power notifications. It is alsoused to control the power mode of the Bluetooth module, i.e., turning it on/offand putting to sleep. In addition, it provides an error handler hw error that iscalled when a Hardware Error is reported by the Bluetooth module. The callbackallows for persistent logging or signaling of this failure.

Page 140: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

139

Overall, the struct btstack control t encapsulates common functionality that isnot covered by the Bluetooth specification. As an example, the btstack chipset cc256x in-stance function returns a pointer to a control struct suitable for the CC256xchipset.

10.3. HCI Transport Implementation. On embedded systems, a Bluetoothmodule can be connected via USB or an UART port. BTstack implements threeUART based protocols for carrying HCI commands, events and data betweena host and a Bluetooth module: HCI UART Transport Layer (H4), H4 witheHCILL support, a lightweight low-power variant by Texas Instruments, and theThree-Wire UART Transport Layer (H5).

10.3.1. HCI UART Transport Layer (H4). Most embedded UART interfaces op-erate on the byte level and generate a processor interrupt when a byte was re-ceived. In the interrupt handler, common UART drivers then place the receiveddata in a ring buffer and set a flag for further processing or notify the higher-levelcode, i.e., in our case the Bluetooth stack.

Bluetooth communication is packet-based and a single packet may contain upto 1021 bytes. Calling a data received handler of the Bluetooth stack for everybyte creates an unnecessary overhead. To avoid that, a Bluetooth packet can beread as multiple blocks where the amount of bytes to read is known in advance.Even better would be the use of on-chip DMA modules for these block reads, ifavailable.

The BTstack UART Hardware Abstraction Layer API reflects this design ap-proach and the underlying UART driver has to implement the following API:

void h a l u a r t d m a i n i t (void ) ;void h a l u a r t d m a s e t b l o c k r e c e i v e d (void (∗ b lock hand l e r ) (void ) ) ;void h a l u a r t d m a s e t b l o c k s e n t (void (∗ b lock hand l e r ) (void ) ) ;int ha l uart dma set baud (uint32 t baud ) ;void ha l uar t dma send b lock ( const uint8 t ∗ bu f f e r , uint16 t l en ) ;void h a l u a r t d m a r e c e i v e b l o c k ( uint8 t ∗ bu f f e r , uint16 t l en ) ;

The main HCI H4 implementations for embedded system is *hci h4 transport-dma* function. This function calls the following sequence: hal uart dma init,

hal uart dma set block received and hal uart dma set block sent functions. thissequence, the HCI layer will start packet processing by calling *hal uart- dma receive block*function. The HAL implementation is responsible for reading the requestedamount of bytes, stopping incoming data via the RTS line when the requestedamount of data was received and has to call the handler. By this, the HALimplementation can stay generic, while requiring only three callbacks per HCIpacket.

10.3.2. H4 with eHCILL support. With the standard H4 protocol interface, it isnot possible for either the host nor the baseband controller to enter a sleep mode.Besides the official H5 protocol, various chip vendors came up with proprietarysolutions to this. The eHCILL support by Texas Instruments allows both thehost and the baseband controller to independently enter sleep mode without

Page 141: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

140

loosing their synchronization with the HCI H4 Transport Layer. In additionto the IRQ-driven block-wise RX and TX, eHCILL requires a callback for CTSinterrupts.

void h a l u a r t d m a s e t c t s i r q h a n d l e r (void (∗ c t s i r q h a n d l e r ) (void ) ) ;void h a l u a r t d m a s e t s l e e p ( uint8 t s l e e p ) ;

10.3.3. H5. H5, makes use of the SLIP protocol to transmit a packet and candeal with packet loss and bit-errors by retransmission. Since it can recover frompacket loss, it’s also possible for either side to enter sleep mode without loosingsynchronization.

The use of hardware flow control in H5 is optional, however, since BTstackuses hardware flow control to avoid packet buffers, it’s recommended to only useH5 with RTS/CTS as well.

For porting, the implementation follows the regular H4 protocol describedabove.

10.4. Persistent Storage APIs. On embedded systems there is no generic wayto persist data like link keys or remote device names, as every type of a devicehas its own capabilities, particularities and limitations. The persistent storageAPIs provides an interface to implement concrete drivers for a particular system.

10.4.1. Link Key DB. As an example and for testing purposes, BTstack providesthe memory-only implementation btstack link key db memory. An implementa-tion has to conform to the interface in Listing below.

typedef struct {// managementvoid (∗ open ) ( ) ;void (∗ c l o s e ) ( ) ;

// l i n k keyint (∗ g e t l i n k k e y ) ( bd addr t bd addr , l i n k k e y t l i n k k e y )

;void (∗ p u t l i n k k e y ) ( bd addr t bd addr , l i n k k e y t key ) ;void (∗ d e l e t e l i n k k e y ) ( bd addr t bd addr ) ;

} b t s t a c k l i n k k e y d b t ;

Listing 81. Persistent storage interface.

11. Existing Ports

Here is a list of existing ports:

• BTstack port for Ambiq Apollo2 with EM9304• BTstack Port for the Espressif ESP32 Platform• BTstack for iOS

Page 142: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

141

• BTstack Port for POSIX Systems with libusb Library• BTstack Port for POSIX Systems with Intel Wireless 8260/8265 Con-

trollers• BTstack Port for the Maxim MAX32630FTHR ARM Cortex-M4F• Experimental port of BTstack to Zephyr running on Nordic nRF5 Series• Experimental port for Nordic nRF5 Series• BTstack Port for the Microchip PIC32 Harmony Platform• BTstack Port for POSIX Systems with H4 Bluetooth Controller• POSIX H4 Port for Atmel ATWILC3000• POSIX H4 Port for Dialog Semiconductor DA14581• POSIX H4 Port for Dialog Semiconductor DA14585• BTstack port for Zephyr Controller with HCI UART Firmware Connec-

tected To POSIX System• BTstack Port for Raspberry Pi 3 with BCM4343 Bluetooth/Wifi Con-

troller• BTstack port for SAMV71 Ultra Xplained with ATWILC3000 SHIELD• STM32 F103RB Nucleo with CC256x• BTstack port for STM32 F4 Discovery Board with CC256x• BTstack port for STM32 Nucleo-L053R8 Board with an EM9304 Shield

- EM9304 DVK• BTstack port for WICED platform• BTstack port for WICED platform using H5 transport and Broadcom/-

Cypress Bluetooth chipsets.• BTstack Port for Windows Systems with Bluetooth Controller connected

via Serial Port• BTstack port for Zephyr Controller with HCI UART Firmware Connec-

tected To POSIX System• BTstack port for Windows Systems using the WinUSB Driver• BTstack port for Windows Systems with Intel Wireless 8260/8265 Con-

trollers

12. BTstack port for Ambiq Apollo2 with EM9304

This port uses the Ambiq Apollo2 EVB and the Ambiq EM9304 (AM BLE)shield. HAL and BSP from Ambiq Suite 1.2.11 were used together with theregular ARM GCC toolchain. Firmware upload is possible via the internal J-Link interface or the 10-pin Mini ARM-JTAG Interface.

12.1. Hardware. Ambiq Apollo2 EVB + AM BLE Shield - http://ambiqmicro.com/apollo-ultra-low-power-mcus/apollo2-mcu/

12.2. Software. AmbiqSuite: - http://ambiqmicro.com/apollo-ultra-low-power-mcus/apollo2-mcu/

Please clone BTstack as AmbiqSuite/third-party/bstack folder into the Am-biqSuite.

12.3. Create Example Projects. To create example GCC projects, go to theApollo2-EM9304 folder

Page 143: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

142

$ cd port / apo l lo2−em9304

and run make

$ . / c reate example s . py

All examples are placed in the boards/apollo2 evb am ble/examples folderwith btstack prefix.

12.4. Compile & Run Example Project. Go to to the gcc folder of one ofthe example folders and run make

$ run make

To upload, please follow the instructions in the Apollo Getting Started docu-ments.

12.5. Debug output. printf is routed over the USB connector of the EVB at115200.

In port/apollo2-em9304/btstack config.h additional debug information can beenabled by uncommenting ENABLE LOG INFO.

Also, the full packet log can be enabled in src/btstack port.c by uncommentingthe hci dump open(..) line. The console output can then be converted into .pklgfiles for OS X PacketLogger or WireShark by running tool/create packet log.py

13. TODO

• BTstack’s TLV persisten storage via Flash memory is not implementedyet.• SPI Fullduplex: Newer Apollo 2 revisions supports SPI Full Duplex. The

Ambiq Suite 1.2.11 does not cover Full Duplex with IRQ callback. Itcould be emulated by setting the Full Duplex mode and doing a regularwrite operation. When the write is complete, the received data can beread from the IOM FIFO.• During MCU sleep without an ongoing SPI operation, the SPI could be

fully disabled, which would reduce enrgey consumption. # BTstack Portfor the Espressif ESP32 Platform {#sec:esp32Port}

Status: Basic port incl. all examples. BTstack runs on dedicated FreeRTOSthread. Multi threading (calling BTstack functions from a different thread) isnot supported.

13.1. Setup.

• Follow Espressif IoT Development Framework (ESP-IDF) setup to installXTensa toolchain and the ESP-IDF.• Make sure your checkout is newer than 4654278b1bd6b7f7f55013f7edad76109f7ee944

from Aug 25th, 2017

Page 144: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

143

• In port/esp32/template, configure the serial port for firmware upload asdescribed in the ESP-IDF setup guides.

13.2. Usage. In port/esp32, run

. / i n t e g r a t e b t s t a c k . py

The script will copy parts of the BTstack tree into the ESP-IDF as $IDF PATH/components/btstackand then create project folders for all examples.

Each example project folder, e.g. port/esp32/examples/spp and le counter,contains a Makefile. Please run the command again after updating the BTstacktree (e.g. by git pull) to also update the copy in the ESP-IDF.

To compile an example, run:

make

To upload the binary to your device, run:

make f l a s h

To get the debug output, run:

make monitor

You can quit the monitor with CTRL-].

13.3. Old Make Versions. Compilation fails with older versions of the maketool, e.g. make 3.8.1 (from 2006) provided by the current Xcode 9 on macOS orUbuntu 14.04.1 LTS.

Interestingly, if you run make a second time, it completes the compilation.

13.4. Configuration. The sdkconfig of the example template disables the origi-nal Bluedroid stack by disabling the CONFIG BLUEDROID ENABLED kconfigoption.

13.5. Limitations.

13.5.1. Issues with the Bluetooth Controller Implementation. There are differ-ent issues in the Bluetooth Controller of the ESP32 that is provided in bi-nary. We’ve submitted appropriate issues on the GitHub Issues page here:https://github.com/espressif/esp-idf/issues/created by/mringwal

13.5.2. Audio playback. Audio playback is implemented by btstack audio esp32.c.It assumes an I2S Codec connected as follows:

Page 145: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

144

ESP32 pin I2S Pin

GPIO25 LRCKGPIO26 BCLKGPIO22 DATA

We’ve used the MAX98357A on the Adafruit breakout board. The sim-plest example is the mod player, which plays back an 8 kB sound file and thea2dp sink demo implements a basic Bluetooth loudspeaker.

Audio input via I2S or ADC is not supported yet. We might have a look at itwhen HFP/SCO via VHCI is working on the ESP32.

13.5.3. Multi-Threading. BTstack is not thread-safe, but you’re using a multi-threading OS. Any function that is called from BTstack, e.g. packet handlers,can directly call into BTstack without issues. For other situations, you needto provide some general ‘do BTstack tasks’ function and trigger BTstack toexecute it on its own thread. To call a function from the BTstack thread, thereare currently two options:

• btstack run loop freertos execute code on main thread allows to directlyschedule a function callback, i.e. ‘do BTstack tasks’ function, from theBTstack thread.• Setup a BTstack Data Source (btstack data source t): Set ‘do BTstack

tasks’ function as its process function and enable its polling callback(DATA SOURCE CALLBACK POLL). The process function will be calledin every iteration of the BTstack Run Loop. To trigger a run loop itera-tion, you can call btstack run loop freertos trigger.

With both options, the called function should check if there are any pendingBTstack tasks and execute them.

The ‘run on main thread’ method is only provided by a few ports and requiresa queue to store the calls. This should be used with care, since calling it multipletimes could cause the queue to overflow.

We’re considering different options to make BTstack thread-safe, but for now,please use one of the suggested options.

13.5.4. Acknowledgments. First HCI Reset was sent to Bluetooth chipset by[@mattkelly](https://github.com/mattkelly)

14. BTstack for iOS

BTstack for iOS provides an alternative Bluetooth stack for iOS devices witha public API.

It supports the following Bluetooth Classic protocols: - L2CAP - RFCOMM- SDP

Based on these protocols, applications or daemons can implement various Blue-tooth profiles. Packages that already use BTstack are: BTstack GPS, Blutrol,WeBe++, and various game emulators.

Page 146: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

145

Note: As BTstack directly uses the Bluetooth hardware, the iOS Bluetoothis automatically disabled for BTstack applications & services. You can alwaysturn BTstack off in Settings->BTstack.

Please visit the project page at GitHub for technical information and checkthe port/ios subfolder.

14.1. How to develop. To write BTstack-based applications, you don’t need tocompile the BTstack Cydia package. You can just install it on your JB iOS deviceand copy /usr/lib/libBTstack.dylib into your project and add btstack/includeto your project includes.

While it’s possible to use Xcode, I highly recommend to use theos to createapps & daemons for JB iOS devices instead.

14.2. Compile Instructions for BTstack package. Install the following tools:* Xcode * csu-ios libraries for deployment targets < 6.0 (BTstack compiles againtiOS 3.0 by default) * rpetrich’s or new official theos fork with “lippoplastic” sup-port

Set the $THEOS environment variable to the location of the theos checkout,e.g. like:

export THEOS=/Pr o j e c t s / theos

Go to btstack/port/ios and run make

cd bts tack / port / i o smake package

If everything went right, you’ll end up with a .deb package that you couldinstall via:

make i n s t a l l

14.3. Console Examples. With THEOS set-up as before, you can compile andinstall a set of command line examples in the example folder:

cd bts tack / port / i o s /examplemake

You can copy the created examples to your device using scp and run it fromthere.

14.4. Wii Mote CoocaTouch example. Similar as before, you can compilethe WiiMoteOpenGLDemo by running make:

Page 147: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

146

cd bts tack / port / i o s /example/WiiMoteOpenGLDemomake package

You’ll end up with a deb file that you can install with

make i n s t a l l

Note: as with any other JB application, you need to refresh the SpringBoardicon cache on the device to make the icon show up. After SSH to your device asroot, you can execute these commands:

su mobileu icachee x i t

15. BTstack Port for POSIX Systems with libusb Library

15.1. Compilation. The quickest way to try BTstack is on a Linux or OS Xsystem with an additional USB Bluetooth dongle. It requires pkg-config andlibusb-1.0 or higher to be installed.

On a recent Debian-based system, all you need is:

apt−get i n s t a l l gcc g i t l ibusb −1.0 pkg−c o n f i g

When everything is ready, you compile all examples with:

make

15.2. Environment. On Linux, the USB Bluetooth dongle is usually not acces-sible to a regular user. You can either: - run the examples as root - add a udevrule for your dongle to extend access rights to user processes

To add an udev rule, please create /etc/udev/rules.d/btstack.rules and add this

# Match a l l d e v i c e s from CSRSUBSYSTEM==”usb” , ATTRS{ idVendor}==”0a12” , MODE=”0666”

# Match DeLOCK Bluetooth 4 .0 dongleSUBSYSTEM==”usb” , ATTRS{ idVendor}==”0 a5c ” , ATTRS{ dev i c e}==”21 e8” ,

MODE=”0666”

# Match Asus BT400

Page 148: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

147

SUBSYSTEM==”usb” , ATTRS{ idVendor}==”0b05” , ATTRS{ dev i c e}==”17cb” ,MODE=”0666”

# Match Laird BT860 / Cypress Semiconductor CYW20704A2SUBSYSTEM==”usb” , ATTRS{ idVendor}==”04b4” , ATTRS{ dev i c e}==” f901 ” ,

MODE=”0666”

On macOS, the OS will try to use a plugged-in Bluetooth Controller if oneis available. It’s best to to tell the OS to always use the internal BluetoothContoller.

For this, execute:

sudo nvram bluetoothHostContro l l e rSwi tchBehav ior=never

and then reboot to activate the change.

15.3. Running the examples. BTstack’s HCI USB transport will try to finda suitable Bluetooth module and use it.

On start, BTstack will try to find a suitable Bluetooth module. It will alsoprint the path to the packet log as well as the USB path.

$ . / l e c o u n t e rPacket Log : /tmp/hci dump . pklgBTstack counter 0001USB Path : 06BTstack up and running on 00 :1A: 7D:DA: 7 1 : 1 3 .

If you want to run multiple examples at the same time, it helps to fix the pathto the used Bluetooth module by passing -u usb-path to the executable.

Example running le streamer and le streamer client in two processes, usingBluetooth dongles at USB path 6 and 4:

. / l e s t r e a m e r −u 6S p e c i f i e d USB Path : 06Packet Log : /tmp/ hci dump 6 . pklgUSB Path : 06BTstack up and running on 00 :1A: 7D:DA: 7 1 : 1 3 .To s t a r t the streaming , p l e a s e run the l e s t r e a m e r c l i e n t example on

other device , or use some GATT Explorer , e . g . LightBlue ,BLExplr .

$ . / l e s t r e a m e r c l i e n t −u 4S p e c i f i e d USB Path : 04Packet Log : /tmp/ hci dump 4 . pklgUSB Path : 04BTstack up and running on 00 :1A: 7D:DA: 7 1 : 1 3 .S ta r t scanning !

Page 149: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

148

16. BTstack Port for POSIX Systems with Intel Wireless8260/8265 Controllers

Same as port/libusb, but customized for Intel Wireless 8260 and 8265 Con-trollers. These controller require firmware upload and configuration to work.Firmware and config is downloaded from the Linux firmware repository.

16.1. Compilation. Requirements: - pkg-config - libusb-1.0On a recent Debian-based system, all you need is:

apt−get i n s t a l l gcc g i t l ibusb −1.0 pkg−c o n f i g

When everything is ready, you compile all examples with:

make

16.2. Environment. On Linux, the USB Bluetooth dongle is usually not acces-sible to a regular user. You can either: - run the examples as root - add a udevrule for your dongle to extend access rights to user processes

To add an udev rule, please create /etc/udev/rules.d/btstack.rules and add this

# Match a l l d e v i c e s from CSRSUBSYSTEM==”usb” , ATTRS{ idVendor}==”0a12” , MODE=”0666”

# Match DeLOCK Bluetooth 4 .0 dongleSUBSYSTEM==”usb” , ATTRS{ idVendor}==”0 a5c ” , ATTRS{ dev i c e}==”21 e8” ,

MODE=”0666”

# Match Asus BT400SUBSYSTEM==”usb” , ATTRS{ idVendor}==”0b05” , ATTRS{ dev i c e}==”17cb” ,

MODE=”0666”

# Match Laird BT860 / Cypress Semiconductor CYW20704A2SUBSYSTEM==”usb” , ATTRS{ idVendor}==”04b4” , ATTRS{ dev i c e}==” f901 ” ,

MODE=”0666”

# Match I n t e l Wire l e s s 8260 8265SUBSYSTEM==”usb” , ATTRS{ idVendor}==”8027” , ATTRS{ dev i c e}==”0a2b ,

MODE=”0666”

On macOS, the OS will try to use a plugged-in Bluetooth Controller if oneis available. It’s best to to tell the OS to always use the internal BluetoothContoller.

For this, execute:

sudo nvram bluetoothHostContro l l e rSwi tchBehav ior=never

Page 150: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

149

and then reboot to activate the change.

16.3. Running the examples. BTstack’s HCI USB transport will try to finda suitable Bluetooth module and use it.

On start, BTstack will try to find a suitable Bluetooth module. It will alsoprint the path to the packet log as well as the USB path.

$ . / l e c o u n t e rPacket Log : /tmp/hci dump . pklgUSB Path : 03−01−04−03Firwmare . / ibt −12−16. s f iFirmware upload completeFirmware o p e r a t i o n a lDone 1BTstack counter 0001USB Path : 03−01−04−03

BTstack up and running on F8:34:41:D5:BE:6F.If you want to run multiple examples at the same time, it helps to fix the path

to the used Bluetooth module by passing -u usb-path to the executable.Example running le streamer and le streamer client in two processes, using

Bluetooth dongles at USB path 6 and 4:

. / l e s t r e a m e r −u 6S p e c i f i e d USB Path : 06Packet Log : /tmp/ hci dump 6 . pklgUSB Path : 06BTstack up and running on 00 :1A: 7D:DA: 7 1 : 1 3 .To s t a r t the streaming , p l e a s e run the l e s t r e a m e r c l i e n t example on

other device , or use some GATT Explorer , e . g . LightBlue ,BLExplr .

$ . / l e s t r e a m e r c l i e n t −u 4S p e c i f i e d USB Path : 04Packet Log : /tmp/ hci dump 4 . pklgUSB Path : 04BTstack up and running on 00 :1A: 7D:DA: 7 1 : 1 3 .S ta r t scanning !

17. BTstack Port for the Maxim MAX32630FTHR ARMCortex-M4F

This port uses the MAX32630FTHR ARM Cortex M4F Board with the on-board TI CC2564B Bluetooth controller. It usually comes with the DAPLINKProgramming Adapter. The DAPLINK allows to upload firmware via a virtual

Page 151: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

150

mass storage device (like mbed), provides a virtual COM port for a console, andenables debugging via the SWD interface via OpenOCD.

The port uses non-blocking polling UART communication with hardware flowcontrol for Bluetooth controller. It was tested and achieved up to 1.8 Mbpsbandwidth between two Max32630FTHR boards.

17.1. Software. The Maxim ARM Toolchain is free software that provides pe-ripheral libraries, linker files, initial code and some board files. It also providesEclipse Neon and Maxim modified OpenOCD to program the microcontrollertogether with various examples for Maxim Cortex M4F ARM processors.

For debugging, OpenOCD can be used. The regular OpenOCD does not sup-port Maxim ARM microcontrollers yet, but a modified OpenOCD for use withMaxim devices can be found in the Maxim ARM Toolchain.

17.2. Toolchain Setup. In the Maxim Toolchain installation directory, thereis a setenv.sh file that sets the MAXIM PATH. MAXIM PATH needs to pointto the root directory where the tool chain installed. If you’re lucky and have acompatible ARM GCC Toolchain in your PATH, it might work without callingsetenv.sh script.

17.3. Usage. The examples can be compiled using GNU ARM Toolchain. Afirmware binary can be flashed either by copying the .bin file to the DAPLINKmass storage drive, or by using OpenOCD on the command line, or from EclipseCDT.

17.4. Build. Checkt that MAXIM PATH points to the root directory where thetool chain installed. Then, go to the port/max32630-fthr folder and run “make”command in terminal to generate example projects in the example folder.

In each example folder, e.g. port/max323630-fthr/example/spp and le streamer,you can run “make” again to build an .elf file in the build folder which is conve-nient for debugging using Eclipse or GDB.

For flashing via the virtual USB drive, the “make release” command will gen-erate .bin file in the build folder.

17.5. Eclipse. Toolchain and Eclipse guide can be found in README.pdf filewhere the Maxim Toolchain is installed. Please note that this port was doneusing Makefiles.

17.6. Flashing Max32630 ARM Processor. There are two ways to programthe board. The simplest way is drag and drop the generated .bin file to theDAPLINK mass storage drive. Once the file is copied to the mass storage device,the DAPLINK should program and then run the new firmware.

Alternatively, OpenOCD can be used to flash and debug the device. A suitableprogramming script can be found in the scripts folder.

17.7. Debugging. OpenOCD can also be used for developing and especiallyfor debugging. Eclipse or GDB via OpenOCD could be used for step by stepdebugging.

Page 152: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

151

17.8. Debug output. printf messages are redirected to UART2. UART2 isaccessible via the DAPLINK Programming Adapter as a virtual COM port at115200 baud with no flow control. If this doesn’t work for you, you can connectP3 1 (UART TX) of the MAX32630FTHR board to a USB-to-UART adapter.

Additional debug information can be enabled by uncommenting ENABLE LOG INFOin the src/btstack config.h header file and a clean rebuild.

17.9. TODOs.

• Support for BTSTACK STDIN• Add flash-openocd to Makefile template• Add Eclipse CDT projects for max32630fthr• Implement hal led.h to control LED on board

18. Experimental port of BTstack to Zephyr running on NordicnRF5 Series

18.1. Overview. This port targets the bare Nordic nRF5-Series chipsets withthe BLE Link Layer provided by the Zephyr project.

18.2. Status. Working with nRF52 pca10040 dev board. Public BD ADDR isset to 11:22:33:44:55:66 since the default 00:00:00:00:00:00 is filtered by iOS.

18.3. Getting Started. To integrate BTstack into Zephyr, please move theBTstack project into the Zephyr root folder ‘zephyr’. Please use the Zephry‘1.9-branch’ for now. In the master branch, Zephyr switched the build system toCMake and this port hasn’t been update for that yet.

Then integrate BTstack:

cd /path/ to /zephy/ bts tack / port / nrf5−zephyr. / i n t e g r a t e b t s t a c k . sh

Now, the BTstack examples can be build from the Zephyr examples folder inthe same way as other examples, e.g.:

cd /path/ to / zephyr / samples / bts tack / l e c o u n t e rmake

to build the le counter example for the pca10040 dev kit using the ARM GCCcompiler.

You can use make flash or ./flash nrf52 pca10040.sh to download it onto the board.All examples that provide a GATT Server use the GATT DB in the .gatt

file. Therefore you need to run ./update gatt db.sh in the example folder aftermodifying the .gatt file.

This port does not support Data Sources aside from the HCI Controller.

Page 153: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

152

18.4. TODO.

• printf is configured by patching ‘drivers/serial/uart nrf5.c’ to use 115200(default: 100000). There should be a better way to set baud rate.• enable/configure DLE for max packet size for LE Streamer

19. Experimental port for Nordic nRF5 Series

19.1. Overview. This port targets the bare Nordic nRF5-Series chipsets with-out the proprietary SoftDevice implementations.

Instead of taking shortcuts within BTstack, the idea here is to provide a com-plete HCI Controller interface. This requires to implement an HCI Commandparser, an LE Link Layer.

19.2. Status. Only tested on the pca10028 dev board.Only supports LE Scanning at the moment, e.g. with the gap le advertisements

example.

19.3. Getting Started. To integrate BTstack into the nRF5 SDK, please movethe BTstack project into nRF5 SDK X/components. Then create projects forthe BTstack examples in nRF5 SDK X/examples/btstack by running:

. / c r ea te example s . py

Now, the BTstack examples can be build from the nRF5 SDK X examplesfolder in the same way as other examples, e.g.:

cd examples / bts tack / g a p l e a d v e r t i s e m e n t s / pca10028 /armgccmake

to build the gap le advertisements example for the pca10028 dev kit using theARM GCC compiler.

See nRF5 SDK documentation about how to install it.

20. BTstack Port for the Microchip PIC32 Harmony Platform

Status: All examples working, polling UART driver. Tested on BluetoothAudio Development Kit only. Created with Harmony v1.07, does not compilewith new v2.x versions.

20.1. Hardware. The PIC32 Bluetooth Audio Development Kit comes with theCSR8811-based BTM805 Bluetooth module. In the port, the UART on the DACdaughter board was used for the debug output. Please remove the DAC boardand connect a 3.3V USB-2-UART converter to GND and TX to get the debugoutput.

20.2. Software. Microchip MPLAB X IDE and the MPLAB XC32 compilerneeds to be installed.

Page 154: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

153

20.3. Setup.

• Place BTstack tree into harmony/framework folder.• Run port/pic32-harmony/create examples.py to create examples in har-

mony/apps/btstack folder.

20.4. Usage. The examples can be opened and compiled in Microchip MPLABX IDE or from the command line using the Makefile generated by it.

20.4.1. Modifications to the GATT Database. After changing the GATT defini-tion in $example.gatt, please run ./update gatt db.h to regenerate example.h inthe $example folder.

20.4.2. Compiler Warnings: The project is set to use -Os optimization whichwill cause warnings if you only have the Free version. It will still compile aworking example.

21. BTstack Port for POSIX Systems with H4 BluetoothController

21.1. Configuration. Most Bluetooth Bluetooth Controllers connected via UAR-T/H4 require some special configuration, e.g. to set the UART baud rate, and/orrequire firmware patches during startup. In this port, we’ve tried to do most ofthese automatically based on information gathered from the Bluetooth Con-troller. Here’s some Controller specific details:

21.2. TI CC256x. The CC2564x needs the correct init script to start up. TheMakfile already has entries for most silicon revisions:

• CC2560: bluetooth init cc2564 2.14.c• CC2564B: bluetooth init cc2564B 1.6 BT Spec 4.1.• CC2564C: bluetooth init cc2564C 1.0.c

Please pick the correct one. The main.c verifies that the correct script isloaded, but the init script is linked to the executable.

21.3. Broadcom BCM/CYW 43430. The correct firmware file needs to beprovided in the current working directory. The Makefile downloads the one forthe BCM43430 e.g. found on later Raspberry Pi editions. Please see the separateport/raspi, too.

21.4. Compilation. BTstack’s POSIX-H4 does not have additional dependen-cies. You can directly run make.

make

Page 155: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

154

21.5. Running the examples. On start, BTstack prints the path to the packetlog and prints the information on the detected Buetooth Controller.

$ . / l e c o u n t e rPacket Log : /tmp/hci dump . pklgBTstack counter 0001BTstack up and running on 00 :1A: 7D:DA: 7 1 : 1 3 .

Please note that BTstack will increase the baudrate. Before starting again,you should reset or power-cycle the Bluetooth Controller. # POSIX H4 Port forAtmel ATWILC3000 {#sec:posix-h4-atwilc3000Port}

This port allows to use the ATWILC3000 connected via UART with BTstackrunning on a POSIX host system, see test setup below (which lacks a properRESET button).

21.6. Compilation. $ makeThe Makefile downloads the wilc3000 bt firmware.bin firmware from the GitHub

atwilc3000/firmware repo.

21.7. Usage. Just run any of the provided examples, e.g.$ ./le counterAt start, the firmware file is first uploaded to the ATWILC3000, before BT-

stack start up.Please note that it configures the ATWILC3000 for a higher baud rate it does

not detect if the firmware has already been downloaded, so you need to reset theATWILC3000 before starting an example.

Tested with the official ATWILC3000 SHIELD on OS X.

Page 156: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

155

# POSIX H4 Port for Dialog Semiconductor DA14581 {#sec:posix-h4-da14581Port}

Page 157: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

156

This port allows to use the DA14581 connected via UART with BTstack run-ning on a POSIX host system.

It first downloads the hci 581 active uart.hex firmware from the DA14581 HCI 3.110.2.12SDK packet, before BTstack starts up.

Please note that it does not detect if the firmware has already been down-loaded, so you need to reset the DA14581 before starting an example.

For production use, the HCI firmware could be flashed into the OTP and thefirmware download could be skipped.

Tested with the official DA14581 Dev Kit on OS X. # POSIX H4 Port forDialog Semiconductor DA14585 {#sec:posix-h4-da14585Port}

This port allows to use the DA14585 connected via UART with BTstack run-ning on a POSIX host system.

It first downloads the hci 581.hex firmware from the 6.0.8.509 SDK, beforeBTstack starts up.

Please note that it does not detect if the firmware has already been down-loaded, so you need to reset the DA14585 before starting an example.

For production use, the HCI firmware could be flashed into the OTP and thefirmware download could be skipped.

Tested with the official DA14585 Dev Kit Basic on OS X. # BTstack port forZephyr Controller with HCI UART Firmware Connectected To POSIX System{#sec:posix-h4-zephyrPort}

The main difference to the regular posix-h4 port is that that the Zephyr Con-toller uses 1000000 as baud rate. In addition, the port defaults to use the fixedstatic address stored during production.

21.8. Prepare Zephyr Controller. Please follow this blog post about how tocompile and flash samples/bluetooth/hci uart to a connected nRF5 dev kit.

In short: you need to install an arm-none-eabi gcc toolchain and the nRF5xCommand Line Tools incl. the J-Link drivers, checkout the Zephyr project, andflash an example project onto the chipset:

• Install J-Link Software and documentation pack.• Get nrfjprog as part of the nRFx-Command-Line-Tools. Click on Down-

loads tab on the top and look for your OS.• Checkout Zephyr and install toolchain. We recommend using the arm-

non-eabi gcc binaries instead of compiling it yourself. At least on OS X,this failed for us.• In samples/bluetooth/hci uart, compile the firmware for nRF52 Dev Kit

$ make BOARD=nrf52 pca10040• Upload the firmware

$ make flash• For the nRF51 Dev Kit, use make BOARD=nrf51 pca10028.

21.9. Configure serial port. To set the serial port of your Zephyr Controller,you can either update config.device name in main.c or always start the exampleswith the −u /path/to/serialport option.

21.10. Compile Examples.

Page 158: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

157

$ make

21.11. Run example. Just run any of the created binaries, e.g.

$ . / l e c o u n t e r

The packet log will be written to /tmp/hci dump.pklg

22. BTstack Port for Raspberry Pi 3 with BCM4343Bluetooth/Wifi Controller

Tested with Raspberry Pi 3 Model B V1.2, Raspberry Pi 3 Model B+, andRaspberry Pi Zero W V1.1.

With minor fixes, the port should also work with older Raspberry Pi modelsthat use the RedBear pHAT. See TODO at the end.

22.1. Raspberry Pi 3 / Zero W Setup. There are various options for settingup the Raspberry Pi, have a look at the Internet. Here’s what we did:

22.1.1. Install Raspian Stretch Lite:

• Insert empty SD Card• Download Raspian Stretch Lite from https://www.raspberrypi.org/downloads/raspbian/• Install Etcher from https://etcher.io• Run Etcher:• Select the image you’ve download before• Select your SD card• Flash!

22.1.2. Configure Wifi. Create the file wpa supplicant.conf in the root folder ofthe SD Card with your Wifi credentials:

c t r l i n t e r f a c e=DIR=/var /run/ wpa suppl icant GROUP=netdevnetwork={

s s i d=”YOURNETWORKNAME”psk=”YOUR PASSWORD”key mgmt=WPA−PSK

}

Alternatively, just plug-it in via Ethernet - unless you have a Raspberry PiZero W.

22.1.3. Enable SSH. Create an empty file called ‘ssh’ in the root folder of theSD Card to enable SSH.

22.1.4. Boot. If everything was setup correctly, it should now boot up and joinyour Wifi network. You can reach it via mDSN as ‘raspberrypi.local’.

Page 159: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

158

22.1.5. Disable bluez. By default, bluez will start up using the the BCM4343.To make it available to BTstack, you can disable its system services:

$ sudo sys t emct l d i s a b l e hc iua r t$ sudo sys t emct l d i s a b l e bthe lpe r$ sudo sys t emct l d i s a b l e b luetooth

and if you don’t want to restart, you can stop them right away. Otherwise,please reboot here.

$ sudo sys t emct l stop hc iua r t$ sudo sys t emct l stop bthe lpe r$ sudo sys t emct l stop b luetooth

If needed, they can be re-enabled later as well.

22.2. Compilation. The Makefile assumes cross-compilation using the regularGCC Cross Toolchain for gnueabihf: arm-linux-gnueabihf-gcc. This should beavailable in your package manager. Read on for a heavy, but easy-to-use ap-proach.

22.2.1. Compile using Docker. For non-Linux users, we recommend to use aRaspberry Pi Cross-Compiler in a Docker Container. Please follow the installa-tion instructions in the README.

Then, setup a shared folder in Docker that contains the BTstack repository.Now, go to the BTstack repository and ‘switch’ to the Raspberry Pi Cross-Compiler container:

$ rpxc bash

The default images doesn’t have a Python installation, so we manually installit:

$ sudo apt−get i n s t a l l python

Change to the port/raspi folder inside the BTstack repo:

$ cd bts tack / port / r a s p i

and compile as usual:

$ make

Page 160: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

159

For regular use, it makes sense to add Python permanently to the Dockercontainer. See documentation at GitHub.

22.3. Running the examples. Copy one of the examples to the Rasperry Piand just run them. BTstack will power cycle the Bluetooth Controller on modelswithout hardware flowcontrol, i.e., Pi 3 A/B. With flowcontrol, e.g Pi Zero Wand Pi 3 A+/B+, the firmware will only uploaded on first start.

pi@raspberryp i : ˜ $ . / l e c o u n t e rPacket Log : /tmp/hci dump . pklgHardware UART without f l o w c o n t r o lPhase 1 : Download f irmwarePhase 2 : Main appBTstack counter 0001BTstack up and running at B8 : 2 7 :EB: 2 7 :AF:56

Model Bluetooth ControllerUARTType

UARTFlowcontrolBT REG EN

HCITransportBaudrate

Older NonePi 3Model A,Model B

CYW43438 HardwareNo 128 H5 921600

Pi 3ModelA+,Model B+

CYW43455 HardwareYes 129(See1)

H4 921600(See2)

Pi Zero W CYW43438 HardwareYes 45 H4 921600

22.4. Bluetooth Hardware Overview.

1. Model A+/B+ have BT REG EN AND WL REG EN on the same (vir-tual) GPIO 129. A Bluetooth Controller power cycle also shuts downWifi (temporarily). BTstack avoids a power cycle on A+/B+.

2. Model A+/B+ support 3 mbps baudrate. Not enabled/activated yet.

22.5. TODO.

• Raspberry Pi Zero W: Check if higher baud rate can be used, 3 mbpsdoes not work.• Raspberry + RedBear IoT pHAT (AP6212A = BCM4343) port: IoT

pHAT need to get detected and the UART configured appropriately. #BTstack port for SAMV71 Ultra Xplained with ATWILC3000 SHIELD{#sec:samv71-xplained-atwilc3000Port}

This port uses the SAMV71 Ultra Xplained Ultra evaluation kit with anATWILC3000 SHIELD. The code is based on the Advanced Software Frame-work (ASF) (previously know as Atmel Software Framework). It uses the GCC

Page 161: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

160

Makefiles provided by the ASF. OpenOCD is used to upload the firmware to thedevice.

22.6. Create Example Projects. To create all example projects in the exam-ple folder, you can run:

$ make

22.7. Compile Example. In one of the example folders:

$ make

To upload the firmware:

$ make f l a s h

You need to connect the the Debug USB to your computer.

22.8. Debug output. printf is routed to USART1, which is connected to thevirtual serial port. To get the console output, open a terminal at 115200.

In btstack config.h, additional debug information can be enabled by uncom-menting ENABLE LOG INFO.

Also, the full packet log can be enabled in the main() function on main.cby uncommenting the hci dump open(..) line. The console output can thenbe converted into .pklg files for OS X PacketLogger or WireShark by runningtool/create packet log.py

22.9. TODOs.

− Implement h a l f l a s h s e c t o r . h to p e r s i s t l i n k keys

22.10. Issues.

− Bluetooth UART d r i v e r uses per−byte i n t e r r u p t s and doesn ’ t workr e l i a b l e at h igher baud r a t e s (921600 seems ok , 2 mbps a l r eadycauses problems ) .

− An o l de r XDMA−based implementation only sends 0x00 bytes over theUART. I t might be b e t t e r to j u s t read incoming data in to twob u f f e r s , ( e . g . us ing a two element l i nked l i s t with XDMA) , andr a i s i n g RTS when one b u f f e r i s f u l l .

Page 162: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

161

23. STM32 F103RB Nucleo with CC256x

BTstack port for STM32 F103RB Nucleo board and CC256x Bluetooth chipsetbased on GNU Tools for ARM Embedded Processors and libopencm3

Requirements: - GNU Tools for ARM Embedded Processors: https://launchpad.net/gcc-arm-embedded - libopencm3 is automatically fetched and build from its git repos-itory by make - openocd 0.8.0 (or higher) is used to upload firmware

Components: - STM32 F103RB Nucleo Board - User’s Manual: http://www.st.com/web/en/resource/technical/document/user manual/DM00105823.pdf- CC2564B Bluetooth Controller: 1. The best option is to get it as a BoostPack -Info: BOOST-CC2564MODA: http://www.ti.com/tool/BOOST-CC2564MODA2. Alternatively, get the evaluation module together with the EM WirelessBooster pack and a 32.768 kHz oscillator - EM Wireless Booster Pack: - Info:http://www.ti.com/tool/boost-ccemadapter - User Guide: http://www.ti.com/lit/ug/swru338a/swru338a.pdf- Booster Pack Pinout: http://www.ti.com/ww/en/launchpad/dl/boosterpack-pinout-v2.pdf - CC256x Evaluation Module: - Info: http://www.ti.com/tool/cc256xqfnem

Configuration: - Sys tick 250 ms - LED on PA5, on when MCU in Run modeand off while in Sleep mode - Debug UART: USART2 - 9600/8/N/1, TX on PA2- Bluetooth: USART3 with hardware flowcontrol RTS. IRQ on CTS Rising. TXPB10, RX PB11, CTS PB13 (in), RTS PB14 (out), N SHUTDOWN PB15

Setup with CC2564 BoosterPack (BOOST-CC2564MODA): - Connect STM32Nucleo Board to EM Wireless Board (see BoosterPack pinout) - GND: CN10-9- 20 (J2) - VCC: CN7 -16 - 1 (J1) - RX3: CN10-18 - 3 (J1) - TX3: CN10-25 - 4(J1) - CTS3: CN10-30 - 36 (J4) - RTS3: CN10-28 - 37 (J4) - N SHUTDOWN:CN10-26 - 19 (J2)

Setup with EM Wireless BoosterPack + CC256x Evaluation Module: - Solder32.768 kHz quarz oscillator to EM Adapter Booster Pack as explained in 4.7 ofthe EM Wireless Booster Pack User Guide. If you don’t have an oscillator ofthat size, you might solder one upside done (turtle-on-back style) to the unusedupper right pad and wire GCC, VCC, and clock with thin wires. - ConnectSTM32 Nucleo Board to EM Wireless Board (see BoosterPack pinout) - GND:CN10-9 - 20 (LP2) - VCC: CN7 -16 - 1 (LP1) - RX3: CN10-18 - 3 (LP1) - TX3:CN10-25 - 4 (LP1) - CTS3: CN10-30 - 11 (LP2) - RTS3: CN10-28 - 12 (LP2) -N SHUTDOWN: CN10-26 - 10 (LP1)

TODO: - figure out how to compile multiple examples with single Makefile/-folder # BTstack port for STM32 F4 Discovery Board with CC256x {#sec:stm32-f4discovery-cc256xPort}

This port uses the STM32 F4 Discovery Board with TI’s CC256XEM STAdapter Kit that allows to plug in a CC256xB or CC256xC Bluetooth module.STCubeMX was used to provide the HAL and initialize the device. Finally,Eclipse CDT + GNU ARM Eclipse projects for all examples are provided. GNUARM Eclipse OpenOCD was used to flash and debug the examples.

23.1. Hardware. STM32 Development kit and adapter for CC256x module: -STM32 F4 Discovery Board - CC256xEM Bluetooth Adatper Kit for ST

CC256x Bluetooth module: - CC2564B Dual-mode Bluetooth Controller Eval-uation Module - CC2564C Dual-mode Bluetooth Controller Evaluation Module

The module with the older CC2564B is around USD 20, while the one withthe new CC2564C costs around USD 60. The projects are configured for the

Page 163: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

162

CC2564B. When using the CC2564C, bluetooth init cc2564C 1.0.c should be useas cc256x init script, see ./create examples.py.

23.2. Software. To compile and flash the examples, Eclipse CDT with GNUARM Eclipse is used. Please follow the installation instructions here: http://gnuarmeclipse.github.ioYou also need to install the GNU ARM Eclipse OpenOCD debugger plug-in.

23.3. Create Example Projects. Eclipse requires a separate project per ex-ample. To create all example projects, navigate to this directory (btstack/port/stm32-f4discovery-cc256x) and run:

. / c r ea te example s . py

This will create an example subfolder with one project per example. Note: itcurrently requires about 500 MB.

23.4. Import Example Project. In Eclipse CDT, select “File -> Import. . . ”,then choose General->Existing Project into Workspace and click Next>. In the“Import Projects” dialog, select either the generated examples folder to importall projects or pick a single example.

23.5. Run Example Project. Build one of the examples by clicking on the‘Hammer’ icon, then start it via the provided Debug Launch configuration “example-debug”. Note: It’s not clear why there are two debug configurations for anexample project sometimes.

23.6. Debug output. printf is routed to USART2. To get the console output,connect PA2 (USART2 TX) of the Discovery board to an USB-2-UART adapterand open a terminal at 115200.

In src/btstack config.h resp. in example/btstack config.h of the generatedprojects, additional debug information can be enabled by uncommenting EN-ABLE LOG INFO.

Also, the full packet log can be enabled in src/port.c resp. btstack/port/stm32-f4discovery-cc256x/src/port.c by uncommenting the hci dump open(..) line. Theconsole output can then be converted into .pklg files for OS X PacketLogger orWireShark by running tool/create packet log.py

23.7. GATT Database. In BTstack, the GATT Database is defined via the.gatt file in the example folder. Before it can be used, run the provided up-date gatt db.sh script in each project folder.

Note: In theory, this can be integrated into the Eclipse project, in fact, it’seasy to configure it as an Eclipse Builder, but it got tricky to correctly add it tothe create examples.py tool. So, whenever you’re updating the .gatt file, pleaserun ./update gatt db.sh manually.

Page 164: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

163

23.8. TODOs.

• move unmodified STM32 Cube files provided by ST32CubeMx into 3rd-party/STM32• link to sources instead of copying into every example project• support on-board DAC in A2DP Sink Demo

23.9. Maintainer Notes - Updating The Port. This paragraph is mainlyfor the maintainers. It describes the steps to make changes to the CubeMXconfiguration and how to update the Eclipse template after that.

23.9.1. Update cubemx-f4discovery-cc256x from STM32CubeMX project.

• open ST32CubeMX• load project file cubemx-f4discovery-cc256x/cubemx-f4discovery-cc256x.ioc• generate code and documentation• patch generated sources: ./patch-cubemx-project.sh

23.9.2. Update local Eclipse project from cubemx-f4discovery-cc256x. This useslocal Eclipse project generated manually from STM32 template provided by GNUARM Eclipse using the CubeMX Importer

. / impor t cubemx in to ec l i p s e . sh

23.9.3. Update eclipse-template from local Eclipse project.

. / u p d a t e f r o m e c l i p s e . sh

24. BTstack port for STM32 Nucleo-L053R8 Board with anEM9304 Shield - EM9304 DVK

This port uses the STM32 Nucleo-L053R8 Board with EM’s EM9304 Shield.The STM32CubeMX tool was used to provide the HAL, initialize the device,

and create a basic Makefile. The Makefile has been exteneded to compile allBTstack LE examples. An examples can be uploaded onto the device by copyingit to the Nucleo virtual mass storage drive.

24.1. Hardware. In this port, the EM9304 is conencted via the SPI1 interfaceand configured for 8 Mhz. Datasheet for the EM9304

24.2. Software. To build all examples, go to the cubemx-l053r8-em9304 folder

$ cd cubemx−l053r8−em9304

and run make

$ make

Page 165: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

164

All examples are placed in the ‘build’ folder.

24.3. Debug output. printf is routed to USART2. To get the console output,open a terminal at 115200 for the virtual serial port of the Nucleo board.

Additional debug information can be enabled by uncommenting ENABLE LOG INFOin btstack config.h.

Also, the full packet log can be enabled in port.c by uncommenting the hci dump open(..)line. The console output can then be converted into .pklg files for OS X Packet-Logger or WireShark by running tool/create packet log.py

24.4. GATT Database. In BTstack, the GATT Database is defined via the.gatt file in the example folder. During the build, the .gatt file is converted intoa .h file with a binary representation of the GATT Database and useful definesfor the application.

24.5. Stability. When sending at full speed, it’s possible that the EM9304 hangsup. This patch (connection event overlay.emp) fixes this problems in our tests.It can be applied with the EM ConfigEditor available via the EM TechnicalSupport.

24.6. Multiple LE Peripheral/Central Roles. It should be possible to usethe EM9304 in multiple roles. In the default configuration, it only supports a sin-gle connection. For multiple roles, it needs to be configured for more connectionsat least.

24.7. Performace. With the patch, the LE Streamer example is able to sendup to 10 packets per Connection Event to an iPhone SE with iOS 10.2, resultingin around 6.5 kB/s throughput for this direction.

Page 166: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

165

24.8. Image.# BTstack port for WICED platform {#sec:wiced-h4Port}

Page 167: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

166

Tested with: - WICED SDK 3.4-6.2.1 - RedBear Duo: Please install RedBearWICED Add-On - Inventek Systems ISM4334x - Please contact Inventek Systemsfor WICED platform files - Inventek Systems ISM4343 (BCM43438 A1) - Pleasecontact Inventek Systems for WICED platform files

To integrate BTstack into the WICED SDK, please move the BTstack projectinto WICED-SDK-6.2.1/libraries.

Then create projects for BTstack examples in WICED/apps/btstack by run-ning:

. / c r ea te example s . py

Now, the BTstack examples can be build from the WICED root in the sameway as other examples, e.g.:

. / make bts tack . spp and l e counte r−RB DUO

to build the SPP-and-LE-Counter example for the RedBear Duo (or use ISM43340 M4G L44/ ISM4343 WBM L151 for the Inventek Systems devices).

See WICED documentation about how to upload the firmware.It should work with all WICED platforms that contain a Broadcom Bluetooth

chipset.The maximal baud rate is currenty limited to 1 mbps.The port uses the generated WIFI address plus 1 as Bluetooth MAC address.

It persists the LE Device DB and Classic Link Keys via the DCT mechanism.All examples that rovide a GATT Server use the GATT DB in the .gatt file.

Therefore you need to run ./update gatt db.sh in the apps/btstack/$(EXAMPLE)folder after modifying the .gatt file. # BTstack port for WICED platform usingH5 transport and Broadcom/Cypress Bluetooth chipsets. {#sec:wiced-h5Port}

25. BTstack port for WICED platform

Tested with: - WICED SDK 3.4-6.2.1 - RedBear Duo: Please install RedBearWICED Add-On - Inventek Systems ISM4334x - Please contact Inventek Systemsfor WICED platform files - Inventek Systems ISM4343 (BCM43438 A1) - Pleasecontact Inventek Systems for WICED platform files

To integrate BTstack into the WICED SDK, please move the BTstack projectinto WICED-SDK-6.2.1/libraries.

Then create projects for BTstack examples in WICED/apps/btstack by run-ning:

. / c r ea te example s . py

Now, the BTstack examples can be build from the WICED root in the sameway as other examples, e.g.:

Page 168: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

167

. / make bts tack . spp and l e counte r−RB DUO

to build the SPP-and-LE-Counter example for the RedBear Duo (or use ISM43340 M4G L44/ ISM4343 WBM L151 for the Inventek Systems devices).

See WICED documentation about how to upload the firmware.It should work with all WICED platforms that contain a Broadcom Bluetooth

chipset.The maximal baud rate is currenty limited to 1 mbps.The port uses the generated WIFI address plus 1 as Bluetooth MAC address.

It persists the LE Device DB and Classic Link Keys via the DCT mechanism.All examples that rovide a GATT Server use the GATT DB in the .gatt file.

Therefore you need to run ./update gatt db.sh in the apps/btstack/$(EXAMPLE)folder after modifying the .gatt file.

25.1. Additional notes on the H5 port. If the CTR/RTS hardware controllines of the Bluetooth Controller is connected to your MCU, we recommend usingthe wiced-h4 port instead. If they are not connected, H5 is required to providea reliable connection including retransmissions in both directions.

There are a few oddities so far that had to be worked around in H5 mode:

• It does not seem possible to upload the FW Mini Driver a.k.a. patchrama.k.a. init script via H5. BTstack uses btstack chipset bcm download firmware.cto upload the FW Mini Driver via a minimal H4 implementation, beforestarting up in H5 mode. BCM/CYP chipsets are able to switch to H5.• With the AP6212A on the RedBear Duo and the FW Mini Driver from

WICED-SDK-3.5.2/libraries/drivers/bluetooth/firmware/43438A1/26MHz/bt firmware image.c,the HCI LE Encrypt command to perform an AES128 encryption hangsin H5 (but works in H4). See Bug Report in Community Forum As awork around, BTstack was configured to use a CPU implementation ofAES128 (#define HAVE AES128).

26. BTstack Port for Windows Systems with BluetoothController connected via Serial Port

The Windows-H4 port uses the native run loop and allows to use BluetoothControllers connected via Serial Port.

Make sure to manually reset the Bluetooth Controller before starting any ofthe examples.

26.1. Toolchain. The port requires a Unix-like toolchain. We successfully usedmingw-w64 to compile and run the examples. mingw64-w64 is based on MinGW,which ‘. . . provides a complete Open Source programming tool set which is suit-able for the development of native MS-Windows applications, and which do notdepend on any 3rd-party C-Runtime DLLs.’

We’ve used the Msys2 package available from the downloads page on Windows10, 64-bit and use the MSYS2 MinGW 32-bit start menu item to compile 32-bitbinaries that run on both 32/64-bit systems.

Page 169: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

168

In the MSYS2 shell, you can install git, python, and, winpty with pacman:

$ pacman −S g i t$ pacman −S python$ pacman −S winpty

26.2. Compilation. With mingw64-w64 installed, just go to the port/windows-winusb directory and run make

$ cd bts tack / port /windows−winusb$ make

26.3. Console Output. When running the examples in the MSYS2 shell, theconsole input (via btstack stdin support) doesn’t work. It works in the olderMSYS and also the regular CMD.exe environment. Another option is to installWinPTY and then start the example via WinPTY like this:

$ winpty . / spp and l e count e r . exe

27. BTstack port for Zephyr Controller with HCI UARTFirmware Connectected To POSIX System

The main difference to the regular posix-h4 port is that that the Zephyr Con-toller uses 1000000 as baud rate. In addition, the port defaults to use the fixedstatic address stored during production.

27.1. Prepare Zephyr Controller. Please follow this blog post about how tocompile and flash samples/bluetooth/hci uart to a connected nRF5 dev kit.

In short: you need to install an arm-none-eabi gcc toolchain and the nRF5xCommand Line Tools incl. the J-Link drivers, checkout the Zephyr project, andflash an example project onto the chipset:

• Install J-Link Software and documentation pack.• Get nrfjprog as part of the nRFx-Command-Line-Tools. Click on Down-

loads tab on the top and look for your OS.• Checkout Zephyr and install toolchain. We recommend using the arm-

non-eabi gcc binaries instead of compiling it yourself. At least on OS X,this failed for us.• In samples/bluetooth/hci uart, compile the firmware for nRF52 Dev Kit

$ make BOARD=nrf52 pca10040• Upload the firmware

$ make flash• For the nRF51 Dev Kit, use make BOARD=nrf51 pca10028.

Page 170: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

169

27.2. Configure serial port. To set the serial port of your Zephyr Controller,you can either update config.device name in main.c or always start the exampleswith the −u /path/to/serialport option.

27.3. Compile Examples.

$ make

27.4. Run example. Just run any of the created binaries, e.g.

$ . / l e c o u n t e r

The packet log will be written to /tmp/hci dump.pklg

28. BTstack port for Windows Systems using the WinUSB Driver

The Windows-WinUSB port uses the native run loop and WinUSB API toaccess a USB Bluetooth dongle.

28.1. Access to Bluetooth USB Dongle with Zadig. To allow libusb orWinUSB to access an USB Bluetooth dongle, you need to install a special devicedriver to make it accessible to user space processes.

It works like this:

• Download Zadig• Start Zadig• Select Options -> “List all devices”• Select USB Bluetooth dongle in the big pull down list• Select WinUSB (libusb) in the right pull pull down list• Select “Replace Driver”

28.2. Toolchain. The port requires a Unix-like toolchain. We successfully usedmingw-w64 to compile and run the examples. mingw64-w64 is based on MinGW,which ‘. . . provides a complete Open Source programming tool set which is suit-able for the development of native MS-Windows applications, and which do notdepend on any 3rd-party C-Runtime DLLs.’

We’ve used the Msys2 package available from the downloads page on Windows10, 64-bit and use the MSYS2 MinGW 32-bit start menu item to compile 32-bitbinaries that run on both 32/64-bit systems.

In the MSYS2 shell, you can install git, python, and, winpty with pacman:

$ pacman −S g i t$ pacman −S python$ pacman −S winpty

Page 171: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

170

28.3. Compilation. With mingw64-w64 installed, just go to the port/windows-winusb directory and run make

$ cd bts tack / port /windows−winusb$ make

28.4. Console Output. When running the examples in the MSYS2 shell, theconsole input (via btstack stdin support) doesn’t work. It works in the olderMSYS and also the regular CMD.exe environment. Another option is to installWinPTY and then start the example via WinPTY like this:

$ winpty . / spp and l e count e r . exe

29. BTstack port for Windows Systems with Intel Wireless8260/8265 Controllers

Same as port/windows-winusb, but customized for Intel Wireless 8260 and8265 Controllers. These controller require firmware upload and configuration towork. Firmware and config is downloaded from the Linux firmware repository.

29.1. Access to Bluetooth USB Dongle with Zadig. To allow libusb orWinUSB to access an USB Bluetooth dongle, you need to install a special devicedriver to make it accessible to user space processes.

It works like this:

• Download Zadig• Start Zadig• Select Options -> “List all devices”• Select USB Bluetooth dongle in the big pull down list• Select WinUSB (libusb) in the right pull pull down list• Select “Replace Driver”

29.2. Toolchain. The port requires a Unix-like toolchain. We successfully usedmingw-w64 to compile and run the examples. mingw64-w64 is based on MinGW,which ‘. . . provides a complete Open Source programming tool set which is suit-able for the development of native MS-Windows applications, and which do notdepend on any 3rd-party C-Runtime DLLs.’

We’ve used the Msys2 package available from the downloads page on Windows10, 64-bit and use the MSYS2 MinGW 32-bit start menu item to compile 32-bitbinaries that run on both 32/64-bit systems.

In the MSYS2 shell, you can install git, python, and, winpty with pacman:

$ pacman −S g i t$ pacman −S python$ pacman −S winpty

Page 172: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

171

29.3. Compilation. With mingw64-w64 installed, just go to the port/windows-winusb directory and run make

$ cd bts tack / port /windows−winusb$ make

29.4. Console Output. When running the examples in the MSYS2 shell, theconsole input (via btstack stdin support) doesn’t work. It works in the olderMSYS and also the regular CMD.exe environment. Another option is to installWinPTY and then start the example via WinPTY like this:

$ winpty . / spp and l e count e r . exe

30. Integrating with Existing Systems

While the run loop provided by BTstack is sufficient for new designs, BTstackis often used with or added to existing projects. In this case, the run loop, datasources, and timers may need to be adapted. The following two sections providesa guideline for single and multi-threaded environments.

To simplify the discussion, we’ll consider an application split into “Main”,“Communication Logic”, and “BTstack”. The Communication Logic containsthe packet handler (PH) that handles all asynchronous events and data packetsfrom BTstack. The Main Application makes use of the Communication Logicfor its Bluetooth communication.

30.1. Adapting BTstack for Single-Threaded Environments. In a single-threaded environment, all application components run on the same (single)thread and use direct function calls as shown in Figure {@fig:BTstackSingle}.

Main  Applica*on  

Communica*on.  Logic    

BTstack  

PH  

{#fig:BTstackSingle}BTstack provides a basic run loop that supports the concept of data sources

and timers, which can be registered centrally. This works well when working witha small MCU and without an operating system. To adapt to a basic operatingsystem or a different scheduler, BTstack’s run loop can be implemented basedon the functions and mechanism of the existing system.

Currently, we have two examples for this:

Page 173: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

172

• btstack run loop posix.c is an implementation for POSIX compliant sys-tems. The data sources are modeled as file descriptors and managed ina linked list. Then, the select function is used to wait for the next filedescriptor to become ready or timer to expire.• btstack run loop cocoa.c is an implementation for the CoreFoundation

Framework used in OS X and iOS. All run loop functions are imple-mented in terms of CoreFoundation calls, data sources and timers aremodeled as CFSockets and CFRunLoopTimer respectively.• btstack run loop windows is an implementation for Windows environment.

The data sources are modeled with Event objects and managed in a linkedlist. Then, the WaitForMultipleObjects is used to wait for the next Eventto becomre ready or timer to expire.

30.2. Adapting BTstack for Multi-Threaded Environments. The basicexecution model of BTstack is a general while loop. Aside from interrupt-drivenUART and timers, everything happens in sequence. When using BTstack in amulti-threaded environment, this assumption has to stay valid - at least withrespect to BTstack. For this, there are two common options:

• The Communication Logic is implemented on a dedicated BTstack thread,and the Main Application communicates with the BTstack thread viaapplication-specific messages over an Interprocess Communication (IPC)as depicted in Figure {@fig:MTMonolithic}. This option results in lesscode and quick adaption.

Communica)on  Logic  

IPC  

BTstack  

Main  Applica)on  

IPC  application custom commands

PH  

{#fig:MTMonolithic}• BTstack must be extended to run standalone, i.e, as a Daemon, on a

dedicated thread and the Main Application controls this daemon viaBTstack extended HCI command over IPC - this is used for the non-embedded version of BTstack e.g., on the iPhone and it is depicted inFigure {@fig:MTDaemon}. This option requires more code but providesmore flexibility.

Page 174: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

173

Daemon  

IPC  

BTstack  

Bluetooth commands and

events

Main  Applica6on  

PH  

Communica6on  Logic  

IPC  PH  

PH  

{#fig:MTDaemon}

Page 175: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

174

31. APIs

31.1. BLE ANCS Client API.

void a n c s c l i e n t i n i t (void ) ;void a n c s c l i e n t r e g i s t e r c a l l b a c k (btstack packet handler t c a l l b a c k

) ;const char ∗ a n c s c l i e n t a t t r i b u t e n a m e f o r i d ( int id ) ;

31.2. BLE ATT Database API.

/∗∗∗ @br ie f I n i t ATT DB s to rage∗/

void a t t d b u t i l i n i t (void ) ;

/∗∗∗ @br ie f Add primary s e r v i c e f o r 16− b i t UUID∗ @param uuid16∗ @returns a t t r i b u t e handle f o r the new s e r v i c e d e f i n i t i o n∗/

uint16 t a t t d b u t i l a d d s e r v i c e u u i d 1 6 (uint16 t uuid16 ) ;

/∗∗∗ @br ie f Add primary s e r v i c e f o r 128− b i t UUID∗ @param uuid1286∗ @returns a t t r i b u t e handle f o r the new s e r v i c e d e f i n i t i o n∗/

uint16 t a t t d b u t i l a d d s e r v i c e u u i d 1 2 8 ( const uint8 t ∗ uuid128 ) ;

/∗∗∗ @br ie f Add Cha r a c t e r i s t i c wi th 16− b i t UUID, p rope r t i e s , and data∗ @param uuid16∗ @param prop e r t i e s − see ATT PROPERTY ∗ in s rc / b l u e t o o t h . h∗ @param read permis s ions − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param wr i t e p e rmi s s i on s − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param data re turned in read opera t i ons i f ATT PROPERTYDYNAMIC

i s not s p e c i f i e d∗ @param da t a l en∗ @returns a t t r i b u t e handle o f the new c h a r a c t e r i s t i c va lue

d e c l a r a t i on∗ @note I f p r o p e r t i e s conta ins ATT PROPERTY NOTIFY or

ATT PROPERTY INDICATE f l a g s , a C l i en t Conf i gura t ionCha r a c t e r i s t i c Descr ip tor (CCCD)

∗ i s c rea t ed as w e l l . The a t t r i b u t e va lue handle o f the CCCDi s the a t t r i b u t e va lue handle p l u s 1

∗/uint16 t a t t d b u t i l a d d c h a r a c t e r i s t i c u u i d 1 6 (uint16 t uuid16 ,

uint16 t prope r t i e s , uint8 t read permis s ion , uint8 twr i t e pe rmi s s i on , uint8 t ∗ data , uint16 t data l en ) ;

/∗∗∗ @br ie f Add Cha r a c t e r i s t i c wi th 128− b i t UUID, p rope r t i e s , and data

Page 176: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

175

∗ @param uuid128∗ @param prop e r t i e s − see ATT PROPERTY ∗ in s rc / b l u e t o o t h . h∗ @param read permis s ions − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param wr i t e p e rmi s s i on s − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param data re turned in read opera t i ons i f ATT PROPERTYDYNAMIC

i s not s p e c i f i e d∗ @param da t a l en∗ @returns a t t r i b u t e handle o f the new c h a r a c t e r i s t i c va lue

d e c l a r a t i on∗ @note I f p r o p e r t i e s conta ins ATT PROPERTY NOTIFY or

ATT PROPERTY INDICATE f l a g s , a C l i en t Conf i gura t ionCha r a c t e r i s t i c Descr ip tor (CCCD)

∗ i s c rea t ed as w e l l . The a t t r i b u t e va lue handle o f the CCCDi s the a t t r i b u t e va lue handle p l u s 1

∗/uint16 t a t t d b u t i l a d d c h a r a c t e r i s t i c u u i d 1 2 8 ( const uint8 t ∗

uuid128 , uint16 t prope r t i e s , uint8 t read permis s ion , uint8 twr i t e pe rmi s s i on , uint8 t ∗ data , uint16 t data l en ) ;

/∗∗∗ @br ie f Add d e s c r i p t o r wi th 128− b i t UUID, p rope r t i e s , and data∗ @param uuid16∗ @param prop e r t i e s − see ATT PROPERTY ∗ in s rc / b l u e t o o t h . h∗ @param read permis s ions − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param wr i t e p e rmi s s i on s − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param data re turned in read opera t i ons i f ATT PROPERTYDYNAMIC i s

not s p e c i f i e d∗ @param da t a l en∗ @returns a t t r i b u t e handle o f the new c h a r a c t e r i s t i c d e s c r i p t o r

d e c l a r a t i on∗/uint16 t a t t d b u t i l a d d d e s c r i p t o r u u i d 1 6 (uint16 t uuid16 , uint16 t

prope r t i e s , uint8 t read permis s ion , uint8 t wr i t e pe rmi s s i on ,uint8 t ∗ data , uint16 t data l en ) ;

/∗∗∗ @br ie f Add d e s c r i p t o r wi th 128− b i t UUID, p rope r t i e s , and data∗ @param uuid16∗ @param prop e r t i e s − see ATT PROPERTY ∗ in s rc / b l u e t o o t h . h∗ @param read permis s ions − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param wr i t e p e rmi s s i on s − see ATT SECURITY ∗ in s rc / b l u e t o o t h . h∗ @param data re turned in read opera t i ons i f ATT PROPERTYDYNAMIC i s

not s p e c i f i e d∗ @param da t a l en∗ @returns a t t r i b u t e handle o f the new c h a r a c t e r i s t i c d e s c r i p t o r

d e c l a r a t i on∗/uint16 t a t t d b u t i l a d d d e s c r i p t o r u u i d 1 2 8 ( const uint8 t ∗ uuid128 ,

uint16 t prope r t i e s , uint8 t read permis s ion , uint8 twr i t e pe rmi s s i on , uint8 t ∗ data , uint16 t data l en ) ;

/∗∗∗ @br ie f Get address o f cons t ruc t ed ATT DB∗/

Page 177: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

176

uint8 t ∗ a t t d b u t i l g e t a d d r e s s (void ) ;

/∗∗∗ @br ie f Get s i z e o f cons t ruc t ed ATT DB∗/

uint16 t a t t d b u t i l g e t s i z e (void ) ;

31.3. BLE ATT Server API.

/∗∗ @br ie f se tup ATT serv e r∗ @param db a t t r i b u t e database crea t ed by compile−g a t t . ph∗ @param read ca l l b a c k , see a t t d b . h , can be NULL∗ @param wr i t e c a l l b a c k , see a t t l . h , can be NULL∗/

void a t t s e r v e r i n i t ( uint8 t const ∗ db , a t t r e a d c a l l b a c k tr ead ca l l back , a t t w r i t e c a l l b a c k t w r i t e c a l l b a c k ) ;

/∗∗ @br ie f r e g i s t e r packe t hand ler f o r ATT ser ve r even t s :∗ − ATT EVENT CAN SEND NOW∗ − ATT EVENT HANDLE VALUE INDICATION COMPLETE∗ − ATTEVENTMTUEXCHANGECOMPLETE∗ @param hand ler∗/

void a t t s e r v e r r e g i s t e r p a c k e t h a n d l e r (btstack packet handler thandler ) ;

/∗∗∗ @br ie f r e g i s t e r read/ wr i t e c a l l b a c k s f o r s p e c i f i c handle range∗ @param a t t s e r v i c e h a n d l e r t∗/

void a t t s e r v e r r e g i s t e r s e r v i c e h a n d l e r ( a t t s e r v i c e h a n d l e r t ∗handler ) ;

/∗∗∗ @br ie f Request c a l l b a c k when sending i s p o s s i b l e∗ @note c a l l b a c k might happend during c a l l to t h i s f unc t i on∗ @param c a l l b a c k r e g i s t r a t i o n to po in t to c a l l b a c k func t i on and

con t ex t in format ion∗ @param con handle∗ @return 0 i f ok , e r ror o therw i s e∗/

int a t t s e r v e r r e g i s t e r c a n s e n d n o w c a l l b a c k (b t s t a c k c o n t e x t c a l l b a c k r e g i s t r a t i o n t ∗ c a l l b a c k r e g i s t r a t i o n ,

h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Return ATT MTU∗ @param con handle∗ @return mtu i f ok , 0 o the rw i s e∗/

uint16 t a t t s e r v e r g e t m t u ( h c i c o n h a n d l e t con handle ) ;

Page 178: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

177

/∗∗∗ @br ie f Request c a l l b a c k when sending n o t i f c a t i o n i s p o s s i b l e∗ @note c a l l b a c k might happend during c a l l to t h i s f unc t i on∗ @param c a l l b a c k r e g i s t r a t i o n to po in t to c a l l b a c k func t i on and

con t ex t in format ion∗ @param con handle∗ @return 0 i f ok , e r ror o therw i s e∗/

int a t t s e r v e r r e q u e s t t o s e n d n o t i f i c a t i o n (b t s t a c k c o n t e x t c a l l b a c k r e g i s t r a t i o n t ∗ c a l l b a c k r e g i s t r a t i o n ,

h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Request c a l l b a c k when sending i nd i c a t i on i s p o s s i b l e∗ @note c a l l b a c k might happend during c a l l to t h i s f unc t i on∗ @param c a l l b a c k r e g i s t r a t i o n to po in t to c a l l b a c k func t i on and

con t ex t in format ion∗ @param con handle∗ @return 0 i f ok , e r ror o therw i s e∗/

int a t t s e r v e r r e q u e s t t o s e n d i n d i c a t i o n (b t s t a c k c o n t e x t c a l l b a c k r e g i s t r a t i o n t ∗ c a l l b a c k r e g i s t r a t i o n ,

h c i c o n h a n d l e t con handle ) ;

/∗∗ @br ie f n o t i f y c l i e n t about a t t r i b u t e va lue change∗ @param con handle∗ @param a t t r i b u t e h a n d l e∗ @param va lue∗ @param va l u e l e n∗ @return 0 i f ok , e r ror o therw i s e∗/

int a t t s e r v e r n o t i f y ( h c i c o n h a n d l e t con handle , uint16 ta t t r i bu t e hand l e , const uint8 t ∗value , uint16 t v a l u e l e n ) ;

/∗∗ @br ie f i n d i c a t e va lue change to c l i e n t . c l i e n t i s supposed to

r e p l y wi th an ind i c a t i on r e s pon s e∗ @param con handle∗ @param a t t r i b u t e h a n d l e∗ @param va lue∗ @param va l u e l e n∗ @return 0 i f ok , e r ror o therw i s e∗/

int a t t s e r v e r i n d i c a t e ( h c i c o n h a n d l e t con handle , uint16 ta t t r i bu t e hand l e , const uint8 t ∗value , uint16 t v a l u e l e n ) ;

#ifde f ENABLE ATT DELAYED RESPONSE/∗∗ @br ie f response ready − c a l l e d a f t e r r e tu rn ing

ATT READ RESPONSE PENDING in an a t t r e a d c a l l b a c k or∗ ATT ERROR WRITE REQUEST PENDING IN a t t w r i t e c a l l b a c k b e f o r e to

t r i g g e r c a l l b a c k again and complete the t r an sac t i on

Page 179: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

178

∗ @nore The ATT Server w i l l r e t r y hand l ing the curren t ATT reque s t∗ @param con handle∗ @return 0 i f ok , e r ror o therw i s e∗/

int a t t s e r v e r r e s p o n s e r e a d y ( h c i c o n h a n d l e t con handle ) ;#endif

// the f o l l ow i n g f unc t i on s w i l l be removed soon

/∗∗ @br ie f t e s t s i f a n o t i f i c a t i o n or i n d i c a t i on can be send r i g h t

now∗ @param con handle∗ @return 1 , i f packe t can be sen t∗/

int a t t s e rv e r can s end packe t now ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Request emiss ion o f ATT EVENT CAN SEND NOW as soon as

p o s s i b l e∗ @note ATT EVENT CAN SEND NOW might be emi t ted during c a l l to t h i s

f unc t i on∗ so packe t hand ler shou ld be ready to handle i t∗ @param con handle∗/

void a t t s e r v e r r e q u e s t c a n s e n d n o w e v e n t ( h c i c o n h a n d l e tcon handle ) ;

// end o f depreca ted f unc t i on s

31.4. BLE GATT Client API.

typedef struct {uint16 t s t a r t g roup hand l e ;uint16 t end group handle ;uint16 t uuid16 ;uint8 t uuid128 [ 1 6 ] ;

} gatt c l ient service t ;

typedef struct {uint16 t s t a r t h a n d l e ;uint16 t va lue hand le ;uint16 t end handle ;uint16 t p r o p e r t i e s ;uint16 t uuid16 ;uint8 t uuid128 [ 1 6 ] ;

} gatt c l ient character ist ic t ;

typedef struct {uint16 t handle ;uint16 t uuid16 ;uint8 t uuid128 [ 1 6 ] ;

} gatt cl ient characterist ic descriptor t ;

Page 180: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

179

/∗∗∗ @br ie f Set up GATT c l i e n t .∗/

void g a t t c l i e n t i n i t (void ) ;

/∗∗∗ @br ie f MTU i s a v a i l a b l e a f t e r the f i r s t query has completed . I f

s t a t u s i s equa l to 0 , i t r e tu rns the r e a l va lue , o the rw i s e thed e f a u l t va lue o f 23.

∗ @param con handle∗ @param mtu∗/

uint8 t g a t t c l i e n t g e t m t u ( h c i c o n h a n d l e t con handle , uint16 t ∗mtu) ;

/∗∗∗ @br ie f Se t s whether a MTU Exchange Request s h a l l be au t oma t i c a l l y

send be f o r e the f i r s t a t t r i b u t e read r e que s t i s send . De fau l ti s enab led .

∗ @param enab led∗/

void g a t t c l i e n t m t u e n a b l e a u t o n e g o t i a t i o n ( uint8 t enabled ) ;

/∗∗∗ @br ie f Sends a MTU Exchange Request , t h i s a l l ow s f o r the c l i e n t to

exchange MTU when g a t t c l i e n t m t u e n a b l e a u t o n e g o t i a t i o n i sd i s a b l e d .

∗ @param ca l l b a c k∗ @param con handle∗/

void g a t t c l i e n t s e n d m t u n e g o t i a t i o n (btstack packet handler tca l lback , h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Returns i f the GATT c l i e n t i s ready to r e c e i v e a query . I t

i s used wi th daemon .∗ @param con handle∗/

int g a t t c l i e n t i s r e a d y ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Discovers a l l primary s e r v i c e s . For each found se r v i c e , an

l e s e r v i c e e v e n t t wi th type s e t toGATT EVENT SERVICE QUERY RESULT w i l l be generated and passed tothe r e g i s t e r e d c a l l b a c k . The g a t t c omp l e t e e v en t t , wi th type

s e t to GATT EVENTQUERY COMPLETE, marks the end o f d i s cove ry .∗ @param ca l l b a c k∗ @param con handle∗/

uint8 t g a t t c l i e n t d i s c o v e r p r i m a r y s e r v i c e s (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ) ;

/∗∗

Page 181: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

180

∗ @br ie f Discovers a s p e c i f i c primary s e r v i c e g iven i t s UUID. Thiss e r v i c e may e x i s t mu l t i p l e t imes . For each found se r v i c e , anl e s e r v i c e e v e n t t wi th type s e t toGATT EVENT SERVICE QUERY RESULT w i l l be generated and passed tothe r e g i s t e r e d c a l l b a c k . The g a t t c omp l e t e e v en t t , wi th type

s e t to GATT EVENTQUERY COMPLETE, marks the end o f d i s cove ry .∗ @param ca l l b a c k∗ @param con handle∗ @param uuid16∗/

uint8 t g a t t c l i e n t d i s c o v e r p r i m a r y s e r v i c e s b y u u i d 1 6 (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t uuid16 ) ;

/∗∗∗ @br ie f Discovers a s p e c i f i c primary s e r v i c e g iven i t s UUID. This

s e r v i c e may e x i s t mu l t i p l e t imes . For each found se r v i c e , anl e s e r v i c e e v e n t t wi th type s e t toGATT EVENT SERVICE QUERY RESULT w i l l be generated and passed tothe r e g i s t e r e d c a l l b a c k . The g a t t c omp l e t e e v en t t , wi th type

s e t to GATT EVENTQUERY COMPLETE, marks the end o f d i s cove ry .∗ @param ca l l b a c k∗ @param con handle∗ @param uuid128∗/

uint8 t g a t t c l i e n t d i s c o v e r p r i m a r y s e r v i c e s b y u u i d 1 2 8 (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,const uint8 t ∗ uuid128 ) ;

/∗∗∗ @br ie f Finds inc luded s e r v i c e s w i th in the s p e c i f i e d s e r v i c e . For

each found inc luded se r v i c e , an l e s e r v i c e e v e n t t wi th types e t to GATT EVENT INCLUDED SERVICE QUERY RESULT w i l l begenerated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f d i s cove ry .Informat ion about inc luded s e r v i c e type ( primary/ secondary ) canbe r e t r i e v e d e i t h e r by sending an ATT f ind in format ion r e que s tf o r the re turned s t a r t group handle ( r e tu rn ing the handle and

the UUID fo r primary or secondary s e r v i c e ) or by comparing thes e r v i c e to the l i s t o f a l l primary s e r v i c e s .

∗ @param ca l l b a c k∗ @param con handle∗ @param s e r v i c e∗/

uint8 t g a t t c l i e n t f i n d i n c l u d e d s e r v i c e s f o r s e r v i c e (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient service t ∗ s e r v i c e ) ;

/∗∗

Page 182: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

181

∗ @br ie f Discovers a l l c h a r a c t e r i s t i c s w i th in the s p e c i f i e d s e r v i c e. For each found c h a r a c t e r i s t i c , an l e c h a r a c t e r i s t i c s e v e n t twi th type s e t to GATT EVENT CHARACTERISTIC QUERY RESULT w i l l begenerated and passed to the r e g i s t e r e d c a l l b a c k . The

g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f d i s cove ry .

∗ @param ca l l b a c k∗ @param con handle∗ @param s e r v i c e∗/

uint8 t g a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c s f o r s e r v i c e (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient service t ∗ s e r v i c e ) ;

/∗∗∗ @br ie f The f o l l ow i n g four f unc t i on s are used to d i s co v e r a l l

c h a r a c t e r i s t i c s w i th in the s p e c i f i e d s e r v i c e or handle range ,and re turn those t ha t match the g iven UUID. For each foundc h a r a c t e r i s t i c , an l e c h a r a c t e r i s t i c e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC QUERY RESULT w i l l be genera ted andpassed to the r e g i s t e r e d c a l l b a c k . The g a t t c omp l e t e e v e n t twi th type s e t to GATT EVENTQUERY COMPLETE, marks the end o fd i s cove ry .

∗ @param ca l l b a c k∗ @param con handle∗ @param s t a r t h an d l e∗ @param end handle∗ @param uuid16∗/

uint8 tg a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c s f o r h a n d l e r a n g e b y u u i d 1 6 (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t s t a r t hand l e , uint16 t end handle , uint16 t uuid16 ) ;

/∗∗∗ @br ie f The f o l l ow i n g four f unc t i on s are used to d i s co v e r a l l

c h a r a c t e r i s t i c s w i th in the s p e c i f i e d s e r v i c e or handle range ,and re turn those t ha t match the g iven UUID. For each foundc h a r a c t e r i s t i c , an l e c h a r a c t e r i s t i c e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC QUERY RESULT w i l l be genera ted andpassed to the r e g i s t e r e d c a l l b a c k . The g a t t c omp l e t e e v e n t twi th type s e t to GATT EVENTQUERY COMPLETE, marks the end o fd i s cove ry .

∗ @param ca l l b a c k∗ @param con handle∗ @param s t a r t h an d l e∗ @param end handle∗ @param uuid128∗/

uint8 tg a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c s f o r h a n d l e r a n g e b y u u i d 1 2 8(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t s t a r t hand l e , uint16 t end handle , uint8 t ∗ uuid128 )

;

Page 183: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

182

/∗∗∗ @br ie f The f o l l ow i n g four f unc t i on s are used to d i s co v e r a l l

c h a r a c t e r i s t i c s w i th in the s p e c i f i e d s e r v i c e or handle range ,and re turn those t ha t match the g iven UUID. For each foundc h a r a c t e r i s t i c , an l e c h a r a c t e r i s t i c e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC QUERY RESULT w i l l be genera ted andpassed to the r e g i s t e r e d c a l l b a c k . The g a t t c omp l e t e e v e n t twi th type s e t to GATT EVENTQUERY COMPLETE, marks the end o fd i s cove ry .

∗ @param ca l l b a c k∗ @param con handle∗ @param s e r v i c e∗ @param uuid16∗/

uint8 t g a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c s f o r s e r v i c e b y u u i d 1 6 (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient service t ∗ s e r v i c e , uint16 t uuid16 ) ;

/∗∗∗ @br ie f The f o l l ow i n g four f unc t i on s are used to d i s co v e r a l l

c h a r a c t e r i s t i c s w i th in the s p e c i f i e d s e r v i c e or handle range ,and re turn those t ha t match the g iven UUID. For each foundc h a r a c t e r i s t i c , an l e c h a r a c t e r i s t i c e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC QUERY RESULT w i l l be genera ted andpassed to the r e g i s t e r e d c a l l b a c k . The g a t t c omp l e t e e v e n t twi th type s e t to GATT EVENTQUERY COMPLETE, marks the end o fd i s cove ry .

∗ @param ca l l b a c k∗ @param con handle∗ @param s e r v i c e∗ @param uuid128∗/

uint8 t g a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c s f o r s e r v i c e b y u u i d 1 2 8 (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient service t ∗ s e r v i c e , uint8 t ∗ uuid128 ) ;

/∗∗∗ @br ie f Discovers a t t r i b u t e handle and UUID of a c h a r a c t e r i s t i c

d e s c r i p t o r w i th in the s p e c i f i e d c h a r a c t e r i s t i c . For each foundde s c r i p t o r , an l e c h a r a c t e r i s t i c d e s c r i p t o r e v e n t t wi th types e t to GATT EVENT ALL CHARACTERISTIC DESCRIPTORS QUERY RESULTw i l l be generated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f d i s cove ry .

∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c∗/

uint8 t g a t t c l i e n t d i s c o v e r c h a r a c t e r i s t i c d e s c r i p t o r s (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient character ist ic t ∗ c h a r a c t e r i s t i c ) ;

/∗∗

Page 184: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

183

∗ @br ie f Reads the c h a r a c t e r i s t i c va lue us ing the c h a r a c t e r i s t i c ’ sva lue handle . I f the c h a r a c t e r i s t i c va lue i s found , anl e c h a r a c t e r i s t i c v a l u e e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC VALUE QUERY RESULT w i l l be generatedand passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c∗/

uint8 t g a t t c l i e n t r e a d v a l u e o f c h a r a c t e r i s t i c (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient character ist ic t ∗ c h a r a c t e r i s t i c ) ;

/∗∗∗ @br ie f Reads the c h a r a c t e r i s t i c va lue us ing the c h a r a c t e r i s t i c ’ s

va lue handle . I f the c h a r a c t e r i s t i c va lue i s found , anl e c h a r a c t e r i s t i c v a l u e e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC VALUE QUERY RESULT w i l l be generatedand passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗/

uint8 t g a t t c l i e n t r e a d v a l u e o f c h a r a c t e r i s t i c u s i n g v a l u e h a n d l e (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t c h a r a c t e r i s t i c v a l u e h a n d l e ) ;

/∗∗∗ @br ie f Reads the c ha ra c t e r i c va lue o f a l l c h a r a c t e r i s t i c s wi th

the uuid . For each found , an l e c h a r a c t e r i s t i c v a l u e e v e n t twi th type s e t to GATT EVENT CHARACTERISTIC VALUE QUERY RESULTw i l l be generated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param s t a r t h an d l e∗ @param end handle∗ @param uuid16∗/

uint8 t g a t t c l i e n t r e a d v a l u e o f c h a r a c t e r i s t i c s b y u u i d 1 6 (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t s t a r t hand l e , uint16 t end handle , uint16 t uuid16 ) ;

/∗∗

Page 185: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

184

∗ @br ie f Reads the c ha ra c t e r i c va lue o f a l l c h a r a c t e r i s t i c s wi ththe uuid . For each found , an l e c h a r a c t e r i s t i c v a l u e e v e n t twi th type s e t to GATT EVENT CHARACTERISTIC VALUE QUERY RESULTw i l l be generated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param s t a r t h an d l e∗ @param end handle∗ @param uuid128∗/

uint8 t g a t t c l i e n t r e a d v a l u e o f c h a r a c t e r i s t i c s b y u u i d 1 2 8 (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t s t a r t hand l e , uint16 t end handle , uint8 t ∗ uuid128 ) ;

/∗∗∗ @br ie f Reads the long c h a r a c t e r i s t i c va lue us ing the

c h a r a c t e r i s t i c ’ s va lue handle . The va lue w i l l be re turned ins e v e r a l b l o b s . For each b lob , anl e c h a r a c t e r i s t i c v a l u e e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC VALUE QUERY RESULT and updated va lueo f f s e t w i l l be generated and passed to the r e g i s t e r e d c a l l b a c k .The g a t t c omp l e t e e v e n t t wi th type s e t to

GATT EVENTQUERY COMPLETE, mark the end o f read .∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c∗/

uint8 t g a t t c l i e n t r e a d l o n g v a l u e o f c h a r a c t e r i s t i c (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient character ist ic t ∗ c h a r a c t e r i s t i c ) ;

/∗∗∗ @br ie f Reads the long c h a r a c t e r i s t i c va lue us ing the

c h a r a c t e r i s t i c ’ s va lue handle . The va lue w i l l be re turned ins e v e r a l b l o b s . For each b lob , anl e c h a r a c t e r i s t i c v a l u e e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC VALUE QUERY RESULT and updated va lueo f f s e t w i l l be generated and passed to the r e g i s t e r e d c a l l b a c k .The g a t t c omp l e t e e v e n t t wi th type s e t to

GATT EVENTQUERY COMPLETE, mark the end o f read .∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗/

uint8 tg a t t c l i e n t r e a d l o n g v a l u e o f c h a r a c t e r i s t i c u s i n g v a l u e h a n d l e(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t c h a r a c t e r i s t i c v a l u e h a n d l e ) ;

/∗∗

Page 186: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

185

∗ @br ie f Reads the long c h a r a c t e r i s t i c va lue us ing thec h a r a c t e r i s t i c ’ s va lue handle . The va lue w i l l be re turned ins e v e r a l b l o b s . For each b lob , anl e c h a r a c t e r i s t i c v a l u e e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC VALUE QUERY RESULT and updated va lueo f f s e t w i l l be generated and passed to the r e g i s t e r e d c a l l b a c k .The g a t t c omp l e t e e v e n t t wi th type s e t to

GATT EVENTQUERY COMPLETE, mark the end o f read .∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗ @param o f f s e t∗/

uint8 tg a t t c l i e n t r e a d l o n g v a l u e o f c h a r a c t e r i s t i c u s i n g v a l u e h a n d l e w i t h o f f s e t(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t c h a r a c t e r i s t i c v a l u e h a n d l e , uint16 t o f f s e t ) ;

/∗∗ @br ie f Read mu l t i p l e c h a r a c t e r i s t i c va l u e s∗ @param ca l l b a c k∗ @param con handle∗ @param num value hand les∗ @param va l u e hand l e s l i s t o f hand les∗/

uint8 t g a t t c l i e n t r e a d m u l t i p l e c h a r a c t e r i s t i c v a l u e s (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,int num value handles , uint16 t ∗ va lue hand l e s ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c va lue us ing the c h a r a c t e r i s t i c ’ s

va lue handle wi thou t an acknowledgment t ha t the wr i t e wass u c c e s s f u l l y performed .

∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done∗/

uint8 t g a t t c l i e n t w r i t e v a l u e o f c h a r a c t e r i s t i c w i t h o u t r e s p o n s e (h c i c o n h a n d l e t con handle , uint16 tc h a r a c t e r i s t i c v a l u e h a n d l e , uint16 t l ength , uint8 t ∗ data ) ;

/∗∗∗ @br ie f Writes the au t h en t i c a t e d c h a r a c t e r i s t i c va lue us ing the

c h a r a c t e r i s t i c ’ s va lue handle wi thout an acknowledgment t ha tthe wr i t e was s u c c e s s f u l l y performed .

∗ @param ca l l b a c k∗ @param con handle∗ @param va lue hand l e∗ @param message len∗ @param message i s not copied , make sure memory i s a c c e s s i b l e

u n t i l wr i t e i s done∗/

Page 187: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

186

uint8 t g a t t c l i e n t s i g n e d w r i t e w i t h o u t r e s p o n s e (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t value handle , uint16 t message len , uint8 t ∗ message );

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c va lue us ing the c h a r a c t e r i s t i c ’ s

va lue handle . The g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

uint8 t g a t t c l i e n t w r i t e v a l u e o f c h a r a c t e r i s t i c (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t c h a r a c t e r i s t i c v a l u e h a n d l e , uint16 t l ength , uint8 t∗ data ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c va lue us ing the c h a r a c t e r i s t i c ’ s

va lue handle . The g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

uint8 t g a t t c l i e n t w r i t e l o n g v a l u e o f c h a r a c t e r i s t i c (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t c h a r a c t e r i s t i c v a l u e h a n d l e , uint16 t l ength , uint8 t∗ data ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c va lue us ing the c h a r a c t e r i s t i c ’ s

va lue handle . The g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗ @param o f f s e t o f va lue∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed

Page 188: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

187

∗/uint8 t g a t t c l i e n t w r i t e l o n g v a l u e o f c h a r a c t e r i s t i c w i t h o f f s e t (

btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t c h a r a c t e r i s t i c v a l u e h a n d l e , uint16 t o f f s e t , uint16 tl ength , uint8 t ∗ data ) ;

/∗∗∗ @br ie f Writes o f the long c h a r a c t e r i s t i c va lue us ing the

c h a r a c t e r i s t i c ’ s va lue handle . I t uses s e r v e r response tov a l i d a t e t ha t the wr i t e was c o r r e c t l y r e c e i v ed . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERYCOMPLETE marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to0 .

∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c v a l u e h a n d l e∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

uint8 t g a t t c l i e n t r e l i a b l e w r i t e l o n g v a l u e o f c h a r a c t e r i s t i c (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t c h a r a c t e r i s t i c v a l u e h a n d l e , uint16 t l ength , uint8 t∗ data ) ;

/∗∗∗ @br ie f Reads the c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle . I f

the c h a r a c t e r i s t i c d e s c r i p t o r i s found , anl e c h a r a c t e r i s t i c d e s c r i p t o r e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT w i l l begenerated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r∗/

uint8 t g a t t c l i e n t r e a d c h a r a c t e r i s t i c d e s c r i p t o r (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt cl ient characterist ic descriptor t ∗ d e s c r i p t o r ) ;

/∗∗∗ @br ie f Reads the c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle . I f

the c h a r a c t e r i s t i c d e s c r i p t o r i s found , anl e c h a r a c t e r i s t i c d e s c r i p t o r e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT w i l l begenerated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r∗/

Page 189: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

188

uint8 tg a t t c l i e n t r e a d c h a r a c t e r i s t i c d e s c r i p t o r u s i n g d e s c r i p t o r h a n d l e(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t d e s c r i p t o r h a n d l e ) ;

/∗∗∗ @br ie f Reads the long c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle .

I t w i l l be re turned in s e v e r a l b l o b s . For each b lob , anl e c h a r a c t e r i s t i c d e s c r i p t o r e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT w i l l begenerated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r h and l e∗/

uint8 t g a t t c l i e n t r e a d l o n g c h a r a c t e r i s t i c d e s c r i p t o r (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt cl ient characterist ic descriptor t ∗ d e s c r i p t o r ) ;

/∗∗∗ @br ie f Reads the long c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle .

I t w i l l be re turned in s e v e r a l b l o b s . For each b lob , anl e c h a r a c t e r i s t i c d e s c r i p t o r e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT w i l l begenerated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r h and l e∗/

uint8 tg a t t c l i e n t r e a d l o n g c h a r a c t e r i s t i c d e s c r i p t o r u s i n g d e s c r i p t o r h a n d l e(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t d e s c r i p t o r h a n d l e ) ;

/∗∗∗ @br ie f Reads the long c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle .

I t w i l l be re turned in s e v e r a l b l o b s . For each b lob , anl e c h a r a c t e r i s t i c d e s c r i p t o r e v e n t t wi th type s e t toGATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT w i l l begenerated and passed to the r e g i s t e r e d c a l l b a c k . Theg a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f read .

∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r h and l e∗ @param o f f s e t∗/

Page 190: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

189

uint8 tg a t t c l i e n t r e a d l o n g c h a r a c t e r i s t i c d e s c r i p t o r u s i n g d e s c r i p t o r h a n d l e w i t h o f f s e t(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t de s c r i p to r hand l e , uint16 t o f f s e t ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle . The

g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

uint8 t g a t t c l i e n t w r i t e c h a r a c t e r i s t i c d e s c r i p t o r (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt cl ient characterist ic descriptor t ∗ de s c r i p to r , uint16 tl ength , uint8 t ∗ data ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle . The

g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r h and l e∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

uint8 tg a t t c l i e n t w r i t e c h a r a c t e r i s t i c d e s c r i p t o r u s i n g d e s c r i p t o r h a n d l e(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t de s c r i p to r hand l e , uint16 t l ength , uint8 t ∗ data ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle . The

g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

Page 191: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

190

uint8 t g a t t c l i e n t w r i t e l o n g c h a r a c t e r i s t i c d e s c r i p t o r (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt cl ient characterist ic descriptor t ∗ de s c r i p to r , uint16 tl ength , uint8 t ∗ data ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle . The

g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r h and l e∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

uint8 tg a t t c l i e n t w r i t e l o n g c h a r a c t e r i s t i c d e s c r i p t o r u s i n g d e s c r i p t o r h a n d l e(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t de s c r i p to r hand l e , uint16 t l ength , uint8 t ∗ data ) ;

/∗∗∗ @br ie f Writes the c h a r a c t e r i s t i c d e s c r i p t o r us ing i t s handle . The

g a t t c omp l e t e e v e n t t wi th type s e t toGATT EVENTQUERY COMPLETE, marks the end o f wr i t e . The wr i t e i ss u c c e s s f u l l y performed , i f the event ’ s s t a t u s f i e l d i s s e t to

0 .∗ @param ca l l b a c k∗ @param con handle∗ @param de s c r i p t o r h and l e∗ @param o f f s e t o f va lue∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

uint8 tg a t t c l i e n t w r i t e l o n g c h a r a c t e r i s t i c d e s c r i p t o r u s i n g d e s c r i p t o r h a n d l e w i t h o f f s e t(btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,uint16 t de s c r i p to r hand l e , uint16 t o f f s e t , uint16 t l ength ,

uint8 t ∗ data ) ;

/∗∗∗ @br ie f Writes the c l i e n t c h a r a c t e r i s t i c c on f i g u ra t i on o f the

s p e c i f i e d c h a r a c t e r i s t i c . I t i s used to s u b s c r i b e f o rn o t i f i c a t i o n s or i n d i c a t i o n s o f the c h a r a c t e r i s t i c va lue . Forn o t i f i c a t i o n s or i n d i c a t i o n s s p e c i f y :GATT CLIENT CHARACTERISTICS CONFIGURATION NOTIFICATION resp .GATT CLIENT CHARACTERISTICS CONFIGURATION INDICATION ascon f i g u ra t i on va lue .

∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c

Page 192: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

191

∗ @param con f i g u r a t i on∗/

uint8 t g a t t c l i e n t w r i t e c l i e n t c h a r a c t e r i s t i c c o n f i g u r a t i o n (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient character ist ic t ∗ c h a r a c t e r i s t i c , uint16 tc o n f i g u r a t i o n ) ;

/∗∗∗ @br ie f Reg i s t e r f o r n o t i f i c a t i o n s and i n d i c a t i o n s o f a

c h a r a c t e r i s t i c enab led byg a t t c l i e n t w r i t e c l i e n t c h a r a c t e r i s t i c c o n f i g u r a t i o n

∗ @param n o t i f i c a t i o n s t r u c t used to s t o r e r e g i s t r a t i o n∗ @param ca l l b a c k∗ @param con handle∗ @param c h a r a c t e r i s t i c∗/

void g a t t c l i e n t l i s t e n f o r c h a r a c t e r i s t i c v a l u e u p d a t e s (g a t t c l i e n t n o t i f i c a t i o n t ∗ n o t i f i c a t i o n ,btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ,gatt c l ient character ist ic t ∗ c h a r a c t e r i s t i c ) ;

/∗∗∗ @br ie f Stop l i s t e n i n g to c h a r a c t e r i s t i c va lue updates r e g i s t e r e d

wi th g a t t c l i e n t l i s t e n f o r c h a r a c t e r i s t i c v a l u e u p d a t e s∗ @param n o t i f i c a t i o n s t r u c t used in

g a t t c l i e n t l i s t e n f o r c h a r a c t e r i s t i c v a l u e u p d a t e s∗/

void g a t t c l i e n t s t o p l i s t e n i n g f o r c h a r a c t e r i s t i c v a l u e u p d a t e s (g a t t c l i e n t n o t i f i c a t i o n t ∗ n o t i f i c a t i o n ) ;

/∗∗∗ @br ie f Requests GATT EVENT CANWRITEWITHOUT RESPONSE tha t

guarantees a s i n g l e s u c c e s s f u lg a t t c l i e n t w r i t e v a l u e o f c h a r a c t e r i s t i c w i t h o u t r e s p o n s e

∗ @param ca l l b a c k∗ @param con handle∗ @returns s t a t u s∗/

uint8 t g a t t c l i e n t r e q u e s t c a n w r i t e w i t h o u t r e s p o n s e e v e n t (btstack packet handler t ca l lback , h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Transac t iona l wr i t e . I t can be c a l l e d as many t imes as i t

i s needed to wr i t e the c h a r a c t e r i s t i c s w i th in the samet ran sac t i on . Ca l l g a t t c l i e n t e x e c u t e w r i t e to commit thet r an sac t i on .

∗ @param ca l l b a c k∗ @param con handle∗ @param a t t r i b u t e h a n d l e∗ @param o f f s e t o f va lue∗ @param l eng t h o f data∗ @param data i s not copied , make sure memory i s a c c e s s i b l e u n t i l

wr i t e i s done , i . e . GATT EVENTQUERYCOMPLETE i s r e c e i v ed∗/

Page 193: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

192

uint8 t g a t t c l i e n t p r e p a r e w r i t e (btstack packet handler t ca l lback ,h c i c o n h a n d l e t con handle , uint16 t a t t r i bu t e hand l e ,

uint16 t o f f s e t , uint16 t l ength , uint8 t ∗ data ) ;

/∗∗∗ @br ie f Commit t r an s a c t i o na l wr i t e . GATT EVENTQUERYCOMPLETE i s

r e c e i v ed .∗ @param ca l l b a c k∗ @param con handle∗/

uint8 t g a t t c l i e n t e x e c u t e w r i t e (btstack packet handler t ca l lback ,h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Abort t r an s a c t i o na l wr i t e . GATT EVENTQUERYCOMPLETE i s

r e c e i v ed .∗ @param ca l l b a c k∗ @param con handle∗/

uint8 t g a t t c l i e n t c a n c e l w r i t e (btstack packet handler t ca l lback ,h c i c o n h a n d l e t con handle ) ;

31.5. BLE Device Database API.

/∗∗∗ @br ie f i n i t∗/

void l e d e v i c e d b i n i t (void ) ;

/∗∗∗ @br ie f s e t s l o c a l bd addr . a l l ow s f o r db per B lue too th c o n t r o l l e r∗ @param bd addr∗/

void l e d e v i c e d b s e t l o c a l b d a d d r (bd addr t bd addr ) ;

/∗∗∗ @br ie f add dev i c e to db∗ @param addr type , address o f the dev i c e∗ @param i r k o f the dev i c e∗ @returns index i f s u c c e s s f u l , −1 o the rw i s e∗/

int l e d e v i c e d b a d d ( int addr type , bd addr t addr , sm key t i r k ) ;

/∗∗∗ @br ie f g e t number o f d e v i c e s in db∗ @returns number o f dev i c e in db∗/

int l e d e v i c e d b c o u n t (void ) ;

/∗∗∗ @br ie f g e t max number o f d e v i c e s in db f o r enumeration∗ @returns max number o f dev i c e in db

Page 194: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

193

∗/int l e dev i ce db max count (void ) ;

/∗∗∗ @br ie f g e t dev i c e in format ion : addr type and address needed to

i d e n t i f y dev i c e∗ @param index∗ @param addr type , address o f the dev i c e as output∗ @param i r k o f the dev i c e∗/

void l e d e v i c e d b i n f o ( int index , int ∗ addr type , bd addr t addr ,sm key t i r k ) ;

/∗∗∗ @br ie f s e t remote encryp t ion in f o∗ @br ie f index∗ @br ie f ed i v∗ @br ie f rand∗ @br ie f l t k∗ @br ie f key s i z e∗ @br ie f au t h en t i c a t e d∗ @br ie f au thor i z ed∗ @bre i f s ecure connec t i on∗/

void l e d e v i c e d b e n c r y p t i o n s e t ( int index , uint16 t ediv , uint8 trand [ 8 ] , sm key t l tk , int key s i z e , int authent icated , intauthor ized , int s e c u r e c o nn e c t i o n ) ;

/∗∗∗ @br ie f g e t remote encryp t ion in f o∗ @br ie f index∗ @br ie f ed i v∗ @br ie f rand∗ @br ie f l t k∗ @br ie f key s i z e∗ @br ie f au t h en t i c a t e d∗ @br ie f au thor i z ed∗ @bre i f s ecure connec t i on∗/

void l e d e v i c e d b e n c r y p t i o n g e t ( int index , uint16 t ∗ ediv , uint8 trand [ 8 ] , sm key t l tk , int ∗ key s i z e , int ∗ authent icated ,

int ∗ author ized , int ∗ s e c u r e c o nn e c t i o n ) ;

#ifde f ENABLE LE SIGNED WRITE

/∗∗∗ @br ie f s e t l o c a l s i gn in g key f o r t h i s dev i c e∗ @param index∗ @param s i gn in g key as input∗/

void l e d e v i c e d b l o c a l c s r k s e t ( int index , sm key t c s rk ) ;

/∗∗

Page 195: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

194

∗ @br ie f g e t l o c a l s i gn in g key f o r t h i s dev i c e∗ @param index∗ @param s i gn in g key as output∗/

void l e d e v i c e d b l o c a l c s r k g e t ( int index , sm key t c s rk ) ;

/∗∗∗ @br ie f s e t remote s i gn in g key f o r t h i s dev i c e∗ @param index∗ @param s i gn in g key as input∗/

void l e d e v i c e d b r e m o t e c s r k s e t ( int index , sm key t c s rk ) ;

/∗∗∗ @br ie f g e t remote s i gn in g key f o r t h i s dev i c e∗ @param index∗ @param s i gn in g key as output∗/

void l e d e v i c e d b r e m o t e c s r k g e t ( int index , sm key t c s rk ) ;

/∗∗∗ @br ie f query l a s t used/ seen s i gn in g counter∗ @param index∗ @returns next expec ted counter , 0 a f t e r d e v i c e s was added∗/

uint32 t l e d e v i c e d b r e m o t e c o u n t e r g e t ( int index ) ;

/∗∗∗ @br ie f update s i gn in g counter∗ @param index∗ @param counter to s t o r e∗/

void l e d e v i c e d b r e m o t e c o u n t e r s e t ( int index , uint32 t counter ) ;

/∗∗∗ @br ie f query l a s t used/ seen s i gn in g counter∗ @param index∗ @returns next expec ted counter , 0 a f t e r d e v i c e s was added∗/

uint32 t l e d e v i c e d b l o c a l c o u n t e r g e t ( int index ) ;

/∗∗∗ @br ie f update s i gn in g counter∗ @param index∗ @param counter to s t o r e∗/

void l e d e v i c e d b l o c a l c o u n t e r s e t ( int index , uint32 t counter ) ;

#endif

/∗∗∗ @br ie f f r e e dev i c e∗ @param index∗/

Page 196: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

195

void l e dev i c e db remove ( int index ) ;

void l e dev ice db dump (void ) ;

31.6. BLE Security Manager API.

/∗∗∗ @br ie f I n i t i a l i z e s the Secur i t y Manager , connects to L2CAP∗/

void s m i n i t (void ) ;

/∗∗∗ @br ie f Set s e c r e t ER key f o r key genera t ion as de s c r i b ed in Core

V4.0 , Vol 3 , Part G, 5 . 2 . 2∗ @note I f not s e t and b t s t a c k t l v i s conf igured , ER key i s

generated and s t o r ed in TLV by SM∗ @param er∗/

void s m s e t e r ( sm key t er ) ;

/∗∗∗ @br ie f Set s e c r e t IR key f o r key genera t ion as de s c r i b ed in Core

V4.0 , Vol 3 , Part G, 5 . 2 . 2∗ @note I f not s e t and b t s t a c k t l v i s conf igured , IR key i s

generated and s t o r ed in TLV by SM∗/

void s m s e t i r ( sm key t i r ) ;

/∗∗∗∗ @br ie f Reg i s t e r s OOB Data Ca l l back . The c a l l b a c k shou ld s e t the

oob data and re turn 1 i f OOB data i s a v a i l b l e∗ @param g e t o o b d a t a c a l l b a c k∗/

void s m r e g i s t e r o o b d a t a c a l l b a c k ( int (∗ g e t o o b d a t a c a l l b a c k ) (uint8 t address type , bd addr t addr , uint8 t ∗ oob data ) ) ;

/∗∗∗ @br ie f Add event packe t hand ler .∗/

void sm add event handler ( b t s t a c k p a c k e t c a l l b a c k r e g i s t r a t i o n t ∗c a l l b a c k h a n d l e r ) ;

/∗∗∗ @br ie f Limit the STK genera t ion methods . Bonding i s s topped i f

the r e s u l t i n g one i sn ’ t in the l i s t∗ @param OR combination o f SM STK GENERATION METHOD∗/

void sm se t accep t ed s tk gene ra t i on methods ( uint8 taccepted s tk gene ra t i on methods ) ;

/∗∗

Page 197: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

196

∗ @br ie f Set the accepted encryp t ion key s i z e range . Bonding i ss topped i f the r e s u l t i sn ’ t w i th in the range

∗ @param min s i ze ( d e f a u l t 7)∗ @param max size ( d e f a u l t 16)∗/

void s m s e t e n c r y p t i o n k e y s i z e r a n g e ( uint8 t min s ize , uint8 tmax size ) ;

/∗∗∗ @br ie f Se t s the r eque s t ed au t h en t i c a t i on requirements , bonding

yes /no , MITM yes /no , SC yes /no , keypre s s yes /no∗ @param OR combination o f SM AUTHREQ f l a g s∗/

void s m s e t a u t h e n t i c a t i o n r e q u i r e m e n t s ( uint8 t auth req ) ;

/∗∗∗ @br ie f Se t s the a v a i l a b l e IO Cap a b i l i t i e s∗ @param IO CAPABILITY∗/

void s m s e t i o c a p a b i l i t i e s ( i o c a p a b i l i t y t i o c a p a b i l i t y ) ;

/∗∗∗ @br ie f Let Per iphera l r e que s t an encrypted connect ion r i g h t a f t e r

connect ing∗ @note Not used normal ly . Bonding i s t r i g g e r e d by acces s to

p ro t e c t ed a t t r i b u t e s in ATT Server∗/

void s m s e t r e q u e s t s e c u r i t y ( int enable ) ;

/∗∗∗ @br ie f Tr igger Secur i t y Request∗ @note Not used normal ly . Bonding i s t r i g g e r e d by acces s to

p ro t e c t ed a t t r i b u t e s in ATT Server∗/

void s m s e n d s e c u r i t y r e q u e s t ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Dec l ine bonding t r i g g e r e d by event b e f o r e∗ @param con handle∗/

void sm bonding dec l ine ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Confirm Just Works bonding∗ @param con handle∗/

void sm jus t works con f i rm ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Confirm va lue from SM EVENT NUMERIC COMPARISON REQUEST fo r

Numeric Comparison bonding∗ @param con handle∗/

void sm numeric comparison conf i rm ( h c i c o n h a n d l e t con handle ) ;

Page 198: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

197

/∗∗∗ @br ie f Reports passkey input by user∗ @param con handle∗ @param passkey in [ 0 . . 9 9 9999 ]∗/

void sm passkey input ( h c i c o n h a n d l e t con handle , uint32 t passkey );

/∗∗∗ @br ie f Send keypre s s n o t i f i c a t i o n f o r keyboard only d e v i c e s∗ @param con handle∗ @param ac t ion see SM KEYPRESS ∗ in b l u e t o o t h . h∗/

void s m k e y p r e s s n o t i f i c a t i o n ( h c i c o n h a n d l e t con handle , uint8 tac t i on ) ;

/∗∗∗ @br ie f Used by a t t s e r v e r . c to r e que s t user au t ho r i z a t i on .∗ @param con handle∗/

void s m r e q u e s t p a i r i n g ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Report user au t ho r i z a t i on d e c l i n e .∗ @param con handle∗/

void s m a u t h o r i z a t i o n d e c l i n e ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Report user au t ho r i z a t i on grant .∗ @param con handle∗/

void sm author i za t i on g rant ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Support f o r s i gned wr i t e s , used by a t t s e r v e r .∗ @returns ready∗/

int sm cmac ready (void ) ;

/∗∗∗ @br ie f Support f o r s i gned wr i t e s , used by a t t s e r v e r .∗ @note Message i s in l i t t l e endian to a l l ows pass ing in ATT PDU

without f l i p p i n g .∗ @note s i gn in g data : [ opcode , a t t r i b u t e h and l e , message ,

s i gn coun t e r ]∗ @note c a l c u l a t e d hash in done ca l l b a c k i s b i g endian and has 16

by t e .∗ @param key∗ @param opcde∗ @param a t t r i b u t e h a n d l e∗ @param message len∗ @param message

Page 199: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

198

∗ @param s i gn coun t e r∗/

void sm cmac s i gned wr i t e s t a r t ( const sm key t key , uint8 t opcode ,uint16 t a t t r i bu t e hand l e , uint16 t message len , const uint8 t ∗

message , uint32 t s i gn counte r , void (∗ done ca l l back ) ( uint8 t ∗hash ) ) ;

/∗∗ @br ie f Match address aga in s t bonded dev i c e s∗ @return 0 i f s u c c e s s f u l l y added to lookup queue∗ @note Tr igger s SM IDENTITY RESOLVING ∗ even t s∗/

int s m a d d r e s s r e s o l u t i o n l o o k u p ( uint8 t addr type , bd addr t addr ) ;

/∗∗∗ @br ie f I d e n t i f y dev i c e in LE Device DB.∗ @param handle∗ @return index from l e d e v i c e d b or −1 i f not found/ i d e n t i f i e d∗/

int s m l e d e v i c e i n d e x ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Use f i x e c passkey f o r Legacy and SC in s t ead o f genera t ing

a random number∗ @note Can be used to improve s e c u r i t y over Jus t Works i f no

keyboard or d i s p l a r y are pre sen t and∗ i n d i v i d u a l random passkey can be pr in t ed on the dev i c e

during product ion∗ @param passkey∗/

void s m u s e f i x e d p a s s k e y i n d i s p l a y r o l e (uint32 t passkey ) ;

/∗∗∗ @br ie f Allow connect ion re−encryp t ion in Per iphera l ( Responder )

r o l e f o r LE Legacy Pair ing∗ wi thout entry f o r Centra l d ev i c e s t o r ed in LE Device DB∗ @note BTstack in Per iphera l Role ( Responder ) suppor t s LE Legacy

Pair ing wi thout a p e r s i s t e n t LE Device DB as∗ the LTK i s r e cons t ruc t ed from a l o c a l s e c r e t IRK and EDIV +

Random s to r ed on Centra l ( I n i t i a t o r ) dev i c e∗ On the downside , i t ’ s not r e a l l y p o s s i b l e to d e l e t e a

pa i r i n g i f t h i s i s enab led .∗ @param a l l ow encryp t ion us ing r e cons t ruc t ed LTK wi thout s t o r ed

entry ( De fau l t : 1)∗/

void s m a l l o w l t k r e c o n s t r u c t i o n w i t h o u t l e d e v i c e d b e n t r y ( inta l low ) ;

/∗∗∗ @br ie f Generate OOB data f o r LE Secure Connections∗ @note This genera t e s a 128 b i t random number ra and then

c a l c u l a t e s Ca = f4 (PKa, PKa, ra , 0)∗ New OOB data shou ld be generated f o r each pa i r i n g . Ra i s

used f o r subsequent OOB pa i r i n g s

Page 200: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

199

∗ @param ca l l b a c k∗ @returns s t a t u s∗/

uint8 t sm genera te s c oob data (void (∗ c a l l b a c k ) ( const uint8 t ∗conf i rm value , const uint8 t ∗ random value ) ) ;

/∗∗∗∗ @br ie f Reg i s t e r s OOB Data Ca l l back f o r LE Secure Conections . The

c a l l b a c k shou ld s e t a l l arguments and re turn 1 i f OOB data i sa v a i l b l e

∗ @note the oob sc l oca l random usua l l y i s the random valuere turend by sm genera t e s c oob da ta

∗ @param g e t o o b d a t a c a l l b a c k∗/

void s m r e g i s t e r s c o o b d a t a c a l l b a c k ( int (∗g e t s c o o b d a t a c a l l b a c k ) ( uint8 t address type , bd addr t addr ,uint8 t ∗ oob sc pee r con f i rm , uint8 t ∗ oob sc peer random ) ) ;

31.7. BNEP API.

/∗∗∗ @br ie f Set up BNEP.∗/

void b n e p i n i t (void ) ;

/∗∗∗ @br ie f Check i f a data packe t can be send out .∗/

int bnep can send packet now (uint16 t bnep c id ) ;

/∗∗∗ @br ie f Request emiss ion o f BNEP CAN SEND NOW as soon as p o s s i b l e∗ @note BNEP CAN SEND NOW might be emi t ted during c a l l to t h i s

f unc t i on∗ so packe t hand ler shou ld be ready to handle i t∗ @param bnep c id∗/

void bnep request can send now event (uint16 t bnep c id ) ;

/∗∗∗ @br ie f Send a data packe t .∗/

int bnep send (uint16 t bnep cid , uint8 t ∗packet , uint16 t l en ) ;

/∗∗∗ @br ie f Set the network p ro t o co l f i l t e r .∗/

int b n e p s e t n e t t y p e f i l t e r (uint16 t bnep cid , b n e p n e t f i l t e r t ∗f i l t e r , uint16 t l en ) ;

/∗∗∗ @br ie f Set the mu l t i c a s t address f i l t e r .

Page 201: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

200

∗/int b n e p s e t m u l t i c a s t f i l t e r (uint16 t bnep cid , b n e p m u l t i f i l t e r t

∗ f i l t e r , uint16 t l en ) ;

/∗∗∗ @br ie f Set s e c u r i t y l e v e l r e qu i r ed f o r incoming connect ions , need

to be c a l l e d b e f o r e r e g i s t e r i n g s e r v i c e s .∗/

void b n e p s e t r e q u i r e d s e c u r i t y l e v e l ( g a p s e c u r i t y l e v e l ts e c u r i t y l e v e l ) ;

/∗∗∗ @br ie f Creates BNEP connect ion ( channel ) to a g iven s e r v e r on a

remote dev i c e wi th baseband address . A new baseband connect ionw i l l be i n i t i a t e d i f necessary .

∗/int bnep connect (btstack packet handler t packet handler , bd addr t

addr , uint16 t l2cap psm , uint16 t uu id s rc , uint16 t uu id des t );

/∗∗∗ @br ie f Disconnects BNEP channel wi th g iven i d e n t i f i e r .∗/

void bnep d i sconnect (bd addr t addr ) ;

/∗∗∗ @br ie f Reg i s t e r s BNEP serv i c e , s e t a maximum frame s i z e and

a s s i gn s a packe t hand ler . On embedded systems , use NULL fo rconnect ion parameter .

∗/uint8 t b n e p r e g i s t e r s e r v i c e (btstack packet handler t

packet handler , uint16 t s e r v i c e u u i d , uint16 t max frame s ize ) ;

/∗∗∗ @br ie f Unreg i s t e r BNEP s e r v i c e .∗/

void b n e p u n r e g i s t e r s e r v i c e (uint16 t s e r v i c e u u i d ) ;

31.8. Link Key DB API.

typedef struct {

// management

/∗∗∗ @br ie f Open the Link Key DB∗/

void (∗ open ) (void ) ;

/∗∗∗ @br ie f Se t s BD Addr o f l o c a l B lue too th Con t ro l l e r .∗ @note Only needed i f B lue too th Con t ro l l e r can be swapped , e . g

. USB Dongles on desk top systems

Page 202: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

201

∗/void (∗ s e t l o c a l b d a d d r ) (bd addr t bd addr ) ;

/∗∗∗ @br ie f Close the Link Key DB∗/

void (∗ c l o s e ) (void ) ;

// ge t / s e t / d e l e t e l i n k key

/∗∗∗ @br ie f Get Link Key f o r g i ven address∗ @param addr to lookup∗ @param l i n k k e y ( out )∗ @param type ( out )∗ @returns 1 on succe s s∗/

int (∗ g e t l i n k k e y ) (bd addr t bd addr , l ink key t l i nk key ,l i n k k e y t y p e t ∗ type ) ;

/∗∗∗ @br ie f Update/ Store Link key∗ @br ie f addr∗ @br ie f l i n k k e y∗ @br ie f type o f l i n k key∗/

void (∗ p u t l i n k k e y ) (bd addr t bd addr , l ink key t l i nk key ,l i n k k e y t y p e t type ) ;

/∗∗∗ @br ie f De le t e Link Keys∗ @br ie f addr∗/

void (∗ d e l e t e l i n k k e y ) (bd addr t bd addr ) ;

// i t e r a t o r : i t ’ s a l l owed to d e l e t e

/∗∗∗ @br ie f Setup i t e r a t o r∗ @param i t∗ @returns 1 on succe s s∗/

int (∗ i t e r a t o r i n i t ) ( b t s t a c k l i n k k e y i t e r a t o r t ∗ i t ) ;

/∗∗∗ @br ie f Get next Link Key∗ @param i t∗ @br ie f addr∗ @br ie f l i n k k e y∗ @br ie f type o f l i n k key∗ @returns 1 , i f v a l i d l i n k key found∗/

Page 203: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

202

int (∗ i t e r a t o r g e t n e x t ) ( b t s t a c k l i n k k e y i t e r a t o r t ∗ i t ,bd addr t bd addr , l ink key t l i nk key , l i n k k e y t y p e t ∗type ) ;

/∗∗∗ @br ie f Frees re source s a l l o c a t e d by i t e r a t o r i n i t∗ @note Must be c a l l e d a f t e r i t e r a t i o n to f r e e re source s∗ @param i t∗/

void (∗ i t e r a t o r d o n e ) ( b t s t a c k l i n k k e y i t e r a t o r t ∗ i t ) ;

} btstack link key db t ;

31.9. HSP Headset API.

/∗∗∗ @br ie f Set up HSP HS.∗ @param rfcomm channel nr∗/

void h s p h s i n i t ( uint8 t r fcomm channel nr ) ;

/∗∗∗ @br ie f Create HSP Headset (HS) SDP s e r v i c e record .∗ @param s e r v i c e Empty b u f f e r in which a new s e r v i c e record w i l l be

s t o r ed .∗ @param rfcomm channel nr∗ @param name∗ @param have remo te aud io con t ro l∗/

void h s p h s c r e a t e s d p r e c o r d ( uint8 t ∗ s e r v i c e , uint32 ts e r v i c e r e c o r d h a n d l e , int rfcomm channel nr , const char ∗ name ,uint8 t have remote aud io cont ro l ) ;

/∗∗∗ @br ie f Reg i s t e r packe t hand ler to r e c e i v e HSP HS even t s .∗∗ The HSP HS event has type HCI EVENT HSP META with f o l l ow i n g

sub type s :∗ − HSP SUBEVENT RFCOMMCONNECTION COMPLETE∗ − HSP SUBEVENT RFCOMMDISCONNECTION COMPLETE∗ − HSP SUBEVENT AUDIO CONNECTION COMPLETE∗ − HSP SUBEVENT AUDIO DISCONNECTION COMPLETE∗ − HSP SUBEVENT RING∗ − HSP SUBEVENT MICROPHONE GAIN CHANGED∗ − HSP SUBEVENT SPEAKER GAIN CHANGED∗ − HSP SUBEVENT AG INDICATION∗∗ @param ca l l b a c k∗/

void h s p h s r e g i s t e r p a c k e t h a n d l e r (btstack packet handler tc a l l b a c k ) ;

/∗∗

Page 204: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

203

∗ @br ie f Connect to HSP Audio Gateway .∗∗ Perform SDP query f o r an RFCOMM se r v i c e on a remote dev ice ,∗ and e s t a b l i s h an RFCOMM connect ion i f such s e r v i c e i s found .

Reception o f the∗ HSP SUBEVENT RFCOMMCONNECTION COMPLETE with s t a t u s 0∗ i n d i c a t e s i f the connect ion i s s u c c e s s f u l l y e s t a b l i s h e d .∗∗ @param bd addr∗/

void hsp hs connect (bd addr t bd addr ) ;

/∗∗∗ @br ie f Disconnect from HSP Audio Gateway∗∗ Releases the RFCOMM channel . Reception o f the∗ HSP SUBEVENT RFCOMMDISCONNECTION COMPLETE with s t a t u s 0∗ i n d i c a t e s i f the connect ion i s s u c c e s s f u l l y r e l e a s e d .∗ @param bd addr∗/

void hsp hs d i s connec t (void ) ;

/∗∗∗ @br ie f Send but ton pre s s ac t i on . Toggle e s t a b l i s h / r e l e a s e o f

audio connect ion .∗/

void hsp hs s end but ton pr e s s (void ) ;

/∗∗∗ @br ie f Triger e s t a b l i s h i n g audio connect ion .∗∗ Reception o f the HSP SUBEVENT AUDIO CONNECTION COMPLETE with

s t a t u s 0∗ i n d i c a t e s i f the audio connect ion i s s u c c e s s f u l l y e s t a b l i s h e d .∗ @param bd addr∗/

void h s p h s e s t a b l i s h a u d i o c o n n e c t i o n (void ) ;

/∗∗∗ @br ie f Tr igger r e l e a s i n g audio connect ion .∗∗ Reception o f the HSP SUBEVENT AUDIO DISCONNECTION COMPLETE with

s t a t u s 0∗ i n d i c a t e s i f the connect ion i s s u c c e s s f u l l y r e l e a s e d .∗ @param bd addr∗/

void h s p h s r e l e a s e a u d i o c o n n e c t i o n (void ) ;

/∗∗∗ @br ie f Set microphone gain .∗∗ The new gain va lue w i l l be confirmed by the HSP Audio Gateway .∗ A HSP SUBEVENT MICROPHONE GAIN CHANGED event w i l l be r e c e i v ed .

Page 205: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

204

∗ @param gain Val id range : [ 0 , 1 5 ]∗/

void hsp hs s e t mic rophone ga in ( uint8 t gain ) ;

/∗∗∗ @br ie f Set speaker gain .∗∗ The new gain va lue w i l l be confirmed by the HSP Audio Gateway .∗ A HSP SUBEVENT SPEAKER GAIN CHANGED event w i l l be r e c e i v ed .∗ @param gain − v a l i d range : [ 0 , 1 5 ]∗/

void h s p h s s e t s p e a k e r g a i n ( uint8 t gain ) ;

/∗∗∗ @br ie f Enable custom ind i c a t i o n s .∗∗ Custom ind i c a t i o n s are d i s a b l e d by d e f a u l t .∗ When enabled , custom ind i c a t i o n s are r e c e i v ed v ia the

HSP SUBEVENT AG INDICATION.∗ @param enab l e∗/

void h s p h s e n a b l e c u s t o m i n d i c a t i o n s ( int enable ) ;

/∗∗∗ @br ie f Send answer to custom ind i c a t i on .∗∗ On HSP SUBEVENT AG INDICATION, the c l i e n t needs to respond∗ with t h i s f unc t i on wi th the r e s u l t to the custom ind i c a t i on∗ @param r e s u l t∗/

int h s p h s s e n d r e s u l t ( const char ∗ r e s u l t ) ;

31.10. HSP Audio Gateway API.

/∗∗∗ @br ie f Set up HSP AG.∗ @param rfcomm channel nr∗/

void h s p a g i n i t ( uint8 t r fcomm channel nr ) ;

/∗∗∗ @br ie f Create HSP Audio Gateway (AG) SDP s e r v i c e record .∗ @param s e r v i c e Empty b u f f e r in which a new s e r v i c e record w i l l be

s t o r ed .∗ @param s e r v i c e r e c o r d hand l e∗ @param rfcomm channel nr∗ @param name∗/

void h s p a g c r e a t e s d p r e c o r d ( uint8 t ∗ s e r v i c e , uint32 ts e r v i c e r e c o r d h a n d l e , int rfcomm channel nr , const char ∗ name);

Page 206: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

205

/∗∗∗ @br ie f Reg i s t e r packe t hand ler to r e c e i v e HSP AG even t s .

∗ The HSP AG event has type HCI EVENT HSP META with f o l l ow i n gsub type s :

∗ − HSP SUBEVENT RFCOMMCONNECTION COMPLETE∗ − HSP SUBEVENT RFCOMMDISCONNECTION COMPLETE∗ − HSP SUBEVENT AUDIO CONNECTION COMPLETE∗ − HSP SUBEVENT AUDIO DISCONNECTION COMPLETE∗ − HSP SUBEVENT MICROPHONE GAIN CHANGED∗ − HSP SUBEVENT SPEAKER GAIN CHANGED∗ − HSP SUBEVENT HS COMMAND∗∗ @param ca l l b a c k∗/

void h s p a g r e g i s t e r p a c k e t h a n d l e r (btstack packet handler tc a l l b a c k ) ;

/∗∗∗ @br ie f Connect to HSP Headset .∗∗ Perform SDP query f o r an RFCOMM se r v i c e on a remote dev ice ,∗ and e s t a b l i s h an RFCOMM connect ion i f such s e r v i c e i s found .

Reception o f the∗ HSP SUBEVENT RFCOMMCONNECTION COMPLETE with s t a t u s 0∗ i n d i c a t e s i f the connect ion i s s u c c e s s f u l l y e s t a b l i s h e d .∗∗ @param bd addr∗/

void hsp ag connect (bd addr t bd addr ) ;

/∗∗∗ @br ie f Disconnect from HSP Headset∗∗ Reception o f the HSP SUBEVENT RFCOMMDISCONNECTION COMPLETE with

s t a t u s 0∗ i n d i c a t e s i f the connect ion i s s u c c e s s f u l l y r e l e a s e d .∗ @param bd addr∗/

void hsp ag d i s connec t (void ) ;

/∗∗∗ @br ie f E s t a b l i s h audio connect ion .∗∗ Reception o f the HSP SUBEVENT AUDIO CONNECTION COMPLETE with

s t a t u s 0∗ i n d i c a t e s i f the audio connect ion i s s u c c e s s f u l l y e s t a b l i s h e d .∗ @param bd addr∗/

void h s p a g e s t a b l i s h a u d i o c o n n e c t i o n (void ) ;

/∗∗

Page 207: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

206

∗ @br ie f Release audio connect ion .∗∗ Reception o f the HSP SUBEVENT AUDIO DISCONNECTION COMPLETE with

s t a t u s 0∗ i n d i c a t e s i f the connect ion i s s u c c e s s f u l l y r e l e a s e d .∗ @param bd addr∗/

void h s p a g r e l e a s e a u d i o c o n n e c t i o n (void ) ;

/∗∗∗ @br ie f Set microphone gain .∗ @param gain Val id range : [ 0 , 1 5 ]∗/

void hsp ag se t mic rophone ga in ( uint8 t gain ) ;

/∗∗∗ @br ie f Set speaker gain .∗ @param gain Val id range : [ 0 , 1 5 ]∗/

void h s p a g s e t s p e a k e r g a i n ( uint8 t gain ) ;

/∗∗∗ @br ie f S t a r t r i n g in g because o f incoming c a l l .∗/

void h s p a g s t a r t r i n g i n g (void ) ;

/∗∗∗ @br ie f Stop r in g ing ( e . g . c a l l was terminated ) .∗/

void h s p a g s t o p r i n g i n g (void ) ;

/∗∗∗ @br ie f Enable custom AT commands .∗∗ Custom commands are d i s a b l e d by d e f a u l t .∗ When enabled , custom AT commands are r e c e i v ed v ia the

HSP SUBEVENT HS COMMAND.∗ @param enab l e∗/

void hsp ag enable custom commands ( int enable ) ;

/∗∗∗ @br ie f Send a custom AT command to HSP Headset .∗∗ On HSP SUBEVENT AG INDICATION, the c l i e n t needs to respond∗ with t h i s f unc t i on wi th the r e s u l t to the custom command .∗ @param r e s u l t∗/

int h s p a g s e n d r e s u l t (char ∗ r e s u l t ) ;

31.11. HFP Hands-Free API.

/∗∗

Page 208: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

207

∗ @br ie f Create HFP Hands−Free (HF) SDP s e r v i c e record .∗ @param s e r v i c e∗ @param rfcomm channel nr∗ @param name∗ @param supo r t e d f e a t u r e s 32− b i t bitmap , see HFP HFSF ∗ va l u e s in

hfp . h∗ @param wide band speech suppor ted∗/

void h f p h f c r e a t e s d p r e c o r d ( uint8 t ∗ s e r v i c e , uint32 ts e r v i c e r e c o r d h a n d l e , int rfcomm channel nr , const char ∗ name ,uint16 t suppor t ed f ea tu r e s , int wide band speech ) ;

/∗∗∗ @br ie f Set up HFP Hands−Free (HF) dev i c e wi thou t a d d i t i o n a l

suppor ted f e a t u r e s .∗ @param rfcomm channel nr∗/

void h f p h f i n i t (uint16 t r fcomm channel nr ) ;

/∗∗∗ @br ie f Set codecs .∗ @param codecs nr∗ @param codecs∗/

void h f p h f i n i t c o d e c s ( int codecs nr , uint8 t ∗ codecs ) ;

/∗∗∗ @br ie f Set suppor ted f e a t u r e s .∗ @param suppo r t e d f e a t u r e s 32− b i t bitmap , see HFP HFSF ∗ va l u e s in

hfp . h∗/

void h f p h f i n i t s u p p o r t e d f e a t u r e s (uint32 t s u p p o r t e d f e a t u r e s ) ;

/∗∗∗ @br ie f Set HF ind i c a t o r s .∗ @param ind i c a t o r s n r∗ @param ind i c a t o r s∗/

void h f p h f i n i t h f i n d i c a t o r s ( int i n d i c a t o r s n r , uint16 t ∗i n d i c a t o r s ) ;

/∗∗∗ @br ie f Reg i s t e r c a l l b a c k f o r the HFP Hands−Free (HF) c l i e n t .∗ @param ca l l b a c k∗/

void h f p h f r e g i s t e r p a c k e t h a n d l e r (btstack packet handler tc a l l b a c k ) ;

/∗∗∗ @br ie f E s t a b l i s h RFCOMM connect ion wi th the AG with g iven

Blue too th address ,∗ and perform s e r v i c e l e v e l connect ion (SLC) agreement :∗ − exchange suppor ted f e a t u r e s

Page 209: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

208

∗ − r e t r i e v e Audio Gateway (AG) i n d i c a t o r s and t h e i r s t a t u s∗ − enab l e i n d i c a t o r s t a t u s update in the AG∗ − no t i f y the AG about i t s own a v a i l a b l e codecs , i f p o s s i b l e∗ − r e t r i e v e the AG informat ion d e s c r i b i n g the c a l l ho ld and

mu l t i pa r t y s e r v i c e s , i f p o s s i b l e∗ − r e t r i e v e which HF ind i c a t o r s are enab led on the AG, i f p o s s i b l e∗ The s t a t u s o f SLC connect ion e s t a b l i s hmen t i s repor t ed v ia∗ HFP SUBEVENT SERVICE LEVEL CONNECTION ESTABLISHED.∗∗ @param bd addr Blue too th address o f the AG∗/

void h f p h f e s t a b l i s h s e r v i c e l e v e l c o n n e c t i o n (bd addr t bd addr ) ;

/∗∗∗ @br ie f Release the RFCOMM channel and the audio connect ion

between the HF and the AG.∗ The s t a t u s o f r e l e a s i n g the SLC connect ion i s repor t ed v ia∗ HFP SUBEVENT SERVICE LEVEL CONNECTION RELEASED.∗∗ @param ac l h and l e o f the AG∗/

void h f p h f r e l e a s e s e r v i c e l e v e l c o n n e c t i o n ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗∗ @br ie f Enable s t a t u s update f o r a l l i n d i c a t o r s in the AG.∗ The s t a t u s f i e l d o f the HFP SUBEVENT COMPLETE repo r t s i f the

command was accepted .∗ The s t a t u s o f an AG ind i c a t o r i s r epor t ed v ia

HFP SUBEVENT AG INDICATOR STATUS CHANGED.∗∗ @param ac l h and l e o f the AG∗/

void h f p h f e n a b l e s t a t u s u p d a t e f o r a l l a g i n d i c a t o r s (h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f D i sab l e s t a t u s update f o r a l l i n d i c a t o r s in the AG.∗ The s t a t u s f i e l d o f the HFP SUBEVENT COMPLETE repo r t s i f the

command was accepted .∗ @param ac l h and l e o f the AG∗/

void h f p h f d i s a b l e s t a t u s u p d a t e f o r a l l a g i n d i c a t o r s (h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Enable or d i s a b l e s t a t u s update f o r the i n d i v i d u a l

i n d i c a t o r s in the AG using bitmap .∗ The s t a t u s f i e l d o f the HFP SUBEVENT COMPLETE repo r t s i f the

command was accepted .∗ The s t a t u s o f an AG ind i c a t o r i s r epor t ed v ia

HFP SUBEVENT AG INDICATOR STATUS CHANGED.∗∗ @param ac l h and l e o f the AG

Page 210: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

209

∗ @param ind i c a t o r s s t a t u s b i tmap 32− b i t bitmap , 0 − i n d i c a t o r i sd i s a b l e d , 1 − i n d i c a t o r i s enab led

∗/void h f p h f s e t s t a t u s u p d a t e f o r i n d i v i d u a l a g i n d i c a t o r s (

h c i c o n h a n d l e t ac l hand le , uint32 t i n d i c a t o r s s t a t u s b i t m a p ) ;

/∗∗∗ @br ie f Query the name o f the cu r r en t l y s e l e c t e d Network opera tor

by AG.∗∗ The name i s r e s t r i c t e d to max 16 charac t e r s . The r e s u l t i s

r epor t ed v ia∗ HFP SUBEVENTNETWORKOPERATORCHANGED subtype∗ con ta in ing network opera tor mode , format and name .∗ I f no opera tor i s s e l e c t e d , format and opera tor are omit ted .∗∗ @param ac l h and l e o f the AG∗/

void h f p h f q u e r y o p e r a t o r s e l e c t i o n ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Enable Extended Audio Gateway Error r e s u l t codes in the AG

.∗ Whenever t he r e i s an error r e l a t i n g to the f u n c t i o n a l i t y o f the

AG as a∗ r e s u l t o f AT command , the AG s h a l l send +CME ERROR. This error i s

repor t ed v ia∗ HFP SUBEVENT EXTENDED AUDIO GATEWAY ERROR, see h f p cme e r ro r t in

hfp . h∗∗ @param ac l h and l e o f the AG∗/

void h f p h f e n a b l e r e p o r t e x t e n d e d a u d i o g a t e w a y e r r o r r e s u l t c o d e (h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f D i sab l e Extended Audio Gateway Error r e s u l t codes in the

AG.∗∗ @param ac l h and l e o f the AG∗/void h f p h f d i s a b l e r e p o r t e x t e n d e d a u d i o g a t e w a y e r r o r r e s u l t c o d e

( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f E s t a b l i s h audio connect ion .∗ The s t a t u s o f audio connect ion e s t a b l i s hmen t i s repor t ed v ia∗ HFP SUBEVENT AUDIO CONNECTION ESTABLISHED.∗ @param ac l h and l e o f the AG∗/

void h f p h f e s t a b l i s h a u d i o c o n n e c t i o n ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Release audio connect ion .

Page 211: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

210

∗ The s t a t u s o f r e l e a s i n g o f the audio connect ion i s repor t ed v ia∗ HFP SUBEVENT AUDIO CONNECTION RELEASED.∗∗ @param ac l h and l e o f the AG∗/

void h f p h f r e l e a s e a u d i o c o n n e c t i o n ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Answer incoming c a l l .∗ @param ac l h and l e o f the AG∗/

void h f p h f a n s w e r i n c o m i n g c a l l ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Re jec t incoming c a l l .∗ @param ac l h and l e o f the AG∗/

void h f p h f r e j e c t i n c o m i n g c a l l ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Release a l l h e l d c a l l s or s e t s User Determined User Busy (

UDUB) fo r a wa i t ing c a l l .∗ @param ac l h and l e o f the AG∗/

void h f p h f u s e r b u s y ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Release a l l a c t i v e c a l l s ( i f any e x i s t ) and accep t s the

o ther ( he l d or wa i t ing ) c a l l .∗ @param ac l h and l e o f the AG∗/

void h f p h f e n d a c t i v e a n d a c c e p t o t h e r ( h c i c o n h a n d l e t a c l h a n d l e );

/∗∗∗ @br ie f Place a l l a c t i v e c a l l s ( i f any e x i s t ) on ho ld and accep t s

the o ther ( he l d or wa i t ing ) c a l l .∗ @param ac l h and l e o f the AG∗/

void h f p h f s w a p c a l l s ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Add a he ld c a l l to the conver sa t i on .∗ @param ac l h and l e o f the AG∗/

void h f p h f j o i n h e l d c a l l ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Connect the two c a l l s and d i s connec t s the s u b s c r i b e r from

both c a l l s ( E x p l i c i t Ca l lTransfer ) .∗ @param ac l h and l e o f the AG∗/

void h f p h f c o n n e c t c a l l s ( h c i c o n h a n d l e t a c l h a n d l e ) ;

Page 212: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

211

/∗∗∗ @br ie f Terminate an incoming or an outgo ing c a l l .∗ HFP SUBEVENT CALL TERMINATED i s sen t upon c a l l t e rminat ion .∗ @param ac l h and l e o f the AG∗/

void h f p h f t e r m i n a t e c a l l ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f I n i t i a t e ou tgo ing vo i c e c a l l by p rov i d ing the d e s t i n a t i o n

phone number to the AG.∗ @param ac l h and l e o f the AG∗ @param number∗/

void h fp h f d ia l number ( h c i c o n h a n d l e t ac l hand l e , char ∗ number ) ;

/∗∗∗ @br ie f I n i t i a t e ou tgo ing vo i c e c a l l us ing the memory d i a l i n g

f e a t u r e o f the AG.∗ @param ac l h and l e o f the AG∗ @param memory id∗/

void hfp hf d ia l memory ( h c i c o n h a n d l e t ac l hand l e , int memory id ) ;

/∗∗∗ @br ie f I n i t i a t e ou tgo ing vo i c e c a l l by r e c a l l i n g the l a s t number

d i a l e d by the AG.∗ @param ac l h and l e o f the AG∗/

void h f p h f r e d i a l l a s t n u m b e r ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Enable the C a l l Waiting n o t i f i c a t i o n func t i on in the

AG.∗ The AG s h a l l send the corresponding r e s u l t code to the HF

whenever∗ an incoming c a l l i s wa i t ing during an ongoing c a l l . In t ha t event

,∗ the HFP SUBEVENT CALL WAITING NOTIFICATION i s emi t ted .∗∗ @param ac l h and l e o f the AG∗/

void h f p h f a c t i v a t e c a l l w a i t i n g n o t i f i c a t i o n ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗ @br ie f D i sab l e the C a l l Waiting n o t i f i c a t i o n func t i on in

the AG.∗ @param ac l h and l e o f the AG∗/

void h f p h f d e a c t i v a t e c a l l w a i t i n g n o t i f i c a t i o n ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗

Page 213: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

212

∗ @br ie f Enable the C a l l i n g Line I d e n t i f i c a t i o n n o t i f i c a t i o nfunc t i on in the AG.

∗ The AG s h a l l i s s u e the corresponding r e s u l t code j u s t a f t e r everyRING ind i ca t i on ,

∗ when the HF i s a l e r t e d in an incoming c a l l . In t ha t event ,∗ the HFP SUBEVENT CALLING LINE INDETIFICATION NOTIFICATION i s

emi t ted .∗ @param ac l h and l e o f the AG∗/

void h f p h f a c t i v a t e c a l l i n g l i n e n o t i f i c a t i o n ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗ @br ie f D i sab l e the C a l l i n g Line I d e n t i f i c a t i o n n o t i f i c a t i o n

func t i on in the AG.∗ @param ac l h and l e o f the AG∗/

void h f p h f d e a c t i v a t e c a l l i n g l i n e n o t i f i c a t i o n ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗ @br ie f Ac t i va t e echo cance l i ng and no i se reduc t ion in the AG. By

de f au l t ,∗ i f the AG suppor t s i t s own embedded echo cance l i ng and/or no i se

reduc t ion∗ f unc t ions , i t s h a l l have them ac t i v a t e d u n t i l t h i s f unc t i on i s

c a l l e d .∗ I f the AG does not suppor t any echo cance l i ng and no i se reduc t ion

func t ions ,∗ i t s h a l l respond with the ERROR ind i c a t o r (TODO)∗ @param ac l h and l e o f the AG∗/

void h f p h f a c t i v a t e e c h o c a n c e l i n g a n d n o i s e r e d u c t i o n (h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Deac t i va te echo cance l i ng and no i se reduc t ion in the AG.∗/

void h f p h f d e a c t i v a t e e c h o c a n c e l i n g a n d n o i s e r e d u c t i o n (h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Ac t i va t e vo i c e r e co gn i t i on func t i on .∗ @param ac l h and l e o f the AG∗/

void h f p h f a c t i v a t e v o i c e r e c o g n i t i o n n o t i f i c a t i o n ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗ @br ie f Dec t i va t e vo i c e r e co gn i t i on func t i on .∗ @param ac l h and l e o f the AG∗/

Page 214: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

213

void h f p h f d e a c t i v a t e v o i c e r e c o g n i t i o n n o t i f i c a t i o n (h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Set microphone gain .∗ @param ac l h and l e o f the AG∗ @param gain Val id range : [ 0 , 1 5 ]∗/

void h f p h f s e t m i c r o p h o n e g a i n ( h c i c o n h a n d l e t ac l hand le , intgain ) ;

/∗∗ @br ie f Set speaker gain .∗ @param ac l h and l e o f the AG∗ @param gain Val id range : [ 0 , 1 5 ]∗/

void h f p h f s e t s p e a k e r g a i n ( h c i c o n h a n d l e t ac l hand le , int gain ) ;

/∗∗ @br ie f I n s t r u c t the AG to transmi t a DTMF code .∗ @param ac l h and l e o f the AG∗ @param dtmf code∗/

void h fp h f s end dtmf code ( h c i c o n h a n d l e t ac l hand l e , char code ) ;

/∗∗ @br ie f Read numbers from the AG fo r the purpose o f c r ea t i n g∗ a unique vo i c e tag and s t o r i n g the number and i t s l i n k e d vo i ce∗ tag in the H F s memory .∗ The number i s repor t ed v ia HFP SUBEVENT NUMBER FOR VOICE TAG.∗ @param ac l h and l e o f the AG∗/

void h f p h f r e q u e s t p h o n e n u m b e r f o r v o i c e t a g ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗ @br ie f Query the l i s t o f curren t c a l l s in AG.∗ The r e s u l t i s r e c e i v ed v ia HFP SUBEVENT ENHANCED CALL STATUS.∗ @param ac l h and l e o f the AG∗/

void h f p h f q u e r y c u r r e n t c a l l s t a t u s ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Release a c a l l wi th index in the AG.∗ @param ac l h and l e o f the AG∗ @param index∗/

void h f p h f r e l e a s e c a l l w i t h i n d e x ( h c i c o n h a n d l e t ac l hand le , intindex ) ;

/∗∗ @br ie f Place a l l p a r t i e s o f a mu l t i pa r t y c a l l on ho ld wi th the∗ excep t i on o f the s p e c i f i e d c a l l .∗ @param ac l h and l e o f the AG

Page 215: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

214

∗ @param index∗/

void h f p h f p r i v a t e c o n s u l t a t i o n w i t h c a l l ( h c i c o n h a n d l e tac l hand le , int index ) ;

/∗∗ @br ie f Query the s t a t u s o f the R e s p o n s e and H o l d s t a t e o f

the AG.∗ The r e s u l t i s r epor t ed v ia HFP SUBEVENT RESPONSE AND HOLD STATUS.∗ @param ac l h and l e o f the AG∗/

void h f p h f r r h q u e r y s t a t u s ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Put an incoming c a l l on ho ld in the AG.∗ @param ac l h and l e o f the AG∗/

void h f p h f r r h h o l d c a l l ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Accept he l d incoming c a l l in the AG.∗ @param ac l h and l e o f the AG∗/

void h f p h f r r h a c c e p t h e l d c a l l ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Re jec t he l d incoming c a l l in the AG.∗ @param ac l h and l e o f the AG∗/

void h f p h f r r h r e j e c t h e l d c a l l ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Query the AG su b s c r i b e r number .∗ The r e s u l t i s r epor t ed v ia

HFP SUBEVENT SUBSCRIBER NUMBER INFORMATION.∗ @param ac l h and l e o f the AG∗/

void h fp h f que ry subsc r ibe r number ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗ @br ie f Set HF ind i c a t o r .∗ @param ac l h and l e o f the AG∗ @param assigned number∗ @param va lue∗/

void h f p h f s e t h f i n d i c a t o r ( h c i c o n h a n d l e t ac l hand le , intassigned number , int value ) ;

/∗∗ @br ie f Tests i f in−band r ing tone i s a c t i v e on AG ( r e qu i r e s SLC)∗ @aram ac l h and l e r o f the AG∗/

int h f p h f i n b a n d r i n g t o n e a c t i v e ( h c i c o n h a n d l e t a c l h a n d l e ) ;

Page 216: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

215

31.12. HFP Audio Gateway API.

typedef struct {uint8 t type ;const char ∗ number ;

} hfp phone number t ;

/∗∗∗ @br ie f Create HFP Audio Gateway (AG) SDP s e r v i c e record .∗ @param s e r v i c e∗ @param rfcomm channel nr∗ @param name∗ @param a b i l i t y t o r e j e c t c a l l∗ @param supo r t e d f e a t u r e s 32− b i t bitmap , see HFP AGSF ∗ va l u e s in

hfp . h∗ @param wide band speech suppor ted∗/

void h f p a g c r e a t e s d p r e c o r d ( uint8 t ∗ s e r v i c e , uint32 ts e r v i c e r e c o r d h a n d l e , int rfcomm channel nr , const char ∗ name ,uint8 t a b i l i t y t o r e j e c t c a l l , uint16 t suppor t ed f ea tu r e s ,

int wide band speech ) ;

/∗∗∗ @br ie f Set up HFP Audio Gateway (AG) dev i c e wi thou t a d d i t i o n a l

suppor ted f e a t u r e s .∗ @param rfcomm channel nr∗/

void h f p a g i n i t (uint16 t r fcomm channel nr ) ;

/∗∗∗ @br ie f Set codecs .∗ @param codecs nr∗ @param codecs∗/

void h f p a g i n i t c o d e c s ( int codecs nr , uint8 t ∗ codecs ) ;

/∗∗∗ @br ie f Set suppor ted f e a t u r e s .∗ @param suppo r t e d f e a t u r e s 32− b i t bitmap , see HFP AGSF ∗ va l u e s in

hfp . h∗/

void h f p a g i n i t s u p p o r t e d f e a t u r e s (uint32 t s u p p o r t e d f e a t u r e s ) ;

/∗∗∗ @br ie f Set AG ind i c a t o r s .∗ @param ind i c a t o r s n r∗ @param ind i c a t o r s∗/

void h f p a g i n i t a g i n d i c a t o r s ( int a g i n d i c a t o r s n r ,h f p a g i n d i c a t o r t ∗ a g i n d i c a t o r s ) ;

/∗∗∗ @br ie f Set HF ind i c a t o r s .∗ @param ind i c a t o r s n r

Page 217: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

216

∗ @param ind i c a t o r s∗/

void h f p a g i n i t h f i n d i c a t o r s ( int h f i n d i c a t o r s n r ,h f p g e n e r i c s t a t u s i n d i c a t o r t ∗ h f i n d i c a t o r s ) ;

/∗∗∗ @br ie f Set Ca l l Hold s e r v i c e s .∗ @param ind i c a t o r s n r∗ @param ind i c a t o r s∗/

void h f p a g i n i t c a l l h o l d s e r v i c e s ( int c a l l h o l d s e r v i c e s n r , constchar ∗ c a l l h o l d s e r v i c e s [ ] ) ;

/∗∗∗ @br ie f Reg i s t e r c a l l b a c k f o r the HFP Audio Gateway (AG) c l i e n t .∗ @param ca l l b a c k∗/

void h f p a g r e g i s t e r p a c k e t h a n d l e r (btstack packet handler tc a l l b a c k ) ;

/∗∗∗ @br ie f Enable in−band r ing tone .∗ @param us e i n band r i n g t on e∗/

void h f p a g s e t u s e i n b a n d r i n g t o n e ( int u s e i n b a n d r i n g t o n e ) ;

// ac t i on s used by l o c a l d ev i c e / user

/∗∗∗ @br ie f E s t a b l i s h RFCOMM connection , and perform s e r v i c e l e v e l

connect ion agreement :∗ − exchange o f suppor ted f e a t u r e s∗ − r epor t Audio Gateway (AG) i n d i c a t o r s and t h e i r s t a t u s∗ − enab l e i n d i c a t o r s t a t u s update in the AG∗ − accept the in format ion about a v a i l a b l e codecs in the Hands−Free

(HF) , i f s en t∗ − r epor t own in format ion d e s c r i b i n g the c a l l ho ld and mu l t i pa r t y

s e r v i c e s , i f p o s s i b l e∗ − r epor t which HF ind i c a t o r s are enab led on the AG, i f p o s s i b l e∗ The s t a t u s o f SLC connect ion e s t a b l i s hmen t i s repor t ed v ia∗ HFP SUBEVENT SERVICE LEVEL CONNECTION ESTABLISHED.∗∗ @param bd addr Blue too th address o f the HF∗/

void h f p a g e s t a b l i s h s e r v i c e l e v e l c o n n e c t i o n (bd addr t bd addr ) ;

/∗∗∗ @br ie f Release the RFCOMM channel and the audio connect ion

between the HF and the AG.∗ I f the audio connect ion e x i s t s , i t w i l l be r e l e a s e d .∗ The s t a t u s o f r e l e a s i n g the SLC connect ion i s repor t ed v ia∗ HFP SUBEVENT SERVICE LEVEL CONNECTION RELEASED.

Page 218: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

217

∗∗ @param bd addr Blue too th address o f the HF∗/

void h f p a g r e l e a s e s e r v i c e l e v e l c o n n e c t i o n ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗∗ @br ie f E s t a b l i s h audio connect ion .∗ The s t a t u s o f Audio connect ion e s t a b l i s hmen t i s repor t ed v ia i s

repor t ed v ia∗ HSP SUBEVENT AUDIO CONNECTION COMPLETE.∗ @param bd addr Blue too th address o f the HF∗/

void h f p a g e s t a b l i s h a u d i o c o n n e c t i o n ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Release audio connect ion .∗ The s t a t u s o f r e l e a s i n g the Audio connect ion i s repor t ed v ia i s

repor t ed v ia∗ HSP SUBEVENT AUDIO DISCONNECTION COMPLETE.∗ @param bd addr Blue too th address o f the HF∗/

void h f p a g r e l e a s e a u d i o c o n n e c t i o n ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Put the curren t c a l l on hold , i f i t e x i s t s , and accep t

incoming c a l l .∗/

void h f p a g a n s w e r i n c o m i n g c a l l (void ) ;

/∗∗∗ @br ie f Join he l d c a l l wi th a c t i v e c a l l .∗/

void h f p a g j o i n h e l d c a l l (void ) ;

/∗∗∗ @br ie f Re jec t incoming c a l l , i f e x i s t s , or terminate a c t i v e c a l l .∗/

void h f p a g t e r m i n a t e c a l l (void ) ;

/∗∗ @br ie f Put incoming c a l l on ho ld .∗/

void h f p a g h o l d i n c o m i n g c a l l (void ) ;

/∗∗ @br ie f Accept the he l d incoming c a l l .∗/

void h f p a g a c c e p t h e l d i n c o m i n g c a l l (void ) ;

/∗∗ @br ie f Re jec t the he l d incoming c a l l .∗/

void h f p a g r e j e c t h e l d i n c o m i n g c a l l (void ) ;

Page 219: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

218

/∗∗ @br ie f Set microphone gain .∗ @param bd addr Blue too th address o f the HF∗ @param gain Val id range : [ 0 , 1 5 ]∗/

void h fp ag s e t mic rophone ga in ( h c i c o n h a n d l e t ac l hand le , intgain ) ;

/∗∗ @br ie f Set speaker gain .∗ @param bd addr Blue too th address o f the HF∗ @param gain Val id range : [ 0 , 1 5 ]∗/

void h f p a g s e t s p e a k e r g a i n ( h c i c o n h a n d l e t ac l hand le , int gain ) ;

/∗∗ @br ie f Set b a t t e r y l e v e l .∗ @param l e v e l Val id range : [ 0 , 5 ]∗/

void h f p a g s e t b a t t e r y l e v e l ( int l e v e l ) ;

/∗∗ @br ie f Clear l a s t d i a l e d number .∗/

void h f p a g c l e a r l a s t d i a l e d n u m b e r (void ) ;

/∗∗ @br ie f No t i f y the HF tha t an incoming c a l l i s wa i t ing∗ during an ongoing c a l l . The n o t i f i c a t i o n w i l l be sen t on ly i f the

HF has∗ has p r e v i o u s l y enab led the ”Ca l l Waiting n o t i f i c a t i o n ” in the AG.∗ @param bd addr Blue too th address o f the HF∗/

void h f p a g n o t i f y i n c o m i n g c a l l w a i t i n g ( h c i c o n h a n d l e t a c l h a n d l e) ;

// Voice Recogni t ion

/∗∗ @br ie f Ac t i va t e vo i c e r e co gn i t i on .∗ @param bd addr Blue too th address o f the HF∗ @param a c t i v a t e∗/

void h f p a g a c t i v a t e v o i c e r e c o g n i t i o n ( h c i c o n h a n d l e t ac l hand le ,int a c t i v a t e ) ;

/∗∗ @br ie f Send a phone number back to the HF.∗ @param bd addr Blue too th address o f the HF∗ @param phone number∗/

void h fp ag send phone number f o r vo i c e tag ( h c i c o n h a n d l e tac l hand le , const char ∗ phone number ) ;

Page 220: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

219

/∗∗ @br ie f Re jec t sending a phone number to the HF.∗ @param bd addr Blue too th address o f the HF∗/

void h f p a g r e j e c t p h o n e n u m b e r f o r v o i c e t a g ( h c i c o n h a n d l e ta c l h a n d l e ) ;

/∗∗∗ @br ie f Store phone number wi th i n i t i a t e d c a l l .∗ @param type∗ @param number∗/

void h f p a g s e t c l i p ( uint8 t type , const char ∗ number ) ;

// Ce l l u l a r Actions

/∗∗∗ @br ie f Pass the accep t incoming c a l l event to the AG.∗/

void h f p a g i n c o m i n g c a l l (void ) ;

/∗∗∗ @br ie f Pass the r e j e c t ou tgo ing c a l l event to the AG.∗/

void h f p a g o u t g o i n g c a l l r e j e c t e d (void ) ;

/∗∗∗ @br ie f Pass the accep t outgo ing c a l l event to the AG.∗/

void h f p a g o u t g o i n g c a l l a c c e p t e d (void ) ;

/∗∗∗ @br ie f Pass the outgo ing c a l l r i n g in g event to the AG.∗/

void h f p a g o u t g o i n g c a l l r i n g i n g (void ) ;

/∗∗∗ @br ie f Pass the outgo ing c a l l e s t a b l i s h e d event to the AG.∗/

void h f p a g o u t g o i n g c a l l e s t a b l i s h e d (void ) ;

/∗∗∗ @br ie f Pass the c a l l droped event to the AG.∗/

void h f p a g c a l l d r o p p e d (void ) ;

/∗∗ @br ie f Set network r e g i s t r a t i o n s t a t u s .∗ @param s t a t u s 0 − not r e g i s t e r e d , 1 − r e g i s t e r e d∗/

void h f p a g s e t r e g i s t r a t i o n s t a t u s ( int s t a t u s ) ;

Page 221: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

220

/∗∗ @br ie f Set network s i g n a l s t r en g t h .∗ @param s t r en g t h [0−5]∗/

void h f p a g s e t s i g n a l s t r e n g t h ( int s t r ength ) ;

/∗∗ @br ie f Set roaming s t a t u s .∗ @param s t a t u s 0 − no roaming , 1 − roaming a c t i v e∗/

void h f p a g s e t r o a m i n g s t a t u s ( int s t a t u s ) ;

/∗∗ @br ie f Set s u b c r i b e r number information , e . g . the phone number∗ @param numbers∗ @param numbers count∗/

void h fp ag s e t subc r i b e r number in f o rmat i o n ( hfp phone number t ∗numbers , int numbers count ) ;

/∗∗ @br ie f Ca l l ed by c e l l u l a r un i t a f t e r a DTMF code was t ransmi t ted ,

so t ha t the next one can be emi t ted .∗ @param bd addr Blue too th address o f the HF∗/

void hfp ag send dtmf code done ( h c i c o n h a n d l e t a c l h a n d l e ) ;

/∗∗∗ @br ie f Report Extended Audio Gateway Error r e s u l t codes in the AG

.∗ Whenever t he r e i s an error r e l a t i n g to the f u n c t i o n a l i t y o f the

AG as a∗ r e s u l t o f AT command , the AG s h a l l send +CME ERROR:∗ − +CME ERROR: 0 − AG f a i l u r e∗ − +CME ERROR: 1 − no connect ion to phone∗ − +CME ERROR: 3 − opera t ion not a l l owed∗ − +CME ERROR: 4 − opera t ion not supported∗ − +CME ERROR: 5 − PH−SIM PIN requ i r ed∗ − +CME ERROR: 10 − SIM not i n s e r t e d∗ − +CME ERROR: 11 − SIM PIN requ i r ed∗ − +CME ERROR: 12 − SIM PUK requ i r ed∗ − +CME ERROR: 13 − SIM f a i l u r e∗ − +CME ERROR: 14 − SIM busy∗ − +CME ERROR: 16 − i n c o r r e c t password∗ − +CME ERROR: 17 − SIM PIN2 requ i r ed∗ − +CME ERROR: 18 − SIM PUK2 requ i r ed∗ − +CME ERROR: 20 − memory f u l l∗ − +CME ERROR: 21 − i n v a l i d index∗ − +CME ERROR: 23 − memory f a i l u r e∗ − +CME ERROR: 24 − t e x t s t r i n g too long∗ − +CME ERROR: 25 − i n v a l i d charac t e r s in t e x t s t r i n g∗ − +CME ERROR: 26 − d i a l s t r i n g too long∗ − +CME ERROR: 27 − i n v a l i d charac t e r s in d i a l s t r i n g∗ − +CME ERROR: 30 − no network s e r v i c e

Page 222: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

221

∗ − +CME ERROR: 31 − network Timeout .∗ − +CME ERROR: 32 − network not a l l owed Emergency c a l l s on ly∗∗ @param bd addr Blue too th address o f the HF∗ @param error∗/

void h f p a g r e p o r t e x t e n d e d a u d i o g a t e w a y e r r o r r e s u l t c o d e (h c i c o n h a n d l e t ac l hand le , h f p c m e e r r o r t e r r o r ) ;

31.13. PAN API.

/∗∗∗ @br ie f Creates SDP record f o r PANU BNEP s e r v i c e in prov ided empty

b u f f e r .∗ @note Make sure the b u f f e r i s b i g enough .∗∗ @param s e r v i c e i s an empty b u f f e r to s t o r e s e r v i c e record∗ @param s e r v i c e r e c o r d hand l e f o r new s e r v i c e∗ @param ne twork packe t t ype s array o f t ype s terminated by a 0x0000

entry∗ @param name i f NULL, the d e f a u l t s e r v i c e name w i l l be as s i gned∗ @param de s c r i p t i o n i f NULL, the d e f a u l t s e r v i c e d e s c r i p t i o n w i l l

be as s i gned∗ @param s e c u r i t y d e s c∗/

void pan crea te panu sdp reco rd ( uint8 t ∗ s e r v i c e , uint32 ts e r v i c e r e c o r d h a n d l e , uint16 t ∗ network packet types , constchar ∗name ,const char ∗ d e s c r i p t i o n , s e c u r i t y d e s c r i p t i o n t s e c u r i t y d e s c ) ;

/∗∗∗ @br ie f Creates SDP record f o r GN BNEP s e r v i c e in prov ided empty

b u f f e r .∗ @note Make sure the b u f f e r i s b i g enough .∗∗ @param s e r v i c e i s an empty b u f f e r to s t o r e s e r v i c e record∗ @param s e r v i c e r e c o r d hand l e f o r new s e r v i c e∗ @param ne twork packe t t ype s array o f t ype s terminated by a 0x0000

entry∗ @param name i f NULL, the d e f a u l t s e r v i c e name w i l l be as s i gned∗ @param de s c r i p t i o n i f NULL, the d e f a u l t s e r v i c e d e s c r i p t i o n w i l l

be as s i gned∗ @param s e c u r i t y d e s c∗ @param IPv4Subnet i s o p t i ona l subnet d e f i n i t i o n , e . g .

”10 .0 .0 .0/8”∗ @param IPv6Subnet i s o p t i ona l subnet d e f i n i t i o n g iven in the

s tandard IETF format wi th the a b s o l u t e a t t r i b u t e IDs∗/

void pan c r ea t e gn sdp r e co rd ( uint8 t ∗ s e r v i c e , uint32 ts e r v i c e r e c o r d h a n d l e , uint16 t ∗ network packet types , constchar ∗name ,const char ∗ d e s c r i p t i o n , s e c u r i t y d e s c r i p t i o n t s e c u r i t y d e s c ,

const char ∗ IPv4Subnet ,

Page 223: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

222

const char ∗ IPv6Subnet ) ;

/∗∗∗ @br ie f Creates SDP record f o r NAP BNEP s e r v i c e in prov ided empty

b u f f e r .∗ @note Make sure the b u f f e r i s b i g enough .∗∗ @param s e r v i c e i s an empty b u f f e r to s t o r e s e r v i c e record∗ @param s e r v i c e r e c o r d hand l e f o r new s e r v i c e∗ @param name i f NULL, the d e f a u l t s e r v i c e name w i l l be as s i gned∗ @param ne twork packe t t ype s array o f t ype s terminated by a 0x0000

entry∗ @param de s c r i p t i o n i f NULL, the d e f a u l t s e r v i c e d e s c r i p t i o n w i l l

be as s i gned∗ @param s e c u r i t y d e s c∗ @param ne t a c c e s s t y p e type o f a v a i l a b l e network acces s∗ @param max ne t acce s s ra t e based on n e t a c c e s s t y p e measured in

by t e / s∗ @param IPv4Subnet i s o p t i ona l subnet d e f i n i t i o n , e . g .

”10 .0 .0 .0/8”∗ @param IPv6Subnet i s o p t i ona l subnet d e f i n i t i o n g iven in the

s tandard IETF format wi th the a b s o l u t e a t t r i b u t e IDs∗/

void pan c r ea t e nap sdp re co rd ( uint8 t ∗ s e r v i c e , uint32 ts e r v i c e r e c o r d h a n d l e , uint16 t ∗ network packet types , constchar ∗name ,const char ∗ d e s c r i p t i o n , s e c u r i t y d e s c r i p t i o n t s e c u r i t y d e s c ,

n e t a c c e s s t y p e t ne t a c c e s s ty pe ,uint32 t max net acce s s ra t e , const char ∗ IPv4Subnet , const char

∗ IPv6Subnet ) ;

31.14. RFCOMM API.

/∗∗∗ @br ie f Set up RFCOMM.∗/

void r f comm init (void ) ;

/∗∗∗ @br ie f Set s e c u r i t y l e v e l r e qu i r ed f o r incoming connect ions , need

to be c a l l e d b e f o r e r e g i s t e r i n g s e r v i c e s .∗/

void r f c o m m s e t r e q u i r e d s e c u r i t y l e v e l ( g a p s e c u r i t y l e v e l ts e c u r i t y l e v e l ) ;

/∗∗ @br ie f Create RFCOMM connect ion to a g iven s e r v e r channel on a

remote de i v ce .∗ This channel w i l l a u t oma t i c a l l y prov ide enough c r e d i t s to the

remote s i d e .∗ @param addr∗ @param se r v e r channe l∗ @param ou t c i d

Page 224: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

223

∗ @resu l t s t a t u s∗/

uint8 t r f comm create channe l (btstack packet handler tpacket handler , bd addr t addr , uint8 t s e rve r channe l , uint16 t∗ o u t c i d ) ;

/∗∗ @br ie f Create RFCOMM connect ion to a g iven s e r v e r channel on a

remote de i v ce .∗ This channel w i l l use e x p l i c i t c r e d i t management . During channel

e s tab l i shment , an i n i t i a l amount o f c r e d i t s i s prov ided .∗ @param addr∗ @param se r v e r channe l∗ @param i n i t i a l c r e d i t s∗ @param ou t c i d∗ @resu l t s t a t u s∗/

uint8 t r f c o m m c r e a t e c h a n n e l w i t h i n i t i a l c r e d i t s (btstack packet handler t packet handler , bd addr t addr , uint8 t

s e rve r channe l , uint8 t i n i t i a l c r e d i t s , uint16 t ∗ o u t c i d ) ;

/∗∗∗ @br ie f Disconnects RFCOMM channel wi th g iven i d e n t i f i e r .∗/

void r fcomm disconnect (uint16 t rfcomm cid ) ;

/∗∗∗ @br ie f Reg i s t e r s RFCOMM se r v i c e f o r a s e r v e r channel and a

maximum frame s i z e , and a s s i gn s a packe t hand ler .∗ This channel p rov ide s c r e d i t s au t oma t i c a l l y to the remote s i d e −>

no f l ow con t r o l∗ @param packe t hand ler f o r a l l channe ls o f t h i s s e r v i c e∗ @param channel∗ @param max frame size∗/

uint8 t r f c o m m r e g i s t e r s e r v i c e (btstack packet handler tpacket handler , uint8 t channel , uint16 t max frame s ize ) ;

/∗∗∗ @br ie f Reg i s t e r s RFCOMM se r v i c e f o r a s e r v e r channel and a

maximum frame s i z e , and a s s i gn s a packe t hand ler .∗ This channel w i l l use e x p l i c i t c r e d i t management . During channel

e s tab l i shment , an i n i t i a l amount o f c r e d i t s i s prov ided .∗ @param packe t hand ler f o r a l l channe ls o f t h i s s e r v i c e∗ @param channel∗ @param max frame size∗ @param i n i t i a l c r e d i t s∗/

uint8 t r f c o m m r e g i s t e r s e r v i c e w i t h i n i t i a l c r e d i t s (btstack packet handler t packet handler , uint8 t channel ,uint16 t max frame size , uint8 t i n i t i a l c r e d i t s ) ;

/∗∗∗ @br ie f Unreg i s t e r RFCOMM se r v i c e .

Page 225: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

224

∗/void r f c o m m u n r e g i s t e r s e r v i c e ( uint8 t s e r v i c e c h a n n e l ) ;

/∗∗∗ @br ie f Accepts incoming RFCOMM connect ion .∗/

void r fcomm accept connect ion (uint16 t rfcomm cid ) ;

/∗∗∗ @br ie f Deny incoming RFCOMM connect ion .∗/

void r f comm dec l ine connect ion (uint16 t rfcomm cid ) ;

/∗∗∗ @br ie f Grant more incoming c r e d i t s to the remote s i d e f o r the

g iven RFCOMM channel i d e n t i f i e r .∗/

void r f comm grant c r ed i t s (uint16 t rfcomm cid , uint8 t c r e d i t s ) ;

/∗∗∗ @br ie f Checks i f RFCOMM can send packe t .∗ @param rfcomm cid∗ @resu l t != 0 i f can send now∗/

int rfcomm can send packet now (uint16 t rfcomm cid ) ;

/∗∗∗ @br ie f Request emiss ion o f RFCOMMEVENTCAN SENDNOW as soon as

p o s s i b l e∗ @note RFCOMMEVENTCAN SENDNOW might be emi t ted during c a l l to

t h i s f unc t i on∗ so packe t hand ler shou ld be ready to handle i t∗ @param rfcomm cid∗/

void r fcomm request can send now event (uint16 t rfcomm cid ) ;

/∗∗∗ @br ie f Sends RFCOMM data packe t to the RFCOMM channel wi th g iven

i d e n t i f i e r .∗ @param rfcomm cid∗/

int rfcomm send (uint16 t rfcomm cid , uint8 t ∗data , uint16 t l en ) ;

/∗∗∗ @br ie f Sends Local Line Status , see LINE STATUS . .∗ @param rfcomm cid∗ @param l i n e s t a t u s∗/

int r f c o m m s e n d l o c a l l i n e s t a t u s (uint16 t rfcomm cid , uint8 tl i n e s t a t u s ) ;

/∗∗∗ @br ie f Send l o c a l modem s t a t u s . see MODEM STAUS . .∗ @param rfcomm cid

Page 226: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

225

∗ @param modem status∗/

int rfcomm send modem status (uint16 t rfcomm cid , uint8 tmodem status ) ;

/∗∗∗ @br ie f Conf igure remote por t∗ @param rfcomm cid∗ @param baud ra te∗ @param d a t a b i t s∗ @param s t o p b i t s∗ @param pa r i t y∗ @param f l ow c on t r o l∗/

int r f comm send por t con f i gura t i on (uint16 t rfcomm cid , rpn baud tbaud rate , r p n d a t a b i t s t da ta b i t s , r p n s t o p b i t s t s t o p b i t s ,

r p n p a r i t y t par i ty , r p n f l o w c o n t r o l t f l o w c o n t r o l ) ;

/∗∗∗ @br ie f Query remote por t∗ @param rfcomm cid∗/

int r f comm query por t con f i gura t i on (uint16 t rfcomm cid ) ;

/∗∗∗ @br ie f Query max frame s i z e∗ @param rfcomm cid∗/

uint16 t r fcomm get max frame s ize (uint16 t rfcomm cid ) ;

/∗∗∗ @br ie f Allow to c r ea t e RFCOMM packe t in outgo ing b u f f e r .∗ i f ( r fcomm can send packet now ( c id ) ){∗ r f c omm re s e r v e pack e t bu f f e r ( ) ;∗ u i n t 8 t ∗ b u f f e r = r f comm ge t ou t go ing bu f f e r ( ) ;∗ u i n t 1 6 t b u f f e r s i z e = rfcomm get max frame size ( c id ) ;∗ // . . se tup data in b u f f e r wi th l en∗ rfcomm send prepared ( cid , l en )∗ }∗/

int r f c omm re s e rve packe t bu f f e r (void ) ;uint8 t ∗ r f comm get outgo ing bu f f e r (void ) ;int rfcomm send prepared (uint16 t rfcomm cid , uint16 t l en ) ;void r f c o m m r e l e a s e p a c k e t b u f f e r (void ) ;

/∗∗∗ @br ie f Enable L2CAP ERTM mode f o r RFCOMM. reque s t c a l l b a c k i s

used to prov ide ERTM bu f f e r . r e l e a s e d c a l l b a c k re turns b u f f e r∗∗ @note on r e q u e s t c a l l b a c k , the app must s e t the er tm conf ig ,

bu f f e r , s i z e f i e l d s to enab l e ERTM for the curren t connect ion∗ @note i f b u f f e r i s not se t , BASIC mode w i l l be used in s t ead∗

Page 227: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

226

∗ @note r e l e a s e d c a l l b a c k prov ide s er tm id from e a r l i e r r e que s t tomatch r e que s t and r e l e a s e

∗∗ @param r e q u e s t c a l l b a c k∗ @param r e l e a s e d c a l l b a c k∗/

void r fcomm enable l2cap ertm (void r e q u e s t c a l l b a c k (r fcomm ertm request t ∗ r eque s t ) , void r e l e a s e d c a l l b a c k (uint16 t ertm id ) ) ;

31.15. SDP Client API.

typedef struct d e s t a t e {uint8 t in state GET DE HEADER LENGTH ;uint32 t addon header bytes ;uint32 t d e s i z e ;uint32 t d e o f f s e t ;

} d e s t a t e t ;

void d e s t a t e i n i t ( d e s t a t e t ∗ s t a t e ) ;int d e s t a t e s i z e ( uint8 t eventByte , d e s t a t e t ∗ d e s t a t e ) ;

/∗∗∗ @br ie f Checks i f the SDP Cl i en t i s ready∗ @return 1 when no query i s a c t i v e∗/

int s d p c l i e n t r e a d y (void ) ;

/∗∗∗ @br ie f Queries the SDP s e r v i c e o f the remote dev i c e g iven a

s e r v i c e search pa t t e rn and a l i s t o f a t t r i b u t e IDs .∗ The remote data i s handled by the SDP parser . The SDP parser

d e l i v e r s a t t r i b u t e va l u e s and done event v ia the c a l l b a c k .∗ @param ca l l b a c k f o r a t t r i b u t e s va l u e s and done event∗ @param remote address∗ @param d e s s e r v i c e s e a r c h p a t t e r n∗ @param d e s a t t r i b u t e i d l i s t∗/

uint8 t s d p c l i e n t q u e r y (btstack packet handler t ca l lback ,bd addr t remote , const uint8 t ∗ d e s s e r v i c e s e a r c h p a t t e r n ,const uint8 t ∗ d e s a t t r i b u t e i d l i s t ) ;

/∗∗ @br ie f Searches SDP records on a remote dev i c e f o r a l l s e r v i c e s

wi th a g iven UUID.∗ @note c a l l s s d p c l i e n t q u e r y wi th s e r v i c e search pa t t e rn based on

uuid16∗/

uint8 t s d p c l i e n t q u e r y u u i d 1 6 (btstack packet handler t ca l lback ,bd addr t remote , uint16 t uuid16 ) ;

/∗

Page 228: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

227

∗ @br ie f Searches SDP records on a remote dev i c e f o r a l l s e r v i c e swi th a g iven UUID.

∗ @note c a l l s s d p c l i e n t q u e r y wi th s e r v i c e search pa t t e rn based onuuid128

∗/uint8 t s d p c l i e n t q u e r y u u i d 1 2 8 (btstack packet handler t ca l lback ,

bd addr t remote , const uint8 t∗ uuid128 ) ;

/∗∗∗ @br ie f Re t r i e v e s a l l a t t r i b u t e IDs o f a SDP record s p e c i f i e d by

i t s s e r v i c e record handle and a l i s t o f a t t r i b u t e IDs .∗ The remote data i s handled by the SDP parser . The SDP parser

d e l i v e r s a t t r i b u t e va l u e s and done event v ia the c a l l b a c k .∗ @note on ly prov ided i f ENABLE SDP EXTRA QUERIES i s de f ined∗ @param ca l l b a c k f o r a t t r i b u t e s va l u e s and done event∗ @param remote address∗ @param s ea r c h s e r v i c e r e c o r d hand l e∗ @param d e s a t t r i b u t e IDL i s t∗/

uint8 t s d p c l i e n t s e r v i c e a t t r i b u t e s e a r c h (btstack packet handler tca l lback , bd addr t remote , uint32 t

s e a r c h s e r v i c e r e c o r d h a n d l e , const uint8 t ∗d e s a t t r i b u t e I D L i s t ) ;

/∗∗∗ @br ie f Query the l i s t o f SDP records t ha t match a g iven s e r v i c e

search pa t t e rn .∗ The remote data i s handled by the SDP parser . The SDP parser

d e l i v e r s a t t r i b u t e va l u e s and done event v ia the c a l l b a c k .∗ @note on ly prov ided i f ENABLE SDP EXTRA QUERIES i s de f ined∗ @param ca l l b a c k f o r a t t r i b u t e s va l u e s and done event∗ @param remote address∗ @param d e s s e r v i c e s e a r c h p a t t e r n∗/

uint8 t s d p c l i e n t s e r v i c e s e a r c h (btstack packet handler t ca l lback ,bd addr t remote , const uint8 t ∗ d e s s e r v i c e s e a r c h p a t t e r n ) ;

#ifde f ENABLE SDP EXTRA QUERIESvoid s d p c l i e n t p a r s e s e r v i c e r e c o r d h a n d l e l i s t ( uint8 t∗ packet ,

uint16 t t o ta l count , uint16 t cur r ent count ) ;#endif

31.16. SDP RFCOMM Query API.

/∗∗∗ @br ie f Searches SDP records on a remote dev i c e f o r RFCOMM

se r v i c e s wi th a g iven 16− b i t UUID.∗ @note c a l l s s d p s e r v i c e s e a r c h p a t t e r n f o r u u i d 1 6 t ha t uses

g l o b a l b u f f e r∗/

Page 229: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

228

uint8 t sdp c l i en t query r f comm channe l and name fo r uu id (btstack packet handler t ca l lback , bd addr t remote , uint16 tuuid ) ;

/∗∗∗ @br ie f Searches SDP records on a remote dev i c e f o r RFCOMM

se r v i c e s wi th a g iven 128− b i t UUID.∗ @note c a l l s s d p s e r v i c e s e a r c h p a t t e r n f o r uu i d 1 2 8 t ha t uses

g l o b a l b u f f e r∗/

uint8 t sdp c l i ent query r f comm channe l and name for uu id128 (btstack packet handler t ca l lback , bd addr t remote , constuint8 t ∗ uuid128 ) ;

/∗∗∗ @br ie f Searches SDP records on a remote dev i c e f o r RFCOMM

se r v i c e s wi th a g iven s e r v i c e search pa t t e rn .∗/

uint8 t sdp c l i en t que ry r f comm channe l and name fo r s ea r ch pat t e rn (btstack packet handler t ca l lback , bd addr t remote , constuint8 t ∗ d e s s e r v i c e S e a r c h P a t t e r n ) ;

31.17. SDP Server API.

/∗∗∗ @br ie f Set up SDP.∗/

void s d p i n i t (void ) ;

/∗∗∗ @br ie f Reg i s t e r Serv i c e Record wi th database us ing

ServiceRecordHandle s t o r ed in record∗ @pre At t r i bu t e IDs are in ascending order∗ @pre ServiceRecordHandle i s f i r s t a t t r i b u t e and v a l i d∗ @param record i s not cop ied !∗ @resu l t s t a t u s∗/

uint8 t s d p r e g i s t e r s e r v i c e ( const uint8 t ∗ record ) ;

/∗∗∗ @br ie f Unreg i s t e r s e r v i c e record i n t e r n a l l y .∗/

void s d p u n r e g i s t e r s e r v i c e (uint32 t s e r v i c e r e c o r d h a n d l e ) ;

31.18. SDP Utils API.

typedef enum {DE NIL = 0 ,DE UINT,DE INT ,DE UUID,DE STRING,

Page 230: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

229

DE BOOL,DE DES,DE DEA,DE URL

} de type t ;

typedef enum {DE SIZE 8 = 0 ,DE SIZE 16 ,DE SIZE 32 ,DE SIZE 64 ,DE SIZE 128 ,DE SIZE VAR 8 ,DE SIZE VAR 16 ,DE SIZE VAR 32

} d e s i z e t ;

// MARK: DateElementvoid de dump data element ( const uint8 t ∗ record ) ;int d e g e t l e n ( const uint8 t ∗ header ) ;

// @note re turned ” s t r i n g ” i s not NULL terminatedconst uint8 t ∗ d e g e t s t r i n g ( const uint8 t ∗ element ) ;

d e s i z e t d e g e t s i z e t y p e ( const uint8 t ∗ header ) ;d e type t de ge t e l ement type ( const uint8 t ∗ header ) ;uint32 t d e g e t h e a d e r s i z e ( const uint8 t ∗ header ) ;int de e l ement ge t u in t16 ( const uint8 t ∗ element , uint16 t ∗

value ) ;uint32 t d e g e t d a t a s i z e ( const uint8 t ∗ header ) ;uint32 t de get uu id32 ( const uint8 t ∗ element ) ;int de ge t norma l i z ed uu id ( uint8 t ∗uuid128 , const uint8 t ∗

element ) ;void d e c r e a t e s e q u e n c e ( uint8 t ∗ header ) ;void d e s t o r e d e s c r i p t o r w i t h l e n ( uint8 t ∗ header , d e type t

type , d e s i z e t s i z e , uint32 t l en ) ;uint8 t ∗ de push sequence ( uint8 t ∗header ) ;void de pop sequence ( uint8 t ∗ parent , uint8 t ∗ c h i l d ) ;void de add number ( uint8 t ∗ seq , d e type t type , d e s i z e t s i z e

, uint32 t value ) ;void de add data ( uint8 t ∗ seq , d e type t type , uint16 t s i z e ,

uint8 t ∗data ) ;

void de add uuid128 ( uint8 t ∗ seq , uint8 t ∗ uuid ) ;

// re turns data element l en i f date e lement i s sma l l e r than s i z euint32 t d e g e t l e n s a f e ( const uint8 t ∗ header , uint32 t s i z e ) ;

// MARK: DES i t e r a t o rtypedef struct {

uint8 t ∗ element ;uint16 t pos ;uint16 t l ength ;

Page 231: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

230

} d e s i t e r a t o r t ;

int d e s i t e r a t o r i n i t ( d e s i t e r a t o r t ∗ i t , uint8 t ∗ element ) ;int d e s i t e r a t o r h a s m o r e ( d e s i t e r a t o r t ∗ i t ) ;d e type t d e s i t e r a t o r g e t t y p e ( d e s i t e r a t o r t ∗ i t ) ;uint16 t d e s i t e r a t o r g e t s i z e ( d e s i t e r a t o r t ∗ i t ) ;uint8 t ∗ d e s i t e r a t o r g e t e l e m e n t ( d e s i t e r a t o r t ∗ i t ) ;void d e s i t e r a t o r n e x t ( d e s i t e r a t o r t ∗ i t ) ;

// MARK: SDPuint16 t s d p a p p e n d a t t r i b u t e s i n a t t r i b u t e I D L i s t ( uint8 t ∗ record ,

uint8 t ∗ a t t r i bu t e IDL i s t , uint16 t s t a r t O f f s e t , uint16 tmaxBytes , uint8 t ∗ b u f f e r ) ;

uint8 t ∗ s d p g e t a t t r i b u t e v a l u e f o r a t t r i b u t e i d ( uint8 t ∗ record ,uint16 t at t r ibute ID ) ;

uint8 t s d p s e t a t t r i b u t e v a l u e f o r a t t r i b u t e i d ( uint8 t ∗ record ,uint16 t attr ibute ID , uint32 t value ) ;

int s d p r e c o r d m a t c h e s s e r v i c e s e a r c h p a t t e r n ( uint8 t ∗ record ,uint8 t ∗ s e rv i c eSea r chPat t e rn ) ;

int s p d g e t f i l t e r e d s i z e ( uint8 t ∗ record , uint8 t ∗a t t r i b u t e I D L i s t ) ;

int s d p f i l t e r a t t r i b u t e s i n a t t r i b u t e I D L i s t ( uint8 t ∗ record ,uint8 t ∗ a t t r i bu t e IDL i s t , uint16 t s t a r t O f f s e t , uint16 tmaxBytes , uint16 t ∗usedBytes , uint8 t ∗ b u f f e r ) ;

int s d p a t t r i b u t e l i s t c o n s t a i n s i d ( uint8 t ∗ a t t r i bu t e IDL i s t ,uint16 t at t r ibute ID ) ;

int sdp t rave r s a l mat ch pa t t e rn ( uint8 t ∗ element , d e type tattr ibuteType , d e s i z e t s i z e , void ∗my context ) ;

/∗∗ @br ie f Returns s e r v i c e search pa t t e rn f o r g iven UUID−16∗ @note Uses f i x e d b u f f e r∗/

uint8 t∗ s d p s e r v i c e s e a r c h p a t t e r n f o r u u i d 1 6 (uint16 t uuid16 ) ;

/∗∗ @br ie f Returns s e r v i c e search pa t t e rn f o r g iven UUID−128∗ @note Uses f i x e d b u f f e r∗/

uint8 t∗ s d p s e r v i c e s e a r c h p a t t e r n f o r u u i d 1 2 8 ( const uint8 t ∗uuid128 ) ;

31.19. BLE Advertisements Parser API.

typedef struct ad context {const uint8 t ∗ data ;uint8 t o f f s e t ;uint8 t l ength ;

} ad con t ex t t ;

// Adver t i s i ng or Scan Response data i t e r a t o rvoid a d i t e r a t o r i n i t ( ad con t ex t t ∗ context , uint8 t ad len , const

uint8 t ∗ ad data ) ;

Page 232: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

231

int a d i t e r a t o r h a s m o r e ( const ad con t ex t t ∗ context ) ;void a d i t e r a t o r n e x t ( ad con t ex t t ∗ context ) ;

// Access f unc t i on suint8 t a d i t e r a t o r g e t d a t a t y p e ( const ad con t ex t t ∗

context ) ;uint8 t a d i t e r a t o r g e t d a t a l e n ( const ad con t ex t t ∗

context ) ;const uint8 t ∗ a d i t e r a t o r g e t d a t a ( const ad con t ex t t ∗ context ) ;

// convenience func t i on on complete adver t i s ement sint ad data conta in s uu id16 ( uint8 t ad len , const uint8 t ∗ ad data ,

uint16 t uuid ) ;int ad data conta in s uu id128 ( uint8 t ad len , const uint8 t ∗ ad data

, const uint8 t ∗ uuid128 ) ;

31.20. BTstack Chipset API.

31.21. BTstack Hardware Control API.

31.22. HCI Event Getter API.

/∗∗∗ @br ie f Get event type∗ @param event∗ @return type o f event∗/

stat ic i n l i n e uint8 t h c i e v e n t p a c k e t g e t t y p e ( const uint8 t ∗event ) {return event [ 0 ] ;

}

/∗∗∗∗ @br ie f Get subevent code f o r a2dp event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i event a2dp meta ge t subevent code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r ancs event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i even t anc s meta ge t subeven t code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r avdtp event∗ @param event packe t∗ @return subeven t code

Page 233: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

232

∗/stat ic i n l i n e uint8 t hc i event avdtp meta ge t subevent code ( const

uint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r avrcp event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i even t av r cp meta ge t subevent code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r g a t t s e r v i c e event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t h c i e v e n t g a t t s e r v i c e m e t a g e t s u b e v e n t c o d e (const uint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r goep event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i event goep meta ge t subevent code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r h fp event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i even t h fp meta ge t subeven t code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r h id event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i ev en t h id meta ge t subeven t code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r h id s event∗ @param event packe t∗ @return subeven t code

Page 234: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

233

∗/stat ic i n l i n e uint8 t h c i e v e n t h i d s m e t a g e t s u b e v e n t c o d e ( const

uint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r hsp event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i even t h sp meta ge t subevent code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r l e event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t h c i e v e n t l e m e t a g e t s u b e v e n t c o d e ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗∗ @br ie f Get subevent code f o r pbap event∗ @param event packe t∗ @return subeven t code∗/

stat ic i n l i n e uint8 t hc i event pbap meta ge t subevent code ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event HCI EVENT INQUIRY COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t i n q u i r y c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d num responses from event

HCI EVENT INQUIRY RESULT∗ @param event packe t∗ @return num responses∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t i n q u i r y r e s u l t g e t n u m r e s p o n s e s (const uint8 t ∗ event ) {return event [ 2 ] ;

}

Page 235: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

234

/∗∗∗ @br ie f Get f i e l d bd addr from event HCI EVENT INQUIRY RESULT∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t i n q u i r y r e s u l t g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d page s can repe t i t i on mode from event

HCI EVENT INQUIRY RESULT∗ @param event packe t∗ @return page scan repe t i t i on mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t i n q u i r y r e s u l t g e t p a g e s c a n r e p e t i t i o n m o d e ( constuint8 t ∗ event ) {return event [ 9 ] ;

}/∗∗∗ @br ie f Get f i e l d re served1 from event HCI EVENT INQUIRY RESULT∗ @param event packe t∗ @return reserved1∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t i n q u i r y r e s u l t g e t r e s e r v e d 1 ( constuint8 t ∗ event ) {return event [ 1 0 ] ;

}/∗∗∗ @br ie f Get f i e l d re served2 from event HCI EVENT INQUIRY RESULT∗ @param event packe t∗ @return reserved2∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t i n q u i r y r e s u l t g e t r e s e r v e d 2 ( constuint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d c l a s s o f d e v i c e from event

HCI EVENT INQUIRY RESULT∗ @param event packe t∗ @return c l a s s o f d e v i c e∗ @note : b t s t a c k t y p e 3∗/

stat ic i n l i n e uint32 t h c i e v e n t i n q u i r y r e s u l t g e t c l a s s o f d e v i c e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 2 4 ( event , 12) ;

}/∗∗

Page 236: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

235

∗ @br ie f Get f i e l d c l o c k o f f s e t from event HCI EVENT INQUIRY RESULT∗ @param event packe t∗ @return c l o c k o f f s e t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h c i e v e n t i n q u i r y r e s u l t g e t c l o c k o f f s e t (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 15) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event HCI EVENT CONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t c o n n e c t i o n c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI EVENT CONNECTION COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event HCI EVENT CONNECTION COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void hc i ev en t connec t i o n comp l e t e g e t bd addr ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 5 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d l i n k t y p e from event

HCI EVENT CONNECTION COMPLETE∗ @param event packe t∗ @return l i n k t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t c o n n e c t i o n c o m p l e t e g e t l i n k t y p e (const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗

Page 237: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

236

∗ @br ie f Get f i e l d enc ryp t i on enab l ed from eventHCI EVENT CONNECTION COMPLETE

∗ @param event packe t∗ @return enc ryp t i on enab l ed∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t c o n n e c t i o n c o m p l e t e g e t e n c r y p t i o n e n a b l e d ( constuint8 t ∗ event ) {return event [ 1 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event HCI EVENT CONNECTION REQUEST∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t c o n n e c t i o n r e q u e s t g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d c l a s s o f d e v i c e from event

HCI EVENT CONNECTION REQUEST∗ @param event packe t∗ @return c l a s s o f d e v i c e∗ @note : b t s t a c k t y p e 3∗/

stat ic i n l i n e uint32 th c i e v e n t c o n n e c t i o n r e q u e s t g e t c l a s s o f d e v i c e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 2 4 ( event , 8) ;

}/∗∗∗ @br ie f Get f i e l d l i n k t y p e from event

HCI EVENT CONNECTION REQUEST∗ @param event packe t∗ @return l i n k t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t c o n n e c t i o n r e q u e s t g e t l i n k t y p e (const uint8 t ∗ event ) {return event [ 1 1 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT DISCONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

Page 238: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

237

stat ic i n l i n e uint8 t h c i e v e n t d i s c o n n e c t i o n c o m p l e t e g e t s t a t u s (const uint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI EVENT DISCONNECTION COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t d i s c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d reason from event

HCI EVENT DISCONNECTION COMPLETE∗ @param event packe t∗ @return reason∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t d i s c o n n e c t i o n c o m p l e t e g e t r e a s o n (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT AUTHENTICATION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t a u t h e n t i c a t i o n c o m p l e t e g e t s t a t u s (const uint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI EVENT AUTHENTICATION COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t a u t h e n t i c a t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗

Page 239: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

238

∗ @br ie f Get f i e l d s t a t u s from eventHCI EVENT REMOTE NAME REQUEST COMPLETE

∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 thc i ev en t r e mote nam e r e que s t co mp l e t e g e t s t a tu s ( const uint8 t∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT REMOTE NAME REQUEST COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidhc i event r emote name reques t comple t e ge t bd addr ( const uint8 t∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d remote name from event

HCI EVENT REMOTE NAME REQUEST COMPLETE∗ @param event packe t∗ @return remote name∗ @note : b t s t a c k t y p e N∗/

stat ic i n l i n e const char ∗hc i event remote name request complete get remote name ( constuint8 t ∗ event ) {return ( const char ∗) &event [ 9 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event HCI EVENT ENCRYPTION CHANGE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t e n c r y p t i o n c h a n g e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI EVENT ENCRYPTION CHANGE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e 2∗/

Page 240: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

239

stat ic i n l i n e uint16 th c i e v e n t e n c r y p t i o n c h a n g e g e t c o n n e c t i o n h a n d l e ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d enc ryp t i on enab l ed from event

HCI EVENT ENCRYPTION CHANGE∗ @param event packe t∗ @return enc ryp t i on enab l ed∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t e n c r y p t i o n c h a n g e g e t e n c r y p t i o n e n a b l e d ( const uint8 t∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT CHANGE CONNECTION LINK KEY COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t c h a n g e c o n n e c t i o n l i n k k e y c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI EVENT CHANGE CONNECTION LINK KEY COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t c h a n g e c o n n e c t i o n l i n k k e y c o m p l e t e g e t c o n n e c t i o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT MASTER LINK KEY COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t m a s t e r l i n k k e y c o m p l e t e g e t s t a t u s (const uint8 t ∗ event ) {return event [ 2 ] ;

}

Page 241: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

240

/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI EVENT MASTER LINK KEY COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t m a s t e r l i n k k e y c o m p l e t e g e t c o n n e c t i o n h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d k e y f l a g from event

HCI EVENT MASTER LINK KEY COMPLETE∗ @param event packe t∗ @return k e y f l a g∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t m a s t e r l i n k k e y c o m p l e t e g e t k e y f l a g ( const uint8 t ∗event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d num hci command packets from event

HCI EVENTCOMMANDCOMPLETE∗ @param event packe t∗ @return num hci command packets∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 thci event command complete get num hci command packets ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d command opcode from event

HCI EVENTCOMMANDCOMPLETE∗ @param event packe t∗ @return command opcode∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t hci event command complete get command opcode( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d re turn parameters from event

HCI EVENTCOMMANDCOMPLETE∗ @param event packe t∗ @return re turn parameters∗ @note : b t s t a c k t y p e R

Page 242: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

241

∗/stat ic i n l i n e const uint8 t ∗

hc i event command complete get return parameters ( const uint8 t ∗event ) {return &event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event HCI EVENT COMMAND STATUS∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t hc i event command s ta tus ge t s ta tus ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d num hci command packets from event

HCI EVENT COMMAND STATUS∗ @param event packe t∗ @return num hci command packets∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 thci event command status get num hci command packets ( constuint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d command opcode from event

HCI EVENT COMMAND STATUS∗ @param event packe t∗ @return command opcode∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t hci event command status get command opcode (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}

/∗∗∗ @br ie f Get f i e l d hardware code from event

HCI EVENT HARDWARE ERROR∗ @param event packe t∗ @return hardware code∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t hc i even t ha rdware e r ro r g e t ha rdware code (const uint8 t ∗ event ) {return event [ 2 ] ;

}

/∗∗

Page 243: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

242

∗ @br ie f Get f i e l d s t a t u s from event HCI EVENT ROLE CHANGE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t r o l e c h a n g e g e t s t a t u s ( const uint8 t∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event HCI EVENT ROLE CHANGE∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t r o l e c h a n g e g e t b d a d d r ( const uint8 t ∗event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d r o l e from event HCI EVENT ROLE CHANGE∗ @param event packe t∗ @return r o l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t r o l e c h a n g e g e t r o l e ( const uint8 t ∗event ) {return event [ 9 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event HCI EVENTMODE CHANGE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t hc i even t mode change ge t s ta tu s ( const uint8 t∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d handle from event HCI EVENTMODE CHANGE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t hc i event mode change get hand le (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d mode from event HCI EVENTMODE CHANGE∗ @param event packe t∗ @return mode

Page 244: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

243

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t hci event mode change get mode ( const uint8 t ∗event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d i n t e r v a l from event HCI EVENTMODE CHANGE∗ @param event packe t∗ @return i n t e r v a l∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h c i e v e n t m o d e c h a n g e g e t i n t e r v a l ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event HCI EVENT PIN CODE REQUEST∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t p i n c o d e r e q u e s t g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event HCI EVENT LINK KEY REQUEST∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t l i n k k e y r e q u e s t g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}

/∗∗∗ @br ie f Get f i e l d l i n k t y p e from event

HCI EVENT DATA BUFFER OVERFLOW∗ @param event packe t∗ @return l i n k t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t d a t a b u f f e r o v e r f l o w g e t l i n k t y p e (const uint8 t ∗ event ) {return event [ 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d handle from event HCI EVENT MAX SLOTS CHANGED∗ @param event packe t

Page 245: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

244

∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i e v e n t m ax s l o t s c ha n ge d g e t h an d l e ( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d lmp max s lo t s from event

HCI EVENT MAX SLOTS CHANGED∗ @param event packe t∗ @return lmp max s lo t s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t hc i even t max s l o t s changed ge t lmp max s l o t s (const uint8 t ∗ event ) {return event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT READ CLOCK OFFSET COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t r e a d c l o c k o f f s e t c o m p l e t e g e t s t a t u s ( const uint8 t ∗event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d handle from event

HCI EVENT READ CLOCK OFFSET COMPLETE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i e v e n t r e a d c l o c k o f f s e t c o m p l e t e g e t h a n d l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d c l o c k o f f s e t from event

HCI EVENT READ CLOCK OFFSET COMPLETE∗ @param event packe t∗ @return c l o c k o f f s e t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t r e a d c l o c k o f f s e t c o m p l e t e g e t c l o c k o f f s e t ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

Page 246: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

245

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT CONNECTION PACKET TYPE CHANGED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t c o n n e c t i o n p a c k e t t y p e c h a n g e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d handle from event

HCI EVENT CONNECTION PACKET TYPE CHANGED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i e v e n t c o nn e c t i on p a c ke t t y pe c h an g e d g e t h a nd l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d pa c k e t t y p e s from event

HCI EVENT CONNECTION PACKET TYPE CHANGED∗ @param event packe t∗ @return pa c k e t t y p e s∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t c o n n e c t i o n p a c k e t t y p e c h a n g e d g e t p a c k e t t y p e s ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

}

/∗∗∗ @br ie f Get f i e l d num responses from event

HCI EVENT INQUIRY RESULT WITH RSSI∗ @param event packe t∗ @return num responses∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t i n q u i r y r e s u l t w i t h r s s i g e t n u m r e s p o n s e s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT INQUIRY RESULT WITH RSSI

Page 247: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

246

∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t i n q u i r y r e s u l t w i t h r s s i g e t b d a d d r (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d page s can repe t i t i on mode from event

HCI EVENT INQUIRY RESULT WITH RSSI∗ @param event packe t∗ @return page scan repe t i t i on mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t i n q u i r y r e s u l t w i t h r s s i g e t p a g e s c a n r e p e t i t i o n m o d e( const uint8 t ∗ event ) {return event [ 9 ] ;

}/∗∗∗ @br ie f Get f i e l d r e s e rved from event

HCI EVENT INQUIRY RESULT WITH RSSI∗ @param event packe t∗ @return re se rved∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t i n q u i r y r e s u l t w i t h r s s i g e t r e s e r v e d ( const uint8 t ∗event ) {return event [ 1 0 ] ;

}/∗∗∗ @br ie f Get f i e l d c l a s s o f d e v i c e from event

HCI EVENT INQUIRY RESULT WITH RSSI∗ @param event packe t∗ @return c l a s s o f d e v i c e∗ @note : b t s t a c k t y p e 3∗/

stat ic i n l i n e uint32 th c i e v e n t i n q u i r y r e s u l t w i t h r s s i g e t c l a s s o f d e v i c e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 2 4 ( event , 11) ;

}/∗∗∗ @br ie f Get f i e l d c l o c k o f f s e t from event

HCI EVENT INQUIRY RESULT WITH RSSI∗ @param event packe t∗ @return c l o c k o f f s e t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t i n q u i r y r e s u l t w i t h r s s i g e t c l o c k o f f s e t ( constuint8 t ∗ event ) {

Page 248: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

247

return l i t t l e e n d i a n r e a d 1 6 ( event , 14) ;}/∗∗∗ @br ie f Get f i e l d r s s i from event

HCI EVENT INQUIRY RESULT WITH RSSI∗ @param event packe t∗ @return r s s i∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t i n q u i r y r e s u l t w i t h r s s i g e t r s s i (const uint8 t ∗ event ) {return event [ 1 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t s y n c h r o n o u s c o n n e c t i o n c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d handle from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e thc i ev en t synch ronous connec t i on comp l e t e g e t hand l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidhc i event synchronous connec t i on comp l e t e ge t bd addr ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 5 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d l i n k t y p e from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t

Page 249: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

248

∗ @return l i n k t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t s y n c h r o n o u s c o n n e c t i o n c o m p l e t e g e t l i n k t y p e ( constuint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d t r a n sm i s s i o n i n t e r v a l from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @return t r an sm i s s i o n i n t e r v a l∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t s y n c h r o n o u s c o n n e c t i o n c o m p l e t e g e t t r a n s m i s s i o n i n t e r v a l( const uint8 t ∗ event ) {return event [ 1 2 ] ;

}/∗∗∗ @br ie f Get f i e l d r e t r a n sm i s s i o n i n t e r v a l from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @return r e t r an sm i s s i o n i n t e r v a l∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t s y n c h r o n o u s c o n n e c t i o n c o m p l e t e g e t r e t r a n s m i s s i o n i n t e r v a l( const uint8 t ∗ event ) {return event [ 1 3 ] ;

}/∗∗∗ @br ie f Get f i e l d r x p a c k e t l e n g t h from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @return r x p a c k e t l e n g t h∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t s y n c h r o n o u s c o n n e c t i o n c o m p l e t e g e t r x p a c k e t l e n g t h (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 14) ;

}/∗∗∗ @br ie f Get f i e l d t x p a c k e t l e n g t h from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @return t x p a c k e t l e n g t h∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t s y n c h r o n o u s c o n n e c t i o n c o m p l e t e g e t t x p a c k e t l e n g t h (const uint8 t ∗ event ) {

Page 250: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

249

return l i t t l e e n d i a n r e a d 1 6 ( event , 16) ;}/∗∗∗ @br ie f Get f i e l d air mode from event

HCI EVENT SYNCHRONOUS CONNECTION COMPLETE∗ @param event packe t∗ @return air mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 thc i even t synchronous connec t i on comp l e t e ge t a i r mode ( constuint8 t ∗ event ) {return event [ 1 8 ] ;

}

/∗∗∗ @br ie f Get f i e l d num responses from event

HCI EVENT EXTENDED INQUIRY RESPONSE∗ @param event packe t∗ @return num responses∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t e x t e n d e d i n q u i r y r e s p o n s e g e t n u m r e s p o n s e s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT EXTENDED INQUIRY RESPONSE∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t e x t e n d e d i n q u i r y r e s p o n s e g e t b d a d d r (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d page s can repe t i t i on mode from event

HCI EVENT EXTENDED INQUIRY RESPONSE∗ @param event packe t∗ @return page scan repe t i t i on mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t e x t e n d e d i n q u i r y r e s p o n s e g e t p a g e s c a n r e p e t i t i o n m o d e( const uint8 t ∗ event ) {return event [ 9 ] ;

}/∗∗∗ @br ie f Get f i e l d r e s e rved from event

HCI EVENT EXTENDED INQUIRY RESPONSE∗ @param event packe t

Page 251: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

250

∗ @return re se rved∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t e x t e n d e d i n q u i r y r e s p o n s e g e t r e s e r v e d ( const uint8 t ∗

event ) {return event [ 1 0 ] ;

}/∗∗∗ @br ie f Get f i e l d c l a s s o f d e v i c e from event

HCI EVENT EXTENDED INQUIRY RESPONSE∗ @param event packe t∗ @return c l a s s o f d e v i c e∗ @note : b t s t a c k t y p e 3∗/

stat ic i n l i n e uint32 th c i e v e n t e x t e n d e d i n q u i r y r e s p o n s e g e t c l a s s o f d e v i c e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 2 4 ( event , 11) ;

}/∗∗∗ @br ie f Get f i e l d c l o c k o f f s e t from event

HCI EVENT EXTENDED INQUIRY RESPONSE∗ @param event packe t∗ @return c l o c k o f f s e t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i e v e n t e x t e n d e d i n q u i r y r e s p o n s e g e t c l o c k o f f s e t ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 14) ;

}/∗∗∗ @br ie f Get f i e l d r s s i from event

HCI EVENT EXTENDED INQUIRY RESPONSE∗ @param event packe t∗ @return r s s i∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t e x t e n d e d i n q u i r y r e s p o n s e g e t r s s i (const uint8 t ∗ event ) {return event [ 1 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT ENCRYPTION KEY REFRESH COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i e v e n t e n c r y p t i o n k e y r e f r e s h c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {

Page 252: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

251

return event [ 2 ] ;}/∗∗∗ @br ie f Get f i e l d handle from event

HCI EVENT ENCRYPTION KEY REFRESH COMPLETE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i e v e n t e n c r y p t i o n k e y r e f r e s h c o m p l e t e g e t h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT USER CONFIRMATION REQUEST∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t u s e r c o n f i r m a t i o n r e q u e s t g e t b d a d d r (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d numeric va lue from event

HCI EVENT USER CONFIRMATION REQUEST∗ @param event packe t∗ @return numeric va lue∗ @note : b t s t a c k t y p e 4∗/

stat ic i n l i n e uint32 th c i e v e n t u s e r c o n f i r m a t i o n r e q u e s t g e t n u m e r i c v a l u e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 8) ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT USER PASSKEY REQUEST∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t u s e r p a s s k e y r e q u e s t g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT REMOTE OOB DATA REQUEST

Page 253: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

252

∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v en t r e mo t e o o b d a t a r e qu e s t g e t b d a d dr (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI EVENT SIMPLE PAIRING COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t s i m p l e p a i r i n g c o m p l e t e g e t s t a t u s (const uint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HCI EVENT SIMPLE PAIRING COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h c i e v e n t s i m p l e p a i r i n g c o m p l e t e g e t b d a d d r (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t e from event BTSTACK EVENT STATE∗ @param event packe t∗ @return s t a t e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t b t s t a c k e v e n t s t a t e g e t s t a t e ( const uint8 t ∗event ) {return event [ 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d number connect ions from event

BTSTACK EVENT NR CONNECTIONS CHANGED∗ @param event packe t∗ @return number connect ions∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tbt s tack event nr connec t i on s changed ge t number connec t i on s (const uint8 t ∗ event ) {return event [ 2 ] ;

Page 254: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

253

}

/∗∗∗ @br ie f Get f i e l d d i s c o v e r a b l e from event

BTSTACK EVENT DISCOVERABLE ENABLED∗ @param event packe t∗ @return d i s c o v e r a b l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tb t s t a c k e v e n t d i s c o v e r a b l e e n a b l e d g e t d i s c o v e r a b l e ( constuint8 t ∗ event ) {return event [ 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d a c t i v e from event HCI EVENT TRANSPORT SLEEP MODE∗ @param event packe t∗ @return a c t i v e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i e v e n t t r a n s p o r t s l e e p m o d e g e t a c t i v e (const uint8 t ∗ event ) {return event [ 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d handle from event HCI EVENT SCO CAN SEND NOW∗ @param event packe t∗ @param Pointer to s t o rage f o r handle∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void hc i ev en t s c o can s en d now ge t han d l e ( constuint8 t ∗ event , bd addr t handle ) {r eve r s e bd addr (&event [ 2 ] , handle ) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t l 2 c a p e v e n t c h a n n e l o p e n e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

Page 255: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

254

stat ic i n l i n e void l 2 c ap e ve n t c ha nn e l o pe ne d g e t a dd r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 3 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d handle from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t l 2 cap event channe l opened ge t hand l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d psm from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return psm∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 cap event channe l opened get psm ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 11) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t c h a n n e l o p e n e d g e t l o c a l c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 13) ;

}/∗∗∗ @br ie f Get f i e l d remote c id from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return remote c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c ap even t channe l opened ge t r emote c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 15) ;

}/∗∗∗ @br ie f Get f i e l d l o ca l mtu from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return l oca l mtu∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t c h a n n e l o p e n e d g e t l o c a l m t u (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 17) ;

}

Page 256: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

255

/∗∗∗ @br ie f Get f i e l d remote mtu from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return remote mtu∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 cap event channe l opened get remote mtu (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 19) ;

}/∗∗∗ @br ie f Get f i e l d f l u s h t imeou t from event

L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return f l u s h t imeou t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t c h a n n e l o p e n e d g e t f l u s h t i m e o u t (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 21) ;

}/∗∗∗ @br ie f Get f i e l d incoming from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return incoming∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t l 2 cap event channe l opened ge t incoming ( constuint8 t ∗ event ) {return event [ 2 3 ] ;

}/∗∗∗ @br ie f Get f i e l d mode from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t l 2 cap event channe l opened get mode ( constuint8 t ∗ event ) {return event [ 2 4 ] ;

}/∗∗∗ @br ie f Get f i e l d f c s from event L2CAP EVENT CHANNEL OPENED∗ @param event packe t∗ @return f c s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t l 2 c a p e v e n t c h a n n e l o p e n e d g e t f c s ( constuint8 t ∗ event ) {return event [ 2 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event L2CAP EVENT CHANNEL CLOSED

Page 257: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

256

∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t c h a n n e l c l o s e d g e t l o c a l c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}

/∗∗∗ @br ie f Get f i e l d address from event

L2CAP EVENT INCOMING CONNECTION∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void l 2 c a p e v e n t i n c o m i n g c o n n e c t i o n g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 2 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d handle from event

L2CAP EVENT INCOMING CONNECTION∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tl 2 cap even t in coming connec t i on ge t hand l e ( const uint8 t ∗ event) {return l i t t l e e n d i a n r e a d 1 6 ( event , 8) ;

}/∗∗∗ @br ie f Get f i e l d psm from event L2CAP EVENT INCOMING CONNECTION∗ @param event packe t∗ @return psm∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 cap event incoming connec t i on ge t psm ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 10) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event

L2CAP EVENT INCOMING CONNECTION∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t i n c o m i n g c o n n e c t i o n g e t l o c a l c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 12) ;

}/∗∗

Page 258: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

257

∗ @br ie f Get f i e l d remote c id from eventL2CAP EVENT INCOMING CONNECTION

∗ @param event packe t∗ @return remote c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 c a p e v e n t i n c o m i n g c o n n e c t i o n g e t r e m o t e c i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 14) ;

}

/∗∗∗ @br ie f Get f i e l d handle from event

L2CAP EVENT CONNECTION PARAMETER UPDATE REQUEST∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tl 2 c ap ev en t co nnec t i on pa r amet e r upd a t e r eq ue s t g e t han d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d i n t e r va l m in from event

L2CAP EVENT CONNECTION PARAMETER UPDATE REQUEST∗ @param event packe t∗ @return in t e r va l m in∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 c a p e v e n t c o n n e c t i o n p a r a m e t e r u p d a t e r e q u e s t g e t i n t e r v a l m i n( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d in t e r va l max from event

L2CAP EVENT CONNECTION PARAMETER UPDATE REQUEST∗ @param event packe t∗ @return in t e rva l max∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 c a p e v e n t c o n n e c t i o n p a r a m e t e r u p d a t e r e q u e s t g e t i n t e r v a l m a x( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d l a t enc ey from event

L2CAP EVENT CONNECTION PARAMETER UPDATE REQUEST∗ @param event packe t∗ @return l a t enc ey∗ @note : b t s t a c k t y p e 2

Page 259: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

258

∗/stat ic i n l i n e uint16 t

l 2 c a p e v e n t c o n n e c t i o n p a r a m e t e r u p d a t e r e q u e s t g e t l a t e n c e y (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 8) ;

}/∗∗∗ @br ie f Get f i e l d t imeou t mu l t i p l i e r from event

L2CAP EVENT CONNECTION PARAMETER UPDATE REQUEST∗ @param event packe t∗ @return t imeou t mu l t i p l i e r∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 c a p e v e n t c o n n e c t i o n p a r a m e t e r u p d a t e r e q u e s t g e t t i m e o u t m u l t i p l i e r( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 10) ;

}

/∗∗∗ @br ie f Get f i e l d handle from event

L2CAP EVENT CONNECTION PARAMETER UPDATE RESPONSE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tl 2 cap even t connec t i on pa ramete r upda t e r e spons e ge t hand l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d r e s u l t from event

L2CAP EVENT CONNECTION PARAMETER UPDATE RESPONSE∗ @param event packe t∗ @return r e s u l t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 c a p e v e n t c o n n e c t i o n p a r a m e t e r u p d a t e r e s p o n s e g e t r e s u l t (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}

/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event L2CAP EVENT CAN SEND NOW∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t c a n s e n d n o w g e t l o c a l c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}

Page 260: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

259

/∗∗∗ @br ie f Get f i e l d add r e s s t ype from event

L2CAP EVENT LE INCOMING CONNECTION∗ @param event packe t∗ @return add r e s s t ype∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tl 2 c a p e v e n t l e i n c o m i n g c o n n e c t i o n g e t a d d r e s s t y p e ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

L2CAP EVENT LE INCOMING CONNECTION∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void l 2 c a p e v e n t l e i n c o m i n g c o n n e c t i o n g e t a d d r e s s (const uint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 3 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d handle from event

L2CAP EVENT LE INCOMING CONNECTION∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tl 2 c a p e v e n t l e i n c o m i n g c o n n e c t i o n g e t h a n d l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d psm from event

L2CAP EVENT LE INCOMING CONNECTION∗ @param event packe t∗ @return psm∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p ev en t l e i n co min g co nn ec t i o n ge t p s m (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 11) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event

L2CAP EVENT LE INCOMING CONNECTION∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

Page 261: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

260

stat ic i n l i n e uint16 tl 2 c a p e v e n t l e i n c o m i n g c o n n e c t i o n g e t l o c a l c i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 13) ;

}/∗∗∗ @br ie f Get f i e l d remote c id from event

L2CAP EVENT LE INCOMING CONNECTION∗ @param event packe t∗ @return remote c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 c a p e v e n t l e i n c o m i n g c o n n e c t i o n g e t r e m o t e c i d ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 15) ;

}/∗∗∗ @br ie f Get f i e l d remote mtu from event

L2CAP EVENT LE INCOMING CONNECTION∗ @param event packe t∗ @return remote mtu∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 cap even t l e i n coming connec t i on ge t r emote mtu ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 17) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t l 2 c a p e v e n t l e c h a n n e l o p e n e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d add r e s s t ype from event

L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return add r e s s t ype∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t l 2 c a p e v e n t l e c h a n n e l o p e n e d g e t a d d r e s s t y p e( const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t

Page 262: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

261

∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void l 2 c a p e v e n t l e c h a n n e l o p e n e d g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 4 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d handle from event L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tl 2 c a p e v e n t l e c h a n n e l o p e n e d g e t h a n d l e ( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 10) ;

}/∗∗∗ @br ie f Get f i e l d incoming from event

L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return incoming∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t l 2 c a p e v e n t l e c h a n n e l o p e n e d g e t i n c o m i n g (const uint8 t ∗ event ) {return event [ 1 2 ] ;

}/∗∗∗ @br ie f Get f i e l d psm from event L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return psm∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 cap even t l e channe l opened ge t p sm ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 13) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event

L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t l e c h a n n e l o p e n e d g e t l o c a l c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 15) ;

}/∗∗∗ @br ie f Get f i e l d remote c id from event

L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return remote c id

Page 263: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

262

∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t l e c h a n n e l o p e n e d g e t r e m o t e c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 17) ;

}/∗∗∗ @br ie f Get f i e l d l o ca l mtu from event

L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return l oca l mtu∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t l e c h a n n e l o p e n e d g e t l o c a l m t u (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 19) ;

}/∗∗∗ @br ie f Get f i e l d remote mtu from event

L2CAP EVENT LE CHANNEL OPENED∗ @param event packe t∗ @return remote mtu∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 cap event l e channe l opened ge t r emote mtu (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 21) ;

}

/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event

L2CAP EVENT LE CHANNEL CLOSED∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t l e c h a n n e l c l o s e d g e t l o c a l c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}

/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event L2CAP EVENT LE CAN SEND NOW∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t l e c a n s e n d n o w g e t l o c a l c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}

/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event L2CAP EVENT LE PACKET SENT

Page 264: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

263

∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t l 2 c a p e v e n t l e p a c k e t s e n t g e t l o c a l c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}

/∗∗∗ @br ie f Get f i e l d l o c a l c i d from event

L2CAP EVENT ERTM BUFFER RELEASED∗ @param event packe t∗ @return l o c a l c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tl 2 c a p e v e n t e r t m b u f f e r r e l e a s e d g e t l o c a l c i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event RFCOMMEVENTCHANNELOPENED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t r f comm event channe l opened get s ta tus ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event RFCOMMEVENTCHANNELOPENED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void r f comm event channe l opened get bd addr ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d con hand le from event

RFCOMMEVENTCHANNELOPENED∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t r f comm event channe l opened get con handle (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗

Page 265: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

264

∗ @br ie f Get f i e l d s e r v e r channe l from eventRFCOMMEVENTCHANNELOPENED

∗ @param event packe t∗ @return s e r v e r channe l∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t r f comm event channe l opened ge t s e rve r channe l( const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d rfcomm cid from event

RFCOMMEVENTCHANNELOPENED∗ @param event packe t∗ @return rfcomm cid∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t r fcomm event channe l opened get r fcomm cid (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 12) ;

}/∗∗∗ @br ie f Get f i e l d max frame s ize from event

RFCOMMEVENTCHANNELOPENED∗ @param event packe t∗ @return max frame s ize∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tr f comm event channe l opened get max f rame s i ze ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 14) ;

}/∗∗∗ @br ie f Get f i e l d incoming from event RFCOMMEVENTCHANNELOPENED∗ @param event packe t∗ @return incoming∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t r fcomm event channe l opened get incoming ( constuint8 t ∗ event ) {return event [ 1 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d rfcomm cid from event

RFCOMMEVENTCHANNEL CLOSED∗ @param event packe t∗ @return rfcomm cid∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t r f comm event channe l c l o s ed get r f comm cid (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

Page 266: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

265

}

/∗∗∗ @br ie f Get f i e l d bd addr from event

RFCOMMEVENT INCOMING CONNECTION∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void r f comm event incoming connect ion get bd addr (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d s e r v e r channe l from event

RFCOMMEVENT INCOMING CONNECTION∗ @param event packe t∗ @return s e r v e r channe l∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tr f comm event incoming connec t i on ge t s e rve r channe l ( constuint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d rfcomm cid from event

RFCOMMEVENT INCOMING CONNECTION∗ @param event packe t∗ @return rfcomm cid∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tr f comm event incoming connect ion get r f comm cid ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}

/∗∗∗ @br ie f Get f i e l d rfcomm cid from event

RFCOMM EVENT REMOTE LINE STATUS∗ @param event packe t∗ @return rfcomm cid∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tr f c omm event r emote l i n e s ta tu s ge t r f comm c id ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d l i n e s t a t u s from event

RFCOMM EVENT REMOTE LINE STATUS∗ @param event packe t

Page 267: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

266

∗ @return l i n e s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tr f c o m m e v e n t r e m o t e l i n e s t a t u s g e t l i n e s t a t u s ( const uint8 t ∗event ) {return event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d rfcomm cid from event

RFCOMMEVENTREMOTEMODEMSTATUS∗ @param event packe t∗ @return rfcomm cid∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tr fcomm event remote modem status get r fcomm cid ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d modem status from event

RFCOMMEVENTREMOTEMODEMSTATUS∗ @param event packe t∗ @return modem status∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tr fcomm event remote modem status get modem status ( const uint8 t∗ event ) {return event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d rfcomm cid from event RFCOMMEVENTCAN SENDNOW∗ @param event packe t∗ @return rfcomm cid∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t r fcomm event can send now get r fcomm cid (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event SDP EVENT QUERY COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s d p e v e n t q u e r y c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

Page 268: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

267

}

/∗∗∗ @br ie f Get f i e l d rfcomm channel from event

SDP EVENT QUERY RFCOMM SERVICE∗ @param event packe t∗ @return rfcomm channel∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tsdp event query r f comm serv i ce ge t r f comm channe l ( const uint8 t∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d name from event SDP EVENT QUERY RFCOMM SERVICE∗ @param event packe t∗ @return name∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗ sdp event query r f comm serv i ce get name (const uint8 t ∗ event ) {return ( const char ∗) &event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d r e co rd i d from event

SDP EVENT QUERY ATTRIBUTE BYTE∗ @param event packe t∗ @return r e co rd i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t s d p e v e n t q u e r y a t t r i b u t e b y t e g e t r e c o r d i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d a t t r i b u t e i d from event

SDP EVENT QUERY ATTRIBUTE BYTE∗ @param event packe t∗ @return a t t r i b u t e i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ts d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d a t t r i b u t e l e n g t h from event

SDP EVENT QUERY ATTRIBUTE BYTE∗ @param event packe t∗ @return a t t r i b u t e l e n g t h∗ @note : b t s t a c k t y p e 2

Page 269: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

268

∗/stat ic i n l i n e uint16 t

s d p e v e n t q u e r y a t t r i b u t e b y t e g e t a t t r i b u t e l e n g t h ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d d a t a o f f s e t from event

SDP EVENT QUERY ATTRIBUTE BYTE∗ @param event packe t∗ @return d a t a o f f s e t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ts d p e v e n t q u e r y a t t r i b u t e b y t e g e t d a t a o f f s e t ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 8) ;

}/∗∗∗ @br ie f Get f i e l d data from event SDP EVENT QUERY ATTRIBUTE BYTE∗ @param event packe t∗ @return data∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s d p e v e n t q u e r y a t t r i b u t e b y t e g e t d a t a ( constuint8 t ∗ event ) {return event [ 1 0 ] ;

}

/∗∗∗ @br ie f Get f i e l d r e co rd i d from event

SDP EVENT QUERY ATTRIBUTE VALUE∗ @param event packe t∗ @return r e co rd i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t s d p e v e n t q u e r y a t t r i b u t e v a l u e g e t r e c o r d i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d a t t r i b u t e i d from event

SDP EVENT QUERY ATTRIBUTE VALUE∗ @param event packe t∗ @return a t t r i b u t e i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ts d p e v e n t q u e r y a t t r i b u t e v a l u e g e t a t t r i b u t e i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗

Page 270: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

269

∗ @br ie f Get f i e l d a t t r i b u t e l e n g t h from eventSDP EVENT QUERY ATTRIBUTE VALUE

∗ @param event packe t∗ @return a t t r i b u t e l e n g t h∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e ints d p e v e n t q u e r y a t t r i b u t e v a l u e g e t a t t r i b u t e l e n g t h ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d a t t r i b u t e v a l u e from event

SDP EVENT QUERY ATTRIBUTE VALUE∗ @param event packe t∗ @return a t t r i b u t e v a l u e∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗s d p e v e n t q u e r y a t t r i b u t e v a l u e g e t a t t r i b u t e v a l u e ( constuint8 t ∗ event ) {return &event [ 8 ] ;

}

/∗∗∗ @br ie f Get f i e l d t o t a l c o un t from event

SDP EVENT QUERY SERVICE RECORD HANDLE∗ @param event packe t∗ @return t o t a l c o un t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ts d p e v e n t q u e r y s e r v i c e r e c o r d h a n d l e g e t t o t a l c o u n t ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d r ecord index from event

SDP EVENT QUERY SERVICE RECORD HANDLE∗ @param event packe t∗ @return record index∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ts d p e v e n t q u e r y s e r v i c e r e c o r d h a n d l e g e t r e c o r d i n d e x ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d record hand l e from event

SDP EVENT QUERY SERVICE RECORD HANDLE∗ @param event packe t∗ @return record hand l e∗ @note : b t s t a c k t y p e 4

Page 271: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

270

∗/stat ic i n l i n e uint32 t

s d p e v e n t q u e r y s e r v i c e r e c o r d h a n d l e g e t r e c o r d h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 6) ;

}

#ifde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event GATT EVENTQUERYCOMPLETE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t ga t t even t que ry comp l e t e g e t hand l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event GATT EVENTQUERYCOMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a t t e v e n t q u e r y c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 4 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT SERVICE QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t s e r v i c e q u e r y r e s u l t g e t h a n d l e ( const uint8 t ∗ event) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d s e r v i c e from event

GATT EVENT SERVICE QUERY RESULT∗ @param event packe t∗ @param Pointer to s t o rage f o r s e r v i c e∗ @note : b t s t a c k t y p e X∗/

stat ic i n l i n e void g a t t e v e n t s e r v i c e q u e r y r e s u l t g e t s e r v i c e ( constuint8 t ∗ event , gatt c l ient service t ∗ s e r v i c e ) {g a t t c l i e n t d e s e r i a l i z e s e r v i c e ( event , 4 , s e r v i c e ) ;

}

Page 272: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

271

#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT CHARACTERISTIC QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t c h a r a c t e r i s t i c q u e r y r e s u l t g e t h a n d l e ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d c h a r a c t e r i s t i c from event

GATT EVENT CHARACTERISTIC QUERY RESULT∗ @param event packe t∗ @param Pointer to s t o rage f o r c h a r a c t e r i s t i c∗ @note : b t s t a c k t y p e Y∗/

stat ic i n l i n e voidg a t t e v e n t c h a r a c t e r i s t i c q u e r y r e s u l t g e t c h a r a c t e r i s t i c ( constuint8 t ∗ event , gatt c l ient character ist ic t ∗ c h a r a c t e r i s t i c ) {g a t t c l i e n t d e s e r i a l i z e c h a r a c t e r i s t i c ( event , 4 , c h a r a c t e r i s t i c )

;}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT INCLUDED SERVICE QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t i n c l u d e d s e r v i c e q u e r y r e s u l t g e t h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d i n c l ud e hand l e from event

GATT EVENT INCLUDED SERVICE QUERY RESULT∗ @param event packe t∗ @return in c l ud e hand l e∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t e v e n t i n c l u d e d s e r v i c e q u e r y r e s u l t g e t i n c l u d e h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

Page 273: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

272

}/∗∗∗ @br ie f Get f i e l d s e r v i c e from event

GATT EVENT INCLUDED SERVICE QUERY RESULT∗ @param event packe t∗ @param Pointer to s t o rage f o r s e r v i c e∗ @note : b t s t a c k t y p e X∗/

stat ic i n l i n e voidg a t t e v e n t i n c l u d e d s e r v i c e q u e r y r e s u l t g e t s e r v i c e ( constuint8 t ∗ event , gatt c l ient service t ∗ s e r v i c e ) {g a t t c l i e n t d e s e r i a l i z e s e r v i c e ( event , 6 , s e r v i c e ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT ALL CHARACTERISTIC DESCRIPTORS QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t a l l c h a r a c t e r i s t i c d e s c r i p t o r s q u e r y r e s u l t g e t h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d c h a r a c t e r i s t i c d e s c r i p t o r from event

GATT EVENT ALL CHARACTERISTIC DESCRIPTORS QUERY RESULT∗ @param event packe t∗ @param Pointer to s t o rage f o r c h a r a c t e r i s t i c d e s c r i p t o r∗ @note : b t s t a c k t y p e Z∗/

stat ic i n l i n e voidg a t t e v e n t a l l c h a r a c t e r i s t i c d e s c r i p t o r s q u e r y r e s u l t g e t c h a r a c t e r i s t i c d e s c r i p t o r( const uint8 t ∗ event , gatt cl ient characterist ic descriptor t∗ c h a r a c t e r i s t i c d e s c r i p t o r ) {g a t t c l i e n t d e s e r i a l i z e c h a r a c t e r i s t i c d e s c r i p t o r ( event , 4 ,

c h a r a c t e r i s t i c d e s c r i p t o r ) ;}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

Page 274: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

273

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d va l u e hand l e from event

GATT EVENT CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return va l u e hand l e∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t e v e n t c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t v a l u e h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d v a l u e l e n g t h from event

GATT EVENT CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return v a l u e l e n g t h∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e intg a t t e v e n t c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t v a l u e l e n g t h (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d va lue from event

GATT EVENT CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗g a t t e v e n t c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t v a l u e ( constuint8 t ∗ event ) {return &event [ 8 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT LONG CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t l o n g c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t h a n d l e (const uint8 t ∗ event ) {

Page 275: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

274

return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;}/∗∗∗ @br ie f Get f i e l d va l u e hand l e from event

GATT EVENT LONG CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return va l u e hand l e∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t e v e n t l o n g c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t v a l u e h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d v a l u e o f f s e t from event

GATT EVENT LONG CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return v a l u e o f f s e t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t e v e n t l o n g c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t v a l u e o f f s e t( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d v a l u e l e n g t h from event

GATT EVENT LONG CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return v a l u e l e n g t h∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e intg a t t e v e n t l o n g c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t v a l u e l e n g t h( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 8) ;

}/∗∗∗ @br ie f Get f i e l d va lue from event

GATT EVENT LONG CHARACTERISTIC VALUE QUERY RESULT∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗g a t t e v e n t l o n g c h a r a c t e r i s t i c v a l u e q u e r y r e s u l t g e t v a l u e (const uint8 t ∗ event ) {return &event [ 1 0 ] ;

}#endif

#i fde f ENABLE BLE/∗∗

Page 276: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

275

∗ @br ie f Get f i e l d handle from event GATT EVENT NOTIFICATION∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t g a t t e v e n t n o t i f i c a t i o n g e t h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d va l u e hand l e from event GATT EVENT NOTIFICATION∗ @param event packe t∗ @return va l u e hand l e∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t g a t t e v e n t n o t i f i c a t i o n g e t v a l u e h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d v a l u e l e n g t h from event GATT EVENT NOTIFICATION∗ @param event packe t∗ @return v a l u e l e n g t h∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e int g a t t e v e n t n o t i f i c a t i o n g e t v a l u e l e n g t h ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d va lue from event GATT EVENT NOTIFICATION∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗ g a t t e v e n t n o t i f i c a t i o n g e t v a l u e (const uint8 t ∗ event ) {return &event [ 8 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event GATT EVENT INDICATION∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t g a t t e v e n t i n d i c a t i o n g e t h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d va l u e hand l e from event GATT EVENT INDICATION

Page 277: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

276

∗ @param event packe t∗ @return va l u e hand l e∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t g a t t e v e n t i n d i c a t i o n g e t v a l u e h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d v a l u e l e n g t h from event GATT EVENT INDICATION∗ @param event packe t∗ @return v a l u e l e n g t h∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e int g a t t e v e n t i n d i c a t i o n g e t v a l u e l e n g t h ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d va lue from event GATT EVENT INDICATION∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗ g a t t e v e n t i n d i c a t i o n g e t v a l u e ( constuint8 t ∗ event ) {return &event [ 8 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d d e s c r i p t o r h and l e from event

GATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT∗ @param event packe t∗ @return d e s c r i p t o r h and l e∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t e v e n t c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t d e s c r i p t o r h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

Page 278: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

277

}/∗∗∗ @br ie f Get f i e l d d e s c r i p t o r l e n g t h from event

GATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT∗ @param event packe t∗ @return d e s c r i p t o r l e n g t h∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e intg a t t e v e n t c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t d e s c r i p t o r l e n g t h( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d d e s c r i p t o r from event

GATT EVENT CHARACTERISTIC DESCRIPTOR QUERY RESULT∗ @param event packe t∗ @return d e s c r i p t o r∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗g a t t e v e n t c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t d e s c r i p t o r( const uint8 t ∗ event ) {return &event [ 8 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT LONG CHARACTERISTIC DESCRIPTOR QUERY RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t l o n g c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d d e s c r i p t o r o f f s e t from event

GATT EVENT LONG CHARACTERISTIC DESCRIPTOR QUERY RESULT∗ @param event packe t∗ @return d e s c r i p t o r o f f s e t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t e v e n t l o n g c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t d e s c r i p t o r o f f s e t( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗

Page 279: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

278

∗ @br ie f Get f i e l d d e s c r i p t o r l e n g t h from eventGATT EVENT LONG CHARACTERISTIC DESCRIPTOR QUERY RESULT

∗ @param event packe t∗ @return d e s c r i p t o r l e n g t h∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e intg a t t e v e n t l o n g c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t d e s c r i p t o r l e n g t h( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d d e s c r i p t o r from event

GATT EVENT LONG CHARACTERISTIC DESCRIPTOR QUERY RESULT∗ @param event packe t∗ @return d e s c r i p t o r∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗g a t t e v e n t l o n g c h a r a c t e r i s t i c d e s c r i p t o r q u e r y r e s u l t g e t d e s c r i p t o r( const uint8 t ∗ event ) {return &event [ 8 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event GATT EVENTMTU∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t ga t t event mtu ge t hand l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d MTU from event GATT EVENTMTU∗ @param event packe t∗ @return MTU∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t gatt event mtu get MTU ( const uint8 t ∗ event ){return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

GATT EVENT CANWRITEWITHOUT RESPONSE∗ @param event packe t∗ @return handle

Page 280: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

279

∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tg a t t e v e n t c a n w r i t e w i t h o u t r e s p o n s e g e t h a n d l e ( const uint8 t ∗

event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}#endif

/∗∗∗ @br ie f Get f i e l d handle from event

ATT EVENTMTUEXCHANGECOMPLETE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ta t t event mtu exchange comple te ge t hand l e ( const uint8 t ∗ event) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d MTU from event ATT EVENTMTUEXCHANGECOMPLETE∗ @param event packe t∗ @return MTU∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t att event mtu exchange complete get MTU ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

ATT EVENT HANDLE VALUE INDICATION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta t t e v e n t h a n d l e v a l u e i n d i c a t i o n c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d conn handle from event

ATT EVENT HANDLE VALUE INDICATION COMPLETE∗ @param event packe t∗ @return conn handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ta t t e v e n t h a n d l e v a l u e i n d i c a t i o n c o m p l e t e g e t c o n n h a n d l e ( constuint8 t ∗ event ) {

Page 281: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

280

return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;}/∗∗∗ @br ie f Get f i e l d a t t r i b u t e h a n d l e from event

ATT EVENT HANDLE VALUE INDICATION COMPLETE∗ @param event packe t∗ @return a t t r i b u t e h a n d l e∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta t t e v e n t h a n d l e v a l u e i n d i c a t i o n c o m p l e t e g e t a t t r i b u t e h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event BNEP EVENT SERVICE REGISTERED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t b n e p e v e n t s e r v i c e r e g i s t e r e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d s e r v i c e uu i d from event

BNEP EVENT SERVICE REGISTERED∗ @param event packe t∗ @return s e r v i c e uu i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tb n e p e v e n t s e r v i c e r e g i s t e r e d g e t s e r v i c e u u i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event BNEP EVENT CHANNEL OPENED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t bnep event channe l opened ge t s ta tu s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d bnep c id from event BNEP EVENT CHANNEL OPENED∗ @param event packe t∗ @return bnep c id∗ @note : b t s t a c k t y p e 2

Page 282: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

281

∗/stat ic i n l i n e uint16 t bnep event channe l opened get bnep c id ( const

uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d source uu id from event BNEP EVENT CHANNEL OPENED∗ @param event packe t∗ @return source uu id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t bnep event channe l opened ge t source uu id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

}/∗∗∗ @br ie f Get f i e l d d e s t i n a t i on uu i d from event

BNEP EVENT CHANNEL OPENED∗ @param event packe t∗ @return d e s t i n a t i on uu i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tbnep even t channe l opened ge t de s t i na t i on uu id ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 7) ;

}/∗∗∗ @br ie f Get f i e l d mtu from event BNEP EVENT CHANNEL OPENED∗ @param event packe t∗ @return mtu∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t bnep event channe l opened get mtu ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d remote address from event

BNEP EVENT CHANNEL OPENED∗ @param event packe t∗ @param Pointer to s t o rage f o r remote address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void bnep event channe l opened get r emote addre s s (const uint8 t ∗ event , bd addr t remote address ) {r eve r s e bd addr (&event [ 1 1 ] , remote address ) ;

}

/∗∗∗ @br ie f Get f i e l d bnep c id from event BNEP EVENT CHANNEL CLOSED∗ @param event packe t∗ @return bnep c id∗ @note : b t s t a c k t y p e 2

Page 283: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

282

∗/stat ic i n l i n e uint16 t b n e p e v e n t c h a n n e l c l o s e d g e t b n e p c i d ( const

uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d source uu id from event BNEP EVENT CHANNEL CLOSED∗ @param event packe t∗ @return source uu id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t b n e p e v e n t c h a n n e l c l o s e d g e t s o u r c e u u i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d d e s t i n a t i on uu i d from event

BNEP EVENT CHANNEL CLOSED∗ @param event packe t∗ @return d e s t i n a t i on uu i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tb n e p e v e n t c h a n n e l c l o s e d g e t d e s t i n a t i o n u u i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d remote address from event

BNEP EVENT CHANNEL CLOSED∗ @param event packe t∗ @param Pointer to s t o rage f o r remote address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void b n ep e v en t c h an n e l c l o s e d g e t r e mo t e a d dr e s s (const uint8 t ∗ event , bd addr t remote address ) {r eve r s e bd addr (&event [ 8 ] , r emote address ) ;

}

/∗∗∗ @br ie f Get f i e l d bnep c id from event BNEP EVENT CHANNEL TIMEOUT∗ @param event packe t∗ @return bnep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t bnep event channe l t imeout ge t bnep c id ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d source uu id from event

BNEP EVENT CHANNEL TIMEOUT∗ @param event packe t∗ @return source uu id

Page 284: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

283

∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t bnep even t channe l t imeout ge t sou r c e uu id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d d e s t i n a t i on uu i d from event

BNEP EVENT CHANNEL TIMEOUT∗ @param event packe t∗ @return d e s t i n a t i on uu i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tb n e p e v e n t c h a n n e l t i m e o u t g e t d e s t i n a t i o n u u i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d remote address from event

BNEP EVENT CHANNEL TIMEOUT∗ @param event packe t∗ @param Pointer to s t o rage f o r remote address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void bnep event channe l t imeout ge t r emote addre s s (const uint8 t ∗ event , bd addr t remote address ) {r eve r s e bd addr (&event [ 8 ] , r emote address ) ;

}/∗∗∗ @br ie f Get f i e l d c h anne l s t a t e from event

BNEP EVENT CHANNEL TIMEOUT∗ @param event packe t∗ @return channe l s t a t e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t b n e p e v e n t c h a n n e l t i m e o u t g e t c h a n n e l s t a t e (const uint8 t ∗ event ) {return event [ 1 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d bnep c id from event BNEP EVENT CAN SEND NOW∗ @param event packe t∗ @return bnep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t bnep event can send now get bnep c id ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d source uu id from event BNEP EVENT CAN SEND NOW∗ @param event packe t

Page 285: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

284

∗ @return source uu id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t bnep event can send now get source uu id ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d d e s t i n a t i on uu i d from event

BNEP EVENT CAN SEND NOW∗ @param event packe t∗ @return d e s t i n a t i on uu i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t bnep event can s end now ge t de s t ina t i on uu id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d remote address from event

BNEP EVENT CAN SEND NOW∗ @param event packe t∗ @param Pointer to s t o rage f o r remote address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void bnep event can send now get remote addres s ( constuint8 t ∗ event , bd addr t remote address ) {r eve r s e bd addr (&event [ 8 ] , r emote address ) ;

}

#ifde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT JUST WORKS REQUEST∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t j u s t w o r k s r e q u e s t g e t h a n d l e ( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event SM EVENT JUST WORKS REQUEST∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t j u s t w o r k s r e q u e s t g e t a d d r t y p e (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event SM EVENT JUST WORKS REQUEST∗ @param event packe t

Page 286: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

285

∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t j u s t w o r k s r e q u e s t g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT JUST WORKS CANCEL∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t s m e v e n t j u s t w o r k s c a n c e l g e t h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event SM EVENT JUST WORKS CANCEL∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t j u s t w o r k s c a n c e l g e t a d d r t y p e ( constuint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event SM EVENT JUST WORKS CANCEL∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t j u s t w o r k s c a n c e l g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

SM EVENT PASSKEY DISPLAY NUMBER∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tsm event pas skey d i sp lay number get hand le ( const uint8 t ∗ event) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

Page 287: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

286

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT PASSKEY DISPLAY NUMBER∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t sm event pas skey d i sp lay number get addr type (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT PASSKEY DISPLAY NUMBER∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void sm event pas skey d i sp lay number ge t addre s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d passkey from event

SM EVENT PASSKEY DISPLAY NUMBER∗ @param event packe t∗ @return passkey∗ @note : b t s t a c k t y p e 4∗/

stat ic i n l i n e uint32 t sm event pas skey d i sp lay number ge t pas skey (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 11) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

SM EVENT PASSKEY DISPLAY CANCEL∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t p a s s k e y d i s p l a y c a n c e l g e t h a n d l e ( const uint8 t ∗ event) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT PASSKEY DISPLAY CANCEL∗ @param event packe t∗ @return addr type

Page 288: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

287

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t p a s s k e y d i s p l a y c a n c e l g e t a d d r t y p e (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT PASSKEY DISPLAY CANCEL∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t p a s s k e y d i s p l a y c a n c e l g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT PASSKEY INPUT NUMBER∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tsm event passkey input number get handle ( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT PASSKEY INPUT NUMBER∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t sm event passkey input number get addr type (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event SM EVENT PASSKEY INPUT NUMBER∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void sm event passkey input number get addres s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE

Page 289: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

288

/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT PASSKEY INPUT CANCEL∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e ve n t p a s s k e y i np ut c an c e l g e t h an d l e ( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT PASSKEY INPUT CANCEL∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e ve n t pa s sk ey in pu t c anc e l g e t ad dr ty pe (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event SM EVENT PASSKEY INPUT CANCEL∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t p a s s k e y i n p u t c a n c e l g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

SM EVENT NUMERIC COMPARISON REQUEST∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tsm event numer i c compar i son reques t ge t hand le ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT NUMERIC COMPARISON REQUEST∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

Page 290: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

289

stat ic i n l i n e uint8 tsm event numer i c compar i son reques t ge t addr type ( const uint8 t∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT NUMERIC COMPARISON REQUEST∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void sm event numer i c compar i son reques t ge t addre s s (const uint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d passkey from event

SM EVENT NUMERIC COMPARISON REQUEST∗ @param event packe t∗ @return passkey∗ @note : b t s t a c k t y p e 4∗/

stat ic i n l i n e uint32 tsm event numer i c compar i son reques t ge t pas skey ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 11) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

SM EVENT NUMERIC COMPARISON CANCEL∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tsm event numer i c compar i son cance l ge t hand l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT NUMERIC COMPARISON CANCEL∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tsm event numer i c compar i son cance l ge t addr type ( const uint8 t ∗

event ) {return event [ 4 ] ;

Page 291: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

290

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT NUMERIC COMPARISON CANCEL∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void sm event numer i c compar i son cance l ge t addre s s (const uint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

SM EVENT IDENTITY RESOLVING STARTED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t i d e n t i t y r e s o l v i n g s t a r t e d g e t h a n d l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT IDENTITY RESOLVING STARTED∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ts m e v e n t i d e n t i t y r e s o l v i n g s t a r t e d g e t a d d r t y p e ( const uint8 t∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT IDENTITY RESOLVING STARTED∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t i d e n t i t y r e s o l v i n g s t a r t e d g e t a d d r e s s (const uint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗

Page 292: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

291

∗ @br ie f Get f i e l d handle from eventSM EVENT IDENTITY RESOLVING FAILED

∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t i d e n t i t y r e s o l v i n g f a i l e d g e t h a n d l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT IDENTITY RESOLVING FAILED∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ts m e v e n t i d e n t i t y r e s o l v i n g f a i l e d g e t a d d r t y p e ( const uint8 t ∗event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT IDENTITY RESOLVING FAILED∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t i d e n t i t y r e s o l v i n g f a i l e d g e t a d d r e s s (const uint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

SM EVENT IDENTITY RESOLVING SUCCEEDED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t h a n d l e ( const uint8 t ∗

event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT IDENTITY RESOLVING SUCCEEDED∗ @param event packe t∗ @return addr type

Page 293: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

292

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ts m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t a d d r t y p e ( constuint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT IDENTITY RESOLVING SUCCEEDED∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t a d d r e s s( const uint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d i d e n t i t y a d d r t y p e from event

SM EVENT IDENTITY RESOLVING SUCCEEDED∗ @param event packe t∗ @return i d e n t i t y a d d r t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ts m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t i d e n t i t y a d d r t y p e (const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d i d e n t i t y a d d r e s s from event

SM EVENT IDENTITY RESOLVING SUCCEEDED∗ @param event packe t∗ @param Pointer to s t o rage f o r i d e n t i t y a d d r e s s∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voids m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t i d e n t i t y a d d r e s s ( constuint8 t ∗ event , bd addr t i d e n t i t y a d d r e s s ) {r eve r s e bd addr (&event [ 1 2 ] , i d e n t i t y a d d r e s s ) ;

}/∗∗∗ @br ie f Get f i e l d index from event

SM EVENT IDENTITY RESOLVING SUCCEEDED∗ @param event packe t∗ @return index∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ts m e v e n t i d e n t i t y r e s o l v i n g s u c c e e d e d g e t i n d e x ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 18) ;

}

Page 294: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

293

#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT AUTHORIZATION REQUEST∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t a u t h o r i z a t i o n r e q u e s t g e t h a n d l e ( const uint8 t ∗ event ){return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT AUTHORIZATION REQUEST∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t a u t h o r i z a t i o n r e q u e s t g e t a d d r t y p e (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

SM EVENT AUTHORIZATION REQUEST∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t a u t h o r i z a t i o n r e q u e s t g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT AUTHORIZATION RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t a u t h o r i z a t i o n r e s u l t g e t h a n d l e ( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event

SM EVENT AUTHORIZATION RESULT∗ @param event packe t∗ @return addr type

Page 295: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

294

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t a u t h o r i z a t i o n r e s u l t g e t a d d r t y p e (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event SM EVENT AUTHORIZATION RESULT∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t a u t h o r i z a t i o n r e s u l t g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d a u t h o r i z a t i o n r e s u l t from event

SM EVENT AUTHORIZATION RESULT∗ @param event packe t∗ @return a u t h o r i z a t i o n r e s u l t∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ts m e v e n t a u t h o r i z a t i o n r e s u l t g e t a u t h o r i z a t i o n r e s u l t ( constuint8 t ∗ event ) {return event [ 1 1 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT KEYPRESS NOTIFICATION∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ts m e v e n t k e y p r e s s n o t i f i c a t i o n g e t h a n d l e ( const uint8 t ∗ event ){return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d ac t i on from event SM EVENT KEYPRESS NOTIFICATION∗ @param event packe t∗ @return ac t i on∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t k e y p r e s s n o t i f i c a t i o n g e t a c t i o n (const uint8 t ∗ event ) {return event [ 4 ] ;

}#endif

Page 296: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

295

#ifde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT IDENTITY CREATED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t s m e v e n t i d e n t i t y c r e a t e d g e t h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event SM EVENT IDENTITY CREATED∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t i d e n t i t y c r e a t e d g e t a d d r t y p e ( constuint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event SM EVENT IDENTITY CREATED∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t i d e n t i t y c r e a t e d g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d i d e n t i t y a d d r t y p e from event

SM EVENT IDENTITY CREATED∗ @param event packe t∗ @return i d e n t i t y a d d r t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ts m e v e n t i d e n t i t y c r e a t e d g e t i d e n t i t y a d d r t y p e ( const uint8 t ∗event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d i d e n t i t y a d d r e s s from event

SM EVENT IDENTITY CREATED∗ @param event packe t∗ @param Pointer to s t o rage f o r i d e n t i t y a d d r e s s∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t i d e n t i t y c r e a t e d g e t i d e n t i t y a d d r e s s (const uint8 t ∗ event , bd addr t i d e n t i t y a d d r e s s ) {r eve r s e bd addr (&event [ 1 2 ] , i d e n t i t y a d d r e s s ) ;

}

Page 297: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

296

/∗∗∗ @br ie f Get f i e l d index from event SM EVENT IDENTITY CREATED∗ @param event packe t∗ @return index∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t s m e v e n t i d e n t i t y c r e a t e d g e t i n d e x ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 18) ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event SM EVENT PAIRING COMPLETE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t sm event pa i r i ng comp l e t e ge t hand l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d addr type from event SM EVENT PAIRING COMPLETE∗ @param event packe t∗ @return addr type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t sm event pa i r i ng comp l e t e ge t addr type ( constuint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event SM EVENT PAIRING COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void s m e v e n t p a i r i n g c o m p l e t e g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 5 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event SM EVENT PAIRING COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t p a i r i n g c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗

Page 298: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

297

∗ @br ie f Get f i e l d reason from event SM EVENT PAIRING COMPLETE∗ @param event packe t∗ @return reason∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t s m e v e n t p a i r i n g c o m p l e t e g e t r e a s o n ( constuint8 t ∗ event ) {return event [ 1 2 ] ;

}#endif

/∗∗∗ @br ie f Get f i e l d handle from event GAP EVENT SECURITY LEVEL∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e t g a p e v e n t s e c u r i t y l e v e l g e t h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 2) ;

}/∗∗∗ @br ie f Get f i e l d s e c u r i t y l e v e l from event

GAP EVENT SECURITY LEVEL∗ @param event packe t∗ @return s e c u r i t y l e v e l∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a p e v e n t s e c u r i t y l e v e l g e t s e c u r i t y l e v e l (const uint8 t ∗ event ) {return event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

GAP EVENT DEDICATED BONDING COMPLETED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tgap event ded i ca t ed bond ing comp l e t ed ge t s t a tu s ( const uint8 t ∗

event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event

GAP EVENT DEDICATED BONDING COMPLETED∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void gap event ded i ca t ed bond ing comp le t ed ge t addre s s( const uint8 t ∗ event , bd addr t address ) {

Page 299: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

298

r eve r s e bd addr (&event [ 3 ] , address ) ;}

/∗∗∗ @br ie f Get f i e l d a d v e r t i s i n g e v e n t t y p e from event

GAP EVENT ADVERTISING REPORT∗ @param event packe t∗ @return a d v e r t i s i n g e v e n t t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tg a p e v e n t a d v e r t i s i n g r e p o r t g e t a d v e r t i s i n g e v e n t t y p e ( constuint8 t ∗ event ) {return event [ 2 ] ;

}/∗∗∗ @br ie f Get f i e l d add r e s s t ype from event

GAP EVENT ADVERTISING REPORT∗ @param event packe t∗ @return add r e s s t ype∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s t y p e (const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d address from event GAP EVENT ADVERTISING REPORT∗ @param event packe t∗ @param Pointer to s t o rage f o r address∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void g a p e v e n t a d v e r t i s i n g r e p o r t g e t a d d r e s s ( constuint8 t ∗ event , bd addr t address ) {r eve r s e bd addr (&event [ 4 ] , address ) ;

}/∗∗∗ @br ie f Get f i e l d r s s i from event GAP EVENT ADVERTISING REPORT∗ @param event packe t∗ @return r s s i∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a p e v e n t a d v e r t i s i n g r e p o r t g e t r s s i ( constuint8 t ∗ event ) {return event [ 1 0 ] ;

}/∗∗∗ @br ie f Get f i e l d d a t a l e n g t h from event

GAP EVENT ADVERTISING REPORT∗ @param event packe t∗ @return da t a l e n g t h∗ @note : b t s t a c k t y p e J∗/

Page 300: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

299

stat ic i n l i n e int g a p e v e n t a d v e r t i s i n g r e p o r t g e t d a t a l e n g t h ( constuint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d data from event GAP EVENT ADVERTISING REPORT∗ @param event packe t∗ @return data∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗ g a p e v e n t a d v e r t i s i n g r e p o r t g e t d a t a (const uint8 t ∗ event ) {return &event [ 1 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void g a p e v e n t i n q u i r y r e s u l t g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 2 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d page s can repe t i t i on mode from event

GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return page scan repe t i t i on mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tg a p e v e n t i n q u i r y r e s u l t g e t p a g e s c a n r e p e t i t i o n m o d e ( constuint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d c l a s s o f d e v i c e from event

GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return c l a s s o f d e v i c e∗ @note : b t s t a c k t y p e 3∗/

stat ic i n l i n e uint32 t g a p e v e n t i n q u i r y r e s u l t g e t c l a s s o f d e v i c e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 2 4 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d c l o c k o f f s e t from event GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return c l o c k o f f s e t∗ @note : b t s t a c k t y p e 2∗/

Page 301: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

300

stat ic i n l i n e uint16 t g a p e v e n t i n q u i r y r e s u l t g e t c l o c k o f f s e t (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 12) ;

}/∗∗∗ @br ie f Get f i e l d r s s i a v a i l a b l e from event

GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return r s s i a v a i l a b l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a p e v e n t i n q u i r y r e s u l t g e t r s s i a v a i l a b l e (const uint8 t ∗ event ) {return event [ 1 4 ] ;

}/∗∗∗ @br ie f Get f i e l d r s s i from event GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return r s s i∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a p e v e n t i n q u i r y r e s u l t g e t r s s i ( constuint8 t ∗ event ) {return event [ 1 5 ] ;

}/∗∗∗ @br ie f Get f i e l d name ava i l ab l e from event

GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return name ava i l ab l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a p e v e n t i n q u i r y r e s u l t g e t n a m e a v a i l a b l e (const uint8 t ∗ event ) {return event [ 1 6 ] ;

}/∗∗∗ @br ie f Get f i e l d name len from event GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return name len∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e int g a p e v e n t i n q u i r y r e s u l t g e t n a m e l e n ( constuint8 t ∗ event ) {return event [ 1 7 ] ;

}/∗∗∗ @br ie f Get f i e l d name from event GAP EVENT INQUIRY RESULT∗ @param event packe t∗ @return name∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗ g a p e v e n t i n q u i r y r e s u l t g e t n a m e (const uint8 t ∗ event ) {

Page 302: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

301

return &event [ 1 8 ] ;}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event GAP EVENT INQUIRY COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t g a p e v e n t i n q u i r y c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t s t a t u s( const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d r o l e from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return r o l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t r o l e (const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d p e e r add r e s s t y p e from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return pe e r add r e s s t y p e∗ @note : b t s t a c k t y p e 1

Page 303: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

302

∗/stat ic i n l i n e uint8 t

h c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t p e e r a d d r e s s t y p e ( constuint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d pee r addre s s from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r pee r addre s s∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidh c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t p e e r a d d r e s s ( constuint8 t ∗ event , bd addr t pee r addre s s ) {r eve r s e bd addr (&event [ 8 ] , p e e r addr e s s ) ;

}/∗∗∗ @br ie f Get f i e l d c onn in t e r v a l from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return conn in t e r v a l∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n i n t e r v a l ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 14) ;

}/∗∗∗ @br ie f Get f i e l d conn la tency from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return conn la tency∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t c o n n l a t e n c y ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 16) ;

}/∗∗∗ @br ie f Get f i e l d supe r v i s i on t imeou t from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return supe r v i s i on t imeou t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t s u p e r v i s i o n t i m e o u t (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 18) ;

}

Page 304: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

303

/∗∗∗ @br ie f Get f i e l d mas t e r c l ock accuracy from event

HCI SUBEVENT LE CONNECTION COMPLETE∗ @param event packe t∗ @return mas t e r c l ock accuracy∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e c o n n e c t i o n c o m p l e t e g e t m a s t e r c l o c k a c c u r a c y (const uint8 t ∗ event ) {return event [ 2 0 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI SUBEVENT LE CONNECTION UPDATE COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI SUBEVENT LE CONNECTION UPDATE COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n e c t i o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d c onn in t e r v a l from event

HCI SUBEVENT LE CONNECTION UPDATE COMPLETE∗ @param event packe t∗ @return conn in t e r v a l∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n i n t e r v a l (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d conn la tency from event

HCI SUBEVENT LE CONNECTION UPDATE COMPLETE∗ @param event packe t∗ @return conn la tency

Page 305: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

304

∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t c o n n l a t e n c y (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 8) ;

}/∗∗∗ @br ie f Get f i e l d supe r v i s i on t imeou t from event

HCI SUBEVENT LE CONNECTION UPDATE COMPLETE∗ @param event packe t∗ @return supe r v i s i on t imeou t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e c o n n e c t i o n u p d a t e c o m p l e t e g e t s u p e r v i s i o n t i m e o u t( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 10) ;

}

/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI SUBEVENT LE READ REMOTE USED FEATURES COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i s u b e v e n t l e r e a d r e m o t e u s e d f e a t u r e s c o m p l e t e g e t c o n n e c t i o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d random number from event

HCI SUBEVENT LE READ REMOTE USED FEATURES COMPLETE∗ @param event packe t∗ @return random number∗ @note : b t s t a c k t y p e D∗/

stat ic i n l i n e const uint8 t ∗hc i subevent l e r ead remote used f ea tur e s comp le t e ge t random number( const uint8 t ∗ event ) {return ( const uint8 t ∗) &event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d e n c r y p t i o n d i v e r s i f i e r from event

HCI SUBEVENT LE READ REMOTE USED FEATURES COMPLETE∗ @param event packe t∗ @return e n c r y p t i o n d i v e r s i f i e r∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e r e a d r e m o t e u s e d f e a t u r e s c o m p l e t e g e t e n c r y p t i o n d i v e r s i f i e r( const uint8 t ∗ event ) {

Page 306: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

305

return l i t t l e e n d i a n r e a d 1 6 ( event , 13) ;}

/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI SUBEVENT LE LONG TERM KEY REQUEST∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i s u b e v e n t l e l o n g t e r m k e y r e q u e s t g e t c o n n e c t i o n h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d random number from event

HCI SUBEVENT LE LONG TERM KEY REQUEST∗ @param event packe t∗ @return random number∗ @note : b t s t a c k t y p e D∗/

stat ic i n l i n e const uint8 t ∗hc i subevent l e l ong te rm key reques t ge t random number ( constuint8 t ∗ event ) {return ( const uint8 t ∗) &event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d e n c r y p t i o n d i v e r s i f i e r from event

HCI SUBEVENT LE LONG TERM KEY REQUEST∗ @param event packe t∗ @return e n c r y p t i o n d i v e r s i f i e r∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e l o n g t e r m k e y r e q u e s t g e t e n c r y p t i o n d i v e r s i f i e r( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 13) ;

}

/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI SUBEVENT LE REMOTE CONNECTION PARAMETER REQUEST∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i s u b e v e n t l e r e m o t e c o n n e c t i o n p a r a m e t e r r e q u e s t g e t c o n n e c t i o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗

Page 307: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

306

∗ @br ie f Get f i e l d i n t e r va l m in from eventHCI SUBEVENT LE REMOTE CONNECTION PARAMETER REQUEST

∗ @param event packe t∗ @return in t e r va l m in∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e r e m o t e c o n n e c t i o n p a r a m e t e r r e q u e s t g e t i n t e r v a l m i n( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

}/∗∗∗ @br ie f Get f i e l d in t e r va l max from event

HCI SUBEVENT LE REMOTE CONNECTION PARAMETER REQUEST∗ @param event packe t∗ @return in t e rva l max∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e r e m o t e c o n n e c t i o n p a r a m e t e r r e q u e s t g e t i n t e r v a l m a x( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 7) ;

}/∗∗∗ @br ie f Get f i e l d l a t ency from event

HCI SUBEVENT LE REMOTE CONNECTION PARAMETER REQUEST∗ @param event packe t∗ @return l a t ency∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e r e m o t e c o n n e c t i o n p a r a m e t e r r e q u e s t g e t l a t e n c y (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d t imeout from event

HCI SUBEVENT LE REMOTE CONNECTION PARAMETER REQUEST∗ @param event packe t∗ @return t imeout∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e r e m o t e c o n n e c t i o n p a r a m e t e r r e q u e s t g e t t i m e o u t (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 11) ;

}

/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI SUBEVENT LE DATA LENGTH CHANGE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e H

Page 308: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

307

∗/stat ic i n l i n e h c i c o n h a n d l e t

h c i s u b e v e n t l e d a t a l e n g t h c h a n g e g e t c o n n e c t i o n h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d max t x o c t e t s from event

HCI SUBEVENT LE DATA LENGTH CHANGE∗ @param event packe t∗ @return max t x o c t e t s∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e d a t a l e n g t h c h a n g e g e t m a x t x o c t e t s ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

}/∗∗∗ @br ie f Get f i e l d max tx t ime from event

HCI SUBEVENT LE DATA LENGTH CHANGE∗ @param event packe t∗ @return max tx t ime∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e d a t a l e n g t h c h a n g e g e t m a x t x t i m e ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 7) ;

}/∗∗∗ @br ie f Get f i e l d max rx oc t e t s from event

HCI SUBEVENT LE DATA LENGTH CHANGE∗ @param event packe t∗ @return max rx oc t e t s∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e d a t a l e n g t h c h a n g e g e t m a x r x o c t e t s ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d max rx t ime from event

HCI SUBEVENT LE DATA LENGTH CHANGE∗ @param event packe t∗ @return max rx time∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e d a t a l e n g t h c h a n g e g e t m a x r x t i m e ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 11) ;

}

Page 309: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

308

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI SUBEVENT LE READ LOCAL P256 PUBLIC KEY COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e r e a d l o c a l p 2 5 6 p u b l i c k e y c o m p l e t e g e t s t a t u s (const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d dhkey x from event

HCI SUBEVENT LE READ LOCAL P256 PUBLIC KEY COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r dhkey x∗ @note : b t s t a c k t y p e Q∗/

stat ic i n l i n e voidh c i s u b e v e n t l e r e a d l o c a l p 2 5 6 p u b l i c k e y c o m p l e t e g e t d h k e y x (const uint8 t ∗ event , uint8 t ∗ dhkey x ) {r e v e r s e b y t e s (&event [ 4 ] , dhkey x , 32) ;

}/∗∗∗ @br ie f Get f i e l d dhkey y from event

HCI SUBEVENT LE READ LOCAL P256 PUBLIC KEY COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r dhkey y∗ @note : b t s t a c k t y p e Q∗/

stat ic i n l i n e voidh c i s u b e v e n t l e r e a d l o c a l p 2 5 6 p u b l i c k e y c o m p l e t e g e t d h k e y y (const uint8 t ∗ event , uint8 t ∗ dhkey y ) {r e v e r s e b y t e s (&event [ 3 6 ] , dhkey y , 32) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI SUBEVENT LE GENERATE DHKEY COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e g e n e r a t e d h k e y c o m p l e t e g e t s t a t u s ( const uint8 t∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d dhkey from event

HCI SUBEVENT LE GENERATE DHKEY COMPLETE∗ @param event packe t

Page 310: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

309

∗ @param Pointer to s t o rage f o r dhkey∗ @note : b t s t a c k t y p e Q∗/

stat ic i n l i n e void hc i subeven t l e g ene ra t e dhkey comp l e t e g e t dhkey( const uint8 t ∗ event , uint8 t ∗ dhkey ) {r e v e r s e b y t e s (&event [ 4 ] , dhkey , 32) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d connec t ion hand le from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @return connec t ion hand le∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t c o n n e c t i o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d r o l e from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @return r o l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t r o l e ( constuint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d p e e r add r e s s t y p e from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @return pe e r add r e s s t y p e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t p e e r a d d r e s s t y p e( const uint8 t ∗ event ) {

Page 311: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

310

return event [ 7 ] ;}/∗∗∗ @br ie f Get f i e l d p e r r add r e s s s from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r p e r r add r e s s s∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidh c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t p e r r a d d r e s s s (const uint8 t ∗ event , bd addr t p e r r a d d r e s s s ) {r eve r s e bd addr (&event [ 8 ] , p e r r a d d r e s s s ) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l r e s o l v a b l e p r i v a t e a d d r e s from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r l o c a l r e s o l v a b l e p r i v a t e a d d r e s∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidh c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t l o c a l r e s o l v a b l e p r i v a t e a d d r e s( const uint8 t ∗ event , bd addr tl o c a l r e s o l v a b l e p r i v a t e a d d r e s ) {r eve r s e bd addr (&event [ 1 4 ] , l o c a l r e s o l v a b l e p r i v a t e a d d r e s ) ;

}/∗∗∗ @br ie f Get f i e l d p e e r r e s o l v a b l e p r i v a t e a d d r e s from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @param Pointer to s t o rage f o r p e e r r e s o l v a b l e p r i v a t e a d d r e s∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidh c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t p e e r r e s o l v a b l e p r i v a t e a d d r e s( const uint8 t ∗ event , bd addr t p e e r r e s o l v a b l e p r i v a t e a d d r e s) {r eve r s e bd addr (&event [ 2 0 ] , p e e r r e s o l v a b l e p r i v a t e a d d r e s ) ;

}/∗∗∗ @br ie f Get f i e l d c onn in t e r v a l from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @return conn in t e r v a l∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t c o n n i n t e r v a l (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 26) ;

}/∗∗

Page 312: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

311

∗ @br ie f Get f i e l d conn la tency from eventHCI SUBEVENT LE ENHANCED CONNECTION COMPLETE

∗ @param event packe t∗ @return conn la tency∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t c o n n l a t e n c y (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 28) ;

}/∗∗∗ @br ie f Get f i e l d supe r v i s i on t imeou t from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @return supe r v i s i on t imeou t∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t s u p e r v i s i o n t i m e o u t( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 30) ;

}/∗∗∗ @br ie f Get f i e l d mas t e r c l ock accuracy from event

HCI SUBEVENT LE ENHANCED CONNECTION COMPLETE∗ @param event packe t∗ @return mas t e r c l ock accuracy∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th c i s u b e v e n t l e e n h a n c e d c o n n e c t i o n c o m p l e t e g e t m a s t e r c l o c k a c c u r a c y( const uint8 t ∗ event ) {return event [ 3 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HSP SUBEVENT RFCOMMCONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 thsp subevent r f comm connec t i on comple t e ge t s ta tus ( const uint8 t∗ event ) {return event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HSP SUBEVENT RFCOMMDISCONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s

Page 313: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

312

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 thsp subevent r f comm di s connec t i on comp l e t e ge t s ta tu s ( constuint8 t ∗ event ) {return event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HSP SUBEVENT AUDIO CONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th s p s u b e v e n t a u d i o c o n n e c t i o n c o m p l e t e g e t s t a t u s ( const uint8 t∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d handle from event

HSP SUBEVENT AUDIO CONNECTION COMPLETE∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th sp subevent aud io connec t i on comp l e t e ge t hand l e ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HSP SUBEVENT AUDIO DISCONNECTION COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th s p s u b e v e n t a u d i o d i s c o n n e c t i o n c o m p l e t e g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d gain from event

HSP SUBEVENT MICROPHONE GAIN CHANGED∗ @param event packe t∗ @return gain∗ @note : b t s t a c k t y p e 1∗/

Page 314: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

313

stat ic i n l i n e uint8 t hsp subevent mic rophone ga in changed get ga in (const uint8 t ∗ event ) {return event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d gain from event

HSP SUBEVENT SPEAKER GAIN CHANGED∗ @param event packe t∗ @return gain∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t hsp subeven t speake r ga in changed ge t ga in (const uint8 t ∗ event ) {return event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d v a l u e l e n g t h from event HSP SUBEVENT HS COMMAND∗ @param event packe t∗ @return v a l u e l e n g t h∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e int hsp subevent hs command get va lue length ( constuint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d va lue from event HSP SUBEVENT HS COMMAND∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗ hsp subevent hs command get value (const uint8 t ∗ event ) {return &event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d v a l u e l e n g t h from event

HSP SUBEVENT AG INDICATION∗ @param event packe t∗ @return v a l u e l e n g t h∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e int h s p s u b e v e n t a g i n d i c a t i o n g e t v a l u e l e n g t h ( constuint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d va lue from event HSP SUBEVENT AG INDICATION∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V

Page 315: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

314

∗/stat ic i n l i n e const uint8 t ∗ h s p s u b e v e n t a g i n d i c a t i o n g e t v a l u e (

const uint8 t ∗ event ) {return &event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HFP SUBEVENT SERVICE LEVEL CONNECTION ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t s e r v i c e l e v e l c o n n e c t i o n e s t a b l i s h e d g e t s t a t u s (const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d con hand le from event

HFP SUBEVENT SERVICE LEVEL CONNECTION ESTABLISHED∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th f p s u b e v e n t s e r v i c e l e v e l c o n n e c t i o n e s t a b l i s h e d g e t c o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HFP SUBEVENT SERVICE LEVEL CONNECTION ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidh f p s u b e v e n t s e r v i c e l e v e l c o n n e c t i o n e s t a b l i s h e d g e t b d a d d r (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 6 ] , bd addr ) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HFP SUBEVENT AUDIO CONNECTION ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a u d i o c o n n e c t i o n e s t a b l i s h e d g e t s t a t u s ( constuint8 t ∗ event ) {

Page 316: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

315

return event [ 3 ] ;}/∗∗∗ @br ie f Get f i e l d handle from event

HFP SUBEVENT AUDIO CONNECTION ESTABLISHED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th f p s u b e v e n t a u d i o c o n n e c t i o n e s t a b l i s h e d g e t h a n d l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 4) ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HFP SUBEVENT AUDIO CONNECTION ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidh f p s u b e v e n t a u d i o c o n n e c t i o n e s t a b l i s h e d g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 6 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d ne go t i a t e d codec from event

HFP SUBEVENT AUDIO CONNECTION ESTABLISHED∗ @param event packe t∗ @return nego t i a t e d codec∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a u d i o c o n n e c t i o n e s t a b l i s h e d g e t n e g o t i a t e d c o d e c (const uint8 t ∗ event ) {return event [ 1 2 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event HFP SUBEVENT COMPLETE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h f p s u b e v e n t c o m p l e t e g e t s t a t u s ( const uint8 t∗ event ) {return event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d i n d i c a t o r i n d e x from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED

Page 317: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

316

∗ @param event packe t∗ @return i n d i c a t o r i n d e x∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r i n d e x (const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d i n d i c a t o r s t a t u s from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED∗ @param event packe t∗ @return i n d i c a t o r s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r s t a t u s (const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d ind i ca to r min range from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED∗ @param event packe t∗ @return ind i ca to r min range∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r m i n r a n g e( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d ind ica tor max range from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED∗ @param event packe t∗ @return ind ica tor max range∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r m a x r a n g e( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d ind ica tor mandatory from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED∗ @param event packe t∗ @return ind ica tor mandatory∗ @note : b t s t a c k t y p e 1∗/

Page 318: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

317

stat ic i n l i n e uint8 th f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r m a n d a t o r y( const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d i n d i c a t o r ena b l e d from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED∗ @param event packe t∗ @return i n d i c a t o r ena b l e d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r e n a b l e d (const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d i n d i c a t o r s t a t u s c h an g e d from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED∗ @param event packe t∗ @return i n d i c a t o r s t a t u s c h an g e d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r s t a t u s c h a n g e d( const uint8 t ∗ event ) {return event [ 9 ] ;

}/∗∗∗ @br ie f Get f i e l d indicator name from event

HFP SUBEVENT AG INDICATOR STATUS CHANGED∗ @param event packe t∗ @return indicator name∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗h f p s u b e v e n t a g i n d i c a t o r s t a t u s c h a n g e d g e t i n d i c a t o r n a m e (const uint8 t ∗ event ) {return ( const char ∗) &event [ 1 0 ] ;

}

/∗∗∗ @br ie f Get f i e l d network operator mode from event

HFP SUBEVENTNETWORKOPERATORCHANGED∗ @param event packe t∗ @return network operator mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 thfp subevent network operator changed get network operator mode (const uint8 t ∗ event ) {return event [ 3 ] ;

}

Page 319: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

318

/∗∗∗ @br ie f Get f i e l d ne twork opera tor format from event

HFP SUBEVENTNETWORKOPERATORCHANGED∗ @param event packe t∗ @return ne twork opera tor format∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th fp subevent ne twork opera to r changed ge t ne twork opera to r f o rmat( const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d network operator name from event

HFP SUBEVENTNETWORKOPERATORCHANGED∗ @param event packe t∗ @return network operator name∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗hfp subevent network operator changed get network operator name (const uint8 t ∗ event ) {return ( const char ∗) &event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d error from event

HFP SUBEVENT EXTENDED AUDIO GATEWAY ERROR∗ @param event packe t∗ @return error∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t e x t e n d e d a u d i o g a t e w a y e r r o r g e t e r r o r ( constuint8 t ∗ event ) {return event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d number from event

HFP SUBEVENT PLACE CALL WITH NUMBER∗ @param event packe t∗ @return number∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗h fp subevent p lace ca l l w i th number ge t number ( const uint8 t ∗event ) {return ( const char ∗) &event [ 3 ] ;

}

Page 320: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

319

/∗∗∗ @br ie f Get f i e l d number from event

HFP SUBEVENT NUMBER FOR VOICE TAG∗ @param event packe t∗ @return number∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗hfp subevent number fo r vo i c e tag ge t number ( const uint8 t ∗event ) {return ( const char ∗) &event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d dtmf from event HFP SUBEVENT TRANSMIT DTMF CODES∗ @param event packe t∗ @return dtmf∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗ h fp subevent t ransmi t d tmf code s ge t d tmf( const uint8 t ∗ event ) {return ( const char ∗) &event [ 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event HFP SUBEVENT SPEAKER VOLUME∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h fp subeven t speake r vo lume ge t s t a tu s ( constuint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d gain from event HFP SUBEVENT SPEAKER VOLUME∗ @param event packe t∗ @return gain∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h fp subevent speake r vo lume ge t ga in ( constuint8 t ∗ event ) {return event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event HFP SUBEVENTMICROPHONE VOLUME∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1

Page 321: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

320

∗/stat ic i n l i n e uint8 t hfp subevent mic rophone vo lume get s ta tus (

const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d gain from event HFP SUBEVENTMICROPHONE VOLUME∗ @param event packe t∗ @return gain∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t hfp subevent microphone vo lume get ga in ( constuint8 t ∗ event ) {return event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d type from event

HFP SUBEVENT CALL WAITING NOTIFICATION∗ @param event packe t∗ @return type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t c a l l w a i t i n g n o t i f i c a t i o n g e t t y p e ( const uint8 t ∗event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d number from event

HFP SUBEVENT CALL WAITING NOTIFICATION∗ @param event packe t∗ @return number∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗h f p s u b e v e n t c a l l w a i t i n g n o t i f i c a t i o n g e t n u m b e r ( const uint8 t∗ event ) {return ( const char ∗) &event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d type from event

HFP SUBEVENT CALLING LINE IDENTIFICATION NOTIFICATION∗ @param event packe t∗ @return type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t c a l l i n g l i n e i d e n t i f i c a t i o n n o t i f i c a t i o n g e t t y p e (const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗

Page 322: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

321

∗ @br ie f Get f i e l d number from eventHFP SUBEVENT CALLING LINE IDENTIFICATION NOTIFICATION

∗ @param event packe t∗ @return number∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗h f p s u b e v e n t c a l l i n g l i n e i d e n t i f i c a t i o n n o t i f i c a t i o n g e t n u m b e r( const uint8 t ∗ event ) {return ( const char ∗) &event [ 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d c l c c i d x from event

HFP SUBEVENT ENHANCED CALL STATUS∗ @param event packe t∗ @return c l c c i d x∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h f p s u b e v e n t e n h a n c e d c a l l s t a t u s g e t c l c c i d x( const uint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d c l c c d i r from event

HFP SUBEVENT ENHANCED CALL STATUS∗ @param event packe t∗ @return c l c c d i r∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h f p s u b e v e n t e n h a n c e d c a l l s t a t u s g e t c l c c d i r( const uint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d c l c c s t a t u s from event

HFP SUBEVENT ENHANCED CALL STATUS∗ @param event packe t∗ @return c l c c s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t e n h a n c e d c a l l s t a t u s g e t c l c c s t a t u s ( const uint8 t∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d c lcc mode from event

HFP SUBEVENT ENHANCED CALL STATUS∗ @param event packe t∗ @return clcc mode∗ @note : b t s t a c k t y p e 1∗/

Page 323: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

322

stat ic i n l i n e uint8 th f p s u b e v e n t e n h a n c e d c a l l s t a t u s g e t c l c c m o d e ( const uint8 t ∗event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d c l cc mpty from event

HFP SUBEVENT ENHANCED CALL STATUS∗ @param event packe t∗ @return c l cc mpty∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t e n h a n c e d c a l l s t a t u s g e t c l c c m p t y ( const uint8 t ∗event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d bn i p t ype from event

HFP SUBEVENT ENHANCED CALL STATUS∗ @param event packe t∗ @return bn i p t ype∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t e n h a n c e d c a l l s t a t u s g e t b n i p t y p e ( const uint8 t ∗event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d bnip number from event

HFP SUBEVENT ENHANCED CALL STATUS∗ @param event packe t∗ @return bnip number∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗h fp subeven t enhanced ca l l s t a tu s ge t bn ip number ( const uint8 t∗ event ) {return ( const char ∗) &event [ 9 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

HFP SUBEVENT SUBSCRIBER NUMBER INFORMATION∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th f p s u b e v e n t s u b s c r i b e r n u m b e r i n f o r m a t i o n g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 3 ] ;

}

Page 324: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

323

/∗∗∗ @br ie f Get f i e l d bn i p t ype from event

HFP SUBEVENT SUBSCRIBER NUMBER INFORMATION∗ @param event packe t∗ @return bn i p t ype∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th fp subeven t subs c r i b e r number in f o rmat i on ge t bn ip type ( constuint8 t ∗ event ) {return event [ 4 ] ;

}/∗∗∗ @br ie f Get f i e l d bnip number from event

HFP SUBEVENT SUBSCRIBER NUMBER INFORMATION∗ @param event packe t∗ @return bnip number∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗hfp subevent subsc r ibe r number in fo rmat ion get bn ip number ( constuint8 t ∗ event ) {return ( const char ∗) &event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d va lue from event

HFP SUBEVENT RESPONSE AND HOLD STATUS∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗h f p s u b e v e n t r e s p o n s e a n d h o l d s t a t u s g e t v a l u e ( const uint8 t ∗event ) {return ( const char ∗) &event [ 3 ] ;

}

#ifde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event ANCS SUBEVENT CLIENT CONNECTED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ta n c s s u b e v e n t c l i e n t c o n n e c t e d g e t h a n d l e ( const uint8 t ∗ event ){return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}#endif

#i fde f ENABLE BLE/∗∗

Page 325: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

324

∗ @br ie f Get f i e l d handle from eventANCS SUBEVENT CLIENT NOTIFICATION

∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ta n c s s u b e v e n t c l i e n t n o t i f i c a t i o n g e t h a n d l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d a t t r i b u t e i d from event

ANCS SUBEVENT CLIENT NOTIFICATION∗ @param event packe t∗ @return a t t r i b u t e i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta n c s s u b e v e n t c l i e n t n o t i f i c a t i o n g e t a t t r i b u t e i d ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

}/∗∗∗ @br ie f Get f i e l d t e x t from event

ANCS SUBEVENT CLIENT NOTIFICATION∗ @param event packe t∗ @return t e x t∗ @note : b t s t a c k t y p e T∗/

stat ic i n l i n e const char ∗a n c s s u b e v e n t c l i e n t n o t i f i c a t i o n g e t t e x t ( const uint8 t ∗ event) {return ( const char ∗) &event [ 7 ] ;

}#endif

#i fde f ENABLE BLE/∗∗∗ @br ie f Get f i e l d handle from event

ANCS SUBEVENT CLIENT DISCONNECTED∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e ta n c s s u b e v e n t c l i e n t d i s c o n n e c t e d g e t h a n d l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}#endif

/∗∗

Page 326: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

325

∗ @br ie f Get f i e l d a vd t p c i d from eventAVDTP SUBEVENT SIGNALING ACCEPT

∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a v d t p s u b e v e n t s i g n a l i n g a c c e p t g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING ACCEPT∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a v d t p s u b e v e n t s i g n a l i n g a c c e p t g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d s i g n a l i d e n t i f i e r from event

AVDTP SUBEVENT SIGNALING ACCEPT∗ @param event packe t∗ @return s i g n a l i d e n t i f i e r∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g a c c e p t g e t s i g n a l i d e n t i f i e r ( constuint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING REJECT∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a v d t p s u b e v e n t s i g n a l i n g r e j e c t g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING REJECT∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a v d t p s u b e v e n t s i g n a l i n g r e j e c t g e t l o c a l s e i d( const uint8 t ∗ event ) {

Page 327: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

326

return event [ 5 ] ;}/∗∗∗ @br ie f Get f i e l d s i g n a l i d e n t i f i e r from event

AVDTP SUBEVENT SIGNALING REJECT∗ @param event packe t∗ @return s i g n a l i d e n t i f i e r∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g r e j e c t g e t s i g n a l i d e n t i f i e r ( constuint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING GENERAL REJECT∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g g e n e r a l r e j e c t g e t a v d t p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING GENERAL REJECT∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g g e n e r a l r e j e c t g e t l o c a l s e i d ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d s i g n a l i d e n t i f i e r from event

AVDTP SUBEVENT SIGNALING GENERAL REJECT∗ @param event packe t∗ @return s i g n a l i d e n t i f i e r∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g g e n e r a l r e j e c t g e t s i g n a l i d e n t i f i e r (const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗

Page 328: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

327

∗ @br ie f Get f i e l d a vd t p c i d from eventAVDTP SUBEVENT SIGNALING CONNECTION ESTABLISHED

∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g c o n n e c t i o n e s t a b l i s h e d g e t a v d t p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

AVDTP SUBEVENT SIGNALING CONNECTION ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voida v d t p s u b e v e n t s i g n a l i n g c o n n e c t i o n e s t a b l i s h e d g e t b d a d d r (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 5 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

AVDTP SUBEVENT SIGNALING CONNECTION ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g c o n n e c t i o n e s t a b l i s h e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 1 1 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING CONNECTION RELEASED∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g c o n n e c t i o n r e l e a s e d g e t a v d t p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING SEP FOUND∗ @param event packe t∗ @return avd t p c i d

Page 329: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

328

∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g s e p f o u n d g e t a v d t p c i d ( const uint8 t ∗

event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING SEP FOUND∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g s e p f o u n d g e t r e m o t e s e i d ( const uint8 t∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d in u se from event

AVDTP SUBEVENT SIGNALING SEP FOUND∗ @param event packe t∗ @return in use∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a v d t p s u b e v e n t s i g n a l i n g s e p f o u n d g e t i n u s e (const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d media type from event

AVDTP SUBEVENT SIGNALING SEP FOUND∗ @param event packe t∗ @return media type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tav dtp su be ven t s i gn a l i ng s e p f o und ge t me d i a ty pe ( const uint8 t∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d s ep t ype from event

AVDTP SUBEVENT SIGNALING SEP FOUND∗ @param event packe t∗ @return s ep t ype∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g s e p f o u n d g e t s e p t y p e ( const uint8 t ∗event ) {return event [ 8 ] ;

}

Page 330: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

329

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d media type from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return media type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t m e d i a t y p e( const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d samp l ing f requency b i tmap from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return samp l ing f requency b i tmap

Page 331: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

330

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t s a m p l i n g f r e q u e n c y b i t m a p( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d channel mode bitmap from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return channel mode bitmap∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavdtp subeven t s i gna l i ng med ia codec sbc capab i l i t y ge t channe l mode b i tmap( const uint8 t ∗ event ) {return event [ 9 ] ;

}/∗∗∗ @br ie f Get f i e l d b l o c k l e n g t h b i tmap from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return b l o c k l e n g t h b i tmap∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t b l o c k l e n g t h b i t m a p( const uint8 t ∗ event ) {return event [ 1 0 ] ;

}/∗∗∗ @br ie f Get f i e l d subbands bi tmap from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return subbands bi tmap∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavdtp subeven t s i gna l i ng med i a codec sbc capab i l i t y g e t subbands b i tmap( const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d a l l o ca t i on me thod b i tmap from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return a l l o ca t i on me thod b i tmap∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t a l l o c a t i o n m e t h o d b i t m a p( const uint8 t ∗ event ) {return event [ 1 2 ] ;

Page 332: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

331

}/∗∗∗ @br ie f Get f i e l d m in b i t p o o l v a l u e from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return m in b i t p o o l v a l u e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t m i n b i t p o o l v a l u e( const uint8 t ∗ event ) {return event [ 1 3 ] ;

}/∗∗∗ @br ie f Get f i e l d max b i t poo l v a l u e from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CAPABILITY∗ @param event packe t∗ @return max b i t poo l v a l u e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c a p a b i l i t y g e t m a x b i t p o o l v a l u e( const uint8 t ∗ event ) {return event [ 1 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c a p a b i l i t y g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c a p a b i l i t y g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CAPABILITY∗ @param event packe t

Page 333: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

332

∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c a p a b i l i t y g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d media type from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CAPABILITY∗ @param event packe t∗ @return media type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c a p a b i l i t y g e t m e d i a t y p e( const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d media codec type from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CAPABILITY∗ @param event packe t∗ @return media codec type∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c a p a b i l i t y g e t m e d i a c o d e c t y p e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 8) ;

}/∗∗∗ @br ie f Get f i e l d med ia codec in fo rmat ion l en from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CAPABILITY∗ @param event packe t∗ @return med ia codec in fo rmat ion l en∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e inta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c a p a b i l i t y g e t m e d i a c o d e c i n f o r m a t i o n l e n( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 10) ;

}/∗∗∗ @br ie f Get f i e l d media codec in format ion from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CAPABILITY∗ @param event packe t∗ @return media codec in format ion∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗a v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c a p a b i l i t y g e t m e d i a c o d e c i n f o r m a t i o n( const uint8 t ∗ event ) {

Page 334: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

333

return &event [ 1 2 ] ;}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING MEDIA TRANSPORT CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a t r a n s p o r t c a p a b i l i t y g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING MEDIA TRANSPORT CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a t r a n s p o r t c a p a b i l i t y g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING MEDIA TRANSPORT CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a t r a n s p o r t c a p a b i l i t y g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING REPORTING CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g r e p o r t i n g c a p a b i l i t y g e t a v d t p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗

Page 335: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

334

∗ @br ie f Get f i e l d l o c a l s e i d from eventAVDTP SUBEVENT SIGNALING REPORTING CAPABILITY

∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g r e p o r t i n g c a p a b i l i t y g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING REPORTING CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g r e p o r t i n g c a p a b i l i t y g e t r e m o t e s e i d (const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING RECOVERY CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g r e c o v e r y c a p a b i l i t y g e t a v d t p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING RECOVERY CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g r e c o v e r y c a p a b i l i t y g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING RECOVERY CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1

Page 336: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

335

∗/stat ic i n l i n e uint8 t

a v d t p s u b e v e n t s i g n a l i n g r e c o v e r y c a p a b i l i t y g e t r e m o t e s e i d (const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d r e cov e r y t yp e from event

AVDTP SUBEVENT SIGNALING RECOVERY CAPABILITY∗ @param event packe t∗ @return r e cov e r y t yp e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g r e c o v e r y c a p a b i l i t y g e t r e c o v e r y t y p e (const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d maximum recovery window size from event

AVDTP SUBEVENT SIGNALING RECOVERY CAPABILITY∗ @param event packe t∗ @return maximum recovery window size∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavdtp subevent s i gna l i ng r e cove ry capab i l i t y ge t max imum recove ry w indow s i z e( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d maximum number media packets from event

AVDTP SUBEVENT SIGNALING RECOVERY CAPABILITY∗ @param event packe t∗ @return maximum number media packets∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavdtp subevent s igna l ing recovery capab i l i ty ge t max imum number med ia packet s( const uint8 t ∗ event ) {return event [ 9 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING CONTENT PROTECTION CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g c o n t e n t p r o t e c t i o n c a p a b i l i t y g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

Page 337: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

336

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING CONTENT PROTECTION CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g c o n t e n t p r o t e c t i o n c a p a b i l i t y g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING CONTENT PROTECTION CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g c o n t e n t p r o t e c t i o n c a p a b i l i t y g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d cp t ype from event

AVDTP SUBEVENT SIGNALING CONTENT PROTECTION CAPABILITY∗ @param event packe t∗ @return cp type∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g c o n t e n t p r o t e c t i o n c a p a b i l i t y g e t c p t y p e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 7) ;

}/∗∗∗ @br ie f Get f i e l d c p t y p e v a l u e l e n from event

AVDTP SUBEVENT SIGNALING CONTENT PROTECTION CAPABILITY∗ @param event packe t∗ @return c p t y p e v a l u e l e n∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e inta v d t p s u b e v e n t s i g n a l i n g c o n t e n t p r o t e c t i o n c a p a b i l i t y g e t c p t y p e v a l u e l e n( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d c p t y p e v a l u e from event

AVDTP SUBEVENT SIGNALING CONTENT PROTECTION CAPABILITY∗ @param event packe t∗ @return cp t y p e v a l u e

Page 338: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

337

∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗a v d t p s u b e v e n t s i g n a l i n g c o n t e n t p r o t e c t i o n c a p a b i l i t y g e t c p t y p e v a l u e( const uint8 t ∗ event ) {return &event [ 1 1 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t a v d t p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d f ragmenta t ion from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return fragmentat ion∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t f r a g m e n t a t i o n( const uint8 t ∗ event ) {

Page 339: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

338

return event [ 7 ] ;}/∗∗∗ @br ie f Get f i e l d t r an s p o r t i d e n t i f i e r s num from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return t r an s p o r t i d e n t i f i e r s num∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t t r a n s p o r t i d e n t i f i e r s n u m( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d t r a n s p o r t s e s s i o n i d e n t i f i e r 1 from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return t r a n s p o r t s e s s i o n i d e n t i f i e r 1∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t t r a n s p o r t s e s s i o n i d e n t i f i e r 1( const uint8 t ∗ event ) {return event [ 9 ] ;

}/∗∗∗ @br ie f Get f i e l d t r a n s p o r t s e s s i o n i d e n t i f i e r 2 from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return t r a n s p o r t s e s s i o n i d e n t i f i e r 2∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t t r a n s p o r t s e s s i o n i d e n t i f i e r 2( const uint8 t ∗ event ) {return event [ 1 0 ] ;

}/∗∗∗ @br ie f Get f i e l d t r a n s p o r t s e s s i o n i d e n t i f i e r 3 from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return t r a n s p o r t s e s s i o n i d e n t i f i e r 3∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t t r a n s p o r t s e s s i o n i d e n t i f i e r 3( const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d t c i d 1 from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t

Page 340: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

339

∗ @return t c i d 1∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t t c i d 1 (const uint8 t ∗ event ) {return event [ 1 2 ] ;

}/∗∗∗ @br ie f Get f i e l d t c i d 2 from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return t c i d 2∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t t c i d 2 (const uint8 t ∗ event ) {return event [ 1 3 ] ;

}/∗∗∗ @br ie f Get f i e l d t c i d 3 from event

AVDTP SUBEVENT SIGNALING MULTIPLEXING CAPABILITY∗ @param event packe t∗ @return t c i d 3∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m u l t i p l e x i n g c a p a b i l i t y g e t t c i d 3 (const uint8 t ∗ event ) {return event [ 1 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING DELAY REPORTING CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g d e l a y r e p o r t i n g c a p a b i l i t y g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING DELAY REPORTING CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

Page 341: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

340

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g d e l a y r e p o r t i n g c a p a b i l i t y g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING DELAY REPORTING CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g d e l a y r e p o r t i n g c a p a b i l i t y g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING HEADER COMPRESSION CAPABILITY∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g h e a d e r c o m p r e s s i o n c a p a b i l i t y g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING HEADER COMPRESSION CAPABILITY∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g h e a d e r c o m p r e s s i o n c a p a b i l i t y g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING HEADER COMPRESSION CAPABILITY∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g h e a d e r c o m p r e s s i o n c a p a b i l i t y g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}

Page 342: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

341

/∗∗∗ @br ie f Get f i e l d back ch from event

AVDTP SUBEVENT SIGNALING HEADER COMPRESSION CAPABILITY∗ @param event packe t∗ @return back ch∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g h e a d e r c o m p r e s s i o n c a p a b i l i t y g e t b a c k c h( const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d media from event

AVDTP SUBEVENT SIGNALING HEADER COMPRESSION CAPABILITY∗ @param event packe t∗ @return media∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g h e a d e r c o m p r e s s i o n c a p a b i l i t y g e t m e d i a( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d recovery from event

AVDTP SUBEVENT SIGNALING HEADER COMPRESSION CAPABILITY∗ @param event packe t∗ @return recovery∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g h e a d e r c o m p r e s s i o n c a p a b i l i t y g e t r e c o v e r y( const uint8 t ∗ event ) {return event [ 9 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return l o c a l s e i d

Page 343: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

342

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t l o c a l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d r e con f i gu r e from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return r e con f i gu r e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t r e c o n f i g u r e( const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d media type from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return media type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t m e d i a t y p e( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d samp l ing f requency from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return samp l ing f requency∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t s a m p l i n g f r e q u e n c y( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

Page 344: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

343

}/∗∗∗ @br ie f Get f i e l d channel mode from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return channel mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta vd tp s ub ev e n t s i g na l i n g m ed i a c od ec s bc c on f i g u r a t i on g e t c ha nn e l m od e( const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d num channels from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return num channels∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tav d tp s ub ev en t s i g na l i ng m ed i a c od ec s bc c on f i gu ra t i on g e t nu m c ha nn e l s( const uint8 t ∗ event ) {return event [ 1 2 ] ;

}/∗∗∗ @br ie f Get f i e l d b l o c k l e n g t h from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return b l o c k l e n g t h∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t b l o c k l e n g t h( const uint8 t ∗ event ) {return event [ 1 3 ] ;

}/∗∗∗ @br ie f Get f i e l d subbands from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return subbands∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t s u b b a n d s( const uint8 t ∗ event ) {return event [ 1 4 ] ;

}/∗∗∗ @br ie f Get f i e l d a l l o ca t i on me thod from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return a l l o ca t i on me thod

Page 345: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

344

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t a l l o c a t i o n m e t h o d( const uint8 t ∗ event ) {return event [ 1 5 ] ;

}/∗∗∗ @br ie f Get f i e l d m in b i t p o o l v a l u e from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return m in b i t p o o l v a l u e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t m i n b i t p o o l v a l u e( const uint8 t ∗ event ) {return event [ 1 6 ] ;

}/∗∗∗ @br ie f Get f i e l d max b i t poo l v a l u e from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return max b i t poo l v a l u e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t m a x b i t p o o l v a l u e( const uint8 t ∗ event ) {return event [ 1 7 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t a v d t p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t l o c a l s e i d( const uint8 t ∗ event ) {

Page 346: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

345

return event [ 5 ] ;}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t r e m o t e s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d r e con f i gu r e from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return r e con f i gu r e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t r e c o n f i g u r e( const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d media type from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return media type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a t y p e( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d media codec type from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return media codec type∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a c o d e c t y p e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d med ia codec in fo rmat ion l en from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t

Page 347: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

346

∗ @return med ia codec in fo rmat ion l en∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e inta v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a c o d e c i n f o r m a t i o n l e n( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 11) ;

}/∗∗∗ @br ie f Get f i e l d media codec in format ion from event

AVDTP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return media codec in format ion∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗a v d t p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a c o d e c i n f o r m a t i o n( const uint8 t ∗ event ) {return &event [ 1 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT STREAMING CONNECTION ESTABLISHED∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s t r e a m i n g c o n n e c t i o n e s t a b l i s h e d g e t a v d t p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

AVDTP SUBEVENT STREAMING CONNECTION ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidav dtp su beve n t s t r eam ing co nnec t i o n e s t ab l i sh ed ge t bd ad dr (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 5 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT STREAMING CONNECTION ESTABLISHED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

Page 348: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

347

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s t r e a m i n g c o n n e c t i o n e s t a b l i s h e d g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT STREAMING CONNECTION ESTABLISHED∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s t r e a m i n g c o n n e c t i o n e s t a b l i s h e d g e t r e m o t e s e i d (const uint8 t ∗ event ) {return event [ 1 2 ] ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

AVDTP SUBEVENT STREAMING CONNECTION ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s t r e a m i n g c o n n e c t i o n e s t a b l i s h e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 1 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT STREAMING CONNECTION RELEASED∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s t r e a m i n g c o n n e c t i o n r e l e a s e d g e t a v d t p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT STREAMING CONNECTION RELEASED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s t r e a m i n g c o n n e c t i o n r e l e a s e d g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}

Page 349: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

348

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT STREAMING CAN SENDMEDIA PACKET NOW∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tavdtp subevent s t r eaming can send med ia packet now get avdtp c id( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT STREAMING CAN SENDMEDIA PACKET NOW∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavdtp subeven t s t r eaming can s end med ia packe t now ge t l o ca l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d sequence number from event

AVDTP SUBEVENT STREAMING CAN SENDMEDIA PACKET NOW∗ @param event packe t∗ @return sequence number∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tavdtp subevent st reaming can send media packet now get sequence number( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING CAPABILITY DONE∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g c a p a b i l i t y d o n e g e t a v d t p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

AVDTP SUBEVENT SIGNALING CAPABILITY DONE∗ @param event packe t

Page 350: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

349

∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g c a p a b i l i t y d o n e g e t l o c a l s e i d ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

AVDTP SUBEVENT SIGNALING CAPABILITY DONE∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v d t p s u b e v e n t s i g n a l i n g c a p a b i l i t y d o n e g e t r e m o t e s e i d ( constuint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a vd t p c i d from event

AVDTP SUBEVENT SIGNALING SEP DICOVERY DONE∗ @param event packe t∗ @return avd t p c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v d t p s u b e v e n t s i g n a l i n g s e p d i c o v e r y d o n e g e t a v d t p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT STREAMING CAN SEND MEDIA PACKET NOW∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta2dp subevent s t reaming can send med ia packet now get a2dp c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT STREAMING CAN SEND MEDIA PACKET NOW∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

Page 351: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

350

stat ic i n l i n e uint8 ta2dp subeven t s t r eaming can s end med ia packe t now ge t l o ca l s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t a 2 d p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d i n t s e i d from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return i n t s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t i n t s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d a cp s e i d from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return acp s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t a c p s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d r e con f i gu r e from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return r e con f i gu r e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t r e c o n f i g u r e( const uint8 t ∗ event ) {return event [ 7 ] ;

}

Page 352: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

351

/∗∗∗ @br ie f Get f i e l d media type from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return media type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t m e d i a t y p e( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d samp l ing f requency from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return samp l ing f requency∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t s a m p l i n g f r e q u e n c y( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d channel mode from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return channel mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta2dp subeven t s i gna l i ng med i a codec sbc con f i gu ra t i on ge t channe l mode( const uint8 t ∗ event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d num channels from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return num channels∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta2dp subeven t s i gna l i ng med i a codec sbc con f i gu ra t i on ge t num channe l s( const uint8 t ∗ event ) {return event [ 1 2 ] ;

}/∗∗∗ @br ie f Get f i e l d b l o c k l e n g t h from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return b l o c k l e n g t h∗ @note : b t s t a c k t y p e 1

Page 353: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

352

∗/stat ic i n l i n e uint8 t

a 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t b l o c k l e n g t h( const uint8 t ∗ event ) {return event [ 1 3 ] ;

}/∗∗∗ @br ie f Get f i e l d subbands from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return subbands∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t s u b b a n d s( const uint8 t ∗ event ) {return event [ 1 4 ] ;

}/∗∗∗ @br ie f Get f i e l d a l l o ca t i on me thod from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return a l l o ca t i on me thod∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t a l l o c a t i o n m e t h o d( const uint8 t ∗ event ) {return event [ 1 5 ] ;

}/∗∗∗ @br ie f Get f i e l d m in b i t p o o l v a l u e from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return m in b i t p o o l v a l u e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t m i n b i t p o o l v a l u e( const uint8 t ∗ event ) {return event [ 1 6 ] ;

}/∗∗∗ @br ie f Get f i e l d max b i t poo l v a l u e from event

A2DP SUBEVENT SIGNALING MEDIA CODEC SBC CONFIGURATION∗ @param event packe t∗ @return max b i t poo l v a l u e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c s b c c o n f i g u r a t i o n g e t m a x b i t p o o l v a l u e( const uint8 t ∗ event ) {return event [ 1 7 ] ;

}

Page 354: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

353

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t a 2 d p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d i n t s e i d from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return i n t s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t i n t s e i d( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d a cp s e i d from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return acp s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t a c p s e i d( const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d r e con f i gu r e from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return r e con f i gu r e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t r e c o n f i g u r e( const uint8 t ∗ event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d media type from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return media type

Page 355: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

354

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a t y p e( const uint8 t ∗ event ) {return event [ 8 ] ;

}/∗∗∗ @br ie f Get f i e l d media codec type from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return media codec type∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a c o d e c t y p e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}/∗∗∗ @br ie f Get f i e l d med ia codec in fo rmat ion l en from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return med ia codec in fo rmat ion l en∗ @note : b t s t a c k t y p e L∗/

stat ic i n l i n e inta 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a c o d e c i n f o r m a t i o n l e n( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 11) ;

}/∗∗∗ @br ie f Get f i e l d media codec in format ion from event

A2DP SUBEVENT SIGNALING MEDIA CODEC OTHER CONFIGURATION∗ @param event packe t∗ @return media codec in format ion∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗a 2 d p s u b e v e n t s i g n a l i n g m e d i a c o d e c o t h e r c o n f i g u r a t i o n g e t m e d i a c o d e c i n f o r m a t i o n( const uint8 t ∗ event ) {return &event [ 1 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT STREAM ESTABLISHED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a 2 d p s u b e v e n t s t r e a m e s t a b l i s h e d g e t a 2 d p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

Page 356: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

355

}/∗∗∗ @br ie f Get f i e l d bd addr from event

A2DP SUBEVENT STREAM ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void a2dp subevent s t r eam es tab l i shed ge t bd addr (const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 5 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT STREAM ESTABLISHED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s t r e a m e s t a b l i s h e d g e t l o c a l s e i d ( const uint8 t ∗event ) {return event [ 1 1 ] ;

}/∗∗∗ @br ie f Get f i e l d remote se id from event

A2DP SUBEVENT STREAM ESTABLISHED∗ @param event packe t∗ @return remote se id∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s t r e a m e s t a b l i s h e d g e t r e m o t e s e i d ( const uint8 t ∗

event ) {return event [ 1 2 ] ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

A2DP SUBEVENT STREAM ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a 2 d p s u b e v e n t s t r e a m e s t a b l i s h e d g e t s t a t u s (const uint8 t ∗ event ) {return event [ 1 3 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event A2DP SUBEVENT STREAM STARTED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

Page 357: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

356

stat ic i n l i n e uint16 t a2dp subeven t s t r eam sta r t ed ge t a2dp c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT STREAM STARTED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a 2 d p s u b e v e n t s t r e a m s t a r t e d g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT STREAM SUSPENDED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a2dp subevent s t ream suspended get a2dp c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT STREAM SUSPENDED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a 2 d p s u b e v e n t s t r e a m s u s p e n d e d g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event A2DP SUBEVENT STREAM STOPPED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a2dp subevent s t r eam stopped get a2dp c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT STREAM STOPPED∗ @param event packe t∗ @return l o c a l s e i d

Page 358: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

357

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a 2 d p s u b e v e n t s t r e a m s t o p p e d g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT STREAM RELEASED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a2dp subeven t s t r eam re l e a s ed ge t a2dp c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT STREAM RELEASED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a 2 d p s u b e v e n t s t r e a m r e l e a s e d g e t l o c a l s e i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENTCOMMANDACCEPTED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a2dp subevent command accepted get a2dp cid (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENTCOMMANDACCEPTED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a2dp subevent command accepted get loca l s e id (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗

Page 359: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

358

∗ @br ie f Get f i e l d s i g n a l i d e n t i f i e r from eventA2DP SUBEVENTCOMMANDACCEPTED

∗ @param event packe t∗ @return s i g n a l i d e n t i f i e r∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta2dp subeven t command acc ep t ed ge t s i gna l i d en t i f i e r ( constuint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT COMMANDREJECTED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a2dp subevent command re jected get a2dp c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT COMMANDREJECTED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a2dp subevent command re j e c t ed ge t l o ca l s e id (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d s i g n a l i d e n t i f i e r from event

A2DP SUBEVENT COMMANDREJECTED∗ @param event packe t∗ @return s i g n a l i d e n t i f i e r∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t c o m m a n d r e j e c t e d g e t s i g n a l i d e n t i f i e r ( constuint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT SIGNALING CONNECTION ESTABLISHED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

Page 360: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

359

stat ic i n l i n e uint16 ta 2 d p s u b e v e n t s i g n a l i n g c o n n e c t i o n e s t a b l i s h e d g e t a 2 d p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

A2DP SUBEVENT SIGNALING CONNECTION ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voida 2 d p s u b e v e n t s i g n a l i n g c o n n e c t i o n e s t a b l i s h e d g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 5 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

A2DP SUBEVENT SIGNALING CONNECTION ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s i g n a l i n g c o n n e c t i o n e s t a b l i s h e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 1 1 ] ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT SIGNALING CONNECTION RELEASED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta 2 d p s u b e v e n t s i g n a l i n g c o n n e c t i o n r e l e a s e d g e t a 2 d p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d a2dp c id from event

A2DP SUBEVENT STREAM RECONFIGURED∗ @param event packe t∗ @return a2dp c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta2dp subeven t s t r eam recon f i gu r ed ge t a2dp c id ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

Page 361: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

360

}/∗∗∗ @br ie f Get f i e l d l o c a l s e i d from event

A2DP SUBEVENT STREAM RECONFIGURED∗ @param event packe t∗ @return l o c a l s e i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta 2 d p s u b e v e n t s t r e a m r e c o n f i g u r e d g e t l o c a l s e i d ( const uint8 t ∗

event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

A2DP SUBEVENT STREAM RECONFIGURED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a 2 d p s u b e v e n t s t r e a m r e c o n f i g u r e d g e t s t a t u s (const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

AVRCP SUBEVENT CONNECTION ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t c o n n e c t i o n e s t a b l i s h e d g e t s t a t u s ( const uint8 t ∗

event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

AVRCP SUBEVENT CONNECTION ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void a v r c p s u b e v e n t c o n n e c t i o n e s t a b l i s h e d g e t b d a d d r( const uint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 4 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT CONNECTION ESTABLISHED∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2

Page 362: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

361

∗/stat ic i n l i n e uint16 t

a v r c p s u b e v e n t c o n n e c t i o n e s t a b l i s h e d g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 10) ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT CONNECTION RELEASED∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t c o n n e c t i o n r e l e a s e d g e t a v r c p c i d ( const uint8 t ∗

event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT SHUFFLE AND REPEAT MODE∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t s h u f f l e a n d r e p e a t m o d e g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT SHUFFLE AND REPEAT MODE∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent shuf f l e and repeat mode get command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d repeat mode from event

AVRCP SUBEVENT SHUFFLE AND REPEAT MODE∗ @param event packe t∗ @return repeat mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent shu f f l e and repea t mode ge t r epea t mode ( constuint8 t ∗ event ) {

Page 363: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

362

return event [ 6 ] ;}/∗∗∗ @br ie f Get f i e l d shu f f l e mode from event

AVRCP SUBEVENT SHUFFLE AND REPEAT MODE∗ @param event packe t∗ @return shu f f l e mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t s h u f f l e a n d r e p e a t m o d e g e t s h u f f l e m o d e ( constuint8 t ∗ event ) {return event [ 7 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event AVRCP SUBEVENT PLAY STATUS∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a v r c p s u b e v e n t p l a y s t a t u s g e t a v r c p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT PLAY STATUS∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t avrcp subevent p lay status get command type (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d s ong l eng t h from event

AVRCP SUBEVENT PLAY STATUS∗ @param event packe t∗ @return song l eng t h∗ @note : b t s t a c k t y p e 4∗/

stat ic i n l i n e uint32 t a v r c p s u b e v e n t p l a y s t a t u s g e t s o n g l e n g t h (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 6) ;

}/∗∗∗ @br ie f Get f i e l d s on g po s i t i on from event

AVRCP SUBEVENT PLAY STATUS∗ @param event packe t∗ @return s ong po s i t i on∗ @note : b t s t a c k t y p e 4∗/

Page 364: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

363

stat ic i n l i n e uint32 t a v r c p s u b e v e n t p l a y s t a t u s g e t s o n g p o s i t i o n (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 10) ;

}/∗∗∗ @br ie f Get f i e l d p l a y s t a t u s from event

AVRCP SUBEVENT PLAY STATUS∗ @param event packe t∗ @return p l a y s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a v r c p s u b e v e n t p l a y s t a t u s g e t p l a y s t a t u s (const uint8 t ∗ event ) {return event [ 1 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOTIFICATION PLAYBACK STATUS CHANGED∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o t i f i c a t i o n p l a y b a c k s t a t u s c h a n g e d g e t a v r c p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOTIFICATION PLAYBACK STATUS CHANGED∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent not i f i c a t i on p layback s ta tus changed ge t command type( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d p l a y s t a t u s from event

AVRCP SUBEVENT NOTIFICATION PLAYBACK STATUS CHANGED∗ @param event packe t∗ @return p l a y s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t n o t i f i c a t i o n p l a y b a c k s t a t u s c h a n g e d g e t p l a y s t a t u s( const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗

Page 365: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

364

∗ @br ie f Get f i e l d a v r cp c i d from eventAVRCP SUBEVENT NOTIFICATION TRACK CHANGED

∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o t i f i c a t i o n t r a c k c h a n g e d g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOTIFICATION TRACK CHANGED∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent not i f i ca t i on t rack changed ge t command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOTIFICATION NOW PLAYING CONTENT CHANGED∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o t i f i c a t i o n n o w p l a y i n g c o n t e n t c h a n g e d g e t a v r c p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOTIFICATION NOW PLAYING CONTENT CHANGED∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent not i f i ca t i on now play ing content changed get command type( const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOTIFICATION AVAILABLE PLAYERS CHANGED∗ @param event packe t∗ @return av r cp c i d

Page 366: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

365

∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o t i f i c a t i o n a v a i l a b l e p l a y e r s c h a n g e d g e t a v r c p c i d( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOTIFICATION AVAILABLE PLAYERS CHANGED∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t n o t i f i c a t i o n a v a i l a b l e p l a y e r s c h a n g e d g e t c o m m a n d t y p e( const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOTIFICATION VOLUME CHANGED∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o t i f i c a t i o n v o l u m e c h a n g e d g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOTIFICATION VOLUME CHANGED∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent not i f i ca t ion vo lume changed get command type (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d ab so lu t e vo lume from event

AVRCP SUBEVENT NOTIFICATION VOLUME CHANGED∗ @param event packe t∗ @return abso lu t e vo lume∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tav r cp subeven t no t i f i c a t i on vo lume changed ge t ab so lu t e vo lume (const uint8 t ∗ event ) {

Page 367: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

366

return event [ 6 ] ;}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT SET ABSOLUTE VOLUME RESPONSE∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t s e t a b s o l u t e v o l u m e r e s p o n s e g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT SET ABSOLUTE VOLUME RESPONSE∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent se t abso lute vo lume response get command type (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d ab so lu t e vo lume from event

AVRCP SUBEVENT SET ABSOLUTE VOLUME RESPONSE∗ @param event packe t∗ @return abso lu t e vo lume∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u be v e n t s e t a b so l u t e v o lu m e r e sp o n s e g e t a b so l u t e v o lu m e (const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT ENABLE NOTIFICATION COMPLETE∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t e n a b l e n o t i f i c a t i o n c o m p l e t e g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗

Page 368: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

367

∗ @br ie f Get f i e l d command type from eventAVRCP SUBEVENT ENABLE NOTIFICATION COMPLETE

∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent enab l e no t i f i c a t i on comple t e ge t command type (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d n o t i f i c a t i o n i d from event

AVRCP SUBEVENT ENABLE NOTIFICATION COMPLETE∗ @param event packe t∗ @return n o t i f i c a t i o n i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t e n a b l e n o t i f i c a t i o n c o m p l e t e g e t n o t i f i c a t i o n i d (const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT OPERATION START∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a v r c p s u b e v e n t o p e r a t i o n s t a r t g e t a v r c p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT OPERATION START∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent operat ion s ta r t ge t command type ( const uint8 t ∗event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d op e r a t i on i d from event

AVRCP SUBEVENT OPERATION START∗ @param event packe t∗ @return ope r a t i on i d∗ @note : b t s t a c k t y p e 1∗/

Page 369: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

368

stat ic i n l i n e uint8 ta v r c p s u b e v e n t o p e r a t i o n s t a r t g e t o p e r a t i o n i d ( const uint8 t ∗event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT OPERATION COMPLETE∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t o p e r a t i o n c o m p l e t e g e t a v r c p c i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT OPERATION COMPLETE∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent operat ion complete get command type ( const uint8 t∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d op e r a t i on i d from event

AVRCP SUBEVENT OPERATION COMPLETE∗ @param event packe t∗ @return ope r a t i on i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t o p e r a t i o n c o m p l e t e g e t o p e r a t i o n i d ( const uint8 t∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT PLAYER APPLICATION VALUE RESPONSE∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t p l a y e r a p p l i c a t i o n v a l u e r e s p o n s e g e t a v r c p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

Page 370: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

369

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT PLAYER APPLICATION VALUE RESPONSE∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent p l aye r app l i c a t i on va lue r e sponse ge t command type( const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT COMPANY IDS QUERY∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tavrcp subevent company id s query ge t avrcp c id ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT EVENT IDS QUERY∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a v r c p s u b e v e n t e v e n t i d s q u e r y g e t a v r c p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT PLAY STATUS QUERY∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t p l a y s t a t u s q u e r y g e t a v r c p c i d ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event AVRCP SUBEVENT OPERATION

Page 371: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

370

∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t a v r c p s u b e v e n t o p e r a t i o n g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d op e r a t i on i d from event AVRCP SUBEVENT OPERATION∗ @param event packe t∗ @return ope r a t i on i d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a v r c p s u b e v e n t o p e r a t i o n g e t o p e r a t i o n i d (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d operands l eng th from event

AVRCP SUBEVENT OPERATION∗ @param event packe t∗ @return operands l eng th∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t a v r c p s u be v e n t o p e ra t i o n g e t o p e r a n d s l e n g t h (const uint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d operand from event AVRCP SUBEVENT OPERATION∗ @param event packe t∗ @return operand∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t avrcp subevent ope ra t i on ge t ope rand ( constuint8 t ∗ event ) {return event [ 7 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING TRACK INFO∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o w p l a y i n g t r a c k i n f o g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗

Page 372: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

371

∗ @br ie f Get f i e l d command type from eventAVRCP SUBEVENT NOW PLAYING TRACK INFO

∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent now play ing t rack in fo get command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d t rack from event

AVRCP SUBEVENT NOW PLAYING TRACK INFO∗ @param event packe t∗ @return t rack∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t n o w p l a y i n g t r a c k i n f o g e t t r a c k ( const uint8 t ∗event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING TOTAL TRACKS INFO∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o w p l a y i n g t o t a l t r a c k s i n f o g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOW PLAYING TOTAL TRACKS INFO∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent now p lay ing to ta l t r a ck s in f o ge t command type (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d t o t a l t r a c k s from event

AVRCP SUBEVENT NOW PLAYING TOTAL TRACKS INFO∗ @param event packe t∗ @return t o t a l t r a c k s∗ @note : b t s t a c k t y p e 1

Page 373: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

372

∗/stat ic i n l i n e uint8 t

a v r c p s u b e v e n t n o w p l a y i n g t o t a l t r a c k s i n f o g e t t o t a l t r a c k s (const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING SONG LENGTH MS INFO∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o w p l a y i n g s o n g l e n g t h m s i n f o g e t a v r c p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOW PLAYING SONG LENGTH MS INFO∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent now play ing song length ms in fo get command type (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d s ong l eng t h from event

AVRCP SUBEVENT NOW PLAYING SONG LENGTH MS INFO∗ @param event packe t∗ @return song l eng t h∗ @note : b t s t a c k t y p e 4∗/

stat ic i n l i n e uint32 ta v r c p s u b e v e n t n o w p l a y i n g s o n g l e n g t h m s i n f o g e t s o n g l e n g t h (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 6) ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING TITLE INFO∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o w p l a y i n g t i t l e i n f o g e t a v r c p c i d ( constuint8 t ∗ event ) {

Page 374: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

373

return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOW PLAYING TITLE INFO∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent now p lay ing t i t l e i n f o ge t command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d v a l u e l e n from event

AVRCP SUBEVENT NOW PLAYING TITLE INFO∗ @param event packe t∗ @return v a l u e l e n∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e inta v r c p s u b e v e n t n o w p l a y i n g t i t l e i n f o g e t v a l u e l e n ( constuint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d va lue from event

AVRCP SUBEVENT NOW PLAYING TITLE INFO∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗a v r c p s u b e v e n t n o w p l a y i n g t i t l e i n f o g e t v a l u e ( const uint8 t ∗event ) {return &event [ 7 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING ARTIST INFO∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o w p l a y i n g a r t i s t i n f o g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOW PLAYING ARTIST INFO

Page 375: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

374

∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent now p lay ing ar t i s t in f o ge t command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d v a l u e l e n from event

AVRCP SUBEVENT NOW PLAYING ARTIST INFO∗ @param event packe t∗ @return v a l u e l e n∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e inta v r c p s u b e v e n t n o w p l a y i n g a r t i s t i n f o g e t v a l u e l e n ( constuint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d va lue from event

AVRCP SUBEVENT NOW PLAYING ARTIST INFO∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗a v r c p s u b e v e n t n o w p l a y i n g a r t i s t i n f o g e t v a l u e ( const uint8 t ∗event ) {return &event [ 7 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING ALBUM INFO∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tav r cp subeven t now p lay ing a lbum in fo ge t av r cp c id ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOW PLAYING ALBUM INFO∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

Page 376: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

375

stat ic i n l i n e uint8 tavrcp subevent now play ing a lbum info get command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d v a l u e l e n from event

AVRCP SUBEVENT NOW PLAYING ALBUM INFO∗ @param event packe t∗ @return v a l u e l e n∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e intav r c p sube ven t now p lay ing a lbu m in f o ge t va lu e l en ( constuint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d va lue from event

AVRCP SUBEVENT NOW PLAYING ALBUM INFO∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗avrcp subevent now p lay ing a lbum in fo ge t va lue ( const uint8 t ∗event ) {return &event [ 7 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING GENRE INFO∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o w p l a y i n g g e n r e i n f o g e t a v r c p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOW PLAYING GENRE INFO∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent now play ing genre in fo get command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}

Page 377: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

376

/∗∗∗ @br ie f Get f i e l d v a l u e l e n from event

AVRCP SUBEVENT NOW PLAYING GENRE INFO∗ @param event packe t∗ @return v a l u e l e n∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e inta v r c p s u b e v e n t n o w p l a y i n g g e n r e i n f o g e t v a l u e l e n ( constuint8 t ∗ event ) {return event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d va lue from event

AVRCP SUBEVENT NOW PLAYING GENRE INFO∗ @param event packe t∗ @return va lue∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗a v r c p s u b e v e n t n o w p l a y i n g g e n r e i n f o g e t v a l u e ( const uint8 t ∗event ) {return &event [ 7 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOW PLAYING INFO DONE∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o w p l a y i n g i n f o d o n e g e t a v r c p c i d ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOW PLAYING INFO DONE∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent now play ing in fo done get command type ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

AVRCP SUBEVENT NOW PLAYING INFO DONE∗ @param event packe t∗ @return s t a t u s

Page 378: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

377

∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t n o w p l a y i n g i n f o d o n e g e t s t a t u s ( const uint8 t ∗event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d bd addr from event

AVRCP SUBEVENT INCOMING BROWSING CONNECTION∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e voidavrcp subevent incoming brows ing connec t i on ge t bd addr ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 3 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d b rows ing c i d from event

AVRCP SUBEVENT INCOMING BROWSING CONNECTION∗ @param event packe t∗ @return brows ing c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tavrcp subevent incoming brows ing connec t i on ge t b rows ing c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 9) ;

}

/∗∗∗ @br ie f Get f i e l d s t a t u s from event

AVRCP SUBEVENT BROWSING CONNECTION ESTABLISHED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t b r o w s i n g c o n n e c t i o n e s t a b l i s h e d g e t s t a t u s ( constuint8 t ∗ event ) {return event [ 3 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

AVRCP SUBEVENT BROWSING CONNECTION ESTABLISHED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

Page 379: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

378

stat ic i n l i n e voida v r c p s u b e ve n t b r o ws i n g c o n ne c t i o n e s t a b l i s h e d g e t b d a d d r ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 4 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d b rows ing c i d from event

AVRCP SUBEVENT BROWSING CONNECTION ESTABLISHED∗ @param event packe t∗ @return brows ing c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t b r o w s i n g c o n n e c t i o n e s t a b l i s h e d g e t b r o w s i n g c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 10) ;

}

/∗∗∗ @br ie f Get f i e l d b rows ing c i d from event

AVRCP SUBEVENT BROWSING CONNECTION RELEASED∗ @param event packe t∗ @return brows ing c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t b r o w s i n g c o n n e c t i o n r e l e a s e d g e t b r o w s i n g c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d b rows ing c i d from event

AVRCP SUBEVENT BROWSING DONE∗ @param event packe t∗ @return brows ing c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t avrcp subevent brows ing done ge t brows ing c id( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d u id coun te r from event

AVRCP SUBEVENT BROWSING DONE∗ @param event packe t∗ @return u id coun te r∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t avrcp subevent brows ing done ge t u id counte r (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 5) ;

}/∗∗

Page 380: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

379

∗ @br ie f Get f i e l d b r ows i n g s t a t u s from eventAVRCP SUBEVENT BROWSING DONE

∗ @param event packe t∗ @return b rows in g s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent brows ing done ge t b rows ing s ta tu s ( const uint8 t ∗

event ) {return event [ 7 ] ;

}/∗∗∗ @br ie f Get f i e l d b l u e t o o t h s t a t u s from event

AVRCP SUBEVENT BROWSING DONE∗ @param event packe t∗ @return b l u e t o o t h s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tav r cp subeven t b rows ing done ge t b lu e too th s ta tu s ( const uint8 t∗ event ) {return event [ 8 ] ;

}

/∗∗∗ @br ie f Get f i e l d b rows ing c i d from event

AVRCP SUBEVENT BROWSING GET FOLDER ITEMS∗ @param event packe t∗ @return brows ing c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t b r o w s i n g g e t f o l d e r i t e m s g e t b r o w s i n g c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d scope from event

AVRCP SUBEVENT BROWSING GET FOLDER ITEMS∗ @param event packe t∗ @return scope∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 ta v r c p s u b e v e n t b r o w s i n g g e t f o l d e r i t e m s g e t s c o p e ( const uint8 t∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d a t t r b i tmap from event

AVRCP SUBEVENT BROWSING GET FOLDER ITEMS∗ @param event packe t∗ @return a t t r b i tmap∗ @note : b t s t a c k t y p e 4

Page 381: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

380

∗/stat ic i n l i n e uint32 t

a v r c p s u b e v e n t b r o w s i n g g e t f o l d e r i t e m s g e t a t t r b i t m a p ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 6) ;

}

/∗∗∗ @br ie f Get f i e l d b rows ing c i d from event

AVRCP SUBEVENT BROWSING GET TOTAL NUM ITEMS∗ @param event packe t∗ @return brows ing c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tav r cp subeven t b rows ing ge t t o ta l num i t ems ge t b rows ing c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d scope from event

AVRCP SUBEVENT BROWSING GET TOTAL NUM ITEMS∗ @param event packe t∗ @return scope∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tav r cp subeven t b rows ing ge t t o ta l num i t ems ge t s cope ( constuint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d a v r cp c i d from event

AVRCP SUBEVENT NOTIFICATION PLAYBACK POS CHANGED∗ @param event packe t∗ @return av r cp c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 ta v r c p s u b e v e n t n o t i f i c a t i o n p l a y b a c k p o s c h a n g e d g e t a v r c p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d command type from event

AVRCP SUBEVENT NOTIFICATION PLAYBACK POS CHANGED∗ @param event packe t∗ @return command type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tavrcp subevent not i f i ca t i on p layback pos changed get command type( const uint8 t ∗ event ) {

Page 382: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

381

return event [ 5 ] ;}/∗∗∗ @br ie f Get f i e l d p l a y back po s i t i on ms from event

AVRCP SUBEVENT NOTIFICATION PLAYBACK POS CHANGED∗ @param event packe t∗ @return p l a y back po s i t i on ms∗ @note : b t s t a c k t y p e 4∗/

stat ic i n l i n e uint32 ta v r c p s u b e v e n t n o t i f i c a t i o n p l a y b a c k p o s c h a n g e d g e t p l a y b a c k p o s i t i o n m s( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 3 2 ( event , 6) ;

}

/∗∗∗ @br ie f Get f i e l d goep c id from event

GOEP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t goep subevent connec t i on opened ge t goep c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

GOEP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t goep subeven t connec t i on opened ge t s t a tu s (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

GOEP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void goep subevent connect ion opened get bd addr ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 6 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d con hand le from event

GOEP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e H

Page 383: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

382

∗/stat ic i n l i n e h c i c o n h a n d l e t

goep subevent connec t i on opened ge t con hand l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 12) ;

}/∗∗∗ @br ie f Get f i e l d incoming from event

GOEP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return incoming∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t goep subevent connect ion opened get incoming (const uint8 t ∗ event ) {return event [ 1 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d goep c id from event

GOEP SUBEVENT CONNECTION CLOSED∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t g o e p s u b e v e n t c o n n e c t i o n c l o s e d g e t g o e p c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d goep c id from event GOEP SUBEVENT CAN SEND NOW∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t goep subevent can send now get goep c id ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d pbap c id from event

PBAP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return pbap c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t pbap subevent connect ion opened get pbap c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗

Page 384: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

383

∗ @br ie f Get f i e l d s t a t u s from eventPBAP SUBEVENT CONNECTION OPENED

∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t pbap subevent connec t i on opened ge t s ta tus (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

PBAP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void pbap subevent connect ion opened get bd addr ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 6 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d con hand le from event

PBAP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e tpbap subevent connect ion opened get con hand le ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 12) ;

}/∗∗∗ @br ie f Get f i e l d incoming from event

PBAP SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return incoming∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t pbap subevent connect ion opened get incoming (const uint8 t ∗ event ) {return event [ 1 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d goep c id from event

PBAP SUBEVENT CONNECTION CLOSED∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t p b a p s u b e v e n t c o n n e c t i o n c l o s e d g e t g o e p c i d (const uint8 t ∗ event ) {

Page 385: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

384

return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;}

/∗∗∗ @br ie f Get f i e l d goep c id from event

PBAP SUBEVENT OPERATION COMPLETED∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tpbap subevent ope ra t i on comp le t ed ge t goep c id ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event

PBAP SUBEVENT OPERATION COMPLETED∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t pbap subevent ope ra t i on comp l e t ed ge t s ta tu s (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d goep c id from event PBAP SUBEVENT PHONEBOOK SIZE∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t pbap subevent phonebook s i z e ge t goep c id (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event PBAP SUBEVENT PHONEBOOK SIZE∗ @param event packe t∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t pbap subevent phonebook s i z e ge t s ta tu s ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d phoneboook s i ze from event

PBAP SUBEVENT PHONEBOOK SIZE∗ @param event packe t∗ @return phoneboook s i ze∗ @note : b t s t a c k t y p e 2∗/

Page 386: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

385

stat ic i n l i n e uint16 tpbap subevent phonebook s i z e ge t phoneboook s i ze ( const uint8 t ∗

event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 6) ;

}

/∗∗∗ @br ie f Get f i e l d goep c id from event

PBAP SUBEVENT AUTHENTICATION REQUEST∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tp b a p s u b e v e n t a u t h e n t i c a t i o n r e q u e s t g e t g o e p c i d ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d u s e r i d r e q u i r e d from event

PBAP SUBEVENT AUTHENTICATION REQUEST∗ @param event packe t∗ @return u s e r i d r e q u i r e d∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tp b a p s u b e v e n t a u t h e n t i c a t i o n r e q u e s t g e t u s e r i d r e q u i r e d ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d f u l l a c c e s s from event

PBAP SUBEVENT AUTHENTICATION REQUEST∗ @param event packe t∗ @return f u l l a c c e s s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tp b a p s u b e v e n t a u t h e n t i c a t i o n r e q u e s t g e t f u l l a c c e s s ( constuint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d goep c id from event PBAP SUBEVENT CARD RESULT∗ @param event packe t∗ @return goep c id∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t p b a p s u b e v e n t c a r d r e s u l t g e t g o e p c i d ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗

Page 387: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

386

∗ @br ie f Get f i e l d name len from event PBAP SUBEVENT CARD RESULT∗ @param event packe t∗ @return name len∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e int pbap subeven t ca rd r e su l t g e t name l en ( constuint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d name from event PBAP SUBEVENT CARD RESULT∗ @param event packe t∗ @return name∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗ pbap subevent ca rd re su l t ge t name (const uint8 t ∗ event ) {return &event [ 6 ] ;

}/∗∗∗ @br ie f Get f i e l d hand l e l en from event PBAP SUBEVENT CARD RESULT∗ @param event packe t∗ @return hand l e l en∗ @note : b t s t a c k t y p e J∗/

stat ic i n l i n e int p b a p s u b e v e n t c a r d r e s u l t g e t h a n d l e l e n ( constuint8 t ∗ event ) {return event [ 6 + event [ 5 ] ] ;

}/∗∗∗ @br ie f Get f i e l d handle from event PBAP SUBEVENT CARD RESULT∗ @param event packe t∗ @return handle∗ @note : b t s t a c k t y p e V∗/

stat ic i n l i n e const uint8 t ∗ p b a p s u b e v e n t c a r d r e s u l t g e t h a n d l e (const uint8 t ∗ event ) {return &event [ 6 + event [ 5 ] + 1 ] ;

}

/∗∗∗ @br ie f Get f i e l d h i d c i d from event

HID SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return h i d c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h i d s u b e v e n t c o n n e c t i o n o p e n e d g e t h i d c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d s t a t u s from event HID SUBEVENT CONNECTION OPENED∗ @param event packe t

Page 388: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

387

∗ @return s t a t u s∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h i d s u b e v e n t c o n n e c t i o n o p e n e d g e t s t a t u s (const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d bd addr from event

HID SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @param Pointer to s t o rage f o r bd addr∗ @note : b t s t a c k t y p e B∗/

stat ic i n l i n e void h id subevent connec t i on opened ge t bd addr ( constuint8 t ∗ event , bd addr t bd addr ) {r eve r s e bd addr (&event [ 6 ] , bd addr ) ;

}/∗∗∗ @br ie f Get f i e l d con hand le from event

HID SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e H∗/

stat ic i n l i n e h c i c o n h a n d l e th id subevent connec t i on opened ge t con hand l e ( const uint8 t ∗event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 12) ;

}/∗∗∗ @br ie f Get f i e l d incoming from event

HID SUBEVENT CONNECTION OPENED∗ @param event packe t∗ @return incoming∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h id subevent connec t i on opened ge t incoming (const uint8 t ∗ event ) {return event [ 1 4 ] ;

}

/∗∗∗ @br ie f Get f i e l d h i d c i d from event

HID SUBEVENT CONNECTION CLOSED∗ @param event packe t∗ @return h i d c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h i d s u b e v e n t c o n n e c t i o n c l o s e d g e t h i d c i d (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

Page 389: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

388

/∗∗∗ @br ie f Get f i e l d h i d c i d from event HID SUBEVENT CAN SEND NOW∗ @param event packe t∗ @return h i d c i d∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h id subeven t can s end now ge t h id c id ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event HID SUBEVENT SUSPEND∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h id subevent su spend ge t con hand l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event HID SUBEVENT EXIT SUSPEND∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h i d s u b e v e n t e x i t s u s p e n d g e t c o n h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event HIDS SUBEVENT CAN SEND NOW∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h ids subevent can send now get con hand l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

HIDS SUBEVENT PROTOCOL MODE∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h id s subevent pro toco l mode ge t con hand l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

Page 390: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

389

}/∗∗∗ @br ie f Get f i e l d protoco l mode from event

HIDS SUBEVENT PROTOCOL MODE∗ @param event packe t∗ @return protoco l mode∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h ids subevent pro toco l mode ge t pro toco l mode (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

HIDS SUBEVENT BOOT MOUSE INPUT REPORT ENABLE∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th i d s s u b e ve n t b o o t m o u s e i n p ut r e p o r t e n a b l e g e t c o n h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d enab l e from event

HIDS SUBEVENT BOOT MOUSE INPUT REPORT ENABLE∗ @param event packe t∗ @return enab l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th i d s s u b e v e n t b o o t m o u s e i n p u t r e p o r t e n a b l e g e t e n a b l e ( constuint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

HIDS SUBEVENT BOOT KEYBOARD INPUT REPORT ENABLE∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th i d s s u b e v e n t b o o t k e y b o a r d i n p u t r e p o r t e n a b l e g e t c o n h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d enab l e from event

HIDS SUBEVENT BOOT KEYBOARD INPUT REPORT ENABLE∗ @param event packe t

Page 391: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

390

∗ @return enab l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 th i d s s u b e v e n t b o o t k e y b o a r d i n p u t r e p o r t e n a b l e g e t e n a b l e ( constuint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

HIDS SUBEVENT INPUT REPORT ENABLE∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th i d s s u b e v e n t i n p u t r e p o r t e n a b l e g e t c o n h a n d l e ( const uint8 t ∗

event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d enab l e from event

HIDS SUBEVENT INPUT REPORT ENABLE∗ @param event packe t∗ @return enab l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h i d s s u b e v e n t i n p u t r e p o r t e n a b l e g e t e n a b l e (const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

HIDS SUBEVENT OUTPUT REPORT ENABLE∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th i d s s u b e v e n t o u t p u t r e p o r t e n a b l e g e t c o n h a n d l e ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d enab l e from event

HIDS SUBEVENT OUTPUT REPORT ENABLE∗ @param event packe t∗ @return enab l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h i d s s u b e v e n t o u t p u t r e p o r t e n a b l e g e t e n a b l e (const uint8 t ∗ event ) {

Page 392: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

391

return event [ 5 ] ;}

/∗∗∗ @br ie f Get f i e l d con hand le from event

HIDS SUBEVENT FEATURE REPORT ENABLE∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 th i d s s u b e v e n t f e a t u r e r e p o r t e n a b l e g e t c o n h a n d l e ( const uint8 t∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d enab l e from event

HIDS SUBEVENT FEATURE REPORT ENABLE∗ @param event packe t∗ @return enab l e∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 t h i d s s u b e v e n t f e a t u r e r e p o r t e n a b l e g e t e n a b l e( const uint8 t ∗ event ) {return event [ 5 ] ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event HIDS SUBEVENT SUSPEND∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h id s subevent su spend ge t con hand l e ( constuint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event HIDS SUBEVENT EXIT SUSPEND∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 t h i d s s u b e v e n t e x i t s u s p e n d g e t c o n h a n d l e (const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

GATTSERVICE SUBEVENT CYCLING POWER START CALIBRATION∗ @param event packe t∗ @return con handle

Page 393: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

392

∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t s e r v i c e s u b e v e n t c y c l i n g p o w e r s t a r t c a l i b r a t i o n g e t c o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}/∗∗∗ @br ie f Get f i e l d measurement type from event

GATTSERVICE SUBEVENT CYCLING POWER START CALIBRATION∗ @param event packe t∗ @return measurement type∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tg a t t s e r v i c e s u b e v e n t c y c l i n g p o w e r s t a r t c a l i b r a t i o n g e t m e a s u r e m e n t t y p e( const uint8 t ∗ event ) {return event [ 5 ] ;

}/∗∗∗ @br ie f Get f i e l d i s enhanced from event

GATTSERVICE SUBEVENT CYCLING POWER START CALIBRATION∗ @param event packe t∗ @return i s enhanced∗ @note : b t s t a c k t y p e 1∗/

stat ic i n l i n e uint8 tg a t t s e r v i c e s u b e v e n t c y c l i n g p o w e r s t a r t c a l i b r a t i o n g e t i s e n h a n c e d( const uint8 t ∗ event ) {return event [ 6 ] ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

GATTSERVICE SUBEVENT CYCLING POWER BROADCAST START∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

stat ic i n l i n e uint16 tg a t t s e r v i c e s u b e v e n t c y c l i n g p o w e r b r o a d c a s t s t a r t g e t c o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

/∗∗∗ @br ie f Get f i e l d con hand le from event

GATTSERVICE SUBEVENT CYCLING POWER BROADCAST STOP∗ @param event packe t∗ @return con handle∗ @note : b t s t a c k t y p e 2∗/

Page 394: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

393

stat ic i n l i n e uint16 tg a t t s e r v i c e s u b e v e n t c y c l i n g p o w e r b r o a d c a s t s t o p g e t c o n h a n d l e( const uint8 t ∗ event ) {return l i t t l e e n d i a n r e a d 1 6 ( event , 3) ;

}

31.23. BTstack Memory Management API.

/∗∗∗ @br ie f I n i t i a l i z e s BTstack memory poo l s .∗/

void btstack memory in i t (void ) ;

31.24. BTstack Linked List API.

typedef struct b t s t a c k l i n k e d i t e m {struct b t s t a c k l i n k e d i t e m ∗next ; // <−− next e lement in l i s t ,

or NULL} b t s t a c k l i n k e d i t e m t ;

typedef b t s t a c k l i n k e d i t e m t ∗ b t s t a c k l i n k e d l i s t t ;

typedef struct {int advance on next ;b t s t a c k l i n k e d i t e m t ∗ prev ; // po in t s to the item be f o r e the

curren t oneb t s t a c k l i n k e d i t e m t ∗ curr ; // po in t s to the curren t item (

to d e t e c t item removal )} b t s t a c k l i n k e d l i s t i t e r a t o r t ;

// t e s t i f l i s t i s emptyint b t s t a c k l i n k e d l i s t e m p t y (

b t s t a c k l i n k e d l i s t t ∗ l i s t ) ;// add item to l i s t as f i r s t e lementvoid b t s t a c k l i n k e d l i s t a d d (

b t s t a c k l i n k e d l i s t t ∗ l i s t , b t s t a c k l i n k e d i t e m t ∗ item ) ;// add item to l i s t as l a s t e lementvoid b t s t a c k l i n k e d l i s t a d d t a i l (

b t s t a c k l i n k e d l i s t t ∗ l i s t , b t s t a c k l i n k e d i t e m t ∗ item ) ;// pop ( ge t + remove ) f i r s t e lementb t s t a c k l i n k e d i t e m t ∗ b t s t a c k l i n k e d l i s t p o p (

b t s t a c k l i n k e d l i s t t ∗ l i s t ) ;// remove item from l i s tint b t s t a c k l i n k e d l i s t r e m o v e (

b t s t a c k l i n k e d l i s t t ∗ l i s t , b t s t a c k l i n k e d i t e m t ∗ item ) ;// ge t f i r s t e lementb t s t a c k l i n k e d i t e m t ∗ b t s t a c k l i n k e d l i s t g e t f i r s t i t e m (

b t s t a c k l i n k e d l i s t t ∗ l i s t ) ;// f i nd the l a s t item in the l i s tb t s t a c k l i n k e d i t e m t ∗ b t s t a c k l i n k e d l i s t g e t l a s t i t e m (

b t s t a c k l i n k e d l i s t t ∗ l i s t ) ;

Page 395: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

394

/∗∗∗ @br ie f Counts number o f i tems in l i s t∗ @returns number o f i tems in l i s t∗/

int b t s t a c k l i n k e d l i s t c o u n t ( b t s t a c k l i n k e d l i s t t ∗ l i s t ) ;

//// i t e r a t o r f o r l i n k e d l i s t s . a l l ow s to remove current e lement .// robus t a ga in s t removal o f curren t e lement by

b t s t a c k l i n k e d l i s t r emo v e .//void b t s t a c k l i n k e d l i s t i t e r a t o r i n i t (

b t s t a c k l i n k e d l i s t i t e r a t o r t ∗ i t , b t s t a c k l i n k e d l i s t t ∗l i s t ) ;

int b t s t a c k l i n k e d l i s t i t e r a t o r h a s n e x t (b t s t a c k l i n k e d l i s t i t e r a t o r t ∗ i t ) ;

b t s t a c k l i n k e d i t e m t ∗ b t s t a c k l i n k e d l i s t i t e r a t o r n e x t (b t s t a c k l i n k e d l i s t i t e r a t o r t ∗ i t ) ;

void b t s t a c k l i n k e d l i s t i t e r a t o r r e m o v e (b t s t a c k l i n k e d l i s t i t e r a t o r t ∗ i t ) ;

31.25. Run Loop API.

/∗∗∗ @br ie f I n i t main run loop . Must be c a l l e d b e f o r e any o ther run

loop c a l l .∗∗ Use b t s t a c k r un l o o p $ ( btstack run loop TYPE ) g e t i n s t a n c e ( ) from

b t s t a c k r un l o o p $ ( btstack run loop TYPE ) . h to ge t in s tance∗/

void b t s t a c k r u n l o o p i n i t ( const b t s t a c k r u n l o o p t ∗ run loop ) ;

/∗∗∗ @br ie f Set t imer based on curren t time in m i l l i s e c ond s .∗/

void b t s t a c k r u n l o o p s e t t i m e r (btstack timer source t ∗ ts ,uint32 t t imeout in ms ) ;

/∗∗∗ @br ie f Set c a l l b a c k t ha t w i l l be executed when timer e xp i r e s .∗/

void b t s t a c k r u n l o o p s e t t i m e r h a n d l e r (btstack timer source t ∗ ts ,void (∗ proce s s ) (btstack timer source t ∗ t s ) ) ;

/∗∗∗ @br ie f Set con t ex t f o r t h i s t imer∗/

void b t s t a c k r u n l o o p s e t t i m e r c o n t e x t (btstack timer source t ∗ ts ,void ∗ context ) ;

/∗∗∗ @br ie f Get con t ex t f o r t h i s t imer

Page 396: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

395

∗/void ∗ b t s t a c k r u n l o o p g e t t i m e r c o n t e x t (btstack timer source t ∗

t s ) ;

/∗∗∗ @br ie f Add timer source .∗/

void bt s ta ck run l oop add t imer (btstack timer source t ∗ t imer ) ;

/∗∗∗ @br ie f Remove t imer source .∗/

int bt s tack run loop remove t imer (btstack timer source t ∗ t imer ) ;

/∗∗∗ @br ie f Get curren t time in ms∗ @note 32− b i t ms counter w i l l o v e r f l ow a f t e r approx . 52 days∗/

uint32 t bt s t a ck run l oop ge t t ime ms (void ) ;

/∗∗∗ @br ie f Set data source c a l l b a c k .∗/

void b t s t a c k r u n l o o p s e t d a t a s o u r c e h a n d l e r (btstack data source t∗ data source , void (∗ proce s s ) (btstack data source t ∗ ds ,b t s t a c k d a t a s o u r c e c a l l b a c k t y p e t c a l l b a c k t y p e ) ) ;

/∗∗∗ @br ie f Set data source f i l e d e s c r i p t o r .∗ @param data source∗ @param fd f i l e d e s c r i p t o r∗ @note No e f f e c t i f por t doensn ’ t have f i l e d e s c r i p t o r s∗/

void b t s t a c k r u n l o o p s e t d a t a s o u r c e f d (btstack data source t ∗data source , int fd ) ;

/∗∗∗ @br ie f Get data source f i l e d e s c r i p t o r .∗ @param data source∗/

int b t s t a c k r u n l o o p g e t d a t a s o u r c e f d (btstack data source t ∗data source ) ;

/∗∗∗ @br ie f Set data source f i l e d e s c r i p t o r .∗ @param data source∗ @param handle∗ @note No e f f e c t i f por t doensn ’ t have f i l e d e s c r i p t o r s∗/

void b t s t a c k r u n l o o p s e t d a t a s o u r c e h a n d l e (btstack data source t ∗data source , void ∗ handle ) ;

/∗∗

Page 397: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

396

∗ @br ie f Get data source f i l e d e s c r i p t o r .∗ @param data source∗/

void ∗ b t s t a c k r u n l o o p g e t d a t a s o u r c e h a n d l e (btstack data source t∗ data source ) ;

/∗∗∗ @br ie f Enable c a l l b a c k s f o r a data source∗ @param data source to remove∗ @param ca l l b a c k t ype s to enab l e∗/

void b t s t a c k r u n l o o p e n a b l e d a t a s o u r c e c a l l b a c k s (btstack data source t ∗ data source , uint16 t c a l l b a c k s ) ;

/∗∗∗ @br ie f Enable c a l l b a c k s f o r a data source∗ @param data source to remove∗ @param ca l l b a c k t ype s to d i s a b l e∗/

void b t s t a c k r u n l o o p d i s a b l e d a t a s o u r c e c a l l b a c k s (btstack data source t ∗ data source , uint16 t c a l l b a c k s ) ;

/∗∗∗ @br ie f Add data source to run loop∗ @param data source to add∗/

void b t s t a ck r un l oo p a dd d a t a s o u r c e (btstack data source t ∗data source ) ;

/∗∗∗ @br ie f Remove data source from run loop∗ @param data source to remove∗/

int bt s tack run loop r emove data sour c e (btstack data source t ∗data source ) ;

/∗∗∗ @br ie f Execute con f i gured run loop . This f unc t i on does not re turn

.∗/

void b t s t a c k r u n l o o p e x e c u t e (void ) ;

31.26. Common Utils API.

/∗∗∗ @br ie f Minimum func t i on f o r u i n t 3 2 t∗ @param a∗ @param b∗ @return va lue∗/

uint32 t btstack min (uint32 t a , uint32 t b) ;

/∗∗

Page 398: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

397

∗ @br ie f Maximum func t i on f o r u i n t 3 2 t∗ @param a∗ @param b∗ @return va lue∗/

uint32 t btstack max (uint32 t a , uint32 t b) ;

/∗∗∗ @br ie f Read 16/24/32 b i t l i t t l e endian va lue from bu f f e r∗ @param bu f f e r∗ @param po s i t i o n in b u f f e r∗ @return va lue∗/

uint16 t l i t t l e e n d i a n r e a d 1 6 ( const uint8 t ∗ bu f f e r , int p o s i t i o n );

uint32 t l i t t l e e n d i a n r e a d 2 4 ( const uint8 t ∗ bu f f e r , int p o s i t i o n );

uint32 t l i t t l e e n d i a n r e a d 3 2 ( const uint8 t ∗ bu f f e r , int p o s i t i o n );

/∗∗∗ @br ie f Write 16/32 b i t l i t t l e endian va lue in to b u f f e r∗ @param bu f f e r∗ @param po s i t i o n in b u f f e r∗ @param va lue∗/

void l i t t l e e n d i a n s t o r e 1 6 ( uint8 t ∗ bu f f e r , uint16 t pos i t i on ,uint16 t value ) ;

void l i t t l e e n d i a n s t o r e 2 4 ( uint8 t ∗ bu f f e r , uint16 t pos i t i on ,uint32 t value ) ;

void l i t t l e e n d i a n s t o r e 3 2 ( uint8 t ∗ bu f f e r , uint16 t pos i t i on ,uint32 t value ) ;

/∗∗∗ @br ie f Read 16/24/32 b i t b i g endian va lue from bu f f e r∗ @param bu f f e r∗ @param po s i t i o n in b u f f e r∗ @return va lue∗/

uint32 t b ig end i an r ead 16 ( const uint8 t ∗ bu f f e r , int pos ) ;uint32 t b ig end i an r ead 24 ( const uint8 t ∗ bu f f e r , int pos ) ;uint32 t b ig end i an r ead 32 ( const uint8 t ∗ bu f f e r , int pos ) ;

/∗∗∗ @br ie f Write 16/32 b i t b i g endian va lue in t o b u f f e r∗ @param bu f f e r∗ @param po s i t i o n in b u f f e r∗ @param va lue∗/

void b i g e n d i a n s t o r e 1 6 ( uint8 t ∗ bu f f e r , uint16 t pos , uint16 tvalue ) ;

void b i g e n d i a n s t o r e 2 4 ( uint8 t ∗ bu f f e r , uint16 t pos , uint32 tvalue ) ;

Page 399: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

398

void b i g e n d i a n s t o r e 3 2 ( uint8 t ∗ bu f f e r , uint16 t pos , uint32 tvalue ) ;

/∗∗∗ @br ie f Swap by t e s in 16 b i t i n t e g e r∗/

stat ic i n l i n e uint16 t b t s t a c k f l i p 1 6 (uint16 t value ) {return (uint16 t ) ( ( va lue & 0 x f f ) << 8) | ( va lue >> 8) ;

}

/∗∗∗ @br ie f Check f o r b i g endian system∗ @returns 1 i f on b i g endian∗/

stat ic i n l i n e int b t s t a c k i s b i g e n d i a n (void ) {uint16 t sample = 0x0100 ;return ∗( uint8 t ∗) &sample ;

}

/∗∗∗ @br ie f Check f o r l i t t l e endian system∗ @returns 1 i f on l i t t l e endian∗/

stat ic i n l i n e int b t s t a c k i s l i t t l e e n d i a n (void ) {uint16 t sample = 0x0001 ;return ∗( uint8 t ∗) &sample ;

}

/∗∗∗ @br ie f Copy from source to d e s t i n a t i o n and rev e r s e by t e order∗ @param src∗ @param des t∗ @param len∗/

void r e v e r s e b y t e s ( const uint8 t ∗ src , uint8 t ∗ dest , int l en ) ;

/∗∗∗ @br ie f Wrapper around r e v e r s e b y t e s f o r common bu f f e r s i z e s∗ @param src∗ @param des t∗/

void r e v e r s e 2 4 ( const uint8 t ∗ src , uint8 t ∗ dest ) ;void r e v e r s e 4 8 ( const uint8 t ∗ src , uint8 t ∗ dest ) ;void r e v e r s e 5 6 ( const uint8 t ∗ src , uint8 t ∗ dest ) ;void r e v e r s e 6 4 ( const uint8 t ∗ src , uint8 t ∗ dest ) ;void r e v e r s e 1 2 8 ( const uint8 t ∗ src , uint8 t ∗ dest ) ;void r e v e r s e 2 5 6 ( const uint8 t ∗ src , uint8 t ∗ dest ) ;

void r eve r s e bd addr ( const bd addr t src , bd addr t dest ) ;

/∗∗∗ @br ie f ASCII charac t e r f o r 4− b i t n i b b l e∗ @return charac t e r

Page 400: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

399

∗/char c h a r f o r n i b b l e ( int n ibb l e ) ;

/∗∗∗ @bri f 4− b i t n i b b l e from ASCII charac t e r∗ @return va lue∗/

int n i b b l e f o r c h a r (char c ) ;

/∗∗∗ @br ie f Compare two Blue too th addres se s∗ @param a∗ @param b∗ @return 0 i f equa l∗/

int bd addr cmp ( const bd addr t a , const bd addr t b) ;

/∗∗∗ @br ie f Copy Blue too th address∗ @param des t∗ @param src∗/

void bd addr copy (bd addr t dest , const bd addr t s r c ) ;

/∗∗∗ @br ie f Use p r i n t f to wr i t e hexdump as s i n g l e l i n e o f data∗/

void printf hexdump ( const void ∗data , int s i z e ) ;

/∗∗∗ @br ie f Create human readab l e r e p r e s en t a t i on f o r UUID128∗ @note uses f i x e d g l o b a l b u f f e r∗ @return po in t e r to UUID128 s t r i n g∗/

char ∗ u u i d 1 2 8 t o s t r ( const uint8 t ∗ uuid ) ;

/∗∗∗ @br ie f Create human readab l e r e p r e s ena t i on t o f B lue too th address∗ @note uses f i x e d g l o b a l b u f f e r∗ @return po in t e r to Blue too th address s t r i n g∗/

char ∗ b d a d d r t o s t r ( const bd addr t addr ) ;

/∗∗∗ @br ie f Parse B lue too th address∗ @param add r e s s s t r i n g∗ @param bu f f e r f o r parsed address∗ @return 1 i f s t r i n g was parsed s u c c e s s f u l l y∗/

int s s can f bd addr ( const char ∗ addr s t r ing , bd addr t addr ) ;

/∗∗∗ @br ie f Constructs UUID128 from 16 or 32 b i t UUID us ing Blue too th

base UUID

Page 401: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

400

∗ @param uuid128 output b u f f e r∗ @param sho r t uu i d∗/

void u u i d a d d b l u e t o o t h p r e f i x ( uint8 t ∗ uuid128 , uint32 tsho r t uu id ) ;

/∗∗∗ @br ie f Checks i f UUID128 has Blue too th base UUID p r e f i x∗ @param uui128 to t e s t∗ @return 1 i f i t can be expre s sed as UUID32∗/

int u u i d h a s b l u e t o o t h p r e f i x ( const uint8 t ∗ uuid128 ) ;

/∗∗∗ @br ie f Parse unsigned number∗ @param s t r to parse∗ @return va lue∗/

uint32 t b t s t a c k a t o i ( const char ∗ s t r ) ;

/∗∗∗ @br ie f Return number o f d i g i t s o f a u int32 number∗ @param uint32 number∗ @return num dig i t s∗/

int s t r i n g l e n f o r u i n t 3 2 (uint32 t i ) ;

/∗∗∗ @br ie f Return number o f s e t b i t s in a uint32 number∗ @param uint32 number∗ @return num se t b i t s∗/

int c o u n t s e t b i t s u i n t 3 2 (uint32 t x ) ;

/∗∗∗ CRC8 func t i on s us ing ETSI TS 101 369 V6 . 3 . 0 .∗ Only used by RFCOMM∗/

uint8 t b t s t a c k c r c 8 c h e c k ( uint8 t ∗data , uint16 t len , uint8 tcheck sum ) ;

uint8 t b t s t a c k c r c 8 c a l c ( uint8 t ∗data , uint16 t l en ) ;

31.27. GAP API.

// C la s s i c + LE

/∗∗∗ @br ie f Disconnect connect ion wi th handle∗ @param handle∗/

uint8 t gap d i s connect ( h c i c o n h a n d l e t handle ) ;

/∗∗

Page 402: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

401

∗ @br ie f Get connect ion type∗ @param con handle∗ @resu l t connec t i on type∗/

gap connec t i on type t gap ge t connec t i on type ( h c i c o n h a n d l e tconnect ion hand le ) ;

// C la s s i c

/∗∗∗ @br ie f Se t s l o c a l name .∗ @note has to be done be f o r e s t a c k s t a r t s up∗ @note De fau l t name i s ’ BTstack 00 : 00 : 00 : 00 : 00 : 00 ’∗ @note ’ 00 : 00 : 00 : 00 : 00 : 00 ’ in loca l name w i l l be r ep l aced wi th

a c t ua l bd addr∗ @param name i s not copied , make sure memory i s a c c e s s i b l e dur ing

s t a c k s t a r t up∗/

void gap s e t l o ca l name ( const char ∗ l oca l name ) ;

/∗∗∗ @br ie f Set Extended Inqu i ry Response data∗ @note has to be done be f o r e s t a c k s t a r t s up∗ @note I f not se t , l o c a l name w i l l be used f o r EIR data ( see

gap s e t l o ca l name )∗ @note ’ 00 : 00 : 00 : 00 : 00 : 00 ’ in loca l name w i l l be r ep l aced wi th

a c t ua l bd addr∗ @param e i r d a t a s i z e 240 bytes , i s not cop ied make sure memory i s

a c c e s s i b l e dur ing s t a c k s t a r t up∗/

void g a p s e t e x t e n d e d i n q u i r y r e s p o n s e ( const uint8 t ∗ data ) ;

/∗∗∗ @br ie f Set c l a s s o f dev i c e t ha t w i l l be s e t dur ing Blue too th i n i t

.∗ @note has to be done be f o r e s t a c k s t a r t s up∗/

void g a p s e t c l a s s o f d e v i c e (uint32 t c l a s s o f d e v i c e ) ;

/∗∗∗ @br ie f Set d e f a u l t l i n k p o l i c y s e t t i n g s f o r a l l c l a s s i c ACL l i n k s∗ @param d e f a u l t l i n k p o l i c y s e t t i n g s − see LM LINK POLICY ∗ in

b l u e t o o t h . h∗ @note common va lue : LM LINK POLICY ENABLE ROLE SWITCH |

LM LINK POLICY ENABLE SNIFF MODE to enab l e r o l e sw i t ch ands n i f f mode

∗ @note has to be done be f o r e s t a c k s t a r t s up∗/

void g a p s e t d e f a u l t l i n k p o l i c y s e t t i n g s (uint16 td e f a u l t l i n k p o l i c y s e t t i n g s ) ;

/∗∗∗ @br ie f Enable / d i s a b l e bonding . De fau l t i s enab led .∗ @param enab led

Page 403: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

402

∗/void gap set bondable mode ( int enabled ) ;

/∗∗∗ @br ie f Get bondab le mode .∗ @return 1 i f bondab le∗/

int gap get bondable mode (void ) ;

/∗ Configure Secure Simple Pair ing ∗/

/∗∗∗ @br ie f Enable w i l l enab l e SSP during i n i t .∗/

void g a p s s p s e t e n a b l e ( int enable ) ;

/∗∗∗ @br ie f Set IO Capab i l i t y . BTstack w i l l re turn c a p a b i l i t y to SSP

r e qu e s t s∗/

void g a p s s p s e t i o c a p a b i l i t y ( int s s p i o c a p a b i l i t y ) ;

/∗∗∗ @br ie f Set Authen t i ca t ion Requirements us ing during SSP∗/

void g a p s s p s e t a u t h e n t i c a t i o n r e q u i r e m e n t ( intauthent i ca t i on r equ i r ement ) ;

/∗∗∗ @br ie f I f se t , BTstack w i l l confirm a numeric comparison and

enter ’000000 ’ i f r e que s t ed .∗/

void g a p s s p s e t a u t o a c c e p t ( int auto accept ) ;

/∗∗∗ @br ie f S t a r t ded i ca t ed bonding wi th dev i c e . Disconnect a f t e r

bonding .∗ @param dev i c e∗ @param reque s t MITM pro t e c t i on∗ @return error , i f max num ac l connec t ions a c t i v e∗ @resu l t GAP DEDICATED BONDING COMPLETE∗/

int gap dedicated bonding (bd addr t device , intmitm protec t i on requ i r ed ) ;

g a p s e c u r i t y l e v e l t g a p s e c u r i t y l e v e l f o r l i n k k e y t y p e (l i n k k e y t y p e t l i n k k e y t y p e ) ;

g a p s e c u r i t y l e v e l t g a p s e c u r i t y l e v e l ( h c i c o n h a n d l e t con handle );

void g a p r e q u e s t s e c u r i t y l e v e l ( h c i c o n h a n d l e t con handle ,g a p s e c u r i t y l e v e l t l e v e l ) ;

Page 404: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

403

int g a p m i t m p r o t e c t i o n r e q u i r e d f o r s e c u r i t y l e v e l (g a p s e c u r i t y l e v e l t l e v e l ) ;

// LE

/∗∗∗ @br ie f Set parameters f o r LE Scan∗/

void gap se t s can paramete r s ( uint8 t scan type , uint16 ts c a n i n t e r v a l , uint16 t scan window ) ;

/∗∗∗ @br ie f S t a r t LE Scan∗/

void g a p s t a r t s c a n (void ) ;

/∗∗∗ @br ie f Stop LE Scan∗/

void gap s top scan (void ) ;

/∗∗∗ @br ie f Enable pr i vacy by us ing random addres se s∗ @param random address type to use ( i n c l . OFF)∗/

void gap random address set mode ( gap random address type trandom address type ) ;

/∗∗∗ @br ie f Get pr i vacy mode∗/

gap random address type t gap random address get mode (void ) ;

/∗∗∗ @br ie f Se t s update per iod f o r random address∗ @param period ms in ms∗/void gap random addres s s e t update per iod ( int per iod ms ) ;

/∗∗∗ @br ie f Se t s a f i x e d random address f o r a d v e r t i s i n g∗ @param addr∗ @note Se t s random address mode to type o f f∗/

void gap random address set (bd addr t addr ) ;

/∗∗∗ @br ie f Set Advert isement Data∗ @param ad v e r t i s i n g d a t a l e n g t h∗ @param ad v e r t i s i n g d a t a (max 31 o c t e t s )∗ @note data i s not copied , po in t e r has to s tay v a l i d∗ @note ’ 00 : 00 : 00 : 00 : 00 : 00 ’ in a d v e r t i s i n g d a t a w i l l be r ep l aced

wi th a c t ua l bd addr∗/

Page 405: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

404

void gap adve r t i s ement s s e t da ta ( uint8 t a d v e r t i s i n g d a t a l e n g t h ,uint8 t ∗ a d v e r t i s i n g d a t a ) ;

/∗∗∗ @br ie f Set Advert isement Paramters∗ @param adv in t min∗ @param adv int max∗ @param adv type∗ @param d i r e c t a d d r e s s t y p e∗ @param d i r e c t a d d r e s s∗ @param channel map∗ @param f i l t e r p o l i c y∗ @note own address type i s used from gap random address set mode∗/

void gap adver t i s ements se t params (uint16 t adv int min , uint16 tadv int max , uint8 t adv type ,uint8 t d i r e c t a d d r e s s t y p , bd addr t d i r e c t a d d r e s s , uint8 t

channel map , uint8 t f i l t e r p o l i c y ) ;

/∗∗∗ @br ie f Enable /Di sab l e Advert i sements . OFF by d e f a u l t .∗ @param enab led∗/

void gap adver t i s ement s enab l e ( int enabled ) ;

/∗∗∗ @br ie f Set Scan Response Data∗∗ @note For scan response data , scannab le und i rec t ed a d v e r t i s i n g (

ADV SCAN IND) need to be used∗∗ @param ad v e r t i s i n g d a t a l e n g t h∗ @param ad v e r t i s i n g d a t a (max 31 o c t e t s )∗ @note data i s not copied , po in t e r has to s tay v a l i d∗ @note ’ 00 : 00 : 00 : 00 : 00 : 00 ’ in scan re sponse da ta w i l l be r ep l aced

wi th a c t ua l bd addr∗/

void g a p s c a n r e s p o n s e s e t d a t a ( uint8 t s can r e spons e da ta l eng th ,uint8 t ∗ s can r e sponse da ta ) ;

/∗∗∗ @br ie f Set connect ion parameters f o r outgo ing connec t ions∗ @param conn s can in t e r va l ( un i t : 0.625 msec ) , d e f a u l t : 60 ms∗ @param conn scan window ( un i t : 0.625 msec ) , d e f a u l t : 30 ms∗ @param conn in te rva l min ( un i t : 1 .25ms) , d e f a u l t : 10 ms∗ @param conn in terva l max ( un i t : 1 .25ms) , d e f a u l t : 30 ms∗ @param conn la tency , d e f a u l t : 4∗ @param supe r v i s i on t imeou t ( un i t : 10ms) , d e f a u l t : 720 ms∗ @param min ce l eng th ( un i t : 0.625ms) , d e f a u l t : 10 ms∗ @param max ce l eng th ( un i t : 0.625ms) , d e f a u l t : 30 ms∗/

void gap se t connec t i on paramete r s (uint16 t co nn s c an in t e r va l ,uint16 t conn scan window ,

Page 406: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

405

uint16 t conn inte rva l min , uint16 t conn interva l max , uint16 tconn latency ,

uint16 t supe rv i s i on t imeout , uint16 t min ce length , uint16 tmax ce length ) ;

/∗∗∗ @br ie f Request an update o f the connect ion parameter f o r a g iven

LE connect ion∗ @param handle∗ @param conn in te rva l min ( un i t : 1 .25ms)∗ @param conn in terva l max ( un i t : 1 .25ms)∗ @param conn la tency∗ @param supe r v i s i on t imeou t ( un i t : 10ms)∗ @returns 0 i f ok∗/

int gap reques t connect i on paramete r update ( h c i c o n h a n d l e tcon handle , uint16 t conn inte rva l min ,uint16 t conn interva l max , uint16 t conn latency , uint16 t

s u pe r v i s i o n t i me o u t ) ;

/∗∗∗ @br ie f Updates the connect ion parameters f o r a g iven LE

connect ion∗ @param handle∗ @param conn in te rva l min ( un i t : 1 .25ms)∗ @param conn in terva l max ( un i t : 1 .25ms)∗ @param conn la tency∗ @param supe r v i s i on t imeou t ( un i t : 10ms)∗ @returns 0 i f ok∗/

int gap update connect ion parameter s ( h c i c o n h a n d l e t con handle ,uint16 t conn inte rva l min ,uint16 t conn interva l max , uint16 t conn latency , uint16 t

s u pe r v i s i o n t i me o u t ) ;

/∗∗∗ @br ie f Set accepted connect ion parameter range∗ @param range∗/

void gap ge t connec t i on paramete r range (l e c o n n e c t i o n p a r a m e t e r r a n g e t ∗ range ) ;

/∗∗∗ @br ie f Get accepted connect ion parameter range∗ @param range∗/

void gap se t connec t i on paramete r range (l e c o n n e c t i o n p a r a m e t e r r a n g e t ∗ range ) ;

/∗∗∗ @br ie f Test i f connect ion parameters are i n s i d e in e x i s t i n g rage∗ @param conn in te rva l min ( un i t : 1 .25ms)∗ @param conn in terva l max ( un i t : 1 .25ms)∗ @param conn la tency

Page 407: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

406

∗ @param supe r v i s i on t imeou t ( un i t : 10ms)∗ @returns 1 i f inc luded∗/

int gap connec t i on paramete r range inc luded (l e c o n n e c t i o n p a r a m e t e r r a n g e t ∗ e x i s t i n g r a n g e , uint16 tl e c o n n i n t e r v a l m i n , uint16 t l e conn in t e rva l max , uint16 tl e c o n n l a t e n c y , uint16 t l e s u p e r v i s i o n t i m e o u t ) ;

/∗∗∗ @br ie f Set max number o f connec t ions in LE Per iphera l r o l e ( i f

B lue too th Con t ro l l e r suppor t s i t )∗ @note : d e f a u l t : 1∗ @param max per iphera l connec t i ons∗/

void gap se t max number per iphera l connect i ons ( intmax per iphe ra l connec t i ons ) ;

/∗∗∗ @br ie f Connect to remote LE dev i c e∗/

uint8 t gap connect (bd addr t addr , bd addr type t addr type ) ;

/∗∗∗ @br ie f Cancel connect ion process i n i t i a t e d by gap connect∗/

uint8 t gap connec t cance l (void ) ;

/∗∗∗ @br ie f Auto Connection Es tab l i shment − S ta r t Connecting to dev i c e∗ @param addre s s t yp∗ @param address∗ @returns 0 i f ok∗/

int g a p a u t o c o n n e c t i o n s t a r t ( bd addr type t address typ , bd addr taddress ) ;

/∗∗∗ @br ie f Auto Connection Es tab l i shment − Stop Connecting to dev i c e∗ @param addre s s t yp∗ @param address∗ @returns 0 i f ok∗/

int gap auto connec t i on s top ( bd addr type t address typ , bd addr taddress ) ;

/∗∗∗ @br ie f Auto Connection Es tab l i shment − Stop ev e r y t h in g∗ @note Convenience func t i on to s top a l l a c t i v e auto connect ion

at tempts∗/

void g a p a u t o c o n n e c t i o n s t o p a l l (void ) ;

/∗∗∗ @br ie f Set LE PHY

Page 408: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

407

∗ @param con handle∗ @param a l l p h y s 0 = s e t rx / tx , 1 = s e t on ly rx , 2 = s e t on ly t x∗ @param tx phy s 1 = 1M, 2 = 2M, 4 = Coded∗ @param rx phys 1 = 1M, 2 = 2M, 4 = Coded∗ @param phy op t i ons 0 = no pr e f e r r e d coding f o r Coded , 1 = S=2

coding (500 k b i t ) , 2 = S=8 coding (125 k b i t )∗ @returns 0 i f ok∗/

uint8 t g a p l e s e t p h y ( h c i c o n h a n d l e t con handle , uint8 t a l l phys, uint8 t tx phys , uint8 t rx phys , uint8 t phy opt ions ) ;

/∗∗∗ @br ie f Get connect ion i n t e r v a l∗ @return connect ion i n t e r v a l , o the rw i s e 0 i f e r ror∗/

uint16 t g a p l e c o n n e c t i o n i n t e r v a l ( h c i c o n h a n d l e tconnect ion hand le ) ;

/∗∗∗∗ @br ie f Get encryp t ion key s i z e .∗ @param con handle∗ @return 0 i f not encrypted , 7−16 o the rw i s e∗/

int g a p e n c r y p t i o n k e y s i z e ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Get au t h en t i c a t i on proper ty .∗ @param con handle∗ @return 1 i f bonded wi th OOB/Passkey (AND MITM pro t e c t i on )∗/

int gap authent i ca ted ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Get secure connect ion proper ty∗ @param con handle∗ @return 1 i f bonded usiung LE Secure Connections∗/

int gap s e cu r e connec t i on ( h c i c o n h a n d l e t con handle ) ;

/∗∗∗ @br ie f Queries au t ho r i z a t i on s t a t e .∗ @param con handle∗ @return a u t h o r i z a t i o n s t a t e f o r the current s e s s i on∗/

a u t h o r i z a t i o n s t a t e t g a p a u t h o r i z a t i o n s t a t e ( h c i c o n h a n d l e tcon handle ) ;

// C la s s i c

/∗∗∗ @br ie f Override page scan mode . Page scan mode enab led by l2cap

when s e r v i c e s are r e g i s t e r e d

Page 409: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

408

∗ @note Might be used to reduce power consumption wh i l e B lue too thmodule s t a y s powered but no (new)

∗ connec t ions are expec ted∗/

void g a p c o n n e c t a b l e c o n t r o l ( uint8 t enable ) ;

/∗∗∗ @br ie f Al lows to con t r o l i f d ev i c e i s d i s c o v e r a b l e . OFF by

d e f a u l t .∗/

void g a p d i s c o v e r a b l e c o n t r o l ( uint8 t enable ) ;

/∗∗∗ @br ie f Gets l o c a l address .∗/

void gap l o ca l bd addr (bd addr t a d d r e s s b u f f e r ) ;

/∗∗∗ @br ie f De l e t e s l i n k key f o r remote dev i c e wi th baseband address .∗ @param addr∗/

void g a p d r o p l i n k k e y f o r b d a d d r (bd addr t addr ) ;

/∗∗∗ @br ie f De le t e a l l s t o r ed l i n k keys∗/

void g a p d e l e t e a l l l i n k k e y s (void ) ;

/∗∗∗ @br ie f Store l i n k key f o r remote dev i c e wi th baseband address∗ @param addr∗ @param l i n k k e y∗ @param l i n k k e y t y p e∗/

void g a p s t o r e l i n k k e y f o r b d a d d r (bd addr t addr , l ink key tl i nk key , l i n k k e y t y p e t type ) ;

/∗∗∗ @br ie f Setup Link Key i t e r a t o r∗ @param i t∗ @returns 1 on succe s s∗/

int g a p l i n k k e y i t e r a t o r i n i t ( b t s t a c k l i n k k e y i t e r a t o r t ∗ i t ) ;

/∗∗∗ @br ie f Get next Link Key∗ @param i t∗ @br ie f addr∗ @br ie f l i n k k e y∗ @br ie f type o f l i n k key∗ @returns 1 , i f v a l i d l i n k key found∗/

Page 410: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

409

int g a p l i n k k e y i t e r a t o r g e t n e x t ( b t s t a c k l i n k k e y i t e r a t o r t ∗ i t ,bd addr t bd addr , l ink key t l i nk key , l i n k k e y t y p e t ∗ type )

;

/∗∗∗ @br ie f Frees re source s a l l o c a t e d by i t e r a t o r i n i t∗ @note Must be c a l l e d a f t e r i t e r a t i o n to f r e e re source s∗ @param i t∗/

void g a p l i n k k e y i t e r a t o r d o n e ( b t s t a c k l i n k k e y i t e r a t o r t ∗ i t ) ;

/∗∗∗ @br ie f S t a r t GAP Cla s s i c Inqu i ry∗ @param durat ion in 1.28 s un i t s∗ @return 0 i f ok∗ @events : GAP EVENT INQUIRY RESULT, GAP EVENT INQUIRY COMPLETE∗/

int g a p i n q u i r y s t a r t ( uint8 t dura t i on in 1280ms un i t s ) ;

/∗∗∗ @br ie f Stop GAP Cla s s i c Inqu i ry∗ @br ie f Stop GAP Cla s s i c Inqu i ry∗ @returns 0 i f ok∗ @events : GAP EVENT INQUIRY COMPLETE∗/

int g a p i n q u i r y s t o p (void ) ;

/∗∗∗ @br ie f Remote Name Request∗ @param addr∗ @param page scan repe t i t i on mode∗ @param c l o c k o f f s e t on ly used when b i t 15 i s s e t − pass 0 i f not

known∗ @events : HCI EVENT REMOTE NAME REQUEST COMPLETE∗/

int gap remote name request (bd addr t addr , uint8 tpage scan repet i t i on mode , uint16 t c l o c k o f f s e t ) ;

/∗∗∗ @br ie f Legacy Pair ing Pin Code Response∗ @param addr∗ @param pin∗ @return 0 i f ok∗/

int gap p in code r e sponse (bd addr t addr , const char ∗ pin ) ;

/∗∗∗ @br ie f Abort Legacy Pair ing∗ @param addr∗ @param pin∗ @return 0 i f ok∗/

int gap p in code nega t i v e (bd addr t addr ) ;

Page 411: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

410

/∗∗∗ @br ie f SSP Passkey Response∗ @param addr∗ @param passkey [ 0 . . 9 9 9999 ]∗ @return 0 i f ok∗/

int gap s sp pa s skey r e spons e (bd addr t addr , uint32 t passkey ) ;

/∗∗∗ @br ie f Abort SSP Passkey Entry/Pair ing∗ @param addr∗ @param pin∗ @return 0 i f ok∗/

int gap s sp pa s skey nega t i v e (bd addr t addr ) ;

/∗∗∗ @br ie f Accept SSP Numeric Comparison∗ @param addr∗ @param passkey∗ @return 0 i f ok∗/

int g a p s s p c o n f i r m a t i o n r e s p o n s e (bd addr t addr ) ;

/∗∗∗ @br ie f Abort SSP Numeric Comparison/Pair ing∗ @param addr∗ @param pin∗ @return 0 i f ok∗/

int g a p s s p c o n f i r m a t i o n n e g a t i v e (bd addr t addr ) ;

/∗∗∗ @br ie f Enter Sn i f f mode∗ @param con handle∗ @param s n i f f m i n i n t e r v a l range : 0x0002 to 0xFFFE; only even

va l u e s are va l i d , Time = N ∗ 0.625 ms∗ @param sn i f f ma x i n t e r v a l range : 0x0002 to 0xFFFE; only even

va l u e s are va l i d , Time = N ∗ 0.625 ms∗ @param sn i f f a t t emp t Number o f Baseband r e c e i v e s l o t s f o r s n i f f

a t tempt .∗ @param sn i f f t im e o u t Number o f Baseband r e c e i v e s l o t s f o r s n i f f

t imeout .@ @return 0 i f ok∗/

uint8 t g a p s n i f f m o d e e n t e r ( h c i c o n h a n d l e t con handle , uint16 ts n i f f m i n i n t e r v a l , uint16 t s n i f f m a x i n t e r v a l , uint16 ts n i f f a t t e m p t , uint16 t s n i f f t i m e o u t ) ;

/∗∗∗ @br ie f Ex i t S n i f f mode∗ @param con handle@ @return 0 i f ok∗/

Page 412: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

411

uint8 t g a p s n i f f m o d e e x i t ( h c i c o n h a n d l e t con handle ) ;

// LE

/∗∗∗ @br ie f Get own addr type and address used f o r LE∗/

void gap l e g e t own addre s s ( uint8 t ∗ addr type , bd addr t addr ) ;

/∗∗∗ @br ie f Get s t a t e o f connect ion re−encryp t iong f o r bonded de v i c e s

when in c en t r a l r o l e∗ @note used by g a t t c l i e n t and a t t s e r v e r to wai t f o r re−

encryp t ion∗ @param con handle∗ @return 1 i f s e c u r i t y se tup i s a c t i v e∗/

int g a p r e c o n n e c t s e c u r i t y s e t u p a c t i v e ( h c i c o n h a n d l e t con handle );

31.28. HCI API.

// HCI i n i t and con f i g u r a t i on

/∗∗∗ @br ie f Set up HCI . Needs to be c a l l e d b e f o r e any o ther func t i on .∗/

void h c i i n i t ( const hci transport t ∗ t ransport , const void ∗ c o n f i g ) ;

/∗∗∗ @br ie f Conf igure Blue too th c h i p s e t d r i v e r . Has to be c a l l e d

b e f o r e power on , or r i g h t a f t e r r e c e i v i n g the l o c a l v e r s i onin format ion .

∗/void h c i s e t c h i p s e t ( const b t s t a c k c h i p s e t t ∗ c h i p s e t d r i v e r ) ;

/∗∗∗ @br ie f Conf igure Blue too th hardware con t r o l . Has to be c a l l e d

b e f o r e power on .∗/

void h c i s e t c o n t r o l ( const btstack control t ∗ hardware contro l ) ;

/∗∗∗ @br ie f Conf igure Blue too th hardware con t r o l . Has to be c a l l e d

b e f o r e power on .∗/

void h c i s e t l i n k k e y d b ( btstack link key db t const ∗ l i nk key db ) ;

/∗∗∗ @br ie f Set c a l l b a c k f o r B lue too th Hardware Error∗/

Page 413: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

412

void h c i s e t h a r d w a r e e r r o r c a l l b a c k (void (∗ fn ) ( uint8 t e r r o r ) ) ;

/∗∗∗ @br ie f Set Pub l i c BD ADDR − passed on to Blue too th c h i p s e t during

i n i t i f suppor ted in b t c o n t r o l h∗/

void h c i s e t b d a d d r (bd addr t addr ) ;

/∗∗∗ @br ie f Conf igure Voice S e t t i n g f o r use wi th SCO data in HSP/HFP∗/

void h c i s e t s c o v o i c e s e t t i n g (uint16 t v o i c e s e t t i n g ) ;

/∗∗∗ @br ie f Get SCO Voice S e t t i n g∗ @return current vo i c e s e t t i n g∗/

uint16 t h c i g e t s c o v o i c e s e t t i n g (void ) ;

/∗∗∗ @br ie f Set i n qu i r y mode : standard , wi th RSSI , wi th RSSI +

Extended Inqu i ry Resu l t s . Has to be c a l l e d b e f o r e power on .∗ @param inquriy mode see b l u e t o o t h d e f i n e s . h∗/

void h c i s e t i n q u i r y m o d e ( inqu i ry mode t mode) ;

/∗∗∗ @br ie f Requests the change o f BTstack power mode .∗/

int h c i p o w e r c o n t r o l (HCI POWER MODE mode) ;

/∗∗∗ @br ie f Shutdown HCI∗/

void h c i c l o s e (void ) ;

// Ca l l back r e g i s t r a t i o n

/∗∗∗ @br ie f Add event packe t hand ler .∗/

void hc i add even t hand l e r ( b t s t a c k p a c k e t c a l l b a c k r e g i s t r a t i o n t ∗c a l l b a c k h a n d l e r ) ;

/∗∗∗ @br ie f Reg i s t e r s a packe t hand ler f o r ACL data . Used by L2CAP∗/

void h c i r e g i s t e r a c l p a c k e t h a n d l e r (btstack packet handler thandler ) ;

/∗∗

Page 414: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

413

∗ @br ie f Reg i s t e r s a packe t hand ler f o r SCO data . Used f o r HSP andHFP p r o f i l e s .

∗/void h c i r e g i s t e r s c o p a c k e t h a n d l e r (btstack packet handler t

handler ) ;

// Sending HCI Commands

/∗∗∗ @br ie f Check i f CMD packe t can be sen t to c o n t r o l l e r∗/

int hci can send command packet now (void ) ;

/∗∗∗ @br ie f Creates and sends HCI command packe t s based on a temp la te

and a l i s t o f parameters . Wi l l re turn error i f ou tgo ing datab u f f e r i s occupied .

∗/int hci send cmd ( const hci cmd t ∗cmd , . . . ) ;

// Sending SCO Packets

/∗∗ @br ie f Get SCO packe t l e n g t h f o r curren t SCO Voice s e t t i n g∗ @note Using SCO packe t s o f the exac t l e n g t h i s r e qu i r ed f o r USB

t r an s f e r∗ @return Length o f SCO packe t s in b y t e s ( not audio frames ) i n c l .

3 by t e header∗/

int h c i g e t s c o p a c k e t l e n g t h (void ) ;

/∗∗∗ @br ie f Request emiss ion o f HCI EVENT SCO CAN SEND NOW as soon as

p o s s i b l e∗ @note HCI EVENT SCO CAN SEND NOW might be emi t ted during c a l l to

t h i s f unc t i on∗ so packe t hand ler shou ld be ready to handle i t∗/

void h c i r e q u e s t s c o c a n s e n d n o w e v e n t (void ) ;

/∗∗∗ @br ie f Check HCI packe t b u f f e r and i f SCO packe t can be sen t to

c o n t r o l l e r∗/

int hc i can send sco packe t now (void ) ;

/∗∗∗ @br ie f Check i f SCO packe t can be sen t to c o n t r o l l e r∗/

int hc i can send prepared sco packe t now (void ) ;

/∗∗∗ @br ie f Send SCO packe t prepared in HCI packe t b u f f e r

Page 415: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

414

∗/int h c i s e n d s c o p a c k e t b u f f e r ( int s i z e ) ;

// Outgoing packe t bu f f e r , a l s o used f o r SCO packe t s// see hc i can send prepared sco packe t now amn

h c i s e n d s c o p a c k e t b u f f e r

/∗∗∗ Reserves outgo ing packe t b u f f e r .∗ @return 1 on succe s s∗/

int h c i r e s e r v e p a c k e t b u f f e r (void ) ;

/∗∗∗ Get po in t e r f o r outgo ing packe t b u f f e r∗/

uint8 t∗ h c i g e t o u t g o i n g p a c k e t b u f f e r (void ) ;

/∗∗∗ Release outgo ing packe t b u f f e r \∗ @note on ly c a l l e d in s t ead o f hc i s end preparared∗/

void h c i r e l e a s e p a c k e t b u f f e r (void ) ;

/∗∗∗ @br ie f Se t s the master/ s l a v e p o l i c y∗ @param po l i c y ( 0 : at tempt to become master , 1 : l e t connect ing

dev i c e dec ide )∗/void h c i s e t m a s t e r s l a v e p o l i c y ( uint8 t p o l i c y ) ;

31.29. HCI Logging API.

typedef enum {HCI DUMP BLUEZ = 0 ,HCI DUMP PACKETLOGGER,HCI DUMP STDOUT

} hci dump format t ;

/∗∗ @br ie f∗/

void hci dump open ( const char ∗ f i l ename , hc i dump format t format ) ;

/∗∗ @br ie f∗/

void hci dump set max packets ( int packets ) ; // −1 f o r un l imi t ed

/∗∗ @br ie f∗/

Page 416: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

415

void hci dump packet ( uint8 t packet type , uint8 t in , uint8 t ∗packet , uint16 t l en ) ;

/∗∗ @br ie f∗/

void hci dump log ( int l o g l e v e l , const char ∗ format , . . . )#ifde f GNUC

a t t r i b u t e ( ( format ( p r i n t f , 2 , 3) ) )#endif;

/∗∗ @br ie f∗/

void h c i d u m p e n a b l e l o g l e v e l ( int l o g l e v e l , int enable ) ;

/∗∗ @br ie f∗/

void hc i dump c lose (void ) ;

31.30. HCI Transport API.

/∗ HCI packe t t ype s ∗/typedef struct {

/∗∗∗ t r an spo r t name∗/

const char ∗ name ;

/∗∗∗ i n i t t r an spo r t∗ @param t r an s p o r t c on f i g∗/

void (∗ i n i t ) ( const void ∗ t r a n s p o r t c o n f i g ) ;

/∗∗∗ open t ranspo r t connect ion∗/

int (∗ open ) (void ) ;

/∗∗∗ c l o s e t r an spo r t connect ion∗/

int (∗ c l o s e ) (void ) ;

/∗∗∗ r e g i s t e r packe t hand ler f o r HCI packe t s : ACL, SCO, and Events∗/

void (∗ r e g i s t e r p a c k e t h a n d l e r ) (void (∗ handler ) ( uint8 tpacket type , uint8 t ∗packet , uint16 t s i z e ) ) ;

Page 417: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

416

/∗∗∗ suppor t async t r an spo r t l aye r s , e . g . IRQ dr iven wi thout

b u f f e r s∗/

int (∗ can send packet now ) ( uint8 t packet type ) ;

/∗∗∗ send packe t∗/

int (∗ send packet ) ( uint8 t packet type , uint8 t ∗packet , ints i z e ) ;

/∗∗∗ ex t ens ion f o r UART transpo r t implementat ions∗/

int (∗ s e t baudra te ) (uint32 t baudrate ) ;

/∗∗∗ ex t ens ion f o r UART H5 on CSR: r e s e t BCSP/H5 Link∗/

void (∗ r e s e t l i n k ) (void ) ;

/∗∗∗ ex t ens ion f o r USB t ranspo r t implementat ions : c on f i g SCO

connect ions∗/

void (∗ s e t s c o c o n f i g ) (uint16 t v o i c e s e t t i n g , intnum connections ) ;

} hci transport t ;

typedef enum {HCI TRANSPORT CONFIG UART,HCI TRANSPORT CONFIG USB

} h c i t r a n s p o r t c o n f i g t y p e t ;

typedef struct {h c i t r a n s p o r t c o n f i g t y p e t type ;

} h c i t r a n s p o r t c o n f i g t ;

typedef struct {h c i t r a n s p o r t c o n f i g t y p e t type ; // ==

HCI TRANSPORT CONFIG UARTuint32 t b a u d r a t e i n i t ; // i n i t i a l baud ra t euint32 t baudrate main ; // = 0: same as i n i t i a l baudrateint f l o w c o n t r o l ; //const char ∗device name ;

} h c i t r a n s p o r t c o n f i g u a r t t ;

// i n l i n e var ious hc i t r an spo r t X . h f i l e s

/∗∗ @br ie f Setup H4 ins tance wi th u a r t d r i v e r

Page 418: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

417

∗ @param ua r t d r i v e r to use∗/

const hci transport t ∗ h c i t r a n s p o r t h 4 i n s t a n c e ( constb t s t a c k u a r t b l o c k t ∗ u a r t d r i v e r ) ;

/∗∗ @br ie f Setup H5 ins tance wi th u a r t d r i v e r∗ @param ua r t d r i v e r to use∗/

const hci transport t ∗ h c i t r a n s p o r t h 5 i n s t a n c e ( constb t s t a c k u a r t b l o c k t ∗ u a r t d r i v e r ) ;

/∗∗ @br ie f Setup H4 over SPI ins tance f o r EM9304 with

em9304 sp i dr i ve r∗ @param em9304 sp i dr i ve r to use∗/

const hci transport t ∗ h c i t r a n s p o r t e m 9 3 0 4 s p i i n s t a n c e ( constbt s ta ck em9304 sp i t ∗ em9304 sp i d r iv e r ) ;

/∗∗ @br ie f Enable H5 Low Power Mode : en ter s l e e p mode a f t e r x ms o f

i n a c t i v i t y∗ @param ina c t i v i t y t imeou t ms or 0 f o r o f f∗/

void h c i t r a n s p o r t h 5 s e t a u t o s l e e p (uint16 t i n a c t i v i t y t i m e o u t m s );

/∗∗ @br ie f Enable BSCP mode H5, by enab l i ng event p a r i t y∗/

void hc i t ranspor t h5 enab l e bc sp mode (void ) ;

/∗∗ @br ie f∗/

const hci transport t ∗ h c i t r a n s p o r t u s b i n s t a n c e (void ) ;

/∗∗∗ @br ie f Spec i f y USB Blue too th dev i c e v ia por t numbers from root to

dev i c e∗/

void h c i t r a n s p o r t u s b s e t p a t h ( int len , uint8 t ∗ port numbers ) ;

31.31. L2CAP API.

/∗∗∗ @br ie f Set up L2CAP and r e g i s t e r L2CAP with HCI l a y e r .∗/

void l 2 c a p i n i t (void ) ;

/∗∗

Page 419: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

418

∗ @br ie f Reg i s t e r s packe t hand ler f o r LE Connection ParameterUpdate even t s

∗/void l 2 c a p r e g i s t e r p a c k e t h a n d l e r (void (∗ handler ) ( uint8 t

packet type , uint16 t channel , uint8 t ∗packet , uint16 t s i z e ) ) ;

/∗∗∗ @br ie f Get max MTU for C l a s s i c connec t ions based on b t s t a c k

con f i g u ra t i on∗/

uint16 t l2cap max mtu (void ) ;

/∗∗∗ @br ie f Get max MTU for LE connect ions based on b t s t a c k

con f i g u ra t i on∗/

uint16 t l2cap max le mtu (void ) ;

/∗∗∗ @br ie f Set the max MTU for LE connect ions , i f not s e t

l2cap max mtu () w i l l be used .∗/void l 2 cap se t max le mtu (uint16 t max mtu) ;

/∗∗∗ @br ie f Creates L2CAP channel to the PSM of a remote dev i c e wi th

baseband address . A new baseband connect ion w i l l be i n i t i a t e di f necessary .

∗ @param packe t hand l e r∗ @param address∗ @param psm∗ @param mtu∗ @param l o c a l c i d∗ @return s t a t u s∗/

uint8 t l 2 c a p c r e a t e c h a n n e l (btstack packet handler t packet handler, bd addr t address , uint16 t psm , uint16 t mtu , uint16 t ∗o u t l o c a l c i d ) ;

/∗∗∗ @br ie f Creates L2CAP channel to the PSM of a remote dev i c e wi th

baseband address us ing Enhanced Retransmiss ion Mode .∗ A new baseband connect ion w i l l be i n i t i a t e d i f necessary .∗ @param packe t hand l e r∗ @param address∗ @param psm∗ @param er tm con f i g∗ @param bu f f e r to s t o r e reassembled rx packet , out−of−order

packe t s and unacknowledged outgo ing packe t s wi th t h e i rt r e t r an smi s s i on t imers

∗ @param s i z e o f b u f f e r∗ @param l o c a l c i d∗ @return s t a t u s∗/

Page 420: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

419

uint8 t l 2 c a p c r e a t e e r t m c h a n n e l (btstack packet handler tpacket handler , bd addr t address , uint16 t psm ,l 2 c a p e r t m c o n f i g t ∗ ertm cont ig , uint8 t ∗ bu f f e r , uint32 t

s i z e , uint16 t ∗ o u t l o c a l c i d ) ;

/∗∗∗ @br ie f Disconnects L2CAP channel wi th g iven i d e n t i f i e r .∗/

void l 2 c a p d i s c o n n e c t (uint16 t l o c a l c i d , uint8 t reason ) ;

/∗∗∗ @br ie f Queries the maximal t r an s f e r un i t (MTU) fo r L2CAP channel

wi th g iven i d e n t i f i e r .∗/

uint16 t l 2 c a p g e t r e m o t e m t u f o r l o c a l c i d (uint16 t l o c a l c i d ) ;

/∗∗∗ @br ie f Sends L2CAP data packe t to the channel wi th g iven

i d e n t i f i e r .∗/

int l 2 cap send (uint16 t l o c a l c i d , uint8 t ∗data , uint16 t l en ) ;

/∗∗∗ @br ie f Reg i s t e r s L2CAP s e r v i c e wi th g i ven PSM and MTU, and

a s s i gn s a packe t hand ler .∗/

uint8 t l 2 c a p r e g i s t e r s e r v i c e (btstack packet handler tpacket handler , uint16 t psm , uint16 t mtu , g a p s e c u r i t y l e v e l t

s e c u r i t y l e v e l ) ;

/∗∗∗ @br ie f Unreg i s t e r s L2CAP s e r v i c e wi th g iven PSM.∗/

uint8 t l 2 c a p u n r e g i s t e r s e r v i c e (uint16 t psm) ;

/∗∗∗ @br ie f Accepts incoming L2CAP connect ion .∗/

void l 2 c a p a c c e p t c o n n e c t i o n (uint16 t l o c a l c i d ) ;

/∗∗∗ @br ie f Accepts incoming L2CAP connect ion f o r Enhanced

Retransmiss ion Mode∗ @param l o c a l c i d∗ @param er tm con f i g∗ @param bu f f e r to s t o r e reassembled rx packet , out−of−order

packe t s and unacknowledged outgo ing packe t s wi th t h e i rt r e t r an smi s s i on t imers

∗ @param s i z e o f b u f f e r∗ @return s t a t u s∗/

uint8 t l 2 cap acc ep t e r tm connec t i on (uint16 t l o c a l c i d ,l 2 c a p e r t m c o n f i g t ∗ ertm cont ig , uint8 t ∗ bu f f e r , uint32 ts i z e ) ;

Page 421: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

420

/∗∗∗ @br ie f Deny incoming L2CAP connect ion .∗/

void l 2 c a p d e c l i n e c o n n e c t i o n (uint16 t l o c a l c i d ) ;

/∗∗∗ @br ie f Check i f ou tgo ing b u f f e r i s a v a i l a b l e and t ha t t h e r e ’ s

space on the Blue too th module∗/

int l 2cap can send packet now (uint16 t l o c a l c i d ) ;

/∗∗∗ @br ie f Request emiss ion o f L2CAP EVENT CAN SEND NOW as soon as

p o s s i b l e∗ @note L2CAP EVENT CAN SEND NOW might be emi t ted during c a l l to

t h i s f unc t i on∗ so packe t hand ler shou ld be ready to handle i t∗ @param l o c a l c i d∗/

void l 2 cap reque s t can send now event (uint16 t l o c a l c i d ) ;

/∗∗∗ @br ie f Reserve outgo ing b u f f e r∗ @note Only f o r L2CAP Basic Mode Channels∗/

int l 2 c a p r e s e r v e p a c k e t b u f f e r (void ) ;

/∗∗∗ @br ie f Get outgo ing b u f f e r and prepare data .∗ @note Only f o r L2CAP Basic Mode Channels∗/

uint8 t ∗ l 2 c a p g e t o u t g o i n g b u f f e r (void ) ;

/∗∗∗ @br ie f Send L2CAP packe t prepared in outgo ing b u f f e r to channel∗ @note Only f o r L2CAP Basic Mode Channels∗/

int l 2 cap send prepared (uint16 t l o c a l c i d , uint16 t l en ) ;

/∗∗∗ @br ie f Release outgo ing b u f f e r ( on ly needed i f

l 2 cap send prepared i s not c a l l e d )∗ @note Only f o r L2CAP Basic Mode Channels∗/

void l 2 c a p r e l e a s e p a c k e t b u f f e r (void ) ;

//// LE Connection Oriented Channels f e a t u r e wi th the LE Cred i t Based

Flow Contro l Mode == LE Data Channel//

Page 422: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

421

/∗∗∗ @br ie f Reg i s t e r L2CAP LE Data Channel s e r v i c e∗ @note MTU and i n i t i a l c r e d i t s are s p e c i f i e d in

l 2 c a p l e a c c e p t c onn e c t i o n ( . . ) c a l l∗ @param packe t hand l e r∗ @param psm∗ @param s e c u r i t y l e v e l∗/

uint8 t l 2 c a p l e r e g i s t e r s e r v i c e (btstack packet handler tpacket handler , uint16 t psm , g a p s e c u r i t y l e v e l ts e c u r i t y l e v e l ) ;

/∗∗∗ @br ie f Unreg i s t e r L2CAP LE Data Channel s e r v i c e∗ @param psm∗/

uint8 t l 2 c a p l e u n r e g i s t e r s e r v i c e (uint16 t psm) ;

/∗∗ @br ie f Accept incoming LE Data Channel connect ion∗ @param l o c a l c i d L2CAP LE Data Channel I d e n t i f i e r∗ @param r e c e i v e b u f f e r b u f f e r used f o r reassembly o f L2CAP

LE Informat ion Frames in to s e r v i c e data un i t (SDU) with g ivenMTU

∗ @param r e c e i v e b u f f e r s i z e b u f f e r s i z e e qua l s MTU∗ @param i n i t i a l c r e d i t s Number o f i n i t i a l c r e d i t s prov ided

to peer or L2CAP LE AUTOMATIC CREDITS to enab l e automaticc r e d i t s

∗/

uint8 t l 2 c a p l e a c c e p t c o n n e c t i o n (uint16 t l o c a l c i d , uint8 t ∗r e c e i v e s d u b u f f e r , uint16 t mtu , uint16 t i n i t i a l c r e d i t s ) ;

/∗∗∗ @br ie f Deny incoming LE Data Channel connect ion due to resource

c on s t r a i n t s∗ @param l o c a l c i d L2CAP LE Data Channel I d e n t i f i e r∗/

uint8 t l 2 c a p l e d e c l i n e c o n n e c t i o n (uint16 t l o c a l c i d ) ;

/∗∗∗ @br ie f Create LE Data Channel∗ @param packe t hand l e r Packet hand ler f o r t h i s connect ion∗ @param con handle ACL−LE HCI Connction Handle∗ @param psm Serv i c e PSM to connect to∗ @param r e c e i v e b u f f e r b u f f e r used f o r reassembly o f L2CAP

LE Informat ion Frames in to s e r v i c e data un i t (SDU) with g ivenMTU

∗ @param r e c e i v e b u f f e r s i z e b u f f e r s i z e e qua l s MTU∗ @param i n i t i a l c r e d i t s Number o f i n i t i a l c r e d i t s prov ided

to peer or L2CAP LE AUTOMATIC CREDITS to enab l e automaticc r e d i t s

Page 423: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

422

∗ @param s e c u r i t y l e v e l Minimum requ i r ed s e c u r i t y l e v e l∗ @param o u t l o c a l c i d L2CAP LE Channel I d e n t i f i e r i s

s t o r ed here∗/

uint8 t l 2 c a p l e c r e a t e c h a n n e l (btstack packet handler tpacket handler , h c i c o n h a n d l e t con handle ,uint16 t psm , uint8 t ∗ r e c e i v e s d u b u f f e r , uint16 t mtu ,

uint16 t i n i t i a l c r e d i t s , g a p s e c u r i t y l e v e l ts e c u r i t y l e v e l ,

uint16 t ∗ o u t l o c a l c i d ) ;

/∗∗∗ @br ie f Provide c r e d t i s f o r LE Data Channel∗ @param l o c a l c i d L2CAP LE Data Channel I d e n t i f i e r∗ @param c r e d i t s Number a d d i t i o n a l c r e d i t s f o r peer∗/

uint8 t l 2 c a p l e p r o v i d e c r e d i t s (uint16 t cid , uint16 t c r e d i t s ) ;

/∗∗∗ @br ie f Check i f packe t can be schedu l ed f o r t ransmiss ion∗ @param l o c a l c i d L2CAP LE Data Channel I d e n t i f i e r∗/

int l 2 cap l e can send now (uint16 t c id ) ;

/∗∗∗ @br ie f Request emiss ion o f L2CAP EVENT LE CAN SEND NOW as soon as

p o s s i b l e∗ @note L2CAP EVENT CAN SEND NOW might be emi t ted during c a l l to

t h i s f unc t i on∗ so packe t hand ler shou ld be ready to handle i t∗ @param l o c a l c i d L2CAP LE Data Channel I d e n t i f i e r∗/

uint8 t l 2 c a p l e r e q u e s t c a n s e n d n o w e v e n t (uint16 t c id ) ;

/∗∗∗ @br ie f Send data v ia LE Data Channel∗ @note Since data l a r g e r then the maximum PDU needs to be

segmented in to mu l t i p l e PDUs, data needs to s tay v a l i d u n t i l. . . event

∗ @param l o c a l c i d L2CAP LE Data Channel I d e n t i f i e r∗ @param data data to send∗ @param s i z e data s i z e∗/

uint8 t l 2 c a p l e s e n d d a t a (uint16 t cid , uint8 t ∗ data , uint16 ts i z e ) ;

/∗∗∗ @br ie f Disconnect from LE Data Channel∗ @param l o c a l c i d L2CAP LE Data Channel I d e n t i f i e r∗/

uint8 t l 2 c a p l e d i s c o n n e c t (uint16 t c id ) ;

32. Events and Errors

Page 424: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

423

32.1. L2CAP Events. L2CAP events and data packets are delivered to thepacket handler specified by l2cap register service resp. l2cap create channel. Datapackets have the L2CAP DATA PACKET packet type. L2CAP provides the fol-lowing events:

• L2CAP EVENT CHANNEL OPENED - sent if channel establishment isdone. Status not equal zero indicates an error. Possible errors: out ofmemory; connection terminated by local host, when the connection toremote device fails.• L2CAP EVENT CHANNEL CLOSED - emitted when channel is closed.

No status information is provided.• L2CAP EVENT INCOMING CONNECTION - received when the con-

nection is requested by remote. Connection accept and decline are per-formed with l2cap accept connection and l2cap decline connecti-on re-spectively.• L2CAP EVENT CAN SEND NOW - Indicates that an L2CAP data packet

could be sent on the reported l2cap cid. It is emitted after a call tol2cap request can send now. See Sending L2CAP Data Please note thatthe guarantee that a packet can be sent is only valid when the event isreceived. After returning from the packet handler, BTstack might needto send itself.

Table 3: L2CAP Events.

Event Event Code

L2CAP EVENT CHANNEL OPENED 0x70L2CAP EVENT CHANNEL CLOSED 0x71L2CAP EVENT INCOMING CONNECTION 0x72L2CAP EVENT CAN SEND NOW 0x78

L2CAP event paramaters, with size in bits:

• L2CAP EVENT CHANNEL OPENED:– event(8), len(8), status(8), address(48), handle(16), psm(16), lo-

cal cid(16), remote cid(16), local mtu(16), remote mtu(16)

• L2CAP EVENT CHANNEL CLOSED:– event (8), len(8), channel(16)

• L2CAP EVENT INCOMING CONNECTION:– event(8), len(8), address(48), handle(16), psm (16), local cid(16),

remote cid (16)• L2CAP EVENT CAN SEND NOW:

– *event(8), len(8), local cid(16)

32.2. RFCOMM Events. All RFCOMM events and data packets are currentlydelivered to the packet handler specified by rfcomm register packet handler. Datapackets have the DATA PACKET packet type. Here is the list of events pro-vided by RFCOMM:

Page 425: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

424

• RFCOMM EVENT INCOMING CONNECTION - received when the con-nection is requested by remote. Connection accept and decline are per-formed with rfcomm accept connection and rfcomm decline connectionrespectively.• RFCOMM EVENT CHANNEL CLOSED - emitted when channel is closed.

No status information is provided.• RFCOMM EVENT CHANNEL OPENED - sent if channel establishment

is done. Status not equal zero indicates an error. Possible errors: anL2CAP error, out of memory.• RFCOMM EVENT CAN SEND NOW - Indicates that an RFCOMM

data packet could be sent on the reported rfcomm cid. It is emitted af-ter a call to rfcomm request can send now. See Sending RFCOMM DataPlease note that the guarantee that a packet can be sent is only validwhen the event is received. After returning from the packet handler,BTstack might need to send itself.

Table 4: RFCOMM Events.

Event Event Code

RFCOMM EVENT CHANNEL OPENED 0x80RFCOMM EVENT CHANNEL CLOSED 0x81RFCOMM EVENT INCOMING CONNECTION 0x82RFCOMM EVENT CAN SEND NOW 0x89

RFCOMM event paramaters, with size in bits:

• RFCOMM EVENT CHANNEL OPENED:– event(8), len(8), status(8), address(48), handle(16), server channel(8),

rfcomm cid(16), max frame size(16)• RFCOMM EVENT CHANNEL CLOSED:

– event(8), len(8), rfcomm cid(16)• RFCOMM EVENT INCOMING CONNECTION:

– event(8), len(8), address(48), channel (8), rfcomm cid(16)• RFCOMM EVENT CAN SEND NOW:

– *event(8), len(8), rfcomm cid(16)

Table 5: Errors.

Error Error Code

BTSTACK MEMORY ALLOC FAILED 0x56BTSTACK ACL BUFFERS FULL 0x57L2CAP COMMAND REJECT REASON COMMAND NOT UNDERSTOOD 0x60L2CAP COMMAND REJECT REASON SIGNALING MTU EXCEEDED 0x61L2CAP COMMAND REJECT REASON INVALID CID IN REQUEST 0x62L2CAP CONNECTION RESPONSE RESULT SUCCESSFUL 0x63L2CAP CONNECTION RESPONSE RESULT PENDING 0x64L2CAP CONNECTION RESPONSE RESULT REFUSED PSM 0x65

Page 426: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

425

Error Error Code

L2CAP CONNECTION RESPONSE RESULT REFUSED SECURITY 0x66L2CAP CONNECTION RESPONSE RESULT REFUSED RESOURCES 0x65L2CAP CONFIG RESPONSE RESULT SUCCESSFUL 0x66L2CAP CONFIG RESPONSE RESULT UNACCEPTABLE PARAMS 0x67L2CAP CONFIG RESPONSE RESULT REJECTED 0x68L2CAP CONFIG RESPONSE RESULT UNKNOWN OPTIONS 0x69L2CAP SERVICE ALREADY REGISTERED 0x6aRFCOMM MULTIPLEXER STOPPED 0x70RFCOMM NO OUTGOING CREDITS 0x72SDP HANDLE ALREADY REGISTERED 0x80

32.3. Errors.

33. Migration to v1.0

We already had two listings with the Bluetooth SIG, but no official BTstackv1.0 release. After the second listing, we decided that it’s time for a majoroverhaul of the API - making it easier for new users.

In the following, we provide an overview of the changes and guidelines forupdating an existing code base. At the end, we present a command line tool andas an alternative a Web service, that can simplify the migration to the new v1.0API.

34. Changes

34.1. Repository structure.

34.1.1. include/btstack folder. The header files had been split between src/ andinclude/btstack/. Now, the include/ folder is gone and the headers are pro-vided in src/, src/classic/, src/ble/ or by the platform/ folders. There’s a newsrc/btstack.h header that includes all BTstack headers.

34.1.2. Plural folder names. Folder with plural names have been renamed to thesingular form, examples: doc, chipset, platform, tool.

34.1.3. ble and src folders. The ble folder has been renamed into src/ble. Filesthat are relevant for using BTstack in Classic mode, have been moved to src/-classic. Files in src that are specific to individual platforms have been moved toplatform or port.

34.1.4. platform and port folders. The platforms folder has been split into plat-form and “port” folders. The port folder contains a complete BTstack port offor a specific setup consisting of an MCU and a Bluetooth chipset. Code thatdidn’t belong to the BTstack core in src have been moved to platform or port aswell, e.g. hci transport h4 dma.c.

34.1.5. Common file names. Types with generic names like linked list have beenprefixed with btstack (e.g. btstack linked list.h) to avoid problems when inte-grating with other environments like vendor SDKs.

Page 427: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

426

34.2. Defines and event names. All defines that originate from the Blue-tooth Specification are now in src/bluetooth.h. Addition defines by BTstackare collected in src/btstack defines.h. All events names have the form MOD-ULE EVENT NAME now.

34.3. Function names.

• The internal suffix has been an artifact from the iOS port. All publicfunctions with the internal suffix have been stripped of this suffix.• Types with generic names like linked list have been prefixed with btstack

(e.g. btstack linked list) to avoid problems when integrating with otherenvironments like vendor SDKs.

34.4. Packet Handlers. We streamlined the use of packet handlers and theirtypes. Most callbacks are now of type btstack packet handler t and receive apointer to an HCI Event packet. Often a void * connection was the first argument- this has been removed.

To facilitate working with HCI Events and get rid of manually calculatingoffsets into packets, we’re providing auto-generated getters for all fields of allevents in src/hci event.h. All functions are defined as static inline, so they arenot wasting any program memory if not used. If used, the memory footprintshould be identical to accessing the field directly via offsets into the packet. Feelfree to start using these getters as needed.

34.5. Event Forwarding. In the past, events have been forwarded up the stackfrom layer to layer, with the undesired effect that an app that used both att serverand security manager would get each HCI event twice. To fix this and otherpotential issues, this has been cleaned up by providing a way to register multiplelisteners for HCI events. If you need to receive HCI or GAP events, you can nowdirectly register your callback with hci add event handler.

34.6. util folder. The utils folder has been renamed into btstack util to avoidcompile issues with other frameworks.

• The functions to read/store values in little/bit endian have been renamedinto big/little endian read/write 16/24/32.• The functions to reverse bytes swap16/24/32/48/64/128/X habe been

renamed to reverse 16/24/32/48/64/128/X.

34.7. btstack config.h.

• btstack-config.h is now btstack config.h• Defines have been sorted: HAVE specify features that are particular to

your port. ENABLE features can be added as needed.• NO has been replaced with NR for the BTstack static memory allocation,

e.g., MAX NO HCI CONNECTIONS8 -> MAX NR HCI CONNECTIONS• The #define EMBEDDED is dropped, i.e. the distinction if the API is

for embedded or not has been removed.

Page 428: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

427

34.8. Linked List.

• The file has been renamed to btstack linked list.• All functions are prefixed with btstack .• The user data field has been removed as well.

34.9. Run Loop.

• The files have been renamed to btstack run loop• To allow for simpler integration of custom run loop implementations,

run loop init(. . . ) is now called with a pointer to a run loop t functiontable instead of using an enum that needs to be defined inside the BTstacksources.• Timers now have a new context field that can be used by the user.

34.10. HCI Setup. In the past, hci init(. . . ) was called with an hci transport t,the transport configuration, remote device t and a bt control t objects. Besidescleaning up the types (see remote device db and bt control below), hci init onlyrequires the hci transport t and it’s configuration.

The used btstack chipset t, bt control t, or link key db t can now be set withhci set chipset, hci set control, and hci set link key db respectively.

34.10.1. remote device db. Has been split into src/classic/btstack link key db, plat-form/daemon/btstack device name db, and platform/daemon/rfcomm service db.

34.10.2. bt control. Has been split into src/btstack chipset.h and src/bstack control.h

34.11. HCI / GAP. HCI functions that are commonly placed in GAP havebeen moved from src/hci.h to src/gap.h

34.12. RFCOMM. In contrast to L2CAP, RFCOMM did not allow to regis-ter individual packet handlers for each service and outgoing connection. Thishas been fixed and the general rfcomm register packet handler(. . . ) has beenremoved.

34.13. SPP Server. The function to create an SPP SDP record has been movedinto spp server.h

34.14. SDP Client.

• SDP Query structs have been replaced by HCI events. You can usebtstack event.h to access the fields.

34.15. SDP Server.

• Has been renamed to src/classic/sdp server.h.• The distinction if the API is for embedded or not has been removed.

34.16. Security Manager.

• In all Security Manager calls that refer to an active connection, pass inthe current handle instead of addr + addr type.• All Security Manager events are now regular HCI Events instead of sm *

structs• Multiple packet handler can be registered with sm add event handler(. . . )

similar to HCI.

Page 429: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

428

34.17. GATT Client.

• All GATT Client events are now regular HCI Events instead of gatt *structs.• The subclient id has been replaced by a complete handler for GATT

Client requests

34.18. ANCS Client. Renamed to src/ble/ancs client

34.19. Flow control / DAEMON EVENT HCI PACKET SENT. In BT-stack, you can only send a packet with most protocols (L2CAP, RFCOMM, ATT)if the outgoing buffer is free and also per-protocol constraints are satisfied, e.g.,there are outgoing credits for RFCOMM.

Before v1.0, we suggested to check with l2cap can send packet now(..) or rf-comm can send packet(..) whenever an HCI event was received. This has beencleaned up and streamlined in v1.0.

Now, when there is a need to send a packet, you can call rcomm request can send now(..)/ l2cap request can send now(..) to let BTstack know that you want to send apacket. As soon as it becomes possible to send a RFCOMM EVENT CAN SEND NOW/L2CAP EVENT CAN SEND NOWwill be emitted and you can directly react on that and send a packet. After that,you can request another “can send event” if needed.

34.20. Daemon.

• Not tested since API migration!• Moved into platform/daemon/• Header for clients: platform/daemon/btstack client.h• Java bindings are now at platform/daemon/bindings

34.21. Migration to v1.0 with a script. To simplify the migration to the newv1.0 API, we’ve provided a tool in tool/migration to v1.0 that fixes include pathchanges, handles all function renames and also updates the packet handlers tothe btstack packet handler t type. It also has a few rules that try to rename filenames in Makefile as good as possible.

It’s possible to migrate most of the provided embedded examples to v1.0. Theone change that it cannot handle is the switch from structs to HCI Events for theSDP, GATT, and ANCS clients. The migration tool updates the packet handlersignature to btstack packet handler t, but it does not convert the field accesses tosue the appropriate getters in btstack event.h. This has to be done manually, butit is straight forward. E.g., to read the field status of the GATT EVENT QUERY COMPLETE,you call call gatt event query complete get status(packet).

34.21.1. Requirements.

• bash• sed• Coccinelle. On Debian-based distributions, it’s available via apt. On OS

X, it can be installed via Homebrew.

Page 430: IncludingQuickstartGuide - BlueKitchen GmbH Contents 1. Welcome2 2. Quick Start2 2.1. General Tools2 2.2. Getting BTstack from GitHub2 2.3. Let’s Go2 3. BTstack Architecture3 3.1.

429

34.21.2. Usage.

t o o l / mig ra t i on to v1 .0/ migrat ion . sh PATH TO ORIGINAL PROJECTPATH TO MIGRATED PROJECT

The tool first creates a copy of the original project and then uses sed andcoccinelle to update the source files.

34.22. Migration to v1.0 with a Web Service. BlueKitchen GmbH is pro-viding a web service to help migrate your sources if you don’t want or cannotinstall Coccinelle yourself.


Recommended