Ble overview and_implementation

34
BLE Overview and Implementation Stanley Chang 02, May. 2014

description

This is a quick start kit and concept for BLE implementation.

Transcript of Ble overview and_implementation

Page 1: Ble overview and_implementation

BLE Overview and Implementation

Stanley Chang02, May. 2014

Page 2: Ble overview and_implementation

Agenda

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

Page 3: Ble overview and_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

Page 4: Ble overview and_implementation

Link Layer

• 3 Advertising Channels and 37 Data Channels

Page 5: Ble overview and_implementation

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

Page 6: Ble overview and_implementation

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)

Page 7: Ble overview and_implementation

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.25ms in range of 7.5ms and 4.0s

• Supervision Timeout:multiple of 10ms in the range of 100ms and 32.0s. Must be larger than:

(1 + slaveLatency) * (ConnInterval)

• Slave Latency:any value between 0 and 499, though it cannot exceed:

((supervisionTimeout / connInterval) –1)

Page 8: Ble overview and_implementation

Connection Interval

Page 9: Ble overview and_implementation

Logical Link Control and Adaptation Protocol (L2CAP)

• 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

Page 10: Ble overview and_implementation

Security Manager Protocol (SMP)

• Performs authentication and key management

• AES-128 encryption algorithm • Works with GAP to manage

relationships between devices:• Pairing • Authentication • Bonding

Bonding

Page 11: Ble overview and_implementation

Generic Access Profile (GAP)

• Defines generic procedures for connection-related 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

Page 12: Ble overview and_implementation

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.

Page 13: Ble overview and_implementation

Advertisement and Scan Response Data• “AD” 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

Page 14: Ble overview and_implementation

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

Page 15: Ble overview and_implementation

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

Page 16: Ble overview and_implementation

Service Example

Page 17: Ble overview and_implementation

CC2541DK MINI Kit: SensorTag

Page 18: Ble overview and_implementation

BLE Implementation: UART port

Page 19: Ble overview and_implementation

BLE Implementation: Project option

Page 20: Ble overview and_implementation

BLE Implementation: Application Overview

BLE_Bridge

2B00: Control Service3B00: Voice Note Service4B00: Notification Service5B00: Motion Service

HAL_UART_DMA HalUARTInit HalUARTOpen HalUARTRead HalUARTWrite

InitializationTask event processorProcess task messageService change Callback

osal_start_systemosal_run_systemtaskEvents table

Page 21: Ble overview and_implementation

Signed GATT Service Profiles UUID

Page 22: Ble overview and_implementation

BLE Implementation: Service UUIDs

• Motion UX Service:

• 00005B00-0000-1000-8000-00805f9b34fb --> Command Service UUID

• 00005B01-0000-1000-8000-00805f9b34fb --> Motion DATA Characteristic (Notification)• 00005B02-0000-1000-8000-00805f9b34fb --> Motion Switcher Characteristic (Writable)• 00005B03-0000-1000-8000-00805f9b34fb --> Motion Pattern Characteristic (Notification)

• 00005B04-0000-1000-8000-00805f9b34fb --> Information Request Characteristic (Notification)• 00005B05-0000-1000-8000-00805f9b34fb --> Silence Rington Chacteristic (Writable from ND)

Page 23: Ble overview and_implementation

BLE Implementation: Service UUIDs

• Voice Service:

• 00003B00-0000-1000-8000-00805f9b34fb --> Voice Service UUID

• 00003B01-0000-1000-8000-00805f9b34fb --> Voice AVAILABLE Characteristic (Notification)

• 00003B02-0000-1000-8000-00805f9b34fb --> Voice READ Characteristic (Readable from phone)

• 00003B03-0000-1000-8000-00805f9b34fb --> Voice ACK Characteristic (Writable from phone)

Page 24: Ble overview and_implementation

BLE Implementation: Service UUIDs

