#!/system/bin/sh
#
# wlan_loader
#
# NITdroid WLAN driver loader
#
# Loads and calibrates the WiFi driver
# Assumes initfs is already mounted
#
# Otto Solares Cabrera <solca@guug.org>

INITFS=/nokia/mnt/initfs

if ! exists ${INITFS}/usr/bin/stlc45xx-cal; then
    for CALTOOL in /sdcard/stlc45xx-cal*
    do
        if exists ${CALTOOL}; then
            if mount -o remount,rw,noatime /dev/block/mtdblock3 ${INITFS}; then
                cat ${CALTOOL} >${INITFS}/usr/bin/stlc45xx-cal
                chmod 0755 ${INITFS}/usr/bin/stlc45xx-cal
                mount -o remount,ro /dev/block/mtdblock3 ${INITFS}
                break
            fi
        fi
    done
fi

if ! exists ${INITFS}/usr/bin/stlc45xx-cal; then
    echo "stlc45xx-cal calibration tool not present."
    echo "Device will operate sub-obtimal."
    echo "Download it from: http://stlc45xx.garage.maemo.org/"
    echo "Then place it at: /sdcard"
else
    if ! chroot ${INITFS} /usr/bin/stlc45xx-cal; then
        echo "stlc45xx calibration failed."
    fi
fi

if netcfg wlan0 up; then
    sleep 1
    setprop wlan.driver.status ok
fi
