CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::core::UsbManager Class Reference

#include <UsbManager.h>

Inheritance diagram for cdc::core::UsbManager:
cdc::core::IService

Public Member Functions

const char * getName () const override
bool init () override
 Initializes USB manager service state.
bool start () override
 Starts USB manager service state.
void stop () override
 Stops USB manager service state.
ServiceState getState () const override
bool registerInterface (UsbHidInterface type, const char *moduleName, const UsbInterfaceSpec &def)
 Registers a HID interface request from a module.
void unregisterInterface (UsbHidInterface type, const char *moduleName)
 Unregisters a previously registered HID interface.
uint8_t activeInterfaceMask () const
bool applyConfiguration ()
 Applies current interface set to USB HID stack.
bool needsReplug () const
bool registerMassStorage (const char *owner)
 Registers the single USB Mass Storage LUN and re-enumerates.
void unregisterMassStorage (const char *owner)
 Unregisters the MSC LUN and re-enumerates (drive disappears).
bool massStorageActive () const
 Reports whether the MSC LUN is currently active.
bool hidSlotsFull () const
 Reports whether the HID interface budget is exhausted.
bool newlyRequiresReplug (bool wasNeededBefore) const
 Tests whether a toggle newly introduced a replug requirement.
Public Member Functions inherited from cdc::core::IService
virtual ~IService ()=default

Static Public Member Functions

static UsbManagerinstance ()
 Returns singleton USB manager instance.

Detailed Description

UsbManager - HID interface arbitration

CDC is always enabled (handled by usb_badge). HID interfaces are optional and registered by modules at runtime.

Definition at line 52 of file UsbManager.h.

Member Function Documentation

◆ activeInterfaceMask()

uint8_t cdc::core::UsbManager::activeInterfaceMask ( ) const
inline

Definition at line 67 of file UsbManager.h.

◆ applyConfiguration()

bool cdc::core::UsbManager::applyConfiguration ( )

Applies current interface set to USB HID stack.

Returns
true when configuration call succeeded.

Definition at line 159 of file UsbManager.cpp.

References cdc::core::Ccid, cdc::core::Fido, cdc::core::Keyboard, and usb_hid_apply_config().

Referenced by registerInterface(), and unregisterInterface().

◆ getName()

const char * cdc::core::UsbManager::getName ( ) const
inlineoverridevirtual

Get service name (for logging/debugging)

Implements cdc::core::IService.

Definition at line 56 of file UsbManager.h.

◆ getState()

ServiceState cdc::core::UsbManager::getState ( ) const
inlineoverridevirtual

Get current service state

Implements cdc::core::IService.

Definition at line 61 of file UsbManager.h.

◆ hidSlotsFull()

bool cdc::core::UsbManager::hidSlotsFull ( ) const
inline

Reports whether the HID interface budget is exhausted.

Returns
true when active HID interfaces reached MAX_ACTIVE_HID.

Definition at line 94 of file UsbManager.h.

◆ init()

bool cdc::core::UsbManager::init ( )
overridevirtual

Initializes USB manager service state.

Returns
Always true.

Implements cdc::core::IService.

Definition at line 23 of file UsbManager.cpp.

References cdc::core::INITIALIZED.

◆ instance()

◆ massStorageActive()

bool cdc::core::UsbManager::massStorageActive ( ) const
inline

Reports whether the MSC LUN is currently active.

Returns
true when the MSC interface is part of the descriptor.

Definition at line 88 of file UsbManager.h.

◆ needsReplug()

bool cdc::core::UsbManager::needsReplug ( ) const
inline

◆ newlyRequiresReplug()

bool cdc::core::UsbManager::newlyRequiresReplug ( bool wasNeededBefore) const
inline

Tests whether a toggle newly introduced a replug requirement.

Callers snapshot needsReplug() before performing a module toggle and pass it here afterwards; returns true only on a false-to-true transition.

Parameters
wasNeededBeforeneedsReplug() value captured before the toggle.
Returns
true if a replug is now required but was not before.

Definition at line 104 of file UsbManager.h.

◆ registerInterface()

bool cdc::core::UsbManager::registerInterface ( UsbHidInterface type,
const char * moduleName,
const UsbInterfaceSpec & def )

Registers a HID interface request from a module.

Parameters
typeHID interface slot.
moduleNameOwning module name.
defInterface descriptor definition.
Returns
true on successful registration.

Definition at line 96 of file UsbManager.cpp.

References applyConfiguration(), LOG_I, LOG_W, and TAG.

◆ registerMassStorage()

bool cdc::core::UsbManager::registerMassStorage ( const char * owner)

Registers the single USB Mass Storage LUN and re-enumerates.

Parameters
ownerOwning module name.
Returns
true on success; false if the USB endpoint budget is exhausted.
Parameters
ownerOwning module name.
Returns
true on success; false if the endpoint budget is exhausted.

Definition at line 187 of file UsbManager.cpp.

References LOG_I, LOG_W, TAG, and usb_hid_set_msc().

◆ start()

bool cdc::core::UsbManager::start ( )
overridevirtual

Starts USB manager service state.

Returns
Always true.

Implements cdc::core::IService.

Definition at line 32 of file UsbManager.cpp.

References cdc::core::STARTED.

◆ stop()

void cdc::core::UsbManager::stop ( )
overridevirtual

Stops USB manager service state.

Implements cdc::core::IService.

Definition at line 40 of file UsbManager.cpp.

References cdc::core::STOPPED.

◆ unregisterInterface()

void cdc::core::UsbManager::unregisterInterface ( UsbHidInterface type,
const char * moduleName )

Unregisters a previously registered HID interface.

Parameters
typeHID interface slot.
moduleNameRequesting module name.

Definition at line 135 of file UsbManager.cpp.

References applyConfiguration(), LOG_I, LOG_W, and TAG.

Referenced by cdc::mod_fido2::Fido2Module::start(), cdc::mod_fido2::Fido2Module::stop(), and cdc::mod_gpg::GpgModule::stop().

◆ unregisterMassStorage()

void cdc::core::UsbManager::unregisterMassStorage ( const char * owner)

Unregisters the MSC LUN and re-enumerates (drive disappears).

Unregisters the MSC LUN and re-enumerates.

Parameters
ownerOwning module name.

Definition at line 209 of file UsbManager.cpp.

References LOG_I, LOG_W, TAG, and usb_hid_set_msc().


The documentation for this class was generated from the following files: