BLE Implementation Agenda BLE Protocol Stack BLE Software

BLE Implementation

Agenda • BLE Protocol Stack • BLE Software Architecture and Structure • GATT Profiles and Services • Implementation

Protocol Stack • Protocol stack consists of two main sections: • Controller • Host • Solution: single-device, dual-device, network processor. • RF Specifications: • Operates in 2. 4 GHz ISM band • 40 channels with 2 MHz spacing • 3 fixed advertisting channels for broadcasting, which avoid 802. 11 interferance • 37 adaptively frequency hopped dynamic data channel

Link Layer • 3 Advertising Channels and 37 Data Channels

States and Network Topology • Standby-device is not transmitting or receiving any data, and is not connected to any other device • Advertiser - periodically broadcasting advertisements • Scanner - actively looking for advertisers • Initiator - actively trying to initiate a connection with another device • Master - connected to another device as a master • Slave -connected to another device as a slave • BLE is a “star” topology network

Advertisement Events • A device in the advertising state transmits advertising packets • Advertising packets can contain a data payload • Advertising packets can be directed towards a specific scanner device, or undirected • Advertisements can be connectable or non-connectable (and therefore just used for broadcast of data) • During one “advertising event”, an advertisement packet is transmitted on each of the three advertising channels (37, 38, and 39)

Connection Parameters • Channel Map: indicates which data channels are used during the connection • Hop Increment: random value between 5 and 16 for channel selection algorithm • Connection Interval: multiple of 1. 25 ms in range of 7. 5 ms and 4. 0 s • Supervision Timeout: multiple of 10 ms in the range of 100 ms and 32. 0 s. Must be larger than: (1 + slave. Latency) * (Conn. Interval) • Slave Latency: any value between 0 and 499, though it cannot exceed: ((supervision. Timeout / conn. Interval) -1)

Connection Interval

Logical Link Control and Adaptation Protocol (L 2 CAP) • Permits upper level protocols and applications to transmit and receive upper layer data packets up to 23 bytes in length. • Provides channel management, allowing for logical channels between two endpoints, supported by the link layer • Connection Parameter Updates

Security Manager Protocol (SMP) • Performs authentication and key management • AES-128 encryption algorithm • Works with GAP to manage Bonding relationships between devices: • Pairing • Authentication • Bonding

Generic Access Profile (GAP) • Defines generic procedures for connectionrelated services: • Device Discovery • Link Establishment • Link Management • Link Termination • Initiation of security features • AES-128 encryption algorithm • Works with GAP to manage relationships between devices: • Pairing • Authentication • Bonding

GAP Profile Roles • Broadcaster: an advertiser that is non-connectable • Observer: scans for advertisements, but cannot initiate connections. • Peripheral: an advertiser that is connectable and can operate as a slave in a single link layer connection. • Central: scans for advertisements and initiates connections; operates as a master in a single or multiple link layer connections.

Advertisement and Scan Response Data • “ D” types: • Device Services (e. g. “I am a remote control”) • Service Solicitation (e. g. “I want a remote control to talk to me”) • Device Name • “Flags” -describes the discoverable mode and whether device supports standard Bluetooth or just Low Energy • Tx Power Level • Slave preferred connection interval range • Security support • Manufacturer-specific data

Attribute Protocol (ATT) • An attribute is a discrete value that has associated with it the following three properties: • A handle (address) • A type • A set of permissions • ATT defines the over-the-air protocol for reading, writing, and discovering attributes • Allows for different permissions to be assigned to attributes, including whether they are readable or writeable, and whether additional security is required for access

Generic Attribute Profile (GATT) • A profile is composed of one or more “services” necessary to fulfill a use-case • A service may contain certain attributes called “characteristic values”, which are values used by a service • A characteristic value must have a mandatory “characteristic declaration” attribute immediately before the value, containing the properties of the characteristic • Characteristics may also contain optional “descriptor” attributes, with fields such as a configuration or a description

Service Example

CC 2541 DK MINI Kit: Sensor. Tag

BLE Implementation: UART port

BLE Implementation: Project option

BLE Implementation: Application Overview HAL (Hardware Abstraction Layer) OSAL (Operating System Abstraction Layer) Initialization Task event processor Process task message Service change Callback 2 B 00: Control Service 3 B 00: Voice Note Service 4 B 00: Notification Service 5 B 00: Motion Service BLE_Bridge HAL_UART_DMA Hal. UARTInit Hal. UARTOpen Hal. UARTRead Hal. UARTWrite osal_start_system osal_run_system task. Events table

Signed GATT Service Profiles UUID (Universal Unique Identifiers)

