Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / netproto / atm / uni / unisig_proto.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/unisig_proto.c,v 1.5 2000/01/17 20:49:57 mks Exp $
27  *
28  */
29
30 /*
31  * ATM Forum UNI 3.0/3.1 Signalling Manager
32  * ----------------------------------------
33  *
34  * Protocol processing module.
35  *
36  */
37
38 #include <netatm/kern_include.h>
39
40 #include <netatm/uni/unisig_var.h>
41
42 #ifndef lint
43 __RCSID("@(#) $FreeBSD: src/sys/netatm/uni/unisig_proto.c,v 1.5 2000/01/17 20:49:57 mks Exp $");
44 #endif
45
46
47 /*
48  * Process a UNISIG timeout
49  *
50  * Called when a previously scheduled protocol instance control block
51  * timer expires.  This routine passes a timeout event to the UNISIG
52  * signalling manager state machine.
53  *
54  * Called at splnet.
55  *
56  * Arguments:
57  *      tip     pointer to UNISIG timer control block
58  *
59  * Returns:
60  *      none
61  *
62  */
63 void
64 unisig_timer(tip)
65         struct atm_time *tip;
66 {
67         struct unisig   *usp;
68
69         /*
70          * Back-off to UNISIG control block
71          */
72         usp = (struct unisig *)
73                 ((caddr_t)tip - (int)(&((struct unisig *)0)->us_time));
74
75         ATM_DEBUG2("unisig_timer: usp=%p,state=%d\n",
76                         usp, usp->us_state);
77
78         /*
79          * Pass the timeout to the signalling manager state machine
80          */
81         (void) unisig_sigmgr_state(usp,
82                         UNISIG_SIGMGR_TIMEOUT,
83                         (KBuffer *) 0);
84 }
85
86
87 /*
88  * Process a UNISIG VCC timeout
89  *
90  * Called when a previously scheduled UNISIG VCCB timer expires.
91  * Processing will based on the current VCC state.
92  *
93  * Called at splnet.
94  *
95  * Arguments:
96  *      tip     pointer to vccb timer control block
97  *
98  * Returns:
99  *      none
100  *
101  */
102 void
103 unisig_vctimer(tip)
104         struct atm_time *tip;
105 {
106         struct unisig           *usp;
107         struct unisig_vccb      *uvp;
108
109         /*
110          * Get VCCB and UNISIG control block addresses
111          */
112         uvp = (struct unisig_vccb *) ((caddr_t)tip -
113                         (int)(&((struct vccb *)0)->vc_time));
114         usp = (struct unisig *)uvp->uv_pif->pif_siginst;
115
116         ATM_DEBUG3("unisig_vctimer: uvp=%p, sstate=%d, ustate=%d\n",
117                         uvp, uvp->uv_sstate, uvp->uv_ustate);
118
119         /*
120          * Hand the timeout to the VC finite state machine
121          */
122         if (uvp->uv_ustate == VCCU_ABORT) {
123                 /*
124                  * If we're aborting, this is an ABORT call
125                  */
126                 (void) unisig_vc_state(usp, uvp, UNI_VC_ABORT_CALL,
127                                 (struct unisig_msg *) 0);
128         } else {
129                 /*
130                  * If we're not aborting, it's a timeout
131                  */
132                 (void) unisig_vc_state(usp, uvp, UNI_VC_TIMEOUT,
133                                 (struct unisig_msg *) 0);
134         }
135 }
136
137
138 /*
139  * UNISIG SAAL Control Handler
140  *
141  * This is the module which receives data on the UNISIG signalling
142  * channel.  Processing is based on the indication received from the
143  * SSCF and the protocol state.
144  *
145  * Arguments:
146  *      cmd     command code
147  *      tok     session token (pointer to UNISIG protocol control block)
148  *      a1      argument 1
149  *
150  * Returns:
151  *      none
152  *
153  */
154 void
155 unisig_saal_ctl(cmd, tok, a1)
156         int             cmd;
157         void            *tok;
158         void            *a1;
159 {
160         struct unisig   *usp = tok;
161
162         ATM_DEBUG4("unisig_upper: usp=%p,state=%d,cmd=%d,a1=0x%lx,\n",
163                         usp, usp->us_state, cmd, (u_long)a1);
164
165         /*
166          * Process command
167          */
168         switch (cmd) {
169
170         case SSCF_UNI_ESTABLISH_IND:
171                 (void) unisig_sigmgr_state(usp,
172                                 UNISIG_SIGMGR_SSCF_EST_IND,
173                                 (KBuffer *) 0);
174                 break;
175
176         case SSCF_UNI_ESTABLISH_CNF:
177                 (void) unisig_sigmgr_state(usp,
178                                 UNISIG_SIGMGR_SSCF_EST_CNF,
179                                 (KBuffer *) 0);
180                 break;
181
182         case SSCF_UNI_RELEASE_IND:
183                 (void) unisig_sigmgr_state(usp,
184                                 UNISIG_SIGMGR_SSCF_RLS_IND,
185                                 (KBuffer *) 0);
186                 break;
187
188         case SSCF_UNI_RELEASE_CNF:
189                 (void) unisig_sigmgr_state(usp,
190                                 UNISIG_SIGMGR_SSCF_RLS_CNF,
191                                 (KBuffer *) 0);
192                 break;
193
194         default:
195                 log(LOG_ERR,
196                         "unisig: unknown SAAL cmd: usp=%p, state=%d, cmd=%d\n",
197                         usp, usp->us_state, cmd);
198         }
199 }
200
201
202 /*
203  * UNISIG SAAL Data Handler
204  *
205  * This is the module which receives data on the UNISIG signalling
206  * channel.  Processing is based on the protocol state.
207  *
208  * Arguments:
209  *      tok     session token (pointer to UNISIG protocol control block)
210  *      m       pointer to data
211  *
212  * Returns:
213  *      none
214  *
215  */
216 void
217 unisig_saal_data(tok, m)
218         void            *tok;
219         KBuffer         *m;
220 {
221         struct unisig   *usp = tok;
222
223         ATM_DEBUG3("unisig_saal_data: usp=%p,state=%d,m=%p,\n",
224                         usp, usp->us_state, m);
225
226         /*
227          * Pass data to signalling manager state machine
228          */
229         (void) unisig_sigmgr_state(usp,
230                         UNISIG_SIGMGR_SSCF_DATA_IND,
231                         m);
232 }
233
234
235 /*
236  * Get Connection's Application/Owner Name
237  *
238  * Arguments:
239  *      tok     UNI signalling connection token (pointer to protocol instance)
240  *
241  * Returns:
242  *      addr    pointer to string containing our name
243  *
244  */
245 caddr_t
246 unisig_getname(tok)
247         void            *tok;
248 {
249         struct unisig   *usp = tok;
250
251         if (usp->us_proto == ATM_SIG_UNI30)
252                 return ("UNI3.0");
253         else if (usp->us_proto == ATM_SIG_UNI31)
254                 return ("UNI3.1");
255         else if (usp->us_proto == ATM_SIG_UNI40)
256                 return ("UNI4.0");
257         else
258                 return ("UNI");
259 }
260
261
262 /*
263  * Process a VCC connection notification
264  *
265  * Should never be called.
266  *
267  * Arguments:
268  *      tok     user's connection token (unisig protocol block)
269  *
270  * Returns:
271  *      none
272  *
273  */
274 void
275 unisig_connected(tok)
276         void            *tok;
277 {
278         struct unisig           *usp = tok;
279
280         ATM_DEBUG2("unisig_connected: usp=%p,state=%d\n",
281                         usp, usp->us_state);
282
283         /*
284          * Connected routine shouldn't ever get called for a PVC
285          */
286         log(LOG_ERR, "unisig: connected notification, usp=%p\n",
287                         usp);
288 }
289
290
291 /*
292  * Process a VCC closed notification
293  *
294  * Called when UNISIG signalling channel is closed.
295  *
296  * Arguments:
297  *      tok     user's connection token (unisig protocol block)
298  *      cp      pointer to cause structure
299  *
300  * Returns:
301  *      none
302  *
303  */
304 void
305 unisig_cleared(tok, cp)
306         void                    *tok;
307         struct t_atm_cause      *cp;
308 {
309         struct unisig           *usp = tok;
310
311         ATM_DEBUG3("unisig_cleared: usp=%p, state=%d, cause=%d\n",
312                         usp, usp->us_state, cp->cause_value);
313
314         /*
315          * VCC has been closed.  Notify the signalling
316          * manager state machine.
317          */
318         (void) unisig_sigmgr_state(usp,
319                         UNISIG_SIGMGR_CALL_CLEARED,
320                         (KBuffer *) 0);
321 }