aboutsummaryrefslogtreecommitdiffstats
path: root/tools/usb/usbip/src
diff options
context:
space:
mode:
authorKrzysztof Opasiak <k.opasiak@samsung.com>2016-03-08 15:49:04 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-04-26 18:19:50 -0400
commit3391ba0e2792411dc3372b76a4662971d6eaa405 (patch)
treefbdcc3eaa65fbd29882b06f0300fef4afc91fb71 /tools/usb/usbip/src
parentea6873a45a22f35c8ab0f9c025df6a6c6dd532f3 (diff)
usbip: tools: Extract generic code to be shared with vudc backend
Extract the code from current stub driver backend and a common interface for both stub driver and vudc. This allows to share most of the usbipd code for both of them. Based on code created in cooperation with Open Operating Systems Student Society at University of Warsaw (O2S3@UW) consisting of: Igor Kotrasinski <ikotrasinsk@gmail.com> Karol Kosik <karo9@interia.eu> Ewelina Kosmider <3w3lfin@gmail.com> Dawid Lazarczyk <lazarczyk.dawid@gmail.com> Piotr Szulc <ps347277@students.mimuw.edu.pl> Tutor and project owner: Krzysztof Opasiak <k.opasiak@samsung.com> Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/usb/usbip/src')
-rw-r--r--tools/usb/usbip/src/usbipd.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index 2a7cd2b8d966..8a2ec4dab4bd 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -1,6 +1,9 @@
1/* 1/*
2 * Copyright (C) 2011 matt mooney <mfm@muteddisk.com> 2 * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
3 * 2005-2007 Takahiro Hirofuchi 3 * 2005-2007 Takahiro Hirofuchi
4 * Copyright (C) 2015-2016 Samsung Electronics
5 * Igor Kotrasinski <i.kotrasinsk@samsung.com>
6 * Krzysztof Opasiak <k.opasiak@samsung.com>
4 * 7 *
5 * This program is free software: you can redistribute it and/or modify 8 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
@@ -41,6 +44,7 @@
41#include <poll.h> 44#include <poll.h>
42 45
43#include "usbip_host_driver.h" 46#include "usbip_host_driver.h"
47#include "usbip_host_common.h"
44#include "usbip_common.h" 48#include "usbip_common.h"
45#include "usbip_network.h" 49#include "usbip_network.h"
46#include "list.h" 50#include "list.h"
@@ -83,6 +87,8 @@ static const char usbipd_help_string[] =
83 " -v, --version\n" 87 " -v, --version\n"
84 " Show version.\n"; 88 " Show version.\n";
85 89
90static struct usbip_host_driver *driver;
91
86static void usbipd_help(void) 92static void usbipd_help(void)
87{ 93{
88 printf("%s\n", usbipd_help_string); 94 printf("%s\n", usbipd_help_string);
@@ -107,7 +113,7 @@ static int recv_request_import(int sockfd)
107 } 113 }
108 PACK_OP_IMPORT_REQUEST(0, &req); 114 PACK_OP_IMPORT_REQUEST(0, &req);
109 115
110 list_for_each(i, &host_driver->edev_list) { 116 list_for_each(i, &driver->edev_list) {
111 edev = list_entry(i, struct usbip_exported_device, node); 117 edev = list_entry(i, struct usbip_exported_device, node);
112 if (!strncmp(req.busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) { 118 if (!strncmp(req.busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) {
113 info("found requested device: %s", req.busid); 119 info("found requested device: %s", req.busid);
@@ -121,7 +127,7 @@ static int recv_request_import(int sockfd)
121 usbip_net_set_nodelay(sockfd); 127 usbip_net_set_nodelay(sockfd);
122 128
123 /* export device needs a TCP/IP socket descriptor */ 129 /* export device needs a TCP/IP socket descriptor */
124 rc = usbip_host_export_device(edev, sockfd); 130 rc = usbip_export_device(edev, sockfd);
125 if (rc < 0) 131 if (rc < 0)
126 error = 1; 132 error = 1;
127 } else { 133 } else {
@@ -166,7 +172,7 @@ static int send_reply_devlist(int connfd)
166 172
167 reply.ndev = 0; 173 reply.ndev = 0;
168 /* number of exported devices */ 174 /* number of exported devices */
169 list_for_each(j, &host_driver->edev_list) { 175 list_for_each(j, &driver->edev_list) {
170 reply.ndev += 1; 176 reply.ndev += 1;
171 } 177 }
172 info("exportable devices: %d", reply.ndev); 178 info("exportable devices: %d", reply.ndev);
@@ -184,7 +190,7 @@ static int send_reply_devlist(int connfd)
184 return -1; 190 return -1;
185 } 191 }
186 192
187 list_for_each(j, &host_driver->edev_list) { 193 list_for_each(j, &driver->edev_list) {
188 edev = list_entry(j, struct usbip_exported_device, node); 194 edev = list_entry(j, struct usbip_exported_device, node);
189 dump_usb_device(&edev->udev); 195 dump_usb_device(&edev->udev);
190 memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev)); 196 memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev));
@@ -246,7 +252,7 @@ static int recv_pdu(int connfd)
246 return -1; 252 return -1;
247 } 253 }
248 254
249 ret = usbip_host_refresh_device_list(); 255 ret = usbip_refresh_device_list(driver);
250 if (ret < 0) { 256 if (ret < 0) {
251 dbg("could not refresh device list: %d", ret); 257 dbg("could not refresh device list: %d", ret);
252 return -1; 258 return -1;
@@ -491,16 +497,13 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
491 struct timespec timeout; 497 struct timespec timeout;
492 sigset_t sigmask; 498 sigset_t sigmask;
493 499
494 if (usbip_host_driver_open()) { 500 if (usbip_driver_open(driver))
495 err("please load " USBIP_CORE_MOD_NAME ".ko and "
496 USBIP_HOST_DRV_NAME ".ko!");
497 return -1; 501 return -1;
498 }
499 502
500 if (daemonize) { 503 if (daemonize) {
501 if (daemon(0, 0) < 0) { 504 if (daemon(0, 0) < 0) {
502 err("daemonizing failed: %s", strerror(errno)); 505 err("daemonizing failed: %s", strerror(errno));
503 usbip_host_driver_close(); 506 usbip_driver_close(driver);
504 return -1; 507 return -1;
505 } 508 }
506 umask(0); 509 umask(0);
@@ -525,7 +528,7 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
525 528
526 ai_head = do_getaddrinfo(NULL, family); 529 ai_head = do_getaddrinfo(NULL, family);
527 if (!ai_head) { 530 if (!ai_head) {
528 usbip_host_driver_close(); 531 usbip_driver_close(driver);
529 return -1; 532 return -1;
530 } 533 }
531 nsockfd = listen_all_addrinfo(ai_head, sockfdlist, 534 nsockfd = listen_all_addrinfo(ai_head, sockfdlist,
@@ -533,7 +536,7 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
533 freeaddrinfo(ai_head); 536 freeaddrinfo(ai_head);
534 if (nsockfd <= 0) { 537 if (nsockfd <= 0) {
535 err("failed to open a listening socket"); 538 err("failed to open a listening socket");
536 usbip_host_driver_close(); 539 usbip_driver_close(driver);
537 return -1; 540 return -1;
538 } 541 }
539 542
@@ -574,7 +577,7 @@ static int do_standalone_mode(int daemonize, int ipv4, int ipv6)
574 577
575 info("shutting down " PROGNAME); 578 info("shutting down " PROGNAME);
576 free(fds); 579 free(fds);
577 usbip_host_driver_close(); 580 usbip_driver_close(driver);
578 581
579 return 0; 582 return 0;
580} 583}
@@ -613,6 +616,7 @@ int main(int argc, char *argv[])
613 err("not running as root?"); 616 err("not running as root?");
614 617
615 cmd = cmd_standalone_mode; 618 cmd = cmd_standalone_mode;
619 driver = &host_driver;
616 for (;;) { 620 for (;;) {
617 opt = getopt_long(argc, argv, "46DdP::t:hv", longopts, NULL); 621 opt = getopt_long(argc, argv, "46DdP::t:hv", longopts, NULL);
618 622