FreeCalypso > hg > fc-magnetite
comparison src/g23m-gprs/sm/sm_context_deactivate_control.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: Context Deactivate Control sub-state machine implementation | |
17 | in the SM entity. | |
18 | For design details, see: | |
19 | 8010.908 SM Detailed Specification | |
20 +---------------------------------------------------------------------------*/ | |
21 | |
22 /*==== DECLARATION CONTROL =================================================*/ | |
23 | |
24 /*==== INCLUDES =============================================================*/ | |
25 | |
26 #include "sm.h" | |
27 | |
28 #include "sm_context_control.h" | |
29 #include "sm_context_deactivate_control.h" | |
30 | |
31 /*==== CONSTS ===============================================================*/ | |
32 | |
33 /*==== TYPES ================================================================*/ | |
34 | |
35 typedef void (*T_SM_CONTEXT_DEACTIVATE_CONTROL_TRANSITION_FUNC)(struct T_SM_CONTEXT_DATA *ptr_context_data, /*@null@*/ void *data); | |
36 | |
37 typedef struct { | |
38 #ifdef DEBUG | |
39 T_SM_CONTEXT_DEACTIVATE_CONTROL_EVENT event; | |
40 #endif /* DEBUG */ | |
41 T_SM_CONTEXT_DEACTIVATE_CONTROL_TRANSITION_FUNC func; | |
42 } T_SM_CONTEXT_DEACTIVATE_CONTROL_TRANSITION; | |
43 | |
44 /*==== LOCALS ===============================================================*/ | |
45 | |
46 static void state_event_error(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
47 static void ignored (struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
48 static void go_to_S1 (struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
49 static void go_to_S2 (struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
50 static void handle_deactivate_network_in_S0(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
51 static void handle_deactivate_user_plane_in_S0(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
52 static void handle_deactivate_network_and_user_plane_in_S0(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
53 static void handle_deactivate_user_plane_in_S1(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
54 static void handle_deactivate_network_in_S2(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
55 static void handle_deactivate_completed(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data); | |
56 | |
57 /*********************************************************************** | |
58 * State/Transition Table | |
59 */ | |
60 static const T_SM_CONTEXT_DEACTIVATE_CONTROL_TRANSITION | |
61 transition[SM_CONTEXT_DEACTIVATE_CONTROL_NUMBER_OF_STATES][SM_CONTEXT_DEACTIVATE_CONTROL_NUMBER_OF_EVENTS] = | |
62 { | |
63 { /* S0: SM CONTEXT DEACTIVATE NULL */ | |
64 M_TRANSITION(SM_I_DEACTIVATE_NETWORK, handle_deactivate_network_in_S0), | |
65 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE, handle_deactivate_user_plane_in_S0), | |
66 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_AND_USER_PLANE, handle_deactivate_network_and_user_plane_in_S0), | |
67 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_COMPLETED, ignored), | |
68 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE_COMPLETED, ignored) | |
69 }, | |
70 { /* S1: SM CONTEXT DEACTIVATE NETWORK */ | |
71 M_TRANSITION(SM_I_DEACTIVATE_NETWORK, ignored), | |
72 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE, handle_deactivate_user_plane_in_S1), | |
73 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_AND_USER_PLANE, handle_deactivate_user_plane_in_S1), | |
74 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_COMPLETED, handle_deactivate_completed), | |
75 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE_COMPLETED, state_event_error) | |
76 }, | |
77 { /* S2: SM CONTEXT DEACTIVATE USER PLANE */ | |
78 M_TRANSITION(SM_I_DEACTIVATE_NETWORK, handle_deactivate_network_in_S2), | |
79 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE, ignored), | |
80 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_AND_USER_PLANE, handle_deactivate_network_in_S2), | |
81 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_COMPLETED, state_event_error), | |
82 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE_COMPLETED, handle_deactivate_completed) | |
83 }, | |
84 { /* S3: SM CONTEXT DEACTIVATE BOTH */ | |
85 M_TRANSITION(SM_I_DEACTIVATE_NETWORK, ignored), | |
86 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE, ignored), | |
87 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_AND_USER_PLANE, ignored), | |
88 M_TRANSITION(SM_I_DEACTIVATE_NETWORK_COMPLETED, go_to_S2), | |
89 M_TRANSITION(SM_I_DEACTIVATE_USER_PLANE_COMPLETED, go_to_S1) | |
90 } | |
91 }; | |
92 | |
93 /*==== PRIVATE FUNCTIONS ====================================================*/ | |
94 | |
95 /* | |
96 +------------------------------------------------------------------------------ | |
97 | Function : state_event_error | |
98 +------------------------------------------------------------------------------ | |
99 | Description : General function used to report state event errors. | |
100 | | |
101 | Parameters : context - Not used | |
102 | data - Not used | |
103 +------------------------------------------------------------------------------ | |
104 */ | |
105 static void state_event_error(/*@unused@*/ struct T_SM_CONTEXT_DATA *context, /*@unused@*/ /*@null@*/ void *data) | |
106 { | |
107 (void)TRACE_ERROR("SM Context Deactivate Control: STATE EVENT ERROR!"); | |
108 } | |
109 | |
110 /* | |
111 +------------------------------------------------------------------------------ | |
112 | Function : ignored | |
113 +------------------------------------------------------------------------------ | |
114 | Description : General function used for transitions that shall be ignored | |
115 | | |
116 | Parameters : context - Not used | |
117 | data - Not used | |
118 +------------------------------------------------------------------------------ | |
119 */ | |
120 static void ignored(/*@unused@*/ struct T_SM_CONTEXT_DATA *context, /*@unused@*/ /*@null@*/ void *data) | |
121 { | |
122 (void)TRACE_FUNCTION("SM Context Deactivate Control: Event ignored."); | |
123 } | |
124 | |
125 /* | |
126 +------------------------------------------------------------------------------ | |
127 | Function : go_to_S* | |
128 +------------------------------------------------------------------------------ | |
129 | Description : General functions for simple state transitions | |
130 | | |
131 | Parameters : context - Not used | |
132 | data - Not used | |
133 +------------------------------------------------------------------------------ | |
134 */ | |
135 static void go_to_S1(/*@unused@*/ struct T_SM_CONTEXT_DATA *context, /*@unused@*/ /*@null@*/ void *data) | |
136 { | |
137 /* Go to S1: SM CONTEXT DEACTIVATE NETWORK */ | |
138 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_NETWORK; | |
139 } | |
140 | |
141 static void go_to_S2(/*@unused@*/ struct T_SM_CONTEXT_DATA *context, /*@unused@*/ /*@null@*/ void *data) | |
142 { | |
143 /* Go to S0: SM CONTEXT DEACTIVATE USER PLANE */ | |
144 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_USER_PLANE; | |
145 } | |
146 | |
147 /* | |
148 +------------------------------------------------------------------------------ | |
149 | Function : handle_deactivate_network_in_S0 | |
150 +------------------------------------------------------------------------------ | |
151 | Description : Handle event SM_I_DEACTIVATE_NETWORK in S0 | |
152 | | |
153 | Parameters : context - Context data | |
154 | data - Cause | |
155 +------------------------------------------------------------------------------ | |
156 */ | |
157 static void handle_deactivate_network_in_S0(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data) | |
158 { | |
159 (void)TRACE_FUNCTION("handle_deactivate_network_in_S0"); | |
160 | |
161 TRACE_ASSERT(data != NULL); | |
162 | |
163 /* Go to state SM CONTEXT DEACTIVATE NETWORK */ | |
164 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_NETWORK; | |
165 | |
166 /* Order Network Control to deactivate */ | |
167 sm_network_control(context, SM_I_NETWORK_DEACTIVATE, data); | |
168 } | |
169 | |
170 /* | |
171 +------------------------------------------------------------------------------ | |
172 | Function : handle_deactivate_user_plane_in_S0 | |
173 +------------------------------------------------------------------------------ | |
174 | Description : Handle event SM_I_DEACTIVATE_USER_PLANE in S0 | |
175 | | |
176 | Parameters : context - Context data | |
177 | data - Not used | |
178 +------------------------------------------------------------------------------ | |
179 */ | |
180 static void handle_deactivate_user_plane_in_S0(struct T_SM_CONTEXT_DATA *context, /*@null@*/ /*@unused@*/ void *data) | |
181 { | |
182 (void)TRACE_FUNCTION("handle_deactivate_user_plane_in_S0"); | |
183 | |
184 /* Go to state SM CONTEXT DEACTIVATE USER PLANE */ | |
185 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_USER_PLANE; | |
186 | |
187 /* Order User Plane Control to deactivate */ | |
188 sm_user_plane_control(context, SM_I_USER_PLANE_DEACTIVATE, NULL); | |
189 } | |
190 | |
191 /* | |
192 +------------------------------------------------------------------------------ | |
193 | Function : handle_deactivate_network_and_user_plane_in_S0 | |
194 +------------------------------------------------------------------------------ | |
195 | Description : Handle event SM_I_DEACTIVATE_NETWORK_AND_USER_PLANE in S0 | |
196 | | |
197 | Parameters : context - Context data | |
198 | data - Cause | |
199 +------------------------------------------------------------------------------ | |
200 */ | |
201 static void handle_deactivate_network_and_user_plane_in_S0(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data) | |
202 { | |
203 (void)TRACE_FUNCTION("handle_deactivate_network_and_user_plane_in_S0"); | |
204 | |
205 TRACE_ASSERT(data != NULL); | |
206 | |
207 /* Go to state SM CONTEXT DEACTIVATE BOTH */ | |
208 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_BOTH; | |
209 | |
210 /* Order Network Control and User Plane Control to deactivate */ | |
211 sm_network_control (context, SM_I_NETWORK_DEACTIVATE, data); | |
212 sm_user_plane_control(context, SM_I_USER_PLANE_DEACTIVATE, NULL); | |
213 } | |
214 | |
215 /* | |
216 +------------------------------------------------------------------------------ | |
217 | Function : handle_deactivate_user_plane_in_S1 | |
218 +------------------------------------------------------------------------------ | |
219 | Description : Handle event SM_I_DEACTIVATE_USER_PLANE in S1 | |
220 | | |
221 | Parameters : context - Context data | |
222 | data - Not used | |
223 +------------------------------------------------------------------------------ | |
224 */ | |
225 static void handle_deactivate_user_plane_in_S1(struct T_SM_CONTEXT_DATA *context, /*@null@*/ /*@unused@*/ void *data) | |
226 { | |
227 (void)TRACE_FUNCTION("handle_deactivate_user_plane_in_S1"); | |
228 | |
229 /* Go to state SM CONTEXT DEACTIVATE BOTH */ | |
230 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_BOTH; | |
231 | |
232 /* Order User Plane Control to deactivate */ | |
233 sm_user_plane_control(context, SM_I_USER_PLANE_DEACTIVATE, NULL); | |
234 } | |
235 | |
236 /* | |
237 +------------------------------------------------------------------------------ | |
238 | Function : handle_deactivate_network_in_S2 | |
239 +------------------------------------------------------------------------------ | |
240 | Description : Handle event SM_I_DEACTIVATE_NETWORK in S2 | |
241 | | |
242 | Parameters : context - Context data | |
243 | data - Cause | |
244 +------------------------------------------------------------------------------ | |
245 */ | |
246 static void handle_deactivate_network_in_S2(struct T_SM_CONTEXT_DATA *context, /*@null@*/ void *data) | |
247 { | |
248 (void)TRACE_FUNCTION("handle_deactivate_network_in_S2"); | |
249 | |
250 TRACE_ASSERT(data != NULL); | |
251 | |
252 /* Go to state SM CONTEXT DEACTIVATE BOTH */ | |
253 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_BOTH; | |
254 | |
255 /* Order Network Control to deactivate */ | |
256 sm_network_control(context, SM_I_NETWORK_DEACTIVATE, data); | |
257 } | |
258 | |
259 /* | |
260 +------------------------------------------------------------------------------ | |
261 | Function : handle_deactivate_completed | |
262 +------------------------------------------------------------------------------ | |
263 | Description : Handle event SM_I_NETWORK_DEACTIVATE_COMPLETED in S1, or | |
264 | event SM_I_USER_PLANE_DEACTIVATED in S2. | |
265 | | |
266 | Parameters : context - Context data | |
267 | data - Not used | |
268 +------------------------------------------------------------------------------ | |
269 */ | |
270 static void handle_deactivate_completed(struct T_SM_CONTEXT_DATA *context, /*@null@*/ /*@unused@*/ void *data) | |
271 { | |
272 (void)TRACE_FUNCTION("handle_deactivate_completed"); | |
273 | |
274 /* Go to state SM CONTEXT DEACTIVATE NULL */ | |
275 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_NULL; | |
276 | |
277 /* Report deactivation complete to Context Control */ | |
278 sm_context_control(context, SM_I_DEACTIVATE_COMPLETED, NULL); | |
279 } | |
280 | |
281 /*==== PUBLIC FUNCTIONS =====================================================*/ | |
282 | |
283 /* | |
284 +------------------------------------------------------------------------------ | |
285 | Function : sm_context_deactivate_control_init | |
286 +------------------------------------------------------------------------------ | |
287 | Description : User Plane Control state machine initialization function | |
288 | |
289 | Parameters : context - Context data | |
290 +------------------------------------------------------------------------------ | |
291 */ | |
292 void sm_context_deactivate_control_init(struct T_SM_CONTEXT_DATA *context) | |
293 { | |
294 (void)TRACE_FUNCTION("sm_context_deactivate_control_init"); | |
295 | |
296 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_NULL; | |
297 } | |
298 | |
299 /* | |
300 +------------------------------------------------------------------------------ | |
301 | Function : sm_context_deactivate_control_exit | |
302 +------------------------------------------------------------------------------ | |
303 | Description : User Plane Control state machine exit function | |
304 | |
305 | Parameters : context - Context data | |
306 +------------------------------------------------------------------------------ | |
307 */ | |
308 void sm_context_deactivate_control_exit(struct T_SM_CONTEXT_DATA *context) | |
309 { | |
310 (void)TRACE_FUNCTION("sm_context_deactivate_control_exit"); | |
311 | |
312 context->context_deactivate_control_state = SM_CONTEXT_DEACTIVATE_NULL; | |
313 } | |
314 | |
315 /* | |
316 +------------------------------------------------------------------------------ | |
317 | Function : sm_context_deactivate_control_state | |
318 +------------------------------------------------------------------------------ | |
319 | Description : Returns a read-only string with the name of the active state. | |
320 | |
321 | Parameters : context - Context data | |
322 +------------------------------------------------------------------------------ | |
323 */ | |
324 #ifdef DEBUG | |
325 /*@observer@*/const char * | |
326 sm_context_deactivate_control_state(struct T_SM_CONTEXT_DATA *context) | |
327 { | |
328 /*@observer@*/ | |
329 static const char *state_name[SM_CONTEXT_DEACTIVATE_CONTROL_NUMBER_OF_STATES] = { | |
330 "S0_SM_CONTEXT_DEACTIVATE_NULL", | |
331 "S1_SM_CONTEXT_DEACTIVATE_NETWORK", | |
332 "S2_SM_CONTEXT_DEACTIVATE_USER_PLANE", | |
333 "S3_SM_CONTEXT_DEACTIVATE_BOTH" | |
334 }; | |
335 | |
336 TRACE_ASSERT(context->context_deactivate_control_state < SM_CONTEXT_DEACTIVATE_CONTROL_NUMBER_OF_STATES); | |
337 | |
338 return state_name[(U16)context->context_deactivate_control_state]; | |
339 } | |
340 #endif | |
341 | |
342 /* | |
343 +------------------------------------------------------------------------------ | |
344 | Function : sm_context_deactivate_control | |
345 +------------------------------------------------------------------------------ | |
346 | Description : User Plane Control state machine | |
347 | | |
348 | Parameters : context - Context data | |
349 | event - Internal event (see sm_context_deactivate_control.h) | |
350 | data - Event dependent parameter | |
351 +------------------------------------------------------------------------------ | |
352 */ | |
353 void sm_context_deactivate_control(struct T_SM_CONTEXT_DATA *context, | |
354 T_SM_CONTEXT_DEACTIVATE_CONTROL_EVENT event, | |
355 /*@null@*/ void *data) | |
356 { | |
357 #ifdef DEBUG | |
358 const char *old_state_name, *new_state_name; | |
359 T_SM_CONTEXT_DEACTIVATE_CONTROL_STATE old_state; | |
360 /*@observer@*/ | |
361 static const char *event_name[SM_CONTEXT_DEACTIVATE_CONTROL_NUMBER_OF_EVENTS] = { | |
362 "SM_I_DEACTIVATE_NETWORK", | |
363 "SM_I_DEACTIVATE_USER_PLANE", | |
364 "SM_I_DEACTIVATE_NETWORK_AND_USER_PLANE", | |
365 "SM_I_DEACTIVATE_NETWORK_COMPLETED", | |
366 "SM_I_DEACTIVATE_USER_PLANE_COMPLETED" | |
367 }; | |
368 | |
369 TRACE_ASSERT(event < SM_CONTEXT_DEACTIVATE_CONTROL_NUMBER_OF_EVENTS); | |
370 | |
371 old_state = context->context_deactivate_control_state; | |
372 old_state_name = sm_context_deactivate_control_state(context); | |
373 | |
374 if (transition[(U16)old_state][(U16)event].event != event) { | |
375 (void)TRACE_ERROR("Event table error in sm_context_deactivate_control!"); | |
376 } | |
377 #endif /* DEBUG */ | |
378 | |
379 transition[(U16)context->context_deactivate_control_state] | |
380 [(U16)event].func(context, data); | |
381 | |
382 #ifdef DEBUG | |
383 new_state_name = sm_context_deactivate_control_state(context); | |
384 | |
385 (void)TRACE_EVENT_P4("SM CX DEAC #%d: %s => %s to %s", context->nsapi, | |
386 event_name[(U16)event], old_state_name, new_state_name); | |
387 #endif /* DEBUG */ | |
388 } | |
389 | |
390 /*==== END OF FILE ==========================================================*/ |