# Copyright (c) 2011-2016, 2018-2020 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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 init
    mount configfs none /config
    mkdir /config/usb_gadget/g1 0775
    mkdir /config/usb_gadget/g2 0770
    mkdir /config/usb_gadget/g1/strings/0x409 0770
    mkdir /config/usb_gadget/g2/strings/0x409 0770
    write /config/usb_gadget/g1/bcdUSB 0x0200
    write /config/usb_gadget/g2/bcdUSB 0x0200
    write /config/usb_gadget/g1/os_desc/use 1
    mkdir /config/usb_gadget/g1/functions/usbnet.usb0
    mkdir /config/usb_gadget/g1/functions/mass_storage.0
    mkdir /config/usb_gadget/g1/functions/mtp.gs0
    mkdir /config/usb_gadget/g1/functions/ptp.gs1
    mkdir /config/usb_gadget/g1/functions/accessory.gs2
    mkdir /config/usb_gadget/g1/functions/audio_source.gs3
    mkdir /config/usb_gadget/g1/functions/midi.gs5
    mkdir /config/usb_gadget/g1/functions/ffs.adb
    mkdir /config/usb_gadget/g1/functions/mtk_rndis.gs4
    mkdir /config/usb_gadget/g1/functions/acm.gs0
    mkdir /config/usb_gadget/g1/functions/acm.gs1
    mkdir /config/usb_gadget/g1/functions/acm.gs2
    mkdir /config/usb_gadget/g1/functions/acm.gs3
    mkdir /config/usb_gadget/g1/functions/cser.dun.0
    mkdir /config/usb_gadget/g1/functions/cser.nmea.1
    mkdir /config/usb_gadget/g1/functions/cser.dun.2
    mkdir /config/usb_gadget/g1/functions/gsi.rmnet
    mkdir /config/usb_gadget/g1/functions/gsi.rndis
    mkdir /config/usb_gadget/g1/functions/rndis_bam.rndis
    mkdir /config/usb_gadget/g1/functions/rndis.rndis
    mkdir /config/usb_gadget/g1/functions/ncm.0
    mkdir /config/usb_gadget/g1/functions/ccid.ccid
    mkdir /config/usb_gadget/g1/functions/uac2.0
    mkdir /config/usb_gadget/g1/functions/uvc.0
    mkdir /config/usb_gadget/g1/functions/uvc.0/control/header/h
    symlink /config/usb_gadget/g1/functions/uvc.0/control/header/h /config/usb_gadget/g1/functions/uvc.0/control/class/fs/h
    symlink /config/usb_gadget/g1/functions/uvc.0/control/header/h /config/usb_gadget/g1/functions/uvc.0/control/class/ss/h
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/360p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/360p/dwFrameInterval \
"333333
666666
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/360p/wWidth 640
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/360p/wHeight 360
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/360p/dwMaxVideoFrameBufferSize 460800
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/360p/dwMinBitRate 55296000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/360p/dwMaxBitRate 110592000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/480p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/480p/dwFrameInterval \
"500000
666666
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/480p/wWidth 640
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/480p/wHeight 480
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/480p/dwMaxVideoFrameBufferSize 614400
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/480p/dwMinBitRate 73728000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/480p/dwMaxBitRate 98304000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/720p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/720p/dwFrameInterval \
"1000000
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/720p/wWidth 1280
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/720p/wHeight 720
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/720p/dwMaxVideoFrameBufferSize 1843200
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/720p/dwMinBitRate 147456000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u/720p/dwMaxBitRate 147456000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/360p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/360p/dwFrameInterval \
"333333
666666
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/360p/wWidth 640
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/360p/wHeight 360
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/360p/dwMaxVideoFrameBufferSize 345600
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/360p/dwMinBitRate 41472000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/360p/dwMaxBitRate 82944000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/480p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/480p/dwFrameInterval \
"333333
666666
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/480p/wWidth 640
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/480p/wHeight 480
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/480p/dwMaxVideoFrameBufferSize 460800
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/480p/dwMinBitRate 55296000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/480p/dwMaxBitRate 110592000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwFrameInterval \
"333333
666666
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wWidth 1280
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/wHeight 720
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMaxVideoFrameBufferSize 1382400
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMinBitRate 165888000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/720p/dwMaxBitRate 331776000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/960p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/960p/dwFrameInterval \
"333333
666666
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/960p/wWidth 1280
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/960p/wHeight 960
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/960p/dwMaxVideoFrameBufferSize 1843200
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/960p/dwMinBitRate 221184000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/960p/dwMaxBitRate 442368000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwFrameInterval \
"333333
666666
"
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wWidth 1920
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/wHeight 1080
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMaxVideoFrameBufferSize 3110400
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMinBitRate 373248000
    write /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m/1080p/dwMaxBitRate 746496000
    mkdir /config/usb_gadget/g1/functions/uvc.0/streaming/header/h
    symlink /config/usb_gadget/g1/functions/uvc.0/streaming/uncompressed/u /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/u
    symlink /config/usb_gadget/g1/functions/uvc.0/streaming/mjpeg/m /config/usb_gadget/g1/functions/uvc.0/streaming/header/h/m
    symlink /config/usb_gadget/g1/functions/uvc.0/streaming/header/h /config/usb_gadget/g1/functions/uvc.0/streaming/class/fs/h
    symlink /config/usb_gadget/g1/functions/uvc.0/streaming/header/h /config/usb_gadget/g1/functions/uvc.0/streaming/class/hs/h
    symlink /config/usb_gadget/g1/functions/uvc.0/streaming/header/h /config/usb_gadget/g1/functions/uvc.0/streaming/class/ss/h
    write /config/usb_gadget/g1/functions/uvc.0/streaming_maxburst 15
    write /config/usb_gadget/g1/functions/uvc.0/streaming_maxpacket 3072
    write /config/usb_gadget/g1/functions/uvc.0/streaming_interval 2
    write /config/usb_gadget/g1/functions/uvc.0/streaming_txfifo_hint 9
    write /config/usb_gadget/g1/functions/uvc.0/function_name "Moto Webcam
