2014年6月26日 星期四

[Bluetooth] ibeacon Packet Format 分析

ibeacon是Apple於2013年底所發表的室內定位技術。Apple利用Bluetooth4.0 LE(2010 Release) advertising 特性,定期廣播訊ibeacon packet,使得Client端取得訊息強度之參數(RSSI,Received Signal Strength Indication),再透過訊號強度與距離換算函數計算出真實距離,最後搭配定位演算做到室內定位之功能。

AIR INTERFACE PACKETS是一個只能運作在LE Device下的特殊封包,也是在Link layer中,唯一可以運作在advertising channel和data channel的Packet。Apple利用此特性,把ibeacon資訊夾帶在這個封包裡面。

AIR INTERFACE PACKETS 定義如下:

圖一 : AIR INTERFACE PACKET FORMAT
圖片來源 : Bluetooth 4.0 Spec
  • Preamble
    • 所有的Link Layer pakcet都有這個Byte,可以被使用在執行
      • Frequency synchronization
      • symbol timing estimation
      • Automatic Gain Control (AGC) training
    • Advertising Channel Preamble => 10101010b
    • Data Channel Preamble,有兩種可能
      • LSB of Access Address is 1 => 01010101b
      • LSB of Access Address is 0 => 10101010b
  •  Access Address
    • All advertising channel packets => 10001110100010011011111011010110b  (0x8E89BED6)
    • Data channel packets
  • PDU ( Protocol Data Unit )
    • 儲存下一層Protocol的Data

  • CRC
    • 檢查碼

iBeacon packet format定義如下:
圖三 : iBeacon packet format

以下 Raw Data是從網路下取得,藉此來解釋封包。必須要注意Bluetooth的傳遞為little endian,故要做轉換。

Raw Data
D6 BE 89 8E 40 24 65 FA D9 72 39 D0 02 01 06 1A
FF 4C 00 02 15 74 27 8B DA B6 44 45 20 8F 0C 72
0E AF 05 99 35 00 00 00 00 C5 04 21 B9
  • Access Addres(4bytes) = 0x8E89BED6 (Advertising Channel)
  • Advertising PDU Header (2 bytes) 
圖四 : Advertising channel PDU Header
圖片來源 : Bluetooth 4.0 Spec
註: RFU = RESERVED FOR FUTURE USE
    •  PDU Type(4bits) = 0000b
    圖五 : Advertising channel PDU Header's PDU Type field enconding
    圖片來源 : Bluetooth 4.0 Spec
      • ADV_IND: connectable undirected advertising event
      • ADV_DIRECT_IND: connectable directed advertising event
      • ADV_NONCONN_IND: non-connectable undirected advertising event
      • ADV_SCAN_IND: scannable undirected advertising event
    • RFU (2bits)   = 00b
    • TxAdd(1bits) = 1b
    • RxAdd(1bits) = 0b
    • Length(6bits) =  0x24 = 36bytes
  •  MAC Address (6bytes) = D0:39:72:D9:FA:65
  •  Advertising Data
    • AD1 Length(1byte) = 0x02
    • AD1 Type(1byte)  = 0x01 
    • AD1 Flags(1byte) = 0x06
圖六 : Flags
圖片來源 : Bluetooth 4.0 Spec
    • AD2 Length(1byte) = 0x1A = 25 bytes
    • AD2 Type(1byte)  = 0xFF
圖七 : Manufacturer Specific Data
圖片來源 : Bluetooth 4.0 Spec
  •  Manufacturer Specific Data
    • Manufacturer type(2bytes) = 0x004C
圖八 : Manufacturer Specific Data
資料來源 :what-is-the-ibeacon-bluetooth-profile
    • ibeacon AD Indicator(2bytes) = 02
    • Data Length (1byte) = 0x15 = 21 bytes
    • UUID (16bytes) =74 27 8B DA B6 44 45 20 8F 0C 720E AF 05 99 35
    • Major Number (2bytes) = 00 00
    • Minor Number (2bytes) = 00 00
    • TX Power (1byte) = 0xC5 = -59db
    圖三 : TX Power Level
    圖片來源 : Bluetooth 4.0 Spec
  • CRC(3bytes) = 04 21 B9
    Reference :
    [1] bluetooth org
    [2] how-do-ibeacons-work
    [3] what-is-the-ibeacon-bluetooth-profile
    [4] Core Version 4.0 - Bluetooth

    沒有留言:

    張貼留言