1 |
14055f6e
|
(no author)
|
/* OpenPCD USB handler - handle incoming USB requests on OUT pipe
|
2 |
32985a29
|
laforge
|
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
3 |
|
|
*
|
4 |
|
|
* This program is free software; you can redistribute it and/or modify
|
5 |
|
|
* it under the terms of the GNU General Public License as published by
|
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
7 |
|
|
* (at your option) any later version.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the Free Software
|
16 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17 |
|
|
*
|
18 |
14055f6e
|
(no author)
|
*/
|
19 |
|
|
|
20 |
|
|
#include <sys/types.h>
|
21 |
|
|
#include <errno.h>
|
22 |
|
|
#include <string.h>
|
23 |
|
|
|
24 |
|
|
#include <openpcd.h>
|
25 |
|
|
|
26 |
520784c7
|
(no author)
|
#include <os/pcd_enumerate.h>
|
27 |
|
|
#include <os/usb_handler.h>
|
28 |
|
|
#include <os/req_ctx.h>
|
29 |
|
|
#include <os/led.h>
|
30 |
|
|
#include <os/dbgu.h>
|
31 |
|
|
|
32 |
|
|
#include "../openpcd.h"
|
33 |
14055f6e
|
(no author)
|
|
34 |
81416e6a
|
(no author)
|
static usb_cmd_fn *cmd_hdlrs[16];
|
35 |
|
|
|
36 |
373c172a
|
Harald Welte
|
int usb_hdlr_register(usb_cmd_fn *hdlr, uint8_t class)
|
37 |
81416e6a
|
(no author)
|
{
|
38 |
|
|
cmd_hdlrs[class] = hdlr;
|
39 |
83c18361
|
(no author)
|
return 0;
|
40 |
81416e6a
|
(no author)
|
}
|
41 |
|
|
|
42 |
373c172a
|
Harald Welte
|
void usb_hdlr_unregister(uint8_t class)
|
43 |
81416e6a
|
(no author)
|
{
|
44 |
|
|
cmd_hdlrs[class] = NULL;
|
45 |
|
|
}
|
46 |
14055f6e
|
(no author)
|
|
47 |
|
|
static int usb_in(struct req_ctx *rctx)
|
48 |
|
|
{
|
49 |
514b0f72
|
laforge
|
struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
|
50 |
81416e6a
|
(no author)
|
usb_cmd_fn *hdlr;
|
51 |
514b0f72
|
laforge
|
int ret;
|
52 |
14055f6e
|
(no author)
|
|
53 |
4d1e8b3c
|
meri
|
/* DEBUGP("usb_in(cls=%d) ", OPENPCD_CMD_CLS(poh->cmd));*/
|
54 |
14055f6e
|
(no author)
|
|
55 |
514b0f72
|
laforge
|
if (rctx->tot_len < sizeof(*poh))
|
56 |
14055f6e
|
(no author)
|
return -EINVAL;
|
57 |
174e6403
|
(no author)
|
|
58 |
81416e6a
|
(no author)
|
hdlr = cmd_hdlrs[OPENPCD_CMD_CLS(poh->cmd)];
|
59 |
514b0f72
|
laforge
|
if (!hdlr) {
|
60 |
|
|
DEBUGPCR("no handler for this class ");
|
61 |
|
|
ret = USB_ERR(USB_ERR_CMD_UNKNOWN);
|
62 |
|
|
} else
|
63 |
|
|
ret = (hdlr)(rctx);
|
64 |
|
|
|
65 |
|
|
if (ret & USB_RET_ERR) {
|
66 |
|
|
poh->val = ret & 0xff;
|
67 |
|
|
poh->flags = OPENPCD_FLAG_ERROR;
|
68 |
|
|
}
|
69 |
|
|
if (ret & USB_RET_RESPOND) {
|
70 |
|
|
req_ctx_set_state(rctx, RCTX_STATE_UDP_EP2_PENDING);
|
71 |
|
|
udp_refill_ep(2);
|
72 |
|
|
}
|
73 |
|
|
|
74 |
4d1e8b3c
|
meri
|
/* DEBUGPCR("");*/
|
75 |
514b0f72
|
laforge
|
return (ret & USB_RET_ERR) ? 1 : 0;
|
76 |
14055f6e
|
(no author)
|
}
|
77 |
|
|
|
78 |
38f0dbf7
|
(no author)
|
/* Process all pending request contexts that want to Tx on either
|
79 |
|
|
* IN or INTERRUPT endpoint */
|
80 |
a5c8f60f
|
(no author)
|
void usb_out_process(void)
|
81 |
|
|
{
|
82 |
238c6c3c
|
laforge
|
/* interrupts are likely to be more urgent than bulk */
|
83 |
|
|
udp_refill_ep(3);
|
84 |
|
|
udp_refill_ep(2);
|
85 |
a5c8f60f
|
(no author)
|
}
|
86 |
|
|
|
87 |
38f0dbf7
|
(no author)
|
/* process incoming USB packets (OUT pipe) that have already been
|
88 |
|
|
* put into request contexts by the UDP IRQ handler */
|
89 |
14055f6e
|
(no author)
|
void usb_in_process(void)
|
90 |
|
|
{
|
91 |
|
|
struct req_ctx *rctx;
|
92 |
|
|
|
93 |
514b0f72
|
laforge
|
while (rctx = req_ctx_find_get(0, RCTX_STATE_UDP_RCV_DONE,
|
94 |
14055f6e
|
(no author)
|
RCTX_STATE_MAIN_PROCESSING)) {
|
95 |
4d1e8b3c
|
meri
|
/* DEBUGPCRF("found used ctx %u: len=%u",
|
96 |
|
|
req_ctx_num(rctx), rctx->tot_len);*/
|
97 |
14055f6e
|
(no author)
|
usb_in(rctx);
|
98 |
|
|
}
|
99 |
|
|
udp_unthrottle();
|
100 |
|
|
}
|