#!/bin/sh
#
# bluetooth
#
# Initialize a PCMCIA Bluetooth device
# Written by Colin Pinkney <colin.pinkney@orange.net>
#
# $1 - start/stop
# $2 - HCI device (e.g. hci0)
#

IDENT="/sbin/cardctl ident"
UART_CONF="/etc/bluetooth/uart"

ID=`$IDENT | grep info: | sed 's/^ *product info: *//'`
TYPE=`$IDENT | grep function: | sed 's/^ *function: *//' | cut -f1 -d" "`

case "$1" in
start|resume)
   case "$TYPE" in
	# Serial device
	2)
	   [ -f /usr/sbin/hciattach -a -f $UART_CONF ] || exit 0
           ID=`/sbin/cardctl ident | grep info: | sed 's/^ *product info: *//' | sed 's/"/\\"/g'`
           UART_SET=`grep "$ID" $UART_CONF | cut -f2 -d":"`
           if [ "$UART_SET" != "" ]; then
              DEVICE=`echo $UART_SET | cut -f1 -d" "`
              IRQ=`setserial $DEVICE | sed -e 's/.*IRQ: //'`
              setserial $DEVICE irq 0 ; setserial $DEVICE irq $IRQ
              /usr/sbin/hciattach $UART_SET
           fi
        ;;
        *)
           # Do nothing for other types
        ;;
   esac
;;
stop|suspend)
   hciconfig $2 down
   sleep 1
   
   case "$TYPE" in
   2)
      killall hciattach > /dev/null 2>&1
   ;;
   *)
      # Do nothing specific for non-serial
   ;;
   esac
;;
esac

exit 0

