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.6 2006/01/14 13:36:39 swildner Exp $
31 * ATM Forum UNI Support
32 * ---------------------
34 * Service Specific Connection Oriented Protocol (SSCOP)
38 #include <netproto/atm/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 (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 atm_untimeout(&sscop_timer
);
193 * Deregister the stack service
195 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
224 sscop_inst(struct stack_defn
**ssp
, Atm_connvc
*cvp
)
226 struct stack_defn
*sdp_up
= ssp
[0],
232 ATM_DEBUG2("sscop_inst: ssp=%p, cvp=%p\n", ssp
, cvp
);
237 if ((sdp_low
->sd_sap
& SAP_CLASS_MASK
) != SAP_CPCS
)
241 * Allocate our control block
243 sop
= (struct sscop
*)atm_allocate(&sscop_pool
);
247 sop
->so_state
= SOS_INST
;
248 sop
->so_connvc
= cvp
;
249 sop
->so_toku
= sdp_up
->sd_toku
;
250 sop
->so_upper
= sdp_up
->sd_upper
;
253 * Store my token into service definition
255 sdp_me
->sd_toku
= sop
;
258 * Update and save input buffer headroom
260 HEADIN(cvp
, sizeof(struct pdu_hdr
), 0);
261 /* sop->so_headin = cvp->cvc_attr.headin; */
264 * Pass instantiation down the stack
266 err
= sdp_low
->sd_inst(ssp
+ 1, cvp
);
269 * Lower layer instantiation failed, free our resources
271 atm_free((caddr_t
)sop
);
276 * Link in connection block
278 LINK2TAIL(sop
, struct sscop
, sscop_head
, so_next
);
280 sscop_stat
.sos_connects
++;
283 * Save and update output buffer headroom
285 sop
->so_headout
= cvp
->cvc_attr
.headout
;
286 HEADOUT(cvp
, sizeof(struct pdu_hdr
), 0);
289 * Save lower layer's interface info
291 sop
->so_lower
= sdp_low
->sd_lower
;
292 sop
->so_tokl
= sdp_low
->sd_toku
;
295 * Initialize version (until INIT received)
297 sop
->so_vers
= SSCOP_VERS_Q2110
;
304 * Report Management Error
306 * Called to report an error to the layer management entity.
309 * sop pointer to sscop control block
317 sscop_maa_error(struct sscop
*sop
, int code
)
322 * Validate error code
324 if ((code
< MAA_ERROR_MIN
) ||
325 (code
> MAA_ERROR_MAX
))
326 code
= MAA_ERROR_INVAL
;
327 i
= code
- MAA_ERROR_MIN
;
330 * Bump statistics counters
332 sscop_stat
.sos_maa_error
[i
]++;
337 if (sscop_maa_log
[i
] != 0) {
338 struct vccb
*vcp
= sop
->so_connvc
->cvc_vcc
;
339 struct atm_pif
*pip
= vcp
->vc_pif
;
342 "sscop_maa_error: intf=%s%d vpi=%d vci=%d code=%c state=%d\n",
343 pip
->pif_name
, pip
->pif_unit
,
344 vcp
->vc_vpi
, vcp
->vc_vci
, code
, sop
->so_state
);
350 * Abort an SSCOP connection
352 * Called when an unrecoverable or "should never happen" error occurs.
353 * We log a message, send an END PDU to our peer and request the signalling
354 * manager to abort the connection.
357 * sop pointer to sscop control block
358 * msg pointer to error message
365 sscop_abort(struct sscop
*sop
, char *msg
)
367 Atm_connvc
*cvp
= sop
->so_connvc
;
370 * Log and count error
372 log(LOG_ERR
, "%s", msg
);
373 sscop_stat
.sos_aborts
++;
376 * Send an END PDU as a courtesy to peer
378 sscop_send_end(sop
, SSCOP_SOURCE_SSCOP
);
381 * Set termination state
383 sop
->so_state
= SOS_TERM
;
386 * Flush all of our queues
388 sscop_xmit_drain(sop
);
389 sscop_rcvr_drain(sop
);
392 * Tell Connection Manager to abort this connection
394 atm_cm_abort(cvp
, &sscop_cause
);