"
    mkdir /config/usb_gadget/g1/configs/b.1 0770
    mkdir /config/usb_gadget/g2/configs/b.1 0770
    mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770
    mkdir /config/usb_gadget/g2/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"
    symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b.1
    mkdir /dev/usb-ffs 0775 shell system
    mkdir /dev/usb-ffs/adb 0770 shell shell
    mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000,rmode=0770,fmode=0660
    chown system system /sys/class/android_usb/android0/secure
    chmod 0660 /sys/class/android_usb/android0/secure

on boot && property:vendor.usb.use_ffs_mtp=1
   mkdir /config/usb_gadget/g1/functions/ffs.mtp
   mkdir /config/usb_gadget/g1/functions/ffs.ptp
   mkdir /dev/usb-ffs/mtp 0770 mtp mtp
   mount functionfs mtp /dev/usb-ffs/mtp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1
   mkdir /dev/usb-ffs/ptp 0770 mtp mtp
   mount functionfs ptp /dev/usb-ffs/ptp rmode=0770,fmode=0660,uid=1024,gid=1024,no_disconnect=1

#  This is a good place to write these, since system props would be loaded.
on firmware_mounts_complete
    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.model}

on firmware_mounts_complete && property:ro.vendor.product.display.plain_text=*
    write /config/usb_gadget/g1/strings/0x409/product ${ro.vendor.product.display.plain_text}

on load_bpf_programs
    setprop vendor.usb.config  ${sys.usb.config}
    setprop persist.vendor.mot.usb.config  ${persist.sys.usb.config:-" "}
    setprop persist.vendor.usb.config  ${persist.sys.usb.config:-" "}

on property:ro.boot.console=ttyGS0 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/UDC "none"
    mkdir /config/usb_gadget/g1/functions/acm.0
    # "f0" is used here so that we won't take anything from f1 ~ f9
    symlink /config/usb_gadget/g1/functions/acm.0 /config/usb_gadget/g1/configs/b.1/f0
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}

on property:sys.boot_completed=*
    setprop vendor.boot_completed ${sys.boot_completed}

on property:persist.vendor.usb.config=*
    setprop persist.sys.usb.config ${persist.vendor.usb.config}

on property:vendor.usb.config=*
    setprop sys.usb.config ${vendor.usb.config}

on property:vendor.usb.controller=*
    setprop sys.usb.controller ${vendor.usb.controller}

on property:persist.vendor.usb.mot-factory.config=*
    setprop persist.sys.usb.mot-factory.config ${persist.vendor.usb.mot-factory.config}
    setprop persist.sys.usb.mot-factory.func ${persist.vendor.usb.mot-factory.config}

