FreeCalypso > hg > fc-tourmaline
comparison src/g23m-gprs/upm/upm.c @ 1:fa8dc04885d8
src/g23m-*: import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Oct 2020 06:25:50 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:4e78acac3d88 | 1:fa8dc04885d8 |
---|---|
1 /*---------------------------------------------------------------------------- | |
2 | Project : 3G PS | |
3 | Module : UPM | |
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 for the UPM entity. | |
17 | For design details, see: | |
18 | 8010.939 UPM Detailed Specification | |
19 +---------------------------------------------------------------------------*/ | |
20 | |
21 /*==== DECLARATION CONTROL =================================================*/ | |
22 | |
23 /*==== INCLUDES ============================================================*/ | |
24 | |
25 #include "upm.h" | |
26 | |
27 /*==== CONSTS ===============================================================*/ | |
28 | |
29 /*==== TYPES ================================================================*/ | |
30 | |
31 T_UPM_DATA upm_data; | |
32 | |
33 /*==== LOCALS ===============================================================*/ | |
34 | |
35 /*==== PUBLIC FUNCTIONS =====================================================*/ | |
36 | |
37 /* | |
38 +------------------------------------------------------------------------------ | |
39 | Function : upm_pfree | |
40 +------------------------------------------------------------------------------ | |
41 | Description : PFREE macro replacement | |
42 | | |
43 | Parameters : data - memory to free | |
44 +------------------------------------------------------------------------------ | |
45 */ | |
46 void upm_pfree(/*@only@*/ /*@null@*/ /*@out@*/ void *data) | |
47 { | |
48 if (data != NULL) | |
49 { | |
50 vsi_c_pfree((T_VOID_STRUCT **)&data FILE_LINE_MACRO); | |
51 } | |
52 } | |
53 | |
54 /* | |
55 +------------------------------------------------------------------------------ | |
56 | Function : upm_mfree | |
57 +------------------------------------------------------------------------------ | |
58 | Description : Wrapper for MFREE macro. | |
59 | | |
60 | Parameters : data - memory to free (NULL allowed) | |
61 +------------------------------------------------------------------------------ | |
62 */ | |
63 void upm_mfree(/*@only@*/ /*@out@*/ /*@null@*/ void *data) | |
64 { | |
65 if (data != NULL) { | |
66 MFREE(data); | |
67 } | |
68 } | |
69 | |
70 /* | |
71 +------------------------------------------------------------------------------ | |
72 | Function : upm_nsapi2nsapi_set | |
73 +------------------------------------------------------------------------------ | |
74 | Description : Return nsapi_set corresponding to NSAPI | |
75 | | |
76 | Parameters : nsapi - NSAPI | |
77 +------------------------------------------------------------------------------ | |
78 */ | |
79 U16 upm_nsapi2nsapi_set(int /*@alt U8@*/ nsapi) /*@*/ | |
80 { | |
81 TRACE_ASSERT ((T_NAS_nsapi)nsapi >= NAS_NSAPI_5 && nsapi <= NAS_NSAPI_15); | |
82 | |
83 return (U16)(1UL << (U16)nsapi); | |
84 } | |
85 | |
86 /* | |
87 +------------------------------------------------------------------------------ | |
88 | Function : upm_get_context_data_from_nsapi | |
89 +------------------------------------------------------------------------------ | |
90 | Description : Returns context data structure associated with indicated NSAPI. | |
91 | | |
92 | Parameters : nsapi - NSAPI index | |
93 +------------------------------------------------------------------------------ | |
94 */ | |
95 /*@null@*/ /*@exposed@*/ | |
96 struct T_CONTEXT_DATA *upm_get_context_data_from_nsapi(int /*@alt U8@*/ nsapi) | |
97 { | |
98 TRACE_ASSERT (((T_NAS_nsapi)nsapi >= NAS_NSAPI_5 && nsapi <= NAS_NSAPI_15)); | |
99 | |
100 /*lint -e{661} upm_context_array causes out of bounds access, it does not! */ | |
101 return (upm_data.upm_context_array[nsapi - (int)NAS_NSAPI_5]); | |
102 } | |
103 | |
104 /* | |
105 +------------------------------------------------------------------------------ | |
106 | Function : upm_assign_context_data_to_nsapi | |
107 +------------------------------------------------------------------------------ | |
108 | Description : Assign context data structure to global context array. | |
109 | | |
110 | Parameters : ptr_context_data - Pointer to context data | |
111 | nsapi - NSAPI index | |
112 +------------------------------------------------------------------------------ | |
113 */ | |
114 void upm_assign_context_data_to_nsapi(/*@keep@*/ | |
115 struct T_CONTEXT_DATA *ptr_context_data, | |
116 int /*@alt U8@*/ nsapi) | |
117 { | |
118 (void)TRACE_EVENT_P2("upm_assign_context_data_to_nsapi: NSAPI%3d = %p", nsapi, ptr_context_data); | |
119 | |
120 TRACE_ASSERT ((T_NAS_nsapi)nsapi >= NAS_NSAPI_5 && nsapi <= NAS_NSAPI_15); | |
121 | |
122 /*lint -e{661} upm_context_array causes out of bounds access, it does not! */ | |
123 upm_data.upm_context_array[nsapi - (int)NAS_NSAPI_5] = ptr_context_data; | |
124 ptr_context_data->nsapi = nsapi; | |
125 } | |
126 | |
127 /* | |
128 +------------------------------------------------------------------------------ | |
129 | Function : upm_free_context_data | |
130 +------------------------------------------------------------------------------ | |
131 | Description : Free context data structure associated with indicated NSAPI. | |
132 | | |
133 | Parameters : nsapi - NSAPI index | |
134 +------------------------------------------------------------------------------ | |
135 */ | |
136 void upm_free_context_data(int /*@alt U8@*/ nsapi) | |
137 { | |
138 TRACE_ASSERT ((T_NAS_nsapi)nsapi >= NAS_NSAPI_5 && nsapi <= NAS_NSAPI_15); | |
139 | |
140 /*lint -e661 (upm_context_array causes out of bounds access, it does not!) */ | |
141 if ( upm_data.upm_context_array[nsapi - (int)NAS_NSAPI_5] != NULL ) { | |
142 upm_mfree(upm_data.upm_context_array[nsapi - (int)NAS_NSAPI_5]); | |
143 upm_data.upm_context_array[nsapi - (int)NAS_NSAPI_5] = NULL; | |
144 /*lint +e661 (upm_context_array causes out of bounds access, it does not!) */ | |
145 } | |
146 } | |
147 | |
148 /* | |
149 +------------------------------------------------------------------------------ | |
150 | Function : upm_check_for_released_context_and_release | |
151 +------------------------------------------------------------------------------ | |
152 | Description : Check whether a context is released (both link and DTI | |
153 | connections released), and if so, freee context data structure | |
154 | associated with indicated NSAPI. | |
155 | | |
156 | Parameters : nsapi - NSAPI index | |
157 +------------------------------------------------------------------------------ | |
158 */ | |
159 void upm_check_for_released_context_and_release(struct T_CONTEXT_DATA *context) | |
160 { | |
161 if (upm_is_link_released(context) | |
162 #ifndef UPM_WITHOUT_USER_PLANE | |
163 && upm_is_dti_disconnected(context) | |
164 #endif | |
165 ) | |
166 { | |
167 U8 nsapi = context->nsapi; | |
168 | |
169 upm_free_context_data(nsapi); | |
170 (void)TRACE_EVENT_P1("upm_check_for_released_context_and_release on NSAPI %d: Context data freed...", nsapi); | |
171 } | |
172 } | |
173 | |
174 /* | |
175 +------------------------------------------------------------------------------ | |
176 | Function : upm_get_current_rat | |
177 +------------------------------------------------------------------------------ | |
178 | Description : Returns the RAT in which UPM is currently active | |
179 | | |
180 | Parameters : None | |
181 +------------------------------------------------------------------------------ | |
182 */ | |
183 #ifdef TI_DUAL_MODE | |
184 T_PS_rat upm_get_current_rat(void) | |
185 { | |
186 return upm_data.upm_rat; | |
187 } | |
188 #endif /* TI_DUAL_MODE */ | |
189 | |
190 /* | |
191 +------------------------------------------------------------------------------ | |
192 | Function : upm_set_current_rat | |
193 +------------------------------------------------------------------------------ | |
194 | Description : Sets currently active RAT | |
195 | | |
196 | Parameters : rat - RAT received from SM or MM | |
197 +------------------------------------------------------------------------------ | |
198 */ | |
199 #ifdef TI_DUAL_MODE | |
200 void upm_set_current_rat(T_PS_rat rat) | |
201 /*@modifies upm_data.upm_rat@*/ | |
202 { | |
203 upm_data.upm_rat = rat; | |
204 } | |
205 #endif /* TI_DUAL_MODE */ | |
206 | |
207 /* | |
208 +------------------------------------------------------------------------------ | |
209 | Function : upm_ll_entity_test | |
210 +------------------------------------------------------------------------------ | |
211 | Description : Returns TRUE if upm_ll_entity_test is set in UPM data struct | |
212 | | |
213 | Parameters : None | |
214 +------------------------------------------------------------------------------ | |
215 */ | |
216 BOOL upm_ll_entity_test(void) | |
217 { | |
218 return upm_data.upm_ll_entity_test; | |
219 } | |
220 | |
221 /* | |
222 +------------------------------------------------------------------------------ | |
223 | Function : upm_activate_ll_entity_test | |
224 +------------------------------------------------------------------------------ | |
225 | Description : Enables lower layer stubs for entity test | |
226 | | |
227 | Parameters : None | |
228 +------------------------------------------------------------------------------ | |
229 */ | |
230 void upm_activate_ll_entity_test(void) | |
231 { | |
232 upm_data.upm_ll_entity_test = TRUE; | |
233 } | |
234 | |
235 /* | |
236 +------------------------------------------------------------------------------ | |
237 | Function : upm_set_sequence_number | |
238 +------------------------------------------------------------------------------ | |
239 | Description : Stores the receive sequence number from MM for later retrieval | |
240 | | |
241 | Parameters : ptr_context_data - Context data | |
242 | seq_no - Receive sequence number | |
243 +------------------------------------------------------------------------------ | |
244 */ | |
245 void upm_set_sequence_number(struct T_CONTEXT_DATA *ptr_context_data, U8 seq_no) | |
246 { | |
247 (void)TRACE_FUNCTION("upm_set_sequence_number"); | |
248 | |
249 ptr_context_data->seq_nos_valid = (U8)TRUE; | |
250 ptr_context_data->recv_seq_no = seq_no; | |
251 } | |
252 | |
253 /* | |
254 +------------------------------------------------------------------------------ | |
255 | Function : upm_get_sequence_number | |
256 +------------------------------------------------------------------------------ | |
257 | Description : Retrieves the receive sequence number previously gotten from MM | |
258 | | |
259 | Parameters : ptr_context_data - Context data | |
260 +------------------------------------------------------------------------------ | |
261 */ | |
262 U8 upm_get_sequence_number(struct T_CONTEXT_DATA *ptr_context_data) | |
263 { | |
264 (void)TRACE_FUNCTION("upm_get_sequence_number"); | |
265 | |
266 if (ptr_context_data->seq_nos_valid != (U8)0) | |
267 { | |
268 ptr_context_data->seq_nos_valid = (U8)0; | |
269 return ptr_context_data->recv_seq_no; | |
270 } else { | |
271 return (U8)0; | |
272 } | |
273 } | |
274 | |
275 /*==== END OF FILE ==========================================================*/ |