BLE Implementation: Service UUIDs • Motion UX Service: • 00005 B 00 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Command Service UUID • 00005 B 01 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Motion DATA Characteristic (Notification) • 00005 B 02 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Motion Switcher Characteristic (Writable) • 00005 B 03 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Motion Pattern Characteristic (Notification) • 00005 B 04 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Information Request Characteristic (Notification) • 00005 B 05 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Silence Rington Chacteristic (Writable from ND)

BLE Implementation: Service UUIDs • Voice Service: • 00003 B 00 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Voice Service UUID • 00003 B 01 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Voice AVAILABLE Characteristic (Notification) • 00003 B 02 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Voice READ Characteristic (Readable from phone) • 00003 B 03 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Voice ACK Characteristic (Writable from phone)

BLE Implementation: Service UUIDs • Notification Service: • 00004 B 00 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Notification Service UUID • 00004 B 01 -0000 -1000 -8000 -00805 f 9 b 34 fb --> SMS Characteristic (Writable from phone) • 00004 B 02 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Imcoming Call Characteristic (Writable from phone) • 00004 B 03 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Missed Call Chacteristic (Writable from phone) • 00004 B 04 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Time Sync Chacteristic (Writable from phone) • Control Service: • 00002 B 00 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Micro. App. Manager Service UUID • 00002 B 01 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Micro. App Installer Characteristic (Writable from phone) • 00002 B 02 -0000 -1000 -8000 -00805 f 9 b 34 fb --> Micro. App Installer ACK Characteristic (Notification)

BLE Implementation: Application Startup Application (BLE_Bridge. c) --> BLE_Bridge_Init() HAL Hal. UARTInit() User Profile (Motion. Sensor. Service. c) - motion. Data - motion. Cfg

BLE Implementation: Notifications ON

BLE Implementation: Value Changes

BLE Implementation: Profile/Service 1. include profile/service header file in the beginning. #include “Typical. Service. h“ #define MOTIONSENSOR_SERV_UUID 0 x 5 B 00 2. Define service UUID format in GLOBAL VARIABLES area static CONST uint 8 motion. Service. UUID[ATT_BT_UUID_SIZE] = { LO_UINT 16(MOTIONSENSOR_SERV_UUID), HI_UINT 16(MOTIONSENSOR_SERV_UUID) }; 3. Create Profile Attributes Table - Motion Service - Characteristic Declaration - Characteristic Value "Data" - Characteristic configuration - Characteristic User Description

BLE Implementation: Profile/Service 4. LOCAL FUNCTIONS definition - motion_Read. Attr. CB - motion_Write. Attr. CB - motion_Handle. Conn. Status. CB 5. PROFILE CALLBACKS definition static CONST gatt. Service. CBs_t motion. CBs = { motion_Read. Attr. CB, // Read callback function pointer motion_Write. Attr. CB, // Write callback function pointer NULL // Authorization callback function pointer }; 6. PUBLIC FUNCTIONS - MOT_Add. Service: Initializes motion service by registering GATT attributes with the GATT server. - MOT_Set. Parameter: Set motion service parameter. - MOT_Get. Parameter: Get motion service parameter.

BLE Implementation: Main function • Import related service file in project source, PROFILE. • Add services: • VDR_Add. Service(GATT_ALL_SERVICES); • NFY_Add. Service(GATT_ALL_SERVICES); • MOT_Add. Service(GATT_ALL_SERVICES); • CTL_Add. Service(GATT_ALL_SERVICES); • Register callbacks with profile: • VOID VDR_Register. App. CBs(&iv 01_vdr. CBs); • VOID NFY_Register. App. CBs(&iv 01_nfy. CBs); • VOID MOT_Register. App. CBs(&iv 01_mot. CBs); • VOID CTL_Register. App. CBs(&iv 01_ctl. CBs);

BLE Implementation: Event Process if (events & MOTION_SENSOR_EVT) { if (motion. Enabled) { if (Motion. Date. Changed) { Motion. Date. Changed = 0; UARTSend. Command(_CMDID_MOTION); Read. Motion. Data(); } osal_start_timer. Ex(BLE_Bridge_Task. ID, MOTION_SENSOR_EVT, sync. Period); } } return (events ^ MOTION_SENSOR_EVT);

BLE Implementation: Callback Value was changed by connected device, then send OSAL event request to handle the related behavior.

Customized Name The User description will show up as one of the sub-fields when you expand the service and characteristic. The name is taken from an XML file in Program Files (x 86)Texas InstrumentsBLE Device Monitorgatt_uuid. xml. The names are aquirred from the SIG profiles which associate a name with an UUID. This metadata is not available over the air, as it's assumed that a UUID is unique and known to both sides for correct operation.

Reference • BLE_CC 2540_Deep. Dive_Training • TI_BLE_Sample_Applications_Guide • TI_BLE_Software_Developer's_Guide • HAL Driver API • BLE Bridge sample introduction Thank you!
- Slides: 34