replace common qcom sources with samsung ones

This commit is contained in:
SaschaNes
2025-08-12 22:13:00 +02:00
parent ba24dcded9
commit 6f7753de11
5682 changed files with 2450203 additions and 103634 deletions

View File

@@ -0,0 +1,32 @@
prebuilt_etc {
name: "init.qcom.usb.rc",
src: "init.qcom.usb.rc",
vendor: true,
sub_dir: "init/hw",
}
prebuilt_etc {
name: "init.qti.usb.debug.rc",
src: "init.qti.usb.debug.rc",
vendor: true,
sub_dir: "init",
}
sh_binary {
name: "init.qcom.usb.sh",
src: "init.qcom.usb.sh",
vendor: true,
}
sh_binary {
name: "init.qti.usb.debug.sh",
src: "init.qti.usb.debug.sh",
vendor: true,
}
prebuilt_etc {
name: "init.qti.usb.qmaa.rc",
src: "init.qti.usb.qmaa.rc",
vendor: true,
sub_dir: "init",
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,200 @@
#!/vendor/bin/sh
# Copyright (c) 2012-2018, 2020-2021 The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Changes from Qualcomm Innovation Center are provided under the following license:
# Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
# Set platform variables
soc_hwplatform=`cat /sys/devices/soc0/hw_platform 2> /dev/null`
soc_machine=`cat /sys/devices/soc0/machine 2> /dev/null`
soc_machine=${soc_machine:0:2}
soc_id=`cat /sys/devices/soc0/soc_id 2> /dev/null`
#
# Check ESOC for external modem
#
# Note: currently only a single MDM/SDX is supported
#
esoc_name=`cat /sys/bus/esoc/devices/esoc0/esoc_name 2> /dev/null`
target=`getprop ro.board.platform`
#
# Override USB default composition
#
if [ "$(getprop ro.build.type)" != "user" ]; then
# If USB persist config not set, set default configuration
if [ "$(getprop persist.vendor.usb.config)" == "" ]; then
if [ "$esoc_name" != "" ]; then
setprop persist.vendor.usb.config diag,diag_mdm,qdss,qdss_mdm,serial_cdev,dpl,rmnet,adb
else
case "$(getprop ro.baseband)" in
"apq")
setprop persist.vendor.usb.config diag,adb
;;
*)
case "$soc_hwplatform" in
"Dragon" | "SBC")
setprop persist.vendor.usb.config diag,adb
;;
*)
case "$soc_machine" in
"SA")
setprop persist.vendor.usb.config diag,adb
;;
*)
case "$target" in
"msm8996")
setprop persist.vendor.usb.config diag,serial_cdev,serial_tty,rmnet_ipa,mass_storage,adb
;;
"msm8909")
setprop persist.vendor.usb.config diag,serial_smd,rmnet_qti_bam,adb
;;
"msm8937")
if [ -d /config/usb_gadget ]; then
setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
else
case "$soc_id" in
"313" | "320")
setprop persist.vendor.usb.config diag,serial_smd,rmnet_ipa,adb
;;
*)
setprop persist.vendor.usb.config diag,serial_smd,rmnet_qti_bam,adb
;;
esac
fi
;;
"msm8953")
if [ -d /config/usb_gadget ]; then
setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
else
setprop persist.vendor.usb.config diag,serial_smd,rmnet_ipa,adb
fi
;;
"msm8998" | "sdm660" | "apq8098_latv")
setprop persist.vendor.usb.config diag,serial_cdev,rmnet,adb
;;
"monaco")
setprop persist.vendor.usb.config diag,qdss,rmnet,adb
;;
"sdm845" | "sdm710")
setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
;;
"msmnile" | "sm6150" | "trinket" | "lito" | "atoll" | "bengal" | "lahaina" | "holi" | \
"taro" | "kalama" | "pineapple" | "sun" | "parrot")
#setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,qdss,adb
setprop persist.vendor.usb.config diag,adb
;;
*)
setprop persist.vendor.usb.config diag,adb
;;
esac
;;
esac
;;
esac
;;
esac
fi
fi
else # for user build let persist.sys.usb.config dictate the default composition
setprop persist.vendor.usb.config ""
fi
# This check is needed for GKI 1.0 targets where QDSS is not available
if [ "$(getprop persist.vendor.usb.config)" == "diag,serial_cdev,rmnet,dpl,qdss,adb" -a \
! -d /config/usb_gadget/g1/functions/qdss.qdss ]; then
setprop persist.vendor.usb.config diag,serial_cdev,rmnet,dpl,adb
fi
# Start peripheral mode on primary USB controllers for Automotive platforms
case "$soc_machine" in
"SA")
if [ -f /sys/bus/platform/devices/a600000.ssusb/mode ]; then
default_mode=`cat /sys/bus/platform/devices/a600000.ssusb/mode`
case "$default_mode" in
"none")
echo peripheral > /sys/bus/platform/devices/a600000.ssusb/mode
;;
esac
fi
;;
esac
# check configfs is mounted or not
if [ -d /config/usb_gadget ]; then
machine_type=`cat /sys/devices/soc0/machine`
# Chip ID & serial are used for unique MSM identification in Product String
# If not present, then omit them instead of using 0x00000000
msm_chipid=`cat /sys/devices/soc0/nproduct_id`;
if [ "$msm_chipid" != "" ]; then
msm_chipid_hex=`printf _CID:%04X $msm_chipid`
fi
msm_serial=`cat /sys/devices/soc0/serial_number`;
if [ "$msm_serial" != "" ]; then
msm_serial_hex=`printf _SN:%08X $msm_serial`
fi
setprop vendor.usb.product_string "$machine_type-$soc_hwplatform$msm_chipid_hex$msm_serial_hex"
# ADB requires valid iSerialNumber; if ro.serialno is missing, use dummy
serialnumber=`cat /config/usb_gadget/g1/strings/0x409/serialnumber 2> /dev/null`
if [ "$serialnumber" == "" ]; then
serialno=1234567
echo $serialno > /config/usb_gadget/g1/strings/0x409/serialnumber
fi
setprop vendor.usb.configfs 1
fi
#
# Initialize RNDIS Diag option. If unset, set it to 'none'.
#
diag_extra=`getprop persist.vendor.usb.config.extra`
if [ "$diag_extra" == "" ]; then
setprop persist.vendor.usb.config.extra none
fi
# enable rps cpus on msm8937 target
setprop vendor.usb.rps_mask 0
case "$soc_id" in
"294" | "295" | "353" | "354")
setprop vendor.usb.rps_mask 40
;;
esac
#
# Initialize UVC conifguration.
#
if [ -d /config/usb_gadget/g1/functions/uvc.0 ]; then
setprop vendor.usb.uvc.function.init 1
fi

