on boot
    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}

    # OS DESCRIPTORS
    #===============
    # OS STRING
    #----------
    write /config/usb_gadget/g1/os_desc/b_vendor_code 1
    write /config/usb_gadget/g1/os_desc/qw_sign "MSFT100"
    # use os desc or not is up to each usb functions respectively
    # write /config/usb_gadget/g1/os_desc/use 1

    # MAKE b.1 THE ONE ASSOCIATED WITH OS DESCRIPTORS
    #------------------------------------------------
    symlink /config/usb_gadget/g1/configs/b.1 /config/usb_gadget/g1/os_desc/b1

    setprop sys.usb.configfs 1

    # 38100000.dwc3 is the fixed UDC name for 8mq type c usb
    setprop sys.usb.controller 38100000.dwc3

on fs
    mkdir /dev/usb-ffs 0770 shell shell
    mkdir /dev/usb-ffs/adb 0770 shell shell
    # mount the configfs on /config
    mount configfs none /config mode=0755
    mkdir /config/usb_gadget/g1
    mkdir /config/usb_gadget/g1/configs/b.1
    # mkdir for functions needed
    # this will call each gadget's alloc_inst()
    mkdir /config/usb_gadget/g1/functions/ffs.adb
    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/rndis.gs4
    mkdir /config/usb_gadget/g1/functions/midi.gs5
    mkdir /config/usb_gadget/g1/strings/0x409
    mkdir /config/usb_gadget/g1/configs/b.1/strings/0x409
    # The mount of functionfs for adb must be put AFTER the mkdir for functions in configfs
    mount functionfs adb /dev/usb-ffs/adb uid=2000,gid=2000

on property:sys.usb.config=none && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/os_desc/use 0

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x4ee7
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.config=mtp && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/mtp.gs0/os_desc/interface.MTP/compatible_id "MTP"
    write /config/usb_gadget/g1/os_desc/use 1
    write /config/usb_gadget/g1/idProduct 0x4ee1
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=mtp,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/mtp.gs0/os_desc/interface.MTP/compatible_id "MTP"
    write /config/usb_gadget/g1/os_desc/use 1
    write /config/usb_gadget/g1/idProduct 0x4ee2
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.config=ptp && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/ptp.gs1/os_desc/interface.MTP/compatible_id "PTP"
    write /config/usb_gadget/g1/os_desc/use 1
    write /config/usb_gadget/g1/idProduct 0x4ee5
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=ptp,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/ptp.gs1/os_desc/interface.MTP/compatible_id "PTP"
    write /config/usb_gadget/g1/os_desc/use 1
    write /config/usb_gadget/g1/idProduct 0x4ee6
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.config=accessory && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2d00
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2d01
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.config=audio_source && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2d02
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=audio_source,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2d03
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.config=accessory,audio_source && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2d04
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,audio_source,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x2d05
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.config=midi && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x4ee8
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=midi,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/idProduct 0x4ee9
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.config=rndis && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/rndis.gs4/os_desc/interface.rndis/compatible_id "RNDIS"
    write /config/usb_gadget/g1/os_desc/use 1
    write /config/usb_gadget/g1/idProduct 0x4ee3
    write /config/usb_gadget/g1/idVendor 0x18d1

on property:sys.usb.ffs.ready=1 && property:sys.usb.config=rndis,adb && property:sys.usb.configfs=1
    write /config/usb_gadget/g1/functions/rndis.gs4/os_desc/interface.rndis/compatible_id "RNDIS"
    write /config/usb_gadget/g1/os_desc/use 1
    write /config/usb_gadget/g1/idProduct 0x4ee4
    write /config/usb_gadget/g1/idVendor 0x18d1
