comparison g23m-aci/aci/cmh_gmmf.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
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 mobility management ( GMM ).
19 +-----------------------------------------------------------------------------
20 */
21
22 #if defined (GPRS) && defined (DTI)
23
24 #ifndef CMH_GMMF_C
25 #define CMH_GMMF_C
26 #endif
27
28 #include "aci_all.h"
29
30 /*==== INCLUDES ===================================================*/
31 #include "dti.h" /* functionality of the dti library */
32 #include "aci_cmh.h"
33 #include "ati_cmd.h"
34 #include "aci_cmd.h"
35 #include "pcm.h"
36
37 #include "dti_conn_mng.h"
38
39 #include "aci.h"
40 #include "gaci.h"
41 #include "gaci_cmh.h"
42 #include "psa.h"
43 #include "psa_mm.h"
44 #include "psa_gmm.h"
45 #include "psa_sm.h"
46 #include "psa_gppp.h"
47 #include "psa_sim.h"
48
49 #include "cmh.h"
50 #include "cmh_mm.h"
51 #include "cmh_gmm.h"
52 #include "cmh_sm.h"
53 #include "cmh_gppp.h"
54 #include "cmh_sim.h"
55
56 #include "aci_ext_pers.h"
57 #include "aci_slock.h"
58 /*==== CONSTANTS ==================================================*/
59
60 /*==== TYPES ======================================================*/
61
62 /*==== EXPORT =====================================================*/
63
64 /*==== VARIABLES ==================================================*/
65 static T_ATTACH_STATE attach_state;
66 static T_plmn _plmn;
67
68 #ifdef SIM_PERS
69 EXTERN T_ACI_SLOCK_SHARED AciSLockShrd;
70 #endif
71
72 LOCAL BOOL frstFlg = TRUE; /* flags first attempt */
73 /*==== FUNCTIONS ==================================================*/
74
75 /*
76 +--------------------------------------------------------------------+
77 | PROJECT : GPRS (8441) MODULE : CMH_GMM |
78 | STATE : finished ROUTINE : cmhGMM_Init |
79 +--------------------------------------------------------------------+
80
81 PURPOSE : Fill variables for the own use with default values.
82 */
83 GLOBAL void cmhGMM_Init (void)
84 {
85 gmmEntStat.curCmd = AT_CMD_NONE;
86 gmmEntStat.entOwn = CMD_SRC_NONE;
87
88 frstFlg = TRUE;
89 cmhGMM_Set_state ( AS_MOBILE_OFF );
90 _plmn.v_plmn = INVLD_PLMN;
91
92 }
93
94 /*
95 +--------------------------------------------------------------------+
96 | PROJECT : GPRS (8441) MODULE : CMH_GMM |
97 | STATE : finished ROUTINE : cmhGMM_Get_state |
98 +--------------------------------------------------------------------+
99
100 PURPOSE : Get state of attachment.
101 */
102 GLOBAL T_ATTACH_STATE cmhGMM_Get_state ( void )
103 {
104
105 return attach_state;
106
107 }
108
109 /*
110 +--------------------------------------------------------------------+
111 | PROJECT : GPRS (8441) MODULE : CMH_GMM |
112 | STATE : finished ROUTINE : cmhGMM_Set_state |
113 +--------------------------------------------------------------------+
114
115 PURPOSE : Set state of attachment.
116 */
117 GLOBAL void cmhGMM_Set_state ( T_ATTACH_STATE state )
118 {
119
120 if ( state > AS_INVALID_STATE AND state <= AS_SUSPENTED )
121 attach_state = state;
122
123 }
124
125 /*
126 +----------------------------------------------------------------------+
127 | PROJECT : GPRS (8441) MODULE : CMH_GMM |
128 | STATE : finished ROUTINE : cmhGMM_attach_if_necessary |
129 +----------------------------------------------------------------------+
130
131 PURPOSE : Set state of attachment.
132 */
133 GLOBAL T_ACI_RETURN cmhGMM_attach_if_necessary ( T_ACI_CMD_SRC srcId, T_ACI_AT_CMD curCmd )
134 {
135 UBYTE mobileClass = PERCENT_CGCLASS_MAX;
136
137 if( AS_MOBILE_OFF EQ attach_state )
138 {
139 return AT_FAIL;
140 }
141
142 /* normal case: if mobile not GPRS attached */
143 if ( AS_DETACHED EQ attach_state )
144 {
145 mobileClass = gmmShrdPrm.mobile_class;
146 }
147
148 /* case for NMOIII: if class BX -> BG requested */
149 if( PERCENT_CGCLASS_BX EQ gaciMobileClass.current AND
150 GMMREG_CLASS_BG NEQ gmmShrdPrm.mobile_class )
151 {
152 mobileClass = GMMREG_CLASS_BG;
153 }
154
155 if( PERCENT_CGCLASS_MAX NEQ mobileClass )
156 {
157 gmmShrdPrm.last_attach_type = gmmShrdPrm.current_attach_type;
158 gmmEntStat.entOwn = srcId;
159 gmmEntStat.curCmd = curCmd;
160
161 return cmhGMM_attach(mobileClass);
162 }
163
164 return AT_CMPL;
165 }
166
167 /*
168 +--------------------------------------------------------------------------+
169 | PROJECT : GPRS (8441) MODULE : CMH_GMM |
170 | STATE : finished ROUTINE : cmhGMM_inform_other_psa |
171 +--------------------------------------------------------------------------+
172
173 PURPOSE : inform other PSA's if a automatic attach is passed or failed
174 */
175 GLOBAL SHORT cmhGMM_inform_other_psa ( SHORT state )
176 {
177 /* possible commands */
178 switch ( gmmEntStat.curCmd )
179 {
180 case( AT_CMD_CGCLASS ):
181 case( AT_CMD_CGATT ):
182 default:
183 /* no information necessary */
184 return 0;
185 case( AT_CMD_CGDATA ):
186 case( AT_CMD_CGACT ):
187 cmhSM_GprsAttached((T_GPRS_ATTACH_STATE)state);
188 return 1;
189 }
190
191 }
192
193 /*
194 +--------------------------------------------------------------------------+
195 | PROJECT : GPRS (8441) MODULE : CMH_GMM |
196 | STATE : finished ROUTINE : cmhGMM_isClassCG |
197 +--------------------------------------------------------------------------+
198
199 PURPOSE : return true if the
200 */
201 GLOBAL BOOL cmhGMM_isClassCG ( void )
202 {
203 if (gmmShrdPrm.requested_mobile_class EQ GMMREG_CLASS_CG)
204 return TRUE;
205
206 return FALSE;
207 }
208
209 GLOBAL SHORT psaG_MM_CMD_REG ( void )
210 {
211 UBYTE attach_type;
212 /*
213 * Set automatic registration mode in MM
214 */
215 psaG_MM_CMD_SET_REGMD ( MODE_AUTO );
216
217 /*
218 *-------------------------------------------------------------------
219 * call the corresponding SAP subroutine
220 *-------------------------------------------------------------------
221 */
222 if ( gmmShrdPrm.mobile_class NEQ GMMREG_CLASS_CG )
223 {
224 gmmShrdPrm.requested_mobile_class = gmmShrdPrm.mobile_class;
225
226 attach_type = cmhGMM_requested_attach_type(GMMU_AT_GSM, gmmShrdPrm.requested_mobile_class);
227
228 /* OVK Set proper service mode dependent on Sim lock state */
229 #ifdef SIM_PERS
230 if (AciSLockShrd.blocked EQ TRUE)
231 {
232 gmmShrdPrm.service_mode = SERVICE_MODE_LIMITED;
233 }
234 else
235 #endif
236 if ( simShrdPrm.imei_blocked EQ TRUE )
237 {
238 gmmShrdPrm.service_mode = SERVICE_MODE_LIMITED;
239 }
240 else
241 {
242 gmmShrdPrm.service_mode = SERVICE_MODE_FULL;
243 }
244
245 psaGMM_Attach( gmmShrdPrm.requested_mobile_class,
246 attach_type,
247 gmmShrdPrm.service_mode);
248
249 frstFlg = FALSE;
250 }
251 else
252 {
253 PALLOC (mmr_nreg_ind, MMR_NREG_IND);
254
255 mmr_nreg_ind->service = NREG_NO_SERVICE;
256 mmr_nreg_ind->search_running = SEARCH_NOT_RUNNING;
257 psa_mmr_nreg_ind(mmr_nreg_ind);
258 }
259
260
261 return 0;
262 }
263
264 GLOBAL SHORT psaG_MM_CMD_DEREG ( UBYTE detach_type )
265 {
266 /*
267 *-------------------------------------------------------------------
268 * process parameter
269 *-------------------------------------------------------------------
270 */
271 frstFlg = TRUE;
272
273 psaGMM_Detach( detach_type );
274
275 return 0;
276 }
277
278 GLOBAL SHORT psaG_MM_CMD_NET_SRCH ( void )
279 {
280
281 /*
282 * Set manual registration mode in MM
283 */
284 psaG_MM_CMD_SET_REGMD ( MODE_MAN );
285
286 /*
287 *-------------------------------------------------------------------
288 * process parameter
289 *-------------------------------------------------------------------
290 */
291 if( frstFlg EQ TRUE
292 #ifdef FF_DUAL_SIM
293 AND CFUNfun EQ CFUN_FUN_Full
294 #endif /*FF_DUAL_SIM*/
295 )
296 {
297 gmmShrdPrm.requested_mobile_class = gmmShrdPrm.mobile_class;
298
299 psaGMM_Attach( gmmShrdPrm.requested_mobile_class,
300 cmhGMM_requested_attach_type(GMMU_AT_GSM, gmmShrdPrm.requested_mobile_class),
301 SERVICE_MODE_FULL );
302 frstFlg = FALSE;
303 }
304 else
305 {
306 psaGMM_Net_Req();
307 }
308
309 return 0;
310 }
311
312 GLOBAL SHORT psaG_MM_CMD_NET_SEL ( void )
313 {
314 /*
315 *-------------------------------------------------------------------
316 * process parameter for both calls
317 *-------------------------------------------------------------------
318 */
319
320 /*
321 * Set manual registration mode in MM
322 */
323 psaG_MM_CMD_SET_REGMD ( MODE_MAN );
324
325 /*
326 *-------------------------------------------------------------------
327 * process parameter
328 *-------------------------------------------------------------------
329 */
330 gmmShrdPrm.requested_mobile_class = gmmShrdPrm.mobile_class;
331
332 /*
333 *-------------------------------------------------------------------
334 * call the corresponding SAP subroutine
335 *-------------------------------------------------------------------
336 */
337 psaGMM_Plmn_res( gmmShrdPrm.requested_mobile_class,
338 cmhGMM_requested_attach_type(GMMU_AT_GSM, gmmShrdPrm.requested_mobile_class),
339 &mmShrdPrm.slctPLMN );
340
341 frstFlg = FALSE;
342
343 return 0;
344 }
345
346 GLOBAL SHORT psaG_MM_CMD_SET_REGMD ( UBYTE mode )
347 {
348
349 /*
350 *-------------------------------------------------------------------
351 * process parameter
352 *-------------------------------------------------------------------
353 */
354 switch (mode)
355 {
356 case MODE_AUTO:
357 psaGMM_Plmn_mode_req( GMMREG_NET_SEL_MODE_AUTO );
358 break;
359 case MODE_MAN:
360 psaGMM_Plmn_mode_req( GMMREG_NET_SEL_MODE_MAN );
361 break;
362 default:
363 return -1;
364 }
365
366 /*
367 *-------------------------------------------------------------------
368 * call the corresponding SAP subroutine
369 *-------------------------------------------------------------------
370 */
371 return 0;
372 }
373
374 GLOBAL SHORT gprs_sim_inserted ( void )
375 {
376
377 /* OVK Set proper service mode dependent on Sim lock state */
378 #ifdef SIM_PERS
379 if (AciSLockShrd.blocked EQ TRUE)
380 {
381 gmmShrdPrm.service_mode = SERVICE_MODE_LIMITED;
382 }
383 else
384 #endif
385 if ( simShrdPrm.imei_blocked EQ TRUE )
386 {
387 gmmShrdPrm.service_mode = SERVICE_MODE_LIMITED;
388 }
389 else
390 {
391 gmmShrdPrm.service_mode = SERVICE_MODE_FULL;
392 }
393 gmmShrdPrm.mobile_class = default_mobile_class;
394
395 cmhGMM_Set_state( AS_DETACHED );
396
397 return 0;
398 }
399
400 GLOBAL T_ACI_RETURN cmhGMM_attach ( UBYTE mobile_class )
401 {
402
403 TRACE_FUNCTION ("cmhGMM_attach()");
404
405 if ( cmhGMM_Get_state() EQ AS_MOBILE_OFF )
406 {
407 gmmEntStat.curCmd = AT_CMD_NONE;
408 gmmShrdPrm.requested_mobile_class = gmmShrdPrm.mobile_class = default_mobile_class = mobile_class;
409
410 return AT_CMPL;
411 }
412
413 gmmShrdPrm.requested_mobile_class = mobile_class;
414 gmmShrdPrm.last_attach_type = gmmShrdPrm.current_attach_type;
415
416 gmmShrdPrm.requested_attach_type = cmhGMM_requested_attach_type(GMMU_AT_GPRS, gmmShrdPrm.requested_mobile_class);
417
418 psaGMM_Attach( gmmShrdPrm.requested_mobile_class,
419 gmmShrdPrm.requested_attach_type,
420 gmmShrdPrm.service_mode);
421
422 return AT_EXCT;
423 }
424
425 /*
426 +--------------------------------------------------------------------------+
427 | PROJECT : GPRS (8441) MODULE : CMH_GMM |
428 | STATE : finished ROUTINE : cmhGMM_allContextsDeactivated |
429 +--------------------------------------------------------------------------+
430
431 PURPOSE : For automatic detaching the mobile after context deactivation.
432 */
433 GLOBAL void cmhGMM_allContextsDeactivated ( void )
434 {
435
436 TRACE_FUNCTION ("cmhGMM_allContextsDeactivated()");
437
438 /* case for NMOIII: if class BX -> BC requested */
439 /* in this particular case an attach would be first sent just to inform
440 GMM of the class change.
441 It is OK if an attach_req is sent and then right after a detach_req. */
442 if( PERCENT_CGCLASS_BX EQ gaciMobileClass.current AND
443 GMMREG_CLASS_BC NEQ gmmShrdPrm.mobile_class )
444 {
445 gmmShrdPrm.last_attach_type = gmmShrdPrm.current_attach_type;
446
447 cmhGMM_attach((UBYTE)GMMREG_CLASS_BC);
448 }
449
450 /* GPRS detach req will be sent only when the automatic detach mode is ON and
451 the curCmd of mmEntStat should not be equal to CFUN.If user uses CFUN to deregister
452 from the network or to switch the mobile to power off mode, though automatic detach
453 mode is ON it will not send one more gmmreg_detach_req. */
454 if ( automatic_detach_mode EQ CGAATT_DETACH_MODE_ON AND mmEntStat.curCmd NEQ AT_CMD_CFUN)
455 {
456 psaGMM_Detach( GMMREG_DT_GPRS );
457 }
458 }
459
460 GLOBAL UBYTE cmhGMM_requested_attach_type ( T_GMM_USER usr, UBYTE m_class )
461 {
462 UBYTE attach_type = GMMREG_AT_COMB;
463
464 switch ( m_class )
465 {
466 case GMMREG_CLASS_A:
467 case GMMREG_CLASS_B:
468 case GMMREG_CLASS_BG:
469 case GMMREG_CLASS_BC:
470 switch ( usr )
471 {
472 case GMMU_AT_GSM:
473 if ( automatic_attach_mode NEQ CGAATT_ATTACH_MODE_AUTOMATIC AND
474 ( AS_DETACHED EQ attach_state OR AS_MOBILE_OFF EQ attach_state ))
475
476 {
477 attach_type = GMMREG_AT_IMSI;
478 }
479 break;
480 case GMMU_AT_GPRS:
481 if ( mmShrdPrm.creg_status EQ CREG_STAT_NoSearch OR
482 mmShrdPrm.creg_status EQ CREG_STAT_Denied OR
483 mmShrdPrm.creg_status EQ CREG_STAT_Unknown OR
484 mmShrdPrm.creg_status EQ CREG_STAT_NotPresent)
485 {
486 attach_type = GMMREG_AT_GPRS;
487 }
488 else if ( mmShrdPrm.creg_status EQ CREG_STAT_Search AND
489 mmEntStat.curCmd EQ AT_CMD_NONE )
490 {
491 attach_type = GMMREG_AT_GPRS; /* Check when the registration is initiated */
492 }
493 break;
494 }
495 break;
496 case GMMREG_CLASS_CG:
497 attach_type = GMMREG_AT_GPRS;
498 break;
499 case GMMREG_CLASS_CC:
500 attach_type = GMMREG_AT_IMSI;
501 break;
502 }
503
504 gmmShrdPrm.requested_attach_type = attach_type;
505
506 return attach_type;
507 }
508
509 GLOBAL UBYTE cmhGMM_translate_gmm_cause_to_nreg_cs ( USHORT cause )
510 {
511 switch( cause )
512 {
513 case GMMCS_POWER_OFF:
514 case GMMCS_NO_SERVICE:
515 return NREG_NO_SERVICE;
516
517 /* ####!!!! Translated by GMM? */
518 /* case RRCS_ABORT_CEL_SEL_FAIL:
519 return NREG_NO_SERVICE; */
520
521 case GMMCS_LIMITED_SERVICE:
522 return NREG_LIMITED_SERVICE;
523
524 /*
525 * This catches all remaining GMM originated causes and
526 * all MM originated causes.
527 */
528 default:
529 return NREG_LIMITED_SERVICE;
530 }
531 }
532
533 /*
534 * COPS will be request an only GSM registration.
535 * If the ME is an only GPRS mobile, then it is impossible to request only GSM.
536 * This patch will be eliminate an error in this situation.
537 *
538 * brz, 02.07.01
539 */
540 GLOBAL BOOL cmhGMM_class_eq_CG ( void )
541 {
542
543 if ( gmmShrdPrm.mobile_class EQ GMMREG_CLASS_CG )
544 {
545 /*
546 * If the mobile class is CG than the protocol stack
547 * will be attached automaticly.
548 *
549 * patch brz, 090701
550 */
551 /*if ( automatic_attach_mode EQ CGAATT_ATTACH_MODE_AUTOMATIC )*/
552 {
553 gmmShrdPrm.requested_mobile_class = GMMREG_CLASS_CG;
554
555 psaGMM_Attach( GMMREG_CLASS_CG, GMMREG_AT_GPRS, gmmShrdPrm.service_mode);
556 }
557
558 return TRUE;
559 }
560
561 return FALSE;
562 }
563
564 /*
565 +---------------------------------------------------------------------------------+
566 | PROJECT : GSM-PS (6147) MODULE : CMH_GMMF |
567 | ROUTINE : cmhGMM_send_NetworkRegistrationStatus |
568 +---------------------------------------------------------------------------------+
569
570 PURPOSE : report function
571 */
572 GLOBAL void cmhGMM_send_NetworkRegistrationStatus( T_CGREG_STAT cgreg, T_P_CGREG_STAT p_cgreg )
573 {
574 USHORT src;
575
576 TRACE_FUNCTION("cmhGMM_send_NetworkRegistrationStatus");
577
578 /* +CGREG */
579 gmmShrdPrm.cgreg_stat = cgreg;
580
581 for( src = 0 ; src < CMD_SRC_MAX; src++ )
582 {
583 R_AT( RAT_CGREG, (T_ACI_CMD_SRC)src ) (cgreg, gmmShrdPrm.lac, gmmShrdPrm.cid);
584 }
585
586 /* %CGREG */
587 cmhGMM_send_percentNetworkRegistrationStatus( p_cgreg );
588 }
589
590 /*
591 +----------------------------------------------------------------------------------------+
592 | PROJECT : GSM-PS (6147) MODULE : CMH_GMMF |
593 | ROUTINE : cmhGMM_send_percentNetworkRegistrationStatus |
594 +----------------------------------------------------------------------------------------+
595
596 PURPOSE : report function
597 */
598 GLOBAL void cmhGMM_send_percentNetworkRegistrationStatus( T_P_CGREG_STAT p_cgreg )
599 {
600 USHORT src;
601 BOOL bActiveContext = FALSE;
602
603 TRACE_FUNCTION("cmhGMM_send_percentNetworkRegistrationStatus");
604
605 /* %CGREG */
606 gmmShrdPrm.p_cgreg_stat = p_cgreg;
607
608 bActiveContext = cmhSM_isContextActive();
609
610 for( src = 0 ; src < CMD_SRC_MAX; src++ )
611 {
612 R_AT( RAT_P_CGREG, (T_ACI_CMD_SRC)src ) (p_cgreg, gmmShrdPrm.lac, gmmShrdPrm.cid, bActiveContext );
613 }
614 }
615
616 /*
617 +---------------------------------------------------------------------------------+
618 | PROJECT : GSM-PS (6147) MODULE : CMH_GMMF |
619 | ROUTINE : cmhGMM_setPLMN |
620 +---------------------------------------------------------------------------------+
621
622 PURPOSE : report function
623 */
624 GLOBAL void cmhGMM_setPLMN(T_plmn *plmn)
625 {
626 memcpy(&_plmn, plmn, sizeof(T_plmn));
627 }
628
629 /*
630 +---------------------------------------------------------------------------------+
631 | PROJECT : GSM-PS (6147) MODULE : CMH_GMMF |
632 | ROUTINE : cmhGMM_isPLMN_Home |
633 +---------------------------------------------------------------------------------+
634
635 PURPOSE : report function
636 */
637 GLOBAL UBYTE cmhGMM_isPLMN_Home( void )
638 {
639 SHORT mccCur, mncCur; /* holds MCC and MCC of current PLMN */
640
641 if ( _plmn.v_plmn EQ VLD_PLMN )
642 {
643 cmhMM_CnvrtPLMN2INT( _plmn.mcc,
644 _plmn.mnc,
645 &mccCur, &mncCur );
646 if (cmhSIM_plmn_is_hplmn (mccCur, mncCur))
647 {
648 return 1; /* yes, it is */
649 }
650 }
651
652 return 0; /* no, it isn't */
653 }
654
655 GLOBAL T_ACI_RETURN cmhGMM_contextActivation( T_ACI_CMD_SRC srcId, T_ACI_AT_CMD curCmd )
656 {
657
658 /* case for NMOIII: if class BX -> BG requested */
659 if( PERCENT_CGCLASS_BX EQ gaciMobileClass.current AND
660 GMMREG_CLASS_BG NEQ gmmShrdPrm.mobile_class )
661 {
662 gmmEntStat.entOwn = srcId;
663 gmmEntStat.curCmd = curCmd;
664
665 gmmShrdPrm.last_attach_type = gmmShrdPrm.current_attach_type;
666
667 return cmhGMM_attach((UBYTE)GMMREG_CLASS_BG);
668 }
669
670 return AT_CMPL;
671
672 }
673
674 /*
675 +---------------------------------------------------------------------------------+
676 | PROJECT : GSM-PS (6147) MODULE : CMH_GMMF |
677 | ROUTINE : cmhGMM_isPLMN_Valid |
678 +---------------------------------------------------------------------------------+
679
680 PURPOSE : Checks if _plmn contains a valid PLMN
681 */
682 GLOBAL UBYTE cmhGMM_isPLMN_Valid (void)
683 {
684 if ( _plmn.v_plmn EQ VLD_PLMN )
685 {
686 return 1;
687 }
688 return 0;
689 }
690
691 #endif /* GPRS */
692 /*==== EOF ========================================================*/