#!/bin/sh
#
# Copyright (c) 2005 "Thomas Wintergerst" <twinterg@gmx.de>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD$
# $Id: i4bcapimgr,v 1.1.2.1 2005/05/27 16:29:31 thomas Exp $
# Creation date        23.03.2005
# Project              CAPI for BSD
#
# /etc/rc.d/capibase - Startup script for the link between c4b and i4b
#

# PROVIDE: i4bcapimgr
# REQUIRE: capibase capictlr
# BEFORE: isdnd
# KEYWORD: FreeBSD CAPI i4bcapimgr



. /etc/rc.subr

name="i4bcapimgr"
start_cmd="i4bcapimgr_start"
stop_cmd="i4bcapimgr_stop"



# Start the link between i4b and c4b if enabled by system configuraion
i4bcapimgr_start ()
{
	# check if CAPI and I4B are both configured
	case "${isdn_enable}" in
	[Yy][Ee][Ss])
		case "${capi_enable}" in
		[Yy][Ee][Ss])
	                echo -n 'i4bcapimgr '
			if ! sysctl capi.i4bcapimgr.version > /dev/null 2>&1; then
				if kldload i4bcapimgr; then
					debug 'I4B CAPI manager controller driver module loaded.'
				else
					warn 'I4B CAPI manager controller driver module failed to load.'
				fi
			fi
			;;
		esac
		;;
	esac
}



# Unload the link between i4b and c4b
i4bcapimgr_stop ()
{
	if kldstat -n i4bcapimgr > /dev/null 2>&1; then
		if kldunload i4bcapimgr; then
			debug 'I4B CAPI manager controller driver module unloaded.'
		else
			warn 'I4B CAPI manager controller driver module failed to unload.'
		fi
	fi
}



load_rc_config $name
run_rc_command "$1"
