XilinxProcessorIPLib/drivers/usbps/examples/xusbps_ch9_audio.c
u32 XUsbPs_Ch9SetupStrDescReply(u8 *BufPtr, u32 BufLen, u8 Index)
{
	s32 i;
	char *String;
	u32 StringLen;
	u32 DescLen;
	u8 TmpBuf[128];
	u8 StrArray;

	USB_STD_STRING_DESC *StringDesc;

	if (!BufPtr) {
		return 0;
	}

	if (Index >= sizeof(StringList) / sizeof(u8 *)) {
		return 0;
	}

	/* USB 2.0 */
	StrArray = 0;

	String = (char *)&StringList[StrArray][Index];

	StringLen = strlen(String);

	StringDesc = (USB_STD_STRING_DESC *) TmpBuf;

	/* Index 0 is special as we can not represent the string required in
	 * the table above. Therefore we handle index 0 as a special case.
	 */
	if (0 == Index) {
		StringDesc->bLength = 4;
		StringDesc->bDescriptorType = 0x03;
		StringDesc->wLANGID[0] = 0x0409;
	}
	/* All other strings can be pulled from the table above. */
	else {
		StringDesc->bLength = StringLen * 2 + 2;
		StringDesc->bDescriptorType = 0x03;

		for (i = 0; i < StringLen; i++) {
			StringDesc->wLANGID[i] = (u16) String[i];
		}
	}
	DescLen = StringDesc->bLength;

	/* Check if the provided buffer is big enough to hold the descriptor. */
	if (DescLen > BufLen) {
		return 0;
	}

	memcpy(BufPtr, StringDesc, DescLen);

	return DescLen;
}
/*****************************************************************************/
/**
 *
 * This function returns a string descriptor for the given index.
 *
 * @param	InstancePtr is a pointer to the Usb_DevData instance.
 * @param	BufPtr is a  pointer to the buffer that is to be filled with
 *			the descriptor.
 * @param	BufLen is the size of the provided buffer.
 * @param	Index is the index of the string for which the descriptor
 *			is requested.
 *
 * @return 	Length of the descriptor in the buffer on success.
 *			0 on error.
 *
 ******************************************************************************/
This function returns a string descriptor for the given index.
@param       InstancePtr is a pointer to the Usb_DevData instance.
@param       BufPtr is a  pointer to the buffer that is to be filled with
the descriptor.
@param       BufLen is the size of the provided buffer.
@param       Index is the index of the string for which the descriptor
is requested.

@return      Length of the descriptor in the buffer on success.
0 on error.
This function returns a string descriptor for the given index . @param InstancePtr is a pointer to the Usb_DevData instance . @param BufPtr is a pointer to the buffer that is to be filled with the descriptor . @param BufLen is the size of the provided buffer . @param Index is the index of the string for which the descriptor is requested . @return Length of the descriptor in the buffer on success . 0 on error .
u32 XUsbPs_Ch9SetupStrDescReply(u8 *BufPtr, u32 BufLen, u8 Index)
{
	s32 i;
	char *String;
	u32 StringLen;
	u32 DescLen;
	u8 TmpBuf[128];
	u8 StrArray;
	USB_STD_STRING_DESC *StringDesc;
	if (!BufPtr) {
		return 0;
	}
	if (Index >= sizeof(StringList) / sizeof(u8 *)) {
		return 0;
	}
	StrArray = 0;
	String = (char *)&StringList[StrArray][Index];
	StringLen = strlen(String);
	StringDesc = (USB_STD_STRING_DESC *) TmpBuf;
	if (0 == Index) {
		StringDesc->bLength = 4;
		StringDesc->bDescriptorType = 0x03;
		StringDesc->wLANGID[0] = 0x0409;
	}
	else {
		StringDesc->bLength = StringLen * 2 + 2;
		StringDesc->bDescriptorType = 0x03;
		for (i = 0; i < StringLen; i++) {
			StringDesc->wLANGID[i] = (u16) String[i];
		}
	}
	DescLen = StringDesc->bLength;
	if (DescLen > BufLen) {
		return 0;
	}
	memcpy(BufPtr, StringDesc, DescLen);
	return DescLen;
}
u32 XUsbPs_Ch9SetupStrDescReply ( u8 * BufPtr , u32 BufLen , u8 Index ) { s32 i ; char * String ; u32 StringLen ; u32 DescLen ; u8 TmpBuf [ 128 ] ; u8 StrArray ; USB_STD_STRING_DESC * StringDesc ; if ( ! BufPtr ) { return 0 ; } if ( Index >= sizeof ( StringList ) / sizeof ( u8 * ) ) { return 0 ; } StrArray = 0 ; String = ( char * ) & StringList [ StrArray ] [ Index ] ; StringLen = strlen ( String ) ; StringDesc = ( USB_STD_STRING_DESC * ) TmpBuf ; if ( 0 == Index ) { StringDesc -> bLength = 4 ; StringDesc -> bDescriptorType = 0x03 ; StringDesc -> wLANGID [ 0 ] = 0x0409 ; } else { StringDesc -> bLength = StringLen * 2 + 2 ; StringDesc -> bDescriptorType = 0x03 ; for ( i = 0 ; i < StringLen ; i ++ ) { StringDesc -> wLANGID [ i ] = ( u16 ) String [ i ] ; } } DescLen = StringDesc -> bLength ; if ( DescLen > BufLen ) { return 0 ; } memcpy ( BufPtr , StringDesc , DescLen ) ; return DescLen ; }
This function returns a string descriptor for the given index.
This function returns a string descriptor for the given index .
/* USB 2.0 */ /* Index 0 is special as we can not represent the string required in
	 * the table above. Therefore we handle index 0 as a special case.
	 */ /* All other strings can be pulled from the table above. */ /* Check if the provided buffer is big enough to hold the descriptor. */