1#!/bin/sh
2#
3# Copyright (c) 2000  The FreeBSD Project
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD$
28#
29
30# PROVIDE: atm1
31# REQUIRE: root
32# BEFORE: netif
33# KEYWORD: nojail
34
35. /etc/rc.subr
36
37name="atm"
38rcvar="atm_enable"
39start_cmd="atm_start"
40stop_cmd=":"
41
42# ATM networking startup script
43#
44# Initial interface configuration.
45# N.B. /usr is not mounted.
46#
47atm_start()
48{
49	if [ -n "${natm_interfaces}" ] ; then
50		# Load the HARP pseudo interface
51		load_kld if_harp || return 1
52
53		# Load all the NATM drivers that we need
54		for natm in ${natm_interfaces} ; do
55			ifconfig ${natm} up
56		done
57	fi
58
59	# Load loadable HARP drivers
60	for dev in ${atm_load} ; do
61		load_kld ${dev} || return 1
62	done
63
64	# Locate all probed ATM adapters
65	atmdev=`atm sh stat int | while read dev junk; do
66		case ${dev} in
67		hea[0-9] | hea[0-9][0-9])
68			echo "${dev} "
69			;;
70		hfa[0-9] | hfa[0-9][0-9])
71			echo "${dev} "
72			;;
73		idt[0-9] | idt[0-9][0-9])
74			echo "${dev} "
75			;;
76
77		# NATM interfaces per pseudo driver
78		en[0-9] | en[0-9][0-9])
79			echo "${dev} "
80			;;
81		fatm[0-9] | fatm[0-9][0-9])
82			echo "${dev} "
83			;;
84		hatm[0-9] | hatm[0-9][0-9])
85			echo "${dev} "
86			;;
87		patm[0-9] | patm[0-9][0-9])
88			echo "${dev} "
89			;;
90		*)
91			continue
92			;;
93		esac
94	done`
95
96	if [ -z "${atmdev}" ]; then
97		echo 'No ATM adapters found'
98		return 0
99	fi
100
101	# Load microcode into FORE adapters (if needed)
102	if [ `expr "${atmdev}" : '.*hfa.*'` -ne 0 ]; then
103		fore_dnld
104	fi
105
106	# Configure physical interfaces
107	ilmid=0
108	for phy in ${atmdev}; do
109		echo -n "Configuring ATM device ${phy}:"
110
111		# Define network interfaces
112		eval netif_args=\$atm_netif_${phy}
113		if [ -n "${netif_args}" ]; then
114			atm set netif ${phy} ${netif_args} || continue
115		else
116			echo ' missing network interface definition'
117			continue
118		fi
119
120		# Override physical MAC address
121		eval macaddr_args=\$atm_macaddr_${phy}
122		if [ -n "${macaddr_args}" ]; then
123			case ${macaddr_args} in
124			[Nn][Oo] | '')
125				;;
126			*)
127				atm set mac ${phy} ${macaddr_args} || continue
128				;;
129			esac
130		fi
131
132		# Configure signalling manager
133		eval sigmgr_args=\$atm_sigmgr_${phy}
134		if [ -n "${sigmgr_args}" ]; then
135			atm attach ${phy} ${sigmgr_args} || continue
136		else
137			echo ' missing signalling manager definition'
138			continue
139		fi
140
141		# Configure UNI NSAP prefix
142		eval prefix_args=\$atm_prefix_${phy}
143		if [ `expr "${sigmgr_args}" : '[uU][nN][iI].*'` -ne 0 ]; then
144			if [ -z "${prefix_args}" ]; then
145				echo ' missing NSAP prefix for UNI interface'
146				continue
147			fi
148
149			case ${prefix_args} in
150			ILMI)
151				ilmid=1
152				;;
153			*)
154				atm set prefix ${phy} ${prefix_args} || continue
155				;;
156			esac
157		fi
158
159		atm_phy="${atm_phy} ${phy}"
160		echo '.'
161	done
162
163	echo -n 'Starting initial ATM daemons:'
164	# Start ILMI daemon (if needed)
165	case ${ilmid} in
166	1)
167		echo -n ' ilmid'
168		ilmid
169		;;
170	esac
171
172	echo '.'
173}
174
175load_rc_config $name
176run_rc_command "$1"
177