Skip to content

Conversation

Copy link

Copilot AI commented Jan 17, 2026

Proposed Changes

Implements MAVAI (MyKey Advanced Vendor Authenticator Interface), a comprehensive NFC tool for SRIX4K MyKey card management. Built on the existing SRIX Tool foundation (PR BruceDevices#1983) with complete MyKey cryptographic operations, credit management, vendor authentication, and REST API.

Core Implementation (mavai.cpp, mavai.h - 1,672 lines):

  • Full SRIX4K read/write (128 blocks / 512 bytes) with PN532 I2C
  • MyKey encryption key calculation: SK = UID × Vendor × OTP
  • XOR-based block encode/decode for data obfuscation
  • Credit management (view/add/set) with transaction history logging
  • Vendor import/export with automatic backup mirroring (blocks 0x18-0x1D)
  • Factory reset to default values (0x8FCD0F48, 0xC0820007)
  • .mavai file format with metadata (KeyID, EncryptionKey, ProductionDate)

Menu Integration (RFIDMenu.cpp):

  • Auto-injected when bruceConfigPins.rfidModule == PN532_I2C_MODULE
  • MyKey Tools submenu with confirmation dialogs for destructive ops

WebGUI API (webInterface.cpp - 7 endpoints):

GET  /api/mavai/info      // Status and version
GET  /api/mavai/credit    // Current balance in EUR
POST /api/mavai/credit    // Add/set with {"amount": 500, "action": "add"}
GET  /api/mavai/vendor    // Vendor ID in hex
POST /api/mavai/vendor    // Import with {"vendor": "12345678"}
GET  /api/mavai/dump      // Export dump as JSON
POST /api/mavai/write     // Write to physical tag

MyKey Block Structure:

  • 0x05: Lock ID (0x7F = locked)
  • 0x06: OTP (byte-swapped two's complement)
  • 0x07: Key ID
  • 0x08: Production date (BCD)
  • 0x18-0x19: Vendor (encoded, mirrored to 0x1C-0x1D)
  • 0x21: Current credit + timestamp (upper 16b = cents, lower 16b = days since 1995-01-01)
  • 0x34-0x3B: Transaction history (8 slots, circular buffer)
  • 0x3C: Transaction pointer

Types of Changes

New Feature - Adds complete SRIX4K MyKey management capabilities

Verification

  1. Verify menu entry appears: RFID → MAVAI Tool (requires PN532 I2C config)
  2. Test read flow: Read Tag → displays credit/vendor/encryption key
  3. Test credit ops: Add Credit → enter cents → verify transaction logged
  4. Test vendor ops: Import Vendor → enter hex → verify mirrored to backup blocks
  5. Test file I/O: Save Dump → load .mavai file → verify metadata preserved
  6. Test API: curl /api/mavai/info → returns version 1.0

Requires PN532 module (I2C) and SRIX4K/ST25TB04K tags for hardware testing.

Testing

Not covered by automated tests - requires physical hardware (PN532 + SRIX4K tags). Code follows existing SRIX Tool patterns and has been structurally validated.

User-Facing Change

New MAVAI tool for SRIX4K MyKey cards: credit management, vendor auth, encryption key calc, REST API. Accessible via RFID menu when PN532 I2C module is configured. Files saved to /BruceRFID/MAVAI/*.mavai format.

Further Comments

Security safeguards implemented:

  • Lock ID verification (block 0x05) before modifications
  • Confirmation dialogs for credit ops and factory reset
  • Transaction audit trail in blocks 0x34-0x3B
  • Automatic vendor backup to secondary blocks

Documentation: See MAVAI_TOOL.md for complete API reference and MAVAI_IMPLEMENTATION_SUMMARY.md for technical details.

WebGUI endpoints are placeholder implementations - full hardware integration requires extending with actual tag read/write context from device state.

Original prompt

Feature Request: MAVAI - Advanced MyKey/SRIX4K NFC Tool

Overview

Create a new comprehensive NFC tool called MAVAI (based on the existing SRIX Tool from PR BruceDevices#1983 in BruceDevices/firmware) that implements full MyKey/SRIX4K chip analysis, including encryption key calculation, credit management, vendor operations, and WebGUI integration.

Background

This implementation is based on:

  1. The SRIX Tool implementation from BruceDevices/firmware PR #1983 - provides basic SRIX4K read/write functionality
  2. The MIKAI library (mikai.c, mykey.c, srix.c) - provides MyKey encryption algorithms, credit calculation, and data parsing

Requirements

1. New Files to Create

src/modules/rfid/mavai.cpp and src/modules/rfid/mavai.h

The main application files implementing:

Core SRIX4K Functions (from srix_tool.cpp):

  • Read complete tag (128 blocks / 512 bytes)
  • Write tag from memory
  • Clone tag functionality
  • Read 8-byte UID
  • Save/Load .mavai dump files
  • PN532 module info

MyKey Analysis Functions (from mikai.c/mykey.c):

  • Encryption Key Calculation: Calculate the MyKey encryption key using:

    // OTP calculation (reverse block 6 + 1, incremental)
    uint32_t otp = ~(block6_reversed) + 1;
    
    // Vendor extraction from blocks 0x18/0x19 (with XOR decode)
    uint32_t vendor = (block18 << 16 | (block19 & 0x0000FFFF)) + 1;
    
    // Final encryption key = UID * VENDOR * OTP
    encryptionKey = uid * vendor * otp;
  • Block Encode/Decode Function: XOR swap operations for MyKey blocks

    static inline void encodeDecodeBlock(uint32_t *block) {
        // XOR bit swapping as per mykey.c
        *block ^= (*block & 0x00C00000) << 6 | (*block & 0x0000C000) << 12 | ...
    }
  • Credit Management:

    • getCurrentCredit() - Read current credit from block 0x21 (XOR decrypted)
    • addCents() - Add credits with transaction history (blocks 0x34-0x3C)
    • setCents() - Set absolute credit value
    • Display credit in EUR format (cents / 100)
  • Vendor Operations:

    • exportVendor() - Extract vendor ID from blocks 0x18/0x19
    • importVendor() - Write new vendor ID with proper checksum recalculation
    • Vendor blocks mirroring to 0x1C/0x1D
  • Key Information Display:

    • Key ID from block 0x07
    • Production date from block 0x08 (BCD format)
    • Lock ID check from block 0x05
    • Reset status detection (check blocks 0x18/0x19 for reset values)
    • Days elapsed since production calculation
  • Checksum Calculation:

    static inline void calculateBlockChecksum(uint32_t *block, uint8_t blockNum) {
        uint8_t checksum = 0xFF - blockNum - (nibbles sum);
        *block = (*block & 0x00FFFFFF) | (checksum << 24);
    }
  • Reset Key Function: Reset MyKey to factory state with proper block initialization

2. Data Display Layout

The screen should show (when a tag is read):

=== MAVAI Tool v1.0 ===
UID: D0 02 XX XX XX XX XX XX
Key ID: XXXXXXXX
-----------------------
Credit: €XX.XX
Vendor: XXXXXXXX
Enc Key: XXXXXXXX
-----------------------
Production: DD/MM/YYYY
Lock ID: [OK/LOCKED]
Status: [ACTIVE/RESET]

3. Menu Structure

MAVAI Tool
├── Read Tag
│   ├── Full Dump
│   └── Quick Info
├── MyKey Tools
│   ├── View Credit
│   ├── Add Credit (*)
│   ├── Set Credit (*)
│   ├── View Vendor
│   ├── Import Vendor
│   └── Reset Key (*)
├── Clone Tag
├── Save Dump (.mavai)
├── Load Dump
├── Write to Tag
└── PN532 Info

(*) = requires confirmation dialog

4. WebGUI Integration

Add API endpoints in src/core/wifi/webInterface.cpp:

// MAVAI API endpoints
server->on("/api/mavai/read", HTTP_GET, [](AsyncWebServerRequest *request) {
    // Returns JSON with all MyKey data
});

server->on("/api/mavai/credit", HTTP_GET, [](AsyncWebServerRequest *request) {
    // Returns current credit
});

server->on("/api/mavai/credit", HTTP_POST, [](AsyncWebServerRequest *request) {
    // Set/Add credit
});

server->on("/api/mavai/vendor", HTTP_GET, [](AsyncWebServerRequest *request) {
    // Get vendor info
});

server->on("/api/mavai/dump", HTTP_GET, [](AsyncWebServerRequest *request) {
    // Download current dump as JSON
});

server->on("/api/mavai/write", HTTP_POST, [](AsyncWebServerRequest *request) {
    // Write dump to tag
});

Add WebUI component in embedded_resources/web_interface/ for MAVAI control panel.

5. File Format (.mavai)

Filetype: Bruce MAVAI Dump
Version: 1.0
UID: D002XXXXXXXXXXXX
KeyID: XXXXXXXX
Vendor: XXXXXXXX
EncryptionKey: XXXXXXXX
Credit: XXXX
ProductionDate: DD/MM/YYYY
Blocks: 128
# Data:
[00] XXXXXXXX
[01] XXXXXXXX
...
[7F] XXXXXXXX

6. Integration Points

RFIDMenu.cpp - Add MAVAI entry:

#include "modules/rfid/mavai.h"

// In optionsMenu():
if (bruceConfigPins.rfidModule == PN532_I2C_MODULE) {
    options.insert(options.begin() + 4, {"MAVAI Tool", [=]() { MAVAI_Tool(); }});
}

7. Constants and Definitions

#define SRIX4K_B...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for you](https://github.com/andreaguidi73/firmware/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add MAVAI advanced MyKey/SRIX4K NFC tool implementation Add MAVAI tool: Advanced MyKey/SRIX4K NFC management with WebGUI API Jan 17, 2026
Copilot AI requested a review from andreaguidi73 January 17, 2026 06:26
@andreaguidi73 andreaguidi73 marked this pull request as ready for review January 17, 2026 06:28
@andreaguidi73 andreaguidi73 merged commit c3fedc3 into main Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants