Permalink
Browse files

softusb: clean up device reporting

Moved reporting of the device(s) detected out of port_service, making
it a bit less cluttered and providing a more comfortable basis for
future additions.
  • Loading branch information...
1 parent 6ca46c2 commit b553999d20ad4bf5be9c52f46db7ff88f3372162 @wpwrak wpwrak committed with sbourdeauducq Nov 30, 2011
Showing with 26 additions and 22 deletions.
  1. +26 −22 softusb-input/main.c
View
@@ -518,6 +518,11 @@ static struct ep_status *identify_protocol(const unsigned char *itf,
return NULL;
}
+static const char found[] PROGMEM = "Found ";
+static const char unsupported_device[] PROGMEM = "unsupported device\n";
+static const char mouse[] PROGMEM = "mouse\n";
+static const char keyboard[] PROGMEM = "keyboard\n";
+
static char validate_configuration_descriptor(const unsigned char *descriptor,
char len, struct port_status *p)
{
@@ -537,9 +542,24 @@ static char validate_configuration_descriptor(const unsigned char *descriptor,
}
offset += descriptor[offset+0];
}
+ if(p->keyboard.ep) {
+ print_string(found);
+ print_string(keyboard);
+ }
+ if(p->mouse.ep) {
+ print_string(found);
+ print_string(mouse);
+ }
return p->keyboard.ep || p->mouse.ep;
}
+static void unsupported(struct port_status *p)
+{
+ print_string(found);
+ print_string(unsupported_device);
+ p->state = PORT_STATE_UNSUPPORTED;
+}
+
static const char retry_exceed[] PROGMEM = "Retry count exceeded, disabling device.\n";
static void check_retry(struct port_status *p)
{
@@ -552,11 +572,6 @@ static void check_retry(struct port_status *p)
static const char vid[] PROGMEM = "VID: ";
static const char pid[] PROGMEM = ", PID: ";
-static const char found[] PROGMEM = "Found ";
-static const char unsupported_device[] PROGMEM = "unsupported device\n";
-static const char mouse[] PROGMEM = "mouse\n";
-static const char keyboard[] PROGMEM = "keyboard\n";
-
static int get_device_descriptor(unsigned char *buf, int size,
unsigned char ep0_size)
{
@@ -688,10 +703,9 @@ static void port_service(struct port_status *p, char name)
/* check for bDeviceClass=0 and bDeviceSubClass=0.
* HID devices have those.
*/
- if((device_descriptor[4] != 0) || (device_descriptor[5] != 0)) {
- print_string(found); print_string(unsupported_device);
- p->state = PORT_STATE_UNSUPPORTED;
- } else
+ if((device_descriptor[4] != 0) || (device_descriptor[5] != 0))
+ unsupported(p);
+ else
p->state = PORT_STATE_GET_CONFIGURATION_DESCRIPTOR;
}
check_retry(p);
@@ -716,20 +730,10 @@ static void port_service(struct port_status *p, char name)
if(len >= 0) {
p->retry_count = 0;
if(!validate_configuration_descriptor(
- configuration_descriptor, len, p)) {
- print_string(found); print_string(unsupported_device);
- p->state = PORT_STATE_UNSUPPORTED;
- } else {
- if(p->keyboard.ep) {
- print_string(found);
- print_string(keyboard);
- }
- if(p->mouse.ep) {
- print_string(found);
- print_string(mouse);
- }
+ configuration_descriptor, len, p))
+ unsupported(p);
+ else
p->state = PORT_STATE_SET_CONFIGURATION;
- }
}
check_retry(p);
break;

0 comments on commit b553999

Please sign in to comment.