1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
/*
* Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*---------------------------------------------------------------------------
*
* i4b daemon - controller state support routines
* ----------------------------------------------
*
* $FreeBSD$
*
* last edit-date: [Mon May 10 21:35:55 1999]
*
*---------------------------------------------------------------------------*/
#include "isdnd.h"
/*--------------------------------------------------------------------------*
* init controller state table entry
*--------------------------------------------------------------------------*/
int
init_controller_state(int controller, int ctrl_type, int card_type, int tei)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "init_controller_state: invalid controller number [%d]!", controller);
return(ERROR);
}
/* init controller tab */
if(ctrl_type == CTRL_PASSIVE)
{
if((card_type > CARD_TYPEP_UNK) &&
(card_type <= CARD_TYPEP_MAX))
{
isdn_ctrl_tab[controller].ctrl_type = ctrl_type;
isdn_ctrl_tab[controller].card_type = card_type;
isdn_ctrl_tab[controller].state = CTRL_UP;
isdn_ctrl_tab[controller].stateb1 = CHAN_IDLE;
isdn_ctrl_tab[controller].stateb2 = CHAN_IDLE;
isdn_ctrl_tab[controller].freechans = MAX_CHANCTRL;
isdn_ctrl_tab[controller].tei = tei;
DBGL(DL_RCCF, (log(LL_DBG, "init_controller_state: controller %d is %s",
controller,
name_of_controller(isdn_ctrl_tab[controller].ctrl_type,
isdn_ctrl_tab[controller].card_type))));
}
else
{
log(LL_ERR, "init_controller_state: unknown card type %d", card_type);
return(ERROR);
}
}
else if(ctrl_type == CTRL_DAIC)
{
isdn_ctrl_tab[controller].ctrl_type = ctrl_type;
isdn_ctrl_tab[controller].card_type = card_type;
isdn_ctrl_tab[controller].state = CTRL_DOWN;
isdn_ctrl_tab[controller].stateb1 = CHAN_IDLE;
isdn_ctrl_tab[controller].stateb2 = CHAN_IDLE;
isdn_ctrl_tab[controller].freechans = MAX_CHANCTRL;
isdn_ctrl_tab[controller].tei = -1;
log(LL_DMN, "init_controller_state: controller %d is %s",
controller,
name_of_controller(isdn_ctrl_tab[controller].ctrl_type,
isdn_ctrl_tab[controller].card_type));
}
else if(ctrl_type == CTRL_TINADD)
{
isdn_ctrl_tab[controller].ctrl_type = ctrl_type;
isdn_ctrl_tab[controller].card_type = 0;
isdn_ctrl_tab[controller].state = CTRL_DOWN;
isdn_ctrl_tab[controller].stateb1 = CHAN_IDLE;
isdn_ctrl_tab[controller].stateb2 = CHAN_IDLE;
isdn_ctrl_tab[controller].freechans = MAX_CHANCTRL;
isdn_ctrl_tab[controller].tei = -1;
log(LL_DMN, "init_controller_state: controller %d is %s",
controller,
name_of_controller(isdn_ctrl_tab[controller].ctrl_type,
isdn_ctrl_tab[controller].card_type));
}
else
{
log(LL_ERR, "init_controller_state: unknown controller type %d", ctrl_type);
return(ERROR);
}
return(GOOD);
}
/*--------------------------------------------------------------------------*
* init active controller
*--------------------------------------------------------------------------*/
void
init_active_controller(void)
{
int ret;
int unit = 0;
int controller;
char cmdbuf[MAXPATHLEN+128];
for(controller = 0; controller < ncontroller; controller++)
{
if(isdn_ctrl_tab[controller].ctrl_type == CTRL_TINADD)
{
DBGL(DL_RCCF, (log(LL_DBG, "init_active_controller, tina-dd %d: executing [%s %d]", unit, tinainitprog, unit)));
sprintf(cmdbuf, "%s %d", tinainitprog, unit);
if((ret = system(cmdbuf)) != 0)
{
log(LL_ERR, "init_active_controller, tina-dd %d: %s returned %d!", unit, tinainitprog, ret);
do_exit(1);
}
}
}
}
/*--------------------------------------------------------------------------*
* set controller state to UP/DOWN
*--------------------------------------------------------------------------*/
int
set_controller_state(int controller, int state)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "set_controller_state: invalid controller number [%d]!", controller);
return(ERROR);
}
if(state == CTRL_UP)
{
isdn_ctrl_tab[controller].state = CTRL_UP;
DBGL(DL_CNST, (log(LL_DBG, "set_controller_state: controller [%d] set UP!", controller)));
}
else if (state == CTRL_DOWN)
{
isdn_ctrl_tab[controller].state = CTRL_DOWN;
DBGL(DL_CNST, (log(LL_DBG, "set_controller_state: controller [%d] set DOWN!", controller)));
}
else
{
log(LL_ERR, "set_controller_state: invalid controller state [%d]!", state);
return(ERROR);
}
return(GOOD);
}
/*--------------------------------------------------------------------------*
* get controller state
*--------------------------------------------------------------------------*/
int
get_controller_state(int controller)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "set_controller_state: invalid controller number [%d]!", controller);
return(ERROR);
}
return(isdn_ctrl_tab[controller].state);
}
/*--------------------------------------------------------------------------*
* decrement number of free channels for controller
*--------------------------------------------------------------------------*/
int
decr_free_channels(int controller)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "decr_free_channels: invalid controller number [%d]!", controller);
return(ERROR);
}
if(isdn_ctrl_tab[controller].freechans > 0)
{
(isdn_ctrl_tab[controller].freechans)--;
DBGL(DL_CNST, (log(LL_DBG, "decr_free_channels: ctrl %d, now %d chan free", controller, isdn_ctrl_tab[controller].freechans)));
return(GOOD);
}
else
{
log(LL_ERR, "decr_free_channels: controller [%d] already 0 free chans!", controller);
return(ERROR);
}
}
/*--------------------------------------------------------------------------*
* increment number of free channels for controller
*--------------------------------------------------------------------------*/
int
incr_free_channels(int controller)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "incr_free_channels: invalid controller number [%d]!", controller);
return(ERROR);
}
if(isdn_ctrl_tab[controller].freechans < MAX_CHANCTRL)
{
(isdn_ctrl_tab[controller].freechans)++;
DBGL(DL_CNST, (log(LL_DBG, "incr_free_channels: ctrl %d, now %d chan free", controller, isdn_ctrl_tab[controller].freechans)));
return(GOOD);
}
else
{
log(LL_ERR, "incr_free_channels: controller [%d] already 2 free chans!", controller);
return(ERROR);
}
}
/*--------------------------------------------------------------------------*
* get number of free channels for controller
*--------------------------------------------------------------------------*/
int
get_free_channels(int controller)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "get_free_channels: invalid controller number [%d]!", controller);
return(ERROR);
}
DBGL(DL_CNST, (log(LL_DBG, "get_free_channels: ctrl %d, %d chan free", controller, isdn_ctrl_tab[controller].freechans)));
return(isdn_ctrl_tab[controller].freechans);
}
/*--------------------------------------------------------------------------*
* set channel state to busy
*--------------------------------------------------------------------------*/
int
set_channel_busy(int controller, int channel)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "set_channel_busy: invalid controller number [%d]!", controller);
return(ERROR);
}
switch(channel)
{
case CHAN_B1:
if(isdn_ctrl_tab[controller].stateb1 == CHAN_RUN)
{
DBGL(DL_CNST, (log(LL_DBG, "set_channel_busy: controller [%d] channel B1 already busy!", controller)));
}
else
{
isdn_ctrl_tab[controller].stateb1 = CHAN_RUN;
DBGL(DL_CNST, (log(LL_DBG, "set_channel_busy: controller [%d] channel B1 set to BUSY!", controller)));
}
break;
case CHAN_B2:
if(isdn_ctrl_tab[controller].stateb2 == CHAN_RUN)
{
DBGL(DL_CNST, (log(LL_DBG, "set_channel_busy: controller [%d] channel B2 already busy!", controller)));
}
else
{
isdn_ctrl_tab[controller].stateb2 = CHAN_RUN;
DBGL(DL_CNST, (log(LL_DBG, "set_channel_busy: controller [%d] channel B2 set to BUSY!", controller)));
}
break;
default:
log(LL_ERR, "set_channel_busy: controller [%d], invalid channel [%d]!", controller, channel);
return(ERROR);
break;
}
return(GOOD);
}
/*--------------------------------------------------------------------------*
* set channel state to idle
*--------------------------------------------------------------------------*/
int
set_channel_idle(int controller, int channel)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "set_channel_idle: invalid controller number [%d]!", controller);
return(ERROR);
}
switch(channel)
{
case CHAN_B1:
if(isdn_ctrl_tab[controller].stateb1 == CHAN_IDLE)
{
DBGL(DL_CNST, (log(LL_DBG, "set_channel_idle: controller [%d] channel B1 already idle!", controller)));
}
else
{
isdn_ctrl_tab[controller].stateb1 = CHAN_IDLE;
DBGL(DL_CNST, (log(LL_DBG, "set_channel_idle: controller [%d] channel B1 set to IDLE!", controller)));
}
break;
case CHAN_B2:
if(isdn_ctrl_tab[controller].stateb2 == CHAN_IDLE)
{
DBGL(DL_CNST, (log(LL_DBG, "set_channel_idle: controller [%d] channel B2 already idle!", controller)));
}
else
{
isdn_ctrl_tab[controller].stateb2 = CHAN_IDLE;
DBGL(DL_CNST, (log(LL_DBG, "set_channel_idle: controller [%d] channel B2 set to IDLE!", controller)));
}
break;
default:
DBGL(DL_CNST, (log(LL_DBG, "set_channel_idle: controller [%d], invalid channel [%d]!", controller, channel)));
return(ERROR);
break;
}
return(GOOD);
}
/*--------------------------------------------------------------------------*
* return channel state
*--------------------------------------------------------------------------*/
int
ret_channel_state(int controller, int channel)
{
if((controller < 0) || (controller >= ncontroller))
{
log(LL_ERR, "ret_channel_state: invalid controller number [%d]!", controller);
return(ERROR);
}
switch(channel)
{
case CHAN_B1:
return(isdn_ctrl_tab[controller].stateb1);
break;
case CHAN_B2:
return(isdn_ctrl_tab[controller].stateb2);
break;
default:
log(LL_ERR, "ret_channel_state: controller [%d], invalid channel [%d]!", controller, channel);
return(ERROR);
break;
}
return(ERROR);
}
/* EOF */
|