Skip to main content

Python API to find FREE-WILi devices

Project description

FreeWili Finder

A cross-platform C/C++ library for discovering and interfacing with FreeWili devices connected to a host system.

Overview

The FreeWili Finder library provides both modern C++ and C APIs to:

  • Discover all connected FreeWili devices automatically
  • Enumerate USB devices associated with each FreeWili
  • Identify device types (Serial ports, Mass storage, FTDI/FPGA, etc.)
  • Access device information (VID/PID, serial numbers, port paths)

Supported Devices

Device DeviceType Detection
FREE-WILi (FW1) FreeWili Hub VID 0x0424 / PID 0x2513
FREE-WILi2 (FW2) FreeWili2 Hub VID 0x093C / PID 0x2059
DEFCON 2024 Badge DEFCON2024Badge Standalone
DEFCON 2025 Badge DEFCON2025FwBadge Standalone
Winky Winky Standalone
UF2 Bootloader UF2 Standalone

Features

  • Dual API Support: Modern C++23 API with std::expected error handling, plus C API for maximum compatibility
  • Language Bindings: Python (pyfwfinder) and Zig bindings
  • Cross-Platform: Supports Windows, macOS, and Linux
  • Type Safety: Strongly-typed USB device classification system
  • Error Handling: Comprehensive error reporting and handling
  • Memory Safe: RAII in C++, explicit memory management in C API
  • Testing: Full test suite with GoogleTest integration

Quick Start

C++ API Example

#include <fwfinder.hpp>
#include <iostream>

int main() {
    if (auto devices = Fw::find_all(); devices.has_value()) {
        for (const auto& device : devices.value()) {
            std::cout << "Found: " << device.name
                     << " (Serial: " << device.serial << ")\n";

            // Get serial ports
            auto serials = device.getUSBDevices(Fw::USBDeviceType::Serial);
            for (const auto& serial : serials) {
                std::cout << "  Port: " << serial.port.value_or("Unknown") << "\n";
            }
        }
    } else {
        std::cerr << "Error: " << devices.error() << "\n";
    }
    return 0;
}

C API Example

#include <cfwfinder.h>
#include <stdio.h>

int main(void) {
    fw_freewili_device_t* devices[16];
    uint32_t device_count = 16;
    char error_msg[256];
    uint32_t error_size = sizeof(error_msg);

    if (fw_device_find_all(devices, &device_count, error_msg, &error_size) == fw_error_success) {
        printf("Found %u device(s)\n", device_count);

        for (uint32_t i = 0; i < device_count; ++i) {
            char name[64];
            fw_device_get_str(devices[i], fw_stringtype_name, name, sizeof(name));
            printf("Device: %s\n", name);
        }

        fw_device_free(devices, device_count);
    }
    return 0;
}

Building

Prerequisites

  • CMake 3.20 or later
  • C++23 compatible compiler (GCC 11+, Clang 14+, MSVC 2022+)
  • Platform dependencies:
    • Linux: libudev-dev
    • macOS: Xcode command line tools
    • Windows: Windows SDK (SetupAPI, Cfgmgr32)

Build Instructions

# Clone the repository
git clone https://github.com/your-org/freewili-finder.git
cd freewili-finder

# Create build directory
mkdir build && cd build

# Configure
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build .

# Run tests
ctest --output-on-failure

CMake Options

  • FW_FINDER_BUILD_TESTS=ON/OFF - Build test suite (default: ON)
  • FW_BUILD_C_API=ON/OFF - Build C API library (default: ON)
  • FW_BUILD_STATIC=ON/OFF - Build static libraries (default: ON)
  • FW_BUILD_EXAMPLES=ON/OFF - Build example applications (default: ON)

Python Bindings (pyfwfinder)

Requires Python 3.8+ and uv (recommended) or pip.

# Install with uv (recommended)
uv sync

# Or install with pip
pip install .

Usage:

import pyfwfinder

