#include <sys/types.h>
#include <sys/bus.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/module.h>
#include <sys/systm.h>
#include <sys/taskqueue.h>
#include "usbdevs.h"
#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#define USB_DEBUG_VAR usb_debug
#include <dev/usb/usb_debug.h>
#include <netgraph/ng_message.h>
#include <netgraph/netgraph.h>
#include <netgraph/ng_parse.h>
#include <netgraph/bluetooth/include/ng_bluetooth.h>
#include <netgraph/bluetooth/include/ng_hci.h>
#include <netgraph/bluetooth/include/ng_ubt.h>
#include <netgraph/bluetooth/drivers/ubt/ng_ubt_var.h>
static device_probe_t ubt_rtl_probe;
const STRUCT_USB_HOST_ID ubt_rtl_devs[] =
{
{ USB_VENDOR(USB_VENDOR_REALTEK),
USB_IFACE_CLASS(UDCLASS_WIRELESS),
USB_IFACE_SUBCLASS(UDSUBCLASS_RF),
USB_IFACE_PROTOCOL(UDPROTO_BLUETOOTH) },
{ USB_VPI(0x13d3, 0x3529, 0) },
{ USB_VPI(0x13d3, 0x3600, 0) },
{ USB_VPI(0x04c5, 0x165c, 0) },
{ USB_VPI(0x04ca, 0x4006, 0) },
{ USB_VPI(0x0cb8, 0xc549, 0) },
{ USB_VPI(0x04ca, 0x4007, 0) },
{ USB_VPI(0x04c5, 0x1675, 0) },
{ USB_VPI(0x0cb8, 0xc558, 0) },
{ USB_VPI(0x13d3, 0x3587, 0) },
{ USB_VPI(0x13d3, 0x3586, 0) },
{ USB_VPI(0x13d3, 0x3592, 0) },
{ USB_VPI(0x13d3, 0x3612, 0) },
{ USB_VPI(0x0489, 0xe122, 0) },
{ USB_VPI(0x0cb8, 0xc559, 0) },
{ USB_VPI(0x13d3, 0x3570, 0) },
{ USB_VPI(0x13d3, 0x3571, 0) },
{ USB_VPI(0x13d3, 0x3572, 0) },
{ USB_VPI(0x13d3, 0x3591, 0) },
{ USB_VPI(0x0489, 0xe123, 0) },
{ USB_VPI(0x0489, 0xe125, 0) },
{ USB_VPI(0x13d3, 0x3617, 0) },
{ USB_VPI(0x13d3, 0x3616, 0) },
{ USB_VPI(0x0489, 0xe130, 0) },
{ USB_VPI(0x0930, 0x021d, 0) },
{ USB_VPI(0x13d3, 0x3394, 0) },
{ USB_VPI(0x0489, 0xe085, 0) },
{ USB_VPI(0x0489, 0xe08b, 0) },
{ USB_VPI(0x04f2, 0xb49f, 0) },
{ USB_VPI(0x13d3, 0x3410, 0) },
{ USB_VPI(0x13d3, 0x3416, 0) },
{ USB_VPI(0x13d3, 0x3459, 0) },
{ USB_VPI(0x13d3, 0x3494, 0) },
{ USB_VPI(0x7392, 0xa611, 0) },
{ USB_VPI(0x2ff8, 0xb011, 0) },
{ USB_VPI(0x2c4e, 0x0115, 0) },
{ USB_VPI(0x2357, 0x0604, 0) },
{ USB_VPI(0x0b05, 0x190e, 0) },
{ USB_VPI(0x2550, 0x8761, 0) },
{ USB_VPI(0x6655, 0x8771, 0) },
{ USB_VPI(0x7392, 0xc611, 0) },
{ USB_VPI(0x2b89, 0x8761, 0) },
{ USB_VPI(0x0b05, 0x17dc, 0) },
{ USB_VPI(0x13d3, 0x3414, 0) },
{ USB_VPI(0x13d3, 0x3458, 0) },
{ USB_VPI(0x13d3, 0x3461, 0) },
{ USB_VPI(0x13d3, 0x3462, 0) },
{ USB_VPI(0x13d3, 0x3526, 0) },
{ USB_VPI(0x0b05, 0x185c, 0) },
{ USB_VPI(0x04ca, 0x4005, 0) },
{ USB_VPI(0x04c5, 0x161f, 0) },
{ USB_VPI(0x0b05, 0x18ef, 0) },
{ USB_VPI(0x13d3, 0x3548, 0) },
{ USB_VPI(0x13d3, 0x3549, 0) },
{ USB_VPI(0x13d3, 0x3553, 0) },
{ USB_VPI(0x13d3, 0x3555, 0) },
{ USB_VPI(0x2ff8, 0x3051, 0) },
{ USB_VPI(0x1358, 0xc123, 0) },
{ USB_VPI(0x0cb5, 0xc547, 0) },
};
const size_t ubt_rtl_devs_sizeof = sizeof(ubt_rtl_devs);
static const uint16_t ubt_rtl_lmp_subvers[] = {
0x8703, 0x1200, 0x8723, 0x8821,
0x8761, 0x8822, 0x8852, 0x8851,
};
static usb_error_t
ubt_rtl_do_hci_request(struct usb_device *udev, uint16_t opcode,
void *resp, uint8_t resp_len)
{
#define UBT_RTL_HCICMD_TIMEOUT 2000
struct ubt_hci_event_command_compl *evt;
struct ubt_hci_cmd cmd;
usb_error_t error;
memset(&cmd, 0, sizeof(cmd));
cmd.opcode = htole16(opcode);
evt = malloc(offsetof(struct ubt_hci_event_command_compl, data) +
resp_len, M_TEMP, M_ZERO | M_WAITOK);
evt->header.event = NG_HCI_EVENT_COMMAND_COMPL;
evt->header.length = resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE;
error = ubt_do_hci_request(udev, &cmd, evt, UBT_RTL_HCICMD_TIMEOUT);
if (error != USB_ERR_NORMAL_COMPLETION)
goto exit;
if (evt->header.event == NG_HCI_EVENT_COMMAND_COMPL &&
evt->header.length == resp_len + UBT_HCI_EVENT_COMPL_HEAD_SIZE)
memcpy(resp, evt->data, resp_len);
else
error = USB_ERR_INVAL;
exit:
free(evt, M_TEMP);
return (error);
}
static int
ubt_rtl_probe(device_t dev)
{
struct usb_attach_arg *uaa = device_get_ivars(dev);
ng_hci_read_local_ver_rp ver;
unsigned int i;
int error;
if (uaa->usb_mode != USB_MODE_HOST)
return (ENXIO);
if (uaa->info.bIfaceIndex != 0)
return (ENXIO);
error = usbd_lookup_id_by_uaa(ubt_rtl_devs, sizeof(ubt_rtl_devs), uaa);
if (error != 0)
return (error);
if (ubt_rtl_do_hci_request(uaa->device,
NG_HCI_OPCODE(NG_HCI_OGF_INFO, NG_HCI_OCF_READ_LOCAL_VER),
&ver, sizeof(ver)) != USB_ERR_NORMAL_COMPLETION)
return (ENXIO);
DPRINTFN(2, "hci_version 0x%02x\n", ver.hci_version);
DPRINTFN(2, "hci_revision 0x%04x\n", le16toh(ver.hci_revision));
DPRINTFN(2, "lmp_version 0x%02x\n", ver.lmp_version);
DPRINTFN(2, "lmp_subversion 0x%04x\n", le16toh(ver.lmp_subversion));
for (i = 0; i < nitems(ubt_rtl_lmp_subvers); i++)
if (le16toh(ver.lmp_subversion) == ubt_rtl_lmp_subvers[i])
return (ENXIO);
return (BUS_PROBE_DEFAULT);
}
static device_method_t ubt_rtl_methods[] =
{
DEVMETHOD(device_probe, ubt_rtl_probe),
DEVMETHOD_END
};
DEFINE_CLASS_1(ubt, ubt_rtl_driver, ubt_rtl_methods,
sizeof(struct ubt_softc), ubt_driver);
DRIVER_MODULE(ng_ubt_rtl, uhub, ubt_rtl_driver, 0, 0);
MODULE_VERSION(ng_ubt_rtl, NG_BLUETOOTH_VERSION);
MODULE_DEPEND(ng_ubt_rtl, netgraph, NG_ABI_VERSION, NG_ABI_VERSION, NG_ABI_VERSION);
MODULE_DEPEND(ng_ubt_rtl, ng_hci, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION, NG_BLUETOOTH_VERSION);
MODULE_DEPEND(ng_ubt_rtl, usb, 1, 1, 1);