使用堆栈的BlueZ作为外设时错误的有效载荷 [英] Wrong payload when using BlueZ stack as peripheral

查看:1185
本文介绍了使用堆栈的BlueZ作为外设时错误的有效载荷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照href=\"http://stackoverflow.com/questions/16151360/use-bluez-stack-as-a-peripheral-advertiser\">这个问题。下面是我用的命令:

I tried to follow the steps provided by davidgyoung in this question. Here are the commands I use:

hciconfig hci0 up
hciconfig hci0 noleadv
hcitool -i hci0 cmd 0x08 0x0008 48 45 4c 4c 4f 57 4f 52 4c 44
hciconfig hci0 leadv

这给了我这样的输出:

Which gives me this output:

LE set advertise enable on hci0 returned status 12 
< HCI Command: ogf 0x08, ocf 0x0008, plen 10 
48 45 4C 4C 4F 57 4F 52 4C 44 
> HCI Event: 0x0e plen 4 
01 08 20 12 

请注意,我不能用建议的命令 hciconfig hci0 leadv 0 ,因为它会引发错误警告:未知的命令 - 0

Note that I can't use the advised command hciconfig hci0 leadv 0 because it will throw the error Warning: unknown command - "0".

然而,当我尝试读出(例如使用 hcidump --raw )中公布的程序包有效载荷从另一个设备我得到的输出喜欢这个

However, when I try to read out (e.g. with a hcidump --raw) the payload in the advertised package from another device I'm getting an output like this:

hcitool莱斯康 - 复制输出片断(这两个项目被重复了一遍又一遍,看着MAC应该是相同的设备,虽然):

hcitool lescan -- duplicates output snippet (both entries are repeated over and over again, looking at the MAC it should be the same device, though):

00:1A:7D:DA:71:14 mint17-0
00:1A:7D:DA:71:14 (unknown)

匹配 hcidump --raw 输出片段:

> 04 3E 16 02 01 04 00 14 71 DA 7D 1A 00 0A 09 09 6D 69 6E 74 31 37 2D 30 BE 
> 04 3E 12 02 01 00 00 14 71 DA 7D 1A 00 06 02 01 02 02 0A 08 AD     

我使用的是配合bluez 5.26和CSR4.0加密狗。结果
这是advertisier的 hciconfig 输出:

hci0:   Type: BR/EDR  Bus: USB
    BD Address: 00:1A:7D:DA:71:14  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING PSCAN ISCAN 
    RX bytes:1242 acl:0 sco:0 events:77 errors:0
    TX bytes:2079 acl:0 sco:0 commands:77 errors:0

这是从扫描仪输出 hciconfig

hci0:   Type: BR/EDR  Bus: USB
    BD Address: 00:1A:7D:DA:71:13  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING PSCAN ISCAN 
    RX bytes:11753 acl:0 sco:0 events:552 errors:0
    TX bytes:1842 acl:0 sco:0 commands:75 errors:0

我错过了什么得到它的工作?

What did I miss to get it to work?

更新:结果
继大卫的意见,我改变了CMD值

Update:
Following David's advice I changed the cmd values to

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

得到这个输出

< HCI Command: ogf 0x08, ocf 0x0008, plen 18
10 02 01 1A 0C FF 18 01 48 45 4C 4C 4F 57 4F 52 4C 44 
> HCI Event: 0x0e plen 4
01 08 20 12 

但还是乱码有效载荷(即 hcidump --raw 输出的有效载荷部分)

af:08:0a:02:02:01:02
b7:08:0a:02:02:01:02
be:08:0a:02:02:01:02
...

更新2:结果
下面我尝试添加一些00有效载荷的下一个建议是:

Update 2:
Following the next advice I tried adding some 00 to the payload:

< HCI Command: ogf 0x08, ocf 0x0008, plen 42
  10 02 01 1A 0C FF 18 01 48 45 4C 4C 4F 57 4F 52 4C 44 00 00 
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
  00 00 
> HCI Event: 0x0e plen 4
  01 08 20 12

和这里的 hcidump --raw输出

> 04 3E 16 02 01 04 00 14 71 DA 7D 1A 00 0A 09 09 6D 69 6E 74 
  31 37 2D 30 BF 
> 04 3E 12 02 01 00 00 14 71 DA 7D 1A 00 06 02 01 02 02 0A 08 
  AC 
> 04 3E 12 02 01 00 00 14 71 DA 7D 1A 00 06 02 01 02 02 0A 08 
  BF 
> 04 3E 16 02 01 04 00 14 71 DA 7D 1A 00 0A 09 09 6D 69 6E 74 
  31 37 2D 30 BF 