### Support USB Secure Mode
on property:sys.usb.secure_mode=*
    setprop vendor.usb.secure_mode ${sys.usb.secure_mode}

on property:vendor.usb.secure_mode=1
    setprop sys.usb.controller none
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}

on property:vendor.usb.secure_mode=0
    setprop sys.usb.controller ${vendor.usb.controller}
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}

service vendor.mmi-usb-sh /vendor/bin/init.mmi.usb.sh
    class late_start
    user root
    group system
    oneshot

on userspace-reboot-resume
    setprop persist.vendor.mot.usb.config ${persist.sys.usb.config}
    setprop persist.vendor.usb.config ${persist.sys.usb.config}

on charger
    insmod /vendor/lib/modules/moto_f_mass_storage.ko
    setprop vendor.usb.adb_early ${ro.boot.adb_early:-"0"}
    setprop vendor.usb.charging.func.name moto_mass_storage
    start vendor.mmi-usb-sh

 # Wait for the USB init shell script to finish, to prevent enumeration issues
on property:init.svc.vendor.mmi-usb-sh=stopped && property:ro.boot.mode=charger && property:vendor.usb.adb_early=0
    setprop sys.usb.configfs 1
    setprop sys.usb.config charging

on property:init.svc.vendor.mmi-usb-sh=stopped && property:ro.boot.mode=charger && property:vendor.usb.adb_early=1
    setprop sys.usb.configfs 1
    setprop sys.usb.config charging,adb

### Factory Compositions
on property:sys.usb.config=usbnet,adb && property:sys.usb.configfs=1
    start adbd
    start vendor.tcmd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=usbnet,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "Motorola Test Command"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e2d
    write /config/usb_gadget/g1/os_desc/use 1
    symlink /config/usb_gadget/g1/functions/usbnet.usb0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=usbnet && property:sys.usb.configfs=1
    start vendor.tcmd
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "Motorola Test Command without ADB"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e2c
    write /config/usb_gadget/g1/os_desc/use 0
    symlink /config/usb_gadget/g1/functions/usbnet.usb0 /config/usb_gadget/g1/configs/b.1/f1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=atm_gs0gs3 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/UDC "none"
    write /config/usb_gadget/g1/bDeviceClass 0
    write /config/usb_gadget/g1/bDeviceSubClass 0
    write /config/usb_gadget/g1/bDeviceProtocol 0
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rmdir /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name}
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=atm_gs0gs3 && \
property:sys.usb.configfs=1 && property:ro.bootmode=mot-factory
    start vendor.tcmd
    setprop vendor.usb.acm_port0 0
    setprop vendor.usb.acm_port1 3
    setprop vendor.usb.acm_cnt 2
    setprop vendor.usb.acm_enable 1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb_acm"
    write /sys/class/udc/${sys.usb.controller}/device/saving 1
    write /sys/devices/platform/soc/mt_usb/saving 1
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e2d
    symlink /config/usb_gadget/g1/functions/usbnet.usb0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    symlink /config/usb_gadget/g1/functions/acm.gs0 /config/usb_gadget/g1/configs/b.1/f3
    symlink /config/usb_gadget/g1/functions/acm.gs3 /config/usb_gadget/g1/configs/b.1/f4
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}

on property:sys.usb.config=adb && property:vendor.usb.acm_enable=1 && \
property:sys.usb.configfs=1 && property:ro.bootmode=mot-factory
    write /config/usb_gadget/g1/UDC "none"
    write /config/usb_gadget/g1/bDeviceClass 0
    write /config/usb_gadget/g1/bDeviceSubClass 0
    write /config/usb_gadget/g1/bDeviceProtocol 0
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rmdir /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name}
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && \
property:vendor.usb.acm_enable=1 && property:sys.usb.configfs=1 && property:ro.bootmode=mot-factory
    start vendor.tcmd
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "adb_acm"
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e2d
    write /sys/class/udc/${sys.usb.controller}/device/saving 1
    write /sys/devices/platform/soc/mt_usb/saving 1
    symlink /config/usb_gadget/g1/functions/usbnet.usb0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    symlink /config/usb_gadget/g1/functions/acm.gs0 /config/usb_gadget/g1/configs/b.1/f3
    symlink /config/usb_gadget/g1/functions/acm.gs3 /config/usb_gadget/g1/configs/b.1/f4
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

