samples/subsys/usb/webusb/src/webusb_serial.c
/**
 * @brief Handler called for Class requests not handled by the USB stack.
 *
 * @param pSetup    Information about the request to execute.
 * @param len       Size of the buffer.
 * @param data      Buffer containing the request result.
 *
 * @return  0 on success, negative errno code on fail.
 */
@brief Handler called for Class requests not handled by the USB stack.
@param pSetup    Information about the request to execute.
@param len       Size of the buffer.
@param data      Buffer containing the request result.

@return  0 on success, negative errno code on fail.
@brief Handler called for Class requests not handled by the USB stack . @param pSetup Information about the request to execute . @param len Size of the buffer . @param data Buffer containing the request result . @return 0 on success negative errno code on fail .
int webusb_serial_class_handle_req(struct usb_setup_packet *pSetup,
		s32_t *len, u8_t **data)
{
	struct webusb_serial_dev_data_t * const dev_data =
	    DEV_DATA(webusb_serial_dev);
	switch (pSetup->bRequest) {
	case CDC_SET_LINE_CODING:
		memcpy(&dev_data->line_coding,
		    *data, sizeof(dev_data->line_coding));
		SYS_LOG_DBG("\nCDC_SET_LINE_CODING %d %d %d %d",
		    sys_le32_to_cpu(dev_data->line_coding.dwDTERate),
		    dev_data->line_coding.bCharFormat,
		    dev_data->line_coding.bParityType,
		    dev_data->line_coding.bDataBits);
		break;
	case CDC_SET_CONTROL_LINE_STATE:
		dev_data->line_state = (u8_t)sys_le16_to_cpu(pSetup->wValue);
		SYS_LOG_DBG("CDC_SET_CONTROL_LINE_STATE 0x%x",
			    dev_data->line_state);
		break;
	case CDC_GET_LINE_CODING:
		*data = (u8_t *)(&dev_data->line_coding);
		*len = sizeof(dev_data->line_coding);
		SYS_LOG_DBG("\nCDC_GET_LINE_CODING %d %d %d %d",
		    sys_le32_to_cpu(dev_data->line_coding.dwDTERate),
		    dev_data->line_coding.bCharFormat,
		    dev_data->line_coding.bParityType,
		    dev_data->line_coding.bDataBits);
		break;
	default:
		SYS_LOG_DBG("WebUSB request 0x%x, value 0x%x",
		    pSetup->bRequest, pSetup->wValue);
		return -EINVAL;
	}
	return 0;
}
int webusb_serial_class_handle_req ( struct usb_setup_packet * pSetup , s32_t * len , u8_t * * data ) { struct webusb_serial_dev_data_t * const dev_data = DEV_DATA ( webusb_serial_dev ) ; switch ( pSetup -> bRequest ) { case CDC_SET_LINE_CODING : memcpy ( & dev_data -> line_coding , * data , sizeof ( dev_data -> line_coding ) ) ; SYS_LOG_DBG ( " \n " , sys_le32_to_cpu ( dev_data -> line_coding . dwDTERate ) , dev_data -> line_coding . bCharFormat , dev_data -> line_coding . bParityType , dev_data -> line_coding . bDataBits ) ; break ; case CDC_SET_CONTROL_LINE_STATE : dev_data -> line_state = ( u8_t ) sys_le16_to_cpu ( pSetup -> wValue ) ; SYS_LOG_DBG ( " " , dev_data -> line_state ) ; break ; case CDC_GET_LINE_CODING : * data = ( u8_t * ) ( & dev_data -> line_coding ) ; * len = sizeof ( dev_data -> line_coding ) ; SYS_LOG_DBG ( " \n " , sys_le32_to_cpu ( dev_data -> line_coding . dwDTERate ) , dev_data -> line_coding . bCharFormat , dev_data -> line_coding . bParityType , dev_data -> line_coding . bDataBits ) ; break ; default : SYS_LOG_DBG ( " " , pSetup -> bRequest , pSetup -> wValue ) ; return - EINVAL ; } return 0 ; }
@brief Handler called for Class requests not handled by the USB stack.
@brief Handler called for Class requests not handled by the USB stack .