]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/i4b/layer3/i4b_l4if.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / i4b / layer3 / i4b_l4if.c
1 /*-
2  * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25
26 /*---------------------------------------------------------------------------
27  *
28  *      i4b_l4if.c - Layer 3 interface to Layer 4
29  *      -------------------------------------------
30  *      last edit-date: [Sat Mar  9 19:36:08 2002]
31  *
32  *---------------------------------------------------------------------------*/
33
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/mbuf.h>
40
41 #include <i4b/include/i4b_debug.h>
42 #include <i4b/include/i4b_ioctl.h>
43 #include <i4b/include/i4b_cause.h>
44
45 #include <i4b/include/i4b_l2l3.h>
46 #include <i4b/include/i4b_l3l4.h>
47 #include <i4b/include/i4b_global.h>
48
49 #include <i4b/layer3/i4b_l3.h>
50 #include <i4b/layer3/i4b_l3fsm.h>
51
52 #include <i4b/layer4/i4b_l4.h>
53
54 extern void isic_settrace(int unit, int val);           /*XXX*/
55 extern int isic_gettrace(int unit);                     /*XXX*/
56
57 static void n_connect_request(u_int cdid);
58 static void n_connect_response(u_int cdid, int response, int cause);
59 static void n_disconnect_request(u_int cdid, int cause);
60 static void n_alert_request(u_int cdid);
61 static void n_mgmt_command(int unit, int cmd, void *parm);
62
63 /*---------------------------------------------------------------------------*
64  *      i4b_mdl_status_ind - status indication from lower layers
65  *---------------------------------------------------------------------------*/
66 int
67 i4b_mdl_status_ind(int unit, int status, int parm)
68 {
69         int sendup;
70         int i;
71         
72         NDBGL3(L3_MSG, "unit = %d, status = %d, parm = %d", unit, status, parm);
73
74         switch(status)
75         {
76                 case STI_ATTACH:
77                         NDBGL3(L3_MSG, "STI_ATTACH: attaching unit %d to controller %d", unit, nctrl);
78                 
79                         /* init function pointers */
80                         
81                         ctrl_desc[nctrl].N_CONNECT_REQUEST = n_connect_request;
82                         ctrl_desc[nctrl].N_CONNECT_RESPONSE = n_connect_response;
83                         ctrl_desc[nctrl].N_DISCONNECT_REQUEST = n_disconnect_request;
84                         ctrl_desc[nctrl].N_ALERT_REQUEST = n_alert_request;     
85                         ctrl_desc[nctrl].N_DOWNLOAD = NULL;     /* only used by active cards */
86                         ctrl_desc[nctrl].N_DIAGNOSTICS = NULL;  /* only used by active cards */
87                         ctrl_desc[nctrl].N_MGMT_COMMAND = n_mgmt_command;
88                 
89                         /* init type and unit */
90                         
91                         ctrl_desc[nctrl].unit = unit;
92                         ctrl_desc[nctrl].ctrl_type = CTRL_PASSIVE;
93                         ctrl_desc[nctrl].card_type = parm;
94                 
95                         /* state fields */
96                 
97                         ctrl_desc[nctrl].dl_est = DL_DOWN;
98                         ctrl_desc[nctrl].nbch = 2; /* XXX extra param? */
99                         for (i = 0; i < ctrl_desc[nctrl].nbch; i++)
100                             ctrl_desc[nctrl].bch_state[i] = BCH_ST_FREE;
101
102                         ctrl_desc[nctrl].tei = -1;
103                         
104                         /* init unit to controller table */
105                         
106                         utoc_tab[unit] = nctrl;
107                         
108                         /* increment no. of controllers */
109                         
110                         nctrl++;
111
112                         break;
113                         
114                 case STI_L1STAT:
115                         i4b_l4_l12stat(unit, 1, parm);
116                         NDBGL3(L3_MSG, "STI_L1STAT: unit %d layer 1 = %s", unit, status ? "up" : "down");
117                         break;
118                         
119                 case STI_L2STAT:
120                         i4b_l4_l12stat(unit, 2, parm);
121                         NDBGL3(L3_MSG, "STI_L2STAT: unit %d layer 2 = %s", unit, status ? "up" : "down");
122                         break;
123
124                 case STI_TEIASG:
125                         ctrl_desc[unit].tei = parm;
126                         i4b_l4_teiasg(unit, parm);
127                         NDBGL3(L3_MSG, "STI_TEIASG: unit %d TEI = %d = 0x%02x", unit, parm, parm);
128                         break;
129
130                 case STI_PDEACT:        /* L1 T4 timeout */
131                         NDBGL3(L3_ERR, "STI_PDEACT: unit %d TEI = %d = 0x%02x", unit, parm, parm);
132
133                         sendup = 0;
134
135                         for(i=0; i < N_CALL_DESC; i++)
136                         {
137                                 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
138                                     (ctrl_desc[call_desc[i].controller].unit == unit))
139                                 {
140                                         i4b_l3_stop_all_timers(&(call_desc[i]));
141                                         if(call_desc[i].cdid != CDID_UNUSED)
142                                                 sendup++;
143                                 }
144                         }
145
146                         ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
147                         for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
148                             ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
149                         ctrl_desc[utoc_tab[unit]].tei = -1;
150
151                         if(sendup)
152                         {
153                                 i4b_l4_pdeact(unit, sendup);
154                                 call_desc[i].cdid = CDID_UNUSED;
155                         }
156                         break;
157
158                 case STI_NOL1ACC:       /* no outgoing access to S0 */
159                         NDBGL3(L3_ERR, "STI_NOL1ACC: unit %d no outgoing access to S0", unit);
160
161                         for(i=0; i < N_CALL_DESC; i++)
162                         {
163                                 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
164                                     (ctrl_desc[call_desc[i].controller].unit == unit))
165                                 {
166                                         if(call_desc[i].cdid != CDID_UNUSED)
167                                         {
168                                                 SET_CAUSE_TYPE(call_desc[i].cause_in, CAUSET_I4B);
169                                                 SET_CAUSE_VAL(call_desc[i].cause_in, CAUSE_I4B_L1ERROR);
170                                                 i4b_l4_disconnect_ind(&(call_desc[i]));
171                                         }
172                                 }
173                         }
174
175                         ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
176                         for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
177                             ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
178                         ctrl_desc[utoc_tab[unit]].tei = -1;
179                         break;
180
181                 default:
182                         NDBGL3(L3_ERR, "ERROR, unit %d, unknown status value %d!", unit, status);
183                         break;
184         }               
185         return(0);
186 }
187
188 /*---------------------------------------------------------------------------*
189  *      send command to the lower layers
190  *---------------------------------------------------------------------------*/
191 static void
192 n_mgmt_command(int unit, int cmd, void *parm)
193 {
194         int i;
195
196         switch(cmd)
197         {
198                 case CMR_DOPEN:
199                         NDBGL3(L3_MSG, "CMR_DOPEN for unit %d", unit);
200                         
201                         for(i=0; i < N_CALL_DESC; i++)
202                         {
203                                 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
204                                     (ctrl_desc[call_desc[i].controller].unit == unit))
205                                 {
206                                         call_desc[i].cdid = CDID_UNUSED;
207                                 }
208                         }
209
210                         ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
211                         for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
212                             ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
213                         ctrl_desc[utoc_tab[unit]].tei = -1;
214                         break;
215
216                 case CMR_DCLOSE:
217                         NDBGL3(L3_MSG, "CMR_DCLOSE for unit %d", unit);
218                         break;
219                         
220                 case CMR_SETTRACE:
221                         NDBGL3(L3_MSG, "CMR_SETTRACE for unit %d", unit);
222                         break;
223                         
224                 default:
225                         NDBGL3(L3_MSG, "unknown cmd %d for unit %d", cmd, unit);
226                         break;
227         }
228
229         MDL_Command_Req(unit, cmd, parm);
230         
231 }
232
233 /*---------------------------------------------------------------------------*
234  *      handle connect request message from userland
235  *---------------------------------------------------------------------------*/
236 static void
237 n_connect_request(u_int cdid)
238 {
239         call_desc_t *cd;
240
241         cd = cd_by_cdid(cdid);
242
243         next_l3state(cd, EV_SETUPRQ);   
244 }
245
246 /*---------------------------------------------------------------------------*
247  *      handle setup response message from userland
248  *---------------------------------------------------------------------------*/
249 static void
250 n_connect_response(u_int cdid, int response, int cause)
251 {
252         call_desc_t *cd;
253         int chstate;
254
255         cd = cd_by_cdid(cdid);
256
257         T400_stop(cd);
258         
259         cd->response = response;
260         cd->cause_out = cause;
261
262         switch(response)
263         {
264                 case SETUP_RESP_ACCEPT:
265                         next_l3state(cd, EV_SETACRS);
266                         chstate = BCH_ST_USED;
267                         break;
268                 
269                 case SETUP_RESP_REJECT:
270                         next_l3state(cd, EV_SETRJRS);
271                         chstate = BCH_ST_FREE;
272                         break;
273                         
274                 case SETUP_RESP_DNTCRE:
275                         next_l3state(cd, EV_SETDCRS);
276                         chstate = BCH_ST_FREE;
277                         break;
278
279                 default:        /* failsafe */
280                         next_l3state(cd, EV_SETDCRS);
281                         chstate = BCH_ST_FREE;
282                         NDBGL3(L3_ERR, "unknown response, doing SETUP_RESP_DNTCRE");
283                         break;
284         }
285
286         if((cd->channelid >= 0) && (cd->channelid < ctrl_desc[cd->controller].nbch))
287         {
288                 ctrl_desc[cd->controller].bch_state[cd->channelid] = chstate;
289         }
290         else
291         {
292                 NDBGL3(L3_MSG, "Warning, invalid channelid %d, response = %d\n", cd->channelid, response);
293         }
294 }
295
296 /*---------------------------------------------------------------------------*
297  *      handle disconnect request message from userland
298  *---------------------------------------------------------------------------*/
299 static void
300 n_disconnect_request(u_int cdid, int cause)
301 {
302         call_desc_t *cd;
303
304         cd = cd_by_cdid(cdid);
305
306         cd->cause_out = cause;
307
308         next_l3state(cd, EV_DISCRQ);
309 }
310
311 /*---------------------------------------------------------------------------*
312  *      handle alert request message from userland
313  *---------------------------------------------------------------------------*/
314 static void
315 n_alert_request(u_int cdid)
316 {
317         call_desc_t *cd;
318
319         cd = cd_by_cdid(cdid);
320
321         next_l3state(cd, EV_ALERTRQ);
322 }