comparison src/g23m-gprs/sm/sm.c @ 183:219afcfc6250

src/g23m-gprs: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 13 Oct 2016 04:24:13 +0000
parents
children
comparison
equal deleted inserted replaced
182:f02d0a0e1849 183:219afcfc6250
1 /*----------------------------------------------------------------------------
2 | Project : 3G PS
3 | Module : SM
4 +-----------------------------------------------------------------------------
5 | Copyright 2003 Texas Instruments.
6 | All rights reserved.
7 |
8 | This file is confidential and a trade secret of Texas
9 | Instruments .
10 | The receipt of or possession of this file does not convey
11 | any rights to reproduce or disclose its contents or to
12 | manufacture, use, or sell anything it may describe, in
13 | whole, or in part, without the specific written consent of
14 | Texas Instruments.
15 +-----------------------------------------------------------------------------
16 | Purpose: Utility functions implementation in the SM entity.
17 | For design details, see:
18 | 8010.908 SM Detailed Specification
19 +---------------------------------------------------------------------------*/
20
21 /*==== DECLARATION CONTROL =================================================*/
22
23 /*==== INCLUDES =============================================================*/
24
25 #include <stdio.h>
26 #include "sm.h"
27
28 /*==== CONSTS ===============================================================*/
29
30 /*==== TYPES ================================================================*/
31
32 /*==== LOCALS ===============================================================*/
33
34 /*==== PRIVATE FUNCTIONS ====================================================*/
35
36 /*==== PUBLIC FUNCTIONS =====================================================*/
37
38 /*
39 +------------------------------------------------------------------------------
40 | Function : sm_nsapi2nsapi_set
41 +------------------------------------------------------------------------------
42 | Description : Returns nsapi_set corresponding to the input NSAPI
43 |
44 | Parameters : nsapi - NSAPI to convert to nsapi_set
45 +------------------------------------------------------------------------------
46 */
47 U16 sm_nsapi2nsapi_set(int /*@alt U8@*/ nsapi)
48 {
49 return (U16)(1UL << (U8)nsapi);
50 }
51
52 /*
53 +------------------------------------------------------------------------------
54 | Function : sm_add_nsapi_to_nsapi_set
55 +------------------------------------------------------------------------------
56 | Description : Returns nsapi_set with nsapi added to it (1 << nsapi).
57 |
58 | Parameters : nsapi - NSAPI to add
59 | nsapi_set - nsapi_set to which to add NSAPI
60 +------------------------------------------------------------------------------
61 */
62 U16 sm_add_nsapi_to_nsapi_set(int /*@alt U8@*/ nsapi, U16 nsapi_set)
63 {
64 return (nsapi_set | sm_nsapi2nsapi_set(nsapi));
65 }
66
67 /*
68 +------------------------------------------------------------------------------
69 | Function : sm_remove_nsapi_from_nsapi_set
70 +------------------------------------------------------------------------------
71 | Description : Returns nsapi_set with nsapi removed from it (1 << nsapi).
72 |
73 | Parameters : nsapi - NSAPI to remove
74 | nsapi_set - nsapi_set in which to remove NSAPI
75 +------------------------------------------------------------------------------
76 */
77 U16 sm_remove_nsapi_from_nsapi_set(int /*@alt U8@*/ nsapi, U16 nsapi_set)
78 {
79 return (nsapi_set & (0xffff ^ sm_nsapi2nsapi_set(nsapi)));
80 }
81
82 /*
83 +------------------------------------------------------------------------------
84 | Function : sm_is_nsapi_in_nsapi_set
85 +------------------------------------------------------------------------------
86 | Description : Returns TRUE iff the input NSAPI (converted to nsapi_set) is
87 | set in the input nsapi_set.
88 |
89 | Parameters : nsapi - NSAPI whose presence to check
90 | nsapi_set - nsapi_set to compare
91 +------------------------------------------------------------------------------
92 */
93 BOOL sm_is_nsapi_in_nsapi_set(int /*@alt U8,U16@*/ nsapi, U16 nsapi_set)
94 {
95 return ((nsapi_set & sm_nsapi2nsapi_set(nsapi)) != 0);
96 }
97
98 /*
99 +------------------------------------------------------------------------------
100 | Function : sm_nsapi_to_index
101 +------------------------------------------------------------------------------
102 | Description : Returns array index corresponding to NSAPI (nsapi - 5)
103 |
104 | Parameters : nsapi - NSAPI value
105 +------------------------------------------------------------------------------
106 */
107 U16 /*@alt int@*/ sm_nsapi_to_index(U16 /*@alt U8,int@*/nsapi)
108 {
109 TRACE_ASSERT((T_NAS_nsapi)nsapi >= NAS_NSAPI_5 && nsapi <= NAS_NSAPI_15);
110 return (nsapi - (U16)NAS_NSAPI_5);
111 }
112
113 /*
114 +------------------------------------------------------------------------------
115 | Function : sm_index_to_nsapi
116 +------------------------------------------------------------------------------
117 | Description : Returns nsapi value corresponding to array index (index + 5)
118 |
119 | Parameters : index - index value
120 +------------------------------------------------------------------------------
121 */
122 U16 /*@alt int@*/ sm_index_to_nsapi(U16 /*@alt U8,int@*/index)
123 {
124 TRACE_ASSERT(index < SM_MAX_NSAPI_OFFSET);
125 return (index + (U16)NAS_NSAPI_5);
126 }
127
128 /*
129 +------------------------------------------------------------------------------
130 | Function : sm_get_pdp_context_status
131 +------------------------------------------------------------------------------
132 | Description : Get the network status of all NSAPIs. A bit is set in the
133 | nsapi_set, iff the context corresponding to the NSAPI is
134 | not in network state INACTIVE.
135 |
136 | Parameters : None
137 +------------------------------------------------------------------------------
138 */
139 U16 sm_get_pdp_context_status(void)
140 {
141 return sm_data.sm_context_activation_status;
142 }
143
144 /*
145 +------------------------------------------------------------------------------
146 | Function : sm_get_current_rat
147 +------------------------------------------------------------------------------
148 | Description : Returns the RAT in which SM is currently active
149 |
150 | Parameters : None
151 +------------------------------------------------------------------------------
152 */
153 T_PS_rat /*@alt U8@*/sm_get_current_rat(void)
154 {
155 return sm_data.sm_current_rat;
156 }
157
158 /*
159 +------------------------------------------------------------------------------
160 | Function : sm_set_current_rat
161 +------------------------------------------------------------------------------
162 | Description : Sets the RAT in which SM is currently active
163 |
164 | Parameters : rat - Active RAT (GSM / UMTS)
165 +------------------------------------------------------------------------------
166 */
167 void sm_set_current_rat(T_PS_rat rat)
168 {
169 if (rat == PS_RAT_GSM || rat == PS_RAT_UMTS_FDD) {
170 sm_data.sm_current_rat = rat;
171 } else {
172 (void)TRACE_ERROR("Tried to set unknown RAT! (This is OK for EDGE)");
173 }
174 }
175
176 /*
177 +------------------------------------------------------------------------------
178 | Function : sm_get_current_nw_release
179 +------------------------------------------------------------------------------
180 | Description : Returns the core network release of the network in which SM
181 | is currently active
182 |
183 | Parameters : None
184 +------------------------------------------------------------------------------
185 */
186 T_PS_sgsn_rel /*@alt U8@*/ sm_get_current_nw_release(void)
187 {
188 return sm_data.sm_current_nw_release;
189 }
190
191 /*
192 +------------------------------------------------------------------------------
193 | Function : sm_is_suspended
194 +------------------------------------------------------------------------------
195 | Description : Returns TRUE if SM is suspended, i.e. has received an
196 | MMPM_SUSPEND_IND primitive from MM.
197 |
198 | Parameters : None
199 +------------------------------------------------------------------------------
200 */
201 BOOL sm_is_suspended(void)
202 {
203 return sm_data.sm_suspended;
204 }
205
206 /*
207 +------------------------------------------------------------------------------
208 | Function : sm_is_attached
209 +------------------------------------------------------------------------------
210 | Description : Returns TRUE if SM is attached, i.e. has received an
211 | MMPM_ATTACH_IND primitive from MM.
212 |
213 | Parameters : None
214 +------------------------------------------------------------------------------
215 */
216 BOOL sm_is_attached(void)
217 {
218 return sm_data.sm_attached;
219 }
220
221 /*
222 +------------------------------------------------------------------------------
223 | Function : sm_is_secondary
224 +------------------------------------------------------------------------------
225 | Description : Returns TRUE if secondary flag is set for the context.
226 |
227 | Parameters : context - Context data
228 +------------------------------------------------------------------------------
229 */
230 BOOL sm_is_secondary(struct T_SM_CONTEXT_DATA *context)
231 {
232 return (context->flags & (U8)SM_CONTEXT_FLAG_SECONDARY_CONTEXT) != (U8)0;
233 }
234
235 /*
236 +------------------------------------------------------------------------------
237 | Function : sm_set_secondary
238 +------------------------------------------------------------------------------
239 | Description : Set secondary flag for the input context
240 |
241 | Parameters : context - Context data
242 +------------------------------------------------------------------------------
243 */
244 void sm_set_secondary(struct T_SM_CONTEXT_DATA *context)
245 {
246 context->flags |= (U8)SM_CONTEXT_FLAG_SECONDARY_CONTEXT;
247 }
248
249 /*
250 +------------------------------------------------------------------------------
251 | Function : sm_set_started_during_suspend
252 +------------------------------------------------------------------------------
253 | Description : Set started during suspend flag for the context
254 |
255 | Parameters : context - Context data
256 +------------------------------------------------------------------------------
257 */
258 void sm_set_started_during_suspend(struct T_SM_CONTEXT_DATA *context)
259 {
260 if (sm_is_suspended()) {
261 context->flags |= (U8)SM_CONTEXT_FLAG_STARTED_DURING_SUSPEND;
262 } else {
263 context->flags &= 0xff ^ (U8)SM_CONTEXT_FLAG_STARTED_DURING_SUSPEND;
264 }
265 }
266
267 /*
268 +------------------------------------------------------------------------------
269 | Function : sm_clear_started_during_suspend
270 +------------------------------------------------------------------------------
271 | Description : Clear started during suspend flag for the context
272 |
273 | Parameters : context - Context data
274 +------------------------------------------------------------------------------
275 */
276 void sm_clear_started_during_suspend(struct T_SM_CONTEXT_DATA *context)
277 {
278 context->flags &= 0xff ^ (U8)SM_CONTEXT_FLAG_STARTED_DURING_SUSPEND;
279 }
280
281 /*
282 +------------------------------------------------------------------------------
283 | Function : sm_is_started_during_suspend
284 +------------------------------------------------------------------------------
285 | Description : Return TRUE if started during suspend flag is set for the
286 | context.
287 |
288 | Parameters : context - Context data
289 +------------------------------------------------------------------------------
290 */
291 BOOL sm_is_started_during_suspend(struct T_SM_CONTEXT_DATA *context)
292 {
293 return (context->flags & (U8)SM_CONTEXT_FLAG_STARTED_DURING_SUSPEND) != (U8)0;
294 }
295
296 /*
297 +------------------------------------------------------------------------------
298 | Function : sm_mark_context_for_deallocation
299 +------------------------------------------------------------------------------
300 | Description : Set pending deallocation flag for the context
301 |
302 | Parameters : context - Context data
303 +------------------------------------------------------------------------------
304 */
305 void sm_mark_context_for_deallocation(struct T_SM_CONTEXT_DATA *context)
306 {
307 context->flags |= (U8)SM_CONTEXT_FLAG_PENDING_DEALLOCATION;
308 }
309
310 /*
311 +------------------------------------------------------------------------------
312 | Function : sm_is_context_pending_deallocation
313 +------------------------------------------------------------------------------
314 | Description : Returns TRUE if pending deallocation flag is set for the context
315 |
316 | Parameters : context - Context data
317 +------------------------------------------------------------------------------
318 */
319 BOOL sm_is_context_pending_deallocation(struct T_SM_CONTEXT_DATA *context)
320 {
321 return (context->flags & (U8)SM_CONTEXT_FLAG_PENDING_DEALLOCATION) != (U8)0;
322 }
323
324 /*
325 +------------------------------------------------------------------------------
326 | Function : sm_set_context_pending_reactivation
327 +------------------------------------------------------------------------------
328 | Description : Set or clear pending reactivation flag for the context
329 |
330 | Parameters : context - Context data
331 +------------------------------------------------------------------------------
332 */
333 void sm_set_context_pending_reactivation(struct T_SM_CONTEXT_DATA *context, BOOL flag)
334 {
335 if (flag)
336 {
337 context->flags |= (U8)(U8)SM_CONTEXT_FLAG_PENDING_REACTIVATION;
338 } else {
339 context->flags &= 0xff ^ (U8)(U8)SM_CONTEXT_FLAG_PENDING_REACTIVATION;
340 }
341 }
342
343 /*
344 +------------------------------------------------------------------------------
345 | Function : sm_is_context_pending_reactivation
346 +------------------------------------------------------------------------------
347 | Description : Returns TRUE if pending reactivation flag is set for the context
348 |
349 | Parameters : context - Context data
350 +------------------------------------------------------------------------------
351 */
352 BOOL sm_is_context_pending_reactivation(struct T_SM_CONTEXT_DATA *context)
353 {
354 return (context->flags & (U8)SM_CONTEXT_FLAG_PENDING_REACTIVATION) != (U8)0;
355 }
356
357 /*
358 +------------------------------------------------------------------------------
359 | Function : sm_is_aci_update_required
360 +------------------------------------------------------------------------------
361 | Description : Returns TRUE if one of the flags affecting the SMREG interface
362 | have changed/are set.
363 |
364 | Parameters : update_flags - Update flags
365 +------------------------------------------------------------------------------
366 */
367 BOOL sm_is_aci_update_required(T_SM_UPDATE_FLAGS update_flags)
368 {
369 if ((int)(update_flags & SM_UPDATE_QOS) != 0 ||
370 (int)(update_flags & SM_UPDATE_QOS_DOWNGRADE) != 0 ||
371 (int)(update_flags & SM_UPDATE_ADDRESS) != 0 ||
372 (int)(update_flags & SM_UPDATE_COMP_PARAMS) != 0) {
373 return TRUE;
374 }
375 return FALSE;
376 }
377
378 /*
379 +------------------------------------------------------------------------------
380 | Function : sm_is_user_plane_update_required
381 +------------------------------------------------------------------------------
382 | Description : Returns TRUE if one of the flags affecting the SM interface
383 | have changed/are set.
384 |
385 | Parameters : update_flags - Update flags
386 +------------------------------------------------------------------------------
387 */
388 BOOL sm_is_user_plane_update_required(T_SM_UPDATE_FLAGS update_flags)
389 {
390 if ((int)(update_flags & SM_UPDATE_QOS) != 0 ||
391 (int)(update_flags & SM_UPDATE_COMP_PARAMS) != 0 ||
392 (int)(update_flags & SM_UPDATE_SAPI_RADIO_PRIO_PFI) != 0) {
393 return TRUE;
394 }
395 return FALSE;
396 }
397
398 /*
399 +------------------------------------------------------------------------------
400 | Function : sm_set_pfi_included
401 +------------------------------------------------------------------------------
402 | Description : Set PFI included flag for the context
403 |
404 | Parameters : context - Context data
405 +------------------------------------------------------------------------------
406 */
407 void sm_set_pfi_included(struct T_SM_CONTEXT_DATA *context, BOOL flag)
408 {
409 if (flag)
410 {
411 context->flags |= (U8)SM_CONTEXT_FLAG_PFI_PRESENT;
412 } else {
413 context->flags &= 0xff ^ (U8)SM_CONTEXT_FLAG_PFI_PRESENT;
414 }
415 }
416
417 /*
418 +------------------------------------------------------------------------------
419 | Function : sm_is_pfi_included
420 +------------------------------------------------------------------------------
421 | Description : Return TRUE if PFI included flag is set for the context.
422 |
423 | Parameters : context - Context data
424 +------------------------------------------------------------------------------
425 */
426 BOOL sm_is_pfi_included(struct T_SM_CONTEXT_DATA *context)
427 {
428 return (context->flags & (U8)SM_CONTEXT_FLAG_PFI_PRESENT) != (U8)0;
429 }
430
431 /*
432 +------------------------------------------------------------------------------
433 | Function : sm_is_llc_sapi_valid
434 +------------------------------------------------------------------------------
435 | Description : Return TRUE if the LLC SAPI provided is valid, FALSE otherwise.
436 |
437 | Parameters : llc_sapi - LLC SAPI
438 | ti - TI for context
439 +------------------------------------------------------------------------------
440 */
441 BOOL sm_is_llc_sapi_valid(U8 llc_sapi, U8 ti)
442 {
443 /* This check is only valid in non-UMTS-single mode configurations */
444 #if !defined(TI_UMTS) || defined(TI_DUAL_MODE)
445 T_CAUSE_ps_cause cause;
446
447 if ( (llc_sapi == PS_SAPI_3) ||
448 (llc_sapi == PS_SAPI_5) ||
449 (llc_sapi == PS_SAPI_9) ||
450 (llc_sapi == PS_SAPI_11) )
451 {
452 /* LLC SAPI is OK. Return TRUE. */
453 return TRUE;
454 } else {
455 /* LLC SAPI has a reserved value. Send a status message. */
456 cause.ctrl_value = CAUSE_is_from_nwsm;
457 cause.value.nwsm_cause = (U16)CAUSE_NWSM_INVALID_MANDATORY_ELEMENT;
458 send_msg_sm_status(ti, &cause);
459 return FALSE;
460 }
461 #else
462 /* In UMTS single mode, this check is disabled */
463 return TRUE;
464 #endif
465 }
466
467 /*
468 +------------------------------------------------------------------------------
469 | Function : sm_set_current_nw_release
470 +------------------------------------------------------------------------------
471 | Description : Sets the core network release of the network in which SM
472 | is currently active
473 |
474 | Parameters : sgsn_rel - Network release (pre-R99 / R99)
475 +------------------------------------------------------------------------------
476 */
477 void sm_set_current_nw_release(T_PS_sgsn_rel sgsn_rel)
478 {
479 if (sgsn_rel == PS_SGSN_98_OLDER || sgsn_rel == PS_SGSN_99_ONWARDS) {
480 sm_data.sm_current_nw_release = sgsn_rel;
481 }
482 else { /*The Berlin way*/
483 /*If SGSN release is unknown set the value to R98*/
484 (void)TRACE_ERROR("Tried to set unknown core network release. \
485 Setting R97 as default !");
486 sm_data.sm_current_nw_release = PS_SGSN_98_OLDER;
487 }
488 }
489
490 /*
491 +------------------------------------------------------------------------------
492 | Function : sm_set_aci_cause
493 +------------------------------------------------------------------------------
494 | Description : Sets the cause value for a context. Used during retransmissions
495 | etc.
496 |
497 | Parameters : context - context data
498 | ctrl_cause - cause originator
499 | cause - vause value
500 +------------------------------------------------------------------------------
501 */
502 void sm_set_aci_cause(struct T_SM_CONTEXT_DATA *context,
503 T_CAUSE_ctrl_value ctrl_cause, U16 cause)
504 {
505 (void)TRACE_EVENT_P2("sm_set_aci_cause(ctrl=%d, cause=%04x)", (int)ctrl_cause, cause);
506 TRACE_ASSERT(context != NULL);
507 /*lint -e613 (Possible use of null pointer 'context' in left argument to operator '->') */
508 context->aci_cause.ctrl_value = ctrl_cause;
509 context->aci_cause.value.nwsm_cause = cause;
510 /*lint +e613 (Possible use of null pointer 'context' in left argument to operator '->') */
511 }
512
513 /*
514 +------------------------------------------------------------------------------
515 | Function : sm_get_aci_cause
516 +------------------------------------------------------------------------------
517 | Description : Gets the cause value for a context. Used during retransmissions
518 | etc.
519 |
520 | Parameters : context - context data
521 +------------------------------------------------------------------------------
522 */
523 /*@observer@*/
524 T_CAUSE_ps_cause *sm_get_aci_cause(struct T_SM_CONTEXT_DATA *context)
525 {
526 TRACE_ASSERT(context != NULL);
527 /*lint -e613 (Possible use of null pointer 'context' in left argument to operator '->') */
528 return &context->aci_cause;
529 }
530
531 /*
532 +------------------------------------------------------------------------------
533 | Function : sm_set_nw_cause
534 +------------------------------------------------------------------------------
535 | Description : Sets the cause value for a context. Used during retransmissions
536 | etc.
537 |
538 | Parameters : context - context data
539 | ctrl_cause - cause originator
540 | cause - vause value
541 +------------------------------------------------------------------------------
542 */
543 void sm_set_nw_cause(struct T_SM_CONTEXT_DATA *context,
544 T_CAUSE_ctrl_value ctrl_cause, U16 cause)
545 {
546 TRACE_ASSERT(context != NULL);
547 /*lint -e613 (Possible use of null pointer 'context' in left argument to operator '->') */
548 context->nw_cause.ctrl_value = ctrl_cause;
549 context->nw_cause.value.nwsm_cause = cause;
550 /*lint +e613 (Possible use of null pointer 'context' in left argument to operator '->') */
551 }
552
553 /*
554 +------------------------------------------------------------------------------
555 | Function : sm_get_nw_cause
556 +------------------------------------------------------------------------------
557 | Description : Gets the cause value for a context. Used during retransmissions
558 | etc.
559 |
560 | Parameters : context - context data
561 +------------------------------------------------------------------------------
562 */
563 /*@observer@*/
564 T_CAUSE_ps_cause *sm_get_nw_cause(struct T_SM_CONTEXT_DATA *context)
565 {
566 TRACE_ASSERT(context != NULL);
567 /*lint -e613 (Possible use of null pointer 'context' in left argument to operator '->') */
568 #ifdef DEBUG
569 if (context->nw_cause.ctrl_value != CAUSE_is_from_nwsm &&
570 context->nw_cause.ctrl_value != CAUSE_is_from_sm) {
571 (void)TRACE_EVENT_P2("sm_get_nw_cause(): ERROR! Cause element not "
572 "initialized or not from SM (ctrl=%d, cause=%d)",
573 context->nw_cause.ctrl_value, context->nw_cause.value.nwsm_cause);
574 }
575 #endif
576 return &context->nw_cause;
577 /*lint +e613 (Possible use of null pointer 'context' in left argument to operator '->') */
578 }
579
580 /*==== END OF FILE ==========================================================*/