* Remove (void) casts for discarded return values.
[dragonfly.git] / sys / netproto / atm / uni / sscf_uni.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
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.
12  *
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.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/sys/netatm/uni/sscf_uni.c,v 1.7.2.1 2001/09/30 22:54:35 kris Exp $
27  *      @(#) $DragonFly: src/sys/netproto/atm/uni/sscf_uni.c,v 1.6 2006/01/14 13:36:39 swildner Exp $
28  */
29
30 /*
31  * ATM Forum UNI Support
32  * ---------------------
33  *
34  * Signalling AAL SSCF at the UNI
35  *
36  */
37
38 #include <netproto/atm/kern_include.h>
39
40 #include "uni.h"
41 #include "sscf_uni_var.h"
42
43 /*
44  * Global variables
45  */
46 int     sscf_uni_vccnt = 0;
47
48 /*
49  * Local functions
50  */
51 static int      sscf_uni_inst (struct stack_defn **, Atm_connvc *);
52
53 /*
54  * Local variables
55  */
56 static struct sp_info   sscf_uni_pool = {
57         "sscf uni pool",                /* si_name */
58         sizeof(struct univcc),          /* si_blksiz */
59         5,                              /* si_blkcnt */
60         100                             /* si_maxallow */
61 };
62
63 static struct stack_defn        sscf_uni_service = {
64         NULL,
65         SAP_SSCF_UNI,
66         0,
67         sscf_uni_inst,
68         sscf_uni_lower,
69         sscf_uni_upper,
70         0
71 };
72
73 static struct t_atm_cause       sscf_uni_cause = {
74         T_ATM_ITU_CODING,
75         T_ATM_LOC_USER,
76         T_ATM_CAUSE_TEMPORARY_FAILURE,
77         {0, 0, 0, 0}
78 };
79
80
81 /*
82  * Initialize SSCF UNI processing
83  * 
84  * This will be called during module loading.  We will register our stack
85  * service and wait for someone to talk to us.
86  *
87  * Arguments:
88  *      none
89  *
90  * Returns:
91  *      0       initialization was successful 
92  *      errno   initialization failed - reason indicated
93  *
94  */
95 int
96 sscf_uni_start(void)
97 {
98         int     err = 0;
99
100         /*
101          * Register stack service
102          */
103         if ((err = atm_stack_register(&sscf_uni_service)) != 0)
104                 goto done;
105
106 done:
107         return (err);
108 }
109
110
111 /*
112  * Terminate SSCF UNI processing 
113  * 
114  * This will be called just prior to unloading the module from memory.  All 
115  * signalling instances should have been terminated by now, so we just free
116  * up all of our resources.
117  *
118  * Called at splnet.
119  *
120  * Arguments:
121  *      none
122  *
123  * Returns:
124  *      0       termination was successful 
125  *      errno   termination failed - reason indicated
126  *
127  */
128 int
129 sscf_uni_stop(void)
130 {
131         /*
132          * Any connections still exist??
133          */
134         if (sscf_uni_vccnt) {
135
136                 /*
137                  * Yes, can't stop yet
138                  */
139                 return (EBUSY);
140         }
141
142         /*
143          * Deregister the stack service
144          */
145         atm_stack_deregister(&sscf_uni_service);
146
147         /*
148          * Free our storage pools
149          */
150         atm_release_pool(&sscf_uni_pool);
151
152         return (0);
153 }
154
155
156 /*
157  * SSCF_UNI Stack Instantiation 
158  * 
159  * Called at splnet.
160  *
161  * Arguments:
162  *      ssp     pointer to array of stack definition pointers for connection
163  *              ssp[0] points to upper layer's stack service definition
164  *              ssp[1] points to this layer's stack service definition
165  *              ssp[2] points to lower layer's stack service definition
166  *      cvp     pointer to connection vcc for this stack
167  *
168  * Returns:
169  *      0       instantiation successful
170  *      errno   instantiation failed - reason indicated
171  *
172  */
173 static int
174 sscf_uni_inst(struct stack_defn **ssp, Atm_connvc *cvp)
175 {
176         struct stack_defn       *sdp_up = ssp[0],
177                                 *sdp_me = ssp[1],
178                                 *sdp_low = ssp[2];
179         struct univcc   *uvp;
180         int             err;
181
182         ATM_DEBUG2("sscf_uni_inst: ssp=%p, cvp=%p\n", ssp, cvp);
183
184         /*
185          * Validate lower SAP
186          */
187         if (sdp_low->sd_sap != SAP_SSCOP)
188                 return (EINVAL);
189
190         /*
191          * Allocate our control block
192          */
193         uvp = (struct univcc *)atm_allocate(&sscf_uni_pool);
194         if (uvp == NULL)
195                 return (ENOMEM);
196
197         uvp->uv_ustate = UVU_INST;
198         uvp->uv_lstate = UVL_INST;
199         uvp->uv_connvc = cvp;
200         uvp->uv_toku = sdp_up->sd_toku;
201         uvp->uv_upper = sdp_up->sd_upper;
202         sscf_uni_vccnt++;
203
204         /*
205          * Store my token into service definition
206          */
207         sdp_me->sd_toku = uvp;
208
209         /*
210          * Update and save input buffer headroom
211          */
212         HEADIN(cvp, 0, 0);
213         /* uvp->uv_headin = cvp->cvc_attr.headin; */
214
215         /*
216          * Pass instantiation down the stack
217          */
218         err = sdp_low->sd_inst(ssp + 1, cvp);
219         if (err) {
220                 /*
221                  * Lower layer instantiation failed, free our resources
222                  */
223                 atm_free((caddr_t)uvp);
224                 sscf_uni_vccnt--;
225                 return (err);
226         }
227
228         /*
229          * Save and update output buffer headroom
230          */
231         /* uvp->uv_headout = cvp->cvc_attr.headout; */
232         HEADOUT(cvp, 0, 0);
233
234         /*
235          * Save lower layer's interface info
236          */
237         uvp->uv_lower = sdp_low->sd_lower;
238         uvp->uv_tokl = sdp_low->sd_toku;
239
240         return (0);
241 }
242
243
244 /*
245  * Abort an SSCF_UNI connection
246  * 
247  * Called when an unrecoverable or "should never happen" error occurs.
248  * We just log a message and request the signalling manager to abort the
249  * connection.
250  *
251  * Arguments:
252  *      uvp     pointer to univcc control block
253  *      msg     pointer to error message
254  *
255  * Returns:
256  *      none
257  *
258  */
259 void
260 sscf_uni_abort(struct univcc *uvp, char *msg)
261 {
262         /*
263          * Log error message
264          */
265         log(LOG_ERR, "%s", msg);
266
267         /*
268          * Set termination states
269          */
270         uvp->uv_ustate = UVU_TERM;
271         uvp->uv_lstate = UVL_TERM;
272
273         /*
274          * Tell Connection Manager to abort this connection
275          */
276         atm_cm_abort(uvp->uv_connvc, &sscf_uni_cause);
277 }
278
279
280 /*
281  * Print an SSCF PDU
282  * 
283  * Arguments:
284  *      uvp     pointer to univcc control block
285  *      m       pointer to pdu buffer chain
286  *      msg     pointer to message string
287  *
288  * Returns:
289  *      none
290  *
291  */
292 void
293 sscf_uni_pdu_print(struct univcc *uvp, KBuffer *m, char *msg)
294 {
295         char            buf[128];
296         struct vccb     *vcp;
297
298         vcp = uvp->uv_connvc->cvc_vcc;
299         snprintf(buf, sizeof(buf), "sscf_uni %s: vcc=(%d,%d)\n",
300                         msg, vcp->vc_vpi, vcp->vc_vci);
301         atm_pdu_print(m, buf);
302 }
303