View File

@@ -0,0 +1,30 @@
# Copyright (c) 2021 The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
on post-fs-data
exec u:r:vendor-qti-testscripts:s0 -- /vendor/bin/sh /vendor/bin/init.qti.usb.debug.sh

View File

@@ -0,0 +1,99 @@
#!/vendor/bin/sh
# Copyright (c) 2021 The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of The Linux Foundation nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# Changes from Qualcomm Innovation Center, Inc. are provided under the following license:
# Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
prop_enabled=`getprop persist.vendor.usb.enable_ftrace 0`
consolidate=$(cat /proc/version | grep -E "(consolidate|debug)")
# bail out if its perf config
if [ "$prop_enabled" == "0" -a "$consolidate" == "" ]; then
return
fi
# Enable various ftrace debugging events for USB
tracefs=/sys/kernel/tracing
if [ -d $tracefs ]; then
cd $tracefs
# global kprobe events
echo 'p:usb_gadget/ config_usb_cfg_link cfg=+0(+0($arg1)):string func=+0(+0($arg2)):string' >> kprobe_events
echo 'r:usb_gadget/ config_usb_cfg_link ret=$retval:s32' >> kprobe_events
echo 'p:usb_gadget/ config_usb_cfg_unlink cfg=+0(+0($arg1)):string func=+0(+0($arg2)):string' >> kprobe_events
echo 'p:usb_gadget/ gadget_dev_desc_UDC_store udc=+0($arg2):string' >> kprobe_events
echo 'r:usb_gadget/ gadget_dev_desc_UDC_store ret=$retval:s32' >> kprobe_events
echo 'p:usb_gadget/ unregister_gadget_item gadget=+0(+0($arg1)):string' >> kprobe_events
# usb instances
mkdir instances/usb
cd instances/usb
# dwc3
echo 1 > events/dwc3/dwc3_complete_trb/enable
echo 1 > events/dwc3/dwc3_ctrl_req/enable
echo 1 > events/dwc3/dwc3_ep_dequeue/enable
echo 1 > events/dwc3/dwc3_ep_queue/enable
echo 1 > events/dwc3/dwc3_gadget_ep_cmd/enable
echo 1 > events/dwc3/dwc3_gadget_ep_disable/enable
echo 1 > events/dwc3/dwc3_gadget_ep_enable/enable
echo 1 > events/dwc3/dwc3_gadget_giveback/enable
echo 1 > events/dwc3/dwc3_prepare_trb/enable
echo 1 > events/dwc3/dwc3_event/enable
# ucsi
echo 1 > events/ucsi/ucsi_connector_change/enable
echo 1 > events/ucsi/ucsi_reset_ppm/enable
echo 1 > events/ucsi/ucsi_run_command/enable
# USB gadget
echo 1 > events/gadget/usb_gadget_disconnect/enable
echo 1 > events/gadget/usb_gadget_connect/enable
echo 1 > events/gadget/usb_gadget_vbus_draw/enable
# usb instance kprobe events
echo 1 > events/usb_gadget/enable
#DWC3 core runtime
echo 'name~"a600000.*"' > events/rpm/filter
echo 1 > events/rpm/rpm_resume/enable
echo 1 > events/rpm/rpm_suspend/enable
echo 1 > events/rpm/rpm_return_int/enable
#xhci
mkdir $tracefs/instances/usb_xhci
echo 1 > $tracefs/instances/usb_xhci/events/xhci-hcd/enable
echo 1 > $tracefs/instances/usb_xhci/tracing_on
echo 1 > tracing_on
fi

View File

@@ -0,0 +1,32 @@
# Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
on init
mount configfs none /config
mkdir /config/usb_gadget/g1 0770
mkdir /config/usb_gadget/g1/strings/0x409 0770
write /config/usb_gadget/g1/bcdUSB 0x0200
write /config/usb_gadget/g1/os_desc/use 1
write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno}
write /config/usb_gadget/g1/strings/0x409/manufacturer ${ro.product.manufacturer}
write /config/usb_gadget/g1/strings/0x409/product ${ro.product.name}
mkdir /config/usb_gadget/g1/functions/ffs.adb
mkdir /config/usb_gadget/g1/configs/b.1 0770
mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770
write /config/usb_gadget/g1/configs/b.1/MaxPower 900
write /config/usb_gadget/g1/os_desc/b_vendor_code 0x1
write /config/usb_gadget/g1/os_desc/qw_sign "MSFT100"
mkdir /dev/usb-ffs 0775 shell system
mkdir /dev/usb-ffs/adb 0770 shell system
mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=1000,rmode=0770,fmode=0660
write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb"
symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
write /config/usb_gadget/g1/idVendor 0x18d1
write /config/usb_gadget/g1/idProduct 0x4ee7
symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1
start adbd
setprop sys.usb.configfs -1
on property:sys.usb.ffs.ready=1
write /config/usb_gadget/g1/UDC ${vendor.usb.controller}
setprop sys.usb.state adb

View File

