Project

General

Profile

Download (5.13 KB) Statistics
| Branch: | Tag: | Revision:
1 28eb4a57 laforge
/* main_librfid - OpenPCD firmware using in-firmware librfid
2
 *
3
 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by 
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 */
20
21
#include <errno.h>
22
#include <string.h>
23
#include <lib_AT91SAM7.h>
24
#include <librfid/rfid.h>
25
#include <librfid/rfid_scan.h>
26
#include <librfid/rfid_reader.h>
27
#include <librfid/rfid_layer2.h>
28
#include <librfid/rfid_protocol.h>
29
//#include "rc632.h"
30
#include <os/dbgu.h>
31
#include <os/led.h>
32
#include <os/pcd_enumerate.h>
33
#include <os/trigger.h>
34
#include <os/req_ctx.h>
35
36
#include "../openpcd.h"
37
38
static struct rfid_reader_handle *rh;
39
static struct rfid_layer2_handle *l2h;
40
static struct rfid_protocol_handle *ph;
41
42
void _init_func(void)
43
{
44
	trigger_init();
45
	rc632_init();
46
	rc632_test();
47
	DEBUGP("opening reader ");
48
#if 1
49
	rh = rfid_reader_open(NULL, RFID_READER_OPENPCD);
50
	DEBUGP("rh=%p ", rh);
51
#endif
52
	led_switch(2, 1);
53
}
54
55
int _main_dbgu(char key)
56
{
57
	int ret = -EINVAL;
58
	return ret;
59
}
60
61
struct openpcd_l2_connectinfo {
62 373c172a Harald Welte
	uint32_t proto_supported;	
63 28eb4a57 laforge
64 373c172a Harald Welte
	uint8_t speed_rx;
65
	uint8_t speed_tx;
66 28eb4a57 laforge
67 373c172a Harald Welte
	uint8_t uid_len;
68
	uint8_t uid[10];
69 28eb4a57 laforge
} __attribute__ ((packed));
70
71
struct openpcd_proto_connectinfo {
72
} __attribute__ ((packed));
73
74
struct openpcd_proto_tcl_connectinfo {
75 373c172a Harald Welte
	uint8_t fsc;
76
	uint8_t fsd;
77
	uint8_t ta;
78
	uint8_t sfgt;
79 28eb4a57 laforge
80 373c172a Harald Welte
	uint8_t flags;
81
	uint8_t cid;
82
	uint8_t nad;
83 28eb4a57 laforge
84 373c172a Harald Welte
	uint8_t ats_tot_len;
85
	uint8_t ats_snippet[0];
86 28eb4a57 laforge
} __attribute__ ((packed));
87
88
static int init_proto(void)
89
{
90
	struct req_ctx *detect_rctx;
91
	struct openpcd_hdr *opcdh;
92
	struct openpcd_l2_connectinfo *l2c;
93
	struct openpcd_proto_connectinfo *pc;
94
	unsigned int size;
95
96
	l2h = rfid_layer2_scan(rh);
97
	if (!l2h)
98
		return 0;
99
100
	DEBUGP("l2='%s' ", rfid_layer2_name(l2h));
101
102
	detect_rctx = req_ctx_find_get(0, RCTX_STATE_FREE,
103
					RCTX_STATE_LIBRFID_BUSY);
104
	if (detect_rctx) {
105
		unsigned int uid_len;
106
		opcdh = (struct openpcd_hdr *) detect_rctx->data;
107
		l2c = (struct openpcd_l2_connectinfo *) 
108
				(char *) opcdh + sizeof(opcdh);
109
		l2c->uid_len = sizeof(l2c->uid);
110
		opcdh->cmd = OPENPCD_CMD_LRFID_DETECT_IRQ;
111
		opcdh->flags = 0x00;
112
		opcdh->reg = 0x03;
113
		opcdh->val = l2h->l2->id;
114
115 5200cf56 laforge
		detect_rctx->tot_len = sizeof(*opcdh) + sizeof(*l2c);
116 28eb4a57 laforge
#if 0
117
		/* copy UID / PUPI into data section */
118
		rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID, (void *)l2c->uid, 
119
					&uid_len);
120
		l2c->uid_len = uid_len & 0xff;
121
		
122
		size = sizeof(l2c->proto_supported);
123
		rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_PROTO_SUPP,
124
					&l2c->proto_supported, &size);
