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/uni/sscop.c,v 1.6.2.1 2001/09/30 22:54:35 kris Exp $
27 * @(#) $DragonFly: src/sys/netproto/atm/uni/sscop.c,v 1.3 2003/08/07 21:17:35 dillon Exp $
31 * ATM Forum UNI Support
32 * ---------------------
34 * Service Specific Connection Oriented Protocol (SSCOP)
38 #include <netatm/kern_include.h>
41 #include "sscop_misc.h"
42 #include "sscop_pdu.h"
43 #include "sscop_var.h"
50 struct sscop *sscop_head = NULL;
52 struct sscop_stat sscop_stat = {0};
54 struct atm_time sscop_timer = {0, 0};
56 struct sp_info sscop_pool = {
57 "sscop pool", /* si_name */
58 sizeof(struct sscop), /* si_blksiz */
67 static int sscop_inst __P((struct stack_defn **, Atm_connvc *));
73 static struct stack_defn sscop_service = {
83 static struct t_atm_cause sscop_cause = {
86 T_ATM_CAUSE_TEMPORARY_FAILURE,
90 static u_char sscop_maa_log[MAA_ERROR_COUNT] = {
120 * Initialize SSCOP processing
122 * This will be called during module loading. We will register our stack
123 * service and wait for someone to talk to us.
129 * 0 initialization was successful
130 * errno initialization failed - reason indicated
139 * Register stack service
141 if ((err = atm_stack_register(&sscop_service)) != 0)
147 atm_timeout(&sscop_timer, ATM_HZ/SSCOP_HZ, sscop_timeout);
155 * Terminate SSCOP processing
157 * This will be called just prior to unloading the module from memory. All
158 * signalling instances should have been terminated by now, so we just free
159 * up all of our resources.
167 * 0 termination was successful
168 * errno termination failed - reason indicated
177 * Any connections still exist??
182 * Yes, can't stop yet
190 (void) atm_untimeout(&sscop_timer);
193 * Deregister the stack service
195 (void) atm_stack_deregister(&sscop_service);
198 * Free our storage pools
200 atm_release_pool(&sscop_pool);
207 * SSCOP Stack Instantiation
212 * ssp pointer to array of stack definition pointers for connection
213 * ssp[0] points to upper layer's stack service definition
214 * ssp[1] points to this layer's stack service definition
215 * ssp[2] points to lower layer's stack service definition
216 * cvp pointer to connection vcc for this stack
219 * 0 instantiation successful
220 * errno instantiation failed - reason indicated
225 struct stack_defn **ssp;
228 struct stack_defn *sdp_up = ssp[0],
234 ATM_DEBUG2("sscop_inst: ssp=%p, cvp=%p\n", ssp, cvp);
239 if ((sdp_low->sd_sap & SAP_CLASS_MASK) != SAP_CPCS)
243 * Allocate our control block
245 sop = (struct sscop *)atm_allocate(&sscop_pool);
249 sop->so_state = SOS_INST;
250 sop->so_connvc = cvp;
251 sop->so_toku = sdp_up->sd_toku;
252 sop->so_upper = sdp_up->sd_upper;
255 * Store my token into service definition
257 sdp_me->sd_toku = sop;
260 * Update and save input buffer headroom
262 HEADIN(cvp, sizeof(struct pdu_hdr), 0);
263 /* sop->so_headin = cvp->cvc_attr.headin; */
266 * Pass instantiation down the stack
268 err = sdp_low->sd_inst(ssp + 1, cvp);
271 * Lower layer instantiation failed, free our resources
273 atm_free((caddr_t)sop);
278 * Link in connection block
280 LINK2TAIL(sop, struct sscop, sscop_head, so_next);
282 sscop_stat.sos_connects++;
285 * Save and update output buffer headroom
287 sop->so_headout = cvp->cvc_attr.headout;
288 HEADOUT(cvp, sizeof(struct pdu_hdr), 0);
291 * Save lower layer's interface info
293 sop->so_lower = sdp_low->sd_lower;
294 sop->so_tokl = sdp_low->sd_toku;
297 * Initialize version (until INIT received)
299 sop->so_vers = SSCOP_VERS_Q2110;
306 * Report Management Error
308 * Called to report an error to the layer management entity.
311 * sop pointer to sscop control block
319 sscop_maa_error(sop, code)
326 * Validate error code
328 if ((code < MAA_ERROR_MIN) ||
329 (code > MAA_ERROR_MAX))
330 code = MAA_ERROR_INVAL;
331 i = code - MAA_ERROR_MIN;
334 * Bump statistics counters
336 sscop_stat.sos_maa_error[i]++;
341 if (sscop_maa_log[i] != 0) {
342 struct vccb *vcp = sop->so_connvc->cvc_vcc;
343 struct atm_pif *pip = vcp->vc_pif;
346 "sscop_maa_error: intf=%s%d vpi=%d vci=%d code=%c state=%d\n",
347 pip->pif_name, pip->pif_unit,
348 vcp->vc_vpi, vcp->vc_vci, code, sop->so_state);
354 * Abort an SSCOP connection
356 * Called when an unrecoverable or "should never happen" error occurs.
357 * We log a message, send an END PDU to our peer and request the signalling
358 * manager to abort the connection.
361 * sop pointer to sscop control block
362 * msg pointer to error message
369 sscop_abort(sop, msg)
373 Atm_connvc *cvp = sop->so_connvc;
376 * Log and count error
378 log(LOG_ERR, "%s", msg);
379 sscop_stat.sos_aborts++;
382 * Send an END PDU as a courtesy to peer
384 (void) sscop_send_end(sop, SSCOP_SOURCE_SSCOP);
387 * Set termination state
389 sop->so_state = SOS_TERM;
392 * Flush all of our queues
394 sscop_xmit_drain(sop);
395 sscop_rcvr_drain(sop);
398 * Tell Connection Manager to abort this connection
400 (void) atm_cm_abort(cvp, &sscop_cause);