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