comparison src/g23m-gprs/sm/sm_pei.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: This module implements the process body interface
17 | for the User Plane Manager (SM) entity.
18 | For design details, see:
19 | 8010.939 SM Detailed Specification
20 +---------------------------------------------------------------------------*/
21
22 /*==== DECLARATION CONTROL =================================================*/
23
24 #ifndef SM_PEI_C
25 #define SM_PEI_C
26 #endif
27
28 /*==== INCLUDES =============================================================*/
29
30 #include "sm.h"
31
32 #include "ccdapi.h"
33
34 #include "sm_sequencer.h"
35 #include "sm_dispatcher.h"
36
37 #include "mon_sm.h"
38
39 /*==== CONSTS ===============================================================*/
40
41 /*==== TYPES ================================================================*/
42
43 /*==== LOCALS ===============================================================*/
44
45 /* Communication handles */
46 T_HANDLE hCommACI = VSI_ERROR;
47 T_HANDLE hCommMM = VSI_ERROR;
48 T_HANDLE hCommUPM = VSI_ERROR;
49 T_HANDLE sm_handle;
50
51 static T_MONITOR sm_mon;
52 static BOOL first_access = TRUE;
53
54 /* Global entity data structure */
55 T_SM_DATA sm_data;
56
57 /* Air interface message coding/decoding buffer */
58 U8 _decodedMsg [MAX_MSTRUCT_LEN_SM];
59
60 /*==== PRIVATE FUNCTIONS ====================================================*/
61
62 /*
63 +------------------------------------------------------------------------------
64 | Function : pei_primitive
65 +------------------------------------------------------------------------------
66 | Description : This function is called by the frame when a primitive is
67 | received and needs to be processed.
68 |
69 | | |
70 | | | UPPER LAYER
71 | v v
72 | +--------------(SMREG SAP)--------------(SM SAP)---------------+
73 | | |
74 | | SM |
75 | | |
76 | +-------------------------------^------------------------------+
77 | |
78 | | LOWER LAYER
79 | (MMPM SAP)
80 |
81 | Parameters : prim - Pointer to the received primitive
82 |
83 | Return : PEI_OK - function succeeded
84 | PEI_ERROR - function failed
85 +------------------------------------------------------------------------------
86 */
87 static short pei_primitive (void *primitive)
88 {
89 (void)TRACE_FUNCTION("SM pei_primitive");
90
91 if (primitive != NULL)
92 {
93 T_PRIM_HEADER *prim;
94 U32 opc;
95
96 opc = P_OPC(primitive);
97
98 /*@i1@*/ (void)PTRACE_IN (opc);
99
100 prim = (T_PRIM_HEADER *)&((T_PRIM *)primitive)->data;
101
102 /* Memory supervision ? */
103 VSI_PPM_RCV (primitive);
104
105 switch (opc)
106 {
107 /* SMREG SAP */
108 case SMREG_PDP_ACTIVATE_REQ:
109 sm_disp_smreg_pdp_activate_req((T_SMREG_PDP_ACTIVATE_REQ *)(prim));
110 PFREE(prim);
111 break;
112
113 case SMREG_PDP_ACTIVATE_SEC_REQ:
114 sm_disp_smreg_pdp_activate_sec_req((T_SMREG_PDP_ACTIVATE_SEC_REQ *)(prim));
115 PFREE(prim);
116 break;
117
118 case SMREG_PDP_ACTIVATE_REJ_RES:
119 sm_disp_smreg_pdp_activate_rej_res((T_SMREG_PDP_ACTIVATE_REJ_RES *)(prim));
120 PFREE(prim);
121 break;
122
123 case SMREG_PDP_DEACTIVATE_REQ:
124 sm_disp_smreg_pdp_deactivate_req((T_SMREG_PDP_DEACTIVATE_REQ *)(prim));
125 PFREE(prim);
126 break;
127
128 case SMREG_PDP_MODIFY_REQ:
129 sm_disp_smreg_pdp_modify_req((T_SMREG_PDP_MODIFY_REQ *)(prim));
130 PFREE(prim);
131 break;
132
133
134 /* SM SAP */
135 case SM_ACTIVATE_RES:
136 sm_disp_sm_activate_res((T_SM_ACTIVATE_RES *)(prim));
137 PFREE(prim);
138 break;
139
140 case SM_DEACTIVATE_RES:
141 sm_disp_sm_deactivate_res((T_SM_DEACTIVATE_RES *)(prim));
142 PFREE(prim);
143 break;
144
145 case SM_MODIFY_RES:
146 sm_disp_sm_modify_res((T_SM_MODIFY_RES *)(prim));
147 PFREE(prim);
148 break;
149
150 case SM_STATUS_REQ:
151 sm_disp_sm_status_req((T_SM_STATUS_REQ *)(prim));
152 PFREE(prim);
153 break;
154
155 /* MMPM SAP */
156 case MMPM_ATTACH_IND:
157 sm_disp_mmpm_attach_ind((T_MMPM_ATTACH_IND *)(prim));
158 PFREE(prim);
159 break;
160
161 case MMPM_DETACH_IND:
162 sm_disp_mmpm_detach_ind((T_MMPM_DETACH_IND *)(prim));
163 PFREE(prim);
164 break;
165
166 case MMPM_UNITDATA_IND:
167 sm_disp_mmpm_unitdata_ind((T_MMPM_UNITDATA_IND *)(prim));
168 PFREE(prim);
169 break;
170
171 case MMPM_SUSPEND_IND:
172 sm_disp_mmpm_suspend_ind((T_MMPM_SUSPEND_IND *)(prim));
173 PFREE(prim);
174 break;
175
176 case MMPM_RESUME_IND:
177 sm_disp_mmpm_resume_ind((T_MMPM_RESUME_IND *)(prim));
178 PFREE(prim);
179 break;
180
181 default:
182 /* forward sys primitives to the environment */
183 if ( (opc & SYS_MASK) != 0) {
184 (void)vsi_c_primitive(VSI_CALLER primitive);
185 return (short)PEI_OK;
186 } else {
187 PFREE(prim);
188 return (short)PEI_ERROR;
189 }
190 } /* switch */
191 } /* if (prim != NULL) */
192
193 return PEI_OK;
194 }
195
196 /*
197 +------------------------------------------------------------------------------
198 | Function : pei_init
199 +------------------------------------------------------------------------------
200 | Description : This function is called by the frame. It is used
201 | to initialise the entity.
202 |
203 | Parameters : handle - task handle
204 |
205 | Return : PEI_OK - entity initialised
206 | PEI_ERROR - entity not (yet) initialised
207 +------------------------------------------------------------------------------
208 */
209 static short pei_init (T_HANDLE handle)
210 {
211 (void)TRACE_FUNCTION ("SM pei_init");
212
213 /*
214 * Initialize task handle
215 */
216 sm_handle = handle;
217 /*
218 * Open communication channels
219 */
220 if (hCommACI < VSI_OK)
221 {
222 if ((hCommACI = vsi_c_open(VSI_CALLER ACI_NAME)) < VSI_OK)
223 {
224 return (short)PEI_ERROR;
225 }
226 }
227
228 if (hCommMM < VSI_OK)
229 {
230 /*#ifdef SM_EDGE */
231 if ((hCommMM = vsi_c_open(VSI_CALLER GMM_NAME)) < VSI_OK)
232 /*#else */ /* #ifdef SM_EDGE */
233 /* if ((hCommMM = vsi_c_open(VSI_CALLER MM_NAME)) < VSI_OK)
234 #endif */ /*#ifdef SM_EDGE*/
235 {
236 return (short)PEI_ERROR;
237 }
238 }
239
240 if (hCommUPM < VSI_OK)
241 {
242 if ((hCommUPM = vsi_c_open (VSI_CALLER UPM_NAME)) < VSI_OK)
243 {
244 return (short)PEI_ERROR;
245 }
246 }
247
248 /* Clear static entity data store */
249 memset(&sm_data, 0, sizeof(sm_data));
250
251 /* Initialize multi-entity state machine */
252 sm_sequencer_init();
253
254 /*
255 * Initialize entity data (call init functions)
256 */
257 (void)ccd_init();
258
259 return (short)PEI_OK;
260 }
261
262 /*
263 +------------------------------------------------------------------------------
264 | Function : pei_timeout
265 +------------------------------------------------------------------------------
266 | Description : This function is called by the frame when a timer has expired.
267 |
268 | Parameters : index - timer index
269 |
270 | Return : PEI_OK - timeout processed
271 | PEI_ERROR - timeout not processed
272 |
273 +------------------------------------------------------------------------------
274 */
275
276 static short pei_timeout (U16 index)
277 {
278 (void)TRACE_FUNCTION("pei_timeout");
279
280 /*
281 * Process timeout
282 */
283 sm_disp_pei_timeout(index);
284
285 return PEI_OK;
286 }
287
288 /*
289 +------------------------------------------------------------------------------
290 | Function : pei_exit
291 +------------------------------------------------------------------------------
292 | Description : This function is called by the frame when the entity
293 | is terminated. All open resources are freed.
294 |
295 | Parameters : -
296 |
297 | Return : PEI_OK - exit sucessful
298 | PEI_ERROR - exit not successful
299 +------------------------------------------------------------------------------
300 */
301 static short pei_exit (void)
302 {
303 int nsapi;
304 (void)TRACE_FUNCTION ("SM pei_exit");
305
306 /*
307 * Clean up entity data
308 */
309
310 for (nsapi = (int)NAS_NSAPI_5; nsapi < NAS_SIZE_NSAPI; nsapi++) {
311 int index = sm_nsapi_to_index((U16)nsapi);
312
313 if (sm_data.sm_context_array[index] != NULL) {
314 /* sm_free_context_data_by_nsapi also sets pointer to NULL */
315 sm_free_context_data_by_nsapi(nsapi);
316 }
317
318 if (sm_data.sm_pending_mt_array[index] != NULL) {
319 /* sm_free_pending_mt_context_by_index also sets pointer to NULL */
320 sm_free_pending_mt_context_by_index((U16)index);
321 }
322 }
323
324 sm_sequencer_exit();
325
326 /* Exit CCD to clean up data stores */
327 (void)ccd_exit();
328
329 /*
330 * Close communication channels
331 */
332 (void)vsi_c_close(VSI_CALLER hCommACI);
333 hCommACI = VSI_ERROR;
334
335 (void)vsi_c_close(VSI_CALLER hCommMM);
336 hCommMM = VSI_ERROR;
337
338 (void)vsi_c_close(VSI_CALLER hCommUPM);
339 hCommUPM = VSI_ERROR;
340
341 return (short)PEI_OK;
342 }
343
344 /*
345 +------------------------------------------------------------------------------
346 | Function : pei_config
347 +------------------------------------------------------------------------------
348 | Description : This function is called by the frame when a primitive is
349 | received indicating dynamic configuration.
350 |
351 | This function is not used in this entity.
352 |
353 | Parameters : handle - Communication handle
354 |
355 | Return : PEI_OK - sucessful
356 | PEI_ERROR - not successful
357 +------------------------------------------------------------------------------
358 */
359 static short pei_config (char *inString)
360 {
361 (void)TRACE_FUNCTION ("SM pei_config");
362 (void)TRACE_FUNCTION (inString);
363
364 #ifdef DEBUG
365 if ( strcmp(inString, "DUMP_STATE") == 0) {
366 sm_dump_state();
367 }
368 #endif
369
370 return (short)PEI_OK;
371 }
372
373 /*
374 +------------------------------------------------------------------------------
375 | Function : pei_monitor
376 +------------------------------------------------------------------------------
377 | Description : This function is called by the frame in case sudden entity
378 | specific data is requested (e.g. entity Version).
379 |
380 | Parameters : out_monitor - return the address of the data to be
381 | monitoredCommunication handle
382 |
383 | Return : PEI_OK - sucessful (address in out_monitor is valid)
384 | PEI_ERROR - not successful
385 +------------------------------------------------------------------------------
386 */
387 /*@-compdef@*/ /*@-mods@*/
388 static short pei_monitor (void **out_monitor) /*@globals undef sm_mon@*/
389 {
390 (void)TRACE_FUNCTION ("SM pei_monitor");
391
392 /*
393 * Version = "0.S" (S = Step).
394 */
395 sm_mon.version = "SM 0.1";
396 *out_monitor = &sm_mon;
397
398 return PEI_OK;
399 }
400 /*@=compdef@*/ /*@=mods@*/
401
402 /*==== PUBLIC FUNCTIONS =====================================================*/
403
404 /*
405 +------------------------------------------------------------------------------
406 | Function : pei_create
407 +------------------------------------------------------------------------------
408 | Description : This function is called by the frame when the process is
409 | created.
410 |
411 | Parameters : out_name - Pointer to the buffer in which to locate
412 | the name of this entity
413 |
414 | Return : PEI_OK - entity created successfuly
415 | PEI_ERROR - entity could not be created
416 |
417 +------------------------------------------------------------------------------
418 */
419 short pei_create (T_PEI_INFO **info)
420 {
421 /*@-nullassign@*/
422 static T_PEI_INFO pei_info =
423 {
424 /*@i1@*/ SM_NAME, /* name */
425 { /* pei-table */
426 pei_init,
427 pei_exit,
428 pei_primitive,
429 pei_timeout,
430 NULL, /* no pei_signal function */
431 NULL, /* no pei_run function */
432 pei_config,
433 pei_monitor
434 },
435 (U32)2048, /* stack size */
436 (U16)10, /* queue entries */
437 (U16)165, /* priority (1->low, 255->high) */
438 (U16)SM_TIMER_MAX, /* number of timers */
439 (U8)0x03 /* flags: bit 0 active(0) body/passive(1) */
440 }; /* bit 1 com by copy(0)/reference(1) */
441 /*@=nullassign@*/
442
443 (void)TRACE_FUNCTION ("SM pei_create");
444
445 /*
446 * Close Resources if open
447 */
448 if (first_access)
449 {
450 first_access = FALSE;
451 } else {
452 (void)pei_exit();
453 }
454
455 /*
456 * Export startup configuration data
457 */
458 *info = &pei_info;
459
460 return PEI_OK;
461 }
462
463 /*==== END OF FILE ==========================================================*/