devices = pyfwfinder.find_all()
for device in devices:
    print(f"{device.name} (Serial: {device.serial})")
    for usb in device.usb_devices:
        print(f"  {usb.kind}: {usb.name}")

API Reference

C++ API (fwfinder.hpp)

Core Functions

namespace Fw {
    // Find all connected FreeWili devices
    auto find_all() noexcept -> std::expected<FreeWiliDevices, std::string>;

    // USB device type detection
    auto getUSBDeviceTypeFrom(uint16_t vid, uint16_t pid) -> USBDeviceType;
    auto getUSBDeviceTypeName(USBDeviceType type) -> std::string;
}

Device Types

enum class DeviceType {
    Unknown,           // Unknown device
    FreeWili,          // FREE-WILi (FW1)
    DEFCON2024Badge,   // DEFCON 2024 Badge
    DEFCON2025FwBadge, // DEFCON 2025 Badge
    UF2,               // UF2 Bootloader mode
    Winky,             // Winky
    FreeWili2,         // FREE-WILi2 (FW2)
};

enum class USBDeviceType {
    Hub,              // USB Hub (parent device)
    Serial,           // Serial Port (general)
    SerialMain,       // MainCPU Serial Port
    SerialDisplay,    // DisplayCPU Serial Port
    MassStorage,      // Mass Storage Device
    ESP32,            // ESP32 USB (JTAG/RTT)
    FTDI,             // FTDI/FPGA Device
    Other             // Other USB device
};

C API (cfwfinder.h)

Core Functions

// Find all devices
fw_error_t fw_device_find_all(fw_freewili_device_t** devices, uint32_t* count,
                              char* error_msg, uint32_t* error_size);

// Device validation and info
bool fw_device_is_valid(fw_freewili_device_t* device);
fw_error_t fw_device_get_str(fw_freewili_device_t* device, fw_stringtype_t type,
                             char* buffer, uint32_t buffer_size);

// USB device enumeration
fw_error_t fw_usb_device_begin(fw_freewili_device_t* device);
fw_error_t fw_usb_device_count(fw_freewili_device_t* device, uint32_t* count);
fw_error_t fw_usb_device_next(fw_freewili_device_t* device);
fw_error_t fw_usb_device_get_str(fw_freewili_device_t* device, fw_stringtype_t type,
                                 char* buffer, uint32_t buffer_size);
fw_error_t fw_usb_device_get_int(fw_freewili_device_t* device, fw_inttype_t type,
                                 uint32_t* value);

// Memory management
fw_error_t fw_device_free(fw_freewili_device_t** devices, uint32_t count);

Examples

Complete example applications are provided in the examples/ directory:

  • basic_usage.cpp - Modern C++ API demonstration
  • c_api_basic_usage.cpp - C API demonstration (compiled as C++)
  • c_api_basic_usage_pure_c.c - Pure C implementation

Build and run examples:

cd build
make basic_usage_cpp basic_usage_c
./examples/basic_usage_cpp
./examples/basic_usage_c

Project Structure

freewili-finder/
├── include/
│   ├── fwfinder.hpp          # Main C++ API header
│   └── usbdef.hpp            # USB device definitions
├── src/
│   ├── fwfinder.cpp          # Core implementation
│   ├── fwfinder_linux.cpp    # Linux-specific code
│   ├── fwfinder_mac.cpp      # macOS-specific code
│   ├── fwfinder_windows.cpp  # Windows-specific code
│   └── usbdef.cpp            # USB device type mappings
├── c_api/
│   ├── include/cfwfinder.h   # C API header
│   ├── src/cfwfinder.cpp     # C API implementation
│   └── test/                 # C API tests
├── test/                     # C++ API tests
├── examples/                 # Example applications
├── bindings/
│   ├── python/               # Python bindings (pyfwfinder)
│   └── zig/                  # Zig bindings
└── pyproject.toml            # Python package configuration

Testing

