summaryrefslogtreecommitdiffstats
path: root/drivers/isdn/pcbit/edss1.c
blob: 1ad8b07efd8ba3ab773d501d20eaa5a9e066f0cc (plain)
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
/*
 * DSS.1 Finite State Machine
 * base: ITU-T Rec Q.931
 *
 * Copyright (C) 1996 Universidade de Lisboa
 * 
 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
 *
 * This software may be used and distributed according to the terms of 
 * the GNU General Public License, incorporated herein by reference.
 */

/*
 *        TODO: complete the FSM
 *              move state/event descriptions to a user space logger
 */

#include <linux/sched.h>
#include <linux/string.h>
#include <linux/kernel.h>

#include <linux/types.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/skbuff.h>

#include <linux/timer.h>
#include <asm/io.h>

#include <linux/isdnif.h>

#include "pcbit.h"
#include "edss1.h"
#include "layer2.h"
#include "callbacks.h"


char * isdn_state_table[] = {
  "Closed",
  "Call initiated",
  "Overlap sending",
  "Outgoing call proceeding",
  "NOT DEFINED",
  "Call delivered",
  "Call present",
  "Call received",
  "Connect request",
  "Incoming call proceeding",
  "Active",
  "Disconnect request",
  "Disconnect indication",
  "NOT DEFINED",
  "NOT DEFINED",
  "Suspend request",
  "NOT DEFINED",
  "Resume request",
  "NOT DEFINED",
  "Release Request",
  "NOT DEFINED",
  "NOT DEFINED",
  "NOT DEFINED",
  "NOT DEFINED",
  "NOT DEFINED",
  "Overlap receiving",
  "Select protocol on B-Channel",
  "Activate B-channel protocol"
};

#ifdef DEBUG_ERRS
static
struct CauseValue {
  byte nr;
  char *descr;
} cvlist[]={
  {0x01,"Unallocated (unassigned) number"},
  {0x02,"No route to specified transit network"},
  {0x03,"No route to destination"},
  {0x04,"Send special information tone"},
  {0x05,"Misdialled trunk prefix"},
  {0x06,"Channel unacceptable"},
  {0x07,"Channel awarded and being delivered in an established channel"},
  {0x08,"Preemption"},
  {0x09,"Preemption - circuit reserved for reuse"},
  {0x10,"Normal call clearing"},
  {0x11,"User busy"},
  {0x12,"No user responding"},
  {0x13,"No answer from user (user alerted)"},
  {0x14,"Subscriber absent"},
  {0x15,"Call rejected"},
  {0x16,"Number changed"},
  {0x1a,"non-selected user clearing"},
  {0x1b,"Destination out of order"},
  {0x1c,"Invalid number format (address incomplete)"},
  {0x1d,"Facility rejected"},
  {0x1e,"Response to Status enquiry"},
  {0x1f,"Normal, unspecified"},
  {0x22,"No circuit/channel available"},
  {0x26,"Network out of order"},
  {0x27,"Permanent frame mode connection out-of-service"},
  {0x28,"Permanent frame mode connection operational"},
  {0x29,"Temporary failure"},
  {0x2a,"Switching equipment congestion"},
  {0x2b,"Access information discarded"},
  {0x2c,"Requested circuit/channel not available"},
  {0x2e,"Precedence call blocked"},
  {0x2f,"Resource unavailable, unspecified"},
  {0x31,"Quality of service unavailable"},
  {0x32,"Requested facility not subscribed"},
  {0x35,"Outgoing calls barred within CUG"},
  {0x37,"Incoming calls barred within CUG"},
  {0x39,"Bearer capability not authorized"},
  {0x3a,"Bearer capability not presently available"},
  {0x3e,"Inconsistency in designated outgoing access information and subscriber class"},
  {0x3f,"Service or option not available, unspecified"},
  {0x41,"Bearer capability not implemented"},
  {0x42,"Channel type not implemented"},
  {0x43,"Requested facility not implemented"},
  {0x44,"Only restricted digital information bearer capability is available"},
  {0x4f,"Service or option not implemented"},
  {0x51,"Invalid call reference value"},
  {0x52,"Identified channel does not exist"},
  {0x53,"A suspended call exists, but this call identity does not"},
  {0x54,"Call identity in use"},
  {0x55,"No call suspended"},
  {0x56,"Call having the requested call identity has been cleared"},
  {0x57,"User not member of CUG"},
  {0x58,"Incompatible destination"},
  {0x5a,"Non-existent CUG"},
  {0x5b,"Invalid transit network selection"},
  {0x5f,"Invalid message, unspecified"},
  {0x60,"Mandatory information element is missing"},
  {0x61,"Message type non-existent or not implemented"},
  {0x62,"Message not compatible with call state or message type non-existent or not implemented"},
  {0x63,"Information element/parameter non-existent or not implemented"},
  {0x64,"Invalid information element contents"},
  {0x65,"Message not compatible with call state"},
  {0x66,"Recovery on timer expiry"},
  {0x67,"Parameter non-existent or not implemented - passed on"},
  {0x6e,"Message with unrecognized parameter discarded"},
  {0x6f,"Protocol error, unspecified"},
  {0x7f,"Interworking, unspecified"}
};