### ATCI
on property:persist.vendor.radio.port_index=1 && property:sys.boot_completed=1
    setprop vendor.usb.acm_port0 0
    setprop vendor.usb.acm_enable 1
    setprop vendor.usb.acm_idx 1
    setprop vendor.usb.acm_cnt 1
    setprop sys.usb.config none
    setprop sys.usb.config ${sys.usb.state}

on property:persist.vendor.radio.port_index=0 && property:vendor.usb.acm_enable=1
    setprop vendor.usb.acm_enable 0
    setprop vendor.usb.acm_idx ""
    setprop vendor.usb.acm_cnt 0
    setprop sys.usb.config none
    setprop sys.usb.config ${sys.usb.state}
    setprop persist.vendor.radio.port_index ""

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb &&  property:sys.usb.configfs=1 && \
property:vendor.usb.acm_enable=1 && property:persist.vendor.radio.port_index=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "atci"
    write /config/usb_gadget/g1/idVendor 0x0e8d
    write /config/usb_gadget/g1/idProduct 0x2006
    write /sys/class/udc/${sys.usb.controller}/device/saving 1
    write /sys/devices/platform/soc/mt_usb/saving 1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/acm.gs0 /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1 && \
property:vendor.usb.acm_enable=1 && property:persist.vendor.radio.port_index=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "atci"
    write /config/usb_gadget/g1/idVendor 0x0e8d
    write /config/usb_gadget/g1/idProduct 0x200a
    write /sys/class/udc/${sys.usb.controller}/device/saving 1
    write /sys/devices/platform/soc/mt_usb/saving 1
    symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    symlink /config/usb_gadget/g1/functions/acm.gs0 /config/usb_gadget/g1/configs/b.1/f3
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

### Bell
on property:sys.usb.config=acm_gs0gs3 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/UDC "none"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=acm_gs0gs3 && \
property:sys.usb.configfs=1
    setprop vendor.usb.acm_port0 0
    setprop vendor.usb.acm_port1 3
    setprop vendor.usb.acm_cnt 2
    setprop vendor.usb.acm_enable 1
    setprop vendor.usb.acm_idx "1,4"
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "acm_gs0gs3"
    write /sys/class/udc/${sys.usb.controller}/device/saving 1
    write /sys/devices/platform/soc/mt_usb/saving 1
    write /config/usb_gadget/g1/idVendor 0x0e8d
    write /config/usb_gadget/g1/idProduct 0x2029
    symlink /config/usb_gadget/g1/functions/mass_storage.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    symlink /config/usb_gadget/g1/functions/acm.gs0 /config/usb_gadget/g1/configs/b.1/f3
    symlink /config/usb_gadget/g1/functions/acm.gs3 /config/usb_gadget/g1/configs/b.1/f4
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

### ELT Logging port
on property:persist.vendor.radio.port_index=4 && property:sys.boot_completed=1
    setprop vendor.usb.acm_port0 3
    setprop vendor.usb.acm_enable 1
    setprop vendor.usb.acm_idx 4
    setprop vendor.usb.acm_cnt 1
    setprop sys.usb.config none
    setprop sys.usb.config ${sys.usb.state}

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb &&  property:sys.usb.configfs=1 && \
property:vendor.usb.acm_enable=1 && property:persist.vendor.radio.port_index=4
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ELT"
    write /config/usb_gadget/g1/idVendor 0x0e8d
    write /config/usb_gadget/g1/idProduct 0x2006
    write /sys/class/udc/${sys.usb.controller}/device/saving 1
    write /sys/devices/platform/soc/mt_usb/saving 1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/acm.gs3 /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1 && \
property:vendor.usb.acm_enable=1 && property:persist.vendor.radio.port_index=4
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ELT"
    write /config/usb_gadget/g1/idVendor 0x0e8d
    write /config/usb_gadget/g1/idProduct 0x200a
    write /sys/class/udc/${sys.usb.controller}/device/saving 1
    write /sys/devices/platform/soc/mt_usb/saving 1
    symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    symlink /config/usb_gadget/g1/functions/acm.gs3 /config/usb_gadget/g1/configs/b.1/f3
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

