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.
26 * @(#) $FreeBSD: src/sys/netatm/atm_cm.c,v 1.6 1999/08/28 00:48:34 peter Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/atm_cm.c,v 1.5 2004/09/16 22:59:06 joerg Exp $
34 * ATM Connection Manager
38 #include "kern_include.h"
39 #include <sys/kernel.h>
44 struct atm_cm_stat atm_cm_stat = {0};
45 struct callout atm_cm_procinq_ch;
47 SYSINIT(atm_cm, SI_SUB_DRIVERS, SI_ORDER_ANY, callout_init, &atm_cm_procinq_ch);
52 static void atm_cm_cpcs_upper (int, void *, int, int);
53 static void atm_cm_saal_upper (int, void *, int, int);
54 static void atm_cm_sscop_upper (int, void *, int, int);
55 static Atm_connvc * atm_cm_share_llc (Atm_attributes *);
56 static void atm_cm_closeconn (Atm_connection *,
57 struct t_atm_cause *);
58 static void atm_cm_closevc (Atm_connvc *);
59 static void atm_cm_timeout (struct atm_time *);
60 static KTimeout_ret atm_cm_procinq (void *);
61 static void atm_cm_incall (Atm_connvc *);
62 static int atm_cm_accept (Atm_connvc *, Atm_connection *);
67 static Queue_t atm_connection_queue = {NULL};
68 static Queue_t atm_incoming_queue = {NULL};
69 static int atm_incoming_qlen = 0;
70 static Atm_connection *atm_listen_queue = NULL;
71 static struct attr_cause atm_cause_tmpl =
72 {T_ATM_PRESENT, {T_ATM_ITU_CODING, T_ATM_LOC_USER, 0, {0, 0, 0, 0}}};
75 * Stack commands, indexed by API
81 {CPCS_INIT, CPCS_TERM}, /* CMAPI_CPCS */
82 {SSCF_UNI_INIT, SSCF_UNI_TERM}, /* CMAPI_SAAL */
83 {SSCOP_INIT, SSCOP_TERM}, /* CMAPI_SSCOP */
87 static struct sp_info atm_connection_pool = {
88 "atm connection pool", /* si_name */
89 sizeof(Atm_connection), /* si_blksiz */
93 static struct sp_info atm_connvc_pool = {
94 "atm connection vcc pool", /* si_name */
95 sizeof(Atm_connvc), /* si_blksiz */
102 * Initiate Outgoing ATM Call
104 * Called by an endpoint service to create a new Connection Manager API
105 * instance and to initiate an outbound ATM connection. The endpoint
106 * provided token will be used in all further CM -> endpoint function
107 * calls, and the returned connection block pointer must be used in all
108 * subsequent endpoint -> CM function calls.
110 * If the return indicates that the connection setup has been immediately
111 * successful (typically only for PVCs and shared SVCs), then the connection
112 * is ready for data transmission.
114 * If the return indicates that the connection setup is still in progress,
115 * then the endpoint must wait for notification from the Connection Manager
116 * indicating the final status of the call setup. If the call setup completes
117 * successfully, then a "call connected" notification will be sent to the
118 * endpoint by the Connection Manager. If the call setup fails, then the
119 * endpoint will receive a "call cleared" notification.
121 * All connection instances must be freed with an atm_cm_release() call.
124 * epp pointer to endpoint definition structure
125 * token endpoint's connection instance token
126 * ap pointer to requested connection attributes
127 * copp pointer to location to return allocated connection block
130 * 0 connection has been successfully established
131 * EINPROGRESS connection establishment is in progress
132 * errno connection failed - reason indicated
136 atm_cm_connect(epp, token, ap, copp)
140 Atm_connection **copp;
146 struct stack_list sl;
147 void (*upf)(int, void *, int, int);
148 int s, sli, err, err2;
154 * Get a connection block
156 cop = (Atm_connection *)atm_allocate(&atm_connection_pool);
161 * Initialize connection info
164 cop->co_toku = token;
167 * Initialize stack list index
172 * Validate and extract useful attribute information
176 * Must specify a network interface (validated below)
178 if (ap->nif == NULL) {
189 upf = atm_cm_cpcs_upper;
193 sl.sl_sap[sli++] = SAP_SSCF_UNI;
194 sl.sl_sap[sli++] = SAP_SSCOP;
195 upf = atm_cm_saal_upper;
199 sl.sl_sap[sli++] = SAP_SSCOP;
200 upf = atm_cm_sscop_upper;
211 if (ap->aal.tag != T_ATM_PRESENT) {
216 switch (ap->aal.type) {
219 sl.sl_sap[sli++] = SAP_CPCS_AAL5;
220 sl.sl_sap[sli++] = SAP_SAR_AAL5;
221 sl.sl_sap[sli++] = SAP_ATM;
225 sl.sl_sap[sli++] = SAP_CPCS_AAL3_4;
226 sl.sl_sap[sli++] = SAP_SAR_AAL3_4;
227 sl.sl_sap[sli++] = SAP_ATM;
236 * Broadband Bearer Attributes
238 if (ap->bearer.tag != T_ATM_PRESENT) {
243 switch (ap->bearer.v.connection_configuration) {
246 cop->co_flags |= COF_P2P;
249 case T_ATM_1_TO_MANY:
251 cop->co_flags |= COF_P2MP;
261 * Logical Link Control Attributes
263 if (ap->llc.tag == T_ATM_PRESENT) {
264 if ((ap->blli.tag_l2 != T_ATM_PRESENT) ||
265 (ap->blli.v.layer_2_protocol.ID_type != T_ATM_SIMPLE_ID) ||
266 (ap->blli.v.layer_2_protocol.ID.simple_ID !=
267 T_ATM_BLLI2_I8802) ||
268 (ap->llc.v.llc_len < T_ATM_LLC_MIN_LEN) ||
269 (ap->llc.v.llc_len > T_ATM_LLC_MAX_LEN)) {
273 cop->co_mpx = ATM_ENC_LLC;
274 cop->co_llc = ap->llc;
276 cop->co_mpx = ATM_ENC_NULL;
279 * Called Party Attributes
281 if (ap->called.tag != T_ATM_PRESENT) {
286 if ((ap->called.addr.address_format == T_ATM_ABSENT) ||
287 (ap->called.addr.address_length == 0)) {
293 * Calling Party Attributes
295 if (ap->calling.tag != T_ATM_ABSENT) {
301 * Quality of Service Attributes
303 if (ap->qos.tag != T_ATM_PRESENT) {
309 * Terminate stack list
316 * Let multiplexors decide whether we need a new VCC
318 switch (cop->co_mpx) {
322 * All of these connections require a new VCC
328 * See if we can share an existing LLC connection
330 cvp = atm_cm_share_llc(ap);
335 * We've got a connection to share
337 cop->co_connvc = cvp;
338 if (cvp->cvc_state == CVCS_ACTIVE) {
339 cop->co_state = COS_ACTIVE;
342 cop->co_state = COS_OUTCONN;
345 LINK2TAIL(cop, Atm_connection, cvp->cvc_conn->co_mxh, co_next);
346 cop->co_mxh = cvp->cvc_conn->co_mxh;
353 panic("atm_cm_connect: unknown mpx");
357 * If we get here, it means we need to create
358 * a new VCC for this connection
362 * Validate that network interface is registered and that
363 * a signalling manager is attached
365 for (pip = atm_interface_head; pip != NULL; pip = pip->pif_next) {
367 for (nip = pip->pif_nif; nip; nip = nip->nif_pnext) {
379 if ((smp = pip->pif_sigmgr) == NULL) {
385 * Get a connection VCC block
387 cvp = (Atm_connvc *)atm_allocate(&atm_connvc_pool);
394 * Save VCC attributes
397 cvp->cvc_flags |= CVCF_CALLER;
400 * Link the control blocks
402 cop->co_connvc = cvp;
404 cvp->cvc_sigmgr = smp;
407 * Create a service stack
409 err = atm_create_stack(cvp, &sl, upf);
411 cvp->cvc_state = CVCS_CLEAR;
417 * Let the signalling manager handle the VCC creation
419 cvp->cvc_state = CVCS_SETUP;
420 switch ((*smp->sm_setup)(cvp, &err)) {
424 * Connection is fully setup - initialize the stack
426 cvp->cvc_state = CVCS_INIT;
427 STACK_CALL(atm_stackcmds[ap->api].init, cvp->cvc_lower,
428 cvp->cvc_tokl, cvp, ap->api_init, 0, err2);
430 panic("atm_cm_connect: init");
432 if (cvp->cvc_flags & CVCF_ABORTING) {
434 * Someone on the stack bailed out...schedule the
435 * VCC and stack termination
441 * Everything looks fine from here
443 cvp->cvc_state = CVCS_ACTIVE;
444 cop->co_state = COS_ACTIVE;
450 * Terminate stack and clean up before we leave
452 cvp->cvc_state = CVCS_CLEAR;
456 case CALL_PROCEEDING:
458 * We'll just wait for final call status
460 cop->co_state = COS_OUTCONN;
465 panic("atm_cm_connect: setup");
472 if (err && err != EINPROGRESS) {
474 * Undo any partial setup stuff
477 atm_free((caddr_t)cop);
480 * Finish connection setup
483 cvp->cvc_flags |= CVCF_CONNQ;
484 ENQUEUE(cvp, Atm_connvc, cvc_q, atm_connection_queue);
485 LINK2TAIL(cop, Atm_connection, cop->co_mxh, co_next);
494 * Listen for Incoming ATM Calls
496 * Called by an endpoint service in order to indicate its willingness to
497 * accept certain incoming calls. The types of calls which the endpoint
498 * is prepared to accept are specified in the Atm_attributes parameter.
500 * For each call which meets the criteria specified by the endpoint, the
501 * endpoint service will receive an incoming call notification via the
502 * endpoint's ep_incoming() function.
504 * To cancel the listening connection, the endpoint user should invoke
508 * epp pointer to endpoint definition structure
509 * token endpoint's listen instance token
510 * ap pointer to listening connection attributes
511 * copp pointer to location to return allocated connection block
514 * 0 listening connection installed
515 * errno listen failed - reason indicated
519 atm_cm_listen(epp, token, ap, copp)
523 Atm_connection **copp;
531 * Get a connection block
533 cop = (Atm_connection *)atm_allocate(&atm_connection_pool);
538 * Initialize connection info
541 cop->co_toku = token;
545 * Validate and extract useful attribute information
566 switch (ap->aal.tag) {
570 switch (ap->aal.type) {
592 * Broadband High Layer Information Attributes
594 switch (ap->bhli.tag) {
607 * Broadband Low Layer Information Attributes
609 switch (ap->blli.tag_l2) {
621 switch (ap->blli.tag_l3) {
634 * Logical Link Control Attributes
636 switch (ap->llc.tag) {
639 if ((ap->blli.tag_l2 != T_ATM_PRESENT) ||
640 (ap->blli.v.layer_2_protocol.ID_type != T_ATM_SIMPLE_ID) ||
641 (ap->blli.v.layer_2_protocol.ID.simple_ID !=
642 T_ATM_BLLI2_I8802) ||
643 (ap->llc.v.llc_len < T_ATM_LLC_MIN_LEN) ||
644 (ap->llc.v.llc_len > T_ATM_LLC_MAX_LEN)) {
648 cop->co_mpx = ATM_ENC_LLC;
649 cop->co_llc = ap->llc;
654 cop->co_mpx = ATM_ENC_NULL;
663 * Called Party Attributes
665 switch (ap->called.tag) {
668 switch (ap->called.addr.address_format) {
671 ap->called.tag = T_ATM_ABSENT;
690 * Get an attribute block and save listening attributes
692 cop->co_lattr = (Atm_attributes *)atm_allocate(&atm_attributes_pool);
693 if (cop->co_lattr == NULL) {
697 *cop->co_lattr = *ap;
700 * Now try to register the listening connection
703 if (atm_cm_match(cop->co_lattr, NULL) != NULL) {
705 * Can't have matching listeners
710 cop->co_state = COS_LISTEN;
711 LINK2TAIL(cop, Atm_connection, atm_listen_queue, co_next);
719 * Undo any partial setup stuff
723 atm_free((caddr_t)cop->co_lattr);
724 atm_free((caddr_t)cop);
728 * Finish connection setup
737 * Add to LLC Connection
739 * Called by an endpoint service to create a new Connection Manager API
740 * instance to be associated with an LLC-multiplexed connection instance
741 * which has been previously created. The endpoint provided token will
742 * be used in all further CM -> endpoint function calls, and the returned
743 * connection block pointer must be used in all subsequent endpoint -> CM
746 * If the return indicates that the connection setup has been immediately
747 * successful, then the connection is ready for data transmission.
749 * If the return indicates that the connection setup is still in progress,
750 * then the endpoint must wait for notification from the Connection Manager
751 * indicating the final status of the call setup. If the call setup completes
752 * successfully, then a "call connected" notification will be sent to the
753 * endpoint by the Connection Manager. If the call setup fails, then the
754 * endpoint will receive a "call cleared" notification.
756 * All connection instances must be freed with an atm_cm_release() call.
759 * epp pointer to endpoint definition structure
760 * token endpoint's connection instance token
761 * llc pointer to llc attributes for new connection
762 * ecop pointer to existing connection block
763 * copp pointer to location to return allocated connection block
766 * 0 connection has been successfully established
767 * EINPROGRESS connection establishment is in progress
768 * errno addllc failed - reason indicated
772 atm_cm_addllc(epp, token, llc, ecop, copp)
775 struct attr_llc *llc;
776 Atm_connection *ecop;
777 Atm_connection **copp;
779 Atm_connection *cop, *cop2;
786 * Check out requested LLC attributes
788 if ((llc->tag != T_ATM_PRESENT) ||
789 ((llc->v.flags & T_ATM_LLC_SHARING) == 0) ||
790 (llc->v.llc_len < T_ATM_LLC_MIN_LEN) ||
791 (llc->v.llc_len > T_ATM_LLC_MAX_LEN))
795 * Get a connection block
797 cop = (Atm_connection *)atm_allocate(&atm_connection_pool);
802 * Initialize connection info
805 cop->co_toku = token;
811 * Ensure that supplied connection is really valid
814 for (cvp = Q_HEAD(atm_connection_queue, Atm_connvc); cvp;
815 cvp = Q_NEXT(cvp, Atm_connvc, cvc_q)) {
816 for (cop2 = cvp->cvc_conn; cop2; cop2 = cop2->co_next) {
828 switch (ecop->co_state) {
845 * Connection must be LLC multiplexed and shared
847 if ((ecop->co_mpx != ATM_ENC_LLC) ||
848 ((ecop->co_llc.v.flags & T_ATM_LLC_SHARING) == 0)) {
854 * This new LLC header must be unique for this VCC
858 int i = MIN(llc->v.llc_len, cop2->co_llc.v.llc_len);
860 if (KM_CMP(llc->v.llc_info, cop2->co_llc.v.llc_info, i) == 0) {
865 cop2 = cop2->co_next;
869 * Everything seems to check out
871 cop->co_flags = ecop->co_flags;
872 cop->co_state = ecop->co_state;
873 cop->co_mpx = ecop->co_mpx;
874 cop->co_connvc = ecop->co_connvc;
876 LINK2TAIL(cop, Atm_connection, ecop->co_mxh, co_next);
877 cop->co_mxh = ecop->co_mxh;
882 if (err && err != EINPROGRESS) {
884 * Undo any partial setup stuff
887 atm_free((caddr_t)cop);
890 * Pass new connection back to caller
902 * cop pointer to connection block
903 * id identifier for party to be added
904 * addr address of party to be added
907 * 0 addparty successful
908 * errno addparty failed - reason indicated
912 atm_cm_addparty(cop, id, addr)
915 struct t_atm_sap *addr;
925 * cop pointer to connection block
926 * id identifier for party to be added
927 * cause pointer to cause of drop
930 * 0 dropparty successful
931 * errno dropparty failed - reason indicated
935 atm_cm_dropparty(cop, id, cause)
938 struct t_atm_cause *cause;
945 * Release Connection Resources
947 * Called by the endpoint service in order to terminate an ATM connection
948 * and to release all system resources for the connection. This function
949 * must be called for every allocated connection instance and must only
950 * be called by the connection's owner.
953 * cop pointer to connection block
954 * cause pointer to cause of release
957 * 0 release successful
958 * errno release failed - reason indicated
962 atm_cm_release(cop, cause)
964 struct t_atm_cause *cause;
972 * First, a quick state validation check
974 switch (cop->co_state) {
992 panic("atm_cm_release: bogus conn state");
996 * Check out the VCC state too
998 if ((cvp = cop->co_connvc) != NULL) {
1000 switch (cvp->cvc_state) {
1017 panic("atm_cm_release: bogus connvc state");
1021 * If we're the only connection, terminate the VCC
1023 if ((cop->co_mxh == cop) && (cop->co_next == NULL)) {
1024 cvp->cvc_attr.cause.tag = T_ATM_PRESENT;
1025 cvp->cvc_attr.cause.v = *cause;
1026 atm_cm_closevc(cvp);
1031 * Now get rid of the connection
1033 atm_cm_closeconn(cop, cause);
1040 * Abort an ATM Connection VCC
1042 * This function allows any non-owner kernel entity to request an
1043 * immediate termination of an ATM VCC. This will normally be called
1044 * when encountering a catastrophic error condition that cannot be
1045 * resolved via the available stack protocols. The connection manager
1046 * will schedule the connection's termination, including notifying the
1047 * connection owner of the termination.
1049 * This function should only be called by a stack entity instance. After
1050 * calling the function, the caller should set a protocol state which just
1051 * waits for a <sap>_TERM stack command to be delivered.
1054 * cvp pointer to connection VCC block
1055 * cause pointer to cause of abort
1058 * 0 abort successful
1059 * errno abort failed - reason indicated
1063 atm_cm_abort(cvp, cause)
1065 struct t_atm_cause *cause;
1067 ATM_DEBUG2("atm_cm_abort: cvp=%p cause=%d\n",
1068 cvp, cause->cause_value);
1071 * Note that we're aborting
1073 cvp->cvc_flags |= CVCF_ABORTING;
1075 switch (cvp->cvc_state) {
1079 * In-line code will handle this
1081 cvp->cvc_attr.cause.tag = T_ATM_PRESENT;
1082 cvp->cvc_attr.cause.v = *cause;
1089 * Schedule connection termination, since we want
1090 * to avoid any sequencing interactions
1092 cvp->cvc_attr.cause.tag = T_ATM_PRESENT;
1093 cvp->cvc_attr.cause.v = *cause;
1102 * Ignore abort, as we're already terminating
1108 "atm_cm_abort: invalid state: cvp=%p, state=%d\n",
1109 cvp, cvp->cvc_state);
1116 * Incoming ATM Call Received
1118 * Called by a signalling manager to indicate that a new call request has
1119 * been received. This function will allocate and initialize the connection
1120 * manager control blocks and queue this call request. The call request
1121 * processing function, atm_cm_procinq(), will be scheduled to perform the
1125 * vcp pointer to incoming call's VCC control block
1126 * ap pointer to incoming call's attributes
1129 * 0 call queuing successful
1130 * errno call queuing failed - reason indicated
1134 atm_cm_incoming(vcp, ap)
1143 * Do some minimal attribute validation
1147 * Must specify a network interface
1149 if (ap->nif == NULL)
1155 if ((ap->aal.tag != T_ATM_PRESENT) ||
1156 ((ap->aal.type != ATM_AAL5) &&
1157 (ap->aal.type != ATM_AAL3_4)))
1161 * Traffic Descriptor Attributes
1163 if ((ap->traffic.tag != T_ATM_PRESENT) &&
1164 (ap->traffic.tag != T_ATM_ABSENT))
1168 * Broadband Bearer Attributes
1170 if ((ap->bearer.tag != T_ATM_PRESENT) ||
1171 ((ap->bearer.v.connection_configuration != T_ATM_1_TO_1) &&
1172 (ap->bearer.v.connection_configuration != T_ATM_1_TO_MANY)))
1176 * Broadband High Layer Attributes
1178 if ((ap->bhli.tag != T_ATM_PRESENT) &&
1179 (ap->bhli.tag != T_ATM_ABSENT))
1183 * Broadband Low Layer Attributes
1185 if ((ap->blli.tag_l2 != T_ATM_PRESENT) &&
1186 (ap->blli.tag_l2 != T_ATM_ABSENT))
1188 if ((ap->blli.tag_l3 != T_ATM_PRESENT) &&
1189 (ap->blli.tag_l3 != T_ATM_ABSENT))
1193 * Logical Link Control Attributes
1195 if (ap->llc.tag == T_ATM_PRESENT)
1197 ap->llc.tag = T_ATM_ANY;
1200 * Called Party Attributes
1202 if ((ap->called.tag != T_ATM_PRESENT) ||
1203 (ap->called.addr.address_format == T_ATM_ABSENT))
1205 if (ap->called.tag == T_ATM_ABSENT) {
1206 ap->called.addr.address_format = T_ATM_ABSENT;
1207 ap->called.addr.address_length = 0;
1208 ap->called.subaddr.address_format = T_ATM_ABSENT;
1209 ap->called.subaddr.address_length = 0;
1213 * Calling Party Attributes
1215 if ((ap->calling.tag != T_ATM_PRESENT) &&
1216 (ap->calling.tag != T_ATM_ABSENT))
1218 if (ap->calling.tag == T_ATM_ABSENT) {
1219 ap->calling.addr.address_format = T_ATM_ABSENT;
1220 ap->calling.addr.address_length = 0;
1221 ap->calling.subaddr.address_format = T_ATM_ABSENT;
1222 ap->calling.subaddr.address_length = 0;
1226 * Quality of Service Attributes
1228 if (ap->qos.tag != T_ATM_PRESENT)
1232 * Transit Network Attributes
1234 if ((ap->transit.tag != T_ATM_PRESENT) &&
1235 (ap->transit.tag != T_ATM_ABSENT))
1241 if ((ap->cause.tag != T_ATM_PRESENT) &&
1242 (ap->cause.tag != T_ATM_ABSENT))
1246 * Get a connection VCC block
1248 cvp = (Atm_connvc *)atm_allocate(&atm_connvc_pool);
1255 * Initialize the control block
1258 cvp->cvc_sigmgr = vcp->vc_pif->pif_sigmgr;
1259 cvp->cvc_attr = *ap;
1260 cvp->cvc_state = CVCS_INCOMING;
1263 * Control queue length
1266 if (atm_incoming_qlen >= ATM_CALLQ_MAX) {
1273 * Queue request and schedule call processing function
1275 cvp->cvc_flags |= CVCF_INCOMQ;
1276 ENQUEUE(cvp, Atm_connvc, cvc_q, atm_incoming_queue);
1277 if (atm_incoming_qlen++ == 0) {
1278 atm_cm_procinq(NULL);
1282 * Link for signalling manager
1284 vcp->vc_connvc = cvp;
1292 * Free any resources
1295 atm_free((caddr_t)cvp);
1301 * VCC Connected Notification
1303 * This function is called by a signalling manager as notification that a
1304 * VCC call setup has been successful.
1307 * cvp pointer to connection VCC block
1314 atm_cm_connected(cvp)
1317 Atm_connection *cop, *cop2;
1324 * Validate connection vcc
1326 switch (cvp->cvc_state) {
1330 * Initialize the stack
1332 cvp->cvc_state = CVCS_INIT;
1333 STACK_CALL(atm_stackcmds[cvp->cvc_attr.api].init,
1334 cvp->cvc_lower, cvp->cvc_tokl,
1335 cvp, cvp->cvc_attr.api_init, 0, err);
1337 panic("atm_cm_connected: init");
1339 if (cvp->cvc_flags & CVCF_ABORTING) {
1341 * Someone on the stack bailed out...notify all of the
1342 * connections and schedule the VCC termination
1344 cop = cvp->cvc_conn;
1346 cop2 = cop->co_next;
1347 atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
1350 atm_cm_closevc(cvp);
1358 * Stack already initialized
1363 panic("atm_cm_connected: connvc state");
1367 * VCC is ready for action
1369 cvp->cvc_state = CVCS_ACTIVE;
1372 * Notify all connections that the call has completed
1374 cop = cvp->cvc_conn;
1376 cop2 = cop->co_next;
1378 switch (cop->co_state) {
1382 cop->co_state = COS_ACTIVE;
1383 (*cop->co_endpt->ep_connected)(cop->co_toku);
1388 * May get here if an ep_connected() call (from
1389 * above) results in an atm_cm_addllc() call for
1390 * the just connected connection.
1395 panic("atm_cm_connected: connection state");
1404 * Input any queued packets
1406 while ((m = cvp->cvc_rcvq) != NULL) {
1407 cvp->cvc_rcvq = KB_QNEXT(m);
1412 * Currently only supported for CPCS API
1414 atm_cm_cpcs_upper(CPCS_UNITDATA_SIG, cvp, (int)m, 0);
1422 * VCC Cleared Notification
1424 * This function is called by a signalling manager as notification that a
1425 * VCC call has been cleared. The cause information describing the reason
1426 * for the call clearing will be contained in the connection VCC attributes.
1429 * cvp pointer to connection VCC block
1439 Atm_connection *cop, *cop2;
1443 if ((cvp->cvc_state == CVCS_FREE) ||
1444 (cvp->cvc_state >= CVCS_CLEAR))
1445 panic("atm_cm_cleared");
1448 cvp->cvc_state = CVCS_CLEAR;
1453 * Terminate all connections
1455 cop = cvp->cvc_conn;
1457 cop2 = cop->co_next;
1458 atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
1463 * Clean up connection VCC
1465 atm_cm_closevc(cvp);
1474 * Process Incoming Call Queue
1476 * This function is scheduled by atm_cm_incoming() in order to process
1477 * all the entries on the incoming call queue.
1480 * arg argument passed on timeout() call
1494 * Only process incoming calls up to our quota
1496 while (cnt++ < ATM_CALLQ_MAX) {
1501 * Get next awaiting call
1503 cvp = Q_HEAD(atm_incoming_queue, Atm_connvc);
1508 DEQUEUE(cvp, Atm_connvc, cvc_q, atm_incoming_queue);
1509 atm_incoming_qlen--;
1510 cvp->cvc_flags &= ~CVCF_INCOMQ;
1521 * If we've expended our quota, reschedule ourselves
1523 if (cnt >= ATM_CALLQ_MAX) {
1524 callout_reset(&atm_cm_procinq_ch, 1, atm_cm_procinq, NULL);
1530 * Process Incoming Call
1532 * This function will search through the listening queue and try to find
1533 * matching endpoint(s) for the incoming call. If we find any, we will
1534 * notify the endpoint service(s) of the incoming call and will then
1535 * notify the signalling manager to progress the call to an active status.
1537 * If there are no listeners for the call, the signalling manager will be
1538 * notified of a call rejection.
1543 * cvp pointer to connection VCC for incoming call
1553 Atm_connection *cop, *lcop, *hcop;
1554 Atm_attributes attr;
1560 attr = cvp->cvc_attr;
1563 * Look for matching listeners
1565 while ((lcop = atm_cm_match(&attr, lcop)) != NULL) {
1569 * Need a new connection block
1571 cop = (Atm_connection *)
1572 atm_allocate(&atm_connection_pool);
1574 cvp->cvc_attr.cause = atm_cause_tmpl;
1575 cvp->cvc_attr.cause.v.cause_value =
1576 T_ATM_CAUSE_TEMPORARY_FAILURE;
1582 * Initialize connection from listener and incoming call
1585 cop->co_state = COS_INCONN;
1586 cop->co_mpx = lcop->co_mpx;
1587 cop->co_endpt = lcop->co_endpt;
1588 cop->co_llc = lcop->co_llc;
1590 switch (attr.bearer.v.connection_configuration) {
1593 cop->co_flags |= COF_P2P;
1596 case T_ATM_1_TO_MANY:
1598 cop->co_flags |= COF_P2MP;
1599 cvp->cvc_attr.cause = atm_cause_tmpl;
1600 cvp->cvc_attr.cause.v.cause_value =
1601 T_ATM_CAUSE_BEARER_CAPABILITY_NOT_IMPLEMENTED;
1606 * Notify endpoint of incoming call
1608 err = (*cop->co_endpt->ep_incoming)
1609 (lcop->co_toku, cop, &cvp->cvc_attr, &cop->co_toku);
1614 * Endpoint has accepted the call
1616 * Setup call attributes
1619 cvp->cvc_attr.api = lcop->co_lattr->api;
1620 cvp->cvc_attr.api_init =
1621 lcop->co_lattr->api_init;
1622 cvp->cvc_attr.llc = lcop->co_lattr->llc;
1624 cvp->cvc_attr.headin = MAX(cvp->cvc_attr.headin,
1625 lcop->co_lattr->headin);
1628 * Setup connection info and queueing
1630 cop->co_state = COS_INACCEPT;
1631 cop->co_connvc = cvp;
1632 LINK2TAIL(cop, Atm_connection, hcop, co_next);
1636 * Need a new connection block next time around
1642 * Endpoint refuses call
1649 * We're done looking for listeners
1653 * Someone actually wants the call, so notify
1654 * the signalling manager to continue
1656 cvp->cvc_flags |= CVCF_CONNQ;
1657 ENQUEUE(cvp, Atm_connvc, cvc_q, atm_connection_queue);
1658 if (atm_cm_accept(cvp, hcop))
1663 * Nobody around to take the call
1665 cvp->cvc_attr.cause = atm_cause_tmpl;
1666 cvp->cvc_attr.cause.v.cause_value =
1667 T_ATM_CAUSE_INCOMPATIBLE_DESTINATION;
1672 * Clean up loose ends
1675 atm_free((caddr_t)cop);
1678 * Call has been accepted
1684 * Call failed - notify any endpoints of the call failure
1688 * Clean up loose ends
1691 atm_free((caddr_t)cop);
1693 if (cvp->cvc_attr.cause.tag != T_ATM_PRESENT) {
1694 cvp->cvc_attr.cause = atm_cause_tmpl;
1695 cvp->cvc_attr.cause.v.cause_value =
1696 T_ATM_CAUSE_UNSPECIFIED_NORMAL;
1700 Atm_connection *cop2 = cop->co_next;
1701 atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
1706 * Tell the signalling manager to reject the call
1708 atm_cm_closevc(cvp);
1715 * Accept an Incoming ATM Call
1717 * Some endpoint service(s) wants to accept an incoming call, so the
1718 * signalling manager will be notified to attempt to progress the call
1719 * to an active status.
1721 * If the signalling manager indicates that connection activation has
1722 * been immediately successful, then all of the endpoints will be notified
1723 * that the connection is ready for data transmission.
1725 * If the return indicates that connection activation is still in progress,
1726 * then the endpoints must wait for notification from the Connection Manager
1727 * indicating the final status of the call setup. If the call setup completes
1728 * successfully, then a "call connected" notification will be sent to the
1729 * endpoints by the Connection Manager. If the call setup fails, then the
1730 * endpoints will receive a "call cleared" notification.
1735 * cvp pointer to connection VCC for incoming call
1736 * cop pointer to head of accepted connections
1739 * 0 connection has been successfully activated
1740 * errno accept failed - reason indicated
1744 atm_cm_accept(cvp, cop)
1746 Atm_connection *cop;
1748 struct stack_list sl;
1749 void (*upf)(int, void *, int, int);
1754 * Link vcc to connections
1756 cvp->cvc_conn = cop;
1759 * Initialize stack list index
1764 * Check out Data API
1766 switch (cvp->cvc_attr.api) {
1769 upf = atm_cm_cpcs_upper;
1773 sl.sl_sap[sli++] = SAP_SSCF_UNI;
1774 sl.sl_sap[sli++] = SAP_SSCOP;
1775 upf = atm_cm_saal_upper;
1779 sl.sl_sap[sli++] = SAP_SSCOP;
1780 upf = atm_cm_sscop_upper;
1790 switch (cvp->cvc_attr.aal.type) {
1793 sl.sl_sap[sli++] = SAP_CPCS_AAL5;
1794 sl.sl_sap[sli++] = SAP_SAR_AAL5;
1795 sl.sl_sap[sli++] = SAP_ATM;
1799 sl.sl_sap[sli++] = SAP_CPCS_AAL3_4;
1800 sl.sl_sap[sli++] = SAP_SAR_AAL3_4;
1801 sl.sl_sap[sli++] = SAP_ATM;
1806 * Terminate stack list
1811 * Create a service stack
1813 err = atm_create_stack(cvp, &sl, upf);
1819 * Let the signalling manager finish the VCC activation
1821 switch ((*cvp->cvc_sigmgr->sm_accept)(cvp->cvc_vcc, &err)) {
1823 case CALL_PROCEEDING:
1825 * Note that we're not finished yet
1830 case CALL_CONNECTED:
1832 * Initialize the stack now, even if the call isn't totally
1833 * active yet. We want to avoid the delay between getting
1834 * the "call connected" event and actually notifying the
1835 * adapter to accept cells on the new VCC - if the delay is
1836 * too long, then we end up dropping the first pdus sent by
1839 cvp->cvc_state = CVCS_INIT;
1840 STACK_CALL(atm_stackcmds[cvp->cvc_attr.api].init,
1841 cvp->cvc_lower, cvp->cvc_tokl, cvp,
1842 cvp->cvc_attr.api_init, 0, err2);
1844 panic("atm_cm_accept: init");
1846 if (cvp->cvc_flags & CVCF_ABORTING) {
1848 * Someone on the stack bailed out...schedule the
1849 * VCC and stack termination
1854 * Everything looks fine from here
1857 cvp->cvc_state = CVCS_ACCEPT;
1859 cvp->cvc_state = CVCS_ACTIVE;
1865 * Terminate stack and clean up before we leave
1867 cvp->cvc_state = CVCS_CLEAR;
1871 panic("atm_cm_accept: accept");
1877 * Call has been connected, notify endpoints
1880 Atm_connection *cop2 = cop->co_next;
1882 cop->co_state = COS_ACTIVE;
1883 (*cop->co_endpt->ep_connected)(cop->co_toku);
1887 } else if (err == EINPROGRESS) {
1889 * Call is still in progress, endpoint must wait
1895 * Let caller know we failed
1897 cvp->cvc_attr.cause = atm_cause_tmpl;
1898 cvp->cvc_attr.cause.v.cause_value =
1899 T_ATM_CAUSE_UNSPECIFIED_RESOURCE_UNAVAILABLE;
1907 * Match Attributes on Listening Queue
1909 * This function will attempt to match the supplied connection attributes
1910 * with one of the registered attributes in the listening queue. The pcop
1911 * argument may be supplied in order to allow multiple listeners to share
1912 * an incoming call (if supported by the listeners).
1917 * ap pointer to attributes to be matched
1918 * pcop pointer to the previously matched connection
1921 * addr connection with which a match was found
1926 atm_cm_match(ap, pcop)
1928 Atm_connection *pcop;
1930 Atm_connection *cop;
1931 Atm_attributes *lap;
1935 * If we've already matched a listener...
1939 * Make sure already matched listener supports sharing
1941 if ((pcop->co_mpx != ATM_ENC_LLC) ||
1942 ((pcop->co_llc.v.flags & T_ATM_LLC_SHARING) == 0))
1946 * Position ourselves after the matched entry
1948 for (cop = atm_listen_queue; cop; cop = cop->co_next) {
1950 cop = pcop->co_next;
1956 * Start search at top of listening queue
1958 cop = atm_listen_queue;
1962 * Search through listening queue
1964 for (; cop; cop = cop->co_next) {
1966 lap = cop->co_lattr;
1969 * If we're trying to share, check that this entry allows it
1972 if ((cop->co_mpx != ATM_ENC_LLC) ||
1973 ((cop->co_llc.v.flags & T_ATM_LLC_SHARING) == 0))
1978 * ALL "matchable" attributes must match
1984 if (lap->bhli.tag == T_ATM_ABSENT) {
1985 if (ap->bhli.tag == T_ATM_PRESENT)
1987 } else if (lap->bhli.tag == T_ATM_PRESENT) {
1988 if (ap->bhli.tag == T_ATM_ABSENT)
1990 if (ap->bhli.tag == T_ATM_PRESENT)
1991 if (KM_CMP(&lap->bhli.v, &ap->bhli.v,
1992 sizeof(struct t_atm_bhli)))
1999 if (lap->blli.tag_l2 == T_ATM_ABSENT) {
2000 if (ap->blli.tag_l2 == T_ATM_PRESENT)
2002 } else if (lap->blli.tag_l2 == T_ATM_PRESENT) {
2003 if (ap->blli.tag_l2 == T_ATM_ABSENT)
2005 if (ap->blli.tag_l2 == T_ATM_PRESENT) {
2006 if (KM_CMP(&lap->blli.v.layer_2_protocol.ID,
2007 &ap->blli.v.layer_2_protocol.ID,
2009 ap->blli.v.layer_2_protocol.ID)))
2017 if (lap->blli.tag_l3 == T_ATM_ABSENT) {
2018 if (ap->blli.tag_l3 == T_ATM_PRESENT)
2020 } else if (lap->blli.tag_l3 == T_ATM_PRESENT) {
2021 if (ap->blli.tag_l3 == T_ATM_ABSENT)
2023 if (ap->blli.tag_l3 == T_ATM_PRESENT) {
2024 if (KM_CMP(&lap->blli.v.layer_3_protocol.ID,
2025 &ap->blli.v.layer_3_protocol.ID,
2027 ap->blli.v.layer_3_protocol.ID)))
2035 if (lap->llc.tag == T_ATM_ABSENT) {
2036 if (ap->llc.tag == T_ATM_PRESENT)
2038 } else if (lap->llc.tag == T_ATM_PRESENT) {
2039 if (ap->llc.tag == T_ATM_ABSENT)
2041 if (ap->llc.tag == T_ATM_PRESENT) {
2042 int i = MIN(lap->llc.v.llc_len,
2045 if (KM_CMP(lap->llc.v.llc_info,
2046 ap->llc.v.llc_info, i))
2054 if (lap->aal.tag == T_ATM_ABSENT) {
2055 if (ap->aal.tag == T_ATM_PRESENT)
2057 } else if (lap->aal.tag == T_ATM_PRESENT) {
2058 if (ap->aal.tag == T_ATM_ABSENT)
2060 if (ap->aal.tag == T_ATM_PRESENT) {
2061 if (lap->aal.type != ap->aal.type)
2063 if (lap->aal.type == ATM_AAL5) {
2064 if (lap->aal.v.aal5.SSCS_type !=
2065 ap->aal.v.aal5.SSCS_type)
2068 if (lap->aal.v.aal4.SSCS_type !=
2069 ap->aal.v.aal4.SSCS_type)
2078 if (lap->called.tag == T_ATM_ABSENT) {
2079 if (ap->called.tag == T_ATM_PRESENT)
2081 } else if (lap->called.tag == T_ATM_PRESENT) {
2082 if (ap->called.tag == T_ATM_ABSENT)
2084 if (ap->called.tag == T_ATM_PRESENT) {
2085 if ((!ATM_ADDR_EQUAL(&lap->called.addr,
2086 &ap->called.addr)) ||
2087 (!ATM_ADDR_EQUAL(&lap->called.subaddr,
2088 &ap->called.subaddr)))
2094 * Found a full match - return it
2104 * Find Shareable LLC VCC
2106 * Given a endpoint-supplied connection attribute using LLC multiplexing,
2107 * this function will attempt to locate an existing connection which meets
2108 * the requirements of the supplied attributes.
2113 * ap pointer to requested attributes
2116 * addr shareable LLC connection VCC
2117 * 0 no shareable VCC available
2121 atm_cm_share_llc(ap)
2124 Atm_connection *cop;
2128 * Is requestor willing to share?
2130 if ((ap->llc.v.flags & T_ATM_LLC_SHARING) == 0)
2134 * Try to find a shareable connection
2136 for (cvp = Q_HEAD(atm_connection_queue, Atm_connvc); cvp;
2137 cvp = Q_NEXT(cvp, Atm_connvc, cvc_q)) {
2140 * Dont use terminating connections
2142 switch (cvp->cvc_state) {
2154 * Is connection LLC and shareable?
2156 if ((cvp->cvc_attr.llc.tag != T_ATM_PRESENT) ||
2157 ((cvp->cvc_attr.llc.v.flags & T_ATM_LLC_SHARING) == 0))
2161 * Match requested attributes with existing connection
2163 if (ap->nif != cvp->cvc_attr.nif)
2166 if ((ap->api != cvp->cvc_attr.api) ||
2167 (ap->api_init != cvp->cvc_attr.api_init))
2173 if (cvp->cvc_flags & CVCF_CALLER) {
2174 if ((!ATM_ADDR_EQUAL(&ap->called.addr,
2175 &cvp->cvc_attr.called.addr)) ||
2176 (!ATM_ADDR_EQUAL(&ap->called.subaddr,
2177 &cvp->cvc_attr.called.subaddr)))
2180 if (cvp->cvc_attr.calling.tag != T_ATM_PRESENT)
2182 if ((!ATM_ADDR_EQUAL(&ap->called.addr,
2183 &cvp->cvc_attr.calling.addr)) ||
2184 (!ATM_ADDR_EQUAL(&ap->called.subaddr,
2185 &cvp->cvc_attr.calling.subaddr)))
2192 if (ap->aal.type == ATM_AAL5) {
2193 struct t_atm_aal5 *ap5, *cv5;
2195 ap5 = &ap->aal.v.aal5;
2196 cv5 = &cvp->cvc_attr.aal.v.aal5;
2198 if ((cvp->cvc_attr.aal.type != ATM_AAL5) ||
2199 (ap5->SSCS_type != cv5->SSCS_type))
2202 if (cvp->cvc_flags & CVCF_CALLER) {
2203 if (ap5->forward_max_SDU_size >
2204 cv5->forward_max_SDU_size)
2207 if (ap5->forward_max_SDU_size >
2208 cv5->backward_max_SDU_size)
2212 struct t_atm_aal4 *ap4, *cv4;
2214 ap4 = &ap->aal.v.aal4;
2215 cv4 = &cvp->cvc_attr.aal.v.aal4;
2217 if ((cvp->cvc_attr.aal.type != ATM_AAL3_4) ||
2218 (ap4->SSCS_type != cv4->SSCS_type))
2221 if (cvp->cvc_flags & CVCF_CALLER) {
2222 if (ap4->forward_max_SDU_size >
2223 cv4->forward_max_SDU_size)
2226 if (ap4->forward_max_SDU_size >
2227 cv4->backward_max_SDU_size)
2233 * Traffic Descriptor
2235 if ((ap->traffic.tag != T_ATM_PRESENT) ||
2236 (cvp->cvc_attr.traffic.tag != T_ATM_PRESENT) ||
2237 (ap->traffic.v.best_effort != T_YES) ||
2238 (cvp->cvc_attr.traffic.v.best_effort != T_YES))
2244 if (ap->bearer.v.connection_configuration !=
2245 cvp->cvc_attr.bearer.v.connection_configuration)
2251 if (cvp->cvc_flags & CVCF_CALLER) {
2252 if ((ap->qos.v.forward.qos_class !=
2253 cvp->cvc_attr.qos.v.forward.qos_class) ||
2254 (ap->qos.v.backward.qos_class !=
2255 cvp->cvc_attr.qos.v.backward.qos_class))
2258 if ((ap->qos.v.forward.qos_class !=
2259 cvp->cvc_attr.qos.v.backward.qos_class) ||
2260 (ap->qos.v.backward.qos_class !=
2261 cvp->cvc_attr.qos.v.forward.qos_class))
2266 * The new LLC header must also be unique for this VCC
2268 for (cop = cvp->cvc_conn; cop; cop = cop->co_next) {
2269 int i = MIN(ap->llc.v.llc_len,
2270 cop->co_llc.v.llc_len);
2272 if (KM_CMP(ap->llc.v.llc_info,
2273 cop->co_llc.v.llc_info, i) == 0)
2278 * If no header overlaps, then we're done
2291 * This function will terminate a connection, including notifying the
2292 * user, if necessary, and freeing up control block memory. The caller
2293 * is responsible for managing the connection VCC.
2298 * cop pointer to connection block
2299 * cause pointer to cause of close
2306 atm_cm_closeconn(cop, cause)
2307 Atm_connection *cop;
2308 struct t_atm_cause *cause;
2312 * Decide whether user needs notification
2314 switch (cop->co_state) {
2322 * Yup, let 'em know connection is gone
2325 (*cop->co_endpt->ep_cleared)(cop->co_toku, cause);
2330 * Nope,they should know already
2335 panic("atm_cm_closeconn: bogus state");
2339 * Unlink connection from its queues
2341 switch (cop->co_state) {
2344 atm_free((caddr_t)cop->co_lattr);
2345 UNLINK(cop, Atm_connection, atm_listen_queue, co_next);
2350 * Remove connection from multiplexor queue
2352 if (cop->co_mxh != cop) {
2354 * Connection is down the chain, just unlink it
2356 UNLINK(cop, Atm_connection, cop->co_mxh, co_next);
2358 } else if (cop->co_next != NULL) {
2360 * Connection is at the head of a non-singleton chain,
2361 * so unlink and reset the chain head
2363 Atm_connection *t, *nhd;
2365 t = nhd = cop->co_next;
2371 nhd->co_connvc->cvc_conn = nhd;
2376 * Free the connection block
2378 cop->co_state = COS_FREE;
2379 atm_free((caddr_t)cop);
2386 * Close Connection VCC
2388 * This function will terminate a connection VCC, including releasing the
2389 * the call to the signalling manager, terminating the VCC protocol stack,
2390 * and freeing up control block memory.
2395 * cvp pointer to connection VCC block
2408 * Break links with the connection block
2410 cvp->cvc_conn = NULL;
2413 * Cancel any running timer
2418 * Free queued packets
2420 while (cvp->cvc_rcvq) {
2424 cvp->cvc_rcvq = KB_QNEXT(m);
2430 * Unlink from any queues
2432 if (cvp->cvc_flags & CVCF_INCOMQ) {
2433 DEQUEUE(cvp, Atm_connvc, cvc_q, atm_incoming_queue);
2434 atm_incoming_qlen--;
2435 cvp->cvc_flags &= ~CVCF_INCOMQ;
2437 } else if (cvp->cvc_flags & CVCF_CONNQ) {
2438 DEQUEUE(cvp, Atm_connvc, cvc_q, atm_connection_queue);
2439 cvp->cvc_flags &= ~CVCF_CONNQ;
2443 * Release the signalling call
2445 switch (cvp->cvc_state) {
2453 cvp->cvc_state = CVCS_RELEASE;
2454 switch ((*cvp->cvc_sigmgr->sm_release)
2455 (cvp->cvc_vcc, &err)) {
2459 * Looks good so far...
2463 case CALL_PROCEEDING:
2465 * We'll have to wait for the call to clear
2471 * If there's a memory shortage, retry later.
2472 * Otherwise who knows what's going on....
2474 if ((err == ENOMEM) || (err == ENOBUFS)) {
2475 CVC_TIMER(cvp, 1 * ATM_HZ);
2479 "atm_cm_closevc: release %d\n", err);
2488 cvp->cvc_state = CVCS_REJECT;
2489 switch ((*cvp->cvc_sigmgr->sm_reject)
2490 (cvp->cvc_vcc, &err)) {
2494 * Looks good so far...
2500 * If there's a memory shortage, retry later.
2501 * Otherwise who knows what's going on....
2503 if ((err == ENOMEM) || (err == ENOBUFS)) {
2504 CVC_TIMER(cvp, 1 * ATM_HZ);
2508 "atm_cm_closevc: reject %d\n", err);
2517 * No need for anything here
2522 panic("atm_cm_closevc: bogus state");
2526 * Now terminate the stack
2528 if (cvp->cvc_tokl) {
2529 cvp->cvc_state = CVCS_TERM;
2532 * Wait until stack is unwound before terminating
2534 if ((cvp->cvc_downcnt > 0) || (cvp->cvc_upcnt > 0)) {
2539 STACK_CALL(atm_stackcmds[cvp->cvc_attr.api].term,
2540 cvp->cvc_lower, cvp->cvc_tokl, cvp, 0, 0, err);
2542 cvp->cvc_tokl = NULL;
2546 * Let signalling manager finish up
2548 cvp->cvc_state = CVCS_FREE;
2550 (void) (*cvp->cvc_sigmgr->sm_free)(cvp->cvc_vcc);
2554 * Finally, free our own control blocks
2556 atm_free((caddr_t)cvp);
2563 * Process a Connection VCC timeout
2565 * Called when a previously scheduled cvc control block timer expires.
2566 * Processing will be based on the current cvc state.
2571 * tip pointer to cvc timer control block
2579 struct atm_time *tip;
2581 Atm_connection *cop, *cop2;
2585 * Back-off to cvc control block
2587 cvp = (Atm_connvc *)
2588 ((caddr_t)tip - (int)(&((Atm_connvc *)0)->cvc_time));
2591 * Process timeout based on protocol state
2593 switch (cvp->cvc_state) {
2601 if ((cvp->cvc_flags & CVCF_ABORTING) == 0)
2605 * Terminate all connections
2607 cop = cvp->cvc_conn;
2609 cop2 = cop->co_next;
2610 atm_cm_closeconn(cop, &cvp->cvc_attr.cause.v);
2617 atm_cm_closevc(cvp);
2625 * Retry failed operation
2627 atm_cm_closevc(cvp);
2633 "atm_cm_timeout: invalid state: cvp=%p, state=%d\n",
2634 cvp, cvp->cvc_state);
2640 * CPCS User Control Commands
2642 * This function is called by an endpoint user to pass a control command
2643 * across a CPCS data API. Mostly we just send these down the stack.
2646 * cmd stack command code
2647 * cop pointer to connection block
2651 * 0 command output successful
2652 * errno output failed - reason indicated
2656 atm_cm_cpcs_ctl(cmd, cop, arg)
2658 Atm_connection *cop;
2665 * Validate connection state
2667 if (cop->co_state != COS_ACTIVE) {
2672 cvp = cop->co_connvc;
2673 if (cvp->cvc_state != CVCS_ACTIVE) {
2678 if (cvp->cvc_attr.api != CMAPI_CPCS) {
2697 * This function is called by an endpoint user to output a data packet
2698 * across a CPCS data API. After we've validated the connection state, the
2699 * packet will be encapsulated (if necessary) and sent down the data stack.
2702 * cop pointer to connection block
2703 * m pointer to packet buffer chain to be output
2706 * 0 packet output successful
2707 * errno output failed - reason indicated
2711 atm_cm_cpcs_data(cop, m)
2712 Atm_connection *cop;
2716 struct attr_llc *llcp;
2722 * Validate connection state
2724 if (cop->co_state != COS_ACTIVE) {
2729 cvp = cop->co_connvc;
2730 if (cvp->cvc_state != CVCS_ACTIVE) {
2735 if (cvp->cvc_attr.api != CMAPI_CPCS) {
2741 * Add any packet encapsulation
2743 switch (cop->co_mpx) {
2753 * Need to add an LLC header
2755 llcp = &cop->co_llc;
2758 * See if there's room to add LLC header to front of packet.
2760 KB_HEADROOM(m, space);
2761 if (space < llcp->v.llc_len) {
2765 * We have to allocate another buffer and tack it
2766 * onto the front of the packet
2768 KB_ALLOCPKT(n, llcp->v.llc_len, KB_F_NOWAIT,
2774 KB_TAILALIGN(n, llcp->v.llc_len);
2779 * Header fits, just adjust buffer controls
2781 KB_HEADADJ(m, llcp->v.llc_len);
2785 * Add the LLC header
2787 KB_DATASTART(m, bp, void *);
2788 KM_COPY(llcp->v.llc_info, bp, llcp->v.llc_len);
2789 KB_PLENADJ(m, llcp->v.llc_len);
2793 panic("atm_cm_cpcs_data: mpx");
2797 * Finally, we can send the packet on its way
2799 STACK_CALL(CPCS_UNITDATA_INV, cvp->cvc_lower, cvp->cvc_tokl,
2800 cvp, (int)m, 0, err);
2808 * Process CPCS Stack Commands
2810 * This is the top of the CPCS API data stack. All upward stack commands
2811 * for the CPCS data API will be received and processed here.
2814 * cmd stack command code
2815 * tok session token (pointer to connection VCC control block)
2824 atm_cm_cpcs_upper(cmd, tok, arg1, arg2)
2830 Atm_connection *cop;
2831 Atm_connvc *cvp = tok;
2838 case CPCS_UNITDATA_SIG:
2842 m = (KBuffer *)arg1;
2844 if (cvp->cvc_state != CVCS_ACTIVE) {
2845 if (cvp->cvc_state == CVCS_ACCEPT) {
2849 * Queue up any packets received before sigmgr
2850 * notifies us of incoming call completion
2852 if (cvp->cvc_rcvqlen >= CVC_RCVQ_MAX) {
2854 atm_cm_stat.cms_rcvconnvc++;
2858 if (cvp->cvc_rcvq == NULL) {
2861 for (n = cvp->cvc_rcvq;
2862 KB_QNEXT(n) != NULL;
2871 atm_cm_stat.cms_rcvconnvc++;
2877 * Locate packet's connection
2879 cop = cvp->cvc_conn;
2880 switch (cop->co_mpx) {
2884 * We're already there...
2890 * Find connection with matching LLC header
2892 if (KB_LEN(m) < T_ATM_LLC_MAX_LEN) {
2893 KB_PULLUP(m, T_ATM_LLC_MAX_LEN, m);
2895 atm_cm_stat.cms_llcdrop++;
2899 KB_DATASTART(m, bp, void *);
2904 if (KM_CMP(bp, cop->co_llc.v.llc_info,
2905 cop->co_llc.v.llc_len) == 0)
2914 * No connected user for this LLC
2917 atm_cm_stat.cms_llcid++;
2922 * Strip off the LLC header
2924 KB_HEADADJ(m, -cop->co_llc.v.llc_len);
2925 KB_PLENADJ(m, -cop->co_llc.v.llc_len);
2929 panic("atm_cm_cpcs_upper: mpx");
2933 * We've found our connection, so hand the packet off
2935 if (cop->co_state != COS_ACTIVE) {
2937 atm_cm_stat.cms_rcvconn++;
2940 (*cop->co_endpt->ep_cpcs_data)(cop->co_toku, m);
2943 case CPCS_UABORT_SIG:
2944 case CPCS_PABORT_SIG:
2946 * We don't support these (yet), so just fall thru...
2950 log(LOG_ERR, "atm_cm_cpcs_upper: unknown cmd 0x%x\n", cmd);
2956 * SAAL User Control Commands
2958 * This function is called by an endpoint user to pass a control command
2959 * across a SAAL data API. Mostly we just send these down the stack.
2962 * cmd stack command code
2963 * cop pointer to connection block
2967 * 0 command output successful
2968 * errno output failed - reason indicated
2972 atm_cm_saal_ctl(cmd, cop, arg)
2974 Atm_connection *cop;
2981 * Validate connection state
2983 if (cop->co_state != COS_ACTIVE) {
2988 cvp = cop->co_connvc;
2989 if (cvp->cvc_state != CVCS_ACTIVE) {
2994 if (cvp->cvc_attr.api != CMAPI_SAAL) {
3001 case SSCF_UNI_ESTABLISH_REQ:
3002 case SSCF_UNI_RELEASE_REQ:
3004 * Pass command down the stack
3006 STACK_CALL(cmd, cvp->cvc_lower, cvp->cvc_tokl, cvp,
3022 * This function is called by an endpoint user to output a data packet
3023 * across a SAAL data API. After we've validated the connection state,
3024 * the packet will be sent down the data stack.
3027 * cop pointer to connection block
3028 * m pointer to packet buffer chain to be output
3031 * 0 packet output successful
3032 * errno output failed - reason indicated
3036 atm_cm_saal_data(cop, m)
3037 Atm_connection *cop;
3045 * Validate connection state
3047 if (cop->co_state != COS_ACTIVE) {
3052 cvp = cop->co_connvc;
3053 if (cvp->cvc_state != CVCS_ACTIVE) {
3058 if (cvp->cvc_attr.api != CMAPI_SAAL) {
3064 * Finally, we can send the packet on its way
3066 STACK_CALL(SSCF_UNI_DATA_REQ, cvp->cvc_lower, cvp->cvc_tokl,
3067 cvp, (int)m, 0, err);
3075 * Process SAAL Stack Commands
3077 * This is the top of the SAAL API data stack. All upward stack commands
3078 * for the SAAL data API will be received and processed here.
3081 * cmd stack command code
3082 * tok session token (pointer to connection VCC control block)
3091 atm_cm_saal_upper(cmd, tok, arg1, arg2)
3097 Atm_connection *cop;
3098 Atm_connvc *cvp = tok;
3103 case SSCF_UNI_ESTABLISH_IND:
3104 case SSCF_UNI_ESTABLISH_CNF:
3105 case SSCF_UNI_RELEASE_IND:
3106 case SSCF_UNI_RELEASE_CNF:
3110 cop = cvp->cvc_conn;
3111 if (cvp->cvc_state != CVCS_ACTIVE)
3113 if (cop->co_state != COS_ACTIVE)
3116 (*cop->co_endpt->ep_saal_ctl)(cmd, cop->co_toku, (void *)arg1);
3119 case SSCF_UNI_DATA_IND:
3123 cop = cvp->cvc_conn;
3124 if (cvp->cvc_state != CVCS_ACTIVE) {
3125 atm_cm_stat.cms_rcvconnvc++;
3126 KB_FREEALL((KBuffer *)arg1);
3129 if (cop->co_state != COS_ACTIVE) {
3130 atm_cm_stat.cms_rcvconn++;
3131 KB_FREEALL((KBuffer *)arg1);
3135 (*cop->co_endpt->ep_saal_data)(cop->co_toku, (KBuffer *)arg1);
3138 case SSCF_UNI_UNITDATA_IND:
3142 KB_FREEALL((KBuffer *)arg1);
3147 log(LOG_ERR, "atm_cm_saal_upper: unknown cmd 0x%x\n", cmd);
3153 * SSCOP User Control Commands
3155 * This function is called by an endpoint user to pass a control command
3156 * across a SSCOP data API. Mostly we just send these down the stack.
3159 * cmd stack command code
3160 * cop pointer to connection block
3165 * 0 command output successful
3166 * errno output failed - reason indicated
3170 atm_cm_sscop_ctl(cmd, cop, arg1, arg2)
3172 Atm_connection *cop;
3180 * Validate connection state
3182 if (cop->co_state != COS_ACTIVE) {
3187 cvp = cop->co_connvc;
3188 if (cvp->cvc_state != CVCS_ACTIVE) {
3193 if (cvp->cvc_attr.api != CMAPI_SSCOP) {
3200 case SSCOP_ESTABLISH_REQ:
3201 case SSCOP_ESTABLISH_RSP:
3202 case SSCOP_RELEASE_REQ:
3203 case SSCOP_RESYNC_REQ:
3204 case SSCOP_RESYNC_RSP:
3205 case SSCOP_RECOVER_RSP:
3206 case SSCOP_RETRIEVE_REQ:
3208 * Pass command down the stack
3210 STACK_CALL(cmd, cvp->cvc_lower, cvp->cvc_tokl, cvp,
3211 (int)arg1, (int)arg2, err);
3226 * This function is called by an endpoint user to output a data packet
3227 * across a SSCOP data API. After we've validated the connection state,
3228 * the packet will be encapsulated and sent down the data stack.
3231 * cop pointer to connection block
3232 * m pointer to packet buffer chain to be output
3235 * 0 packet output successful
3236 * errno output failed - reason indicated
3240 atm_cm_sscop_data(cop, m)
3241 Atm_connection *cop;
3249 * Validate connection state
3251 if (cop->co_state != COS_ACTIVE) {
3256 cvp = cop->co_connvc;
3257 if (cvp->cvc_state != CVCS_ACTIVE) {
3262 if (cvp->cvc_attr.api != CMAPI_SSCOP) {
3268 * Finally, we can send the packet on its way
3270 STACK_CALL(SSCOP_DATA_REQ, cvp->cvc_lower, cvp->cvc_tokl,
3271 cvp, (int)m, 0, err);
3279 * Process SSCOP Stack Commands
3281 * This is the top of the SSCOP API data stack. All upward stack commands
3282 * for the SSCOP data API will be received and processed here.
3285 * cmd stack command code
3286 * tok session token (pointer to connection VCC control block)
3295 atm_cm_sscop_upper(cmd, tok, arg1, arg2)
3301 Atm_connection *cop;
3302 Atm_connvc *cvp = tok;
3306 case SSCOP_ESTABLISH_IND:
3307 case SSCOP_ESTABLISH_CNF:
3308 case SSCOP_RELEASE_IND:
3309 case SSCOP_RESYNC_IND:
3313 cop = cvp->cvc_conn;
3314 if ((cvp->cvc_state != CVCS_ACTIVE) ||
3315 (cop->co_state != COS_ACTIVE)) {
3316 KB_FREEALL((KBuffer *)arg1);
3320 (*cop->co_endpt->ep_sscop_ctl)
3321 (cmd, cop->co_toku, (void *)arg1, (void *)arg2);
3324 case SSCOP_RELEASE_CNF:
3325 case SSCOP_RESYNC_CNF:
3326 case SSCOP_RECOVER_IND:
3327 case SSCOP_RETRIEVE_IND:
3328 case SSCOP_RETRIEVECMP_IND:
3332 cop = cvp->cvc_conn;
3333 if ((cvp->cvc_state != CVCS_ACTIVE) ||
3334 (cop->co_state != COS_ACTIVE))
3337 (*cop->co_endpt->ep_sscop_ctl)
3338 (cmd, cop->co_toku, (void *)arg1, (void *)arg2);
3341 case SSCOP_DATA_IND:
3345 cop = cvp->cvc_conn;
3346 if (cvp->cvc_state != CVCS_ACTIVE) {
3347 atm_cm_stat.cms_rcvconnvc++;
3348 KB_FREEALL((KBuffer *)arg1);
3351 if (cop->co_state != COS_ACTIVE) {
3352 atm_cm_stat.cms_rcvconn++;
3353 KB_FREEALL((KBuffer *)arg1);
3357 (*cop->co_endpt->ep_sscop_data)
3358 (cop->co_toku, (KBuffer *)arg1, arg2);
3361 case SSCOP_UNITDATA_IND:
3365 KB_FREEALL((KBuffer *)arg1);
3370 log(LOG_ERR, "atm_cm_sscop_upper: unknown cmd 0x%x\n", cmd);
3376 * Register an ATM Endpoint Service
3378 * Every ATM endpoint service must register itself here before it can
3379 * issue or receive any connection requests.
3382 * epp pointer to endpoint definition structure
3385 * 0 registration successful
3386 * errno registration failed - reason indicated
3390 atm_endpoint_register(epp)
3396 * See if we need to be initialized
3404 if (epp->ep_id > ENDPT_MAX) {
3408 if (atm_endpoints[epp->ep_id] != NULL) {
3414 * Add endpoint to list
3416 atm_endpoints[epp->ep_id] = epp;
3424 * De-register an ATM Endpoint Service
3426 * Each ATM endpoint service provider must de-register its registered
3427 * endpoint(s) before terminating. Specifically, loaded kernel modules
3428 * must de-register their services before unloading themselves.
3431 * epp pointer to endpoint definition structure
3434 * 0 de-registration successful
3435 * errno de-registration failed - reason indicated
3439 atm_endpoint_deregister(epp)
3447 if (epp->ep_id > ENDPT_MAX) {
3451 if (atm_endpoints[epp->ep_id] != epp) {
3457 * Remove endpoint from list
3459 atm_endpoints[epp->ep_id] = NULL;