55 #include <linux/module.h>
56 #include <linux/slab.h>
66 #define WUSB_QUIRK_WHCI_CMD_EVT 0x01
117 int hwarc_filter_evt_beacon_WUSB_0100(
struct uwb_rc *
rc,
124 size_t bytes_left, ielength;
129 if (bytes_left <
sizeof(*be)) {
130 dev_err(dev,
"Beacon Received Notification: Not enough data "
131 "to decode for filtering (%zu vs %zu bytes needed)\n",
132 bytes_left,
sizeof(*be));
135 bytes_left -=
sizeof(*be);
137 if (bytes_left < ielength) {
138 dev_err(dev,
"Beacon Received Notification: Not enough data "
139 "to decode IEs (%zu vs %zu bytes needed)\n",
140 bytes_left, ielength);
143 newbe = kzalloc(
sizeof(*newbe) + ielength,
GFP_ATOMIC);
154 *header = &newbe->
rceb;
155 *new_size =
sizeof(*newbe) + ielength;
175 int hwarc_filter_evt_drp_avail_WUSB_0100(
struct uwb_rc *
rc,
183 size_t bytes_left, ielength;
189 if (bytes_left <
sizeof(*da)) {
190 dev_err(dev,
"Not enough data to decode DRP Avail "
191 "Notification for filtering. Expected %zu, "
192 "received %zu.\n", (
size_t)
sizeof(*da), bytes_left);
195 bytes_left -=
sizeof(*da);
197 if (bytes_left < ielength) {
198 dev_err(dev,
"DRP Avail Notification filter: IE length "
199 "[%zu bytes] does not match actual length "
200 "[%zu bytes].\n", ielength, bytes_left);
203 if (ielength <
sizeof(*ie_hdr)) {
204 dev_err(dev,
"DRP Avail Notification filter: Not enough "
205 "data to decode IE [%zu bytes, %zu needed]\n",
206 ielength,
sizeof(*ie_hdr));
209 ie_hdr = (
void *) da->
IEData;
211 dev_err(dev,
"DRP Availability Change event has unexpected "
212 "length for filtering. Expected < 32 bytes, "
213 "got %zu bytes.\n", (
size_t)ie_hdr->
length);
220 memcpy(newda->bmp, (
u8 *) ie_hdr +
sizeof(*ie_hdr), ie_hdr->
length);
221 *header = &newda->
rceb;
222 *new_size =
sizeof(*newda);
250 int hwarc_filter_evt_drp_WUSB_0100(
struct uwb_rc *rc,
252 const size_t buf_size,
257 size_t bytes_left, ielength;
262 if (bytes_left <
sizeof(*drpev)) {
263 dev_err(dev,
"Not enough data to decode DRP Notification "
264 "for filtering. Expected %zu, received %zu.\n",
265 (
size_t)
sizeof(*drpev), bytes_left);
269 bytes_left -=
sizeof(*drpev);
270 if (bytes_left < ielength) {
271 dev_err(dev,
"DRP Notification filter: header length [%zu "
272 "bytes] does not match actual length [%zu "
273 "bytes].\n", ielength, bytes_left);
276 newdrpev = kzalloc(
sizeof(*newdrpev) + ielength,
GFP_ATOMIC);
277 if (newdrpev ==
NULL)
285 *header = &newdrpev->
rceb;
286 *new_size =
sizeof(*newdrpev) + ielength;
309 int hwarc_filter_cmd_scan_WUSB_0100(
struct uwb_rc *rc,
347 int hwarc_filter_cmd_set_drp_ie_WUSB_0100(
struct uwb_rc *rc,
357 cmd = kzalloc(
sizeof(*cmd) + ielength,
GFP_KERNEL);
364 *header = &cmd->
rccb;
365 *size =
sizeof(*cmd) + ielength;
392 int hwarc_filter_cmd_WUSB_0100(
struct uwb_rc *rc,
struct uwb_rccb **header,
400 result = hwarc_filter_cmd_scan_WUSB_0100(rc, header, size);
403 result = hwarc_filter_cmd_set_drp_ie_WUSB_0100(rc, header, size);
429 result = hwarc_filter_cmd_WUSB_0100(rc, header, size);
446 size_t core_size,
size_t offset,
447 const size_t buf_size)
451 size_t type_size =
sizeof(
__le16);
454 if (offset + type_size >= buf_size) {
455 dev_err(dev,
"Not enough data to read extra size of event "
456 "0x%02x/%04x/%02x, only got %zu bytes.\n",
498 int hwarc_filter_event_WUSB_0100(
struct uwb_rc *rc,
struct uwb_rceb **header,
499 const size_t buf_size,
size_t *_real_size,
515 event_size = hwarc_get_event_size(rc, rceb, core_size,
519 *_real_size = event_size;
520 result = hwarc_filter_evt_beacon_WUSB_0100(rc, header,
521 buf_size, _new_size);
524 *_new_size = *_real_size =
533 event_size = hwarc_get_event_size(rc, rceb, core_size,
537 *_real_size = event_size;
538 result = hwarc_filter_evt_drp_avail_WUSB_0100(
539 rc, header, buf_size, _new_size);
545 event_size = hwarc_get_event_size(rc, rceb, core_size,
549 *_real_size = event_size;
550 result = hwarc_filter_evt_drp_WUSB_0100(rc, header,
551 buf_size, _new_size);
578 int hwarc_filter_event(
struct uwb_rc *rc,
struct uwb_rceb **header,
579 const size_t buf_size,
size_t *_real_size,
584 result = hwarc_filter_event_WUSB_0100(
585 rc, header, buf_size, _real_size, _new_size);
606 0, hwarc->
usb_iface->cur_altsetting->desc.bInterfaceNumber,
607 (
void *) cmd, cmd_size, 100 );
611 int hwarc_reset(
struct uwb_rc *uwb_rc)
613 struct hwarc *hwarc = uwb_rc->
priv;
624 void hwarc_neep_cb(
struct urb *
urb)
626 struct hwarc *hwarc = urb->context;
628 struct device *dev = &usb_iface->dev;
631 switch (result = urb->status) {
645 dev_err(dev,
"NEEP: URB error %d\n", urb->status);
648 if (result < 0 && result != -
ENODEV && result != -
EPERM) {
650 dev_err(dev,
"NEEP: Can't resubmit URB (%d) resetting device\n",
658 dev_err(dev,
"NEEP: URB max acceptable errors "
659 "exceeded, resetting device\n");
666 static void hwarc_init(
struct hwarc *hwarc)
679 static int hwarc_neep_init(
struct uwb_rc *rc)
681 struct hwarc *hwarc = rc->
priv;
683 struct usb_device *usb_dev = interface_to_usbdev(iface);
684 struct device *dev = &iface->dev;
688 epd = &iface->cur_altsetting->endpoint[0].desc;
691 dev_err(dev,
"Unable to allocate notification's read buffer\n");
692 goto error_rd_buffer;
696 dev_err(dev,
"Unable to allocate notification URB\n");
697 goto error_urb_alloc;
699 usb_fill_int_urb(hwarc->
neep_urb, usb_dev,
705 dev_err(dev,
"Cannot submit notification URB: %d\n", result);
706 goto error_neep_submit;
720 static void hwarc_neep_release(
struct uwb_rc *rc)
722 struct hwarc *hwarc = rc->
priv;
738 static int hwarc_get_version(
struct uwb_rc *rc)
742 struct hwarc *hwarc = rc->
priv;
745 struct usb_device *usb_dev = hwarc->
usb_dev;
748 size_t itr_size, actconfig_idx;
751 actconfig_idx = (usb_dev->actconfig - usb_dev->config) /
752 sizeof(usb_dev->config[0]);
753 itr = usb_dev->rawdescriptors[actconfig_idx];
754 itr_size =
le16_to_cpu(usb_dev->actconfig->desc.wTotalLength);
755 while (itr_size >=
sizeof(*hdr)) {
757 dev_dbg(dev,
"Extra device descriptor: "
758 "type %02x/%u bytes @ %zu (%zu left)\n",
760 (itr - usb_dev->rawdescriptors[actconfig_idx]),
767 dev_err(dev,
"cannot find Radio Control Interface Class descriptor\n");
773 dev_err(dev,
"incomplete Radio Control Interface Class "
774 "descriptor (%zu bytes left, %u needed)\n",
778 if (hdr->
bLength <
sizeof(*descr)) {
779 dev_err(dev,
"short Radio Control Interface Class "
786 if (version != 0x0100) {
787 dev_err(dev,
"Device reports protocol version 0x%04x. We "
788 "do not support that. \n", version);
793 dev_dbg(dev,
"Device supports WUSB protocol version 0x%04x \n", rc->
version);
810 struct uwb_rc *uwb_rc;
812 struct device *dev = &iface->dev;
816 if (uwb_rc ==
NULL) {
817 dev_err(dev,
"unable to allocate RC instance\n");
822 dev_err(dev,
"unable to allocate HWA RC instance\n");
831 uwb_rc->
start = hwarc_neep_init;
832 uwb_rc->
stop = hwarc_neep_release;
833 uwb_rc->
cmd = hwarc_cmd;
834 uwb_rc->
reset = hwarc_reset;
846 result = hwarc_get_version(uwb_rc);
848 dev_err(dev,
"cannot retrieve version of RC \n");
849 goto error_get_version;
851 usb_set_intfdata(iface, hwarc);
867 struct hwarc *hwarc = usb_get_intfdata(iface);
868 struct uwb_rc *uwb_rc = hwarc->
uwb_rc;
880 struct hwarc *hwarc = usb_get_intfdata(iface);
881 struct uwb_rc *uwb_rc = hwarc->
uwb_rc;
889 struct hwarc *hwarc = usb_get_intfdata(iface);
890 struct uwb_rc *uwb_rc = hwarc->
uwb_rc;
898 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3d02, 0xe0, 0x01, 0x02),
901 { USB_DEVICE_AND_INTERFACE_INFO(0x8086, 0x0c3b, 0xe0, 0x01, 0x02),
904 { USB_INTERFACE_INFO(0xe0, 0x01, 0x02), },
909 static struct usb_driver hwarc_driver = {
911 .id_table = hwarc_id_table,
912 .probe = hwarc_probe,
913 .disconnect = hwarc_disconnect,
914 .pre_reset = hwarc_pre_reset,
915 .post_reset = hwarc_post_reset,