示例#1
0
/* SSC DMA informs us about completion of filling one rctx */
void usb_submit_req_ctx(struct req_ctx *rctx)
{
	req_ctx_set_state(rctx, RCTX_STATE_UDP_EP2_PENDING);

#ifdef FPGA_TEST_STATS
	rctx_stats_add(rctx, &usb_state.stats);
#endif
	//TRACE_INFO("USB rctx enqueue (%08x, %u/%u)\n\r", rctx, rctx->size, rctx->tot_len);
	req_ctx_enqueue(&usb_state.queue, rctx);

	fastsource_start();
}
示例#2
0
static int refill_dma(void)
{
	struct req_ctx *rctx;
	int res;

	rctx = req_ctx_dequeue(&usb_state.queue);
	if (!rctx) {
		//TRACE_WARNING("No rctx for re-filling USB DMA\n\r");
		usb_state.active = 0;
		return -ENOENT;
	}

	req_ctx_set_state(rctx, RCTX_STATE_UDP_EP2_BUSY);

	if ((res = USBD_Write(EP_NR, rctx->data, rctx->tot_len, wr_compl_cb, rctx)) != USBD_STATUS_SUCCESS) {
		TRACE_WARNING("USB EP busy while re-filling USB DMA: %d\n\r", res);
		req_ctx_set_state(rctx, RCTX_STATE_FREE);
		usb_state.active = 0;
		return -EBUSY;
	}

	usb_state.active = 1;
	return 0;
}
示例#3
0
/* completion callback: USBD_Write() has completed an IN transfer */
static void wr_compl_cb(void *arg, unsigned char status, unsigned int transferred,
			unsigned int remain)
{
	struct req_ctx *rctx = arg;

	usb_state.active = 0;

	req_ctx_set_state(rctx, RCTX_STATE_FREE);

	if (status == 0 && remain == 0) {
		refill_dma();
	} else {
		TRACE_WARNING("Err: EP%u wr_compl, status 0x%02u, xfr %u, remain %u\r\n",
				EP_NR, status, transferred, remain);
	}
}
示例#4
0
void req_ctx_put(struct req_ctx *ctx)
{
	req_ctx_set_state(ctx, RCTX_STATE_FREE);
}
示例#5
0
static int init_proto(void)
{
	struct req_ctx *detect_rctx;
	struct openpcd_hdr *opcdh;
	struct openpcd_l2_connectinfo *l2c;
	struct openpcd_proto_connectinfo *pc;
	unsigned int size;

	l2h = rfid_layer2_scan(rh);
	if (!l2h)
		return 0;

	DEBUGP("l2='%s' ", rfid_layer2_name(l2h));

	detect_rctx = req_ctx_find_get(0, RCTX_STATE_FREE,
					RCTX_STATE_LIBRFID_BUSY);
	if (detect_rctx) {
		unsigned int uid_len;
		opcdh = (struct openpcd_hdr *) detect_rctx->data;
		l2c = (struct openpcd_l2_connectinfo *) 
				(char *) opcdh + sizeof(opcdh);
		l2c->uid_len = sizeof(l2c->uid);
		opcdh->cmd = OPENPCD_CMD_LRFID_DETECT_IRQ;
		opcdh->flags = 0x00;
		opcdh->reg = 0x03;
		opcdh->val = l2h->l2->id;

		detect_rctx->tot_len = sizeof(*opcdh) + sizeof(*l2c);
#if 0
		/* copy UID / PUPI into data section */
		rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID, (void *)l2c->uid, 
					&uid_len);
		l2c->uid_len = uid_len & 0xff;
		
		size = sizeof(l2c->proto_supported);
		rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_PROTO_SUPP,
					&l2c->proto_supported, &size);

		switch (l2h->l2->id) {
		case RFID_LAYER2_ISO14443A:
			break;
		case RFID_LAYER2_ISO14443B:
			break;
		case RFID_LAYER2_ISO15693:
			break;
		}
#endif
		req_ctx_set_state(detect_rctx, RCTX_STATE_UDP_EP3_PENDING);
	} else
		DEBUGPCRF("=>>>>>>>>>>>>>>no req_ctx for L2!");
	ph = rfid_protocol_scan(l2h);
	if (!ph)
		return 3;

	DEBUGP("p='%s' ", rfid_protocol_name(ph));
	detect_rctx = req_ctx_find_get(0, RCTX_STATE_FREE,
					RCTX_STATE_LIBRFID_BUSY);
	if (detect_rctx) {
		opcdh = (struct openpcd_hdr *) detect_rctx->data;
		pc = (struct openpcd_proto_connectinfo *)
				((char *) opcdh + sizeof(*opcdh));
		detect_rctx->tot_len = sizeof(*opcdh) + sizeof(*pc);
		opcdh->cmd = OPENPCD_CMD_LRFID_DETECT_IRQ;
		opcdh->flags = 0x00;
		opcdh->reg = 0x04;
		opcdh->val = ph->proto->id;
		/* copy L4 info into data section */

#if 0
		switch (ph->proto->id) {
		case RFID_PROTOCOL_TCL: {
			struct openpcd_proto_tcl_connectinfo *ptc
				= (struct openpcd_proto_tcl_connectinfo *)
						((char *) ph + sizeof(*ph));
			unsigned int space;
			detect_rctx->tot_len += sizeof(*ptc);
			space = detect_rctx->size - sizeof(*opcdh)-sizeof(*pc);
			size = space;
			rfid_protocol_getopt(ph, RFID_OPT_P_TCL_ATS,
					     &ptc->ats_snippet, &size);
			if (size == space) {
				/* we've only copied part of the ATS */
				size = sizeof(ptc->ats_tot_len);
				rfid_protocol_getopt(ph, 
						     RFID_OPT_P_TCL_ATS_LEN,
						     &ptc->ats_tot_len, &size);
			} else {
				ptc->ats_tot_len = size;
			}

			} break;
		}
#endif
		req_ctx_set_state(detect_rctx, RCTX_STATE_UDP_EP3_PENDING);
	} else
		DEBUGPCRF("=>>>>>>>>>>>>>>no req_ctx for L2!");
	led_switch(1, 1);

	if (ph->proto->id == RFID_PROTOCOL_MIFARE_CLASSIC) {
		int rc;

		DEBUGPCR("Authenticating sector %u: ", sector);
		rc = mfcl_set_key(ph, MIFARE_CL_KEYA_DEFAULT_INFINEON);
		if (rc < 0) {
			DEBUGPCR("key format error");
			return 4;
		}
		rc = mfcl_auth(ph, RFID_CMD_MIFARE_AUTH1A, sector*4);
		if (rc < 0) {
			DEBUGPCR("mifare auth error");
			return 4;
		} else
			DEBUGPCR("mifare auth succeeded!\n");

		mifare_classic_read_sector(ph, sector);

		return 5;
	}

	return 4;
}