diff options
Diffstat (limited to 'firmware/usbstack/core')
-rw-r--r-- | firmware/usbstack/core/config.c | 90 | ||||
-rw-r--r-- | firmware/usbstack/core/core.c | 197 | ||||
-rw-r--r-- | firmware/usbstack/core/epsetup.c | 98 | ||||
-rw-r--r-- | firmware/usbstack/core/utils.c | 102 |
4 files changed, 244 insertions, 243 deletions
diff --git a/firmware/usbstack/core/config.c b/firmware/usbstack/core/config.c index a05a508bf9..277156d0d9 100644 --- a/firmware/usbstack/core/config.c +++ b/firmware/usbstack/core/config.c | |||
@@ -23,58 +23,58 @@ | |||
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include "usbstack/core.h" | 24 | #include "usbstack/core.h" |
25 | 25 | ||
26 | static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descriptor_header** src) { | 26 | static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descriptor_header** src) |
27 | 27 | { | |
28 | uint8_t* dest = buf; | 28 | uint8_t* dest = buf; |
29 | 29 | ||
30 | if (!src) { | 30 | if (!src) { |
31 | return -EINVAL; | 31 | return -EINVAL; |
32 | } | 32 | } |
33 | 33 | ||
34 | /* fill buffer from src[] until null descriptor ptr */ | 34 | /* fill buffer from src[] until null descriptor ptr */ |
35 | for (; 0 != *src; src++) { | 35 | for (; 0 != *src; src++) { |
36 | unsigned len = (*src)->bLength; | 36 | unsigned len = (*src)->bLength; |
37 | 37 | ||
38 | logf("len: %d", len); | 38 | logf("len: %d", len); |
39 | 39 | ||
40 | if (len > buflen) | 40 | if (len > buflen) |
41 | return -EINVAL; | 41 | return -EINVAL; |
42 | memcpy(dest, *src, len); | 42 | memcpy(dest, *src, len); |
43 | buflen -= len; | 43 | buflen -= len; |
44 | dest += len; | 44 | dest += len; |
45 | } | 45 | } |
46 | return dest - (uint8_t *)buf; | 46 | return dest - (uint8_t *)buf; |
47 | } | 47 | } |
48 | 48 | ||
49 | int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf, unsigned length, struct usb_descriptor_header** desc) { | 49 | int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf, unsigned length, struct usb_descriptor_header** desc) |
50 | 50 | { | |
51 | struct usb_config_descriptor* cp = buf; | 51 | struct usb_config_descriptor* cp = buf; |
52 | int len; | 52 | int len; |
53 | |||
54 | if (length < USB_DT_CONFIG_SIZE || !desc) { | ||
55 | return -EINVAL; | ||
56 | } | ||
57 | |||
58 | /* config descriptor first */ | ||
59 | *cp = *config; | ||
60 | |||
61 | /* then interface/endpoint/class/vendor/... */ | ||
62 | len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf, length - USB_DT_CONFIG_SIZE, desc); | ||
63 | |||
64 | if (len < 0) { | ||
65 | return len; | ||
66 | } | ||
53 | 67 | ||
54 | if (length < USB_DT_CONFIG_SIZE || !desc) { | 68 | len += USB_DT_CONFIG_SIZE; |
55 | return -EINVAL; | 69 | if (len > 0xffff) { |
56 | } | 70 | return -EINVAL; |
57 | 71 | } | |
58 | /* config descriptor first */ | ||
59 | *cp = *config; | ||
60 | 72 | ||
61 | /* then interface/endpoint/class/vendor/... */ | 73 | /* patch up the config descriptor */ |
62 | len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf, length - USB_DT_CONFIG_SIZE, desc); | 74 | cp->bLength = USB_DT_CONFIG_SIZE; |
63 | 75 | cp->bDescriptorType = USB_DT_CONFIG; | |
64 | if (len < 0) { | 76 | cp->wTotalLength = len; |
65 | return len; | 77 | cp->bmAttributes |= USB_CONFIG_ATT_ONE; |
66 | } | ||
67 | |||
68 | len += USB_DT_CONFIG_SIZE; | ||
69 | if (len > 0xffff) { | ||
70 | return -EINVAL; | ||
71 | } | ||
72 | 78 | ||
73 | /* patch up the config descriptor */ | 79 | return len; |
74 | cp->bLength = USB_DT_CONFIG_SIZE; | ||
75 | cp->bDescriptorType = USB_DT_CONFIG; | ||
76 | cp->wTotalLength = len; | ||
77 | cp->bmAttributes |= USB_CONFIG_ATT_ONE; | ||
78 | |||
79 | return len; | ||
80 | } | 80 | } |
diff --git a/firmware/usbstack/core/core.c b/firmware/usbstack/core/core.c index 61b7f83636..94131ac3f1 100644 --- a/firmware/usbstack/core/core.c +++ b/firmware/usbstack/core/core.c | |||
@@ -39,26 +39,26 @@ static void bind_device_driver(struct usb_device_driver* driver); | |||
39 | /** | 39 | /** |
40 | * Initialize usb stack. | 40 | * Initialize usb stack. |
41 | */ | 41 | */ |
42 | void usb_stack_init(void) { | 42 | void usb_stack_init(void) |
43 | { | ||
44 | int i; | ||
45 | logf("usb_stack_init"); | ||
43 | 46 | ||
44 | int i; | ||
45 | logf("usb_stack_init"); | ||
46 | |||
47 | /* init datastructures */ | 47 | /* init datastructures */ |
48 | usbcore.controller[0] = NULL; | 48 | usbcore.controller[0] = NULL; |
49 | usbcore.controller[1] = NULL; | 49 | usbcore.controller[1] = NULL; |
50 | usbcore.active_controller = NULL; | 50 | usbcore.active_controller = NULL; |
51 | usbcore.device_driver = NULL; | 51 | usbcore.device_driver = NULL; |
52 | usbcore.running = false; | 52 | usbcore.running = false; |
53 | 53 | ||
54 | memset(&device_driver_names, 0, USB_STACK_MAX_SETTINGS_NAME); | 54 | memset(&device_driver_names, 0, USB_STACK_MAX_SETTINGS_NAME); |
55 | 55 | ||
56 | /* init arrays */ | 56 | /* init arrays */ |
57 | for (i = 0; i < NUM_DRIVERS; i++) { | 57 | for (i = 0; i < NUM_DRIVERS; i++) { |
58 | usbcore.device_drivers[i] = NULL; | 58 | usbcore.device_drivers[i] = NULL; |
59 | usbcore.host_drivers[i] = NULL; | 59 | usbcore.host_drivers[i] = NULL; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* init controllers */ | 62 | /* init controllers */ |
63 | #if (USBSTACK_CAPS & CONTROLLER_DEVICE) | 63 | #if (USBSTACK_CAPS & CONTROLLER_DEVICE) |
64 | usb_dcd_init(); | 64 | usb_dcd_init(); |
@@ -77,31 +77,31 @@ void usb_stack_init(void) { | |||
77 | * Start processing of usb stack. This function init | 77 | * Start processing of usb stack. This function init |
78 | * active usb controller. | 78 | * active usb controller. |
79 | */ | 79 | */ |
80 | void usb_stack_start(void) { | 80 | void usb_stack_start(void) |
81 | 81 | { | |
82 | /* are we allready running? */ | 82 | /* are we allready running? */ |
83 | if (usbcore.running) { | 83 | if (usbcore.running) { |
84 | logf("allready running!"); | 84 | logf("allready running!"); |
85 | return; | 85 | return; |
86 | } | 86 | } |
87 | 87 | ||
88 | if (usbcore.active_controller == NULL) { | 88 | if (usbcore.active_controller == NULL) { |
89 | logf("no active controller!"); | 89 | logf("no active controller!"); |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | 92 | ||
93 | /* forward to controller */ | 93 | /* forward to controller */ |
94 | logf("starting controller"); | 94 | logf("starting controller"); |
95 | usbcore.active_controller->start(); | 95 | usbcore.active_controller->start(); |
96 | usbcore.running = true; | 96 | usbcore.running = true; |
97 | 97 | ||
98 | /* look if started controller is a device controller | 98 | /* look if started controller is a device controller |
99 | * and if it has a device driver bind to it */ | 99 | * and if it has a device driver bind to it */ |
100 | logf("check for auto bind"); | 100 | logf("check for auto bind"); |
101 | if (usbcore.active_controller->type == DEVICE) { | 101 | if (usbcore.active_controller->type == DEVICE) { |
102 | if (usbcore.active_controller->device_driver == NULL && usbcore.device_driver != NULL) { | 102 | if (usbcore.active_controller->device_driver == NULL && usbcore.device_driver != NULL) { |
103 | /* bind driver */ | 103 | /* bind driver */ |
104 | logf("binding..."); | 104 | logf("binding..."); |
105 | bind_device_driver(usbcore.device_driver); | 105 | bind_device_driver(usbcore.device_driver); |
106 | } | 106 | } |
107 | } | 107 | } |
@@ -111,15 +111,15 @@ void usb_stack_start(void) { | |||
111 | * Stop processing of usb stack. This function shutsdown | 111 | * Stop processing of usb stack. This function shutsdown |
112 | * active usb controller. | 112 | * active usb controller. |
113 | */ | 113 | */ |
114 | void usb_stack_stop(void) { | 114 | void usb_stack_stop(void) |
115 | { | ||
116 | /* are we allready stopped? */ | ||
117 | if (usbcore.running == false) { | ||
118 | return; | ||
119 | } | ||
115 | 120 | ||
116 | /* are we allready stopped? */ | ||
117 | if (usbcore.running == false) { | ||
118 | return; | ||
119 | } | ||
120 | |||
121 | /* forward to controller */ | 121 | /* forward to controller */ |
122 | usbcore.active_controller->stop(); | 122 | usbcore.active_controller->stop(); |
123 | usbcore.running = false; | 123 | usbcore.running = false; |
124 | } | 124 | } |
125 | 125 | ||
@@ -127,8 +127,8 @@ void usb_stack_stop(void) { | |||
127 | * Gets called by upper layers to indicate that there is | 127 | * Gets called by upper layers to indicate that there is |
128 | * an interrupt waiting for the controller. | 128 | * an interrupt waiting for the controller. |
129 | */ | 129 | */ |
130 | void usb_stack_irq(void) { | 130 | void usb_stack_irq(void) |
131 | 131 | { | |
132 | /* simply notify usb controller */ | 132 | /* simply notify usb controller */ |
133 | if (usbcore.active_controller != NULL && usbcore.active_controller->irq != NULL) { | 133 | if (usbcore.active_controller != NULL && usbcore.active_controller->irq != NULL) { |
134 | usbcore.active_controller->irq(); | 134 | usbcore.active_controller->irq(); |
@@ -140,7 +140,8 @@ void usb_stack_irq(void) { | |||
140 | * to call for maintanence. We need to check if a new device has connected, | 140 | * to call for maintanence. We need to check if a new device has connected, |
141 | * find suitable drivers for new devices. | 141 | * find suitable drivers for new devices. |
142 | */ | 142 | */ |
143 | void usb_stack_work(void) { | 143 | void usb_stack_work(void) |
144 | { | ||
144 | /* TODO will be used with host device controllers | 145 | /* TODO will be used with host device controllers |
145 | * and needs to be called in a loop (thread) */ | 146 | * and needs to be called in a loop (thread) */ |
146 | } | 147 | } |
@@ -153,8 +154,8 @@ void usb_stack_work(void) { | |||
153 | * @param ctrl pointer to controller to register. | 154 | * @param ctrl pointer to controller to register. |
154 | * @return 0 on success else a defined error code. | 155 | * @return 0 on success else a defined error code. |
155 | */ | 156 | */ |
156 | int usb_controller_register(struct usb_controller* ctrl) { | 157 | int usb_controller_register(struct usb_controller* ctrl) |
157 | 158 | { | |
158 | if (ctrl == NULL) { | 159 | if (ctrl == NULL) { |
159 | return EINVAL; | 160 | return EINVAL; |
160 | } | 161 | } |
@@ -220,21 +221,21 @@ int usb_controller_unregister(struct usb_controller* ctrl) { | |||
220 | * | 221 | * |
221 | * @param type of controller to activate. | 222 | * @param type of controller to activate. |
222 | */ | 223 | */ |
223 | void usb_controller_select(int type) { | 224 | void usb_controller_select(int type) |
224 | 225 | { | |
225 | struct usb_controller* new = NULL; | 226 | struct usb_controller* new = NULL; |
226 | 227 | ||
227 | /* check if a controller of the wanted type is already loaded */ | 228 | /* check if a controller of the wanted type is already loaded */ |
228 | if (usbcore.active_controller != NULL && (int)usbcore.active_controller->type == type) { | 229 | if (usbcore.active_controller != NULL && (int)usbcore.active_controller->type == type) { |
229 | logf("controller already set"); | 230 | logf("controller already set"); |
230 | return; | 231 | return; |
231 | } | 232 | } |
232 | 233 | ||
233 | logf("usb_controller_select"); | 234 | logf("usb_controller_select"); |
234 | logf(" -> type: %d", type); | 235 | logf(" -> type: %d", type); |
236 | |||
237 | usbcore.mode = type; | ||
235 | 238 | ||
236 | usbcore.mode = type; | ||
237 | |||
238 | switch (type) { | 239 | switch (type) { |
239 | case DEVICE: | 240 | case DEVICE: |
240 | new = usbcore.controller[0]; | 241 | new = usbcore.controller[0]; |
@@ -246,20 +247,20 @@ void usb_controller_select(int type) { | |||
246 | 247 | ||
247 | /* if there is only one controller, stop here */ | 248 | /* if there is only one controller, stop here */ |
248 | if (new == NULL) { | 249 | if (new == NULL) { |
249 | logf("no suitable cntrl found"); | 250 | logf("no suitable cntrl found"); |
250 | return; | 251 | return; |
251 | } | 252 | } |
252 | 253 | ||
253 | /* shutdown current used controller */ | 254 | /* shutdown current used controller */ |
254 | if (usbcore.active_controller != NULL) { | 255 | if (usbcore.active_controller != NULL) { |
255 | logf("shuting down old one"); | 256 | logf("shuting down old one"); |
256 | usbcore.active_controller->shutdown(); | 257 | usbcore.active_controller->shutdown(); |
257 | } | 258 | } |
258 | 259 | ||
259 | /* set and init new controller */ | 260 | /* set and init new controller */ |
260 | usbcore.active_controller = new; | 261 | usbcore.active_controller = new; |
261 | logf("init controller"); | 262 | logf("init controller"); |
262 | usbcore.active_controller->init(); | 263 | usbcore.active_controller->init(); |
263 | } | 264 | } |
264 | 265 | ||
265 | int usb_stack_get_mode(void) { | 266 | int usb_stack_get_mode(void) { |
@@ -272,10 +273,10 @@ int usb_stack_get_mode(void) { | |||
272 | * @param driver pointer to an usb_device_driver struct. | 273 | * @param driver pointer to an usb_device_driver struct. |
273 | * @return 0 on success, else a defined error code. | 274 | * @return 0 on success, else a defined error code. |
274 | */ | 275 | */ |
275 | int usb_device_driver_register(struct usb_device_driver* driver) { | 276 | int usb_device_driver_register(struct usb_device_driver* driver) |
276 | 277 | { | |
277 | int i; | 278 | int i; |
278 | 279 | ||
279 | if (driver == NULL) { | 280 | if (driver == NULL) { |
280 | return EINVAL; | 281 | return EINVAL; |
281 | } | 282 | } |
@@ -284,109 +285,109 @@ int usb_device_driver_register(struct usb_device_driver* driver) { | |||
284 | logf("usb_stack: register usb driver"); | 285 | logf("usb_stack: register usb driver"); |
285 | for (i = 0; i < NUM_DRIVERS; i++) { | 286 | for (i = 0; i < NUM_DRIVERS; i++) { |
286 | if (usbcore.device_drivers[i] == NULL) { | 287 | if (usbcore.device_drivers[i] == NULL) { |
287 | usbcore.device_drivers[i] = driver; | 288 | usbcore.device_drivers[i] = driver; |
288 | update_driver_names(device_driver_names); | 289 | update_driver_names(device_driver_names); |
289 | return 0; | 290 | return 0; |
290 | } | 291 | } |
291 | } | 292 | } |
292 | 293 | ||
293 | update_driver_names(device_driver_names); | 294 | update_driver_names(device_driver_names); |
294 | 295 | ||
295 | return 0; | 296 | return 0; |
296 | } | 297 | } |
297 | 298 | ||
298 | int usb_device_driver_bind(const char* name) { | 299 | int usb_device_driver_bind(const char* name) { |
299 | 300 | ||
300 | int i; | 301 | int i; |
301 | struct usb_device_driver *tmp = NULL; | 302 | struct usb_device_driver *tmp = NULL; |
302 | struct usb_device_driver *driver = NULL; | 303 | struct usb_device_driver *driver = NULL; |
303 | 304 | ||
304 | if (name == NULL) { | 305 | if (name == NULL) { |
305 | return EINVAL; | 306 | return EINVAL; |
306 | } | 307 | } |
307 | 308 | ||
308 | /* look for driver */ | 309 | /* look for driver */ |
309 | logf("looking for driver %s", name); | 310 | logf("looking for driver %s", name); |
310 | for (i = 0; i < NUM_DRIVERS; i++) { | 311 | for (i = 0; i < NUM_DRIVERS; i++) { |
311 | tmp = usbcore.device_drivers[i]; | 312 | tmp = usbcore.device_drivers[i]; |
312 | if (tmp != NULL && strcmp(name, tmp->name) == 0) { | 313 | if (tmp != NULL && strcmp(name, tmp->name) == 0) { |
313 | driver = tmp; | 314 | driver = tmp; |
314 | } | 315 | } |
315 | } | 316 | } |
316 | 317 | ||
317 | if (driver == NULL) { | 318 | if (driver == NULL) { |
318 | logf("no driver found"); | 319 | logf("no driver found"); |
319 | return ENODRIVERFOUND; | 320 | return ENODRIVERFOUND; |
320 | } | 321 | } |
321 | 322 | ||
322 | /* look if there is an usb controller loaded */ | 323 | /* look if there is an usb controller loaded */ |
323 | if (usbcore.active_controller == NULL) { | 324 | if (usbcore.active_controller == NULL) { |
324 | /* safe choosen driver and set it when controller starts */ | 325 | /* safe choosen driver and set it when controller starts */ |
325 | usbcore.device_driver = driver; | 326 | usbcore.device_driver = driver; |
326 | 327 | ||
327 | } else { | 328 | } else { |
328 | 329 | ||
329 | /* we need to have an active dcd controller */ | 330 | /* we need to have an active dcd controller */ |
330 | if (usbcore.active_controller->type != DEVICE) { | 331 | if (usbcore.active_controller->type != DEVICE) { |
331 | logf("wrong type"); | 332 | logf("wrong type"); |
332 | return EWRONGCONTROLLERTYPE; | 333 | return EWRONGCONTROLLERTYPE; |
333 | } | 334 | } |
334 | 335 | ||
335 | /* bind driver to controller */ | 336 | /* bind driver to controller */ |
336 | bind_device_driver(driver); | 337 | bind_device_driver(driver); |
337 | } | 338 | } |
338 | 339 | ||
339 | return 0; | 340 | return 0; |
340 | } | 341 | } |
341 | 342 | ||
342 | void usb_device_driver_unbind(void) { | 343 | void usb_device_driver_unbind(void) { |
343 | 344 | ||
344 | logf("usb_device_driver_unbind"); | 345 | logf("usb_device_driver_unbind"); |
345 | if (usbcore.active_controller->device_driver != NULL) { | 346 | if (usbcore.active_controller->device_driver != NULL) { |
346 | usbcore.active_controller->device_driver->unbind(); | 347 | usbcore.active_controller->device_driver->unbind(); |
347 | usbcore.active_controller->device_driver = NULL; | 348 | usbcore.active_controller->device_driver = NULL; |
348 | } | 349 | } |
349 | 350 | ||
350 | usbcore.device_driver = NULL; | 351 | usbcore.device_driver = NULL; |
351 | } | 352 | } |
352 | 353 | ||
353 | static void update_driver_names(unsigned char* result) { | 354 | static void update_driver_names(unsigned char* result) { |
354 | 355 | ||
355 | int i; | 356 | int i; |
356 | int pos = 0; | 357 | int pos = 0; |
357 | unsigned char terminator = ','; | 358 | unsigned char terminator = ','; |
358 | struct usb_device_driver* dd = NULL; | 359 | struct usb_device_driver* dd = NULL; |
359 | 360 | ||
360 | /* reset buffer, iterate through drivers and add to char array */ | 361 | /* reset buffer, iterate through drivers and add to char array */ |
361 | memset(result, 0, USB_STACK_MAX_SETTINGS_NAME); | 362 | memset(result, 0, USB_STACK_MAX_SETTINGS_NAME); |
362 | for (i = 0; i < NUM_DRIVERS; i++) { | 363 | for (i = 0; i < NUM_DRIVERS; i++) { |
363 | int len; | 364 | int len; |
364 | dd = usbcore.device_drivers[i]; | 365 | dd = usbcore.device_drivers[i]; |
365 | 366 | ||
366 | if (dd != NULL) { | 367 | if (dd != NULL) { |
367 | len = strlen(dd->name); | 368 | len = strlen(dd->name); |
368 | if (pos > 0) { | 369 | if (pos > 0) { |
369 | memcpy(result + pos, &terminator, 1); | 370 | memcpy(result + pos, &terminator, 1); |
370 | pos++; | 371 | pos++; |
371 | } | 372 | } |
372 | memcpy(result + pos, dd->name, len); | 373 | memcpy(result + pos, dd->name, len); |
373 | pos += len; | 374 | pos += len; |
374 | } | 375 | } |
375 | } | 376 | } |
376 | } | 377 | } |
377 | 378 | ||
378 | static void bind_device_driver(struct usb_device_driver* driver) { | 379 | static void bind_device_driver(struct usb_device_driver* driver) { |
379 | 380 | ||
380 | /* look if there is an old driver */ | 381 | /* look if there is an old driver */ |
381 | if (usbcore.active_controller->device_driver != NULL) { | 382 | if (usbcore.active_controller->device_driver != NULL) { |
382 | usbcore.active_controller->device_driver->unbind(); | 383 | usbcore.active_controller->device_driver->unbind(); |
383 | } | 384 | } |
384 | 385 | ||
385 | /* bind driver to controller */ | 386 | /* bind driver to controller */ |
386 | usbcore.active_controller->device_driver = driver; | 387 | usbcore.active_controller->device_driver = driver; |
387 | 388 | ||
388 | /* init dirver */ | 389 | /* init dirver */ |
389 | driver->bind(usbcore.active_controller->controller_ops); | 390 | driver->bind(usbcore.active_controller->controller_ops); |
390 | } | 391 | } |
391 | 392 | ||
392 | 393 | ||
diff --git a/firmware/usbstack/core/epsetup.c b/firmware/usbstack/core/epsetup.c index 6ae54fb9ac..36c24e6805 100644 --- a/firmware/usbstack/core/epsetup.c +++ b/firmware/usbstack/core/epsetup.c | |||
@@ -25,27 +25,27 @@ | |||
25 | * | 25 | * |
26 | * Naming Convention for Endpoint Names | 26 | * Naming Convention for Endpoint Names |
27 | * | 27 | * |
28 | * - ep1, ep2, ... address is fixed, not direction or type | 28 | * - ep1, ep2, ... address is fixed, not direction or type |
29 | * - ep1in, ep2out, ... address and direction are fixed, not type | 29 | * - ep1in, ep2out, ... address and direction are fixed, not type |
30 | * - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction | 30 | * - ep1-bulk, ep2-bulk, ... address and type are fixed, not direction |
31 | * - ep1in-bulk, ep2out-iso, ... all three are fixed | 31 | * - ep1in-bulk, ep2out-iso, ... all three are fixed |
32 | * - ep-* ... no functionality restrictions | 32 | * - ep-* ... no functionality restrictions |
33 | * | 33 | * |
34 | * Type suffixes are "-bulk", "-iso", or "-int". Numbers are decimal. | 34 | * Type suffixes are "-bulk", "-iso", or "-int". Numbers are decimal. |
35 | * | 35 | * |
36 | */ | 36 | */ |
37 | static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc); | 37 | static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc); |
38 | 38 | ||
39 | void usb_ep_autoconfig_reset(void) { | 39 | void usb_ep_autoconfig_reset(void) |
40 | 40 | { | |
41 | struct usb_ep* ep = NULL; | 41 | struct usb_ep* ep = NULL; |
42 | if (usbcore.active_controller == NULL) { | 42 | if (usbcore.active_controller == NULL) { |
43 | return; | 43 | return; |
44 | } | 44 | } |
45 | 45 | ||
46 | logf("resetting endpoints"); | 46 | logf("resetting endpoints"); |
47 | list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) { | 47 | list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) { |
48 | logf("reset %s", ep->name); | 48 | logf("reset %s", ep->name); |
49 | ep->claimed = false; | 49 | ep->claimed = false; |
50 | } | 50 | } |
51 | } | 51 | } |
@@ -55,48 +55,48 @@ void usb_ep_autoconfig_reset(void) { | |||
55 | * @param desc usb descritpro to use for seraching. | 55 | * @param desc usb descritpro to use for seraching. |
56 | * @return NULL or a valid endpoint. | 56 | * @return NULL or a valid endpoint. |
57 | */ | 57 | */ |
58 | struct usb_ep* usb_ep_autoconfig(struct usb_endpoint_descriptor* desc) { | 58 | struct usb_ep* usb_ep_autoconfig(struct usb_endpoint_descriptor* desc) |
59 | 59 | { | |
60 | struct usb_ep* ep = NULL; | 60 | struct usb_ep* ep = NULL; |
61 | if (usbcore.active_controller == NULL) { | 61 | if (usbcore.active_controller == NULL) { |
62 | logf("active controller NULL"); | 62 | logf("active controller NULL"); |
63 | return NULL; | 63 | return NULL; |
64 | } | 64 | } |
65 | 65 | ||
66 | list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) { | 66 | list_for_each_entry(ep, &usbcore.active_controller->endpoints.list, list) { |
67 | if (ep_matches (ep, desc)) { | 67 | if (ep_matches (ep, desc)) { |
68 | return ep; | 68 | return ep; |
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | return NULL; | 72 | return NULL; |
73 | } | 73 | } |
74 | 74 | ||
75 | static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) { | 75 | static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) |
76 | 76 | { | |
77 | uint8_t type; | 77 | uint8_t type; |
78 | const char* tmp; | 78 | const char* tmp; |
79 | uint16_t max; | 79 | uint16_t max; |
80 | 80 | ||
81 | /* endpoint already claimed? */ | 81 | /* endpoint already claimed? */ |
82 | if (ep->claimed) { | 82 | if (ep->claimed) { |
83 | logf("!! claimed !!"); | 83 | logf("!! claimed !!"); |
84 | return 0; | 84 | return 0; |
85 | } | 85 | } |
86 | 86 | ||
87 | /* only support ep0 for portable CONTROL traffic */ | 87 | /* only support ep0 for portable CONTROL traffic */ |
88 | type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; | 88 | type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; |
89 | if (type == USB_ENDPOINT_XFER_CONTROL) { | 89 | if (type == USB_ENDPOINT_XFER_CONTROL) { |
90 | logf("type == control"); | 90 | logf("type == control"); |
91 | return 0; | 91 | return 0; |
92 | } | 92 | } |
93 | 93 | ||
94 | /* some other naming convention */ | 94 | /* some other naming convention */ |
95 | if (ep->name[0] != 'e') { | 95 | if (ep->name[0] != 'e') { |
96 | logf("wrong name"); | 96 | logf("wrong name"); |
97 | return 0; | 97 | return 0; |
98 | } | 98 | } |
99 | 99 | ||
100 | /* type-restriction: "-iso", "-bulk", or "-int". | 100 | /* type-restriction: "-iso", "-bulk", or "-int". |
101 | * direction-restriction: "in", "out". | 101 | * direction-restriction: "in", "out". |
102 | */ | 102 | */ |
@@ -111,20 +111,20 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) { | |||
111 | if (tmp[2] == 's') { // == "-iso" | 111 | if (tmp[2] == 's') { // == "-iso" |
112 | return 0; | 112 | return 0; |
113 | } | 113 | } |
114 | break; | 114 | break; |
115 | case USB_ENDPOINT_XFER_BULK: | 115 | case USB_ENDPOINT_XFER_BULK: |
116 | if (tmp[1] != 'b') { // != "-bulk" | 116 | if (tmp[1] != 'b') { // != "-bulk" |
117 | return 0; | 117 | return 0; |
118 | } | 118 | } |
119 | break; | 119 | break; |
120 | case USB_ENDPOINT_XFER_ISOC: | 120 | case USB_ENDPOINT_XFER_ISOC: |
121 | if (tmp[2] != 's') { // != "-iso" | 121 | if (tmp[2] != 's') { // != "-iso" |
122 | return 0; | 122 | return 0; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | } else { | 125 | } else { |
126 | tmp = ep->name + strlen (ep->name); | 126 | tmp = ep->name + strlen (ep->name); |
127 | } | 127 | } |
128 | 128 | ||
129 | /* direction-restriction: "..in-..", "out-.." */ | 129 | /* direction-restriction: "..in-..", "out-.." */ |
130 | tmp--; | 130 | tmp--; |
@@ -132,7 +132,7 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) { | |||
132 | if (desc->bEndpointAddress & USB_DIR_IN) { | 132 | if (desc->bEndpointAddress & USB_DIR_IN) { |
133 | if ('n' != *tmp) { | 133 | if ('n' != *tmp) { |
134 | return 0; | 134 | return 0; |
135 | } | 135 | } |
136 | } else { | 136 | } else { |
137 | if ('t' != *tmp) { | 137 | if ('t' != *tmp) { |
138 | return 0; | 138 | return 0; |
@@ -147,40 +147,40 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc) { | |||
147 | * the usb spec fixes high speed bulk maxpacket at 512 bytes. | 147 | * the usb spec fixes high speed bulk maxpacket at 512 bytes. |
148 | */ | 148 | */ |
149 | max = 0x7ff & desc->wMaxPacketSize; | 149 | max = 0x7ff & desc->wMaxPacketSize; |
150 | 150 | ||
151 | switch (type) { | 151 | switch (type) { |
152 | case USB_ENDPOINT_XFER_INT: | 152 | case USB_ENDPOINT_XFER_INT: |
153 | /* INT: limit 64 bytes full speed, 1024 high speed */ | 153 | /* INT: limit 64 bytes full speed, 1024 high speed */ |
154 | if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 64)) { | 154 | if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 64)) { |
155 | return 0; | 155 | return 0; |
156 | } | 156 | } |
157 | /* FALLTHROUGH */ | 157 | /* FALLTHROUGH */ |
158 | 158 | ||
159 | case USB_ENDPOINT_XFER_ISOC: | 159 | case USB_ENDPOINT_XFER_ISOC: |
160 | if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 1023)) { | 160 | if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 1023)) { |
161 | return 0; | 161 | return 0; |
162 | } | 162 | } |
163 | break; | 163 | break; |
164 | } | 164 | } |
165 | 165 | ||
166 | /* MATCH!! */ | 166 | /* MATCH!! */ |
167 | 167 | ||
168 | /* report address */ | 168 | /* report address */ |
169 | desc->bEndpointAddress |= ep->ep_num; | 169 | desc->bEndpointAddress |= ep->ep_num; |
170 | 170 | ||
171 | /* report (variable) full speed bulk maxpacket */ | 171 | /* report (variable) full speed bulk maxpacket */ |
172 | if (type == USB_ENDPOINT_XFER_BULK) { | 172 | if (type == USB_ENDPOINT_XFER_BULK) { |
173 | int size = max; | 173 | int size = max; |
174 | 174 | ||
175 | /* min() doesn't work on bitfields with gcc-3.5 */ | 175 | /* min() doesn't work on bitfields with gcc-3.5 */ |
176 | if (size > 64) { | 176 | if (size > 64) { |
177 | size = 64; | 177 | size = 64; |
178 | } | 178 | } |
179 | desc->wMaxPacketSize = size; | 179 | desc->wMaxPacketSize = size; |
180 | } | 180 | } |
181 | 181 | ||
182 | /* save desc in endpoint */ | 182 | /* save desc in endpoint */ |
183 | ep->desc = desc; | 183 | ep->desc = desc; |
184 | 184 | ||
185 | return 1; | 185 | return 1; |
186 | } | 186 | } |
diff --git a/firmware/usbstack/core/utils.c b/firmware/usbstack/core/utils.c index 2fb2695732..0ec4faa098 100644 --- a/firmware/usbstack/core/utils.c +++ b/firmware/usbstack/core/utils.c | |||
@@ -20,98 +20,98 @@ | |||
20 | #include <string.h> | 20 | #include <string.h> |
21 | #include "usbstack/core.h" | 21 | #include "usbstack/core.h" |
22 | 22 | ||
23 | void into_usb_ctrlrequest(struct usb_ctrlrequest* request) { | 23 | void into_usb_ctrlrequest(struct usb_ctrlrequest* request) |
24 | { | ||
25 | char* type = ""; | ||
26 | char* req = ""; | ||
27 | char* extra = 0; | ||
24 | 28 | ||
25 | char* type = ""; | 29 | logf("-usb request-"); |
26 | char* req = ""; | ||
27 | char* extra = 0; | ||
28 | |||
29 | logf("-usb request-"); | ||
30 | /* check if packet is okay */ | 30 | /* check if packet is okay */ |
31 | if (request->bRequestType == 0 && | 31 | if (request->bRequestType == 0 && |
32 | request->bRequest == 0 && | 32 | request->bRequest == 0 && |
33 | request->wValue == 0 && | 33 | request->wValue == 0 && |
34 | request->wIndex == 0 && | 34 | request->wIndex == 0 && |
35 | request->wLength == 0) { | 35 | request->wLength == 0) { |
36 | logf(" -> INVALID <-"); | 36 | logf(" -> INVALID <-"); |
37 | return; | 37 | return; |
38 | } | 38 | } |
39 | 39 | ||
40 | switch (request->bRequestType & USB_TYPE_MASK) { | 40 | switch (request->bRequestType & USB_TYPE_MASK) { |
41 | case USB_TYPE_STANDARD: | 41 | case USB_TYPE_STANDARD: |
42 | type = "standard"; | 42 | type = "standard"; |
43 | 43 | ||
44 | switch (request->bRequest) { | 44 | switch (request->bRequest) { |
45 | case USB_REQ_GET_STATUS: | 45 | case USB_REQ_GET_STATUS: |
46 | req = "get status"; | 46 | req = "get status"; |
47 | break; | 47 | break; |
48 | case USB_REQ_CLEAR_FEATURE: | 48 | case USB_REQ_CLEAR_FEATURE: |
49 | req = "clear feature"; | 49 | req = "clear feature"; |
50 | break; | 50 | break; |
51 | case USB_REQ_SET_FEATURE: | 51 | case USB_REQ_SET_FEATURE: |
52 | req = "set feature"; | 52 | req = "set feature"; |
53 | break; | 53 | break; |
54 | case USB_REQ_SET_ADDRESS: | 54 | case USB_REQ_SET_ADDRESS: |
55 | req = "set address"; | 55 | req = "set address"; |
56 | break; | 56 | break; |
57 | case USB_REQ_GET_DESCRIPTOR: | 57 | case USB_REQ_GET_DESCRIPTOR: |
58 | req = "get descriptor"; | 58 | req = "get descriptor"; |
59 | 59 | ||
60 | switch (request->wValue >> 8) { | 60 | switch (request->wValue >> 8) { |
61 | case USB_DT_DEVICE: | 61 | case USB_DT_DEVICE: |
62 | extra = "get device descriptor"; | 62 | extra = "get device descriptor"; |
63 | break; | 63 | break; |
64 | case USB_DT_DEVICE_QUALIFIER: | 64 | case USB_DT_DEVICE_QUALIFIER: |
65 | extra = "get device qualifier"; | 65 | extra = "get device qualifier"; |
66 | break; | 66 | break; |
67 | case USB_DT_OTHER_SPEED_CONFIG: | 67 | case USB_DT_OTHER_SPEED_CONFIG: |
68 | extra = "get other-speed config descriptor"; | 68 | extra = "get other-speed config descriptor"; |
69 | case USB_DT_CONFIG: | 69 | case USB_DT_CONFIG: |
70 | extra = "get configuration descriptor"; | 70 | extra = "get configuration descriptor"; |
71 | break; | 71 | break; |
72 | case USB_DT_STRING: | 72 | case USB_DT_STRING: |
73 | extra = "get string descriptor"; | 73 | extra = "get string descriptor"; |
74 | break; | 74 | break; |
75 | case USB_DT_DEBUG: | 75 | case USB_DT_DEBUG: |
76 | extra = "debug"; | 76 | extra = "debug"; |
77 | break; | 77 | break; |
78 | } | 78 | } |
79 | break; | 79 | break; |
80 | 80 | ||
81 | break; | 81 | break; |
82 | case USB_REQ_SET_DESCRIPTOR: | 82 | case USB_REQ_SET_DESCRIPTOR: |
83 | req = "set descriptor"; | 83 | req = "set descriptor"; |
84 | break; | 84 | break; |
85 | case USB_REQ_GET_CONFIGURATION: | 85 | case USB_REQ_GET_CONFIGURATION: |
86 | req = "get configuration"; | 86 | req = "get configuration"; |
87 | break; | 87 | break; |
88 | case USB_REQ_SET_CONFIGURATION: | 88 | case USB_REQ_SET_CONFIGURATION: |
89 | req = "set configuration"; | 89 | req = "set configuration"; |
90 | break; | 90 | break; |
91 | case USB_REQ_GET_INTERFACE: | 91 | case USB_REQ_GET_INTERFACE: |
92 | req = "get interface"; | 92 | req = "get interface"; |
93 | break; | 93 | break; |
94 | case USB_REQ_SET_INTERFACE: | 94 | case USB_REQ_SET_INTERFACE: |
95 | req = "set interface"; | 95 | req = "set interface"; |
96 | break; | 96 | break; |
97 | case USB_REQ_SYNCH_FRAME: | 97 | case USB_REQ_SYNCH_FRAME: |
98 | req = "sync frame"; | 98 | req = "sync frame"; |
99 | break; | 99 | break; |
100 | default: | 100 | default: |
101 | req = "unkown"; | 101 | req = "unkown"; |
102 | break; | 102 | break; |
103 | } | 103 | } |
104 | 104 | ||
105 | break; | 105 | break; |
106 | case USB_TYPE_CLASS: | 106 | case USB_TYPE_CLASS: |
107 | type = "class"; | 107 | type = "class"; |
108 | break; | 108 | break; |
109 | 109 | ||
110 | case USB_TYPE_VENDOR: | 110 | case USB_TYPE_VENDOR: |
111 | type = "vendor"; | 111 | type = "vendor"; |
112 | break; | 112 | break; |
113 | } | 113 | } |
114 | 114 | ||
115 | logf(" -b 0x%x", request->bRequestType); | 115 | logf(" -b 0x%x", request->bRequestType); |
116 | logf(" -b 0x%x", request->bRequest); | 116 | logf(" -b 0x%x", request->bRequest); |
117 | logf(" -b 0x%x", request->wValue); | 117 | logf(" -b 0x%x", request->wValue); |
@@ -120,6 +120,6 @@ void into_usb_ctrlrequest(struct usb_ctrlrequest* request) { | |||
120 | logf(" -> t: %s", type); | 120 | logf(" -> t: %s", type); |
121 | logf(" -> r: %s", req); | 121 | logf(" -> r: %s", req); |
122 | if (extra != 0) { | 122 | if (extra != 0) { |
123 | logf(" -> e: %s", extra); | 123 | logf(" -> e: %s", extra); |
124 | } | 124 | } |
125 | } | 125 | } |