import init.htcleo.usb.rc

on early-init
    export SD_EXT_DIRECTORY /sd-ext
    mkdir /sd-ext 0771 system system
    export EXTERNAL_STORAGE /mnt/sdcard
    mkdir /mnt/sdcard 0000 system system
    # for backwards compatibility
    symlink /mnt/sdcard /sdcard

on fs
    mount yaffs2 mtd@system /system remount

on post-fs-data

    mount rootfs rootfs / remount

    mkdir /data/misc/wifi 0770 wifi wifi
    mkdir /data/misc/wifi/sockets 0770 wifi wifi
    mkdir /data/misc/dhcp 0770 dhcp dhcp
    chown dhcp dhcp /data/misc/dhcp

    setprop vold.post_fs_data_done 1

on boot
    mount debugfs /sys/kernel/debug /sys/kernel/debug

    # bluetooth power up/down interface
    chown bluetooth bluetooth /sys/class/rfkill/rfkill0/type
    chown bluetooth bluetooth /sys/class/rfkill/rfkill0/state
    chmod 0660                /sys/class/rfkill/rfkill0/state
    chown bluetooth bluetooth /dev/ttyHS0
    chmod 0600                /dev/ttyHS0

    # bluetooth MAC address programming
    chown bluetooth bluetooth /sys/module/board_htcleo/parameters/bdaddr
    setprop ro.bt.bdaddr_path /sys/module/board_htcleo/parameters/bdaddr

    # bluetooth car dock pin
    chown system system /sys/class/switch/dock/bt_pin

    # Permissions for Liblights.
    chown system system /sys/class/leds/green/brightness
    chown system system /sys/class/leds/green/blink
    chown system system /sys/class/leds/amber/brightness
    chown system system /sys/class/leds/amber/blink
    chown system system /sys/class/leds/button-backlight/brightness
    chown system system /sys/class/leds/lcd-backlight/brightness

    # ===============================
    # begin of permissions for htcleo
    # ===============================
    # flashlight
    chown system camera /sys/devices/platform/flashlight.0/leds/flashlight/brightness
    chmod 0660          /sys/devices/platform/flashlight.0/leds/flashlight/brightness
    chmod 0666          /sys/devices/platform/flashlight.0/leds/flashlight/max_brightness

    # 720p cam support
    symlink /dev/msm_camera/control0 /dev/msm_camera/control1
    symlink /dev/msm_camera/frame0 /dev/msm_camera/frame1
    symlink /dev/msm_camera/config0 /dev/msm_camera/config1

    # ICS camera
    chmod 0777 /dev/msm_camera/config0
    chmod 0777 /dev/msm_camera/config1
    chmod 0777 /dev/msm_camera/control0
    chmod 0777 /dev/msm_camera/control1
    chmod 0777 /dev/msm_camera/frame0
    chmod 0777 /dev/msm_camera/frame1
    chmod 0777 /dev/graphics/fb0

    # allow net_raw to have access to /dev/socket directory
    chown root net_raw /dev/socket
    chmod 0775 /dev/socket

    # allow system to modify cpufreq control files
    chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
    chmod 0664 /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
    chown root system /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq

    # for wireless modem
    chown system system /sys/module/serial/parameters/modem_enabled
    chown system.system /dev/cpu_dma_latency
    chown system system /dev/smd0
    chown system system /dev/smd1
    chown system system /dev/smd9
    chown system system /dev/smd27
    chown system system /dev/ttyHSUSB0

    # others
    chown radio system  /sys/camera_led_status/led_ril_status
    chown system system /sys/camera_led_status/led_wimax_status
    chown system system /sys/camera_led_status/led_hotspot_status
    chown radio radio   /sys/module/pm/parameters/idle_sleep_mode

    chmod 0666 /dev/rfkill
    chmod 0666 /dev/q6venc
    chmod 0666 /proc/cmdline

    chmod 666 /dev/input/event0
    chmod 666 /dev/input/event1
    chmod 666 /dev/input/event2
    chmod 666 /dev/input/event3
    chmod 666 /dev/input/event4
    chmod 666 /dev/input/event5
    chmod 666 /dev/input/event6
    
    chmod 666 /dev/uinput
    chmod 666 /dev/msm_qcelp_in
    chmod 666 /dev/msm_aac_in
    chmod 666 /dev/msm_audio_ctl
    chmod 666 /dev/msm_audio_route
    chmod 666 /dev/msm_mp3
    chmod 666 /dev/msm_pcm_in
    chmod 666 /dev/msm_pcm_out

    chmod 666 /dev/qmi0
    chmod 666 /dev/qmi1
    chmod 666 /dev/qmi2

    chmod 666 /etc/bluez/audio.conf
    chmod 666 /etc/bluez/hcid.conf 
    chmod 666 /etc/bluez/input.conf

    chmod 0777 /dev/smd0
    chmod 0777 /dev/smd1
    chmod 0777 /dev/smd27
    chmod 0777 /dev/msm_camera
    chmod 0777 /dev/akm8973_aot
    chmod 0777 /dev/akm8973_daemon
    chmod 0777 /dev/cpu_dma_latency
    chmod 0777 /dev/lightsensor
    chmod 0777 /dev/bma150
    chmod 0777 /dev/kgsl
    chmod 0777 /dev/cm3602
    chmod 0777 /dev/htc-acoustic
    #chmod 0777 /dev/vfe
    #chmod 0777 /dev/camera
    #chmod 0777 /dev/compass

    # Wireless properties
    setprop net.dns1 8.8.8.8
    setprop net.dns2 8.8.4.4

    # =============================
    # end of permissions for htcleo
    # =============================

    # enable the GPS
    setprop ro.ril.def.agps.mode 2

    # Add permissions for camera access
    chmod 0666 /dev/msm_camera/config0
    chmod 0666 /dev/msm_camera/control0
    chmod 0666 /dev/msm_camera/frame0

    chmod 0666 /dev/graphics/fb0

    # performance tweaks for flash
    write /sys/block/mtdblock3/bdi/read_ahead_kb 4
    write /sys/block/mtdblock4/bdi/read_ahead_kb 4
    write /sys/block/mtdblock5/bdi/read_ahead_kb 4

    # Power Management
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq 245000
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 998400
    write /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ondemand
    write /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate 40000

    # KSM defaults
    # write /sys/kernel/mm/ksm/sleep_millisecs 1500
    write /sys/kernel/mm/ksm/sleep_millisecs 3000
    write /sys/kernel/mm/ksm/pages_to_scan 256

    # enable KSM
    write /sys/kernel/mm/ksm/run 1

    # Wakelock debug
    write /sys/module/wakelock/parameters/debug_mask 7

    # Fast dormancy settings
    setprop ro.ril.fast.dormancy.rule 1
    setprop ro.ril.fd.scron.timeout 4
    setprop ro.ril.fd.scroff.timeout 3

    # GPRS class
    setprop ro.ril.gprsclass 10

