勇闖新世界︰ W!o《卡夫卡村》變形祭︰神奇護照‧四

俗話講︰成王敗寇。將之用於這世界的『技術規範』主流通常也是如此。雖說經過『市場洗禮』沒什麼不好,然而『眼前近利』恐易放棄『長遠福祉』。是以思『子孫綿延』者,不得不謀『千秋萬世 』吉祥。或將理解『天下交相利,國危也。』之所指的耶!如是觀『 nfcpy 』與『 libnfc 』理念之異同,自當可求其會通處也。

 

【 nfcpy 安裝】

# 取得派生二 nfcpy 
pi@raspberrypi ~ mkdir nfc pi@raspberrypi ~ cd nfc
pi@raspberrypi ~ wget https://launchpad.net/nfcpy/0.10/0.10.0/+download/nfcpy-0.10.0.tar.gz  pi@raspberrypi ~/nfc ls
nfcpy-0.10.0.tar.gz

pi@raspberrypi ~/nfc tar zxvf nfcpy-0.10.0.tar.gz   # 安裝 nfcpy 所需之 python 程式庫 pi@raspberrypi ~/nfc sudo apt-get install python-usb
pi@raspberrypi ~/nfc sudo apt-get install python-serial pi@raspberrypi ~/nfc sudo pip install docopt==0.6.1

# 執行驗證
pi@raspberrypi ~/nfc cd 0.10.0/  # 可能無法自動偵測 USB ACS / ACR122U nfc 讀寫機 pi@raspberrypi ~/nfc/0.10.0 python examples/tagtool.py show
[nfc.clf] searching for reader on path usb
[nfc.clf] no reader available on path usb
[main] no contactless reader found on usb
[main] no contactless reader available

# 指定裝置,注意使用者 pi 的讀寫權限
pi@raspberrypi ~/nfc/0.10.0 python examples/tagtool.py --device usb:072f:2200 show [nfc.clf] searching for reader on path usb:072f:2200 [main] access denied for device with path usb:072f:2200 [main] first match for path usb:072f:2200 is usb:001:008 [main] usb:001:008 is owned by root but you are pi [main] members of the root group may use usb:001:008 [main] you may want to add a udev rule to access this device [main] sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"072f\", ATTRS{idProduct}==\"2200\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules' [main] no contactless reader available  # 確定 sudo 可以正確執行 pi@raspberrypi ~/nfc/0.10.0 sudo python examples/tagtool.py --device usb:072f:2200 show
[nfc.clf] searching for reader on path usb:072f:2200
[nfc.clf] using ACS ACR122U PN532v1.6 at usb:001:008
** waiting for a tag **
Type2Tag ID=E0E72711

# 依建議增加 nfc 裝置的 udev 規則
pi@raspberrypi ~/nfc/0.10.0 sudo sh -c 'echo SUBSYSTEM==\"usb\", ACTION==\"add\", ATTRS{idVendor}==\"072f\", ATTRS{idProduct}==\"2200\", GROUP=\"plugdev\" >> /etc/udev/rules.d/nfcdev.rules'  pi@raspberrypi ~/nfc/0.10.0 more /etc/udev/rules.d/nfcdev.rules 
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="072f", ATTRS{idProduct}=="220
0", GROUP="plugdev"

# 重新開機
pi@raspberrypi ~/nfc/0.10.0 sudo reboot  # 確認使用者 pi 的權限 pi@raspberrypi ~/nfc/0.10.0 python examples/tagtool.py --device usb:072f:2200 show
[nfc.clf] searching for reader on path usb:072f:2200
[nfc.clf] using ACS ACR122U PN532v1.6 at usb:001:008
** waiting for a tag **
Type2Tag ID=E0E72711

