140006Sphk#!/bin/sh
240006Sphk#
366830Sobrien# Copyright (c) 2000  The FreeBSD Project
466830Sobrien# All rights reserved.
540006Sphk#
666830Sobrien# Redistribution and use in source and binary forms, with or without
766830Sobrien# modification, are permitted provided that the following conditions
866830Sobrien# are met:
966830Sobrien# 1. Redistributions of source code must retain the above copyright
1066830Sobrien#    notice, this list of conditions and the following disclaimer.
1166830Sobrien# 2. Redistributions in binary form must reproduce the above copyright
1266830Sobrien#    notice, this list of conditions and the following disclaimer in the
1366830Sobrien#    documentation and/or other materials provided with the distribution.
1466830Sobrien#
1566830Sobrien# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1666830Sobrien# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1766830Sobrien# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1866830Sobrien# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1966830Sobrien# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2066830Sobrien# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2166830Sobrien# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2266830Sobrien# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2366830Sobrien# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2466830Sobrien# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2566830Sobrien# SUCH DAMAGE.
2666830Sobrien#
2750472Speter# $FreeBSD$
2866830Sobrien#
2940006Sphk
30100280Sgordon# PROVIDE: atm1
31100280Sgordon# REQUIRE: root
32113676Smtm# BEFORE: netif
33136224Smtm# KEYWORD: nojail
34100280Sgordon
35100280Sgordon. /etc/rc.subr
36100280Sgordon
37100280Sgordonname="atm"
38100280Sgordonrcvar="atm_enable"
39100280Sgordonstart_cmd="atm_start"
40100280Sgordonstop_cmd=":"
41100280Sgordon
4266830Sobrien# ATM networking startup script
4366830Sobrien#
4440006Sphk# Initial interface configuration.
4540006Sphk# N.B. /usr is not mounted.
4640006Sphk#
47104181Smdoddatm_start()
48100280Sgordon{
49118123Sharti	if [ -n "${natm_interfaces}" ] ; then
50118123Sharti		# Load the HARP pseudo interface
51165683Syar		load_kld if_harp || return 1
52118123Sharti
53118123Sharti		# Load all the NATM drivers that we need
54118123Sharti		for natm in ${natm_interfaces} ; do
55118123Sharti			ifconfig ${natm} up
56118123Sharti		done
57118123Sharti	fi
58118123Sharti
59118123Sharti	# Load loadable HARP drivers
60118123Sharti	for dev in ${atm_load} ; do
61165683Syar		load_kld ${dev} || return 1
62118123Sharti	done
63118123Sharti
6451231Ssheldonh	# Locate all probed ATM adapters
6551231Ssheldonh	atmdev=`atm sh stat int | while read dev junk; do
6651231Ssheldonh		case ${dev} in
6751231Ssheldonh		hea[0-9] | hea[0-9][0-9])
6851231Ssheldonh			echo "${dev} "
6951231Ssheldonh			;;
7051231Ssheldonh		hfa[0-9] | hfa[0-9][0-9])
7151231Ssheldonh			echo "${dev} "
7251231Ssheldonh			;;
73104181Smdodd		idt[0-9] | idt[0-9][0-9])
74104181Smdodd			echo "${dev} "
75104181Smdodd			;;
76118123Sharti
77118123Sharti		# NATM interfaces per pseudo driver
78118123Sharti		en[0-9] | en[0-9][0-9])
79118123Sharti			echo "${dev} "
80118123Sharti			;;
81118123Sharti		fatm[0-9] | fatm[0-9][0-9])
82118123Sharti			echo "${dev} "
83118123Sharti			;;
84118123Sharti		hatm[0-9] | hatm[0-9][0-9])
85118123Sharti			echo "${dev} "
86118123Sharti			;;
87118123Sharti		patm[0-9] | patm[0-9][0-9])
88118123Sharti			echo "${dev} "
89118123Sharti			;;
9051231Ssheldonh		*)
9151231Ssheldonh			continue
9251231Ssheldonh			;;
9351231Ssheldonh		esac
9451231Ssheldonh	done`
9540006Sphk
9651231Ssheldonh	if [ -z "${atmdev}" ]; then
9770108Sdougb		echo 'No ATM adapters found'
9851231Ssheldonh		return 0
9940006Sphk	fi
10040006Sphk
10151231Ssheldonh	# Load microcode into FORE adapters (if needed)
10251231Ssheldonh	if [ `expr "${atmdev}" : '.*hfa.*'` -ne 0 ]; then
10357230Sphk		fore_dnld
10440006Sphk	fi
10540006Sphk
10651231Ssheldonh	# Configure physical interfaces
10751231Ssheldonh	ilmid=0
10851231Ssheldonh	for phy in ${atmdev}; do
10951231Ssheldonh		echo -n "Configuring ATM device ${phy}:"
11040006Sphk
11151231Ssheldonh		# Define network interfaces
11251231Ssheldonh		eval netif_args=\$atm_netif_${phy}
11351231Ssheldonh		if [ -n "${netif_args}" ]; then
11451231Ssheldonh			atm set netif ${phy} ${netif_args} || continue
11551231Ssheldonh		else
11670108Sdougb			echo ' missing network interface definition'
11740006Sphk			continue
11840006Sphk		fi
11951231Ssheldonh
12051231Ssheldonh		# Override physical MAC address
12151231Ssheldonh		eval macaddr_args=\$atm_macaddr_${phy}
12251231Ssheldonh		if [ -n "${macaddr_args}" ]; then
12351231Ssheldonh			case ${macaddr_args} in
12451231Ssheldonh			[Nn][Oo] | '')
12551231Ssheldonh				;;
12651231Ssheldonh			*)
12751231Ssheldonh				atm set mac ${phy} ${macaddr_args} || continue
12851231Ssheldonh				;;
12951231Ssheldonh			esac
13051231Ssheldonh		fi
13151231Ssheldonh
13251231Ssheldonh		# Configure signalling manager
13351231Ssheldonh		eval sigmgr_args=\$atm_sigmgr_${phy}
13451231Ssheldonh		if [ -n "${sigmgr_args}" ]; then
13551231Ssheldonh			atm attach ${phy} ${sigmgr_args} || continue
13640006Sphk		else
13770108Sdougb			echo ' missing signalling manager definition'
13851231Ssheldonh			continue
13940006Sphk		fi
14040006Sphk
14151231Ssheldonh		# Configure UNI NSAP prefix
14251231Ssheldonh		eval prefix_args=\$atm_prefix_${phy}
14351231Ssheldonh		if [ `expr "${sigmgr_args}" : '[uU][nN][iI].*'` -ne 0 ]; then
14451231Ssheldonh			if [ -z "${prefix_args}" ]; then
14570108Sdougb				echo ' missing NSAP prefix for UNI interface'
14651231Ssheldonh				continue
14751231Ssheldonh			fi
14840006Sphk
14951231Ssheldonh			case ${prefix_args} in
15051231Ssheldonh			ILMI)
15151231Ssheldonh				ilmid=1
15251231Ssheldonh				;;
15351231Ssheldonh			*)
15451231Ssheldonh				atm set prefix ${phy} ${prefix_args} || continue
15551231Ssheldonh				;;
15651231Ssheldonh			esac
15751231Ssheldonh		fi
15840006Sphk
15951231Ssheldonh		atm_phy="${atm_phy} ${phy}"
16070108Sdougb		echo '.'
16151231Ssheldonh	done
16251231Ssheldonh
16370108Sdougb	echo -n 'Starting initial ATM daemons:'
16451231Ssheldonh	# Start ILMI daemon (if needed)
16551231Ssheldonh	case ${ilmid} in
16651231Ssheldonh	1)
16770108Sdougb		echo -n ' ilmid'
16851231Ssheldonh		ilmid
16951231Ssheldonh		;;
17051231Ssheldonh	esac
17151231Ssheldonh
17270108Sdougb	echo '.'
17340006Sphk}
17440006Sphk
175100280Sgordonload_rc_config $name
176100280Sgordonrun_rc_command "$1"
177