Exemplo n.º 1
0
/* wrap data, transmit to the device and get answer */
RESPONSECODE sendData(PUCHAR TxBuffer, DWORD TxLength, 
				 PUCHAR RxBuffer, PDWORD RxLength, int wait)
{
	RESPONSECODE rc;
	
	if (present == 0)
	{
		return IFD_COMMUNICATION_ERROR;
	}
	
	unsigned char apdu[TxLength];
	unsigned char buffer[2000];
	unsigned int i, j, response_length, n = 0;
	int sLen = TxLength;
	
	for (i = 0; i < TxLength; ++i)
	{
		apdu[i] = *(TxBuffer + i);
	}

	Log2(PCSC_LOG_DEBUG, "preparing to write %d data bytes", TxLength);
	printf(">> %s \n", hexdump(TxBuffer, TxLength));
	int rv;

	rv = rfid_protocol_transceive(ph, TxBuffer, TxLength, RxBuffer, &response_length, 0, 0);
	if (rv < 0)
	{
		Log2(PCSC_LOG_ERROR, "Error from transceive, returned %d\n", rv);
		present = 0;
		rfid_protocol_close(ph);
		rfid_layer2_close(l2h);
		rfid_reader_close(rh);
		return IFD_COMMUNICATION_ERROR;
	}

	Log2(PCSC_LOG_DEBUG, "wrote %d data bytes", TxLength);		
	Log2(PCSC_LOG_DEBUG, "got %d response bytes", response_length);
		
    if (response_length > 0)
    {
		*RxLength = response_length;
		
		//for (j = 0; j < response_length; ++j)
		//{
		//	*(RxBuffer + j) = buffer[j];
		//}
		rc = IFD_SUCCESS;
	    
	}
	else
	{
	    Log1(PCSC_LOG_ERROR, "no response, meaning eof, reader not usable anymore\n");
		present = 0;
		rfid_protocol_close(ph);
		rfid_layer2_close(l2h);
		rfid_reader_close(rh);
	    rc = IFD_COMMUNICATION_ERROR;
	}
	return rc;
}
Exemplo n.º 2
0
void closeLib()
{
	RESPONSECODE rv;

	if (present == 1)
	{
		rfid_protocol_close(ph);
		rfid_layer2_close(l2h);
	}

	present = 0;
	rfid_reader_close(rh);
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
	FILE *fh;
	int slen, rlen, retval = 0;
	char *next, *sbuf, *rbuf;

	if (argc != 2) {
		fprintf(stderr, "Syntax: %s scriptfile\n", argv[0]);
		exit(1);
	}

	fh = fopen(argv[1], "r");
	if (!fh) {
		perror("fopen");
		exit(1);
	}

	if (init() < 0)
		exit(1);

	if (l3(RFID_PROTOCOL_TCL) < 0)
		exit(1);

	printf("Protocol T=CL\n");
	/* we've established T=CL at this point */

	while (next = nextline(fh)) {
		if (!(strlen(next) >= 2 && strncmp(next, "//", 2) == 0)) {
			if (make_command(next, &sbuf, &slen)) {
				rlen = 1024;
				rbuf = calloc(rlen, 1);
				
				retval = send_command(sbuf, slen, rbuf, rlen);

				free(sbuf);
				free(rbuf);
			}
		}
		free(next);

		if (retval < 0)
			break;
	}

	rfid_reader_close(rh);
	
	exit(0);
}
Exemplo n.º 4
0
EXPORT int EXPORT_CONVENTION openpcd_close_reader(MIFARE_HANDLE handle)
{
    struct openpcd_state *state;
    
    if(!handle)
	return PCDERROR_INVALID_PARAMETER;
    state=(struct openpcd_state*)handle;

    openpcd_deselect_card(handle);

    openpcd_reset_reader(handle);
    Sleep(500);

    state->magic=0;
    rfid_reader_close(state->rh);
    free(state);    
    
    return PCDERROR_NONE;
}
Exemplo n.º 5
0
EXPORT int EXPORT_CONVENTION openpcd_open_reader(MIFARE_HANDLE *handle)
{
    struct rfid_reader_handle *rh;
    struct openpcd_state *state;
    
    if(!handle)
	return PCDERROR_INVALID_PARAMETER;
	
    rh = rfid_reader_open(NULL, RFID_READER_OPENPCD);
    if(!rh)
	return PCDERROR_NO_READER;
    
    state=(struct openpcd_state*)malloc(sizeof(*state));
    if(state)
    {
	memset(state,0,sizeof(*state));
	state->magic=LIBMIFARE_MAGIC;
	state->rh=rh;
	state->cl_auth=RFID_CMD_MIFARE_AUTH1A;
	memset(state->key,0xFF,sizeof(state->key));
	
	// do initial reset
	openpcd_reset_reader((MIFARE_HANDLE)state);
	Sleep(1500);
	// reopen
        state->rh = rfid_reader_open(NULL, RFID_READER_OPENPCD);
	
	*handle=(MIFARE_HANDLE)state;
	
	return PCDERROR_NONE;
    }
    else
    {	
	rfid_reader_close(rh);
	return PCDERROR_OUT_OF_MEMORY;
    }
}