#!/bin/sh
#
# bluetooth
#
# PCMCIA Bluetooth device initialization
# Written by Maxim Krasnyanskiy <maxk@qualcomm.com>
#
# This script requires new cardmgr and expects following
# environment variables FUNCTION, VENDORID, CARDNAME
#

#
# $Id: bluetooth,v 1.5 2004/05/12 21:48:08 holtmann Exp $
#

if [ -r ./shared ]; then . ./shared ; else . /etc/pcmcia/shared ; fi

# Get device attributes
get_info $DEVICE

#
# Serial devices
#
start_serial() {
    # perhaps we should check /etc/sysconfig/bluetooth:START_SERVICES here
    # we have a problem: a running hcid is needed, otherwise errors occure
    # if we have none, we nevertheless try it.
    [ -x /etc/init.d/bluetooth ] && /etc/init.d/bluetooth start

    IRQ=`setserial /dev/$DEVICE | sed -e 's/.*IRQ: //'`
    setserial /dev/$DEVICE irq 0 ; setserial /dev/$DEVICE irq $IRQ
 
    # I don't have a generic solution, sorry
    if [ $MANFID = "0160,0002" ]; then
    	/usr/sbin/hciattach $DEVICE $MANFID 115200
    else
    	/usr/sbin/hciattach $DEVICE $MANFID
    fi
}
stop_serial() {
    do_fuser -k -HUP /dev/$DEVICE > /dev/null
}
suspend_serial() {
    stop_serial
}
resume_serial() {
    start_serial
}

start=
stop=
suspend=
resume=
check=
cksum=

case "$FUNCID" in
2)  # Serial
    start=start_serial
    stop=stop_serial
    suspend=suspend_serial
    resume=resume_serial
    ;;
esac

eval \$$ACTION

exit 0
