FreeCalypso > hg > fc-selenite
comparison src/g23m-fad/ppp/ppp_arbp.c @ 1:d393cd9bb723
src/g23m-*: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:40:46 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:b6a5e36de839 | 1:d393cd9bb723 |
---|---|
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 primitives as described in | |
19 | the SDL-documentation (ARB-statemachine) | |
20 +----------------------------------------------------------------------------- | |
21 */ | |
22 | |
23 #ifndef PPP_ARBP_C | |
24 #define PPP_ARBP_C | |
25 #endif /* !PPP_ARBP_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_rts.h" /* to get signal interface from rt */ | |
43 #include "ppp_ptxs.h" /* to get signal interface from ptx */ | |
44 #include "ppp_ftxs.h" /* to get signal interface from ftx */ | |
45 #include "ppp_arbf.h" /* to get function interface from arb */ | |
46 #include "ppp_lcps.h" /* to get signal interface from lcp */ | |
47 #include "ppp_ncps.h" /* to get signal interface from ncp */ | |
48 #include "ppp_paps.h" /* to get signal interface from pap */ | |
49 #include "ppp_caps.h" /* to get signal interface from chap */ | |
50 | |
51 #include <string.h> /* to get strcmp */ | |
52 #include <stdio.h> /* to get sprintf */ | |
53 | |
54 /*==== CONST ================================================================*/ | |
55 | |
56 /*==== LOCAL VARS ===========================================================*/ | |
57 | |
58 /*==== PRIVATE FUNCTIONS ====================================================*/ | |
59 | |
60 /*==== PUBLIC FUNCTIONS =====================================================*/ | |
61 | |
62 /* | |
63 +------------------------------------------------------------------------------ | |
64 | Function : arb_ppp_establish_req | |
65 +------------------------------------------------------------------------------ | |
66 | Description : Handles the primitive PPP_ESTABLISH_REQ | |
67 | | |
68 | Parameters : *ppp_establish_req - Ptr to primitive payload | |
69 | | |
70 +------------------------------------------------------------------------------ | |
71 */ | |
72 GLOBAL void arb_ppp_establish_req ( T_PPP_ESTABLISH_REQ *ppp_establish_req ) | |
73 { | |
74 UBYTE open_channel=0; | |
75 TRACE_FUNCTION( "arb_ppp_establish_req" ); | |
76 | |
77 /* | |
78 * Open the DTI channels. Poll - because the VSI channel | |
79 * may not be ready at once. | |
80 */ | |
81 switch( GET_STATE( PPP_SERVICE_ARB ) ) | |
82 { | |
83 case ARB_DEAD: | |
84 ppp_data->ppp_cause = 0; | |
85 ppp_data->mode = ppp_establish_req->mode; | |
86 ppp_data->mru = ppp_establish_req->mru; | |
87 | |
88 switch(ppp_data->mode) | |
89 { | |
90 case PPP_TRANSPARENT: | |
91 break; | |
92 | |
93 case PPP_SERVER: | |
94 ppp_data->mc=ppp_establish_req->mc; | |
95 ppp_data->mt=ppp_establish_req->mt; | |
96 ppp_data->mf=ppp_establish_req->mf; | |
97 sig_arb_rt_parameters_req(ppp_establish_req->rt); | |
98 sig_arb_lcp_parameters_req(ppp_establish_req->mru, | |
99 ppp_establish_req->ap, | |
100 ppp_establish_req->accm); | |
101 sig_arb_ftx_blocked_mode_req(); | |
102 sig_arb_ptx_blocked_mode_req(); | |
103 break; | |
104 | |
105 case PPP_CLIENT: | |
106 ppp_data->mc=ppp_establish_req->mc; | |
107 ppp_data->mt=ppp_establish_req->mt; | |
108 ppp_data->mf=ppp_establish_req->mf; | |
109 sig_arb_rt_parameters_req(ppp_establish_req->rt); | |
110 sig_arb_lcp_parameters_req(ppp_establish_req->mru, | |
111 ppp_establish_req->ap, | |
112 ppp_establish_req->accm); | |
113 /* login information for authentication for PAP or CHAP */ | |
114 ppp_data->login = ppp_establish_req->login; | |
115 sig_arb_ncp_parameters_req(ppp_establish_req->ppp_hc, | |
116 PPP_MSID_DEFAULT, | |
117 ppp_establish_req->ip, | |
118 ppp_establish_req->dns1, | |
119 ppp_establish_req->dns2, | |
120 PPP_GATEWAY_DEFAULT); | |
121 sig_arb_ftx_blocked_mode_req(); | |
122 sig_arb_ptx_blocked_mode_req(); | |
123 break; | |
124 | |
125 default: | |
126 TRACE_ERROR( "PPP_ESTABLISH_REQ with invalid parameter: mode" ); | |
127 break; | |
128 } | |
129 break; | |
130 default: | |
131 TRACE_ERROR( "PPP_ESTABLISH_REQ unexpected" ); | |
132 break; | |
133 } /* switch */ | |
134 | |
135 while ((dti_open( | |
136 ppp_data->ppphDTI, | |
137 PPP_INSTANCE, | |
138 PROT_LAYER, | |
139 PROT_CHANNEL, | |
140 PTX_QUEUE_SIZE, | |
141 ppp_establish_req->prot_direction, | |
142 DTI_QUEUE_WATERMARK, | |
143 DTI_VERSION_10, | |
144 ppp_establish_req->protocol_channel.protocol_entity, | |
145 ppp_establish_req->prot_link_id | |
146 ) EQ FALSE) && (open_channel < MAX_TRIES_OPEN_VSI_CHAN)) | |
147 { | |
148 TRACE_EVENT("Problem to connect VSI channel to prot layer"); | |
149 open_channel++; | |
150 } | |
151 | |
152 if(open_channel < MAX_TRIES_OPEN_VSI_CHAN) | |
153 { | |
154 open_channel=0; | |
155 | |
156 while ((dti_open( | |
157 ppp_data->ppphDTI, | |
158 PPP_INSTANCE, | |
159 PEER_LAYER, | |
160 PEER_CHANNEL, | |
161 FTX_QUEUE_SIZE, | |
162 ppp_establish_req->peer_direction, | |
163 DTI_QUEUE_WATERMARK, | |
164 DTI_VERSION_10, | |
165 ppp_establish_req->peer_channel.peer_entity, | |
166 ppp_establish_req->peer_link_id | |
167 ) EQ FALSE) && (open_channel < MAX_TRIES_OPEN_VSI_CHAN)) | |
168 { | |
169 TRACE_EVENT("Problem to connect VSI channel to peer layer"); | |
170 open_channel++; | |
171 } | |
172 } | |
173 | |
174 /* | |
175 * Do nothing if VSI communication channels not opened | |
176 */ | |
177 | |
178 if(open_channel >= MAX_TRIES_OPEN_VSI_CHAN) | |
179 { | |
180 PALLOC (ppp_terminate_ind, PPP_TERMINATE_IND); | |
181 SET_STATE( PPP_SERVICE_ARB, ARB_DEAD ); | |
182 sig_arb_ncp_down_req(); | |
183 sig_arb_pap_down_req(); | |
184 sig_arb_chap_down_req(); | |
185 sig_arb_lcp_down_req(); | |
186 sig_arb_ptx_dead_mode_req(); | |
187 sig_arb_ftx_dead_mode_req(); | |
188 arb_dti_close_prot_ind(); | |
189 arb_dti_close_peer_ind(); | |
190 | |
191 /* | |
192 * set error code | |
193 */ | |
194 ppp_data->ppp_cause = PPP_TERM_NO_CHANNEL; | |
195 ppp_terminate_ind->ppp_cause = ppp_data->ppp_cause; | |
196 PSEND (hCommMMI, ppp_terminate_ind); | |
197 } | |
198 PFREE(ppp_establish_req); | |
199 } /* arb_ppp_establish_req() */ | |
200 | |
201 /* | |
202 +------------------------------------------------------------------------------ | |
203 | Function : arb_ppp_terminate_req | |
204 +------------------------------------------------------------------------------ | |
205 | Description : Handles the primitive PPP_TERMINATE_REQ | |
206 | | |
207 | Parameters : *ppp_terminate_req - Ptr to primitive payload | |
208 | | |
209 +------------------------------------------------------------------------------ | |
210 */ | |
211 GLOBAL void arb_ppp_terminate_req ( T_PPP_TERMINATE_REQ *ppp_terminate_req ) | |
212 { | |
213 TRACE_FUNCTION( "arb_ppp_terminate_req" ); | |
214 | |
215 TRACE_EVENT( "ACI requested Termination" ); | |
216 | |
217 switch( GET_STATE( PPP_SERVICE_ARB ) ) | |
218 { | |
219 case ARB_PAP_ESTABLISH: | |
220 case ARB_PAP_RECONF: | |
221 SET_STATE( PPP_SERVICE_ARB, ARB_LCP_RECONF ); | |
222 sig_arb_pap_down_req(); | |
223 break; | |
224 case ARB_CHAP_ESTABLISH: | |
225 case ARB_CHAP_RECONF: | |
226 SET_STATE( PPP_SERVICE_ARB, ARB_LCP_RECONF ); | |
227 sig_arb_chap_down_req(); | |
228 break; | |
229 case ARB_PDP_WAIT: | |
230 SET_STATE( PPP_SERVICE_ARB, ARB_LCP_RECONF ); | |
231 sig_any_rt_srt_req(); | |
232 break; | |
233 } | |
234 | |
235 switch( GET_STATE( PPP_SERVICE_ARB ) ) | |
236 { | |
237 case ARB_IP: | |
238 sig_arb_ftx_blocked_mode_req(); | |
239 sig_arb_ptx_blocked_mode_req(); | |
240 case ARB_NCP_ESTABLISH: | |
241 case ARB_NCP_RECONF: | |
242 case ARB_NCP_MOD: | |
243 sig_arb_ncp_down_req(); | |
244 case ARB_PDP_SENT: | |
245 case ARB_DEAD: | |
246 case ARB_LCP_ESTABLISH: | |
247 case ARB_LCP_PDP: | |
248 case ARB_LCP_NCP: | |
249 case ARB_LCP_RECONF: | |
250 case ARB_LCP_MOD: | |
251 if(ppp_data->arb.last_ipcp) | |
252 { | |
253 MFREE_DESC2(ppp_data->arb.last_ipcp); | |
254 ppp_data->arb.last_ipcp = NULL; | |
255 } | |
256 if(ppp_terminate_req->lower_layer EQ PPP_LOWER_LAYER_UP) | |
257 { | |
258 /* | |
259 * inform PPP-peer about termination | |
260 */ | |
261 SET_STATE( PPP_SERVICE_ARB, ARB_LCP_RECONF ); | |
262 /* | |
263 * set error code | |
264 */ | |
265 if(ppp_data->ppp_cause EQ 0) | |
266 ppp_data->ppp_cause = PPP_TERM_OK_MMI; | |
267 sig_arb_lcp_close_req(); | |
268 /* xxxxx close dti?! */ | |
269 } | |
270 else | |
271 { | |
272 /* | |
273 * free all PPP resources and finish | |
274 */ | |
275 PALLOC (ppp_terminate_ind, PPP_TERMINATE_IND); | |
276 SET_STATE( PPP_SERVICE_ARB, ARB_DEAD ); | |
277 sig_arb_ncp_down_req(); | |
278 sig_arb_pap_down_req(); | |
279 sig_arb_chap_down_req(); | |
280 sig_arb_lcp_down_req(); | |
281 sig_arb_ptx_dead_mode_req(); | |
282 sig_arb_ftx_dead_mode_req(); | |
283 arb_dti_close_prot_ind(); | |
284 arb_dti_close_peer_ind(); | |
285 | |
286 /* | |
287 * set error code | |
288 */ | |
289 if(ppp_data->ppp_cause EQ 0) | |
290 ppp_data->ppp_cause = PPP_TERM_OK_MMI; | |
291 ppp_terminate_ind->ppp_cause = ppp_data->ppp_cause; | |
292 PSEND (hCommMMI, ppp_terminate_ind); | |
293 } /* end else */ | |
294 break; | |
295 case ARB_TRANSPARENT: | |
296 { | |
297 PALLOC (ppp_terminate_ind, PPP_TERMINATE_IND); | |
298 SET_STATE( PPP_SERVICE_ARB, ARB_DEAD ); | |
299 sig_arb_ncp_down_req(); | |
300 sig_arb_pap_down_req(); | |
301 sig_arb_chap_down_req(); | |
302 sig_arb_lcp_down_req(); | |
303 sig_arb_ptx_dead_mode_req(); | |
304 sig_arb_ftx_dead_mode_req(); | |
305 | |
306 arb_dti_close_prot_ind(); | |
307 arb_dti_close_peer_ind(); | |
308 | |
309 /* | |
310 * set error code | |
311 */ | |
312 if(ppp_data->ppp_cause EQ 0) | |
313 ppp_data->ppp_cause = PPP_TERM_OK_MMI; | |
314 ppp_terminate_ind->ppp_cause = ppp_data->ppp_cause; | |
315 PSEND (hCommMMI, ppp_terminate_ind); | |
316 } | |
317 break; | |
318 default: | |
319 TRACE_ERROR( "PPP_TERMINATE_REQ unexpected" ); | |
320 break; | |
321 } | |
322 PFREE(ppp_terminate_req); | |
323 | |
324 } /* arb_ppp_terminate_req() */ | |
325 | |
326 | |
327 | |
328 /* | |
329 +------------------------------------------------------------------------------ | |
330 | Function : arb_ppp_pdp_activate_res | |
331 +------------------------------------------------------------------------------ | |
332 | Description : Handles the primitive PPP_PDP_ACTIVATE_RES | |
333 | | |
334 | Parameters : *ppp_pdp_activate_res - Ptr to primitive payload | |
335 | | |
336 +------------------------------------------------------------------------------ | |
337 */ | |
338 GLOBAL void arb_ppp_pdp_activate_res ( T_PPP_PDP_ACTIVATE_RES *ppp_pdp_activate_res ) | |
339 { | |
340 ULONG dns1, dns2, gateway; | |
341 T_desc2* temp_desc; | |
342 | |
343 TRACE_FUNCTION( "arb_ppp_pdp_activate_res" ); | |
344 /* | |
345 * extract DNS addresses | |
346 */ | |
347 arb_analyze_pco_list(&ppp_pdp_activate_res->sdu, &dns1, &dns2, &gateway); | |
348 | |
349 TRACE_EVENT("PDP context activated"); | |
350 TRACE_EVENT_P5("IP: %d.%d.%d.%d (%08x)", | |
351 ((ppp_pdp_activate_res->ip >> 24) & 0x000000ff), | |
352 ((ppp_pdp_activate_res->ip >> 16) & 0x000000ff), | |
353 ((ppp_pdp_activate_res->ip >> 8) & 0x000000ff), | |
354 ( ppp_pdp_activate_res->ip & 0x000000ff), | |
355 ppp_pdp_activate_res->ip); | |
356 if(dns1 NEQ 0) | |
357 { | |
358 TRACE_EVENT_P5("primary DNS: %d.%d.%d.%d (%08x)", | |
359 ((dns1 >> 24) & 0x000000ff), | |
360 ((dns1 >> 16) & 0x000000ff), | |
361 ((dns1 >> 8) & 0x000000ff), | |
362 ( dns1 & 0x000000ff), | |
363 dns1); | |
364 } | |
365 else | |
366 { | |
367 TRACE_EVENT("no primary DNS"); | |
368 } | |
369 if(dns2 NEQ 0) | |
370 { | |
371 TRACE_EVENT_P5("secondary DNS: %d.%d.%d.%d (%08x)", | |
372 ((dns2 >> 24) & 0x000000ff), | |
373 ((dns2 >> 16) & 0x000000ff), | |
374 ((dns2 >> 8) & 0x000000ff), | |
375 ( dns2 & 0x000000ff), | |
376 dns2); | |
377 } | |
378 else | |
379 { | |
380 TRACE_EVENT("no secondary DNS"); | |
381 } | |
382 if(gateway NEQ 0) | |
383 { | |
384 TRACE_EVENT_P5("Gateway: %d.%d.%d.%d (%08x)", | |
385 ((gateway >> 24) & 0x000000ff), | |
386 ((gateway >> 16) & 0x000000ff), | |
387 ((gateway >> 8) & 0x000000ff), | |
388 ( gateway & 0x000000ff), | |
389 gateway); | |
390 } | |
391 else | |
392 { | |
393 TRACE_EVENT("no Gateway"); | |
394 } | |
395 if(ppp_pdp_activate_res->ppp_hc EQ PPP_HC_OFF) | |
396 { | |
397 TRACE_EVENT("do not use header compression"); | |
398 } | |
399 else if(ppp_pdp_activate_res->ppp_hc EQ PPP_HC_VJ) | |
400 { | |
401 TRACE_EVENT("using VJ header compression"); | |
402 } | |
403 /* | |
404 * set ncp parameters | |
405 */ | |
406 sig_arb_ncp_parameters_req(ppp_pdp_activate_res->ppp_hc, | |
407 ppp_pdp_activate_res->msid, | |
408 ppp_pdp_activate_res->ip, | |
409 dns1, | |
410 dns2, | |
411 gateway); | |
412 | |
413 switch( GET_STATE( PPP_SERVICE_ARB ) ) | |
414 { | |
415 case ARB_LCP_PDP: | |
416 SET_STATE( PPP_SERVICE_ARB, ARB_LCP_NCP ); | |
417 break; | |
418 case ARB_PDP_SENT: | |
419 SET_STATE( PPP_SERVICE_ARB, ARB_NCP_ESTABLISH ); | |
420 sig_arb_ncp_open_req(); | |
421 if(ppp_data->arb.last_ipcp) | |
422 { | |
423 temp_desc = ppp_data->arb.last_ipcp; | |
424 ppp_data->arb.last_ipcp = NULL; | |
425 sig_arb_ncp_packet_req(temp_desc); | |
426 } | |
427 break; | |
428 default: | |
429 TRACE_ERROR( "PPP_PDP_ACTIVATE_RES unexpected" ); | |
430 break; | |
431 } | |
432 PFREE(ppp_pdp_activate_res); | |
433 | |
434 } /* arb_ppp_pdp_activate_res() */ | |
435 | |
436 | |
437 | |
438 /* | |
439 +------------------------------------------------------------------------------ | |
440 | Function : arb_ppp_pdp_activate_rej | |
441 +------------------------------------------------------------------------------ | |
442 | Description : Handles the primitive PPP_PDP_ACTIVATE_REJ | |
443 | | |
444 | Parameters : *ppp_pdp_activate_rej - Ptr to primitive payload | |
445 | | |
446 +------------------------------------------------------------------------------ | |
447 */ | |
448 GLOBAL void arb_ppp_pdp_activate_rej ( T_PPP_PDP_ACTIVATE_REJ *ppp_pdp_activate_rej ) | |
449 { | |
450 TRACE_FUNCTION( "arb_ppp_pdp_activate_rej" ); | |
451 | |
452 TRACE_EVENT_P1("PDP context activation rejected by the network (cause=%x)", | |
453 ppp_pdp_activate_rej->ppp_cause); | |
454 /* | |
455 * set error code | |
456 */ | |
457 if(ppp_data->ppp_cause EQ 0) | |
458 ppp_data->ppp_cause = ppp_pdp_activate_rej->ppp_cause; | |
459 | |
460 switch( GET_STATE( PPP_SERVICE_ARB ) ) | |
461 { | |
462 case ARB_PDP_SENT: | |
463 case ARB_LCP_PDP: | |
464 SET_STATE( PPP_SERVICE_ARB, ARB_LCP_ESTABLISH ); | |
465 if(ppp_data->arb.last_ipcp) | |
466 { | |
467 MFREE_DESC2(ppp_data->arb.last_ipcp); | |
468 ppp_data->arb.last_ipcp = NULL; | |
469 } | |
470 sig_arb_lcp_close_req(); | |
471 break; | |
472 default: | |
473 TRACE_ERROR( "PPP_PDP_ACTIVATE_REJ unexpected" ); | |
474 break; | |
475 } | |
476 PFREE(ppp_pdp_activate_rej); | |
477 | |
478 } /* arb_ppp_pdp_activate_rej() */ | |
479 | |
480 | |
481 | |
482 /* | |
483 +------------------------------------------------------------------------------ | |
484 | Function : arb_ppp_modification_req | |
485 +------------------------------------------------------------------------------ | |
486 | Description : Handles the primitive PPP_MODIFICATION_REQ | |
487 | | |
488 | Parameters : *ppp_modification_req - Ptr to primitive payload | |
489 | | |
490 +------------------------------------------------------------------------------ | |
491 */ | |
492 GLOBAL void arb_ppp_modification_req ( T_PPP_MODIFICATION_REQ *ppp_modification_req ) | |
493 { | |
494 TRACE_FUNCTION( "arb_ppp_modification_req" ); | |
495 | |
496 sig_arb_ncp_modify_hc_req(ppp_modification_req->ppp_hc, | |
497 ppp_modification_req->msid); | |
498 | |
499 switch( GET_STATE( PPP_SERVICE_ARB ) ) | |
500 { | |
501 case ARB_LCP_RECONF: | |
502 SET_STATE( PPP_SERVICE_ARB, ARB_LCP_MOD ); | |
503 case ARB_LCP_MOD: | |
504 break; | |
505 case ARB_IP: | |
506 sig_arb_ftx_blocked_mode_req(); | |
507 sig_arb_ptx_blocked_mode_req(); | |
508 case ARB_NCP_RECONF: | |
509 SET_STATE( PPP_SERVICE_ARB, ARB_NCP_MOD ); | |
510 case ARB_NCP_MOD: | |
511 sig_arb_ncp_open_req(); | |
512 break; | |
513 default: | |
514 TRACE_ERROR( "PPP_MODIFICATION_REQ unexpected" ); | |
515 break; | |
516 } | |
517 PFREE(ppp_modification_req); | |
518 | |
519 } /* arb_ppp_modification_req() */ |