Back to Librepods

Bluetooth Low Energy (BLE) - Apple Proximity Pairing Message

Proximity Pairing Message.md

0.2.56.4 KB
Original Source

Bluetooth Low Energy (BLE) - Apple Proximity Pairing Message

This document describes how the AirPods BLE "Proximity Pairing Message" is parsed and interpreted in the application. This message is broadcast by Apple devices (such as AirPods) and contains key information about the device's state, battery, and other properties.

Overview

When scanning for BLE devices, the application looks for manufacturer data with Apple's ID (0x004C). If the data starts with 0x07, it is identified as a Proximity Pairing Message. The message contains various fields, each representing a specific property of the AirPods.

Proximity Pairing Message Structure

Byte IndexField NameDescriptionExample Value(s)
0PrefixMessage type (should be 0x07 for proximity pairing)0x07
1LengthLength of the message0x12
2Pairing Mode0x01 = Paired, 0x00 = Pairing mode0x01, 0x00
3-4Device ModelBig-endian: [3]=high, [4]=low0x0E20 (AirPods Pro)
5StatusBitfield, see below0x62
6Pods Battery ByteNibbles for left/right pod battery0xA7
7Flags & Case BatteryUpper nibble: case battery, lower: flags0xB3
8Lid IndicatorBits for lid state and open counter0x09
9Device ColorColor code0x02
10Connection StateEnum, see below0x04
11-26Encrypted Payload16 bytes, not parsed

Field Details

Device Model

Value (hex)Model Name
0x0220AirPods 1st Gen
0x0F20AirPods 2nd Gen
0x1320AirPods 3rd Gen
0x1920AirPods 4th Gen
0x1B20AirPods 4th Gen (ANC)
0x0A20AirPods Max
0x1F20AirPods Max (USB-C)
0x0E20AirPods Pro
0x1420AirPods Pro 2nd Gen
0x2420AirPods Pro 2nd Gen (USB-C)

Status Byte (Bitfield)

BitMeaningValue if Set
0Right Pod In Ear (XOR logic)true
1Right Pod In Ear (XOR logic)true
2Both Pods In Casetrue
3Left Pod In Ear (XOR logic)true
4One Pod In Casetrue
5Primary Pod (1=Left, 0=Right)true/false
6This Pod In Casetrue

Ear Detection Logic

The in-ear detection uses XOR logic based on:

  • Whether the right pod is primary (areValuesFlipped)
  • Whether this pod is in the case (isThisPodInTheCase)
cpp
bool xorFactor = areValuesFlipped ^ deviceInfo.isThisPodInTheCase;
deviceInfo.isLeftPodInEar = xorFactor ? (status & 0x08) != 0 : (status & 0x02) != 0;  // Bit 3 or 1
deviceInfo.isRightPodInEar = xorFactor ? (status & 0x02) != 0 : (status & 0x08) != 0; // Bit 1 or 3

Primary Pod

Determined by bit 5 of the status byte:

  • 1 = Left pod is primary
  • 0 = Right pod is primary

This affects:

  1. Battery level interpretation (which nibble corresponds to which pod)
  2. Microphone assignment
  3. Ear detection logic

Microphone Status

The active microphone is determined by:

cpp
deviceInfo.isLeftPodMicrophone = primaryLeft ^ deviceInfo.isThisPodInTheCase;
deviceInfo.isRightPodMicrophone = !primaryLeft ^ deviceInfo.isThisPodInTheCase;

Pods Battery Byte

  • Upper nibble: one pod battery (depends on primary)
  • Lower nibble: other pod battery
ValueMeaning
0x0-0x90-90% (x10)
0xA-0xE100%
0xFNot available

Flags & Case Battery Byte

  • Upper nibble: case battery (same encoding as pods)
  • Lower nibble: flags

Flags (Lower Nibble)

BitMeaning
0Right Pod Charging (XOR)
1Left Pod Charging (XOR)
2Case Charging

Lid Indicator

BitsMeaning
0-2Lid Open Counter
3Lid State (0=Open, 1=Closed)

Device Color

ValueColor
0x00White
0x01Black
0x02Red
0x03Blue
0x04Pink
0x05Gray
0x06Silver
0x07Gold
0x08Rose Gold
0x09Space Gray
0x0ADark Blue
0x0BLight Blue
0x0CYellow
0x0D+Unknown

Connection State

ValueState
0x00Disconnected
0x04Idle
0x05Music
0x06Call
0x07Ringing
0x09Hanging Up
0xFFUnknown

Example Message

Byte IndexExample ValueDescription
00x07Proximity Pairing Message
10x12Length
20x01Paired
3-40x0E 0x20AirPods Pro
50x62Status
60xA7Pods Battery
70xB3Flags & Case Battery
80x09Lid Indicator
90x02Device Color
100x04Connection State (Idle)

For further details, see BleManager and BleScanner.