2 * URB formatting related implementation
5 #include <minix/sysutil.h> /* panic */
6 #include <minix/usb.h> /* struct usb_ctrlrequest */
8 #include <string.h> /* memset */
12 #include "urb_helper.h"
14 /*---------------------------*
16 *---------------------------*/
17 /*===========================================================================*
19 *===========================================================================*/
21 init_urb(struct ddekit_usb_urb
* urb
, struct ddekit_usb_dev
* dev
,
29 assert((DDEKIT_USB_TRANSFER_BLK
== conf
->type
) ||
30 (DDEKIT_USB_TRANSFER_CTL
== conf
->type
) ||
31 (DDEKIT_USB_TRANSFER_INT
== conf
->type
) ||
32 (DDEKIT_USB_TRANSFER_ISO
== conf
->type
));
33 assert((conf
->ep_num
>= 0) && (conf
->ep_num
< 16));
34 assert((DDEKIT_USB_IN
== conf
->direction
) ||
35 (DDEKIT_USB_OUT
== conf
->direction
));
37 /* Clear block first */
38 memset(urb
, 0, sizeof(*urb
));
40 /* Set supplied values */
42 urb
->type
= conf
->type
;
43 urb
->endpoint
= conf
->ep_num
;
44 urb
->direction
= conf
->direction
;
45 urb
->interval
= conf
->interval
;
49 /*===========================================================================*
51 *===========================================================================*/
53 attach_urb_data(struct ddekit_usb_urb
* urb
, int buf_type
,
54 void * buf
, ddekit_uint32_t buf_len
)
61 /* Mutual exclusion */
62 if (URB_BUF_TYPE_DATA
== buf_type
) {
65 } else if ( URB_BUF_TYPE_SETUP
== buf_type
) {
66 assert(sizeof(struct usb_ctrlrequest
) == buf_len
);
67 urb
->setup_packet
= buf
;
69 panic("Unexpected buffer type!");
73 /*===========================================================================*
74 * blocking_urb_submit *
75 *===========================================================================*/
77 blocking_urb_submit(struct ddekit_usb_urb
* urb
, ddekit_sem_t
* sem
,
84 assert((check_len
== URB_SUBMIT_CHECK_LEN
) ||
85 (check_len
== URB_SUBMIT_ALLOW_MISMATCH
));
87 /* Submit and block until semaphore gets up */
88 if (ddekit_usb_submit_urb(urb
)) {
89 HUB_MSG("Submitting DDEKit URB failed");
92 /* Submitting succeeded so block and wait for reply */
95 /* Check for DDEKit status first */
97 HUB_MSG("Invalid DDEKit URB status");
100 if (URB_SUBMIT_CHECK_LEN
== check_len
) {
101 /* Compare lengths */
102 if (urb
->actual_length
!= urb
->size
) {
103 HUB_MSG("URB different than expected");