#!/bin/sh
#
# bluetooth
#
# PCMCIA Bluetooth device initialization
# Original script by Maxim Krasnyanskiy <maxk@qualcomm.com>
#
# The original script has been adapted for the use of udev and the new
# kernel-based PCMCIA-system.
#
# adaption for Debian by Filippo Giunchedi <filippo@debian.org>
#
# This script is assumed to be run from udev as
#
#	bluetooth.sh $sysfs{manf_id} $sysfs{card_id}
#

TYPEID=$1","$2

start_serial() {
	[ -x /etc/init.d/bluetooth ] && /etc/init.d/bluetooth start

	IRQ=`setserial $DEVNAME | sed -e 's/.*IRQ: //'`
	setserial $DEVNAME irq 0 ; setserial $DEVNAME irq $IRQ

	DEVICE=`echo $DEVNAME|sed -e 's_/dev/__'`
	# I don't have a generic solution, sorry
	if [ $TYPEID = "0x0160,0x0002" ]; then
		/usr/sbin/hciattach $DEVICE $TYPEID 115200
	else
		/usr/sbin/hciattach $DEVICE $TYPEID
	fi
}

stop_serial() {
	[ -x /bin/fuser ] || return 1 
    /bin/fuser -k -HUP $DEVNAME > /dev/null
}

case "$ACTION" in
  add)
	start_serial
	;;
  remove)
	stop_serial
	;;
  *)
	logger "Unknown action received $0: $ACTION"
	;;
esac
