#!/bin/sh # $Id: uppcsetup,v 1.3 2004/03/26 01:42:14 sam Exp $ # Copyright 2004 Sam Lawrance # Do as you wish with it :) # This is a script to help install and set up the uppc driver, # and get it going with a Windows CE device. It's only really meant # for installation, but it can also be installed and used at any time. # Inputs to this script: # INSTALLDIR - location of installed uppc.ko module # MODDIR - where the kernel modules are if test -n ${INSTALLDIR}; then INSTALLDIR=/usr/local/lib; fi if test -n ${MODDIR}; then MODDIR=/boot/kernel; fi # usbfind() detects a usb device by looking at dmesg and usbdevs output. # Argument 1 is a regexp to look for in dmesg. The last match is used. # From this a device name is extracted. # Information about this device, if it is still attached, is then gathered # from 'usbdevs'. # From this, the device's usb vendor and product IDs are extracted. # If the device in the dmesg line is not currently attached, no # (useful) device information will be available except DEVMSG and DEVNAME, # and the function will return nonzero. usbfind() { DEVMSG=`dmesg|grep "$1"|tail -n 1` DEVNAME=`echo ${DEVMSG} | awk -F":" "{print \\$1;}"` DEVINFO=`usbdevs -vd|grep -B1 "${DEVNAME}"|head -1` DEVIDS=`echo ${DEVINFO} | awk -F "[()]" "{print \\$2, \\$4;}"` DEVPRODUCT=`echo ${DEVIDS} | awk -F" " "{print \\$1;}"` DEVVENDOR=`echo ${DEVIDS} | awk -F" " "{print \\$2;}"` if test -n "${DEVNAME}" -a -n "${DEVINFO}" ; then return 0; else return 1; fi } # Arg 1 is vendor ID, arg 2 is product ID setup_runtime_sysctls() { # Remove old uppc sysctls local tempfile=`mktemp -t __sysctl.conf` cat /etc/sysctl.conf > ${tempfile} grep -v "^hw\.usb\.uppc\." ${tempfile} > /etc/sysctl.conf rm -f ${tempfile} # Copy in new ones echo "hw.usb.uppc.vendor=${1}" >> /etc/sysctl.conf echo "hw.usb.uppc.product=${2}" >> /etc/sysctl.conf sysctl hw.usb.uppc.vendor="${1}" sysctl hw.usb.uppc.product="${2}" } # Create a ppp configuration file and include it in the main ppp.conf setup_ppp_entry() { # Add the include only if it isn't already there grep -q "[ \t]*!include[ \t]\+/etc/ppp/ppp-uppc.conf" /etc/ppp/ppp.conf || echo "!include /etc/ppp/ppp-uppc.conf" >> /etc/ppp/ppp.conf # Whatever is in this file gets clobbered with default values cat << EOF > /etc/ppp/ppp-uppc.conf # Generated automatically by uppcsetup. uppc: disable dns accept dns set login "CLIENT CLIENTSERVER" # DEVNAME is set by usbd set device /dev/\$DEVNAME set dial "" set ifaddr 192.168.130.102 192.168.130.201 set speed 115200 set timeout 300 EOF } # Add a section to usbd to bring up ppp to the device on attach. # The entry is wrapped by magic comments for removal later on. setup_usbd_entry() { # Copy usbd.conf local tempfile=`mktemp -t __usbd.conf` cat /etc/usbd.conf > ${tempfile} local newfile=`mktemp -t __usbd.conf` # Remove old sections for this vendor and product id sed -i "" -e "/^# uppcsetup-config-begin-$DEVPRODUCT-$DEVVENDOR/,/^# uppcsetup-config-end-$DEVPRODUCT-$DEVVENDOR/ d" ${tempfile} cat << EOF > ${newfile} # uppcsetup-config-begin-${DEVPRODUCT}-${DEVVENDOR} # DO NOT ALTER THE COMMENTS WRAPPING THIS SECTION # Generated automatically by uppcsetup. device "Windows CE Device" devname "cuaU[0-9]" vendor ${DEVVENDOR} product ${DEVPRODUCT} attach "/usr/sbin/ppp -background uppc" # uppcsetup-config-end-${DEVPRODUCT}-${DEVVENDOR} EOF # Append the old usbd.conf, less old configurationis cat $tempfile >> $newfile # Install cat $newfile > /etc/usbd.conf # If usbd was started by the system, restart it /etc/rc.d/usbd status && /etc/rc.d/usbd restart } ################################################################### # Here's where the work begins. ################################################################### dialog --yesno "The uppc.ko driver module has been installed in ${INSTALLDIR}. Do you want to copy it to ${MODDIR} (where modules are usually kept)? You must choose yes if you want to set up your connection automatically." 8 65 if test ! $? = 0; then exit; fi dialog --yesno "Do you want to set up your Pocket PC connection automatically?" 6 65 if test ! $? = 0; then exit; fi # This instruction is so that when we come to kldunload the module, # it is not in use. If PPP is using the device it may take up to # a minute to die and allow it to detach properly. dialog --msgbox "If your Pocket PC is physically connected to your computer, please disconnect it now and wait 60 seconds before continuing or your machine may PANIC." 8 65 cp ${INSTALLDIR}/uppc.ko ${MODDIR}/uppc.ko echo 'uppc_load="YES"' >> /boot/loader.conf dialog --msgbox "The command uppc_load=\"YES\" has been added to /boot/loader.conf. The uppc driver will be automatically loaded at boot from now on." 8 65 kldunload uppc.ko 2>&1 > /dev/null kldload uppc.ko KLD_ERR=$? if test ${KLD_ERR} -ne 0; then dialog --msgbox "The uppc module could not be loaded. The error returned by kldload was: ${KLD_ERR}. Cannot continue." 8 65 exit else dialog --msgbox "The uppc module has been loaded. Connect your Pocket PC to the computer through a USB cradle or cable, then press enter." 6 65 fi # Now we use the usbdevs function to check for the following: # If the device was found & detected, there's nothing else to do. # If it was found but not detected by the driver (ie attached to by ugen), # help the user configure the driver to pick up the device. # If it was not found at all, warn and give up. if usbfind "ucom.: "; then dialog --msgbox "Your device was detected successfully and is now ready to use (${DEVMSG})" 8 65 dialog --yesno "Would you like me to add entries to /etc/ppp/ppp.conf and /etc/usbd.conf to bring up a PPP link with the device when it attaches?" 7 65 if test ! $? = 0; then exit; fi setup_ppp_entry setup_usbd_entry else if usbfind "ugen.: "; then dialog --msgbox "Your device was not detected automatically by the driver. You will need to supply your device's USB vendor ID and product ID so the driver can recognise your device. I will attempt to guess the correct values by looking at the last device that was attached." 9 65 tempfile=`mktemp -t __input` dialog --inputbox "Enter your device's USB vendor ID" 8 65 "${DEVVENDOR}" 2> ${tempfile} DEVVENDOR=`cat ${tempfile}` dialog --inputbox "Enter your device's USB product ID" 8 65 "${DEVPRODUCT}" 2> ${tempfile} DEVPRODUCT=`cat ${tempfile}` rm -f ${tempfile} setup_runtime_sysctls ${DEVVENDOR} ${DEVPRODUCT} dialog --msgbox "This information has been added to /etc/sysctl.conf. The driver will now recognise the device ID you entered. Remove your Pocket PC from its cradle/cable, wait 5 seconds, then reconnect it." 8 65 if usbfind "ucom.: "; then dialog --msgbox "Your device was detected successfully and is now ready to use (${DEVMSG})" 7 65 dialog --yesno "Would you like me to add entries to /etc/ppp/ppp.conf and /etc/usbd.conf to bring up a PPP link with the device when it attaches?" 7 65 if test ! $? = 0; then exit; fi setup_ppp_entry setup_usbd_entry else dialog --msgbox "Your device was still not detected successfully. Please read the uppc man page to configure the driver manually." 7 65 fi else dialog --msgbox "Could not find any device that may be a Pocket PC. This can be caused by a faulty cable or connection or there may be something wrong with your USB setup. Please read the uppc man page to configure the driver manually." 8 65 exit fi fi dialog --msgbox "All done! Remember: when a PPP link is established with your device, it expects to be able to connect to a running dccm (ports/palm/synce-dccm)." 8 65