Commit Graph

7 Commits

Author SHA1 Message Date
Z. Cliffe Schreuders
7ecda9d39d feat(rfid): Implement multi-protocol RFID system with 4 protocols
Implement comprehensive multi-protocol RFID system with deterministic
card_id-based generation, MIFARE key attacks, and protocol-specific UI.

## New Protocol System (4 protocols):
- EM4100 (low security) - Instant clone, already implemented
- MIFARE_Classic_Weak_Defaults (low) - Dictionary attack succeeds (95%)
- MIFARE_Classic_Custom_Keys (medium) - Requires Darkside attack (30s)
- MIFARE_DESFire (high) - UID only, forces physical theft

## Key Features:

### 1. Protocol Foundation
- Created rfid-protocols.js with protocol definitions
- Added protocol detection, capabilities, security levels
- Defined attack durations and common MIFARE keys

### 2. Deterministic Card Generation
- Updated rfid-data.js with card_id-based generation
- Same card_id always produces same hex/UID (deterministic)
- Simplified scenario format - no manual hex/UID needed
- getCardDisplayData() supports all protocols

### 3. MIFARE Attack System
- Created rfid-attacks.js with MIFAREAttackManager
- Dictionary Attack: Instant, 95% success on weak defaults
- Darkside Attack: 30 sec (10s on weak), cracks all keys
- Nested Attack: 10 sec, uses known key to crack rest
- Protocol-aware attack behavior

### 4. UI Enhancements
- Updated rfid-ui.js with protocol-specific displays
- showProtocolInfo() with color-coded security badges
- showAttackProgress() and updateAttackProgress()
- Protocol headers with icons and frequency info
- Updated showCardDataScreen() and showEmulationScreen()

### 5. Unlock System Integration
- Updated unlock-system.js for card_id matching
- Support multiple valid cards per door (array)
- Added acceptsUIDOnly flag for DESFire UID emulation
- Backward compatible with legacy key_id format

### 6. Minigame Integration
- Updated rfid-minigame.js with attack methods
- startKeyAttack() triggers dictionary/darkside/nested
- handleCardTap() and handleEmulate() use card_id arrays
- UID-only emulation validation for DESFire
- Attack manager cleanup on minigame exit

### 7. Styling
- Added CSS for protocol headers and security badges
- Color-coded security levels (red=low, teal=medium, green=high)
- Attack progress styling with smooth transitions
- Dimmed menu items for unlikely attack options

## Scenario Format Changes:

Before (manual technical data):
```json
{
  "type": "keycard",
  "rfid_hex": "01AB34CD56",
  "rfid_facility": 1,
  "key_id": "employee_badge"
}
```

After (simplified with card_id):
```json
{
  "type": "keycard",
  "card_id": "employee_badge",
  "rfid_protocol": "MIFARE_Classic_Weak_Defaults",
  "name": "Employee Badge"
}
```

Technical data (hex/UID) generated automatically from card_id.

## Door Configuration:

Multiple valid cards per door:
```json
{
  "lockType": "rfid",
  "requires": ["employee_badge", "contractor_badge", "master_card"],
  "acceptsUIDOnly": false
}
```

## Files Modified:
- js/minigames/rfid/rfid-protocols.js (NEW)
- js/minigames/rfid/rfid-attacks.js (NEW)
- js/minigames/rfid/rfid-data.js
- js/minigames/rfid/rfid-ui.js
- js/minigames/rfid/rfid-minigame.js
- js/systems/unlock-system.js
- css/rfid-minigame.css
- planning_notes/rfid_keycard/protocols_and_interactions/03_UPDATES_SUMMARY.md (NEW)

## Next Steps:
- Phase 5: Ink integration (syncCardProtocolsToInk)
- Test with scenarios for each protocol
- Add Ink variable documentation

Estimated implementation time: ~12 hours (Phases 1-4 complete)
2025-11-15 23:48:15 +00:00
Z. Cliffe Schreuders
d697eef3ca docs(rfid): Add multi-protocol RFID system planning & review
Created comprehensive planning for adding multiple RFID protocols with
different security levels and attack capabilities.

Planning Documents:
- 00_IMPLEMENTATION_SUMMARY.md: Complete implementation guide (14h estimate)
- 01_TECHNICAL_DESIGN.md: Protocol specs, data models, UI design
- 02_IMPLEMENTATION_PLAN.md: Detailed file-by-file implementation plan
- CRITICAL_REVIEW.md: Pre-implementation review with 12 improvements

Protocol System (Simplified from Original):
 EM4100 (low security) - Instant clone, already implemented
 MIFARE Classic (medium) - Requires key attacks (Darkside/Nested/Dictionary)
 MIFARE DESFire (high) - UID only, forces physical theft
 HID Prox - Removed (too similar to EM4100, saves 2h)

