subsys/usb/usb_device.c
/*
 * @brief get specified USB descriptor
 *
 * This function parses the list of installed USB descriptors and attempts
 * to find the specified USB descriptor.
 *
 * @param [in]  type_index Type and index of the descriptor
 * @param [in]  lang_id    Language ID of the descriptor (currently unused)
 * @param [out] len        Descriptor length
 * @param [out] data       Descriptor data
 *
 * @return true if the descriptor was found, false otherwise
 */
@brief get specified USB descriptor
This function parses the list of installed USB descriptors and attempts
to find the specified USB descriptor.

@param [in]  type_index Type and index of the descriptor
@param [in]  lang_id    Language ID of the descriptor (currently unused)
@param [out] len        Descriptor length
@param [out] data       Descriptor data

@return true if the descriptor was found, false otherwise
@brief get specified USB descriptor This function parses the list of installed USB descriptors and attempts to find the specified USB descriptor . @param [ in ] type_index Type and index of the descriptor @param [ in ] lang_id Language ID of the descriptor ( currently unused ) @param [ out ] len Descriptor length @param [ out ] data Descriptor data @return true if the descriptor was found false otherwise
static bool usb_get_descriptor(u16_t type_index, u16_t lang_id,
		s32_t *len, u8_t **data)
{
	u8_t type = 0;
	u8_t index = 0;
	u8_t *p = NULL;
	s32_t cur_index = 0;
	bool found = false;
	lang_id = lang_id;
	type = GET_DESC_TYPE(type_index);
	index = GET_DESC_INDEX(type_index);
	p = (u8_t *)usb_dev.descriptors;
	cur_index = 0;
	while (p[DESC_bLength] != 0) {
		if (p[DESC_bDescriptorType] == type) {
			if (cur_index == index) {
				found = true;
				break;
			}
			cur_index++;
		}
		p += p[DESC_bLength];
	}
	if (found) {
		*data = p;
		if (type == DESC_CONFIGURATION) {
			*len = (p[CONF_DESC_wTotalLength]) |
			    (p[CONF_DESC_wTotalLength + 1] << 8);
		} else {
			*len = p[DESC_bLength];
		}
	} else {
		SYS_LOG_DBG("Desc %x not found!\n", type_index);
	}
	return found;
}
static bool usb_get_descriptor ( u16_t type_index , u16_t lang_id , s32_t * len , u8_t * * data ) { u8_t type = 0 ; u8_t index = 0 ; u8_t * p = NULL ; s32_t cur_index = 0 ; bool found = false ; lang_id = lang_id ; type = GET_DESC_TYPE ( type_index ) ; index = GET_DESC_INDEX ( type_index ) ; p = ( u8_t * ) usb_dev . descriptors ; cur_index = 0 ; while ( p [ DESC_bLength ] != 0 ) { if ( p [ DESC_bDescriptorType ] == type ) { if ( cur_index == index ) { found = true ; break ; } cur_index ++ ; } p += p [ DESC_bLength ] ; } if ( found ) { * data = p ; if ( type == DESC_CONFIGURATION ) { * len = ( p [ CONF_DESC_wTotalLength ] ) | ( p [ CONF_DESC_wTotalLength + 1 ] << 8 ) ; } else { * len = p [ DESC_bLength ] ; } } else { SYS_LOG_DBG ( " \n " , type_index ) ; } return found ; }
@brief get specified USB descriptor
 This function parses the list of installed USB descriptors and attempts
 to find the specified USB descriptor.
@brief get specified USB descriptor This function parses the list of installed USB descriptors and attempts to find the specified USB descriptor .
/*Avoid compiler warning until this is used for something*/ /* skip to next descriptor */ /* set data pointer */ /* get length from structure */ /* configuration descriptor is an
			 * exception, length is at offset
			 * 2 and 3
			 */ /* normally length is at offset 0 */ /* nothing found */