Bluetooth: btlinux: adapt to dynamic HCI interface index

Signed-off-by: hmz007 <hmz007@gmail.com>
master
hmz007 9 months ago
parent 1293c05d0d
commit e09eee9541

@ -84,10 +84,14 @@ int BluetoothHci::openBtHci() {
}
bt_soc_fd_ = fd;
if (waitHciDev(hci_interface)) {
int ret = waitHciDev(hci_interface);
if (ret < 0) {
ALOGE( "HCI interface (%d) not found", hci_interface);
::close(fd);
return -1;
} else if (hci_interface != ret) {
hci_interface = ret;
ALOGD( "HCI interface (%d) found", hci_interface);
}
struct sockaddr_hci addr;
memset(&addr, 0, sizeof(addr));
@ -173,7 +177,10 @@ int BluetoothHci::waitHciDev(int hci_interface) {
break;
}
if (ev.opcode == MGMT_EV_INDEX_ADDED && ev.index == hci_interface) {
if (ev.opcode == MGMT_EV_INDEX_ADDED) {
if (hci_interface != ev.index) {
ret = ev.index;
}
goto end;
} else if (ev.opcode == MGMT_EV_COMMAND_COMP) {
struct mgmt_event_read_index* cc;
@ -186,6 +193,10 @@ int BluetoothHci::waitHciDev(int hci_interface) {
for (i = 0; i < cc->num_intf; i++) {
if (cc->index[i] == hci_interface) goto end;
}
if (cc->num_intf > 0) {
ret = cc->index[0];
goto end;
}
}
}
}

@ -40,6 +40,11 @@ H4Protocol::H4Protocol(int fd, PacketReadCallback event_cb,
disconnect_cb_(std::move(disconnect_cb)) {}
size_t H4Protocol::Send(uint8_t type, const uint8_t* data, size_t length) {
if (disconnected_) {
ALOGE("%s error writing to disconnected device", __func__);
return 0;
}
/* For HCI communication over USB dongle, multiple write results in
* response timeout as driver expect type + data at once to process
* the command, so using "writev"(for atomicity) here.
@ -126,6 +131,11 @@ void H4Protocol::OnDataReady(int fd) {
}
if (bytes_read < 0) {
ALOGW("error reading from UART (%s)", strerror(errno));
if (errno == EPIPE) {
disconnected_ = true;
disconnect_cb_();
// LOG_ALWAYS_FATAL("HCI device disconnected");
}
return;
}
send_data_to_packetizer(buffer, bytes_read);

Loading…
Cancel
Save