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 HDF_USB_CDC_ETHER_H 17 #define HDF_USB_CDC_ETHER_H 18 19 #include "hdf_base.h" 20 #include "hdf_device_desc.h" 21 #include "osal_atomic.h" 22 #include "usb_session.h" 23 #include "usb_interface_pool.h" 24 #include "data_fifo.h" 25 26 #define ECM_NW 16 27 #define ECM_NR 16 28 #define TARGET_MASK 0x3 29 #define REQUEST_TYPE_MASK 0x3 30 #define DIRECTION_MASK 0x1 31 #define USB_CTRL_SET_TIMEOUT 5000 32 #define READ_BUF_SIZE 8192 33 #define USB_MAX_INTERFACES 32 34 #define ETHER_SLEEP_TIME 100000 35 #define ETHER_SLEEP_MS_TIME 2 36 37 enum EcmCmd { 38 CMD_ECM_OPEN = 0, 39 CMD_ECM_CLOSE, 40 CMD_ECM_READ, 41 CMD_ECM_WRITE, 42 CMD_ECM_GET_MAC, 43 CMD_ECM_ADD_INTERFACE = 14, 44 CMD_ECM_REMOVE_INTERFACE, 45 }; 46 47 typedef enum { 48 HOST_ECM_OPEN = 0, 49 HOST_ECM_CLOSE, 50 HOST_ECM_READ, 51 HOST_ECM_WRITE, 52 HOST_ECM_GET_MAC, 53 HOST_ECM_ADD_INTERFACE = 16, 54 HOST_ECM_REMOVE_INTERFACE, 55 } EcmModuleTestCmdType; 56 57 struct EcmDevice; 58 struct EcmWb { 59 struct UsbRequest *request; 60 struct EcmDevice *instance; 61 uint8_t *buf; 62 int32_t len; 63 int32_t use; 64 struct EcmDevice *ecm; 65 }; 66 67 struct EcmRb { 68 uint8_t *base; 69 int32_t size; 70 int32_t index; 71 int32_t use; 72 struct EcmDevice *instance; 73 }; 74 75 struct EcmControlParams { 76 uint8_t request; 77 uint8_t requestType; 78 uint16_t value; 79 uint16_t index; 80 void *data; 81 uint16_t size; 82 }; 83 84 struct EcmDevice { 85 struct IDeviceIoService service; 86 struct HdfDeviceObject *device; 87 struct UsbInterface *ctrIface; 88 struct UsbPipeInfo *ctrPipe; 89 struct UsbPipeInfo *intPipe; 90 struct UsbPipeInfo *dataInPipe; 91 struct UsbPipeInfo *dataOutPipe; 92 struct EcmWb wb[ECM_NW]; 93 struct EcmRb rb[ECM_NR]; 94 struct UsbPipeInfo wPipeInfo; 95 struct OsalMutex writeLock; 96 struct OsalMutex readLock; 97 struct UsbRequest *notifyReq; 98 struct UsbRequest *readReq[ECM_NR]; 99 struct UsbRequest *writeReq; 100 struct UsbRequest *ctrlReq; 101 struct UsbInterface *itface; 102 UsbInterfaceHandle *devHandle[USB_MAX_INTERFACES]; 103 UsbInterfaceHandle *ctrDevHandle; 104 struct UsbSession *session; 105 struct DataFifo readFifo; 106 uint32_t nbIndex; 107 uint32_t nbSize; 108 int32_t transmitting; 109 int32_t ctrlReqNum; 110 uint8_t busNum; 111 uint8_t devAddr; 112 uint8_t interfaceCnt; 113 uint8_t *notificationBuffer; 114 uint8_t interfaceIndex[USB_MAX_INTERFACES]; 115 struct UsbInterface *iface[USB_MAX_INTERFACES]; 116 uint32_t ctrlSize; 117 uint32_t intSize; 118 uint32_t writeSize; 119 uint32_t readSize; 120 struct UsbCdcLineCoding lineCoding; 121 bool openFlag; 122 uint32_t readReqNum; 123 uint32_t writeReqNum; 124 bool initFlag; 125 }; 126 127 #endif 128