1. 向USB core z注册 HCI_USB_DRIVER
static int __init hci_usb_init(void)
{
int err;
BT_INFO("HCI USB driver ver %s", VERSION);
if ((err = usb_register(&hci_usb_driver)) < 0)
BT_ERR("Failed to register HCI USB driver");
return err;
}
2.实际上是在热插拔的时候让USB core 调用hci_usb_probe 以及hci_usb_disconnect
static struct usb_driver hci_usb_driver = {
.owner = THIS_MODULE,
.name = "hci_usb",
.probe = hci_usb_probe,
.disconnect = hci_usb_disconnect,
.id_table = bluetooth_ids,
};
在probe 函数中,Bluetooth USB driver 向上层HCI 注册,。
if (hci_register_dev(hdev) < 0) {
BT_ERR("Can't register HCI device");
hci_free_dev(hdev);
goto probe_error;
}
向上层提供操作本层USB设备的方法。
hdev->open = hci_usb_open;
hdev->close = hci_usb_close;
hdev->flush = hci_usb_flush;
hdev->send = hci_usb_send_frame;
hdev->destruct = hci_usb_destruct;
hdev->notify = hci_usb_notify;
hci_usb_Driver 是 USB Core 中的USB类得抽象
hci_dev 是在HCI 层中对设备的一个抽象
usb_device 是USB Core 中的一个设备抽象。udev = interface_to_usbdev(intf); intf 由probe 提供
hci_usb (husb) 结构体通过 2个分别指向 hci_dev结构体和 usb_device结构体
的指针将HCI 层与USB 设备联系起来。
struct sk_buff_head transmit_q[4];
struct sk_buff *reassembly[4]; /* Reassembly buffers */
rwlock_t completion_lock;
atomic_t pending_tx[4]; /* Number of pending requests */
struct _urb_queue pending_q[4]; /* Pending requests */
struct _urb_queue completed_q[4]; /* Completed requests */