想起之前買了個PN532
設(shè)備喇澡,然后就撿起來體驗一下
注意一下左上角有個模式切換開關(guān):
我這里使用的是I2C模式佣蓉,于是把開關(guān)切換成了 1 0
這個是我的樹莓派
我的接線如下:(BOARD編碼)
GND -> 6 地線
VCC ->4 電源
SDA/TX -> 2 SDA.1
SCL/RX ->3 SCL.1
接線完成之后中間PWD有個黃色指示燈會亮
-
安裝樹莓派上面必要的庫
sudo apt-get install libusb-dev libpcsclite-dev //這是libnfc依賴的庫
sudo apt-get install automake autoconf
如果安裝libusb-dev和libpcsclite-dev報版本錯誤安裝失敗“ Unable to correct problems, you have held broken packages.”碘举,
可執(zhí)行命令:aptitude install libusb-dev 宛裕,然后依次輸n、y涛目、y 即可赞季。
-
安裝nfc操作模塊
wget http://dl.bintray.com/nfc-tools/sources/libnfc-1.7.1.tar.bz2
tar -xf libnfc-1.7.1.tar.bz2
cd libnfc-1.7.1
./configure --prefix=/usr --sysconfdir=/etc
make
sudo make install
-
安裝mfoc(破解key,讀出數(shù)據(jù)到文件)
git clone https://github.com/nfc-tools/mfoc.git
cd mfoc
automake
autoconf
autoreconf -is
./configure
make && sudo make install
-
安裝mfuck(破解全加密數(shù)據(jù))
git clone https://github.com/nfc-tools/mfcuk.git
cd mfcuk
automake
autoconf
autoreconf -is
./configure
make && sudo make install
-
修改配置文件
cd /etc
sudo mkdir nfc
sudo nano /etc/nfc/libnfc.conf
添加下面內(nèi)容
# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to manually set a device
# configuration using file or environment variable
allow_autoscan = true
# Allow intrusive auto-detection (default: false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, so user should prefer to add manually his/her device.
allow_intrusive_scan = false
# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
log_level = 1
# Manually set default device (no default)
# To set a default device, users must set both name and connstring for their device
# Note: if autoscan is enabled, default device will be the first device available in device list.
device.name = "Itead_PN532_I2C"
device.connstring = "pn532_i2c:/dev/i2c-1"
如果你的設(shè)備沒有開啟
I2C
肃续,則開啟一下
執(zhí)行sudo raspi-config
黍檩,在第5項
里打開i2c
。
保存之后重啟一下
pi@raspberrypi:~/mfoc $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- 24 -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
如果輸入命令i2cdetect -y 1
返回的全部都是 -- 則沒有讀取出來數(shù)據(jù)
通過nfc-list
命令可以查看相關(guān)的結(jié)果
如果是下面這樣的
pi@raspberrypi:~/mfoc $ nfc-list
nfc-list uses libnfc 1.7.1
error libnfc.bus.i2c Error: wrote only -1 bytes (10 expected).
error libnfc.driver.pn532_i2c Unable to transmit data. (TX)
pn53x_check_communication: Input / Output Error
error libnfc.bus.i2c Error: wrote only -1 bytes (10 expected).
error libnfc.driver.pn532_i2c Unable to transmit data. (TX)
nfc-list: ERROR: Unable to open NFC device: pn532_i2c:/dev/i2c-1
可能是SDA SCL
線插錯了始锚,或者最開始說的模式?jīng)]有調(diào)對刽酱,調(diào)整好重插一下PN532
設(shè)備就可以了
調(diào)整好之后是這樣的
pi@raspberrypi:~/mfoc $ nfc-list
nfc-list uses libnfc 1.7.1
NFC device: pn532_i2c:/dev/i2c-1 opened
這個時候往PN532
上面放一張IC
卡 再次輸入命令
pi@raspberrypi:~/mfoc $ nfc-list
nfc-list uses libnfc 1.7.1
NFC device: pn532_i2c:/dev/i2c-1 opened
1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 04
UID (NFCID1): 29 0f 82 73
SAK (SEL_RES): 08
就能讀取到數(shù)據(jù)了
-
讀取數(shù)據(jù)
mfoc -O output.mfd // 讀出卡中的數(shù)據(jù)保存為文件output.mfd
mfoc
是讀取數(shù)據(jù),如果有加密就自動破解瞧捌,如果全加密棵里,就沒法讀取,可用mfuck
命令破解姐呐。
nfc-mfclassic w a output.mfd output.mfd // 寫入數(shù)據(jù)殿怜,w小寫,如果大寫是強寫0扇區(qū)
由于每張卡的0
扇區(qū)信息(UID
)不一樣曙砂,0
扇區(qū)又不可寫头谜,不同的卡沒法互寫。但是可寫入0
扇區(qū)可寫的UID
卡鸠澈。
參考鏈接:
https://www.rabbittu.com/raspi-pn532/
https://www.cnblogs.com/panda-blog/p/9998446.html