comparison src/aci2/aci/psa_gmmf.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 for the protocol
18 | stack adapter for the registration part of mobility
19 | management ( GMM ).
20 +-----------------------------------------------------------------------------
21 */
22
23 #if defined (GPRS) && defined (DTI)
24
25 #ifndef PSA_GMMF_C
26 #define PSA_GMMF_C
27 #endif
28
29 #include "aci_all.h"
30
31 #undef TRACING
32 /*==== INCLUDES ===================================================*/
33 #include "aci_cmh.h"
34 #include "ati_cmd.h"
35 #include "aci_cmd.h"
36
37 #include "dti.h"
38 #include "dti_conn_mng.h"
39 #include "dti_cntrl_mng.h"
40
41 #include "gaci_cmh.h"
42 #include "gaci.h"
43 #include "aci.h"
44 #include "psa.h"
45 #include "psa_gmm.h"
46 #include "cmh.h"
47 #include "cmh_gmm.h"
48
49 /*==== CONSTANTS ==================================================*/
50
51 /*==== TYPES ======================================================*/
52
53
54 /*==== EXPORT =====================================================*/
55
56
57 /*==== VARIABLES ==================================================*/
58
59 /*==== FUNCTIONS ==================================================*/
60
61
62 /*
63 +-------------------------------------------------------------------+
64 | PROJECT : GPRS (8441) MODULE : PSA_GMMF |
65 | ROUTINE : psaGMM_Init |
66 +-------------------------------------------------------------------+
67
68 PURPOSE : initialize the protocol stack adapter for GMM.
69
70 */
71
72 /* MACRO: initializer for set parameter */
73 #ifdef INIT_SET_PARM
74 #undef INIT_SET_PARM
75 #endif
76
77 #define INIT_SET_PARM( dest, def )\
78 for( LpCnt = 0; LpCnt < OWN_MAX; LpCnt++ )\
79 gmmShrdPrm.setPrm[LpCnt].dest = def
80
81 GLOBAL void psaGMM_Init ( UBYTE auto_attach, UBYTE auto_detach, UBYTE mobile_class )
82 {
83 UBYTE LpCnt; /* holds loop counter for macro */
84
85 /*
86 *-------------------------------------------------------------------
87 * set default parms
88 *-------------------------------------------------------------------
89 */
90 default_mobile_class = mobile_class;
91 gmmShrdPrm.mobile_class = default_mobile_class;
92 gmmShrdPrm.requested_mobile_class = gmmShrdPrm.mobile_class;
93 gmmShrdPrm.last_attach_type = ATTACH_TYPE_DETACHED;
94 gmmShrdPrm.current_attach_type = ATTACH_TYPE_DETACHED;
95 gmmShrdPrm.requested_attach_type = ATTACH_TYPE_DETACHED;
96
97 automatic_attach_mode = auto_attach;
98 automatic_detach_mode = auto_detach;
99
100 /*
101 * GlumPs
102 * ANS 15-Mar-00
103 * GMM knows that SIM is not inserted
104 * gmmShrdPrm.service_mode = SERVICE_MODE_LIMITED;
105 */
106 gmmShrdPrm.service_mode = SERVICE_MODE_FULL;
107
108 for (LpCnt = 0; LpCnt < MAX_PLMN_ID; LpCnt++)
109 gmmShrdPrm.gprs_status[LpCnt] = GMMREG_GSM_ONLY;
110
111 gmmShrdPrm.gprs_indicator = P_CREG_GPRS_Support_Unknown; /* ACI-SPR-24473 */
112
113 gmmShrdPrm.cgreg_stat = CGREG_STAT_NOT_REG; /* +CGREG status */
114 gmmShrdPrm.p_cgreg_stat = P_CGREG_STAT_NOT_REG; /* %CGREG status */
115 gmmShrdPrm.lac = NOT_PRESENT_16BIT; /* current cell coordinates */
116 gmmShrdPrm.cid = NOT_PRESENT_16BIT;
117
118 switch(gmmShrdPrm.mobile_class)
119 {
120 case GMMREG_CLASS_A :
121 gaciMobileClass.current = PERCENT_CGCLASS_A;
122 break;
123 case GMMREG_CLASS_B :
124 gaciMobileClass.current = PERCENT_CGCLASS_B;
125 break;
126 case GMMREG_CLASS_BC :
127 gaciMobileClass.current = PERCENT_CGCLASS_BC;
128 break;
129 case GMMREG_CLASS_BG :
130 gaciMobileClass.current = PERCENT_CGCLASS_BG;
131 break;
132 case GMMREG_CLASS_CC :
133 gaciMobileClass.current = PERCENT_CGCLASS_CC;
134 break;
135 case GMMREG_CLASS_CG :
136 gaciMobileClass.current = PERCENT_CGCLASS_CG;
137 break;
138 default:
139 gaciMobileClass.current = PERCENT_CGCLASS_MAX;
140 break;
141 }
142 }
143
144 #ifdef GMM_PRIMITIVE_TRACES_ADVANCED
145
146 char* dbg_attachType(UBYTE attach_type)
147 {
148 char* type[3] ={"GPRS", "IMSI", "COMB"};
149 return type[attach_type - 1];
150 }
151 char* dbg_detachType(UBYTE detach_type)
152 {
153 char* type[8] ={"GPRS", "IMSI", "COMB",
154 "SIM_REM", "POWER_OFF", "DISABLE_GPRS",
155 "LIM_SERV", "SOFT_OFF"};
156 return type[detach_type - 1];
157 }
158 char* dbg_mobileClass(UBYTE mobile_class)
159 {
160 char* running[6] ={"A", "B", "BC",
161 "BG", "CC", "CG"};
162 return running[mobile_class - 1];
163
164 }
165 char* dbg_searchRunning(UBYTE search_running)
166 {
167 char* running[2] ={"NOT_RUN", "SEARCH_RUN"};
168 return running[search_running];
169 }
170 char* dbg_cellState(UBYTE cell_state)
171 {
172 char* state[8] ={"FULL_SERV", "LIM_SERV", "CS_CALL",
173 "GPRS_NOT_SUP", "TRY_TO_UPD"};
174 return state[cell_state];
175 }
176
177 #endif /* GMM_PRIMITIVE_TRACES_ADVANCED */
178
179 /*
180 +-----------------------------------------------------------------------------+
181 | PROJECT : GSM-PS (6147) MODULE : PSA_GMMF |
182 | ROUTINE : is_GMM_searching_stoped |
183 +-----------------------------------------------------------------------------+
184
185 PURPOSE : Answer the Question: "Is the automatic searching from GMM stoped?"
186 */
187 LOCAL BOOL is_GMM_searching_stoped (USHORT cause)
188 {
189 switch ( cause )
190 {
191 case MMCS_IMSI_IN_HLR: /* Network cause #2 via MM */
192 /* GMMCS_IMSI_UNKNOWN: */ /* Via GMM, this doesn't stop GPRS */
193
194 case MMCS_ILLEGAL_MS: /* Network cause #3 */
195 case GMMCS_ILLEGAL_MS:
196
197 case MMCS_ILLEGAL_ME: /* Network cause #2 */
198 case GMMCS_ILLEGAL_ME:
199
200 /* No MMCS_GPRS_NOT_ALLOWED */ /* Doesn't exist in MM protocol */
201 case GMMCS_GPRS_NOT_ALLOWED: /* Network cause #7 */
202
203 /* No MMCS_GSM_GPRS_NOT_ALLOWED */ /* Doesn't exist in MM protocol */
204 case GMMCS_GSM_GPRS_NOT_ALLOWED: /* Network cause #8 */
205
206 case MMCS_SIM_REMOVED: /* SIM has been removed/disabled */
207 case GMMCS_SIM_REMOVED:
208
209 case MMCS_AUTHENTICATION_REJECTED: /* AUTHENTICATION REJECT received */
210 case GMMCS_AUTHENTICATION_REJECTED:
211
212 /* No MMCS_POWER_OFF */ /* Swiched off */
213 case GMMCS_POWER_OFF:
214 return(TRUE); /* yes, it is stoped */
215 }
216
217 return(FALSE); /* no, it isn't stoped */
218 }
219
220
221 typedef enum
222 {
223 NRS_NOT_REGISTERED,
224 NRS_SEARCHING,
225 NRS_REGISTERED
226
227 } T_NETWORK_REGISTRATION_STATUS;
228
229 /*
230 +-----------------------------------------------------------------------------+
231 | PROJECT : GSM-PS (6147) MODULE : PSA_GMMF |
232 | ROUTINE : is_GMM_searching_stoped |
233 +-----------------------------------------------------------------------------+
234
235 PURPOSE : Answer the Question: "Is the automatic searching from GMM stoped?"
236 */
237 LOCAL T_NETWORK_REGISTRATION_STATUS
238 GMM_detached ( T_NETWORK_REGISTRATION_STATUS stat,
239 BOOL suspended,
240 UBYTE detach_type,
241 USHORT cause,
242 ULONG caller )
243 {
244 if ( detach_type NEQ GMMREG_DT_IMSI )
245 {
246 /* special causes stops in every state the GMM searching*/
247 if ( is_GMM_searching_stoped(cause) )
248 {
249 if( stat NEQ NRS_NOT_REGISTERED )
250 {
251 if ( caller EQ GMMREG_ATTACH_REJ &&
252 ( gmmShrdPrm.last_attach_type EQ GMMREG_AT_IMSI ||
253 gmmShrdPrm.last_attach_type EQ ATTACH_TYPE_DETACHED ) )
254 {
255 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_DEN, P_CGREG_STAT_REG_DEN );
256 }
257 else
258 {
259 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_NOT_REG, P_CGREG_STAT_NOT_REG );
260 }
261 return NRS_NOT_REGISTERED;
262 }
263 }
264 else
265 {
266 if ( ( stat EQ NRS_REGISTERED && !suspended ) || /* in this state always */
267 ( stat EQ NRS_REGISTERED && suspended ) && /* in this state only with special detach_type */
268 ( detach_type EQ GMMREG_DT_LIMITED_SERVICE ||
269 detach_type EQ GMMREG_DT_SIM_REMOVED ) )
270 {
271 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_SEARCHING, P_CGREG_STAT_SEARCHING );
272 return NRS_SEARCHING;
273 }
274 }
275 }
276 else /* detach_type EQ GMMREG_DT_IMSI -> attach_type EQ GPRS*/
277 {
278 if( stat NEQ NRS_REGISTERED )
279 {
280 if ( cmhGMM_isPLMN_Home())
281 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_HOME, P_CGREG_STAT_REG_HOME ); }
282 else
283 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_ROAM, P_CGREG_STAT_REG_ROAM ); }
284
285 return NRS_REGISTERED;
286 }
287 }
288
289 return stat;
290 }
291
292 /*
293 +-----------------------------------------------------------------------------+
294 | PROJECT : GSM-PS (6147) MODULE : PSA_GMMF |
295 | ROUTINE : psaGMM_NetworkRegistrationStatus |
296 +-----------------------------------------------------------------------------+
297
298 PURPOSE : this function reported the network registration status for GPRS
299 (+CGREG, %CGREG).
300 */
301 GLOBAL void psaGMM_NetworkRegistrationStatus ( ULONG prim, void* para)
302 {
303 T_NETWORK_REGISTRATION_STATUS tmp_stat; /* only temporary in use*/
304 static T_NETWORK_REGISTRATION_STATUS stat = NRS_NOT_REGISTERED; /* current GPRS NRS */
305 static BOOL suspended = FALSE; /* is GPRS suspended */
306
307 TRACE_FUNCTION ("psaGMM_NetworkRegistrationStatus()");
308
309 switch ( prim )
310 {
311 case SMREG_PDP_ACTIVATE_REQ:
312 if ( stat EQ NRS_NOT_REGISTERED )
313 {
314 stat = NRS_SEARCHING;
315 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_SEARCHING, P_CGREG_STAT_SEARCHING );
316 }
317 break;
318 case GMMREG_ATTACH_REQ:
319 if ( stat EQ NRS_NOT_REGISTERED &&
320 ((T_GMMREG_ATTACH_REQ*)para)->attach_type NEQ GMMREG_AT_IMSI )
321 {
322 stat = NRS_SEARCHING;
323 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_SEARCHING, P_CGREG_STAT_SEARCHING );
324 }
325 break;
326 case GMMREG_ATTACH_CNF:
327 if ((stat EQ NRS_NOT_REGISTERED || stat EQ NRS_SEARCHING) && !suspended &&
328 ((T_GMMREG_ATTACH_CNF*)para)->attach_type NEQ GMMREG_AT_IMSI )
329 {
330 stat = NRS_REGISTERED;
331
332 if ( cmhGMM_isPLMN_Home())
333 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_HOME, P_CGREG_STAT_REG_HOME ); }
334 else
335 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_ROAM, P_CGREG_STAT_REG_ROAM ); }
336 }
337 else if ( (stat EQ NRS_REGISTERED) && suspended &&
338 ((T_GMMREG_ATTACH_CNF*)para)->attach_type NEQ GMMREG_AT_IMSI &&
339 ((T_GMMREG_ATTACH_CNF*)para)->search_running EQ GMMREG_SEARCH_NOT_RUNNING )
340 {
341 if(((T_GMMREG_ATTACH_CNF*)para)->gprs_indicator NEQ GMM_GPRS_SUPP_YES)
342 {
343 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_NOT_REG, P_CGREG_STAT_NOT_REG );
344 break;
345 }
346 suspended = FALSE;
347
348 if ( cmhGMM_isPLMN_Home())
349 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_HOME, P_CGREG_STAT_REG_HOME ); }
350 else
351 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_ROAM, P_CGREG_STAT_REG_ROAM ); }
352 }
353
354 else
355 { /* answer to ATTACH_REQ->attach_type=IMSI */
356 if ( stat NEQ NRS_NOT_REGISTERED &&
357 ((T_GMMREG_ATTACH_CNF*)para)->search_running EQ GMMREG_SEARCH_NOT_RUNNING &&
358 ((T_GMMREG_ATTACH_CNF*)para)->attach_type EQ GMMREG_AT_IMSI )
359 {
360 stat = NRS_NOT_REGISTERED;
361 suspended = FALSE;
362 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_NOT_REG, P_CGREG_STAT_NOT_REG );
363 }
364 }
365 break;
366 case GMMREG_ATTACH_REJ:
367 tmp_stat = GMM_detached(stat,
368 suspended,
369 ((T_GMMREG_ATTACH_REJ*)para)->detach_type,
370 ((T_GMMREG_ATTACH_REJ*)para)->cause,
371 GMMREG_ATTACH_REJ );
372
373 if( stat NEQ tmp_stat )
374 {
375 stat = tmp_stat;
376 suspended = FALSE;
377 }
378 break;
379 case GMMREG_DETACH_CNF:
380 if ( stat NEQ NRS_NOT_REGISTERED &&
381 ((T_GMMREG_DETACH_CNF*)para)->detach_type NEQ GMMREG_DT_IMSI )
382 {
383 stat = NRS_NOT_REGISTERED;
384 suspended = FALSE;
385 cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_NOT_REG, P_CGREG_STAT_NOT_REG );
386 }
387 break;
388 case GMMREG_DETACH_IND:
389 tmp_stat = GMM_detached(stat,
390 suspended,
391 ((T_GMMREG_DETACH_IND*)para)->detach_type,
392 ((T_GMMREG_DETACH_IND*)para)->cause,
393 GMMREG_DETACH_IND );
394
395 if( stat NEQ tmp_stat )
396 {
397 stat = tmp_stat;
398 suspended = FALSE;
399 }
400 break;
401 case GMMREG_SUSPEND_IND:
402 if ( ( stat EQ NRS_REGISTERED && !suspended ) || stat EQ NRS_SEARCHING)
403 {
404 suspended = TRUE;
405 switch ( ((T_GMMREG_SUSPEND_IND*)para)->cell_state )
406 {
407 case GMMREG_FULL_SERVICE:
408 /* nobody knows why we are not resumed */
409 suspended = FALSE;
410 break;
411 case GMMREG_LIMITED_SERVICE:
412 cmhGMM_send_percentNetworkRegistrationStatus( P_CGREG_STAT_LIMITED );
413 break;
414 case GMMREG_CS_CALL:
415 cmhGMM_send_percentNetworkRegistrationStatus( P_CGREG_STAT_GSM_CALL );
416 break;
417 case GMMREG_GPRS_NOT_SUPPORTED:
418 cmhGMM_send_percentNetworkRegistrationStatus( P_CGREG_STAT_NO_CELL );
419 break;
420 case GMMREG_TRY_TO_UPDATE:
421 cmhGMM_send_percentNetworkRegistrationStatus( P_CGREG_STAT_TRY_TO_UPDATE );
422 break;
423 }
424 }
425 break;
426 case GMMREG_RESUME_IND:
427 if ( suspended )
428 {
429 suspended = FALSE;
430
431 if ( stat NEQ NRS_REGISTERED )
432 {
433 if ( cmhGMM_isPLMN_Home())
434 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_HOME, P_CGREG_STAT_REG_HOME ); }
435 else
436 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_ROAM, P_CGREG_STAT_REG_ROAM ); }
437 }
438 else
439 {
440 if ( cmhGMM_isPLMN_Home())
441 { cmhGMM_send_percentNetworkRegistrationStatus( P_CGREG_STAT_REG_HOME ); }
442 else
443 { cmhGMM_send_percentNetworkRegistrationStatus( P_CGREG_STAT_REG_ROAM ); }
444 }
445 stat = NRS_REGISTERED;
446 }
447 break;
448 case GMMREG_AHPLMN_IND: /* Enhancement for ActingHPLMN*/
449 if(cmhGMM_isPLMN_Valid())
450 {
451 if(cmhGMM_isPLMN_Home())
452 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_HOME, P_CGREG_STAT_REG_HOME); }
453 else
454 { cmhGMM_send_NetworkRegistrationStatus( CGREG_STAT_REG_ROAM, P_CGREG_STAT_REG_ROAM ); }
455 }
456 break;
457 case GMMREG_DETACH_REQ:
458 case GMMREG_NET_REQ:
459 case GMMREG_PLMN_IND:
460 case GMMREG_PLMN_RES:
461 case GMMREG_PLMN_MODE_REQ:
462 case GMMREG_INFO_IND:
463 case GMMREG_CONFIG_REQ:
464 case GMMREG_CIPHERING_IND:
465 break;
466 default:
467 TRACE_EVENT_P1("UNSUPPORTED PRIMITIVE: %d", prim);
468 }
469
470 }
471
472
473 #if 0
474 /*
475 +-------------------------------------------------------------------+
476 | PROJECT : GSM-PS (6147) MODULE : PSA_GMMF |
477 | ROUTINE : psaGMM_shrPrmDump |
478 +-------------------------------------------------------------------+
479
480 PURPOSE : this function dumps the shared parameter to the debug
481 output.
482 */
483
484 GLOBAL void psaGMM_shrPrmDump ( void )
485 {
486 #ifdef TRACING
487
488 char lnBuf [80]; /* holds buffer for output line */
489 char mccBuf[SIZE_MCC + 1]; /* MCC converted to printable C-string */
490 char mncBuf[SIZE_MNC + 1]; /* MNC converted to printable C-string */
491 SHORT chrNr; /* holds number of processed chars */
492 SHORT cnt; /* holds a counter */
493
494 /* --- PLMN list ------------------------------------------------*/
495 for( cnt = 0; cnt<MAX_PLMN_ID AND
496 mmShrdPrm.PLMNLst[cnt].v_plmn NEQ INVLD_PLMN; cnt++ )
497 {
498 chrNr = sprintf( lnBuf, "%*.*s[%2d]", HDR_WDT, HDR_WDT, " PLMN list",cnt );
499 utl_BCD2String (mccBuf, mmShrdPrm.PLMNLst[cnt].mcc, SIZE_MCC);
500 utl_BCD2String (mncBuf, mmShrdPrm.PLMNLst[cnt].mnc, SIZE_MNC);
501 chrNr += sprintf( lnBuf+chrNr, "%*s %*s",
502 ITM_WDT/2, ITM_WDT/2, mccBuf, mncBuf);
503 TRACE_EVENT( lnBuf );
504 }
505
506 /* --- used PLMN ------------------------------------------------*/
507 chrNr = sprintf( lnBuf, "%*.*s", HDR_WDT, HDR_WDT, " used PLMN" );
508 if( mmShrdPrm.usedPLMN.v_plmn EQ VLD_PLMN )
509 {
510 utl_BCD2String (mccBuf, mmShrdPrm.usedPLMN.mcc, SIZE_MCC);
511 utl_BCD2String (mncBuf, mmShrdPrm.usedPLMN.mnc, SIZE_MNC);
512 chrNr += sprintf( lnBuf+chrNr, "%*s %*s",
513 ITM_WDT/2, ITM_WDT/2, mccBuf, mncBuf);
514 }
515 else
516 {
517 chrNr += sprintf( lnBuf+chrNr, "%*s", ITM_WDT, "none" );
518 }
519 TRACE_EVENT( lnBuf );
520
521 /* --- registration mode ----------------------------------------*/
522 chrNr = sprintf( lnBuf, "%*.*s", HDR_WDT, HDR_WDT, "rgstr mode" );
523 chrNr += sprintf( lnBuf+chrNr, "%*hd", ITM_WDT,
524 mmShrdPrm.setPrm[0].regMode );
525 TRACE_EVENT( lnBuf );
526
527 /* --- registration status --------------------------------------*/
528 chrNr = sprintf( lnBuf, "%*.*s", HDR_WDT, HDR_WDT, "rgstr stat" );
529 chrNr += sprintf( lnBuf+chrNr, "%*hd", ITM_WDT,
530 mmShrdPrm.regStat );
531 TRACE_EVENT( lnBuf );
532
533 /* --- search result --------------------------------------------*/
534 chrNr = sprintf( lnBuf, "%*.*s", HDR_WDT, HDR_WDT, " srch rslt" );
535 chrNr += sprintf( lnBuf+chrNr, "%*hd", ITM_WDT,
536 mmShrdPrm.srchRslt );
537 TRACE_EVENT( lnBuf );
538
539 /* --- de-registration cause ------------------------------------*/
540 chrNr = sprintf( lnBuf, "%*.*s", HDR_WDT, HDR_WDT, "dereg caus" );
541 chrNr += sprintf( lnBuf+chrNr, "%*X", ITM_WDT,
542 mmShrdPrm.deregCs );
543 TRACE_EVENT( lnBuf );
544
545 #endif /* of #ifdef TRACING */
546 }
547 #endif /* #if 0 */
548
549 #endif /* GPRS */
550 /*==== EOF ========================================================*/
551