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 USBFN_CFG_MGR_H 17 #define USBFN_CFG_MGR_H 18 19 #include <device_resource_if.h> 20 #include "usbfn_device.h" 21 #include "usbfn_request.h" 22 #include "usbfn_interface.h" 23 24 #define DESC_LENGTH "bLength" 25 #define DESC_TYPE "bDescriptorType" 26 27 /* USB_DT_DEVICE: Device descriptor */ 28 #define USBDEV_CLASS "bDeviceClass" 29 #define USBDEV_SUBCLASS "bDeviceSubClass" 30 #define USBDEV_PROTOCOL "bDeviceProtocol" 31 #define USBDEV_MAXSIZE "bMaxPacketSize0" 32 #define USBDEV_MANUFACTURER "manufacturer" 33 #define USBDEV_PRODUCT "product" 34 #define USBDEV_SERIALNUM "serialnumber" 35 #define USBDEV_NUMCFG "numConfigurations" 36 #define USBDEV_BCD "bcdUSB" 37 #define USBDEV_VENDOR "idVendor" 38 #define USBDEV_IDPRODUCT "idProduct" 39 #define USBDEV_BCDDEVICE "bcdDevice" 40 41 /* USB_DT_INTERFACE */ 42 #define INTERFACE_NUMBER "bInterfaceNumber" 43 #define INTERFACE_ALTERNATE "bAlternateSetting" 44 #define INTERFACE_NENDPOINT "bNumEndpoints" 45 #define INTERFACE_CLASS "bInterfaceClass" 46 #define INTERFACE_SUBCLASS "bInterfaceSubClass" 47 #define INTERFACE_PROTOCOL "bInterfaceProtocol" 48 #define INTERFACE_INTERFACE "iInterface" 49 50 /* USB_DT_INTERFACE_ASSOCIATION */ 51 #define INTERFACE_FIRST "bFirstInterface" 52 #define INTERFACE_COUNT "bInterfaceCount" 53 #define FUNCTION_CLASS "bFunctionClass" 54 #define FUNCTION_SUBCLASS "bFunctionSubClass" 55 #define FUNCTION_PROTOCOL "bFunctionProtocol" 56 #define FUNCTION_INDEX "iFunction" 57 58 /* USB_DT_ENDPOINT */ 59 #define ENDPOINT_ADDRESS "bEndpointAddress" 60 #define ENDPOINT_MATTR "bmAttributes" 61 #define ENDPOINT_MAXPACKSIZE_W "wMaxPacketSize" 62 #define ENDPOINT_INTERVAL "bInterval" 63 #define ENDPOINT_REFRESH "bRefresh" 64 #define ENDPOINT_SYNCADDR "bSynchAddress" 65 66 /* USB_DT_STRING: String descriptor */ 67 #define STRING_DATA "wData" 68 69 /* USB_DT_SSP_ISOC_ENDPOINT_COMP */ 70 #define SSP_ISOC_EPCOMP_WRESEVED "wReseved" 71 #define SSP_ISOC_EPCOMP_DWPERINTERVAL "dwBytesPerInterval" 72 73 /* USB_DT_SS_ENDPOINT_COMP */ 74 #define SS_EP_COMP_MAXBURST "bMaxBurst" 75 #define SS_EP_COMP_MTTRIBUTE "bmAttributes" 76 #define SS_EP_COMP_WPERINTERVAL "wBytesPerInterval" 77 78 /* USB_DT_DEVICE_QUALIFIER */ 79 #define QUALIFIER_BCD "bcdUSB" 80 #define QUALIFIER_CLASS "bDeviceClass" 81 #define QUALIFIER_SUBCLASS "bDeviceSubClass" 82 #define QUALIFIER_PROTOCOL "bDeviceProtocol" 83 #define QUALIFIER_MAXSIZE "bMaxPacketSize0" 84 #define QUALIFIER_NUMCFG "bNumConfigurations" 85 #define QUALIFIER_RESERVED "bRESERVED" 86 87 /* USB_DT_OTG (from OTG 2.0 supplement) */ 88 #define OTG_MTTRIBUTE "bmAttributes" 89 #define OTG_BCDOTG "bcdOTG" 90 91 /* USB_DT_DEBUG */ 92 #define DEBUG_IN "bDebugInEndpoint" 93 #define DEBUG_OUT "bDebugOutEndpoint" 94 95 /* USB_DT_SECURITY */ 96 #define SECURITY_TOTALLENGTH "wTotalLength" 97 #define SECURITY_ENCRYTYPE "bNumEncryptionTypes" 98 99 #define MAX_LEN 64 100 101 typedef struct { 102 uint8_t size; 103 uint8_t cmd; 104 uint8_t type; 105 uint8_t nameLen; 106 uint8_t dataLen; 107 }SelfProp; 108 109 typedef enum { 110 PROP_TYPE_UINT, 111 PROP_TYPE_STRING 112 }FuncDescType; 113 114 struct UsbFnCfgPropMgr { 115 const struct UsbFnInterface *intf; 116 char name[MAX_LEN]; 117 char value[MAX_LEN]; 118 uint8_t isDevProp; 119 UsbFnPropCallback getPropCallback; 120 UsbFnPropCallback setPropCallback; 121 struct DListHead entry; 122 }; 123 124 struct UsbFnDeviceDesc *UsbFnCfgMgrGetInstanceFromHCS(const struct DeviceResourceNode *node); 125 void UsbFnCfgMgrFreeUsbFnDeviceDesc(struct UsbFnDeviceDesc *fnDevDesc); 126 int32_t UsbFnCfgMgrSetProp(const struct UsbFnInterface *intf, const char *name, const char *value); 127 int32_t UsbFnCfgMgrGetProp(const struct UsbFnInterface *intf, const char *name, char *value); 128 int32_t UsbFnCfgMgrRegisterProp(const struct UsbFnInterface *intf, 129 const struct UsbFnRegistInfo *registInfo); 130 void UsbFnCfgMgrUnRegisterAllProp(void); 131 132 #endif /* USBFN_CFG_MGR_H */ 133