* [PATCH] Add code to support USBIP Project for Windows
@ 2019-03-18 16:37 ` VizXu
0 siblings, 0 replies; 6+ messages in thread
From: VizXu @ 2019-03-18 16:37 UTC (permalink / raw)
To: valentina.manea.m; +Cc: shuah, gregkh, linux-usb, linux-kernel, VizXu
Signed-off-by: VizXu <xujiweigo@163.com>
---
drivers/usb/usbip/stub_dev.c | 4 ++++
drivers/usb/usbip/stub_rx.c | 37 +++++++++++++++++++++++++++++++++++++
drivers/usb/usbip/usbip_common.h | 16 ++++++++++++++++
3 files changed, 57 insertions(+)
diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index c0d6ff1..be95c72 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -270,6 +270,10 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev)
sdev->ud.tcp_socket = NULL;
sdev->ud.sockfd = -1;
+#ifdef SUPPORT_WIN
+ sdev->ud.is_configured = false;
+#endif
+
INIT_LIST_HEAD(&sdev->priv_init);
INIT_LIST_HEAD(&sdev->priv_tx);
INIT_LIST_HEAD(&sdev->priv_free);
diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c
index 97b09a4..8e004bc 100644
--- a/drivers/usb/usbip/stub_rx.c
+++ b/drivers/usb/usbip/stub_rx.c
@@ -11,6 +11,35 @@
#include "usbip_common.h"
#include "stub.h"
+#ifdef SUPPORT_WIN
+static int usbip_device_init_configuration(struct usbip_device *ud)
+{
+ struct usb_ctrlrequest req;
+ __u16 config;
+ int err;
+
+ struct stub_device *sdev = container_of(ud, struct stub_device, ud);
+
+ struct usb_device *udev = sdev->udev;
+
+ req.bRequest = USB_REQ_SET_CONFIGURATION;
+ req.bRequestType = USB_RECIP_DEVICE;
+ req.wIndex = 0x00;
+ req.wLength = 0x00;
+ req.wValue = 0x01;
+ config = le16_to_cpu(req.wValue);
+
+ err = usb_set_configuration(udev, config);
+ if (err && err != -ENODEV) {
+ dev_err(&udev->dev, "%s can't set config\n", "usbip_device_init_configuration");
+ return -1;
+ }
+ ud->is_configured = true;
+
+ return 0;
+}
+#endif
+
static int is_clear_halt_cmd(struct urb *urb)
{
struct usb_ctrlrequest *req;
@@ -579,6 +608,14 @@ int stub_rx_loop(void *data)
{
struct usbip_device *ud = data;
+#ifdef SUPPORT_WIN
+ if (!ud->is_configured) {
+ if (-1 == usbip_device_init_configuration(ud)) {
+ usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
+ }
+ }
+#endif
+
while (!kthread_should_stop()) {
if (usbip_event_happened(ud))
break;
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
index bf8afe9..b5189e6 100644
--- a/drivers/usb/usbip/usbip_common.h
+++ b/drivers/usb/usbip/usbip_common.h
@@ -122,6 +122,17 @@ extern struct device_attribute dev_attr_usbip_debug;
#define USBIP_DIR_IN 0x01
/**
+* Support USBIP project for Windows: http://usbip.sourceforge.net/
+* The configuration is not initialized after an USB device bound in Linux
+* and that would make Linux kernel crash if usbip.exe attach it.
+* I've analysized this process with wireshark and found that usbip.exe
+* would not "SET CONFIGURATION Request". I suppose the process of loading
+* a USB device is different between Linux and Windows.
+* Make a usb_set_configuration at the first time would fix this issue.
+*/
+#define SUPPORT_WIN
+
+/**
* struct usbip_header_basic - data pertinent to every request
* @command: the usbip request type
* @seqnum: sequential number that identifies requests; incremented per
@@ -257,6 +268,11 @@ struct usbip_device {
spinlock_t lock;
int sockfd;
+
+#ifdef SUPPORT_WIN
+ bool is_configured;
+#endif
+
struct socket *tcp_socket;
struct task_struct *tcp_rx;
--
2.7.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Add code to support USBIP Project for Windows
@ 2019-03-18 16:37 ` VizXu
0 siblings, 0 replies; 6+ messages in thread
From: VizXu @ 2019-03-18 16:37 UTC (permalink / raw)
To: valentina.manea.m; +Cc: shuah, gregkh, linux-usb, linux-kernel, VizXu
Signed-off-by: VizXu <xujiweigo@163.com>
---
drivers/usb/usbip/stub_dev.c | 4 ++++
drivers/usb/usbip/stub_rx.c | 37 +++++++++++++++++++++++++++++++++++++
drivers/usb/usbip/usbip_common.h | 16 ++++++++++++++++
3 files changed, 57 insertions(+)
diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index c0d6ff1..be95c72 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -270,6 +270,10 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev)
sdev->ud.tcp_socket = NULL;
sdev->ud.sockfd = -1;
+#ifdef SUPPORT_WIN
+ sdev->ud.is_configured = false;
+#endif
+
INIT_LIST_HEAD(&sdev->priv_init);
INIT_LIST_HEAD(&sdev->priv_tx);
INIT_LIST_HEAD(&sdev->priv_free);
diff --git a/drivers/usb/usbip/stub_rx.c b/drivers/usb/usbip/stub_rx.c
index 97b09a4..8e004bc 100644
--- a/drivers/usb/usbip/stub_rx.c
+++ b/drivers/usb/usbip/stub_rx.c
@@ -11,6 +11,35 @@
#include "usbip_common.h"
#include "stub.h"
+#ifdef SUPPORT_WIN
+static int usbip_device_init_configuration(struct usbip_device *ud)
+{
+ struct usb_ctrlrequest req;
+ __u16 config;
+ int err;
+
+ struct stub_device *sdev = container_of(ud, struct stub_device, ud);
+
+ struct usb_device *udev = sdev->udev;
+
+ req.bRequest = USB_REQ_SET_CONFIGURATION;
+ req.bRequestType = USB_RECIP_DEVICE;
+ req.wIndex = 0x00;
+ req.wLength = 0x00;
+ req.wValue = 0x01;
+ config = le16_to_cpu(req.wValue);
+
+ err = usb_set_configuration(udev, config);
+ if (err && err != -ENODEV) {
+ dev_err(&udev->dev, "%s can't set config\n", "usbip_device_init_configuration");
+ return -1;
+ }
+ ud->is_configured = true;
+
+ return 0;
+}
+#endif
+
static int is_clear_halt_cmd(struct urb *urb)
{
struct usb_ctrlrequest *req;
@@ -579,6 +608,14 @@ int stub_rx_loop(void *data)
{
struct usbip_device *ud = data;
+#ifdef SUPPORT_WIN
+ if (!ud->is_configured) {
+ if (-1 == usbip_device_init_configuration(ud)) {
+ usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
+ }
+ }
+#endif
+
while (!kthread_should_stop()) {
if (usbip_event_happened(ud))
break;
diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
index bf8afe9..b5189e6 100644
--- a/drivers/usb/usbip/usbip_common.h
+++ b/drivers/usb/usbip/usbip_common.h
@@ -122,6 +122,17 @@ extern struct device_attribute dev_attr_usbip_debug;
#define USBIP_DIR_IN 0x01
/**
+* Support USBIP project for Windows: http://usbip.sourceforge.net/
+* The configuration is not initialized after an USB device bound in Linux
+* and that would make Linux kernel crash if usbip.exe attach it.
+* I've analysized this process with wireshark and found that usbip.exe
+* would not "SET CONFIGURATION Request". I suppose the process of loading
+* a USB device is different between Linux and Windows.
+* Make a usb_set_configuration at the first time would fix this issue.
+*/
+#define SUPPORT_WIN
+
+/**
* struct usbip_header_basic - data pertinent to every request
* @command: the usbip request type
* @seqnum: sequential number that identifies requests; incremented per
@@ -257,6 +268,11 @@ struct usbip_device {
spinlock_t lock;
int sockfd;
+
+#ifdef SUPPORT_WIN
+ bool is_configured;
+#endif
+
struct socket *tcp_socket;
struct task_struct *tcp_rx;
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Add code to support USBIP Project for Windows
@ 2019-03-18 16:52 ` Randy Dunlap
0 siblings, 0 replies; 6+ messages in thread
From: Randy Dunlap @ 2019-03-18 16:52 UTC (permalink / raw)
To: VizXu, valentina.manea.m; +Cc: shuah, gregkh, linux-usb, linux-kernel
On 3/18/19 9:37 AM, VizXu wrote:
> Signed-off-by: VizXu <xujiweigo@163.com>
> ---
> drivers/usb/usbip/stub_dev.c | 4 ++++
> drivers/usb/usbip/stub_rx.c | 37 +++++++++++++++++++++++++++++++++++++
> drivers/usb/usbip/usbip_common.h | 16 ++++++++++++++++
> 3 files changed, 57 insertions(+)
>
> diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
> index bf8afe9..b5189e6 100644
> --- a/drivers/usb/usbip/usbip_common.h
> +++ b/drivers/usb/usbip/usbip_common.h
> @@ -122,6 +122,17 @@ extern struct device_attribute dev_attr_usbip_debug;
> #define USBIP_DIR_IN 0x01
>
> /**
This comment block is not kernel-doc notation so it should not begin
with /**.
> +* Support USBIP project for Windows: http://usbip.sourceforge.net/
> +* The configuration is not initialized after an USB device bound in Linux
> +* and that would make Linux kernel crash if usbip.exe attach it.
> +* I've analysized this process with wireshark and found that usbip.exe
analyzed
> +* would not "SET CONFIGURATION Request". I suppose the process of loading
> +* a USB device is different between Linux and Windows.
> +* Make a usb_set_configuration at the first time would fix this issue.
> +*/
> +#define SUPPORT_WIN
> +
> +/**
> * struct usbip_header_basic - data pertinent to every request
> * @command: the usbip request type
> * @seqnum: sequential number that identifies requests; incremented per
> @@ -257,6 +268,11 @@ struct usbip_device {
> spinlock_t lock;
>
> int sockfd;
> +
> +#ifdef SUPPORT_WIN
> + bool is_configured;
> +#endif
> +
> struct socket *tcp_socket;
>
> struct task_struct *tcp_rx;
>
--
~Randy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Add code to support USBIP Project for Windows
@ 2019-03-18 16:52 ` Randy Dunlap
0 siblings, 0 replies; 6+ messages in thread
From: Randy Dunlap @ 2019-03-18 16:52 UTC (permalink / raw)
To: VizXu, valentina.manea.m; +Cc: shuah, gregkh, linux-usb, linux-kernel
On 3/18/19 9:37 AM, VizXu wrote:
> Signed-off-by: VizXu <xujiweigo@163.com>
> ---
> drivers/usb/usbip/stub_dev.c | 4 ++++
> drivers/usb/usbip/stub_rx.c | 37 +++++++++++++++++++++++++++++++++++++
> drivers/usb/usbip/usbip_common.h | 16 ++++++++++++++++
> 3 files changed, 57 insertions(+)
>
> diff --git a/drivers/usb/usbip/usbip_common.h b/drivers/usb/usbip/usbip_common.h
> index bf8afe9..b5189e6 100644
> --- a/drivers/usb/usbip/usbip_common.h
> +++ b/drivers/usb/usbip/usbip_common.h
> @@ -122,6 +122,17 @@ extern struct device_attribute dev_attr_usbip_debug;
> #define USBIP_DIR_IN 0x01
>
> /**
This comment block is not kernel-doc notation so it should not begin
with /**.
> +* Support USBIP project for Windows: http://usbip.sourceforge.net/
> +* The configuration is not initialized after an USB device bound in Linux
> +* and that would make Linux kernel crash if usbip.exe attach it.
> +* I've analysized this process with wireshark and found that usbip.exe
analyzed
> +* would not "SET CONFIGURATION Request". I suppose the process of loading
> +* a USB device is different between Linux and Windows.
> +* Make a usb_set_configuration at the first time would fix this issue.
> +*/
> +#define SUPPORT_WIN
> +
> +/**
> * struct usbip_header_basic - data pertinent to every request
> * @command: the usbip request type
> * @seqnum: sequential number that identifies requests; incremented per
> @@ -257,6 +268,11 @@ struct usbip_device {
> spinlock_t lock;
>
> int sockfd;
> +
> +#ifdef SUPPORT_WIN
> + bool is_configured;
> +#endif
> +
> struct socket *tcp_socket;
>
> struct task_struct *tcp_rx;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Add code to support USBIP Project for Windows
@ 2019-03-18 17:42 ` Greg Kroah-Hartman
0 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-03-18 17:42 UTC (permalink / raw)
To: VizXu; +Cc: valentina.manea.m, shuah, linux-usb, linux-kernel
On Mon, Mar 18, 2019 at 09:37:28AM -0700, VizXu wrote:
> Signed-off-by: VizXu <xujiweigo@163.com>
> ---
I can not take patches without any changelog text, sorry.
Please fix up and resend so we have an idea of what this patch is for
and why it is needed.
> drivers/usb/usbip/stub_dev.c | 4 ++++
> drivers/usb/usbip/stub_rx.c | 37 +++++++++++++++++++++++++++++++++++++
> drivers/usb/usbip/usbip_common.h | 16 ++++++++++++++++
> 3 files changed, 57 insertions(+)
>
> diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
> index c0d6ff1..be95c72 100644
> --- a/drivers/usb/usbip/stub_dev.c
> +++ b/drivers/usb/usbip/stub_dev.c
> @@ -270,6 +270,10 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev)
> sdev->ud.tcp_socket = NULL;
> sdev->ud.sockfd = -1;
>
> +#ifdef SUPPORT_WIN
> + sdev->ud.is_configured = false;
> +#endif
#ifdef should never be in a .c file if at all possible. Please rework
this to use the proper style of doing this type of thing in a .h file.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Add code to support USBIP Project for Windows
@ 2019-03-18 17:42 ` Greg Kroah-Hartman
0 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2019-03-18 17:42 UTC (permalink / raw)
To: VizXu; +Cc: valentina.manea.m, shuah, linux-usb, linux-kernel
On Mon, Mar 18, 2019 at 09:37:28AM -0700, VizXu wrote:
> Signed-off-by: VizXu <xujiweigo@163.com>
> ---
I can not take patches without any changelog text, sorry.
Please fix up and resend so we have an idea of what this patch is for
and why it is needed.
> drivers/usb/usbip/stub_dev.c | 4 ++++
> drivers/usb/usbip/stub_rx.c | 37 +++++++++++++++++++++++++++++++++++++
> drivers/usb/usbip/usbip_common.h | 16 ++++++++++++++++
> 3 files changed, 57 insertions(+)
>
> diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
> index c0d6ff1..be95c72 100644
> --- a/drivers/usb/usbip/stub_dev.c
> +++ b/drivers/usb/usbip/stub_dev.c
> @@ -270,6 +270,10 @@ static struct stub_device *stub_device_alloc(struct usb_device *udev)
> sdev->ud.tcp_socket = NULL;
> sdev->ud.sockfd = -1;
>
> +#ifdef SUPPORT_WIN
> + sdev->ud.is_configured = false;
> +#endif
#ifdef should never be in a .c file if at all possible. Please rework
this to use the proper style of doing this type of thing in a .h file.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-03-18 17:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-18 16:37 [PATCH] Add code to support USBIP Project for Windows VizXu
2019-03-18 16:37 ` VizXu
2019-03-18 16:52 ` [PATCH] " Randy Dunlap
2019-03-18 16:52 ` Randy Dunlap
2019-03-18 17:42 ` [PATCH] " Greg KH
2019-03-18 17:42 ` Greg Kroah-Hartman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.