Example #1
0
//*****************************************************************************
//
//! \internal
//!
//! Determines the number of individual descriptors of a particular type within
//! a supplied configuration descriptor.
//!
//! \param psConfig points to the header structure for the configuration
//! descriptor that is to be searched.
//! \param ulType identifies the type of descriptor that is to be counted.  If
//! the value is \b USB_DESC_ANY, the function returns the total number of
//! descriptors regardless of type.
//!
//! This function can be used to count the number of descriptors of a
//! particular type within a configuration descriptor.  The caller can provide
//! a specific type value which the function matches against the second byte
//! of each descriptor or, alternatively, can specify \b USB_DESC_ANY to have
//! the function count all descriptors regardless of their type.
//!
//! The search performed by this function traverses through the list of
//! sections comprising the configuration descriptor.  Note that the similar
//! top-level function, USBDescGetNum(), searches through a single, contiguous
//! block of data to perform the same enumeration.
//!
//! \return Returns the number of descriptors found in the supplied block of
//! data.
//
//*****************************************************************************
unsigned long
USBDCDConfigDescGetNum(const tConfigHeader *psConfig, unsigned long ulType)
{
    unsigned long ulSection;
    unsigned long ulNumDescs;

    //
    // Initialize our counts.
    //
    ulNumDescs = 0;

    //
    // Determine the number of descriptors of the given type in each of the
    // sections comprising the config descriptor.  Note that this assumes each
    // section contains only whole descriptors!
    //
    for(ulSection = 0; ulSection < (unsigned long)psConfig->ucNumSections;
        ulSection++)
    {
        ulNumDescs += USBDescGetNum(
                (tDescriptorHeader *)psConfig->psSections[ulSection]->pucData,
                psConfig->psSections[ulSection]->usSize,
                ulType);
    }

    return(ulNumDescs);
}
Example #2
0
//*****************************************************************************
//
//! \internal
//!
//! Determines the number of individual descriptors of a particular type within
//! a supplied configuration descriptor.
//!
//! \param psConfig points to the header structure for the configuration
//! descriptor that is to be searched.
//! \param ui32Type identifies the type of descriptor that is to be counted.
//! If the value is \b USB_DESC_ANY, the function returns the total number of
//! descriptors regardless of type.
//!
//! This function can be used to count the number of descriptors of a
//! particular type within a configuration descriptor.  The caller can provide
//! a specific type value which the function matches against the second byte
//! of each descriptor or, alternatively, can specify \b USB_DESC_ANY to have
//! the function count all descriptors regardless of their type.
//!
//! The search performed by this function traverses through the list of
//! sections comprising the configuration descriptor.  Note that the similar
//! top-level function, USBDescGetNum(), searches through a single, contiguous
//! block of data to perform the same enumeration.
//!
//! \return Returns the number of descriptors found in the supplied block of
//! data.
//
//*****************************************************************************
uint32_t
USBDCDConfigDescGetNum(const tConfigHeader *psConfig, uint32_t ui32Type)
{
    uint32_t ui32Section, ui32NumDescs;

    //
    // Initialize our counts.
    //
    ui32NumDescs = 0;

    //
    // Determine the number of descriptors of the given type in each of the
    // sections comprising the configuration descriptor.  Note that this
    // assumes each section contains only whole descriptors!
    //
    for(ui32Section = 0; ui32Section < (uint32_t)psConfig->ui8NumSections;
        ui32Section++)
    {
        ui32NumDescs += USBDescGetNum(
            (tDescriptorHeader *)psConfig->psSections[ui32Section]->pui8Data,
            psConfig->psSections[ui32Section]->ui16Size, ui32Type);
    }

    return(ui32NumDescs);
}
Example #3
0
//*****************************************************************************
//
//! \internal
//!
//! Finds the n-th descriptor of a particular type within the supplied
//! configuration descriptor.
//!
//! \param psConfig points to the header structure for the configuration
//! descriptor that is to be searched.
//! \param ulType identifies the type of descriptor that is to be found.  If
//! the value is \b USB_DESC_ANY, the function returns a pointer to the n-th
//! descriptor regardless of type.
//! \param ulIndex is the zero based index of the descriptor whose pointer is
//! to be returned.  For example, passing value 1 in \e ulIndex returns the
//! second matching descriptor.
//! \param pulSection points to storage which will receive the section index
//! containing the requested descriptor.
//!
//! Return a pointer to the n-th descriptor of a particular type found in the
//! configuration descriptor passed.
//!
//! The search performed by this function traverses through the list of
//! sections comprising the configuration descriptor.  Note that the similar
//! top-level function, USBDescGet(), searches through a single, contiguous
//! block of data to perform the same enumeration.
//!
//! \return Returns a pointer to the header of the required descriptor if
//! found or NULL otherwise.
//
//*****************************************************************************
tDescriptorHeader *
USBDCDConfigDescGet(const tConfigHeader *psConfig, unsigned long ulType,
                    unsigned long ulIndex, unsigned long *pulSection)
{
    unsigned long ulSection;
    unsigned long ulTotalDescs;
    unsigned long ulNumDescs;

    //
    // Initialize our counts.
    //
    ulTotalDescs = 0;

    //
    // Determine the number of descriptors of the given type in each of the
    // sections comprising the config descriptor.  This allows us to determine
    // which section contains the descriptor we are being asked for.
    //
    for(ulSection = 0; ulSection < (unsigned long)psConfig->ucNumSections;
        ulSection++)
    {
        //
        // How many descriptors of the requested type exist in this section?
        //
        ulNumDescs = USBDescGetNum(
                (tDescriptorHeader *)psConfig->psSections[ulSection]->pucData,
                psConfig->psSections[ulSection]->usSize,
                ulType);

        //
        // Does this section contain the descriptor whose index we are looking
        // for?
        //
        if((ulTotalDescs + ulNumDescs) > ulIndex)
        {
            //
            // We know the requested descriptor exists in the current
            // block so write the section number to the caller's storage.
            //
            *pulSection = ulSection;

            //
            // Now find the actual descriptor requested and return its pointer.
            //
            return(USBDescGet(
                 (tDescriptorHeader *)psConfig->psSections[ulSection]->pucData,
                 psConfig->psSections[ulSection]->usSize,
                 ulType,
                 ulIndex - ulTotalDescs));
        }

        //
        // We have not found the required descriptor yet.  Update our running
        // count of the number of type matches found so far then move on to
        // the next section.
        //
        ulTotalDescs += ulNumDescs;
    }

    //
    // If we drop out of the loop, we can't find the requested descriptor
    // so return NULL.
    //
    return((tDescriptorHeader *)0);
}