/* $Id$ */
/** @file
* VirtualBox USB filter abstraction.
*/
/*
* Copyright (C) 2007-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <VBox/usbfilter.h>
/** @todo split this up for the sake of device drivers and such. */
/**
* Initializes an USBFILTER structure.
*
* @param pFilter The filter to initialize.
* @param enmType The filter type. If not valid, the filter will not
* be properly initialized and all other calls will fail.
*/
{
}
/**
* Make a clone of the specified filter.
*
* @param pFilter The target filter.
* @param pToClone The source filter.
*/
{
}
/**
* Deletes (invalidates) an USBFILTER structure.
*
* @param pFilter The filter to delete.
*/
{
}
/**
* Skips blanks.
*
* @returns Next non-blank char in the string.
* @param psz The string.
*/
{
while (RT_C_IS_BLANK(*psz))
psz++;
return psz;
}
/**
* Worker for usbfilterReadNumber that parses a hexadecimal number.
*
* @returns Same as usbfilterReadNumber, except for VERR_NO_DIGITS.
* @param pszExpr Where to start converting, first char is a valid digit.
* @param ppszExpr See usbfilterReadNumber.
* @param pu16Val See usbfilterReadNumber.
*/
{
do
{
: *pszExpr - '0';
if (uDigit >= 16)
break;
u32 *= 16;
if (u32 > UINT16_MAX)
} while (*++pszExpr);
return VINF_SUCCESS;
}
/**
* Worker for usbfilterReadNumber that parses a decimal number.
*
* @returns Same as usbfilterReadNumber, except for VERR_NO_DIGITS.
* @param pszExpr Where to start converting, first char is a valid digit.
* @param uBase The base - 8 or 16.
* @param ppszExpr See usbfilterReadNumber.
* @param pu16Val See usbfilterReadNumber.
*/
static int usbfilterReadNumberDecimal(const char *pszExpr, unsigned uBase, const char **ppszExpr, uint16_t *pu16Val)
{
do
{
break;
if (u32 > UINT16_MAX)
} while (*++pszExpr);
return rc;
}
/**
* Reads a number from a numeric expression.
*
* @returns IPRT status code.
* @retval VINF_SUCCESS if all is fine. *ppszExpr and *pu16Val are updated.
* @retval VWRN_NUMBER_TOO_BIG if the number exceeds unsigned 16-bit, both *ppszExpr and *pu16Val are updated.
* @retval VERR_NO_DIGITS if there aren't any digits.
*
* @param ppszExpr Pointer to the current expression pointer.
* This is advanced past the expression and trailing blanks on success.
* @param pu16Val Where to store the value on success.
*/
{
if (!RT_C_IS_DIGIT(*pszExpr))
return VERR_NO_DIGITS;
if (*pszExpr == '0')
{
{
return VERR_NO_DIGITS;
}
/* Solitary 0! */
return VERR_NO_DIGITS;
}
}
/**
* Validates a numeric expression.
*
* @returns VBox status code.
* @retval VINF_SUCCESS if valid.
* @retval VERR_INVALID_PARAMETER if invalid.
* @retval VERR_NO_DIGITS if some expression is short of digits.
*
* @param pszExpr The numeric expression.
*/
{
/*
* An empty expression is fine.
*/
if (!*pszExpr)
return VINF_SUCCESS;
/*
* The string format is: "(<m>|([<m>]-[<n>]))|(<m>|([<m>]-[<n>]))+"
* where <m> and <n> are numbers in the decimal, hex (0xNNN) or octal (0NNN)
* form. Spaces are allowed around <m> and <n>.
*/
unsigned cSubExpressions = 0;
while (*pszExpr)
{
/*
* Skip remnants of the previous expression and any empty expressions.
* ('|' is the expression separator.)
*/
pszExpr++;
if (!*pszExpr)
break;
/*
* Parse the expression.
*/
int rc;
if (*pszExpr == '-')
{
/* -N */
pszExpr++;
}
else
{
/* M or M-N */
if (RT_SUCCESS(rc))
{
if (*pszExpr == '-')
{
/* M-N */
pszExpr++;
}
else
{
/* M */
}
}
}
if (RT_FAILURE(rc))
return rc;
/*
* We should either be at the end of the string or at
* an expression separator (|).
*/
return VERR_INVALID_PARAMETER;
}
}
/**
* Validates a string pattern.
*
* @returns VBox status code.
* @retval VINF_SUCCESS if valid.
* @retval VERR_INVALID_PARAMETER if invalid.
*
* @param psz The string pattern.
*/
{
/*
* This is only becomes important if we start doing
* sets ([0-9]) and such like.
*/
return VINF_SUCCESS;
}
/**
* Thoroughly validates the USB Filter.
*
* @returns Appropriate VBox status code.
* @param pFilter The filter to validate.
*/
{
return VERR_INVALID_POINTER;
return VERR_INVALID_MAGIC;
{
return VERR_INVALID_PARAMETER;
}
{
return VERR_INVALID_PARAMETER;
}
/*
* Validate the string table.
*/
{
return VERR_INVALID_PARAMETER;
}
{
if (!pszEnd)
{
Log(("USBFilter: %p - string at %#x isn't terminated!\n",
return VERR_INVALID_PARAMETER;
}
unsigned i;
break;
{
Log(("USBFilter: %p - string at %#x isn't used by anyone! (%s)\n",
return VERR_INVALID_PARAMETER;
}
}
{
Log(("USBFilter: %p - offCurEnd=%#x currently at %#x\n",
return VERR_INVALID_PARAMETER;
}
{
if (*psz)
{
Log(("USBFilter: %p - str tab isn't zero padded! %#x: %c\n",
return VERR_INVALID_PARAMETER;
}
psz++;
}
/*
* Validate the fields.
*/
int rc;
{
{
case USBFILTERMATCH_IGNORE:
case USBFILTERMATCH_PRESENT:
{
Log(("USBFilter: %p - #%d/%d u16Value=%d expected 0!\n",
return VERR_INVALID_PARAMETER;
}
break;
case USBFILTERMATCH_NUM_EXACT:
if (!USBFilterIsNumericField((USBFILTERIDX)i))
{
Log(("USBFilter: %p - #%d / %d - not numeric field\n",
return VERR_INVALID_PARAMETER;
}
break;
if (!USBFilterIsNumericField((USBFILTERIDX)i))
{
Log(("USBFilter: %p - #%d / %d - not numeric field\n",
return VERR_INVALID_PARAMETER;
}
{
Log(("USBFilter: %p - #%d / %d - off=%#x max=%#x\n",
return VERR_INVALID_PARAMETER;
}
if (RT_FAILURE(rc))
{
Log(("USBFilter: %p - #%d / %d - bad num expr: %s (rc=%Rrc)\n",
return rc;
}
break;
case USBFILTERMATCH_STR_EXACT:
if (!USBFilterIsStringField((USBFILTERIDX)i))
{
Log(("USBFilter: %p - #%d / %d - not string field\n",
return VERR_INVALID_PARAMETER;
}
{
Log(("USBFilter: %p - #%d / %d - off=%#x max=%#x\n",
return VERR_INVALID_PARAMETER;
}
break;
if (!USBFilterIsStringField((USBFILTERIDX)i))
{
Log(("USBFilter: %p - #%d / %d - not string field\n",
return VERR_INVALID_PARAMETER;
}
{
Log(("USBFilter: %p - #%d / %d - off=%#x max=%#x\n",
return VERR_INVALID_PARAMETER;
}
if (RT_FAILURE(rc))
{
Log(("USBFilter: %p - #%d / %d - bad string pattern: %s (rc=%Rrc)\n",
return rc;
}
break;
default:
return VERR_INVALID_PARAMETER;
}
}
return VINF_SUCCESS;
}
/**
* Find the specified field in the string table.
*
* @returns Pointer to the string in the string table on success.
* NULL if the field is invalid or it doesn't have a string value.
* @param pFilter The filter.
* @param enmFieldIdx The field index.
*/
{
if ((unsigned)enmFieldIdx < (unsigned)USBFILTERIDX_END)
{
{
case USBFILTERMATCH_STR_EXACT:
default:
case USBFILTERMATCH_IGNORE:
case USBFILTERMATCH_PRESENT:
case USBFILTERMATCH_NUM_EXACT:
break;
}
}
return NULL;
}
/**
* Gets a number value of a field.
*
* The field must contain a numeric value.
*
* @returns The field value on success, -1 on failure (invalid input / not numeric).
* @param pFilter The filter.
* @param enmFieldIdx The field index.
*/
{
if ((unsigned)enmFieldIdx < (unsigned)USBFILTERIDX_END)
{
{
case USBFILTERMATCH_NUM_EXACT:
default:
case USBFILTERMATCH_IGNORE:
case USBFILTERMATCH_PRESENT:
case USBFILTERMATCH_STR_EXACT:
break;
}
}
return -1;
}
/**
* Performs simple pattern matching.
*
* @returns true on match and false on mismatch.
* @param pszExpr The numeric expression.
* @param u16Value The value to match.
*/
{
/*
* The string format is: "(<m>|([<m>]-[<n>]))|(<m>|([<m>]-[<n>]))+"
* where <m> and <n> are numbers in the decimal, hex (0xNNN) or octal (0NNN)
* form. Spaces are allowed around <m> and <n>.
*/
while (*pszExpr)
{
/*
* Skip remnants of the previous expression and any empty expressions.
* ('|' is the expression separator.)
*/
pszExpr++;
if (!*pszExpr)
break;
/*
* Parse the expression.
*/
int rc;
if (*pszExpr == '-')
{
/* -N */
pszExpr++;
}
else
{
/* M or M-N */
if (RT_SUCCESS(rc))
{
if (*pszExpr == '-')
{
/* M-N */
pszExpr++;
}
else
{
/* M */
}
}
}
/* On success, we should either be at the end of the string or
at an expression separator (|). */
if (RT_SUCCESS(rc))
{
/*
* Swap the values if the order is mixed up.
*/
{
}
/*
* Perform the compare.
*/
return true;
}
else
{
/*
* Skip the bad expression.
* ('|' is the expression separator.)
*/
pszExpr++;
}
}
return false;
}
/**
* Performs simple pattern matching.
*
* @returns true on match and false on mismatch.
* @param pszPattern The pattern to match against.
* @param psz The string to match.
*/
{
char ch;
while ((ch = *pszPattern++))
{
if (ch == '?')
{
/*
* Matches one char or end of string.
*/
if (*psz)
psz++;
}
else if (ch == '*')
{
/*
* Matches zero or more characters.
*/
/* skip subsequent wildcards */
|| ch == '?')
pszPattern++;
if (!ch)
/* Pattern ends with a '*' and thus matches the rest of psz. */
return true;
/* Find the length of the following exact pattern sequence. */
&& ch != '*'
&& ch != '?')
cchMatch++;
/* Check if the exact pattern sequence is too long. */
if (cch < 0)
return false;
/* Is the rest an exact match? */
if (!ch)
/*
* This is where things normally starts to get recursive or ugly.
*
* Just to make life simple, we'll skip the nasty stuff and say
* that we will do a maximal wildcard match and forget about any
* alternative matches.
*
* If somebody is bored out of their mind one day, feel free to
* implement correct matching without using recursion.
*/
ch = *pszPattern;
while ( cch-- >= 0
&& *psz)
{
psz++;
}
if (!pszMatch)
return false;
/* advance */
pszPattern += cchMatch;
}
else
{
/* exact match */
return false;
psz++;
}
}
return *psz == '\0';
}
/**
* Match a filter against a device.
*
* @returns true if they match, false if not.
*
* @param pFilter The filter to match with.
* @param pDevice The device data. This is a filter (type ignored) that
* contains 'exact' values for all present fields and 'ignore'
* values for the non-present fields.
*
* @remark Both the filter and the device are ASSUMED to be valid because
* we don't wish to waste any time in this function.
*/
{
}
#if 0 /*def IN_RING0*/ /** @todo convert to proper logging. */
#else
# define dprintf(a) do {} while (0)
#endif
/**
* Match a filter against a device and rate the result.
*
* @returns -1 if no match, matching rate between 1 and 100 (inclusive) if matched.
*
* @param pFilter The filter to match with.
* @param pDevice The device data. This is a filter (type ignored) that
* contains 'exact' values for all present fields and 'ignore'
* values for the non-present fields.
*
* @remark Both the filter and the device are ASSUMED to be valid because
* we don't wish to waste any time in this function.
*/
{
unsigned iRate = 0;
{
{
case USBFILTERMATCH_IGNORE:
iRate += 2;
break;
case USBFILTERMATCH_PRESENT:
{
dprintf(("filter match[%d]: !present\n", i));
return -1;
}
iRate += 2;
break;
case USBFILTERMATCH_NUM_EXACT:
{
dprintf(("filter match[%d]: !num_exact device=ignore\n", i));
else
dprintf(("filter match[%d]: !num_exact %#x (filter) != %#x (device)\n", i, pFilter->aFields[i].u16Value, pDevice->aFields[i].u16Value));
return -1;
}
iRate += 2;
break;
{
dprintf(("filter match[%d]: !num_exact_np %#x (filter) != %#x (device)\n", i, pFilter->aFields[i].u16Value, pDevice->aFields[i].u16Value));
return -1;
}
iRate += 2;
break;
{
dprintf(("filter match[%d]: !num_expression\n", i));
return -1;
}
iRate += 1;
break;
{
dprintf(("filter match[%d]: !num_expression_no\n", i));
return -1;
}
iRate += 1;
break;
case USBFILTERMATCH_STR_EXACT:
{
dprintf(("filter match[%d]: !str_exact\n", i));
return -1;
}
iRate += 2;
break;
{
dprintf(("filter match[%d]: !str_exact_np\n", i));
return -1;
}
iRate += 2;
break;
{
dprintf(("filter match[%d]: !str_pattern\n", i));
return -1;
}
iRate += 1;
break;
{
dprintf(("filter match[%d]: !str_pattern_np\n", i));
return -1;
}
iRate += 1;
break;
default:
return -1;
}
}
/* iRate is the range 0..2*cFields - recalc to percent. */
? 100
}
/**
* Match a filter against a USBDEVICE.
*
* @returns true if they match, false if not.
*
* @param pFilter The filter to match with.
* @param pDevice The device to match.
*
* @remark Both the filter and the device are ASSUMED to be valid because
* we don't wish to waste any time in this function.
*/
{
{
{
case USBFILTERMATCH_IGNORE:
break;
case USBFILTERMATCH_PRESENT:
{
const char *psz;
switch (i)
{
default: psz = ""; break;
}
if (!psz)
return false;
break;
}
case USBFILTERMATCH_NUM_EXACT:
{
switch (i)
{
default: u16Value = ~0; break;
}
{
case USBFILTERMATCH_NUM_EXACT:
return false;
break;
return false;
break;
}
break;
}
case USBFILTERMATCH_STR_EXACT:
{
const char *psz;
switch (i)
{
}
{
case USBFILTERMATCH_STR_EXACT:
if ( !psz
return false;
break;
if ( psz
return false;
break;
if ( !psz
return false;
break;
if ( psz
return false;
break;
}
break;
}
default:
return false;
}
}
return true;
}
/**
* Checks if the two filters are identical.
*
* @returns true if the are identical, false if they aren't.
* @param pFilter The first filter.
* @param pFilter2 The second filter.
*/
{
/* Lazy works here because we're darn strict with zero padding and such elsewhere. */
}
/**
* Sets the filter type.
*
* @returns VBox status code.
* @retval VERR_INVALID_PARAMETER if the filter type is invalid.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmType The new filter type.
*/
{
AssertReturn(enmType > USBFILTERTYPE_INVALID && enmType < USBFILTERTYPE_END, VERR_INVALID_PARAMETER);
return VINF_SUCCESS;
}
/**
* Replaces the string value of a field.
*
* This will remove any existing string value current held by the field from the
* string table and then attempt to add the new value. This function can be used
* to delete any assigned string before changing the type to numeric by passing
* in an empty string. This works because the first byte in the string table is
* reserved for the empty (NULL) string.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_BUFFER_OVERFLOW if the string table is full.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx isn't valid.
* @retval VERR_INVALID_POINTER if pszString isn't valid.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index.
* @param pszString The string to add.
*/
{
/*
* Validate input.
*/
/*
* Remove old string value if any.
*/
{
if (cchToMove > 0)
{
/* We're not last - must shift the strings. */
}
/* zero the unused string table (to allow lazyness/strictness elsewhere). */
}
/*
* Make a special case for the empty string.
* (This also makes the delete logical above work correctly for the last string.)
*/
if (!*pszString)
else
{
return VERR_BUFFER_OVERFLOW;
}
return VINF_SUCCESS;
}
/**
* Wrapper around usbfilterSetString() that deletes any string value
* currently assigned to a field.
*
* Upon successful return the field contains a null string, nothing or a number.
*
* This function will validate the field index if there isn't any string
* value to delete, thus preventing any extra validating of the index.
*
* @returns VBox status code. See usbfilterSetString.
* @param pFilter The filter.
* @param enmFieldIdx The index of the field which string value should be deleted.
*/
{
else if ((unsigned)enmFieldIdx >= (unsigned)USBFILTERIDX_END)
return rc;
}
/**
* Sets a field to always match (ignore whatever is thrown at it).
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx isn't valid.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index. This must be a string field.
*/
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Sets a field to match on device field present only.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx isn't valid.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index. This must be a string field.
*/
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Sets a field to exactly match a number.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx isn't valid.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index. This must be a string field.
* @param u16Value The string pattern.
* @param fMustBePresent If set, a non-present field on the device will result in a mismatch.
* If clear, a non-present field on the device will match.
*/
USBLIB_DECL(int) USBFilterSetNumExact(PUSBFILTER pFilter, USBFILTERIDX enmFieldIdx, uint16_t u16Value, bool fMustBePresent)
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
pFilter->aFields[enmFieldIdx].enmMatch = fMustBePresent ? USBFILTERMATCH_NUM_EXACT : USBFILTERMATCH_NUM_EXACT_NP;
}
}
return rc;
}
/**
* Sets a field to match a numeric expression.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_BUFFER_OVERFLOW if the string table is full.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx or the numeric expression aren't valid.
* @retval VERR_INVALID_POINTER if pszExpression isn't a valid pointer.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index. This must be a string field.
* @param pszExpression The numeric expression.
* @param fMustBePresent If set, a non-present field on the device will result in a mismatch.
* If clear, a non-present field on the device will match.
*/
USBLIB_DECL(int) USBFilterSetNumExpression(PUSBFILTER pFilter, USBFILTERIDX enmFieldIdx, const char *pszExpression, bool fMustBePresent)
{
if (RT_SUCCESS(rc))
{
/* Strip leading spaces and empty sub expressions (||). */
if (RT_SUCCESS(rc))
{
/* We could optimize the expression further (stripping spaces, convert numbers),
but it's more work than what it's worth and it could upset some users. */
if (RT_SUCCESS(rc))
pFilter->aFields[enmFieldIdx].enmMatch = fMustBePresent ? USBFILTERMATCH_NUM_EXPRESSION : USBFILTERMATCH_NUM_EXPRESSION_NP;
else if (rc == VERR_NO_DIGITS)
}
}
return rc;
}
/**
* Sets a field to exactly match a string.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_BUFFER_OVERFLOW if the string table is full.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx isn't valid.
* @retval VERR_INVALID_POINTER if pszPattern isn't a valid pointer.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index. This must be a string field.
* @param pszValue The string value.
* @param fMustBePresent If set, a non-present field on the device will result in a mismatch.
* If clear, a non-present field on the device will match.
*/
USBLIB_DECL(int) USBFilterSetStringExact(PUSBFILTER pFilter, USBFILTERIDX enmFieldIdx, const char *pszValue, bool fMustBePresent)
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
pFilter->aFields[enmFieldIdx].enmMatch = fMustBePresent ? USBFILTERMATCH_STR_EXACT : USBFILTERMATCH_STR_EXACT_NP;
}
return rc;
}
/**
* Sets a field to match a string pattern.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_BUFFER_OVERFLOW if the string table is full.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx or pattern aren't valid.
* @retval VERR_INVALID_POINTER if pszPattern isn't a valid pointer.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index. This must be a string field.
* @param pszPattern The string pattern.
* @param fMustBePresent If set, a non-present field on the device will result in a mismatch.
* If clear, a non-present field on the device will match.
*/
USBLIB_DECL(int) USBFilterSetStringPattern(PUSBFILTER pFilter, USBFILTERIDX enmFieldIdx, const char *pszPattern, bool fMustBePresent)
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
pFilter->aFields[enmFieldIdx].enmMatch = fMustBePresent ? USBFILTERMATCH_STR_PATTERN : USBFILTERMATCH_STR_PATTERN_NP;
}
}
return rc;
}
/**
* Sets the must-be-present part of a field.
*
* This only works on field which already has matching criteria. This means
* that field marked 'ignore' will not be processed and will result in a
* warning status code.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VWRN_INVALID_PARAMETER if the field is marked 'ignore'. No assertions.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx or pattern aren't valid.
* @retval VERR_INVALID_POINTER if pszPattern isn't a valid pointer.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index.
* @param fMustBePresent If set, a non-present field on the device will result in a mismatch.
* If clear, a non-present field on the device will match.
*/
USBLIB_DECL(int) USBFilterSetMustBePresent(PUSBFILTER pFilter, USBFILTERIDX enmFieldIdx, bool fMustBePresent)
{
if (fMustBePresent)
{
switch (enmMatch)
{
case USBFILTERMATCH_IGNORE:
return VWRN_INVALID_PARAMETER;
case USBFILTERMATCH_PRESENT:
case USBFILTERMATCH_NUM_EXACT:
case USBFILTERMATCH_STR_EXACT:
break;
break;
break;
break;
break;
default:
AssertMsgFailedReturn(("%p: enmFieldIdx=%d enmMatch=%d\n", pFilter, enmFieldIdx, enmMatch), VERR_INVALID_MAGIC);
}
}
else
{
switch (enmMatch)
{
case USBFILTERMATCH_IGNORE:
return VWRN_INVALID_PARAMETER;
break;
case USBFILTERMATCH_PRESENT:
break;
case USBFILTERMATCH_NUM_EXACT:
break;
break;
case USBFILTERMATCH_STR_EXACT:
break;
break;
default:
AssertMsgFailedReturn(("%p: enmFieldIdx=%d enmMatch=%d\n", pFilter, enmFieldIdx, enmMatch), VERR_INVALID_MAGIC);
}
}
return VINF_SUCCESS;
}
/**
* Gets the filter type.
*
* @returns The filter type.
* USBFILTERTYPE_INVALID if the filter is invalid.
* @param pFilter The filter.
*/
{
}
/**
* Gets the matching method for a field.
*
* @returns The matching method on success, UBFILTERMATCH_INVALID on invalid field index.
* @param pFilter The filter.
* @param enmFieldIdx The field index.
*/
USBLIB_DECL(USBFILTERMATCH) USBFilterGetMatchingMethod(PCUSBFILTER pFilter, USBFILTERIDX enmFieldIdx)
{
&& (unsigned)enmFieldIdx < (unsigned)USBFILTERIDX_END)
return USBFILTERMATCH_INVALID;
}
/**
* Gets the numeric value of a field.
*
* The field must contain a number, we're not doing any conversions for you.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx isn't valid or if the field doesn't contain a number.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index.
* @param pu16Value Where to store the value.
*/
USBLIB_DECL(int) USBFilterQueryNum(PUSBFILTER pFilter, USBFILTERIDX enmFieldIdx, uint16_t *pu16Value)
{
if (iValue == -1)
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
}
/**
* Gets the numeric value of a field.
*
* The field must contain a number, we're not doing any conversions for you.
*
* @returns The field value on success, -1 on failure (invalid input / not numeric).
*
* @param pFilter The filter.
* @param enmFieldIdx The field index.
*/
{
}
/**
* Gets the string value of a field.
*
* The field must contain a string, we're not doing any conversions for you.
*
* @returns VBox status code.
* @retval VINF_SUCCESS on success.
* @retval VERR_BUFFER_OVERFLOW if the buffer isn't sufficient to hold the string. The buffer
* will be filled with as much of the string that'll fit.
* @retval VERR_INVALID_PARAMETER if the enmFieldIdx isn't valid or if the field doesn't contain a string.
* @retval VERR_INVALID_MAGIC if pFilter is invalid.
*
* @param pFilter The filter.
* @param enmFieldIdx The field index.
* @param pszBuf Where to store the string.
* @param cchBuf The size of the buffer.
*/
USBLIB_DECL(int) USBFilterQueryString(PUSBFILTER pFilter, USBFILTERIDX enmFieldIdx, char *pszBuf, size_t cchBuf)
{
if (RT_UNLIKELY(!psz))
return VERR_INVALID_PARAMETER;
else
{
if (cchBuf)
{
}
}
return rc;
}
/**
* Gets the string table entry for a field.
*
* @returns Pointer to the string. (readonly!)
*
* @param pFilter The filter.
* @param enmFieldIdx The field index.
*/
{
if (RT_UNLIKELY(!psz))
return NULL;
return psz;
}
/**
* Gets the string length of a field containing a string.
*
* @returns String length on success, -1 on failure (not a string, bad filter).
* @param pFilter The filter.
* @param enmFieldIdx The field index.
*/
{
{
}
return -1;
}
/**
* Check if any of the fields are set to something substatial.
*
* Consider the fileter a wildcard if this returns false.
*
* @returns true / false.
* @param pFilter The filter.
*/
{
{
{
case USBFILTERMATCH_IGNORE:
case USBFILTERMATCH_PRESENT:
break;
case USBFILTERMATCH_NUM_EXACT:
case USBFILTERMATCH_STR_EXACT:
return true;
{
if (psz)
{
psz++;
if (*psz)
return true;
}
break;
}
{
if (psz)
{
psz++;
if (*psz)
return true;
}
break;
}
}
}
return false;
}
/**
* Checks whether the specified field is a numeric field or not.
*
* @returns true / false.
* @param enmFieldIdx The field index.
*/
{
switch (enmFieldIdx)
{
case USBFILTERIDX_VENDOR_ID:
case USBFILTERIDX_PRODUCT_ID:
case USBFILTERIDX_DEVICE:
case USBFILTERIDX_BUS:
case USBFILTERIDX_PORT:
return true;
default:
case USBFILTERIDX_PRODUCT_STR:
return false;
}
}
/**
* Checks whether the specified field is a string field or not.
*
* @returns true / false.
* @param enmFieldIdx The field index.
*/
{
switch (enmFieldIdx)
{
default:
case USBFILTERIDX_VENDOR_ID:
case USBFILTERIDX_PRODUCT_ID:
case USBFILTERIDX_DEVICE:
case USBFILTERIDX_BUS:
case USBFILTERIDX_PORT:
return false;
case USBFILTERIDX_PRODUCT_STR:
return true;
}
}
/**
* Checks whether the specified matching method uses a numeric value or not.
*
* @returns true / false.
* @param enmMatchingMethod The matching method.
*/
{
switch (enmMatchingMethod)
{
default:
case USBFILTERMATCH_IGNORE:
case USBFILTERMATCH_PRESENT:
case USBFILTERMATCH_STR_EXACT:
return false;
case USBFILTERMATCH_NUM_EXACT:
return true;
}
}
/**
* Checks whether the specified matching method uses a string value or not.
*
* @returns true / false.
* @param enmMatchingMethod The matching method.
*/
{
switch (enmMatchingMethod)
{
default:
case USBFILTERMATCH_IGNORE:
case USBFILTERMATCH_PRESENT:
case USBFILTERMATCH_NUM_EXACT:
return false;
case USBFILTERMATCH_STR_EXACT:
return true;
}
}
/**
* Checks if a matching method is for string fields or not.
*
* @returns true / false.
* @param enmMatchingMethod The matching method.
*/
{
return enmMatchingMethod >= USBFILTERMATCH_NUM_FIRST
}
/**
* Checks if a matching method is for string fields or not.
*
* @returns true / false.
* @param enmMatchingMethod The matching method.
*/
{
return enmMatchingMethod >= USBFILTERMATCH_STR_FIRST
}