static int send_reply_devlist(int sockfd) { int ret; struct usbip_exported_device *edev; struct op_devlist_reply reply; reply.ndev = 0; /* how many devices are exported ? */ dlist_for_each_data(stub_driver->edev_list, edev, struct usbip_exported_device) { reply.ndev += 1; } dbg("%d devices are exported", reply.ndev); ret = usbip_send_op_common(sockfd, OP_REP_DEVLIST, ST_OK); if (ret < 0) { err("send op_common"); return ret; } PACK_OP_DEVLIST_REPLY(1, &reply); ret = usbip_send(sockfd, (void *) &reply, sizeof(reply)); if (ret < 0) { err("send op_devlist_reply"); return ret; } dlist_for_each_data(stub_driver->edev_list, edev, struct usbip_exported_device) { struct usb_device pdu_udev; dump_usb_device(&edev->udev); memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev)); pack_usb_device(1, &pdu_udev); ret = usbip_send(sockfd, (void *) &pdu_udev, sizeof(pdu_udev)); if (ret < 0) { err("send pdu_udev"); return ret; } for (int i=0; i < edev->udev.bNumInterfaces; i++) { struct usb_interface pdu_uinf; dump_usb_interface(&edev->uinf[i]); memcpy(&pdu_uinf, &edev->uinf[i], sizeof(pdu_uinf)); pack_usb_interface(1, &pdu_uinf); ret = usbip_send(sockfd, (void *) &pdu_uinf, sizeof(pdu_uinf)); if (ret < 0) { err("send pdu_uinf"); return ret; } } } return 0; }
static int send_reply_devlist(int connfd) { struct usbip_exported_device *edev; struct usbip_usb_device pdu_udev; struct usbip_usb_interface pdu_uinf; struct op_devlist_reply reply; int i; int rc; reply.ndev = 0; /* number of exported devices */ dlist_for_each_data(host_driver->edev_list, edev, struct usbip_exported_device) { reply.ndev += 1; } info("exportable devices: %d", reply.ndev); rc = usbip_net_send_op_common(connfd, OP_REP_DEVLIST, ST_OK); if (rc < 0) { dbg("usbip_net_send_op_common failed: %#0x", OP_REP_DEVLIST); return -1; } PACK_OP_DEVLIST_REPLY(1, &reply); rc = usbip_net_send(connfd, &reply, sizeof(reply)); if (rc < 0) { dbg("usbip_net_send failed: %#0x", OP_REP_DEVLIST); return -1; } dlist_for_each_data(host_driver->edev_list, edev, struct usbip_exported_device) { dump_usb_device(&edev->udev); memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev)); usbip_net_pack_usb_device(1, &pdu_udev); rc = usbip_net_send(connfd, &pdu_udev, sizeof(pdu_udev)); if (rc < 0) { dbg("usbip_net_send failed: pdu_udev"); return -1; } for (i = 0; i < edev->udev.bNumInterfaces; i++) { dump_usb_interface(&edev->uinf[i]); memcpy(&pdu_uinf, &edev->uinf[i], sizeof(pdu_uinf)); usbip_net_pack_usb_interface(1, &pdu_uinf); rc = usbip_net_send(connfd, &pdu_uinf, sizeof(pdu_uinf)); if (rc < 0) { dbg("usbip_net_send failed: pdu_uinf"); return -1; } } } return 0; }