XilinxProcessorIPLib/drivers/usbpsu/examples/xusb_ch9_composite.c
u32 Usb_Ch9SetupStrDescReply(struct Usb_DevData *InstancePtr, u8 *BufPtr,
		u32 BufLen, u8 Index)
{
	u32 i;
	char *String;
	u32 StringLen;
	u32 DescLen;
	u8 TmpBuf[128];
	s32 Status;
	u8 StrArray;
	USBCH9_DATA *ch9_ptr =
		(USBCH9_DATA *)Get_DrvData(InstancePtr->PrivateData);
	struct dfu_if *DFU = &((struct composite_dev *)(ch9_ptr->data_ptr))->f_dfu;

	USB_STD_STRING_DESC *StringDesc;

	Status = IsSuperSpeed(InstancePtr);
	if (Status != XST_SUCCESS) {
		/* USB 2.0 */
		StrArray = 0;
	} else {
		/* USB 3.0 */
		StrArray = 1;
	}

	if (!BufPtr)
		return 0;

	if (DFU->is_dfu == 1) {
		String = (char *)&DFUStringList[StrArray][Index];
		if (Index >= sizeof(DFUStringList) / sizeof(u8 *))
			return 0;
	} else {
		String = (char *)&StringList[StrArray][Index];
		if (Index >= sizeof(StringList) / sizeof(u8 *))
			return 0;
	}

	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.
This function returns a string descriptor for the given index .
u32 Usb_Ch9SetupStrDescReply(struct Usb_DevData *InstancePtr, u8 *BufPtr,
		u32 BufLen, u8 Index)
{
	u32 i;
	char *String;
	u32 StringLen;
	u32 DescLen;
	u8 TmpBuf[128];
	s32 Status;
	u8 StrArray;
	USBCH9_DATA *ch9_ptr =
		(USBCH9_DATA *)Get_DrvData(InstancePtr->PrivateData);
	struct dfu_if *DFU = &((struct composite_dev *)(ch9_ptr->data_ptr))->f_dfu;
	USB_STD_STRING_DESC *StringDesc;
	Status = IsSuperSpeed(InstancePtr);
	if (Status != XST_SUCCESS) {
		StrArray = 0;
	} else {
		StrArray = 1;
	}
	if (!BufPtr)
		return 0;
	if (DFU->is_dfu == 1) {
		String = (char *)&DFUStringList[StrArray][Index];
		if (Index >= sizeof(DFUStringList) / sizeof(u8 *))
			return 0;
	} else {
		String = (char *)&StringList[StrArray][Index];
		if (Index >= sizeof(StringList) / sizeof(u8 *))
			return 0;
	}
	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 Usb_Ch9SetupStrDescReply ( struct Usb_DevData * InstancePtr , u8 * BufPtr , u32 BufLen , u8 Index ) { u32 i ; char * String ; u32 StringLen ; u32 DescLen ; u8 TmpBuf [ 128 ] ; s32 Status ; u8 StrArray ; USBCH9_DATA * ch9_ptr = ( USBCH9_DATA * ) Get_DrvData ( InstancePtr -> PrivateData ) ; struct dfu_if * DFU = & ( ( struct composite_dev * ) ( ch9_ptr -> data_ptr ) ) -> f_dfu ; USB_STD_STRING_DESC * StringDesc ; Status = IsSuperSpeed ( InstancePtr ) ; if ( Status != XST_SUCCESS ) { StrArray = 0 ; } else { StrArray = 1 ; } if ( ! BufPtr ) return 0 ; if ( DFU -> is_dfu == 1 ) { String = ( char * ) & DFUStringList [ StrArray ] [ Index ] ; if ( Index >= sizeof ( DFUStringList ) / sizeof ( u8 * ) ) return 0 ; } else { String = ( char * ) & StringList [ StrArray ] [ Index ] ; if ( Index >= sizeof ( StringList ) / sizeof ( u8 * ) ) return 0 ; } 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 */ /* USB 3.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. */