usbdcore_ep0.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /*
  2. * (C) Copyright 2003
  3. * Gerry Hamel, geh@ti.com, Texas Instruments
  4. *
  5. * Based on
  6. * linux/drivers/usbd/ep0.c
  7. *
  8. * Copyright (c) 2000, 2001, 2002 Lineo
  9. * Copyright (c) 2001 Hewlett Packard
  10. *
  11. * By:
  12. * Stuart Lynne <sl@lineo.com>,
  13. * Tom Rushworth <tbr@lineo.com>,
  14. * Bruce Balden <balden@lineo.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  29. *
  30. */
  31. /*
  32. * This is the builtin ep0 control function. It implements all required functionality
  33. * for responding to control requests (SETUP packets).
  34. *
  35. * XXX
  36. *
  37. * Currently we do not pass any SETUP packets (or other) to the configured
  38. * function driver. This may need to change.
  39. *
  40. * XXX
  41. */
  42. #include <common.h>
  43. #if defined(CONFIG_OMAP1510) && defined(CONFIG_USB_DEVICE)
  44. #include "usbdcore.h"
  45. #if 0
  46. #define dbg_ep0(lvl,fmt,args...) serial_printf("[%s] %s:%d: "fmt"\n",__FILE__,__FUNCTION__,__LINE__,##args)
  47. #else
  48. #define dbg_ep0(lvl,fmt,args...)
  49. #endif
  50. /* EP0 Configuration Set ********************************************************************* */
  51. /**
  52. * ep0_get_status - fill in URB data with appropriate status
  53. * @device:
  54. * @urb:
  55. * @index:
  56. * @requesttype:
  57. *
  58. */
  59. static int ep0_get_status (struct usb_device_instance *device,
  60. struct urb *urb, int index, int requesttype)
  61. {
  62. char *cp;
  63. urb->actual_length = 2;
  64. cp = urb->buffer;
  65. cp[0] = cp[1] = 0;
  66. switch (requesttype) {
  67. case USB_REQ_RECIPIENT_DEVICE:
  68. cp[0] = USB_STATUS_SELFPOWERED;
  69. break;
  70. case USB_REQ_RECIPIENT_INTERFACE:
  71. break;
  72. case USB_REQ_RECIPIENT_ENDPOINT:
  73. cp[0] = usbd_endpoint_halted (device, index);
  74. break;
  75. case USB_REQ_RECIPIENT_OTHER:
  76. urb->actual_length = 0;
  77. default:
  78. break;
  79. }
  80. dbg_ep0 (2, "%02x %02x", cp[0], cp[1]);
  81. return 0;
  82. }
  83. /**
  84. * ep0_get_one
  85. * @device:
  86. * @urb:
  87. * @result:
  88. *
  89. * Set a single byte value in the urb send buffer. Return non-zero to signal
  90. * a request error.
  91. */
  92. static int ep0_get_one (struct usb_device_instance *device, struct urb *urb,
  93. __u8 result)
  94. {
  95. urb->actual_length = 1; /* XXX 2? */
  96. ((char *) urb->buffer)[0] = result;
  97. return 0;
  98. }
  99. /**
  100. * copy_config
  101. * @urb: pointer to urb
  102. * @data: pointer to configuration data
  103. * @length: length of data
  104. *
  105. * Copy configuration data to urb transfer buffer if there is room for it.
  106. */
  107. static void copy_config (struct urb *urb, void *data, int max_length,
  108. int max_buf)
  109. {
  110. int available;
  111. int length;
  112. /*dbg_ep0(3, "-> actual: %d buf: %d max_buf: %d max_length: %d data: %p", */
  113. /* urb->actual_length, urb->buffer_length, max_buf, max_length, data); */
  114. if (!data) {
  115. dbg_ep0 (1, "data is NULL");
  116. return;
  117. }
  118. if (!(length = *(unsigned char *) data)) {
  119. dbg_ep0 (1, "length is zero");
  120. return;
  121. }
  122. if (length > max_length) {
  123. dbg_ep0 (1, "length: %d >= max_length: %d", length,
  124. max_length);
  125. return;
  126. }
  127. /*dbg_ep0(1, " actual: %d buf: %d max_buf: %d max_length: %d length: %d", */
  128. /* urb->actual_length, urb->buffer_length, max_buf, max_length, length); */
  129. if ((available =
  130. /*urb->buffer_length */ max_buf - urb->actual_length) <= 0) {
  131. return;
  132. }
  133. /*dbg_ep0(1, "actual: %d buf: %d max_buf: %d length: %d available: %d", */
  134. /* urb->actual_length, urb->buffer_length, max_buf, length, available); */
  135. if (length > available) {
  136. length = available;
  137. }
  138. /*dbg_ep0(1, "actual: %d buf: %d max_buf: %d length: %d available: %d", */
  139. /* urb->actual_length, urb->buffer_length, max_buf, length, available); */
  140. memcpy (urb->buffer + urb->actual_length, data, length);
  141. urb->actual_length += length;
  142. dbg_ep0 (3,
  143. "copy_config: <- actual: %d buf: %d max_buf: %d max_length: %d available: %d",
  144. urb->actual_length, urb->buffer_length, max_buf, max_length,
  145. available);
  146. }
  147. /**
  148. * ep0_get_descriptor
  149. * @device:
  150. * @urb:
  151. * @max:
  152. * @descriptor_type:
  153. * @index:
  154. *
  155. * Called by ep0_rx_process for a get descriptor device command. Determine what
  156. * descriptor is being requested, copy to send buffer. Return zero if ok to send,
  157. * return non-zero to signal a request error.
  158. */
  159. static int ep0_get_descriptor (struct usb_device_instance *device,
  160. struct urb *urb, int max, int descriptor_type,
  161. int index)
  162. {
  163. int port = 0; /* XXX compound device */
  164. char *cp;
  165. /*dbg_ep0(3, "max: %x type: %x index: %x", max, descriptor_type, index); */
  166. if (!urb || !urb->buffer || !urb->buffer_length
  167. || (urb->buffer_length < 255)) {
  168. dbg_ep0 (2, "invalid urb %p", urb);
  169. return -1L;
  170. }
  171. /* setup tx urb */
  172. urb->actual_length = 0;
  173. cp = urb->buffer;
  174. dbg_ep0 (2, "%s", USBD_DEVICE_DESCRIPTORS (descriptor_type));
  175. switch (descriptor_type) {
  176. case USB_DESCRIPTOR_TYPE_DEVICE:
  177. {
  178. struct usb_device_descriptor *device_descriptor;
  179. if (!
  180. (device_descriptor =
  181. usbd_device_device_descriptor (device, port))) {
  182. return -1;
  183. }
  184. /* copy descriptor for this device */
  185. copy_config (urb, device_descriptor,
  186. sizeof (struct usb_device_descriptor),
  187. max);
  188. /* correct the correct control endpoint 0 max packet size into the descriptor */
  189. device_descriptor =
  190. (struct usb_device_descriptor *) urb->buffer;
  191. device_descriptor->bMaxPacketSize0 =
  192. urb->device->bus->maxpacketsize;
  193. }
  194. /*dbg_ep0(3, "copied device configuration, actual_length: %x", urb->actual_length); */
  195. break;
  196. case USB_DESCRIPTOR_TYPE_CONFIGURATION:
  197. {
  198. int bNumInterface;
  199. struct usb_configuration_descriptor
  200. *configuration_descriptor;
  201. struct usb_device_descriptor *device_descriptor;
  202. if (!
  203. (device_descriptor =
  204. usbd_device_device_descriptor (device, port))) {
  205. return -1;
  206. }
  207. /*dbg_ep0(2, "%d %d", index, device_descriptor->bNumConfigurations); */
  208. if (index > device_descriptor->bNumConfigurations) {
  209. dbg_ep0 (0, "index too large: %d > %d", index,
  210. device_descriptor->
  211. bNumConfigurations);
  212. return -1;
  213. }
  214. if (!
  215. (configuration_descriptor =
  216. usbd_device_configuration_descriptor (device,
  217. port,
  218. index))) {
  219. dbg_ep0 (0,
  220. "usbd_device_configuration_descriptor failed: %d",
  221. index);
  222. return -1;
  223. }
  224. copy_config (urb, configuration_descriptor,
  225. sizeof (struct
  226. usb_configuration_descriptor),
  227. max);
  228. /* iterate across interfaces for specified configuration */
  229. dbg_ep0 (0, "bNumInterfaces: %d",
  230. configuration_descriptor->bNumInterfaces);
  231. for (bNumInterface = 0;
  232. bNumInterface <
  233. configuration_descriptor->bNumInterfaces;
  234. bNumInterface++) {
  235. int bAlternateSetting;
  236. struct usb_interface_instance
  237. *interface_instance;
  238. dbg_ep0 (3, "[%d] bNumInterfaces: %d",
  239. bNumInterface,
  240. configuration_descriptor->bNumInterfaces);
  241. if (! (interface_instance = usbd_device_interface_instance (device,
  242. port, index, bNumInterface)))
  243. {
  244. dbg_ep0 (3, "[%d] interface_instance NULL",
  245. bNumInterface);
  246. return -1;
  247. }
  248. /* iterate across interface alternates */
  249. for (bAlternateSetting = 0;
  250. bAlternateSetting < interface_instance->alternates;
  251. bAlternateSetting++) {
  252. /*int class; */
  253. int bNumEndpoint;
  254. struct usb_interface_descriptor *interface_descriptor;
  255. struct usb_alternate_instance *alternate_instance;
  256. dbg_ep0 (3, "[%d:%d] alternates: %d",
  257. bNumInterface,
  258. bAlternateSetting,
  259. interface_instance->alternates);
  260. if (! (alternate_instance = usbd_device_alternate_instance (device, port, index, bNumInterface, bAlternateSetting))) {
  261. dbg_ep0 (3, "[%d] alternate_instance NULL",
  262. bNumInterface);
  263. return -1;
  264. }
  265. /* copy descriptor for this interface */
  266. copy_config (urb, alternate_instance->interface_descriptor,
  267. sizeof (struct usb_interface_descriptor),
  268. max);
  269. /*dbg_ep0(3, "[%d:%d] classes: %d endpoints: %d", bNumInterface, bAlternateSetting, */
  270. /* alternate_instance->classes, alternate_instance->endpoints); */
  271. /* iterate across classes for this alternate interface */
  272. #if 0
  273. for (class = 0;
  274. class < alternate_instance->classes;
  275. class++) {
  276. struct usb_class_descriptor *class_descriptor;
  277. /*dbg_ep0(3, "[%d:%d:%d] classes: %d", bNumInterface, bAlternateSetting, */
  278. /* class, alternate_instance->classes); */
  279. if (!(class_descriptor = usbd_device_class_descriptor_index (device, port, index, bNumInterface, bAlternateSetting, class))) {
  280. dbg_ep0 (3, "[%d] class NULL",
  281. class);
  282. return -1;
  283. }
  284. /* copy descriptor for this class */
  285. copy_config (urb, class_descriptor,
  286. sizeof (struct usb_class_descriptor),
  287. max);
  288. }
  289. #endif
  290. /* iterate across endpoints for this alternate interface */
  291. interface_descriptor = alternate_instance->interface_descriptor;
  292. for (bNumEndpoint = 0;
  293. bNumEndpoint < alternate_instance->endpoints;
  294. bNumEndpoint++) {
  295. struct usb_endpoint_descriptor *endpoint_descriptor;
  296. dbg_ep0 (3, "[%d:%d:%d] endpoint: %d",
  297. bNumInterface,
  298. bAlternateSetting,
  299. bNumEndpoint,
  300. interface_descriptor->
  301. bNumEndpoints);
  302. if (!(endpoint_descriptor = usbd_device_endpoint_descriptor_index (device, port, index, bNumInterface, bAlternateSetting, bNumEndpoint))) {
  303. dbg_ep0 (3, "[%d] endpoint NULL",
  304. bNumEndpoint);
  305. return -1;
  306. }
  307. /* copy descriptor for this endpoint */
  308. copy_config (urb, endpoint_descriptor,
  309. sizeof (struct usb_endpoint_descriptor),
  310. max);
  311. }
  312. }
  313. }
  314. dbg_ep0 (3, "lengths: %d %d",
  315. le16_to_cpu (configuration_descriptor->wTotalLength),
  316. urb->actual_length);
  317. }
  318. break;
  319. case USB_DESCRIPTOR_TYPE_STRING:
  320. {
  321. struct usb_string_descriptor *string_descriptor;
  322. if (!(string_descriptor = usbd_get_string (index))) {
  323. return -1;
  324. }
  325. /*dbg_ep0(3, "string_descriptor: %p", string_descriptor); */
  326. copy_config (urb, string_descriptor, string_descriptor->bLength, max);
  327. }
  328. break;
  329. case USB_DESCRIPTOR_TYPE_INTERFACE:
  330. return -1;
  331. case USB_DESCRIPTOR_TYPE_ENDPOINT:
  332. return -1;
  333. case USB_DESCRIPTOR_TYPE_HID:
  334. {
  335. return -1; /* unsupported at this time */
  336. #if 0
  337. int bNumInterface =
  338. le16_to_cpu (urb->device_request.wIndex);
  339. int bAlternateSetting = 0;
  340. int class = 0;
  341. struct usb_class_descriptor *class_descriptor;
  342. if (!(class_descriptor =
  343. usbd_device_class_descriptor_index (device,
  344. port, 0,
  345. bNumInterface,
  346. bAlternateSetting,
  347. class))
  348. || class_descriptor->descriptor.hid.bDescriptorType != USB_DT_HID) {
  349. dbg_ep0 (3, "[%d] interface is not HID",
  350. bNumInterface);
  351. return -1;
  352. }
  353. /* copy descriptor for this class */
  354. copy_config (urb, class_descriptor,
  355. class_descriptor->descriptor.hid.bLength,
  356. max);
  357. #endif
  358. }
  359. break;
  360. case USB_DESCRIPTOR_TYPE_REPORT:
  361. {
  362. return -1; /* unsupported at this time */
  363. #if 0
  364. int bNumInterface =
  365. le16_to_cpu (urb->device_request.wIndex);
  366. int bAlternateSetting = 0;
  367. int class = 0;
  368. struct usb_class_report_descriptor *report_descriptor;
  369. if (!(report_descriptor =
  370. usbd_device_class_report_descriptor_index
  371. (device, port, 0, bNumInterface,
  372. bAlternateSetting, class))
  373. || report_descriptor->bDescriptorType !=
  374. USB_DT_REPORT) {
  375. dbg_ep0 (3, "[%d] descriptor is not REPORT",
  376. bNumInterface);
  377. return -1;
  378. }
  379. /* copy report descriptor for this class */
  380. /*copy_config(urb, &report_descriptor->bData[0], report_descriptor->wLength, max); */
  381. if (max - urb->actual_length > 0) {
  382. int length =
  383. MIN (report_descriptor->wLength,
  384. max - urb->actual_length);
  385. memcpy (urb->buffer + urb->actual_length,
  386. &report_descriptor->bData[0], length);
  387. urb->actual_length += length;
  388. }
  389. #endif
  390. }
  391. break;
  392. default:
  393. return -1;
  394. }
  395. dbg_ep0 (1, "urb: buffer: %p buffer_length: %2d actual_length: %2d packet size: %2d",
  396. urb->buffer, urb->buffer_length, urb->actual_length,
  397. device->bus->endpoint_array[0].tx_packetSize);
  398. /*
  399. if ((urb->actual_length < max) && !(urb->actual_length % device->bus->endpoint_array[0].tx_packetSize)) {
  400. dbg_ep0(0, "adding null byte");
  401. urb->buffer[urb->actual_length++] = 0;
  402. dbg_ep0(0, "urb: buffer_length: %2d actual_length: %2d packet size: %2d",
  403. urb->buffer_length, urb->actual_length device->bus->endpoint_array[0].tx_packetSize);
  404. }
  405. */
  406. return 0;
  407. }
  408. /**
  409. * ep0_recv_setup - called to indicate URB has been received
  410. * @urb: pointer to struct urb
  411. *
  412. * Check if this is a setup packet, process the device request, put results
  413. * back into the urb and return zero or non-zero to indicate success (DATA)
  414. * or failure (STALL).
  415. *
  416. */
  417. int ep0_recv_setup (struct urb *urb)
  418. {
  419. /*struct usb_device_request *request = urb->buffer; */
  420. /*struct usb_device_instance *device = urb->device; */
  421. struct usb_device_request *request;
  422. struct usb_device_instance *device;
  423. int address;
  424. dbg_ep0 (0, "entering ep0_recv_setup()");
  425. if (!urb || !urb->device) {
  426. dbg_ep0 (3, "invalid URB %p", urb);
  427. return -1;
  428. }
  429. request = &urb->device_request;
  430. device = urb->device;
  431. dbg_ep0 (3, "urb: %p device: %p", urb, urb->device);
  432. /*dbg_ep0(2, "- - - - - - - - - -"); */
  433. dbg_ep0 (2,
  434. "bmRequestType:%02x bRequest:%02x wValue:%04x wIndex:%04x wLength:%04x %s",
  435. request->bmRequestType, request->bRequest,
  436. le16_to_cpu (request->wValue), le16_to_cpu (request->wIndex),
  437. le16_to_cpu (request->wLength),
  438. USBD_DEVICE_REQUESTS (request->bRequest));
  439. /* handle USB Standard Request (c.f. USB Spec table 9-2) */
  440. if ((request->bmRequestType & USB_REQ_TYPE_MASK) != 0) {
  441. dbg_ep0 (1, "non standard request: %x",
  442. request->bmRequestType & USB_REQ_TYPE_MASK);
  443. return -1; /* Stall here */
  444. }
  445. switch (device->device_state) {
  446. case STATE_CREATED:
  447. case STATE_ATTACHED:
  448. case STATE_POWERED:
  449. /* It actually is important to allow requests in these states,
  450. * Windows will request descriptors before assigning an
  451. * address to the client.
  452. */
  453. /*dbg_ep0 (1, "request %s not allowed in this state: %s", */
  454. /* USBD_DEVICE_REQUESTS(request->bRequest), */
  455. /* usbd_device_states[device->device_state]); */
  456. /*return -1; */
  457. break;
  458. case STATE_INIT:
  459. case STATE_DEFAULT:
  460. switch (request->bRequest) {
  461. case USB_REQ_GET_STATUS:
  462. case USB_REQ_GET_INTERFACE:
  463. case USB_REQ_SYNCH_FRAME: /* XXX should never see this (?) */
  464. case USB_REQ_CLEAR_FEATURE:
  465. case USB_REQ_SET_FEATURE:
  466. case USB_REQ_SET_DESCRIPTOR:
  467. /* case USB_REQ_SET_CONFIGURATION: */
  468. case USB_REQ_SET_INTERFACE:
  469. dbg_ep0 (1,
  470. "request %s not allowed in DEFAULT state: %s",
  471. USBD_DEVICE_REQUESTS (request->bRequest),
  472. usbd_device_states[device->device_state]);
  473. return -1;
  474. case USB_REQ_SET_CONFIGURATION:
  475. case USB_REQ_SET_ADDRESS:
  476. case USB_REQ_GET_DESCRIPTOR:
  477. case USB_REQ_GET_CONFIGURATION:
  478. break;
  479. }
  480. case STATE_ADDRESSED:
  481. case STATE_CONFIGURED:
  482. break;
  483. case STATE_UNKNOWN:
  484. dbg_ep0 (1, "request %s not allowed in UNKNOWN state: %s",
  485. USBD_DEVICE_REQUESTS (request->bRequest),
  486. usbd_device_states[device->device_state]);
  487. return -1;
  488. }
  489. /* handle all requests that return data (direction bit set on bm RequestType) */
  490. if ((request->bmRequestType & USB_REQ_DIRECTION_MASK)) {
  491. dbg_ep0 (3, "Device-to-Host");
  492. switch (request->bRequest) {
  493. case USB_REQ_GET_STATUS:
  494. return ep0_get_status (device, urb, request->wIndex,
  495. request->bmRequestType &
  496. USB_REQ_RECIPIENT_MASK);
  497. case USB_REQ_GET_DESCRIPTOR:
  498. return ep0_get_descriptor (device, urb,
  499. le16_to_cpu (request->wLength),
  500. le16_to_cpu (request->wValue) >> 8,
  501. le16_to_cpu (request->wValue) & 0xff);
  502. case USB_REQ_GET_CONFIGURATION:
  503. return ep0_get_one (device, urb,
  504. device->configuration);
  505. case USB_REQ_GET_INTERFACE:
  506. return ep0_get_one (device, urb, device->alternate);
  507. case USB_REQ_SYNCH_FRAME: /* XXX should never see this (?) */
  508. return -1;
  509. case USB_REQ_CLEAR_FEATURE:
  510. case USB_REQ_SET_FEATURE:
  511. case USB_REQ_SET_ADDRESS:
  512. case USB_REQ_SET_DESCRIPTOR:
  513. case USB_REQ_SET_CONFIGURATION:
  514. case USB_REQ_SET_INTERFACE:
  515. return -1;
  516. }
  517. }
  518. /* handle the requests that do not return data */
  519. else {
  520. /*dbg_ep0(3, "Host-to-Device"); */
  521. switch (request->bRequest) {
  522. case USB_REQ_CLEAR_FEATURE:
  523. case USB_REQ_SET_FEATURE:
  524. dbg_ep0 (0, "Host-to-Device");
  525. switch (request->
  526. bmRequestType & USB_REQ_RECIPIENT_MASK) {
  527. case USB_REQ_RECIPIENT_DEVICE:
  528. /* XXX DEVICE_REMOTE_WAKEUP or TEST_MODE would be added here */
  529. /* XXX fall through for now as we do not support either */
  530. case USB_REQ_RECIPIENT_INTERFACE:
  531. case USB_REQ_RECIPIENT_OTHER:
  532. dbg_ep0 (0, "request %s not",
  533. USBD_DEVICE_REQUESTS (request->bRequest));
  534. default:
  535. return -1;
  536. case USB_REQ_RECIPIENT_ENDPOINT:
  537. dbg_ep0 (0, "ENDPOINT: %x", le16_to_cpu (request->wValue));
  538. if (le16_to_cpu (request->wValue) == USB_ENDPOINT_HALT) {
  539. /*return usbd_device_feature (device, le16_to_cpu (request->wIndex), */
  540. /* request->bRequest == USB_REQ_SET_FEATURE); */
  541. /* NEED TO IMPLEMENT THIS!!! */
  542. return -1;
  543. } else {
  544. dbg_ep0 (1, "request %s bad wValue: %04x",
  545. USBD_DEVICE_REQUESTS
  546. (request->bRequest),
  547. le16_to_cpu (request->wValue));
  548. return -1;
  549. }
  550. }
  551. case USB_REQ_SET_ADDRESS:
  552. /* check if this is a re-address, reset first if it is (this shouldn't be possible) */
  553. if (device->device_state != STATE_DEFAULT) {
  554. dbg_ep0 (1, "set_address: %02x state: %s",
  555. le16_to_cpu (request->wValue),
  556. usbd_device_states[device->device_state]);
  557. return -1;
  558. }
  559. address = le16_to_cpu (request->wValue);
  560. if ((address & 0x7f) != address) {
  561. dbg_ep0 (1, "invalid address %04x %04x",
  562. address, address & 0x7f);
  563. return -1;
  564. }
  565. device->address = address;
  566. /*dbg_ep0(2, "address: %d %d %d", */
  567. /* request->wValue, le16_to_cpu(request->wValue), device->address); */
  568. serial_printf ("DEVICE_ADDRESS_ASSIGNED.. event?\n");
  569. return 0;
  570. case USB_REQ_SET_DESCRIPTOR: /* XXX should we support this? */
  571. dbg_ep0 (0, "set descriptor: NOT SUPPORTED");
  572. return -1;
  573. case USB_REQ_SET_CONFIGURATION:
  574. /* c.f. 9.4.7 - the top half of wValue is reserved */
  575. /* */
  576. if ((device->configuration =
  577. le16_to_cpu (request->wValue) & 0x7f) != 0) {
  578. /* c.f. 9.4.7 - zero is the default or addressed state, in our case this */
  579. /* is the same is configuration zero */
  580. device->configuration = 0; /* TBR - ?????? */
  581. }
  582. /* reset interface and alternate settings */
  583. device->interface = device->alternate = 0;
  584. /*dbg_ep0(2, "set configuration: %d", device->configuration); */
  585. /*serial_printf("DEVICE_CONFIGURED.. event?\n"); */
  586. return 0;
  587. case USB_REQ_SET_INTERFACE:
  588. device->interface = le16_to_cpu (request->wIndex);
  589. device->alternate = le16_to_cpu (request->wValue);
  590. /*dbg_ep0(2, "set interface: %d alternate: %d", device->interface, device->alternate); */
  591. serial_printf ("DEVICE_SET_INTERFACE.. event?\n");
  592. return 0;
  593. case USB_REQ_GET_STATUS:
  594. case USB_REQ_GET_DESCRIPTOR:
  595. case USB_REQ_GET_CONFIGURATION:
  596. case USB_REQ_GET_INTERFACE:
  597. case USB_REQ_SYNCH_FRAME: /* XXX should never see this (?) */
  598. return -1;
  599. }
  600. }
  601. return -1;
  602. }
  603. #endif