2 * DSS.1 Finite State Machine
3 * base: ITU-T Rec Q.931
5 * Copyright (C) 1996 Universidade de Lisboa
7 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
9 * This software may be used and distributed according to the terms of
10 * the GNU General Public License, incorporated herein by reference.
14 * TODO: complete the FSM
15 * move state/event descriptions to a user space logger
18 #include <linux/sched.h>
19 #include <linux/string.h>
20 #include <linux/kernel.h>
22 #include <linux/types.h>
23 #include <linux/slab.h>
25 #include <linux/skbuff.h>
27 #include <linux/timer.h>
30 #include <linux/isdnif.h>
35 #include "callbacks.h"
38 char * isdn_state_table
[] = {
42 "Outgoing call proceeding",
48 "Incoming call proceeding",
51 "Disconnect indication",
65 "Select protocol on B-Channel",
66 "Activate B-channel protocol"
75 {0x01,"Unallocated (unassigned) number"},
76 {0x02,"No route to specified transit network"},
77 {0x03,"No route to destination"},
78 {0x04,"Send special information tone"},
79 {0x05,"Misdialled trunk prefix"},
80 {0x06,"Channel unacceptable"},
81 {0x07,"Channel awarded and being delivered in an established channel"},
83 {0x09,"Preemption - circuit reserved for reuse"},
84 {0x10,"Normal call clearing"},
86 {0x12,"No user responding"},
87 {0x13,"No answer from user (user alerted)"},
88 {0x14,"Subscriber absent"},
89 {0x15,"Call rejected"},
90 {0x16,"Number changed"},
91 {0x1a,"non-selected user clearing"},
92 {0x1b,"Destination out of order"},
93 {0x1c,"Invalid number format (address incomplete)"},
94 {0x1d,"Facility rejected"},
95 {0x1e,"Response to Status enquiry"},
96 {0x1f,"Normal, unspecified"},
97 {0x22,"No circuit/channel available"},
98 {0x26,"Network out of order"},
99 {0x27,"Permanent frame mode connection out-of-service"},
100 {0x28,"Permanent frame mode connection operational"},
101 {0x29,"Temporary failure"},
102 {0x2a,"Switching equipment congestion"},
103 {0x2b,"Access information discarded"},
104 {0x2c,"Requested circuit/channel not available"},
105 {0x2e,"Precedence call blocked"},
106 {0x2f,"Resource unavailable, unspecified"},
107 {0x31,"Quality of service unavailable"},
108 {0x32,"Requested facility not subscribed"},
109 {0x35,"Outgoing calls barred within CUG"},
110 {0x37,"Incoming calls barred within CUG"},
111 {0x39,"Bearer capability not authorized"},
112 {0x3a,"Bearer capability not presently available"},
113 {0x3e,"Inconsistency in designated outgoing access information and subscriber class"},
114 {0x3f,"Service or option not available, unspecified"},
115 {0x41,"Bearer capability not implemented"},
116 {0x42,"Channel type not implemented"},
117 {0x43,"Requested facility not implemented"},
118 {0x44,"Only restricted digital information bearer capability is available"},
119 {0x4f,"Service or option not implemented"},
120 {0x51,"Invalid call reference value"},
121 {0x52,"Identified channel does not exist"},
122 {0x53,"A suspended call exists, but this call identity does not"},
123 {0x54,"Call identity in use"},
124 {0x55,"No call suspended"},
125 {0x56,"Call having the requested call identity has been cleared"},
126 {0x57,"User not member of CUG"},
127 {0x58,"Incompatible destination"},
128 {0x5a,"Non-existent CUG"},
129 {0x5b,"Invalid transit network selection"},
130 {0x5f,"Invalid message, unspecified"},
131 {0x60,"Mandatory information element is missing"},
132 {0x61,"Message type non-existent or not implemented"},
133 {0x62,"Message not compatible with call state or message type non-existent or not implemented"},
134 {0x63,"Information element/parameter non-existent or not implemented"},
135 {0x64,"Invalid information element contents"},
136 {0x65,"Message not compatible with call state"},
137 {0x66,"Recovery on timer expiry"},
138 {0x67,"Parameter non-existent or not implemented - passed on"},
139 {0x6e,"Message with unrecognized parameter discarded"},
140 {0x6f,"Protocol error, unspecified"},
141 {0x7f,"Interworking, unspecified"}
146 static struct isdn_event_desc
{
149 } isdn_event_table
[] = {
150 {EV_USR_SETUP_REQ
, "CC->L3: Setup Request"},
151 {EV_USR_SETUP_RESP
, "CC->L3: Setup Response"},
152 {EV_USR_PROCED_REQ
, "CC->L3: Proceeding Request"},
153 {EV_USR_RELEASE_REQ
, "CC->L3: Release Request"},
155 {EV_NET_SETUP
, "NET->TE: setup "},
156 {EV_NET_CALL_PROC
, "NET->TE: call proceeding"},
157 {EV_NET_SETUP_ACK
, "NET->TE: setup acknowledge (more info needed)"},
158 {EV_NET_CONN
, "NET->TE: connect"},
159 {EV_NET_CONN_ACK
, "NET->TE: connect acknowledge"},
160 {EV_NET_DISC
, "NET->TE: disconnect indication"},
161 {EV_NET_RELEASE
, "NET->TE: release"},
162 {EV_NET_RELEASE_COMP
, "NET->TE: release complete"},
163 {EV_NET_SELP_RESP
, "Board: Select B-channel protocol ack"},
164 {EV_NET_ACTV_RESP
, "Board: Activate B-channel protocol ack"},
165 {EV_TIMER
, "Timeout"},
169 char * strisdnevent(ushort ev
)
171 struct isdn_event_desc
* entry
;
173 for (entry
= isdn_event_table
; entry
->ev
; entry
++)
181 * Euro ISDN finite state machine
184 static struct fsm_timer_entry fsm_timers
[] = {
194 static struct fsm_entry fsm_table
[] = {
197 {ST_NULL
, ST_CALL_INIT
, EV_USR_SETUP_REQ
, cb_out_1
},
199 {ST_CALL_INIT
, ST_OVER_SEND
, EV_NET_SETUP_ACK
, cb_notdone
},
200 {ST_CALL_INIT
, ST_CALL_PROC
, EV_NET_CALL_PROC
, NULL
},
201 {ST_CALL_INIT
, ST_NULL
, EV_NET_DISC
, cb_out_2
},
203 {ST_CALL_PROC
, ST_ACTIVE_SELP
, EV_NET_CONN
, cb_out_2
},
204 {ST_CALL_PROC
, ST_NULL
, EV_NET_DISC
, cb_disc_1
},
205 {ST_CALL_PROC
, ST_DISC_REQ
, EV_USR_RELEASE_REQ
, cb_disc_2
},
208 {ST_NULL
, ST_CALL_PRES
, EV_NET_SETUP
, NULL
},
210 {ST_CALL_PRES
, ST_INCM_PROC
, EV_USR_PROCED_REQ
, cb_in_1
},
211 {ST_CALL_PRES
, ST_DISC_REQ
, EV_USR_RELEASE_REQ
, cb_disc_2
},
213 {ST_INCM_PROC
, ST_CONN_REQ
, EV_USR_SETUP_RESP
, cb_in_2
},
214 {ST_INCM_PROC
, ST_DISC_REQ
, EV_USR_RELEASE_REQ
, cb_disc_2
},
216 {ST_CONN_REQ
, ST_ACTIVE_SELP
, EV_NET_CONN_ACK
, cb_in_3
},
219 {ST_ACTIVE
, ST_NULL
, EV_NET_DISC
, cb_disc_1
},
220 {ST_ACTIVE
, ST_DISC_REQ
, EV_USR_RELEASE_REQ
, cb_disc_2
},
221 {ST_ACTIVE
, ST_NULL
, EV_NET_RELEASE
, cb_disc_3
},
225 {ST_DISC_REQ
, ST_NULL
, EV_NET_DISC
, cb_disc_1
},
226 {ST_DISC_REQ
, ST_NULL
, EV_NET_RELEASE
, cb_disc_3
},
228 /* protocol selection */
229 {ST_ACTIVE_SELP
, ST_ACTIVE_ACTV
, EV_NET_SELP_RESP
, cb_selp_1
},
230 {ST_ACTIVE_SELP
, ST_DISC_REQ
, EV_USR_RELEASE_REQ
, cb_disc_2
},
232 {ST_ACTIVE_ACTV
, ST_ACTIVE
, EV_NET_ACTV_RESP
, cb_open
},
233 {ST_ACTIVE_ACTV
, ST_DISC_REQ
, EV_USR_RELEASE_REQ
, cb_disc_2
},
236 {ST_CALL_PROC
, ST_DISC_REQ
, EV_TIMER
, cb_disc_2
},
237 {ST_DISC_REQ
, ST_NULL
, EV_TIMER
, cb_disc_3
},
238 {ST_ACTIVE_SELP
, ST_DISC_REQ
, EV_TIMER
, cb_disc_2
},
239 {ST_ACTIVE_ACTV
, ST_DISC_REQ
, EV_TIMER
, cb_disc_2
},
240 {ST_INCM_PROC
, ST_DISC_REQ
, EV_TIMER
, cb_disc_2
},
241 {ST_CONN_REQ
, ST_CONN_REQ
, EV_TIMER
, cb_in_2
},
247 static void pcbit_fsm_timer(unsigned long data
)
249 struct pcbit_dev
*dev
;
250 struct pcbit_chan
*chan
;
252 chan
= (struct pcbit_chan
*) data
;
254 del_timer(&chan
->fsm_timer
);
255 chan
->fsm_timer
.function
= NULL
;
257 dev
= chan2dev(chan
);
260 printk(KERN_WARNING
"pcbit: timer for unknown device\n");
264 pcbit_fsm_event(dev
, chan
, EV_TIMER
, NULL
);
268 void pcbit_fsm_event(struct pcbit_dev
*dev
, struct pcbit_chan
*chan
,
269 unsigned short event
, struct callb_data
*data
)
271 struct fsm_entry
* action
;
272 struct fsm_timer_entry
*tentry
;
275 spin_lock_irqsave(&dev
->lock
, flags
);
277 for (action
= fsm_table
; action
->init
!= 0xff; action
++)
278 if (action
->init
== chan
->fsm_state
&& action
->event
== event
)
281 if (action
->init
== 0xff) {
283 spin_unlock_irqrestore(&dev
->lock
, flags
);
284 printk(KERN_DEBUG
"fsm error: event %x on state %x\n",
285 event
, chan
->fsm_state
);
289 if (chan
->fsm_timer
.function
) {
290 del_timer(&chan
->fsm_timer
);
291 chan
->fsm_timer
.function
= NULL
;
294 chan
->fsm_state
= action
->final
;
296 pcbit_state_change(dev
, chan
, action
->init
, event
, action
->final
);
298 for (tentry
= fsm_timers
; tentry
->init
!= 0xff; tentry
++)
299 if (tentry
->init
== chan
->fsm_state
)
302 if (tentry
->init
!= 0xff) {
303 init_timer(&chan
->fsm_timer
);
304 chan
->fsm_timer
.function
= &pcbit_fsm_timer
;
305 chan
->fsm_timer
.data
= (ulong
) chan
;
306 chan
->fsm_timer
.expires
= jiffies
+ tentry
->timeout
* HZ
;
307 add_timer(&chan
->fsm_timer
);
310 spin_unlock_irqrestore(&dev
->lock
, flags
);
313 action
->callb(dev
, chan
, data
);