125
126
		switch (l2h->l2->id) {
127
		case RFID_LAYER2_ISO14443A:
128
			break;
129
		case RFID_LAYER2_ISO14443B:
130
			break;
131
		case RFID_LAYER2_ISO15693:
132
			break;
133
		}
134
#endif
135
		req_ctx_set_state(detect_rctx, RCTX_STATE_UDP_EP3_PENDING);
136 5200cf56 laforge
	} else
137
		DEBUGPCRF("=>>>>>>>>>>>>>>no req_ctx for L2!");
138 28eb4a57 laforge
	ph = rfid_protocol_scan(l2h);
139
	if (!ph)
140
		return 3;
141
142
	DEBUGP("p='%s' ", rfid_protocol_name(ph));
143
	detect_rctx = req_ctx_find_get(0, RCTX_STATE_FREE,
144
					RCTX_STATE_LIBRFID_BUSY);
145
	if (detect_rctx) {
146
		opcdh = (struct openpcd_hdr *) detect_rctx->data;
147
		pc = (struct openpcd_proto_connectinfo *)
148
				((char *) opcdh + sizeof(*opcdh));
149
		detect_rctx->tot_len = sizeof(*opcdh) + sizeof(*pc);
150
		opcdh->cmd = OPENPCD_CMD_LRFID_DETECT_IRQ;
151
		opcdh->flags = 0x00;
152
		opcdh->reg = 0x04;
153
		opcdh->val = ph->proto->id;
154
		/* copy L4 info into data section */
155
156
#if 0
157
		switch (ph->proto->id) {
158
		case RFID_PROTOCOL_TCL: {
159
			struct openpcd_proto_tcl_connectinfo *ptc
160
				= (struct openpcd_proto_tcl_connectinfo *)
161
						((char *) ph + sizeof(*ph));
162
			unsigned int space;
163
			detect_rctx->tot_len += sizeof(*ptc);
164
			space = detect_rctx->size - sizeof(*opcdh)-sizeof(*pc);
165
			size = space;
166
			rfid_protocol_getopt(ph, RFID_OPT_P_TCL_ATS,
167
					     &ptc->ats_snippet, &size);
168
			if (size == space) {
169
				/* we've only copied part of the ATS */
170
				size = sizeof(ptc->ats_tot_len);
171
				rfid_protocol_getopt(ph, 
172
						     RFID_OPT_P_TCL_ATS_LEN,
173
						     &ptc->ats_tot_len, &size);
174
			} else {
175
				ptc->ats_tot_len = size;
176
			}
177
178
			} break;
179
		}
180
#endif
181
		req_ctx_set_state(detect_rctx, RCTX_STATE_UDP_EP3_PENDING);
182 5200cf56 laforge
	} else
183
		DEBUGPCRF("=>>>>>>>>>>>>>>no req_ctx for L2!");
184 28eb4a57 laforge
	led_switch(1, 1);
185
186
	return 4;
187
}
188
189
static int opcd_lrfid_usb_in(struct req_ctx *rctx)
190
{
191
	struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
192
	return 0;
193
}
194
195
196
void _main_func(void)
197
{
198
	int ret;
199
200
	usb_out_process();
201
	usb_in_process();
202
	
203
	ret = init_proto();
204
205
	if (ret >= 4)
206
		rfid_protocol_close(ph);
207
	if (ret >= 3)
208
		rfid_layer2_close(l2h);
209
210
	rc632_turn_off_rf(NULL);
211 5200cf56 laforge
	{ volatile int i; for (i = 0; i < 0xfffff; i++) ; }
212 28eb4a57 laforge
	rc632_turn_on_rf(NULL);
213
214
	led_switch(1, 0);
215
	led_toggle(2);
216
}
Add picture from clipboard (Maximum size: 48.8 MB)