# compass/accelerometer daemon
service akmd /system/bin/akmd
    class main
    user compass
    group compass misc input

service wpa_supplicant /system/bin/wpa_supplicant \
    -Dwext -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf
#   we will start as root and wpa_supplicant will switch to user wifi
#   after setting up the capabilities required for WEXT
#   user wifi
#   group wifi inet keystore
    class main
    socket wpa_wlan0 dgram 660 wifi wifi
    disabled
    oneshot

service dhcpcd_wlan0 /system/bin/dhcpcd -ABKL
    class main
    disabled
    oneshot

service dhcpcd_bnep0 /system/bin/dhcpcd -ABKL
    class main
    disabled
    oneshot

service iprenew_wlan0 /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

service iprenew_bnep0 /system/bin/dhcpcd -n
    class main
    disabled
    oneshot

# bugreport is triggered by the KEY_VOLUMEUP and BTN_MOUSE keycodes
service bugreport /system/bin/dumpstate -d -v -o /sdcard/bugreports/bugreport
    class main
    disabled
    oneshot
    keycodes 115 272

service hciattach /system/bin/brcm_patchram_plus --enable_hci --enable_lpm \
    --baudrate 3000000 --patchram /etc/firmware/bcm4329.hcd /dev/ttyHS0
    class main
    user bluetooth
    group bluetooth net_bt_admin
    disabled
    oneshot

service dspcrashd /system/bin/dspcrashd
