blob: b2262ba6f0c9a6b9f5d5b2b82db16a8aecd0d633 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * DSS.1 Finite State Machine
3 * base: ITU-T Rec Q.931
4 *
5 * Copyright (C) 1996 Universidade de Lisboa
Joe Perches475be4d2012-02-19 19:52:38 -08006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
8 *
Joe Perches475be4d2012-02-19 19:52:38 -08009 * This software may be used and distributed according to the terms of
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * the GNU General Public License, incorporated herein by reference.
11 */
12
13/*
14 * TODO: complete the FSM
15 * move state/event descriptions to a user space logger
16 */
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/string.h>
19#include <linux/kernel.h>
20
21#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/mm.h>
23#include <linux/skbuff.h>
24
25#include <linux/timer.h>
26#include <asm/io.h>
27
28#include <linux/isdnif.h>
29
30#include "pcbit.h"
31#include "edss1.h"
32#include "layer2.h"
33#include "callbacks.h"
34
35
Joe Perches6f68ad72010-09-13 18:23:52 +000036const char * const isdn_state_table[] = {
Joe Perches475be4d2012-02-19 19:52:38 -080037 "Closed",
38 "Call initiated",
39 "Overlap sending",
40 "Outgoing call proceeding",
41 "NOT DEFINED",
42 "Call delivered",
43 "Call present",
44 "Call received",
45 "Connect request",
46 "Incoming call proceeding",
47 "Active",
48 "Disconnect request",
49 "Disconnect indication",
50 "NOT DEFINED",
51 "NOT DEFINED",
52 "Suspend request",
53 "NOT DEFINED",
54 "Resume request",
55 "NOT DEFINED",
56 "Release Request",
57 "NOT DEFINED",
58 "NOT DEFINED",
59 "NOT DEFINED",
60 "NOT DEFINED",
61 "NOT DEFINED",
62 "Overlap receiving",
63 "Select protocol on B-Channel",
64 "Activate B-channel protocol"
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
67#ifdef DEBUG_ERRS
68static
69struct CauseValue {
Joe Perches475be4d2012-02-19 19:52:38 -080070 byte nr;
71 char *descr;
72} cvlist[] = {
73 {0x01, "Unallocated (unassigned) number"},
74 {0x02, "No route to specified transit network"},
75 {0x03, "No route to destination"},
76 {0x04, "Send special information tone"},
77 {0x05, "Misdialled trunk prefix"},
78 {0x06, "Channel unacceptable"},
79 {0x07, "Channel awarded and being delivered in an established channel"},
80 {0x08, "Preemption"},
81 {0x09, "Preemption - circuit reserved for reuse"},
82 {0x10, "Normal call clearing"},
83 {0x11, "User busy"},
84 {0x12, "No user responding"},
85 {0x13, "No answer from user (user alerted)"},
86 {0x14, "Subscriber absent"},
87 {0x15, "Call rejected"},
88 {0x16, "Number changed"},
89 {0x1a, "non-selected user clearing"},
90 {0x1b, "Destination out of order"},
91 {0x1c, "Invalid number format (address incomplete)"},
92 {0x1d, "Facility rejected"},
93 {0x1e, "Response to Status enquiry"},
94 {0x1f, "Normal, unspecified"},
95 {0x22, "No circuit/channel available"},
96 {0x26, "Network out of order"},
97 {0x27, "Permanent frame mode connection out-of-service"},
98 {0x28, "Permanent frame mode connection operational"},
99 {0x29, "Temporary failure"},
100 {0x2a, "Switching equipment congestion"},
101 {0x2b, "Access information discarded"},
102 {0x2c, "Requested circuit/channel not available"},
103 {0x2e, "Precedence call blocked"},
104 {0x2f, "Resource unavailable, unspecified"},
105 {0x31, "Quality of service unavailable"},
106 {0x32, "Requested facility not subscribed"},
107 {0x35, "Outgoing calls barred within CUG"},
108 {0x37, "Incoming calls barred within CUG"},
109 {0x39, "Bearer capability not authorized"},
110 {0x3a, "Bearer capability not presently available"},
111 {0x3e, "Inconsistency in designated outgoing access information and subscriber class"},
112 {0x3f, "Service or option not available, unspecified"},
113 {0x41, "Bearer capability not implemented"},
114 {0x42, "Channel type not implemented"},
115 {0x43, "Requested facility not implemented"},
116 {0x44, "Only restricted digital information bearer capability is available"},
117 {0x4f, "Service or option not implemented"},
118 {0x51, "Invalid call reference value"},
119 {0x52, "Identified channel does not exist"},
120 {0x53, "A suspended call exists, but this call identity does not"},
121 {0x54, "Call identity in use"},
122 {0x55, "No call suspended"},
123 {0x56, "Call having the requested call identity has been cleared"},
124 {0x57, "User not member of CUG"},
125 {0x58, "Incompatible destination"},
126 {0x5a, "Non-existent CUG"},
127 {0x5b, "Invalid transit network selection"},
128 {0x5f, "Invalid message, unspecified"},
129 {0x60, "Mandatory information element is missing"},
130 {0x61, "Message type non-existent or not implemented"},
131 {0x62, "Message not compatible with call state or message type non-existent or not implemented"},
132 {0x63, "Information element/parameter non-existent or not implemented"},
133 {0x64, "Invalid information element contents"},
134 {0x65, "Message not compatible with call state"},
135 {0x66, "Recovery on timer expiry"},
136 {0x67, "Parameter non-existent or not implemented - passed on"},
137 {0x6e, "Message with unrecognized parameter discarded"},
138 {0x6f, "Protocol error, unspecified"},
139 {0x7f, "Interworking, unspecified"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140};
141
142#endif
143
144static struct isdn_event_desc {
Joe Perches475be4d2012-02-19 19:52:38 -0800145 unsigned short ev;
146 char *desc;
147} isdn_event_table[] = {
148 {EV_USR_SETUP_REQ, "CC->L3: Setup Request"},
149 {EV_USR_SETUP_RESP, "CC->L3: Setup Response"},
150 {EV_USR_PROCED_REQ, "CC->L3: Proceeding Request"},
151 {EV_USR_RELEASE_REQ, "CC->L3: Release Request"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Joe Perches475be4d2012-02-19 19:52:38 -0800153 {EV_NET_SETUP, "NET->TE: setup "},
154 {EV_NET_CALL_PROC, "NET->TE: call proceeding"},
155 {EV_NET_SETUP_ACK, "NET->TE: setup acknowledge (more info needed)"},
156 {EV_NET_CONN, "NET->TE: connect"},
157 {EV_NET_CONN_ACK, "NET->TE: connect acknowledge"},
158 {EV_NET_DISC, "NET->TE: disconnect indication"},
159 {EV_NET_RELEASE, "NET->TE: release"},
160 {EV_NET_RELEASE_COMP, "NET->TE: release complete"},
161 {EV_NET_SELP_RESP, "Board: Select B-channel protocol ack"},
162 {EV_NET_ACTV_RESP, "Board: Activate B-channel protocol ack"},
163 {EV_TIMER, "Timeout"},
164 {0, "NULL"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165};
166
Joe Perches475be4d2012-02-19 19:52:38 -0800167char *strisdnevent(ushort ev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168{
Joe Perches475be4d2012-02-19 19:52:38 -0800169 struct isdn_event_desc *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Joe Perches475be4d2012-02-19 19:52:38 -0800171 for (entry = isdn_event_table; entry->ev; entry++)
172 if (entry->ev == ev)
173 break;
174
175 return entry->desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
178/*
179 * Euro ISDN finite state machine
180 */
181
182static struct fsm_timer_entry fsm_timers[] = {
Joe Perches475be4d2012-02-19 19:52:38 -0800183 {ST_CALL_PROC, 10},
184 {ST_DISC_REQ, 2},
185 {ST_ACTIVE_SELP, 5},
186 {ST_ACTIVE_ACTV, 5},
187 {ST_INCM_PROC, 10},
188 {ST_CONN_REQ, 2},
189 {0xff, 0}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190};
191
192static struct fsm_entry fsm_table[] = {
193/* Connect Phase */
Joe Perches475be4d2012-02-19 19:52:38 -0800194 /* Outgoing */
195 {ST_NULL, ST_CALL_INIT, EV_USR_SETUP_REQ, cb_out_1},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Joe Perches475be4d2012-02-19 19:52:38 -0800197 {ST_CALL_INIT, ST_OVER_SEND, EV_NET_SETUP_ACK, cb_notdone},
198 {ST_CALL_INIT, ST_CALL_PROC, EV_NET_CALL_PROC, NULL},
199 {ST_CALL_INIT, ST_NULL, EV_NET_DISC, cb_out_2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Joe Perches475be4d2012-02-19 19:52:38 -0800201 {ST_CALL_PROC, ST_ACTIVE_SELP, EV_NET_CONN, cb_out_2},
202 {ST_CALL_PROC, ST_NULL, EV_NET_DISC, cb_disc_1},
203 {ST_CALL_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Joe Perches475be4d2012-02-19 19:52:38 -0800205 /* Incoming */
206 {ST_NULL, ST_CALL_PRES, EV_NET_SETUP, NULL},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Joe Perches475be4d2012-02-19 19:52:38 -0800208 {ST_CALL_PRES, ST_INCM_PROC, EV_USR_PROCED_REQ, cb_in_1},
209 {ST_CALL_PRES, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Joe Perches475be4d2012-02-19 19:52:38 -0800211 {ST_INCM_PROC, ST_CONN_REQ, EV_USR_SETUP_RESP, cb_in_2},
212 {ST_INCM_PROC, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Joe Perches475be4d2012-02-19 19:52:38 -0800214 {ST_CONN_REQ, ST_ACTIVE_SELP, EV_NET_CONN_ACK, cb_in_3},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Joe Perches475be4d2012-02-19 19:52:38 -0800216 /* Active */
217 {ST_ACTIVE, ST_NULL, EV_NET_DISC, cb_disc_1},
218 {ST_ACTIVE, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
219 {ST_ACTIVE, ST_NULL, EV_NET_RELEASE, cb_disc_3},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Joe Perches475be4d2012-02-19 19:52:38 -0800221 /* Disconnect */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Joe Perches475be4d2012-02-19 19:52:38 -0800223 {ST_DISC_REQ, ST_NULL, EV_NET_DISC, cb_disc_1},
224 {ST_DISC_REQ, ST_NULL, EV_NET_RELEASE, cb_disc_3},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Joe Perches475be4d2012-02-19 19:52:38 -0800226 /* protocol selection */
227 {ST_ACTIVE_SELP, ST_ACTIVE_ACTV, EV_NET_SELP_RESP, cb_selp_1},
228 {ST_ACTIVE_SELP, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Joe Perches475be4d2012-02-19 19:52:38 -0800230 {ST_ACTIVE_ACTV, ST_ACTIVE, EV_NET_ACTV_RESP, cb_open},
231 {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_USR_RELEASE_REQ, cb_disc_2},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Joe Perches475be4d2012-02-19 19:52:38 -0800233 /* Timers */
234 {ST_CALL_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
235 {ST_DISC_REQ, ST_NULL, EV_TIMER, cb_disc_3},
236 {ST_ACTIVE_SELP, ST_DISC_REQ, EV_TIMER, cb_disc_2},
237 {ST_ACTIVE_ACTV, ST_DISC_REQ, EV_TIMER, cb_disc_2},
238 {ST_INCM_PROC, ST_DISC_REQ, EV_TIMER, cb_disc_2},
239 {ST_CONN_REQ, ST_CONN_REQ, EV_TIMER, cb_in_2},
240
241 {0xff, 0, 0, NULL}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242};
243
244
245static void pcbit_fsm_timer(unsigned long data)
246{
Joe Perches475be4d2012-02-19 19:52:38 -0800247 struct pcbit_dev *dev;
248 struct pcbit_chan *chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Joe Perches475be4d2012-02-19 19:52:38 -0800250 chan = (struct pcbit_chan *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Joe Perches475be4d2012-02-19 19:52:38 -0800252 del_timer(&chan->fsm_timer);
253 chan->fsm_timer.function = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Joe Perches475be4d2012-02-19 19:52:38 -0800255 dev = chan2dev(chan);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Joe Perches475be4d2012-02-19 19:52:38 -0800257 if (dev == NULL) {
258 printk(KERN_WARNING "pcbit: timer for unknown device\n");
259 return;
260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Joe Perches475be4d2012-02-19 19:52:38 -0800262 pcbit_fsm_event(dev, chan, EV_TIMER, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263}
264
265
266void pcbit_fsm_event(struct pcbit_dev *dev, struct pcbit_chan *chan,
Joe Perches475be4d2012-02-19 19:52:38 -0800267 unsigned short event, struct callb_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
Joe Perches475be4d2012-02-19 19:52:38 -0800269 struct fsm_entry *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 struct fsm_timer_entry *tentry;
271 unsigned long flags;
272
273 spin_lock_irqsave(&dev->lock, flags);
274
Joe Perches475be4d2012-02-19 19:52:38 -0800275 for (action = fsm_table; action->init != 0xff; action++)
276 if (action->init == chan->fsm_state && action->event == event)
277 break;
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (action->init == 0xff) {
Joe Perches475be4d2012-02-19 19:52:38 -0800280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 spin_unlock_irqrestore(&dev->lock, flags);
Joe Perches475be4d2012-02-19 19:52:38 -0800282 printk(KERN_DEBUG "fsm error: event %x on state %x\n",
283 event, chan->fsm_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return;
285 }
286
Joe Perches475be4d2012-02-19 19:52:38 -0800287 if (chan->fsm_timer.function) {
288 del_timer(&chan->fsm_timer);
289 chan->fsm_timer.function = NULL;
290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 chan->fsm_state = action->final;
Joe Perches475be4d2012-02-19 19:52:38 -0800293
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 pcbit_state_change(dev, chan, action->init, event, action->final);
295
Joe Perches475be4d2012-02-19 19:52:38 -0800296 for (tentry = fsm_timers; tentry->init != 0xff; tentry++)
297 if (tentry->init == chan->fsm_state)
298 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Joe Perches475be4d2012-02-19 19:52:38 -0800300 if (tentry->init != 0xff) {
301 init_timer(&chan->fsm_timer);
302 chan->fsm_timer.function = &pcbit_fsm_timer;
303 chan->fsm_timer.data = (ulong) chan;
304 chan->fsm_timer.expires = jiffies + tentry->timeout * HZ;
305 add_timer(&chan->fsm_timer);
306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 spin_unlock_irqrestore(&dev->lock, flags);
309
310 if (action->callb)
311 action->callb(dev, chan, data);
312
313}