2 * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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
26 /*---------------------------------------------------------------------------
28 * i4b_l4if.c - Layer 3 interface to Layer 4
29 * -------------------------------------------
30 * last edit-date: [Sat Mar 9 19:36:08 2002]
32 *---------------------------------------------------------------------------*/
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/systm.h>
41 #include <i4b/include/i4b_debug.h>
42 #include <i4b/include/i4b_ioctl.h>
43 #include <i4b/include/i4b_cause.h>
45 #include <i4b/include/i4b_l2l3.h>
46 #include <i4b/include/i4b_l3l4.h>
47 #include <i4b/include/i4b_global.h>
49 #include <i4b/layer3/i4b_l3.h>
50 #include <i4b/layer3/i4b_l3fsm.h>
52 #include <i4b/layer4/i4b_l4.h>
54 extern void isic_settrace(int unit, int val); /*XXX*/
55 extern int isic_gettrace(int unit); /*XXX*/
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);
63 /*---------------------------------------------------------------------------*
64 * i4b_mdl_status_ind - status indication from lower layers
65 *---------------------------------------------------------------------------*/
67 i4b_mdl_status_ind(int unit, int status, int parm)
72 NDBGL3(L3_MSG, "unit = %d, status = %d, parm = %d", unit, status, parm);
77 NDBGL3(L3_MSG, "STI_ATTACH: attaching unit %d to controller %d", unit, nctrl);
79 /* init function pointers */
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;
89 /* init type and unit */
91 ctrl_desc[nctrl].unit = unit;
92 ctrl_desc[nctrl].ctrl_type = CTRL_PASSIVE;
93 ctrl_desc[nctrl].card_type = parm;
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;
102 ctrl_desc[nctrl].tei = -1;
104 /* init unit to controller table */
106 utoc_tab[unit] = nctrl;
108 /* increment no. of controllers */
115 i4b_l4_l12stat(unit, 1, parm);
116 NDBGL3(L3_MSG, "STI_L1STAT: unit %d layer 1 = %s", unit, status ? "up" : "down");
120 i4b_l4_l12stat(unit, 2, parm);
121 NDBGL3(L3_MSG, "STI_L2STAT: unit %d layer 2 = %s", unit, status ? "up" : "down");
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);
130 case STI_PDEACT: /* L1 T4 timeout */
131 NDBGL3(L3_ERR, "STI_PDEACT: unit %d TEI = %d = 0x%02x", unit, parm, parm);
135 for(i=0; i < N_CALL_DESC; i++)
137 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
138 (ctrl_desc[call_desc[i].controller].unit == unit))
140 i4b_l3_stop_all_timers(&(call_desc[i]));
141 if(call_desc[i].cdid != CDID_UNUSED)
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;
153 i4b_l4_pdeact(unit, sendup);
154 call_desc[i].cdid = CDID_UNUSED;
158 case STI_NOL1ACC: /* no outgoing access to S0 */
159 NDBGL3(L3_ERR, "STI_NOL1ACC: unit %d no outgoing access to S0", unit);
161 for(i=0; i < N_CALL_DESC; i++)
163 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
164 (ctrl_desc[call_desc[i].controller].unit == unit))
166 if(call_desc[i].cdid != CDID_UNUSED)
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]));
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;
182 NDBGL3(L3_ERR, "ERROR, unit %d, unknown status value %d!", unit, status);
188 /*---------------------------------------------------------------------------*
189 * send command to the lower layers
190 *---------------------------------------------------------------------------*/
192 n_mgmt_command(int unit, int cmd, void *parm)
199 NDBGL3(L3_MSG, "CMR_DOPEN for unit %d", unit);
201 for(i=0; i < N_CALL_DESC; i++)
203 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
204 (ctrl_desc[call_desc[i].controller].unit == unit))
206 call_desc[i].cdid = CDID_UNUSED;
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;
217 NDBGL3(L3_MSG, "CMR_DCLOSE for unit %d", unit);
221 NDBGL3(L3_MSG, "CMR_SETTRACE for unit %d", unit);
225 NDBGL3(L3_MSG, "unknown cmd %d for unit %d", cmd, unit);
229 MDL_Command_Req(unit, cmd, parm);
233 /*---------------------------------------------------------------------------*
234 * handle connect request message from userland
235 *---------------------------------------------------------------------------*/
237 n_connect_request(u_int cdid)
241 cd = cd_by_cdid(cdid);
243 next_l3state(cd, EV_SETUPRQ);
246 /*---------------------------------------------------------------------------*
247 * handle setup response message from userland
248 *---------------------------------------------------------------------------*/
250 n_connect_response(u_int cdid, int response, int cause)
255 cd = cd_by_cdid(cdid);
259 cd->response = response;
260 cd->cause_out = cause;
264 case SETUP_RESP_ACCEPT:
265 next_l3state(cd, EV_SETACRS);
266 chstate = BCH_ST_USED;
269 case SETUP_RESP_REJECT:
270 next_l3state(cd, EV_SETRJRS);
271 chstate = BCH_ST_FREE;
274 case SETUP_RESP_DNTCRE:
275 next_l3state(cd, EV_SETDCRS);
276 chstate = BCH_ST_FREE;
279 default: /* failsafe */
280 next_l3state(cd, EV_SETDCRS);
281 chstate = BCH_ST_FREE;
282 NDBGL3(L3_ERR, "unknown response, doing SETUP_RESP_DNTCRE");
286 if((cd->channelid >= 0) && (cd->channelid < ctrl_desc[cd->controller].nbch))
288 ctrl_desc[cd->controller].bch_state[cd->channelid] = chstate;
292 NDBGL3(L3_MSG, "Warning, invalid channelid %d, response = %d\n", cd->channelid, response);
296 /*---------------------------------------------------------------------------*
297 * handle disconnect request message from userland
298 *---------------------------------------------------------------------------*/
300 n_disconnect_request(u_int cdid, int cause)
304 cd = cd_by_cdid(cdid);
306 cd->cause_out = cause;
308 next_l3state(cd, EV_DISCRQ);
311 /*---------------------------------------------------------------------------*
312 * handle alert request message from userland
313 *---------------------------------------------------------------------------*/
315 n_alert_request(u_int cdid)
319 cd = cd_by_cdid(cdid);
321 next_l3state(cd, EV_ALERTRQ);