diff --git a/emulation/Makefile b/emulation/Makefile index 23a61df..7739329 100644 --- a/emulation/Makefile +++ b/emulation/Makefile @@ -1,4 +1,4 @@ -SRCS = usbip-server.c usb-emu.c +SRCS = usbip-server.c usb-emu.c glue.c OBJS = $(SRCS:.c=.o) TARGET=gnuk_emulation GNUKDIR=../src diff --git a/emulation/glue.c b/emulation/glue.c new file mode 100644 index 0000000..91c513b --- /dev/null +++ b/emulation/glue.c @@ -0,0 +1,54 @@ +#include + +uint8_t _regnual_start; +uint8_t __heap_end__; + +int +check_crc32 (const uint32_t *start_p, const uint32_t *end_p) +{ + return 0; +} + +uint8_t * +sram_address (uint32_t offset) +{ + return ((uint8_t *)0x20000000) + offset; +} + +const uint8_t sys_version[8] = { + 3*2+2, /* bLength */ + 0x03, /* bDescriptorType = USB_STRING_DESCRIPTOR_TYPE */ + /* sys version: "3.0" */ + '3', 0, '.', 0, '0', 0, +}; + +void +led_blink (int spec) +{ +} + +void +ccid_usb_reset (int full) +{ +} + +void +ccid_card_change_signal (int how) +{ +} + +enum ccid_state { + CCID_STATE_NOCARD, /* No card available */ + CCID_STATE_START, /* Initial */ + CCID_STATE_WAIT, /* Waiting APDU */ + /* Busy1, Busy2, Busy3, Busy5 */ + CCID_STATE_EXECUTE, /* Busy4 */ + CCID_STATE_RECEIVE, /* APDU Received Partially */ + CCID_STATE_SEND, /* APDU Sent Partially */ + + CCID_STATE_EXITED, /* ICC Thread Terminated */ + CCID_STATE_EXEC_REQUESTED, /* Exec requested */ +}; + +static enum ccid_state ccid_state; +enum ccid_state *const ccid_state_p = &ccid_state; diff --git a/emulation/usbip-server.c b/emulation/usbip-server.c index 2e179c9..e69e93d 100644 --- a/emulation/usbip-server.c +++ b/emulation/usbip-server.c @@ -34,8 +34,8 @@ #define USBIP_PORT 3240 -#define CMD_REQ_LIST 0x01008005 -#define CMD_REQ_ATTACH 0x01008003 +#define CMD_REQ_LIST 0x01118005 +#define CMD_REQ_ATTACH 0x01118003 #define CMD_URB 0x00000001 #define CMD_DETACH 0x00000002 @@ -44,11 +44,70 @@ struct usbip_msg_head { uint32_t seq; }; +#define USBIP_REPLY_HEADER_SIZE 12 +#define DEVICE_INFO_SIZE (256+32+12+6+6) +#define INTERFACE_INFO_SIZE 4 +#define DEVICE_LIST_SIZE (USBIP_REPLY_HEADER_SIZE+DEVICE_INFO_SIZE*1+INTERFACE_INFO_SIZE*1) + +#define USBIP_REPLY_DEVICE_LIST "\x01\x11\x00\x05" +#define NETWORK_UINT32_ZERO "\x00\x00\x00\x00" +#define NETWORK_UINT32_ONE "\x00\x00\x00\x01" +#define NETWORK_UINT32_TWO "\x00\x00\x00\x02" +#define NETWORK_UINT16_FSIJ "\x23\x4b" +#define NETWORK_UINT16_ZERO "\x00\x00" +#define NETWORK_UINT16_ONE_ONE "\x01\x01" + static char * list_devices (size_t *len_p) { + char *p0, *p; + *len_p = 0; - return NULL; + p0 = malloc (DEVICE_LIST_SIZE); + if (p0 == NULL) + return NULL; + + *len_p = DEVICE_LIST_SIZE; + + p = p0; + memcpy (p, USBIP_REPLY_DEVICE_LIST, 4); + p += 4; + memcpy (p, NETWORK_UINT32_ZERO, 4); + p += 4; + memcpy (p, NETWORK_UINT32_ONE, 4); + p += 4; + memset (p, 0, 256); + strcpy (p, "/sys/devices/pci0000:00/0000:00:01.1/usb1/1-1"); + p += 256; + memset (p, 0, 32); + strcpy (p, "1-1"); + p += 32; + memcpy (p, NETWORK_UINT32_ONE, 4); /* Bus */ + p += 4; + memcpy (p, NETWORK_UINT32_TWO, 4); /* Dev */ + p += 4; + memcpy (p, NETWORK_UINT32_ONE, 4); /* Speed */ + p += 4; + memcpy (p, NETWORK_UINT16_FSIJ, 2); + p += 2; + memcpy (p, NETWORK_UINT16_ZERO, 2); /* Gnuk */ + p += 2; + memcpy (p, NETWORK_UINT16_ONE_ONE, 2); /* USB 1.1 */ + p += 2; + + *p++ = 0; /* bDeviceClass */ + *p++ = 0; /* bDeviceSubClass */ + *p++ = 0; /* bDeviceProtocol */ + *p++ = 0; /* bConfigurationValue */ + *p++ = 1; /* bConfigurationValue */ + *p++ = 1; /* bNumInterfaces */ + + *p++ = 11; /* bInterfaceClass */ + *p++ = 0; /* bInterfaceSubClass */ + *p++ = 0; /* bInterfaceProtocol */ + *p++ = 0; /* ----pad----------- */ + + return p0; } static char * @@ -65,8 +124,7 @@ handle_urb (int fd) } - -void +static void run_server (void) { int sock; @@ -202,7 +260,7 @@ run_server (void) } else { - fprintf (stderr, "Unknown command %x, disconnecting.\n", msg.cmd); + fprintf (stderr, "Unknown command %08x, disconnecting.\n", msg.cmd); break; } } @@ -210,3 +268,11 @@ run_server (void) close (fd); } } + + +int +main (int argc, const char *argv[]) +{ + run_server (); + return 0; +}