BLE Stack API Reference v2.2
BLE Stack API Reference v2.2
Copyright 2001 - 2012 Bluegiga Technologies Bluegiga Technologies reserves the right to alter the hardware, software, and/or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. Bluegiga Technologies assumes no responsibility for any errors which may appear in this manual. Bluegiga Technologies' products are not authorized for use as critical components in life support devices or systems. Bluegiga Access Server, Access Point, AX4, BSM, iWRAP, BGScript and WRAP THOR are trademarks of Bluegiga Technologies. The Bluetooth trademark and logo are registered trademarks and are owned by the Bluetooth SIG, Inc. ARM and ARM9 are trademarks of ARM Ltd. Linux is a trademark of Linus Torvalds. All other trademarks listed herein belong to their respective owners.
TABLE OF CONTENTS
1. Version History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2. Introduction to Bluetooth Smart SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1 Bluetooth 4.0 single mode stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 BGAPI protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 BGLib library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 BGScript scripting language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5 Profile Toolkit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3. Introduction to Bluetooth Smart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.1 Physical layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Packet format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.1 Generic packet format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.2 Advertisement packet format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2.3 Data packet format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3 Link layer state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4 Link layer operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.1 Passive scanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.2 Active scanning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.4.3 Connection establishment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5 Topologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.6 Connections and packet timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.7 Encryption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.8 L2CAP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.9 Security Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.10 Attribute Protocol (ATT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.11 Generic Attribute Profile (GATT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.12 Generic Access Profile (GAP) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4. API definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.1 BGAPI protocol definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 BGLib functions definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 BGScript API definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5. API Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1 Attribute Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.1 Attribute Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.2 Execute Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.3 Find By Type Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.4 Find Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.5 Indicate Confirm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.6 Prepare Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.7 Read By Group Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.8 Read By Handle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.9 Read By Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.10 Read Long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.11 Read Multiple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1.12 Write Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2.1 Attribute Value Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3.1 Attribute Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3.2 Find Information Found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3.3 Group Found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3.4 Indicated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3.5 Procedure Completed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3.6 Read Multiple Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Attribute Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1.1 Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1.2 Read Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1.3 User Read Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1.4 User Write Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.1.5 Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 8 8 9 9 10 11 12 12 13 13 13 13 15 16 16 17 17 18 19 21 22 23 24 27 30 31 31 34 35 36 37 38 38 38 40 42 44 46 47 49 51 53 55 57 59 61 61 62 62 63 64 65 66 67 68 68 68 70 71 72 73
5.2.2 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.2.1 Attribute Change Reason . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.2.2 Attribute Status Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.3 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.3.1 Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.3.2 User Read Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2.3.3 Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1.1 Disconnect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1.2 Get Rssi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1.3 Get Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1.4 Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.1.5 Version Update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.2 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.2.1 Connection Status Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.3 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.3.1 Disconnected . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.3.2 Feature Ind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.3.3 Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3.3.4 Version Ind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Generic Access Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.1 Connect Direct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.2 Connect Selective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.3 Discover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.4 End Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.5 Set Adv Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.6 Set Adv Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.7 Set Directed Connectable Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.8 Set Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.9 Set Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.10 Set Privacy Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.1.11 Set Scan Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.1 AD_FLAGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.2 AD Type Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.3 Advertising policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.4 Bluetooth Address Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.5 GAP Connectable Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.6 GAP Discoverable Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.7 GAP Discover Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.8 SCAN_HEADER_FLAGS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.2.9 Scan Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.3 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.3.1 Scan Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.1 ADC Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.2 I2c Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.3 I2c Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.4 Io Port Config Direction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.5 Io Port Config Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.6 IO Port Config IRQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.7 Io Port Config Pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.8 Io Port Read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.9 Io Port Write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.10 Set Soft Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.11 Set Txpower . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.12 Spi Config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.13 Spi Transfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.1.14 Timer Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.2 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.2.1 ADC Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74 74 75 76 76 77 78 79 79 79 81 82 83 85 87 87 88 88 89 90 91 92 92 92 94 96 98 99 100 102 104 105 107 108 109 109 110 111 112 113 114 115 116 117 118 118 120 120 120 122 124 126 128 129 131 133 134 135 137 138 140 142 144 144
5.5.2.2 IO Port Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5.2.3 Soft Timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6 Persistent Store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.1.1 PS Defrag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.1.2 PS Dump . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.1.3 PS Erase All . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.1.4 PS Erase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.1.5 PS Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.1.6 PS Save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.2 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.6.2.1 PS Key . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7 Security Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1.1 Delete Bonding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1.2 Encrypt Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1.3 Get Bonds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1.4 Passkey Entry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1.5 Set Bondable Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1.6 Set Oob Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.1.7 Set Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.2 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.2.1 Bonding Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.2.2 SMP IO Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.3 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.3.1 Bonding Fail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.3.2 Bond Status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.3.3 Passkey Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.7.3.4 Passkey Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8 System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.1 Address Get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.2 Endpoint Rx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.3 Endpoint Set Watermarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.4 Endpoint Tx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.5 Get Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.6 Get Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.7 Get Info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.8 Hello . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.9 Reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.10 Whitelist Append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.11 Whitelist Clear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.1.12 Whitelist Remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.2 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.2.1 Endpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.3 Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.3.1 Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.3.2 Endpoint Watermark Rx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.3.3 Endpoint Watermark Tx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.8.3.4 Script Failure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9 Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1 BGAPI Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.1 Invalid Parameter (0x0180) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.2 Device in Wrong State (0x0181) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.3 Out Of Memory (0x0182) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.4 Feature Not Implemented (0x0183) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.5 Command Not Recognized (0x0184) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.6 Timeout (0x0185) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.7 Not Connected (0x0186) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.8 flow (0x0187) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.1.9 User Attribute (0x0188) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2 Bluetooth Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.1 Authentication Failure (0x0205) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.2 Pin or Key Missing (0x0206) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
145 146 147 147 147 148 149 150 151 152 153 153 154 154 154 156 158 159 160 161 162 163 163 164 165 165 166 167 168 169 169 169 170 171 173 174 175 176 178 179 180 181 182 183 183 184 184 185 186 187 188 188 188 188 188 189 189 189 189 189 189 189 189 189
5.9.2.3 Memory Capacity Exceeded (0x0207) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.4 Connection Timeout (0x0208) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.5 Connection Limit Exceeded (0x0209) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.6 Command Disallowed (0x020C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.7 Invalid Command Parameters (0x0212) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.8 Remote User Terminated Connection (0x0213) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.9 Connection Terminated by Local Host (0x0216) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.10 LL Response Timeout (0x0222) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.11 LL Instant Passed (0x0228) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.12 Controller Busy (0x023A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.13 Directed Advertising Timeout (0x023C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.14 MIC Failure (0x023D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.2.15 Connection Failed to be Established (0x023E) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3 Security Manager Protocol Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.1 Passkey Entry Failed (0x0301) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.2 OOB Data is not available (0x0302) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.3 Authentication Requirements (0x0303) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.4 Confirm Value Failed (0x0304) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.5 Pairing Not Supported (0x0305) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.6 Encryption Key Size (0x0306) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.7 Command Not Supported (0x0307) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.8 Unspecified Reason (0x0308) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.9 Repeated Attempts (0x0309) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.3.10 Invalid Parameters (0x030A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4 Attribute Protocol Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.1 Invalid Handle (0x0401) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.2 Read Not Permitted (0x0402) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.3 Write Not Permitted (0x0403) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.4 Invalid PDU (0x0404) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.5 Insufficient Authentication (0x0405) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.6 Request Not Supported (0x0406) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.7 Invalid Offset (0x0407) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.8 Insufficient Authorization (0x0408) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.9 Prepare Queue Full (0x0409) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.10 Attribute Not Found (0x040A) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.11 Attribute Not Long (0x040B) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.12 Insufficient Encryption Key Size (0x040C) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.13 Invalid Attribute Value Length (0x040D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.14 Unlikely Error (0x040E) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.15 Insufficient Encryption (0x040F) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.16 Unsupported Group Type (0x0410) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.17 Insufficient Resources (0x0411) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.9.4.18 Application Error Codes (0x0480) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6. Contact information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
190 190 190 190 190 190 190 190 190 190 190 190 190 190 191 191 191 191 191 191 191 191 192 192 192 192 192 192 193 193 193 193 193 193 193 193 193 193 193 193 193 193 194 195
1 Version History
Version 1.3 2.0 2.1 API documentation for SW version v.1.0.3 (Build 43) API documentation for v.1.1.0 beta (Build 46) API documentation for v.1.1.0 beta (Build 55) Note: API changes history is now included here (not separate) Changed APIs: * Attribute Database User Read Response (function implemented for Beta 2) * Connection Connection Status Flags (fixed) Doc improved for following APIs: * Attribute Client Attribute Value, Indicated, Procedure Completed, Group Found * Attribute Database User Read Request * Generic Access Profile Discover, Set Adv Parameters * Hardware I2c Read, I2c Write, Set Soft Timer, Set Txpower * Security Manager Delete Bonding, Get Bonds * System Whitelist Append Other sections (outside API reference) has also been updated to improve the document 2.2 Added documentation how to use BGAPI protocol without UART flow control. Section updated: BGAPI protocol definition
Page 7 of 195
Page 8 of 195
Page 9 of 195
Page 10 of 195
Page 11 of 195
The requirements for the Bluetooth low energy radio are: Feature Minimum TX power Maximum TX power Value 0.01mW (-20 dBm) 10 mW (10 dBm)
Minimum RX sensitivity -70 dBm (BER 0.1%) The typical range for Bluetooth low energy radios is: TX power RX sensitivity Range 0 dBm 10 dBm -70 dBm -90 dBm ~30 meters 100+ meters
The figure below illustrates the link layer channels. There are 37 data channels and 3 advertisement channels.
Page 12 of 195
Figure 6: Generic packet format Preamble: either 010101010 or 101010101 Access address: advertisement packets use a fixed access address of 0x8E89BED6. Data packets use a random access address depending on the connection. PDU: protocol data unit depends on the packet type. CRC: a 24-bit CRC checksum is used to protect the PDU.
Page 13 of 195
An encrypted data packet can have 0 to 31 bytes of payload length, but MIC (Message Integrity Check) is part of it.
Page 14 of 195
Page 15 of 195
The advertisement packets typically contains information like: Discoverability and connectability modes The address of advertiser TX power level Supported services Application data
Page 16 of 195
Figure 12: Active scanning The scan response packets typically contains information like: Device friendly name Supported services (profiles)
Page 17 of 195
3.5 Topologies
Bluetooth low energy has four device roles: advertiser, scanner, master and slave. The technology supports point-to-point and start topologies. The figure below illustrates the device roles, and topologies. Advetiser : Broadcasts advertisement packets, but is not able to receive them Scanner : Listens for advertisement packets sent out by advertisers. Can try to connect an advertiser. Master : A device that is connected to one or several slaves Slave : A deivce that is connected to a master. Can only be connected to one master at a time
Figure 14: Bluetooth low energy topologies Devices can change roles and topologies as illustrated below.
Page 18 of 195
Conn_Latency
Supervision_Timeout
The connection parameters can be updated during the connection. The connection timeline and events are illustrated below.
Figure 16: Bluetooth LE connection The connection event starts, when master sends a packet to the slave at the defined connection interval. The slave can respond 150us after it has received a packet from the master. However if the slave has no data to send it can skip a certain number of connection events defined by the slave latency parameter. If no packets are received by the master or slave within the time defined by the supervision timeout, the connection is terminated. If the slave has more data to send than what can be fitted into a single packet, the connection event will automatically extend and the slave can send as many packets as there is time until the beginning of next connection interval. This however can only be used with attribute protocol operations, that do not require an acknowledgement.
Page 19 of 195
Page 20 of 195
3.7 Encryption
Bluetooth low energy uses AES-128 link layer encryption block with Counter Mode CBC MAC (defined in RFC 3610). The data packets are encrypted as show below.
Figure 18: Encrypted data packet The full AES encryption procedure is illustrated below.
Limitations of link layer encryption Maximum 2^39 packets per Long Term Key (LTK) 13.7 TB of data / connection ~12 years at maximum data rate
Page 21 of 195
3.8 L2CAP
L2CAP stands for Logical Link Control and Adaptation Protocol and it is acts as a protocol multiplexer and handles segmentation and reassembly of packets. It also provides logical channels, which are multiplexed over a or more logical links. All application data is sent over L2CAP packets and the L2CAP structure is illustrated below.
Figure 20: L2CAP packet format The following CIDs are defined: CID Description Notes Not used BR/EDR only BR/EDR only BR/EDR only LE only
0x0000 Null identifier 0x0001 L2CAP Signaling Channel 0x0002 Connectionless Channel 0x0003 AMP Manager Protocol 0x0004 Attribute Protocol
0x0005 LE L2CAP Signaling Channel LE only 0x0006 Security Manager Protocol LE only
Page 22 of 195
Page 23 of 195
Figure 22: Device roles Attribute types: Attributes are values: Arrays of octets From 0 to 512 octets Can be fixed or variable length Example: Value 0x0000 0x426c75656769676120546563686e6f6c6f67696573 Attribute have handles, which are used to address an individual attribute. The client accesses the server's attributes using this handle. Example: Handle Value 0x0001 0x0000 0x0002 0x426c75656769676120546563686e6f6c6f6769657
Attributes also have a type, described by a UUID. UUID determines what the attribute value means.
Page 24 of 195
Two types of UUIDs are used: Globally unique 16-bit UUID defined in the characteristics specifications (http://developer.bluetooth.org/) Manufacturer specific 128-bit UUIDs, which can for example be generated online. ( http://www.uuidgenerator.com/) Example: Handle UUID Value Description TX power as dBm
0x0002 0x2a00 0x426c75656769676120546563686e6f6c6f6769657 Device name, UTF-8 Attribute permissions: Attributes also have permissions, which can be: Readable / Not readable Writable / Not writable Readable and writable / Not readable and not writable The attributes may also require: Authentication to read or write Authorization to read or write Encryption and pairing to read or write The attribute types and handles are public information, but the permissions are not. Therefore and read or write request may result an error Read/Write Not Permitted or Insufficient authentication.
Page 25 of 195
Attribute protocol methods: The attribute protocol is a stateless sequential protocol, meaning that no state is stored in the protocol and only one operation can be performed at a time. The available Attribute Protocol methods are described in the table below: Method Find Information (starting handle, ending handle) Find By Type Value (starting handle, ending handle, type, value) Read By Group Type (starting handle, ending handle, type) Read By Type (starting handle, ending handle, type) Read (handle) Read Blob (handle, offset) Description Used to discover attribute handles and their types (UUIDs) Returns the handles of all attributes matching the type and value Reads the value of each attribute of a given type in a range Reads the value of each attribute of a given type in a range Reads the value of given handle Maximum payload : 22 bytes Can be used to read long attributes larger than 22 bytes. Maximum payload: 64 kBytes Used to read multiple values at the same time Writes the value to the given handle, with no response Maximum payload: 20 bytes Prepares a write procedure, which is queued in server until the write is executed. Direction Client -> Server Client -> Server Client -> Server Client -> Server Client -> Server Client -> Server Client -> Server Client -> Server Client -> Server Server -> Client Server -> Client Server -> Client
Read Multiple ([Handle]*) Write (handle, value) Prepare Write (handle, offset, value) and Execute (exec/cancel)
Handle Value Notification (handle, value) Server notifies client of an attribute with a new value Maximum payload: 20 bytes Handle Value Indication (handle, value) Server indicates to client an attribute with a new value. Client must confirm reception. Maximum payload: 20 bytes Any request can cause an error and error response contains information about the error
Error response
Page 26 of 195
Figure 23: GATT architecture GATT defines concepts of: Service Group Characteristic Group Declarations Descriptors It's important also to understand that GATT does not does not define rules for their use. Characteristics Characteristic is a value, with a known type, and a known format. They characteristics are defined in Characteristic Specification available at http://developer.bluetooth.org. Characteristics consist of: Characteristic Declaration Describes the properties of characteristic value (read, write, indicate etc.), characteristic value handle and characteristic value type (UUID) Characteristic Value Contains the value of the characteristic. Characteristic Descriptor(s) Provide additional information about the characteristic (characteristic user description, characteristic client configuration, vendor specific information etc.)
Page 27 of 195
Service A service is: defined in a service specification (http://developer.bluetooth.org) collection of characteristics references to other services There are two types of service: Primary services A primary service exposes primary functionality of a device. It can be included by an other service. Secondary services Secondary service is a subservient of another primary or a secondary service. It's only relevant in the context of an other service. Attributes alone are just flat:
Figure 25: List of attributes Grouping attributes into services gives structure:
Page 28 of 195
GATT procedures The available Attribute Protocol methods are described in the table below: Procedure Server Configuration Primary Service Discovery Relationship Discovery Characteristic Discovery Sub-Procedures Exchange MTU Discovery All Primary Service Discover Primary Service by Service UUID. Find Included Services Discover All Characteristics of a Service Discover Characteristics by UUID
Characteristic Descriptor Discovery Discover All Characteristic Descriptors Characteristic Value Read Characteristic Value Read Read Characteristic Value Read Using Characteristic UUID Read Long Characteristic Values Read Multiple Characteristic Values Characteristic Value Write Write Without Response Write Without Response With Authentication Write Characteristic Value Write Long Characteristic Values Reliable Writes Notifications Indications Read Characteristic Descriptors Read Long Characteristic Descriptors Write Characteristic Descriptors Write Long Characteristic Descriptors
Page 29 of 195
Page 30 of 195
4 API definition
This section contains the generic Bluetooth low energy stack API definition. The definition consist of three parts: The BGAPI protocol definition The BGLib C library description The BGScript scriting API description This section of the document only provides the generic definition and description of the API and the actual commands, responses and event are described in the API reference section.
Packet format
Packets in either direction use the following format. Table 1: BGAPI packet format Octet Octet 0 ... Octet bits Length 7 6:3 1 bit 4 bits Description Message Type (MT) Notes 0: Command/Response 1: Event
Technology Type (TT) 0000: Bluetooth 4.0 single mode 0001: Wi-Fi
Length High (LH) Length Low (LL) Class ID (CID) Command ID (CMD)
Payload length (high bits) Payload length (low bits) Command class ID Command ID Up to 2048 bytes of payload
Octet 4-n -
Message types
The following message types exist in the BGAPI protocol. Table 2: BGAPI message types Message type Command Response Event Value Description 0x00 0x00 0x80 Command from host to the stack Response from stack to the host Event from stack to the host
Page 31 of 195
Generic Access Profile GAP functions Hardware Provides access to hardware such as timers and ADC
Packet Exchange
The BGAPI protocol is a simple command / response protocol. The host should wait for the response to a command before issuing another command.
Page 32 of 195
Below is a simple example which shows how a System Get Info (Raw: 0x00 0x00 0x00 0x08) is sent in this BGAPI packet format.
Page 33 of 195
The command parameters and return values are the same as used in the BGAPI binary protocol and they are not documented separately. Callback programming Callback programming is a style of computer programming, which allows lower layer of software to call functions defined on a higher layer. Callback is piece of code or a reference to a piece of code that is passed as an argument. The figure below illustrates the callback architecture used with BGLib.
Figure 27: Callback arhitecture If you are not familiar with callback programming a basic tutorial can for example be found from here: http://www.codeguru.com/cpp/cpp/cpp_mfc/callbacks/article.php/c10557
Page 34 of 195
The BGScript command parameters and return values are the same as used in the BGAPI binary protocol and they are not documented separately.
Page 35 of 195
uint8array byte array, first byte is array size bd_addr Bluetooth address in little endian format
Page 36 of 195
5 API Reference
This section of the document contains the actual API description, so the description of commands, responses, events and enumerations. The high level categorizationis made based on the command classes, which are: Description System Persistent Store Attribute database Connection Attribute client Security Manager Explanation Provides access to system functions Provides access the persistence store (parameters) Provides access to local GATT database Provides access to connection management functions Functions to access remote devices GATT database Bluetooth low energy security functions
Generic Access Profile GAP functions Hardware Provides access to hardware such as timers and ADC
Final section of the API reference contains description of the error codes categorized as follows: Description BGAPI errors Bluetooth errors Security manager errors Attribute protocols errors
Page 37 of 195
5.1.1 Commands
Attribute Client commands
Attribute Write
Writes a remote attribute's value with given handle and value. Attribute write operation will be acknowledged by the remote end, telling the write was successful. Attribute write can be used to write attribute values up to 20 bytes. Table 6: COMMAND Byte Type 0 1 2 3 4 0x00 0x04 0x04 0x05 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
connection Connection handle atthandle Attribute handle to write to Attribute value Table 7: RESPONSE
5 - 6 uint16 7
uint8array data
Description Message type: response Minimum payload length Message class: Attribute Client Message ID
connection Connection handle 0 : write was successful Otherwise error occurred Table 8: EVENTS
5 - 6 uint16 result
Event
Description
Page 38 of 195
C Functions
/* Function */ void ble_cmd_attclient_attribute_write( uint8 connection, uint16 atthandle, uint8 data_len, const uint8* data_data ); /* Callback */ struct ble_msg_attclient_attribute_write_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_attribute_write( const struct ble_msg_attclient_attribute_write_rsp_t * msg )
BGScript Functions
call attclient_attribute_write(connection, atthandle, data_len, data_data)(connection, result)
Page 39 of 195
Execute Write
Executes or Cancels previously queued prepare_write commands on remote host Table 9: COMMAND Byte Type Name 0 1 2 3 4 5 0x00 0x02 0x04 hilen lolen class Description Message type: command Minimum payload length Message class: Attribute Client Message ID
0x0A method
uint8 connection Connection Handle uint8 commit 1 - commits queued writes, 0- cancels Table 10: RESPONSE
Description Message type: command Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Event
Description
C Functions
/* Function */ void ble_cmd_attclient_execute_write( uint8 connection, uint8 commit ); /* Callback */ struct ble_msg_attclient_execute_write_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_execute_write( const struct ble_msg_attclient_execute_write_rsp_t * msg )
Page 40 of 195
BGScript Functions
call attclient_execute_write(connection, commit)(connection, result)
Page 41 of 195
connection Connection handle start end uuid First requested handle number Last requested handle number 2 octet UUID to find Attribute value to find Table 13: RESPONSE
9 - 10 uint16 11
uint8array value
Description Message type: response Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Otherwise error occurred Table 14: EVENTS Event attclient group_found attclient procedure_completed Description Attributes found Procedure has completed and new procedure can be started on GATT server
Page 42 of 195
C Functions
/* Function */ void ble_cmd_attclient_find_by_type_value( uint8 connection, uint16 start, uint16 end, uint16 uuid, uint8 value_len, const uint8* value_data ); /* Callback */ struct ble_msg_attclient_find_by_type_value_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_find_by_type_value( const struct ble_msg_attclient_find_by_type_value_rsp_t * msg )
BGScript Functions
Page 43 of 195
Find Information
This command is used to discover attribute handles and their types (UUIDs) in a given handle range. Table 15: COMMAND Byte Type 0 1 2 3 4 0x00 0x05 0x04 0x03 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
connection Connection handle First attribute handle Last attribute handle Table 16: RESPONSE
Description Message type: response Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
attclient find_information_found Handle, type - mapping found attclient procedure_completed Find information procedure has completed
Page 44 of 195
C Functions
/* Function */ void ble_cmd_attclient_find_information( uint8 connection, uint16 start, uint16 end ); /* Callback */ struct ble_msg_attclient_find_information_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_find_information( const struct ble_msg_attclient_find_information_rsp_t * msg )
BGScript Functions
call attclient_find_information(connection, start, end)(connection, result)
Page 45 of 195
Indicate Confirm
Send confirmation for received indication. Use only if manual indications are enabled in config.xml Table 18: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x04 0x07 hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
Description Message type: command Minimum payload length Message class: Attribute Client
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_attclient_indicate_confirm( uint8 connection ); /* Callback */ struct ble_msg_attclient_indicate_confirm_rsp_t{ uint16 result } void ble_rsp_attclient_indicate_confirm( const struct ble_msg_attclient_indicate_confirm_rsp_t * msg )
BGScript Functions
call attclient_indicate_confirm(connection)(result)
Page 46 of 195
Prepare Write
Send prepare write request to remote host for queueing. Queued writes are executed or canceled with attclient_execute_write command. NOTE: It is not mandatory for server to support this command. It is recommended to use this command to only write long-attributes which do not fit in single att-packet. Table 20: COMMAND Byte Type 0 1 2 3 4 0x00 0x06 0x04 0x09 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
connection Connection Handle atthandle offset Attribute handle Offset to write to data to write Table 21: RESPONSE
5 - 6 uint16 7 - 8 uint16 9
uint8array data
Description Message type: command Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Event
Description
Page 47 of 195
C Functions
/* Function */ void ble_cmd_attclient_prepare_write( uint8 connection, uint16 atthandle, uint16 offset, uint8 data_len, const uint8* data_data ); /* Callback */ struct ble_msg_attclient_prepare_write_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_prepare_write( const struct ble_msg_attclient_prepare_write_rsp_t * msg )
BGScript Functions
call attclient_prepare_write(connection, atthandle, offset, data_len, data_data)(connection, result)
Page 48 of 195
connection Connection handle start end First requested attribute handle Last requested attribute handle group UUID to find Table 24: RESPONSE
5 - 6 uint16 7 - 8 uint16 9
uint8array uuid
Description Message type: response Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Otherwise error occurred Table 25: EVENTS Event attclient group_found attclient procedure_completed Description Attributes found Procedure has completed and new procedure can be started on GATT server
Page 49 of 195
C Functions
/* Function */ void ble_cmd_attclient_read_by_group_type( uint8 connection, uint16 start, uint16 end, uint8 uuid_len, const uint8* uuid_data ); /* Callback */ struct ble_msg_attclient_read_by_group_type_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_read_by_group_type( const struct ble_msg_attclient_read_by_group_type_rsp_t * msg )
BGScript Functions
call attclient_read_by_group_type(connection, start, end, uuid_len, uuid_data)(connection, result)
Page 50 of 195
Read By Handle
This command reads a remote attribute's value with the given handle. Read by handle can be used to read attributes up to 22 bytes. Table 26: COMMAND Byte Type 0 1 2 3 4 0x00 0x03 0x04 0x04 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 chrhandle
Description Message type: response Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Otherwise error occurred Table 28: EVENTS Event attclient attribute_value Description Attribute value received
Page 51 of 195
C Functions
/* Function */ void ble_cmd_attclient_read_by_handle( uint8 connection, uint16 chrhandle ); /* Callback */ struct ble_msg_attclient_read_by_handle_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_read_by_handle( const struct ble_msg_attclient_read_by_handle_rsp_t * msg )
BGScript Functions
call attclient_read_by_handle(connection, chrhandle)(connection, result)
Page 52 of 195
Read By Type
Reads the value of each attribute of a given type (UUID) and in a given attribute handle range. The command for example used to discover the characteristic declarations (UUID: 0x2803) of a service. Table 29: COMMAND Byte Type 0 1 2 3 4 0x00 0x06 0x04 0x02 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
connection Connection handle start end First attribute handle Last attribute handle Attribute type (UUID) Table 30: RESPONSE
5 - 6 uint16 7 - 8 uint16 9
uint8array uuid
Description Message type: response Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Otherwise an error occurred Table 31: EVENTS Event attclient attribute_value Description Attribute value read from GATT server
Page 53 of 195
C Functions
/* Function */ void ble_cmd_attclient_read_by_type( uint8 connection, uint16 start, uint16 end, uint8 uuid_len, const uint8* uuid_data ); /* Callback */ struct ble_msg_attclient_read_by_type_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_read_by_type( const struct ble_msg_attclient_read_by_type_rsp_t * msg )
BGScript Functions
Page 54 of 195
Read Long
Use this command to read long attribute values. Starts a procedure where client first sends normal read to the server. and if returned attribute value length is equal to MTU, sends read long read requests until rest of the attribute is read. Table 32: COMMAND Byte Type 0 1 2 3 4 0x00 0x03 0x04 0x08 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 chrhandle
Description Message type: command Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Non-zero : An error occurred Table 34: EVENTS Event attclient attribute_value Description Data received from remote end
Page 55 of 195
C Functions
/* Function */ void ble_cmd_attclient_read_long( uint8 connection, uint16 chrhandle ); /* Callback */ struct ble_msg_attclient_read_long_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_read_long( const struct ble_msg_attclient_read_long_rsp_t * msg )
BGScript Functions
call attclient_read_long(connection, chrhandle)(connection, result)
Page 56 of 195
Read Multiple
Read multiple attributes from server Table 35: COMMAND Byte Type 0 1 2 3 4 5 0x00 0x02 0x04 0x0B uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
connection Connection handle List of attribute handles to read from remote end Table 36: RESPONSE
uint8array handles
Description Message type: command Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
Event
Description
attclient read_multiple_response Attribute data if command was succesful attclient procedure_completed Operation has failed
C Functions
/* Function */ void ble_cmd_attclient_read_multiple( uint8 connection, uint8 handles_len, const uint8* handles_data ); /* Callback */ struct ble_msg_attclient_read_multiple_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_read_multiple( const struct ble_msg_attclient_read_multiple_rsp_t * msg )
Page 57 of 195
BGScript Functions
call attclient_read_multiple(connection, handles_len, handles_data)(connection, result)
Page 58 of 195
Write Command
Writes a remote attribute's value with given handle and value. Write command will NOT be acknowledged by the remote end. Write command can be used to write attribute values up to 20 bytes. Table 38: COMMAND Byte Type 0 1 2 3 4 0x00 0x04 0x04 0x06 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Attribute Client Message ID
connection Connection handle atthandle Attribute handle to write Value for the attribute Table 39: RESPONSE
5 - 6 uint16 7
uint8array data
Description Message type: command Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 result
C Functions
/* Function */ void ble_cmd_attclient_write_command( uint8 connection, uint16 atthandle, uint8 data_len, const uint8* data_data ); /* Callback */ struct ble_msg_attclient_write_command_rsp_t{ uint8 connection, uint16 result } void ble_rsp_attclient_write_command( const struct ble_msg_attclient_write_command_rsp_t * msg )
Page 59 of 195
BGScript Functions
call attclient_write_command(connection, atthandle, data_len, data_data)(connection, result)
Page 60 of 195
5.1.2 Enumerations
Attribute Client commands
attclient_attribute_value_type_indicate_rsp_req Value was indicated and remote end is waiting for confirmation, use Indicate Confirm to send confirmation to other end.
Page 61 of 195
5.1.3 Events
Attribute Client events
Attribute Value
This event is produced at the GATT client side when an attribute value is passed from the GATT server to the GATT client, typically after a Read by Handle command. This is also received at the GATT client side when an attribute is indicated or notified by the GATT server to the GATT client. Table 41: EVENT Byte Type 0 1 2 3 4 0x80 0x05 0x04 0x05 uint8 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Attribute Client Message ID
connection Connection handle atthandle type Attribute handle Attribute type Attribute value (data)
5 - 6 uint16 7 8 uint8
uint8array value
C Functions
/* Callback */ struct ble_msg_attclient_attribute_value_evt_t{ uint8 connection, uint16 atthandle, uint8 type, uint8 value_len, const uint8* value_data } void ble_evt_attclient_attribute_value( const struct ble_msg_attclient_attribute_value_evt_t * msg )
BGScript Functions
event attclient_attribute_value(connection, atthandle, type, value_len, value_data)
Page 62 of 195
5 - 6 uint16 7
uint8array uuid
C Functions
/* Callback */ struct ble_msg_attclient_find_information_found_evt_t{ uint8 connection, uint16 chrhandle, uint8 uuid_len, const uint8* uuid_data } void ble_evt_attclient_find_information_found( const struct ble_msg_attclient_find_information_found_evt_t * msg )
BGScript Functions
event attclient_find_information_found(connection, chrhandle, uuid_len, uuid_data)
Page 63 of 195
Group Found
This event is produced when an attribute group (service) is found. Typically this event is produced after Read by Group Type command. Table 43: EVENT Byte Type 0 1 2 3 4 0x80 0x06 0x04 0x02 uint8 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Attribute Client Message ID
connection Connection handle start end Starting handle Ending handle (Note "end" is a reserver word and in BG script, "end" cannot be used as such. UUID if the service Length is 0 if no services are found
5 - 6 uint16 7 - 8 uint16 9
uint8array uuid
C Functions
/* Callback */ struct ble_msg_attclient_group_found_evt_t{ uint8 connection, uint16 start, uint16 end, uint8 uuid_len, const uint8* uuid_data } void ble_evt_attclient_group_found( const struct ble_msg_attclient_group_found_evt_t * msg )
BGScript Functions
event attclient_group_found(connection_handle, start_handle, end_handle, uuid_len, uuid_data)
Page 64 of 195
Indicated
This event is produced at the GATT server side when an attribute is successfully indicated by the GATT server to the GATT client. That is, the event is only produced at the GATT server if the indication is acknowledged by the GATT client at the remote side. Table 44: EVENT Byte Type 0 1 2 3 4 0x80 0x03 0x04 0x00 uint8 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Attribute Client Message ID
5 - 6 uint16 attrhandle
C Functions
/* Callback */ struct ble_msg_attclient_indicated_evt_t{ uint8 connection, uint16 attrhandle } void ble_evt_attclient_indicated( const struct ble_msg_attclient_indicated_evt_t * msg )
BGScript Functions
event attclient_indicated(connection, attrhandle)
Page 65 of 195
Procedure Completed
This event is produced at the GATT client when an attribute protocol event is completed. This event is produced for example after the attclient_attribute_write is used by the GATT client, to indicate if the GATT server has written the intended attribute. Table 45: EVENT Byte Type 0 1 2 3 4 0x80 0x05 0x04 0x01 uint8 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Attribute Client Message ID
C Functions
/* Callback */ struct ble_msg_attclient_procedure_completed_evt_t{ uint8 connection, uint16 result, uint16 chrhandle } void ble_evt_attclient_procedure_completed( const struct ble_msg_attclient_procedure_completed_evt_t * msg )
BGScript Functions
event attclient_procedure_completed(connection, result, chrhandle)
Page 66 of 195
connection Connection handle List of attribute handles to read from remote end
uint8array handles
C Functions
/* Callback */ struct ble_msg_attclient_read_multiple_response_evt_t{ uint8 connection, uint8 handles_len, const uint8* handles_data } void ble_evt_attclient_read_multiple_response( const struct ble_msg_attclient_read_multiple_response_evt_t * msg )
BGScript Functions
event attclient_read_multiple_response(connection, handles_len, handles_data)
Page 67 of 195
5.2.1 Commands
Attribute database commands
Read
The command reads the given attribute's value from the local database. Table 47: COMMAND Byte Type 0 1 2 3 0x00 0x04 0x02 0x01 Name hilen lolen class Description Message type: command Minimum payload length Message class: Attribute Database
method Message ID
4 - 5 uint16 handle Handle of the attribute to read 6 - 7 uint16 offset Offset to read from Table 48: RESPONSE Byte Type 0 1 2 3 0x00 0x07 0x02 0x01 Name hilen lolen class Description Message type: response Minimum payload length Message class: Attribute Database
method Message ID handle Handle of the attribute which was read offset result Offset read from 0 : the read was successful Non-zero: An error occurred
10
uint8array value
Page 68 of 195
C Functions
/* Function */ void ble_cmd_attributes_read( uint16 handle, uint16 offset ); /* Callback */ struct ble_msg_attributes_read_rsp_t{ uint16 handle, uint16 offset, uint16 result, uint8 value_len, const uint8* value_data } void ble_rsp_attributes_read( const struct ble_msg_attributes_read_rsp_t * msg )
BGScript Functions
call attributes_read(handle, offset)(handle, offset, result, value_len, value_data)
Page 69 of 195
Read Type
This command reads the given attribute's type (UUID) from the local database. Table 49: COMMAND Byte Type 0 1 2 3 0x00 0x02 0x02 0x02 Name hilen lolen class Description Message type: command Minimum payload length Message class: Attribute Database
method Message ID
4 - 5 uint16 handle Handle of the attribute to read Table 50: RESPONSE Byte Type 0 1 2 3 0x00 0x05 0x02 0x02 Name hilen lolen class Description Message type: response Minimum payload length Message class: Attribute Database
method Message ID handle Handle of the attribute which was read result 0: if the read was successful Non-zero: An error occurred
4 - 5 uint16 6 - 7 uint16
uint8array value
C Functions
/* Function */ void ble_cmd_attributes_read_type( uint16 handle ); /* Callback */ struct ble_msg_attributes_read_type_rsp_t{ uint16 handle, uint16 result, uint8 value_len, const uint8* value_data } void ble_rsp_attributes_read_type( const struct ble_msg_attributes_read_type_rsp_t * msg )
BGScript Functions
call attributes_read_type(handle)(handle, result, value_len, value_data)
Page 70 of 195
connection Connection handle to respond to att_error Attribute errorcode to send if error, set to 0 to send datafield Data to send Table 52: RESPONSE
uint8array value
Description Message type: command Minimum payload length Message class: Attribute Database
C Functions
/* Function */ void ble_cmd_attributes_user_read_response( uint8 connection, uint8 att_error, uint8 value_len, const uint8* value_data ); /* Callback * void ble_rsp_attributes_user_read_response( const void *nul )
BGScript Functions
call attributes_user_read_response(connection, att_error, value_len, value_data)
Page 71 of 195
uint8 connection Connection handle to respond to uint8 att_error Attribute errorcode to send if error, set to 0 to accept write Table 54: RESPONSE
Description Message type: command Minimum payload length Message class: Attribute Database
C Functions
/* Function */ void ble_cmd_attributes_user_write_response( uint8 connection, uint8 att_error ); /* Callback * void ble_rsp_attributes_user_write_response( const void *nul )
BGScript Functions
call attributes_user_write_response(connection, att_error)
Page 72 of 195
Write
This command writes an attribute's value to the local database. Table 55: COMMAND Byte Type 0 1 2 3 0x00 0x04 0x02 0x00 Name hilen lolen class Description Message type: command Minimum payload length Message class: Attribute Database
method Message ID handle Handle of the attribute to write offset Attribute offset to write data Value of the attribute to write Table 56: RESPONSE
4 - 5 uint16 6 7 uint8
uint8array value
Description Message type: response Minimum payload length Message class: Attribute Database
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_attributes_write( uint16 handle, uint8 offset, uint8 value_len, const uint8* value_data ); /* Callback */ struct ble_msg_attributes_write_rsp_t{ uint16 result } void ble_rsp_attributes_write( const struct ble_msg_attributes_write_rsp_t * msg )
BGScript Functions
call attributes_write(handle, offset, value_len, value_data)(result)
Page 73 of 195
5.2.2 Enumerations
Attribute Database enumerations
attributes_attribute_change_reason_write_request_user Value was written by remote end, stack is waiting for write response to be sent to other end. Use User Write Response to send response.
Page 74 of 195
Page 75 of 195
5.2.3 Events
Attribute Database events
Status
This event indicates the attribute status flags have changed Table 59: EVENT Byte Type 0 1 2 3 0x80 0x03 0x02 0x02 Name hilen lolen class Description Message type: event Minimum payload length Message class: Attribute Database
method Message ID
4 - 5 uint16 handle Attribute handle 6 uint8 flags Attribute status flags See: Attribute Status Flags
C Functions
/* Callback */ struct ble_msg_attributes_status_evt_t{ uint16 handle, uint8 flags } void ble_evt_attributes_status( const struct ble_msg_attributes_status_evt_t * msg )
BGScript Functions
event attributes_status(handle, flags)
Page 76 of 195
connection Connection ID which requested attribute Attribute handle requested Attribute offset to send data from Maximum data size to respond with, if more data is sent extra bytes are ignored
C Functions
/* Callback */ struct ble_msg_attributes_user_read_request_evt_t{ uint8 connection, uint16 handle, uint16 offset, uint8 maxsize } void ble_evt_attributes_user_read_request( const struct ble_msg_attributes_user_read_request_evt_t * msg )
BGScript Functions
event attributes_user_read_request(connection, handle, offset, maxsize)
Page 77 of 195
Value
This event is produced at the GATT server side when a local attribute value is being written by a remote GATT client. Table 61: EVENT Byte Type 0 1 2 3 4 5 0x80 0x07 0x02 0x00 uint8 uint8 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Attribute Database Message ID
connection Connection handle reason handle offset Reason why value has changed see:[enum attributes_attribute_change_reason] Attribute handle, which was changed Offset into attribute value where data starts Attribute value
6 - 7 uint16 8 - 9 uint16 10
uint8array value
C Functions
/* Callback */ struct ble_msg_attributes_value_evt_t{ uint8 connection, uint8 reason, uint16 handle, uint16 offset, uint8 value_len, const uint8* value_data } void ble_evt_attributes_value( const struct ble_msg_attributes_value_evt_t * msg )
BGScript Functions
event attributes_value(connection, reason, handle, offset, value_len, value_data)
Page 78 of 195
5.3 Connection
The Connection class provides methods to manage Bluetooth low energy connections and their statuses.
5.3.1 Commands
Connection class commands
Disconnect
This command disconnects an active connection. The command sends a request to link layer to start disconnection procedure. When link is disconnected Disconnected - event is produced. Table 62: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x03 0x00 hilen lolen class method Description Message type: command Minimum payload length Message class: Connection Message ID
Description Message type: response Minimum payload length Message class: Connection Message ID
5 - 6 uint16 result
Page 79 of 195
C Functions
/* Function */ void ble_cmd_connection_disconnect( uint8 connection ); /* Callback */ struct ble_msg_connection_disconnect_rsp_t{ uint8 connection, uint16 result } void ble_rsp_connection_disconnect( const struct ble_msg_connection_disconnect_rsp_t * msg )
BGScript Functions
call connection_disconnect(connection)(connection, result)
Page 80 of 195
Get Rssi
This commands returns the Receiver Signal Strength Indication (RSSI) of an active connection.
At -38 dBm the BLE112 receiver is saturated. The measurement value may depend on the used hardware and design.
Table 65: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x03 0x01 hilen lolen class method Description Message type: command Minimum payload length Message class: Connection Message ID
Byte Type Name 0 1 2 3 4 5 0x00 0x02 0x03 0x01 hilen lolen class method
Description Message type: response Minimum payload length Message class: Connection Message ID
uint8 connection Connection handle int8 rssi RSSI value of the connection in dBm.
C Functions
/* Function */ void ble_cmd_connection_get_rssi( uint8 connection ); /* Callback */ struct ble_msg_connection_get_rssi_rsp_t{ uint8 connection, int8 rssi } void ble_rsp_connection_get_rssi( const struct ble_msg_connection_get_rssi_rsp_t * msg )
BGScript Functions
call connection_get_rssi(connection)(connection, rssi)
Page 81 of 195
Get Status
This command returns the status of the given connection. Status is returned in Status event. Table 67: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x03 0x07 hilen lolen class method Description Message type: command Minimum payload length Message class: Connection Message ID
Byte Type Name 0 1 2 3 4 0x00 0x01 0x03 0x07 hilen lolen class method
Description Message type: response Minimum payload length Message class: Connection Message ID
Event
Description
C Functions
/* Function */ void ble_cmd_connection_get_status( uint8 connection ); /* Callback */ struct ble_msg_connection_get_status_rsp_t{ uint8 connection } void ble_rsp_connection_get_status( const struct ble_msg_connection_get_status_rsp_t * msg )
BGScript Functions
call connection_get_status(connection)(connection)
Page 82 of 195
Update
This command updates the connection parameters of given connection. If sent from a master, sends parameter update request to the link layer. If sent from a slave, sends L2CAP connection parameter update request to the master. Table 70: COMMAND Byte 0 1 2 3 4 5-6 7-8 9 - 10 Type 0x00 0x09 0x03 0x02 uint8 Name hilen lolen class method connection Description Message type: command Minimum payload length Message class: Connection Message ID Connection handle Minimum connection interval
uint16 interval_min
uint16 interval_max Maximum connection interval uint16 latency Slave latency Supervision timeout Table 71: RESPONSE
11 - 12 uint16 timeout
Description Message type: response Minimum payload length Message class: Connection Message ID
5 - 6 uint16 result
Page 83 of 195
C Functions
/* Function */ void ble_cmd_connection_update( uint8 connection, uint16 interval_min, uint16 interval_max, uint16 latency, uint16 timeout ); /* Callback */ struct ble_msg_connection_update_rsp_t{ uint8 connection, uint16 result } void ble_rsp_connection_update( const struct ble_msg_connection_update_rsp_t * msg )
BGScript Functions
call connection_update(connection, interval_min, interval_max, latency, timeout)(connection, result)
Page 84 of 195
Version Update
This command requests a version exchange of a given connection. Table 72: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x03 0x03 hilen lolen class method Description Message type: command Minimum payload length Message class: Connection Message ID
Description Message type: response Minimum payload length Message class: Connection Message ID
5 - 6 uint16 result
connection version_ind Sent after receiving version indication from other end
C Functions
/* Function */ void ble_cmd_connection_version_update( uint8 connection ); /* Callback */ struct ble_msg_connection_version_update_rsp_t{ uint8 connection, uint16 result } void ble_rsp_connection_version_update( const struct ble_msg_connection_version_update_rsp_t * msg )
Page 85 of 195
BGScript Functions
Page 86 of 195
5.3.2 Enumerations
Connection class enumerations
connection_parameters_change This flag tells that connection parameters have changed and. It is set when connection parameters have changed due to a link layer operation.
Page 87 of 195
5.3.3 Events
Connection class events
Disconnected
This event is produces when a connection is disconnected. Table 76: EVENT Byte Type 0 1 2 3 4 0x80 0x03 0x03 0x04 uint8 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Connection Message ID
5 - 6 uint16 reason
C Functions
/* Callback */ struct ble_msg_connection_disconnected_evt_t{ uint8 connection, uint16 reason } void ble_evt_connection_disconnected( const struct ble_msg_connection_disconnected_evt_t * msg )
BGScript Functions
event connection_disconnected(connection, reason)
Page 88 of 195
Feature Ind
This event indicates the remote devices features. Table 77: EVENT Byte Type 0 1 2 3 4 5 0x80 0x02 0x03 0x02 uint8 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Connection Message ID
uint8array features
C Functions
/* Callback */ struct ble_msg_connection_feature_ind_evt_t{ uint8 connection, uint8 features_len, const uint8* features_data } void ble_evt_connection_feature_ind( const struct ble_msg_connection_feature_ind_evt_t * msg )
BGScript Functions
event connection_feature_ind(connection, features_len, features_data)
Page 89 of 195
Status
This event indicates the connection status and parameters. Table 78: EVENT Byte 0 1 2 3 4 5 6 - 11 12 Type 0x80 0x10 0x03 0x00 uint8 uint8 Name hilen lolen class method connection flags Description Message type: event Minimum payload length Message class: Connection Message ID Connection handle Connection status flags use connstatus-enumerator Remote devices Bluetooth address
address_type Remote address type see: Bluetooth Address Types--gap conn_interval Current connection interval timeout latency bonding Current supervision timeout Slave latency bonding handle if there is stored bonding for this device 0xff otherwise
C Functions
/* Callback */ struct ble_msg_connection_status_evt_t{ uint8 connection, uint8 flags, bd_addr address, uint8 address_type, uint16 conn_interval, uint16 timeout, uint16 latency, uint8 bonding } void ble_evt_connection_status( const struct ble_msg_connection_status_evt_t * msg )
BGScript Functions
event connection_status(connection, flags, address, address_type, conn_interval, timeout, latency, bonding)
Page 90 of 195
Version Ind
This event indicates the remote devices version. Table 79: EVENT Byte Type 0 1 2 3 4 5 0x80 0x06 0x03 0x01 uint8 uint8 Name hilen lolen class method connection vers_nr Description Message type: event Minimum payload length Message class: Connection Message ID Connection handle Bluetooth controller specification version Manufacturer of Bluetooth controller
6 - 7 uint16 comp_id
C Functions
/* Callback */ struct ble_msg_connection_version_ind_evt_t{ uint8 connection, uint8 vers_nr, uint16 comp_id, uint16 sub_vers_nr } void ble_evt_connection_version_ind( const struct ble_msg_connection_version_ind_evt_t * msg )
BGScript Functions
event connection_version_ind(connection, vers_nr, comp_id, sub_vers_nr)
Page 91 of 195
5.4.1 Commands
Generic Access Profile class commands
Connect Direct
This command will start the GAP direct connection establishment procedure to a dedicated Bluetooth low energy device. The device will enter scanning state and when connectable advertisement packet is received from a remote device, that matches given address, connection is opened to that device. Procedure is cancelled with End Procedure - command Table 80: COMMAND Byte Type 0 1 2 3 0x00 0x0F 0x06 0x03 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Generic Access Profile Message ID Bluetooth address of the target device see: Bluetooth Address Types Minimum connection interval (unit1.25ms)
conn_interval_max Maximum connection interval (unit 1.25ms) timeout latency Supervision timeout (unit 10ms) Slave latency. Defines how many connection intervals slave can skip. 0 prevents slave from skipping connection intervals on purpose. 0 is good value to start with. Increasing slave latency can decrease the energy consumption of the slave. Table 81: RESPONSE
Page 92 of 195
Description Message type: response Minimum payload length Message class: Generic Access Profile Message ID 0 : procedure was succesfully started Non-zero: An error occurred
4 - 5 uint16 result
uint8
C Functions
/* Function */ void ble_cmd_gap_connect_direct( bd_addr address, uint8 addr_type, uint16 conn_interval_min, uint16 conn_interval_max, uint16 timeout, uint16 latency ); /* Callback */ struct ble_msg_gap_connect_direct_rsp_t{ uint16 result, uint8 connection_handle } void ble_rsp_gap_connect_direct( const struct ble_msg_gap_connect_direct_rsp_t * msg )
BGScript Functions
call gap_connect_direct(address, addr_type, conn_interval_min, conn_interval_max, timeout, latency)(result, connection_handle)
Page 93 of 195
Connect Selective
This command will open a connection to any Bluetooth low energy device on the local devices white list. Table 83: COMMAND Byte 0 1 2 3 4-5 6-7 8-9 Type 0x00 0x08 0x06 0x05 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Generic Access Profile Message ID Minimum connection interval
uint16 conn_interval_min
uint16 conn_interval_max Maximum connection interval uint16 timeout Supervision timeout Slave latency Table 84: RESPONSE
10 - 11 uint16 latency
Description Message type: command Minimum payload length Message class: Generic Access Profile Message ID 0: Command was executed successfully Non-zero: An error occurred
4 - 5 uint16 result
uint8
Page 94 of 195
C Functions
/* Function */ void ble_cmd_gap_connect_selective( uint16 conn_interval_min, uint16 conn_interval_max, uint16 timeout, uint16 latency ); /* Callback */ struct ble_msg_gap_connect_selective_rsp_t{ uint16 result, uint8 connection_handle } void ble_rsp_gap_connect_selective( const struct ble_msg_gap_connect_selective_rsp_t * msg )
BGScript Functions
call gap_connect_selective(conn_interval_min, conn_interval_max, timeout, latency)(result, connection_handle)
Page 95 of 195
Discover
This command starts the GAP discovery procedure to scan for advertising devices. Scanning parameters can be configured with the set_scan_parameters command. To cancel succesfully started procedure use End Procedure - command Table 86: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x06 0x02 hilen lolen class Description Message type: command Minimum payload length Message class: Generic Access Profile
uint8 mode
Description Message type: response Minimum payload length Message class: Generic Access Profile
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_gap_discover( uint8 mode ); /* Callback */ struct ble_msg_gap_discover_rsp_t{ uint16 result } void ble_rsp_gap_discover( const struct ble_msg_gap_discover_rsp_t * msg )
Page 96 of 195
BGScript Functions
call gap_discover(mode)(result)
Page 97 of 195
End Procedure
This command ends the current GAP procedure. Table 89: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x06 class Description Message type: command Minimum payload length Message class: Generic Access Profile
Description Message type: response Minimum payload length Message class: Generic Access Profile
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_gap_end_procedure( void ); /* Callback */ struct ble_msg_gap_end_procedure_rsp_t{ uint16 result } void ble_rsp_gap_end_procedure( const struct ble_msg_gap_end_procedure_rsp_t * msg )
BGScript Functions
call gap_end_procedure()(result)
Page 98 of 195
set_scanrsp Advertisement data type 0 : sets advertisement data 1 : sets scan response data Advertisement data to send Table 92: RESPONSE
uint8array adv_data
Description Message type: command Minimum payload length Message class: Generic Access Profile
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_gap_set_adv_data( uint8 set_scanrsp, uint8 adv_data_len, const uint8* adv_data_data ); /* Callback */ struct ble_msg_gap_set_adv_data_rsp_t{ uint16 result } void ble_rsp_gap_set_adv_data( const struct ble_msg_gap_set_adv_data_rsp_t * msg )
BGScript Functions
call gap_set_adv_data(set_scanrsp, adv_data_len, adv_data_data)(result)
Page 99 of 195
4 - 5 uint16 adv_interval_min
Range: 0x20 to 0x4000 (Default 0x200 = 320ms) 8 uint8 adv_channels A bit mask to identify which of the three advertisement channels are used. Examples: 0x07: All three channels are used 0x03: Advertisement channels 37 and 38 are used. 0x04: Only advertisement channel 39 is used Table 94: RESPONSE Byte Type 0 1 2 3 0x00 0x02 0x06 0x08 Name hilen lolen class Description Message type: command Minimum payload length Message class: Generic Access Profile
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_gap_set_adv_parameters( uint16 adv_interval_min, uint16 adv_interval_max, uint8 adv_channels ); /* Callback */ struct ble_msg_gap_set_adv_parameters_rsp_t{ uint16 result } void ble_rsp_gap_set_adv_parameters( const struct ble_msg_gap_set_adv_parameters_rsp_t * msg )
BGScript Functions
call gap_set_adv_parameters(adv_interval_min, adv_interval_max, adv_channels)(result)
Description Message type: command Minimum payload length Message class: Generic Access Profile
4 - 5 uint16 result
Event
Description
C Functions
/* Function */ void ble_cmd_gap_set_directed_connectable_mode( bd_addr address, uint8 addr_type ); /* Callback */ struct ble_msg_gap_set_directed_connectable_mode_rsp_t{ uint16 result } void ble_rsp_gap_set_directed_connectable_mode( const struct ble_msg_gap_set_directed_connectable_mode_rsp_t * msg )
BGScript Functions
call gap_set_directed_connectable_mode(address, addr_type)(result)
Set Filtering
Set scan and advertising filtering parameters Table 98: COMMAND Byte Type Name 0 1 2 3 4 5 6 0x00 0x03 0x06 0x06 hilen lolen class method Description Message type: command Minimum payload length Message class: Generic Access Profile Message ID see: enum gap_scan_policy see: enum gap_advertising_policy
uint8 scan_duplicate_filtering 0: Do not filter duplicate advertisers 1: Filter duplicates Table 99: RESPONSE
Description Message type: command Minimum payload length Message class: Generic Access Profile
method Message ID 0: The command was successfully executed Non-zero: An error occurred
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_gap_set_filtering( uint8 scan_policy, uint8 adv_policy, uint8 scan_duplicate_filtering ); /* Callback */ struct ble_msg_gap_set_filtering_rsp_t{ uint16 result } void ble_rsp_gap_set_filtering( const struct ble_msg_gap_set_filtering_rsp_t * msg )
BGScript Functions
call gap_set_filtering(scan_policy, adv_policy, scan_duplicate_filtering)(result)
Set Mode
This command configures the current GAP discoverability and connectability mode. Table 100: COMMAND Byte Type Name 0 1 2 3 4 5 0x00 0x02 0x06 0x01 hilen lolen class method Description Message type: command Minimum payload length Message class: Generic Access Profile Message ID
uint8 discover see:GAP Discoverable Mode uint8 connect see:GAP Connectable Mode Table 101: RESPONSE
Description Message type: response Minimum payload length Message class: Generic Access Profile
4 - 5 uint16 result
connection status Sent if device was connectable and master connected to device
C Functions
/* Function */ void ble_cmd_gap_set_mode( uint8 discover, uint8 connect ); /* Callback */ struct ble_msg_gap_set_mode_rsp_t{ uint16 result } void ble_rsp_gap_set_mode( const struct ble_msg_gap_set_mode_rsp_t * msg )
BGScript Functions
call gap_set_mode(discover, connect)(result)
uint8 peripheral_privacy 1-enable peripheral privacy, 0- disable, all other values no effect on flag uint8 central_privacy 1-enable central privacy, 0- disable, all other values no effect on flag Table 104: RESPONSE
Description Message type: command Minimum payload length Message class: Generic Access Profile
C Functions
/* Function */ void ble_cmd_gap_set_privacy_flags( uint8 peripheral_privacy, uint8 central_privacy ); /* Callback * void ble_rsp_gap_set_privacy_flags( const void *nul )
BGScript Functions
call gap_set_privacy_flags(peripheral_privacy, central_privacy)
4 - 5 uint16 scan_interval At what intervals is scanner started, unit is 625us 6 - 7 uint16 scan_window How long to scan at each interval, unit is 625us must be equal or smaller than interval 8 uint8 active 1 - use active scanning, 0 - use passive scanning Table 106: RESPONSE Byte Type 0 1 2 3 0x00 0x02 0x06 0x07 Name hilen lolen class Description Message type: command Minimum payload length Message class: Generic Access Profile
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_gap_set_scan_parameters( uint16 scan_interval, uint16 scan_window, uint8 active ); /* Callback */ struct ble_msg_gap_set_scan_parameters_rsp_t{ uint16 result } void ble_rsp_gap_set_scan_parameters( const struct ble_msg_gap_set_scan_parameters_rsp_t * msg )
BGScript Functions
call gap_set_scan_parameters(scan_interval, scan_window, active)(result)
5.4.2 Enumerations
Generic Access Profile class enumerations
AD_FLAGS
Scan header flags Table 107: VALUES Value Name 0x01 0x02 0x04 0x10 0x20 0x1f GAP_AD_FLAG_LIMITED_DISCOVERABLE GAP_AD_FLAG_GENERAL_DISCOVERABLE GAP_AD_FLAG_BREDR_NOT_SUPPORTED Description Limited discoverability General discoverability BR/EDR not supported
AD Type Flags
Table 108: VALUES Value Name 0 1 2 3 4 5 6 7 8 9 10 gap_ad_type_none gap_ad_type_flags gap_ad_type_services_16bit_more gap_ad_type_services_16bit_all gap_ad_type_services_32bit_more gap_ad_type_services_32bit_all gap_ad_type_services_128bit_more gap_ad_type_services_128bit_all gap_ad_type_localname_short gap_ad_type_localname_complete gap_ad_type_txpower Description
Advertising policy
Advertising policy Table 109: VALUES Value Name 0 1 2 3 gap_adv_policy_all gap_adv_policy_whitelist_scan Description Allow scan from any, allow connection from any Allow scan from whitelist only, allow connection from any
gap_adv_policy_whitelist_connect Allow scan from any, allow connection from whitelist only gap_adv_policy_whitelist_all Allow scan from whitelist only, allow connection from whitelist only
gap_undirected_connectable Undirected connectable gap_scannable_connectable Same as undirected connectable, but uses ADV_SCAN_IND packets
gap_general_discoverable Discoverable using general scanning mode gap_broadcast gap_user_data Discoverable in observation scanning mode. Limited or general discoverable bits not enabled in flags ad type. Send advertisement data defined by user.
SCAN_HEADER_FLAGS
Scan header flags Table 114: VALUES Value Name 0 1 2 3 4 5 6 GAP_SCAN_HEADER_ADV_IND GAP_SCAN_HEADER_ADV_DIRECT_IND Description Connectable undirected advertising event Connectable directed advertising event
GAP_SCAN_HEADER_ADV_NONCONN_IND Non-connectable undirected advertising event GAP_SCAN_HEADER_SCAN_REQ GAP_SCAN_HEADER_SCAN_RSP GAP_SCAN_HEADER_CONNECT_REQ Scanner wants information from Advertiser Advertiser gives more information to Scanner Initiator wants to connect to Advertiser
Scan Policy
Scan Policy Table 115: VALUES Value Name 0 1 gap_scan_policy_all Description Accept All advertisement Packets
5.4.3 Events
Generic Access Profile class events
Scan Response
This is a scan response event. Table 116: EVENT Byte 0 1 2 3 4 Type 0x80 0x0B 0x06 0x00 int8 Name hilen lolen class method rssi Description Message type: event Minimum payload length Message class: Generic Access Profile Message ID RSSI value (dBm) Range: -103 to -38 5 uint8 packet_type Scan response header 0: Connectable Advertisement packet 2: Non Connectable Advertisement packet 4: Scan response packet 6: Discoverable advertisement packet 6 - 11 bd_addr 12 uint8 sender Advertisers Bluetooth address
13 14
uint8
bond
Bond handle if there is known bond for this device, 0xff otherwise Scan response data
uint8array data
C Functions
/* Callback */ struct ble_msg_gap_scan_response_evt_t{ int8 rssi, uint8 packet_type, bd_addr sender, uint8 address_type, uint8 bond, uint8 data_len, const uint8* data_data } void ble_evt_gap_scan_response( const struct ble_msg_gap_scan_response_evt_t * msg )
BGScript Functions
event gap_scan_response(rssi, packet_type, sender, address_type, bond, data_len, data_data)
5.5 Hardware
The Hardware class provides methods to access the local devices hardware interfaces such as : A/D converters, IO and timers, I2C interface etc.
5.5.1 Commands
Hardware class commands
ADC Read
This command reads the devices local A/D converter. Table 117: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x03 0x07 0x02 hilen lolen class method Description Message type: command Minimum payload length Message class: Hardware Message ID Selects the ADC input. 0x0: AIN0 0x1: AIN1 0x2: AIN2 0x3: AIN3 0x4: AIN4 0x5: AIN5 0x6: AIN6 0x7: AIN7 0x8: AIN0--AIN1 differential 0x9: AIN2--AIN3 differential 0xa: AIN4--AIN5 differential 0xb: AIN6--AIN7 differential 0xc: GND 0xd: Reserved 0xe: Temperature sensor 0xf: VDD/3 5 uint8 decimation Select resolution and conversion rate for conversion, result is always stored in MSB bits. 0: 7 effective bits 1: 9 effective bits 2: 10 effective bits 3: 12 effective bits 6 uint8 reference_selection Selects the reference for the ADC. Reference corresponds to the maximum allowed input value. 0: Internal reference (1.15V) 1: External reference on AIN7 pin 2: AVDD pin 3: External reference on AIN6--AIN7 differential input Table 118: RESPONSE
uint8 input
Description Message type: response Minimum payload length Message class: Hardware
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_hardware_adc_read( uint8 input, uint8 decimation, uint8 reference_selection ); /* Callback */ struct ble_msg_hardware_adc_read_rsp_t{ uint16 result } void ble_rsp_hardware_adc_read( const struct ble_msg_hardware_adc_read_rsp_t * msg )
BGScript Functions
call hardware_adc_read(input, decimation, reference_selection)(result)
I2c Read
Read data from I2C bus using bit-bang method. On BLE112 module the I2C CLK is fixed to P1_7 and I2C data in P1_6. Pull-up must be enabled on both pins.
To convert a 7-bit I2C address to an 8-bit one, shift left by one bit. For example, a 7-bit address of 0x40 (dec 64) would be used as 0x80 (dec 128).
Table 120: COMMAND Byte Type Name 0 1 2 3 4 5 6 0x00 0x03 0x07 hilen lolen class Description Message type: command Minimum payload length Message class: Hardware Message ID
0x0A method
uint8 address I2C's 8-bit slave address with the read/write bit (LSB) set to zero. uint8 stop uint8 length If nonzero Send I2C stop condition after transmission Number of bytes to read Table 121: RESPONSE
Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 6
uint8array data
C Functions
/* Function */ void ble_cmd_hardware_i2c_read( uint8 address, uint8 stop, uint8 length ); /* Callback */ struct ble_msg_hardware_i2c_read_rsp_t{ uint16 result, uint8 data_len, const uint8* data_data } void ble_rsp_hardware_i2c_read( const struct ble_msg_hardware_i2c_read_rsp_t * msg )
BGScript Functions
call hardware_i2c_read(address, stop, length)(result, data_len, data_data)
I2c Write
Write data to I2C bus using bit-bang method. I2C CLK is fixed to P1_7 and I2C data in P1_6. Pull-up must be enabled on both pins.
To convert a 7-bit address to an 8-bit one, shift left by one bit. For example, a 7-bit address of 0x40 (dec 64) would be used as 0x80 (dec 128).
Table 122: COMMAND Byte Type 0 1 2 3 4 5 6 0x00 0x03 0x07 0x0B uint8 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Hardware Message ID
address I2C's 8-bit slave address with the read/write bit (LSB) set to zero. stop If nonzero Send I2C stop condition after transmission Data to write Table 123: RESPONSE
uint8array data
Description Message type: command Minimum payload length Message class: Hardware
C Functions
/* Function */ void ble_cmd_hardware_i2c_write( uint8 address, uint8 stop, uint8 data_len, const uint8* data_data ); /* Callback */ struct ble_msg_hardware_i2c_write_rsp_t{ uint8 written } void ble_rsp_hardware_i2c_write( const struct ble_msg_hardware_i2c_write_rsp_t * msg )
BGScript Functions
call hardware_i2c_write(address, stop, data_len, data_data)(written)
uint8 port
uint8 direction Bitmask for each individual pin direction bit0 means input (default) bit1 means output Example: for all port's pins as output use $FF
Table 125: RESPONSE Byte Type 0 1 2 3 0x00 0x02 0x07 0x03 Name hilen lolen class Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_hardware_io_port_config_direction( uint8 port, uint8 direction ); /* Callback */ struct ble_msg_hardware_io_port_config_direction_rsp_t{ uint16 result } void ble_rsp_hardware_io_port_config_direction( const struct ble_msg_hardware_io_port_config_direction_rsp_t * msg )
BGScript Functions
call hardware_io_port_config_direction(port, direction)(result)
uint8 port
Table 127: RESPONSE Byte Type 0 1 2 3 0x00 0x02 0x07 0x04 Name hilen lolen class Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_hardware_io_port_config_function( uint8 port, uint8 function ); /* Callback */ struct ble_msg_hardware_io_port_config_function_rsp_t{ uint16 result } void ble_rsp_hardware_io_port_config_function( const struct ble_msg_hardware_io_port_config_function_rsp_t * msg )
BGScript Functions
call hardware_io_port_config_function(port, function)(result)
Table 128: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x03 0x07 0x00 hilen lolen class method Description Message type: command Minimum payload length Message class: Hardware Message ID I/O port selection Possible values. 0,1 or 2 5 6 uint8 enable_bits interrupt enable mask for pins
uint8 port
uint8 falling_edge Interrupt sense for port. 0 : rising edge 1 : falling edge Note: affects all pins on port Table 129: RESPONSE
Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
Event
Description
hardware io_port_status Sent after pin change edge detected, and pin irq is enabled
C Functions
/* Function */ void ble_cmd_hardware_io_port_config_irq( uint8 port, uint8 enable_bits, uint8 falling_edge ); /* Callback */ struct ble_msg_hardware_io_port_config_irq_rsp_t{ uint16 result } void ble_rsp_hardware_io_port_config_irq( const struct ble_msg_hardware_io_port_config_irq_rsp_t * msg )
BGScript Functions
call hardware_io_port_config_irq(port, enable_bits, falling_edge)(result)
Table 131: COMMAND Byte Type Name 0 1 2 3 4 5 6 0x00 0x03 0x07 0x05 hilen lolen class method Description Message type: command Minimum payload length Message class: Hardware Message ID I/O port select: 0, 1 or 2
uint8 port
uint8 tristate_mask If bit is set, disabled pull on pin uint8 pull_up 1: pull all port's pins up 0: pull all port's pins down Table 132: RESPONSE
Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_hardware_io_port_config_pull( uint8 port, uint8 tristate_mask, uint8 pull_up ); /* Callback */ struct ble_msg_hardware_io_port_config_pull_rsp_t{ uint16 result } void ble_rsp_hardware_io_port_config_pull( const struct ble_msg_hardware_io_port_config_pull_rsp_t * msg )
BGScript Functions
call hardware_io_port_config_pull(port, tristate_mask, pull_up)(result)
Io Port Read
Read I/O-port Table 133: COMMAND Byte Type Name 0 1 2 3 4 5 0x00 0x02 0x07 0x07 hilen lolen class Description Message type: command Minimum payload length Message class: Hardware
method Message ID I/O port to read 0,1,2 I/O pins to read Table 134: RESPONSE
Description Message type: command Minimum payload length Message class: Hardware
method Message ID error code, 0-success I/O port read I/O port pin state
C Functions
/* Function */ void ble_cmd_hardware_io_port_read( uint8 port, uint8 mask ); /* Callback */ struct ble_msg_hardware_io_port_read_rsp_t{ uint16 result, uint8 port, uint8 data } void ble_rsp_hardware_io_port_read( const struct ble_msg_hardware_io_port_read_rsp_t * msg )
BGScript Functions
call hardware_io_port_read(port, mask)(result, port, data)
Io Port Write
Write I/O-port Table 135: COMMAND Byte Type Name 0 1 2 3 4 5 6 0x00 0x03 0x07 0x06 hilen lolen class Description Message type: command Minimum payload length Message class: Hardware
method Message ID I/O port to write to 0,1,2 Pins to modify Pin values to set Table 136: RESPONSE
Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_hardware_io_port_write( uint8 port, uint8 mask, uint8 data ); /* Callback */ struct ble_msg_hardware_io_port_write_rsp_t{ uint16 result } void ble_rsp_hardware_io_port_write( const struct ble_msg_hardware_io_port_write_rsp_t * msg )
BGScript Functions
call hardware_io_port_write(port, mask, data)(result)
4 - 7 uint32 time
time = 1/32768 seconds if sleep oscillator is installed time = 1/32000 seconds if internal RC oscillator is used
If time is 0, removes scheduled timer 8 9 uint8 uint8 handle Handle that is sent back in event
single_shot Timer mode 0: if timer is repeating 1: sent timer event only once Table 138: RESPONSE
Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
Event
Description
C Functions
/* Function */ void ble_cmd_hardware_set_soft_timer( uint32 time, uint8 handle, uint8 single_shot ); /* Callback */ struct ble_msg_hardware_set_soft_timer_rsp_t{ uint16 result } void ble_rsp_hardware_set_soft_timer( const struct ble_msg_hardware_set_soft_timer_rsp_t * msg )
BGScript Functions
call hardware_set_soft_timer(time, handle, single_shot)(result)
Set Txpower
Set TX Power Table 140: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x07 hilen lolen class Description Message type: command Minimum payload length Message class: Hardware
0x0C method Message ID uint8 power TX power level to use Range: 0 to 15 which give the real TX power from -23 to +3 dBm
Table 141: RESPONSE Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x07 class Description Message type: command Minimum payload length Message class: Hardware
C Functions
/* Function */ void ble_cmd_hardware_set_txpower( int8 power ); /* Callback * void ble_rsp_hardware_set_txpower( const void *nul )
BGScript Functions
call hardware_set_txpower(power)
Spi Config
Configure SPI Table 142: COMMAND Byte Type Name 0 1 2 3 4 5 6 7 8 9 0x00 0x06 0x07 0x08 hilen lolen class method Description Message type: command Minimum payload length Message class: Hardware Message ID USART channel 0,1 Clock polarity 0,1 Clock phase 0,1
uint8 bit_order Endianness select, 0-LSB 1-MSB first uint8 baud_e uint8 baud_m baud rate exponent value baud rate mantissa value Table 143: RESPONSE
Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_hardware_spi_config( uint8 channel, uint8 polarity, uint8 phase, uint8 bit_order, uint8 baud_e, uint8 baud_m ); /* Callback */ struct ble_msg_hardware_spi_config_rsp_t{ uint16 result } void ble_rsp_hardware_spi_config( const struct ble_msg_hardware_spi_config_rsp_t * msg )
BGScript Functions
call hardware_spi_config(channel, polarity, phase, bit_order, baud_e, baud_m)(result)
Spi Transfer
Transfer SPI data Table 144: COMMAND Byte Type 0 1 2 3 4 5 0x00 0x02 0x07 0x09 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: Hardware Message ID
channel SPI channel used 0,1 Data to transmit Table 145: RESPONSE
uint8array data
Description Message type: command Minimum payload length Message class: Hardware Message ID error code, 0-success
4 - 5 uint16 6 7 uint8
uint8array data
C Functions
/* Function */ void ble_cmd_hardware_spi_transfer( uint8 channel, uint8 data_len, const uint8* data_data ); /* Callback */ struct ble_msg_hardware_spi_transfer_rsp_t{ uint16 result, uint8 channel, uint8 data_len, const uint8* data_data } void ble_rsp_hardware_spi_transfer( const struct ble_msg_hardware_spi_transfer_rsp_t * msg )
BGScript Functions
call hardware_spi_transfer(channel, data_len, data_data)(result, channel, data_len, data_data)
Timer Comparator
Set comparator for timer channel. This command may be used to generate e.g. PWM signals with hardware timer. More information on different comparator modes and their usage may be found from Texas Instruments CC2540 User's Guide (SWRU191B), section 9.8 Output Compare Mode. Table 146: COMMAND Byte Type 0 1 2 3 4 5 6 0x00 0x05 0x07 0x0D uint8 uint8 uint8 Name hilen lolen class method timer channel mode Description Message type: command Minimum payload length Message class: Hardware Message ID Timer Timer channel Comparator mode
7 - 8 uint16 comparator_value Comparator value Table 147: RESPONSE Byte Type 0 1 2 3 0x00 0x02 0x07 0x0D Name hilen lolen class Description Message type: command Minimum payload length Message class: Hardware
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_hardware_timer_comparator( uint8 timer, uint8 channel, uint8 mode, uint16 comparator_value ); /* Callback */ struct ble_msg_hardware_timer_comparator_rsp_t{ uint16 result } void ble_rsp_hardware_timer_comparator( const struct ble_msg_hardware_timer_comparator_rsp_t * msg )
BGScript Functions
5.5.2 Events
Hardware class events
ADC Result
This events is produced when an A/D converter result is received. Table 148: EVENT Byte Type Name 0 1 2 3 4 0x80 0x03 0x07 0x02 hilen lolen class Description Message type: event Minimum payload length Message class: Hardware
method Message ID A/D input from which value is received from A/D value
uint8 input
5 - 6 int16 value
C Functions
/* Callback */ struct ble_msg_hardware_adc_result_evt_t{ uint8 input, int16 value } void ble_evt_hardware_adc_result( const struct ble_msg_hardware_adc_result_evt_t * msg )
BGScript Functions
event hardware_adc_result(input, value)
IO Port Status
This event is produced when I/O port status changes. Table 149: EVENT Byte Type 0 1 2 3 0x80 0x07 0x07 0x00 Name hilen lolen class method Description Message type: event Minimum payload length Message class: Hardware Message ID
4 - 7 uint32 timestamp Value of internal timer Range : 0 to 2^24-1 8 9 uint8 uint8 port irq I/O port I/O flags Tells which port caused interrupt (bitmask). Current status of all I/Os in port (bitmask).
10
uint8
state
C Functions
/* Callback */ struct ble_msg_hardware_io_port_status_evt_t{ uint32 timestamp, uint8 port, uint8 irq, uint8 state } void ble_evt_hardware_io_port_status( const struct ble_msg_hardware_io_port_status_evt_t * msg )
BGScript Functions
event hardware_io_port_status(timestamp, port, irq, state)
Soft Timer
This event is produced when software timer interrupt is generated. Table 150: EVENT Byte Type Name 0 1 2 3 4 0x80 0x01 0x07 0x01 hilen lolen class Description Message type: event Minimum payload length Message class: Hardware
method Message ID
C Functions
/* Callback */ struct ble_msg_hardware_soft_timer_evt_t{ uint8 handle } void ble_evt_hardware_soft_timer( const struct ble_msg_hardware_soft_timer_evt_t * msg )
BGScript Functions
event hardware_soft_timer(handle)
5.6.1 Commands
Persistent Store class commands
PS Defrag
This command defragments the Persistent Store. Table 151: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x01 class Description Message type: command Minimum payload length Message class: Persistent Store
Description Message type: response Minimum payload length Message class: Persistent Store
C Functions
/* Function */ void ble_cmd_flash_ps_defrag( void ); /* Callback * void ble_rsp_flash_ps_defrag( const void *nul )
BGScript Functions
call flash_ps_defrag()
PS Dump
This command dumps all Persistent Store keys. Table 153: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x01 class Description Message type: command Minimum payload length Message class: Persistent Store
Description Message type: response Minimum payload length Message class: Persistent Store
Event
Description
C Functions
/* Function */ void ble_cmd_flash_ps_dump( void ); /* Callback * void ble_rsp_flash_ps_dump( const void *nul )
BGScript Functions
call flash_ps_dump()
PS Erase All
This command erases all Persistent Store keys. Table 156: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x01 class Description Message type: command Minimum payload length Message class: Persistent Store
Description Message type: response Minimum payload length Message class: Persistent Store
C Functions
/* Function */ void ble_cmd_flash_ps_erase_all( void ); /* Callback * void ble_rsp_flash_ps_erase_all( const void *nul )
BGScript Functions
call flash_ps_erase_all()
PS Erase
This command erases a Persistent Store key given as parameter. Table 158: COMMAND Byte Type 0 1 2 3 0x00 0x02 0x01 0x05 Name hilen lolen class Description Message type: command Minimum payload length Message class: Persistent Store
4 - 5 uint16 key
Description Message type: response Minimum payload length Message class: Persistent Store
C Functions
/* Function */ void ble_cmd_flash_ps_erase( uint16 key ); /* Callback * void ble_rsp_flash_ps_erase( const void *nul )
BGScript Functions
call flash_ps_erase(key)
PS Load
This command reads a Persistent Store key from the local device. Table 160: COMMAND Byte Type 0 1 2 3 0x00 0x02 0x01 0x04 Name hilen lolen class Description Message type: command Minimum payload length Message class: Persistent Store
method Message ID Key to load Keys 8000 to 807F can be read. Table 161: RESPONSE
4 - 5 uint16 key
Description Message type: response Minimum payload length Message class: Persistent Store
4 - 5 uint16 6
uint8array value
C Functions
/* Function */ void ble_cmd_flash_ps_load( uint16 key ); /* Callback */ struct ble_msg_flash_ps_load_rsp_t{ uint16 result, uint8 value_len, const uint8* value_data } void ble_rsp_flash_ps_load( const struct ble_msg_flash_ps_load_rsp_t * msg )
BGScript Functions
call flash_ps_load(key)(result, value_len, value_data)
PS Save
This command saves a Persistent Store (PS) key to the local device. The size of a single PS-key is 32 bytes and a total of 128 keys are available. Table 162: COMMAND Byte Type 0 1 2 3 0x00 0x03 0x01 0x03 Name hilen lolen class Description Message type: command Minimum payload length Message class: Persistent Store
method Message ID key Key to save. Keys 8000 to 807F can be used for persistent storage of user data.
4 - 5 uint16
uint8array value
Description Message type: response Minimum payload length Message class: Persistent Store
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_flash_ps_save( uint16 key, uint8 value_len, const uint8* value_data ); /* Callback */ struct ble_msg_flash_ps_save_rsp_t{ uint16 result } void ble_rsp_flash_ps_save( const struct ble_msg_flash_ps_save_rsp_t * msg )
BGScript Functions
call flash_ps_save(key, value_len, value_data)(result)
5.6.2 Events
Persistent Store class events
PS Key
This event is produced during a Persistent Store key dump for every dumped key. Table 164: EVENT Byte Type 0 1 2 3 0x80 0x03 0x01 0x00 Name hilen lolen class Description Message type: event Minimum payload length Message class: Persistent Store
4 - 5 uint16 6
uint8array value
C Functions
/* Callback */ struct ble_msg_flash_ps_key_evt_t{ uint16 key, uint8 value_len, const uint8* value_data } void ble_evt_flash_ps_key( const struct ble_msg_flash_ps_key_evt_t * msg )
BGScript Functions
event flash_ps_key(key, value_len, value_data)
5.7.1 Commands
Security Manager class commands
Delete Bonding
This command deletes a bonding from the local security database. There can be a maximum of 8 bonded devices stored at the same time, and one of them must be deleted if you need bonding with a 9th device. Table 165: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x05 0x02 hilen lolen class Description Message type: command Minimum payload length Message class: Security Manager
method Message ID
Description Message type: command Minimum payload length Message class: Security Manager
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_sm_delete_bonding( uint8 handle ); /* Callback */ struct ble_msg_sm_delete_bonding_rsp_t{ uint16 result } void ble_rsp_sm_delete_bonding( const struct ble_msg_sm_delete_bonding_rsp_t * msg )
BGScript Functions
call sm_delete_bonding(handle)(result)
Encrypt Start
This command starts the encryption for a given connection. | Table 167: COMMAND Byte Type Name 0 1 2 3 4 5 0x00 0x02 0x05 0x00 hilen lolen class method Description Message type: command Minimum payload length Message class: Security Manager Message ID Connection handle
uint8 handle
uint8 bonding Create bonding if devices are not already bonded Table 168: RESPONSE
Description Message type: response Minimum payload length Message class: Security Manager
method Message ID handle Connection handle 0 : the encryption was started successfully Table 169: EVENTS
5 - 6 uint16 result
Event sm_bonding_fail
C Functions
/* Function */ void ble_cmd_sm_encrypt_start( uint8 handle, uint8 bonding ); /* Callback */ struct ble_msg_sm_encrypt_start_rsp_t{ uint8 handle, uint16 result } void ble_rsp_sm_encrypt_start( const struct ble_msg_sm_encrypt_start_rsp_t * msg )
BGScript Functions
Get Bonds
List all bonded devices. There can be a maximum of 8 bonded devices. The information related to the bonded devices is stored in the Flash memory, so it is persistent across resets and power-cycles. Table 170: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x05 class Description Message type: command Minimum payload length Message class: Security Manager
Byte Type Name 0 1 2 3 4 0x00 0x01 0x05 0x05 hilen lolen class
Description Message type: command Minimum payload length Message class: Security Manager
uint8 bonds
Event
Description
C Functions
/* Function */ void ble_cmd_sm_get_bonds( void ); /* Callback */ struct ble_msg_sm_get_bonds_rsp_t{ uint8 bonds } void ble_rsp_sm_get_bonds( const struct ble_msg_sm_get_bonds_rsp_t * msg )
BGScript Functions
call sm_get_bonds()(bonds)
Passkey Entry
User entered passkey Table 173: COMMAND Byte Type 0 1 2 3 4 0x00 0x05 0x05 0x04 uint8 Name hilen lolen class method handle Description Message type: command Minimum payload length Message class: Security Manager Message ID Connection Handle
5 - 8 uint32 passkey Passkey range 000000-999999 Table 174: RESPONSE Byte Type 0 1 2 3 0x00 0x02 0x05 0x04 Name hilen lolen class Description Message type: command Minimum payload length Message class: Security Manager
method Message ID
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_sm_passkey_entry( uint8 handle, uint32 passkey ); /* Callback */ struct ble_msg_sm_passkey_entry_rsp_t{ uint16 result } void ble_rsp_sm_passkey_entry( const struct ble_msg_sm_passkey_entry_rsp_t * msg )
BGScript Functions
call sm_passkey_entry(handle, passkey)(result)
uint8 bondable Enables or disables bonding mode 0 : the device is not bondable 1 : the device is bondable Table 176: RESPONSE
Description Message type: command Minimum payload length Message class: Security Manager
C Functions
/* Function */ void ble_cmd_sm_set_bondable_mode( uint8 bondable ); /* Callback * void ble_rsp_sm_set_bondable_mode( const void *nul )
BGScript Functions
call sm_set_bondable_mode(bondable)
method Message ID OOB data to set, if empty clear oob data Table 178: RESPONSE
uint8array oob
Description Message type: command Minimum payload length Message class: Security Manager
C Functions
/* Function */ void ble_cmd_sm_set_oob_data( uint8 oob_len, const uint8* oob_data ); /* Callback * void ble_rsp_sm_set_oob_data( const void *nul )
BGScript Functions
call sm_set_oob_data(oob_len, oob_data)
Set Parameters
Configure Security Manager Table 179: COMMAND Byte Type Name 0 1 2 3 4 5 6 0x00 0x03 0x05 0x03 hilen lolen class method Description Message type: command Minimum payload length Message class: Security Manager Message ID Man-in-the-middle protection required minimum key size in bytes range 7-16
Description Message type: command Minimum payload length Message class: Security Manager
C Functions
/* Function */ void ble_cmd_sm_set_parameters( uint8 mitm, uint8 min_key_size, uint8 io_capabilities ); /* Callback * void ble_rsp_sm_set_parameters( const void *nul )
BGScript Functions
call sm_set_parameters(mitm, min_key_size, io_capabilities)
5.7.2 Enumerations
Security Manager commands
Bonding Keys
Bonding information stored Table 181: VALUES Value Name 0x01 0x02 0x04 0x08 0x10 0x20 0x40 sm_bonding_key_ltk Description LTK saved in master
sm_bonding_key_addr_public Public Address sm_bonding_key_addr_static sm_bonding_key_irk sm_bonding_key_edivrand sm_bonding_key_csrk sm_bonding_key_masterid Static Address Identity resolving key for resolvable private addresses EDIV+RAND received from slave Connection signature resolving key EDIV+RAND sent to master
SMP IO Capabilities
SMP IO Capabilities Table 182: VALUES Value Name 0 1 2 3 4 sm_io_capability_displayonly sm_io_capability_displayyesno sm_io_capability_keyboardonly Description Display Only Display with Yes/No-buttons Keyboard Only
5.7.3 Events
Security Manager class events
Bonding Fail
Link bonding has failed Table 183: EVENT Byte Type 0 1 2 3 4 0x80 0x03 0x05 0x01 uint8 Name hilen lolen class Description Message type: event Minimum payload length Message class: Security Manager
method Message ID handle Connection handle Encryption status, describes error that occurred during bonding
5 - 6 uint16 result
C Functions
/* Callback */ struct ble_msg_sm_bonding_fail_evt_t{ uint8 handle, uint16 result } void ble_evt_sm_bonding_fail( const struct ble_msg_sm_bonding_fail_evt_t * msg )
BGScript Functions
event sm_bonding_fail(handle, result)
Bond Status
Bond status information Table 184: EVENT Byte Type Name 0 1 2 3 4 5 6 7 0x80 0x04 0x05 0x04 hilen lolen class method Description Message type: event Minimum payload length Message class: Security Manager Message ID Bond handle
uint8 bond
uint8 keysize Encryption key size used in long-term key uint8 mitm uint8 keys Was mitm used in pairing Keys stored for bond see:[enum sm_bonding_key]
C Functions
/* Callback */ struct ble_msg_sm_bond_status_evt_t{ uint8 bond, uint8 keysize, uint8 mitm, uint8 keys } void ble_evt_sm_bond_status( const struct ble_msg_sm_bond_status_evt_t * msg )
BGScript Functions
event sm_bond_status(bond, keysize, mitm, keys)
Passkey Display
Passkey to be entered to remote device Table 185: EVENT Byte Type 0 1 2 3 4 0x80 0x05 0x05 0x02 uint8 Name hilen lolen class method handle Description Message type: event Minimum payload length Message class: Security Manager Message ID
C Functions
/* Callback */ struct ble_msg_sm_passkey_display_evt_t{ uint8 handle, uint32 passkey } void ble_evt_sm_passkey_display( const struct ble_msg_sm_passkey_display_evt_t * msg )
BGScript Functions
event sm_passkey_display(handle, passkey)
Passkey Request
Security Manager requests user to enter passkey Use Passkey Entry - command to respond to request Table 186: EVENT Byte Type Name 0 1 2 3 4 0x80 0x01 0x05 0x03 hilen lolen class Description Message type: event Minimum payload length Message class: Security Manager
method Message ID
C Functions
/* Callback */ struct ble_msg_sm_passkey_request_evt_t{ uint8 handle } void ble_evt_sm_passkey_request( const struct ble_msg_sm_passkey_request_evt_t * msg )
BGScript Functions
event sm_passkey_request(handle)
5.8 System
The System class provides access to the local device and contains functions for example to query Bluetooth address, firmware version, packet counters etc.
5.8.1 Commands
System class commands
Address Get
This command reads the local devices public Bluetooth address. Table 187: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x00 class Description Message type: command Minimum payload length Message class: System
Description Message type: response Minimum payload length Message class: System Message ID
C Functions
/* Function */ void ble_cmd_system_address_get( void ); /* Callback */ struct ble_msg_system_address_get_rsp_t{ bd_addr address } void ble_rsp_system_address_get( const struct ble_msg_system_address_get_rsp_t * msg )
BGScript Functions
call system_address_get()(address)
Endpoint Rx
Read data from an endpoint (i.e., data souce, e.g., UART), error is returned if endpoint does not have enough data. Table 189: COMMAND Byte Type Name 0 1 2 3 4 5 0x00 0x02 0x00 hilen lolen class Description Message type: command Minimum payload length Message class: System Message ID
0x0D method
uint8 endpoint Endpoint index to read data from uint8 size Size of data to read Table 190: RESPONSE
Description Message type: command Minimum payload length Message class: System
4 - 5 uint16 6
uint8array data
C Functions
/* Function */ void ble_cmd_system_endpoint_rx( uint8 endpoint, uint8 size ); /* Callback */ struct ble_msg_system_endpoint_rx_rsp_t{ uint16 result, uint8 data_len, const uint8* data_data } void ble_rsp_system_endpoint_rx( const struct ble_msg_system_endpoint_rx_rsp_t * msg )
BGScript Functions
call system_endpoint_rx(endpoint, size)(result, data_len, data_data)
0x0E method
uint8 endpoint Endpoint index to set watermarks. uint8 rx Watermark position on receive buffer 0xFF : watermark is not modified 0 : disables watermark
uint8 tx
Watermark position on transmit buffer 0xFF : watermark is not modified 0 : disables watermark Table 192: RESPONSE
Description Message type: command Minimum payload length Message class: System
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_system_endpoint_set_watermarks( uint8 endpoint, uint8 rx, uint8 tx ); /* Callback */ struct ble_msg_system_endpoint_set_watermarks_rsp_t{ uint16 result } void ble_rsp_system_endpoint_set_watermarks( const struct ble_msg_system_endpoint_set_watermarks_rsp_t * msg )
BGScript Functions
call system_endpoint_set_watermarks(endpoint, rx, tx)(result)
Endpoint Tx
Send data to endpoint, error is returned if endpoint does not have enough space Table 193: COMMAND Byte Type 0 1 2 3 4 5 0x00 0x02 0x00 0x09 uint8 Name hilen lolen class method Description Message type: command Minimum payload length Message class: System Message ID
endpoint Endpoint index to send data to data to send Table 194: RESPONSE
uint8array data
Description Message type: command Minimum payload length Message class: System
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_system_endpoint_tx( uint8 endpoint, uint8 data_len, const uint8* data_data ); /* Callback */ struct ble_msg_system_endpoint_tx_rsp_t{ uint16 result } void ble_rsp_system_endpoint_tx( const struct ble_msg_system_endpoint_tx_rsp_t * msg )
BGScript Functions
call system_endpoint_tx(endpoint, data_len, data_data)(result)
Get Connections
This command reads the number of supported connections from the local device. Table 195: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x00 class Description Message type: command Minimum payload length Message class: System
Byte Type Name 0 1 2 3 4 0x00 0x01 0x00 0x06 hilen lolen class method
Description Message type: response Minimum payload length Message class: System Message ID
Event
Description
C Functions
/* Function */ void ble_cmd_system_get_connections( void ); /* Callback */ struct ble_msg_system_get_connections_rsp_t{ uint8 maxconn } void ble_rsp_system_get_connections( const struct ble_msg_system_get_connections_rsp_t * msg )
BGScript Functions
call system_get_connections()(maxconn)
Get Counters
Read packet counters and resets them, also returns available packet buffers. Table 198: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x00 class Description Message type: command Minimum payload length Message class: System
Byte Type Name 0 1 2 3 4 5 6 7 8 0x00 0x05 0x00 0x05 hilen lolen class
Description Message type: command Minimum payload length Message class: System
method Message ID Acknowledgements received for sent packets Number of packets retransmitted packets received where crc was ok packets received where crc failed Available packet buffers
uint8 txok uint8 txretry uint8 rxok uint8 rxfail uint8 mbuf
C Functions
/* Function */ void ble_cmd_system_get_counters( void ); /* Callback */ struct ble_msg_system_get_counters_rsp_t{ uint8 txok, uint8 txretry, uint8 rxok, uint8 rxfail, uint8 mbuf } void ble_rsp_system_get_counters( const struct ble_msg_system_get_counters_rsp_t * msg )
BGScript Functions
call system_get_counters()(txok, txretry, rxok, rxfail, mbuf)
Get Info
This command reads the local devices software and hardware versions. Table 200: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x00 class Description Message type: command Minimum payload length Message class: System
Description Message type: response Minimum payload length Message class: System Message ID Major software version Minor software version Patch ID Build version Link layer version
C Functions
/* Function */ void ble_cmd_system_get_info( void ); /* Callback */ struct ble_msg_system_get_info_rsp_t{ uint16 major, uint16 minor, uint16 patch, uint16 build, uint16 ll_version, uint8 protocol_version, uint8 hw } void ble_rsp_system_get_info( const struct ble_msg_system_get_info_rsp_t * msg )
BGScript Functions
call system_get_info()(major, minor, patch, build, ll_version, protocol_version, hw)
Hello
This command can be used to test if the local device is functional. Similar to a typical "AT" -> "OK" test. Table 202: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x00 class Description Message type: command Minimum payload length Message class: System
Description Message type: response Minimum payload length Message class: System
C Functions
/* Function */ void ble_cmd_system_hello( void ); /* Callback * void ble_rsp_system_hello( const void *nul )
BGScript Functions
call system_hello()
Reset
This command resets the local device immediately. The command does not have a response. Table 204: COMMAND Byte Type Name 0 1 2 3 4 0x00 0x01 0x00 0x00 hilen lolen class method Description Message type: command Minimum payload length Message class: System Message ID
uint8 boot_in_dfu Selects the boot mode 0 : boot to main program 1 : boot to DFU Table 205: EVENTS
Event
Description
C Functions
/* Function */ void ble_cmd_system_reset( uint8 boot_in_dfu );
BGScript Functions
call system_reset(boot_in_dfu)
Whitelist Append
Add an entry to the running white list defining the remote devices which are allowed to establish a connection. If list is empty, calls from all devices will be accepted. Do not use this command while advertising or while being connected. The current list is discarded upon reset or power-cycle.
Table 206: COMMAND Byte Type 0 1 2 3 0x00 0x07 0x00 0x0A Name hilen lolen class method Description Message type: command Minimum payload length Message class: System Message ID Bluetooth device address to add to the running white list
Description Message type: command Minimum payload length Message class: System
method Message ID
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_system_whitelist_append( bd_addr address, uint8 address_type ); /* Callback */ struct ble_msg_system_whitelist_append_rsp_t{ uint16 result } void ble_rsp_system_whitelist_append( const struct ble_msg_system_whitelist_append_rsp_t * msg )
BGScript Functions
call system_whitelist_append(address, address_type)(result)
Whitelist Clear
Delete alll entries of the white list at once. Do not use this command while advertising or while being connected.
Table 208: COMMAND Byte Type Name 0 1 2 3 0x00 hilen 0x00 lolen 0x00 class Description Message type: command Minimum payload length Message class: System
Description Message type: command Minimum payload length Message class: System
C Functions
/* Function */ void ble_cmd_system_whitelist_clear( void ); /* Callback * void ble_rsp_system_whitelist_clear( const void *nul )
BGScript Functions
call system_whitelist_clear()
Whitelist Remove
Remove an entry from the running white list. Do not use this command while advertising or while being connected.
Table 210: COMMAND Byte Type 0 1 2 3 0x00 0x07 0x00 0x0B Name hilen lolen class method Description Message type: command Minimum payload length Message class: System Message ID
4 - 9 bd_addr address 10 uint8 address_type Table 211: RESPONSE Byte Type 0 1 2 3 0x00 0x02 0x00 0x0B Name hilen lolen class Description Message type: command Minimum payload length Message class: System
method Message ID
4 - 5 uint16 result
C Functions
/* Function */ void ble_cmd_system_whitelist_remove( bd_addr address, uint8 address_type ); /* Callback */ struct ble_msg_system_whitelist_remove_rsp_t{ uint16 result } void ble_rsp_system_whitelist_remove( const struct ble_msg_system_whitelist_remove_rsp_t * msg )
BGScript Functions
call system_whitelist_remove(address, address_type)(result)
5.8.2 Enumerations
System class enumerations
Endpoints
Data Endpoints used in data routing and interface configuration Table 212: VALUES Value Name 0 1 2 3 4 5 system_endpoint_api system_endpoint_test Description Command Parser Radio Test
5.8.3 Events
System class events
Boot
This event is produced when the device boots up and is ready to receive commands This event is not sent over USB interface. Table 213: EVENT Byte 0 1 2 3 4-5 6-7 8-9 Type 0x80 0x0C 0x00 0x00 Name hilen lolen class method Description Message type: event Minimum payload length Message class: System Message ID Major software version Minor software version Patch ID Build version Link layer version
C Functions
/* Callback */ struct ble_msg_system_boot_evt_t{ uint16 major, uint16 minor, uint16 patch, uint16 build, uint16 ll_version, uint8 protocol_version, uint8 hw } void ble_evt_system_boot( const struct ble_msg_system_boot_evt_t * msg )
BGScript Functions
event system_boot(major, minor, patch, build, ll_version, protocol_version, hw)
Endpoint Watermark Rx
This event is generated if the endpoint has reached the threshold defined by the watermark. Table 214: EVENT Byte Type Name 0 1 2 3 4 5 0x80 0x02 0x00 0x02 hilen lolen class method Description Message type: event Minimum payload length Message class: System Message ID
uint8 endpoint Endpoint index where data was received uint8 data Received data size
C Functions
/* Callback */ struct ble_msg_system_endpoint_watermark_rx_evt_t{ uint8 endpoint, uint8 data } void ble_evt_system_endpoint_watermark_rx( const struct ble_msg_system_endpoint_watermark_rx_evt_t * msg )
BGScript Functions
event system_endpoint_watermark_rx(endpoint, data)
Endpoint Watermark Tx
This event is generated if the endpoint (transmitting buffer) has reached the threshold of the watermark. Table 215: EVENT Byte Type Name 0 1 2 3 4 5 0x80 0x02 0x00 0x03 hilen lolen class method Description Message type: event Minimum payload length Message class: System Message ID
uint8 endpoint Endpoint index where data was sent uint8 data Space available
C Functions
/* Callback */ struct ble_msg_system_endpoint_watermark_tx_evt_t{ uint8 endpoint, uint8 data } void ble_evt_system_endpoint_watermark_tx( const struct ble_msg_system_endpoint_watermark_tx_evt_t * msg )
BGScript Functions
event system_endpoint_watermark_tx(endpoint, data)
Script Failure
Script failure detected Table 216: EVENT Byte Type 0 1 2 3 0x80 0x04 0x00 0x04 Name hilen lolen class method Description Message type: event Minimum payload length Message class: System Message ID
4 - 5 uint16 address Address where failure was detected 6 - 7 uint16 reason Reason for failure
C Functions
/* Callback */ struct ble_msg_system_script_failure_evt_t{ uint16 address, uint16 reason } void ble_evt_system_script_failure( const struct ble_msg_system_script_failure_evt_t * msg )
BGScript Functions
event system_script_failure(address, reason)
Timeout (0x0185)
Command or Procedure failed due to timeout
flow (0x0187)
Command would cause either underflow or overflow error
6 Contact information
Sales: [email protected]
Technical support:
[email protected] http://techforum.bluegiga.com
Orders:
WWW:
http://www.bluegiga.com http://www.bluegiga.hk
Phone: +358-9-4355 060 Fax: +358-9-4355 0660 Sinikalliontie 5 A 02630 ESPOO FINLAND
Phone: +1 770 291 2181 Fax: +1 770 291 2183 Bluegiga Technologies, Inc. 3235 Satellite Boulevard, Building 400, Suite 300 Duluth, GA, 30096, USA
Sales Office / Hong-Kong: Phone: +852 3182 7321 Fax: +852 3972 5777 Bluegiga Technologies, Inc. 19/F Silver Fortune Plaza, 1 Wellington Street, Central Hong Kong