问题描述
我有一个蓝牙音频接口,我想更改其名称和CoD(设备类)参数。我曾尝试在Ubuntu上使用hcitool
来执行此操作,其中:sudo hcitool cmd 0x03 0x0024 0x260420
应该将CoD设置为0x260420(当前为0x260404),但是我没有运气。从我现在的理解来看,我认为您不能在Linux计算机上使用hcitool将cmd
命令发送到通过蓝牙连接到该计算机的蓝牙设备。有没有办法做到这一点?
是否有可能以任何方式远程更改蓝牙设备的配置?
解决方法
您可以使用一个小的 1
脚本尝试一下。我们将使用您可以在 C
头文件中找到的这两种方法。
hci_lib.h
请注意,您可以在官方蓝牙文档 (here) 中找到设备类别 (CoD) 的严格要求。这就是您需要 int hci_read_class_of_dev(int dd,uint8_t *cls,int to);
int hci_write_class_of_dev(int dd,uint32_t cls,int to);
来执行的原因。
sudo
控制台返回:
// Simple program to read and write Class of Device.
// To compile: `gcc -o rw_cod rw_cod.c -lbluetooth`
// To install lbluetooth: `apt-get install libbluetooth-dev`
// Execute with `sudo ./rw_cod`
// Note the original CoD first because it has strict rules,you might need to write it back later.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> // for close()
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
int main(void){
int dd = hci_open_dev(hci_devid("DC:A6:32:E4:9C:05"));
int timeout = 1000;
uint8_t cls[3] = {0};
int class;
int ret;
uint32_t new_class = 0x260404;
// Read CoD
ret = hci_read_class_of_dev(dd,cls,timeout);
class = cls[0] | cls[1] << 8 | cls[2] << 16;
printf("Class of Device = 0x%06x [%d]\n",class,ret);
// Set CoD
ret = hci_write_class_of_dev(dd,new_class,2000);
printf("Required new Class of Device = 0x%06x [%d]\n",ret);
// Check read CoD
ret = hci_read_class_of_dev(dd,timeout);
class = cls[0] | cls[1] << 8 | cls[2] << 16;
printf("Actual new Class of Device = 0x%06x [%d]\n",ret);
close(dd);
return 0;
}