Пример #1
0
static void
loop_rfid (void)
{
	int res, line, t;
//  uint32_t counter;
	static unsigned char data[80];

	/* fully initialized */
	GPIOSetValue (LED_PORT, LED_BIT, LED_ON);

	/* read firmware revision */
	debug_printf ("\nreading firmware version...\n");
	data[0] = PN532_CMD_GetFirmwareVersion;
	while ((res = rfid_execute (&data, 1, sizeof (data))) < 0)
	{
		debug_printf ("Reading Firmware Version Error [%i]\n", res);
		pmu_wait_ms (450);
		GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
		pmu_wait_ms (10);
		GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);
	}

	debug_printf ("PN532 Firmware Version: ");
	if (data[1] != 0x32)
		rfid_hexdump (&data[1], data[0]);
	else
		debug_printf ("v%i.%i\n", data[2], data[3]);

	/* Set PN532 to virtual card */
	data[0] = PN532_CMD_SAMConfiguration;
	data[1] = 0x02;																/* Virtual Card Mode */
	data[2] = 0x00;																/* No Timeout Control */
	data[3] = 0x00;																/* No IRQ */
	if ((res = rfid_execute (&data, 4, sizeof (data))) > 0)
	{
		debug_printf ("SAMConfiguration: ");
		rfid_hexdump (&data, res);
	}

	/* init RFID emulator */
	rfid_init_emulator ();

	/* enable debug output */
	GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	line = 0;
	t = 0;

	while (1)
	{
#if 0
		counter = LPC_TMR32B0->TC;
		pmu_wait_ms (100);
		counter = (LPC_TMR32B0->TC - counter) * 10;

		debug_printf ("LPC_TMR32B0[%08u]: %uHz\n", line++, counter);
#endif
		GPIOSetValue (LED_PORT, LED_BIT, GPIOGetValue (1, 8));
	}
}
Пример #2
0
void dump_mifare_card (void)
{
    for (uint8_t i = 0; i < BLOCKS; i++) {
        debug_printf("Block %2d:", i);
        rfid_hexdump(&mifare_card[i*BLOCK_SIZE], BLOCK_SIZE);
    }
}
Пример #3
0
static
void rfid_task(void *pvParameters)
{
	int i;
	static unsigned char data[80];

	/* touch unused Parameter */
	(void) pvParameters;

	/* release reset line after 400ms */
	vTaskDelay( 400 / portTICK_RATE_MS);
	rfid_reset(1);
	/* wait for PN532 to boot */
	vTaskDelay( 100 / portTICK_RATE_MS);

	/* read firmware revision */
	debug_printf("\nreading firmware version...\n");
	data[0] = PN532_CMD_GetFirmwareVersion;
	rfid_execute(&data, 1, sizeof(data));

	/* enable debug output */
	debug_printf("\nenabling debug output...\n");
	WriteRegister(0x6328, 0xFC);
	// select test bus signal
	WriteRegister(0x6321, 6);
	// select test bus type
	WriteRegister(0x6322, 0x07);

	while (1)
	{
		/* wait 100ms */
		vTaskDelay( 100 / portTICK_RATE_MS);

		/* detect cards in field */
		GPIOSetValue(LED_PORT, LED_BIT, LED_ON);
		debug_printf("\nchecking for cards...\n");
		data[0] = PN532_CMD_InListPassiveTarget;
		data[1] = 0x01; /* MaxTg - maximum cards    */
		data[2] = 0x00; /* BrTy - 106 kbps type A   */
		if (((i = rfid_execute(&data, 3, sizeof(data))) >= 11) && (data[1]
				== 0x01) && (data[2] == 0x01))
		{
			debug_printf("card id: ");
			rfid_hexdump(&data[7], data[6]);
		}
		else
			debug_printf("unknown response of %i bytes\n", i);
		GPIOSetValue(LED_PORT, LED_BIT, LED_OFF);

		/* turning field off */
		debug_printf("\nturning field off again...\n");
		data[0] = PN532_CMD_RFConfiguration;
		data[1] = 0x01; /* CfgItem = 0x01           */
		data[2] = 0x00; /* RF Field = off           */
		rfid_execute(&data, 3, sizeof(data));
	}
}
Пример #4
0
static int spidev_fifo_read(struct rfid_asic_transport_handle *rath,
			    unsigned char len, unsigned char *buf)
{
	int ret;

	ret = spidev_read(2, len, buf);
	if (ret < 0)
		return ret;

	DEBUGP("%s len=%u, val=%s\n", __FUNCTION__, len,
	       rfid_hexdump(buf, len));

	return len;
}
Пример #5
0
static int spidev_fifo_write(struct rfid_asic_transport_handle *rath,
			     unsigned char len, const unsigned char *buf,
			     unsigned char flags)
{
	int ret;

	ret = spidev_write(2, len, buf);
        if (ret < 0)
		return ret;

	DEBUGP("%s len=%u, data=%s\n", __FUNCTION__, len,
	       rfid_hexdump(buf, len));

	return len;
}
Пример #6
0
static int rfid_execute(void *data, unsigned int isize, unsigned int osize)
{
	int res;
	if (rfid_write(data, isize))
	{
		debug_printf("getting result\n");
		res = rfid_read(data, osize);
		if (res > 0)
			rfid_hexdump(data, res);
		else
			debug_printf("error: res=%i\n", res);
	}
	else
	{
		debug_printf("->NACK!\n");
		res = -1;
	}
	return res;
}
Пример #7
0
void loop_clone_rfid(uint8_t *menu, uint8_t *opmode)
{
    uint8_t data[80];
    uint8_t keyindex = 0;
    uint8_t block = 0;
    uint8_t tries = 0;
    int res, oid;

	get_firmware_version();

    while (block < BLOCKS) {
        if ( READ != *menu) { break; }
        res = mifare_reader_init(data, sizeof(data));

        if (tries >= KEYS) {
            tries = 0;
            block += 1;
        }

        if (res >= 0) {
            res = initiator_init(data, sizeof(data));

            if (res >= 11) {
                if (0x00 == data[3] && data[6] >= 0x04) {
                    memcpy(&oid, &data[7], sizeof(oid));
                    if (0x00 == block) {
                        debug_printf("MIFARE_CARD_ID:");
                        rfid_hexdump(&oid, sizeof(oid));
                    }

                    set_uid(data, oid);
                    set_key(data, keyindex);

                    res = mifare_authenticate_block(data, sizeof(data), block);

/*
                    debug_printf("res:");
                    rfid_hexdump(&res, sizeof(res));

                    debug_printf("data:");
                    rfid_hexdump(&data[0], sizeof(data));
*/

                    if (0x41 == data[0] && 0x00 == data[1]) {
                        debug_printf("Auth Succeeded.\n");
                        tries = 0;

                        switch (*opmode) {
                            case READ:
                                res = mifare_read_block(data, sizeof(data), block);

                                if (res == 18) {
                                    debug_printf("Block:");
                                    rfid_hexdump(&block, sizeof(block));
                                    debug_printf("Data:");
                                    rfid_hexdump(&data[2], BLOCK_SIZE);
                                    debug_printf("Key:");
                                    rfid_hexdump(&default_keys[keyindex], MIFARE_KEY_SIZE);

                                    memcpy(&mifare_card[block*BLOCK_SIZE], &data[2], BLOCK_SIZE);
                                    if (0x00 == (block+1) % 4) {
                                        memcpy(&mifare_card[block*BLOCK_SIZE], &default_keys[keyindex], MIFARE_KEY_SIZE);
                                        memcpy(&mifare_card[block*BLOCK_SIZE+6], &access_bytes[0], ACCESS_BYTES);
                                        memcpy(&mifare_card[block*BLOCK_SIZE+10], &key_b[0], MIFARE_KEY_SIZE);
                                    }
                                }
                            break;
                            case WRITE:
                                memcpy(&data[4], &mifare_card[block*BLOCK_SIZE], BLOCK_SIZE);
                                res = mifare_write_block(data, sizeof(data), block);
                                debug_printf("res:");
                                rfid_hexdump(&res, sizeof(res));
                            break;
                        }
                        block += 1;
                    } else if (0x41 == data[0] && 0x14 == data[1]) {
                        debug_printf("Auth Failed.\n");
                        keyindex = (keyindex + 1) % KEYS;
                        tries += 1;
                    }
                }
            }
        } else {
            turn_rf_off(data, sizeof(data));
        }
    }
    *menu = LIBNFC;
}
Пример #8
0
static void
loop_rfid (void)
{
  int res;
  static unsigned char data[80];

  /* release reset line after 400ms */
  pmu_wait_ms (400);
  rfid_reset (1);
  /* wait for PN532 to boot */
  pmu_wait_ms (100);

  /* fully initialized */
  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);

  /* read firmware revision */
  debug_printf ("\nreading firmware version...\n");
  data[0] = PN532_CMD_GetFirmwareVersion;
  while ((res = rfid_execute (&data, 1, sizeof (data))) < 0)
  {
    debug_printf ("Reading Firmware Version Error [%i]\n", res);
    pmu_wait_ms (450);
    GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
    pmu_wait_ms (10);
    GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);
  }

  debug_printf ("PN532 Firmware Version: ");
  if (data[1] != 0x32)
    rfid_hexdump (&data[1], data[0]);
  else
    debug_printf ("v%i.%i\n", data[2], data[3]);

  /* enable debug output */
  debug_printf ("\nenabling debug output...\n");
  rfid_write_register (0x6328, 0xFC);
  // select test bus signal
  rfid_write_register (0x6321, 6);
  // select test bus type
  rfid_write_register (0x6322, 0x07);

  /* enable debug output */
  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
  while (1)
    {
      /* wait 10ms */
      pmu_wait_ms (10);

      /* detect cards in field */
      data[0] = PN532_CMD_InListPassiveTarget;
      data[1] = 0x01;		/* MaxTg - maximum cards    */
      data[2] = 0x00;		/* BrTy - 106 kbps type A   */
      if (((res = rfid_execute (&data, 3, sizeof (data))) >= 11) && (data[1]
								     == 0x01)
	  && (data[2] == 0x01))
	{
	  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	  pmu_wait_ms (50);
	  GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);

	  debug_printf ("card id: ");
	  rfid_hexdump (&data[7], data[6]);
	}
      else
	{
	  GPIOSetValue (LED_PORT, LED_BIT, LED_ON);
	  if (res != -8)
	    debug_printf ("PN532 error res=%i\n", res);
	}

      /* turning field off */
      data[0] = PN532_CMD_RFConfiguration;
      data[1] = 0x01;		/* CfgItem = 0x01           */
      data[2] = 0x00;		/* RF Field = off           */
      rfid_execute (&data, 3, sizeof (data));
    }
}