1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef USB_DDK_REQUEST_H 17#define USB_DDK_REQUEST_H 18 19#include "usb_ddk_device.h" 20#include "usb_ddk_interface.h" 21#include "usb_raw_api.h" 22 23typedef enum { 24 /* select a configuration for the device */ 25 USB_REQUEST_SELECT_CONFIGURATION, 26 /* select an alternate setting for an interface */ 27 USB_REQUEST_SELECT_INTERFACE, 28 /* get the device descriptor from a specific USB device/interface/endpoint */ 29 USB_REQUEST_GET_DESCRIPTOR, 30 /* set descriptor on a device/interface/endpoint */ 31 USB_REQUEST_SET_DESCRIPTOR, 32 /* set a feature on a device/interface/endpoint/other */ 33 USB_REQUEST_SET_FEATURE, 34 /* clear a USB-defined feature on a device/interface/endpoint/other */ 35 USB_REQUEST_CLEAR_FEATURE, 36 /* get status form a USB device/interface/endpoint/other */ 37 USB_REQUEST_GET_STATUS, 38 /* get the current configuration on a USB device */ 39 USB_REQUEST_GET_CONFIGURATION = 0x08, 40 /* get the current setting for an interface */ 41 USB_REQUEST_GET_INTERFACE, 42} UsbStandardRequest; 43 44typedef enum { 45 USB_REQUEST_TYPE_CONTROL = 0U, 46 USB_REQUEST_TYPE_ISOCHRONOUS = 1U, 47 USB_REQUEST_TYPE_BULK = 2U, 48 USB_REQUEST_TYPE_INTERRUPT = 3U, 49} UsbRequestType; 50 51struct UsbIsoPacketDesc { 52 unsigned int length; 53 unsigned int actualLength; 54 unsigned int status; 55}; 56 57struct UsbAdapterUrb { 58 unsigned char type; 59 unsigned char endPoint; 60 int32_t status; 61 unsigned int flags; 62 void *buffer; 63 int32_t bufferLength; 64 int32_t actualLength; 65 int32_t startFrame; 66 int32_t numberOfPackets; 67 int32_t errorCount; 68 unsigned int signr; 69 void *userContext; 70 struct UsbIsoPacketDesc isoFrameDesc[0]; 71}; 72 73/* Note:The first five fields of the definition must be consistent with the UsbRawRequest structure definition. */ 74struct UsbHostRequest { 75 /* the address of data buffer */ 76 unsigned char *buffer; 77 /* the length of data buffer */ 78 uint32_t length; 79 /* the actual length of the requested data */ 80 int32_t actualLength; 81 /* the status of the request */ 82 UsbRequestStatus status; 83 /* private user data */ 84 void *userData; 85 86 /* the following fields are not visible to user */ 87 struct HdfSListNode entry; 88 struct DListHead list; 89 struct UsbDeviceHandle *devHandle; 90 UsbRawRequestCallback callback; 91 UsbRequestCallback userCallback; 92 /* the length of data buffer */ 93 int32_t bufLen; 94 struct OsalSem sem; 95 unsigned char endPoint; 96 unsigned int timeout; 97 unsigned char requestType; 98 void *bulkUrb; 99 union { 100 void *urbs; 101 void **isoUrbs; 102 }; 103 int32_t numUrbs; 104 int32_t numRetired; 105 UsbRequestStatus reqStatus; 106 int32_t isoPacketOffset; 107 struct OsalMutex lock; 108 void *privateObj; 109 int32_t numIsoPackets; 110 /* isopacketdesc ptr */ 111 struct UsbIsoPacketDesc isoPacketDesc[0]; 112}__attribute__((aligned(4))); 113 114/* Note:The first seven fields of this definition must be consistent with the UsbRawFillRequestData 115 * structure definition. 116 */ 117struct UsbFillRequestData { 118 unsigned char endPoint; 119 unsigned char *buffer; 120 uint32_t length; 121 int32_t numIsoPackets; 122 UsbRawRequestCallback callback; 123 void *userData; 124 unsigned int timeout; 125 UsbRequestCallback userCallback; 126}; 127 128#ifndef MIN 129static inline int32_t MIN(int32_t a, int32_t b) 130{ 131 return ((a) < (b) ? (a) : (b)); 132} 133#endif 134 135#ifndef MAX 136static inline int32_t MAX(int32_t a, int32_t b) 137{ 138 return ((a) > (b) ? (a) : (b)); 139} 140#endif 141 142#endif /* USB_DDK_REQUEST_H */ 143