comparison gsm-fw/g23m-aci/aci/cmh_gmms.c @ 775:eedbf248bac0

gsm-fw/g23m-aci subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 12 Oct 2014 01:45:14 +0000
parents
children
comparison
equal deleted inserted replaced
774:40a721fd9854 775:eedbf248bac0
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 implements the set fuinctions related to the
18 | protocol stack adapter for GPRS mobility management ( GMM ).
19 +-----------------------------------------------------------------------------
20 */
21
22 #if defined (GPRS) && defined (DTI)
23
24 #ifndef CMH_GMMS_C
25 #define CMH_GMMS_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
34 #include "dti_conn_mng.h"
35
36 #include "gaci.h"
37 #include "gaci_cmh.h"
38 #include "psa.h"
39 #include "psa_gmm.h"
40 #include "psa_sm.h"
41 #ifdef FAX_AND_DATA
42 /* #include "aci_fd.h" */
43 #endif
44 #include "phb.h"
45 #include "cmh.h"
46 #include "cmh_gmm.h"
47 #include "cmh_sm.h"
48 #include "psa_sim.h"
49 #include "cmh_sim.h"
50
51 /*==== CONSTANTS ==================================================*/
52
53 /*==== EXPORT =====================================================*/
54
55 /*==== VARIABLES ==================================================*/
56
57 /*==== FUNCTIONS ==================================================*/
58 GLOBAL T_ACI_RETURN sAT_PlusCGATT ( T_ACI_CMD_SRC srcId, T_CGATT_STATE state );
59 GLOBAL T_ACI_RETURN sAT_PlusCGCLASS ( T_ACI_CMD_SRC srcId, T_CGCLASS_CLASS m_class );
60
61 GLOBAL T_ACI_RETURN sAT_PercentCGAATT ( T_ACI_CMD_SRC srcId, T_CGAATT_ATTACH_MODE att_m, T_CGAATT_DETACH_MODE det_m);
62 GLOBAL T_ACI_RETURN sAT_PercentCGCLASS ( T_ACI_CMD_SRC srcId, T_PERCENT_CGCLASS m_class );
63
64 /*
65 +--------------------------------------------------------------------+
66 | PROJECT : GPRS (8441) MODULE : CMH_GMMQ |
67 | STATE : finished ROUTINE : sAT_PlusCGATT |
68 +--------------------------------------------------------------------+
69
70 PURPOSE : This is the functional counterpart to the +CGATT= GPRS AT
71 command which sets current GACI service state.
72
73 Fails if illegal new state requested. Returns complete if
74 already in existing state, otherwise signals GACI SEM to
75 attach or detach GACI as appropriate.
76
77 (Un)succesful completion of attach/detach is signalled by
78 means of a GACI callback.
79 */
80
81 GLOBAL T_ACI_RETURN sAT_PlusCGATT ( T_ACI_CMD_SRC srcId, T_CGATT_STATE state )
82 {
83 T_ACI_RETURN retCd; /* holds return code */
84
85 TRACE_FUNCTION ("sAT_PlusCGATT()");
86
87 /*
88 *-------------------------------------------------------------------
89 * check command source
90 *-------------------------------------------------------------------
91 */
92 if(!cmh_IsVldCmdSrc (srcId))
93 {
94 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
95 return( AT_FAIL );
96 }
97
98 /*
99 *-------------------------------------------------------------------
100 * check entity status
101 *-------------------------------------------------------------------
102 */
103 if( gmmEntStat.curCmd NEQ AT_CMD_NONE )
104
105 return( AT_BUSY );
106
107 /*
108 *-------------------------------------------------------------------
109 * check cfun status - avoid activating radio in case of flight mode (+CFUN=4)
110 *-------------------------------------------------------------------
111 */
112 if (CFUNfun EQ CFUN_FUN_Disable_TX_RX_RF)
113 {
114 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_OpNotAllow);
115 return( AT_FAIL );
116 }
117
118
119 /*
120 *-------------------------------------------------------------------
121 * check first command argument
122 *-------------------------------------------------------------------
123 */
124 if ( state < CGATT_STATE_OMITTED OR state >= CGATT_STATE_INVALID )
125 {
126 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
127 return( AT_FAIL );
128 }
129 if (pb_get_fdn_mode () EQ FDN_ENABLE AND state EQ CGATT_STATE_ATTACHED)
130 {
131 if (pb_check_fdn (0, (const UBYTE *)"*99#") NEQ PHB_OK)
132 {
133 TRACE_EVENT("sAT_PlusCGATT: Entry not found in FDN, GPRS not allowed.");
134 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_OpNotAllow);
135 return (AT_FAIL);
136 }
137 TRACE_EVENT("sAT_PlusCGATT: Entry found in FDN, GPRS allowed.");
138 }
139
140 /*
141 *-------------------------------------------------------------------
142 * process parameter
143 *-------------------------------------------------------------------
144 */
145 switch ( state )
146 {
147 case CGATT_STATE_OMITTED:
148 switch ( cmhGMM_Get_state() )
149 {
150 case AS_ATTACHED:
151 case AS_SUSPENTED:
152 state = CGATT_STATE_DETACHED;
153 break;
154 case AS_DETACHED:
155 state = CGATT_STATE_ATTACHED;
156 break;
157 case AS_ATTACHING:
158 case AS_DETACHING:
159 return AT_BUSY;
160 case AS_INVALID_STATE:
161 case AS_MOBILE_OFF:
162 default:
163 return AT_FAIL;
164 }
165
166 retCd = sAT_PlusCGATT(srcId, state);
167 break;
168 case CGATT_STATE_ATTACHED:
169 /*
170 * A class CC mobile can not attach GPRS
171 */
172 if ( gmmShrdPrm.mobile_class EQ GMMREG_CLASS_CC )
173 {
174 return AT_FAIL;
175 }
176
177 switch(gmmShrdPrm.current_attach_type)
178 {
179 case GMMREG_AT_GPRS:
180 case GMMREG_AT_COMB:
181 TRACE_EVENT("Already attached, attach not necessary.");
182 retCd = AT_CMPL;
183 break;
184 case GMMREG_AT_IMSI:
185 TRACE_EVENT("GSM already attached, initiating combined attach.");
186 gmmEntStat.curCmd = AT_CMD_CGATT;
187 gmmEntStat.entOwn = srcId;
188 gmmShrdPrm.last_attach_type = gmmShrdPrm.current_attach_type;
189 gmmShrdPrm.requested_attach_type = GMMREG_AT_COMB;
190 gmmShrdPrm.requested_mobile_class = gmmShrdPrm.mobile_class;
191
192 psaGMM_Attach( gmmShrdPrm.requested_mobile_class,
193 gmmShrdPrm.requested_attach_type,
194 gmmShrdPrm.service_mode);
195
196 retCd = AT_EXCT;
197 break;
198 case ATTACH_TYPE_DETACHED:
199 TRACE_EVENT("Mobile is detached, initiating GPRS attach.");
200 gmmEntStat.curCmd = AT_CMD_CGATT;
201 gmmEntStat.entOwn = srcId;
202 gmmShrdPrm.last_attach_type = gmmShrdPrm.current_attach_type;
203 gmmShrdPrm.requested_attach_type = GMMREG_AT_GPRS;
204 gmmShrdPrm.requested_mobile_class = gmmShrdPrm.mobile_class;
205
206 psaGMM_Attach( gmmShrdPrm.requested_mobile_class,
207 gmmShrdPrm.requested_attach_type,
208 gmmShrdPrm.service_mode);
209
210 retCd = AT_EXCT;
211 break;
212 default:
213 retCd = AT_FAIL;
214 break;
215 }
216 break;
217 case CGATT_STATE_DETACHED:
218 switch ( cmhGMM_Get_state() )
219 {
220 case AS_DETACHED:
221 retCd = AT_CMPL;
222 break;
223 case AS_ATTACHING:
224 case AS_DETACHING:
225 retCd = AT_BUSY;
226 break;
227 default:
228 gmmEntStat.curCmd = AT_CMD_CGATT;
229 gmmEntStat.entOwn = srcId;
230
231 psaGMM_Detach( GMMREG_DT_GPRS );
232
233 retCd = AT_EXCT;
234 break;
235 }
236 break;
237 case CGATT_STATE_INVALID:
238 default:
239 retCd = AT_FAIL;
240 break;
241 }
242
243 return retCd;
244 }
245
246 /*
247 +--------------------------------------------------------------------+
248 | PROJECT : GPRS (8441) MODULE : CMH_GMMQ |
249 | STATE : finished ROUTINE : sAT_PlusCGCLASS |
250 +--------------------------------------------------------------------+
251
252 PURPOSE : This is the functional counterpart to the +CGCLASS= GPRS AT
253 command which sets the specified GPRS mobile class.
254 */
255
256 GLOBAL T_ACI_RETURN sAT_PlusCGCLASS ( T_ACI_CMD_SRC srcId, T_CGCLASS_CLASS m_class )
257 {
258 USHORT mobile_class;
259
260 TRACE_FUNCTION ("sAT_PlusCGCLASS()");
261
262 /*
263 *-------------------------------------------------------------------
264 * check command source
265 *-------------------------------------------------------------------
266 */
267 if(!cmh_IsVldCmdSrc (srcId))
268 {
269 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
270 return( AT_FAIL );
271 }
272
273 /*
274 *-------------------------------------------------------------------
275 * check entity status
276 *-------------------------------------------------------------------
277 */
278 if( gmmEntStat.curCmd NEQ AT_CMD_NONE )
279
280 return( AT_BUSY );
281
282 if (pb_get_fdn_mode () EQ FDN_ENABLE AND m_class NEQ CGCLASS_CLASS_CC)
283 {
284 if (pb_check_fdn (0, (const UBYTE *)"*99#") NEQ PHB_OK)
285 {
286 TRACE_EVENT("sAT_PlusCGCLASS: Entry not found in FDN, GPRS not allowed.");
287 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_OpNotAllow);
288 return (AT_FAIL);
289 }
290 TRACE_EVENT("sAT_PlusCGCLASS: Entry found in FDN, GPRS allowed.");
291 }
292
293
294 /*
295 *-------------------------------------------------------------------
296 * process parameter
297 *-------------------------------------------------------------------
298 */
299 switch ( m_class )
300 {
301 case CGCLASS_CLASS_A: /* mobile class A (highest) */
302 mobile_class = GMMREG_CLASS_A;
303 break;
304 case CGCLASS_CLASS_B: /* mobile class B (if necessary consider NET III) */
305 mobile_class = GMMREG_CLASS_BG;
306 break;
307 case CGCLASS_CLASS_CG: /* mobile class CG (GPRS only mode) */
308 mobile_class = GMMREG_CLASS_CG;
309 break;
310 case CGCLASS_CLASS_CC: /* mobile class CC (circuit switched only mode - lowest) */
311 mobile_class = GMMREG_CLASS_CC;
312 break;
313 case CGCLASS_CLASS_OMITTED:
314 mobile_class = gmmShrdPrm.mobile_class;
315 break;
316 case CGCLASS_CLASS_MAX:
317 default: /*bad user command */
318 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
319 return AT_FAIL;
320 }
321
322 gmmEntStat.entOwn = srcId;
323 gmmEntStat.curCmd = AT_CMD_CGCLASS;
324
325 return cmhGMM_attach((UBYTE) mobile_class );
326 }
327
328
329 /*
330 +--------------------------------------------------------------------+
331 | PROJECT : GPRS (8441) MODULE : CMH_GMMQ |
332 | STATE : finished ROUTINE : sAT_PercentCGAATT |
333 +--------------------------------------------------------------------+
334
335 PURPOSE : This command set the mode of automatic attach / detach.
336 */
337
338 GLOBAL T_ACI_RETURN sAT_PercentCGAATT ( T_ACI_CMD_SRC srcId, T_CGAATT_ATTACH_MODE att_m, T_CGAATT_DETACH_MODE det_m )
339 {
340
341 TRACE_FUNCTION ("sAT_PercentCGAATT()");
342
343 /*
344 *-------------------------------------------------------------------
345 * check entity status
346 *-------------------------------------------------------------------
347 */
348 if( gmmEntStat.curCmd NEQ AT_CMD_NONE )
349
350 return( AT_BUSY );
351
352 /*
353 *-------------------------------------------------------------------
354 * check first command argument
355 *-------------------------------------------------------------------
356 */
357 if ( att_m < CGAATT_ATTACH_MODE_OMITTED OR att_m >= CGAATT_ATTACH_MODE_INVALID )
358 {
359 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
360 return( AT_FAIL );
361 }
362
363 if ( det_m < CGAATT_DETACH_MODE_OMITTED OR det_m >= CGAATT_DETACH_MODE_INVALID )
364 {
365 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
366 return( AT_FAIL );
367 }
368
369 if ( att_m EQ CGAATT_ATTACH_MODE_OMITTED )
370 att_m = automatic_attach_mode;
371
372 if ( det_m EQ CGAATT_DETACH_MODE_OMITTED )
373 det_m = automatic_detach_mode;
374
375 /*
376 *-------------------------------------------------------------------
377 * set parameter
378 *-------------------------------------------------------------------
379 */
380
381 automatic_attach_mode = att_m;
382 automatic_detach_mode = det_m;
383
384 return AT_CMPL;
385 }
386
387 /*
388 +--------------------------------------------------------------------+
389 | PROJECT : GPRS (8441) MODULE : CMH_GMMQ |
390 | STATE : finished ROUTINE : sAT_PercentCGMM |
391 +--------------------------------------------------------------------+
392
393 PURPOSE : This command configurates GMM.
394 CIPHER_ON = 1 / OFF = 0
395 TLLI_TWICE = 1 / STANDARD = 0
396 */
397
398 GLOBAL T_ACI_RETURN sAT_PercentCGMM ( T_ACI_CMD_SRC srcId, UBYTE cipher_on,
399 UBYTE tlli_handling )
400 {
401 TRACE_FUNCTION ("sAT_PercentCGMM()");
402
403 /*
404 *-------------------------------------------------------------------
405 * check entity status
406 *-------------------------------------------------------------------
407 */
408 if( gmmEntStat.curCmd NEQ AT_CMD_NONE )
409
410 return( AT_BUSY );
411
412 /*
413 *-------------------------------------------------------------------
414 * check command arguments
415 *-------------------------------------------------------------------
416 */
417 if ( cipher_on NEQ 1 /*GMMREG_CIPHER_ON*/
418 AND cipher_on NEQ 0 /*GMMREG_CIPHER_OFF*/ )
419 {
420 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
421 return( AT_FAIL );
422 }
423
424 if ( tlli_handling NEQ GMMREG_TLLI_STANDARD
425 AND tlli_handling NEQ GMMREG_TLLI_TWICE )
426 {
427 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
428 return( AT_FAIL );
429 }
430
431 /* default value for tlli_handling */
432 if ( tlli_handling EQ NOT_PRESENT_8BIT )
433 tlli_handling = GMMREG_TLLI_STANDARD;
434
435 psaGMM_Config_req( cipher_on, tlli_handling );
436 return AT_CMPL;
437 }
438
439 /*
440 +--------------------------------------------------------------------+
441 | PROJECT : GPRS (8441) MODULE : CMH_GMMQ |
442 | STATE : finished ROUTINE : sAT_PlusCGCLASS |
443 +--------------------------------------------------------------------+
444
445 PURPOSE : This is the functional counterpart to the %CGCLASS= GPRS AT
446 command which sets the specified GPRS mobile class.
447 */
448
449 GLOBAL T_ACI_RETURN sAT_PercentCGCLASS ( T_ACI_CMD_SRC srcId, T_PERCENT_CGCLASS m_class )
450 {
451 USHORT mobile_class;
452
453 TRACE_FUNCTION ("sAT_PercentCGCLASS()");
454
455 /*
456 *-------------------------------------------------------------------
457 * check command source
458 *-------------------------------------------------------------------
459 */
460 if(!cmh_IsVldCmdSrc (srcId))
461 {
462 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
463 return( AT_FAIL );
464 }
465
466 /*
467 *-------------------------------------------------------------------
468 * check entity status
469 *-------------------------------------------------------------------
470 */
471 if( gmmEntStat.curCmd NEQ AT_CMD_NONE )
472
473 return( AT_BUSY );
474
475 if (pb_get_fdn_mode () EQ FDN_ENABLE AND m_class NEQ PERCENT_CGCLASS_CC)
476 {
477 if (pb_check_fdn (0, (const UBYTE *)"*99#") NEQ PHB_OK)
478 {
479 TRACE_EVENT("sAT_PercentCGCLASS: Entry not found in FDN, GPRS not allowed.");
480 ACI_ERR_DESC( ACI_ERR_CLASS_Cme, CME_ERR_OpNotAllow);
481 return (AT_FAIL);
482 }
483 TRACE_EVENT("sAT_PercentCGCLASS: Entry found in FDN, GPRS allowed.");
484 }
485
486 /*
487 *-------------------------------------------------------------------
488 * process parameter
489 *-------------------------------------------------------------------
490 */
491 switch ( m_class )
492 {
493 case PERCENT_CGCLASS_A: /* mobile class A (highest) */
494 mobile_class = GMMREG_CLASS_A;
495 break;
496 case PERCENT_CGCLASS_B: /* mobile class B */
497 mobile_class = GMMREG_CLASS_B;
498 break;
499 case PERCENT_CGCLASS_BG: /* mobile class BG */
500 mobile_class = GMMREG_CLASS_BG;
501 break;
502 case PERCENT_CGCLASS_BC: /* mobile class BC */
503 mobile_class = GMMREG_CLASS_BC;
504 break;
505 case PERCENT_CGCLASS_BX: /* mobile class BX */
506 mobile_class = cmhSM_isContextActive() ? GMMREG_CLASS_BG : GMMREG_CLASS_BC;
507 break;
508 case PERCENT_CGCLASS_CG: /* mobile class CG (GPRS only mode) */
509 mobile_class = GMMREG_CLASS_CG;
510 break;
511 case PERCENT_CGCLASS_CC: /* mobile class CC (circuit switched only mode - lowest) */
512 mobile_class = GMMREG_CLASS_CC;
513 break;
514 case PERCENT_CGCLASS_OMITTED:
515 mobile_class = gmmShrdPrm.mobile_class;
516 break;
517 case PERCENT_CGCLASS_MAX:
518 default: /*bad user command */
519 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
520 return AT_FAIL;
521 }
522
523 gmmEntStat.entOwn = srcId;
524 gmmEntStat.curCmd = AT_CMD_CGCLASS;
525
526 gaciMobileClass.requested = m_class;
527
528 return cmhGMM_attach((UBYTE) mobile_class );
529 }
530
531 #endif /* GPRS */
532 /*==== EOF ========================================================*/