#!/bin/sh
# Checks for modems with id in the supported ranges
 
# locate needed lspci
LSPCI_PATH="/bin /sbin"
for i in $LSPCI_PATH   
do
  if test -x $i/lspci
  then
    LSPCI=$i/lspci
  fi
done

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 "Among Xircom modems some are supported, and these will be"
echo "    reported out during this test."
echo "PCMCIA card modems are NOT accessed by this $0 utilty."
echo
if test ! -x $LSPCI
then
  echo "+-----------------------------------------------------------------------------+"
  echo "| WARNING: /sbin/lspci not found or not executable - not checking for modem   |"
  echo "+-----------------------------------------------------------------------------+"
else
  FOUND="no"

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

  if ! /sbin/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 "Found modem: $PCIDEV"
	  echo "  This modem should be serviced by the ltmodem drivers."
          MODEM_VENDOR=0x`echo $PCIDEV | cut -d':' -f1`
          MODEM_DEVICE=0x`echo $PCIDEV | cut -d':' -f2`
          echo "The id are within the serviced ranges:"
          echo "Name 		vendor_id	device id range"
          echo "-----------------------------------------------"
          echo "LUCENT		0x11c1		0x0440-0x045c	"
          echo "XIRCOM		0x115d		0x0000-0x000F	"
          echo "XIRCOM		0x115d		0x0440-0x045c	"
          echo "XIRCOM	  	0x115d          0x0010-0x03ff   "	
        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 "+----------------------------------------------------------------------------+"  
    fi
  fi
fi
echo
echo "Hope this helps, Bye."
echo
