• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RAW_API_LIBRARY_H
17 #define USB_RAW_API_LIBRARY_H
18 
19 #include "hdf_device_desc.h"
20 #include "hdf_usb_pnp_manage.h"
21 #include "usb_session.h"
22 #include "usb_ddk_device.h"
23 #include "usb_ddk_request.h"
24 #include "usb_raw_api.h"
25 
26 #define BYTE_LENGTH         8
27 
28 #define USB_HOST_PNP_SERVICE_NAME "hdf_usb_pnp_notify_service"
29 
30 #define USB_RAW_REQUEST_TIME_ZERO_MS        (0)
31 #define USB_RAW_REQUEST_DEFAULT_TIMEOUT     (1000)
32 #define USB_RAW_REQUEST_TIMEOUT_MAX         (0xFFFFFFFF)
33 
34 #define DESC_HEADER_LENGTH  2
35 
36 typedef pid_t UsbRawTidType;
37 
38 struct UsbRawControlSetup {
39     uint8_t requestType;
40     uint8_t request;
41     uint16_t value;
42     uint16_t index;
43     uint16_t length;
44 } __attribute__((packed));
45 
46 #define USB_RAW_CONTROL_SETUP_SIZE (sizeof(struct UsbRawControlSetup))
47 
48 union UsbiConfigDescBuf {
49     struct UsbiConfigurationDescriptor desc;
50     uint8_t buf[USB_DDK_DT_CONFIG_SIZE];
51     uint16_t align;     /* Force 2-byte alignment */
52 };
53 
54 enum UsbRawDescriptorType {
55     USB_RAW_CONFIG_DESCRIPTOR_TYPE,
56     USB_RAW_INTERFACE_DESCRIPTOR_TYPE,
57     USB_RAW_ENDPOINT_DESCRIPTOR_TYPE,
58     USB_RAW_AUDIO_ENDPOINT_DESCRIPTOR_TYPE,
59 };
60 
61 enum RawRequestTimeoutFlags {
62     RAW_REQUEST_OS_HANDLES_TIMEOUT = 1U << 0,
63     RAW_REQUEST_TIMEOUT_HANDLED = 1U << 1,
64     RAW_REQUEST_TIMED_OUT = 1U << 2,
65 };
66 
67 struct UsbMessageQueue {
68     struct DListHead entry;
69     struct OsalMutex mutex;
70     struct OsalSem sem;
71 };
72 
73 struct RawUsbRamTestList {
74     uint32_t address;
75     uint32_t size;
76     struct DListHead list;
77     struct OsalMutex lock;
78 };
79 
80 struct UsbSession *RawGetSession(const struct UsbSession *session);
81 int32_t RawInit(struct UsbSession **session);
82 int32_t RawExit(const struct UsbSession *session);
83 struct UsbDeviceHandle *RawOpenDevice(const struct UsbSession *session, uint8_t busNum, uint8_t usbAddr);
84 int32_t RawCloseDevice(const struct UsbDeviceHandle *devHandle);
85 int32_t RawClaimInterface(struct UsbDeviceHandle *devHandle, int interfaceNumber);
86 struct UsbHostRequest *AllocRequest(const struct UsbDeviceHandle *devHandle,  int isoPackets, size_t length);
87 int32_t FreeRequest(const struct UsbHostRequest *request);
88 int32_t RawFillBulkRequest(struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
89     const struct UsbFillRequestData *fillRequestData);
90 int32_t RawFillControlSetup(const unsigned char *setup, const struct UsbControlRequestData *requestData);
91 int32_t RawFillControlRequest(struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
92     const struct UsbFillRequestData *fillRequestData);
93 int32_t RawFillInterruptRequest(struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
94     const struct UsbFillRequestData *fillRequestData);
95 int32_t RawFillIsoRequest(struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
96     const struct UsbFillRequestData *fillRequestData);
97 int32_t RawSendControlRequest(struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
98     const struct UsbControlRequestData *requestData);
99 int32_t RawSendBulkRequest(const struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
100     const struct UsbRequestData *requestData);
101 int32_t RawSendInterruptRequest(const struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
102     const struct UsbRequestData *requestData);
103 struct UsbHostRequest *RawAllocRequest(const struct UsbDeviceHandle *devHandle, int isoPackets, int length);
104 int32_t RawFreeRequest(const struct UsbHostRequest *request);
105 int32_t RawGetConfigDescriptor(const struct UsbDevice *dev, uint8_t configIndex,
106     struct UsbRawConfigDescriptor **config);
107 void RawClearConfiguration(struct UsbRawConfigDescriptor *config);
108 int32_t RawGetConfiguration(const struct UsbDeviceHandle *devHandle, int *config);
109 int32_t RawSetConfiguration(const struct UsbDeviceHandle *devHandle, int configuration);
110 int32_t RawGetDescriptor(const struct UsbHostRequest *request, const struct UsbDeviceHandle *devHandle,
111     const struct UsbRawDescriptorParam *param, const unsigned char *data);
112 struct UsbDevice *RawGetDevice(const struct UsbDeviceHandle *devHandle);
113 int32_t RawGetDeviceDescriptor(const struct UsbDevice *dev, struct UsbDeviceDescriptor *desc);
114 int32_t RawReleaseInterface(struct UsbDeviceHandle *devHandle, int interfaceNumber);
115 int32_t RawResetDevice(const struct UsbDeviceHandle *devHandle);
116 int32_t RawSubmitRequest(const struct UsbHostRequest *request);
117 int32_t RawCancelRequest(const struct UsbHostRequest *request);
118 int32_t RawHandleRequest(const struct UsbDeviceHandle *devHandle);
119 int32_t RawClearHalt(const struct UsbDeviceHandle *devHandle, uint8_t pipeAddress);
120 int RawHandleRequestCompletion(struct UsbHostRequest *request, UsbRequestStatus status);
121 int32_t RawSetInterfaceAltsetting(
122     const struct UsbDeviceHandle *devHandle, uint8_t interfaceNumber, uint8_t settingIndex);
123 UsbRawTidType RawGetTid(void);
124 int32_t RawRegisterSignal(void);
125 int32_t RawKillSignal(struct UsbDeviceHandle *devHandle, UsbRawTidType tid);
126 int RawInitPnpService(enum UsbPnpNotifyServiceCmd cmdType, struct UsbPnpAddRemoveInfo infoData);
127 void RawRequestListInit(struct UsbDevice *deviceObj);
128 void *RawUsbMemAlloc(size_t size);
129 void *RawUsbMemCalloc(size_t size);
130 void RawUsbMemFree(void *mem);
131 int RawUsbMemTestTrigger(bool enable);
132 
133 #endif /* USB_RAW_API_LIBRARY_H */
134