comparison src/aci2/aci/cmh_smf.c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
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 module defines the functions used by the command
18 | handler for GPRS session management ( SM ).
19 +-----------------------------------------------------------------------------
20 */
21
22 #if defined (GPRS) && defined (DTI)
23
24 #ifndef CMH_SMF_C
25 #define CMH_SMF_C
26 #endif
27
28 #include "aci_all.h"
29 /*==== INCLUDES ===================================================*/
30 #include "gprs.h"
31
32 #include "dti.h" /* functionality of the dti library */
33 #include "aci_cmh.h"
34 #include "ati_cmd.h"
35 #include "aci_cmd.h"
36 #include "aci_lst.h"
37 #include "aci.h"
38
39 #include "dti_conn_mng.h"
40 #include "dti_cntrl_mng.h"
41
42 #include "gaci.h"
43 #include "gaci_cmh.h"
44 #include "psa.h"
45 #include "psa_gmm.h"
46 #include "psa_sm.h"
47 #include "psa_gppp.h"
48
49 #include "phb.h"
50 #include "cmh.h"
51 #include "cmh_gmm.h"
52
53 #include "cmh_sm.h"
54 #include "cmh_gppp.h"
55 #include "gaci_srcc.h"
56 #include "psa_cc.h"
57
58 #if defined (CO_UDP_IP) || defined (FF_GPF_TCPIP)
59 #include "wap_aci.h"
60 #include "psa_tcpip.h"
61 #include "cmh_ipa.h"
62 #endif /* WAP || FF_GPF_TCPIP OR SAT E */
63
64 #ifdef SIM_TOOLKIT
65 #include "psa_sat.h"
66 #include "cmh_sat.h"
67 #endif
68
69 #include "psa_sim.h"
70 #include "cmh_sim.h"
71
72 #include "cmh_snd.h"
73
74 /* temp needed because of use of ATI functions here: should eventually disappear */
75 #include "ati_int.h"
76
77 #ifdef FF_GPF_TCPIP
78 #include "dcm_utils.h"
79 #include "dcm_state.h"
80 #include "dcm_env.h"
81 #endif
82 #include "dcm_f.h"
83 #include "psa_uart.h"
84
85
86 /*==== CONSTANTS ==================================================*/
87
88 /*==== TYPES ======================================================*/
89 typedef struct
90 {
91 T_CGEREP_EVENT event;
92 T_CGEREP_EVENT_REP_PARAM parm;
93
94 } T_CGERP_EVENT_BUFFER;
95
96 typedef enum
97 {
98 T_CDS_IDLE,
99 T_CDS_RUNNING
100
101 } T_CONTEXTS_DEACTIVATION_STATUS;
102
103 typedef struct
104 {
105 T_CONTEXTS_DEACTIVATION_STATUS state;
106 USHORT nsapi_set;
107 T_ACI_CMD_SRC srcId;
108 USHORT cid_set;
109
110 } T_CONTEXTS_DEACTIVATION_INFORMATION;
111
112
113 /*==== EXPORT =====================================================*/
114
115 /*==== VARIABLES ==================================================*/
116 GLOBAL SHORT nsapi_to_cid[SMH_NSAPI_MAX];
117 static T_CGSMS_SERVICE m_service;
118 static T_CGERP_EVENT_BUFFER gprs_event_buffer[GPRS_EVENT_REPORTING_BUFFER_SIZE];
119 static SHORT gprs_eb_current_p, gprs_eb_oldest_p;
120 static BOOL m_mt_te_link;
121 static BOOL call_waits_in_table;
122 static T_CONTEXTS_DEACTIVATION_INFORMATION working_cgact_actions;
123 /*==== FUNCTIONS ==================================================*/
124
125 /*
126 * functions for ATA and ATH
127 */
128 /* GLOBAL BOOL cmhSM_sAT_H ( T_ACI_CMD_SRC srcId, T_ACI_RETURN *aci_ret ); */
129 /* GLOBAL BOOL cmhSM_sAT_A ( T_ACI_CMD_SRC srcId, T_ACI_RETURN *aci_ret ); */
130 static BOOL cmhSM_sAT_A_H_intern ( T_ACI_CMD_SRC srcId, T_ACI_RETURN *aci_ret, SHORT mode);
131
132 /*
133 * functions for DTI
134 */
135 /* GLOBAL ULONG cmhSM_get_link_id_SNDCP_peer ( SHORT cid, T_SNDCP_PEER which ); */
136 /* GLOBAL BOOL cmhSM_context_deactivated ( USHORT nsapi_set ); */
137
138 /* GLOBAL T_ACI_RETURN cmhSNDCP_Disable( UBYTE dti_id ); */
139
140
141
142 /*
143 +--------------------------------------------------------------------+
144 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
145 | STATE : finished ROUTINE : cmhSM_Init |
146 +--------------------------------------------------------------------+
147
148 PURPOSE : Fill variables for the own use with default values.
149 */
150 GLOBAL void cmhSM_Init (void)
151 {
152 SHORT i = 0;
153
154 /* SM CMH global parameter */
155 smEntStat.curCmd = AT_CMD_NONE;
156 smEntStat.entOwn = OWN_NONE;
157
158 /* GPRS event reporting */
159 memset(gprs_event_buffer, 0, sizeof(T_CGERP_EVENT_BUFFER) * GPRS_EVENT_REPORTING_BUFFER_SIZE);
160 gprs_eb_current_p = 0;
161 gprs_eb_oldest_p = 0;
162
163
164 cmhSM_empty_call_table();
165
166 /* used for network requested context reactivation */
167 call_waits_in_table = FALSE;
168
169 working_cgact_actions.state = T_CDS_IDLE;
170 working_cgact_actions.nsapi_set = 0;
171 working_cgact_actions.srcId = CMD_SRC_NONE;
172 working_cgact_actions.cid_set = 0;
173
174
175 /*
176 * The following command has to be in the init and the reset function!!!
177 *
178 * Set all to zero in init. In the reset function is a contion action to
179 * not equeal zero.
180 */
181 memset(pdp_context,0 , sizeof(T_GPRS_CONT_CLASS) * MAX_CID);
182
183 for (i = 0; i < MAX_CID; i++)
184 {
185 pdp_context[i].link_id_uart = DTI_LINK_ID_NOTPRESENT;
186 pdp_context[i].link_id_new = DTI_LINK_ID_NOTPRESENT;
187 pdp_context[i].link_id_sn = DTI_LINK_ID_NOTPRESENT;
188 }
189
190 m_mt_te_link = FALSE;
191 }
192
193 GLOBAL void cmhSM_ResetNonWorkingContexts( void )
194 {
195 SHORT i = 0, j = 0;
196 UBYTE srcId = srcId_cb;
197 UBYTE gprs_default_pco[] = {
198 0x80,0x80,0x21,0x10,0x01,0x01,0x00,0x10,0x81,0x06,
199 0x00,0x00,0x00,0x00,0x83,0x06,0x00,0x00,0x00,0x00
200 };
201 for (i = 0; i < MAX_CID; i++)
202 {
203 if ( (pdp_context[i].state EQ CS_UNDEFINED) OR (pdp_context[i].state EQ CS_DEFINED) )
204 {
205
206 for (j = 0; j < SMH_NSAPI_MAX; j++)
207 {
208 if ( nsapi_to_cid[j] EQ i + 1 )
209 {
210 nsapi_to_cid[j] = INVALID_CID;
211 }
212 }
213
214 memset(&pdp_context[i], 0, sizeof(T_GPRS_CONT_CLASS));
215
216 pdp_context[i].state = CS_UNDEFINED;
217 pdp_context[i].smreg_ti = UNDEFINED_TI;
218 pdp_context[i].link_id_uart = DTI_LINK_ID_NOTPRESENT;
219 pdp_context[i].link_id_new = DTI_LINK_ID_NOTPRESENT;
220 pdp_context[i].link_id_sn = DTI_LINK_ID_NOTPRESENT;
221
222 pdp_context[i].user_pco.len = sizeof (gprs_default_pco);
223 memcpy (pdp_context[i].user_pco.pco, gprs_default_pco, sizeof (gprs_default_pco));
224 }
225 }
226
227 memset(work_cids, 0, sizeof(SHORT) * MAX_CID_PLUS_EINS);
228 cid_pointer = 0;
229
230 /* set default context parameter */
231 memset(&defaultCtx, 0, sizeof(T_GPRS_CONT_REC));
232 strcpy(defaultCtx.pdp_type,"IP" );
233
234 /* mode of CGAUTO*/
235 automatic_response_mode = 3;
236
237 m_service = CGSMS_SERVICE_CS_PREFERRED;
238
239 /* GPRS event reporting */
240 ati_user_output_cfg[srcId].CGEREP_mode = CGEREP_MODE_BUFFER;
241 ati_user_output_cfg[srcId].CGEREP_bfr = CGEREP_BFR_CLEAR;
242 sm_cgsms_service = CGSMS_SERVICE_CS_PREFERRED;
243 }
244
245 GLOBAL void cmhSM_Reset( void )
246 {
247 SHORT i = 0;
248 UBYTE gprs_default_pco[] = {
249 0x80,0x80,0x21,0x10,0x01,0x01,0x00,0x10,0x81,0x06,
250 0x00,0x00,0x00,0x00,0x83,0x06,0x00,0x00,0x00,0x00
251 };
252
253 /* SMF CMH local parameter */
254
255 memset(pdp_context, 0, sizeof(T_GPRS_CONT_CLASS) * MAX_CID);
256
257 for (i = 0; i < MAX_CID; i++)
258 {
259 pdp_context[i].state = CS_UNDEFINED;
260 pdp_context[i].smreg_ti = UNDEFINED_TI;
261 pdp_context[i].link_id_uart = DTI_LINK_ID_NOTPRESENT;
262 pdp_context[i].link_id_new = DTI_LINK_ID_NOTPRESENT;
263 pdp_context[i].link_id_sn = DTI_LINK_ID_NOTPRESENT;
264
265 pdp_context[i].user_pco.len = sizeof (gprs_default_pco);
266 memcpy (pdp_context[i].user_pco.pco, gprs_default_pco, sizeof (gprs_default_pco));
267 }
268
269 memset(work_cids, 0, sizeof(SHORT) * MAX_CID_PLUS_EINS);
270
271 for (i = 0; i < SMH_NSAPI_MAX; i++)
272 nsapi_to_cid[i] = INVALID_CID;
273
274 cid_pointer = 0;
275
276 /* set default context parameter */
277 memset(&defaultCtx, 0, sizeof(T_GPRS_CONT_REC));
278 strcpy(defaultCtx.pdp_type,"IP" );
279
280 /* mode of CGAUTO*/
281 automatic_response_mode = 3;
282
283 m_service = CGSMS_SERVICE_CS_PREFERRED;
284
285 /* GPRS event reporting */
286 ati_user_output_cfg[CMD_SRC_ATI].CGEREP_mode = CGEREP_MODE_BUFFER;
287 ati_user_output_cfg[CMD_SRC_ATI].CGEREP_bfr = CGEREP_BFR_CLEAR;
288 sm_cgsms_service = CGSMS_SERVICE_CS_PREFERRED;
289 }
290
291 /*
292 +--------------------------------------------------------------------+
293 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
294 | STATE : finished ROUTINE : cmhSM_empty_call_table |
295 +--------------------------------------------------------------------+
296
297 PURPOSE : Fill variables for the own use with default values.
298 */
299 GLOBAL void cmhSM_empty_call_table (void)
300 {
301 memset (gprs_call_table, 0, sizeof(T_GPRS_CALL_TABLE) *MAX_GPRS_CALL_TABLE_ENTRIES);
302 current_gprs_ct_index = 0;
303 gprs_ct_index = 0;
304 gprs_call_table[0].sm_ind.smreg_ti = UNDEFINED_TI;
305 }
306
307 /*
308 +-------------------------------------------------------------------------------+
309 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
310 | STATE : code ROUTINE : cmhSM_getSrcIdOfRunningCGACTDeactivation |
311 +-------------------------------------------------------------------------------+
312
313 PURPOSE : Returns a source ID if the given cid is requested to deactivate
314 by +CGACT. The source ID indicates where the +CGACT was started.
315 */
316 GLOBAL T_ACI_CMD_SRC cmhSM_getSrcIdOfRunningCGACTDeactivation(SHORT cid)
317 {
318 switch( working_cgact_actions.state )
319 {
320 case T_CDS_RUNNING:
321 if( (1 << (cid - 1) & working_cgact_actions.cid_set) OR
322 INVALID_NSAPI NEQ pdp_context[cid - 1].nsapi AND
323 (pdp_context[cid - 1].nsapi & working_cgact_actions.nsapi_set) )
324 {
325 return working_cgact_actions.srcId;
326 }
327 break;
328 case T_CDS_IDLE:
329 break;
330 }
331 return CMD_SRC_NONE;
332 }
333
334
335 /*
336 +-------------------------------------------------------------------------------+
337 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
338 | STATE : code ROUTINE : cmhSM_getSrcIdOfRunningCGACTDeactivation |
339 +-------------------------------------------------------------------------------+
340
341 PURPOSE : Returns TRUE if +CGACT is running on the given cid -> NO_CARRIER
342 FASE if no CGACT was running on this cid -> CME_ERROR
343 */
344 GLOBAL BOOL isContextDeactivationRequestedByCGACT(SHORT cid)
345 {
346 TRACE_FUNCTION("***isContextDeactivationRequestedByCGACT");
347
348 switch( working_cgact_actions.state )
349 {
350 case T_CDS_RUNNING:
351 if ( (1 << (cid - 1)) & working_cgact_actions.cid_set )
352 {
353 return TRUE;
354 }
355 }
356 return FALSE;
357 }
358
359
360
361 /*
362 +----------------------------------------------------------------------+
363 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
364 | STATE : code ROUTINE : cmhSM_connection_down |
365 +----------------------------------------------------------------------+
366
367 PURPOSE : Control the answer of context deactivations
368 started by an AT command.
369 */
370 GLOBAL void cmhSM_connection_down( UBYTE dti_id )
371 {
372 SHORT cid = gaci_get_cid_over_dti_id( dti_id );
373
374 TRACE_FUNCTION("cmhSM_connection_down");
375
376 switch( working_cgact_actions.state )
377 {
378 case T_CDS_RUNNING:
379 TRACE_EVENT_P1("T_CDS_RUNNING, cid:%d", cid);
380 if ( (1 << (cid - 1)) & working_cgact_actions.cid_set )
381 { /* nsapi deactivation is requested */
382 working_cgact_actions.cid_set &= (USHORT) ~(1U << (cid - 1));
383 TRACE_EVENT_P1("new set: %d",working_cgact_actions.cid_set);
384
385 if ( ! (working_cgact_actions.cid_set OR
386 working_cgact_actions.nsapi_set ) )
387 {
388 R_AT( RAT_OK, working_cgact_actions.srcId ) ( AT_CMD_CGACT );
389 working_cgact_actions.state = T_CDS_IDLE;
390 }
391 else
392 {
393 TRACE_EVENT_P2("NO OK: cid_set:%d, nsapi_set:%d",working_cgact_actions.cid_set,working_cgact_actions.nsapi_set);
394 }
395 }
396 else
397 {
398 TRACE_EVENT_P1("meets not the set: %d",working_cgact_actions.cid_set);
399 }
400 break;
401 case T_CDS_IDLE:
402 TRACE_EVENT("T_CDS_IDLE");
403 break;
404 }
405 }
406
407 /*
408 +--------------------------------------------------------------------+
409 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
410 | STATE : finished ROUTINE : cmhSM_GetNewNSapi |
411 +--------------------------------------------------------------------+
412
413 PURPOSE : Give a free NSapi no. or invalid if all NSapi's are in use.
414 */
415 LOCAL UBYTE cmhSM_GetNewNSapi ( void )
416 {
417 BYTE i = SMH_FIRST_FREE_NSAPIS;
418
419 TRACE_FUNCTION("cmhSM_GetNewNSapi");
420
421 while ( i <= SMH_LAST_FREE_NSAPIS AND nsapi_to_cid[i] NEQ INVALID_CID )
422 i++;
423
424 if ( i <= SMH_LAST_FREE_NSAPIS)
425 {
426 pdp_context[work_cids[cid_pointer] - 1].nsapi = i;
427 nsapi_to_cid[i] = work_cids[cid_pointer];
428
429 TRACE_EVENT_P1("new NSAPI: %d", i);
430
431 return i;
432 }
433
434 return INVALID_NSAPI;
435 }
436
437 /*
438 +--------------------------------------------------------------------+
439 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
440 | STATE : finished ROUTINE : cmhSM_GiveNSapiFree |
441 +--------------------------------------------------------------------+
442
443 PURPOSE : Give a NSapi free after use.
444 */
445 GLOBAL void cmhSM_GiveNSapiFree ( USHORT cid )
446 {
447 UBYTE *nsapi = &pdp_context[cid - 1].nsapi;
448
449 if ( *nsapi <= SMH_LAST_FREE_NSAPIS )
450 {
451 nsapi_to_cid[*nsapi] = INVALID_CID;
452 }
453 }
454
455 /*
456 +--------------------------------------------------------------------+
457 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
458 | STATE : finished ROUTINE : cmhSM_contextDeactivated |
459 +--------------------------------------------------------------------+
460
461 PURPOSE : Detach mobile if necessary?
462 */
463 GLOBAL void cmhSM_contextDeactivated ( void )
464 {
465
466 if ( ! cmhSM_isContextActive() )
467 {
468 cmhGMM_allContextsDeactivated();
469 }
470 }
471
472
473 /*
474 +--------------------------------------------------------------------+
475 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
476 | STATE : finished ROUTINE : cmhSM_Get_pdp_type |
477 +--------------------------------------------------------------------+
478
479 PURPOSE : Give the PDP type of the current PDP context that will build.
480 */
481 GLOBAL UBYTE cmhSM_Get_pdp_type ( void )
482 {
483 if (!strcmp(pdp_context[work_cids[cid_pointer] - 1].con.pdp_type, "IP"))
484 return IP_V_4;
485
486 return 0;
487 }
488
489 /*
490 +--------------------------------------------------------------------+
491 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
492 | STATE : finished ROUTINE : cmhSM_Get_pdp_address |
493 +--------------------------------------------------------------------+
494
495 PURPOSE : Give the PDP address of the current PDP context that will build.
496 */
497 GLOBAL void cmhSM_Get_pdp_address ( T_pdp_address *pdp_address )
498 {
499
500 pdp_address->c_buff =
501 (UBYTE) cmhSM_pdp_address_to_ip(&pdp_context[work_cids[cid_pointer] - 1].con.pdp_addr, (UBYTE*) pdp_address->buff);
502
503 #ifdef _SIMULATION_
504 memset (pdp_address->buff + pdp_address->c_buff, 0, sizeof(pdp_address->buff) - pdp_address->c_buff);
505 #endif
506 }
507
508 /*
509 +--------------------------------------------------------------------+
510 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
511 | STATE : finished ROUTINE : cmhSM_pdp_address_to_ip |
512 +--------------------------------------------------------------------+
513
514 PURPOSE : Transform a PDP address to 4 BYTE IP form.
515 */
516 GLOBAL SHORT cmhSM_pdp_address_to_ip ( T_PDP_ADDRESS *pdp_address, UBYTE *ip )
517 {
518 SHORT i = 0;
519 BOOL isDynamicIP = TRUE;
520 char *start = *pdp_address,
521 *end;
522
523 if ( **pdp_address )
524 {
525 for (i = 0; i < 4; i++)
526 {
527 ip[i] = (UBYTE) strtol(start, &end, 10);
528 start = end + 1;
529 /*
530 * dynamic ip patch
531 * 12.02.02 brz
532 *
533 * if it is a dynamic IP Address than the SM entity need the length set to zero
534 */
535 if ( ip[i] )
536 {
537 isDynamicIP = FALSE;
538 }
539 }
540
541 if ( isDynamicIP EQ TRUE )
542 {
543 return 0;
544 }
545 else
546 {
547 return 4;
548 }
549 }
550 else
551 {
552 *ip = 0;
553 }
554
555 return 0;
556 }
557
558 /*
559 +--------------------------------------------------------------------+
560 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
561 | STATE : finished ROUTINE : cmhSM_ip_to_pdp_address |
562 +--------------------------------------------------------------------+
563
564 PURPOSE : Transform a 4 BYTE IP form to the PDP address.
565 */
566 GLOBAL void cmhSM_ip_to_pdp_address ( UBYTE *ip, T_PDP_ADDRESS pdp_address )
567 {
568
569 sprintf(pdp_address, "%03hd.%03hd.%03hd.%03hd", ip[0], ip[1], ip[2], ip[3] );
570
571 }
572
573 /*
574 +-------------------------------------------------------------------+
575 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
576 | STATE : finished ROUTINE : convert_netaddr_to_apn |
577 +-------------------------------------------------------------------+
578
579 PURPOSE : converts a domain name into an APN
580
581 Technical Information:
582
583 The APN contains out of labels separated by dots.
584 (e.g. xxx.yyy.zzz)
585
586 This string representation must be translated to a network
587 representation.
588
589 The APN network representation contains out of a sequence of
590 a length field (not ASCII) followed by a ASCII string.
591
592 xxx.yyy.zzz => 3xxx3yyy3zzz
593 */
594 LOCAL void convert_netaddr_to_apn ( T_smreg_apn *apn )
595 {
596 UBYTE counter = 0,
597 buffer = apn->buffer[0],
598 *pdest = apn->buffer + apn->c_buffer,
599 *psource = pdest - 1;
600
601 if(apn->c_buffer EQ 0)
602 {
603 return;
604 }
605
606 if(apn->c_buffer >= sizeof apn->buffer)
607 {
608 apn->c_buffer = 0;
609 TRACE_EVENT_P2 ("convert_netaddr_to_apn: array out of bounds exeption (%d >= %d)", apn->c_buffer, sizeof apn->buffer);
610 return;
611 }
612
613 /* The network representation is 1 byte longer. */
614 apn->c_buffer++;
615
616 /* A sentinel */
617 apn->buffer[0] = '.';
618
619 /* Algorithm: copy from back to front! */
620 while(pdest > apn->buffer )
621 {
622 counter = 0;
623 while(*psource NEQ '.')
624 {
625 *(pdest--) = *(psource--);
626 counter++;
627 }
628 *(pdest--) = counter;
629 psource--;
630 }
631
632 /* Correction according to the sentinel */
633 apn->buffer[1] = buffer;
634 apn->buffer[0] = ++counter;
635
636 /* Modify special empty APN to the need of SMREG_SAP */
637 if ((apn->c_buffer EQ 2) AND (apn->buffer[0] EQ 1) AND (apn->buffer[1] EQ 255))
638 {
639 apn->c_buffer = 1; /* Special SMREG_SAP indicating that there is an APN present but empty */
640 apn->buffer[0]= 0;
641 }
642 }
643 /*
644 +--------------------------------------------------------------------+
645 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
646 | STATE : finished ROUTINE : cmhSM_Get_smreg_apn |
647 +--------------------------------------------------------------------+
648
649 PURPOSE : Give the APN of the current PDP context that will build.
650 */
651 GLOBAL void cmhSM_Get_smreg_apn ( T_smreg_apn *smreg_apn )
652 {
653
654 smreg_apn->c_buffer = strlen(pdp_context[work_cids[cid_pointer] - 1].con.apn);
655 strncpy((char *)smreg_apn->buffer, (const char *)pdp_context[work_cids[cid_pointer] - 1].con.apn, smreg_apn->c_buffer);
656 convert_netaddr_to_apn(smreg_apn);
657
658 #ifdef _SIMULATION_
659 memset (smreg_apn->buffer + smreg_apn->c_buffer, 0, sizeof(smreg_apn->buffer) - smreg_apn->c_buffer);
660 #endif
661 }
662
663 /*
664 +--------------------------------------------------------------------+
665 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
666 | STATE : finished ROUTINE : cmhSM_Get_h_comp |
667 +--------------------------------------------------------------------+
668
669 PURPOSE : Give the h_comp of the current PDP context that will build.
670 */
671 GLOBAL UBYTE cmhSM_Get_h_comp ( void )
672 {
673
674 return (UBYTE) pdp_context[work_cids[cid_pointer] - 1].con.h_comp;
675
676 }
677
678 /*
679 +--------------------------------------------------------------------+
680 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
681 | STATE : finished ROUTINE : cmhSM_Get_d_comp |
682 +--------------------------------------------------------------------+
683
684 PURPOSE : Give the d_comp of the current PDP context that will build.
685 */
686 GLOBAL UBYTE cmhSM_Get_d_comp ( void )
687 {
688
689 return (UBYTE) pdp_context[work_cids[cid_pointer] - 1].con.d_comp;
690
691 }
692
693 /*
694 +--------------------------------------------------------------------+
695 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
696 | STATE : finished ROUTINE : cmhSM_change_def_QOS |
697 +--------------------------------------------------------------------+
698
699 PURPOSE : Set the quality of service (requested) of default context.
700
701 */
702 GLOBAL void cmhSM_change_def_QOS ( T_QOS *qos )
703 {
704
705 memcpy(&defaultCtx.qos, qos, sizeof(T_QOS));
706
707 }
708
709 /*
710 +--------------------------------------------------------------------+
711 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
712 | STATE : finished ROUTINE : cmhSM_change_def_QOS_min |
713 +--------------------------------------------------------------------+
714
715 PURPOSE : Set the quality of service (min.) of default context.
716
717 */
718 GLOBAL void cmhSM_change_def_QOS_min ( T_QOS *qos )
719 {
720
721 memcpy(&defaultCtx.min_qos, qos, sizeof(T_QOS));
722
723 }
724
725 /*
726 +--------------------------------------------------------------------+
727 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
728 | STATE : finished ROUTINE : cmhSM_Set_default_QOS |
729 +--------------------------------------------------------------------+
730
731 PURPOSE : Set the quality of service of the spezified PDP context
732 to default.
733 */
734 GLOBAL void cmhSM_Set_default_QOS ( SHORT cid )
735 {
736
737 memcpy(&pdp_context[cid - 1].con.qos, &defaultCtx.qos, sizeof(T_QOS));
738
739 }
740
741 /*
742 +--------------------------------------------------------------------+
743 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
744 | STATE : finished ROUTINE : cmhSM_Set_default_QOS |
745 +--------------------------------------------------------------------+
746
747 PURPOSE : Set the quality of service of the spezified PDP context
748 to default.
749 */
750 GLOBAL void cmhSM_Set_default_QOS_min ( SHORT cid )
751 {
752
753 memcpy(&pdp_context[cid - 1].con.min_qos, &defaultCtx.min_qos, sizeof(T_QOS));
754
755 }
756
757 /*
758 +--------------------------------------------------------------------+
759 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
760 | STATE : finished ROUTINE : cmhSM_Get_QOS |
761 +--------------------------------------------------------------------+
762
763 PURPOSE : Give the requested quality of service of the current
764 PDP context that will build.
765 */
766 GLOBAL void cmhSM_Get_QOS ( T_smreg_qos *dest_qos )
767 {
768 T_QOS *source_qos = &pdp_context[work_cids[cid_pointer] - 1].con.qos;
769
770 dest_qos->preced = source_qos->preced;
771 dest_qos->delay = source_qos->delay;
772 dest_qos->relclass = source_qos->relclass;
773 dest_qos->peak = source_qos->peak;
774 dest_qos->mean = source_qos->mean;
775
776 }
777
778 /*
779 +--------------------------------------------------------------------+
780 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
781 | STATE : finished ROUTINE : cmhSM_Get_QOS_min |
782 +--------------------------------------------------------------------+
783
784 PURPOSE : Give the minimum acceptable quality of service of the
785 current PDP context that will build.
786 */
787 GLOBAL void cmhSM_Get_QOS_min ( T_smreg_min_qos *dest_qos_min )
788 {
789 T_QOS *source_qos = &pdp_context[work_cids[cid_pointer] - 1].con.min_qos;
790
791 dest_qos_min->preced = source_qos->preced;
792 dest_qos_min->delay = source_qos->delay;
793 dest_qos_min->relclass = source_qos->relclass;
794 dest_qos_min->peak = source_qos->peak;
795 dest_qos_min->mean = source_qos->mean;
796
797 }
798
799 GLOBAL USHORT cmhSM_pdp_typ_to_string ( UBYTE pdp_typ_no, char* string )
800 {
801 switch ( pdp_typ_no )
802 {
803 case 0:
804 strcpy (string, "X_121");
805 return 5;
806 case 33:
807 strcpy (string, "IP_V_4");
808 return 6;
809 case 87:
810 strcpy (string, "IP_V_6");
811 return 6;
812 default:
813 strcpy (string, "");
814 return 0;
815 }
816 }
817
818 /*
819 +--------------------------------------------------------------------+
820 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
821 | STATE : finished ROUTINE : cmhSM_ring_gprs_par |
822 +--------------------------------------------------------------------+
823
824 PURPOSE : Return the information for CRING.
825 */
826 GLOBAL char* cmhSM_ring_gprs_par ( void )
827 {
828 static char string[MAX_CRING_INFORMATION_LENGTH] = "\"";
829 unsigned int i = 1;
830
831 i += cmhSM_pdp_typ_to_string(gprs_call_table[current_gprs_ct_index].sm_ind.pdp_type, string + i);
832 string[i++] = '\"';
833
834 string[i++] = ',';
835
836 string[i++] = '\"';
837 memcpy (string + i, gprs_call_table[current_gprs_ct_index].sm_ind.pdp_address.buff,
838 gprs_call_table[current_gprs_ct_index].sm_ind.pdp_address.c_buff);
839
840 i += gprs_call_table[current_gprs_ct_index].sm_ind.pdp_address.c_buff + 1;
841 string[i++] = '\"';
842
843 if ( *gprs_call_table[current_gprs_ct_index].L2P )
844 {
845 string[i++] = ',';
846
847 string[i++] = '\"';
848 strcpy (string + i, gprs_call_table[current_gprs_ct_index].L2P);
849 i += strlen (gprs_call_table[current_gprs_ct_index].L2P);
850 string[i++] = '\"';
851 }
852
853 string[i] = 0;
854
855 return string;
856 }
857
858 /*
859 +--------------------------------------------------------------------+
860 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
861 | STATE : finished ROUTINE : cmhSM_call_answer |
862 +--------------------------------------------------------------------+
863
864 PURPOSE : Return TRUE in this case, if an auto answer is needed.
865 */
866 GLOBAL BOOL cmhSM_call_answer ( UBYTE ring_counter, T_ACI_CRING_MOD mode )
867 {
868
869 switch(automatic_response_mode)
870 {
871 case 0: /* GPRS off, GSM controlled by S0 */
872 if ( mode NEQ CRING_MOD_Gprs AND
873 at.S[0] AND at.S[0] <= ring_counter )
874 return TRUE;
875 break;
876 case 1: /* GPRS on, GSM controlled by S0 */
877 if ( mode EQ CRING_MOD_Gprs )
878 return TRUE;
879 if (at.S[0] AND at.S[0] <= ring_counter)
880 return TRUE;
881 break;
882 case 2: /* modem copatibility mode, GPRS on, GSM off */
883 if ( mode NEQ CRING_MOD_Gprs )
884 break;
885 /*lint -fallthrough*/
886 case 3: /* modem copatibility mode, GPRS on, GSM on */
887 if (at.S[0] AND ring_counter >= at.S[0])
888 return TRUE;
889 }
890
891 return FALSE;
892 }
893
894
895 /*
896 +--------------------------------------------------------------------+
897 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
898 | STATE : finished ROUTINE : cmhSM_call_reject |
899 +--------------------------------------------------------------------+
900
901 PURPOSE : Return TRUE in this case, if an auto reject is needed.
902 */
903 GLOBAL BOOL cmhSM_call_reject ( UBYTE ring_counter, T_ACI_CRING_MOD mode )
904 {
905 switch(automatic_response_mode)
906 {
907 case 0: /* GPRS off, GSM controlled by S0 */
908 return FALSE;
909 case 1: /* GPRS on, GSM controlled by S0 */
910 if (at.S99 AND mode EQ CRING_MOD_Gprs )
911 return TRUE;
912 break;
913 case 2: /* modem copatibility mode, GPRS on, GSM off */
914 case 3: /* modem copatibility mode, GPRS on, GSM on */
915 if ( mode NEQ CRING_MOD_Gprs )
916 break;
917 if (at.S99 AND ring_counter >= at.S99)
918 return TRUE;
919 }
920
921 return FALSE;
922 }
923
924
925
926
927 LOCAL BOOL is_GSM_call_active (void)
928 {
929 SHORT ctbIdx; /* holds call table index */
930
931 for( ctbIdx = 0; ctbIdx < MAX_CALL_NR; ctbIdx++ )
932 {
933 if (ccShrdPrm.ctb[ctbIdx] NEQ NULL)
934 {
935 return (TRUE);
936 }
937 }
938
939 return (FALSE);
940 }
941
942 /*
943 +--------------------------------------------------------------------+
944 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
945 | STATE : finished ROUTINE : cmhSM_sAT_H |
946 +--------------------------------------------------------------------+
947
948 PURPOSE : handle GPRS calls and return FALSE if a circuit switched
949 call need a handle.
950 */
951 GLOBAL BOOL cmhSM_sAT_H ( T_ACI_CMD_SRC srcId, T_ACI_RETURN *aci_ret )
952 {
953
954 SHORT cid_array[1] = { INVALID_CID };
955 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, (UBYTE)srcId, search_ati_src_id);
956
957 if ( ( at.rngPrms.isRng EQ TRUE ) AND ( at.rngPrms.mode EQ CRING_MOD_Gprs) )
958 {
959 /*
960 * brz patch: In the case of context reactivation over SMREG_PDP_ACTIVATE_IND with an used ti
961 * the GPRS ATH command doesn't do anything!
962 *
963 * Why? Because the Windows Dial-Up Networking client send every time an ATH after termination
964 * of the connection and with this a context reactivation was impossible.
965 */
966 if ( gprs_call_table[current_gprs_ct_index].reactivation EQ GCTT_NORMAL )
967 {
968 return cmhSM_sAT_A_H_intern(srcId, aci_ret, 0);
969 }
970 return TRUE;
971 }
972 else
973 {
974 if (is_GSM_call_active())
975 {
976 return (FALSE);
977 }
978 /* if AT_H has been called and no RING is active, then disconnect the active
979 context */
980 #ifdef FF_GPF_TCPIP
981 if(is_gpf_tcpip_call())
982 {
983 T_DCM_STATUS_IND_MSG err_ind_msg;
984 err_ind_msg.hdr.msg_id = DCM_ERROR_IND_MSG;
985 err_ind_msg.result = DCM_PS_CONN_BROKEN;
986 dcm_send_message(err_ind_msg, DCM_SUB_NO_ACTION);
987 }
988 #endif
989 *aci_ret = sAT_PlusCGACT ( srcId, CGACT_STATE_DEACTIVATED, cid_array );
990
991 switch (*aci_ret)
992 {
993 case (AT_CMPL): /*operation completed*/
994 return FALSE; /* return false, so that GSM calls will be canceled */
995 case (AT_EXCT):
996 src_params->curAtCmd = AT_CMD_CGACT;
997 return TRUE;
998 default:
999 cmdCmeError(CME_ERR_Unknown); /*Command failed*/
1000 return FALSE;
1001 }
1002 }
1003 }
1004
1005 /*
1006 +--------------------------------------------------------------------+
1007 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1008 | STATE : finished ROUTINE : cmhSM_sAT_A |
1009 +--------------------------------------------------------------------+
1010
1011 PURPOSE : handle GPRS calls and return FALSE if a circuit switched
1012 call need a handle.
1013 */
1014 GLOBAL BOOL cmhSM_sAT_A ( T_ACI_CMD_SRC srcId, T_ACI_RETURN *aci_ret )
1015 {
1016 BOOL b;
1017
1018 b = cmhSM_sAT_A_H_intern(srcId, aci_ret, 1);
1019
1020 if ( *aci_ret EQ AT_EXCT )
1021 cmdErrStr = NULL;
1022
1023 return b;
1024 }
1025
1026 /*
1027 +--------------------------------------------------------------------+
1028 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1029 | STATE : finished ROUTINE : cmhSM_sAT_A_H_intern |
1030 +--------------------------------------------------------------------+
1031
1032 PURPOSE : handle sAT_A and cAT_H for GPRS
1033 */
1034 static BOOL cmhSM_sAT_A_H_intern ( T_ACI_CMD_SRC srcId, T_ACI_RETURN *aci_ret, SHORT mode)
1035 {
1036 if ( at.rngPrms.isRng EQ TRUE )
1037 {
1038 if ( at.rngPrms.mode EQ CRING_MOD_Gprs)
1039 {
1040 *aci_ret = automatic_response_mode > 1 ? /* modem copatibility mode possible */
1041 sAT_PlusCGANS(srcId, mode, NULL, GPRS_CID_OMITTED): AT_FAIL;
1042 }
1043 else /* circuit switched call */
1044 {
1045 return FALSE;
1046 }
1047 }
1048 else
1049 {
1050 return FALSE;
1051 }
1052 return TRUE;
1053 }
1054
1055 /*
1056 +----------------------------------------------------------------------+
1057 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1058 | STATE : finished ROUTINE : cmhSM_pdp_addr_well_formed |
1059 +----------------------------------------------------------------------+
1060
1061 PURPOSE : check pdp address of well formed
1062 */
1063 GLOBAL BOOL cmhSM_pdp_addr_well_formed( USHORT type, T_PDP_ADDRESS pdp_addr )
1064 {
1065 SHORT i = 0, state = 1;
1066 char *start = pdp_addr, *end;
1067 long temp;
1068
1069 switch ( type )
1070 {
1071 case PDP_T_IP: /* 255.255.255.255 */
1072 if ( *pdp_addr )
1073 {
1074 while ( state AND i < 3)
1075 {
1076 temp = strtol(start, &end, 10);
1077 if ( temp < 0 OR temp > 255 )
1078 state = 0;
1079 if ( *end NEQ '.' )
1080 state = 0;
1081
1082 start = end + 1;
1083 i++;
1084 }
1085 temp = strtol(start, &end, 10);
1086 if ( temp < 0 OR temp > 255 )
1087 state = 0;
1088 }
1089
1090 if(state)
1091 return TRUE;
1092 break;
1093 case PDP_T_X25:
1094 return FALSE;
1095 default:
1096 break;
1097 }
1098 return FALSE;
1099 }
1100
1101 /*
1102 +----------------------------------------------------------------------+
1103 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1104 | STATE : finished ROUTINE : cmhSM_apn_well_formed |
1105 +----------------------------------------------------------------------+
1106
1107 PURPOSE : check APN of well formed
1108 */
1109 GLOBAL BOOL cmhSM_apn_well_formed( T_APN APN )
1110 {
1111 SHORT i = 0, state = 1, length = strlen (APN);
1112 char *no_start_labels[] = {"rac","lac","sgsn"}, *start, *end, *mark;
1113 T_APN apn;
1114
1115 strcpy(apn, APN);
1116 start = apn;
1117
1118 /* change charcter of string to lower cases */
1119 for (i = 0; i < length; i++)
1120 apn[i] = tolower(apn[i]);
1121
1122 /* The Network Identifier shall not start with this labels */
1123 for (i = 0; i < 3; i++)
1124 {
1125 if ( apn EQ strstr(apn, no_start_labels[i]) )
1126 return FALSE;
1127 }
1128
1129 /* the Wild Card APN */
1130 if ( length EQ 1 AND *start EQ '*' )
1131 return TRUE;
1132
1133 /* the APN with no name */
1134 if ( length EQ 1 AND *start EQ /*lint -e(743)*/ '\x0ff' )
1135 return TRUE;
1136
1137 /* Oporater Identifer is optional and the Network Identifer */
1138 mark = strrchr(apn, '.');
1139 if ( mark )
1140 if ( strstr(mark + 1, "gprs") )
1141 {
1142 /* APN Operator Identifier contained (optional) */
1143 if ( length < 18 )
1144 return FALSE;
1145 mark = start + length - 18; /* start of the APN Operator Identifier */
1146 /* check APN Operator Identifier: "mncXXX.mccXXX.gprs" */
1147 if ( mark NEQ strstr(mark, "mnc") )
1148 return FALSE;
1149 if ( mark + 6 NEQ strstr(mark, ".mcc") )
1150 return FALSE;
1151 strtol(mark + 3, &end, 10);
1152 if ( end NEQ mark + 6 )
1153 return FALSE;
1154 strtol(mark + 10, &end, 10);
1155 if ( end NEQ mark + 13 )
1156 return FALSE;
1157 /* check character between APN Network Identifier and the Operator Identifer */
1158 mark--;
1159 if ( *mark NEQ '.' )
1160 return FALSE;
1161 /* set stop mark */
1162 *mark = 0;
1163 }
1164 else
1165 mark = 0;
1166
1167 /* check APN Network Identifier */
1168
1169 /* shall not end in ".gprs" */
1170 end = strrchr(apn, '.');
1171 if ( end )
1172 if ( strstr(end + 1, "gprs") )
1173 return FALSE;
1174
1175 /* parse all labels */
1176 while ( *start )
1177 {
1178 /* in first at least one Label */
1179 while ( (*start >= 'a' AND *start <= 'z') OR (*start >= '0' AND *start <= '9') OR *start EQ '-' )
1180 start ++;
1181
1182 /* next Label or nothing */
1183 if ( *start EQ '.' )
1184 start ++;
1185 else
1186 if ( *start NEQ 0)
1187 return FALSE;
1188 }
1189
1190 /* The APN Network Identifier shall have a maximum length of 63 octets. */
1191 if ( start - apn > 63 )
1192 return FALSE;
1193
1194 /* clear stop mark */
1195 if ( mark )
1196 *mark = '.';
1197
1198 return TRUE;
1199 }
1200
1201 /*
1202 +--------------------------------------------------------------------+
1203 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1204 | STATE : finished ROUTINE : cmhSM_transform_pdp_type |
1205 +--------------------------------------------------------------------+
1206
1207 PURPOSE : transform pdp_type
1208 */
1209 GLOBAL USHORT cmhSM_transform_pdp_type ( char *pdp_type )
1210 {
1211
1212 if ( !strcmp(pdp_type, "IP") )
1213 return PDP_T_IP;
1214
1215 if ( !strcmp(pdp_type, "X25") )
1216 return PDP_T_X25;
1217
1218 return PDP_T_NONE;
1219 }
1220
1221
1222 GLOBAL T_CONTEXT_STATE get_state_over_cid ( SHORT cid )
1223 {
1224 TRACE_FUNCTION("get_state_over_cid()");
1225 if ( (cid < 1) OR (cid > MAX_CID) )
1226 {
1227 TRACE_EVENT("invalid cid detected!");
1228 return CS_INVALID_STATE;
1229 }
1230 return pdp_context[cid - 1].state;
1231
1232 }
1233
1234 GLOBAL void set_state_over_cid ( SHORT cid, T_CONTEXT_STATE c_state )
1235 {
1236 TRACE_EVENT_P3("set_state_over_cid: %d -> %d for cid %d", pdp_context[cid - 1].state, c_state, cid) ;
1237 if (cid > 0 AND cid <= MAX_CID)
1238 pdp_context[cid - 1].state = c_state;
1239 }
1240
1241 GLOBAL T_CONTEXT_STATE get_state_working_cid ( void )
1242 {
1243
1244 if ( work_cids[cid_pointer] EQ INVALID_CID )
1245 {
1246 TRACE_EVENT("working_cid is invalid!");
1247 return CS_INVALID_STATE;
1248 }
1249
1250 return pdp_context[work_cids[cid_pointer] - 1].state;
1251
1252 }
1253
1254 GLOBAL void set_conn_param_on_all_working_cids ( UBYTE owner, T_DTI_ENTITY_ID entity_id )
1255 {
1256 SHORT *pcid = &(work_cids[cid_pointer]);
1257
1258 TRACE_FUNCTION("set_conn_param_on_all_working_cids()");
1259
1260 while(INVALID_CID NEQ *pcid) {
1261 pdp_context[*pcid - 1].owner = owner;
1262 pdp_context[*pcid - 1].entity_id = entity_id;
1263 pcid ++;
1264 }
1265 }
1266
1267 GLOBAL void set_conn_param_on_working_cid ( UBYTE owner, T_DTI_ENTITY_ID entity_id )
1268 {
1269 TRACE_FUNCTION("set_conn_param_on_working_cid()");
1270
1271 pdp_context[work_cids[cid_pointer] - 1].owner = owner;
1272 pdp_context[work_cids[cid_pointer] - 1].entity_id = entity_id;
1273 }
1274
1275 GLOBAL void set_state_working_cid ( T_CONTEXT_STATE c_state )
1276 {
1277 TRACE_FUNCTION("set_state_working_cid()");
1278
1279 if ( work_cids[cid_pointer] NEQ INVALID_CID )
1280 {
1281 pdp_context[work_cids[cid_pointer] - 1].state = c_state;
1282 }
1283 else
1284 {
1285 TRACE_EVENT("working cid is invalid!");
1286 }
1287
1288 }
1289
1290 GLOBAL T_CONTEXT_STATE get_state_over_nsapi_set ( USHORT *nsapi_set, SHORT *cid )
1291 {
1292 USHORT nsapi = 0;
1293
1294 TRACE_FUNCTION("get_state_over_nsapi_set()");
1295 while( nsapi < SMH_LAST_FREE_NSAPIS AND !((*nsapi_set >> nsapi) & 1) )
1296 nsapi++;
1297
1298 if ( !(*nsapi_set & ( 1 << nsapi )) )
1299 {
1300 return CS_INVALID_STATE;
1301 }
1302
1303 TRACE_EVENT_P1("NSAPI: %4d", nsapi);
1304
1305 *nsapi_set &= ~( 1U << nsapi );
1306
1307 return get_state_over_cid( *cid = nsapi_to_cid[nsapi] );
1308
1309 }
1310
1311 GLOBAL T_CONTEXT_STATE get_state_over_nsapi ( USHORT nsapi )
1312 {
1313
1314 return get_state_over_cid( nsapi_to_cid[nsapi] );
1315
1316 }
1317
1318 GLOBAL USHORT cmhSM_Give_nsapi_set ( SHORT cid )
1319 {
1320
1321 if ( (cid < 1) OR (cid > MAX_CID) )
1322 return 0;
1323
1324 return 1 << pdp_context[cid - 1].nsapi;
1325
1326 }
1327
1328 GLOBAL T_ACI_CAL_OWN get_owner_over_cid ( SHORT cid )
1329 {
1330
1331 if ( (cid < 1) OR (cid > MAX_CID) )
1332 return CAL_OWN_NONE;
1333
1334 return pdp_context[cid - 1].owner;
1335
1336 }
1337
1338 GLOBAL void cmhGPPP_send_establish_request ( UBYTE peer )
1339 {
1340 T_PPP_ESTABLISH_REQ est_req;
1341
1342 memset(&est_req, 0, sizeof( T_PPP_ESTABLISH_REQ ));
1343
1344 est_req.mode = PPP_SERVER;
1345 est_req.mru = PPP_MRU_DEFAULT;
1346 est_req.ap = gpppShrdPrm.ppp_authentication_protocol;
1347 est_req.accm = gpppShrdPrm.accm;
1348 est_req.rt = gpppShrdPrm.restart_timer;
1349 est_req.mc = gpppShrdPrm.max_configure;
1350 est_req.mt = gpppShrdPrm.max_terminate;
1351 est_req.mf = gpppShrdPrm.max_failure;
1352
1353 est_req.peer_direction = DTI_CHANNEL_TO_LOWER_LAYER;
1354 est_req.prot_direction = DTI_CHANNEL_TO_HIGHER_LAYER;
1355
1356 est_req.peer_link_id = pdp_context[work_cids[0] - 1].link_id_uart;
1357 est_req.prot_link_id = pdp_context[work_cids[0] - 1].link_id_new;
1358
1359 #ifdef _SIMULATION_
1360 memset (est_req.peer_channel.peer_entity, 0, CHANNEL_NAME_LENGTH);
1361 memset (est_req.protocol_channel.protocol_entity, 0, CHANNEL_NAME_LENGTH);
1362 #endif /* _SIMULATION_ */
1363
1364 strcpy ( (char *) est_req.protocol_channel.protocol_entity, SNDCP_NAME);
1365
1366 switch (peer)
1367 {
1368 #ifdef BT_ADAPTER
1369 case DTI_ENTITY_BLUETOOTH:
1370 strcpy ( (char *) est_req.peer_channel.peer_entity, BTI_NAME);
1371 break;
1372 #endif
1373 case DTI_ENTITY_UART:
1374 strcpy ( (char *) est_req.peer_channel.peer_entity, UART_NAME);
1375 break;
1376 #ifdef FF_PSI
1377 case DTI_ENTITY_PSI:
1378 strcpy ( (char *) est_req.peer_channel.peer_entity, PSI_NAME);
1379 break;
1380 #endif /*FF_PSI*/
1381 case DTI_ENTITY_AAA:
1382 strcpy ( (char *) est_req.peer_channel.peer_entity, RIV_NAME);
1383 break;
1384
1385 default:
1386 TRACE_ERROR ("[cmhGPPP_send_establish_request()] Unexpected peer!");
1387 return;
1388 }
1389
1390 psaGPPP_Establish ( &est_req );
1391
1392 set_state_working_cid( CS_ESTABLISH_1 );
1393 }
1394
1395 GLOBAL void cmhSM_cgerep_buffer ( void )
1396 {
1397 UBYTE srcId = srcId_cb;
1398
1399 switch (ati_user_output_cfg[srcId].CGEREP_bfr)
1400 {
1401 case CGEREP_BFR_CLEAR:
1402 memset(gprs_event_buffer, 0, sizeof(T_CGERP_EVENT_BUFFER) * GPRS_EVENT_REPORTING_BUFFER_SIZE);
1403 break;
1404 case CGEREP_BFR_FLUSH:
1405 if ( uart_is_mt_te_link EQ FALSE)
1406 {
1407 while ( gprs_eb_oldest_p NEQ gprs_eb_current_p )
1408 {
1409 R_AT( RAT_CGEREP, srcId )
1410 ( gprs_event_buffer[gprs_eb_oldest_p].event, gprs_event_buffer[gprs_eb_oldest_p].parm );
1411
1412 gprs_eb_oldest_p++;
1413 }
1414 }
1415 break;
1416 case CGEREP_BFR_OMITTED:
1417 case CGEREP_BFR_INVALID:
1418 default:
1419 break;
1420 }
1421 }
1422
1423 GLOBAL void cmhSM_save_event( T_CGEREP_EVENT event, T_CGEREP_EVENT_REP_PARAM *param )
1424 {
1425
1426 /* save event */
1427 gprs_event_buffer[gprs_eb_current_p].event = event;
1428 if (param)
1429 memcpy (&gprs_event_buffer[gprs_eb_current_p].parm, param, sizeof(T_CGEREP_EVENT_REP_PARAM));
1430
1431 /* is buffer full */
1432 if ( gprs_eb_oldest_p EQ gprs_eb_current_p )
1433 gprs_eb_oldest_p = -1;
1434
1435 /* new current pointer */
1436 gprs_eb_current_p++;
1437 if ( gprs_eb_current_p EQ GPRS_EVENT_REPORTING_BUFFER_SIZE )
1438 gprs_eb_current_p = 0;
1439
1440 /* if buffer full correct pointer to oldest event */
1441 if ( gprs_eb_oldest_p EQ -1 )
1442 gprs_eb_oldest_p = gprs_eb_current_p;
1443
1444 }
1445
1446 GLOBAL void cmhSM_set_sms_service ( T_CGSMS_SERVICE service )
1447 {
1448
1449 {
1450 PALLOC (mnsms_mo_serv_req, MNSMS_MO_SERV_REQ);
1451
1452 /* fill in primitive parameter: command request */
1453 mnsms_mo_serv_req -> mo_sms_serv = (UBYTE) service;
1454
1455 PSENDX (SMS, mnsms_mo_serv_req);
1456 }
1457
1458 m_service = service;
1459 }
1460
1461 /*
1462 +-------------------------------------------------------------------+
1463 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1464 | STATE : finnished ROUTINE : cmhSM_sms_service_changed |
1465 +-------------------------------------------------------------------+
1466
1467 PURPOSE : indicates a network initiated PDP context modification
1468
1469 */
1470 GLOBAL void cmhSM_sms_service_changed ( UBYTE service )
1471 {
1472
1473 TRACE_FUNCTION ("cmhSM_sms_service_changed()");
1474
1475 /*
1476 *-------------------------------------------------------------------
1477 * check for command context
1478 *-------------------------------------------------------------------
1479 */
1480 if ( smEntStat.curCmd EQ AT_CMD_CGSMS )
1481 {
1482 if ( m_service EQ service )
1483 {
1484 sm_cgsms_service = m_service;
1485 R_AT( RAT_OK, smEntStat.entOwn ) ( smEntStat.curCmd );
1486 }
1487 else
1488 {
1489 R_AT( RAT_CME, smEntStat.entOwn ) ( smEntStat.curCmd, CME_ERR_Unknown );
1490 /* log result */
1491 cmh_logRslt ( smEntStat.entOwn, RAT_CME, smEntStat.curCmd, -1, -1, CME_ERR_Unknown );
1492 }
1493
1494 smEntStat.curCmd = AT_CMD_NONE;
1495 }
1496 }
1497
1498 GLOBAL T_ACI_RETURN cmhSM_GprsAttached( SHORT state )
1499 {
1500 SHORT i = 1;
1501
1502 TRACE_FUNCTION ("cmhSM_GprsAttached()");
1503
1504 if ( state )
1505 { /* mobile is attached */
1506 switch ( get_state_working_cid( ) )
1507 {
1508 case CS_ATTACHING_AFTER_DEF:
1509 case CS_ATTACHING_AFTER_UNDEF:
1510 cmhSM_data_link_context();
1511 return AT_EXCT;
1512 case CS_WAITS_FOR_ACTIVATING:
1513 if (cmhSM_activate_context() NEQ AT_FAIL)
1514 {
1515 return AT_EXCT;
1516 }
1517 else /*GPRS is not allowed by FDN */
1518 {
1519 return AT_FAIL;
1520 }
1521 default:
1522 return AT_FAIL;
1523 }
1524 }
1525 else
1526 { /* attach failed */
1527 if ( smEntStat.curCmd EQ AT_CMD_NONE AND
1528 gpppEntStat.curCmd EQ AT_CMD_NONE )
1529 return AT_FAIL;
1530
1531 /*
1532 * it is enough to check only the working cid,
1533 * because only one context can be in work
1534 */
1535 switch ( get_state_working_cid( ) )
1536 {
1537 case CS_ATTACHING_AFTER_DEF:
1538 case CS_ATTACHING_AFTER_UNDEF:
1539 pdp_context[work_cids[cid_pointer] - 1].owner = gpppEntStat.entOwn;
1540 gaci_RAT_caller ( RAT_NO_CARRIER, work_cids[cid_pointer], AT_CMD_CGDATA, 0 );
1541 break;
1542 case CS_WAITS_FOR_ACTIVATING:
1543 pdp_context[work_cids[cid_pointer] - 1].owner = smEntStat.entOwn;
1544 gaci_RAT_caller ( RAT_CME, work_cids[cid_pointer], AT_CMD_CGACT, CME_ERR_GPRSUnspec );
1545 break;
1546 default:
1547 /*
1548 * do nothing, because SM informs ACI over context deactivation
1549 */
1550 return AT_FAIL;
1551 }
1552 return cmhSM_deactivateAContext( smEntStat.entOwn, work_cids[cid_pointer] );
1553 }
1554 }
1555
1556 GLOBAL T_ACI_RETURN cmhSM_activate_context(void)
1557 {
1558 TRACE_FUNCTION ("cmhSM_activate_context()");
1559
1560 if (pb_get_fdn_mode () EQ FDN_ENABLE)
1561 {
1562 if (pb_check_fdn (0, (const UBYTE *)"*99#") NEQ PHB_OK)
1563 {
1564 TRACE_EVENT("Activate Context: Entry not found in FDN, GPRS not allowed.");
1565 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_OpNotAllow);
1566 return (AT_FAIL);
1567 }
1568 TRACE_EVENT("Activate Context: Entry found in FDN, GPRS allowed.");
1569 }
1570
1571 if( AT_CMPL EQ cmhGMM_contextActivation(smEntStat.entOwn, AT_CMD_CGACT) )
1572 {
1573 cmhSM_connect_working_cid();
1574 set_state_working_cid( CS_ACTIVATING );
1575 }
1576 else /* AT_EXCT -> class BX class change requested (NOMIII) */
1577 {
1578 set_state_working_cid( CS_WAITS_FOR_ACTIVATING );
1579 }
1580 return (AT_EXCT);
1581 }
1582
1583
1584 #if defined (CO_UDP_IP) || defined (FF_GPF_TCPIP)
1585 /*
1586 +----------------------------------------------------------------------+
1587 | PROJECT : GPRS (8441) MODULE : cmh_smf |
1588 | STATE : initial ROUTINE : cmhSM_IP_activate_cb |
1589 +----------------------------------------------------------------------+
1590
1591 PURPOSE : callback function for WAP over GPRS.
1592 While handling the command ATD*98# in function atGD()
1593 the function psaTCPIP_Activate() is called for WAP handling.
1594 psaTCPIP_Activate() has this function as parameter for
1595 call backs.
1596 */
1597 void cmhSM_IP_activate_cb(T_ACI_RETURN result)
1598 {
1599 SHORT cid = gaci_get_cid_over_dti_id(wap_dti_id);
1600
1601 TRACE_FUNCTION("cmhSM_IP_activate_cb");
1602 TRACE_EVENT_P1("wap_state: %s",wap_state_to_string(wap_state));
1603 #ifndef FF_SAT_E
1604 ACI_ASSERT(DTI_DTI_ID_NOTPRESENT NEQ wap_dti_id);
1605 ACI_ASSERT(cid >= GPRS_CID_1 AND cid < GPRS_CID_INVALID);
1606 ACI_ASSERT(result NEQ AT_FAIL);
1607 #endif /* not FF_SAT_E */
1608
1609 if ( result EQ AT_FAIL )
1610 {
1611 /* IP activation failed. */
1612 TRACE_EVENT("UDP/TCP/IP activation/configuration returned AT_FAIL");
1613
1614 if (DTI_LINK_ID_NOTPRESENT NEQ wap_dti_id)
1615 {
1616 dti_cntrl_close_dpath_from_dti_id (wap_dti_id);
1617 cmhSM_disconnect_cid(cid, GC_TYPE_WAP );
1618 }
1619
1620 /* reset work_cids */
1621 set_state_over_cid(cid, CS_DEFINED);
1622 sAT_PercentWAP(smShrdPrm.owner, 0);
1623 smEntStat.curCmd = AT_CMD_NONE;
1624 dti_cntrl_erase_entry(wap_dti_id);
1625 cmdCmeError(CME_ERR_Unknown);
1626
1627 #if defined (SIM_TOOLKIT) AND defined (FF_SAT_E)
1628 if( cmhSAT_OpChnGPRSPend( INVALID_CID, OPCH_EST_REQ ))
1629 {
1630 cmhSAT_OpChnUDPDeactGprs();
1631 }
1632 #endif /* SIM_TOOLKIT */
1633 return;
1634 }
1635
1636 switch(wap_state)
1637 {
1638 /* in case CO_UDP_IP and FF_GPF_TCPIP is defined this is a fall through case */
1639 UDPIP_STATEMENT(case IPA_Activated:)
1640 GPF_TCPIP_STATEMENT(case TCPIP_Activation:)
1641
1642 if(is_gpf_tcpip_call()) {
1643 GPF_TCPIP_STATEMENT(set_conn_param_on_working_cid(
1644 (UBYTE)smEntStat.entOwn, DTI_ENTITY_TCPIP));
1645 }
1646 else {
1647 UDPIP_STATEMENT(set_conn_param_on_working_cid(
1648 (UBYTE)smEntStat.entOwn, DTI_ENTITY_IP));
1649 }
1650 cmhSM_activate_context();
1651 return;
1652
1653 UDPIP_STATEMENT(case UDPA_Configurated:)
1654 GPF_TCPIP_STATEMENT(case TCPIP_Configurated:)
1655
1656 /* smEntStat.curCmd = AT_CMD_NONE; */
1657 #if defined (SIM_TOOLKIT) AND defined (FF_SAT_E)
1658 if( cmhSAT_OpChnGPRSPend( INVALID_CID, OPCH_EST_REQ ))
1659 {
1660 cmhSAT_OpChnUDPConfGprs();
1661 }
1662 else
1663 #endif /* SIM_TOOLKIT */
1664 {
1665 R_AT ( RAT_CONNECT, smEntStat.entOwn )( AT_CMD_CGACT, -1, wapId, FALSE );
1666 }
1667 smEntStat.curCmd = AT_CMD_NONE;
1668 smEntStat.entOwn = OWN_NONE;
1669 #ifdef FF_GPF_TCPIP
1670 if(is_gpf_tcpip_call())
1671 {
1672 T_DCM_STATUS_IND_MSG msg;
1673 msg.hdr.msg_id = DCM_NEXT_CMD_READY_MSG;
1674 dcm_send_message(msg, DCM_SUB_WAIT_CGACT_CNF);
1675 }
1676 #endif
1677 break;
1678
1679 UDPIP_STATEMENT(case IPA_Deactivated:)
1680 GPF_TCPIP_STATEMENT(case TCPIP_Deactivated:)
1681
1682 TRACE_EVENT_P1("cmhSM_IP_activate_cb, no connection, dti_id = %d", wap_dti_id);
1683 #if defined (SIM_TOOLKIT) AND defined (FF_SAT_E)
1684 if( cmhSAT_OpChnGPRSPend( INVALID_CID, OPCH_NONE ))
1685 {
1686 cmhSAT_OpChnUDPDeactGprs();
1687 }
1688 else
1689 #endif /* SIM_TOOLKIT */
1690 {
1691 R_AT( RAT_NO_CARRIER, pdp_context[cid - 1].owner) ( AT_CMD_CGDATA, 0 );
1692 }
1693 dti_cntrl_close_dpath_from_dti_id (wap_dti_id);
1694 cmhSM_connection_down(wap_dti_id);
1695 cmhSM_disconnect_cid(cid, GC_TYPE_WAP );
1696 sAT_PercentWAP(smShrdPrm.owner, 0);
1697 if(work_cids[cid_pointer] EQ cid)
1698 {
1699 smEntStat.curCmd = AT_CMD_NONE;
1700 *work_cids = 0;
1701 cid_pointer = 0;
1702 }
1703 #ifdef FF_GPF_TCPIP
1704 if(is_gpf_tcpip_call())
1705 {
1706 T_DCM_STATUS_IND_MSG msg;
1707 msg.hdr.msg_id = DCM_NEXT_CMD_READY_MSG;
1708 dcm_send_message(msg, DCM_SUB_WAIT_CGDEACT_CNF);
1709 }
1710 #endif
1711 break;
1712
1713 default:
1714 TRACE_EVENT("Unexpected wap state in cmhSM_IP_activate_cb()");
1715 if(is_gpf_tcpip_call()) {
1716 GPF_TCPIP_STATEMENT(srcc_delete_count(SRCC_TCPIP_SNDCP_LINK ));
1717 }
1718 else {
1719 UDPIP_STATEMENT(srcc_delete_count(SRCC_IP_SNDCP_LINK ));
1720 }
1721 dti_cntrl_erase_entry(wap_dti_id);
1722 sAT_PercentWAP(smShrdPrm.owner, 0);
1723 smEntStat.curCmd = AT_CMD_NONE;
1724
1725 #if defined (SIM_TOOLKIT) AND defined (FF_SAT_E)
1726 if( cmhSAT_OpChnGPRSPend( INVALID_CID, OPCH_NONE ))
1727 {
1728 cmhSAT_OpChnUDPDeactGprs();
1729 }
1730 else
1731 #endif /* SIM_TOOLKIT */
1732 {
1733 cmdCmeError(CME_ERR_Unknown);
1734 }
1735 break;
1736 }
1737 return;
1738 }
1739
1740
1741 /*
1742 +----------------------------------------------------------------------+
1743 | PROJECT : GPRS (8441) MODULE : cmh_smf |
1744 | STATE : initial ROUTINE : cmhSM_IP_Enable |
1745 +----------------------------------------------------------------------+
1746
1747 PURPOSE : enables IP dti connection.
1748 */
1749 GLOBAL void cmhSM_IP_Enable ( T_DTI_CONN_LINK_ID link_id)
1750 {
1751 TRACE_FUNCTION("cmhSM_IP_Enable");
1752
1753 #ifdef _SIMULATION_
1754 cmhSM_connect_context ( gaci_get_cid_over_link_id( link_id ),
1755 DTI_ENTITY_IP, 0, 100 );
1756 #else /* _SIMULATION_ */
1757 cmhSM_connect_context ( gaci_get_cid_over_link_id( link_id ),
1758 DTI_ENTITY_IP, 0, 0 );
1759 #endif /* _SIMULATION_ */
1760 }
1761
1762
1763 /*
1764 +----------------------------------------------------------------------+
1765 | PROJECT : GPRS (8441) MODULE : cmh_smf |
1766 | STATE : initial ROUTINE : cmhSM_IP_Disable |
1767 +----------------------------------------------------------------------+
1768
1769 PURPOSE : disables IP dti connection.
1770 */
1771 GLOBAL void cmhSM_IP_Disable ()
1772 {
1773 TRACE_FUNCTION("cmhSM_IP_Disable");
1774 }
1775
1776 #endif /* WAP || FF_GPF_TCPIP || SAT E */
1777
1778 /*
1779 +-------------------------------------------------------------------+
1780 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1781 | STATE : finnished ROUTINE : cmhSM_data_link_context |
1782 +-------------------------------------------------------------------+
1783 */
1784
1785 GLOBAL void cmhSM_data_link_context(void)
1786 {
1787
1788 TRACE_FUNCTION ("cmhSM_data_link_context()");
1789
1790 R_AT( RAT_CONNECT, pdp_context[work_cids[cid_pointer] - 1].owner )
1791 ( AT_CMD_CGDATA, 0, 0, FALSE );
1792
1793 /* log result */
1794 cmh_logRslt ( pdp_context[work_cids[cid_pointer] - 1].owner,
1795 RAT_CONNECT, AT_CMD_CGDATA, -1, -1, -1 );
1796
1797 cmhSM_connect_working_cid();
1798
1799 }
1800 /*
1801 +-------------------------------------------------------------------+
1802 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1803 | STATE : finnished ROUTINE : cmhSM_get_cid |
1804 +-------------------------------------------------------------------+
1805
1806 */
1807
1808 GLOBAL SHORT cmhSM_get_cid ( USHORT nsapi )
1809 {
1810
1811 return nsapi_to_cid[nsapi];
1812 }
1813
1814 /*
1815 +-------------------------------------------------------------------+
1816 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1817 | STATE : finnished ROUTINE : cmhSM_next_work_cid |
1818 +-------------------------------------------------------------------+
1819
1820 PURPOSE : start the next context activation if requested
1821
1822 */
1823 GLOBAL BOOL cmhSM_next_work_cid ( T_ACI_AT_CMD curCmd )
1824 {
1825
1826 TRACE_EVENT_P1("cmhSM_next_work_cid, cid_pointer: %d", cid_pointer);
1827
1828 cid_pointer ++;
1829
1830 if ( work_cids[cid_pointer] EQ INVALID_CID )
1831 {
1832 smEntStat.curCmd = AT_CMD_NONE;
1833 gpppEntStat.curCmd = AT_CMD_NONE;
1834
1835 cid_pointer = 0;
1836 *work_cids = 0;
1837 return FALSE;
1838 }
1839
1840 switch ( curCmd )
1841 {
1842 case AT_CMD_CGDATA:
1843 cmhSM_data_link_context();
1844 break;
1845 case AT_CMD_CGACT:
1846 if(AT_FAIL EQ cmhSM_activate_context())
1847 {
1848 smEntStat.curCmd = AT_CMD_NONE;
1849 gpppEntStat.curCmd = AT_CMD_NONE;
1850 cid_pointer = 0;
1851 *work_cids = 0;
1852 /*R_AT (RAT_CME, smEntStat.entOwn)( AT_CMD_CGACT, CME_ERR_Unknown );*/
1853 return FALSE;
1854 }
1855 break;
1856 default:
1857 cid_pointer = 0;
1858 *work_cids = 0;
1859 return FALSE;
1860 }
1861 return TRUE;
1862 }
1863
1864 /*
1865 +-------------------------------------------------------------------+
1866 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1867 | STATE : finnished ROUTINE : cmhSM_define_cid_list |
1868 +-------------------------------------------------------------------+
1869
1870 PURPOSE : define all cid's in the list, if necessary
1871
1872 */
1873 GLOBAL SHORT cmhSM_define_cid_list( T_ACI_CMD_SRC srcId, SHORT *cids )
1874 {
1875 int i = 1;
1876
1877 TRACE_FUNCTION("cmhSM_define_cid_list");
1878
1879 if(INVALID_CID != *work_cids)
1880 {
1881 return 0;
1882 }
1883
1884 if ( *cids EQ GPRS_CID_OMITTED) /* if no cid given */
1885 {
1886 while ( i <= MAX_CID AND get_state_over_cid( (SHORT)i ) NEQ CS_DEFINED )
1887 i++;
1888
1889 if ( i > MAX_CID )
1890 {
1891 i = 1;
1892 while ( i <= MAX_CID AND get_state_over_cid( (SHORT)i ) NEQ CS_UNDEFINED )
1893 i++;
1894
1895 if ( i <= MAX_CID )
1896 {
1897 /*
1898 * reset of context parameter if cid undefined
1899 */
1900 sAT_PlusCGDCONT_exec (srcId, (SHORT)i, &defaultCtx);
1901 set_state_over_cid((SHORT)i, CS_UNDEFINED);
1902 }
1903 else
1904 return 0;
1905 }
1906
1907 *cids = work_cids[0] = i;
1908 work_cids[1] = INVALID_CID;
1909 i = 1; /* no. of cids */
1910 }
1911 else /* if cid(s) is/are given */
1912 {
1913 SHORT j = 0;
1914 i = 0;
1915
1916 /*
1917 * checks given cid parameter
1918 */
1919 while ( i < MAX_CID AND cids[i] NEQ INVALID_CID )
1920 {
1921 /* check cid */
1922 if ( cids[i] < GPRS_CID_1 OR cids[i] >= GPRS_CID_INVALID )
1923 return 0;
1924 /* count cids */
1925 i++;
1926 }
1927
1928 if ( MAX_CID < i )
1929 return 0;
1930
1931 memcpy (work_cids, cids, sizeof( *work_cids ) * (i + 1) );
1932
1933 /*
1934 * reset of context parameter if cid undefined
1935 */
1936 for (j = 0; work_cids[j] NEQ INVALID_CID; j++)
1937 {
1938 switch(get_state_over_cid(work_cids[j]))
1939 {
1940 case CS_UNDEFINED:
1941 sAT_PlusCGDCONT_exec (srcId, work_cids[j], &defaultCtx);
1942 set_state_over_cid(work_cids[j], CS_UNDEFINED);
1943 /*lint -fallthrough*/
1944 case CS_DEFINED:
1945 case CS_ACTIVATED:
1946 break;
1947 default:
1948 memset (work_cids, 0, sizeof( *work_cids ) * (i + 1) );
1949 return 0;
1950 }
1951 }
1952 }
1953
1954 return i;
1955 }
1956
1957 /*
1958 +----------------------------------------------------------------------+
1959 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1960 | STATE : finnished ROUTINE : cmhSM_get_pdp_addr_for_CGPADDR |
1961 +----------------------------------------------------------------------+
1962
1963 PURPOSE : return the PDP_address to one cid for the GPRS CGPADDR AT command
1964
1965 */
1966 GLOBAL SHORT cmhSM_get_pdp_addr_for_CGPADDR ( SHORT cid, T_PDP_ADDRESS pdp_adress )
1967 {
1968 T_CONTEXT_STATE c_state; /* state of context */
1969
1970 c_state = get_state_over_cid( cid );
1971
1972 if ( c_state EQ CS_UNDEFINED OR c_state EQ CS_INVALID_STATE )
1973 {
1974 *pdp_adress = 0;
1975 return INVALID_CID;
1976 }
1977
1978 if ( c_state EQ CS_ACTIVATED OR c_state EQ CS_DATA_LINK )
1979 strcpy( pdp_adress, pdp_context[cid - 1].allocated_pdp_addr );
1980 else
1981 strcpy( pdp_adress, pdp_context[cid - 1].con.pdp_addr );
1982
1983 return cid;
1984 }
1985
1986 /*
1987 +----------------------------------------------------------------------+
1988 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
1989 | STATE : finnished ROUTINE : cmhSM_is_smreg_ti_used |
1990 +----------------------------------------------------------------------+
1991
1992 PURPOSE : handle for used smreg_ti
1993
1994 */
1995 GLOBAL BOOL cmhSM_is_smreg_ti_used ( UBYTE smreg_ti, SHORT *cid )
1996 {
1997 SHORT i = 0;
1998
1999 while ( i < MAX_CID )
2000 {
2001 if ( pdp_context[i].smreg_ti EQ smreg_ti)
2002 {
2003 psaSM_PDP_Deactivate ( (USHORT) (1 << pdp_context[i].nsapi), SMREG_LOCAL);
2004 psaGPPP_Terminate( PPP_LOWER_LAYER_UP );
2005
2006 call_waits_in_table = TRUE;
2007 *cid = i + 1;
2008 set_state_over_cid(*cid, CS_CONTEXT_REACTIVATION_1);
2009 return TRUE;
2010 }
2011
2012 i++;
2013 }
2014
2015 return FALSE;
2016 }
2017
2018 /*
2019 +----------------------------------------------------------------------+
2020 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2021 | STATE : finnished ROUTINE : cmhSM_context_reactivation |
2022 +----------------------------------------------------------------------+
2023
2024 PURPOSE :
2025
2026 */
2027 GLOBAL void cmhSM_context_reactivation ( void )
2028 {
2029 T_CGEREP_EVENT_REP_PARAM event;
2030 T_SMREG_PDP_ACTIVATE_IND *sm_ind;
2031 SHORT i = 0;
2032
2033 if ( call_waits_in_table EQ TRUE )
2034 {
2035 call_waits_in_table = FALSE;
2036 /*
2037 * GPRS event reporting
2038 */
2039 sm_ind = &gprs_call_table[current_gprs_ct_index].sm_ind;
2040
2041 cmhSM_pdp_typ_to_string(sm_ind->pdp_type, (char*) &event.act.pdp_type);
2042 memcpy(&event.act.pdp_addr, &sm_ind->pdp_address.buff, sm_ind->pdp_address.c_buff);
2043 event.act.cid = gprs_call_table[current_gprs_ct_index].cid;
2044 for( i = 0 ; i < CMD_SRC_MAX; i++ )
2045 {
2046 R_AT( RAT_CRING, i ) ( CRING_MOD_Gprs, CRING_TYP_GPRS, CRING_TYP_NotPresent );
2047 R_AT( RAT_CGEREP, i ) ( CGEREP_EVENT_NW_REACT, &event );
2048 R_AT( RAT_P_CGEV, i ) ( CGEREP_EVENT_NW_REACT, &event );
2049 }
2050 }
2051 else
2052 {
2053 cmhSM_next_call_table_entry();
2054 }
2055 }
2056
2057 /*
2058 +----------------------------------------------------------------------+
2059 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2060 | STATE : finnished ROUTINE : cmhSM_stop_context_reactivation |
2061 +----------------------------------------------------------------------+
2062
2063 PURPOSE :
2064
2065 */
2066 GLOBAL void cmhSM_stop_context_reactivation ( void )
2067 {
2068
2069 call_waits_in_table = FALSE;
2070 }
2071
2072 GLOBAL void cmhSM_next_call_table_entry( void )
2073 {
2074 current_gprs_ct_index++;
2075
2076 if ( current_gprs_ct_index >= gprs_ct_index )
2077 {
2078 cmhSM_empty_call_table();
2079 }
2080 else
2081 {
2082 cmhSM_context_reactivation();
2083 }
2084 }
2085
2086 /*
2087 +----------------------------------------------------------------------+
2088 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2089 | STATE : finnished ROUTINE : cmhSM_init_GPRS_DTI_list |
2090 +----------------------------------------------------------------------+
2091
2092 PURPOSE : Init all DTI identifier for GPRS.
2093 */
2094 GLOBAL SHORT cmhSM_connect_working_cid ( void )
2095 {
2096 T_GPRS_CONT_CLASS *context_info = &pdp_context[work_cids[cid_pointer] - 1];
2097
2098 switch ( context_info->entity_id )
2099 {
2100 case DTI_ENTITY_PPPS:
2101 srcc_new_count(SRCC_PPPS_SNDCP_LINK);
2102
2103 if (IS_SRC_BT(context_info->owner))
2104 {
2105 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_BLUETOOTH, DTI_ENTITY_PPPS, DTI_ENTITY_SNDCP};
2106 UBYTE dti_id = dti_cntrl_new_dti(DTI_DTI_ID_NOTPRESENT);
2107 dti_cntrl_est_dpath ( dti_id,
2108 entity_list,
2109 3,
2110 SPLIT,
2111 PPP_UART_connect_dti_cb);
2112 }
2113 else
2114 {
2115 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_PPPS, DTI_ENTITY_SNDCP};
2116 dti_cntrl_est_dpath_indirect ((UBYTE)context_info->owner,
2117 entity_list,
2118 2,
2119 SPLIT,
2120 PPP_UART_connect_dti_cb,
2121 DTI_CPBLTY_SER,
2122 (UBYTE)work_cids[cid_pointer]);
2123 }
2124
2125 m_mt_te_link = TRUE;
2126 break;
2127
2128 case DTI_ENTITY_IP:
2129 #ifdef CO_UDP_IP
2130 {
2131 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_IP, DTI_ENTITY_SNDCP};
2132 UBYTE dti_id;
2133 #ifdef FF_SAT_E
2134 if ( satShrdPrm.opchStat EQ OPCH_EST_REQ )
2135 dti_id = simShrdPrm.sat_class_e_dti_id;
2136 else
2137 #endif /* FF_SAT_E */
2138 dti_id = wap_dti_id;
2139
2140 /* link_id should be created in atGD already, so just connect: */
2141 if (!dti_cntrl_est_dpath( dti_id,
2142 entity_list,
2143 2,
2144 APPEND,
2145 IP_UDP_connect_dti_cb))
2146 {
2147 TRACE_EVENT("cmhSM_connect_working_cid: dti_cntrl_est_dpath returned FALSE");
2148 return 0;
2149 }
2150 }
2151 #endif /* CO_UDP_IP */
2152 break;
2153
2154 #ifdef FF_SAT_E
2155 case DTI_ENTITY_SIM:
2156 {
2157 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_SIM, DTI_ENTITY_SNDCP};
2158 /* create a SAT class E DTI ID if not present */
2159 if ( simShrdPrm.sat_class_e_dti_id EQ DTI_DTI_ID_NOTPRESENT )
2160 {
2161 simShrdPrm.sat_class_e_dti_id = dti_cntrl_new_dti(DTI_DTI_ID_NOTPRESENT);
2162 TRACE_EVENT_P1("sat_class_e_dti_id = %d", simShrdPrm.sat_class_e_dti_id);
2163 }
2164 srcc_new_count(SRCC_SIM_SNDCP_LINK);
2165 TRACE_FUNCTION("cmhSM_connect_working_cid:GC_TYPE_SIM");
2166 context_info->link_id_new =
2167 dti_conn_compose_link_id (0, 0, simShrdPrm.sat_class_e_dti_id, DTI_TUPLE_NO_NOTPRESENT);
2168 dti_cntrl_est_dpath( simShrdPrm.sat_class_e_dti_id,
2169 entity_list,
2170 2,
2171 SPLIT,
2172 SIM_SNDCP_connect_dti_cb);
2173 break;
2174 }
2175 #endif /* FF_SAT_E */
2176
2177 case DTI_ENTITY_NULL:
2178 {
2179 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_NULL, DTI_ENTITY_SNDCP};
2180 UBYTE dti_id = dti_cntrl_new_dti(DTI_DTI_ID_NOTPRESENT);
2181 srcc_new_count(SRCC_NULL_SNDCP_LINK);
2182 context_info->link_id_new = dti_conn_compose_link_id (0, 0, dti_id, DTI_TUPLE_NO_NOTPRESENT );
2183
2184 dti_cntrl_est_dpath( dti_id,
2185 entity_list,
2186 2,
2187 SPLIT,
2188 NULL_SNDCP_connect_dti_cb);
2189 break;
2190 }
2191 #if defined (FF_GPF_TCPIP)
2192 case DTI_ENTITY_TCPIP:
2193 {
2194 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_TCPIP, DTI_ENTITY_SNDCP};
2195 UBYTE dti_id;
2196 dti_id = wap_dti_id;
2197 /* link_id should be created in atGD already, so just connect: */
2198 if (!dti_cntrl_est_dpath( dti_id,
2199 entity_list,
2200 2,
2201 SPLIT,
2202 TCPIP_connect_dti_cb))
2203 {
2204 TRACE_EVENT("cmhSM_connect_working_cid: dti_cntrl_est_dpath returned FALSE");
2205 return 0;
2206 }
2207 }
2208 break;
2209 #endif /* FF_GPF_TCPIP */
2210
2211 #if defined(FF_PKTIO) OR defined(FF_TCP_IP) OR defined (FF_PSI)
2212 case DTI_ENTITY_INVALID:
2213 {
2214 T_DTI_ENTITY_ID entity_list[] = {DTI_ENTITY_SNDCP};
2215 srcc_new_count(SRCC_PKTIO_SNDCP_LINK);
2216
2217 dti_cntrl_est_dpath_indirect((UBYTE)context_info->owner,
2218 entity_list,
2219 1, SPLIT,
2220 PKTIO_SNDCP_connect_dti_cb,
2221 DTI_CPBLTY_PKT,
2222 (UBYTE)work_cids[cid_pointer]);
2223 set_state_working_cid( CS_ACTIVATING );
2224 break;
2225 }
2226 #endif /* FF_PKTIO OR FF_TCP_IP OR FF_PSI */
2227 default:
2228 return 0;
2229
2230 }
2231
2232 return 1;
2233 }
2234
2235
2236 GLOBAL void cmhSM_disconnect_cid ( SHORT cid, T_GPRS_CONNECT_TYPE type )
2237 {
2238 T_DTI_CONN_LINK_ID link_id = cmhSM_get_link_id_SNDCP_peer( cid, SNDCP_PEER_NORMAL );
2239
2240 TRACE_FUNCTION("cmhSM_disconnect_cid");
2241 TRACE_EVENT_P1("link_id %d",link_id);
2242 if ( DTI_LINK_ID_NOTPRESENT NEQ link_id)
2243 {
2244 switch ( type )
2245 {
2246 case GC_TYPE_DATA_LINK:
2247 srcc_delete_count( SRCC_PPPS_SNDCP_LINK );
2248 pdp_context[cid - 1].link_id_sn = DTI_LINK_ID_NOTPRESENT;
2249 pdp_context[cid - 1].link_id_new = DTI_LINK_ID_NOTPRESENT;
2250 pdp_context[cid - 1].link_id_uart = DTI_LINK_ID_NOTPRESENT;
2251 pdp_context[cid - 1].entity_id = DTI_ENTITY_INVALID;
2252 m_mt_te_link = FALSE;
2253 break;
2254
2255 case GC_TYPE_WAP:
2256 if(is_gpf_tcpip_call())
2257 {
2258 GPF_TCPIP_STATEMENT(srcc_delete_count( SRCC_TCPIP_SNDCP_LINK ));
2259 }
2260 else
2261 {
2262 srcc_delete_count( SRCC_IP_SNDCP_LINK );
2263 }
2264 pdp_context[cid - 1].link_id_sn = DTI_LINK_ID_NOTPRESENT;
2265 pdp_context[cid - 1].link_id_new = DTI_LINK_ID_NOTPRESENT;
2266 pdp_context[cid - 1].link_id_uart = DTI_LINK_ID_NOTPRESENT;
2267 pdp_context[cid - 1].entity_id = DTI_ENTITY_INVALID;
2268 break;
2269
2270 case GC_TYPE_NULL:
2271 case GC_TYPE_EMAIL:
2272 switch ( pdp_context[cid - 1].entity_id )
2273 {
2274 case DTI_ENTITY_IP:
2275 GPF_TCPIP_STATEMENT(case DTI_ENTITY_TCPIP:)
2276 if(is_gpf_tcpip_call())
2277 {
2278 GPF_TCPIP_STATEMENT(srcc_delete_count( SRCC_TCPIP_SNDCP_LINK ));
2279 }
2280 else
2281 {
2282 srcc_delete_count( SRCC_IP_SNDCP_LINK );
2283 }
2284 dti_cntrl_erase_entry(EXTRACT_DTI_ID(link_id));
2285 break;
2286
2287 case DTI_ENTITY_NULL:
2288 dti_cntrl_entity_disconnected( link_id, DTI_ENTITY_NULL );
2289 srcc_delete_count( SRCC_NULL_SNDCP_LINK );
2290 dti_cntrl_erase_entry(EXTRACT_DTI_ID(link_id));
2291 break;
2292
2293 #if defined(FF_PKTIO) OR defined(FF_TCP_IP) || defined(FF_GPF_TCPIP) OR defined (FF_PSI)
2294 case DTI_ENTITY_PKTIO:
2295 case DTI_ENTITY_PSI:
2296 case DTI_ENTITY_AAA:
2297 srcc_delete_count( SRCC_PKTIO_SNDCP_LINK );
2298 break;
2299 #endif /* FF_PKTIO OR FF_TCP_IP || FF_GPF_TCPIP OR FF_PSI */
2300 }
2301 pdp_context[cid - 1].link_id_sn = DTI_LINK_ID_NOTPRESENT;
2302 pdp_context[cid - 1].link_id_new = DTI_LINK_ID_NOTPRESENT;
2303 pdp_context[cid - 1].link_id_uart = DTI_LINK_ID_NOTPRESENT;
2304 pdp_context[cid - 1].entity_id = DTI_ENTITY_INVALID;
2305 break;
2306
2307 }
2308 }
2309 }
2310
2311 GLOBAL BOOL uart_is_mt_te_link( void )
2312 {
2313
2314 return m_mt_te_link;
2315 }
2316
2317 GLOBAL void cmhSNDCP_Disable( T_DTI_CONN_LINK_ID link_id )
2318 {
2319 SHORT cid = gaci_get_cid_over_link_id( link_id );
2320
2321 /*
2322 * disconnects the context if the link_id is the current link_id of this context
2323 *
2324 * the other case:
2325 * the context is switching to an other peer and the old link_id is requested
2326 * to be disconnected, NOT the context itself
2327 */
2328 if (cmhSM_get_link_id_SNDCP_peer(cid, SNDCP_PEER_NORMAL) EQ link_id)
2329 {
2330 cmhSM_deactivateAContext(CMD_SRC_NONE, cid);
2331 }
2332 }
2333
2334 /*
2335 +----------------------------------------------------------------------+
2336 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2337 | STATE : finnished ROUTINE : cmhSM_connect_context |
2338 +----------------------------------------------------------------------+
2339
2340 PURPOSE : Connect an activated or deactivated PDP context with an entity.
2341 */
2342 GLOBAL SHORT cmhSM_connect_context ( SHORT cid, T_DTI_ENTITY_ID peer, UBYTE ppp_hc, UBYTE msid )
2343 {
2344 ULONG dti_neighbor;
2345 UBYTE dti_direction, hcomp = cmhSM_Get_h_comp() ? SMREG_COMP_BOTH_DIRECT: SMREG_COMP_NEITHER_DIRECT;
2346
2347 TRACE_FUNCTION("cmhSM_connect_context()");
2348
2349 switch ( peer )
2350 {
2351 case DTI_ENTITY_PPPS:
2352 dti_neighbor = (ULONG) PPP_NAME;
2353 dti_direction = SMREG_HOME;
2354 break;
2355 case DTI_ENTITY_NULL:
2356 dti_neighbor = (ULONG) NULL_NAME;
2357 dti_direction = SMREG_NEIGHBOR;
2358 smShrdPrm.direc = DIREC_MO;
2359 break;
2360 case DTI_ENTITY_IP:
2361 dti_neighbor = (ULONG) IP_NAME;
2362 dti_direction = SMREG_NEIGHBOR;
2363 smShrdPrm.direc = DIREC_MO;
2364 #ifdef FF_WAP
2365 if (Wap_Call)
2366 rAT_WAP_start_gprs_login();
2367 #endif /* FF_WAP */
2368 break;
2369 #ifdef FF_SAT_E
2370 case DTI_ENTITY_SIM:
2371 dti_neighbor = (ULONG) SIM_NAME;
2372 dti_direction = SMREG_NEIGHBOR;
2373 smShrdPrm.direc = DIREC_MO;
2374 break;
2375 #endif /* FF_SAT_E */
2376 #if defined(FF_PKTIO) OR defined(FF_TCP_IP) OR defined(FF_PSI)
2377 case DTI_ENTITY_PKTIO:
2378 dti_neighbor = (ULONG) PKTIO_NAME;
2379 dti_direction = SMREG_HOME;
2380 smShrdPrm.direc = DIREC_MO;
2381 break;
2382 case DTI_ENTITY_PSI:
2383 dti_neighbor = (ULONG) PSI_NAME;
2384 dti_direction = SMREG_HOME;
2385 smShrdPrm.direc = DIREC_MO;
2386 break;
2387 case DTI_ENTITY_AAA:
2388 dti_neighbor = (ULONG) RIV_NAME;
2389 dti_direction = SMREG_NEIGHBOR;
2390 smShrdPrm.direc = DIREC_MO;
2391 break;
2392 #endif /* FF_PKTIO OR FF_TCP_IP OR FF_PSI */
2393 #ifdef FF_GPF_TCPIP
2394 case DTI_ENTITY_TCPIP:
2395 dti_neighbor = (ULONG) TCPIP_NAME;
2396 dti_direction = SMREG_NEIGHBOR;
2397 smShrdPrm.direc = DIREC_MO;
2398 break;
2399 #endif /* FF_GPF_TCPIP */
2400 default:
2401 return 0;
2402 }
2403
2404 pdp_context[cid - 1].entity_id = peer;
2405
2406 #ifdef _SIMULATION_
2407 dti_neighbor = 0xfe1234ef;
2408 #endif
2409
2410 if ( DTI_LINK_ID_NOTPRESENT EQ pdp_context[cid - 1].link_id_sn )
2411 { /* context is deactivated */
2412 cmhSM_GetNewNSapi();
2413
2414 psaSM_ActivateReq ( cid,
2415 (UBYTE) (hcomp? ppp_hc: 0),
2416 msid,
2417 hcomp,
2418 pdp_context[cid - 1].link_id_new,
2419 dti_neighbor,
2420 dti_direction );
2421
2422 }
2423 else
2424 { /* context is activated */
2425 EXTERN void psaSN_SwitchReq ( UBYTE nsapi,
2426 ULONG dti_linkid,
2427 ULONG dti_neighbor,
2428 UBYTE dti_direction );
2429
2430 psaSN_SwitchReq ( pdp_context[cid - 1].nsapi,
2431 pdp_context[cid - 1].link_id_new,
2432 dti_neighbor, dti_direction);
2433
2434 dti_cntrl_close_dpath_from_dti_id (EXTRACT_DTI_ID(pdp_context[cid - 1].link_id_sn));
2435 dti_cntrl_entity_disconnected( pdp_context[cid - 1].link_id_sn, DTI_ENTITY_SNDCP );
2436 dti_cntrl_erase_entry( EXTRACT_DTI_ID(pdp_context[cid - 1].link_id_sn) );
2437 }
2438
2439 return 1;
2440 }
2441
2442 GLOBAL void cp_pdp_primitive(T_SMREG_PDP_ACTIVATE_CNF * pdp_activate_cnf,
2443 T_PPP_PDP_ACTIVATE_RES *activate_result)
2444 {
2445
2446 activate_result->ppp_hc = pdp_activate_cnf->ppp_hc;
2447 activate_result->msid = pdp_activate_cnf->msid;
2448
2449 /*
2450 * copy IP address
2451 */
2452 activate_result->ip = pdp_activate_cnf->pdp_address.buff[0];
2453 activate_result->ip = activate_result->ip << 8;
2454 activate_result->ip+= pdp_activate_cnf->pdp_address.buff[1];
2455 activate_result->ip = activate_result->ip << 8;
2456 activate_result->ip+= pdp_activate_cnf->pdp_address.buff[2];
2457 activate_result->ip = activate_result->ip << 8;
2458 activate_result->ip+= pdp_activate_cnf->pdp_address.buff[3];
2459
2460
2461 activate_result->sdu.l_buf = pdp_activate_cnf->sdu.l_buf;
2462 activate_result->sdu.o_buf = 0;
2463
2464 if (pdp_activate_cnf->sdu.l_buf > 0) {
2465 memcpy(activate_result->sdu.buf,
2466 &pdp_activate_cnf->sdu.buf[pdp_activate_cnf->sdu.o_buf >> 3],
2467 pdp_activate_cnf->sdu.l_buf >> 3);
2468 }
2469 }
2470
2471
2472 GLOBAL SHORT cmhSM_context_connected( USHORT nsapi )
2473 {
2474 T_GPRS_CONT_CLASS *context_info = &pdp_context[nsapi_to_cid[nsapi] - 1];
2475 UBYTE ip[4];
2476
2477 TRACE_FUNCTION("cmhSM_context_connected");
2478
2479 context_info->link_id_sn = context_info->link_id_new;
2480 context_info->link_id_new = DTI_LINK_ID_NOTPRESENT;
2481
2482 switch (context_info->entity_id)
2483 {
2484 case DTI_ENTITY_PPPS:
2485 cmhSM_pdp_address_to_ip(&context_info->allocated_pdp_addr, ip);
2486 psaGPPP_PDP_Activate(0, 0, ip,
2487 context_info->network_pco.pco, context_info->network_pco.len);
2488 set_state_working_cid( CS_ESTABLISH_3 );
2489 break;
2490
2491 #ifdef FF_PKTIO
2492 case DTI_ENTITY_PKTIO:
2493 #endif /* FF_PKTIO */
2494 #ifdef FF_PSI
2495 case DTI_ENTITY_PSI:
2496 #endif /* FF_PSI */
2497 #ifdef FF_SAT_E
2498 case DTI_ENTITY_SIM:
2499 #endif /* FF_SAT_E */
2500 #ifdef FF_TCP_IP
2501 case DTI_ENTITY_AAA:
2502 #endif /* FF_TCP_IP */
2503 #if defined (FF_SAT_E) OR defined (FF_TCP_IP) OR defined (FF_PKTIO) OR defined (FF_PSI)
2504 dti_cntrl_entity_connected( context_info->link_id_sn, DTI_ENTITY_SNDCP, DTI_OK);
2505 set_state_working_cid( CS_ACTIVATED );
2506 #if defined(FF_PKTIO) OR defined (FF_PSI)
2507 cmhSM_next_work_cid(smEntStat.curCmd);
2508 #endif /* FF_PKTIO OR FF_PSI */
2509 break;
2510 #endif /* #if defined (FF_SAT_E) OR defined (FF_TCP_IP) OR defined (FF_PKTIO) OR FF_PSI */
2511 } /* switch (context_info->entity_id) */
2512 return 1;
2513 } /* GLOBAL SHORT cmhSM_context_connected( USHORT nsapi ) */
2514
2515
2516 /*
2517 +----------------------------------------------------------------------+
2518 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2519 | STATE : finnished ROUTINE : cmhSM_set_PCO |
2520 +----------------------------------------------------------------------+
2521
2522 PURPOSE : Set a PCO in the context of the cid.
2523 */
2524 GLOBAL void cmhSM_set_PCO( SHORT cid, T_PCO_TYPE pco_type, UBYTE* buf_addr, UBYTE length)
2525 {
2526 T_GPRS_CONT_PCO* dest;
2527
2528 switch ( pco_type )
2529 {
2530 case PCO_USER:
2531 dest = &pdp_context[cid - 1].user_pco;
2532 break;
2533 case PCO_NETWORK:
2534 dest = &pdp_context[cid - 1].network_pco;
2535 break;
2536 }
2537 /*lint -e(644) */ /* all possible types defined */
2538 memcpy(dest->pco, buf_addr, length);
2539 dest->len = length;
2540 }
2541
2542 /*
2543 +----------------------------------------------------------------------+
2544 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2545 | STATE : finnished ROUTINE : cmhSM_get_dti_SNDCP_pper |
2546 +----------------------------------------------------------------------+
2547
2548 PURPOSE : Give back the right DTI-ID for the SNDCP - peer connection.
2549 */
2550 GLOBAL ULONG cmhSM_get_link_id_SNDCP_peer( SHORT cid, T_SNDCP_PEER which )
2551 {
2552
2553 switch ( which )
2554 {
2555 case SNDCP_PEER_NORMAL:
2556 return pdp_context[cid - 1].link_id_new NEQ DTI_LINK_ID_NOTPRESENT ?
2557 pdp_context[cid - 1].link_id_new: pdp_context[cid - 1].link_id_sn;
2558 case SNDCP_PEER_SWITCHED:
2559 return pdp_context[cid - 1].link_id_sn;
2560 }
2561
2562 return DTI_LINK_ID_NOTPRESENT;
2563 }
2564
2565 /*
2566 +----------------------------------------------------------------------+
2567 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2568 | STATE : code ROUTINE : cmhSM_context_deactivated |
2569 +----------------------------------------------------------------------+
2570
2571 PURPOSE : Control the answer of context deactivations
2572 started by an AT command.
2573 */
2574 GLOBAL void cmhSM_context_deactivated( USHORT nsapi_set )
2575 {
2576
2577 switch( working_cgact_actions.state )
2578 {
2579 case T_CDS_RUNNING:
2580 if ( nsapi_set & working_cgact_actions.nsapi_set )
2581 { /* nsapi deactivation is requested */
2582 working_cgact_actions.nsapi_set &= ~nsapi_set;
2583 if ( ! (working_cgact_actions.cid_set OR
2584 working_cgact_actions.nsapi_set ) )
2585 {
2586 R_AT( RAT_OK, working_cgact_actions.srcId ) ( AT_CMD_CGACT );
2587 working_cgact_actions.state = T_CDS_IDLE;
2588 }
2589 }
2590 break;
2591 case T_CDS_IDLE:
2592 break;
2593 }
2594 }
2595
2596 /*
2597 +----------------------------------------------------------------------+
2598 | PROJECT : GSM-PS (8441) MODULE : CMH_SMF |
2599 | STATE : finnished ROUTINE : deactivateAContextForCGACT |
2600 +----------------------------------------------------------------------+
2601
2602 PURPOSE : deactivate a context for CGACT
2603
2604 RETURN VALUE : TRUE - AT_EXCT have to be returned for this context
2605 FALSE - AT_CMPL have to be reported for this context
2606
2607 */
2608 static T_ACI_RETURN deactivateAContextForCGACT(SHORT cid)
2609 {
2610 T_CONTEXT_STATE ctx_state = get_state_over_cid( cid );
2611
2612 SRCC_LINK_NO srcc_link_no= SRCC_INVALID_LINK;
2613 T_DTI_ENTITY_ID dti_entity_id= DTI_ENTITY_INVALID;
2614
2615
2616
2617 TRACE_FUNCTION("deactivateAContextForCGACT()");
2618
2619 #if defined (CO_UDP_IP) || defined (FF_GPF_TCPIP)
2620
2621
2622
2623 /*
2624 * additinal behaviour for WAP
2625 * abort ATD*98# before context activation requested
2626 * 2003.05.06 brz
2627 */
2628 if(is_gpf_tcpip_call()) {
2629 GPF_TCPIP_STATEMENT(srcc_link_no = SRCC_TCPIP_SNDCP_LINK);
2630 GPF_TCPIP_STATEMENT(dti_entity_id = DTI_ENTITY_TCPIP);
2631 }
2632 else {
2633 srcc_link_no = SRCC_IP_SNDCP_LINK;
2634 dti_entity_id = DTI_ENTITY_IP;
2635 }
2636
2637 if( TRUE NEQ srcc_reserve_sources( srcc_link_no, 1 ) AND
2638 DTI_LINK_ID_NOTPRESENT NEQ pdp_context[cid - 1].link_id_new AND
2639 cid EQ work_cids[cid_pointer] OR
2640 pdp_context[cid - 1].entity_id EQ dti_entity_id)
2641 {
2642 psaTCPIP_Deactivate(cmhSM_IP_activate_cb);
2643
2644 if(CS_UNDEFINED EQ ctx_state OR
2645 CS_DEFINED EQ ctx_state )
2646 {
2647 if(is_gpf_tcpip_call()) {
2648 GPF_TCPIP_STATEMENT(wap_state = TCPIP_Deactivation);
2649 }
2650 else {
2651 wap_state = UDPA_Deactivation;
2652 }
2653 dti_cntrl_close_dpath_from_dti_id(
2654 EXTRACT_DTI_ID(cmhSM_get_link_id_SNDCP_peer(cid , SNDCP_PEER_NORMAL)));
2655 }
2656
2657 if( CS_ATTACHING_AFTER_UNDEF EQ ctx_state OR
2658 CS_ATTACHING_AFTER_DEF EQ ctx_state OR
2659 CS_WAITS_FOR_ACTIVATING EQ ctx_state )
2660 {
2661 srcc_delete_count(srcc_link_no);
2662 return cmhSM_deactivateAContext(CMD_SRC_NONE, cid);
2663 }
2664
2665 return AT_EXCT;
2666 }
2667 else
2668 #endif /* CO_UDP_IP || FF_GPF_TCPIP */
2669 {
2670 if( CS_DEFINED NEQ ctx_state AND CS_UNDEFINED NEQ ctx_state )
2671 {
2672 if( CS_ATTACHING_AFTER_UNDEF EQ ctx_state OR
2673 CS_ATTACHING_AFTER_DEF EQ ctx_state OR
2674 CS_WAITS_FOR_ACTIVATING EQ ctx_state )
2675 {
2676 return cmhSM_deactivateAContext(CMD_SRC_NONE, cid);
2677 }
2678 else
2679 {
2680 dti_cntrl_close_dpath_from_dti_id(
2681 EXTRACT_DTI_ID(cmhSM_get_link_id_SNDCP_peer(cid , SNDCP_PEER_NORMAL)));
2682 return AT_EXCT;
2683 }
2684 }
2685 }
2686 return AT_CMPL;
2687 }
2688
2689 /*
2690 +----------------------------------------------------------------------+
2691 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2692 | STATE : finnished ROUTINE : cmhSM_deactivateAContext |
2693 +----------------------------------------------------------------------+
2694
2695 PURPOSE : deactivate some contexts (able for serial multiplexer mode).
2696 */
2697 GLOBAL T_ACI_RETURN cmhSM_deactivateContexts( T_ACI_CMD_SRC srcId, SHORT *cids)
2698 {
2699 T_ACI_RETURN ret_value = AT_CMPL;
2700 T_CONTEXT_STATE state;
2701 USHORT nsapi_set = 0,
2702 cid_set = 0;
2703 SHORT i,
2704 all_cids[MAX_CID + 1] = {1, 2, INVALID_CID};
2705
2706 TRACE_FUNCTION("cmhSM_deactivateContexts");
2707
2708 if( T_CDS_RUNNING EQ working_cgact_actions.state) {
2709 TRACE_EVENT("cgact_ation is running: bussy returned");
2710 return AT_FAIL; /* AT_BUSY */
2711 }
2712
2713 if(INVALID_CID EQ *cids)
2714 {
2715 cids = all_cids;
2716 }
2717
2718 for(i = 0; cids[i] NEQ INVALID_CID; i++)
2719 {
2720 state = pdp_context[cids[i] - 1].state;
2721 #if defined (CO_UDP_IP) || defined (FF_GPF_TCPIP)
2722 #ifndef _SIMULATION_
2723 pdp_context[cids[i] - 1].owner = srcId;
2724 #endif
2725 #else
2726 pdp_context[cids[i] - 1].owner = srcId;
2727 #endif
2728 if(AT_EXCT EQ deactivateAContextForCGACT( cids[i] ))
2729 {
2730 ret_value = AT_EXCT;
2731 if(0 NEQ pdp_context[cids[i] - 1].nsapi)
2732 {
2733 nsapi_set |= (1 << pdp_context[cids[i] - 1].nsapi);
2734
2735 if(state EQ CS_DATA_LINK OR
2736 state EQ CS_ACTIVATED OR
2737 state EQ CS_CONTEXT_REACTIVATION_1)
2738 {
2739 cid_set = 1 << (cids[i] - 1);
2740 }
2741 }
2742 else
2743 {
2744 cid_set = 1 << (cids[i] - 1);
2745 }
2746 }
2747 }
2748
2749 if(cid_set OR nsapi_set) {
2750 working_cgact_actions.state = T_CDS_RUNNING;
2751 working_cgact_actions.nsapi_set = nsapi_set;
2752 working_cgact_actions.cid_set = cid_set;
2753 working_cgact_actions.srcId = srcId;
2754 }
2755
2756 cmhSM_stop_context_reactivation();
2757
2758 return ret_value;
2759 }
2760
2761
2762 /*
2763 +----------------------------------------------------------------------+
2764 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2765 | STATE : finnished ROUTINE : cmhSM_getCurQOS |
2766 +----------------------------------------------------------------------+
2767
2768 PURPOSE : This function returns the current QOS settings.
2769 */
2770 #ifdef FF_SAT_E
2771 GLOBAL T_QOS* cmhSM_getCurQOS( SHORT cid )
2772 {
2773
2774 return &pdp_context[cid - 1].qos;
2775
2776 }
2777 #endif /* FF_SAT_E */
2778
2779 /*
2780 +----------------------------------------------------------------------+
2781 | PROJECT : GPRS (8441) MODULE : CMH_SMF |
2782 | STATE : finnished ROUTINE : cmhSM_deactivateAContext |
2783 +----------------------------------------------------------------------+
2784
2785 PURPOSE : deactivate all contexts (able for serial multiplexer mode).
2786 */
2787 GLOBAL T_ACI_RETURN cmhSM_deactivateAContext( T_ACI_CMD_SRC srcId, SHORT cid )
2788 {
2789 TRACE_FUNCTION("cmhSM_deactivateAContext()") ;
2790
2791 switch( get_state_over_cid( cid ) )
2792 {
2793 case CS_UNDEFINED:
2794 case CS_DEFINED:
2795 /*
2796 * context ís deactivated -> not action necessary
2797 */
2798 break;
2799 case CS_ATTACHING_AFTER_UNDEF:
2800 /*
2801 * CGDATA has started the attach procedure
2802 * before establish data link
2803 * CGDATA has to be stoped
2804 */
2805 set_state_over_cid( cid, CS_UNDEFINED );
2806 psaGMM_Detach( GMMREG_DT_GPRS );
2807 gpppEntStat.curCmd = AT_CMD_NONE;
2808 cid_pointer = 0;
2809 *work_cids = 0;
2810 if(CMD_SRC_NONE EQ srcId)
2811 {
2812 pdp_context[cid - 1].owner = gpppEntStat.entOwn;
2813 gaci_RAT_caller ( RAT_NO_CARRIER, cid, AT_CMD_CGDATA, 0 );
2814 }
2815 return AT_CMPL;
2816
2817 case CS_ATTACHING_AFTER_DEF:
2818 /*
2819 * CGDATA has started the attach procedure
2820 * before establish data link
2821 * CGDATA has to be stoped
2822 */
2823 set_state_over_cid( cid, CS_DEFINED );
2824 psaGMM_Detach( GMMREG_DT_GPRS );
2825 gpppEntStat.curCmd = AT_CMD_NONE;
2826 cid_pointer = 0;
2827 *work_cids = 0;
2828 if(CMD_SRC_NONE EQ srcId)
2829 {
2830 pdp_context[cid - 1].owner = gpppEntStat.entOwn;
2831 gaci_RAT_caller ( RAT_NO_CARRIER, cid, AT_CMD_CGDATA, 0 );
2832 }
2833 return AT_CMPL;
2834
2835 case CS_ESTABLISH_1:
2836 /*
2837 * context not activated, but PPP has to be terminated
2838 */
2839 set_state_over_cid( cid, CS_ABORT_ESTABLISH );
2840 dti_cntrl_entity_disconnected( pdp_context[cid - 1].link_id_new, DTI_ENTITY_SNDCP );
2841 if (uartShrdPrm.escape_seq EQ UART_DETECT_ESC)
2842 {
2843 psaGPPP_Terminate( PPP_LOWER_LAYER_DOWN );
2844 }
2845 else
2846 {
2847 psaGPPP_Terminate( PPP_LOWER_LAYER_UP );
2848 }
2849 uartShrdPrm.escape_seq = UART_DETECT_DTR;
2850
2851 return AT_EXCT;
2852
2853 case CS_DATA_LINK:
2854 /*lint -fallthrough*/
2855 case CS_ESTABLISH_2:
2856 case CS_ESTABLISH_3:
2857 /*
2858 * context has to be deactivated and PPP has to be terminated
2859 */
2860 set_state_over_cid( cid, CS_CONTEXT_REACTIVATION_1 );
2861 psaSM_PDP_Deactivate( (USHORT) (1 << pdp_context[cid - 1].nsapi), SMREG_NONLOCAL);
2862 psaGPPP_Terminate( PPP_LOWER_LAYER_UP );
2863 return AT_EXCT;
2864
2865 case CS_ACTIVATED:
2866 /*
2867 * special handling for context switching
2868 */
2869 if(DTI_LINK_ID_NOTPRESENT NEQ pdp_context[cid - 1].link_id_sn AND
2870 DTI_LINK_ID_NOTPRESENT NEQ pdp_context[cid - 1].link_id_new )
2871 {
2872 return AT_CMPL;
2873 }
2874 /*lint -fallthrough*/
2875 case CS_ACTIVATING:
2876 /*
2877 * +CGACT aborted
2878 */
2879 set_state_over_cid( cid, CS_DEACTIVATE_NORMAL );
2880 psaSM_PDP_Deactivate( (USHORT) (1 << pdp_context[cid - 1].nsapi), SMREG_NONLOCAL);
2881 return AT_EXCT;
2882 case CS_WAITS_FOR_ACTIVATING:
2883 /*
2884 * reset command state it is enough
2885 */
2886 set_state_working_cid( CS_DEFINED );
2887 gpppEntStat.curCmd = AT_CMD_NONE;
2888 smEntStat.curCmd = AT_CMD_NONE;
2889 *work_cids = 0;
2890 cid_pointer = 0;
2891 return AT_CMPL;
2892
2893 case CS_ABORT_ESTABLISH:
2894 case CS_DEACTIVATE_NORMAL:
2895 case CS_BREAKDOWN_LINK_ERROR:
2896 case CS_BREAKDOWN_LINK_NORMAL:
2897 /*
2898 * context is during deactivation procedure -> not action necessary
2899 */
2900 return AT_EXCT;
2901 case CS_CONTEXT_REACTIVATION_1:
2902 case CS_CONTEXT_REACTIVATION_2:
2903 /*
2904 * context is during deactivation procedure
2905 * -> not action for context deactivation or PPP termination necessary
2906 */
2907 return AT_EXCT;
2908 }
2909
2910 return AT_FAIL;
2911 }
2912
2913 GLOBAL BOOL cmhSM_isContextActive( void )
2914 {
2915 int i = SMH_FIRST_FREE_NSAPIS;
2916
2917 while ( i <= SMH_LAST_FREE_NSAPIS AND ( nsapi_to_cid[i] EQ INVALID_CID))
2918 i++;
2919
2920 if ( i > SMH_LAST_FREE_NSAPIS)
2921 return FALSE;
2922
2923 return TRUE;
2924 }
2925
2926 #endif /* GPRS */
2927 /*==== EOF ========================================================*/