2 * ===================================
3 * HARP | Host ATM Research Platform
4 * ===================================
7 * This Host ATM Research Platform ("HARP") file (the "Software") is
8 * made available by Network Computing Services, Inc. ("NetworkCS")
9 * "AS IS". NetworkCS does not provide maintenance, improvements or
10 * support of any kind.
12 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
13 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
14 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
15 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
16 * In no event shall NetworkCS be responsible for any damages, including
17 * but not limited to consequential damages, arising from or relating to
18 * any use of the Software or related support.
20 * Copyright 1994-1998 Network Computing Services, Inc.
22 * Copies of this Software may be made, however, the above copyright
23 * notice must be reproduced on all copies.
30 * General ATM signalling management
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/socket.h>
39 #include <sys/socketvar.h>
41 #include <netatm/port.h>
42 #include <netatm/queue.h>
43 #include <netatm/atm.h>
44 #include <netatm/atm_sys.h>
45 #include <netatm/atm_sap.h>
46 #include <netatm/atm_cm.h>
47 #include <netatm/atm_if.h>
48 #include <netatm/atm_sigmgr.h>
49 #include <netatm/atm_stack.h>
50 #include <netatm/atm_pcb.h>
51 #include <netatm/atm_var.h>
57 static struct sigmgr *atm_sigmgr_head = NULL;
58 static struct stack_defn *atm_stack_head = NULL;
62 * Register a new Signalling Manager
64 * Each Signalling Manager must register itself here upon completing
65 * its internal initialization. This applies to both linked and loaded
69 * smp pointer to Signalling Manager description
72 * 0 registration was successful
73 * errno registration failed - reason indicated
77 atm_sigmgr_register(struct sigmgr *smp)
83 * See if we need to be initialized
89 * Make sure there's only one instance of each protocol
91 for (smp2 = atm_sigmgr_head; smp2 != NULL; smp2 = smp2->sm_next) {
92 if (smp->sm_proto == smp2->sm_proto) {
99 * Looks okay, link it in
101 LINK2TAIL(smp, struct sigmgr, atm_sigmgr_head, sm_next);
109 * De-register a Signalling Manager
111 * Each Signalling Manager must de-register (is this really a word?)
112 * itself before removing itself from the system. This really only
113 * applies to managers about to be modunload'ed. It is the signal
114 * manager's responsibility to ensure that all its protocol instances
115 * have been successfully terminated before de-registering itself.
118 * smp pointer to Signalling Manager description
121 * 0 deregistration was successful
122 * errno deregistration failed - reason indicated
126 atm_sigmgr_deregister(struct sigmgr *smp)
128 int found, s = splnet();
133 UNLINKF(smp, struct sigmgr, atm_sigmgr_head, sm_next, found);
145 * Attach a Signalling Manager to an ATM physical interface
147 * Each ATM physical interface must have a signalling manager attached to
148 * itself for the signalling protocol to be run across this interface. The
149 * interface must be registered and completely initialized before the attach,
150 * since the signalling manager may initiate virtual circuit activity as part
151 * its response to this call.
156 * pip pointer to atm physical interface control block
157 * proto requested signalling protocol
160 * 0 attach successful
161 * errno attach failed - reason indicated
165 atm_sigmgr_attach(struct atm_pif *pip, u_char proto)
172 * Make sure interface is registered
174 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
183 * Make sure no signalling manager is already attached
185 if (pip->pif_sigmgr != NULL) {
190 * Must have at least one network interface defined
192 if (pip->pif_nif == NULL)
193 return (ETOOMANYREFS);
196 * Find requested protocol
198 for (smp = atm_sigmgr_head; smp != NULL; smp = smp->sm_next) {
199 if (smp->sm_proto == proto)
203 return (EPROTONOSUPPORT);
207 * Tell the signal manager about it
209 err = (*smp->sm_attach)(smp, pip);
212 * Tell all registered convergence modules about this
218 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
219 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
220 if ((err = (*ncp->ncm_stat)
221 (NCM_SIGATTACH, nip, 0)) != 0)
230 * Someone's unhappy, so back all this out
232 (void) atm_sigmgr_detach(pip);
241 * Detach an ATM physical interface from a Signalling Manager
243 * The ATM interface must be detached from the signalling manager
244 * before the interface can be de-registered.
249 * pip pointer to atm physical interface control block
252 * 0 detach successful
253 * errno detach failed - reason indicated
257 atm_sigmgr_detach(struct atm_pif *pip)
266 * Make sure interface is registered
268 for (tp = atm_interface_head; tp != NULL; tp = tp->pif_next) {
277 * Make sure a signalling manager is attached
279 if (pip->pif_sigmgr == NULL) {
284 * Tell all registered convergence modules about this
286 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
287 for (ncp = atm_netconv_head; ncp; ncp = ncp->ncm_next) {
288 (void) (*ncp->ncm_stat)(NCM_SIGDETACH, nip, 0);
293 * Tell the signal manager about it
296 * The only reason this should ever fail is if things are really
297 * hosed up somewhere, in which case doing a bunch of NCM_SIGATTACH's
298 * here just doesn't seem to help much.
300 err = (*pip->pif_sigmgr->sm_detach)(pip);
307 * Register an ATM Stack Service
309 * Each ATM stack service provider must register its provided service(s) here.
310 * Each service must be registered separately. Service providers include
311 * both loaded and linked kernel modules. Device driver services are NOT
312 * registered here - their service registry is performed implicitly through
313 * the device interface structure stack services list (pif_services).
316 * sdp pointer to stack service definition block
319 * 0 registration successful
320 * errno registration failed - reason indicated
324 atm_stack_register(struct stack_defn *sdp)
326 struct stack_defn *tdp;
330 * See if we need to be initialized
336 * Ensure no duplicates
338 for (tdp = atm_stack_head; tdp != NULL; tdp = tdp->sd_next) {
339 if (tdp->sd_sap == sdp->sd_sap)
350 LINK2TAIL(sdp, struct stack_defn, atm_stack_head, sd_next);
358 * De-register an ATM Stack Service
360 * Each ATM stack service provider must de-register its registered service(s)
361 * before terminating the service. Specifically, loaded kernel modules
362 * must de-register their services before unloading themselves.
365 * sdp pointer to stack service definition block
368 * 0 de-registration successful
369 * errno de-registration failed - reason indicated
373 atm_stack_deregister(struct stack_defn *sdp)
375 int found, s = splnet();
378 * Remove service from list
380 UNLINKF(sdp, struct stack_defn, atm_stack_head, sd_next, found);
391 * Create and Instantiate a Stack
393 * For the requested stack list, locate the stack service definitions
394 * necessary to build the stack to implement the listed services.
395 * The stack service definitions provided by the interface device-driver
396 * are always preferred, since they are (hopefully) done with
397 * hardware assistance from the interface card.
399 * After the stack has been built, the selected services are called to
400 * notify them of the new stack instantiation. Each service should then
401 * allocate all the resources it requires for this new stack instance.
402 * The service should then wait for subsequent protocol notification
403 * via its stack command handlers.
405 * Must be called at splnet.
408 * cvp pointer to connection vcc block for the created stack
409 * tlp pointer to stack list
410 * upf top-of-stack CM upper command handler
413 * 0 stack successfully created
414 * errno failed - reason indicated
418 atm_create_stack(Atm_connvc *cvp, struct stack_list *tlp,
419 void (*upf)(int, void *, intptr_t, intptr_t))
421 struct stack_defn *sdp, usd;
422 struct stack_inst svs;
423 struct atm_pif *pip = cvp->cvc_attr.nif->nif_pif;
428 * Initialize stack (element 0 is for owner's services)
430 svs.si_srvc[1] = sdp = NULL;
433 * Locate service provider for each service in the
434 * stack list. We prefer interface driver providers
435 * over kernel module providers.
437 for (i = 0; i < STACK_CNT; i++) {
440 /* Stack list is 0-terminated */
441 if ((sap = tlp->sl_sap[i]) == 0)
445 * Search interface's services
447 for (sdp = pip->pif_services; sdp; sdp = sdp->sd_next)
448 if (sdp->sd_sap == sap)
453 * Search kernel services
455 for (sdp = atm_stack_head; sdp;
457 if (sdp->sd_sap == sap)
463 * Requested service id not found
469 * Save stack definition for this service
471 svs.si_srvc[i+1] = sdp;
474 * Quit loop if this service is terminal, ie. if
475 * it takes care of the rest of the stack.
477 if (sdp->sd_flag & SDF_TERM)
482 * Ensure stack instance array is located and terminated
484 if ((svs.si_srvc[1] == NULL) || !(sdp->sd_flag & SDF_TERM)) {
489 * Setup owner service definition
491 bzero((caddr_t)&usd, sizeof(struct stack_defn));
494 svs.si_srvc[0] = &usd;
497 * Instantiate the stack
499 err = (*svs.si_srvc[1]->sd_inst)(&svs.si_srvc[0], cvp);
505 * Save top 'o stack info
507 cvp->cvc_lower = svs.si_srvc[1]->sd_lower;
508 cvp->cvc_tokl = svs.si_srvc[1]->sd_toku;