#/bin/sh
#
# Adapted for Lucent DSP modem scan by Chris Hebeisen
# Some diaplays added by Marv Stodolsky

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
  fi
done
if test -z $LSPCI
then
  echo "+-----------------------------------------------------------------------------+"
  echo "| WARNING: lspci not found or not executable - not checking for modem         |"
  echo "+-----------------------------------------------------------------------------+"
  echo
  exit 1
  echo 
else
  if ! $LSPCI >/dev/null 2>/dev/null
  then
    echo "WARNING: $LSPCI returned error - not checking for modem"
    echo
    echo Exiting
    echo
    exit 1
  fi
fi
echo "  ... using $LSPCI"
echo
# ending lspci test section

# BN can be inherited from ./build_module or Installer or checkout
if test -z "$BN" ; then 
  BN=`basename $0`
fi
# step through not desirable in environments except
if test "$BN" = "build_module" || test "$BN" = "scanPCI" || test "$BN" = "checkout" || test "$BN" = "Checkout" ; then
  FAST=
else
  FAST=1
fi
# echo BN=$BN
# echo FAST=$FAST

if test -z "$TMPM" ; then
  TMPM=tmpfile
fi

# If a RECORD is not inherited from ./build_module or Installer, start a RECORD
if test -z "$RECORD" ; then
  RECORD=ModemData.txt
  echo > $RECORD
fi
echo BN=$BN >> $RECORD
echo  LSPCI="$LSPCI" >>  $RECORD
echo TMPM=$TMPM >>  $RECORD

# A general Advisory
ETHER=`$LSPCI | grep Ether | cut -d' ' -f1`
if test -n "$ETHER" ; then
  echo >> $RECORD
  echo The System has Ethernet capability: >> $RECORD
  $LSPCI -s $ETHER >> $RECORD
  echo Unless a communications expert, is is adviseable to >> $RECORD
  echo unload Ethernet drivers before initiated modem usage. >> $RECORD
  echo  >> $RECORD
fi
 
#                            Class 07nn: are Modem devices
PCIMODEMS=`$LSPCI -n | grep "Class 07" | cut -d' ' -f1`
if test -n "$PCIMODEMS" ; then
cat <<END >> $TMPM.1
  PCI_IDs of unsupported Lucent AMR modems include:  
  ---- Vendor:
  ALI    10B9:5450 10B9:5457  
  Intel  8086:2416 8086:2426 8086:2446 8086:2486 8086:7196
  VIA    1106:3068 
  SIS    1039:7013
  Lucent 11C1:048C 11C1:048E 11C1:048F Lucent prototypes
END
# For Lucent DSP test
  DEVICES="0x11c1:0x0440-0x045c"
  DEVICES=$DEVICES" 0x115d:0x0000-0x000f"
  DEVICES=$DEVICES" 0x115d:0x0440-0x045c"
  DEVICES=$DEVICES" 0x115d:0x0010-0x03ff"

echo > $TMPM
echo "By the  Class 07nn: criteria, detected system PCI modem devices are:" >> $TMPM
echo >> $TMPM
echo "device  Class   VendorID:DeviceID == ModemID" >> $TMPM
echo ---------------------------------------------------------------- >> $TMPM
# echo PCIMODEMS=$PCIMODEMS >> $TMPM
for MODEM in $PCIMODEMS
do
  $LSPCI -s $MODEM -n    >> $TMPM
  $LSPCI -s $MODEM   >> $TMPM
  PCIDEV=`$LSPCI -s $MODEM -n | cut -d' ' -f4`
  if grep $PCIDEV $TMPM.1 > /dev/null ; then
    echo This AMR modem is NOT supported, within the group: >> $TMPM
  else
#    echo Checking now for DSP Lucent modem >> $TMPM
    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"
        MODEM_ID="$PCIDEV" 
        MODEM_VENDOR=0x`echo $PCIDEV | cut -d':' -f1`
        MODEM_DEVICE=0x`echo $PCIDEV | cut -d':' -f2`
        if [ "$MODEM_VENDOR" = "0x11c1" ] ; then
          VENDED=LUCENT
        else
          VENDED=XIRCOM
        fi 
        echo "VENDOR $MODEM_VENDOR     DEVICE $MODEM_DEVICE" >> $TMPM
        echo "ID are within the serviced ranges:" >> $TMPM
      fi
    done
  fi