#endif

static struct isdn_event_desc {
  unsigned short ev;
  char * desc;
} isdn_event_table [] = {
  {EV_USR_SETUP_REQ,     "CC->L3: Setup Request"},
  {EV_USR_SETUP_RESP,    "CC->L3: Setup Response"},
  {EV_USR_PROCED_REQ,    "CC->L3: Proceeding Request"},
  {EV_USR_RELEASE_REQ,   "CC->L3: Release Request"},

  {EV_NET_SETUP,        "NET->TE: setup "},
  {EV_NET_CALL_PROC,    "NET->TE: call proceeding"},
  {EV_NET_SETUP_ACK,    "NET->TE: setup acknowledge (more info needed)"},
  {EV_NET_CONN,         "NET->TE: connect"},
  {EV_NET_CONN_ACK,     "NET->TE: connect acknowledge"},
  {EV_NET_DISC,         "NET->TE: disconnect indication"},
  {EV_NET_RELEASE,      "NET->TE: release"},
  {EV_NET_RELEASE_COMP, "NET->TE: release complete"},
  {EV_NET_SELP_RESP,    "Board: Select B-channel protocol ack"},
  {EV_NET_ACTV_RESP,    "Board: Activate B-channel protocol ack"},
  {EV_TIMER,            "Timeout"},
  {0, "NULL"}
};

char * strisdnevent(ushort ev)
{
  struct isdn_event_desc * entry;
 
  for (entry = isdn_event_table; entry->ev; entry++)
    if (entry->ev == ev)
      break;

  return entry->desc;
}

/*
 * Euro ISDN finite state machine
 */

static struct fsm_timer_entry fsm_timers[] = {
  {ST_CALL_PROC, 10},
  {ST_DISC_REQ, 2},
  {ST_ACTIVE_SELP, 5},
  {ST_ACTIVE_ACTV, 5},
  {ST_INCM_PROC, 10},
  {ST_CONN_REQ, 2},
  {0xff, 0}
};

static struct fsm_entry fsm_table[] = {
/* Connect Phase */
  /* Outgoing */
  {ST_NULL, ST_CALL_INIT, EV_USR_SETUP_REQ, cb_out_1},

  {ST_CALL_INIT, ST_OVER_SEND, EV_NET_SETUP_ACK, cb_notdone},
  {ST_CALL_INIT, ST_CALL_PROC, EV_NET_CALL_PROC, NULL},
  {ST_CALL_INIT, ST_NULL, EV_NET_DISC, cb_out_2},

  {ST_CALL_PROC, ST_ACTIVE_SELP, EV_NET_CONN, cb_out_2},
  {ST_CALL_PROC, ST_NULL, EV_NET_DISC, cb_disc_1},
  {ST_CALL_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},

