3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
34 * General ATM signalling management
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/socket.h>
41 #include <sys/socketvar.h>
43 #include <netatm/port.h>
44 #include <netatm/queue.h>
45 #include <netatm/atm.h>
46 #include <netatm/atm_sys.h>
47 #include <netatm/atm_sap.h>
48 #include <netatm/atm_cm.h>
49 #include <netatm/atm_if.h>
50 #include <netatm/atm_sigmgr.h>
51 #include <netatm/atm_stack.h>
52 #include <netatm/atm_pcb.h>
53 #include <netatm/atm_var.h>
56 __RCSID("@(#) $FreeBSD$");
63 static struct sigmgr *atm_sigmgr_head = NULL;
64 static struct stack_defn *atm_stack_head = NULL;
68 * Register a new Signalling Manager
70 * Each Signalling Manager must register itself here upon completing
71 * its internal initialization. This applies to both linked and loaded
75 * smp pointer to Signalling Manager description
78 * 0 registration was successful
79 * errno registration failed - reason indicated
83 atm_sigmgr_register(smp)
90 * See if we need to be initialized
96 * Make sure there's only one instance of each protocol
98 for (smp2 = atm_sigmgr_head; smp2 != NULL; smp2 = smp2->sm_next) {
99 if (smp->sm_proto == smp2->sm_proto) {
106 * Looks okay, link it in
108 LINK2TAIL(smp, struct sigmgr, atm_sigmgr_head, sm_next);
116 * De-register a Signalling Manager
118 * Each Signalling Manager must de-register (is this really a word?)
119 * itself before removing itself from the system. This really only
120 * applies to managers about to be modunload'ed. It is the signal
121 * manager's responsibility to ensure that all its protocol instances
122 * have been successfully terminated before de-registering itself.
125 * smp pointer to Signalling Manager description
128 * 0 deregistration was successful
129 * errno deregistration failed - reason indicated
133 atm_sigmgr_deregister(smp)
136 int found, s = splnet();
141 UNLINKF(smp, struct sigmgr, atm_sigmgr_head, sm_next, found);
153 * Attach a Signalling Manager to an ATM physical interface
155 * Each ATM physical interface must have a signalling manager attached to
156 * itself for the signalling protocol to be run across this interface. The
157 * interface must be registered and completely initialized before the attach,
158 * since the signalling manager may initiate virtual circuit activity as part
159 * its response to this call.
164 * pip pointer to atm physical interface control block
165 * proto requested signalling protocol
168 * 0 attach successful
169 * errno attach failed - reason indicated
173 atm_sigmgr_attach(pip, proto)
182 * Make sure interface is registered
184 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
193 * Make sure no signalling manager is already attached
195 if (pip->pif_sigmgr != NULL) {
200 * Must have at least one network interface defined
202 if (pip->pif_nif == NULL)
203 return (ETOOMANYREFS);
206 * Find requested protocol
208 for (smp = atm_sigmgr_head; smp != NULL; smp = smp->sm_next) {
209 if (smp->sm_proto == proto)
213 return (EPROTONOSUPPORT);
217 * Tell the signal manager about it
219 err = (*smp->sm_attach)(smp, pip);
222 * Tell all registered convergence modules about this
228 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
229 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
230 if ((err = (*ncp->ncm_stat)
231 (NCM_SIGATTACH, nip, 0)) != 0)
240 * Someone's unhappy, so back all this out
242 (void) atm_sigmgr_detach(pip);
251 * Detach an ATM physical interface from a Signalling Manager
253 * The ATM interface must be detached from the signalling manager
254 * before the interface can be de-registered.
259 * pip pointer to atm physical interface control block
262 * 0 detach successful
263 * errno detach failed - reason indicated
267 atm_sigmgr_detach(pip)
277 * Make sure interface is registered
279 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
288 * Make sure a signalling manager is attached
290 if (pip->pif_sigmgr == NULL) {
295 * Tell all registered convergence modules about this
297 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
298 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
299 (void) (*ncp->ncm_stat)(NCM_SIGDETACH, nip, 0);
304 * Tell the signal manager about it
307 * The only reason this should ever fail is if things are really
308 * hosed up somewhere, in which case doing a bunch of NCM_SIGATTACH's
309 * here just doesn't seem to help much.
311 err = (*pip->pif_sigmgr->sm_detach)(pip);
318 * Register an ATM Stack Service
320 * Each ATM stack service provider must register its provided service(s) here.
321 * Each service must be registered separately. Service providers include
322 * both loaded and linked kernel modules. Device driver services are NOT
323 * registered here - their service registry is performed implicitly through
324 * the device interface structure stack services list (pif_services).
327 * sdp pointer to stack service definition block
330 * 0 registration successful
331 * errno registration failed - reason indicated
335 atm_stack_register(sdp)
336 struct stack_defn *sdp;
338 struct stack_defn *tdp;
342 * See if we need to be initialized
348 * Ensure no duplicates
350 for (tdp = atm_stack_head; tdp != NULL; tdp = tdp->sd_next) {
351 if (tdp->sd_sap == sdp->sd_sap)
362 LINK2TAIL(sdp, struct stack_defn, atm_stack_head, sd_next);
370 * De-register an ATM Stack Service
372 * Each ATM stack service provider must de-register its registered service(s)
373 * before terminating the service. Specifically, loaded kernel modules
374 * must de-register their services before unloading themselves.
377 * sdp pointer to stack service definition block
380 * 0 de-registration successful
381 * errno de-registration failed - reason indicated
385 atm_stack_deregister(sdp)
386 struct stack_defn *sdp;
388 int found, s = splnet();
391 * Remove service from list
393 UNLINKF(sdp, struct stack_defn, atm_stack_head, sd_next, found);
404 * Create and Instantiate a Stack
406 * For the requested stack list, locate the stack service definitions
407 * necessary to build the stack to implement the listed services.
408 * The stack service definitions provided by the interface device-driver
409 * are always preferred, since they are (hopefully) done with
410 * hardware assistance from the interface card.
412 * After the stack has been built, the selected services are called to
413 * notify them of the new stack instantiation. Each service should then
414 * allocate all the resources it requires for this new stack instance.
415 * The service should then wait for subsequent protocol notification
416 * via its stack command handlers.
418 * Must be called at splnet.
421 * cvp pointer to connection vcc block for the created stack
422 * tlp pointer to stack list
423 * upf top-of-stack CM upper command handler
426 * 0 stack successfully created
427 * errno failed - reason indicated
431 atm_create_stack(cvp, tlp, upf)
433 struct stack_list *tlp;
434 void (*upf)(int, void *, int, int);
436 struct stack_defn *sdp, usd;
437 struct stack_inst svs;
438 struct atm_pif *pip = cvp->cvc_attr.nif->nif_pif;
443 * Initialize stack (element 0 is for owner's services)
445 svs.si_srvc[1] = sdp = NULL;
448 * Locate service provider for each service in the
449 * stack list. We prefer interface driver providers
450 * over kernel module providers.
452 for (i = 0; i < STACK_CNT; i++) {
455 /* Stack list is 0-terminated */
456 if ((sap = tlp->sl_sap[i]) == 0)
460 * Search interface's services
462 for (sdp = pip->pif_services; sdp; sdp = sdp->sd_next)
463 if (sdp->sd_sap == sap)
468 * Search kernel services
470 for (sdp = atm_stack_head; sdp;
472 if (sdp->sd_sap == sap)
478 * Requested service id not found
484 * Save stack definition for this service
486 svs.si_srvc[i+1] = sdp;
489 * Quit loop if this service is terminal, ie. if
490 * it takes care of the rest of the stack.
492 if (sdp->sd_flag & SDF_TERM)
497 * Ensure stack instance array is located and terminated
499 if ((svs.si_srvc[1] == NULL) || !(sdp->sd_flag & SDF_TERM)) {
504 * Setup owner service definition
506 bzero((caddr_t)&usd, sizeof(struct stack_defn));
509 svs.si_srvc[0] = &usd;
512 * Instantiate the stack
514 err = (*svs.si_srvc[1]->sd_inst)(&svs.si_srvc[0], cvp);
520 * Save top 'o stack info
522 cvp->cvc_lower = svs.si_srvc[1]->sd_lower;
523 cvp->cvc_tokl = svs.si_srvc[1]->sd_toku;