static USB_STATUS usb_class_hid_cntrl_common ( /* [IN] The communication device common command structure */ HID_COMMAND_PTR com_ptr, /* [IN] Bitmask of the request type */ uint_8 bmrequesttype, /* [IN] Request code */ uint_8 brequest, /* [IN] Value to copy into WVALUE field of the REQUEST */ uint_16 wvalue, /* [IN] Length of the data associated with REQUEST */ uint_16 wlength, /* [IN] Pointer to data buffer used to send/recv */ uchar_ptr data ) { /* Body */ USB_HID_CLASS_INTF_STRUCT_PTR if_ptr; USB_SETUP req; USB_STATUS status = USBERR_NO_INTERFACE; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_hid_cntrl_common"); #endif USB_lock(); /* Validity checking */ if (usb_host_class_intf_validate(com_ptr->CLASS_PTR)) { if_ptr = (USB_HID_CLASS_INTF_STRUCT_PTR)com_ptr->CLASS_PTR->class_intf_handle; status = usb_hostdev_validate(if_ptr->G.dev_handle); } /* Endif */ if (!status && if_ptr->IN_SETUP) { status = USBERR_TRANSFER_IN_PROGRESS; } /* Endif */ if (!status) { /* Save the higher level callback and ID */ if_ptr->USER_CALLBACK = com_ptr->CALLBACK_FN; if_ptr->USER_PARAM = com_ptr->CALLBACK_PARAM; /* Setup the request */ req.BMREQUESTTYPE = bmrequesttype; req.BREQUEST = brequest; *(uint_16*)req.WVALUE = HOST_TO_LE_SHORT(wvalue); *(uint_16*)req.WINDEX = HOST_TO_LE_SHORT(((INTERFACE_DESCRIPTOR_PTR)if_ptr->G.intf_handle)->bInterfaceNumber); *(uint_16*)req.WLENGTH = HOST_TO_LE_SHORT(wlength); status = _usb_hostdev_cntrl_request(if_ptr->G.dev_handle, &req, data, usb_class_hid_cntrl_callback, if_ptr); if (status == USB_STATUS_TRANSFER_QUEUED) { if_ptr->IN_SETUP = TRUE; } /* Endif */ } /* Endif */ USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_hid_cntrl_common, SUCCESSFUL"); #endif return status; } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_clear_feature * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_clear_feature ( /* usb device */ _usb_device_instance_handle dev_handle, /* request type device/interface/endpoint */ uint_8 req_type, /* device = 0, or interface/endpoint */ uint_8 intf_endpt, /* feature selection */ uint_16 feature ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature"); #endif USB_lock(); switch (req_type) { case REQ_TYPE_DEVICE: break; case REQ_TYPE_INTERFACE: case REQ_TYPE_ENDPOINT: *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(intf_endpt); break; default: USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature, invalid request"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE); } /* EndSwitch */ request.BMREQUESTTYPE = (uchar)(req_type | REQ_TYPE_OUT); request.BREQUEST = REQ_CLEAR_FEATURE; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(feature); error = usb_host_ch9_dev_req(dev_handle, &request, NULL); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_set_configuration * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_set_configuration ( /* usb device */ _usb_device_instance_handle dev_handle, /* configuration value */ uint_16 config ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_configuration"); #endif USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_OUT; request.BREQUEST = REQ_SET_CONFIGURATION; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(config); error = usb_host_ch9_dev_req(dev_handle, &request, NULL); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_configuration SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_set_address * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_set_address ( /* usb device */ _usb_device_instance_handle dev_handle ) { /* Body */ DEV_INSTANCE_PTR dev_ptr = (DEV_INSTANCE_PTR)dev_handle; USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_address"); #endif USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_OUT; request.BREQUEST = REQ_SET_ADDRESS; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(dev_ptr->address); error = usb_host_ch9_dev_req(dev_handle, &request, NULL); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_address,SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_set_descriptor * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_set_descriptor ( /* usb device */ _usb_device_instance_handle dev_handle, /* descriptor type & index */ uint_16 type_index, /* Language ID or 0 */ uint_16 lang_id, /* buffer length */ uint_16 buflen, /* descriptor buffer */ uchar_ptr buffer ) { /* Body */ USB_SETUP request; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_descriptor"); #endif USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_OUT; request.BREQUEST = REQ_SET_DESCRIPTOR; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(type_index); *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(lang_id); *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT(buflen); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_descriptor SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_get_status * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_get_status ( /* usb device */ _usb_device_instance_handle dev_handle, /* request type device/interface/endpoint */ uint_8 req_type, /* device = 0, or interface/endpoint */ uint_8 intf_endpt, /* returned status */ uchar_ptr buffer ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_status"); #endif USB_lock(); switch (req_type) { case REQ_TYPE_DEVICE: case REQ_TYPE_INTERFACE: case REQ_TYPE_ENDPOINT: break; default: USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_status, invalid parameter"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE); } /* EndSwitch */ request.BMREQUESTTYPE = (uchar)(req_type | REQ_TYPE_IN); request.BREQUEST = REQ_GET_STATUS; *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(intf_endpt); *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(2); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_status, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
USB_STATUS usb_class_mass_getmaxlun_bulkonly ( CLASS_CALL_STRUCT_PTR ccs_ptr, uint_8_ptr pLUN, tr_callback callback ) { /* Body */ USB_STATUS status = USBERR_NO_INTERFACE; USB_SETUP request; USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly"); #endif /* Pointer validity-checking, clear memory, init header */ USB_lock(); if (usb_host_class_intf_validate(ccs_ptr)) { intf_ptr = (USB_MASS_CLASS_INTF_STRUCT_PTR) ccs_ptr->class_intf_handle; status = usb_hostdev_validate(intf_ptr->G.dev_handle); } /* Endif */ if (status) { USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly, error status"); #endif return USB_log_error(__FILE__,__LINE__,status); } /* Endif */ /* Get the number of logical units on the device */ request.BMREQUESTTYPE = REQ_TYPE_CLASS | REQ_TYPE_INTERFACE | REQ_TYPE_IN; request.BREQUEST = GET_MAX_LUN; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT_CONST(0); *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(((INTERFACE_DESCRIPTOR_PTR)intf_ptr->G.intf_handle)->bInterfaceNumber); *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(1); /* Send request */ status = _usb_hostdev_cntrl_request (intf_ptr->G.dev_handle, &request, (uchar_ptr)pLUN, callback, NULL); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,status); } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_set_interface * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_set_interface ( /* usb device */ _usb_device_instance_handle dev_handle, /* alternate setting */ uint_8 alternate, /* interface */ uint_8 intf ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_interface"); #endif USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_INTERFACE | REQ_TYPE_OUT; request.BREQUEST = REQ_SET_INTERFACE; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(alternate); *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(intf); error = usb_host_ch9_dev_req(dev_handle, &request, NULL); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_set_interface, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
USB_STATUS usb_printer_class_send ( /* [IN] class-interface data pointer + key */ CLASS_CALL_STRUCT_PTR cc_ptr, /* [IN] TR containing setup packet to be sent */ TR_INIT_PARAM_STRUCT_PTR tr_ptr ) { /* Body */ DESCRIPTOR_UNION desc; PRINTER_INTERFACE_STRUCT_PTR pis_ptr; USB_STATUS error = USBERR_NO_INTERFACE; USB_SETUP_PTR dev_req; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_printer_class_send"); #endif USB_lock (); if (usb_host_class_intf_validate (cc_ptr)) { pis_ptr = (PRINTER_INTERFACE_STRUCT_PTR) cc_ptr->class_intf_handle; desc.pntr = pis_ptr->intf_handle; dev_req = (USB_SETUP_PTR)tr_ptr->DEV_REQ_PTR; *(uint_16*)dev_req->WVALUE = HOST_TO_LE_SHORT_CONST(0); dev_req->WINDEX[0] = desc.intf->bAlternateSetting; dev_req->WINDEX[1] = desc.intf->bInterfaceNumber; *(uint_16*)dev_req->WLENGTH = HOST_TO_LE_SHORT(tr_ptr->G.RX_LENGTH); error = _usb_host_send_setup (pis_ptr->host_handle, pis_ptr->control_pipe, tr_ptr); } /* EndIf */ USB_unlock (); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_printer_class_send, SUCCESSFUL"); #endif return error; } /* Endbody */
USB_STATUS usb_class_mass_reset_recovery_on_usb ( USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr ) { /* Body */ COMMAND_OBJECT_PTR cmd_ptr = NULL; USB_STATUS status = USB_OK; USB_SETUP request; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_reset_recovery_on_usb"); #endif /* Nothing can be done if there is nothing pending*/ usb_class_mass_get_pending_request(intf_ptr,&cmd_ptr); if(cmd_ptr == NULL) { #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_reset_recovery_on_usb,no matching request"); #endif return (USB_STATUS) USB_MASS_NO_MATCHING_REQUEST; } /* Endif */ /* BULK device mass storage reset */ request.BMREQUESTTYPE = REQ_TYPE_CLASS | REQ_TYPE_INTERFACE | REQ_TYPE_OUT; request.BREQUEST = MASS_STORAGE_RESET; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT_CONST(0); *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(((INTERFACE_DESCRIPTOR_PTR)intf_ptr->G.intf_handle)->bInterfaceNumber); *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(0); cmd_ptr->STATUS = STATUS_RESET_DEVICE; status = _usb_hostdev_cntrl_request (intf_ptr->G.dev_handle, &request, NULL, usb_class_mass_reset_callback, (pointer)intf_ptr); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_reset_recovery_on_usb,SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,status); } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_get_interface * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_get_interface ( /* usb device */ _usb_device_instance_handle dev_handle, /* interface index */ uint_8 interface, /* alternate setting buffer */ uchar_ptr buffer ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_interface"); #endif USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_INTERFACE | REQ_TYPE_IN; request.BREQUEST = REQ_GET_INTERFACE; *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(interface); *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(1); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_interface, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_synch_frame * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_synch_frame ( /* usb device */ _usb_device_instance_handle dev_handle, /* interface index */ uint_8 interface, /* configuration buffer */ uchar_ptr buffer ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_synch_frame"); #endif USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_ENDPOINT | REQ_TYPE_IN; request.BREQUEST = REQ_SYNCH_FRAME; *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(interface); *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(2); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_synch_frame, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_audio_cntrl_common * Returned Value : USB_OK if command has been passed on USB. * Comments : * This function is used to send a control request. * It must be run with USB locked. * *END*--------------------------------------------------------------------*/ static USB_STATUS usb_class_audio_cntrl_common ( /* [IN] The communication device common command structure */ AUDIO_COMMAND_PTR com_ptr, /* [IN] The audio control interface */ //AUDIO_CONTROL_INTERFACE_STRUCT_PTR if_ctrl_ptr, /* [IN] Bitmask of the request type */ uint8_t bmrequesttype, /* [IN] Request code */ uint8_t brequest, /* [IN] Value to copy into WVALUE field of the REQUEST */ uint16_t wvalue, /* [IN] Value to copy into WINDEX field of the REQUEST */ uint16_t wIndex, /* [IN] Length of the data associated with REQUEST */ uint16_t wlength, /* [IN] Pointer to data buffer used to send/recv */ unsigned char *data ) { /* Body */ USB_AUDIO_GENERAL_CLASS_PTR if_ptr; USB_SETUP req; USB_STATUS status = USBERR_NO_INTERFACE; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_audio_cntrl_common"); #endif if_ptr = (USB_AUDIO_GENERAL_CLASS_PTR) com_ptr->CLASS_PTR->class_intf_handle; /* Save the higher level callback and ID */ if_ptr->USER_CALLBACK = com_ptr->CALLBACK_FN; if_ptr->USER_PARAM = com_ptr->CALLBACK_PARAM; /* Setup the request */ req.BMREQUESTTYPE = bmrequesttype; req.BREQUEST = brequest; *(uint16_t*)req.WINDEX = HOST_TO_LE_SHORT(wIndex); *(uint16_t*)req.WVALUE = HOST_TO_LE_SHORT(wvalue); *(uint16_t*)req.WLENGTH = HOST_TO_LE_SHORT(wlength); if (USB_STATUS_TRANSFER_QUEUED == (status = _usb_hostdev_cntrl_request(if_ptr->G.dev_handle, &req, data, usb_class_audio_cntrl_callback, if_ptr))) status = USB_OK; #ifdef _HOST_DEBUG_ if (!status) DEBUG_LOG_TRACE("usb_class_audio_cntrl_common, SUCCESSFUL"); else DEBUG_LOG_TRACE("usb_class_audio_cntrl_common, FAILED"); #endif return status; } /* Endbody */