of range for discoverable devices – Discoverable devices can be queried for name, class, list of services • Pairing/Bonding – Before a connec6on can be established – As of Bluetooth 2.1, authen6ca6on is op6onal using Secure Simple Pairing (SSP) – Pairing is the process that leads to a two devices being bonded • Protocols and Profiles – Devices implement profiles, built on top of protocols, to provide services to clients – Logical Link Control and Adapta6on Protocol (L2CAP) • Advanced Audio Distribu6on Profile (A2DP) • Human Interface Device (HID) – Radio Frequency Communica6ons (RFCOMM) • Serial Port Profile (SPP) – Service Discovery Protocol (SDP) • Client/Server Model – Servers "have" data, clients "access" data. Mobile device typically the client.
available to connect with • Iden6fied by a UUID – Standard services are 16-bit added to a common 128-bit base: • 00000000-0000-1000-8000-00805F9B34FB – Custom services can be any generated UUID • Common Service UUIDs – RFCOMM: 0x0003 – L2CAP: 0x0100 – Serial Port (SPP): 0x1101 – A2DP AudioSource: 0x110A – A2DP AudioSink: 0x110B • Full SPP UUID = 00001101-0000-1000-8000-00805F9B34FB 4
the General Aeributes (GATT) profile, built on the Aeributes (ATT) protocol – S6ll runs on top of L2CAP protocol • Server (accessory) devices adver6se presence – Contrast with listeners in BT Classic • Client devices scan for adver6sement packets • Device Roles – Central (client) – Peripheral (server) – Broadcaster (server) – Observer (client) • Central and Observer roles only in the current APIs
Characteris6c Proper6es Value Characteris6c Proper6es Value Characteris6c Proper6es Value Characteris6c Proper6es Value Characteris6c Proper6es Value Characteris6c Proper6es Value Characteris6c Proper6es Value Characteris6c Proper6es Value
RFCOMM Protocol Serial Port Profile RF Radio Link Layer L2CAP Protocol Attribute Protocol GATT Profile Bluetooth 2.1 BR/EDR Bluetooth 4.0 LE • Bluetooth Classic – Single mode – No BLE support • Bluetooth Smart – Single mode – BLE only • Bluetooth Smart Ready – Dual mode
up mul6ple commands • Post your results – Callbacks aren't on the main thread • No6fica6ons have to be set local and remote – setCharacteris6cNo6fica6on() for local – writeCharacteris6c() for remote • Max 4 simultaneous ac6ve no6fica6ons • Ensure device has LE support – <uses-feature> in AndroidManifest.xml • "android.hardware.bluetooth_le" – PackageManager.hasSystemFeature() 15
beacons • Provides all service data in the adver6sement – Adver6sement Data (AD) Structure – Packet contains collec6on of AD Structures • onLeScan() provides AD collec6on from raw scan record. • Faster access to data – No connec6on overhead • Simpler accessory stack implementa6on 16
Structure AD Structure AD Structure ... AD Structure AD Structure AD Structure AD Structure ... AD Structure public void onLeScan(BluetoothDevice, int rssi, byte[] scanRecord) Type Iden6fiers are Assigned Numbers by the Bluetooth SIG Device Name, Service UUIDs, Service Data, TX Power, etc. heps://www.bluetooth.org/en-us/specifica6on/assigned-numbers/generic-access-profile
device classes • BluetoothProfile – Common interface for all supported device profiles – Reports connec6on status of any devices matching the profile – Profile-specific ac6ons implemented in subclasses • Use BluetoothAdapter.getProfileProxy() to register a ServiceListener callback for connec6on events – Binder Proxy to control device's Bluetooth Service • ServiceListener is passed an instance of the profile when a device matching it is connected. 18