diff options
Diffstat (limited to 'firmware/usbstack/core/utils.c')
-rw-r--r-- | firmware/usbstack/core/utils.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/firmware/usbstack/core/utils.c b/firmware/usbstack/core/utils.c index cd32fb3292..d43bd9290f 100644 --- a/firmware/usbstack/core/utils.c +++ b/firmware/usbstack/core/utils.c | |||
@@ -9,6 +9,9 @@ | |||
9 | * | 9 | * |
10 | * Copyright (C) 2007 by Christian Gmeiner | 10 | * Copyright (C) 2007 by Christian Gmeiner |
11 | * | 11 | * |
12 | * Based on linux/drivers/usb/gadget/usbstring.c | ||
13 | * Copyright (C) 2003 David Brownell | ||
14 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | 15 | * All files in this archive are subject to the GNU General Public License. |
13 | * See the file COPYING in the source tree root for full license agreement. | 16 | * See the file COPYING in the source tree root for full license agreement. |
14 | * | 17 | * |
@@ -123,3 +126,51 @@ void into_usb_ctrlrequest(struct usb_ctrlrequest* request) | |||
123 | logf(" -> e: %s", extra); | 126 | logf(" -> e: %s", extra); |
124 | } | 127 | } |
125 | } | 128 | } |
129 | |||
130 | int usb_stack_get_string(struct usb_string* strings, int id, uint8_t* buf) | ||
131 | { | ||
132 | struct usb_string* tmp; | ||
133 | char* sp, *dp; | ||
134 | int len; | ||
135 | |||
136 | /* if id is 0, then we need to send back all supported | ||
137 | * languages. In our case we only support one | ||
138 | * language: en-us (0x0409) */ | ||
139 | if (id == 0) { | ||
140 | buf [0] = 4; | ||
141 | buf [1] = USB_DT_STRING; | ||
142 | buf [2] = (uint8_t) 0x0409; | ||
143 | buf [3] = (uint8_t) (0x0409 >> 8); | ||
144 | return 4; | ||
145 | } | ||
146 | |||
147 | /* look for string */ | ||
148 | for (tmp = strings; tmp && tmp->s; tmp++) { | ||
149 | if (tmp->id == id) { | ||
150 | break; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | /* did we found it? */ | ||
155 | if (!tmp || !tmp->s) { | ||
156 | return -EINVAL; | ||
157 | } | ||
158 | |||
159 | len = MIN ((size_t) 126, strlen (tmp->s)); | ||
160 | memset(buf + 2, 0, 2 * len); | ||
161 | |||
162 | /* convert to utf-16le */ | ||
163 | sp = (char*)tmp->s; | ||
164 | dp = (char*)&buf[2]; | ||
165 | |||
166 | while (*sp) { | ||
167 | *dp++ = *sp++; | ||
168 | *dp++ = 0; | ||
169 | } | ||
170 | |||
171 | /* write len and tag */ | ||
172 | buf [0] = (len + 1) * 2; | ||
173 | buf [1] = USB_DT_STRING; | ||
174 | |||
175 | return buf[0]; | ||
176 | } | ||