• Notification Service:• 00004B00-0000-1000-8000-00805f9b34fb --> Notification Service UUID• 00004B01-0000-1000-8000-00805f9b34fb --> SMS Characteristic (Writable from phone)• 00004B02-0000-1000-8000-00805f9b34fb --> Imcoming Call Characteristic (Writable from phone)• 00004B03-0000-1000-8000-00805f9b34fb --> Missed Call Chacteristic (Writable from phone)• 00004B04-0000-1000-8000-00805f9b34fb --> Time Sync Chacteristic (Writable from phone)

• Control Service:• 00002B00-0000-1000-8000-00805f9b34fb --> MicroAppManager Service UUID• 00002B01-0000-1000-8000-00805f9b34fb --> MicroApp Installer Characteristic (Writable from

phone)• 00002B02-0000-1000-8000-00805f9b34fb --> MicroApp Installer ACK Characteristic (Notification)

Page 25: Ble overview and_implementation

BLE Implementation: Application Startup

Application (BLE_Bridge.c)--> BLE_Bridge_Init()

User Profile (MotionSensorService.c)- motionData- motionCfg

HALHalUARTInit()

Page 26: Ble overview and_implementation

BLE Implementation: Notifications ON

Page 27: Ble overview and_implementation

BLE Implementation: Value Changes

Page 28: Ble overview and_implementation

BLE Implementation: Profile/Service1. include profile/service header file in the beginning.

#include “TypicalService.h“#define MOTIONSENSOR_SERV_UUID 0x5B00

2. Define service UUID format in GLOBAL VARIABLES areastatic CONST uint8 motionServiceUUID[ATT_BT_UUID_SIZE] ={ LO_UINT16(MOTIONSENSOR_SERV_UUID), HI_UINT16(MOTIONSENSOR_SERV_UUID)};

3. Create Profile Attributes Table- Motion Service - Characteristic Declaration - Characteristic Value "Data" - Characteristic configuration - Characteristic User Description

Page 29: Ble overview and_implementation

BLE Implementation: Profile/Service4. LOCAL FUNCTIONS definition

- motion_ReadAttrCB- motion_WriteAttrCB- motion_HandleConnStatusCB

5. PROFILE CALLBACKS definition

static CONST gattServiceCBs_t motionCBs ={ motion_ReadAttrCB, // Read callback function pointer motion_WriteAttrCB, // Write callback function pointer NULL // Authorization callback function pointer};

6. PUBLIC FUNCTIONS- MOT_AddService: Initializes motion service by registering GATT attributes with the GATT server.- MOT_SetParameter: Set motion service parameter.- MOT_GetParameter: Get motion service parameter.

Page 30: Ble overview and_implementation

BLE Implementation: Main function

• Import related service file in project source, PROFILE.• Add services:

• VDR_AddService(GATT_ALL_SERVICES); • NFY_AddService(GATT_ALL_SERVICES); • MOT_AddService(GATT_ALL_SERVICES);• CTL_AddService(GATT_ALL_SERVICES);

• Register callbacks with profile:• VOID VDR_RegisterAppCBs(&iv01_vdrCBs);• VOID NFY_RegisterAppCBs(&iv01_nfyCBs);• VOID MOT_RegisterAppCBs(&iv01_motCBs);• VOID CTL_RegisterAppCBs(&iv01_ctlCBs);

Page 31: Ble overview and_implementation

BLE Implementation: Event Process if (events & MOTION_SENSOR_EVT) { if (motionEnabled) { if (MotionDateChanged) { MotionDateChanged = 0; UARTSendCommand(_CMDID_MOTION); ReadMotionData(); } osal_start_timerEx(BLE_Bridge_TaskID, MOTION_SENSOR_EVT, syncPeriod); }

return (events ^ MOTION_SENSOR_EVT); }

Page 32: Ble overview and_implementation

BLE Implementation: Callback

Value was changed by connected device, then send OSAL event request to handlethe related behavior.

Page 33: Ble overview and_implementation

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 (x86)\Texas Instruments\BLE Device Monitor\gatt_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.

Page 34: Ble overview and_implementation

Reference

• BLE_CC2540_DeepDive_Training• TI_BLE_Sample_Applications_Guide• TI_BLE_Software_Developer's_Guide• HAL Driver API• BLE Bridge sample introduction

Thank you!