mirror of
https://github.com/whowechina/aic_pico.git
synced 2024-11-13 17:30:52 +01:00
Can turn off virtual AIC option on PN532
This commit is contained in:
parent
6a64d5fab1
commit
0c698adafa
Binary file not shown.
@ -12,11 +12,11 @@
|
||||
#include "hardware/gpio.h"
|
||||
#include "hardware/i2c.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "nfc.h"
|
||||
#include "aime.h"
|
||||
|
||||
#define FRAME_TIMEOUT 200000
|
||||
|
||||
#define AIME_EXPIRE_TIME 5000000ULL
|
||||
enum {
|
||||
CMD_GET_FW_VERSION = 0x30,
|
||||
CMD_GET_HW_VERSION = 0x32,
|
||||
@ -74,12 +74,11 @@ const char *led_info[] = { "15084\xFF\x10\x00\x12", "000-00000\xFF\x11\x40" };
|
||||
static int baudrate_mode = 0;
|
||||
|
||||
static struct {
|
||||
bool enabled; // feature enabled
|
||||
bool active; // currently active
|
||||
uint8_t idm[8];
|
||||
const uint8_t pmm[8];
|
||||
const uint8_t syscode[2];
|
||||
} virtual_aic = { true, false, "", "\x00\xf1\x00\x00\x00\x01\x43\x00", "\x88\xb4" };
|
||||
} virtual_aic = { false, "", "\x00\xf1\x00\x00\x00\x01\x43\x00", "\x88\xb4" };
|
||||
|
||||
static void putc_trap(uint8_t byte)
|
||||
{
|
||||
@ -92,11 +91,6 @@ void aime_set_baudrate(int mode)
|
||||
baudrate_mode = (mode == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
void aime_set_virtual_aic(bool enable)
|
||||
{
|
||||
virtual_aic.enabled = enable;
|
||||
}
|
||||
|
||||
void aime_init(aime_putc_func putc_func)
|
||||
{
|
||||
aime_putc = putc_func;
|
||||
@ -207,7 +201,7 @@ static void cmd_key_set(uint8_t key[6])
|
||||
|
||||
static void cmd_set_polling(bool enabled)
|
||||
{
|
||||
//pn532_set_rf_field(0, enabled ? 1 : 0);
|
||||
nfc_rf_field(enabled);
|
||||
send_simple_response(STATUS_OK);
|
||||
}
|
||||
|
||||
@ -219,7 +213,6 @@ typedef struct __attribute__((packed)) {
|
||||
struct {
|
||||
uint8_t idm[8];
|
||||
uint8_t pmm[8];
|
||||
uint8_t syscode[2];
|
||||
};
|
||||
uint8_t uid[6];
|
||||
};
|
||||
@ -230,11 +223,16 @@ static void handle_mifare_card(const uint8_t *uid, int len)
|
||||
card_info_t *card = (card_info_t *) response.payload;
|
||||
|
||||
build_response(len > 4 ? 10 : 7);
|
||||
|
||||
card->count = 1;
|
||||
card->type = 0x10;
|
||||
card->id_len = len;
|
||||
|
||||
memcpy(card->uid, uid, len);
|
||||
|
||||
printf("\nMIFARE Card:");
|
||||
for (int i = 0; i < len; i++) {
|
||||
printf(" %02x", uid[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_felica_card(const uint8_t idm[8], const uint8_t pmm[8])
|
||||
@ -273,10 +271,11 @@ static void handle_no_card()
|
||||
static void cmd_detect_card()
|
||||
{
|
||||
nfc_card_t card = nfc_detect_card();
|
||||
display_card(&card);
|
||||
|
||||
switch (card.card_type) {
|
||||
case NFC_CARD_MIFARE:
|
||||
if (virtual_aic.enabled) {
|
||||
if (aic_cfg->virtual_aic) {
|
||||
printf("\nVirtual FeliCa from MIFARE.");
|
||||
virtual_aic.active = true;
|
||||
memcpy(virtual_aic.idm, "\x01\x01", 2);
|
||||
@ -292,7 +291,7 @@ static void cmd_detect_card()
|
||||
}
|
||||
break;
|
||||
case NFC_CARD_FELICA:
|
||||
if (virtual_aic.enabled) {
|
||||
if (aic_cfg->virtual_aic) {
|
||||
printf("\nVirtual FeliCa from FeliCa.");
|
||||
virtual_aic.active = true;
|
||||
memcpy(virtual_aic.idm, card.uid, 8);
|
||||
@ -302,7 +301,7 @@ static void cmd_detect_card()
|
||||
}
|
||||
break;
|
||||
case NFC_CARD_VICINITY:
|
||||
if (virtual_aic.enabled) {
|
||||
if (aic_cfg->virtual_aic) {
|
||||
printf("\nVirtual FeliCa from 15693.");
|
||||
virtual_aic.active = true;
|
||||
memcpy(virtual_aic.idm, card.uid, 8);
|
||||
@ -320,22 +319,19 @@ static void cmd_detect_card()
|
||||
|
||||
static void cmd_card_select()
|
||||
{
|
||||
printf("CARD SELECT %d\n", request.payload_len);
|
||||
send_simple_response(STATUS_OK);
|
||||
}
|
||||
|
||||
static void cmd_mifare_auth(int type)
|
||||
{
|
||||
printf("MIFARE AUTH\n");
|
||||
nfc_mifare_auth(request.mifare.uid, request.mifare.block_id, type, mifare_keys[type]);
|
||||
const uint8_t *key = mifare_keys[type];
|
||||
nfc_mifare_auth(request.mifare.uid, request.mifare.block_id,
|
||||
type, key);
|
||||
send_simple_response(STATUS_OK);
|
||||
}
|
||||
|
||||
static void cmd_mifare_read()
|
||||
{
|
||||
printf("MIFARE READ %02x %02x %02x %02x %02x\n", request.mifare.block_id,
|
||||
request.mifare.uid[0], request.mifare.uid[1], request.mifare.uid[2],
|
||||
request.mifare.uid[3]);
|
||||
build_response(16);
|
||||
memset(response.payload, 0, 16);
|
||||
nfc_mifare_read(request.mifare.block_id, response.payload);
|
||||
@ -344,7 +340,6 @@ static void cmd_mifare_read()
|
||||
|
||||
static void cmd_mifare_halt()
|
||||
{
|
||||
printf("MIFARE HALT\n");
|
||||
send_simple_response(STATUS_OK);
|
||||
}
|
||||
|
||||
@ -394,7 +389,7 @@ static int cmd_felica_read()
|
||||
uint8_t *req_data = request.felica.data;
|
||||
|
||||
if (req_data[8] != 1) {
|
||||
printf("Felica Encap READ Error: service_num != 1\n");
|
||||
printf("\nFelica Encap READ Error: service_num != 1");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -416,10 +411,11 @@ static int cmd_felica_read()
|
||||
|
||||
for (int i = 0; i < block_num; i++) {
|
||||
uint16_t block_id = (block[i * 2 + 1] << 8) | block[i * 2 + 2];
|
||||
if (block_id == 0x8082) {
|
||||
memcpy(read_resp->block_data[i], felica_resp->idm, 8);
|
||||
}
|
||||
if (!virtual_aic.active) {
|
||||
if (virtual_aic.active) {
|
||||
if (block_id == 0x8082) {
|
||||
memcpy(read_resp->block_data[i], virtual_aic.idm, 8);
|
||||
}
|
||||
} else {
|
||||
nfc_felica_read_wo_encrypt(svc_code, block_id, read_resp->block_data[i]);
|
||||
}
|
||||
}
|
||||
@ -436,7 +432,7 @@ static int cmd_felica_write()
|
||||
uint8_t *req_data = request.felica.data;
|
||||
|
||||
if (req_data[8] != 1) {
|
||||
printf("Felica Encap Write Error: service_num != 1\n");
|
||||
printf("\nFelica Encap Write Error: service_num != 1");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -466,24 +462,16 @@ static int cmd_felica_write()
|
||||
|
||||
static void cmd_felica()
|
||||
{
|
||||
nfc_card_t card = nfc_detect_card();
|
||||
if (!virtual_aic.active) {
|
||||
if (card.card_type != NFC_CARD_FELICA) {
|
||||
send_simple_response(STATUS_FELICA_ERROR);
|
||||
return;
|
||||
}
|
||||
nfc_card_t card = nfc_poll_felica();
|
||||
if ((card.card_type != NFC_CARD_FELICA) && (!virtual_aic.active)) {
|
||||
send_simple_response(STATUS_FELICA_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t felica_code = request.felica.code;
|
||||
/*
|
||||
printf("Felica (%02x):", felica_code);
|
||||
for (int i = 0; i < request.payload_len; i++) {
|
||||
printf(" %02x", request.payload[i]);
|
||||
}
|
||||
printf("\n");
|
||||
*/
|
||||
uint8_t felica_op = request.felica.code;
|
||||
|
||||
int datalen = -1;
|
||||
switch (felica_code) {
|
||||
switch (felica_op) {
|
||||
case CMD_FELICA_OP_GET_SYSTEM_CODE:
|
||||
datalen = cmd_felica_get_syscode(&card);
|
||||
break;
|
||||
@ -497,7 +485,7 @@ static void cmd_felica()
|
||||
datalen = cmd_felica_write();
|
||||
break;
|
||||
default:
|
||||
printf("Unknown code %d\n", felica_code);
|
||||
printf("\nUnknown code %d", felica_op);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -509,7 +497,7 @@ static void cmd_felica()
|
||||
felica_resp_t *felica_resp = (felica_resp_t *) response.payload;
|
||||
build_response(sizeof(*felica_resp) + datalen);
|
||||
felica_resp->len = response.payload_len;
|
||||
felica_resp->code = felica_code + 1;
|
||||
felica_resp->code = felica_op + 1;
|
||||
if (virtual_aic.active) {
|
||||
memcpy(felica_resp->idm, virtual_aic.idm, 8);
|
||||
} else {
|
||||
@ -601,16 +589,18 @@ static void aime_handle_frame()
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Unknown command: %02x [", request.cmd);
|
||||
printf("\nUnknown command: %02x [", request.cmd);
|
||||
for (int i = 0; i < request.len; i++) {
|
||||
printf(" %02x", request.raw[i]);
|
||||
}
|
||||
printf("]\n");
|
||||
printf("]");
|
||||
send_simple_response(STATUS_OK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t expire_time;
|
||||
|
||||
bool aime_feed(int c)
|
||||
{
|
||||
if (c == 0xe0) {
|
||||
@ -640,6 +630,7 @@ bool aime_feed(int c)
|
||||
if (req_ctx.check_sum == c) {
|
||||
aime_handle_frame();
|
||||
req_ctx.active = false;
|
||||
expire_time = time_us_64() + AIME_EXPIRE_TIME;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -651,6 +642,11 @@ bool aime_feed(int c)
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t aime_expire_time()
|
||||
{
|
||||
return expire_time;
|
||||
}
|
||||
|
||||
uint32_t aime_led_color()
|
||||
{
|
||||
return led_color;
|
||||
|
@ -12,6 +12,9 @@ typedef void (*aime_putc_func)(uint8_t byte);
|
||||
void aime_init(aime_putc_func putc_func);
|
||||
bool aime_feed(int c);
|
||||
|
||||
/* aime activity expires at this time */
|
||||
uint64_t aime_expire_time();
|
||||
|
||||
uint32_t aime_led_color();
|
||||
|
||||
// mode 0 or 1
|
||||
|
@ -8,7 +8,7 @@
|
||||
#define I2C_PORT i2c0
|
||||
#define I2C_SCL 21
|
||||
#define I2C_SDA 20
|
||||
#define I2C_FREQ 733*1000
|
||||
#define I2C_FREQ 433*1000
|
||||
|
||||
#define RGB_PIN 12
|
||||
#define RGB_ORDER GRB // or RGB
|
||||
|
@ -39,6 +39,7 @@ static void handle_display()
|
||||
aic_cfg->light.rgb ? "ON" : "OFF",
|
||||
aic_cfg->light.led ? "ON" : "OFF");
|
||||
printf(" Level: [%d ~ %d]\n", aic_cfg->light.min, aic_cfg->light.max);
|
||||
printf(" Virtual AIC: %s\n", aic_cfg->virtual_aic ? "ON" : "OFF");
|
||||
}
|
||||
|
||||
static void handle_save()
|
||||
@ -63,6 +64,27 @@ static void handle_nfc()
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
static void handle_virtual(int argc, char *argv[])
|
||||
{
|
||||
const char *usage = "Usage: virtual <on|off>\n";
|
||||
if (argc != 1) {
|
||||
printf("%s", usage);
|
||||
return;
|
||||
}
|
||||
|
||||
const char *commands[] = { "on", "off" };
|
||||
int match = cli_match_prefix(commands, 2, argv[0]);
|
||||
if (match < 0) {
|
||||
printf("%s", usage);
|
||||
return;
|
||||
}
|
||||
|
||||
aic_cfg->virtual_aic = (match == 0);
|
||||
|
||||
config_changed();
|
||||
}
|
||||
|
||||
static void handle_light(int argc, char *argv[])
|
||||
{
|
||||
const char *usage = "Usage: light <rgb|led|both|off>\n";
|
||||
@ -133,6 +155,7 @@ void commands_init()
|
||||
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 module.");
|
||||
cli_register("virtual", handle_virtual, "Virtual AIC card.");
|
||||
cli_register("light", handle_light, "Turn on/off lights.");
|
||||
cli_register("level", handle_level, "Set light level.");
|
||||
}
|
||||
|
@ -12,7 +12,8 @@
|
||||
aic_cfg_t *aic_cfg;
|
||||
|
||||
static aic_cfg_t default_cfg = {
|
||||
.light = { .min = 0, .max = 128, .rgb = true, .led = true }
|
||||
.light = { .min = 0, .max = 128, .rgb = true, .led = true },
|
||||
.virtual_aic = true,
|
||||
};
|
||||
|
||||
aic_runtime_t *aic_runtime;
|
||||
|
@ -16,6 +16,7 @@ typedef struct __attribute__((packed)) {
|
||||
bool rgb;
|
||||
bool led;
|
||||
} light;
|
||||
bool virtual_aic;
|
||||
uint32_t reserved;
|
||||
} aic_cfg_t;
|
||||
|
||||
|
@ -158,7 +158,7 @@ static void rainbow_fade()
|
||||
last = now;
|
||||
|
||||
if (curr_speed > RAINBOW_MIN_SPEED) {
|
||||
curr_speed = curr_speed * 95 / 100;
|
||||
curr_speed = curr_speed * 90 / 100;
|
||||
}
|
||||
if (curr_level > aic_cfg->light.min) {
|
||||
curr_level -= (curr_level - aic_cfg->light.min) / 10 + 1;
|
||||
|
@ -107,46 +107,60 @@ static void core1_loop()
|
||||
}
|
||||
}
|
||||
|
||||
void detect_card()
|
||||
static void update_cardio(nfc_card_t *card)
|
||||
{
|
||||
static nfc_card_t old_card = { 0 };
|
||||
|
||||
nfc_card_t card = nfc_detect_card();
|
||||
switch (card.card_type) {
|
||||
switch (card->card_type) {
|
||||
case NFC_CARD_MIFARE:
|
||||
hid_cardio.current[0] = REPORT_ID_EAMU;
|
||||
hid_cardio.current[1] = 0xe0;
|
||||
hid_cardio.current[2] = 0x04;
|
||||
if (card.len == 4) {
|
||||
memcpy(hid_cardio.current + 3, card.uid, 4);
|
||||
memcpy(hid_cardio.current + 7, card.uid, 2);
|
||||
} else if (card.len == 7) {
|
||||
memcpy(hid_cardio.current + 3, card.uid + 1, 6);
|
||||
if (card->len == 4) {
|
||||
memcpy(hid_cardio.current + 3, card->uid, 4);
|
||||
memcpy(hid_cardio.current + 7, card->uid, 2);
|
||||
} else if (card->len == 7) {
|
||||
memcpy(hid_cardio.current + 3, card->uid + 1, 6);
|
||||
}
|
||||
break;
|
||||
case NFC_CARD_FELICA:
|
||||
hid_cardio.current[0] = REPORT_ID_FELICA;
|
||||
memcpy(hid_cardio.current + 1, card.uid, 8);
|
||||
memcpy(hid_cardio.current + 1, card->uid, 8);
|
||||
break;
|
||||
case NFC_CARD_VICINITY:
|
||||
hid_cardio.current[0] = REPORT_ID_EAMU;
|
||||
memcpy(hid_cardio.current + 1, card.uid, 8);
|
||||
memcpy(hid_cardio.current + 1, card->uid, 8);
|
||||
break;
|
||||
default:
|
||||
memset(hid_cardio.current, 0, 9);
|
||||
return;
|
||||
}
|
||||
if (memcmp(&old_card, &card, sizeof(card)) == 0) {
|
||||
|
||||
printf(" -> CardIO ");
|
||||
for (int i = 1; i < 9; i++) {
|
||||
printf("%02X", hid_cardio.current[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void detect_card()
|
||||
{
|
||||
if (time_us_64() < aime_expire_time()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
nfc_rf_field(true);
|
||||
|
||||
static nfc_card_t old_card = { 0 };
|
||||
nfc_card_t card = nfc_detect_card();
|
||||
|
||||
nfc_rf_field(false);
|
||||
|
||||
if (memcmp(&old_card, &card, sizeof(old_card)) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
old_card = card;
|
||||
|
||||
display_card(&card);
|
||||
update_cardio(&card);
|
||||
}
|
||||
|
||||
const int aime_intf = 1;
|
||||
|
@ -62,14 +62,19 @@ static bool null_poll_vicinity(uint8_t uid[8])
|
||||
return false;
|
||||
}
|
||||
|
||||
static void null_rf_field(bool on)
|
||||
{
|
||||
}
|
||||
|
||||
struct {
|
||||
bool (*poll_mifare)(uint8_t uid[7], int *len);
|
||||
bool (*poll_felica)(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool from_cache);
|
||||
bool (*poll_vicinity)(uint8_t uid[8]);
|
||||
void (*rf_field)(bool on);
|
||||
} api[3] = {
|
||||
{ pn532_poll_mifare, pn532_poll_felica, null_poll_vicinity,},
|
||||
{ pn5180_poll_mifare, pn5180_poll_felica, pn5180_poll_vicinity,},
|
||||
{ null_poll_mifare, null_poll_felica, null_poll_vicinity,},
|
||||
{ pn532_poll_mifare, pn532_poll_felica, null_poll_vicinity, pn532_rf_field},
|
||||
{ pn5180_poll_mifare, pn5180_poll_felica, pn5180_poll_vicinity, null_rf_field},
|
||||
{ null_poll_mifare, null_poll_felica, null_poll_vicinity, null_rf_field},
|
||||
};
|
||||
|
||||
void nfc_init(nfc_wait_loop_t loop)
|
||||
@ -83,13 +88,6 @@ void nfc_init(nfc_wait_loop_t loop)
|
||||
}
|
||||
}
|
||||
|
||||
static void nfc_config_sam()
|
||||
{
|
||||
if (nfc_module == NFC_MODULE_PN532) {
|
||||
pn532_config_sam();
|
||||
}
|
||||
}
|
||||
|
||||
static bool nfc_detect_mifare(nfc_card_t *card)
|
||||
{
|
||||
uint8_t id[20] = { 0 };
|
||||
@ -138,12 +136,15 @@ static bool nfc_detect_vicinity(nfc_card_t *card)
|
||||
return true;
|
||||
}
|
||||
|
||||
void nfc_rf_field(bool on)
|
||||
{
|
||||
api[nfc_module].rf_field(on);
|
||||
}
|
||||
|
||||
nfc_card_t nfc_detect_card()
|
||||
{
|
||||
nfc_card_t card = { 0 };
|
||||
|
||||
nfc_config_sam();
|
||||
|
||||
if (!nfc_detect_mifare(&card) &&
|
||||
!nfc_detect_felica(&card) &&
|
||||
!nfc_detect_vicinity(&card)) {
|
||||
@ -153,6 +154,25 @@ nfc_card_t nfc_detect_card()
|
||||
return card;
|
||||
}
|
||||
|
||||
nfc_card_t nfc_poll_felica()
|
||||
{
|
||||
nfc_card_t card = { 0 };
|
||||
if (!nfc_detect_felica(&card)) {
|
||||
card.card_type = NFC_CARD_NONE;
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
void display_card(const nfc_card_t *card)
|
||||
{
|
||||
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", card->uid[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool nfc_mifare_auth(const uint8_t uid[4], uint8_t block_id, uint8_t key_id, const uint8_t *key)
|
||||
{
|
||||
if (nfc_module == NFC_MODULE_PN532) {
|
||||
|
@ -31,7 +31,12 @@ typedef struct {
|
||||
} nfc_card_t;
|
||||
|
||||
void nfc_init(nfc_wait_loop_t loop);
|
||||
void nfc_rf_field(bool on);
|
||||
|
||||
nfc_card_t nfc_detect_card();
|
||||
void display_card(const nfc_card_t *card);
|
||||
|
||||
nfc_card_t nfc_poll_felica();
|
||||
|
||||
const char *nfc_module_name();
|
||||
|
||||
|
@ -294,8 +294,7 @@ bool pn532_config_sam()
|
||||
return pn532_read_response(0x14, &resp, 1) == 0;
|
||||
}
|
||||
|
||||
|
||||
bool pn532_set_rf_field(uint8_t auto_rf, uint8_t on_off)
|
||||
static bool pn532_set_rf_field(uint8_t auto_rf, uint8_t on_off)
|
||||
{
|
||||
uint8_t param[] = { 1, auto_rf | on_off };
|
||||
pn532_write_command(0x32, param, 2);
|
||||
@ -304,6 +303,14 @@ bool pn532_set_rf_field(uint8_t auto_rf, uint8_t on_off)
|
||||
return pn532_read_response(0x32, &resp, 1) >= 0;
|
||||
}
|
||||
|
||||
void pn532_rf_field(bool on)
|
||||
{
|
||||
pn532_set_rf_field(0x00, on ? 0x01 : 0x00);
|
||||
if (on) {
|
||||
pn532_config_sam();
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t readbuf[255];
|
||||
|
||||
bool pn532_poll_mifare(uint8_t uid[7], int *len)
|
||||
@ -371,20 +378,21 @@ bool pn532_poll_felica(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool
|
||||
|
||||
bool pn532_mifare_auth(const uint8_t uid[4], uint8_t block_id, uint8_t key_id, const uint8_t *key)
|
||||
{
|
||||
uint8_t param[] = { 1, key_id ? 1 : 0, block_id,
|
||||
key[0], key[1], key[2], key[3], key[4], key[5],
|
||||
uid[0], uid[1], uid[2], uid[3] };
|
||||
uint8_t param[] = {
|
||||
1, key_id ? 0x61 : 0x60, block_id,
|
||||
key[0], key[1], key[2], key[3], key[4], key[5],
|
||||
uid[0], uid[1], uid[2], uid[3]
|
||||
};
|
||||
int ret = pn532_write_command(0x40, param, sizeof(param));
|
||||
if (ret < 0) {
|
||||
printf("Failed mifare auth command\n");
|
||||
printf("\nPN532 failed mifare auth command");
|
||||
return false;
|
||||
}
|
||||
int result = pn532_read_response(0x40, readbuf, sizeof(readbuf));
|
||||
if (readbuf[0] != 0) {
|
||||
printf("PN532 Mifare AUTH failed %d %02x\n", result, readbuf[0]);
|
||||
printf("\nPN532 Mifare AUTH failed %d %02x", result, readbuf[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -394,14 +402,14 @@ bool pn532_mifare_read(uint8_t block_id, uint8_t block_data[16])
|
||||
|
||||
int ret = pn532_write_command(0x40, param, sizeof(param));
|
||||
if (ret < 0) {
|
||||
printf("Failed mifare read command\n");
|
||||
printf("\nPN532 failed mifare read command");
|
||||
return false;
|
||||
}
|
||||
|
||||
int result = pn532_read_response(0x40, readbuf, sizeof(readbuf));
|
||||
|
||||
if (readbuf[0] != 0 || result != 17) {
|
||||
printf("PN532 Mifare READ failed %d %02x\n", result, readbuf[0]);
|
||||
printf("\nPN532 Mifare READ failed %d %02x", result, readbuf[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -423,7 +431,7 @@ int pn532_felica_command(uint8_t cmd, const uint8_t *param, uint8_t param_len, u
|
||||
|
||||
int ret = pn532_write_command(0x40, cmd_buf, sizeof(cmd_buf));
|
||||
if (ret < 0) {
|
||||
printf("Failed send felica command\n");
|
||||
printf("\nFailed send felica command");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -448,13 +456,13 @@ bool pn532_felica_read_wo_encrypt(uint16_t svc_code, uint16_t block_id, uint8_t
|
||||
int result = pn532_felica_command(0x06, param, sizeof(param), readbuf);
|
||||
|
||||
if (result != 12 + 16 || readbuf[9] != 0 || readbuf[10] != 0) {
|
||||
printf("PN532 Felica READ read failed %d %02x %02x\n",
|
||||
result, readbuf[9], readbuf[10]);
|
||||
//printf("\nPN532 Felica READ read failed %d %02x %02x",
|
||||
// result, readbuf[9], readbuf[10]);
|
||||
for (int i = 0; i < result; i++) {
|
||||
printf(" %02x", readbuf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return false;
|
||||
memset(block_data, 0, 16);
|
||||
return true; // we fake the result when it fails
|
||||
}
|
||||
|
||||
const uint8_t *result_data = readbuf + 12;
|
||||
@ -471,13 +479,13 @@ bool pn532_felica_write_wo_encrypt(uint16_t svc_code, uint16_t block_id, const u
|
||||
int result = pn532_felica_command(0x08, param, sizeof(param), readbuf);
|
||||
|
||||
if (result < 0) {
|
||||
printf("PN532 Felica WRITE failed %d\n", result);
|
||||
printf("\nPN532 Felica WRITE failed %d", result);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("\nPN532 Felica WRITE success ");
|
||||
for (int i = 0; i < result; i++) {
|
||||
printf(" %02x", readbuf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ uint32_t pn532_firmware_ver();
|
||||
bool pn532_config_sam();
|
||||
bool pn532_config_rf();
|
||||
|
||||
bool pn532_set_rf_field(uint8_t auto_rf, uint8_t on_off);
|
||||
void pn532_rf_field(bool on);
|
||||
|
||||
bool pn532_poll_mifare(uint8_t uid[7], int *len);
|
||||
bool pn532_poll_felica(uint8_t uid[8], uint8_t pmm[8], uint8_t syscode[2], bool from_cache);
|
||||
|
Loading…
Reference in New Issue
Block a user