### Charging Compositions
on property:vendor.usb.charging.func.name=moto_mass_storage
    mkdir /config/usb_gadget/g1/functions/moto_mass_storage.0

on property:sys.usb.config=charging && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno}
    write /config/usb_gadget/g1/UDC "none"
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "Motorola Charge Only"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2eb7
    write /config/usb_gadget/g1/os_desc/use 0
    symlink /config/usb_gadget/g1/functions/${vendor.usb.charging.func.name:-mass_storage}.0 /config/usb_gadget/g1/configs/b.1/f1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=charging,adb
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=charging,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/strings/0x409/serialnumber ${ro.serialno}
    write /config/usb_gadget/g1/UDC "none"
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "Motorola Charge Only"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2eb7
    write /config/usb_gadget/g1/os_desc/use 1
    symlink /config/usb_gadget/g1/functions/${vendor.usb.charging.func.name:-mass_storage}.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

### Android Compositions
on property:sys.usb.config=mtp && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2e82
    write /config/usb_gadget/g1/idVendor  0x22b8

on property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2e76
    write /config/usb_gadget/g1/idVendor  0x22b8

on property:sys.usb.config=mtp && property:vendor.usb.use_ffs_mtp=0 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/mtp.gs0/os_desc/interface.MTP/compatible_id "MTP"

on property:sys.usb.config=mtp && property:vendor.usb.use_ffs_mtp=1 && property:sys.usb.configfs=1
    symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1

on property:sys.usb.config=mtp,adb && property:vendor.usb.use_ffs_mtp=0 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/mtp.gs0/os_desc/interface.MTP/compatible_id "MTP"

on property:sys.usb.config=mtp,adb && property:vendor.usb.use_ffs_mtp=1 && property:sys.usb.configfs=1
    symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2

on early-init && property:ro.vendor.usb.cdrom.func=moto_mass_storage
    insmod /vendor/lib/modules/moto_f_mass_storage.ko

on init && property:ro.vendor.usb.cdrom.func=moto_mass_storage
    mkdir /config/usb_gadget/g1/functions/moto_mass_storage.0

on init && property:ro.carrier=vzw
    mkdir /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1

on init && property:ro.carrier=vzwpre
    mkdir /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1

on property:sys.usb.config=mtp,cdrom && property:sys.usb.configfs=1
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp, cdrom"
    write /config/usb_gadget/g1/idProduct 0x2e61
    write /config/usb_gadget/g1/idVendor  0x22b8
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.0/file ""
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.0/cdrom 1
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.0/file "/product/etc/cdrom"

on property:sys.usb.config=mtp,cdrom,adb && property:sys.usb.configfs=1
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "mtp, cdrom"
    write /config/usb_gadget/g1/idProduct 0x2e61
    write /config/usb_gadget/g1/idVendor  0x22b8
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.0/file ""
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.0/cdrom 1
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.0/file "/product/etc/cdrom"

on property:sys.usb.config=mtp,cdrom && property:sys.usb.configfs=1 && property:ro.carrier=vzw
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file ""
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/cdrom 1
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file "/product/etc/vzw_cdrom"

on property:sys.usb.config=mtp,cdrom,adb && property:sys.usb.configfs=1 && property:ro.carrier=vzw
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file ""
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/cdrom 1
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file "/product/etc/vzw_cdrom"

on property:sys.usb.config=mtp,cdrom && property:sys.usb.configfs=1 && property:ro.carrier=vzwpre
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file ""
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/cdrom 1
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file "/product/etc/vzw_cdrom"

on property:sys.usb.config=mtp,cdrom,adb && property:sys.usb.configfs=1 && property:ro.carrier=vzwpre
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file ""
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/cdrom 1
    write /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0/lun.1/file "/product/etc/vzw_cdrom"

on property:sys.usb.config=mtp,cdrom && property:vendor.usb.use_ffs_mtp=0 && property:sys.usb.configfs=1
    symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0  /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mtp,cdrom && property:vendor.usb.use_ffs_mtp=1 && property:sys.usb.configfs=1
    symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0  /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mtp,cdrom,adb && property:vendor.usb.use_ffs_mtp=0 && property:sys.usb.configfs=1
    symlink /config/usb_gadget/g1/functions/mtp.gs0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0  /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=mtp,cdrom,adb && property:vendor.usb.use_ffs_mtp=1 && property:sys.usb.configfs=1
    symlink /config/usb_gadget/g1/functions/ffs.mtp /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/${ro.vendor.usb.cdrom.func:-mass_storage}.0  /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=rndis && property:sys.usb.configfs=1
    setprop sys.usb.config rndis,${persist.vendor.usb.config.extra}

