Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wtp_init_states.def
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * wtp_init_state.h: Macro calls for implementing wtp initiator state tables
59  * See documentation for guidance how to use and update these.
60  *
61  * Only classes 0 and 1 are implemented. State NULL is called INITIATOR_NULL_
62  * STATE. 1 in the action field means that action is unconditional.
63  *
64  * Class 0 service is here a stateless invoke message (used for disconnection
65  * or unconfirmed push).
66  *
67  * Basic class 1 transaction, without timers, is following:
68  * - initiator sends an invoke message to the responder
69  * - responder acknowledges it, with an pdu with tid verification
70  * off (if it is on, we have a tid verification transaction,
71  * see below).
72  *
73  * Retransmission until acknowledgement is implemented using timers and
74  * retransmission counters. When the initiator sends an invoke it starts a
75  * timer. When it expires, it resends the packet (either ack or invoke), until
76  * counter reaches the maximum value. Then the transaction is aborted.
77  *
78  * If user acknowledgement is on, timers have different values.
79  *
80  * When the initiator aborts the transaction, it sends an abort pdu. When the
81  * responder does it, the initiator wtp user is indicated.
82  *
83  * Tid verification in the initiator means answering the question posed by the
84  * responder: "Have you an outstanding transaction having this tid". If we do
85  * not have it, we have already, before feeding the event into the state
86  * machine, sent an abort with reason INVALIDTID. So here we answer to an
87  * ack pdu with tidve-flag set with an ack pdu with tidok-flag set. See WTP
88  * 5.6, table 2; WTP 8.9; WTP 9.3.4.1.
89  *
90  * By Aarno Syvšnen for Wapit Ltd.
91  */
92 
93 INIT_STATE_NAME(INITIATOR_NULL_STATE)
94 INIT_STATE_NAME(INITIATOR_RESULT_WAIT)
95 
96 /*
97  * We do not use transaction class 2 here: Server is initiator only when it is
98  * pushing (class 1 or class 0) or disconnecting (class 0). First and second
99  * rows are similar, with exception of timer period.
100  */
101 ROW(INITIATOR_NULL_STATE,
102  TR_Invoke_Req,
103  event->u.TR_Invoke_Req.tcl == 1,
104  {
105  WAPEvent *invoke;
106 /*
107  * A special counter is used for storing value used (1) for tidnew flag when
108  * restarting (See WTP 8.8.3.2)
109  */
110  init_machine->tidnew = tidnew;
111 
112  wap_event_destroy(init_machine->invoke);
113  init_machine->rid = 0;
114  init_machine->rcr = 0;
115 
116  invoke = wtp_pack_invoke(init_machine, event);
117  init_machine->invoke = wap_event_duplicate(invoke);
118  dispatch_to_wdp(invoke);
119  init_machine->rid = 1;
120 /*
121  * Turn the tidnew-flag off if it was on. (This can happen when tid was
122  * wrapped or when we are restarting, see WTP 8.8.3.2)
123  */
124  if (init_machine->tidnew) {
125  init_machine->tidnew = 0;
126  tidnew = 0;
127  }
128  init_machine->u_ack = event->u.TR_Invoke_Req.up_flag;
129  init_machine->rcr = 0;
130  start_initiator_timer_R(init_machine);
131  },
132  INITIATOR_RESULT_WAIT)
133 
134 /*
135  * No need to turn tidnew flag when sending class 0 message; tid validation is
136  * not invoked in this case.
137  */
138 ROW(INITIATOR_NULL_STATE,
139  TR_Invoke_Req,
140  event->u.TR_Invoke_Req.tcl == 0,
141  {
142  WAPEvent *invoke;
143 
144  wap_event_destroy(init_machine->invoke);
145  invoke = wtp_pack_invoke(init_machine, event);
146  init_machine->invoke = wap_event_duplicate(invoke);
147  dispatch_to_wdp(invoke);
148  },
149  INITIATOR_NULL_STATE)
150 
151 ROW(INITIATOR_RESULT_WAIT,
152  TR_Abort_Req,
153  1,
154  {
155  send_abort(init_machine, USER, event->u.TR_Abort_Req.abort_reason);
156  },
157  INITIATOR_NULL_STATE)
158 
159 /*
160  * Neither we check transaction class here: this can only be acknowledgement of
161  * class 1 transaction.
162  */
163 ROW(INITIATOR_RESULT_WAIT,
164  RcvAck,
165  event->u.RcvAck.tid_ok == 0,
166  {
167  stop_initiator_timer(init_machine->timer);
168 
169  wsp_event = create_tr_invoke_cnf(init_machine);
170  dispatch_to_wsp(wsp_event);
171  },
172  INITIATOR_NULL_STATE)
173 
174 /*
175  * This is a positive answer to a tid verification (negative one being
176  * already sent by init_machine_find_or_create).
177  */
178 ROW(INITIATOR_RESULT_WAIT,
179  RcvAck,
180  event->u.RcvAck.tid_ok == 1 && init_machine->rcr < MAX_RCR,
181  {
182  send_ack(init_machine, TID_VERIFICATION, init_machine->rid);
183  init_machine->tidok_sent = 1;
184 
185  ++init_machine->rcr;
186 
187  start_initiator_timer_R(init_machine);
188  },
189  INITIATOR_RESULT_WAIT)
190 
191 /*
192  * RCR must not be greater than RCR_MAX. One of corrections from MOT_WTP_CR_01.
193  */
194  ROW(INITIATOR_RESULT_WAIT,
195  RcvAck,
196  event->u.RcvAck.tid_ok,
197  { },
198  INITIATOR_RESULT_WAIT)
199 
200 ROW(INITIATOR_RESULT_WAIT,
201  RcvAbort,
202  1,
203  {
204  wsp_event = create_tr_abort_ind(init_machine,
205  event->u.RcvAbort.abort_reason);
206  dispatch_to_wsp(wsp_event);
207  },
208  INITIATOR_NULL_STATE)
209 
210 ROW(INITIATOR_RESULT_WAIT,
211  RcvErrorPDU,
212  1,
213  {
214  send_abort(init_machine, USER, PROTOERR);
215 
216  wsp_event = create_tr_abort_ind(init_machine, PROTOERR);
217  dispatch_to_wsp(wsp_event);
218  },
219  INITIATOR_NULL_STATE)
220 
221 ROW(INITIATOR_RESULT_WAIT,
222  TimerTO_R,
223  init_machine->rcr < MAX_RCR && !init_machine->tidok_sent,
224  {
225  WAPEvent *resend;
226 
227  ++init_machine->rcr;
228 
229  start_initiator_timer_R(init_machine);
230 
231  resend = wap_event_duplicate(init_machine->invoke);
232  wtp_pack_set_rid(resend, init_machine->rid);
233  dispatch_to_wdp(resend);
234  },
235  INITIATOR_RESULT_WAIT)
236 
237 ROW(INITIATOR_RESULT_WAIT,
238  TimerTO_R,
239  init_machine->rcr < MAX_RCR && init_machine->tidok_sent,
240  {
241  ++init_machine->rcr;
242 
243  start_initiator_timer_R(init_machine);
244 
245  send_ack(init_machine, TID_VERIFICATION, init_machine->tidok_sent);
246  },
247  INITIATOR_RESULT_WAIT)
248 
249 ROW(INITIATOR_RESULT_WAIT,
250  TimerTO_R,
251  init_machine->rcr == MAX_RCR,
252  {
253  wsp_event = create_tr_abort_ind(init_machine, NORESPONSE);
254  dispatch_to_wsp(wsp_event);
255  },
256  INITIATOR_NULL_STATE)
257 
258 #undef ROW
259 #undef INIT_STATE_NAME
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.