  /* Incoming */
  {ST_NULL, ST_CALL_PRES, EV_NET_SETUP, NULL},

  {ST_CALL_PRES, ST_INCM_PROC, EV_USR_PROCED_REQ, cb_in_1},
  {ST_CALL_PRES, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},

  {ST_INCM_PROC, ST_CONN_REQ, EV_USR_SETUP_RESP, cb_in_2},
  {ST_INCM_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},

  {ST_CONN_REQ, ST_ACTIVE_SELP, EV_NET_CONN_ACK, cb_in_3},

  /* Active */
  {ST_ACTIVE, ST_NULL, EV_NET_DISC, cb_disc_1},
  {ST_ACTIVE, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
  {ST_ACTIVE, ST_NULL, EV_NET_RELEASE, cb_disc_3},

  /* Disconnect */

  {ST_DISC_REQ, ST_NULL, EV_NET_DISC, cb_disc_1},
  {ST_DISC_REQ, ST_NULL, EV_NET_RELEASE, cb_disc_3},

  /* protocol selection */
  {ST_ACTIVE_SELP, ST_ACTIVE_ACTV, EV_NET_SELP_RESP, cb_selp_1},
  {ST_ACTIVE_SELP, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},

  {ST_ACTIVE_ACTV, ST_ACTIVE, EV_NET_ACTV_RESP, cb_open},
  {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},

  /* Timers */
  {ST_CALL_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
  {ST_DISC_REQ, ST_NULL, EV_TIMER, cb_disc_3},
  {ST_ACTIVE_SELP, ST_DISC_REQ, EV_TIMER, cb_disc_2},
  {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_TIMER, cb_disc_2},        
  {ST_INCM_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
  {ST_CONN_REQ, ST_CONN_REQ, EV_TIMER, cb_in_2},
        
  {0xff, 0, 0, NULL}
};


static void pcbit_fsm_timer(unsigned long data)
{
        struct pcbit_dev *dev;
        struct pcbit_chan *chan;

        chan = (struct pcbit_chan *) data;

        del_timer(&chan->fsm_timer);
        chan->fsm_timer.function = NULL;

        dev = chan2dev(chan);

        if (dev == NULL) {
                printk(KERN_WARNING "pcbit: timer for unknown device\n");
                return;
        }

        pcbit_fsm_event(dev, chan, EV_TIMER, NULL);
}


void pcbit_fsm_event(struct pcbit_dev *dev, struct pcbit_chan *chan,
		   unsigned short event, struct callb_data *data)
{
	struct fsm_entry * action;	
	struct fsm_timer_entry *tentry;
	unsigned long flags;

	spin_lock_irqsave(&dev->lock, flags);

        for (action = fsm_table; action->init != 0xff; action++)
                if (action->init == chan->fsm_state && action->event == event)
                        break;
  
	if (action->init == 0xff) {
		
		spin_unlock_irqrestore(&dev->lock, flags);
		printk(KERN_DEBUG "fsm error: event %x on state %x\n", 
                       event, chan->fsm_state);
		return;
	}

        if (chan->fsm_timer.function) {
                del_timer(&chan->fsm_timer);
                chan->fsm_timer.function = NULL;
        }

	chan->fsm_state = action->final;
  
	pcbit_state_change(dev, chan, action->init, event, action->final);

        for (tentry = fsm_timers; tentry->init != 0xff; tentry++)
                if (tentry->init == chan->fsm_state)
                        break;

        if (tentry->init != 0xff) {
                init_timer(&chan->fsm_timer);
                chan->fsm_timer.function = &pcbit_fsm_timer;
                chan->fsm_timer.data = (ulong) chan;
                chan->fsm_timer.expires = jiffies + tentry->timeout * HZ;
                add_timer(&chan->fsm_timer);
        }

	spin_unlock_irqrestore(&dev->lock, flags);

	if (action->callb)
		action->callb(dev, chan, data);

}




OpenPOWER on IntegriCloud