on property:sys.usb.config=rndis,none && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e24
    symlink /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name} /config/usb_gadget/g1/configs/b.1/f1
    write /config/usb_gadget/g1/configs/b.1/f1/wceis 1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state rndis


on property:sys.usb.config=rndis,adb && property:sys.usb.configfs=1
    setprop sys.usb.config rndis,${persist.vendor.usb.config.extra},adb

on property:sys.usb.config=rndis,none,adb && property:sys.usb.configfs=1
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=rndis,none,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis_adb"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e25
    symlink /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name} /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/configs/b.1/f1/wceis 1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state rndis,adb

on property:sys.usb.config=rndis,webcam && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e24
    symlink /config/usb_gadget/g1/functions/uvc.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name} /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/configs/b.1/f2/wceis 1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=rndis,webcam,adb && property:sys.usb.configfs=1
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=rndis,webcam,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "rndis_adb"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e25
    symlink /config/usb_gadget/g1/functions/uvc.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name} /config/usb_gadget/g1/configs/b.1/f2
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f3
    write /config/usb_gadget/g1/configs/b.1/f2/wceis 1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=ncm && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ncm"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e44
    write /config/usb_gadget/g1/functions/ncm.0/os_desc/interface.ncm/compatible_id "WINNCM"
    symlink /config/usb_gadget/g1/functions/ncm.0 /config/usb_gadget/g1/configs/b.1/f1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=ncm,adb && property:sys.usb.configfs=1
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=ncm,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ncm_adb"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e45
    write /config/usb_gadget/g1/functions/ncm.0/os_desc/interface.ncm/compatible_id "WINNCM"
    symlink /config/usb_gadget/g1/functions/ncm.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=ncm,webcam && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ncm"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e44
    write /config/usb_gadget/g1/functions/ncm.0/os_desc/interface.ncm/compatible_id "WINNCM"
    symlink /config/usb_gadget/g1/functions/uvc.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ncm.0 /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    wait /config/usb_gadget/uvc_delay_300ms 0.3
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=ncm,webcam,adb && property:sys.usb.configfs=1
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=ncm,webcam,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "ncm_adb"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e45
    write /config/usb_gadget/g1/functions/ncm.0/os_desc/interface.ncm/compatible_id "WINNCM"
    symlink /config/usb_gadget/g1/functions/uvc.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ncm.0 /config/usb_gadget/g1/configs/b.1/f2
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f3
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    wait /config/usb_gadget/uvc_delay_100ms 0.1
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=readyfor && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "readyfor"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e46
    symlink /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name} /config/usb_gadget/g1/configs/b.1/f1
    write /config/usb_gadget/g1/configs/b.1/f1/wceis 1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=readyfor,adb && property:sys.usb.configfs=1
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=readyfor,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "readyfor_adb"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e47
    symlink /config/usb_gadget/g1/functions/${vendor.usb.rndis.func.name} /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/configs/b.1/f1/wceis 1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=ptp && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2e83
    write /config/usb_gadget/g1/idVendor  0x22b8

on property:sys.usb.config=ptp,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2e84
    write /config/usb_gadget/g1/idVendor  0x22b8

on property:sys.usb.config=ptp && property:vendor.usb.use_ffs_mtp=0 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/ptp.gs1/os_desc/interface.MTP/compatible_id "PTP"

on property:sys.usb.config=ptp,adb && property:vendor.usb.use_ffs_mtp=0 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/ptp.gs1/os_desc/interface.MTP/compatible_id "PTP"

on property:sys.usb.config=ptp && property:vendor.usb.use_ffs_mtp=1 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/ffs.ptp/os_desc/interface.MTP/compatible_id "PTP"
    symlink /config/usb_gadget/g1/functions/ffs.ptp /config/usb_gadget/g1/configs/b.1/f1

on property:sys.usb.config=ptp,adb && property:vendor.usb.use_ffs_mtp=1 && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/ffs.ptp/os_desc/interface.MTP/compatible_id "PTP"
    symlink /config/usb_gadget/g1/functions/ffs.ptp /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2

