nfc-tools / libnfc

Platform independent Near Field Communication (NFC) library
http://nfc-tools.org
GNU Lesser General Public License v3.0
1.69k stars 441 forks source link

Support device 054c:1fc9 Sony Corp. NFC-PRO Reader #693

Closed albfan closed 11 months ago

albfan commented 1 year ago

I buy a cheap reader:

https://es.aliexpress.com/item/1005005158397333.html?channel=twinner

image

and works correctly on windows with this software:

http://ickashuju.com:666/dowloads/jichu/NFC-122-lvse.exe

$ lsusb -d 054c:
Bus 001 Device 057: ID 054c:1fc9 Sony Corp. NFC-PRO Reader

I suppose is a clone, so not sure if that can be added. Just tried this quick patch:

diff --git i/contrib/udev/93-pn53x.rules w/contrib/udev/93-pn53x.rules
index 99058af..472c3ca 100644
--- i/contrib/udev/93-pn53x.rules
+++ w/contrib/udev/93-pn53x.rules
@@ -7,6 +7,7 @@ ACTION!="add", GOTO="pn53x_rules_end"
 # PN531
 ATTRS{idVendor}=="04cc", ATTRS{idProduct}=="0531", MODE="0664", GROUP="plugdev"
 ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0193", MODE="0664", GROUP="plugdev"
+ATTRS{idVendor}=="054c", ATTRS{idProduct}=="1fc9", MODE="0664", GROUP="plugdev"

 # PN533
 ATTRS{idVendor}=="04cc", ATTRS{idProduct}=="2533", MODE="0664", GROUP="plugdev"
diff --git i/libnfc/drivers/pn53x_usb.c w/libnfc/drivers/pn53x_usb.c
index 52c40f0..a0aebbe 100644
--- i/libnfc/drivers/pn53x_usb.c
+++ w/libnfc/drivers/pn53x_usb.c
@@ -140,7 +140,8 @@ const struct pn53x_usb_supported_device pn53x_usb_supported_devices[] = {
   { 0x04E6, 0x5594, SCM_SCL3712, "SCM Micro / SCL3712-NFC&RW",  0, 0, 0 }, // to check on real device
   { 0x054c, 0x0193, SONY_PN531,  "Sony / PN531",                0x84, 0x04, 0x40 },
   { 0x1FD3, 0x0608, ASK_LOGO,    "ASK / LoGO",                  0x84, 0x04, 0x40 },
-  { 0x054C, 0x02E1, SONY_RCS360, "Sony / FeliCa S360 [PaSoRi]", 0x84, 0x04, 0x40 }
+  { 0x054C, 0x02E1, SONY_RCS360, "Sony / FeliCa S360 [PaSoRi]", 0x84, 0x04, 0x40 },
+  { 0x054C, 0x1FC9, SONY_PN531,  "Sony / NFC-PRO Reader",       0x84, 0x04, 0x40 }
 };

 // PN533 USB descriptors backup buffers
@@ -306,6 +307,9 @@ pn53x_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const s
       for (size_t n = 0; n < sizeof(pn53x_usb_supported_devices) / sizeof(struct pn53x_usb_supported_device); n++) {
         if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
             (pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
+
+          log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Found %04x:%04x", dev->descriptor.idVendor, dev->descriptor.idProduct);
+
           // Make sure there are 2 endpoints available
           // libusb-win32 may return a NULL dev->config,
           // or the descriptors may be corrupted, hence

with:

./configure --prefix=/usr --sysconfdir=/etc --with-drivers=pn53x_usb

and I get this error:

$ sudo nfc-list 
error   libnfc.driver.pn53x_usb Found 054c:1fc9
error   libnfc.driver.pn53x_usb Unable to set USB configuration (Device or resource busy)
No NFC device found.

Is there any guide to support new devices? I can test and provide feedback

I can even reverse engineering hid it if needed

albfan commented 1 year ago

Inside there's a

FM17550 chip documented here:

https://www.aliexpress.com/item/1005002458504365.html

1.1 Product introduction

FM17550 is a highly integrated non-contact communication chip that works at 13.56MHz and supports the following 4 different working modes.

Supports reader mode that complies with ISO/IEC 14443 TypeA protocol and Felica protocol

Support the reader mode conforming to ISO/IEC 14443 TypeB

Supports card simulation working mode that conforms to ISO/IEC 14443A protocol and Felica protocol

Support NFC working mode that complies with NFCIP-1 protocol

At the same time, it provides a low-power external card detection function, which is convenient for battery-powered, low-power operation, and requires real-time processing of external card reader devices that enter the radio frequency field at any time.

FM17550 has the characteristics of low voltage, low power consumption, strong drive capability, multi-interface support, and multi-protocol support. It is suitable for low-power, low-voltage, low-cost non-contact reader applications and NFC devices compatible with the NFC protocol.

1.2 Product features

Support ISO/IEC 14443 TypeA reader mode
Support ISO/IEC 14443 TypeB reader mode
Reader mode supports M1 encryption
Support ISO/IEC 14443, FeliCa card simulation working mode
ISO14443 TYPEA supports communication rate 106kbps, 212kbps, 424kbps, 848kbps
The communication rate based on FeliCa protocol supports 212kbps, 424kbps
The NFC communication rate that complies with the NFCIP-1 protocol is up to 424kbps
The operating distance of the reader can reach 50mm (depending on the antenna design)
Support NFC-WI interface
NFC-WI interface adopts independent power supply
Support multiple host interfaces
SPI interface up to 10Mbps
The I2C interface supports fast mode up to 400Kbps and high-speed mode up to 3.4Mbps
Serial UART interface, support RS232 frame format, maximum communication rate 1.2Mbps
Independent power supply for Host interface
64Byte transmit and receive buffer FIFO
The interrupt output mode is flexible and configurable
Built-in external field RF level detection
Automatic detection of internal integrated data mode (A/F automatic recognition during card simulation)
Multiple low power consumption modes
Soft powerdown mode
Hard powerdown mode
Deep powerdown mode (typical value 1uA)
Support low-power external card detection function
Programmable timer
Built-in oscillator circuit externally connected to 27.12MHz crystal
Wide voltage working range 2.2V~3.6V
The RF transmission driver is powered by an independent power supply, up to 5.5V
Built-in CRC coprocessor
Programmable I/O pins

Any started info to interact with it based on that?

albfan commented 1 year ago

More details:

$ lsusb -v -d 054c:

Bus 001 Device 065: ID 054c:1fc9 Sony Corp. NFC-PRO Reader
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x054c Sony Corp.
  idProduct          0x1fc9 
  bcdDevice            8.00
  iManufacturer           1 NXP INC.
  iProduct                2 NFC-PRO Reader
  iSerial                 3 56F1885E3132
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0040
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              300mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              2 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.10
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      27
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk-Only
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
neomilium commented 11 months ago

Great! Provide a PR with commits to support it and ask users that reply here and at https://github.com/nfcpy/nfcpy/issues/226 to help you to debug/test it.

albfan commented 10 months ago

Any tips to implement its features? Not sure where to start

dl3daz commented 10 months ago

FM17550 could be a clone of MFRC522. When I apply albfan's patch, I get the same error as he does. kern.log has a line "kernel: [96739.964705] usb 4-1: usbfs: interface 0 claimed by usbhid while 'nfc-list' sets config #1". After "rmmod usbhid" nfc-list says

error   libnfc.driver.pn53x_usb Unable to write to USB (No such file or directory)
nfc-list: ERROR: Unable to open NFC device: pn53x_usb:004:033

I am not familiar with USB...