89 #include <linux/module.h>
90 #include <linux/ctype.h>
94 #include <linux/random.h>
95 #include <linux/slab.h>
101 #define CBA_NAME_LEN 0x40
132 static int cbaf_check(
struct cbaf *
cbaf)
140 int ar_rhi = 0, ar_assoc = 0;
146 0, cbaf->
usb_iface->cur_altsetting->desc.bInterfaceNumber,
149 dev_err(dev,
"Cannot get available association types: %d\n",
154 assoc_info = cbaf->
buffer;
155 if (result <
sizeof(*assoc_info)) {
156 dev_err(dev,
"Not enough data to decode association info "
157 "header (%zu vs %zu bytes required)\n",
158 (
size_t)result,
sizeof(*assoc_info));
163 if (result < assoc_size) {
164 dev_err(dev,
"Not enough data to decode association info "
165 "(%zu vs %zu bytes required)\n",
166 (
size_t)assoc_size,
sizeof(*assoc_info));
174 itr = cbaf->
buffer +
sizeof(*assoc_info);
175 top = cbaf->
buffer + assoc_size;
176 dev_dbg(dev,
"Found %u association requests (%zu bytes)\n",
180 u16 ar_type, ar_subtype;
186 if (top - itr <
sizeof(*assoc_request)) {
187 dev_err(dev,
"Not enough data to decode associaton "
188 "request (%zu vs %zu bytes needed)\n",
189 top - itr,
sizeof(*assoc_request));
201 switch (ar_subtype) {
203 ar_name =
"RETRIEVE_HOST_INFO";
208 ar_name =
"ASSOCIATE";
215 dev_dbg(dev,
"Association request #%02u: 0x%04x/%04x "
218 ar_subtype, (
size_t)ar_size, ar_name);
220 itr +=
sizeof(*assoc_request);
224 dev_err(dev,
"Missing RETRIEVE_HOST_INFO association "
229 dev_err(dev,
"Missing ASSOCIATE association request\n");
247 static int cbaf_send_host_info(
struct cbaf *cbaf)
254 memset(hi, 0,
sizeof(*hi));
255 *hi = cbaf_host_info_defaults;
267 cbaf->
usb_iface->cur_altsetting->desc.bInterfaceNumber,
278 static int cbaf_cdid_get(
struct cbaf *cbaf)
290 0x0200, cbaf->
usb_iface->cur_altsetting->desc.bInterfaceNumber,
293 dev_err(dev,
"Cannot request device information: %d\n", result);
298 if (result < needed) {
299 dev_err(dev,
"Not enough data in DEVICE_INFO reply (%zu vs "
300 "%zu bytes needed)\n", (
size_t)result, needed);
316 struct cbaf *cbaf = usb_get_intfdata(iface);
319 ckhdid_printf(pr_chid,
sizeof(pr_chid), &cbaf->
chid);
325 const char *buf,
size_t size)
329 struct cbaf *cbaf = usb_get_intfdata(iface);
332 "%02hhx %02hhx %02hhx %02hhx "
333 "%02hhx %02hhx %02hhx %02hhx "
334 "%02hhx %02hhx %02hhx %02hhx "
335 "%02hhx %02hhx %02hhx %02hhx",
336 &cbaf->
chid.data[0] , &cbaf->
chid.data[1],
337 &cbaf->
chid.data[2] , &cbaf->
chid.data[3],
338 &cbaf->
chid.data[4] , &cbaf->
chid.data[5],
339 &cbaf->
chid.data[6] , &cbaf->
chid.data[7],
340 &cbaf->
chid.data[8] , &cbaf->
chid.data[9],
341 &cbaf->
chid.data[10], &cbaf->
chid.data[11],
342 &cbaf->
chid.data[12], &cbaf->
chid.data[13],
343 &cbaf->
chid.data[14], &cbaf->
chid.data[15]);
348 result = cbaf_send_host_info(cbaf);
351 result = cbaf_cdid_get(cbaf);
356 static DEVICE_ATTR(wusb_chid, 0600, cbaf_wusb_chid_show, cbaf_wusb_chid_store);
363 struct cbaf *cbaf = usb_get_intfdata(iface);
370 const char *buf,
size_t size)
374 struct cbaf *cbaf = usb_get_intfdata(iface);
382 static DEVICE_ATTR(wusb_host_name, 0600, cbaf_wusb_host_name_show,
383 cbaf_wusb_host_name_store);
385 static ssize_t cbaf_wusb_host_band_groups_show(
struct device *dev,
390 struct cbaf *cbaf = usb_get_intfdata(iface);
395 static ssize_t cbaf_wusb_host_band_groups_store(
struct device *dev,
397 const char *buf,
size_t size)
401 struct cbaf *cbaf = usb_get_intfdata(iface);
404 result =
sscanf(buf,
"%04hx", &band_groups);
414 cbaf_wusb_host_band_groups_show,
415 cbaf_wusb_host_band_groups_store);
429 struct cbaf *cbaf = usb_get_intfdata(iface);
432 ckhdid_printf(pr_cdid,
sizeof(pr_cdid), &cbaf->
cdid);
438 const char *buf,
size_t size)
442 struct cbaf *cbaf = usb_get_intfdata(iface);
446 "%02hhx %02hhx %02hhx %02hhx "
447 "%02hhx %02hhx %02hhx %02hhx "
448 "%02hhx %02hhx %02hhx %02hhx "
449 "%02hhx %02hhx %02hhx %02hhx",
450 &cdid.data[0] , &cdid.data[1],
451 &cdid.data[2] , &cdid.data[3],
452 &cdid.data[4] , &cdid.data[5],
453 &cdid.data[6] , &cdid.data[7],
454 &cdid.data[8] , &cdid.data[9],
455 &cdid.data[10], &cdid.data[11],
456 &cdid.data[12], &cdid.data[13],
457 &cdid.data[14], &cdid.data[15]);
465 static DEVICE_ATTR(wusb_cdid, 0600, cbaf_wusb_cdid_show, cbaf_wusb_cdid_store);
467 static ssize_t cbaf_wusb_device_band_groups_show(
struct device *dev,
472 struct cbaf *cbaf = usb_get_intfdata(iface);
478 cbaf_wusb_device_band_groups_show,
481 static ssize_t cbaf_wusb_device_name_show(
struct device *dev,
486 struct cbaf *cbaf = usb_get_intfdata(iface);
490 static DEVICE_ATTR(wusb_device_name, 0600, cbaf_wusb_device_name_show,
NULL);
513 static int cbaf_cc_upload(
struct cbaf *cbaf)
521 *ccd = cbaf_cc_data_defaults;
527 dev_dbg(dev,
"Trying to upload CC:\n");
528 ckhdid_printf(pr_cdid,
sizeof(pr_cdid), &ccd->
CHID);
529 dev_dbg(dev,
" CHID %s\n", pr_cdid);
530 ckhdid_printf(pr_cdid,
sizeof(pr_cdid), &ccd->
CDID);
531 dev_dbg(dev,
" CDID %s\n", pr_cdid);
538 0x0201, cbaf->
usb_iface->cur_altsetting->desc.bInterfaceNumber,
539 ccd,
sizeof(*ccd), 1000 );
546 const char *buf,
size_t size)
550 struct cbaf *cbaf = usb_get_intfdata(iface);
553 "%02hhx %02hhx %02hhx %02hhx "
554 "%02hhx %02hhx %02hhx %02hhx "
555 "%02hhx %02hhx %02hhx %02hhx "
556 "%02hhx %02hhx %02hhx %02hhx",
557 &cbaf->
ck.data[0] , &cbaf->
ck.data[1],
558 &cbaf->
ck.data[2] , &cbaf->
ck.data[3],
559 &cbaf->
ck.data[4] , &cbaf->
ck.data[5],
560 &cbaf->
ck.data[6] , &cbaf->
ck.data[7],
561 &cbaf->
ck.data[8] , &cbaf->
ck.data[9],
562 &cbaf->
ck.data[10], &cbaf->
ck.data[11],
563 &cbaf->
ck.data[12], &cbaf->
ck.data[13],
564 &cbaf->
ck.data[14], &cbaf->
ck.data[15]);
568 result = cbaf_cc_upload(cbaf);
576 static struct attribute *cbaf_dev_attrs[] = {
577 &dev_attr_wusb_host_name.attr,
578 &dev_attr_wusb_host_band_groups.attr,
579 &dev_attr_wusb_chid.attr,
580 &dev_attr_wusb_cdid.attr,
581 &dev_attr_wusb_device_name.attr,
582 &dev_attr_wusb_device_band_groups.attr,
583 &dev_attr_wusb_ck.attr,
589 .attrs = cbaf_dev_attrs,
596 struct device *dev = &iface->dev;
604 goto error_kmalloc_buffer;
609 result = cbaf_check(cbaf);
611 dev_err(dev,
"This device is not WUSB-CBAF compliant"
612 "and is not supported yet.\n");
618 dev_err(dev,
"Can't register sysfs attr group: %d\n", result);
619 goto error_create_group;
621 usb_set_intfdata(iface, cbaf);
627 error_kmalloc_buffer:
635 struct cbaf *cbaf = usb_get_intfdata(iface);
636 struct device *dev = &iface->dev;
638 usb_set_intfdata(iface,
NULL);
646 { USB_INTERFACE_INFO(0xef, 0x03, 0x01), },
651 static struct usb_driver cbaf_driver = {
653 .id_table = cbaf_id_table,
655 .disconnect = cbaf_disconnect,