2007-08-27 16:04:32 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2007-08-27 22:12:35 +00:00
|
|
|
* $Id$
|
2007-08-27 16:04:32 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Christian Gmeiner
|
|
|
|
*
|
2007-09-06 07:17:54 +00:00
|
|
|
* Based on linux/drivers/usb/gadget/usbstring.c
|
|
|
|
* Copyright (C) 2003 David Brownell
|
|
|
|
*
|
2007-08-27 16:04:32 +00:00
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "usbstack/core.h"
|
|
|
|
|
2007-08-27 22:07:36 +00:00
|
|
|
void into_usb_ctrlrequest(struct usb_ctrlrequest* request)
|
|
|
|
{
|
|
|
|
char* type = "";
|
|
|
|
char* req = "";
|
|
|
|
char* extra = 0;
|
2007-08-27 16:04:32 +00:00
|
|
|
|
2007-08-27 22:07:36 +00:00
|
|
|
logf("-usb request-");
|
2007-08-27 16:04:32 +00:00
|
|
|
/* check if packet is okay */
|
2007-08-27 22:07:36 +00:00
|
|
|
if (request->bRequestType == 0 &&
|
2007-08-27 16:04:32 +00:00
|
|
|
request->bRequest == 0 &&
|
|
|
|
request->wValue == 0 &&
|
|
|
|
request->wIndex == 0 &&
|
|
|
|
request->wLength == 0) {
|
|
|
|
logf(" -> INVALID <-");
|
|
|
|
return;
|
2007-08-27 22:07:36 +00:00
|
|
|
}
|
|
|
|
|
2007-08-27 16:04:32 +00:00
|
|
|
switch (request->bRequestType & USB_TYPE_MASK) {
|
2007-08-27 22:07:36 +00:00
|
|
|
case USB_TYPE_STANDARD:
|
|
|
|
type = "standard";
|
|
|
|
|
2007-08-27 16:04:32 +00:00
|
|
|
switch (request->bRequest) {
|
|
|
|
case USB_REQ_GET_STATUS:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "get status";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_CLEAR_FEATURE:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "clear feature";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_FEATURE:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "set feature";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_ADDRESS:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "set address";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_GET_DESCRIPTOR:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "get descriptor";
|
|
|
|
|
|
|
|
switch (request->wValue >> 8) {
|
|
|
|
case USB_DT_DEVICE:
|
|
|
|
extra = "get device descriptor";
|
|
|
|
break;
|
|
|
|
case USB_DT_DEVICE_QUALIFIER:
|
|
|
|
extra = "get device qualifier";
|
|
|
|
break;
|
|
|
|
case USB_DT_OTHER_SPEED_CONFIG:
|
|
|
|
extra = "get other-speed config descriptor";
|
|
|
|
case USB_DT_CONFIG:
|
|
|
|
extra = "get configuration descriptor";
|
|
|
|
break;
|
|
|
|
case USB_DT_STRING:
|
|
|
|
extra = "get string descriptor";
|
|
|
|
break;
|
|
|
|
case USB_DT_DEBUG:
|
|
|
|
extra = "debug";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_DESCRIPTOR:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "set descriptor";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_GET_CONFIGURATION:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "get configuration";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_CONFIGURATION:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "set configuration";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_GET_INTERFACE:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "get interface";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_SET_INTERFACE:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "set interface";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
case USB_REQ_SYNCH_FRAME:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "sync frame";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
2007-08-27 22:07:36 +00:00
|
|
|
req = "unkown";
|
|
|
|
break;
|
2007-08-27 16:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case USB_TYPE_CLASS:
|
2007-08-27 22:07:36 +00:00
|
|
|
type = "class";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case USB_TYPE_VENDOR:
|
2007-08-27 22:07:36 +00:00
|
|
|
type = "vendor";
|
2007-08-27 16:04:32 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-27 22:07:36 +00:00
|
|
|
|
2007-08-27 16:04:32 +00:00
|
|
|
logf(" -b 0x%x", request->bRequestType);
|
|
|
|
logf(" -b 0x%x", request->bRequest);
|
|
|
|
logf(" -b 0x%x", request->wValue);
|
|
|
|
logf(" -b 0x%x", request->wIndex);
|
|
|
|
logf(" -b 0x%x", request->wLength);
|
|
|
|
logf(" -> t: %s", type);
|
|
|
|
logf(" -> r: %s", req);
|
|
|
|
if (extra != 0) {
|
2007-08-27 22:07:36 +00:00
|
|
|
logf(" -> e: %s", extra);
|
2007-08-27 16:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-06 07:17:54 +00:00
|
|
|
|
|
|
|
int usb_stack_get_string(struct usb_string* strings, int id, uint8_t* buf)
|
|
|
|
{
|
|
|
|
struct usb_string* tmp;
|
|
|
|
char* sp, *dp;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
/* if id is 0, then we need to send back all supported
|
|
|
|
* languages. In our case we only support one
|
|
|
|
* language: en-us (0x0409) */
|
|
|
|
if (id == 0) {
|
|
|
|
buf [0] = 4;
|
|
|
|
buf [1] = USB_DT_STRING;
|
|
|
|
buf [2] = (uint8_t) 0x0409;
|
|
|
|
buf [3] = (uint8_t) (0x0409 >> 8);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for string */
|
|
|
|
for (tmp = strings; tmp && tmp->s; tmp++) {
|
|
|
|
if (tmp->id == id) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* did we found it? */
|
|
|
|
if (!tmp || !tmp->s) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = MIN ((size_t) 126, strlen (tmp->s));
|
|
|
|
memset(buf + 2, 0, 2 * len);
|
|
|
|
|
|
|
|
/* convert to utf-16le */
|
|
|
|
sp = (char*)tmp->s;
|
|
|
|
dp = (char*)&buf[2];
|
|
|
|
|
|
|
|
while (*sp) {
|
|
|
|
*dp++ = *sp++;
|
|
|
|
*dp++ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write len and tag */
|
|
|
|
buf [0] = (len + 1) * 2;
|
|
|
|
buf [1] = USB_DT_STRING;
|
|
|
|
|
|
|
|
return buf[0];
|
|
|
|
}
|