diff options
author | Hans de Goede <hdegoede@redhat.com> | 2011-06-29 11:31:25 +0200 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2011-06-29 11:31:25 +0200 |
commit | a794dd7cef57f1b372fce755fc0463d99ceeb2c0 (patch) | |
tree | 664d1f09da2eab091252f5cde6c9ff1296e0f75d | |
parent | 1335301e06b4a13394dffd81379836960422f71d (diff) |
Rename device_info -> device_connect, device_disconnected -> device_disconnect
And document how a single usbredirproto connection may be reused for
a newly plugged in / re-plugged device.
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | usb-redirection-protocol.txt | 96 | ||||
-rw-r--r-- | usbredirhost/usbredirhost.c | 20 | ||||
-rw-r--r-- | usbredirparser/usbredirparser.c | 58 | ||||
-rw-r--r-- | usbredirparser/usbredirparser.h | 22 | ||||
-rw-r--r-- | usbredirparser/usbredirproto.h | 12 | ||||
-rw-r--r-- | usbredirtestclient/usbredirtestclient.c | 30 |
7 files changed, 122 insertions, 118 deletions
@@ -1,3 +1,5 @@ +* add usb id, device class to connect_header +* add a interface info packet, with class + subclass info per interface * do endian conversion in usbredirparser where necessary * check length against max packet size * check caps for relevant callbacks in parser diff --git a/usb-redirection-protocol.txt b/usb-redirection-protocol.txt index 7ac5041..0363006 100644 --- a/usb-redirection-protocol.txt +++ b/usb-redirection-protocol.txt @@ -22,22 +22,22 @@ Version 0.2 -Add usb_redir_reset and usb_redir_reset_status packets Version 0.3 +-Add a usb_redir_device_connect packet +-Add a usb_redir_device_disconnect packet -Add a usb_redir_ep_info packet --Report usb_redir_stall as iso status error to indicate a stream stop --Add a usb_redir_device_info packet -Add support for interrupt transfers, add the following packets: usb_redir_start_interrupt_receiving usb_redir_stop_interrupt_receiving usb_redir_interrupt_receiving_status usb_redir_interrupt_packet --Add a usb_redir_device_disconnected packet -Add a list with the possible values for the status field --Drop usb_redir_disconnected status, instead the usb-host should always - send a usb_redir_device_disconnected packet on device disconnection. The +-Report usb_redir_stall as iso status error to indicate a stream stop +-Drop usb_redir_disconnect status, instead the usb-host should always + send a usb_redir_device_disconnect packet on device disconnection. The reason behind this is that having to handle disconnection from data packet handlers make things unnecessarily hard for the usb-guest -Drop usb_redir_reset_status, instead if reconnecting to the device fails - after reset the usb-host will send a usb_redir_device_disconnected packet + after reset the usb-host will send a usb_redir_device_disconnect packet USB redirerection protocol (draft version 0.3) @@ -111,11 +111,10 @@ Packet type list control packets: usb_redir_hello -usb_redir_device_info -usb_redir_ep_info -usb_redir_device_disconnected +usb_redir_device_connect +usb_redir_device_disconnect usb_redir_reset -usb_redir_reset_status +usb_redir_ep_info usb_redir_set_configuration usb_redir_get_configuration usb_redir_configuration_status @@ -190,11 +189,11 @@ enum { usb_redir_cap_bulk_streams, /* USB 3 bulk streams are supported */ }; -usb_redir_device_info ---------------------- +usb_redir_device_connect +------------------------ -usb_redir_header.type: usb_redir_device_info -usb_redir_header.length: sizeof(usb_redir_device_info_header) +usb_redir_header.type: usb_redir_device_connect +usb_redir_header.length: sizeof(usb_redir_device_connect_header) usb_redir_header.id: 0 (always as this is an unsolicited packet) enum { @@ -205,15 +204,47 @@ enum { usb_redir_speed_unknown = 255 } -struct usb_redir_device_info_header { +struct usb_redir_device_connect_header { uint8_t speed; } No packet type specific additional data. -This packet gets send by the usb-host to let the usb-guest know the speed -of the device. It gets send directly after the hello message (so also as -soon as a connection gets established). +This packet gets send by the usb-host when a device becomes available (it is +possible for the usb-host to wait for a device to get plugged in). + +Note that a usb-host may re-use the existing connection for a new / re-plugged +device in this case this packet can be send after a usb_redir_device_disconnect +message to notify the usb-guest that a new device is available. + +usb_redir_device_disconnect +--------------------------- + +usb_redir_header.type: usb_redir_device_disconnect +usb_redir_header.length: 0 (always as this is an unsolicited packet) + +No packet type specific header. + +No packet type specific additional data. + +This packet may be send by the usb-host to indicate that the device has been +disconnect (unplugged). Note on some platforms the usb-host may not become +aware of the disconnection until a usb packet is send to the device. + +usb_redir_reset +--------------- + +usb_redir_header.type: usb_redir_reset +usb_redir_header.length: 0 + +No packet type specific header. + +No packet type specific additional data. + +This packet can be send by the usb-guest to cause a reset of the usb +device. Note that of things go wrong the usb-host may be unable to re-connect +to the device after the reset! If this happens a usb_redir_device_disconnect +packet will be send by the usb-host. usb_redir_ep_info ----------------- @@ -244,35 +275,6 @@ type, interval and interface it belongs to for all possible endpoints, first 0-15 out, then 0-15 in. This gets send after a (successful) initial connection, reset, set_config and set_alt_setting. -usb_redir_device_disconnected ------------------------------ - -usb_redir_header.type: usb_redir_device_disconnected -usb_redir_header.length: 0 (always as this is an unsolicited packet) - -No packet type specific header. - -No packet type specific additional data. - -This packet may be send by the usb-host to indicate that the device has been -disconnected (unplugged). Note on some platforms the usb-host may not become -aware of the disconnection until a usb packet is send to the device. - -usb_redir_reset ---------------- - -usb_redir_header.type: usb_redir_reset -usb_redir_header.length: 0 - -No packet type specific header. - -No packet type specific additional data. - -This packet can be send by the usb-guest to cause a reset of the usb -device. Note that of things go wrong the usb-host may be unable to re-connect -to the device after the reset! If this happens a usb_redir_device_disconnected -packet will be send by the usb-host. - usb_redir_set_configuration --------------------------- diff --git a/usbredirhost/usbredirhost.c b/usbredirhost/usbredirhost.c index 9652e9f..d6e5dd8 100644 --- a/usbredirhost/usbredirhost.c +++ b/usbredirhost/usbredirhost.c @@ -181,7 +181,7 @@ static void usbredirhost_handle_disconnect(struct usbredirhost *host) { if (!host->disconnected) { WARNING("device disconnected"); - usbredirparser_send_device_disconnected(host->parser); + usbredirparser_send_device_disconnect(host->parser); host->disconnected = 1; } } @@ -407,7 +407,7 @@ struct usbredirhost *usbredirhost_open( void *func_priv, const char *version, int verbose) { struct usbredirhost *host; - struct usb_redir_device_info_header device_info; + struct usb_redir_device_connect_header device_connect; enum libusb_speed speed; int r; @@ -472,14 +472,18 @@ struct usbredirhost *usbredirhost_open( speed = libusb_get_device_speed(host->dev); switch (speed) { - case LIBUSB_SPEED_LOW: device_info.speed = usb_redir_speed_low; break; - case LIBUSB_SPEED_FULL: device_info.speed = usb_redir_speed_full; break; - case LIBUSB_SPEED_HIGH: device_info.speed = usb_redir_speed_high; break; - case LIBUSB_SPEED_SUPER: device_info.speed = usb_redir_speed_super; break; + case LIBUSB_SPEED_LOW: + device_connect.speed = usb_redir_speed_low; break; + case LIBUSB_SPEED_FULL: + device_connect.speed = usb_redir_speed_full; break; + case LIBUSB_SPEED_HIGH: + device_connect.speed = usb_redir_speed_high; break; + case LIBUSB_SPEED_SUPER: + device_connect.speed = usb_redir_speed_super; break; default: - device_info.speed = usb_redir_speed_unknown; + device_connect.speed = usb_redir_speed_unknown; } - usbredirparser_send_device_info(host->parser, &device_info); + usbredirparser_send_device_connect(host->parser, &device_connect); return host; } diff --git a/usbredirparser/usbredirparser.c b/usbredirparser/usbredirparser.c index ad2deb5..581400d 100644 --- a/usbredirparser/usbredirparser.c +++ b/usbredirparser/usbredirparser.c @@ -167,19 +167,13 @@ static int usbredirparser_get_type_header_len( switch (type) { case usb_redir_hello: return sizeof(struct usb_redir_hello_header); - case usb_redir_device_info: + case usb_redir_device_connect: if (!command_for_host) { - return sizeof(struct usb_redir_device_info_header); + return sizeof(struct usb_redir_device_connect_header); } else { return -1; } - case usb_redir_ep_info: - if (!command_for_host) { - return sizeof(struct usb_redir_ep_info_header); - } else { - return -1; - } - case usb_redir_device_disconnected: + case usb_redir_device_disconnect: if (!command_for_host) { return 0; } else { @@ -191,6 +185,12 @@ static int usbredirparser_get_type_header_len( } else { return -1; } + case usb_redir_ep_info: + if (!command_for_host) { + return sizeof(struct usb_redir_ep_info_header); + } else { + return -1; + } case usb_redir_set_configuration: if (command_for_host) { return sizeof(struct usb_redir_set_configuration_header); @@ -391,20 +391,20 @@ static void usbredirparser_call_type_func(struct usbredirparser_priv *parser) (struct usb_redir_hello_header *)parser->type_header, parser->data, parser->data_len); break; - case usb_redir_device_info: - parser->callb.device_info_func(parser->callb.priv, - (struct usb_redir_device_info_header *)parser->type_header); - break; - case usb_redir_ep_info: - parser->callb.ep_info_func(parser->callb.priv, - (struct usb_redir_ep_info_header *)parser->type_header); + case usb_redir_device_connect: + parser->callb.device_connect_func(parser->callb.priv, + (struct usb_redir_device_connect_header *)parser->type_header); break; - case usb_redir_device_disconnected: - parser->callb.device_disconnected_func(parser->callb.priv); + case usb_redir_device_disconnect: + parser->callb.device_disconnect_func(parser->callb.priv); break; case usb_redir_reset: parser->callb.reset_func(parser->callb.priv); break; + case usb_redir_ep_info: + parser->callb.ep_info_func(parser->callb.priv, + (struct usb_redir_ep_info_header *)parser->type_header); + break; case usb_redir_set_configuration: parser->callb.set_configuration_func(parser->callb.priv, parser->header.id, @@ -704,22 +704,16 @@ static void usbredirparser_queue(struct usbredirparser *parser_pub, wbuf->next = new_wbuf; } -void usbredirparser_send_device_info(struct usbredirparser *parser, - struct usb_redir_device_info_header *device_info) +void usbredirparser_send_device_connect(struct usbredirparser *parser, + struct usb_redir_device_connect_header *device_connect) { - usbredirparser_queue(parser, usb_redir_device_info, 0, device_info, + usbredirparser_queue(parser, usb_redir_device_connect, 0, device_connect, NULL, 0); } -void usbredirparser_send_ep_info(struct usbredirparser *parser, - struct usb_redir_ep_info_header *ep_info) -{ - usbredirparser_queue(parser, usb_redir_ep_info, 0, ep_info, NULL, 0); -} - -void usbredirparser_send_device_disconnected(struct usbredirparser *parser) +void usbredirparser_send_device_disconnect(struct usbredirparser *parser) { - usbredirparser_queue(parser, usb_redir_device_disconnected, 0, NULL, + usbredirparser_queue(parser, usb_redir_device_disconnect, 0, NULL, NULL, 0); } @@ -728,6 +722,12 @@ void usbredirparser_send_reset(struct usbredirparser *parser) usbredirparser_queue(parser, usb_redir_reset, 0, NULL, NULL, 0); } +void usbredirparser_send_ep_info(struct usbredirparser *parser, + struct usb_redir_ep_info_header *ep_info) +{ + usbredirparser_queue(parser, usb_redir_ep_info, 0, ep_info, NULL, 0); +} + void usbredirparser_send_set_configuration(struct usbredirparser *parser, uint32_t id, struct usb_redir_set_configuration_header *set_configuration) diff --git a/usbredirparser/usbredirparser.h b/usbredirparser/usbredirparser.h index 4a1ab4b..5c8864a 100644 --- a/usbredirparser/usbredirparser.h +++ b/usbredirparser/usbredirparser.h @@ -43,12 +43,12 @@ typedef int (*usbredirparser_write)(void *priv, uint8_t *data, int count); guarenteed to be that of the callback. Control packets: */ -typedef void (*usbredirparser_device_info)(void *priv, - struct usb_redir_device_info_header *device_info); +typedef void (*usbredirparser_device_connect)(void *priv, + struct usb_redir_device_connect_header *device_connect); +typedef void (*usbredirparser_device_disconnect)(void *priv); +typedef void (*usbredirparser_reset)(void *priv); typedef void (*usbredirparser_ep_info)(void *priv, struct usb_redir_ep_info_header *ep_info); -typedef void (*usbredirparser_device_disconnected)(void *priv); -typedef void (*usbredirparser_reset)(void *priv); typedef void (*usbredirparser_set_configuration)(void *priv, uint32_t id, struct usb_redir_set_configuration_header *set_configuration); typedef void (*usbredirparser_get_configuration)(void *priv, uint32_t id); @@ -110,10 +110,10 @@ struct usbredirparser { usbredirparser_read read_func; usbredirparser_write write_func; /* usb-redir-protocol v0.3 control packet complete callbacks */ - usbredirparser_device_info device_info_func; - usbredirparser_ep_info ep_info_func; - usbredirparser_device_disconnected device_disconnected_func; + usbredirparser_device_connect device_connect_func; + usbredirparser_device_disconnect device_disconnect_func; usbredirparser_reset reset_func; + usbredirparser_ep_info ep_info_func; usbredirparser_set_configuration set_configuration_func; usbredirparser_get_configuration get_configuration_func; usbredirparser_configuration_status configuration_status_func; @@ -181,12 +181,12 @@ uint32_t *usbredirparser_get_peer_caps(int *caps_len_ret); 2) if their is not enough memory for buffers the packet will be dropped (and an error message will be logged */ /* Control packets: */ -void usbredirparser_send_device_info(struct usbredirparser *parser, - struct usb_redir_device_info_header *device_info); +void usbredirparser_send_device_connect(struct usbredirparser *parser, + struct usb_redir_device_connect_header *device_connect); +void usbredirparser_send_device_disconnect(struct usbredirparser *parser); +void usbredirparser_send_reset(struct usbredirparser *parser); void usbredirparser_send_ep_info(struct usbredirparser *parser, struct usb_redir_ep_info_header *ep_info); -void usbredirparser_send_device_disconnected(struct usbredirparser *parser); -void usbredirparser_send_reset(struct usbredirparser *parser); void usbredirparser_send_set_configuration(struct usbredirparser *parser, uint32_t id, struct usb_redir_set_configuration_header *set_configuration); diff --git a/usbredirparser/usbredirproto.h b/usbredirparser/usbredirproto.h index 6e6780b..ec772fa 100644 --- a/usbredirparser/usbredirproto.h +++ b/usbredirparser/usbredirproto.h @@ -71,10 +71,10 @@ enum { enum { /* Control packets */ usb_redir_hello, - usb_redir_device_info, - usb_redir_ep_info, - usb_redir_device_disconnected, + usb_redir_device_connect, + usb_redir_device_disconnect, usb_redir_reset, + usb_redir_ep_info, usb_redir_set_configuration, usb_redir_get_configuration, usb_redir_configuration_status, @@ -115,7 +115,7 @@ struct usb_redir_hello_header { uint32_t capabilities[0]; } ATTR_PACKED; -struct usb_redir_device_info_header { +struct usb_redir_device_connect_header { uint8_t speed; } ATTR_PACKED; @@ -125,10 +125,6 @@ struct usb_redir_ep_info_header { uint8_t interface[32]; } ATTR_PACKED; -struct usb_redir_reset_status_header { - uint8_t status; -} ATTR_PACKED; - struct usb_redir_set_configuration_header { uint8_t configuration; } ATTR_PACKED; diff --git a/usbredirtestclient/usbredirtestclient.c b/usbredirtestclient/usbredirtestclient.c index 44164d7..1929469 100644 --- a/usbredirtestclient/usbredirtestclient.c +++ b/usbredirtestclient/usbredirtestclient.c @@ -43,11 +43,11 @@ #define VERSION "usbredirtestclient 0.0" #endif -static void usbredirtestclient_device_info(void *priv, - struct usb_redir_device_info_header *device_info); +static void usbredirtestclient_device_connect(void *priv, + struct usb_redir_device_connect_header *device_connect); +static void usbredirtestclient_device_disconnect(void *priv); static void usbredirtestclient_ep_info(void *priv, struct usb_redir_ep_info_header *ep_info); -static void usbredirtestclient_device_disconnected(void *priv); static void usbredirtestclient_configuration_status(void *priv, uint32_t id, struct usb_redir_configuration_status_header *configuration_status); static void usbredirtestclient_alt_setting_status(void *priv, uint32_t id, @@ -270,9 +270,9 @@ int main(int argc, char *argv[]) parser->log_func = usbredirtestclient_log; parser->read_func = usbredirtestclient_read; parser->write_func = usbredirtestclient_write; - parser->device_info_func = usbredirtestclient_device_info; + parser->device_connect_func = usbredirtestclient_device_connect; + parser->device_disconnect_func = usbredirtestclient_device_disconnect; parser->ep_info_func = usbredirtestclient_ep_info; - parser->device_disconnected_func = usbredirtestclient_device_disconnected; parser->configuration_status_func = usbredirtestclient_configuration_status; parser->alt_setting_status_func = usbredirtestclient_alt_setting_status; parser->iso_stream_status_func = usbredirtestclient_iso_stream_status; @@ -428,10 +428,10 @@ static void usbredirtestclient_cmdline_parse(void) } } -static void usbredirtestclient_device_info(void *priv, - struct usb_redir_device_info_header *device_info) +static void usbredirtestclient_device_connect(void *priv, + struct usb_redir_device_connect_header *device_connect) { - switch (device_info->speed) { + switch (device_connect->speed) { case usb_redir_speed_low: printf("device info: speed: low\n"); break; case usb_redir_speed_full: printf("device info: speed: full\n"); break; case usb_redir_speed_high: printf("device info: speed: high\n"); break; @@ -441,6 +441,13 @@ static void usbredirtestclient_device_info(void *priv, } } +static void usbredirtestclient_device_disconnect(void *priv) +{ + printf("device disconnected"); + close(client_fd); + client_fd = -1; +} + static void usbredirtestclient_ep_info(void *priv, struct usb_redir_ep_info_header *ep_info) { @@ -455,13 +462,6 @@ static void usbredirtestclient_ep_info(void *priv, } } -static void usbredirtestclient_device_disconnected(void *priv) -{ - printf("device disconnected"); - close(client_fd); - client_fd = -1; -} - static void usbredirtestclient_configuration_status(void *priv, uint32_t id, struct usb_redir_configuration_status_header *config_status) { |