#!/bin/sh
# Adapter for Lucent DSP modem scan by Chris Hebeisen
# IRQ=0 screen added by Marv Stodolsky
echo 
RECORD="Modem-info.txt"
echo  > $RECORD
read -p "To start a  scan for supported PCI Lucent DSP chipset modems:  Enter"
echo 
echo "===================================================================="
echo The ltmodem drivers will FAIL to support currently known 
echo "	winmodems with chipsets produced by:" 
echo "	Conexant, Motorola, US Robotics, IBM, PCTel and Intel. "
echo "The Lucent AMR Soft modem is NOT supported." 
echo "The Lucent Venus modems have a Controller supported by the serial.o driver,"
echo "  rather than DSP supporting driver pair, lt_modem.o and lt_serial.o , of this compiler kit."
echo Among Xircom modems some are supported, and these will be
echo "    reported out during this test."
echo "There are supported ISA and PCMCIA card modems,"
echo "	but these types are NOT accessed by this scan."
echo 
### Scanning PCI bus for modem
LSPCI_PATH="/bin /usr/bin /sbin"
for i in $LSPCI_PATH
do
  if test -x $i/lspci
  then
    LSPCI=$i/lspci
    echo  LSPCI="$LSPCI" >> $RECORD
  fi
done
if test -z $LSPCI
then
  echo "+-----------------------------------------------------------------------------+"
  echo "| WARNING: lspci not found or not executable - not checking for modem         |"
  echo "+-----------------------------------------------------------------------------+"
else
#  echo "  ... using $LSPCI"

  FOUND="no"

  DEVICES="0x11c1:0x0440-0x045c"
  DEVICES=$DEVICES" 0x115d:0x0000-0x000f"
  DEVICES=$DEVICES" 0x115d:0x0440-0x045c"
  DEVICES=$DEVICES" 0x115d:0x0010-0x03ff"

  if ! $LSPCI >/dev/null 2>/dev/null
  then
    echo "WARNING: $LSPCI returned error - not checking for modem"
  else
    for PCIDEV in `$LSPCI -n | cut -d' ' -f4`
    do
      DEVVEN=$(( 0x`echo $PCIDEV | cut -d':' -f1` + 0 ))
      DEVNUM=$(( 0x`echo $PCIDEV | cut -d':' -f2` + 0 ))
      for DEV in $DEVICES
      do
        VENDOR=$(( `echo $DEV | cut -d':' -f1` + 0 ))
        DEVMIN=$(( `echo $DEV | cut -d':' -f2 | cut -d'-' -f1` + 0 ))
        DEVMAX=$(( `echo $DEV | cut -d':' -f2 | cut -d'-' -f2` + 0 ))

        if test $DEVVEN -eq $VENDOR && test $DEVNUM -ge $DEVMIN && test $DEVNUM -le $DEVMAX
        then
          FOUND="yes"
          echo "Modem found with ID"
          MODEM_ID="$PCIDEV" 
          echo "	$MODEM_ID" 
          MODEM_VENDOR=0x`echo $PCIDEV | cut -d':' -f1`
          MODEM_DEVICE=0x`echo $PCIDEV | cut -d':' -f2`
         echo "The id are within the serviced ranges:"     
        fi
      done
    done
    if test ! $FOUND = "yes"
    then
      echo "+----------------------------------------------------------------------------+"
      echo "| WARNING: If your modem is a PCI modem it will probably                     |"
      echo "|             not work with this driver pair.                                |"
      echo "+----------------------------------------------------------------------------+"
      echo "The PCI modems served are within the ranges:"
      echo "Name  vendor_id       device id range"          
    fi
  fi 
fi     
echo "-----------------------------------------------"         
echo "LUCENT 0x11c1          0x0440-0x045c   "
echo "XIRCOM 0x115d          0x0000-0x000F   "  
echo "XIRCOM 0x115d          0x0440-0x045c   "  
echo "XIRCOM 0x115d          0x0010-0x03ff   " 
echo "-----------------------------------------------"
echo MODEM_ID="$MODEM_ID" >> $RECORD        
echo "	IDs of supported modems" >> $RECORD
echo "LUCENT 0x11c1          0x0440-0x045c   ">> $RECORD
echo "XIRCOM 0x115d          0x0000-0x000F   ">> $RECORD
echo "XIRCOM 0x115d          0x0440-0x045c   ">> $RECORD
echo "XIRCOM 0x115d          0x0010-0x03ff   ">> $RECORD
echo >> $RECORD

if test -n "$MODEM_ID" ; then
  read -p "For detailed modem information:	Enter"
  echo
  echo Copying this modem information to $RECORD
  echo "----------------------------------------------"
  lspci -d  "$MODEM_ID" -vv 
  echo "----------------------------------------------"
  echo "----------------------------------------------" >> $RECORD
  lspci -d  "$MODEM_ID" -vv                             >> $RECORD
  echo "----------------------------------------------" >> $RECORD
  IRQ=`lspci -d  "$MODEM_ID" -vv | grep Interrupt | cut -d' ' -f7`
  echo IRQ=$IRQ  >> $RECORD
  if [ "$IRQ" = "0" ] ; then
    echo "	`lspci -d "$MODEM_ID" -vv | grep Interrupt`"
    echo "The interrupt assignment:	 IRQ 0"
    echo predicts that modem function will fail unless
    echo the boot up BIOS can be accessed to change to 
    echo a non-PNP mode.  Read DOCs/BIOSaccess.txt
    echo
    echo "	`lspci -d "$MODEM_ID" -vv | grep Interrupt`" >> $RECORD
    echo "The interrupt assignment:	 IRQ 0"              >> $RECORD
    echo predicts that modem function will fail unless       >> $RECORD
    echo the boot up BIOS can be accessed to change to       >> $RECORD
    echo a non-PNP mode.  Read DOCs/BIOSaccess.txt           >> $RECORD
    echo >> $RECORD
  fi
fi    

read -p "To finish: 	Enter"
echo

if [ "$MODEM_ID" = "11c1:0442" ] ; then  
  echo "The "$MODEM_ID" modems have an electro-optical coupling"   >> $RECORD
  echo "which is Not adequately supported by these drivers."         >> $RECORD
  echo "There will likely be a failure of the drivers to recognize the modem."   >> $RECORD
  echo "Browse within DOCs/Insert-param4.txt "   >> $RECORD
  echo   >> $RECORD
fi  

echo "Some combination ethernet-modem cards are not properly detected"
echo "	by the lspci tool used in the above scan,"
echo "	for example, the ComOne MC221 Cardbus modem card."	
echo "	They may netherless achieve support with some extra effort."
echo "	See within DOCs/Ltmomdem.html, the URL for  ComOne MC221"
echo