The library includes comprehensive tests using GoogleTest:

cd build
ctest --output-on-failure

Tests cover:

  • Device discovery functionality
  • USB device type detection
  • C API functionality
  • Cross-platform compatibility
  • Error handling scenarios

Platform Support

Platform Status Requirements
Linux ✅ Supported libudev
macOS ✅ Supported IOKit framework
Windows ✅ Supported Windows SDK (SetupAPI, Cfgmgr32)

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please ensure all tests pass and add tests for new functionality.

License

Copyright Free-Wili

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyfwfinder-0.5.0-cp312-abi3-win_amd64.whl (151.6 kB view details)

Uploaded CPython 3.12+Windows x86-64

pyfwfinder-0.5.0-cp312-abi3-manylinux_2_34_x86_64.whl (248.7 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ x86-64

pyfwfinder-0.5.0-cp312-abi3-macosx_10_15_universal2.whl (182.1 kB view details)

Uploaded CPython 3.12+macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.5.0-cp311-cp311-win_amd64.whl (153.0 kB view details)

Uploaded CPython 3.11Windows x86-64

pyfwfinder-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl (253.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pyfwfinder-0.5.0-cp311-cp311-macosx_10_15_universal2.whl (188.9 kB view details)

Uploaded CPython 3.11macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.5.0-cp310-cp310-win_amd64.whl (152.6 kB view details)

Uploaded CPython 3.10Windows x86-64

pyfwfinder-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl (252.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyfwfinder-0.5.0-cp310-cp310-macosx_10_15_universal2.whl (187.9 kB view details)

Uploaded CPython 3.10macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.5.0-cp39-cp39-win_amd64.whl (153.1 kB view details)

Uploaded CPython 3.9Windows x86-64

pyfwfinder-0.5.0-cp39-cp39-manylinux_2_34_x86_64.whl (253.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pyfwfinder-0.5.0-cp39-cp39-macosx_10_15_universal2.whl (188.4 kB view details)

Uploaded CPython 3.9macOS 10.15+ universal2 (ARM64, x86-64)

pyfwfinder-0.5.0-cp38-cp38-win_amd64.whl (152.2 kB view details)

Uploaded CPython 3.8Windows x86-64

pyfwfinder-0.5.0-cp38-cp38-manylinux_2_34_x86_64.whl (251.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

pyfwfinder-0.5.0-cp38-cp38-macosx_10_15_universal2.whl (186.2 kB view details)

Uploaded CPython 3.8macOS 10.15+ universal2 (ARM64, x86-64)

File details

Details for the file pyfwfinder-0.5.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.5.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 151.6 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfwfinder-0.5.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7c96392022dd8e694dcd633c28f988dd83b06e920e23c1dda742cd4167472fc0
MD5 de660f9f25d5da134c600483b40861c4
BLAKE2b-256 a37c4eed0256923eacdd3cdbc92bc14142f83c4f579dfec396e2d966f2fd12cc

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp312-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e62f291d02b71687653d5163e59bd5dc404b09492c19db568dbd415329decf84
MD5 e6006e662854571d8ef5226db4c8ad58
BLAKE2b-256 7f51eff8c7c79dce484a8341cd812d2765843570e28af37851c3cc4ba6fd4d93

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp312-abi3-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp312-abi3-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 152b6fb9eb17ba7f234e093c3b90e31cf17b371b56bd95461129eedc32a8dba7
MD5 4071bd881ac461a2f110e75dc9bb7436
BLAKE2b-256 1b5f1a7f3be2ccb5d1c441922f9cb0163c3c2cd75b558a44bc6a1977ff7fce69

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.5.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 153.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfwfinder-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f81d5b5bfb1697a226a5f413b7402b7af2831f9039ae88171cad9d6bd9f4e170
MD5 116f066162e35d79567e8061154628ff
BLAKE2b-256 9b4ab1d2d1cf64010e12f9adb9f18f43405581e55d13e3bc2706a6492d87b423

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3282d10e97fc2e1ee7596c93f1f40f941c2d3ee0d5911154f69c61dd1a4a08d9
MD5 a65a1617f73f89286ed93d067247957f
BLAKE2b-256 73a5c4a1689d4ebd6b1b7da8feeff4b504a8fdf41b242a36f8d3dbd6ea019f9d

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp311-cp311-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 34c7f373760c9b58abe5ec704fcc8275c37ce866d11b9cb70e0d2b508cb51ed1
MD5 da3e367bef519a3fb893f26bdd0ad366
BLAKE2b-256 d604448270834a1fc9e9f3ca753fd5ac5c39dc0d83a0e86f70b49e638eed93ff

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 152.6 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfwfinder-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2cf791039ccfc85561b00354f2d33245f6082cd77ad5d6363543dc82cb4c5108
MD5 e663e0318c2373936c8c1dcd940a7da4
BLAKE2b-256 b4178b7c801962b7fc9074b3afdba8976c15c5df1d999355a1aac710663fa830

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e8a6a7e2e07f9181aa9a361b4af0ae26a3948c1c7eb592aac5ab237086d6c586
MD5 3f31211e41d72369de61ae792c7e61f1
BLAKE2b-256 a2e5c393270f8c1727ab1b7e0b104b4c57303911e52dd8aa08bfe3cd6eeca4ac

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp310-cp310-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 388848349b7513d9c819105bba4b89ba312774c670d12c7aeff906d7dc03e771
MD5 da3296246d4f27f22bc6e896aea4b62a
BLAKE2b-256 3b427a276fb95b747da840f233fb34dd017b726af15ea811bbede9af8bb0e1aa

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 153.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfwfinder-0.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 43931be9b2872b477963d8ce51997d1aa2f062f8aa20c6b104984e581709c3a4
MD5 92cb21dc55e0e203fb8d1a227f3af8f8
BLAKE2b-256 a4faabf5f975b2dc1ac0cdf463f351da4220f5cc0ab6c0492fbd614bffe43b46

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1e7438e2255ba37254fc070c33004db172bf6f51ced09ba1ef14e2cddbea511b
MD5 691f12c29af4e0fbcbd75fa233933a83
BLAKE2b-256 0eca83fd2c20ff7b0975828d2048c17156bb3c29cca4a80910918a66cd9f7796

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp39-cp39-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp39-cp39-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 cd8e9b2b697ec42653dd71ce18048dec27415ffb00125dc49f76eccfe4d75776
MD5 2196a9f5cd930637a89c97feef1c7e20
BLAKE2b-256 f607f5191ea1632dabd28e15ab7b9c18db24ab25735d319d6db375b67ae5be94

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: pyfwfinder-0.5.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 152.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyfwfinder-0.5.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0e27f7ffa7c81c9ae2807b17c7828ea812e9214615ee300d7f1a216d52b29b34
MD5 ba552c595b141b6907b52370fcaa1b0b
BLAKE2b-256 a1469246f2dcfa81fdad9b81c665b3b4e7c6f880736c7c745ba215f144074253

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e686189009a26d2c4693a9b2774553e073f42940787c114fd23a2763aabff156
MD5 fb120e4483b583e7b019f623a540a477
BLAKE2b-256 58a362ebcf8cbf5366a51118fa6e74d4e7b98ec15bfcd8db2c1cb5bcb3c2dbcc

See more details on using hashes here.

File details

Details for the file pyfwfinder-0.5.0-cp38-cp38-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for pyfwfinder-0.5.0-cp38-cp38-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 b1d6dc75318d2400b2532c1f052be4ec8692ab2e00329321d4e7bbc87e5af592
MD5 93dc24bbbe6bae3526331ea8843519d4
BLAKE2b-256 d99cd70c39c8e18c95c2cb56e08597fbcacf65a48495ded53a14e086dd266704

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page