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