/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_hostdev_cntrl_request * Returned Value : USB_OK, or error status * Comments : * Function to process class- or vendor-specific control pipe device * requests. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_hostdev_cntrl_request ( /* usb device */ _usb_device_instance_handle dev_handle, /* Device Request to send */ USB_SETUP_PTR devreq, /* buffer to send/receive */ uchar_ptr buff_ptr, /* callback upon completion */ tr_callback callback, /* [IN] the parameter to pass back to the callback function */ pointer callback_param ) { /* Body */ DEV_INSTANCE_PTR dev_ptr; _usb_pipe_handle pipe_handle; TR_INIT_PARAM_STRUCT tr; USB_STATUS error = USB_OK; /* Verify that device handle is valid */ USB_lock(); error = usb_hostdev_validate(dev_handle); if (error != USB_OK) { USB_unlock(); return USBERR_DEVICE_NOT_FOUND; } /* Endif */ dev_ptr = (DEV_INSTANCE_PTR)dev_handle; if (dev_ptr->state < DEVSTATE_ENUM_OK) { USB_unlock(); return USBERR_DEVICE_NOT_FOUND; } /* Endif */ pipe_handle = dev_ptr->control_pipe; usb_hostdev_tr_init(&tr, callback, callback_param); /* Set TR buffer length as required */ if ((REQ_TYPE_IN & devreq->BMREQUESTTYPE) != 0) { tr.RX_BUFFER = buff_ptr; tr.RX_LENGTH = utoh16(devreq->WLENGTH); } else { tr.TX_BUFFER = buff_ptr; tr.TX_LENGTH = utoh16(devreq->WLENGTH); } /* EndIf */ tr.DEV_REQ_PTR = (uchar_ptr)devreq; error = _usb_host_send_setup(dev_ptr->host, pipe_handle, &tr); USB_unlock(); return 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 */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_host_ch9_dev_req * Returned Value : USB_OK, or error status * Comments : * Function to process standard device requests in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * This code does minimal error checking, on the assumption * that it is called only from wrappers in this file. * It is presumed that this function is called with USB interrupts disabled * *END*--------------------------------------------------------------------*/ static USB_STATUS usb_host_ch9_dev_req ( /* usb device */ _usb_device_instance_handle dev_handle, /* Device Request to send */ USB_SETUP_PTR devreq_ptr, /* buffer to send/receive */ uchar_ptr buff_ptr ) { /* Body */ DEV_INSTANCE_PTR dev_ptr; _usb_pipe_handle pipe_handle; TR_INIT_PARAM_STRUCT tr; USB_STATUS error; /* Verify that device handle is valid */ error = usb_hostdev_validate(dev_handle); if (error != USB_OK) { return USBERR_DEVICE_NOT_FOUND; } /* Endif */ dev_ptr = (DEV_INSTANCE_PTR)dev_handle; pipe_handle = dev_ptr->control_pipe; /* Initialize the TR with TR index and default control callback ** function if there is one registered */ usb_hostdev_tr_init(&tr, dev_ptr->control_callback, dev_ptr->control_callback_param); /* Set buffer length if required */ switch (devreq_ptr->BREQUEST) { case REQ_SET_DESCRIPTOR: tr.TX_BUFFER = buff_ptr; tr.TX_LENGTH = utoh16(devreq_ptr->WLENGTH); break; case REQ_GET_CONFIGURATION: case REQ_GET_DESCRIPTOR: case REQ_GET_INTERFACE: case REQ_GET_STATUS: case REQ_SYNCH_FRAME: tr.RX_BUFFER = buff_ptr; tr.RX_LENGTH = utoh16(devreq_ptr->WLENGTH); break; } /* EndSwitch */ tr.DEV_REQ_PTR = (uchar_ptr)(devreq_ptr); if ((dev_ptr->state < DEVSTATE_ENUM_OK) || (tr.CALLBACK == NULL)) { tr.CALLBACK = usb_host_cntrl_transaction_done; tr.CALLBACK_PARAM = NULL; } /* Endif */ error = _usb_host_send_setup(dev_ptr->host, pipe_handle, &tr); return error; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_hostdev_cntrl_request * Returned Value : USB_OK, or error status * Comments : * Function to process class- or vendor-specific control pipe device * requests. * *END*--------------------------------------------------------------------*/ usb_status _usb_hostdev_cntrl_request ( /* usb device */ usb_device_instance_handle dev_handle, /* Device Request to send */ usb_setup_t* devreq, /* buffer to send/receive */ uint8_t * buff_ptr, /* callback upon completion */ tr_callback callback, /* [IN] the parameter to pass back to the callback function */ void* callback_param ) { /* Body */ dev_instance_t* dev_ptr; usb_pipe_handle pipe_handle; tr_struct_t tr; usb_status error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request"); #endif /* Verify that device handle is valid */ OS_Lock(); error = usb_hostdev_validate(dev_handle); if (error != USB_OK) { OS_Unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request, invalid device handle"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_DEVICE_NOT_FOUND); } /* Endif */ dev_ptr = (dev_instance_t*)dev_handle; if (dev_ptr->state < DEVSTATE_ENUM_OK) { OS_Unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request, no device found"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_DEVICE_NOT_FOUND); } /* Endif */ pipe_handle = dev_ptr->control_pipe; usb_hostdev_tr_init(&tr, callback, callback_param); /* Set TR buffer length as required */ if ((REQ_TYPE_IN & devreq->bmrequesttype) != 0) { tr.rx_buffer = buff_ptr; tr.rx_length = USB_SHORT_UNALIGNED_LE_TO_HOST(devreq->wlength); } else { tr.TX_BUFFER = buff_ptr; tr.tx_length = USB_SHORT_UNALIGNED_LE_TO_HOST(devreq->wlength); } /* EndIf */ tr.setup_packet = *devreq; error = _usb_host_send_setup(dev_ptr->host, pipe_handle, &tr); OS_Unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request,SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_hostdev_cntrl_request * Returned Value : USB_OK, or error status * Comments : * Function to process class- or vendor-specific control pipe device * requests. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_hostdev_cntrl_request ( /* usb device */ _usb_device_instance_handle dev_handle, /* Device Request to send */ USB_SETUP_PTR devreq, /* buffer to send/receive */ uchar_ptr buff_ptr, /* callback upon completion */ tr_callback callback, /* [IN] the parameter to pass back to the callback function */ pointer callback_param ) { /* Body */ DEV_INSTANCE_PTR dev_ptr; _usb_pipe_handle pipe_handle; TR_INIT_PARAM_STRUCT tr; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request"); #endif /* Verify that device handle is valid */ USB_lock(); error = usb_hostdev_validate(dev_handle); if (error != USB_OK) { USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request, invalid device handle"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_DEVICE_NOT_FOUND); } /* Endif */ dev_ptr = (DEV_INSTANCE_PTR)dev_handle; if (dev_ptr->state < DEVSTATE_ENUM_OK) { USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request, no device found"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_DEVICE_NOT_FOUND); } /* Endif */ pipe_handle = dev_ptr->control_pipe; usb_hostdev_tr_init(&tr, callback, callback_param); /* Set TR buffer length as required */ if ((REQ_TYPE_IN & devreq->BMREQUESTTYPE) != 0) { tr.G.RX_BUFFER = buff_ptr; tr.G.RX_LENGTH = SHORT_LE_TO_HOST(*(uint_16*)devreq->WLENGTH); } else { tr.G.TX_BUFFER = buff_ptr; tr.G.TX_LENGTH = SHORT_LE_TO_HOST(*(uint_16*)devreq->WLENGTH); } /* EndIf */ tr.DEV_REQ_PTR = (uchar_ptr)devreq; error = _usb_host_send_setup(dev_ptr->host, pipe_handle, &tr); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_hostdev_cntrl_request,SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */