comparison src/g23m-fad/ppp/ppp_caps.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul :
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This modul is part of the entity PPP and implements all
18 | functions to handles the incoming process internal signals as
19 | described in the SDL-documentation (CHAP-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef PPP_CHAPS_C
24 #define PPP_CHAPS_C
25 #endif /* !PPP_CAPS_C */
26
27 #define ENTITY_PPP
28
29 /*==== INCLUDES =============================================================*/
30
31 #include "typedefs.h" /* to get Condat data types */
32 #include "vsi.h" /* to get a lot of macros */
33 #include "macdef.h" /* to get a lot of macros */
34 #include "custom.h" /* to get a lot of macros */
35 #include "gsm.h" /* to get a lot of macros */
36 #include "cnf_ppp.h" /* to get cnf-definitions */
37 #include "mon_ppp.h" /* to get mon-definitions */
38 #include "prim.h" /* to get the definitions of used SAP and directions */
39 #include "dti.h" /* to get the DTILIB definitions */
40 #include "ppp.h" /* to get the global entity definitions */
41
42 #include "ppp_capf.h" /* to get function interface from chap */
43 #include "ppp_arbf.h" /* to get function interface from arb */
44 #include "ppp_ftxs.h" /* to get signal interface from ftx */
45 #include "ppp_arbs.h" /* to get signal interface from arb */
46 #include "ppp_rts.h" /* to get the rt signal interface */
47
48 /*==== CONST ================================================================*/
49
50 /*==== LOCAL VARS ===========================================================*/
51
52 /*==== PRIVATE FUNCTIONS ====================================================*/
53
54 /*==== PUBLIC FUNCTIONS =====================================================*/
55
56
57
58 /*
59 +------------------------------------------------------------------------------
60 | Function : sig_arb_chap_packet_req
61 +------------------------------------------------------------------------------
62 | Description : Handles the internal signal SIG_ARB_CHAP_PACKET_REQ
63 |
64 | Parameters : packet - pointer to a generic data descriptor
65 |
66 +------------------------------------------------------------------------------
67 */
68 GLOBAL void sig_arb_chap_packet_req (T_desc2* packet)
69 {
70
71 T_desc2* temp_desc;
72 UBYTE forward;
73
74 TRACE_ISIG( "sig_arb_chap_packet_req" );
75
76 /*
77 * depend on the code-field call appropriate function
78 */
79 switch(packet->buffer[0])
80 {
81 case CODE_CHALLENGE:
82 chap_rc(&packet, &forward);
83 break;
84 case CODE_RESPONSE:
85 chap_rr(&packet, &forward);
86 break;
87 case CODE_SUCCESS:
88 chap_rs(packet, &forward);
89 break;
90 case CODE_FAILURE:
91 chap_rf(packet, &forward);
92 break;
93 default:
94 forward = FORWARD_DISCARD;
95 break;
96 }
97 switch(forward)
98 {
99 case FORWARD_RC: /* Received Challenge */
100 /*
101 * send Response packet and wait for an appropriate answer
102 */
103 SET_STATE( PPP_SERVICE_CHAP, CHAP_UP );
104 ppp_data->chap.counter = ppp_data->mc;
105 sig_any_ftx_packet_req(DTI_PID_CHAP, packet); /* Response */
106 if(ppp_data->chap.counter > 0)
107 ppp_data->chap.counter--;
108 sig_any_rt_rrt_req();
109 break;
110 case FORWARD_RRP: /* Received Response Positive */
111 /*
112 * send Success packets until receive a stop signal from arb
113 * or the counter becomes zero
114 */
115 SET_STATE( PPP_SERVICE_CHAP, CHAP_UP );
116 ppp_data->chap.counter = ppp_data->mc;
117 sig_any_ftx_packet_req(DTI_PID_CHAP, packet); /* Success */
118 if(ppp_data->chap.counter > 0)
119 ppp_data->chap.counter--;
120 sig_any_rt_rrt_req();
121 sig_any_arb_tlu_ind();
122 break;
123 case FORWARD_RRN: /* Received Response Negative */
124 /*
125 * send Failure packet
126 */
127 sig_any_ftx_packet_req(DTI_PID_CHAP, packet); /* Failure */
128 if(ppp_data->chap.fails > 0)
129 {
130 /*
131 * if failure counter is not zero then create a new Challenge packet
132 */
133 ppp_data->chap.fails--;
134 ppp_data->chap.counter = ppp_data->mc;
135 chap_get_sc(&temp_desc);
136 sig_any_ftx_packet_req(DTI_PID_CHAP, temp_desc); /* Challenge */
137 if(ppp_data->chap.counter > 0)
138 ppp_data->chap.counter--;
139 sig_any_rt_rrt_req();
140 }
141 else
142 {
143 /*
144 * if failure counter expired then set error code
145 */
146 sig_any_rt_srt_req();
147 if(ppp_data->ppp_cause EQ 0)
148 ppp_data->ppp_cause = PPP_TERM_USE_AUTHED_FAILED;
149 sig_any_arb_tlf_ind();
150 }
151 break;
152 case FORWARD_RS: /* Received Success */
153 sig_any_rt_srt_req();
154 sig_any_arb_tlu_ind();
155 break;
156 case FORWARD_RF: /* Received Failure */
157 /*
158 * restart timer and wait for new challenge packet
159 */
160 SET_STATE( PPP_SERVICE_CHAP, CHAP_DOWN );
161 ppp_data->chap.counter = ppp_data->mc;
162 if(ppp_data->chap.counter > 0)
163 ppp_data->chap.counter--;
164 sig_any_rt_rrt_req();
165 break;
166 default:
167 arb_discard_packet(packet);
168 break;
169 }
170 } /* sig_arb_chap_packet_req() */
171
172
173
174 /*
175 +------------------------------------------------------------------------------
176 | Function : sig_arb_chap_open_req
177 +------------------------------------------------------------------------------
178 | Description : Handles the internal signal SIG_ARB_CHAP_OPEN_REQ
179 |
180 | Parameters : no parameters
181 |
182 +------------------------------------------------------------------------------
183 */
184 GLOBAL void sig_arb_chap_open_req ()
185 {
186 T_desc2* packet;
187
188 TRACE_ISIG( "sig_arb_chap_open_req" );
189
190 SET_STATE( PPP_SERVICE_CHAP, CHAP_DOWN );
191 ppp_data->chap.sc = FALSE;
192 ppp_data->chap.counter = ppp_data->mc;
193 ppp_data->chap.fails = ppp_data->mf;
194
195 if(ppp_data->mode EQ PPP_SERVER)
196 {
197 /*
198 * create and send challenge packet
199 */
200 chap_get_sc(&packet);
201 sig_any_ftx_packet_req(DTI_PID_CHAP, packet); /* Challenge */
202 }
203
204 /*
205 * start timer (client and server)
206 */
207 if(ppp_data->chap.counter > 0)
208 ppp_data->chap.counter--;
209 sig_any_rt_rrt_req();
210 } /* sig_arb_chap_open_req() */
211
212
213
214 /*
215 +------------------------------------------------------------------------------
216 | Function : sig_arb_chap_down_req
217 +------------------------------------------------------------------------------
218 | Description : Handles the internal signal SIG_ARB_CHAP_DOWN_REQ
219 |
220 | Parameters : no parameters
221 |
222 +------------------------------------------------------------------------------
223 */
224 GLOBAL void sig_arb_chap_down_req ()
225 {
226 TRACE_ISIG( "sig_arb_chap_down_req" );
227
228 sig_any_rt_srt_req();
229 arb_discard_packet(ppp_data->chap.c_packet);
230 ppp_data->chap.c_packet = NULL;
231 arb_discard_packet(ppp_data->chap.r_packet);
232 ppp_data->chap.r_packet = NULL;
233 } /* sig_arb_chap_down_req() */
234
235
236
237 /*
238 +------------------------------------------------------------------------------
239 | Function : sig_arb_chap_stop_req
240 +------------------------------------------------------------------------------
241 | Description : Handles the internal signal SIG_ARB_CHAP_STOP_REQ
242 |
243 | Parameters : no parameters
244 |
245 +------------------------------------------------------------------------------
246 */
247 GLOBAL void sig_arb_chap_stop_req ()
248 {
249 TRACE_ISIG( "sig_arb_chap_stop_req" );
250
251 sig_any_rt_srt_req();
252 } /* sig_arb_chap_down_req() */
253
254
255
256 /*
257 +------------------------------------------------------------------------------
258 | Function : sig_arb_chap_to_req
259 +------------------------------------------------------------------------------
260 | Description : Handles the internal signal SIG_ARB_CHAP_TO_REQ
261 |
262 | Parameters : no parameters
263 |
264 +------------------------------------------------------------------------------
265 */
266 GLOBAL void sig_arb_chap_to_req ()
267 {
268 T_desc2* packet = NULL;
269
270 TRACE_ISIG( "sig_arb_chap_to_req" );
271
272 if (ppp_data->chap.counter EQ 0)
273 {
274 /*
275 * authentication failed (client and server mode)
276 */
277 if((ppp_data->ppp_cause EQ 0) && (ppp_data->mode EQ PPP_CLIENT))
278 ppp_data->ppp_cause = PPP_TERM_NO_RESPONSE;
279 sig_any_arb_tlf_ind();
280 }
281 else
282 {
283 if(ppp_data->mode EQ PPP_SERVER)
284 {
285 switch( GET_STATE( PPP_SERVICE_CHAP ) )
286 {
287 case CHAP_UP:
288 /*
289 * create Success packet
290 */
291 chap_get_ss(&packet);
292 break;
293 case CHAP_DOWN:
294 /*
295 * create Challenge packet
296 */
297 chap_get_sc(&packet);
298 break;
299 default:
300 TRACE_EVENT("WARNING: unexpected chap time out request in server mode");
301 break;
302 }
303 /*
304 * send packet
305 */
306 sig_any_ftx_packet_req(DTI_PID_CHAP, packet);
307 }
308 else if(ppp_data->mode EQ PPP_CLIENT)
309 {
310 switch( GET_STATE( PPP_SERVICE_CHAP ) )
311 {
312 case CHAP_UP:
313 if(ppp_data->chap.sr)
314 {
315 /*
316 * Retransmit Response packet.
317 */
318 packet = ppp_data->chap.c_packet;
319 chap_get_sr(&packet);
320 /*
321 * Send Response packet.
322 */
323 sig_any_ftx_packet_req(DTI_PID_CHAP, packet);
324 } else {
325 TRACE_EVENT("WARNING: CHAP_UP state, but no Response transmitted");
326 }
327 break;
328 case CHAP_DOWN:
329 /*
330 * Wait for CHAP Challenge,
331 * GET_DATA_REQ will be sent after time out by FTX service.
332 */
333 break;
334 default:
335 TRACE_EVENT("WARNING: unexpected chap time out request in client mode");
336 break;
337 }
338 } else {
339 TRACE_EVENT_P1("ERROR: undefined PPP mode - chap_caps.c (%d)", __LINE__);
340 }
341 /*
342 * restart timer
343 */
344 ppp_data->chap.counter--;
345 sig_any_rt_rrt_req();
346 }
347 } /* sig_arb_chap_to_req() */