partial : fixed some dumb mistakes from my previous commit

Forgot a few characters here and there.

Test fully working with FeliCa.
Mifare tags do get recognized too, just need to write the logic to read block 2 now !
This commit is contained in:
Farewell_ 2024-02-28 13:02:31 +01:00
parent 9994535f24
commit 561d25fc1f
3 changed files with 8 additions and 21 deletions

View File

@ -139,7 +139,7 @@ static unsigned int __stdcall aime_io_poll_thread_proc(void *ctx)
printf("DEBUG: aime_io_poll_thread_proc(). \r\n"); printf("DEBUG: aime_io_poll_thread_proc(). \r\n");
while (!READER_POLL_STOP_FLAG) while (!READER_POLL_STOP_FLAG)
{ {
if (card_data.card_type != 0) // Halting polling once a card is found, waiting for the game to read it's value. if (card_data.card_type == 0) // Halting polling once a card is found, waiting for the game to read it's value.
scard_poll(&card_data); // We're trying to find a card. If we do, the card's id and type are written to card_data. scard_poll(&card_data); // We're trying to find a card. If we do, the card's id and type are written to card_data.
} }
@ -201,7 +201,7 @@ HRESULT aime_io_nfc_poll(uint8_t unit_no)
return S_OK; return S_OK;
// Don't do anything more if the scan key is not held // Don't do anything more if the scan key is not held
if (GetAsyncKeyState(aime_io_cfg.vk_scan) & 0x8000) if (!(GetAsyncKeyState(aime_io_cfg.vk_scan) & 0x8000))
return S_OK; return S_OK;
// Set which card we want to read (we will read the x'th line in the card's file, x being determined by which key is pressed on the keypad). // Set which card we want to read (we will read the x'th line in the card's file, x being determined by which key is pressed on the keypad).
@ -278,7 +278,7 @@ HRESULT aime_io_nfc_get_felica_id(uint8_t unit_no, uint64_t *IDm)
val = (val << 8) | card_data.card_id[i]; val = (val << 8) | card_data.card_id[i];
*IDm = val; *IDm = val;
printf("aime_io_nfc_get_felica_id: Sending FeliCa card with IDm %02X%02X %02X%02X %02X%02X %02X%02X\r\n", card_data.card_id[0], card_data.card_id[1], card_data.card_id[2], card_data.card_id[3], card_data.card_id[4], card_data.card_id[5], card_data.card_id[6], card_data.card_id[7]); printf("aime_io_nfc_get_felica_id: Sending FeliCa card with serial %02X%02X %02X%02X %02X%02X %02X%02X\r\n", card_data.card_id[0], card_data.card_id[1], card_data.card_id[2], card_data.card_id[3], card_data.card_id[4], card_data.card_id[5], card_data.card_id[6], card_data.card_id[7]);
memset(&card_data, 0, sizeof(card_data)); // Reset card_data structure memset(&card_data, 0, sizeof(card_data)); // Reset card_data structure
return S_OK; return S_OK;

View File

@ -51,17 +51,12 @@ int main()
if (aime_io_nfc_get_felica_id(0, &IDm) == S_OK) if (aime_io_nfc_get_felica_id(0, &IDm) == S_OK)
{ {
// aime_io_led_set_color(0, 0, 255, 0); // aime_io_led_set_color(0, 0, 255, 0);
printf("AIMETEST: Found FeliCa card with uid %llx\r\n\n", IDm); printf("AIMETEST: Found FeliCa card with IDm %llx\r\n\n", IDm);
} }
if (aime_io_nfc_get_aime_id(0, luid, 10) == S_OK) if (aime_io_nfc_get_aime_id(0, luid, 10) == S_OK)
{ {
// aime_io_led_set_color(0, 0, 0, 255); // aime_io_led_set_color(0, 0, 0, 255);
printf("AIMETEST: Found old card with uid "); printf("AIMETEST: Found old card with luID %02X%02X %02X%02X %02X%02X %02X%02X %02X%02X\r\n", luid[0], luid[1], luid[2], luid[3], luid[4], luid[5], luid[6], luid[7], luid[8], luid[9]);
for (int i = 0; i < 10; i++)
{
printf("%02x ", luid[i]);
}
printf("\r\n\n");
} }
Sleep(500); Sleep(500);
// printf("poll ok but no card?!\r\n"); // printf("poll ok but no card?!\r\n");

View File

@ -107,16 +107,10 @@ bool scard_init(struct aime_io_config config)
if ((lRet = SCardDisconnect(hCard, SCARD_LEAVE_CARD)) != SCARD_S_SUCCESS) if ((lRet = SCardDisconnect(hCard, SCARD_LEAVE_CARD)) != SCARD_S_SUCCESS)
printf("scard_init: Failed SCardDisconnect : 0x%08X\n", lRet); printf("scard_init: Failed SCardDisconnect : 0x%08X\n", lRet);
// Extract the relevant names from the multi-string. printf("scard_init: Using reader : %s\n", reader_list);
readerNameLen = lstrlen(reader_list);
reader_name = (LPTSTR)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(TCHAR) * (readerNameLen + 1));
memcpy(reader_name, &reader_list, (size_t)(readerNameLen + 1));
if (reader_name)
printf("scard_init: Using reader : %s\n", reader_name);
memset(&reader_state, 0, sizeof(SCARD_READERSTATE)); memset(&reader_state, 0, sizeof(SCARD_READERSTATE));
reader_state.szReader = reader_name; reader_state.szReader = reader_list;
return TRUE; return TRUE;
default: default:
@ -208,8 +202,6 @@ void scard_update(struct card_data *card_data, SCARDCONTEXT _hContext, LPCTSTR _
return; return;
} }
printf("scard_update: atr Return: len(%zu) = %02x (%08X)\n", sizeof(cByteAtr), (unsigned int)atr, cByteAtr);
BYTE cardProtocol = atr[12]; BYTE cardProtocol = atr[12];
if (cardProtocol == SCARD_ATR_PROTOCOL_ISO14443_PART3) if (cardProtocol == SCARD_ATR_PROTOCOL_ISO14443_PART3)
{ {
@ -245,7 +237,7 @@ void scard_update(struct card_data *card_data, SCARDCONTEXT _hContext, LPCTSTR _
memset(&pbRecv[cbRecv], 0, 8 - cbRecv); memset(&pbRecv[cbRecv], 0, 8 - cbRecv);
} }
else if (cbRecv > 8) else if (cbRecv > 8)
printf("scard_update: taking first 8 bytes of len(uid) = %02X\n", cbRecv); printf("scard_update: taking first 8 bytes of %d received\n", cbRecv);
memcpy(card_data->card_id, pbRecv, 8); memcpy(card_data->card_id, pbRecv, 8);
} }