summaryrefslogtreecommitdiff
path: root/firmware/src/os/usbcmd_generic.c
blob: c26daf74bcfc6e6738f4173d0351ac3a99402768 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Some generel USB API commands, common between OpenPCD and OpenPICC
 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
 */

#include <string.h>
#include <sys/types.h>
#include <openpcd.h>
#include <os/req_ctx.h>
#include <os/usb_handler.h>
#include <os/led.h>
#include <os/dbgu.h>
#include <os/main.h>

static int gen_usb_rx(struct req_ctx *rctx)
{
	struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
	struct openpcd_compile_version *ver = 
			(struct openpcd_compile_version *) poh->data;
	int ret = 1;

	rctx->tot_len = sizeof(*poh);

	switch (poh->cmd) {
	case OPENPCD_CMD_GET_VERSION:
		DEBUGP("GET_VERSION ");
		memcpy(ver, &opcd_version, sizeof(*ver));
		rctx->tot_len += sizeof(*ver);
		poh->flags |= OPENPCD_FLAG_RESPOND;
		break;
	case OPENPCD_CMD_SET_LED:
		DEBUGP("SET LED(%u,%u) ", poh->reg, poh->val);
		led_switch(poh->reg, poh->val);
		break;
	case OPENPCD_CMD_GET_SERIAL:
		DEBUGP("GET SERIAL(");
		poh->flags |= OPENPCD_FLAG_RESPOND;
#ifdef PCD
		rctx->tot_len += 4;
		if (rc632_get_serial(NULL, (u_int32_t *)poh->data) < 0) {
			DEBUGP("ERROR) ");
			return USB_ERR(USB_ERR_CMD_NOT_IMPL);
		}

		DEBUGP("%s) ", hexdump(poh->data, 4));
#else
		/* FIXME: where to get serial in PICC case */
		return USB_ERR(USB_ERR_CMD_NOT_IMPL);
#endif
		break;
	default:
		DEBUGP("UNKNOWN ");
		return USB_ERR(USB_ERR_CMD_UNKNOWN);
		break;
	}

	if (poh->flags & OPENPCD_FLAG_RESPOND)
		return USB_RET_RESPOND;
	return 0;
}

void usbcmd_gen_init(void)
{
	usb_hdlr_register(&gen_usb_rx, OPENPCD_CMD_CLS_GENERIC);
}

personal git repositories of Harald Welte. Your mileage may vary