3 * Copyright (c) 2016, Oracle and/or its affiliates.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <sys/types.h>
35 #include <libdevinfo.h>
36 #include <sys/nvpair.h>
37 #include <sys/devctl.h>
38 #include <sys/usb/clients/ugen/usb_ugen.h>
40 #include <sys/usb/usba.h>
44 #include "sunos_usb.h"
46 #define UPDATEDRV_PATH "/usr/sbin/update_drv"
47 #define UPDATEDRV "update_drv"
49 typedef list_t string_list_t;
50 typedef struct string_node {
58 static int sunos_init(struct libusb_context *);
59 static void sunos_exit(struct libusb_context *);
60 static int sunos_get_device_list(struct libusb_context *,
61 struct discovered_devs **);
62 static int sunos_open(struct libusb_device_handle *);
63 static void sunos_close(struct libusb_device_handle *);
64 static int sunos_get_device_descriptor(struct libusb_device *,
66 static int sunos_get_active_config_descriptor(struct libusb_device *,
67 uint8_t*, size_t, int *);
68 static int sunos_get_config_descriptor(struct libusb_device *, uint8_t,
69 uint8_t*, size_t, int *);
70 static int sunos_get_configuration(struct libusb_device_handle *, int *);
71 static int sunos_set_configuration(struct libusb_device_handle *, int);
72 static int sunos_claim_interface(struct libusb_device_handle *, int);
73 static int sunos_release_interface(struct libusb_device_handle *, int);
74 static int sunos_set_interface_altsetting(struct libusb_device_handle *,
76 static int sunos_clear_halt(struct libusb_device_handle *, uint8_t);
77 static int sunos_reset_device(struct libusb_device_handle *);
78 static void sunos_destroy_device(struct libusb_device *);
79 static int sunos_submit_transfer(struct usbi_transfer *);
80 static int sunos_cancel_transfer(struct usbi_transfer *);
81 static void sunos_clear_transfer_priv(struct usbi_transfer *);
82 static int sunos_handle_transfer_completion(struct usbi_transfer *);
83 static int sunos_clock_gettime(int, struct timespec *);
84 static int sunos_kernel_driver_active(struct libusb_device_handle *, int interface);
85 static int sunos_detach_kernel_driver (struct libusb_device_handle *dev, int interface_number);
86 static int sunos_attach_kernel_driver (struct libusb_device_handle *dev, int interface_number);
87 static int sunos_usb_open_ep0(sunos_dev_handle_priv_t *hpriv, sunos_dev_priv_t *dpriv);
88 static int sunos_usb_ioctl(struct libusb_device *dev, int cmd);
90 static struct devctl_iocdata iocdata;
91 static int sunos_get_link(di_devlink_t devlink, void *arg)
93 walk_link_t *larg = (walk_link_t *)arg;
98 char *content = (char *)di_devlink_content(devlink);
99 char *start = strstr(content, "/devices/");
100 start += strlen("/devices");
101 usbi_dbg("%s", start);
103 /* line content must have minor node */
105 strncmp(start, larg->path, larg->len) != 0 ||
106 start[larg->len] != ':')
107 return (DI_WALK_CONTINUE);
110 p = di_devlink_path(devlink);
114 *(larg->linkpp) = strndup(p, strlen(p) - strlen(q));
116 return (DI_WALK_TERMINATE);
120 static int sunos_physpath_to_devlink(
121 const char *node_path, const char *match, char **link_path)
124 di_devlink_handle_t hdl;
127 larg.linkpp = link_path;
128 if ((hdl = di_devlink_init(NULL, 0)) == NULL) {
129 usbi_dbg("di_devlink_init failure");
133 larg.len = strlen(node_path);
134 larg.path = (char *)node_path;
136 (void) di_devlink_walk(hdl, match, NULL, DI_PRIMARY_LINK,
137 (void *)&larg, sunos_get_link);
139 (void) di_devlink_fini(&hdl);
141 if (*link_path == NULL) {
142 usbi_dbg("there is no devlink for this path");
150 sunos_usb_ioctl(struct libusb_device *dev, int cmd)
157 char path_arg[PATH_MAX];
158 sunos_dev_priv_t *dpriv;
159 devctl_ap_state_t devctl_ap_state;
161 dpriv = (sunos_dev_priv_t *)dev->os_priv;
162 phypath = dpriv->phypath;
164 end = strrchr(phypath, '/');
167 hubpath = strndup(phypath, end - phypath);
171 end = strrchr(hubpath, '@');
177 usbi_dbg("unitaddr: %s", end);
179 nvlist_alloc(&nvlist, NV_UNIQUE_NAME_TYPE, KM_NOSLEEP);
180 nvlist_add_int32(nvlist, "port", dev->port_number);
182 snprintf(path_arg, sizeof(path_arg), "/devices%s:hubd", hubpath);
183 usbi_dbg("ioctl hub path: %s", path_arg);
185 fd = open(path_arg, O_RDONLY);
187 usbi_err(DEVICE_CTX(dev), "open failed: %d (%s)", errno, strerror(errno));
193 memset(&iocdata, 0, sizeof(iocdata));
194 memset(&devctl_ap_state, 0, sizeof(devctl_ap_state));
196 nvlist_pack(nvlist, (char **)&iocdata.nvl_user, &iocdata.nvl_usersz, NV_ENCODE_NATIVE, 0);
198 iocdata.cmd = DEVCTL_AP_GETSTATE;
200 iocdata.c_nodename = "hub";
201 iocdata.c_unitaddr = end;
202 iocdata.cpyout_buf = &devctl_ap_state;
203 usbi_dbg("%p, %d", iocdata.nvl_user, iocdata.nvl_usersz);
206 if (ioctl(fd, DEVCTL_AP_GETSTATE, &iocdata) == -1) {
207 usbi_err(DEVICE_CTX(dev), "ioctl failed: fd %d, cmd %x, errno %d (%s)",
208 fd, DEVCTL_AP_GETSTATE, errno, strerror(errno));
210 usbi_dbg("dev rstate: %d", devctl_ap_state.ap_rstate);
211 usbi_dbg("dev ostate: %d", devctl_ap_state.ap_ostate);
216 if (ioctl(fd, (int)cmd, &iocdata) != 0) {
217 usbi_err(DEVICE_CTX(dev), "ioctl failed: fd %d, cmd %x, errno %d (%s)",
218 fd, cmd, errno, strerror(errno));
223 free(iocdata.nvl_user);
231 sunos_kernel_driver_active(struct libusb_device_handle *dev, int interface)
233 sunos_dev_priv_t *dpriv;
234 dpriv = (sunos_dev_priv_t *)dev->dev->os_priv;
236 usbi_dbg("%s", dpriv->ugenpath);
238 return (dpriv->ugenpath == NULL);
244 static int _errno_to_libusb(int);
245 static int sunos_usb_get_status(int fd);
247 static int sunos_init(struct libusb_context *ctx)
249 return (LIBUSB_SUCCESS);
252 static void sunos_exit(struct libusb_context *ctx)
257 static string_list_t *
258 sunos_new_string_list(void)
262 list = calloc(1, sizeof(*list));
264 list_create(list, sizeof(string_node_t),
265 offsetof(string_node_t, link));
271 sunos_append_to_string_list(string_list_t *list, const char *arg)
275 np = calloc(1, sizeof(*np));
279 np->string = strdup(arg);
285 list_insert_tail(list, np);
291 sunos_free_string_list(string_list_t *list)
295 while ((np = list_remove_head(list)) != NULL) {
304 sunos_build_argv_list(string_list_t *list)
310 n = 1; /* Start at 1 for NULL terminator */
311 for (np = list_head(list); np != NULL; np = list_next(list, np))
314 argv_list = calloc(n, sizeof(char *));
315 if (argv_list == NULL)
319 for (np = list_head(list); np != NULL; np = list_next(list, np))
320 argv_list[n++] = np->string;
327 sunos_exec_command(struct libusb_context *ctx, const char *path,
336 argv_list = sunos_build_argv_list(list);
337 if (argv_list == NULL)
343 execv(path, argv_list);
345 } else if (pid > 0) {
348 waitstat = waitpid(pid, &status, 0);
349 } while ((waitstat == -1 && errno == EINTR) ||
350 (waitstat == 0 && !WIFEXITED(status) && !WIFSIGNALED(status)));
353 if (WIFEXITED(status))
354 exit_status = WEXITSTATUS(status);
356 exit_status = WTERMSIG(status);
358 usbi_err(ctx, "waitpid failed: errno %d (%s)", errno, strerror(errno));
363 usbi_err(ctx, "fork failed: errno %d (%s)", errno, strerror(errno));
369 return (exit_status);
373 sunos_detach_kernel_driver(struct libusb_device_handle *dev_handle,
374 int interface_number)
376 struct libusb_context *ctx = HANDLE_CTX(dev_handle);
378 char path_arg[PATH_MAX];
379 sunos_dev_priv_t *dpriv;
382 dpriv = (sunos_dev_priv_t *)dev_handle->dev->os_priv;
383 snprintf(path_arg, sizeof(path_arg), "\'\"%s\"\'", dpriv->phypath);
384 usbi_dbg("%s", path_arg);
386 list = sunos_new_string_list();
388 return (LIBUSB_ERROR_NO_MEM);
390 /* attach ugen driver */
392 r |= sunos_append_to_string_list(list, UPDATEDRV);
393 r |= sunos_append_to_string_list(list, "-a"); /* add rule */
394 r |= sunos_append_to_string_list(list, "-i"); /* specific device */
395 r |= sunos_append_to_string_list(list, path_arg); /* physical path */
396 r |= sunos_append_to_string_list(list, "ugen");
398 sunos_free_string_list(list);
399 return (LIBUSB_ERROR_NO_MEM);
402 r = sunos_exec_command(ctx, UPDATEDRV_PATH, list);
403 sunos_free_string_list(list);
405 return (LIBUSB_ERROR_OTHER);
407 /* reconfigure the driver node */
409 r |= sunos_usb_ioctl(dev_handle->dev, DEVCTL_AP_DISCONNECT);
410 r |= sunos_usb_ioctl(dev_handle->dev, DEVCTL_AP_CONFIGURE);
412 usbi_warn(HANDLE_CTX(dev_handle), "one or more ioctls failed");
414 snprintf(path_arg, sizeof(path_arg), "^usb/%x.%x", dpriv->dev_descr.idVendor,
415 dpriv->dev_descr.idProduct);
416 sunos_physpath_to_devlink(dpriv->phypath, path_arg, &dpriv->ugenpath);
418 if (access(dpriv->ugenpath, F_OK) == -1) {
419 usbi_err(HANDLE_CTX(dev_handle), "fail to detach kernel driver");
420 return (LIBUSB_ERROR_IO);
423 return sunos_usb_open_ep0((sunos_dev_handle_priv_t *)dev_handle->os_priv, dpriv);
427 sunos_attach_kernel_driver(struct libusb_device_handle *dev_handle,
428 int interface_number)
430 struct libusb_context *ctx = HANDLE_CTX(dev_handle);
432 char path_arg[PATH_MAX];
433 sunos_dev_priv_t *dpriv;
436 /* we open the dev in detach driver, so we need close it first. */
437 sunos_close(dev_handle);
439 dpriv = (sunos_dev_priv_t *)dev_handle->dev->os_priv;
440 snprintf(path_arg, sizeof(path_arg), "\'\"%s\"\'", dpriv->phypath);
441 usbi_dbg("%s", path_arg);
443 list = sunos_new_string_list();
445 return (LIBUSB_ERROR_NO_MEM);
447 /* detach ugen driver */
449 r |= sunos_append_to_string_list(list, UPDATEDRV);
450 r |= sunos_append_to_string_list(list, "-d"); /* add rule */
451 r |= sunos_append_to_string_list(list, "-i"); /* specific device */
452 r |= sunos_append_to_string_list(list, path_arg); /* physical path */
453 r |= sunos_append_to_string_list(list, "ugen");
455 sunos_free_string_list(list);
456 return (LIBUSB_ERROR_NO_MEM);
459 r = sunos_exec_command(ctx, UPDATEDRV_PATH, list);
460 sunos_free_string_list(list);
462 return (LIBUSB_ERROR_OTHER);
464 /* reconfigure the driver node */
466 r |= sunos_usb_ioctl(dev_handle->dev, DEVCTL_AP_CONFIGURE);
467 r |= sunos_usb_ioctl(dev_handle->dev, DEVCTL_AP_DISCONNECT);
468 r |= sunos_usb_ioctl(dev_handle->dev, DEVCTL_AP_CONFIGURE);
470 usbi_warn(HANDLE_CTX(dev_handle), "one or more ioctls failed");
476 sunos_fill_in_dev_info(di_node_t node, struct libusb_device *dev)
479 int n, *addr, *port_prop;
482 struct libusb_device_descriptor *descr;
483 sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
484 char match_str[PATH_MAX];
486 /* Device descriptors */
487 proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
488 "usb-dev-descriptor", &rdata);
491 return (LIBUSB_ERROR_IO);
494 descr = (struct libusb_device_descriptor *)rdata;
495 bcopy(descr, &dpriv->dev_descr, LIBUSB_DT_DEVICE_SIZE);
496 dpriv->dev_descr.bcdUSB = libusb_cpu_to_le16(descr->bcdUSB);
497 dpriv->dev_descr.idVendor = libusb_cpu_to_le16(descr->idVendor);
498 dpriv->dev_descr.idProduct = libusb_cpu_to_le16(descr->idProduct);
499 dpriv->dev_descr.bcdDevice = libusb_cpu_to_le16(descr->bcdDevice);
501 /* Raw configuration descriptors */
502 proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
503 "usb-raw-cfg-descriptors", &rdata);
505 usbi_dbg("can't find raw config descriptors");
507 return (LIBUSB_ERROR_IO);
509 dpriv->raw_cfgdescr = calloc(1, proplen);
510 if (dpriv->raw_cfgdescr == NULL) {
511 return (LIBUSB_ERROR_NO_MEM);
513 bcopy(rdata, dpriv->raw_cfgdescr, proplen);
514 dpriv->cfgvalue = ((struct libusb_config_descriptor *)
515 rdata)->bConfigurationValue;
518 n = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "reg", &port_prop);
520 if ((n != 1) || (*port_prop <= 0)) {
521 return (LIBUSB_ERROR_IO);
523 dev->port_number = *port_prop;
525 /* device physical path */
526 phypath = di_devfs_path(node);
528 dpriv->phypath = strdup(phypath);
529 snprintf(match_str, sizeof(match_str), "^usb/%x.%x", dpriv->dev_descr.idVendor, dpriv->dev_descr.idProduct);
530 usbi_dbg("match is %s", match_str);
531 sunos_physpath_to_devlink(dpriv->phypath, match_str, &dpriv->ugenpath);
532 di_devfs_path_free(phypath);
535 free(dpriv->raw_cfgdescr);
537 return (LIBUSB_ERROR_IO);
541 n = di_prop_lookup_ints(DDI_DEV_T_ANY, node, "assigned-address", &addr);
542 if (n != 1 || *addr == 0) {
543 usbi_dbg("can't get address");
545 dev->device_address = *addr;
549 if (di_prop_exists(DDI_DEV_T_ANY, node, "low-speed") == 1) {
550 dev->speed = LIBUSB_SPEED_LOW;
551 } else if (di_prop_exists(DDI_DEV_T_ANY, node, "high-speed") == 1) {
552 dev->speed = LIBUSB_SPEED_HIGH;
553 } else if (di_prop_exists(DDI_DEV_T_ANY, node, "full-speed") == 1) {
554 dev->speed = LIBUSB_SPEED_FULL;
555 } else if (di_prop_exists(DDI_DEV_T_ANY, node, "super-speed") == 1) {
556 dev->speed = LIBUSB_SPEED_SUPER;
559 usbi_dbg("vid=%x pid=%x, path=%s, bus_nmber=0x%x, port_number=%d, "
560 "speed=%d", dpriv->dev_descr.idVendor, dpriv->dev_descr.idProduct,
561 dpriv->phypath, dev->bus_number, dev->port_number, dev->speed);
563 return (LIBUSB_SUCCESS);
567 sunos_add_devices(di_devlink_t link, void *arg)
569 struct devlink_cbarg *largs = (struct devlink_cbarg *)arg;
570 struct node_args *nargs;
571 di_node_t myself, dn;
572 uint64_t session_id = 0;
575 struct libusb_device *dev;
576 sunos_dev_priv_t *devpriv;
580 uint8_t bus_number = 0;
581 uint32_t * regbuf = NULL;
584 nargs = (struct node_args *)largs->nargs;
585 myself = largs->myself;
588 * Construct session ID.
589 * session ID = dev_addr | hub addr |parent hub addr|...|root hub bdf
590 * 8 bits 8bits 8 bits 16bits
592 if (myself == DI_NODE_NIL)
593 return (DI_WALK_CONTINUE);
596 /* find the root hub */
597 while (di_prop_exists(DDI_DEV_T_ANY, dn, "root-hub") != 1) {
598 usbi_dbg("find_root_hub:%s", di_devfs_path(dn));
599 n = di_prop_lookup_ints(DDI_DEV_T_ANY, dn,
600 "assigned-address", &addr_prop);
601 session_id |= ((addr_prop[0] & 0xff) << i++ * 8);
602 dn = di_parent_node(dn);
605 /* dn is the root hub node */
606 n = di_prop_lookup_ints(DDI_DEV_T_ANY, dn, "reg", (int **)®buf);
608 bdf = (PCI_REG_BUS_G(reg) << 8) | (PCI_REG_DEV_G(reg) << 3) | PCI_REG_FUNC_G(reg);
609 /* bdf must larger than i*8 bits */
610 session_id |= (bdf << i * 8);
611 bus_number = (PCI_REG_DEV_G(reg) << 3) | PCI_REG_FUNC_G(reg);
613 usbi_dbg("device bus address=%s:%x, name:%s",
614 di_bus_addr(myself), bus_number, di_node_name(dn));
615 usbi_dbg("session id org:%lx", session_id);
617 /* dn is the usb device */
618 for (dn = di_child_node(myself); dn != DI_NODE_NIL; dn = di_sibling_node(dn)) {
619 usbi_dbg("device path:%s", di_devfs_path(dn));
620 /* skip hub devices, because its driver can not been unload */
621 if (di_prop_lookup_ints(DDI_DEV_T_ANY, dn, "usb-port-count", &addr_prop) != -1)
624 n = di_prop_lookup_ints(DDI_DEV_T_ANY, dn,
625 "assigned-address", &addr_prop);
626 if ((n != 1) || (addr_prop[0] == 0)) {
627 usbi_dbg("cannot get valid usb_addr");
631 sid = (session_id << 8) | (addr_prop[0] & 0xff) ;
632 usbi_dbg("session id %lx", sid);
634 dev = usbi_get_device_by_session_id(nargs->ctx, sid);
636 dev = usbi_alloc_device(nargs->ctx, sid);
638 usbi_dbg("can't alloc device");
641 devpriv = (sunos_dev_priv_t *)dev->os_priv;
642 dev->bus_number = bus_number;
644 if (sunos_fill_in_dev_info(dn, dev) != LIBUSB_SUCCESS) {
645 libusb_unref_device(dev);
646 usbi_dbg("get infomation fail");
649 if (usbi_sanitize_device(dev) < 0) {
650 libusb_unref_device(dev);
651 usbi_dbg("sanatize failed: ");
652 return (DI_WALK_TERMINATE);
655 devpriv = (sunos_dev_priv_t *)dev->os_priv;
656 usbi_dbg("Dev %s exists", devpriv->ugenpath);
659 if (discovered_devs_append(*(nargs->discdevs), dev) == NULL) {
660 usbi_dbg("cannot append device");
664 * we alloc and hence ref this dev. We don't need to ref it
665 * hereafter. Front end or app should take care of their ref.
667 libusb_unref_device(dev);
669 usbi_dbg("Device %s %s id=0x%llx, devcount:%d, bdf=%x",
670 devpriv->ugenpath, di_devfs_path(dn), (uint64_t)sid,
671 (*nargs->discdevs)->len, bdf);
674 return (DI_WALK_CONTINUE);
678 sunos_walk_minor_node_link(di_node_t node, void *args)
680 di_minor_t minor = DI_MINOR_NIL;
682 struct devlink_cbarg arg;
683 struct node_args *nargs = (struct node_args *)args;
684 di_devlink_handle_t devlink_hdl = nargs->dlink_hdl;
686 /* walk each minor to find usb devices */
687 while ((minor = di_minor_next(node, minor)) != DI_MINOR_NIL) {
688 minor_path = di_devfs_minor_path(minor);
692 (void) di_devlink_walk(devlink_hdl,
693 "^usb/hub[0-9]+", minor_path,
694 DI_PRIMARY_LINK, (void *)&arg, sunos_add_devices);
695 di_devfs_path_free(minor_path);
698 /* switch to a different node */
699 nargs->last_ugenpath = NULL;
701 return (DI_WALK_CONTINUE);
705 sunos_get_device_list(struct libusb_context * ctx,
706 struct discovered_devs **discdevs)
709 struct node_args args;
710 di_devlink_handle_t devlink_hdl;
713 args.discdevs = discdevs;
714 args.last_ugenpath = NULL;
715 if ((root_node = di_init("/", DINFOCPYALL)) == DI_NODE_NIL) {
716 usbi_dbg("di_int() failed: %s", strerror(errno));
717 return (LIBUSB_ERROR_IO);
720 if ((devlink_hdl = di_devlink_init(NULL, 0)) == NULL) {
722 usbi_dbg("di_devlink_init() failed: %s", strerror(errno));
724 return (LIBUSB_ERROR_IO);
726 args.dlink_hdl = devlink_hdl;
728 /* walk each node to find USB devices */
729 if (di_walk_node(root_node, DI_WALK_SIBFIRST, &args,
730 sunos_walk_minor_node_link) == -1) {
731 usbi_dbg("di_walk_node() failed: %s", strerror(errno));
734 return (LIBUSB_ERROR_IO);
738 di_devlink_fini(&devlink_hdl);
740 usbi_dbg("%d devices", (*discdevs)->len);
742 return ((*discdevs)->len);
746 sunos_usb_open_ep0(sunos_dev_handle_priv_t *hpriv, sunos_dev_priv_t *dpriv)
748 char filename[PATH_MAX + 1];
750 if (hpriv->eps[0].datafd > 0) {
752 return (LIBUSB_SUCCESS);
754 snprintf(filename, PATH_MAX, "%s/cntrl0", dpriv->ugenpath);
756 usbi_dbg("opening %s", filename);
757 hpriv->eps[0].datafd = open(filename, O_RDWR);
758 if (hpriv->eps[0].datafd < 0) {
759 return(_errno_to_libusb(errno));
762 snprintf(filename, PATH_MAX, "%s/cntrl0stat", dpriv->ugenpath);
763 hpriv->eps[0].statfd = open(filename, O_RDONLY);
764 if (hpriv->eps[0].statfd < 0) {
765 close(hpriv->eps[0].datafd);
766 hpriv->eps[0].datafd = -1;
768 return(_errno_to_libusb(errno));
771 return (LIBUSB_SUCCESS);
775 sunos_usb_close_all_eps(sunos_dev_handle_priv_t *hdev)
780 for (i = 1; i < USB_MAXENDPOINTS; i++) {
781 if (hdev->eps[i].datafd != -1) {
782 (void) close(hdev->eps[i].datafd);
783 hdev->eps[i].datafd = -1;
785 if (hdev->eps[i].statfd != -1) {
786 (void) close(hdev->eps[i].statfd);
787 hdev->eps[i].statfd = -1;
793 sunos_usb_close_ep0(sunos_dev_handle_priv_t *hdev, sunos_dev_priv_t *dpriv)
795 if (hdev->eps[0].datafd >= 0) {
796 close(hdev->eps[0].datafd);
797 close(hdev->eps[0].statfd);
798 hdev->eps[0].datafd = -1;
799 hdev->eps[0].statfd = -1;
804 sunos_usb_ep_index(uint8_t ep_addr)
806 return ((ep_addr & LIBUSB_ENDPOINT_ADDRESS_MASK) +
807 ((ep_addr & LIBUSB_ENDPOINT_DIR_MASK) ? 16 : 0));
811 sunos_find_interface(struct libusb_device_handle *hdev,
812 uint8_t endpoint, uint8_t *interface)
814 struct libusb_config_descriptor *config;
818 r = libusb_get_active_config_descriptor(hdev->dev, &config);
820 return (LIBUSB_ERROR_INVALID_PARAM);
823 for (iface_idx = 0; iface_idx < config->bNumInterfaces; iface_idx++) {
824 const struct libusb_interface *iface =
825 &config->interface[iface_idx];
828 for (altsetting_idx = 0; altsetting_idx < iface->num_altsetting;
830 const struct libusb_interface_descriptor *altsetting =
831 &iface->altsetting[altsetting_idx];
834 for (ep_idx = 0; ep_idx < altsetting->bNumEndpoints;
836 const struct libusb_endpoint_descriptor *ep =
837 &altsetting->endpoint[ep_idx];
838 if (ep->bEndpointAddress == endpoint) {
839 *interface = iface_idx;
840 libusb_free_config_descriptor(config);
842 return (LIBUSB_SUCCESS);
847 libusb_free_config_descriptor(config);
849 return (LIBUSB_ERROR_INVALID_PARAM);
853 sunos_check_device_and_status_open(struct libusb_device_handle *hdl,
854 uint8_t ep_addr, int ep_type)
856 char filename[PATH_MAX + 1], statfilename[PATH_MAX + 1];
857 char cfg_num[16], alt_num[16];
858 int fd, fdstat, mode;
861 sunos_dev_handle_priv_t *hpriv;
863 usbi_dbg("open ep 0x%02x", ep_addr);
864 hpriv = (sunos_dev_handle_priv_t *)hdl->os_priv;
865 ep_index = sunos_usb_ep_index(ep_addr);
866 /* ep already opened */
867 if ((hpriv->eps[ep_index].datafd > 0) &&
868 (hpriv->eps[ep_index].statfd > 0)) {
869 usbi_dbg("ep 0x%02x already opened, return success",
875 if (sunos_find_interface(hdl, ep_addr, &ifc) < 0) {
876 usbi_dbg("can't find interface for endpoint 0x%02x",
882 /* create filename */
883 if (hpriv->config_index > 0) {
884 (void) snprintf(cfg_num, sizeof (cfg_num), "cfg%d",
885 hpriv->config_index + 1);
887 bzero(cfg_num, sizeof (cfg_num));
890 if (hpriv->altsetting[ifc] > 0) {
891 (void) snprintf(alt_num, sizeof (alt_num), ".%d",
892 hpriv->altsetting[ifc]);
894 bzero(alt_num, sizeof (alt_num));
897 (void) snprintf(filename, PATH_MAX, "%s/%sif%d%s%s%d",
898 hpriv->dpriv->ugenpath, cfg_num, ifc, alt_num,
899 (ep_addr & LIBUSB_ENDPOINT_DIR_MASK) ? "in" :
900 "out", (ep_addr & LIBUSB_ENDPOINT_ADDRESS_MASK));
901 (void) snprintf(statfilename, PATH_MAX, "%sstat", filename);
904 * for interrupt IN endpoints, we need to enable one xfer
905 * mode before opening the endpoint
907 if ((ep_type == LIBUSB_TRANSFER_TYPE_INTERRUPT) &&
908 (ep_addr & LIBUSB_ENDPOINT_IN)) {
909 char control = USB_EP_INTR_ONE_XFER;
912 /* open the status device node for the ep first RDWR */
913 if ((fdstat = open(statfilename, O_RDWR)) == -1) {
914 usbi_dbg("can't open %s RDWR: %d",
915 statfilename, errno);
917 count = write(fdstat, &control, sizeof (control));
919 /* this should have worked */
920 usbi_dbg("can't write to %s: %d",
921 statfilename, errno);
922 (void) close(fdstat);
926 /* close status node and open xfer node first */
931 /* open the xfer node first in case alt needs to be changed */
932 if (ep_type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS) {
934 } else if (ep_addr & LIBUSB_ENDPOINT_IN) {
941 * IMPORTANT: must open data xfer node first and then open stat node
942 * Otherwise, it will fail on multi-config or multi-altsetting devices
943 * with "Device Busy" error. See ugen_epxs_switch_cfg_alt() and
944 * ugen_epxs_check_alt_switch() in ugen driver source code.
946 if ((fd = open(filename, mode)) == -1) {
947 usbi_dbg("can't open %s: %d(%s)", filename, errno,
952 /* open the status node */
953 if ((fdstat = open(statfilename, O_RDONLY)) == -1) {
954 usbi_dbg("can't open %s: %d", statfilename, errno);
961 hpriv->eps[ep_index].datafd = fd;
962 hpriv->eps[ep_index].statfd = fdstat;
963 usbi_dbg("ep=0x%02x datafd=%d, statfd=%d", ep_addr, fd, fdstat);
969 sunos_open(struct libusb_device_handle *handle)
971 sunos_dev_handle_priv_t *hpriv;
972 sunos_dev_priv_t *dpriv;
976 hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
977 dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
978 hpriv->dpriv = dpriv;
980 /* set all file descriptors to "closed" */
981 for (i = 0; i < USB_MAXENDPOINTS; i++) {
982 hpriv->eps[i].datafd = -1;
983 hpriv->eps[i].statfd = -1;
986 if (sunos_kernel_driver_active(handle, 0)) {
987 /* pretend we can open the device */
988 return (LIBUSB_SUCCESS);
991 if ((ret = sunos_usb_open_ep0(hpriv, dpriv)) != LIBUSB_SUCCESS) {
992 usbi_dbg("fail: %d", ret);
996 return (LIBUSB_SUCCESS);
1000 sunos_close(struct libusb_device_handle *handle)
1002 sunos_dev_handle_priv_t *hpriv;
1003 sunos_dev_priv_t *dpriv;
1010 hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
1014 dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1019 sunos_usb_close_all_eps(hpriv);
1020 sunos_usb_close_ep0(hpriv, dpriv);
1024 sunos_get_device_descriptor(struct libusb_device *dev, uint8_t *buf,
1027 sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
1029 memcpy(buf, &dpriv->dev_descr, LIBUSB_DT_DEVICE_SIZE);
1032 return (LIBUSB_SUCCESS);
1036 sunos_get_active_config_descriptor(struct libusb_device *dev,
1037 uint8_t *buf, size_t len, int *host_endian)
1039 sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
1040 struct libusb_config_descriptor *cfg;
1046 * Keep raw configuration descriptors updated, in case config
1047 * has ever been changed through setCfg.
1049 if ((node = di_init(dpriv->phypath, DINFOCPYALL)) == DI_NODE_NIL) {
1050 usbi_dbg("di_int() failed: %s", strerror(errno));
1051 return (LIBUSB_ERROR_IO);
1053 proplen = di_prop_lookup_bytes(DDI_DEV_T_ANY, node,
1054 "usb-raw-cfg-descriptors", &rdata);
1056 usbi_dbg("can't find raw config descriptors");
1058 return (LIBUSB_ERROR_IO);
1060 dpriv->raw_cfgdescr = realloc(dpriv->raw_cfgdescr, proplen);
1061 if (dpriv->raw_cfgdescr == NULL) {
1062 return (LIBUSB_ERROR_NO_MEM);
1064 bcopy(rdata, dpriv->raw_cfgdescr, proplen);
1065 dpriv->cfgvalue = ((struct libusb_config_descriptor *)
1066 rdata)->bConfigurationValue;
1070 cfg = (struct libusb_config_descriptor *)dpriv->raw_cfgdescr;
1071 len = MIN(len, libusb_le16_to_cpu(cfg->wTotalLength));
1072 memcpy(buf, dpriv->raw_cfgdescr, len);
1074 usbi_dbg("path:%s len %d", dpriv->phypath, len);
1080 sunos_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
1081 uint8_t *buf, size_t len, int *host_endian)
1084 return(sunos_get_active_config_descriptor(dev, buf, len, host_endian));
1088 sunos_get_configuration(struct libusb_device_handle *handle, int *config)
1090 sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1092 *config = dpriv->cfgvalue;
1094 usbi_dbg("bConfigurationValue %d", *config);
1096 return (LIBUSB_SUCCESS);
1100 sunos_set_configuration(struct libusb_device_handle *handle, int config)
1102 sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1103 sunos_dev_handle_priv_t *hpriv;
1105 usbi_dbg("bConfigurationValue %d", config);
1106 hpriv = (sunos_dev_handle_priv_t *)handle->os_priv;
1108 if (dpriv->ugenpath == NULL)
1109 return (LIBUSB_ERROR_NOT_SUPPORTED);
1111 if (config < 1 || config > dpriv->dev_descr.bNumConfigurations)
1112 return (LIBUSB_ERROR_INVALID_PARAM);
1114 dpriv->cfgvalue = config;
1115 hpriv->config_index = config - 1;
1117 return (LIBUSB_SUCCESS);
1121 sunos_claim_interface(struct libusb_device_handle *handle, int iface)
1123 usbi_dbg("iface %d", iface);
1125 return (LIBUSB_ERROR_INVALID_PARAM);
1128 return (LIBUSB_SUCCESS);
1132 sunos_release_interface(struct libusb_device_handle *handle, int iface)
1134 sunos_dev_handle_priv_t *hpriv =
1135 (sunos_dev_handle_priv_t *)handle->os_priv;
1137 usbi_dbg("iface %d", iface);
1139 return (LIBUSB_ERROR_INVALID_PARAM);
1142 /* XXX: can we release it? */
1143 hpriv->altsetting[iface] = 0;
1145 return (LIBUSB_SUCCESS);
1149 sunos_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
1152 sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)handle->dev->os_priv;
1153 sunos_dev_handle_priv_t *hpriv =
1154 (sunos_dev_handle_priv_t *)handle->os_priv;
1156 usbi_dbg("iface %d, setting %d", iface, altsetting);
1158 if (iface < 0 || altsetting < 0) {
1159 return (LIBUSB_ERROR_INVALID_PARAM);
1161 if (dpriv->ugenpath == NULL)
1162 return (LIBUSB_ERROR_NOT_FOUND);
1164 /* XXX: can we switch altsetting? */
1165 hpriv->altsetting[iface] = altsetting;
1167 return (LIBUSB_SUCCESS);
1171 usb_dump_data(unsigned char *data, size_t size)
1175 if (getenv("LIBUSB_DEBUG") == NULL) {
1179 (void) fprintf(stderr, "data dump:");
1180 for (i = 0; i < size; i++) {
1182 (void) fprintf(stderr, "\n%08x ", i);
1184 (void) fprintf(stderr, "%02x ", (uchar_t)data[i]);
1186 (void) fprintf(stderr, "\n");
1190 sunos_async_callback(union sigval arg)
1192 struct sunos_transfer_priv *tpriv =
1193 (struct sunos_transfer_priv *)arg.sival_ptr;
1194 struct libusb_transfer *xfer = tpriv->transfer;
1195 struct aiocb *aiocb = &tpriv->aiocb;
1197 sunos_dev_handle_priv_t *hpriv;
1200 hpriv = (sunos_dev_handle_priv_t *)xfer->dev_handle->os_priv;
1201 ep = sunos_usb_ep_index(xfer->endpoint);
1203 ret = aio_error(aiocb);
1205 xfer->status = sunos_usb_get_status(hpriv->eps[ep].statfd);
1207 xfer->actual_length =
1208 LIBUSB_TRANSFER_TO_USBI_TRANSFER(xfer)->transferred =
1212 usb_dump_data(xfer->buffer, xfer->actual_length);
1214 usbi_dbg("ret=%d, len=%d, actual_len=%d", ret, xfer->length,
1215 xfer->actual_length);
1217 /* async notification */
1218 usbi_signal_transfer_completion(LIBUSB_TRANSFER_TO_USBI_TRANSFER(xfer));
1222 sunos_do_async_io(struct libusb_transfer *transfer)
1225 struct aiocb *aiocb;
1226 sunos_dev_handle_priv_t *hpriv;
1228 struct sunos_transfer_priv *tpriv;
1232 tpriv = usbi_transfer_get_os_priv(LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer));
1233 hpriv = (sunos_dev_handle_priv_t *)transfer->dev_handle->os_priv;
1234 ep = sunos_usb_ep_index(transfer->endpoint);
1236 tpriv->transfer = transfer;
1237 aiocb = &tpriv->aiocb;
1238 bzero(aiocb, sizeof (*aiocb));
1239 aiocb->aio_fildes = hpriv->eps[ep].datafd;
1240 aiocb->aio_buf = transfer->buffer;
1241 aiocb->aio_nbytes = transfer->length;
1242 aiocb->aio_lio_opcode =
1243 ((transfer->endpoint & LIBUSB_ENDPOINT_DIR_MASK) ==
1244 LIBUSB_ENDPOINT_IN) ? LIO_READ:LIO_WRITE;
1245 aiocb->aio_sigevent.sigev_notify = SIGEV_THREAD;
1246 aiocb->aio_sigevent.sigev_value.sival_ptr = tpriv;
1247 aiocb->aio_sigevent.sigev_notify_function = sunos_async_callback;
1249 if (aiocb->aio_lio_opcode == LIO_READ) {
1250 ret = aio_read(aiocb);
1252 ret = aio_write(aiocb);
1258 /* return the number of bytes read/written */
1260 usb_do_io(int fd, int stat_fd, char *data, size_t size, int flag, int *status)
1265 usbi_dbg("usb_do_io(): datafd=%d statfd=%d size=0x%x flag=%s",
1266 fd, stat_fd, size, flag? "WRITE":"READ");
1271 ret = read(fd, data, size);
1272 usb_dump_data(data, size);
1275 usb_dump_data(data, size);
1277 ret = write(fd, data, size);
1281 usbi_dbg("usb_do_io(): amount=%d", ret);
1284 int save_errno = errno;
1286 usbi_dbg("TID=%x io %s errno=%d(%s) ret=%d", pthread_self(),
1287 flag?"WRITE":"READ", errno, strerror(errno), ret);
1289 /* sunos_usb_get_status will do a read and overwrite errno */
1290 error = sunos_usb_get_status(stat_fd);
1291 usbi_dbg("io status=%d errno=%d(%s)", error,
1292 save_errno, strerror(save_errno));
1295 *status = save_errno;
1298 return (save_errno);
1300 } else if (status) {
1308 solaris_submit_ctrl_on_default(struct libusb_transfer *transfer)
1310 int ret = -1, setup_ret;
1312 sunos_dev_handle_priv_t *hpriv;
1313 struct libusb_device_handle *hdl = transfer->dev_handle;
1315 uint8_t *data = transfer->buffer;
1317 hpriv = (sunos_dev_handle_priv_t *)hdl->os_priv;
1318 wLength = transfer->length - LIBUSB_CONTROL_SETUP_SIZE;
1320 if (hpriv->eps[0].datafd == -1) {
1321 usbi_dbg("ep0 not opened");
1323 return (LIBUSB_ERROR_NOT_FOUND);
1326 if ((data[0] & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN) {
1327 usbi_dbg("IN request");
1328 ret = usb_do_io(hpriv->eps[0].datafd,
1329 hpriv->eps[0].statfd, (char *)data, LIBUSB_CONTROL_SETUP_SIZE,
1330 WRITE, (int *)&status);
1332 usbi_dbg("OUT request");
1333 ret = usb_do_io(hpriv->eps[0].datafd, hpriv->eps[0].statfd,
1334 transfer->buffer, transfer->length, WRITE,
1335 (int *)&transfer->status);
1339 if (ret < LIBUSB_CONTROL_SETUP_SIZE) {
1340 usbi_dbg("error sending control msg: %d", ret);
1342 return (LIBUSB_ERROR_IO);
1345 ret = transfer->length - LIBUSB_CONTROL_SETUP_SIZE;
1347 /* Read the remaining bytes for IN request */
1348 if ((wLength) && ((data[0] & LIBUSB_ENDPOINT_DIR_MASK) ==
1349 LIBUSB_ENDPOINT_IN)) {
1350 usbi_dbg("DATA: %d", transfer->length - setup_ret);
1351 ret = usb_do_io(hpriv->eps[0].datafd,
1352 hpriv->eps[0].statfd,
1353 (char *)transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE,
1354 wLength, READ, (int *)&transfer->status);
1358 transfer->actual_length = ret;
1359 LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer)->transferred = ret;
1361 usbi_dbg("Done: ctrl data bytes %d", ret);
1363 /* sync transfer handling */
1364 ret = usbi_handle_transfer_completion(LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer),
1371 sunos_clear_halt(struct libusb_device_handle *handle, uint8_t endpoint)
1375 usbi_dbg("endpoint=0x%02x", endpoint);
1377 ret = libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT |
1378 LIBUSB_RECIPIENT_ENDPOINT | LIBUSB_REQUEST_TYPE_STANDARD,
1379 LIBUSB_REQUEST_CLEAR_FEATURE, 0, endpoint, NULL, 0, 1000);
1381 usbi_dbg("ret=%d", ret);
1387 sunos_reset_device(struct libusb_device_handle *handle)
1391 return (LIBUSB_ERROR_NOT_SUPPORTED);
1395 sunos_destroy_device(struct libusb_device *dev)
1397 sunos_dev_priv_t *dpriv = (sunos_dev_priv_t *)dev->os_priv;
1398 usbi_dbg("destroy everyting");
1399 free(dpriv->raw_cfgdescr);
1400 free(dpriv->ugenpath);
1401 free(dpriv->phypath);
1405 sunos_submit_transfer(struct usbi_transfer *itransfer)
1407 struct libusb_transfer *transfer;
1408 struct libusb_device_handle *hdl;
1411 transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
1412 hdl = transfer->dev_handle;
1414 err = sunos_check_device_and_status_open(hdl,
1415 transfer->endpoint, transfer->type);
1418 return (_errno_to_libusb(err));
1421 switch (transfer->type) {
1422 case LIBUSB_TRANSFER_TYPE_CONTROL:
1424 usbi_dbg("CTRL transfer: %d", transfer->length);
1425 err = solaris_submit_ctrl_on_default(transfer);
1428 case LIBUSB_TRANSFER_TYPE_BULK:
1430 case LIBUSB_TRANSFER_TYPE_INTERRUPT:
1431 if (transfer->type == LIBUSB_TRANSFER_TYPE_BULK)
1432 usbi_dbg("BULK transfer: %d", transfer->length);
1434 usbi_dbg("INTR transfer: %d", transfer->length);
1435 err = sunos_do_async_io(transfer);
1438 case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
1439 /* Isochronous/Stream is not supported */
1442 case LIBUSB_TRANSFER_TYPE_BULK_STREAM:
1443 if (transfer->type == LIBUSB_TRANSFER_TYPE_ISOCHRONOUS)
1444 usbi_dbg("ISOC transfer: %d", transfer->length);
1446 usbi_dbg("BULK STREAM transfer: %d", transfer->length);
1447 err = LIBUSB_ERROR_NOT_SUPPORTED;
1455 sunos_cancel_transfer(struct usbi_transfer *itransfer)
1457 sunos_xfer_priv_t *tpriv;
1458 sunos_dev_handle_priv_t *hpriv;
1459 struct libusb_transfer *transfer;
1460 struct aiocb *aiocb;
1464 tpriv = usbi_transfer_get_os_priv(itransfer);
1465 aiocb = &tpriv->aiocb;
1466 transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
1467 hpriv = (sunos_dev_handle_priv_t *)transfer->dev_handle->os_priv;
1468 ep = sunos_usb_ep_index(transfer->endpoint);
1470 ret = aio_cancel(hpriv->eps[ep].datafd, aiocb);
1472 usbi_dbg("aio->fd=%d fd=%d ret = %d, %s", aiocb->aio_fildes,
1473 hpriv->eps[ep].datafd, ret, (ret == AIO_CANCELED)?
1474 strerror(0):strerror(errno));
1476 if (ret != AIO_CANCELED) {
1477 ret = _errno_to_libusb(errno);
1480 * we don't need to call usbi_handle_transfer_cancellation(),
1481 * because we'll handle everything in sunos_async_callback.
1483 ret = LIBUSB_SUCCESS;
1490 sunos_clear_transfer_priv(struct usbi_transfer *itransfer)
1498 sunos_handle_transfer_completion(struct usbi_transfer *itransfer)
1500 return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
1504 sunos_clock_gettime(int clkid, struct timespec *tp)
1506 usbi_dbg("clock %d", clkid);
1508 if (clkid == USBI_CLOCK_REALTIME)
1509 return clock_gettime(CLOCK_REALTIME, tp);
1511 if (clkid == USBI_CLOCK_MONOTONIC)
1512 return clock_gettime(CLOCK_MONOTONIC, tp);
1514 return (LIBUSB_ERROR_INVALID_PARAM);
1518 _errno_to_libusb(int err)
1520 usbi_dbg("error: %s (%d)", strerror(err), err);
1524 return (LIBUSB_ERROR_IO);
1526 return (LIBUSB_ERROR_ACCESS);
1528 return (LIBUSB_ERROR_NO_DEVICE);
1530 return (LIBUSB_ERROR_NO_MEM);
1532 return (LIBUSB_ERROR_TIMEOUT);
1535 return (LIBUSB_ERROR_OTHER);
1539 * sunos_usb_get_status:
1540 * gets status of endpoint
1542 * Returns: ugen's last cmd status
1545 sunos_usb_get_status(int fd)
1549 usbi_dbg("sunos_usb_get_status(): fd=%d", fd);
1551 ret = read(fd, &status, sizeof (status));
1552 if (ret == sizeof (status)) {
1554 case USB_LC_STAT_NOERROR:
1555 usbi_dbg("No Error");
1557 case USB_LC_STAT_CRC:
1558 usbi_dbg("CRC Timeout Detected\n");
1560 case USB_LC_STAT_BITSTUFFING:
1561 usbi_dbg("Bit Stuffing Violation\n");
1563 case USB_LC_STAT_DATA_TOGGLE_MM:
1564 usbi_dbg("Data Toggle Mismatch\n");
1566 case USB_LC_STAT_STALL:
1567 usbi_dbg("End Point Stalled\n");
1569 case USB_LC_STAT_DEV_NOT_RESP:
1570 usbi_dbg("Device is Not Responding\n");
1572 case USB_LC_STAT_PID_CHECKFAILURE:
1573 usbi_dbg("PID Check Failure\n");
1575 case USB_LC_STAT_UNEXP_PID:
1576 usbi_dbg("Unexpected PID\n");
1578 case USB_LC_STAT_DATA_OVERRUN:
1579 usbi_dbg("Data Exceeded Size\n");
1581 case USB_LC_STAT_DATA_UNDERRUN:
1582 usbi_dbg("Less data received\n");
1584 case USB_LC_STAT_BUFFER_OVERRUN:
1585 usbi_dbg("Buffer Size Exceeded\n");
1587 case USB_LC_STAT_BUFFER_UNDERRUN:
1588 usbi_dbg("Buffer Underrun\n");
1590 case USB_LC_STAT_TIMEOUT:
1591 usbi_dbg("Command Timed Out\n");
1593 case USB_LC_STAT_NOT_ACCESSED:
1594 usbi_dbg("Not Accessed by h/w\n");
1596 case USB_LC_STAT_UNSPECIFIED_ERR:
1597 usbi_dbg("Unspecified Error\n");
1599 case USB_LC_STAT_NO_BANDWIDTH:
1600 usbi_dbg("No Bandwidth\n");
1602 case USB_LC_STAT_HW_ERR:
1603 usbi_dbg("Host Controller h/w Error\n");
1605 case USB_LC_STAT_SUSPENDED:
1606 usbi_dbg("Device was Suspended\n");
1608 case USB_LC_STAT_DISCONNECTED:
1609 usbi_dbg("Device was Disconnected\n");
1611 case USB_LC_STAT_INTR_BUF_FULL:
1612 usbi_dbg("Interrupt buffer was full\n");
1614 case USB_LC_STAT_INVALID_REQ:
1615 usbi_dbg("Request was Invalid\n");
1617 case USB_LC_STAT_INTERRUPTED:
1618 usbi_dbg("Request was Interrupted\n");
1620 case USB_LC_STAT_NO_RESOURCES:
1621 usbi_dbg("No resources available for "
1624 case USB_LC_STAT_INTR_POLLING_FAILED:
1625 usbi_dbg("Failed to Restart Poll");
1628 usbi_dbg("Error Not Determined %d\n",
1633 usbi_dbg("read stat error: %s",strerror(errno));
1640 const struct usbi_os_backend usbi_backend = {
1645 .get_device_list = sunos_get_device_list,
1646 .get_device_descriptor = sunos_get_device_descriptor,
1647 .get_active_config_descriptor = sunos_get_active_config_descriptor,
1648 .get_config_descriptor = sunos_get_config_descriptor,
1649 .hotplug_poll = NULL,
1651 .close = sunos_close,
1652 .get_configuration = sunos_get_configuration,
1653 .set_configuration = sunos_set_configuration,
1655 .claim_interface = sunos_claim_interface,
1656 .release_interface = sunos_release_interface,
1657 .set_interface_altsetting = sunos_set_interface_altsetting,
1658 .clear_halt = sunos_clear_halt,
1659 .reset_device = sunos_reset_device, /* TODO */
1660 .alloc_streams = NULL,
1661 .free_streams = NULL,
1662 .kernel_driver_active = sunos_kernel_driver_active,
1663 .detach_kernel_driver = sunos_detach_kernel_driver,
1664 .attach_kernel_driver = sunos_attach_kernel_driver,
1665 .destroy_device = sunos_destroy_device,
1666 .submit_transfer = sunos_submit_transfer,
1667 .cancel_transfer = sunos_cancel_transfer,
1668 .handle_events = NULL,
1669 .clear_transfer_priv = sunos_clear_transfer_priv,
1670 .handle_transfer_completion = sunos_handle_transfer_completion,
1671 .clock_gettime = sunos_clock_gettime,
1672 .device_priv_size = sizeof(sunos_dev_priv_t),
1673 .device_handle_priv_size = sizeof(sunos_dev_handle_priv_t),
1674 .transfer_priv_size = sizeof(sunos_xfer_priv_t),