mirror of
https://github.com/whowechina/aic_pico.git
synced 2024-11-27 23:10:48 +01:00
Optimization on nfc part
This commit is contained in:
parent
042738861e
commit
7be6dbd0c0
Binary file not shown.
@ -305,8 +305,8 @@ static void cmd_detect_card()
|
||||
if (virtual_aic.enabled) {
|
||||
printf("\nVirtual FeliCa from 15693.");
|
||||
virtual_aic.active = true;
|
||||
memcpy(virtual_aic.idm, "\x01\x01", 2);
|
||||
memcpy(virtual_aic.idm + 2, card.uid, 6);
|
||||
memcpy(virtual_aic.idm, card.uid, 8);
|
||||
virtual_aic.idm[0] = 0x01;
|
||||
fake_felica_card();
|
||||
}
|
||||
break;
|
||||
|
@ -11,8 +11,7 @@
|
||||
#include "save.h"
|
||||
#include "cli.h"
|
||||
|
||||
#include "pn532.h"
|
||||
#include "pn5180.h"
|
||||
#include "nfc.h"
|
||||
|
||||
static int fps[2];
|
||||
void fps_count(int core)
|
||||
@ -33,6 +32,8 @@ void fps_count(int core)
|
||||
|
||||
static void handle_display()
|
||||
{
|
||||
printf("[NFC Module]\n");
|
||||
printf(" %s\n", nfc_module_name());
|
||||
printf("[Config]\n");
|
||||
printf(" Light: RGB-%s LED-%s\n",
|
||||
aic_cfg->light.rgb ? "ON" : "OFF",
|
||||
@ -53,32 +54,11 @@ static void handle_factory_reset()
|
||||
|
||||
static void handle_nfc()
|
||||
{
|
||||
bool ret;
|
||||
|
||||
// ret = pn532_config_rf();
|
||||
// printf("RF: %d\n", ret);
|
||||
|
||||
ret = pn532_config_sam();
|
||||
printf("Sam: %d\n", ret);
|
||||
|
||||
uint8_t buf[32];
|
||||
int len = sizeof(buf);
|
||||
|
||||
ret = pn532_poll_mifare(buf, &len);
|
||||
printf("Mifare: %d -", len);
|
||||
|
||||
if (ret) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf(" %02x", buf[i]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("Felica: ");
|
||||
if (pn532_poll_felica(buf, buf + 8, buf + 16, false)) {
|
||||
for (int i = 0; i < 18; i++) {
|
||||
printf(" %02x%s", buf[i], (i % 8 == 7) ? "," : "");
|
||||
}
|
||||
printf("NFC module: %s\n", nfc_module_name());
|
||||
nfc_card_t card = nfc_detect_card();
|
||||
printf("Card %s:", nfc_card_name(card.card_type));
|
||||
for (int i = 0; i < card.len; i++) {
|
||||
printf(" %02x", card.uid[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
@ -152,7 +132,7 @@ void commands_init()
|
||||
cli_register("display", handle_display, "Display all settings.");
|
||||
cli_register("save", handle_save, "Save config to flash.");
|
||||
cli_register("factory", handle_factory_reset, "Reset everything to default.");
|
||||
cli_register("nfc", handle_nfc, "NFC debug.");
|
||||
cli_register("nfc", handle_nfc, "NFC module.");
|
||||
cli_register("light", handle_light, "Turn on/off lights.");
|
||||
cli_register("level", handle_level, "Set light level.");
|
||||
}
|
||||
|
@ -130,10 +130,7 @@ void detect_card()
|
||||
break;
|
||||
case NFC_CARD_VICINITY:
|
||||
hid_cardio.current[0] = REPORT_ID_EAMU;
|
||||
// 15693 cards store uid in reverse byte order
|
||||
for (int i = 0; i < 8; i++) {
|
||||
hid_cardio.current[i + 1] = card.uid[7 - i];
|
||||
}
|
||||
memcpy(hid_cardio.current + 1, card.uid, 8);
|
||||
break;
|
||||
default:
|
||||
memset(hid_cardio.current, 0, 9);
|
||||
@ -142,9 +139,8 @@ void detect_card()
|
||||
return;
|
||||
}
|
||||
|
||||
if (card.card_type != NFC_CARD_NULL) {
|
||||
const char *card_type_str[3] = { "MIFARE", "FeliCa", "15693" };
|
||||
printf("\n%s:", card_type_str[card.card_type - 1]);
|
||||
if (card.card_type != NFC_CARD_NONE) {
|
||||
printf("\n%s:", nfc_card_name(card.card_type));
|
||||
for (int i = 0; i < card.len; i++) {
|
||||
printf(" %02x", hid_cardio.current[i + 1]);
|
||||
}
|
||||
|
@ -21,6 +21,32 @@ static enum {
|
||||
NFC_MODULE_UNKNOWN,
|
||||
} nfc_module = NFC_MODULE_UNKNOWN;
|
||||
|
||||
static const char *nfc_module_names[] = {
|
||||
"PN532",
|
||||
"PN5180",
|
||||
"Unknown",
|
||||
};
|
||||
|
||||
const char *nfc_module_name()
|
||||
{
|
||||
return nfc_module_names[nfc_module];
|
||||
}
|
||||
|
||||
static const char *nfc_card_names[] = {
|
||||
"None",
|
||||
"MIFARE",
|
||||
"FeliCa",
|
||||
"15693"
|
||||
};
|
||||
|
||||
const char *nfc_card_name(nfc_card_type card_type)
|
||||
{
|
||||
if (card_type >= sizeof(nfc_card_names) / sizeof(nfc_card_names[0])) {
|
||||
return "Unknown";
|
||||
}
|
||||
return nfc_card_names[card_type];
|
||||
}
|
||||
|
||||
static bool null_poll_mifare(uint8_t uid[7], int *len)
|
||||
{
|
||||
return false;
|
||||
@ -121,7 +147,7 @@ nfc_card_t nfc_detect_card()
|
||||
if (!nfc_detect_mifare(&card) &&
|
||||
!nfc_detect_felica(&card) &&
|
||||
!nfc_detect_vicinity(&card)) {
|
||||
card.card_type = NFC_CARD_NULL;
|
||||
card.card_type = NFC_CARD_NONE;
|
||||
}
|
||||
|
||||
return card;
|
||||
|
@ -10,12 +10,14 @@
|
||||
#include "hardware/i2c.h"
|
||||
|
||||
typedef enum {
|
||||
NFC_CARD_NULL = 0,
|
||||
NFC_CARD_NONE = 0,
|
||||
NFC_CARD_MIFARE,
|
||||
NFC_CARD_FELICA,
|
||||
NFC_CARD_VICINITY,
|
||||
} nfc_card_type;
|
||||
|
||||
const char *nfc_card_name(nfc_card_type card_type);
|
||||
|
||||
typedef void (*nfc_wait_loop_t)();
|
||||
typedef struct {
|
||||
nfc_card_type card_type;
|
||||
@ -31,6 +33,8 @@ typedef struct {
|
||||
void nfc_init(nfc_wait_loop_t loop);
|
||||
nfc_card_t nfc_detect_card();
|
||||
|
||||
const char *nfc_module_name();
|
||||
|
||||
bool nfc_mifare_auth(const uint8_t uid[4], uint8_t block_id, uint8_t key_id, const uint8_t *key);
|
||||
bool nfc_mifare_read(uint8_t block_id, uint8_t block_data[16]);
|
||||
|
||||
|
@ -361,7 +361,9 @@ bool pn5180_poll_vicinity(uint8_t uid[8])
|
||||
if (len == 10) {
|
||||
uint8_t id[10];
|
||||
pn5180_read_data(id, len);
|
||||
memmove(uid, id + 2, 8);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
uid[i] = id[9 - i]; // 15693 stores id in reversed byte order
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user