Key Features:
- Protocol detection with color-coded security levels
- MIFARE key cracking minigames (30s Darkside, 10s Nested, instant Dictionary)
- Ink integration for conditional interactions based on card protocol
- Dual format support (no migration needed)
- UID-only emulation for DESFire with acceptsUIDOnly door property

Review Improvements Applied:
- Merged "attack mode" into clone mode (simpler state machine)
- Removed firmware upgrade system (can add later)
- Dual format card data support instead of migration (safer)
- Added error handling for unsupported protocols
- Added cleanup for background attacks
- Documented required Ink variables

Time Estimate: 14 hours (down from 19h)
- Phase 1: Protocol Foundation (3h)
- Phase 2: Protocol Detection & UI (3h)
- Phase 3: MIFARE Attack System (5h)
- Phase 4: Ink Integration (2h)
- Phase 5: Door Integration & Testing (1h)

Next Steps: Begin implementation starting with Phase 1
2025-11-15 23:48:15 +00:00
Z. Cliffe Schreuders
0210a12c64 docs(rfid): Add comprehensive post-implementation review
Added three review documents analyzing the completed RFID system:

- POST_IMPLEMENTATION_REVIEW.md: Full technical analysis of implementation
  - Reviewed 4 core files, 6 integration points, CSS, and test scenario
  - Found 0 critical issues, 2 medium priority improvements (optional)
  - Confirmed production-ready status
  - Verified correct conversation return pattern
  - Validated EM4100 protocol implementation

- ISSUES_SUMMARY.md: Quick reference for identified issues
  - 7 total issues (all minor/optional)
  - Action items with code examples
  - Testing checklist

- README.md: Review overview and quick status

Key findings:
 Clean modular architecture following established patterns
 Authentic Flipper Zero UI with smooth animations
 Robust error handling and validation
 Seamless integration with all game systems
 Comprehensive test scenario created

Recommended improvements (optional):
- Use hex ID for key_id to prevent collisions
- Add cardToClone validation in clone mode
- Extract timing constants for maintainability

Overall assessment: Production ready with minor improvements recommended
2025-11-15 23:48:15 +00:00
Z. Cliffe Schreuders
a52f8da171 docs(rfid): Second review - fix critical conversation pattern error
CRITICAL ISSUE: Planned return-to-conversation pattern was fundamentally incorrect.
Fixed to use proven window.pendingConversationReturn pattern from container minigame.

Key changes:
- NEW: review2/CRITICAL_FINDINGS.md - 8 findings with detailed analysis
- NEW: review2/README.md - Quick action guide
- FIXED: Task 3.4 - Simplified conversation return (2.5h → 1h)
- ADDED: Task 3.9 - returnToConversationAfterRFID function (0.5h)
- FIXED: Section 2c in architecture doc - Correct minimal context pattern
- Updated time estimates: 102h → 101h

npcConversationStateManager handles all conversation state automatically.
No manual Ink story save/restore needed.

Reference: /js/minigames/container/container-minigame.js:720-754

Risk: HIGH → MEDIUM (after fix)
Confidence: 95% → 98%
2025-11-15 23:48:15 +00:00
Z. Cliffe Schreuders
c5d5ebeff3 docs(rfid): Apply all implementation review improvements to planning docs
Applied all 7 critical fixes and 12 high-priority improvements from the
implementation review to create a complete, self-contained implementation plan.

## Critical Fixes Applied:

1. **CSS File Path Corrected**
   - Changed: css/minigames/rfid-minigame.css → css/rfid-minigame.css
   - Updated: All references in both TODO and architecture docs

2. **Interaction Handler Location Fixed**
   - Changed: inventory.js → interactions.js for keycard click handler
   - Reason: handleObjectInteraction() is defined in interactions.js

3. **Interaction Indicator Integration Added**
   - New Task 3.6: Update getInteractionSpriteKey() for RFID locks
   - Ensures RFID-locked doors show correct icon

4. **Complete 4-Step Registration Pattern**
   - Task 3.2: Added full Import → Export → Register → Window pattern
   - Matches pattern used by all other minigames

5. **Event Dispatcher Integration**
   - Added event emission for card_cloned, card_emulated, rfid_lock_accessed
   - Enables NPC reactions and telemetry tracking

6. **Return-to-Conversation Pattern** (Critical user correction)
   - Task 3.4: Completely rewritten to return to conversation after cloning
   - Added conversation context storage and restoration
   - Matches notes minigame behavior as intended

7. **Hex Validation Specifications**
   - Task 1.2: Added validateHex() method with complete rules
   - Validates length, format, and character set

## High-Priority Improvements:

