• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef HARDWARE_GOOGLE_PIXEL_USB_UTILSCOMMON_H_
18 #define HARDWARE_GOOGLE_PIXEL_USB_UTILSCOMMON_H_
19 
20 #include <android-base/unique_fd.h>
21 
22 #include <string>
23 
24 namespace android {
25 namespace hardware {
26 namespace google {
27 namespace pixel {
28 namespace usb {
29 
30 constexpr int kBufferSize = 512;
31 constexpr int kMaxFilePathLength = 256;
32 constexpr int kEpollEvents = 10;
33 constexpr bool kDebug = false;
34 constexpr int kDisconnectWaitUs = 100000;
35 constexpr int kPullUpDelay = 500000;
36 constexpr int kShutdownMonitor = 100;
37 
38 constexpr char kBuildType[] = "ro.build.type";
39 constexpr char kPersistentVendorConfig[] = "persist.vendor.usb.usbradio.config";
40 constexpr char kVendorConfig[] = "vendor.usb.config";
41 constexpr char kVendorRndisConfig[] = "vendor.usb.rndis.config";
42 constexpr char kUvcEnabled[] = "ro.usb.uvc.enabled";
43 
44 #define GADGET_PATH "/config/usb_gadget/g1/"
45 #define PULLUP_PATH GADGET_PATH "UDC"
46 #define PERSISTENT_BOOT_MODE "ro.bootmode"
47 #define VENDOR_ID_PATH GADGET_PATH "idVendor"
48 #define PRODUCT_ID_PATH GADGET_PATH "idProduct"
49 #define DEVICE_CLASS_PATH GADGET_PATH "bDeviceClass"
50 #define DEVICE_SUB_CLASS_PATH GADGET_PATH "bDeviceSubClass"
51 #define DEVICE_PROTOCOL_PATH GADGET_PATH "bDeviceProtocol"
52 #define DESC_USE_PATH GADGET_PATH "os_desc/use"
53 #define OS_DESC_PATH GADGET_PATH "os_desc/b.1"
54 #define CONFIG_PATH GADGET_PATH "configs/b.1/"
55 #define FUNCTIONS_PATH GADGET_PATH "functions/"
56 #define FUNCTION_NAME "function"
57 #define FUNCTION_PATH CONFIG_PATH FUNCTION_NAME
58 #define RNDIS_PATH FUNCTIONS_PATH "gsi.rndis"
59 
60 // Adds the given fd to the epollfd(epfd).
61 int addEpollFd(const ::android::base::unique_fd &epfd, const ::android::base::unique_fd &fd);
62 // Extracts vendor functions from the vendor init properties.
63 std::string getVendorFunctions();
64 // Removes all the usb functions link in the specified path.
65 int unlinkFunctions(const char *path);
66 // Creates a configfs link for the function.
67 int linkFunction(const char *function, int index);
68 // Sets the USB VID and PID. Returns true on success, false on failure
69 bool setVidPidCommon(const char *vid, const char *pid);
70 // Pulls down USB gadget. Returns true on success, false on failure
71 bool resetGadgetCommon();
72 }  // namespace usb
73 }  // namespace pixel
74 }  // namespace google
75 }  // namespace hardware
76 }  // namespace android
77 
78 #endif  // HARDWARE_GOOGLE_PIXEL_USB_UTILSCOMMON_H_
79