on init
    setprop sys.usb.controller none
    chown root system /sys/module/uvcvideo/parameters/quirks
    chmod 0660 /sys/module/uvcvideo/parameters/quirks
    setprop sys.usb.configfs 1
    setprop ro.vendor.usb.moto_common_rc 1

on boot && property:ro.boot.adb_early=1
     start vendor.mmi-usb-sh

on property:sys.usb.config=adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2E81

on property:sys.usb.config=webcam && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "Webcam"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e85
    symlink /config/usb_gadget/g1/functions/uvc.0 /config/usb_gadget/g1/configs/b.1/f1
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    wait /config/usb_gadget/uvc_delay_300ms 0.3
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=webcam,adb && property:sys.usb.configfs=1
    start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=webcam,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "Webcam"
    rm /config/usb_gadget/g1/configs/b.1/f1
    rm /config/usb_gadget/g1/configs/b.1/f2
    rm /config/usb_gadget/g1/configs/b.1/f3
    rm /config/usb_gadget/g1/configs/b.1/f4
    rm /config/usb_gadget/g1/configs/b.1/f5
    rm /config/usb_gadget/g1/configs/b.1/f6
    rm /config/usb_gadget/g1/configs/b.1/f7
    rm /config/usb_gadget/g1/configs/b.1/f8
    rm /config/usb_gadget/g1/configs/b.1/f9
    write /config/usb_gadget/g1/idVendor 0x22b8
    write /config/usb_gadget/g1/idProduct 0x2e85
    symlink /config/usb_gadget/g1/functions/uvc.0 /config/usb_gadget/g1/configs/b.1/f1
    symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
    write /config/usb_gadget/g1/UDC ${sys.usb.controller}
    wait /config/usb_gadget/uvc_delay_100ms 0.1
    setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=adb,acm && property:sys.usb.configfs=1
   start adbd

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb,acm && property:sys.usb.configfs=1
   mkdir /config/usb_gadget/g1/functions/acm.0
   rm /config/usb_gadget/g1/configs/b.1/f1
   rm /config/usb_gadget/g1/configs/b.1/f2
   rm /config/usb_gadget/g1/configs/b.1/f3
   rm /config/usb_gadget/g1/configs/b.1/f4
   rm /config/usb_gadget/g1/configs/b.1/f5
   rm /config/usb_gadget/g1/configs/b.1/f6
   rm /config/usb_gadget/g1/configs/b.1/f7
   rm /config/usb_gadget/g1/configs/b.1/f8
   rm /config/usb_gadget/g1/configs/b.1/f9
   write /config/usb_gadget/g1/idVendor 0x1d6b
   write /config/usb_gadget/g1/idProduct 0x0104
   symlink /config/usb_gadget/g1/functions/acm.0 /config/usb_gadget/g1/configs/b.1/f1
   symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
   write /config/usb_gadget/g1/UDC ${sys.usb.controller}
   setprop sys.usb.state ${sys.usb.config}

on property:sys.usb.config=acm && property:sys.usb.configfs=1
   mkdir /config/usb_gadget/g1/functions/acm.0
   rm /config/usb_gadget/g1/configs/b.1/f1
   rm /config/usb_gadget/g1/configs/b.1/f2
   rm /config/usb_gadget/g1/configs/b.1/f3
   rm /config/usb_gadget/g1/configs/b.1/f4
   rm /config/usb_gadget/g1/configs/b.1/f5
   rm /config/usb_gadget/g1/configs/b.1/f6
   rm /config/usb_gadget/g1/configs/b.1/f7
   rm /config/usb_gadget/g1/configs/b.1/f8
   rm /config/usb_gadget/g1/configs/b.1/f9
   write /config/usb_gadget/g1/idVendor 0x1d6b
   write /config/usb_gadget/g1/idProduct 0x0104
   symlink /config/usb_gadget/g1/functions/acm.0 /config/usb_gadget/g1/configs/b.1/f1
   write /config/usb_gadget/g1/UDC ${sys.usb.controller}
   setprop sys.usb.state ${sys.usb.config}

on property:vendor.em.usb.set=*
    write /proc/mtk_usb/usb-phy0/u2_phy/${vendor.em.usb.set} ${vendor.em.usb.value}
