目录

树莓派4 Pn5320 Nfc

树莓派

1 树莓派+pn532使用NFC

1.1 连接线

5v(VCC) <==> 5v
GND <==> GND
SDA <==> SDA
SCL <==> SCL

GND -> 6 地线
VCC ->4 电源 5v
SDA/TX  -> 3 SDA.1
SCL/RX  ->5  SCL.1
参考上一篇pi4  JPIO 图

-w483

-w355

注意一下左上角有个模式切换开关:
我这里使用的是I2C模式,于是把开关切换成了 1 0
把1这里推上去

-w499

1.2 开启i2c

pi-pi1  ➜  ~ sudo raspi-config
#配置一下截图后,重启
pi-pi1  ➜  ~ sudo reboot

-w896

-w849

-w427

-w423

#重启完系统会出现下面
pi-pi1  ➜  ~ ll /dev/i2c-1
crw-rw---- 1 root i2c 89, 1 Feb 25 10:44 /dev/i2c-1

pi-pi1 ➜  ~ sudo apt-get install i2c-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
i2c-tools is already the newest version (4.1-1).
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.

#如果出现的不全是横杠,就代表连接成功了
树莓派B型:
pi-pi1  ➜  ~ sudo 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: -- -- -- -- -- -- -- --

树莓派A型:
sudo i2cdetect -y 0

1.3 安装libnfc

sudo apt-get install libusb-dev libpcsclite-dev automake autoconf

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

-w628

#添加配置文件
sudo  mkdir  /etc/nfc
sudo   vim /etc/nfc/libnfc.conf


# 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"



#放一张卡上去,执行nfc-list命令查看卡信息
pi-pi1  ➜  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): a9  f8  b5  b0
      SAK (SEL_RES): 08

1.4 安装mfoc(破解key,读出数据到文件)

git clone https://github.com/nfc-tools/mfoc.git
cd mfoc
automake
autoconf
autoreconf -is
./configure
make && sudo make install

1.5 安装mfuck(破解全加密数据)

git clone https://github.com/nfc-tools/mfcuk.git
cd mfcuk
automake
autoconf
autoreconf -is
./configure
make && sudo make install

1.6 命令

 #半加密
 mfoc -O output.mfd
 #全加密
 mfcuk -C -R 0:A -v 2
 #写入数据
 nfc-mfclassic w a  output.mfd output.mfd    #  写入数据,w小写,如果大写是强写0扇区