done
cat $TMPM
cat $TMPM >> $RECORD
fi

if test -z "$FAST" ; then
  read -p "To continue:	Enter"
else
  sleep 3
fi
echo

if test -z "$MODEM_ID"
then
cat <<END > $TMPM.2
  The ltmodem drivers will FAIL to support currently known 
  winmodems with chipsets produced by: 3COM/US Robotics, Conexant, IBM, 
  Intel, Motorola, ESS and PCTel.
  The Lucent AMR Soft modem is NOT supported. 
  The Lucent Venus modems have a Controller supported by the serial.o driver,
      rather than DSP supporting driver pair, lt_modem.o and lt_serial.o
  Among Xircom modems some are supported, and these will be
      reported out during this test.
  There are supported ISA and PCMCIA card modems,
      but these types are NOT accessed by this scan.
  For PCMCIA with a Texas Instruments bridge, an ltmodem-cs.tar.gz 
  resource at http://www.heby.de/ltmodem may be necessary.
END
cat $TMPM.2
echo  "+----------------------------------------------------------------------------+"
echo  "| WARNING: If your modem is a PCI modem it will probably                     |"
echo  "|          not work with the DSP driver pair:   lt_modem + lt_serial         |"
echo  "+----------------------------------------------------------------------------+"
    
else
  echo "A supported DSP Modem verified:"
  echo MODEM_ID=$MODEM_ID
fi
cat <<END > $TMPM

IDs of supported Lucent DSP PCI modems have ranges:
Vendor  vendor_id   device_id range  
-----------------------------------------------
LUCENT 0x11c1          0x0440-0x045c
XIRCOM 0x115d          0x0000-0x000F
XIRCOM 0x115d          0x0440-0x045c
XIRCOM 0x115d          0x0010-0x03ff

END

cat $TMPM
cat $TMPM >> $RECORD


if test -n "$MODEM_ID" ; then
  echo "VENDOR=$VENDED with MODEM_ID=$MODEM_ID" >> $RECORD
  echo "	To see detailed information on $MODEM_ID"

# Setting up board.info for grepping MODEL_DATA
cat <<END > $TMPM.1
 0x0440 -- Mars 2 - data/fax/voice 
 0x0441 -- Mars 2 - data/fax only 
 0x0442 -- Mars 2 - data/fax/tam only 
 0x0448 -- Mars 2 Global Board - data/fax/voice 
 0x0449 -- Mars 2 Global Board - data/fax only 
 0x044A -- Mars 2 Global Board - data/fax/tam only 
 0x0444 -- Apollo 2 data/fax only : Modem/LAN combo board Apollo behind an Intel 82559 
 0x0445 -- Apollo 2 Global Board data/fax only : Modem/LAN combo board Apollo behind an Intel 82559 
 0x0446 -- Apollo 2 data/fax/voice : Modem/LAN combo board Apollo behind an Intel 82559 
 0x0447 -- Apollo 2 Global Board data/fax/voice : Modem/LAN combo board Apollo behind an Intel 82559 
 0x044C -- Mars 3 Perseus data/fax only:North America and Global board 
 0x044E -- Mars 3 Mercury data fax only 
 0x0450 -- Mars 3 Mercury data fax Global board 
 0x0451 -- Mars 3 Mercury data/fax/voice 
 0x0452 -- Mars 3 Mercury data/fax/voice Global board 
 0x0455 -- Mars 3 Perseus data/fax/voice: North America and Global board 
 0x0458 -- Mars 3 Mercury data/fax/tam only. 
 0x0459 -- Mars 3 Mercury data/fax/tam only. Global board. 
 0x045A -- Mars 3 Perseus data/fax/tam only.: North America and Global board 
 0x045B -- Apollo 3 Perseus data/fax only : Modem/LAN combo board Apollo behind an Intel 82559 
 0x045C -- Apollo 3 Mercury data/fax only : Modem/LAN combo board Apollo behind an Intel 82559 
 0x045D -- Mars 3 Mercury data/fax/tam only. Global board for Cardbus modem product. 
 0x044C -- Mars 3.2 Mercury data fax only when no eeprom is present: North America DAA 
