bluetooth - modrpc/info GitHub Wiki

Table of Contents

Overview

Lectures

Bluetooth Programming

Basics

  • Good for wirelessly tramitting small amounts of data over a short range (<100m)
  • Wireless replacement for serial communication interfaces
  • Operates at 2.4GHz (where ZigBee and WiFi also exist)

Masters, Slaves, and Piconets

  • Bluetooth networks (piconets) use a master/slave model to control when and where devices can send data
  • single master device can be connected up to seven different slave devices
    • master can 1) send data to any of its slaves and 2) request data from slaves
    • slaves are only allowed to transmit to and receive from their master
    • slaves can't talk to each other

Bluetooth Addresses and Names

  • Every single bluetooth device has a unqiue 48-bit address, BD_ADDR
    • organization unique ID (OUI): 24-bit MSB (higher-half) identifies the manufacturer
    • 24-bit LSB (lower-half) is unique part of address
    • represented with 12 hex digits
  • Device can have up-to-248-byte name (e.g. iPad Pro)

Connection Process

Inquiry

  • If two Bluetooth devices know absolutely nothing about each other, one must run an inquiry to try to discover the other.
  • One device sends out the inquiry request, and any device listening for such a request will respond with its address, and possibly its name and other information

Paging (Connecting)

  • Paging is the process of forming a connection between two Bluetooth devices. Before this connection can be initiated, each device needs to know the address of the other (found in the inquiry process).

Connection

  • After a device has completed the paging process, it enters the connection state. While connected, a device can either be actively participating or it can be put into a low power sleep mode.
    • Active Mode: This is the regular connected mode, where the device is actively transmitting or receiving data.
    • Sniff Mode: This is a power-saving mode, where the device is less active. It’ll sleep and only listen for transmissions at a set interval (e.g. every 100ms).
    • Hold Mode: Hold mode is a temporary, power-saving mode where a device sleeps for a defined period and then returns back to active mode when that interval has passed. The master can command a slave device to hold.
    • Park Mode: Park is the deepest of sleep modes. A master can command a slave to “park”, and that slave will become inactive until the master tells it to wake back up.

Bonding and Pairing

  • When two Bluetooth devices share a special affinity for each other, they can be bonded together.
  • Bonded devices automatically establish a connection whenever they’re close enough.
    • Start up the car, then the phone in my pocket immediately connects to the car’s Bluetooth system because they share a bond.
  • Pairing:
    • Bonds are created through one-time a process called pairing.
    • When devices pair up, they share their addresses, names, and profiles, and usually store them in memory.
    • They also share a common secret key, which allows them to bond whenever they’re together in the future.
  • Authentication:
    • Pairing usually requires an authentication process where a user must validate the connection between devices.
    • The flow of the authentication process varies and usually depends on the interface capabilities of one device or the other.
      • Sometimes pairing is a simple “Just Works” operation, where the click of a button is all it takes to pair (this is common for devices with no UI, like headsets).
      • Other times pairing involves matching 6-digit numeric codes.
      • Older, legacy (v2.0 and earlier), pairing processes involve the entering of a common PIN code on each device. The PIN code can range in length and complexity from four numbers (e.g. “0000” or “1234”) to a 16-character alphanumeric string.

Bluetooth Profiles

  • Additional protocols that build upon the basic Bluetooth standard to more clearly define what kind of data a Bluetooth module is transmitting.
  • Bluetooth specifications define how the technology works.
  • Bluetooth profiles define how it’s used.
  • Profile(s) a Bluetooth device supports determine(s) what application it’s geared towards.
    • hands-free Bluetooth headset uses headset profile (HSP)
    • Nintendo Wii Controller would implement the human interface device (HID) profile.
  • For two Bluetooth devices to be compatible, they must support the same profiles.

SPP (Serial Port Profile)

  • great for sending bursts of data between two devices
  • like RS-232 or UART, each connected device can send and receive data like there are RX and TX lines

HID (Human Interface Device)

  • for mouse, keyboard, joystick, game controller (Wii, PS3)

HPF (Hands-Free Profile)

  • hands-free audio systems in cars
  • add features like accept/reject calls, hang-up on top of HSP

HSP (Headset Profile)

  • for sending audio to/from both devices

A2DP (Advanced Audio Distribution Profile)

  • unlike HSP, one-way transmission
  • higher audio quality potential
  • e.g. audio player => Bose speaker
  • e.g. microphone => audio recorder
  • most A2DP modules support some audio codecs (e.g. SBC, MPEG-1, MPEG-2, AAC, etc)

AVRCP (A/V Remote Control Profile)

  • Allows commands to be sent from headphone.
  • e.g. Sony bluetooth headphone sends back/forward/start/stop command to audio palyer

Blutooth Protocols

Controller Stack

Asynchronous Connection-Less [logical] (ACL)

Synchronous connection-oriented (SCO) link

Link management protocol (LMP)

Host Controller Interface (HCI)

Low Energy Link Layer (LE LL)

Host Stack

Logical link control and adaptation protocol (L2CAP)

Bluetooth network encapsulation protocol (BNEP)

Radio frequency communication (RFCOMM)

Service discovery protocol (SDP)

Telephony control protocol (TCS)

Audio/video control transport protocol (AVCTP)

Audio/video data transport protocol (AVDTP)

Object exchange (OBEX)

Low Energy Attribute Protocol (ATT)

Low Energy Security Manager Protocol (SMP)

⚠️ **GitHub.com Fallback** ⚠️