2 * Copyright (c) 1997, 2000 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
25 *---------------------------------------------------------------------------
27 * i4b_l4if.c - Layer 3 interface to Layer 4
28 * -------------------------------------------
30 * $Id: i4b_l4if.c,v 1.27 2000/08/24 11:48:58 hm Exp $
32 * $FreeBSD: src/sys/i4b/layer3/i4b_l4if.c,v 1.6.2.1 2001/08/10 14:08:42 obrien Exp $
33 * $DragonFly: src/sys/net/i4b/layer3/i4b_l4if.c,v 1.5 2005/06/14 21:19:19 joerg Exp $
35 * last edit-date: [Fri Jun 2 14:32:19 2000]
37 *---------------------------------------------------------------------------*/
39 #include "use_i4bq931.h"
43 #include <sys/param.h>
44 #include <sys/systm.h>
47 #include <net/i4b/include/machine/i4b_debug.h>
48 #include <net/i4b/include/machine/i4b_ioctl.h>
49 #include <net/i4b/include/machine/i4b_cause.h>
51 #include "../include/i4b_l2l3.h"
52 #include "../include/i4b_l3l4.h"
53 #include "../include/i4b_global.h"
56 #include "i4b_l3fsm.h"
58 #include "../layer4/i4b_l4.h"
60 extern void isic_settrace(int unit, int val); /*XXX*/
61 extern int isic_gettrace(int unit); /*XXX*/
63 static void n_connect_request(u_int cdid);
64 static void n_connect_response(u_int cdid, int response, int cause);
65 static void n_disconnect_request(u_int cdid, int cause);
66 static void n_alert_request(u_int cdid);
67 static void n_mgmt_command(int unit, int cmd, void *parm);
69 /*---------------------------------------------------------------------------*
70 * i4b_mdl_status_ind - status indication from lower layers
71 *---------------------------------------------------------------------------*/
73 i4b_mdl_status_ind(int unit, int status, int parm)
78 NDBGL3(L3_MSG, "unit = %d, status = %d, parm = %d", unit, status, parm);
83 NDBGL3(L3_MSG, "STI_ATTACH: attaching unit %d to controller %d", unit, nctrl);
85 /* init function pointers */
87 ctrl_desc[nctrl].N_CONNECT_REQUEST = n_connect_request;
88 ctrl_desc[nctrl].N_CONNECT_RESPONSE = n_connect_response;
89 ctrl_desc[nctrl].N_DISCONNECT_REQUEST = n_disconnect_request;
90 ctrl_desc[nctrl].N_ALERT_REQUEST = n_alert_request;
91 ctrl_desc[nctrl].N_DOWNLOAD = NULL; /* only used by active cards */
92 ctrl_desc[nctrl].N_DIAGNOSTICS = NULL; /* only used by active cards */
93 ctrl_desc[nctrl].N_MGMT_COMMAND = n_mgmt_command;
95 /* init type and unit */
97 ctrl_desc[nctrl].unit = unit;
98 ctrl_desc[nctrl].ctrl_type = CTRL_PASSIVE;
99 ctrl_desc[nctrl].card_type = parm;
103 ctrl_desc[nctrl].dl_est = DL_DOWN;
104 ctrl_desc[nctrl].nbch = 2; /* XXX extra param? */
105 for (i = 0; i < ctrl_desc[nctrl].nbch; i++)
106 ctrl_desc[nctrl].bch_state[i] = BCH_ST_FREE;
108 ctrl_desc[nctrl].tei = -1;
110 /* init unit to controller table */
112 utoc_tab[unit] = nctrl;
114 /* increment no. of controllers */
121 i4b_l4_l12stat(unit, 1, parm);
122 NDBGL3(L3_MSG, "STI_L1STAT: unit %d layer 1 = %s", unit, status ? "up" : "down");
126 i4b_l4_l12stat(unit, 2, parm);
127 NDBGL3(L3_MSG, "STI_L2STAT: unit %d layer 2 = %s", unit, status ? "up" : "down");
131 ctrl_desc[unit].tei = parm;
132 i4b_l4_teiasg(unit, parm);
133 NDBGL3(L3_MSG, "STI_TEIASG: unit %d TEI = %d = 0x%02x", unit, parm, parm);
136 case STI_PDEACT: /* L1 T4 timeout */
137 NDBGL3(L3_ERR, "STI_PDEACT: unit %d TEI = %d = 0x%02x", unit, parm, parm);
141 for(i=0; i < N_CALL_DESC; i++)
143 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
144 (ctrl_desc[call_desc[i].controller].unit == unit))
146 i4b_l3_stop_all_timers(&(call_desc[i]));
147 if(call_desc[i].cdid != CDID_UNUSED)
152 ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
153 for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
154 ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
155 ctrl_desc[utoc_tab[unit]].tei = -1;
159 i4b_l4_pdeact(unit, sendup);
160 call_desc[i].cdid = CDID_UNUSED;
164 case STI_NOL1ACC: /* no outgoing access to S0 */
165 NDBGL3(L3_ERR, "STI_NOL1ACC: unit %d no outgoing access to S0", unit);
167 for(i=0; i < N_CALL_DESC; i++)
169 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
170 (ctrl_desc[call_desc[i].controller].unit == unit))
172 if(call_desc[i].cdid != CDID_UNUSED)
174 SET_CAUSE_TYPE(call_desc[i].cause_in, CAUSET_I4B);
175 SET_CAUSE_VAL(call_desc[i].cause_in, CAUSE_I4B_L1ERROR);
176 i4b_l4_disconnect_ind(&(call_desc[i]));
181 ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
182 for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
183 ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
184 ctrl_desc[utoc_tab[unit]].tei = -1;
188 NDBGL3(L3_ERR, "ERROR, unit %d, unknown status value %d!", unit, status);
194 /*---------------------------------------------------------------------------*
195 * send command to the lower layers
196 *---------------------------------------------------------------------------*/
198 n_mgmt_command(int unit, int cmd, void *parm)
205 NDBGL3(L3_MSG, "CMR_DOPEN for unit %d", unit);
207 for(i=0; i < N_CALL_DESC; i++)
209 if( (ctrl_desc[call_desc[i].controller].ctrl_type == CTRL_PASSIVE) &&
210 (ctrl_desc[call_desc[i].controller].unit == unit))
212 call_desc[i].cdid = CDID_UNUSED;
216 ctrl_desc[utoc_tab[unit]].dl_est = DL_DOWN;
217 for (i = 0; i < ctrl_desc[utoc_tab[unit]].nbch; i++)
218 ctrl_desc[utoc_tab[unit]].bch_state[i] = BCH_ST_FREE;
219 ctrl_desc[utoc_tab[unit]].tei = -1;
223 NDBGL3(L3_MSG, "CMR_DCLOSE for unit %d", unit);
227 NDBGL3(L3_MSG, "CMR_SETTRACE for unit %d", unit);
231 NDBGL3(L3_MSG, "unknown cmd %d for unit %d", cmd, unit);
235 MDL_Command_Req(unit, cmd, parm);
239 /*---------------------------------------------------------------------------*
240 * handle connect request message from userland
241 *---------------------------------------------------------------------------*/
243 n_connect_request(u_int cdid)
247 cd = cd_by_cdid(cdid);
249 next_l3state(cd, EV_SETUPRQ);
252 /*---------------------------------------------------------------------------*
253 * handle setup response message from userland
254 *---------------------------------------------------------------------------*/
256 n_connect_response(u_int cdid, int response, int cause)
261 cd = cd_by_cdid(cdid);
265 cd->response = response;
266 cd->cause_out = cause;
270 case SETUP_RESP_ACCEPT:
271 next_l3state(cd, EV_SETACRS);
272 chstate = BCH_ST_USED;
275 case SETUP_RESP_REJECT:
276 next_l3state(cd, EV_SETRJRS);
277 chstate = BCH_ST_FREE;
280 case SETUP_RESP_DNTCRE:
281 next_l3state(cd, EV_SETDCRS);
282 chstate = BCH_ST_FREE;
285 default: /* failsafe */
286 next_l3state(cd, EV_SETDCRS);
287 chstate = BCH_ST_FREE;
288 NDBGL3(L3_ERR, "unknown response, doing SETUP_RESP_DNTCRE");
292 if((cd->channelid >= 0) && (cd->channelid < ctrl_desc[cd->controller].nbch))
294 ctrl_desc[cd->controller].bch_state[cd->channelid] = chstate;
298 NDBGL3(L3_MSG, "Warning, invalid channelid %d, response = %d\n", cd->channelid, response);
302 /*---------------------------------------------------------------------------*
303 * handle disconnect request message from userland
304 *---------------------------------------------------------------------------*/
306 n_disconnect_request(u_int cdid, int cause)
310 cd = cd_by_cdid(cdid);
312 cd->cause_out = cause;
314 next_l3state(cd, EV_DISCRQ);
317 /*---------------------------------------------------------------------------*
318 * handle alert request message from userland
319 *---------------------------------------------------------------------------*/
321 n_alert_request(u_int cdid)
325 cd = cd_by_cdid(cdid);
327 next_l3state(cd, EV_ALERTRQ);
330 #endif /* NI4BQ931 > 0 */