Project

General

Profile

Download (2.18 KB) Statistics
| Branch: | Tag: | Revision:
1
/* 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
#ifdef DEBUG
18
/* Our registers, including their power-up default values */
19
static uint16_t opicc_regs[_OPICC_NUM_REGS] = {
20
	[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
	[OPICC_REG_14443A_ATQA]		= 0x0001,
25
	[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
uint16_t opicc_reg_read(enum opicc_reg reg)
34
{
35
	if (reg < _OPICC_NUM_REGS)
36
		return opicc_regs[reg];
37
	return 0;
38
}
39

    
40
void opicc_reg_write(enum opicc_reg reg, uint16_t val)
41
{
42
	if (reg < _OPICC_NUM_REGS)
43
		opicc_regs[reg] = val;
44
	return;
45
}
46
#endif
47

    
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
	uint16_t *val16 = (uint16_t *) poh->data;
56
	
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
		rctx->tot_len += sizeof(uint16_t);
64
		poh->flags |= OPENPCD_FLAG_RESPOND;
65
		break;
66
	case OPENPCD_CMD_PICC_REG_WRITE:
67
		if (rctx->tot_len < sizeof(*poh) + sizeof(uint16_t)) {
68
			/* we only have an 8bit write */
69
			opicc_reg_write(poh->reg, poh->val);
70
		} else
71
			opicc_reg_write(poh->reg, *val16);
72
		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
}
(12-12/26)
Add picture from clipboard (Maximum size: 48.8 MB)