#!/bin/bash

case "$1" in
'mem')
  USE_MEM=''
  USE_NET='#'
  ;;
'net')
  USE_MEM='#'
  USE_NET=''
  ;;
'both')
  echo "This probably won't work..."
  USE_MEM=''
  USE_NET=''
  ;;
*)
  echo 'sandisk_plus mem | net'
  exit 1
esac

sudo umount /mnt/cf/

cat > /etc/pcmcia/sandisk_plus.conf << EOF
device "hostap_cs"
   class "hostap_fw" module "hostap", "hostap_cs", "hostap_crypt_wep", "hostap_crypt_tkip"

# SanDisk ConnectPlus is only supported as a hard drive
#
card "SanDisk ConnectPlus"
#  version "SanDisk", "ConnectPlus"
  manfid 0xd601, 0x0101
$USE_NET  bind "hostap_cs" to 0
$USE_MEM  bind "ide_cs" to 1

# uncomment this line for SanDisk ConnectPLus CF card support
#include port 0x100-0x4ff, port 0x800-0x8ff, port 0xc00-0xcff 
#include port 0x110-0x4ff, port 0x800-0x8ff, port 0xc00-0xcff

# Optional configuration parameters for hostap_cs.o
# module "hostap_cs" opts "channel=3 iw_mode=3 essid=test ignore_cis_vcc=0"
# module "hostap_cs" opts "dev_template=eth%d"
EOF

cardctl eject
/etc/rc.d/init.d/pcmcia restart
cardctl insert
