diff --git a/init.hardware.diag.rc.userdebug b/init.hardware.diag.rc.userdebug index 1f44c84c..8db3cec6 100644 --- a/init.hardware.diag.rc.userdebug +++ b/init.hardware.diag.rc.userdebug @@ -92,3 +92,9 @@ on property:persist.bluetooth.btsnoopenable=true on property:persist.bluetooth.btsnoopenable=false setprop persist.service.bdroid.soclog false + +on property:vendor.usb.config=* + start usbd + +on property:persist.vendor.usb.usbradio.config=* + start usbd diff --git a/usb/UsbGadget.cpp b/usb/UsbGadget.cpp index 3ba0394e..56447458 100644 --- a/usb/UsbGadget.cpp +++ b/usb/UsbGadget.cpp @@ -32,6 +32,7 @@ constexpr int EPOLL_EVENTS = 10; constexpr bool DEBUG = false; constexpr int DISCONNECT_WAIT_US = 10000; +#define BUILD_TYPE "ro.build.type" #define GADGET_PATH "/config/usb_gadget/g1/" #define PULLUP_PATH GADGET_PATH "UDC" #define GADGET_NAME "a800000.dwc3" @@ -49,6 +50,9 @@ constexpr int DISCONNECT_WAIT_US = 10000; #define FUNCTION_PATH CONFIG_PATH FUNCTION_NAME #define RNDIS_PATH FUNCTIONS_PATH "gsi.rndis" +#define PERSISTENT_VENDOR_CONFIG "persist.vendor.usb.usbradio.config" +#define VENDOR_CONFIG "vendor.usb.config" + namespace android { namespace hardware { namespace usb { @@ -165,10 +169,8 @@ static void *monitorFfs(void *param) { } UsbGadget::UsbGadget() - : mMonitorCreated(false), - mCurrentUsbFunctionsApplied(false) { - if (access(OS_DESC_PATH, R_OK) != 0) - ALOGE("configfs setup not done yet"); + : mMonitorCreated(false), mCurrentUsbFunctionsApplied(false) { + if (access(OS_DESC_PATH, R_OK) != 0) ALOGE("configfs setup not done yet"); } static int unlinkFunctions(const char *path) { @@ -277,40 +279,115 @@ static V1_0::Status setVidPid(const char *vid, const char *pid) { return Status::SUCCESS; } +static std::string getVendorFunctions() { + if (GetProperty(BUILD_TYPE, "") == "user") return "user"; + + std::string bootMode = GetProperty(PERSISTENT_BOOT_MODE, ""); + std::string persistVendorFunctions = + GetProperty(PERSISTENT_VENDOR_CONFIG, ""); + std::string vendorFunctions = GetProperty(VENDOR_CONFIG, ""); + std::string ret = ""; + + if (vendorFunctions != "") { + ret = vendorFunctions; + } else if (bootMode == "usbradio") { + if (persistVendorFunctions != "") + ret = persistVendorFunctions; + else + ret = "diag"; + // vendor.usb.config will reflect the current configured functions + SetProperty(VENDOR_CONFIG, ret); + } + + return ret; +} + static V1_0::Status validateAndSetVidPid(uint64_t functions) { V1_0::Status ret = Status::SUCCESS; + std::string vendorFunctions = getVendorFunctions(); + switch (functions) { case static_cast(GadgetFunction::MTP): - ret = setVidPid("0x18d1", "0x4ee1"); + if (vendorFunctions == "diag") { + ret = setVidPid("0x05C6", "0x901B"); + } else { + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = setVidPid("0x18d1", "0x4ee1"); + } break; case GadgetFunction::ADB | GadgetFunction::MTP: - ret = setVidPid("0x18d1", "0x4ee2"); + if (vendorFunctions == "diag") { + ret = setVidPid("0x05C6", "0x903A"); + } else { + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = setVidPid("0x18d1", "0x4ee2"); + } break; case static_cast(GadgetFunction::RNDIS): - ret = setVidPid("0x18d1", "0x4ee3"); + if (vendorFunctions == "diag") { + ret = setVidPid("0x05C6", "0x902C"); + } else if (vendorFunctions == "serial_cdev,diag") { + ret = setVidPid("0x05C6", "0x90B5"); + } else { + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = setVidPid("0x18d1", "0x4ee3"); + } break; case GadgetFunction::ADB | GadgetFunction::RNDIS: - ret = setVidPid("0x18d1", "0x4ee4"); + if (vendorFunctions == "diag") { + ret = setVidPid("0x05C6", "0x902D"); + } else if (vendorFunctions == "serial_cdev,diag") { + ret = setVidPid("0x05C6", "0x90B6"); + } else { + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = setVidPid("0x18d1", "0x4ee4"); + } break; case static_cast(GadgetFunction::PTP): + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ret = setVidPid("0x18d1", "0x4ee5"); break; case GadgetFunction::ADB | GadgetFunction::PTP: + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ret = setVidPid("0x18d1", "0x4ee6"); break; case static_cast(GadgetFunction::ADB): - ret = setVidPid("0x18d1", "0x4ee7"); + if (vendorFunctions == "diag") { + ret = setVidPid("0x05C6", "0x901D"); + } else if (vendorFunctions == "diag,serial_cdev,rmnet_gsi") { + ret = setVidPid("0x05C6", "0x9091"); + } else if (vendorFunctions == "diag,serial_cdev") { + ret = setVidPid("0x05C6", "0x901F"); + } else { + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); + ret = setVidPid("0x18d1", "0x4ee7"); + } break; case static_cast(GadgetFunction::MIDI): + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ret = setVidPid("0x18d1", "0x4ee8"); break; case GadgetFunction::ADB | GadgetFunction::MIDI: + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ret = setVidPid("0x18d1", "0x4ee9"); break; case static_cast(GadgetFunction::ACCESSORY): + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ret = setVidPid("0x18d1", "0x2d00"); break; case GadgetFunction::ADB | GadgetFunction::ACCESSORY: + if (!(vendorFunctions == "user" || vendorFunctions == "")) + ALOGE("Invalid vendorFunctions set: %s", vendorFunctions.c_str()); ret = setVidPid("0x18d1", "0x2d01"); break; default: @@ -343,7 +420,6 @@ V1_0::Status UsbGadget::setupFunctions( if (inotify_add_watch(inotifyFd, "/dev/usb-ffs/mtp/", IN_ALL_EVENTS) == -1) return Status::ERROR; - if (linkFunction("ffs.mtp", i++)) return Status::ERROR; // Add endpoints to be monitored. @@ -369,7 +445,7 @@ V1_0::Status UsbGadget::setupFunctions( if ((functions & GadgetFunction::MIDI) != 0) { ALOGI("setCurrentUsbFunctions MIDI"); - if (linkFunction("midi.gs5", i++)) return Status::ERROR;; + if (linkFunction("midi.gs5", i++)) return Status::ERROR; } if ((functions & GadgetFunction::ACCESSORY) != 0) { @@ -382,11 +458,19 @@ V1_0::Status UsbGadget::setupFunctions( if (linkFunction("gsi.rndis", i++)) return Status::ERROR; } - if (bootMode == "usbradio") { + std::string vendorFunctions = getVendorFunctions(); + if (vendorFunctions != "") { ALOGI("enable usbradio debug functions"); - if (linkFunction("diag.diag", i++)) return Status::ERROR; - if (linkFunction("cser.dun.0", i++)) return Status::ERROR; - if (linkFunction("gsi.rmnet", i++)) return Status::ERROR; + char *function = strtok(const_cast(vendorFunctions.c_str()), ","); + while (function != NULL) { + if (string(function) == "diag" && linkFunction("diag.diag", i++)) + return Status::ERROR; + if (string(function) == "serial_cdev" && linkFunction("cser.dun.0", i++)) + return Status::ERROR; + if (string(function) == "rmnet_gsi" && linkFunction("gsi.rmnet", i++)) + return Status::ERROR; + function = strtok(NULL, ","); + } } if ((functions & GadgetFunction::ADB) != 0) { diff --git a/usb/UsbGadget.h b/usb/UsbGadget.h index ef2ea4dc..9a2c4dd3 100644 --- a/usb/UsbGadget.h +++ b/usb/UsbGadget.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,7 @@ namespace implementation { using ::android::sp; using ::android::base::GetProperty; +using ::android::base::SetProperty; using ::android::base::unique_fd; using ::android::base::WriteStringToFile; using ::android::hardware::hidl_array;