Orelsanpls
Orelsanpls

Reputation: 23545

iBeacon emulation ubuntu error

I want to use my computer as an iBeacon, and I don't succeed (On a Ubuntu 14.04 running in a virtualBox environement on Windows 8.1)

Here is the code I use

#!/bin/bash                                                                                           
sudo hciconfig hci0 up
sudo hciconfig hci0 noleadv
sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 \
d0 f5 a7 10 96 e0 00 00 00 00 c5 00 00 00 00 00 00 00 00 00 00 00 00 00
sudo hciconfig hci0 leadv

My hciconfig result

hci0:   Type: BR/EDR  Bus: USB
    BD Address: 00:C2:C6:18:C5:E9  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING PSCAN ISCAN 
    RX bytes:5333127 acl:66 sco:0 events:887454 errors:0
    TX bytes:40617442 acl:64 sco:0 commands:887224 errors:0

I have the bluez version 5.36 installed (checked with bluetoothd -v)


I have seen many Stack overflow post about this but cannot figure it out! Check Here, Here or Here.


I have bought a real iBeacon to look about what works to help me, here is what I have:

Using hcidump -R I read this

< 01 0B 20 07 01 10 00 10 00 00 00 
> 04 0E 04 01 0B 20 00 
< 01 0C 20 02 01 01 
> 04 0E 04 01 0C 20 00 
> 04 3E 2A 02 01 00 01 4F 00 00 02 4D CD 1E 02 01 06 1A FF 4C 
  00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60 D0 F5 A7 10 96 E0 00 
  00 00 00 C5 BB 
> 04 3E 2A 02 01 04 01 4F 00 00 02 4D CD 1E 02 0A F4 08 16 F0 
  FF 64 00 00 00 00 11 09 4D 69 6E 69 42 65 61 63 6F 6E 5F 30 
  30 30 37 39 BB 
> 04 3E 2A 02 01 00 01 4F 00 00 02 4D CD 1E 02 01 06 1A FF 4C 
  00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60 D0 F5 A7 10 96 E0 00 
  00 00 00 C5 BB 
> 04 3E 2A 02 01 04 01 4F 00 00 02 4D CD 1E 02 0A F4 08 16 F0 
  FF 64 00 00 00 00 11 09 4D 69 6E 69 42 65 61 63 6F 6E 5F 30 
  30 30 37 39 BB 
< 01 0C 20 02 00 01 
> 04 0E 04 01 0C 20 00

Problem is I don't understand why there so much different paquet size and type (maybe other bluetooth nonBeacon device).

I'm pretty sure that this is the beacon paquet, but theses data make no sense to me

04 3E 2A 02 01 00 01 4F 00 00 02 4D CD 1E 02 01 06 1A FF 4C 
00 02 15 E2 C5 6D B5 DF FB 48 D2 B0 60 D0 F5 A7 10 96 E0 00 
00 00 00 C5 BB 

I have trying to use this to understand it but failed (using some stack overflow responses like the following)


First, in order to get BlueZ to advertise, the byte sequence you supply must include a valid BLE advertisement header, which is a minimum of 8 bytes. So to advertise "helloworld" you actually need to send:

sudo hcitool -i hci0 cmd 0x08 0x0008 10 02 01 1a 0c ff 18 01 48 45 4c 4c 4f 57 4f 52 4c 44

The first 8 bytes are the header and the next 10 bytes are the string "helloworld" encoded as 8-bit ASCII.

The first 8 bytes can be broken down like this:

10 # Total length of the advertising packet
02 # Number of bytes that follow in first AD structure
01 # Flags AD type
1A # Flags value 0x1A = 000011010  
   bit 0 (OFF) LE Limited Discoverable Mode
   bit 1 (ON) LE General Discoverable Mode
   bit 2 (OFF) BR/EDR Not Supported
   bit 3 (ON) Simultaneous LE and BR/EDR to Same Device Capable (controller)
   bit 4 (ON) Simultaneous LE and BR/EDR to Same Device Capable (Host)
0C # Number of bytes that follow in second (and last) AD structure
FF # Manufacturer specific data AD type
18 01 # Company identifier code (0x0118 == Radius Networks)

---------------------

If you got anything that can help me to understand how iBeacon paquet are constructed, thank you

Upvotes: 1

Views: 247

Answers (1)

Orelsanpls
Orelsanpls

Reputation: 23545

Oh Gosh! I have found someone with exactly the same problem as me.

Look Here.


Response that helped from @Richard Wifall


I saw the same issue as memoryhole where I had to remove the extra zeros. I also had to enable advertising before I configured the advertising data for it to work properly with my dongle.

Here is the exact sequence/commands that worked for me:

sudo hciconfig hci0 up
sudo hciconfig hci0 leadv 3
sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0 00 00 00 00 c5 00

This is what my version of the Radius script ended up looking like:

#!/bin/sh
../ibeacon.conf
echo "Launching virtual iBeacon..."
sudo hciconfig $BLUETOOTH_DEVICE up
sudo hciconfig $BLUETOOTH_DEVICE leadv 3
sudo hcitool -i $BLUETOOTH_DEVICE cmd 0x08 0x0008 1e 02 01 1a 1a ff 4c 00 02 15 $UUID $MAJOR $MINOR $POWER 00
echo "Complete"

This was on a Rasberry Pi with a ORICO BTA-402-BK branded BLE dongle (CSR8510 A10)

(I would have left this as a comment, but didn't have enough rep)

Upvotes: 1

Related Questions