hammer(8): adjust markup & improve wording
[dragonfly.git] / sys / netproto / atm / uni / sscop_lower.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/sscop_lower.c,v 1.5 2000/01/17 20:49:51 mks Exp $
27  *      @(#) $DragonFly: src/sys/netproto/atm/uni/sscop_lower.c,v 1.6 2006/01/14 13:36:39 swildner Exp $
28  */
29
30 /*
31  * ATM Forum UNI Support
32  * ---------------------
33  *
34  * SSCOP - SSCOP SAP interface processing 
35  *
36  */
37
38 #include <netproto/atm/kern_include.h>
39
40 #include "sscop.h"
41 #include "sscop_misc.h"
42 #include "sscop_var.h"
43
44 /*
45  * Local variables
46  */
47 /*
48  * Stack commands with arg1 containing an buffer pointer
49  */
50 static u_char   sscop_buf1[] = {
51                 0,
52                 0,              /* SSCOP_INIT */
53                 0,              /* SSCOP_TERM */
54                 0,
55                 0,
56                 0,
57                 0,
58                 0,
59                 0,
60                 0,
61                 0,
62                 0,
63                 0,
64                 0,
65                 0,
66                 0,
67                 1,              /* SSCOP_ESTABLISH_REQ */
68                 0,
69                 1,              /* SSCOP_ESTABLISH_RSP */
70                 0,
71                 1,              /* SSCOP_RELEASE_REQ */
72                 0,
73                 0,
74                 1,              /* SSCOP_DATA_REQ */
75                 0,
76                 1,              /* SSCOP_RESYNC_REQ */
77                 0,
78                 0,              /* SSCOP_RESYNC_RSP */
79                 0,
80                 0,
81                 0,              /* SSCOP_RECOVER_RSP */
82                 1,              /* SSCOP_UNITDATA_REQ */
83                 0,
84                 0,              /* SSCOP_RETRIEVE_REQ */
85                 0,
86                 0
87 };
88
89
90 /*
91  * SSCOP Lower Stack Command Handler
92  * 
93  * This function will receive all of the stack commands issued from the 
94  * layer above SSCOP (ie. using the SSCOP SAP).  The appropriate processing
95  * function will be determined based on the received stack command and the 
96  * current sscop control block state.
97  *
98  * Arguments:
99  *      cmd     stack command code
100  *      tok     session token
101  *      arg1    command specific argument
102  *      arg2    command specific argument
103  *
104  * Returns:
105  *      none
106  *
107  */
108 void
109 sscop_lower(int cmd, void *tok, int arg1, int arg2)
110 {
111         struct sscop    *sop = (struct sscop *)tok;
112         void            (**stab) (struct sscop *, int, int);
113         void            (*func) (struct sscop *, int, int);
114         int             val;
115
116         ATM_DEBUG5("sscop_lower: cmd=0x%x, sop=%p, state=%d, arg1=0x%x, arg2=0x%x\n",
117                 cmd, sop, sop->so_state, arg1, arg2);
118
119         /*
120          * Validate stack command
121          */
122         val = cmd & STKCMD_VAL_MASK;
123         if (((u_int)cmd  < (u_int)SSCOP_CMD_MIN) ||
124             ((u_int)cmd  > (u_int)SSCOP_CMD_MAX) ||
125             ((stab = (sop->so_vers == SSCOP_VERS_QSAAL ? 
126                         sscop_qsaal_aatab[val] : 
127                         sscop_q2110_aatab[val])) == NULL)) {
128                 log(LOG_ERR, "sscop_lower: unknown cmd 0x%x, sop=%p\n",
129                         cmd, sop);
130                 return;
131         }
132
133         /*
134          * Validate sscop state
135          */
136         if (sop->so_state > SOS_MAXSTATE) {
137                 log(LOG_ERR, "sscop_lower: invalid state sop=%p, state=%d\n",
138                         sop, sop->so_state);
139                 /*
140                  * Release possible buffer
141                  */
142                 if (sscop_buf1[val]) {
143                         if (arg1)
144                                 KB_FREEALL((KBuffer *)arg1);
145                 }
146                 return;
147         }
148
149         /*
150          * Validate command/state combination
151          */
152         func = stab[sop->so_state];
153         if (func == NULL) {
154                 log(LOG_ERR, 
155                         "sscop_lower: invalid cmd/state: sop=%p, cmd=0x%x, state=%d\n",
156                         sop, cmd, sop->so_state);
157                 /*
158                  * Release possible buffer
159                  */
160                 if (sscop_buf1[val]) {
161                         if (arg1)
162                                 KB_FREEALL((KBuffer *)arg1);
163                 }
164                 return;
165         }
166
167         /*
168          * Call event processing function
169          */
170         (*func)(sop, arg1, arg2);
171
172         return;
173 }
174
175
176 /*
177  * No-op Processor (no buffers)
178  * 
179  * Arguments:
180  *      sop     pointer to sscop connection block
181  *      arg1    command-specific argument
182  *      arg2    command-specific argument
183  *
184  * Returns:
185  *      none
186  *
187  */
188 void
189 sscop_aa_noop_0(struct sscop *sop, int arg1, int arg2)
190 {
191         /*
192          * Nothing to do
193          */
194         return;
195 }
196
197
198 /*
199  * No-op Processor (arg1 == buffer)
200  * 
201  * Arguments:
202  *      sop     pointer to sscop connection block
203  *      arg1    command-specific argument (buffer pointer)
204  *      arg2    command-specific argument
205  *
206  * Returns:
207  *      none
208  *
209  */
210 void
211 sscop_aa_noop_1(struct sscop *sop, int arg1, int arg2)
212 {
213
214         /*
215          * Just free buffer chain
216          */
217         if (arg1)
218                 KB_FREEALL((KBuffer *)arg1);
219
220         return;
221 }
222
223
224 /*
225  * SSCOP_INIT / SOS_INST Command Processor
226  * 
227  * Arguments:
228  *      sop     pointer to sscop connection block
229  *      arg1    command specific argument
230  *      arg2    command specific argument
231  *
232  * Returns:
233  *      none
234  *
235  */
236 void
237 sscop_init_inst(struct sscop *sop, int arg1, int arg2)
238 {
239         int             err;
240
241         /*
242          * Make ourselves ready and pass on the INIT
243          */
244         sop->so_state = SOS_IDLE;
245
246         /*
247          * Validate SSCOP version to use
248          */
249         switch ((enum sscop_vers)arg1) {
250         case SSCOP_VERS_QSAAL:
251                 break;
252
253         case SSCOP_VERS_Q2110:
254                 break;
255
256         default:
257                 sscop_abort(sop, "sscop: bad version\n");
258                 return;
259         }
260         sop->so_vers = (enum sscop_vers)arg1;
261
262         /*
263          * Copy SSCOP connection parameters to use
264          */
265         sop->so_parm = *(struct sscop_parms *)arg2;
266
267         /*
268          * Initialize lower layers
269          */
270         STACK_CALL(CPCS_INIT, sop->so_lower, sop->so_tokl, sop->so_connvc,
271                 0, 0, err);
272         if (err) {
273                 /*
274                  * Should never happen
275                  */
276                 sscop_abort(sop, "sscop: INIT failure\n");
277                 return;
278         }
279         return;
280 }
281
282
283 /*
284  * SSCOP_TERM / SOS_* Command Processor
285  * 
286  * Arguments:
287  *      sop     pointer to sscop connection block
288  *      arg1    command specific argument
289  *      arg2    command specific argument
290  *
291  * Returns:
292  *      none
293  *
294  */
295 void
296 sscop_term_all(struct sscop *sop, int arg1, int arg2)
297 {
298         int             err;
299
300         /*
301          * Set termination state
302          */
303         sop->so_state = SOS_TERM;
304
305         /*
306          * Pass the TERM down the stack
307          */
308         STACK_CALL(CPCS_TERM, sop->so_lower, sop->so_tokl, sop->so_connvc,
309                 0, 0, err);
310         if (err) {
311                 /*
312                  * Should never happen
313                  */
314                 sscop_abort(sop, "sscop: TERM failure\n");
315                 return;
316         }
317
318         /*
319          * Unlink and free the connection block
320          */
321         UNLINK(sop, struct sscop, sscop_head, so_next);
322         atm_free((caddr_t)sop);
323         sscop_vccnt--;
324         return;
325 }
326