Project

General

Profile

Download (2.18 KB) Statistics
| Branch: | Tag: | Revision:
1 514b0f72 laforge
/* Main state machine and register implementation for OpenPICC
2
 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de> */
3
4
#include <sys/types.h>
5
#include <openpcd.h>
6
#include <openpicc_regs.h>
7
#include <openpicc.h>
8
#include <os/req_ctx.h>
9
#include <os/usb_handler.h>
10
11
#include "opicc_reg.h"
12
13
/********************************************************************
14
 * OpenPICC Register set
15
 ********************************************************************/
16
17 6c6b1878 laforge
#ifdef DEBUG
18 514b0f72 laforge
/* Our registers, including their power-up default values */
19 373c172a Harald Welte
static uint16_t opicc_regs[_OPICC_NUM_REGS] = {
20 514b0f72 laforge
	[OPICC_REG_14443A_UIDLEN]	= 4,
21
	[OPICC_REG_14443A_FDT0]		= 1236,
22
	[OPICC_REG_14443A_FDT1]		= 1172,
23
	[OPICC_REG_14443A_STATE]	= ISO14443A_ST_POWEROFF,
24 28eb4a57 laforge
	[OPICC_REG_14443A_ATQA]		= 0x0001,
25 514b0f72 laforge
	[OPICC_REG_RX_CLK_DIV]		= 32,
26
	[OPICC_REG_RX_CLK_PHASE]	= 0,
27
	[OPICC_REG_RX_CONTROL]		= 0,
28
	[OPICC_REG_TX_CLK_DIV]		= 16,
29
	[OPICC_REG_TX_CONTROL]		= 0,
30
	[OPICC_REG_RX_COMP_LEVEL]	= 0,
31
};
32
33 373c172a Harald Welte
uint16_t opicc_reg_read(enum opicc_reg reg)
34 514b0f72 laforge
{
35
	if (reg < _OPICC_NUM_REGS)
36
		return opicc_regs[reg];
37
	return 0;
38
}
39
40 373c172a Harald Welte
void opicc_reg_write(enum opicc_reg reg, uint16_t val)
41 514b0f72 laforge
{
42
	if (reg < _OPICC_NUM_REGS)
43
		opicc_regs[reg] = val;
44
	return;
45
}
46 6c6b1878 laforge
#endif
47 514b0f72 laforge
48
/********************************************************************
49
 * OpenPICC USB Commandset (access to register set, ...)
50
 ********************************************************************/
51
52
static int opicc_reg_usb_in(struct req_ctx *rctx)
53
{
54
	struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->data[0];
55 373c172a Harald Welte
	uint16_t *val16 = (uint16_t *) poh->data;
56 514b0f72 laforge
	
57
	poh->val = 0;
58
	rctx->tot_len = sizeof(*poh);
59
60
	switch (poh->cmd) {
61
	case OPENPCD_CMD_PICC_REG_READ:
62
		*val16 = opicc_reg_read(poh->reg);
63 373c172a Harald Welte
		rctx->tot_len += sizeof(uint16_t);
64 514b0f72 laforge
		poh->flags |= OPENPCD_FLAG_RESPOND;
65
		break;
66
	case OPENPCD_CMD_PICC_REG_WRITE:
67 373c172a Harald Welte
		if (rctx->tot_len < sizeof(*poh) + sizeof(uint16_t)) {
68 28eb4a57 laforge
			/* we only have an 8bit write */
69
			opicc_reg_write(poh->reg, poh->val);
70
		} else
71
			opicc_reg_write(poh->reg, *val16);
72 514b0f72 laforge
		break;
73
	default:
74
		return USB_ERR(USB_ERR_CMD_UNKNOWN);
75
	}
76
	
77
	if (poh->flags & OPENPCD_FLAG_RESPOND)
78
		return USB_RET_RESPOND;
79
80
	return 0;
81
}
82
83
void opicc_usbapi_init(void)
84
{
85
	usb_hdlr_register(&opicc_reg_usb_in, OPENPCD_CMD_CLS_PICC);
86
}
Add picture from clipboard (Maximum size: 48.8 MB)