为什么使用 ADV_DATA 的广告会产生无效参数
Why is advertising with ADV_DATA producing Invalid Parameters
我正在尝试使用管理编写一些 BlueZ 代码API,但我似乎无法让 BlueZ 在广告系统上宣传任意数据
我有 2 个测试,一个在 C++ 中,一个使用 BlueZ 发布的 btmgmt
工具
当我 运行 这个命令失败时
btmgmt add-adv -d 8C33 1
Add Advertising failed with status 0x0d (Invalid Parameters)
等效的 C++ 代码也同样失败
#include <iostream>
extern "C" {
#include "external/bluetooth/lib/bluetooth.h"
#include "external/bluetooth/lib/mgmt.h"
#include "external/bluetooth/lib/hci.h"
#include "external/bluetooth/lib/hci_lib.h"
#include "external/bluetooth/src/shared/mgmt.h"
}
static void setup_dv(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
std::cout << "good" << std::endl;
}
struct CPadvertising {
uint8_t instance;
uint32_t flags;
uint16_t duration;
uint16_t timeout;
uint8_t adv_data_len;
uint8_t scan_rsp_len;
uint8_t data[4];
} __packed;
int main()
{
mgmt* sock = mgmt_new_default();
CPadvertising* data = new CPadvertising();
data->instance = 1;
data->duration = 2;
data->timeout = 100;
data->adv_data_len = 4;
data->scan_rsp_len = 0;
data->flags = 0;
data->data[0] = 8;
data->data[1] = 12;
data->data[2] = 3;
data->data[3] = 3;
mgmt_send(sock, MGMT_OP_ADD_ADVERTISING, index,
sizeof(CPadvertising), data, setup_dv, nullptr, nullptr);
auto loop = g_main_loop_new(nullptr, FALSE);
g_main_loop_run(loop);
}
在 btmon
中有此输出
@ MGMT Command: Add Advertising (0x003e) plen 13 {0x0003} [hci0] 98.205359
Instance: 1
Flags: 0x00000000
Duration: 2
Timeout: 100
Advertising data length: 4
8 c 3 3 .3
Scan response length: 0
@ MGMT Event: Command Status (0x0002) plen 3 {0x0003} [hci0] 98.205376
Add Advertising (0x003e)
Status: Invalid Parameters (0x0d)
参考这些文档,我不应该得到任何无效参数,但我确实如此
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/mgmt-api.txt
但是,我知道某些类型的数据确实有效
btmgmt add-adv -d 080954657374204C45
甚至以一种更奇怪的方式在 btmon
上提示这个输出
@ MGMT Command: Add Advertising (0x003e) plen 20 {0x0002} [hci0] 143.671485
Instance: 1
Flags: 0x00000000
Duration: 0
Timeout: 0
Advertising data length: 9
Name (complete): Test LL <--- What is this
Scan response length: 0
查看 btmgmt 的源代码,这些是可用的选项:
static void add_adv_usage(void)
{
bt_shell_usage();
print("Options:\n"
"\t -u, --uuid <uuid> Service UUID\n"
"\t -d, --adv-data <data> Advertising Data bytes\n"
"\t -s, --scan-rsp <data> Scan Response Data bytes\n"
"\t -t, --timeout <timeout> Timeout in seconds\n"
"\t -D, --duration <duration> Duration in seconds\n"
"\t -P, --phy <phy> Phy type, Specify 1M/2M/CODED\n"
"\t -c, --connectable \"connectable\" flag\n"
"\t -g, --general-discov \"general-discoverable\" flag\n"
"\t -l, --limited-discov \"limited-discoverable\" flag\n"
"\t -n, --scan-rsp-local-name \"local-name\" flag\n"
"\t -a, --scan-rsp-appearance \"appearance\" flag\n"
"\t -m, --managed-flags \"managed-flags\" flag\n"
"\t -p, --tx-power \"tx-power\" flag\n"
"e.g.:\n"
"\tadd-adv -u 180d -u 180f -d 080954657374204C45 1");
}
查看有效的广告,第一个数字是数据的长度,第二个是data_type,其余是local name
字符串。所以:
0x08 = Length of datatype is 8
0x09 = Data type is <Complete Local Name>
0x54 = T
0x65 = e
0x73 = s
0x74 = t
0x20 = ' '
0x4C = L
0x45 = E
Not sure why that has turned up as Test LL
in the btmon output. I'll
assume it was a slightly different run that you recorded.
正在查看您 8c33
的数据; 8c 不代表长度,33 不是有效的数据类型。
我怀疑你想做的是发送制造商数据。假设您没有 company identifier,那么您可以使用 0xffff
进行测试。
这将是以下命令:
btmgmt add-adv -d 05ffffff8C33 -g 1
在 btmon 中给出了以下内容
@ MGMT Command: Add Adver.. (0x003e) plen 17 {0x0002} [hci0] 341.378134
Instance: 1
Flags: 0x00000002
Advertise as Discoverable
Duration: 0
Timeout: 0
Advertising data length: 6
Company: internal use (65535)
Data: 8c33
Scan response length: 0
我正在尝试使用管理编写一些 BlueZ 代码API,但我似乎无法让 BlueZ 在广告系统上宣传任意数据
我有 2 个测试,一个在 C++ 中,一个使用 BlueZ 发布的 btmgmt
工具
当我 运行 这个命令失败时
btmgmt add-adv -d 8C33 1
Add Advertising failed with status 0x0d (Invalid Parameters)
等效的 C++ 代码也同样失败
#include <iostream>
extern "C" {
#include "external/bluetooth/lib/bluetooth.h"
#include "external/bluetooth/lib/mgmt.h"
#include "external/bluetooth/lib/hci.h"
#include "external/bluetooth/lib/hci_lib.h"
#include "external/bluetooth/src/shared/mgmt.h"
}
static void setup_dv(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
std::cout << "good" << std::endl;
}
struct CPadvertising {
uint8_t instance;
uint32_t flags;
uint16_t duration;
uint16_t timeout;
uint8_t adv_data_len;
uint8_t scan_rsp_len;
uint8_t data[4];
} __packed;
int main()
{
mgmt* sock = mgmt_new_default();
CPadvertising* data = new CPadvertising();
data->instance = 1;
data->duration = 2;
data->timeout = 100;
data->adv_data_len = 4;
data->scan_rsp_len = 0;
data->flags = 0;
data->data[0] = 8;
data->data[1] = 12;
data->data[2] = 3;
data->data[3] = 3;
mgmt_send(sock, MGMT_OP_ADD_ADVERTISING, index,
sizeof(CPadvertising), data, setup_dv, nullptr, nullptr);
auto loop = g_main_loop_new(nullptr, FALSE);
g_main_loop_run(loop);
}
在 btmon
@ MGMT Command: Add Advertising (0x003e) plen 13 {0x0003} [hci0] 98.205359
Instance: 1
Flags: 0x00000000
Duration: 2
Timeout: 100
Advertising data length: 4
8 c 3 3 .3
Scan response length: 0
@ MGMT Event: Command Status (0x0002) plen 3 {0x0003} [hci0] 98.205376
Add Advertising (0x003e)
Status: Invalid Parameters (0x0d)
参考这些文档,我不应该得到任何无效参数,但我确实如此
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/mgmt-api.txt
但是,我知道某些类型的数据确实有效
btmgmt add-adv -d 080954657374204C45
甚至以一种更奇怪的方式在 btmon
@ MGMT Command: Add Advertising (0x003e) plen 20 {0x0002} [hci0] 143.671485
Instance: 1
Flags: 0x00000000
Duration: 0
Timeout: 0
Advertising data length: 9
Name (complete): Test LL <--- What is this
Scan response length: 0
查看 btmgmt 的源代码,这些是可用的选项:
static void add_adv_usage(void)
{
bt_shell_usage();
print("Options:\n"
"\t -u, --uuid <uuid> Service UUID\n"
"\t -d, --adv-data <data> Advertising Data bytes\n"
"\t -s, --scan-rsp <data> Scan Response Data bytes\n"
"\t -t, --timeout <timeout> Timeout in seconds\n"
"\t -D, --duration <duration> Duration in seconds\n"
"\t -P, --phy <phy> Phy type, Specify 1M/2M/CODED\n"
"\t -c, --connectable \"connectable\" flag\n"
"\t -g, --general-discov \"general-discoverable\" flag\n"
"\t -l, --limited-discov \"limited-discoverable\" flag\n"
"\t -n, --scan-rsp-local-name \"local-name\" flag\n"
"\t -a, --scan-rsp-appearance \"appearance\" flag\n"
"\t -m, --managed-flags \"managed-flags\" flag\n"
"\t -p, --tx-power \"tx-power\" flag\n"
"e.g.:\n"
"\tadd-adv -u 180d -u 180f -d 080954657374204C45 1");
}
查看有效的广告,第一个数字是数据的长度,第二个是data_type,其余是local name
字符串。所以:
0x08 = Length of datatype is 8
0x09 = Data type is <Complete Local Name>
0x54 = T
0x65 = e
0x73 = s
0x74 = t
0x20 = ' '
0x4C = L
0x45 = E
Not sure why that has turned up as
Test LL
in the btmon output. I'll assume it was a slightly different run that you recorded.
正在查看您 8c33
的数据; 8c 不代表长度,33 不是有效的数据类型。
我怀疑你想做的是发送制造商数据。假设您没有 company identifier,那么您可以使用 0xffff
进行测试。
这将是以下命令:
btmgmt add-adv -d 05ffffff8C33 -g 1
在 btmon 中给出了以下内容
@ MGMT Command: Add Adver.. (0x003e) plen 17 {0x0002} [hci0] 341.378134
Instance: 1
Flags: 0x00000002
Advertise as Discoverable
Duration: 0
Timeout: 0
Advertising data length: 6
Company: internal use (65535)
Data: 8c33
Scan response length: 0