# ESP32-P4-NANO Network Auditing Tool

A portable network auditing and diagnostic tool built on the ESP32-P4-NANO development board.

## Hardware Setup

### Pin Connections

#### Ethernet (IP101GRI PHY)
- MDC: GPIO 31
- MDIO: GPIO 52
- Reset: GPIO 51
- REF_CLK: GPIO 50
- TX_EN: GPIO 49
- TX0: GPIO 34
- TX1: GPIO 35
- RX0: GPIO 30
- RX1: GPIO 29
- CRS_DV: GPIO 28

#### Status LEDs
- Blue LED (Status): GPIO 8
- Red LED (Error): GPIO 15

#### SD Card (Default SPI Pins)
- MOSI: GPIO 11
- MISO: GPIO 13
- CLK: GPIO 12
- CS: GPIO 10

## Quick Start

1.  **Setup Environment:**
    *   Open a PowerShell terminal.
    *   Run the following command to set up the ESP-IDF environment:
        ```powershell
        . .\esp-idf\export.ps1
        ```

2.  **Insert SD Card:**
    *   Insert a formatted microSD card with the following structure:
        ```
        /sdcard
        ├── config/
        │   ├── network_config.json
        │   └── mac_vendors.csv
        ├── logs/
        ├── scripts/
        └── www/
            └── index.html
        ```

3.  **Build and Flash:**
    *   Build the project:
        ```bash
        idf.py build
        ```
    *   Flash the firmware:
        ```bash
        idf.py -p (PORT) flash
        ```
        Replace `(PORT)` with the serial port of your ESP32-P4-NANO board.

4.  **Connect to Target Network:**
    *   Connect the ESP32-P4-NANO to the target network via Ethernet.

5.  **Connect to Wi-Fi AP:**
    *   Connect to the Wi-Fi Access Point:
        *   **SSID:** audit-tool (configurable)
        *   **Password:** esp12345 (configurable)

6.  **Access Web Interface:**
    *   Open a web browser and navigate to:
        *   **URL:** http://192.168.4.1
        *   **Default login:** admin/admin123

## Configuration

All settings can be configured via `sdcard/config/network_config.json`:
- WiFi AP settings
- Static IP configuration
- Web server settings

## Features

- **Ethernet Network Scanning:**
  - ARP Scan
  - TCP Port Scan
  - ICMP Ping Sweep
- **Wi-Fi AP for Control Interface:**
  - Uses ESP-Hosted-FG solution with the onboard ESP32-C6.
- **Web Dashboard:**
  - Real-time status updates.
  - Control and monitor scans.
- **SD Card Logging:**
  - Logs scan results and system events.
- **OTA Updates:**
  - Update the firmware over the air.
- **Status LED Indicators:**
  - Visual feedback for system status.

## Memory Usage

Task stack sizes:
- Ethernet core: 8KB
- WiFi core: 8KB
- LED task: 2KB

## Troubleshooting

1.  **No Ethernet Connection:**
    *   Check the Ethernet cable.
    *   Verify the PHY pin connections in `include/network_manager.h`.
    *   Check the link LED on the Ethernet port.

2.  **No Wi-Fi AP:**
    *   Check the `sdcard/config/network_config.json` file.
    *   Verify the ESP-Hosted-FG component is correctly configured.

3.  **Web Server Issues:**
    *   Verify the SD card is inserted and has the correct file structure.
    *   Check the file permissions on the SD card.
    *   Confirm you are connected to the correct Wi-Fi AP and using the correct IP address.
