环境:
我必须说HCI BlueZ C API(hci_lib.h)的文档记录很少,有这样的说法,是否有一个C hci_ * API控制主机可发现状态?类似于" hci_write_simple_pairing_mode"能否控制可发现性?
答案 0 :(得分:1)
以下hci命令使适配器可被发现 hciconfig hci0 piscan
以下是来自hciconfig的相应代码
if (!strcmp(opt, "pscan"))
dr.dev_opt = SCAN_PAGE;
else if (!strcmp(opt, "piscan"))
dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
if (ioctl(ctl, HCISETSCAN, (unsigned long) &dr) < 0) {
这里的ctl来自:
if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0)
答案 1 :(得分:0)
解决方案可以在hciconfig.c处找到具体的&lt; cmd_scan&#39;实施(有opt =&#34; piscan&#34;),推导出
HRESULT BluZbridge::SetDiscoverable(IN BOOL bVisible) {
if (0 == m_fdHCI)
return HRESULT_FROM_WIN32(ERROR_NOT_READY);
hci_dev_req req = { DEFAULT_HCI_ADAPTER_ID, ((TRUE == bVisible) ? (SCAN_PAGE | SCAN_INQUIRY) : SCAN_DISABLED) };
if (ioctl(m_fdHCI, HCISETSCAN, (unsigned long)&req) < 0) {
perror("Can't set scan mode on hci0");
return HRESULT_GET_ERRNO();
}
return S_OK;
}