8. **Card Name Generation**
   - Added CARD_NAME_TEMPLATES array with 8 descriptive names
   - Better UX than generic numbered cards

9. **Duplicate Card Handling**
   - Strategy: Overwrite with updated timestamp
   - MAX_SAVED_CARDS limit: 50 cards

10. **DEZ8 Formula Specified**
    - Proper EM4100 format: last 3 bytes (6 hex chars) to decimal
    - Pad to 8 digits with leading zeros

11. **Facility Code Formula**
    - Extract first byte (chars 0-1) as facility code (0-255)
    - Extract next 2 bytes (chars 2-5) as card number (0-65535)

12. **Checksum Calculation**
    - XOR of all bytes for EM4100 compliance
    - Returns checksum byte (0x00-0xFF)

13. **HTML CSS Link Task**
    - New Task 3.7: Add CSS link to index.html
    - Critical integration step that was missing

14. **Phaser Asset Loading Task**
    - New Task 3.8: Load all RFID sprites and icons
    - Critical integration step that was missing

## Files Updated:

### Review Documents:
- review/IMPLEMENTATION_REVIEW.md - Updated Improvement #1 with correct behavior
- review/CRITICAL_FIXES_SUMMARY.md - Added return-to-conversation pattern

### Planning Documents:
- 01_TECHNICAL_ARCHITECTURE.md - All fixes + formulas + patterns
- 02_IMPLEMENTATION_TODO.md - All task updates + 2 new tasks
- README.md - Updated time estimate (91h → 102h)
- PLANNING_COMPLETE.md - Updated time estimate + review notes

## Time Estimate Updates:

- Original: 91 hours (~11 days)
- Updated: 102 hours (~13 days)
- Increase: +11 hours (+12%)
  - Phase 1: +1h (validation/formulas)
  - Phase 3: +2h (new integration tasks)
  - Phase 6: +3h (additional testing)
  - Phase 8: +5h (comprehensive review)

## Impact:

 Planning documents now self-contained and complete
 All critical integration points specified
 All formulas mathematically correct for EM4100
 User-corrected behavior (return to conversation) implemented
 No references to review findings outside review/ directory
 Ready for implementation with high confidence

Confidence level: 95% → 98% (increased after review)
2025-11-15 23:48:15 +00:00
Z. Cliffe Schreuders
ed09fe7c50 docs: Add comprehensive implementation review for RFID keycard system
Review findings:
- 7 critical issues identified (must fix before implementation)
- 12 important improvements recommended
- Complete analysis of integration points
- Code examples for all fixes provided

Critical issues found:
- Incorrect CSS file path (css/minigames/ vs css/)
- Wrong modification target (inventory.js vs interactions.js)
- Missing interaction indicator integration
- Incomplete minigame registration pattern
- Missing event dispatcher integration
- No hex ID validation specified
- Unclear duplicate card handling

Review documents:
- IMPLEMENTATION_REVIEW.md: Full 35-page analysis
- CRITICAL_FIXES_SUMMARY.md: Quick fix checklist
- README.md: Review overview and navigation

Impact:
- Timeline: +2 hours for critical fixes, +6 hours for improvements
- Success probability: Significantly increased with fixes applied
- Overall assessment: 4/5 stars, excellent plan with fixable issues

All fixes are documented with code examples and can be applied in ~2 hours.
Ready for fix application before implementation begins.
2025-11-15 23:48:15 +00:00
Z. Cliffe Schreuders
bd8b9a4f85 docs: Add comprehensive RFID keycard lock system planning documentation
Planning documentation for new RFID keycard lock system feature:

Documentation:
- Complete planning docs in planning_notes/rfid_keycard/
- 7 planning documents (~16,000 words)
- 90+ implementation tasks with estimates
- Technical architecture and code design
- Asset specifications and creation guides

Assets Created:
- 4 keycard sprite variants (CEO, Security, Maintenance, Generic)
- RFID cloner device sprite (Flipper Zero-inspired)
- 2 icon assets (RFID icon, NFC waves)
- Helper scripts for placeholder creation

System Documentation:
- Lock & key system architecture reference
- Lock & key quick start guide

Feature Overview:
- New lock type: "rfid"
- New items: keycard, rfid_cloner
- New minigame: Flipper Zero-style RFID reader/cloner
- Ink tag support: # clone_keycard:name|hex
- Inventory integration: Click cards to clone
- Two modes: Unlock (tap/emulate) and Clone (read/save)

Implementation:
- Estimated time: 91 hours (~11 working days)
- 11 new files, 5 modified files
- Full test plan included
- Ready for immediate implementation

All placeholder assets functional for development.
Documentation provides complete roadmap from planning to deployment.
2025-11-15 23:48:15 +00:00