2 * Copyright (C) 2003-2008 Takahiro Hirofuchi
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 #include <linux/kernel.h>
21 #include <linux/smp_lock.h>
22 #include <linux/file.h>
23 #include <linux/tcp.h>
25 #include "usbip_common.h"
27 /* version information */
28 #define DRIVER_VERSION "1.0"
29 #define DRIVER_AUTHOR "Takahiro Hirofuchi <hirofuchi _at_ users.sourceforge.net>"
30 #define DRIVER_DESC "usbip common driver"
32 /*-------------------------------------------------------------------------*/
35 #ifdef CONFIG_USB_DEBUG
36 unsigned long usbip_debug_flag
= 0xffffffff;
38 unsigned long usbip_debug_flag
;
40 EXPORT_SYMBOL_GPL(usbip_debug_flag
);
44 struct device_attribute dev_attr_usbip_debug
;
45 EXPORT_SYMBOL_GPL(dev_attr_usbip_debug
);
48 static ssize_t
show_flag(struct device
*dev
, struct device_attribute
*attr
,
51 return sprintf(buf
, "%lx\n", usbip_debug_flag
);
54 static ssize_t
store_flag(struct device
*dev
, struct device_attribute
*attr
,
55 const char *buf
, size_t count
)
59 sscanf(buf
, "%lx", &flag
);
60 usbip_debug_flag
= flag
;
64 DEVICE_ATTR(usbip_debug
, (S_IRUGO
| S_IWUSR
), show_flag
, store_flag
);
66 static void usbip_dump_buffer(char *buff
, int bufflen
)
71 for (i
= 0; i
< 128; i
++) {
74 printk("%02x ", (unsigned char) buff
[i
]);
80 printk("... (%d byte)\n", bufflen
);
84 for (i
= 0; i
< bufflen
; i
++) {
87 printk("%02x ", (unsigned char) buff
[i
]);
97 static void usbip_dump_pipe(unsigned int p
)
99 unsigned char type
= usb_pipetype(p
);
100 unsigned char ep
= usb_pipeendpoint(p
);
101 unsigned char dev
= usb_pipedevice(p
);
102 unsigned char dir
= usb_pipein(p
);
104 printk("dev(%d) ", dev
);
105 printk("ep(%d) ", ep
);
106 printk("%s ", dir
? "IN" : "OUT");
109 case PIPE_ISOCHRONOUS
:
110 printk("%s ", "ISO");
113 printk("%s ", "INT");
116 printk("%s ", "CTL");
119 printk("%s ", "BLK");
129 static void usbip_dump_usb_device(struct usb_device
*udev
)
131 struct device
*dev
= &udev
->dev
;
134 dev_dbg(dev
, " devnum(%d) devpath(%s)",
135 udev
->devnum
, udev
->devpath
);
137 switch (udev
->speed
) {
147 case USB_SPEED_UNKNOWN
:
148 printk(" SPD_UNKNOWN");
151 printk(" SPD_ERROR");
154 printk(" tt %p, ttport %d", udev
->tt
, udev
->ttport
);
158 for (i
= 0; i
< 16; i
++)
162 dev_dbg(dev
, " toggle0(IN) :");
163 for (i
= 0; i
< 16; i
++)
164 printk(" %2u", (udev
->toggle
[0] & (1 << i
)) ? 1 : 0);
167 dev_dbg(dev
, " toggle1(OUT):");
168 for (i
= 0; i
< 16; i
++)
169 printk(" %2u", (udev
->toggle
[1] & (1 << i
)) ? 1 : 0);
173 dev_dbg(dev
, " epmaxp_in :");
174 for (i
= 0; i
< 16; i
++) {
177 le16_to_cpu(udev
->ep_in
[i
]->desc
.wMaxPacketSize
));
181 dev_dbg(dev
, " epmaxp_out :");
182 for (i
= 0; i
< 16; i
++) {
185 le16_to_cpu(udev
->ep_out
[i
]->desc
.wMaxPacketSize
));
189 dev_dbg(dev
, "parent %p, bus %p\n", udev
->parent
, udev
->bus
);
191 dev_dbg(dev
, "descriptor %p, config %p, actconfig %p, "
192 "rawdescriptors %p\n", &udev
->descriptor
, udev
->config
,
193 udev
->actconfig
, udev
->rawdescriptors
);
195 dev_dbg(dev
, "have_langid %d, string_langid %d\n",
196 udev
->have_langid
, udev
->string_langid
);
198 dev_dbg(dev
, "maxchild %d, children %p\n",
199 udev
->maxchild
, udev
->children
);
202 static void usbip_dump_request_type(__u8 rt
)
204 switch (rt
& USB_RECIP_MASK
) {
205 case USB_RECIP_DEVICE
:
208 case USB_RECIP_INTERFACE
:
211 case USB_RECIP_ENDPOINT
:
214 case USB_RECIP_OTHER
:
222 static void usbip_dump_usb_ctrlrequest(struct usb_ctrlrequest
*cmd
)
225 printk(" %s : null pointer\n", __func__
);
230 printk("bRequestType(%02X) ", cmd
->bRequestType
);
231 printk("bRequest(%02X) " , cmd
->bRequest
);
232 printk("wValue(%04X) ", cmd
->wValue
);
233 printk("wIndex(%04X) ", cmd
->wIndex
);
234 printk("wLength(%04X) ", cmd
->wLength
);
238 if ((cmd
->bRequestType
& USB_TYPE_MASK
) == USB_TYPE_STANDARD
) {
240 switch (cmd
->bRequest
) {
241 case USB_REQ_GET_STATUS
:
242 printk("GET_STATUS");
244 case USB_REQ_CLEAR_FEATURE
:
245 printk("CLEAR_FEAT");
247 case USB_REQ_SET_FEATURE
:
250 case USB_REQ_SET_ADDRESS
:
251 printk("SET_ADDRRS");
253 case USB_REQ_GET_DESCRIPTOR
:
254 printk("GET_DESCRI");
256 case USB_REQ_SET_DESCRIPTOR
:
257 printk("SET_DESCRI");
259 case USB_REQ_GET_CONFIGURATION
:
260 printk("GET_CONFIG");
262 case USB_REQ_SET_CONFIGURATION
:
263 printk("SET_CONFIG");
265 case USB_REQ_GET_INTERFACE
:
266 printk("GET_INTERF");
268 case USB_REQ_SET_INTERFACE
:
269 printk("SET_INTERF");
271 case USB_REQ_SYNCH_FRAME
:
272 printk("SYNC_FRAME");
275 printk("REQ(%02X) ", cmd
->bRequest
);
279 usbip_dump_request_type(cmd
->bRequestType
);
281 } else if ((cmd
->bRequestType
& USB_TYPE_MASK
) == USB_TYPE_CLASS
)
284 else if ((cmd
->bRequestType
& USB_TYPE_MASK
) == USB_TYPE_VENDOR
)
287 else if ((cmd
->bRequestType
& USB_TYPE_MASK
) == USB_TYPE_RESERVED
)
293 void usbip_dump_urb(struct urb
*urb
)
298 printk(KERN_DEBUG KBUILD_MODNAME
299 ":%s: urb: null pointer!!\n", __func__
);
304 printk(KERN_DEBUG KBUILD_MODNAME
305 ":%s: urb->dev: null pointer!!\n", __func__
);
308 dev
= &urb
->dev
->dev
;
310 dev_dbg(dev
, " urb :%p\n", urb
);
311 dev_dbg(dev
, " dev :%p\n", urb
->dev
);
313 usbip_dump_usb_device(urb
->dev
);
315 dev_dbg(dev
, " pipe :%08x ", urb
->pipe
);
317 usbip_dump_pipe(urb
->pipe
);
319 dev_dbg(dev
, " status :%d\n", urb
->status
);
320 dev_dbg(dev
, " transfer_flags :%08X\n", urb
->transfer_flags
);
321 dev_dbg(dev
, " transfer_buffer :%p\n", urb
->transfer_buffer
);
322 dev_dbg(dev
, " transfer_buffer_length:%d\n", urb
->transfer_buffer_length
);
323 dev_dbg(dev
, " actual_length :%d\n", urb
->actual_length
);
324 dev_dbg(dev
, " setup_packet :%p\n", urb
->setup_packet
);
326 if (urb
->setup_packet
&& usb_pipetype(urb
->pipe
) == PIPE_CONTROL
)
327 usbip_dump_usb_ctrlrequest(
328 (struct usb_ctrlrequest
*)urb
->setup_packet
);
330 dev_dbg(dev
, " start_frame :%d\n", urb
->start_frame
);
331 dev_dbg(dev
, " number_of_packets :%d\n", urb
->number_of_packets
);
332 dev_dbg(dev
, " interval :%d\n", urb
->interval
);
333 dev_dbg(dev
, " error_count :%d\n", urb
->error_count
);
334 dev_dbg(dev
, " context :%p\n", urb
->context
);
335 dev_dbg(dev
, " complete :%p\n", urb
->complete
);
337 EXPORT_SYMBOL_GPL(usbip_dump_urb
);
339 void usbip_dump_header(struct usbip_header
*pdu
)
341 udbg("BASE: cmd %u seq %u devid %u dir %u ep %u\n",
348 switch (pdu
->base
.command
) {
349 case USBIP_CMD_SUBMIT
:
350 udbg("CMD_SUBMIT: x_flags %u x_len %u sf %u #p %u iv %u\n",
351 pdu
->u
.cmd_submit
.transfer_flags
,
352 pdu
->u
.cmd_submit
.transfer_buffer_length
,
353 pdu
->u
.cmd_submit
.start_frame
,
354 pdu
->u
.cmd_submit
.number_of_packets
,
355 pdu
->u
.cmd_submit
.interval
);
357 case USBIP_CMD_UNLINK
:
358 udbg("CMD_UNLINK: seq %u\n", pdu
->u
.cmd_unlink
.seqnum
);
360 case USBIP_RET_SUBMIT
:
361 udbg("RET_SUBMIT: st %d al %u sf %d ec %d\n",
362 pdu
->u
.ret_submit
.status
,
363 pdu
->u
.ret_submit
.actual_length
,
364 pdu
->u
.ret_submit
.start_frame
,
365 pdu
->u
.ret_submit
.error_count
);
366 case USBIP_RET_UNLINK
:
367 udbg("RET_UNLINK: status %d\n", pdu
->u
.ret_unlink
.status
);
374 EXPORT_SYMBOL_GPL(usbip_dump_header
);
377 /*-------------------------------------------------------------------------*/
378 /* thread routines */
380 int usbip_thread(void *param
)
382 struct usbip_task
*ut
= param
;
389 allow_signal(SIGKILL
);
390 ut
->thread
= current
;
393 /* srv.rb must wait for rx_thread starting */
394 complete(&ut
->thread_done
);
396 /* start of while loop */
402 complete_and_exit(&ut
->thread_done
, 0);
405 void usbip_start_threads(struct usbip_device
*ud
)
408 * threads are invoked per one device (per one connection).
412 retval
= kernel_thread(usbip_thread
, (void *)&ud
->tcp_rx
, 0);
414 printk(KERN_ERR
"Creating tcp_rx thread for ud %p failed.\n",
418 retval
= kernel_thread(usbip_thread
, (void *)&ud
->tcp_tx
, 0);
420 printk(KERN_ERR
"Creating tcp_tx thread for ud %p failed.\n",
425 /* confirm threads are starting */
426 wait_for_completion(&ud
->tcp_rx
.thread_done
);
427 wait_for_completion(&ud
->tcp_tx
.thread_done
);
429 EXPORT_SYMBOL_GPL(usbip_start_threads
);
431 void usbip_stop_threads(struct usbip_device
*ud
)
433 /* kill threads related to this sdev, if v.c. exists */
434 if (ud
->tcp_rx
.thread
!= NULL
) {
435 send_sig(SIGKILL
, ud
->tcp_rx
.thread
, 1);
436 wait_for_completion(&ud
->tcp_rx
.thread_done
);
437 udbg("rx_thread for ud %p has finished\n", ud
);
440 if (ud
->tcp_tx
.thread
!= NULL
) {
441 send_sig(SIGKILL
, ud
->tcp_tx
.thread
, 1);
442 wait_for_completion(&ud
->tcp_tx
.thread_done
);
443 udbg("tx_thread for ud %p has finished\n", ud
);
446 EXPORT_SYMBOL_GPL(usbip_stop_threads
);
448 void usbip_task_init(struct usbip_task
*ut
, char *name
,
449 void (*loop_ops
)(struct usbip_task
*))
452 init_completion(&ut
->thread_done
);
454 ut
->loop_ops
= loop_ops
;
456 EXPORT_SYMBOL_GPL(usbip_task_init
);
459 /*-------------------------------------------------------------------------*/
460 /* socket routines */
462 /* Send/receive messages over TCP/IP. I refer drivers/block/nbd.c */
463 int usbip_xmit(int send
, struct socket
*sock
, char *buf
,
464 int size
, int msg_flags
)
471 /* for blocks of if (dbg_flag_xmit) */
477 if (!sock
|| !buf
|| !size
) {
478 printk(KERN_ERR
"%s: invalid arg, sock %p buff %p size %d\n",
479 __func__
, sock
, buf
, size
);
487 printk(KERN_DEBUG
"%-10s:", current
->comm
);
489 printk(KERN_DEBUG
"interupt :");
491 printk("%s: sending... , sock %p, buf %p, "
492 "size %d, msg_flags %d\n", __func__
,
493 sock
, buf
, size
, msg_flags
);
494 usbip_dump_buffer(buf
, size
);
500 sock
->sk
->sk_allocation
= GFP_NOIO
;
505 msg
.msg_control
= NULL
;
506 msg
.msg_controllen
= 0;
508 msg
.msg_flags
= msg_flags
| MSG_NOSIGNAL
;
511 result
= kernel_sendmsg(sock
, &msg
, &iov
, 1, size
);
513 result
= kernel_recvmsg(sock
, &msg
, &iov
, 1, size
,
517 udbg("usbip_xmit: %s sock %p buf %p size %u ret %d"
519 send
? "send" : "receive", sock
, buf
,
520 size
, result
, total
);
534 printk(KERN_DEBUG
"%-10s:", current
->comm
);
536 printk(KERN_DEBUG
"interupt :");
538 printk("usbip_xmit: receiving....\n");
539 usbip_dump_buffer(bp
, osize
);
540 printk("usbip_xmit: received, osize %d ret %d size %d "
541 "total %d\n", osize
, result
, size
,
546 printk("usbip_xmit: send, total %d\n", total
);
554 EXPORT_SYMBOL_GPL(usbip_xmit
);
557 /* now a usrland utility should set options. */
559 int setquickack(struct socket
*socket
)
567 ret
= socket
->ops
->setsockopt(socket
, SOL_TCP
, TCP_QUICKACK
,
568 (char __user
*) &val
, sizeof(ret
));
574 int setnodelay(struct socket
*socket
)
582 ret
= socket
->ops
->setsockopt(socket
, SOL_TCP
, TCP_NODELAY
,
583 (char __user
*) &val
, sizeof(ret
));
589 int setkeepalive(struct socket
*socket
)
597 ret
= socket
->ops
->setsockopt(socket
, SOL_SOCKET
, SO_KEEPALIVE
,
598 (char __user
*) &val
, sizeof(ret
));
604 void setreuse(struct socket
*socket
)
606 socket
->sk
->sk_reuse
= 1;
610 struct socket
*sockfd_to_socket(unsigned int sockfd
)
612 struct socket
*socket
;
618 printk(KERN_ERR
"%s: invalid sockfd\n", __func__
);
622 inode
= file
->f_dentry
->d_inode
;
624 if (!inode
|| !S_ISSOCK(inode
->i_mode
))
627 socket
= SOCKET_I(inode
);
631 EXPORT_SYMBOL_GPL(sockfd_to_socket
);
635 /*-------------------------------------------------------------------------*/
638 /* there may be more cases to tweak the flags. */
639 static unsigned int tweak_transfer_flags(unsigned int flags
)
642 if (flags
& URB_NO_TRANSFER_DMA_MAP
)
644 * vhci_hcd does not provide DMA-mapped I/O. The upper
645 * driver does not need to set this flag. The remote
646 * usbip.ko does not still perform DMA-mapped I/O for
647 * DMA-caplable host controllers. So, clear this flag.
649 flags
&= ~URB_NO_TRANSFER_DMA_MAP
;
651 if (flags
& URB_NO_SETUP_DMA_MAP
)
652 flags
&= ~URB_NO_SETUP_DMA_MAP
;
657 static void usbip_pack_cmd_submit(struct usbip_header
*pdu
, struct urb
*urb
,
660 struct usbip_header_cmd_submit
*spdu
= &pdu
->u
.cmd_submit
;
663 * Some members are not still implemented in usbip. I hope this issue
664 * will be discussed when usbip is ported to other operating systems.
668 spdu
->transfer_flags
=
669 tweak_transfer_flags(urb
->transfer_flags
);
670 spdu
->transfer_buffer_length
= urb
->transfer_buffer_length
;
671 spdu
->start_frame
= urb
->start_frame
;
672 spdu
->number_of_packets
= urb
->number_of_packets
;
673 spdu
->interval
= urb
->interval
;
676 urb
->transfer_flags
= spdu
->transfer_flags
;
678 urb
->transfer_buffer_length
= spdu
->transfer_buffer_length
;
679 urb
->start_frame
= spdu
->start_frame
;
680 urb
->number_of_packets
= spdu
->number_of_packets
;
681 urb
->interval
= spdu
->interval
;
685 static void usbip_pack_ret_submit(struct usbip_header
*pdu
, struct urb
*urb
,
688 struct usbip_header_ret_submit
*rpdu
= &pdu
->u
.ret_submit
;
693 rpdu
->status
= urb
->status
;
694 rpdu
->actual_length
= urb
->actual_length
;
695 rpdu
->start_frame
= urb
->start_frame
;
696 rpdu
->error_count
= urb
->error_count
;
700 urb
->status
= rpdu
->status
;
701 urb
->actual_length
= rpdu
->actual_length
;
702 urb
->start_frame
= rpdu
->start_frame
;
703 urb
->error_count
= rpdu
->error_count
;
708 void usbip_pack_pdu(struct usbip_header
*pdu
, struct urb
*urb
, int cmd
,
712 case USBIP_CMD_SUBMIT
:
713 usbip_pack_cmd_submit(pdu
, urb
, pack
);
715 case USBIP_RET_SUBMIT
:
716 usbip_pack_ret_submit(pdu
, urb
, pack
);
719 err("unknown command");
724 EXPORT_SYMBOL_GPL(usbip_pack_pdu
);
727 static void correct_endian_basic(struct usbip_header_basic
*base
, int send
)
730 base
->command
= cpu_to_be32(base
->command
);
731 base
->seqnum
= cpu_to_be32(base
->seqnum
);
732 base
->devid
= cpu_to_be32(base
->devid
);
733 base
->direction
= cpu_to_be32(base
->direction
);
734 base
->ep
= cpu_to_be32(base
->ep
);
736 base
->command
= be32_to_cpu(base
->command
);
737 base
->seqnum
= be32_to_cpu(base
->seqnum
);
738 base
->devid
= be32_to_cpu(base
->devid
);
739 base
->direction
= be32_to_cpu(base
->direction
);
740 base
->ep
= be32_to_cpu(base
->ep
);
744 static void correct_endian_cmd_submit(struct usbip_header_cmd_submit
*pdu
,
748 pdu
->transfer_flags
= cpu_to_be32(pdu
->transfer_flags
);
750 cpu_to_be32s(&pdu
->transfer_buffer_length
);
751 cpu_to_be32s(&pdu
->start_frame
);
752 cpu_to_be32s(&pdu
->number_of_packets
);
753 cpu_to_be32s(&pdu
->interval
);
755 pdu
->transfer_flags
= be32_to_cpu(pdu
->transfer_flags
);
757 be32_to_cpus(&pdu
->transfer_buffer_length
);
758 be32_to_cpus(&pdu
->start_frame
);
759 be32_to_cpus(&pdu
->number_of_packets
);
760 be32_to_cpus(&pdu
->interval
);
764 static void correct_endian_ret_submit(struct usbip_header_ret_submit
*pdu
,
768 cpu_to_be32s(&pdu
->status
);
769 cpu_to_be32s(&pdu
->actual_length
);
770 cpu_to_be32s(&pdu
->start_frame
);
771 cpu_to_be32s(&pdu
->error_count
);
773 be32_to_cpus(&pdu
->status
);
774 be32_to_cpus(&pdu
->actual_length
);
775 be32_to_cpus(&pdu
->start_frame
);
776 be32_to_cpus(&pdu
->error_count
);
780 static void correct_endian_cmd_unlink(struct usbip_header_cmd_unlink
*pdu
,
784 pdu
->seqnum
= cpu_to_be32(pdu
->seqnum
);
786 pdu
->seqnum
= be32_to_cpu(pdu
->seqnum
);
789 static void correct_endian_ret_unlink(struct usbip_header_ret_unlink
*pdu
,
793 cpu_to_be32s(&pdu
->status
);
795 be32_to_cpus(&pdu
->status
);
798 void usbip_header_correct_endian(struct usbip_header
*pdu
, int send
)
803 cmd
= pdu
->base
.command
;
805 correct_endian_basic(&pdu
->base
, send
);
808 cmd
= pdu
->base
.command
;
811 case USBIP_CMD_SUBMIT
:
812 correct_endian_cmd_submit(&pdu
->u
.cmd_submit
, send
);
814 case USBIP_RET_SUBMIT
:
815 correct_endian_ret_submit(&pdu
->u
.ret_submit
, send
);
817 case USBIP_CMD_UNLINK
:
818 correct_endian_cmd_unlink(&pdu
->u
.cmd_unlink
, send
);
820 case USBIP_RET_UNLINK
:
821 correct_endian_ret_unlink(&pdu
->u
.ret_unlink
, send
);
825 err("unknown command in pdu header: %d", cmd
);
829 EXPORT_SYMBOL_GPL(usbip_header_correct_endian
);
831 static void usbip_iso_pakcet_correct_endian(
832 struct usbip_iso_packet_descriptor
*iso
,
835 /* does not need all members. but copy all simply. */
837 iso
->offset
= cpu_to_be32(iso
->offset
);
838 iso
->length
= cpu_to_be32(iso
->length
);
839 iso
->status
= cpu_to_be32(iso
->status
);
840 iso
->actual_length
= cpu_to_be32(iso
->actual_length
);
842 iso
->offset
= be32_to_cpu(iso
->offset
);
843 iso
->length
= be32_to_cpu(iso
->length
);
844 iso
->status
= be32_to_cpu(iso
->status
);
845 iso
->actual_length
= be32_to_cpu(iso
->actual_length
);
849 static void usbip_pack_iso(struct usbip_iso_packet_descriptor
*iso
,
850 struct usb_iso_packet_descriptor
*uiso
, int pack
)
853 iso
->offset
= uiso
->offset
;
854 iso
->length
= uiso
->length
;
855 iso
->status
= uiso
->status
;
856 iso
->actual_length
= uiso
->actual_length
;
858 uiso
->offset
= iso
->offset
;
859 uiso
->length
= iso
->length
;
860 uiso
->status
= iso
->status
;
861 uiso
->actual_length
= iso
->actual_length
;
866 /* must free buffer */
867 void *usbip_alloc_iso_desc_pdu(struct urb
*urb
, ssize_t
*bufflen
)
870 struct usbip_iso_packet_descriptor
*iso
;
871 int np
= urb
->number_of_packets
;
872 ssize_t size
= np
* sizeof(*iso
);
875 buff
= kzalloc(size
, GFP_KERNEL
);
879 for (i
= 0; i
< np
; i
++) {
880 iso
= buff
+ (i
* sizeof(*iso
));
882 usbip_pack_iso(iso
, &urb
->iso_frame_desc
[i
], 1);
883 usbip_iso_pakcet_correct_endian(iso
, 1);
890 EXPORT_SYMBOL_GPL(usbip_alloc_iso_desc_pdu
);
892 /* some members of urb must be substituted before. */
893 int usbip_recv_iso(struct usbip_device
*ud
, struct urb
*urb
)
896 struct usbip_iso_packet_descriptor
*iso
;
897 int np
= urb
->number_of_packets
;
898 int size
= np
* sizeof(*iso
);
902 if (!usb_pipeisoc(urb
->pipe
))
905 /* my Bluetooth dongle gets ISO URBs which are np = 0 */
907 /* uinfo("iso np == 0\n"); */
908 /* usbip_dump_urb(urb); */
912 buff
= kzalloc(size
, GFP_KERNEL
);
916 ret
= usbip_xmit(0, ud
->tcp_socket
, buff
, size
, 0);
918 dev_err(&urb
->dev
->dev
, "recv iso_frame_descriptor, %d\n",
922 if (ud
->side
== USBIP_STUB
)
923 usbip_event_add(ud
, SDEV_EVENT_ERROR_TCP
);
925 usbip_event_add(ud
, VDEV_EVENT_ERROR_TCP
);
930 for (i
= 0; i
< np
; i
++) {
931 iso
= buff
+ (i
* sizeof(*iso
));
933 usbip_iso_pakcet_correct_endian(iso
, 0);
934 usbip_pack_iso(iso
, &urb
->iso_frame_desc
[i
], 0);
942 EXPORT_SYMBOL_GPL(usbip_recv_iso
);
945 /* some members of urb must be substituted before. */
946 int usbip_recv_xbuff(struct usbip_device
*ud
, struct urb
*urb
)
951 if (ud
->side
== USBIP_STUB
) {
953 /* the direction of urb must be OUT. */
954 if (usb_pipein(urb
->pipe
))
957 size
= urb
->transfer_buffer_length
;
960 /* the direction of urb must be IN. */
961 if (usb_pipeout(urb
->pipe
))
964 size
= urb
->actual_length
;
967 /* no need to recv xbuff */
971 ret
= usbip_xmit(0, ud
->tcp_socket
, (char *)urb
->transfer_buffer
,
974 dev_err(&urb
->dev
->dev
, "recv xbuf, %d\n", ret
);
975 if (ud
->side
== USBIP_STUB
) {
976 usbip_event_add(ud
, SDEV_EVENT_ERROR_TCP
);
978 usbip_event_add(ud
, VDEV_EVENT_ERROR_TCP
);
985 EXPORT_SYMBOL_GPL(usbip_recv_xbuff
);
988 /*-------------------------------------------------------------------------*/
990 static int __init
usbip_common_init(void)
992 printk(KERN_INFO KBUILD_MODNAME
": " DRIVER_DESC
"" DRIVER_VERSION
);
997 static void __exit
usbip_common_exit(void)
1005 module_init(usbip_common_init
);
1006 module_exit(usbip_common_exit
);
1008 MODULE_AUTHOR(DRIVER_AUTHOR
);
1009 MODULE_DESCRIPTION(DRIVER_DESC
);
1010 MODULE_LICENSE("GPL");