memset(&reply, 0, sizeof(reply));
/* send a request */
- rc = usbip_send_op_common(sockfd, OP_REQ_IMPORT, 0);
+ rc = usbip_net_send_op_common(sockfd, OP_REQ_IMPORT, 0);
if (rc < 0) {
err("send op_common");
return -1;
PACK_OP_IMPORT_REQUEST(0, &request);
- rc = usbip_send(sockfd, (void *) &request, sizeof(request));
+ rc = usbip_net_send(sockfd, (void *) &request, sizeof(request));
if (rc < 0) {
err("send op_import_request");
return -1;
}
- /* receive a reply */
- rc = usbip_recv_op_common(sockfd, &code);
+ /* recieve a reply */
+ rc = usbip_net_recv_op_common(sockfd, &code);
if (rc < 0) {
err("recv op_common");
return -1;
}
- rc = usbip_recv(sockfd, (void *) &reply, sizeof(reply));
+ rc = usbip_net_recv(sockfd, (void *) &reply, sizeof(reply));
if (rc < 0) {
err("recv op_import_reply");
return -1;
unsigned int i;
int j, rc;
- rc = usbip_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
+ rc = usbip_net_send_op_common(sockfd, OP_REQ_DEVLIST, 0);
if (rc < 0) {
- dbg("usbip_send_op_common failed");
+ dbg("usbip_net_send_op_common failed");
return -1;
}
- rc = usbip_recv_op_common(sockfd, &code);
+ rc = usbip_net_recv_op_common(sockfd, &code);
if (rc < 0) {
- dbg("usbip_recv_op_common failed");
+ dbg("usbip_net_recv_op_common failed");
return -1;
}
memset(&reply, 0, sizeof(reply));
- rc = usbip_recv(sockfd, &reply, sizeof(reply));
+ rc = usbip_net_recv(sockfd, &reply, sizeof(reply));
if (rc < 0) {
- dbg("usbip_recv_op_devlist failed");
+ dbg("usbip_net_recv_op_devlist failed");
return -1;
}
PACK_OP_DEVLIST_REPLY(0, &reply);
for (i = 0; i < reply.ndev; i++) {
memset(&udev, 0, sizeof(udev));
- rc = usbip_recv(sockfd, &udev, sizeof(udev));
+ rc = usbip_net_recv(sockfd, &udev, sizeof(udev));
if (rc < 0) {
- dbg("usbip_recv failed: usbip_usb_device[%d]", i);
+ dbg("usbip_net_recv failed: usbip_usb_device[%d]", i);
return -1;
}
- pack_usb_device(0, &udev);
+ usbip_net_pack_usb_device(0, &udev);
usbip_names_get_product(product_name, sizeof(product_name),
udev.idVendor, udev.idProduct);
printf("%8s: %s\n", "", class_name);
for (j = 0; j < udev.bNumInterfaces; j++) {
- rc = usbip_recv(sockfd, &uintf, sizeof(uintf));
+ rc = usbip_net_recv(sockfd, &uintf, sizeof(uintf));
if (rc < 0) {
- dbg("usbip_recv failed: usbip_usb_intf[%d]", j);
+ dbg("usbip_net_recv failed: usbip_usb_intf[%d]",
+ j);
+
return -1;
}
- pack_usb_interface(0, &uintf);
+ usbip_net_pack_usb_interface(0, &uintf);
usbip_names_get_class(class_name, sizeof(class_name),
uintf.bInterfaceClass,
#include "usbip_common.h"
#include "usbip_network.h"
-void pack_uint32_t(int pack, uint32_t *num)
+void usbip_net_pack_uint32_t(int pack, uint32_t *num)
{
uint32_t i;
*num = i;
}
-void pack_uint16_t(int pack, uint16_t *num)
+void usbip_net_pack_uint16_t(int pack, uint16_t *num)
{
uint16_t i;
*num = i;
}
-void pack_usb_device(int pack, struct usbip_usb_device *udev)
+void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev)
{
- pack_uint32_t(pack, &udev->busnum);
- pack_uint32_t(pack, &udev->devnum);
- pack_uint32_t(pack, &udev->speed );
+ usbip_net_pack_uint32_t(pack, &udev->busnum);
+ usbip_net_pack_uint32_t(pack, &udev->devnum);
+ usbip_net_pack_uint32_t(pack, &udev->speed );
- pack_uint16_t(pack, &udev->idVendor );
- pack_uint16_t(pack, &udev->idProduct);
- pack_uint16_t(pack, &udev->bcdDevice);
+ usbip_net_pack_uint16_t(pack, &udev->idVendor);
+ usbip_net_pack_uint16_t(pack, &udev->idProduct);
+ usbip_net_pack_uint16_t(pack, &udev->bcdDevice);
}
-void pack_usb_interface(int pack __attribute__((unused)),
- struct usbip_usb_interface *udev __attribute__((unused)))
+void usbip_net_pack_usb_interface(int pack __attribute__((unused)),
+ struct usbip_usb_interface *udev
+ __attribute__((unused)))
{
/* uint8_t members need nothing */
}
-static ssize_t usbip_xmit(int sockfd, void *buff, size_t bufflen, int sending)
+static ssize_t usbip_net_xmit(int sockfd, void *buff, size_t bufflen,
+ int sending)
{
ssize_t nbytes;
ssize_t total = 0;
return total;
}
-ssize_t usbip_recv(int sockfd, void *buff, size_t bufflen)
+ssize_t usbip_net_recv(int sockfd, void *buff, size_t bufflen)
{
- return usbip_xmit(sockfd, buff, bufflen, 0);
+ return usbip_net_xmit(sockfd, buff, bufflen, 0);
}
-ssize_t usbip_send(int sockfd, void *buff, size_t bufflen)
+ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen)
{
- return usbip_xmit(sockfd, buff, bufflen, 1);
+ return usbip_net_xmit(sockfd, buff, bufflen, 1);
}
-int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status)
+int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status)
{
struct op_common op_common;
int rc;
PACK_OP_COMMON(1, &op_common);
- rc = usbip_send(sockfd, &op_common, sizeof(op_common));
+ rc = usbip_net_send(sockfd, &op_common, sizeof(op_common));
if (rc < 0) {
- dbg("usbip_send failed: %d", rc);
+ dbg("usbip_net_send failed: %d", rc);
return -1;
}
return 0;
}
-int usbip_recv_op_common(int sockfd, uint16_t *code)
+int usbip_net_recv_op_common(int sockfd, uint16_t *code)
{
struct op_common op_common;
int rc;
memset(&op_common, 0, sizeof(op_common));
- rc = usbip_recv(sockfd, &op_common, sizeof(op_common));
+ rc = usbip_net_recv(sockfd, &op_common, sizeof(op_common));
if (rc < 0) {
- dbg("usbip_recv failed: %d", rc);
+ dbg("usbip_net_recv failed: %d", rc);
goto err;
}
return -1;
}
-int usbip_set_reuseaddr(int sockfd)
+int usbip_net_set_reuseaddr(int sockfd)
{
const int val = 1;
int ret;
return ret;
}
-int usbip_set_nodelay(int sockfd)
+int usbip_net_set_nodelay(int sockfd)
{
const int val = 1;
int ret;
return ret;
}
-int usbip_set_keepalive(int sockfd)
+int usbip_net_set_keepalive(int sockfd)
{
const int val = 1;
int ret;
continue;
/* should set TCP_NODELAY for usbip */
- usbip_set_nodelay(sockfd);
+ usbip_net_set_nodelay(sockfd);
/* TODO: write code for heartbeat */
- usbip_set_keepalive(sockfd);
+ usbip_net_set_keepalive(sockfd);
if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) == 0)
break;
} __attribute__((packed));
#define PACK_OP_COMMON(pack, op_common) do {\
- pack_uint16_t(pack, &(op_common)->version);\
- pack_uint16_t(pack, &(op_common)->code );\
- pack_uint32_t(pack, &(op_common)->status );\
+ usbip_net_pack_uint16_t(pack, &(op_common)->version);\
+ usbip_net_pack_uint16_t(pack, &(op_common)->code );\
+ usbip_net_pack_uint32_t(pack, &(op_common)->status );\
} while (0)
/* ---------------------------------------------------------------------- */
} while (0)
#define PACK_OP_IMPORT_REPLY(pack, reply) do {\
- pack_usb_device(pack, &(reply)->udev);\
+ usbip_net_pack_usb_device(pack, &(reply)->udev);\
} while (0)
/* ---------------------------------------------------------------------- */
#define PACK_OP_EXPORT_REQUEST(pack, request) do {\
- pack_usb_device(pack, &(request)->udev);\
+ usbip_net_pack_usb_device(pack, &(request)->udev);\
} while (0)
#define PACK_OP_EXPORT_REPLY(pack, reply) do {\
} __attribute__((packed));
#define PACK_OP_UNEXPORT_REQUEST(pack, request) do {\
- pack_usb_device(pack, &(request)->udev);\
+ usbip_net_pack_usb_device(pack, &(request)->udev);\
} while (0)
#define PACK_OP_UNEXPORT_REPLY(pack, reply) do {\
} while (0)
#define PACK_OP_DEVLIST_REPLY(pack, reply) do {\
- pack_uint32_t(pack, &(reply)->ndev);\
+ usbip_net_pack_uint32_t(pack, &(reply)->ndev);\
} while (0)
-void pack_uint32_t(int pack, uint32_t *num);
-void pack_uint16_t(int pack, uint16_t *num);
-void pack_usb_device(int pack, struct usbip_usb_device *udev);
-void pack_usb_interface(int pack, struct usbip_usb_interface *uinf);
-
-ssize_t usbip_recv(int sockfd, void *buff, size_t bufflen);
-ssize_t usbip_send(int sockfd, void *buff, size_t bufflen);
-int usbip_send_op_common(int sockfd, uint32_t code, uint32_t status);
-int usbip_recv_op_common(int sockfd, uint16_t *code);
-int usbip_set_reuseaddr(int sockfd);
-int usbip_set_nodelay(int sockfd);
-int usbip_set_keepalive(int sockfd);
-
+void usbip_net_pack_uint32_t(int pack, uint32_t *num);
+void usbip_net_pack_uint16_t(int pack, uint16_t *num);
+void usbip_net_pack_usb_device(int pack, struct usbip_usb_device *udev);
+void usbip_net_pack_usb_interface(int pack, struct usbip_usb_interface *uinf);
+
+ssize_t usbip_net_recv(int sockfd, void *buff, size_t bufflen);
+ssize_t usbip_net_send(int sockfd, void *buff, size_t bufflen);
+int usbip_net_send_op_common(int sockfd, uint32_t code, uint32_t status);
+int usbip_net_recv_op_common(int sockfd, uint16_t *code);
+int usbip_net_set_reuseaddr(int sockfd);
+int usbip_net_set_nodelay(int sockfd);
+int usbip_net_set_keepalive(int sockfd);
int usbip_net_tcp_connect(char *hostname, char *port);
#endif /* __USBIP_NETWORK_H */
memset(&req, 0, sizeof(req));
memset(&reply, 0, sizeof(reply));
- rc = usbip_recv(sockfd, &req, sizeof(req));
+ rc = usbip_net_recv(sockfd, &req, sizeof(req));
if (rc < 0) {
- dbg("usbip_recv failed: import request");
+ dbg("usbip_net_recv failed: import request");
return -1;
}
PACK_OP_IMPORT_REQUEST(0, &req);
if (found) {
/* should set TCP_NODELAY for usbip */
- usbip_set_nodelay(sockfd);
+ usbip_net_set_nodelay(sockfd);
/* export device needs a TCP/IP socket descriptor */
rc = usbip_host_export_device(edev, sockfd);
error = 1;
}
-
- rc = usbip_send_op_common(sockfd, OP_REP_IMPORT,
- (!error ? ST_OK : ST_NA));
+ rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT,
+ (!error ? ST_OK : ST_NA));
if (rc < 0) {
- dbg("usbip_send_op_common failed: %#0x", OP_REP_IMPORT);
+ dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT);
return -1;
}
}
memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev));
- pack_usb_device(1, &pdu_udev);
+ usbip_net_pack_usb_device(1, &pdu_udev);
- rc = usbip_send(sockfd, &pdu_udev, sizeof(pdu_udev));
+ rc = usbip_net_send(sockfd, &pdu_udev, sizeof(pdu_udev));
if (rc < 0) {
- dbg("usbip_send failed: devinfo");
+ dbg("usbip_net_send failed: devinfo");
return -1;
}
}
info("exportable devices: %d", reply.ndev);
- rc = usbip_send_op_common(connfd, OP_REP_DEVLIST, ST_OK);
+ rc = usbip_net_send_op_common(connfd, OP_REP_DEVLIST, ST_OK);
if (rc < 0) {
- dbg("usbip_send_op_common failed: %#0x", OP_REP_DEVLIST);
+ dbg("usbip_net_send_op_common failed: %#0x", OP_REP_DEVLIST);
return -1;
}
PACK_OP_DEVLIST_REPLY(1, &reply);
- rc = usbip_send(connfd, &reply, sizeof(reply));
+ rc = usbip_net_send(connfd, &reply, sizeof(reply));
if (rc < 0) {
- dbg("usbip_send failed: %#0x", OP_REP_DEVLIST);
+ dbg("usbip_net_send failed: %#0x", OP_REP_DEVLIST);
return -1;
}
struct usbip_exported_device) {
dump_usb_device(&edev->udev);
memcpy(&pdu_udev, &edev->udev, sizeof(pdu_udev));
- pack_usb_device(1, &pdu_udev);
+ usbip_net_pack_usb_device(1, &pdu_udev);
- rc = usbip_send(connfd, &pdu_udev, sizeof(pdu_udev));
+ rc = usbip_net_send(connfd, &pdu_udev, sizeof(pdu_udev));
if (rc < 0) {
- dbg("usbip_send failed: pdu_udev");
+ 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));
- pack_usb_interface(1, &pdu_uinf);
+ usbip_net_pack_usb_interface(1, &pdu_uinf);
- rc = usbip_send(connfd, &pdu_uinf, sizeof(pdu_uinf));
+ rc = usbip_net_send(connfd, &pdu_uinf,
+ sizeof(pdu_uinf));
if (rc < 0) {
- dbg("usbip_send failed: pdu_uinf");
+ dbg("usbip_net_send failed: pdu_uinf");
return -1;
}
}
memset(&req, 0, sizeof(req));
- rc = usbip_recv(connfd, &req, sizeof(req));
+ rc = usbip_net_recv(connfd, &req, sizeof(req));
if (rc < 0) {
- dbg("usbip_recv failed: devlist request");
+ dbg("usbip_net_recv failed: devlist request");
return -1;
}
uint16_t code = OP_UNSPEC;
int ret;
- ret = usbip_recv_op_common(connfd, &code);
+ ret = usbip_net_recv_op_common(connfd, &code);
if (ret < 0) {
dbg("could not receive opcode: %#0x", code);
return -1;
if (sockfdlist[nsockfd] < 0)
continue;
- usbip_set_reuseaddr(sockfdlist[nsockfd]);
- usbip_set_nodelay(sockfdlist[nsockfd]);
+ usbip_net_set_reuseaddr(sockfdlist[nsockfd]);
+ usbip_net_set_nodelay(sockfdlist[nsockfd]);
if (sockfdlist[nsockfd] >= FD_SETSIZE) {
close(sockfdlist[nsockfd]);