物品清单
1.树莓派4x1
2.T型面包板x1
3.PN532 NFC模块x1
4.可改写0扇区的rfid卡
以上所有材料均可在淘宝采购
接线
该模块分为I2C与SPI两种接线模式,我使用的是I2C模式,所以本文只讲I2C 改为i2c模式
对应的映射为
具体可参考PN532 WIKI.
环境配置
如果之前配置过NFC 执行
sudo rm -rf /etc/nfc
删除之前的配置打开树莓拍i2c接口 Interfacing Options -> I2C -> yes.
安装依赖
sudo apt-get update
sudo apt-get install libusb-dev libpcsclite-dev i2c-tools`
下载libnfc
cd ~
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
配置libnfc
cd /etc
sudo mkdir nfc
sudo nano /etc/nfc/libnfc.conf
填入以下内容
# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to set manually 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, user should prefer to add manually his 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, you must set both name and connstring for your device
# Note: if autoscan is enabled, default device will be the first device available in device list.
#device.name = "_PN532_SPI"
#device.connstring = "pn532_spi:/dev/spidev0.0:500000"
device.name = "_PN532_I2c"
device.connstring = "pn532_i2c:/dev/i2c-1"
接好线配置好后重启设备,检测是否成功
i2cdetect –y 1
nfc-list
破解
安装mfoc与mfcuk mfoc(破解key,读出数据到文件):https://github.com/nfc-tools/mfoc mfuck(破解全加密数据):https://github.com/nfc-tools/mfcuk 后两个下载解压后切换到目录里执行:
automake
autoconf
autoreconf -is
./configure
make
make install
修改UID 由于国内大部分门禁卡只是基于UID做识别,所以只需要修改RFID的UID,也就是0扇区,就行了,所以我们需要去采购0扇区可写的rfid卡,复制改写就行了,具体参考nfc-mfsetuid
nfc-mfsetuid [ UID ]
写完uid后再运行
nfc-list
比对新老卡 uid 是否一致,一致则大功告成!
参考文献 PN532 WIKI,nfc-mfsetuid
评论区