Ejemplo n.º 1
0
// Block list accepts only two byte codes.
byte PN532::felica_ReadWithoutEncryption(byte * resp, const word servcode,
		const byte blknum, const word blklist[]) {
	resp[0] = FELICA_CMD_READWITHOUTENCRYPTION;
	memcpy(resp + 1, target.IDm, 8);
	resp[9] = 1;
	resp[10] = servcode & 0xff;
	resp[11] = servcode >> 8 & 0xff;
	resp[12] = blknum;
	byte pos = 13;
	// only two byte array.
	for (int i = 0; i < blknum; i++) {
		// two bytes
		resp[pos++] = (blklist[i] | 0x8000) >> 8 & 0xff;
		resp[pos++] = blklist[i] & 0xff;
	}
	// pos has been incremented after the last substitution
	byte count = InCommunicateThru(resp, pos);
	count = getCommunicateThruResponse(resp);
	if (resp[9] == 0) {
		byte blocks = resp[11];
		memmove(resp, resp + 12, blocks * 16);
		return blocks;
	} else {
		return 0;
	}
}
Ejemplo n.º 2
0
byte PN532::felica_ReadBlocksWithoutEncryption(byte * resp, const word servcode,
		const byte blknum, const word blklist[]) {
	byte mess[40];
	for (int bno = 0; bno < blknum; bno++) {
		mess[0] = FELICA_CMD_READWITHOUTENCRYPTION;
		memcpy(mess + 1, target.IDm, 8);
		mess[9] = 1;
		mess[10] = servcode & 0xff;
		mess[11] = servcode >> 8 & 0xff;
		mess[12] = 1;
		// two bytes
		mess[13] = (blklist[bno] | 0x8000) >> 8 & 0xff;
		mess[14] = blklist[bno] & 0xff;

		// pos has been incremented after the last substitution
		byte count = InCommunicateThru(mess, 15);
		count = getCommunicateThruResponse(mess);
		if (mess[9] == 0) {
			byte blocks = mess[11];
			memcpy(resp + (16 * bno), mess + 12, blocks * 16);
		} else {
			return 0;
		}
	}
	return blknum;
}
Ejemplo n.º 3
0
byte PN532::felica_Polling(byte * resp, const word syscode) {
	// Polling command, with system code request.
#ifdef FELICADEBUG
  Serial.println("felica_Polling");
#endif
	resp[0] = FELICA_CMD_POLLING;
	resp[1] = syscode & 0xff;
	resp[2] = syscode >> 8 & 0xff;
	resp[3] = 0x01; // request code: request sys code
	resp[4] = 0; // time slot #
	byte result = InCommunicateThru(resp, 5);
	result = getCommunicateThruResponse(resp);
#ifdef FELICADEBUG
	Serial.printBytes(resp, result);
  Serial.println();
#endif
	if (resp[0] == FELICA_CMD_POLLING + 1) {
		target.IDLength = 8;
		memcpy(target.ID, resp + 1, target.IDLength);
		target.type = NFC::CARDTYPE_FELICA_212K;
		return result;
	}
	target.type = NFC::CARDTYPE_EMPTY;
	target.IDLength = 0;
	return 0;
}
Ejemplo n.º 4
0
byte PN532::felica_RequestSystemCode(byte * resp) {
	resp[0] = FELICA_CMD_REQUESTSYSTEMCODE;
	memcpy(resp + 1, target.IDm, 8);
	InCommunicateThru(resp, 9);
	if (getCommunicateThruResponse(resp) == 0)
		return 0;
	byte n = resp[9];
	memmove(resp, resp + 10, n * 2);
	return n;
}
Ejemplo n.º 5
0
byte PN532::felica_RequestSystemCode(byte * resp) {
#ifdef FELICADEBUG
  Serial.println("felica_RequestSystemCode");
  #endif
  resp[0] = FELICA_CMD_REQUESTSYSTEMCODE;
	memcpy(resp + 1, target.ID, 8);
	InCommunicateThru(resp, 9);
	if (getCommunicateThruResponse(resp) == 0)
		return 0;
	byte n = resp[9];
	memmove(resp, resp + 10, n * 2);
	return n;
}
Ejemplo n.º 6
0
byte PN532::felica_RequestService(byte * resp, const word servcodes[],
		const byte servnum) {
	resp[0] = FELICA_CMD_REQUESTSERVICE;
	memcpy(resp + 1, target.IDm, 8);
	resp[9] = servnum;
	for (int i = 0; i < servnum; i++) {
		resp[10 + 2 * i] = servcodes[i] & 0xff;
		resp[11 + 2 * i] = servcodes[i] >> 8 & 0xff;
	}
	byte count = InCommunicateThru(resp, 10 + 2 * servnum);
	count = getCommunicateThruResponse(resp);
	if (resp[0] == FELICA_CMD_REQUESTSERVICE + 1 && count >= 10) {
		byte svnum = resp[9];
		memmove(resp, resp + 10, svnum * 2);
		return svnum;
	}
	return 0;
}
Ejemplo n.º 7
0
byte PN532::felica_Polling(byte * resp, const word syscode) {
	// Polling command, with system code request.
	resp[0] = FELICA_CMD_POLLING;
	resp[1] = syscode & 0xff;
	resp[2] = syscode >> 8 & 0xff;
	resp[3] = 0x01; // request code: request sys code
	resp[4] = 0; // time slot #
	byte result = InCommunicateThru(resp, 5);
	result = getCommunicateThruResponse(resp);
//	printHexString(resp, result);
	if (resp[0] == FELICA_CMD_POLLING + 1) {
		target.IDLength = 8;
		memcpy(target.IDm, resp + 1, target.IDLength);
		target.NFCType = Type_FeliCa212kb;
		return result;
	}
	target.NFCType = Type_Empty;
	target.IDLength = 0;
	return 0;
}