1
0
Fork 0

staging: usbip: userspace: usbip_list.c: cleanup exported device functions

Rename functions and cleanup coding style.

Signed-off-by: matt mooney <mfm@muteddisk.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
hifive-unleashed-5.1
matt mooney 2011-05-27 01:44:15 -07:00 committed by Greg Kroah-Hartman
parent 35dd0c2da6
commit 1109566469
1 changed files with 46 additions and 52 deletions

View File

@ -45,45 +45,43 @@ void usbip_list_usage(void)
printf("usage: %s", usbip_list_usage_string); printf("usage: %s", usbip_list_usage_string);
} }
static int query_exported_devices(int sockfd) static int get_exported_devices(int sockfd)
{ {
int ret; char product_name[100];
char class_name[100];
struct op_devlist_reply rep; struct op_devlist_reply rep;
uint16_t code = OP_REP_DEVLIST; uint16_t code = OP_REP_DEVLIST;
struct usbip_usb_device udev;
struct usbip_usb_interface uintf;
unsigned int i;
int j, rc;
rc = usbip_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
if (rc < 0) {
dbg("usbip_send_op_common");
return -1;
}
rc = usbip_recv_op_common(sockfd, &code);
if (rc < 0) {
dbg("usbip_recv_op_common");
return -1;
}
memset(&rep, 0, sizeof(rep)); memset(&rep, 0, sizeof(rep));
rc = usbip_recv(sockfd, &rep, sizeof(rep));
ret = usbip_send_op_common(sockfd, OP_REQ_DEVLIST, 0); if (rc < 0) {
if (ret < 0) { dbg("usbip_recv_op_devlist");
err("send op_common");
return -1; return -1;
} }
ret = usbip_recv_op_common(sockfd, &code);
if (ret < 0) {
err("recv op_common");
return -1;
}
ret = usbip_recv(sockfd, (void *) &rep, sizeof(rep));
if (ret < 0) {
err("recv op_devlist");
return -1;
}
PACK_OP_DEVLIST_REPLY(0, &rep); PACK_OP_DEVLIST_REPLY(0, &rep);
dbg("exportable %d devices", rep.ndev); dbg("exportable devices: %d", rep.ndev);
for (unsigned int i=0; i < rep.ndev; i++) {
char product_name[100];
char class_name[100];
struct usbip_usb_device udev;
for (i = 0; i < rep.ndev; i++) {
memset(&udev, 0, sizeof(udev)); memset(&udev, 0, sizeof(udev));
rc = usbip_recv(sockfd, &udev, sizeof(udev));
ret = usbip_recv(sockfd, (void *) &udev, sizeof(udev)); if (rc < 0) {
if (ret < 0) { dbg("usbip_recv: usbip_usb_device[%d]", i);
err("recv usbip_usb_device[%d]", i);
return -1; return -1;
} }
pack_usb_device(0, &udev); pack_usb_device(0, &udev);
@ -93,38 +91,34 @@ static int query_exported_devices(int sockfd)
usbip_names_get_class(class_name, sizeof(class_name), usbip_names_get_class(class_name, sizeof(class_name),
udev.bDeviceClass, udev.bDeviceSubClass, udev.bDeviceClass, udev.bDeviceSubClass,
udev.bDeviceProtocol); udev.bDeviceProtocol);
printf("%8s: %s\n", udev.busid, product_name); printf("%8s: %s\n", udev.busid, product_name);
printf("%8s: %s\n", " ", udev.path); printf("%8s: %s\n", "", udev.path);
printf("%8s: %s\n", " ", class_name); printf("%8s: %s\n", "", class_name);
for (int j=0; j < udev.bNumInterfaces; j++) { for (j = 0; j < udev.bNumInterfaces; j++) {
struct usbip_usb_interface uinf; rc = usbip_recv(sockfd, &uintf, sizeof(uintf));
if (rc < 0) {
ret = usbip_recv(sockfd, (void *) &uinf, sizeof(uinf)); dbg("usbip_recv: usbip_usb_interface[%d]", j);
if (ret < 0) {
err("recv usbip_usb_interface[%d]", j);
return -1; return -1;
} }
pack_usb_interface(0, &uintf);
pack_usb_interface(0, &uinf);
usbip_names_get_class(class_name, sizeof(class_name), usbip_names_get_class(class_name, sizeof(class_name),
uinf.bInterfaceClass, uintf.bInterfaceClass,
uinf.bInterfaceSubClass, uintf.bInterfaceSubClass,
uinf.bInterfaceProtocol); uintf.bInterfaceProtocol);
printf("%8s: %2d - %s\n", "", j, class_name);
printf("%8s: %2d - %s\n", " ", j, class_name);
} }
printf("\n"); printf("\n");
} }
return rep.ndev; return 0;
} }
static int show_exported_devices(char *host) static int list_exported_devices(char *host)
{ {
int ret; int rc;
int sockfd; int sockfd;
sockfd = usbip_net_tcp_connect(host, USBIP_PORT_STRING); sockfd = usbip_net_tcp_connect(host, USBIP_PORT_STRING);
@ -134,16 +128,16 @@ static int show_exported_devices(char *host)
return -1; return -1;
} }
dbg("connected to %s port %s\n", host, USBIP_PORT_STRING); dbg("connected to %s port %s\n", host, USBIP_PORT_STRING);
printf("- %s\n", host); printf("- %s\n", host);
ret = query_exported_devices(sockfd); rc = get_exported_devices(sockfd);
if (ret < 0) { if (rc < 0) {
err("query"); dbg("get_exported_devices failed");
return -1; return -1;
} }
close(sockfd); close(sockfd);
return 0; return 0;
} }
@ -273,7 +267,7 @@ int usbip_list(int argc, char *argv[])
parsable = true; parsable = true;
break; break;
case 'r': case 'r':
ret = show_exported_devices(optarg); ret = list_exported_devices(optarg);
goto out; goto out;
case 'l': case 'l':
ret = list_devices(parsable); ret = list_devices(parsable);