> 04 3E 12 02 01 00 00 14 71 DA 7D 1A 00 06 02 01 02 02 0A 08 
  AD 

所以仍然没有喜悦。结果
难道是有意义的尝试的bluez不同的(也许较早)的版本?还是可以与硬件有关,我应该尝试不同的蓝牙软件狗?

So still no joy.
Would it make sense to try a different (maybe older) version of bluez? Or can it be hardware related and I should try to get different Bluetooth dongles?

更新3:结果
试着用的bluez 5.21这适用于大卫一样的。

Update 3:
Tried the same with bluez 5.21 which works for David.

这里的 hcidump --raw 输出的一个片段

> 04 3E 0C 02 01 04 00 14 71 DA 7D 1A 00 00 D7 
> 04 3E 22 02 01 00 00 14 71 DA 7D 1A 00 16 02 01 0A 02 0A 08 
  0F 09 72 73 73 6D 74 2D 63 6C 69 65 6E 74 2D 30 D4 
> 04 3E 0C 02 01 04 00 14 71 DA 7D 1A 00 00 D4 
> 04 3E 22 02 01 00 00 14 71 DA 7D 1A 00 16 02 01 0A 02 0A 08 
  0F 09 72 73 73 6D 74 2D 63 6C 69 65 6E 74 2D 30 D2

主机名已更改(第三台计算机上进行测试,到目前为止),所以输出是一个有点不同,但我仍然没有看到'你好世界任何地方。

The hostname has changed (tested on the third machine so far), so the output is a bit different but I still don't see 'hello world' anywhere.

在这一点上的任何想法都无任欢迎!

At this point any ideas are more than welcome!

更新4:结果
尝试了不同的硬件加密狗( IOGEAR GBU521W6由大卫的的建议),这现在看起来非常有前途!

Update 4:
Tried a different hardware dongle (IOGEAR GBU521W6 as suggested by David) and this looks very promising now!

在使用此广告的配置:

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

我得到这个 hcidump --raw 输出:

> 04 3E 1C 02 01 00 00 BA D0 63 70 F3 5C 10 02 01 1A 0C FF 18 01 48 45 4C 4C 4F 57 4F 52 4C B5

正如你所看到的有效载荷已近尾声,但最后一个字符缺失。通过改变长度属性为11,我得到全部有效载荷:

As you can see the payload is almost complete, but the last char is missing. By changing the length attribute to 11 I get the full payload:

hcitool -i hci0 cmd 0x08 0x0008 11 02 01 1a 0c ff 18 01 48 45 4c 4c 4f 57 4f 52 4c 44
----
> 04 3E 1D 02 01 00 00 BA D0 63 70 F3 5C 11 02 01 1A 0C FF 18 01 48 45 4C 4C 4F 57 4F 52 4C 44 AB

因此​​,对于未来的(和不同的有效载荷):所需长度似乎是有效负载的字节(不带长度属性) - 在这种情况下,17

So for the future (and different payloads): the required length seems to be the bytes of the payload (without the length attribute) - 17 in this case.

重要:它不以的bluez 5.26 对我来说,我使用的bluez 5.21 了。

Important: It does not work with bluez 5.26 for me, I'm using bluez 5.21 now.

推荐答案

两个问题:

首先,为了获得到的BlueZ做广告,您提供的字节序列必须包含一个有效的BLE广告标题,这是最起码的8个字节。所以做广告的HelloWorld你真的需要发送:

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:

须藤hcitool -i hci0 CMD 0x08的10×0008 02 01 1A 0℃FF 18 01 48 45 4C 4C 4F 57 4F 52 4C 44

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

的前8个字节是首标和下一个10个字节是字符串HelloWorld的连接$ C $光盘作为8位ASCII

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

前8个字节可以细分如下:

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)

请注意,这个标题包含了两个不同的长度字段,如果你改变HelloWorld的有效载荷的长度,你必须调整。此外,对于实验目的,欢迎您使用您想要的公司标识的两个字节。

Note that this header contains two different length fields that you must adjust if you change the length of the "helloworld" payload. Also, for experimentation purposes, you are welcome to use any two bytes for the company identifier that you want.

二,你看不到与 hcitool莱斯康命令检测到广告的​​原始字节。:要看到原始字节,在结合使用此命令和 hcidump 命令。在这里看到的细节:<一href=\"http://stackoverflow.com/a/21790504/1461050\">http://stackoverflow.com/a/21790504/1461050

Second, you can't see the raw bytes of a detected advertisement with the hcitool lescan command. To see the raw bytes, you have to use this command in combination with the hcidump command. See here for details: http://stackoverflow.com/a/21790504/1461050

这篇关于使用堆栈的BlueZ作为外设时错误的有效载荷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