Skip to content

OptifyIndustrialSolutions/PN532-USB-Serial-Reader

Repository files navigation

PN532 USB Serial Reader

A web-based application for reading RFID/NFC cards using the PN532 reader module via USB serial connection.

Features

🔌 Connection Management

  • Auto-detect PN532 devices on available COM ports
  • Display firmware version information
  • Connect/disconnect functionality

🔍 Card Detection

  • Automatic card type identification
  • Support for multiple MIFARE card types:
    • MIFARE Classic 1K/4K
    • MIFARE Ultralight/NTAG
    • MIFARE DESFire
    • MIFARE Plus

📖 Card Reading

  • Read complete card content (blocks/pages)
  • Display data in HEX and ASCII formats
  • Sector-based view for MIFARE Classic cards
  • Page-based view for MIFARE Ultralight cards
  • Visual card data viewer with color-coded sections

✏️ Card Operations

  • Read Card: Read and display all accessible card data
  • Write Card: Write data to card (implementation in progress)
  • Format Card: Format card to default values (implementation in progress)
  • Scan Again: Scan for another card

Getting Started

Prerequisites

  • PN532 reader module connected via USB serial
  • Modern web browser with Web Serial API support (Chrome, Edge, Opera)
  • Python 3.x (for standalone scanning script)

Web Application Usage

  1. Open the Application

    • Open index.html in a compatible web browser
    • Or host it on a local web server
  2. Connect to PN532

    • Click "Connect to PN532"
    • Select your PN532 device from the serial port list
    • The device will initialize automatically
  3. Get Firmware Information (Optional)

    • Click "Get Firmware Version" to display reader information
  4. Read a Card

    • Present a card to the reader
    • Card will be detected automatically and displayed
    • Card type and UID will be shown
    • Click "Read Card" to view complete card content
    • Data will be displayed in a structured format with:
      • Sector/block numbers
      • HEX data representation
      • ASCII representation (printable characters only)
  5. Scan Another Card

    • Click "Scan Again" to clear current card and scan for a new one

Python Script Usage

The included Python script provides command-line card scanning:

# Auto-detect PN532 device
python pn532_scan.py

# Or specify COM port manually
python pn532_scan.py COM5

The script will:

  • Automatically find the PN532 device
  • Display firmware version
  • Scan for a card
  • Show card UID and type
  • Exit after successful read

Card Data Format

MIFARE Classic Cards

  • Organized into 16 sectors (1K) or 40 sectors (4K)
  • Each sector has 4 blocks
  • Each block contains 16 bytes
  • Last block of each sector is the sector trailer (contains keys)

MIFARE Ultralight Cards

  • Organized into pages
  • Each page contains 4 bytes
  • Standard cards have 16 pages (64 bytes total)

Security Notes

⚠️ Important Security Information:

  • The application uses default MIFARE keys (FF FF FF FF FF FF) for authentication
  • Many cards use default keys, but some may have custom keys configured
  • Blocks/sectors with custom keys will fail authentication and show "Authentication Failed"
  • Never store sensitive data on cards without proper key management

Browser Compatibility

This application requires the Web Serial API, which is supported in:

  • ✅ Google Chrome 89+
  • ✅ Microsoft Edge 89+
  • ✅ Opera 75+
  • ❌ Firefox (not supported)
  • ❌ Safari (not supported)

Project Structure

PN532_read_card/
├── index.html          # Main HTML interface
├── app.js              # Application logic and PN532 communication
├── style.css           # Styling
├── pn532_scan.py      # Python scanning script
└── README.md          # This file

Technical Details

PN532 Commands Used

  • GetFirmwareVersion (0x02): Retrieve reader firmware information
  • InListPassiveTarget (0x4A): Detect and identify cards
  • InDataExchange (0x40): Communicate with cards (read/write)
  • SAMConfiguration (0x14): Configure security access module

Supported Card Types Detection

Card types are identified using SAK (Select Acknowledge) values:

  • SAK & 0x08: MIFARE Classic
  • SAK & 0x20: MIFARE DESFire/SmartMX
  • SAK = 0x00: MIFARE Ultralight/NTAG
  • SAK = 0x20: MIFARE Plus

Troubleshooting

Connection Issues

  • Ensure PN532 is properly connected via USB
  • Check device drivers are installed
  • Try different USB ports
  • Verify baud rate is set to 115200

Card Reading Issues

  • Ensure card is close enough to the reader (within 1-2 cm)
  • Hold card steady during read operation
  • Some sectors may be password-protected (custom keys)
  • Try cleaning the reader antenna

Browser Issues

  • Use a supported browser (Chrome, Edge, Opera)
  • Allow serial port permissions when prompted
  • Check browser console (F12) for error messages

Future Enhancements

  • Custom authentication keys configuration
  • Card writing functionality
  • Card formatting functionality
  • Support for more card types (NTAG213/215/216, etc.)
  • Data export (JSON, CSV)
  • Card cloning capabilities
  • Multiple card management

License

MIT License - Feel free to use and modify as needed.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

Disclaimer

This tool is for educational and legitimate purposes only. Always ensure you have permission to read/write cards. Unauthorized access to RFID/NFC cards may be illegal in your jurisdiction.