@@ -0,0 +1,82 @@
cc_defaults {
name: "qti_usb_hal_defaults",
cflags: [
"-Wno-unused-parameter",
"-Wno-unused-variable",
],
vendor: true,
relative_install_path: "hw",
}
cc_binary {
name: "android.hardware.usb-service.qti",
defaults: ["qti_usb_hal_defaults"],
shared_libs: [
"android.hardware.usb-V1-ndk",
"libbase",
"libbinder_ndk",
"libcutils",
"liblog",
"libutils",
],
srcs: [
"Usb.cpp",
],
init_rc: ["android.hardware.usb-service.qti.rc"],
vintf_fragments: ["android.hardware.usb-service.qti.xml"],
}
cc_fuzz {
name: "aidl_fuzz_usb_service",
defaults: ["qti_usb_hal_defaults"],
shared_libs: [
"android.hardware.usb-V1-ndk",
"libbase",
"libbinder_ndk",
"libcutils",
"liblog",
"libutils",
"libbinder",
],
srcs: [
"Usb.cpp",
],
cflags: [
"-D__LIBFUZZON_LOCAL__",
],
static_libs: [
"libbinder_random_parcel",
],
}
cc_binary {
name: "android.hardware.usb.gadget-service.qti",
defaults: ["qti_usb_hal_defaults"],
shared_libs: [
"android.hardware.usb.gadget@1.1",
"android.hardware.usb.gadget-V1-ndk",
"libbase",
"libbinder_ndk",
"libcutils",
"liblog",
"libutils",
],
static_libs: [
"libusbconfigfs"
],
srcs: [
"UsbGadget.cpp",
],
init_rc: ["android.hardware.usb.gadget-service.qti.rc"],
vintf_fragments: ["android.hardware.usb.gadget-service.qti.xml"],
}
prebuilt_etc {
name: "usb_compositions.conf",
src: "usb_compositions.conf",
vendor: true,
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2019-2021, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef ANDROID_HARDWARE_USB_QTI_USB_H
#define ANDROID_HARDWARE_USB_QTI_USB_H
#include <aidl/android/hardware/usb/BnUsb.h>
#include <aidl/android/hardware/usb/BnUsbCallback.h>
#include <condition_variable>
#include <list>
#include <mutex>
#include <thread>
#include <utils/Log.h>
#include <android-base/unique_fd.h>
namespace aidl {
namespace android {
namespace hardware {
namespace usb {
using ::aidl::android::hardware::usb::IUsbCallback;
using ::aidl::android::hardware::usb::PortRole;
using ::android::sp;
using ::android::base::unique_fd;
using ::ndk::ScopedAStatus;
struct Usb : public BnUsb {
Usb();
ScopedAStatus enableContaminantPresenceDetection(const std::string& in_portName,
bool in_enable, int64_t in_transactionId) override;
ScopedAStatus enableUsbData(const std::string& in_portName, bool in_enable,
int64_t in_transactionId) override;
ScopedAStatus enableUsbDataWhileDocked(const std::string& in_portName,
int64_t in_transactionId) override;
ScopedAStatus queryPortStatus(int64_t in_transactionId) override;
ScopedAStatus setCallback(const std::shared_ptr<IUsbCallback>& in_callback) override;
ScopedAStatus switchRole(const std::string& in_portName, const PortRole& in_role,
int64_t in_transactionId) override;
ScopedAStatus limitPowerTransfer(const std::string& in_portName, bool in_limit,
int64_t in_transactionId) override;
ScopedAStatus resetUsbPort(const std::string& in_portName,
int64_t in_transactionId) override;
Status getPortStatusHelper(std::vector<PortStatus> &currentPortStatus,
const std::string &contaminantStatusPath);
std::shared_ptr<IUsbCallback> mCallback;
// Protects mCallback variable
std::mutex mLock;
// Protects roleSwitch operation
std::mutex mRoleSwitchLock;
// Threads waiting for the partner to come back wait here
std::condition_variable mPartnerCV;
// lock protecting mPartnerCV
std::mutex mPartnerLock;
// Variable to signal partner coming back online after type switch
bool mPartnerUp;
// Variable to indicate presence or absence or contaminant
bool mContaminantPresence;
// Variable to indicate presence or absence of wakeup node
bool mIgnoreWakeup;
// Configuration descriptor for MaxPower
std::string mMaxPower;
// Configuration descriptor for bmAttributes
std::string mAttributes;
// Current power operation mode
std::string mPowerOpMode;
// Path to get the status of contaminant presence
std::string mContaminantStatusPath;
// USB bus reset recovery active
int usbResetRecov;
// USB data disabled
bool usbDataDisabled;
// Limit power transfer
bool limitedPower;
// List of connected HID USB devices
std::list <std::string> hidDevs;
private:
std::thread mPoll;
unique_fd mEventFd;
bool switchMode(const std::string &portName, const PortRole &newRole);
void uevent_work();
};
} // namespace usb
} // namespace hardware
} // namespace android
} // namespace aidl
#endif // ANDROID_HARDWARE_USB_QTI_USB_H

View File

@@ -0,0 +1,549 @@
/*
* Copyright (C) 2018-2021, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2023-2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#define LOG_TAG "android.hardware.usb.gadget-service.qti"
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <functional>
#include <map>
#include <tuple>
#include <fstream>
#include <sstream>
#include <dirent.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <UsbGadgetCommon.h>
#include "UsbGadget.h"
#define USB_CONTROLLER_PROP "vendor.usb.controller"
#define DIAG_FUNC_NAME_PROP "vendor.usb.diag.func.name"
#define RNDIS_FUNC_NAME_PROP "vendor.usb.rndis.func.name"
#define RMNET_FUNC_NAME_PROP "vendor.usb.rmnet.func.name"
#define RMNET_INST_NAME_PROP "vendor.usb.rmnet.inst.name"
#define DPL_INST_NAME_PROP "vendor.usb.dpl.inst.name"
#define VENDOR_USB_PROP "vendor.usb.config"
#define PERSIST_VENDOR_USB_PROP "persist.vendor.usb.config"
#define PERSIST_VENDOR_USB_EXTRA_PROP "persist.vendor.usb.config.extra"
#define QDSS_INST_NAME_PROP "vendor.usb.qdss.inst.name"
#define CONFIG_STRING CONFIG_PATH "strings/0x409/configuration"
namespace aidl {
namespace android {
namespace hardware {
namespace usb {
namespace gadget {
using ::android::base::GetProperty;
using ::android::base::SetProperty;
using ::android::base::Trim;
using ::android::base::WriteStringToFile;
using ::android::base::ReadFileToString;
using ::android::hardware::usb::gadget::addAdb;
using ::android::hardware::usb::gadget::kDisconnectWaitUs;
using ::android::hardware::usb::gadget::linkFunction;
using ::android::hardware::usb::gadget::resetGadget;
using ::android::hardware::usb::gadget::setVidPid;
using ::android::hardware::usb::gadget::unlinkFunctions;
static std::map<std::string, std::tuple<std::string, std::string, std::string> >
supported_compositions;
static void createCompositionsMap(std:: string fileName) {
std::ifstream compositions(fileName);
std::string line;
while (std::getline(compositions, line)) {
std::string prop;
std::tuple<std::string, std::string, std::string> vpa;
// Ignore comments in the file
auto pos = line.find('#');
if (pos != std::string::npos)
line.erase(pos);
std::stringstream words(line);
words >> prop >> std::get<0>(vpa) >> std::get<1>(vpa) >> std::get<2>(vpa);
// If we get vpa[1], we have the three minimum values needed. Or else we skip
if (!std::get<1>(vpa).empty())
supported_compositions.insert_or_assign(prop, vpa);
}
}
UsbGadget::UsbGadget(const char* const gadget)
: mCurrentUsbFunctionsApplied(false),
mMonitorFfs(gadget) {
if (access(CONFIG_PATH, R_OK) != 0)
ALOGE("configfs setup not done yet");
createCompositionsMap("/vendor/etc/usb_compositions.conf");
createCompositionsMap("/odm/etc/usb_compositions.conf");
createCompositionsMap("/product/etc/usb_compositions.conf");
}
ScopedAStatus UsbGadget::getCurrentUsbFunctions(
const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) {
if (callback == nullptr)
return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
ScopedAStatus ret = callback->getCurrentUsbFunctionsCb(
mCurrentUsbFunctions,
mCurrentUsbFunctionsApplied ? Status::FUNCTIONS_APPLIED
: Status::FUNCTIONS_NOT_APPLIED,
in_transactionId);
if (!ret.isOk())
ALOGE("Call to getCurrentUsbFunctionsCb failed %s",
ret.getDescription().c_str());
return ScopedAStatus::ok();
}
ScopedAStatus UsbGadget::reset(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) {
if (callback == nullptr)
return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
if (!WriteStringToFile("none", PULLUP_PATH)) {
ALOGE("reset(): unable to clear pullup");
return ScopedAStatus::fromServiceSpecificError(-1);
}
callback->resetCb(Status::SUCCESS, in_transactionId);
return ScopedAStatus::ok();
}
ScopedAStatus UsbGadget::getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) {
if (callback == nullptr)
return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
std::string gadgetName = GetProperty(USB_CONTROLLER_PROP, "");
std::string current_speed;
if (ReadFileToString("/sys/class/udc/" + gadgetName + "/current_speed",
&current_speed)) {
current_speed = Trim(current_speed);
UsbSpeed speed = UsbSpeed::UNKNOWN;
if (current_speed == "low-speed")
speed = UsbSpeed::LOWSPEED;
else if (current_speed == "full-speed")
speed = UsbSpeed::FULLSPEED;
else if (current_speed == "high-speed")
speed = UsbSpeed::HIGHSPEED;
else if (current_speed == "super-speed")
speed = UsbSpeed::SUPERSPEED;
else if (current_speed == "super-speed-plus")
speed = UsbSpeed::SUPERSPEED_10Gb;
callback->getUsbSpeedCb(speed, in_transactionId);
return ScopedAStatus::ok();
}
return ScopedAStatus::fromServiceSpecificError(-1);
}
Status UsbGadget::tearDownGadget() {
if (mMonitorFfs.isMonitorRunning())
mMonitorFfs.reset();
else
ALOGE("mMonitor not running");
if (resetGadget() != ::android::hardware::usb::gadget::V1_0::Status::SUCCESS)
return Status::ERROR;
if (remove(OS_DESC_PATH))
ALOGI("Unable to remove file %s errno:%d", OS_DESC_PATH, errno);
return Status::SUCCESS;
}
static std::string rndisFuncname() {
std::string rndisFunc = GetProperty(RNDIS_FUNC_NAME_PROP, "");
if (rndisFunc.empty()) {
return "rndis";
}
return rndisFunc + ".rndis";
}
static std::string qdssFuncname(const char *debug) {
auto qdss = "qdss." + GetProperty(QDSS_INST_NAME_PROP, "qdss");
auto debug_iface = FUNCTIONS_PATH + qdss + "/enable_debug_inface";
WriteStringToFile(debug, debug_iface.c_str());
return qdss;
}
static std::map<std::string, std::function<std::string()> > supported_funcs {
{ "adb", [](){ return "ffs.adb"; } },
{ "ccid", [](){ return "ccid.ccid"; } },
{ "diag", [](){ return GetProperty(DIAG_FUNC_NAME_PROP, "diag") + ".diag"; } },
{ "diag_cnss", [](){ return GetProperty(DIAG_FUNC_NAME_PROP, "diag") + ".diag_mdm2"; } },
{ "diag_mdm2", [](){ return GetProperty(DIAG_FUNC_NAME_PROP, "diag") + ".diag_mdm2"; } },
{ "diag_mdm", [](){ return GetProperty(DIAG_FUNC_NAME_PROP, "diag") + ".diag_mdm"; } },
{ "dpl", [](){ return GetProperty(RMNET_FUNC_NAME_PROP, "gsi") + "." + GetProperty(DPL_INST_NAME_PROP, "dpl"); } },
{ "mass_storage", [](){ return "mass_storage.0"; } },
{ "mtp", [](){ return "ffs.mtp"; } },
{ "ncm", [](){ return "ncm.0"; } },
{ "ptp", [](){ return "ffs.ptp"; } },
{ "qdss", [](){ return qdssFuncname("0"); } },
{ "qdss_debug", [](){ return qdssFuncname("1"); } },
{ "qdss_mdm", [](){ return "qdss.qdss_mdm"; } },
{ "rmnet", [](){ return GetProperty(RMNET_FUNC_NAME_PROP, "gsi") + "." + GetProperty(RMNET_INST_NAME_PROP, "rmnet"); } },
{ "rndis", rndisFuncname },
{ "serial_cdev", [](){ return "cser.dun.0"; } },
{ "serial_cdev_nmea", [](){ return "cser.nmea.1"; } },
{ "serial_cdev_mdm", [](){ return "cser.dun.2"; } },
{ "uac2", [](){ return "uac2.0"; } },
{ "uvc", [](){ return "uvc.0"; } },
};
int UsbGadget::addFunctionsFromPropString(std::string prop, bool &ffsEnabled, int &i) {
if (!supported_compositions.count(prop)) {
ALOGE("Composition \"%s\" unsupported", prop.c_str());
return -1;
}
auto [vid, pid, actual_order] = supported_compositions[prop];
ALOGE("vid %s pid %s", vid.c_str(), pid.c_str());
// some compositions differ from the order given in the property string
// e.g. ADB may appear somewhere in the middle instead of being last
if (!actual_order.empty())
prop = actual_order;
WriteStringToFile(prop, CONFIG_STRING);
// tokenize the prop string and add each function individually
for (size_t start = 0; start != std::string::npos; ) {
size_t end = prop.find_first_of(',', start);
std::string funcname;
if (end == std::string::npos) {
funcname = prop.substr(start, prop.length() - start);
start = end;
} else {
funcname = prop.substr(start, end - start);
start = end + 1;
}
if (!supported_funcs.count(funcname)) {
ALOGE("Function \"%s\" unsupported", funcname.c_str());
return -1;
}
ALOGI("Adding %s", funcname.c_str());
if (funcname == "adb") {
if (addAdb(&mMonitorFfs, &i) != ::android::hardware::usb::gadget::V1_0::Status::SUCCESS)
return -1;
ffsEnabled = true;
} else if (linkFunction(supported_funcs[funcname]().c_str(), i))
return -1;
// Set Diag PID for QC DLOAD mode
if (i == 0 && !strcasecmp(vid.c_str(), "0x05c6") && funcname == "diag")
WriteStringToFile(pid, FUNCTIONS_PATH "diag.diag/pid");
++i;
}
if (setVidPid(vid.c_str(), pid.c_str()) != ::android::hardware::usb::gadget::V1_0::Status::SUCCESS)
return -1;
return 0;
}
static Status validateAndSetVidPid(uint64_t functions) {
::android::hardware::usb::gadget::V1_0::Status ret =
::android::hardware::usb::gadget::V1_0::Status::SUCCESS;
switch (functions) {
case static_cast<uint64_t>(GadgetFunction::ADB):
ret = setVidPid("0x18d1", "0x4e11");
break;
case static_cast<uint64_t>(GadgetFunction::MTP):
ret = setVidPid("0x18d1", "0x4ee1");
break;
case GadgetFunction::ADB | GadgetFunction::MTP:
ret = setVidPid("0x18d1", "0x4ee2");
break;
case static_cast<uint64_t>(GadgetFunction::RNDIS):
ret = setVidPid("0x18d1", "0x4ee3");
break;
case GadgetFunction::ADB | GadgetFunction::RNDIS:
ret = setVidPid("0x18d1", "0x4ee4");
break;
case static_cast<uint64_t>(GadgetFunction::PTP):
ret = setVidPid("0x18d1", "0x4ee5");
break;
case GadgetFunction::ADB | GadgetFunction::PTP:
ret = setVidPid("0x18d1", "0x4ee6");
break;
case static_cast<uint64_t>(GadgetFunction::MIDI):
ret = setVidPid("0x18d1", "0x4ee8");
break;
case GadgetFunction::ADB | GadgetFunction::MIDI:
ret = setVidPid("0x18d1", "0x4ee9");
break;
case static_cast<uint64_t>(GadgetFunction::ACCESSORY):
ret = setVidPid("0x18d1", "0x2d00");
break;
case GadgetFunction::ADB | GadgetFunction::ACCESSORY:
ret = setVidPid("0x18d1", "0x2d01");
break;
case static_cast<uint64_t>(GadgetFunction::AUDIO_SOURCE):
ret = setVidPid("0x18d1", "0x2d02");
break;
case GadgetFunction::ADB | GadgetFunction::AUDIO_SOURCE:
ret = setVidPid("0x18d1", "0x2d03");
break;
case GadgetFunction::ACCESSORY | GadgetFunction::AUDIO_SOURCE:
ret = setVidPid("0x18d1", "0x2d04");
break;
case GadgetFunction::ADB | GadgetFunction::ACCESSORY |
GadgetFunction::AUDIO_SOURCE:
ret = setVidPid("0x18d1", "0x2d05");
break;
case static_cast<uint64_t>(GadgetFunction::NCM):
ret = setVidPid("0x18d1", "0x4eeb");
break;
case GadgetFunction::ADB | GadgetFunction::NCM:
ret = setVidPid("0x18d1", "0x4eec");
break;
case GadgetFunction::UVC:
ret = setVidPid("0x18d1", "0x4eed");
break;
case GadgetFunction::ADB | GadgetFunction::UVC:
ret = setVidPid("0x18d1", "0x4eee");
break;
default:
ALOGE("Combination not supported");
ret = ::android::hardware::usb::gadget::V1_0::Status::CONFIGURATION_NOT_SUPPORTED;
}
return static_cast<Status>(ret);
}
Status UsbGadget::setupFunctions(
int64_t functions, const shared_ptr<IUsbGadgetCallback> &callback,
int64_t timeout, int64_t in_transactionId) {
bool ffsEnabled = false;
int i = 0;
std::string gadgetName = GetProperty(USB_CONTROLLER_PROP, "");
std::string vendorProp = GetProperty(VENDOR_USB_PROP, GetProperty(PERSIST_VENDOR_USB_PROP, ""));
std::string vendorExtraProp = GetProperty(PERSIST_VENDOR_USB_EXTRA_PROP, "none");
if (gadgetName.empty()) {
ALOGE("UDC name not defined");
return Status::ERROR;
}
if (((functions & GadgetFunction::RNDIS) != 0) ||
((functions & GadgetFunction::NCM) != 0)) {
ALOGI("setCurrentUsbFunctions rndis");
std::string tetherComp = (functions & GadgetFunction::RNDIS) ? "rndis" : "ncm";
if (vendorExtraProp != "none")
tetherComp += "," + vendorExtraProp;
if (functions & GadgetFunction::ADB)
tetherComp += ",adb";
if (addFunctionsFromPropString(tetherComp, ffsEnabled, i))
return Status::ERROR;
} else if (functions == static_cast<uint64_t>(GadgetFunction::ADB) &&
!vendorProp.empty() && vendorProp != "adb") {
// override adb-only with additional QTI functions if vendor.usb.config
// or persist.vendor.usb.config is set
// tack on ADB to the property string if not there, since we only arrive
// here if "USB debugging enabled" is chosen which implies ADB
if (vendorProp.find("adb") == std::string::npos)
vendorProp += ",adb";
ALOGI("setting composition from %s: %s", VENDOR_USB_PROP,
vendorProp.c_str());
// look up & parse prop string and link each function into the composition
if (addFunctionsFromPropString(vendorProp, ffsEnabled, i)) {
// if failed just fall back to adb-only
unlinkFunctions(CONFIG_PATH);
i = 0;
ffsEnabled = true;
if (addAdb(&mMonitorFfs, &i) != ::android::hardware::usb::gadget::V1_0::Status::SUCCESS)
return Status::ERROR;
}
} else { // standard Android supported functions
WriteStringToFile("android", CONFIG_STRING);
if ((functions & GadgetFunction::UVC) == 0) {
if (addGenericAndroidFunctions(&mMonitorFfs, functions, &ffsEnabled, &i)
!= ::android::hardware::usb::gadget::V1_0::Status::SUCCESS)
return Status::ERROR;
} else {
ALOGI("setCurrentUsbFunctions uvc");
if (linkFunction("uvc.0", i++)) {
return Status::ERROR;
}
}
if ((functions & GadgetFunction::ADB) != 0) {
ffsEnabled = true;
if (addAdb(&mMonitorFfs, &i) != ::android::hardware::usb::gadget::V1_0::Status::SUCCESS)
return Status::ERROR;
}
}
if (functions & (GadgetFunction::ADB | GadgetFunction::MTP | GadgetFunction::PTP)) {
if (symlink(CONFIG_PATH, OS_DESC_PATH)) {
ALOGE("Cannot create symlink %s -> %s errno:%d", CONFIG_PATH, OS_DESC_PATH, errno);
return Status::ERROR;
}
}
// Pull up the gadget right away when there are no ffs functions.
if (!ffsEnabled) {
if (!WriteStringToFile(gadgetName, PULLUP_PATH)) return Status::ERROR;
mCurrentUsbFunctionsApplied = true;
if (callback)
callback->setCurrentUsbFunctionsCb(functions, Status::SUCCESS,
in_transactionId);
ALOGI("Gadget pullup without FFS fuctions");
return Status::SUCCESS;
}
// Monitors the ffs paths to pull up the gadget when descriptors are written.
// Also takes of the pulling up the gadget again if the userspace process
// dies and restarts.
mMonitorFfs.registerFunctionsAppliedCallback(
[](bool functionsApplied, void *payload) {
((UsbGadget*)payload)->mCurrentUsbFunctionsApplied = functionsApplied;
}, this);
mMonitorFfs.startMonitor();
ALOGI("Started monitor for FFS functions");
if (callback) {
bool gadgetPullup = mMonitorFfs.waitForPullUp(timeout);
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(
functions, gadgetPullup ? Status::SUCCESS : Status::ERROR,
in_transactionId);
if (!ret.isOk())
ALOGE("setCurrentUsbFunctionsCb error %s", ret.getDescription().c_str());
}
return Status::SUCCESS;
}
ScopedAStatus UsbGadget::setCurrentUsbFunctions(int64_t functions,
const shared_ptr<IUsbGadgetCallback> &callback,
int64_t timeout, int64_t in_transactionId) {
std::unique_lock<std::mutex> lk(mLockSetCurrentFunction);
mCurrentUsbFunctions = functions;
mCurrentUsbFunctionsApplied = false;
// Unlink the gadget and stop the monitor if running.
Status status = tearDownGadget();
if (status != Status::SUCCESS) {
goto error;
}
// Leave the gadget pulled down to give time for the host to sense disconnect.
usleep(kDisconnectWaitUs);
if (functions == static_cast<uint64_t>(GadgetFunction::NONE)) {
if (callback == nullptr)
return ScopedAStatus::fromExceptionCode(EX_NULL_POINTER);
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions,
Status::SUCCESS,
in_transactionId);
if (!ret.isOk())
ALOGE("Error while calling setCurrentUsbFunctionsCb %s",
ret.getDescription().c_str());
return ret;
}
status = validateAndSetVidPid(functions);
if (status != Status::SUCCESS) {
goto error;
}
status = setupFunctions(functions, callback, timeout, in_transactionId);
if (status != Status::SUCCESS) {
goto error;
}
ALOGI("Usb Gadget setcurrent functions called successfully");
return ScopedAStatus::ok();
error:
ALOGI("Usb Gadget setcurrent functions failed");
if (callback == nullptr)
return ScopedAStatus::fromServiceSpecificErrorWithMessage(-1,
"Usb Gadget setcurrent functions failed");
ScopedAStatus ret = callback->setCurrentUsbFunctionsCb(functions, status, in_transactionId);
if (!ret.isOk()) {
ALOGE("Error while calling setCurrentUsbFunctionsCb %s",
ret.getDescription().c_str());
return ret;
}
return ScopedAStatus::fromServiceSpecificErrorWithMessage(-1,
"Usb Gadget setcurrent functions failed");
}
} // namespace gadget
} // namespace usb
} // namespace hardware
} // namespace android
} // namespace aidl
int main() {
using android::base::GetProperty;
using ::aidl::android::hardware::usb::gadget::UsbGadget;
std::string gadgetName = GetProperty("persist.vendor.usb.controller",
GetProperty(USB_CONTROLLER_PROP, ""));
if (gadgetName.empty()) {
ALOGE("UDC name not defined");
return -1;
}
ABinderProcess_setThreadPoolMaxThreadCount(0);
std::shared_ptr<UsbGadget> usb = ndk::SharedRefBase::make<UsbGadget>(gadgetName.c_str());
const std::string instance = std::string(UsbGadget::descriptor) + "/default";
binder_status_t status = AServiceManager_addService(usb->asBinder().get(), instance.c_str());
CHECK(status == STATUS_OK);
ALOGI("QTI USB Gadget HAL Ready.");
ABinderProcess_joinThreadPool();
return -1; // Should never be reached
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright (C) 2018,2020-2021, The Linux Foundation. All rights reserved.
* Not a Contribution.
*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Changes from Qualcomm Innovation Center are provided under the following license:
* Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef ANDROID_HARDWARE_USB_GADGET_QTI_USBGADGET_H
#define ANDROID_HARDWARE_USB_GADGET_QTI_USBGADGET_H
#include <aidl/android/hardware/usb/gadget/BnUsbGadget.h>
#include <aidl/android/hardware/usb/gadget/BnUsbGadgetCallback.h>
#include <aidl/android/hardware/usb/gadget/GadgetFunction.h>
#include <aidl/android/hardware/usb/gadget/IUsbGadget.h>
#include <aidl/android/hardware/usb/gadget/IUsbGadgetCallback.h>
#include <mutex>
namespace aidl {
namespace android {
namespace hardware {
namespace usb {
namespace gadget {
using ::aidl::android::hardware::usb::gadget::GadgetFunction;
using ::aidl::android::hardware::usb::gadget::IUsbGadgetCallback;
using ::aidl::android::hardware::usb::gadget::IUsbGadget;
using ::aidl::android::hardware::usb::gadget::Status;
using ::aidl::android::hardware::usb::gadget::UsbSpeed;
using ::android::hardware::Return;
using ::android::hardware::usb::gadget::MonitorFfs;
using ::ndk::ScopedAStatus;
using ::std::shared_ptr;
struct UsbGadget : public BnUsbGadget {
UsbGadget(const char* const gadget);
ScopedAStatus setCurrentUsbFunctions(int64_t functions,
const shared_ptr<IUsbGadgetCallback> &callback,
int64_t timeoutMs, int64_t in_transactionId) override;
ScopedAStatus getCurrentUsbFunctions(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) override;
ScopedAStatus reset(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) override;
ScopedAStatus getUsbSpeed(const shared_ptr<IUsbGadgetCallback> &callback,
int64_t in_transactionId) override;
private:
Status tearDownGadget();
Status setupFunctions(int64_t functions,
const shared_ptr<IUsbGadgetCallback> &callback,
int64_t timeout, int64_t in_transactionId);
int addFunctionsFromPropString(std::string prop, bool &ffsEnabled, int &i);
MonitorFfs mMonitorFfs;
// Makes sure that only one request is processed at a time.
std::mutex mLockSetCurrentFunction;
uint64_t mCurrentUsbFunctions;
bool mCurrentUsbFunctionsApplied;
};
} // namespace gadget
} // namespace usb
} // namespace hardware
} // namespace android
} // namespace aidl
#endif // ANDROID_HARDWARE_USB_GADGET_QTI_USBGADGET_H

View File

@@ -0,0 +1,7 @@
# Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
service vendor.usb-hal /vendor/bin/hw/android.hardware.usb-service.qti
class hal
user system
group system mtp usb

View File

@@ -0,0 +1,13 @@
<!-- Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause-Clear
-->
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.usb</name>
<version>1</version>
<interface>
<name>IUsb</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

View File

@@ -0,0 +1,7 @@
# Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause-Clear
service vendor.usbgadget-hal /vendor/bin/hw/android.hardware.usb.gadget-service.qti
class hal
user system
group system mtp usb

View File

@@ -0,0 +1,13 @@
<!-- Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause-Clear
-->
<manifest version="1.0" type="device">
<hal format="aidl">
<name>android.hardware.usb.gadget</name>
<version>1</version>
<interface>
<name>IUsbGadget</name>
<instance>default</instance>
</interface>
</hal>
</manifest>

View File

@@ -0,0 +1,74 @@
# /vendor/etc/usb_compositions.conf: HSUSB VID PID supported compositions
#
# This file lists the vendor supported vid-pid compositions for HSUSB that are
# referenced in UsbGadget.cpp. Use the specified format below for compositions,
# where right-most column is the actual order of properties; these are few
# cases where adb does not appear in the end of the composition
#
# <properties> <vid> <pid> <actual order of properties>
mass_storage 0x05C6 0xF000
mass_storage,adb 0x05C6 0x9015 adb,mass_storage
diag,adb 0x05C6 0x901D
diag,adb,serial_cdev 0x05C6 0x901F
diag 0x05C6 0x900E
diag,serial_cdev,rmnet,adb 0x05C6 0x9091
diag,serial_cdev,rmnet 0x05C6 0x9092
rndis 0x05C6 0xF00E
diag,serial_cdev,serial_cdev_nmea,adb 0x05c6 0x9020 diag,adb,serial_cdev,serial_cdev_nmea
rndis,adb 0x05C6 0x9024
rndis,diag 0x05C6 0x902C
rndis,diag,adb 0x05C6 0x902D
rndis,serial_cdev 0x05C6 0x90B3
rndis,serial_cdev,adb 0x05C6 0x90B4
rndis,serial_cdev,diag 0x05C6 0x90B5
rndis,serial_cdev,diag,adb 0x05C6 0x90B6
mtp,diag 0x05C6 0x901B
mtp,diag,adb 0x05C6 0x903A
diag,qdss 0x05C6 0x904A diag,qdss_debug
diag,qdss,adb 0x05C6 0x9060 diag,qdss_debug,adb
rndis,diag,qdss 0x05C6 0x9081 rndis,diag,qdss_debug
rndis,diag,qdss,adb 0x05C6 0x9082 rndis,diag,qdss_debug,adb
diag,qdss,rmnet 0x05C6 0x9083 diag,qdss_debug,rmnet
diag,qdss,rmnet,adb 0x05C6 0x9084 diag,qdss_debug,adb,rmnet
ncm 0x05C6 0xA4A1
ncm,adb 0x05C6 0x908C
diag,serial_cdev 0x05C6 0x9004
diag,serial_cdev,rmnet,dpl 0x05C6 0x90B7
diag,serial_cdev,rmnet,dpl,adb 0x05C6 0x90B8
rndis,diag,dpl 0x05C6 0x90BF
rndis,diag,dpl,adb 0x05C6 0x90C0
ccid 0x05C6 0x90CE
ccid,adb 0x05C6 0x90CF
ccid,diag 0x05C6 0x90D0
ccid,diag,adb 0x05C6 0x90D1
diag,serial_cdev,rmnet,ccid 0x05C6 0x90D2
diag,serial_cdev,rmnet,ccid,adb 0x05C6 0x90D3
diag,diag_mdm,qdss,qdss_mdm,serial_cdev,serial_cdev_mdm,rmnet 0x05C6 0x90D7
diag,diag_mdm,qdss,qdss_mdm,serial_cdev,serial_cdev_mdm,rmnet,adb 0x05C6 0x90D8
diag,diag_mdm,qdss,qdss_mdm,serial_cdev,serial_cdev_mdm,dpl,rmnet 0x05C6 0x90DD
diag,diag_mdm,qdss,qdss_mdm,serial_cdev,serial_cdev_mdm,dpl,rmnet,adb 0x05C6 0x90DE
diag,serial_cdev,rmnet,dpl,qdss 0x05C6 0x90DC
diag,serial_cdev,rmnet,dpl,qdss,adb 0x05C6 0x90DB
diag,uac2,adb 0x05C6 0x90CA diag,adb,uac2
diag,uac2 0x05C6 0x901C
diag,uvc,adb 0x05C6 0x90CB diag,adb,uvc
diag,uvc 0x05C6 0x90DF
diag,uac2,uvc,adb 0x05C6 0x90CC diag,adb,uac2,uvc
diag,uac2,uvc 0x05C6 0x90E0
diag,diag_mdm,qdss,qdss_mdm,serial_cdev,dpl,rmnet 0x05C6 0x90E4
diag,diag_mdm,qdss,qdss_mdm,serial_cdev,dpl,rmnet,adb 0x05C6 0x90E5
rndis,diag,diag_mdm,qdss,qdss_mdm,serial_cdev,dpl 0x05C6 0x90E6
rndis,diag,diag_mdm,qdss,qdss_mdm,serial_cdev,dpl,adb 0x05C6 0x90E7
rndis,diag,qdss,serial_cdev,dpl 0x05C6 0x90E8
rndis,diag,qdss,serial_cdev,dpl,adb 0x05C6 0x90E9
diag,diag_mdm,adb 0x05C6 0x90D9
diag,diag_mdm,diag_mdm2,qdss,qdss_mdm,serial_cdev,dpl,rmnet 0x05C6 0x90F6
diag,diag_mdm,diag_mdm2,qdss,qdss_mdm,serial_cdev,dpl,rmnet,adb 0x05C6 0x90F7
rndis,diag,diag_mdm,diag_mdm2,qdss,qdss_mdm,serial_cdev,dpl 0x05C6 0x90F8
rndis,diag,diag_mdm,diag_mdm2,qdss,qdss_mdm,serial_cdev,dpl,adb 0x05C6 0x90F9
diag,diag_mdm,adb,ccid 0x05C6 0x9044 diag,diag_mdm,adb,ccid
diag,diag_mdm,qdss_mdm,dpl,adb 0x05C6 0x90FF
diag,qdss,dpl,adb 0x05C6 0x9104
diag,dpl 0x05C6 0x9105
diag,diag_cnss,serial_cdev,rmnet,dpl,qdss,adb 0x05C6 0x9110
diag,diag_cnss,serial_cdev,rmnet,dpl,qdss 0x05C6 0x9111

View File

@@ -0,0 +1,71 @@
#
# Default property overrides for various function configurations
# These can be further overridden at runtime in init*.rc files as needed
#
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.rndis.func.name=gsi
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.rmnet.func.name=gsi
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.rmnet.inst.name=rmnet
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.dpl.inst.name=dpl
ifneq ($(filter blair monaco,$(TARGET_BOARD_PLATFORM)),)
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.controller=4e00000.dwc3
else
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.controller=a600000.dwc3
endif
# QDSS uses SW path on these targets
ifneq ($(filter lahaina taro blair kalama pineapple sun parrot monaco,$(TARGET_BOARD_PLATFORM)),)
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.qdss.inst.name=qdss_sw
else
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.qdss.inst.name=qdss
endif
ifeq ($(TARGET_HAS_DIAG_ROUTER),true)
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.diag.func.name=ffs
else
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.diag.func.name=diag
endif
ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),4.9 4.14 4.19))
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_ffs_mtp=1
PRODUCT_PROPERTY_OVERRIDES += sys.usb.mtp.batchcancel=1
else
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_ffs_mtp=0
endif
ifneq ($(TARGET_KERNEL_VERSION),$(filter $(TARGET_KERNEL_VERSION),4.9 4.14))
PRODUCT_PACKAGES += android.hardware.usb-service.qti
endif
PRODUCT_VENDOR_PROPERTIES += ro.usb.uvc.enabled=true
USB_USES_QMAA = $(TARGET_USES_QMAA)
ifeq ($(TARGET_USES_QMAA_OVERRIDE_USB),true)
USB_USES_QMAA = false
endif
# USB init scripts
ifeq ($(USB_USES_QMAA),true)
PRODUCT_PACKAGES += init.qti.usb.qmaa.rc
else
PRODUCT_PACKAGES += init.qcom.usb.rc init.qcom.usb.sh
#
# USB Gadget HAL is enabled on newer targets and takes the place
# of the init-based configfs rules for setting USB compositions
#
# ifneq ($(filter taro kalama pineapple sun parrot monaco,$(TARGET_BOARD_PLATFORM)),)
# PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_gadget_hal=1
# PRODUCT_PACKAGES += android.hardware.usb.gadget-service.qti
# PRODUCT_PACKAGES += usb_compositions.conf
# else
PRODUCT_PROPERTY_OVERRIDES += vendor.usb.use_gadget_hal=0
# endif
endif
# additional debugging on userdebug/eng builds
ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT)))
PRODUCT_PACKAGES += init.qti.usb.debug.sh
PRODUCT_PACKAGES += init.qti.usb.debug.rc
endif