END
  read -p "Enter"
  echo 
  echo Copying this detailed information to $RECORD
  echo "----------------------------------------------" > $TMPM
  if grep $MODEM_DEVICE $TMPM.1 > /dev/null ; then
    MODEL_DATA=`grep $MODEM_DEVICE $TMPM.1`  
    echo MODEL_DATA=$MODEL_DATA >> $TMPM
  fi
  $LSPCI -d $MODEM_ID   >> $TMPM
  $LSPCI -d $MODEM_ID -nvv  >> $TMPM
  echo "----------------------------------------------" >> $TMPM
  IRQ=`$LSPCI -vv -d $MODEM_ID | grep Interrupt | cut -d' ' -f7`
  if [ "$IRQ" = "0" ] ; then
    echo
    echo "	`$LSPCI -d $MODEM_ID -vv | grep Interrupt`" >> $TMPM
    echo "The interrupt assignment:	 IRQ 0"              >> $TMPM
    echo predicts that modem function will fail unless       >> $TMPM
    echo the boot up BIOS can be accessed to change to       >> $TMPM
    echo a non-PNP mode.  Read DOCs/BIOSaccess.txt           >> $TMPM
    echo >> $TMPM
  fi  
  cat  $TMPM
  cat  $TMPM  >> $RECORD
  if [ "$MODEM_ID" = "11c1:0442" ] ; then  
    echo "The "$MODEM_ID" modems have an electro-optical coupling" >> $RECORD
    echo "which in some hardware 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
  if [ "$VENDED" = "LUCENT" ] ; then
    echo "Get Lucent/Agere information at:"   >> $RECORD 
    echo "	http://www.agere.com/support/client/modem_drivers.html"  >> $RECORD
  else 
    echo "	http://appsr.intel.com/scripts-df/support_intel2.asp"  >> $RECORD
    echo XIRCOM is now owned by Intel  >> $RECORD
    echo "	http://support.intel.com/"  >> $RECORD
  fi     
else
  echo Starting a check for an alternate PCI Communication device.
  if test -z "$FAST" ; then
    read -p "To continue:	Enter"
  else
    sleep 3
  fi
  echo
  echo ommunication >  $TMPM 
  echo Modem >>  $TMPM 
  echo modem >>  $TMPM 
  echo erial controller >>  $TMPM 
  OTHERS=`$LSPCI -v | grep -f  $TMPM  | cut -d' ' -f1`
  if test -n "$OTHERS" ; then
    for OTHER in $OTHERS
    do
      MODEM_ID=`$LSPCI -nv | grep $OTHER | cut -d' ' -f4`
      SUBS=`$LSPCI -s $OTHER -v | grep Subsystem`
      echo Found PCI_DEVICE=$MODEM_ID > $TMPM 
      echo MODEM_ID=$MODEM_ID >> $TMPM 
      $LSPCI -s $OTHER >> $TMPM 
      $LSPCI -s $OTHER -nv >> $TMPM 
      echo
    done 
  else
    echo No obvious modem Communication device found among the PCI devices.
    echo "-------------- PCI devices --------------------------"  >> $TMPM
    $LSPCI >> $TMPM    
  fi
  cat $TMPM 
  cat $TMPM >> $RECORD
  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
fi

if [ "$RECORD" = "ModemData.txt" ] ; then
cat <<END > $TMPM

Some useful URLs for related information are:  
    http://www.yourvote.com/pci/ 
for searching by PCI IDs, and general advice at  
    http://linmodems.technion.ac.il/ 
The original Linux winmodems URL is: 
    http://linmodems.org 
with a a mailing list on Winmodems: 
    discuss@linmodems.org 
Its archives can be searched at: 
    http://linmodems.technion.ac.il/wgindex.html 
There is an extensive modem database at: 
    http://www.idir.net/~gromitkc/winmodem.html 
END
cat $TMPM >> $RECORD
fi

if [ "$BN" = "scanPCI" ] ; then
  echo See the diagnostic output from this $0: 
  echo "cat $RECORD"
  read -p "Enter"
  more $RECORD
  echo
fi
rm "$TMPM"* > /dev/null


