Deleted Added
full compact
libusb20_ugen20.c (184610) libusb20_ugen20.c (185087)
1/* $FreeBSD: head/lib/libusb20/libusb20_ugen20.c 184610 2008-11-04 02:31:03Z alfred $ */
1/* $FreeBSD: head/lib/libusb20/libusb20_ugen20.c 185087 2008-11-19 08:56:35Z alfred $ */
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 293 unchanged lines hidden (view full) ---

303 /* put the device on the backend list */
304 libusb20_be_enqueue_device(pbe, pdev);
305 }
306 close(state.f);
307 return (0); /* success */
308}
309
310static int
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 293 unchanged lines hidden (view full) ---

303 /* put the device on the backend list */
304 libusb20_be_enqueue_device(pbe, pdev);
305 }
306 close(state.f);
307 return (0); /* success */
308}
309
310static int
311ugen20_open_device(struct libusb20_device *pdev, uint16_t nMaxTransfer)
311ugen20_tr_renew(struct libusb20_device *pdev)
312{
312{
313 struct usb2_fs_endpoint *pfse = NULL;
314 struct usb2_fs_init fs_init = { /* zero */ };
313 struct usb2_fs_uninit fs_uninit;
314 struct usb2_fs_init fs_init;
315 struct usb2_fs_endpoint *pfse;
316 int error;
315 uint32_t size;
317 uint32_t size;
318 uint16_t nMaxTransfer;
319
320 nMaxTransfer = pdev->nTransfer;
321 error = 0;
322
323 if (nMaxTransfer == 0) {
324 goto done;
325 }
326 size = nMaxTransfer * sizeof(*pfse);
327
328 if (pdev->privBeData != NULL) {
329 memset(&fs_uninit, 0, sizeof(fs_uninit));
330 if (ioctl(pdev->file, USB_FS_UNINIT, &fs_uninit)) {
331 /* ignore any errors of this kind */
332 }
333 } else {
334 pfse = malloc(size);
335 if (pfse == NULL) {
336 error = LIBUSB20_ERROR_NO_MEM;
337 goto done;
338 }
339 pdev->privBeData = pfse;
340 }
341
342 /* reset endpoint data */
343 memset(pdev->privBeData, 0, size);
344
345 memset(&fs_init, 0, sizeof(fs_init));
346
347 fs_init.pEndpoints = pdev->privBeData;
348 fs_init.ep_index_max = nMaxTransfer;
349
350 if (ioctl(pdev->file, USB_FS_INIT, &fs_init)) {
351 error = LIBUSB20_ERROR_OTHER;
352 goto done;
353 }
354done:
355 return (error);
356}
357
358static int
359ugen20_open_device(struct libusb20_device *pdev, uint16_t nMaxTransfer)
360{
316 uint32_t plugtime;
317 char buf[64];
318 int f;
319 int g;
320 int error;
321
322 snprintf(buf, sizeof(buf), "/dev/ugen%u.%u",
323 pdev->bus_number, pdev->device_address);

--- 16 unchanged lines hidden (view full) ---

340 error = LIBUSB20_ERROR_OTHER;
341 goto done;
342 }
343 /* check that the correct device is still plugged */
344 if (pdev->session_data.plugtime != plugtime) {
345 error = LIBUSB20_ERROR_NO_DEVICE;
346 goto done;
347 }
361 uint32_t plugtime;
362 char buf[64];
363 int f;
364 int g;
365 int error;
366
367 snprintf(buf, sizeof(buf), "/dev/ugen%u.%u",
368 pdev->bus_number, pdev->device_address);

--- 16 unchanged lines hidden (view full) ---

385 error = LIBUSB20_ERROR_OTHER;
386 goto done;
387 }
388 /* check that the correct device is still plugged */
389 if (pdev->session_data.plugtime != plugtime) {
390 error = LIBUSB20_ERROR_NO_DEVICE;
391 goto done;
392 }
348 if (nMaxTransfer != 0) {
393 /* need to set this before "tr_renew()" */
394 pdev->file = f;
395 pdev->file_ctrl = g;
349
396
350 size = nMaxTransfer * sizeof(*pfse);
351
352 pfse = malloc(size);
353 if (!pfse) {
354 error = LIBUSB20_ERROR_NO_MEM;
355 goto done;
356 }
357 memset(pfse, 0, size);
358
359 fs_init.pEndpoints = pfse;
360 fs_init.ep_index_max = nMaxTransfer;
361
362 if (ioctl(f, USB_FS_INIT, &fs_init)) {
363 error = LIBUSB20_ERROR_OTHER;
364 goto done;
365 }
397 /* renew all USB transfers */
398 error = ugen20_tr_renew(pdev);
399 if (error) {
400 goto done;
366 }
367 /* set methods */
368 pdev->methods = &libusb20_ugen20_device_methods;
401 }
402 /* set methods */
403 pdev->methods = &libusb20_ugen20_device_methods;
369 pdev->privBeData = pfse;
370 pdev->file = f;
371 pdev->file_ctrl = g;
372 error = 0;
404
373done:
374 if (error) {
405done:
406 if (error) {
375 if (pfse) {
376 free(pfse);
407 if (pdev->privBeData) {
408 /* cleanup after "tr_renew()" */
409 free(pdev->privBeData);
410 pdev->privBeData = NULL;
377 }
411 }
412 pdev->file = -1;
413 pdev->file_ctrl = -1;
378 close(f);
379 close(g);
380 }
381 return (error);
382}
383
384static int
385ugen20_close_device(struct libusb20_device *pdev)
386{
414 close(f);
415 close(g);
416 }
417 return (error);
418}
419
420static int
421ugen20_close_device(struct libusb20_device *pdev)
422{
387 struct usb2_fs_uninit fs_uninit = { /* zero */ };
423 struct usb2_fs_uninit fs_uninit;
388 int error = 0;
389
390 if (pdev->privBeData) {
424 int error = 0;
425
426 if (pdev->privBeData) {
427 memset(&fs_uninit, 0, sizeof(fs_uninit));
391 if (ioctl(pdev->file, USB_FS_UNINIT, &fs_uninit)) {
392 error = LIBUSB20_ERROR_OTHER;
393 }
394 free(pdev->privBeData);
395 }
396 pdev->nTransfer = 0;
397 pdev->privBeData = NULL;
398 close(pdev->file);

--- 6 unchanged lines hidden (view full) ---

405static void
406ugen20_exit_backend(struct libusb20_backend *pbe)
407{
408 return; /* nothing to do */
409}
410
411static int
412ugen20_get_config_desc_full(struct libusb20_device *pdev,
428 if (ioctl(pdev->file, USB_FS_UNINIT, &fs_uninit)) {
429 error = LIBUSB20_ERROR_OTHER;
430 }
431 free(pdev->privBeData);
432 }
433 pdev->nTransfer = 0;
434 pdev->privBeData = NULL;
435 close(pdev->file);

--- 6 unchanged lines hidden (view full) ---

442static void
443ugen20_exit_backend(struct libusb20_backend *pbe)
444{
445 return; /* nothing to do */
446}
447
448static int
449ugen20_get_config_desc_full(struct libusb20_device *pdev,
413 uint8_t **ppbuf, uint16_t *plen, uint8_t index)
450 uint8_t **ppbuf, uint16_t *plen, uint8_t cfg_index)
414{
451{
415 struct usb2_gen_descriptor gen_desc = { /* zero */ };
452 struct usb2_gen_descriptor gen_desc;
416 struct usb2_config_descriptor cdesc;
417 uint8_t *ptr;
418 uint16_t len;
419 int error;
420
453 struct usb2_config_descriptor cdesc;
454 uint8_t *ptr;
455 uint16_t len;
456 int error;
457
458 memset(&gen_desc, 0, sizeof(gen_desc));
459
421 gen_desc.ugd_data = &cdesc;
422 gen_desc.ugd_maxlen = sizeof(cdesc);
460 gen_desc.ugd_data = &cdesc;
461 gen_desc.ugd_maxlen = sizeof(cdesc);
423 gen_desc.ugd_config_index = index;
462 gen_desc.ugd_config_index = cfg_index;
424
425 error = ioctl(pdev->file_ctrl, USB_GET_FULL_DESC, &gen_desc);
426 if (error) {
427 return (LIBUSB20_ERROR_OTHER);
428 }
429 len = UGETW(cdesc.wTotalLength);
430 if (len < sizeof(cdesc)) {
431 /* corrupt descriptor */

--- 29 unchanged lines hidden (view full) ---

461 return (LIBUSB20_ERROR_OTHER);
462 }
463 *pindex = temp;
464
465 return (0);
466}
467
468static int
463
464 error = ioctl(pdev->file_ctrl, USB_GET_FULL_DESC, &gen_desc);
465 if (error) {
466 return (LIBUSB20_ERROR_OTHER);
467 }
468 len = UGETW(cdesc.wTotalLength);
469 if (len < sizeof(cdesc)) {
470 /* corrupt descriptor */

--- 29 unchanged lines hidden (view full) ---

500 return (LIBUSB20_ERROR_OTHER);
501 }
502 *pindex = temp;
503
504 return (0);
505}
506
507static int
469ugen20_set_config_index(struct libusb20_device *pdev, uint8_t index)
508ugen20_set_config_index(struct libusb20_device *pdev, uint8_t cfg_index)
470{
509{
471 int temp = index;
510 int temp = cfg_index;
472
473 if (ioctl(pdev->file_ctrl, USB_SET_CONFIG, &temp)) {
474 return (LIBUSB20_ERROR_OTHER);
475 }
511
512 if (ioctl(pdev->file_ctrl, USB_SET_CONFIG, &temp)) {
513 return (LIBUSB20_ERROR_OTHER);
514 }
476 return (0);
515 return (ugen20_tr_renew(pdev));
477}
478
479static int
480ugen20_claim_interface(struct libusb20_device *pdev, uint8_t iface_index)
481{
482 int temp = iface_index;
483
484 if (ioctl(pdev->file_ctrl, USB_CLAIM_INTERFACE, &temp)) {

--- 12 unchanged lines hidden (view full) ---

497 }
498 return (0);
499}
500
501static int
502ugen20_set_alt_index(struct libusb20_device *pdev,
503 uint8_t iface_index, uint8_t alt_index)
504{
516}
517
518static int
519ugen20_claim_interface(struct libusb20_device *pdev, uint8_t iface_index)
520{
521 int temp = iface_index;
522
523 if (ioctl(pdev->file_ctrl, USB_CLAIM_INTERFACE, &temp)) {

--- 12 unchanged lines hidden (view full) ---

536 }
537 return (0);
538}
539
540static int
541ugen20_set_alt_index(struct libusb20_device *pdev,
542 uint8_t iface_index, uint8_t alt_index)
543{
505 struct usb2_alt_interface alt_iface = { /* zero */ };
544 struct usb2_alt_interface alt_iface;
506
545
546 memset(&alt_iface, 0, sizeof(alt_iface));
547
507 alt_iface.uai_interface_index = iface_index;
508 alt_iface.uai_alt_index = alt_index;
509
510 if (ioctl(pdev->file_ctrl, USB_SET_ALTINTERFACE, &alt_iface)) {
511 return (LIBUSB20_ERROR_OTHER);
512 }
548 alt_iface.uai_interface_index = iface_index;
549 alt_iface.uai_alt_index = alt_index;
550
551 if (ioctl(pdev->file_ctrl, USB_SET_ALTINTERFACE, &alt_iface)) {
552 return (LIBUSB20_ERROR_OTHER);
553 }
513 return (0);
554 return (ugen20_tr_renew(pdev));
514}
515
516static int
517ugen20_reset_device(struct libusb20_device *pdev)
518{
519 int temp = 0;
520
521 if (ioctl(pdev->file_ctrl, USB_DEVICEENUMERATE, &temp)) {
522 return (LIBUSB20_ERROR_OTHER);
523 }
555}
556
557static int
558ugen20_reset_device(struct libusb20_device *pdev)
559{
560 int temp = 0;
561
562 if (ioctl(pdev->file_ctrl, USB_DEVICEENUMERATE, &temp)) {
563 return (LIBUSB20_ERROR_OTHER);
564 }
524 return (0);
565 return (ugen20_tr_renew(pdev));
525}
526
527static int
528ugen20_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode)
529{
530 int temp;
531
532 switch (power_mode) {

--- 77 unchanged lines hidden (view full) ---

610 return (0); /* kernel driver is active */
611}
612
613static int
614ugen20_do_request_sync(struct libusb20_device *pdev,
615 struct LIBUSB20_CONTROL_SETUP_DECODED *setup,
616 void *data, uint16_t *pactlen, uint32_t timeout, uint8_t flags)
617{
566}
567
568static int
569ugen20_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode)
570{
571 int temp;
572
573 switch (power_mode) {

--- 77 unchanged lines hidden (view full) ---

651 return (0); /* kernel driver is active */
652}
653
654static int
655ugen20_do_request_sync(struct libusb20_device *pdev,
656 struct LIBUSB20_CONTROL_SETUP_DECODED *setup,
657 void *data, uint16_t *pactlen, uint32_t timeout, uint8_t flags)
658{
618 struct usb2_ctl_request req = { /* zero */ };
659 struct usb2_ctl_request req;
619
660
661 memset(&req, 0, sizeof(req));
662
620 req.ucr_data = data;
621 if (!(flags & LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK)) {
622 req.ucr_flags |= USB_SHORT_XFER_OK;
623 }
624 if (libusb20_me_encode(&req.ucr_request,
625 sizeof(req.ucr_request), setup)) {
626 /* ignore */
627 }

--- 56 unchanged lines hidden (view full) ---

684 }
685 return (0); /* done */
686}
687
688static int
689ugen20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize,
690 uint32_t MaxFrameCount, uint8_t ep_no)
691{
663 req.ucr_data = data;
664 if (!(flags & LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK)) {
665 req.ucr_flags |= USB_SHORT_XFER_OK;
666 }
667 if (libusb20_me_encode(&req.ucr_request,
668 sizeof(req.ucr_request), setup)) {
669 /* ignore */
670 }

--- 56 unchanged lines hidden (view full) ---

727 }
728 return (0); /* done */
729}
730
731static int
732ugen20_tr_open(struct libusb20_transfer *xfer, uint32_t MaxBufSize,
733 uint32_t MaxFrameCount, uint8_t ep_no)
734{
692 struct usb2_fs_open temp = { /* zero */ };
735 struct usb2_fs_open temp;
693 struct usb2_fs_endpoint *fsep;
694
736 struct usb2_fs_endpoint *fsep;
737
738 memset(&temp, 0, sizeof(temp));
739
695 fsep = xfer->pdev->privBeData;
696 fsep += xfer->trIndex;
697
698 temp.max_bufsize = MaxBufSize;
699 temp.max_frames = MaxFrameCount;
700 temp.ep_index = xfer->trIndex;
701 temp.ep_no = ep_no;
702

--- 12 unchanged lines hidden (view full) ---

715 fsep->pLength = xfer->pLength; /* zero copy */
716
717 return (0); /* success */
718}
719
720static int
721ugen20_tr_close(struct libusb20_transfer *xfer)
722{
740 fsep = xfer->pdev->privBeData;
741 fsep += xfer->trIndex;
742
743 temp.max_bufsize = MaxBufSize;
744 temp.max_frames = MaxFrameCount;
745 temp.ep_index = xfer->trIndex;
746 temp.ep_no = ep_no;
747

--- 12 unchanged lines hidden (view full) ---

760 fsep->pLength = xfer->pLength; /* zero copy */
761
762 return (0); /* success */
763}
764
765static int
766ugen20_tr_close(struct libusb20_transfer *xfer)
767{
723 struct usb2_fs_close temp = { /* zero */ };
768 struct usb2_fs_close temp;
724
769
770 memset(&temp, 0, sizeof(temp));
771
725 temp.ep_index = xfer->trIndex;
726
727 if (ioctl(xfer->pdev->file, USB_FS_CLOSE, &temp)) {
728 return (LIBUSB20_ERROR_INVALID_PARAM);
729 }
730 return (0); /* success */
731}
732
733static int
734ugen20_tr_clear_stall_sync(struct libusb20_transfer *xfer)
735{
772 temp.ep_index = xfer->trIndex;
773
774 if (ioctl(xfer->pdev->file, USB_FS_CLOSE, &temp)) {
775 return (LIBUSB20_ERROR_INVALID_PARAM);
776 }
777 return (0); /* success */
778}
779
780static int
781ugen20_tr_clear_stall_sync(struct libusb20_transfer *xfer)
782{
736 struct usb2_fs_clear_stall_sync temp = { /* zero */ };
783 struct usb2_fs_clear_stall_sync temp;
737
784
785 memset(&temp, 0, sizeof(temp));
786
738 /* if the transfer is active, an error will be returned */
739
740 temp.ep_index = xfer->trIndex;
741
742 if (ioctl(xfer->pdev->file, USB_FS_CLEAR_STALL_SYNC, &temp)) {
743 return (LIBUSB20_ERROR_INVALID_PARAM);
744 }
745 return (0); /* success */
746}
747
748static void
749ugen20_tr_submit(struct libusb20_transfer *xfer)
750{
787 /* if the transfer is active, an error will be returned */
788
789 temp.ep_index = xfer->trIndex;
790
791 if (ioctl(xfer->pdev->file, USB_FS_CLEAR_STALL_SYNC, &temp)) {
792 return (LIBUSB20_ERROR_INVALID_PARAM);
793 }
794 return (0); /* success */
795}
796
797static void
798ugen20_tr_submit(struct libusb20_transfer *xfer)
799{
751 struct usb2_fs_start temp = { /* zero */ };
800 struct usb2_fs_start temp;
752 struct usb2_fs_endpoint *fsep;
753
801 struct usb2_fs_endpoint *fsep;
802
803 memset(&temp, 0, sizeof(temp));
804
754 fsep = xfer->pdev->privBeData;
755 fsep += xfer->trIndex;
756
757 fsep->nFrames = xfer->nFrames;
758 fsep->flags = 0;
759 if (!(xfer->flags & LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK)) {
760 fsep->flags |= USB_FS_FLAG_SINGLE_SHORT_OK;
761 }

--- 14 unchanged lines hidden (view full) ---

776 /* ignore any errors - should never happen */
777 }
778 return; /* success */
779}
780
781static void
782ugen20_tr_cancel_async(struct libusb20_transfer *xfer)
783{
805 fsep = xfer->pdev->privBeData;
806 fsep += xfer->trIndex;
807
808 fsep->nFrames = xfer->nFrames;
809 fsep->flags = 0;
810 if (!(xfer->flags & LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK)) {
811 fsep->flags |= USB_FS_FLAG_SINGLE_SHORT_OK;
812 }

--- 14 unchanged lines hidden (view full) ---

827 /* ignore any errors - should never happen */
828 }
829 return; /* success */
830}
831
832static void
833ugen20_tr_cancel_async(struct libusb20_transfer *xfer)
834{
784 struct usb2_fs_stop temp = { /* zero */ };
835 struct usb2_fs_stop temp;
785
836
837 memset(&temp, 0, sizeof(temp));
838
786 temp.ep_index = xfer->trIndex;
787
788 if (ioctl(xfer->pdev->file, USB_FS_STOP, &temp)) {
789 /* ignore any errors - should never happen */
790 }
791 return;
792}
793
794static int
795ugen20_be_ioctl(uint32_t cmd, void *data)
796{
797 int f;
839 temp.ep_index = xfer->trIndex;
840
841 if (ioctl(xfer->pdev->file, USB_FS_STOP, &temp)) {
842 /* ignore any errors - should never happen */
843 }
844 return;
845}
846
847static int
848ugen20_be_ioctl(uint32_t cmd, void *data)
849{
850 int f;
798 int err;
851 int error;
799
800 f = open("/dev/usb", O_RDONLY);
801 if (f < 0)
802 return (LIBUSB20_ERROR_OTHER);
852
853 f = open("/dev/usb", O_RDONLY);
854 if (f < 0)
855 return (LIBUSB20_ERROR_OTHER);
803 err = ioctl(f, cmd, data);
804 if (err == -1) {
856 error = ioctl(f, cmd, data);
857 if (error == -1) {
805 if (errno == EPERM) {
858 if (errno == EPERM) {
806 err = LIBUSB20_ERROR_ACCESS;
859 error = LIBUSB20_ERROR_ACCESS;
807 } else {
860 } else {
808 err = LIBUSB20_ERROR_OTHER;
861 error = LIBUSB20_ERROR_OTHER;
809 }
810 }
811 close(f);
862 }
863 }
864 close(f);
812 return (err);
865 return (error);
813}
814
815static int
816ugen20_be_do_perm(uint32_t get_cmd, uint32_t set_cmd, uint8_t bus,
817 uint8_t dev, uint8_t iface, uid_t *uid,
818 gid_t *gid, mode_t *mode)
819{
866}
867
868static int
869ugen20_be_do_perm(uint32_t get_cmd, uint32_t set_cmd, uint8_t bus,
870 uint8_t dev, uint8_t iface, uid_t *uid,
871 gid_t *gid, mode_t *mode)
872{
820 struct usb2_dev_perm perm = { /* zero */ };
821 int err;
873 struct usb2_dev_perm perm;
874 int error;
822
875
876 memset(&perm, 0, sizeof(perm));
877
823 perm.bus_index = bus;
824 perm.dev_index = dev;
825 perm.iface_index = iface;
826
878 perm.bus_index = bus;
879 perm.dev_index = dev;
880 perm.iface_index = iface;
881
827 err = ugen20_be_ioctl(get_cmd, &perm);
828 if (err)
829 return (err);
882 error = ugen20_be_ioctl(get_cmd, &perm);
883 if (error)
884 return (error);
830
831 if (set_cmd == 0) {
832 if (uid)
833 *uid = perm.user_id;
834 if (gid)
835 *gid = perm.group_id;
836 if (mode)
837 *mode = perm.mode;

--- 91 unchanged lines hidden (view full) ---

929{
930 return (ugen20_be_do_perm(USB_GET_IFACE_PERM, USB_SET_IFACE_PERM,
931 pdev->bus_number, pdev->device_address, iface_index,
932 NULL, NULL, &mode));
933}
934
935static int
936ugen20_root_get_dev_quirk(struct libusb20_backend *pbe,
885
886 if (set_cmd == 0) {
887 if (uid)
888 *uid = perm.user_id;
889 if (gid)
890 *gid = perm.group_id;
891 if (mode)
892 *mode = perm.mode;

--- 91 unchanged lines hidden (view full) ---

984{
985 return (ugen20_be_do_perm(USB_GET_IFACE_PERM, USB_SET_IFACE_PERM,
986 pdev->bus_number, pdev->device_address, iface_index,
987 NULL, NULL, &mode));
988}
989
990static int
991ugen20_root_get_dev_quirk(struct libusb20_backend *pbe,
937 uint16_t index, struct libusb20_quirk *pq)
992 uint16_t quirk_index, struct libusb20_quirk *pq)
938{
939 struct usb2_gen_quirk q;
993{
994 struct usb2_gen_quirk q;
940 int err;
995 int error;
941
942 memset(&q, 0, sizeof(q));
943
996
997 memset(&q, 0, sizeof(q));
998
944 q.index = index;
999 q.index = quirk_index;
945
1000
946 err = ugen20_be_ioctl(USB_DEV_QUIRK_GET, &q);
1001 error = ugen20_be_ioctl(USB_DEV_QUIRK_GET, &q);
947
1002
948 if (err) {
1003 if (error) {
949 if (errno == EINVAL) {
950 return (LIBUSB20_ERROR_NOT_FOUND);
951 }
952 } else {
953 pq->vid = q.vid;
954 pq->pid = q.pid;
955 pq->bcdDeviceLow = q.bcdDeviceLow;
956 pq->bcdDeviceHigh = q.bcdDeviceHigh;
957 strlcpy(pq->quirkname, q.quirkname, sizeof(pq->quirkname));
958 }
1004 if (errno == EINVAL) {
1005 return (LIBUSB20_ERROR_NOT_FOUND);
1006 }
1007 } else {
1008 pq->vid = q.vid;
1009 pq->pid = q.pid;
1010 pq->bcdDeviceLow = q.bcdDeviceLow;
1011 pq->bcdDeviceHigh = q.bcdDeviceHigh;
1012 strlcpy(pq->quirkname, q.quirkname, sizeof(pq->quirkname));
1013 }
959 return (err);
1014 return (error);
960}
961
962static int
1015}
1016
1017static int
963ugen20_root_get_quirk_name(struct libusb20_backend *pbe, uint16_t index,
1018ugen20_root_get_quirk_name(struct libusb20_backend *pbe, uint16_t quirk_index,
964 struct libusb20_quirk *pq)
965{
966 struct usb2_gen_quirk q;
1019 struct libusb20_quirk *pq)
1020{
1021 struct usb2_gen_quirk q;
967 int err;
1022 int error;
968
969 memset(&q, 0, sizeof(q));
970
1023
1024 memset(&q, 0, sizeof(q));
1025
971 q.index = index;
1026 q.index = quirk_index;
972
1027
973 err = ugen20_be_ioctl(USB_QUIRK_NAME_GET, &q);
1028 error = ugen20_be_ioctl(USB_QUIRK_NAME_GET, &q);
974
1029
975 if (err) {
1030 if (error) {
976 if (errno == EINVAL) {
977 return (LIBUSB20_ERROR_NOT_FOUND);
978 }
979 } else {
980 strlcpy(pq->quirkname, q.quirkname, sizeof(pq->quirkname));
981 }
1031 if (errno == EINVAL) {
1032 return (LIBUSB20_ERROR_NOT_FOUND);
1033 }
1034 } else {
1035 strlcpy(pq->quirkname, q.quirkname, sizeof(pq->quirkname));
1036 }
982 return (err);
1037 return (error);
983}
984
985static int
986ugen20_root_add_dev_quirk(struct libusb20_backend *pbe,
987 struct libusb20_quirk *pq)
988{
989 struct usb2_gen_quirk q;
1038}
1039
1040static int
1041ugen20_root_add_dev_quirk(struct libusb20_backend *pbe,
1042 struct libusb20_quirk *pq)
1043{
1044 struct usb2_gen_quirk q;
990 int err;
1045 int error;
991
992 memset(&q, 0, sizeof(q));
993
994 q.vid = pq->vid;
995 q.pid = pq->pid;
996 q.bcdDeviceLow = pq->bcdDeviceLow;
997 q.bcdDeviceHigh = pq->bcdDeviceHigh;
998 strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
999
1046
1047 memset(&q, 0, sizeof(q));
1048
1049 q.vid = pq->vid;
1050 q.pid = pq->pid;
1051 q.bcdDeviceLow = pq->bcdDeviceLow;
1052 q.bcdDeviceHigh = pq->bcdDeviceHigh;
1053 strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
1054
1000 err = ugen20_be_ioctl(USB_DEV_QUIRK_ADD, &q);
1001 if (err) {
1055 error = ugen20_be_ioctl(USB_DEV_QUIRK_ADD, &q);
1056 if (error) {
1002 if (errno == ENOMEM) {
1003 return (LIBUSB20_ERROR_NO_MEM);
1004 }
1005 }
1057 if (errno == ENOMEM) {
1058 return (LIBUSB20_ERROR_NO_MEM);
1059 }
1060 }
1006 return (err);
1061 return (error);
1007}
1008
1009static int
1010ugen20_root_remove_dev_quirk(struct libusb20_backend *pbe,
1011 struct libusb20_quirk *pq)
1012{
1013 struct usb2_gen_quirk q;
1062}
1063
1064static int
1065ugen20_root_remove_dev_quirk(struct libusb20_backend *pbe,
1066 struct libusb20_quirk *pq)
1067{
1068 struct usb2_gen_quirk q;
1014 int err;
1069 int error;
1015
1016 memset(&q, 0, sizeof(q));
1017
1018 q.vid = pq->vid;
1019 q.pid = pq->pid;
1020 q.bcdDeviceLow = pq->bcdDeviceLow;
1021 q.bcdDeviceHigh = pq->bcdDeviceHigh;
1022 strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
1023
1070
1071 memset(&q, 0, sizeof(q));
1072
1073 q.vid = pq->vid;
1074 q.pid = pq->pid;
1075 q.bcdDeviceLow = pq->bcdDeviceLow;
1076 q.bcdDeviceHigh = pq->bcdDeviceHigh;
1077 strlcpy(q.quirkname, pq->quirkname, sizeof(q.quirkname));
1078
1024 err = ugen20_be_ioctl(USB_DEV_QUIRK_REMOVE, &q);
1025 if (err) {
1079 error = ugen20_be_ioctl(USB_DEV_QUIRK_REMOVE, &q);
1080 if (error) {
1026 if (errno == EINVAL) {
1027 return (LIBUSB20_ERROR_NOT_FOUND);
1028 }
1029 }
1081 if (errno == EINVAL) {
1082 return (LIBUSB20_ERROR_NOT_FOUND);
1083 }
1084 }
1030 return (err);
1085 return (error);
1031}
1032
1033static int
1034ugen20_dev_set_owner(struct libusb20_device *pdev,
1035 uid_t user, gid_t group)
1036{
1037 return (ugen20_be_do_perm(USB_GET_DEVICE_PERM, USB_SET_DEVICE_PERM,
1038 pdev->bus_number, pdev->device_address, 0,

--- 39 unchanged lines hidden ---
1086}
1087
1088static int
1089ugen20_dev_set_owner(struct libusb20_device *pdev,
1090 uid_t user, gid_t group)
1091{
1092 return (ugen20_be_do_perm(USB_GET_DEVICE_PERM, USB_SET_DEVICE_PERM,
1093 pdev->bus_number, pdev->device_address, 0,

--- 39 unchanged lines hidden ---