USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
usbguard::USBInterfaceType Class Reference

Represents USB interface. More...

#include <USB.hpp>

Public Member Functions

 USBInterfaceType ()
 Constructs new interface by setting everything to zero.
 
 USBInterfaceType (uint8_t bClass, uint8_t bSubClass, uint8_t bProtocol, uint8_t mask=MatchAll)
 Constructs new interface with given class, subclass, protocol and mask. More...
 
 USBInterfaceType (const USBInterfaceDescriptor &descriptor, uint8_t mask=MatchAll)
 Constructs new interface from existing interface descriptor and sets mask. More...
 
 USBInterfaceType (const std::string &type_string)
 Constructs new interface from a string. More...
 
bool operator== (const USBInterfaceType &rhs) const
 Compares two interfaces for equality. More...
 
bool appliesTo (const USBInterfaceType &rhs) const
 Checks whether non-masked parts of interface match rhs interface. More...
 
const std::string typeString () const
 Returns string representation of interface. More...
 
const std::string toRuleString () const
 Returns string representation of interface. More...
 

Static Public Member Functions

static const std::string typeString (uint8_t bClass, uint8_t bSubClass, uint8_t bProtocol, uint8_t mask=MatchAll)
 Returns string representation of interface. More...
 

Static Public Attributes

static const uint8_t MatchClass = 1<<0
 
static const uint8_t MatchSubClass = 1<<1
 
static const uint8_t MatchProtocol = 1<<2
 
static const uint8_t MatchAll = MatchClass|MatchSubClass|MatchProtocol
 

Detailed Description

Represents USB interface.

Format: three 8b numbers separated by a colon, where first number represents interface class, second number represents interface subclass and third number represents interface protocol.
Example: ff:ff:ff

Constructor & Destructor Documentation

◆ USBInterfaceType() [1/3]

usbguard::USBInterfaceType::USBInterfaceType ( uint8_t  bClass,
uint8_t  bSubClass,
uint8_t  bProtocol,
uint8_t  mask = MatchAll 
)

Constructs new interface with given class, subclass, protocol and mask.

Mask by default masks everything.

Parameters
bClassInterface mask.
bSubClassInterface subclass.
bProtocolInterface protocol.
maskInterface mask.

◆ USBInterfaceType() [2/3]

usbguard::USBInterfaceType::USBInterfaceType ( const USBInterfaceDescriptor descriptor,
uint8_t  mask = MatchAll 
)

Constructs new interface from existing interface descriptor and sets mask.

Mask by default masks everything.

Parameters
descriptorInterface descriptor.
maskInterface mask.

◆ USBInterfaceType() [3/3]

usbguard::USBInterfaceType::USBInterfaceType ( const std::string &  type_string)

Constructs new interface from a string.

Exceptions
runtime_errorIf string is not in the correct interface format.

Member Function Documentation

◆ appliesTo()

bool usbguard::USBInterfaceType::appliesTo ( const USBInterfaceType rhs) const

Checks whether non-masked parts of interface match rhs interface.

Parameters
rhsInterface to compare with.
Returns
True if non-masked parts of interface match rhs interface, false otherwise.

◆ operator==()

bool usbguard::USBInterfaceType::operator== ( const USBInterfaceType rhs) const

Compares two interfaces for equality.

Interfaces are equal if they have the same class, subclass, protocol and mask.

Parameters
rhsInterface to compare with.
Returns
True if interfaces are equal, false otherwise.

◆ toRuleString()

const std::string usbguard::USBInterfaceType::toRuleString ( ) const

Returns string representation of interface.

Synonym for typeString().

Returns
String representation of interface.

◆ typeString() [1/2]

const std::string usbguard::USBInterfaceType::typeString ( ) const

Returns string representation of interface.

Internally calls static version of typeString().

Returns
String representation of interface.

◆ typeString() [2/2]

const std::string usbguard::USBInterfaceType::typeString ( uint8_t  bClass,
uint8_t  bSubClass,
uint8_t  bProtocol,
uint8_t  mask = MatchAll 
)
static

Returns string representation of interface.

Masked parts of interface are exchanged with *.
Example: 00:*:*

Parameters
bClassInterface class.
bSubClassInterface subclass.
bProtocolInterface protocol.
maskInterface mask, default value is to mask everything.
Returns
String representation of interface.

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