pi@raspberrypi ~/nfc/0.10.0 </pre>    <span style="color: #808000;">此處使用『 USB ACS / ACR122U 』  nfc 讀寫機,一、介紹一般使用的產品。二、預為『 NFC 卡』未來應用之 探討預作準備。</span>     <a href="http://www.freesandal.org/wp-content/uploads/3-acr122u.png"><img class="alignnone size-full wp-image-40412" src="http://www.freesandal.org/wp-content/uploads/3-acr122u.png" alt="3-acr122u" width="260" height="220" /></a>     <span style="color: #808000;">如果使用『 PN532 Breakout Board』 </span>  <a href="http://www.freesandal.org/wp-content/uploads/USB-RS232接線圖.jpg"><img class="alignnone size-full wp-image-40460" src="http://www.freesandal.org/wp-content/uploads/USB-RS232接線圖.jpg" alt="USB-RS232接線圖" width="2150" height="1118" /></a>     <span style="color: #808080;"><strong>【 nfcpy tagtool 範例】</strong></span> <pre class="lang:sh decode:true">pi@raspberrypi ~/nfc/0.10.0 python examples/tagtool.py --device tty:USB0:pn532 show
[nfc.clf] searching for reader on path tty:USB0:pn532
[nfc.clf] using PN532v1.6 at /dev/ttyUSB0
** waiting for a tag **
Type2Tag ID=E0E72711
pi@raspberrypi ~/nfc/0.10.0 </pre>    <span style="color: #808000;">在繼續進行探討前,讀者最好先對『 nfcpy 』支援的『標籤型態』 <a href="http://nfc-forum.org/our-work/specifications-and-application-documents/specifications/tag-type-technical-specifications/">Tag Type</a> 有些了解︰</span> <h1 class="post-title">Tag Type Technical Specifications</h1> The NFC Forum has mandated four tag types to be operable with NFC devices. This is the backbone of interoperability between different NFC tag providers and NFC device manufacturers to ensure a consistent user experience.  The operation specifications for the NFC Forum Type 1/2/3/4 Tags provide the technical information needed to implement the reader/writer and associated control functionality of the NFC device to interact with the tags. The aim of these specifications is to define how NDEF messages are read from and written to NFC tags.  Type 1/2/3/4 Tags are all based on existing contactless products and are commercially available.  <img class="aligncenter wp-image-2395" src="http://nfc-forum.org/wp-content/uploads/2013/12/NFC1llcp.jpg" alt="NFC1llcp" /> <h3>NFC Forum Type 1 Tag Operation Specification</h3> Type 1 Tag is based on ISO/IEC 14443A. Tags are read and re-write capable; users can configure the tag to become read-only. Memory availability is 96 bytes and expandable to 2 kbyte. <h3>NFC Forum Type 2 Tag Operation Specification</h3> Type 2 Tag is based on ISO/IEC 14443A. Tags are read and re-write capable; users can configure the tag to become read-only. Memory availability is 48 bytes and expandable to 2 kbyte. <h3>NFC Forum Type 3 Tag Operation Specification</h3> Type 3 Tag is based on the Japanese Industrial Standard (JIS) X 6319-4, also known as FeliCa. Tags are pre-configured at manufacture to be either read and re-writable, or read-only. Memory availability is variable, theoretical memory limit is 1MByte per service. <h3>NFC Forum Type 4 Tag Operation Specification 2.0</h3> Type 4 Tag is fully compatible with the ISO/IEC 14443 standard series. Tags are pre-configured at manufacture to be either read and re-writable, or read-only. The memory availability is variable, up to 32 KBytes per service; the communication interface is either Type A or Type B compliant.  ───  <span style="color: #808000;">舉例說,『 nfcpy 』程式庫並不支援 Adafruit 隨機附贈的</span> <h1><span style="color: #808000;"><a style="color: #808000;" href="https://www.adafruit.com/products/359">MiFare Classic (13.56MHz RFID/NFC) Card - 1KB</a></span></h1> <a href="http://www.freesandal.org/wp-content/uploads/x359-00.jpg.pagespeed.ic_.KzETkeh0tG.jpg"><img class="alignnone size-full wp-image-40582" src="http://www.freesandal.org/wp-content/uploads/x359-00.jpg.pagespeed.ic_.KzETkeh0tG.jpg" alt="x359-00.jpg.pagespeed.ic.KzETkeh0tG" width="970" height="728" /></a> <ul> 	<li class="prod-accordion-content prod-accordion-content-description mobile-text-wrapper"> <h1 id="tab_description" class="hidden-sm hidden-xs">Description</h1> <div id="description" class="panel-collapse collapse in-md in-lg in">  This is a blank MiFare Classic card - often used for train/bus passes but also found in other systems where a proximity card is desired. The tag contains a NXP S50 chip and an antenna, and is passively powered by the reader/writer when placed a couple inches away.  These can be read by almost any 13.56MHz RFID/NFC reader but make sure it can handle MiFare cards as there are a few other encoding standards (like FeLica) They are tested and work great with both our <a href="http://www.adafruit.com/products/364">PN532 NFC/RFID breakout board</a> and <a href="http://www.adafruit.com/products/789">Adafruit NFC/RFID Shield for Arduino</a>!  <b>These chips can be written to</b> & store up to 1 KB of data in writable EEPROM divided into banks, and can handle over 100,000 re-writes. You can use our <a href="http://www.adafruit.com/products/364">PN532 NFC/RFID breakout board</a> or <a href="http://www.adafruit.com/products/789">Adafruit NFC/RFID Shield for Arduino</a> to read and write data to the EEPROM inside the tag. There is also a permanent 4-byte ID burned into the chip that you can use to identify one tag from another - <b>the ID number cannot be changed</b>.  These use the S50 chipset, which used to be the 'classic' NFC chipset. <span style="color: #ff9900;">In ~2014, the NFC forum decided not to support this chipset anymore, so newer phones do not support the MiFare classic.</span> This only matters if you're trying to use this tag with a phone/tablet.  </div></li> </ul> ───  <span style="color: #808000;">同時最好對『 <a style="color: #808000;" href="https://learn.adafruit.com/adafruit-pn532-rfid-nfc/ndef">NDEF </a>』 NFC Data Exchange Format 有些初步認識,以及仔細閱讀</span> <h1><a href="http://nfcpy.org/latest/examples/ndeftool.html">ndeftool.py</a></h1> The <strong>ndeftool</strong> intends to be a swiss army knife for working with NDEF data. <pre class="lang:sh decode:true"> ndeftool.py [-h] [-v] [-d] {print,make,pack,split,cat} ...

 

tagtool.py

The tagtool.py example program can be used to read or write NFC Forum Tags. For some tags, currently Type 3 Tags only, tagtool can also be used to format for NDEF use.

$ tagtool.py [-h|--help] [options] command

 

說明文件,以免引生不必要的誤解。由於『 nfc 論壇』之所有的『技術文件』,或需要『授權』或必須『購買』,所以作者對其『內容』或不知或無法提供來源,若是遇到語焉不詳之處,絕非『刻意』不講,實是不知或不便也。