Skip to content

Commit

Permalink
支持了banapass,感谢 Lee 和 LTC 的帮助。
Browse files Browse the repository at this point in the history
  • Loading branch information
Sucareto committed Mar 12, 2022
1 parent eabca8f commit 9ded22e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
9 changes: 6 additions & 3 deletions Arduino-Aime-Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ void SerialCheck() {
case SG_NFC_CMD_FELICA_ENCAP:
sg_nfc_cmd_felica_encap();
break;
case SG_NFC_CMD_MIFARE_AUTHENTICATE:
sg_nfc_cmd_mifare_authenticate();
case SG_NFC_CMD_AIME_AUTHENTICATE:
sg_nfc_cmd_aime_authenticate();
break;
case SG_NFC_CMD_BANA_AUTHENTICATE:
sg_nfc_cmd_bana_authenticate();
break;
case SG_NFC_CMD_MIFARE_SELECT_TAG:
sg_nfc_cmd_mifare_select_tag();
Expand All @@ -142,7 +145,7 @@ void SerialCheck() {
sg_nfc_cmd_mifare_set_key_aime();
break;
case SG_NFC_CMD_MIFARE_SET_KEY_BANA:
sg_res_init();
sg_nfc_cmd_mifare_set_key_bana();
break;
case SG_NFC_CMD_RADIO_ON:
sg_nfc_cmd_radio_on();
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Arduino-Aime-Reader
使用 Arduino + PN532 + WS2812B 制作的 Aime 兼容读卡器。支持 Felica,Aime。
使用 Arduino + PN532 + WS2812B 制作的 Aime 兼容读卡器。
支持 [FeliCa](https://zh.wikipedia.org/wiki/FeliCa)(Amusement IC、Suica、八达通等)和 [MIFARE](https://zh.wikipedia.org/wiki/MIFARE)(Aime,Banapassport)。
实现逻辑为官方读卡器串口数据对比 + 脑补,不保证正确实现。
通信数据格式参考了 [Segatools]() 和官方读卡器抓包数据,可在 [Example.txt](doc/Example.txt)[nfc.txt](doc/nfc.txt) 查看。

Expand All @@ -19,11 +20,11 @@


### 支持列表:
- SDBT:COM12,支持读取 FelicaAime
- SDDT/SDEZ:COM1,支持读取 FelicaAime
- SBZV/SDDF:COM10,支持读取 FelicaAime
- SDEY:COM2,仅支持读取 Aime
- SDHD:COM4,支持读取 FelicaAime
- SDBT:COM12,支持读取 FeliCaMIFARE
- SDDT/SDEZ:COM1,支持读取 FeliCaMIFARE
- SBZV/SDDF:COM10,支持读取 FeliCaMIFARE
- SDEY:COM2,仅支持读取 MIFARE
- SDHD:COM4,支持读取 FeliCaMIFARE

有使用 amdaemon 的,可以参考 config_common.json 内 aime > unit > port,high_baudrate 来确定 COM 号和波特率。

Expand All @@ -36,7 +37,6 @@

### 已知问题:
- Felica 在非 amdaemon 游戏可能无法正常工作,因为 NDA_06 未正确回复
- banapassport 卡因为没有数据参考,所以没有支持
- 未确定`res.status`的意义,因此`res.status = 1;`可能是错误的
- 因为`get_fw``get_hw`返回的是自定义版本号,启动时可能触发 amdaemon 的固件升级,可以将 aime_firm 文件夹重命名或删除
- 未实现`mifare_select_tag`,未支持多卡选择,只会读到最先识别的卡片
Expand Down
21 changes: 18 additions & 3 deletions cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CRGB leds[NUM_LEDS];
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);

uint8_t AimeKey[6];
uint8_t AimeKey[6], BanaKey[6];;

enum {
SG_NFC_CMD_GET_FW_VERSION = 0x30,
Expand All @@ -22,7 +22,7 @@ enum {
SG_NFC_CMD_BANA_AUTHENTICATE = 0x51,
SG_NFC_CMD_MIFARE_READ_BLOCK = 0x52,
SG_NFC_CMD_MIFARE_SET_KEY_AIME = 0x54,
SG_NFC_CMD_MIFARE_AUTHENTICATE = 0x55,
SG_NFC_CMD_AIME_AUTHENTICATE = 0x55,
SG_NFC_CMD_UNKNOW0 = 0x60, /* maybe some stuff about AimePay*/
SG_NFC_CMD_UNKNOW1 = 0x61,
SG_NFC_CMD_RESET = 0x62,
Expand Down Expand Up @@ -159,6 +159,11 @@ static void sg_nfc_cmd_mifare_set_key_aime() {
memcpy(AimeKey, req.key, 6);
}

static void sg_nfc_cmd_mifare_set_key_bana() {
sg_res_init();
memcpy(BanaKey, req.key, 6);
}

static void sg_led_cmd_reset() {
sg_res_init();
FastLED.clear();
Expand Down Expand Up @@ -214,7 +219,7 @@ static void sg_nfc_cmd_mifare_select_tag() {
sg_res_init();
}

static void sg_nfc_cmd_mifare_authenticate() {
static void sg_nfc_cmd_aime_authenticate() {
sg_res_init();
//AuthenticateBlock(uid,uidLen,block,keyType(A=0,B=1),keyData)
if (nfc.mifareclassic_AuthenticateBlock(req.uid, 4, req.block_no, 1, AimeKey)) {
Expand All @@ -224,6 +229,16 @@ static void sg_nfc_cmd_mifare_authenticate() {
}
}

static void sg_nfc_cmd_bana_authenticate() {
sg_res_init();
//AuthenticateBlock(uid,uidLen,block,keyType(A=0,B=1),keyData)
if (nfc.mifareclassic_AuthenticateBlock(req.uid, 4, req.block_no, 0, BanaKey)) {
return;
} else {
res.status = 1;
}
}

static void sg_nfc_cmd_mifare_read_block() {//读取卡扇区数据
if (nfc.mifareclassic_ReadDataBlock(req.block_no, res.block)) {
sg_res_init(0x10);
Expand Down

0 comments on commit 9ded22e

Please sign in to comment.