comparison g23m-gsm/mm/mm_em.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
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 defines the engineering mode (EM) device driver for
18 | the G23 protocol stack. This driver is used to control all
19 } engineering mode related functions.
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef MM_EM_C
24 #define MM_EM_C
25
26 #include "config.h"
27 #include "fixedconf.h"
28 #include "condat-features.h"
29
30 #define ENTITY_MM
31
32 /*==== INCLUDES ===================================================*/
33
34 #include <string.h>
35 #include <stdlib.h>
36 #include <stddef.h>
37 #include "typedefs.h"
38 #include "pcm.h"
39 #include "pconst.cdg"
40 #include "mconst.cdg"
41 #include "message.h"
42 #include "ccdapi.h"
43 #include "vsi.h"
44 #include "custom.h"
45 #include "gsm.h"
46 #include "prim.h"
47 #include "cnf_mm.h"
48 #include "mon_mm.h"
49 #include "pei.h"
50 #include "tok.h"
51 #include "mm.h"
52 #include "mm_em.h"
53
54 /*==== EXPORT =====================================================*/
55
56 /*==== PRIVAT =====================================================*/
57
58 /*==== VARIABLES ==================================================*/
59
60 #ifdef FF_EM_MODE
61 GLOBAL UBYTE em_mm_event_buffer[EM_MM_BUFFER_SIZE];
62 GLOBAL UBYTE em_mm_buffer_write;
63
64 /* Event tracing flags for EM */
65 GLOBAL BOOL mm_v[EM_MAX_MM_EVENTS];
66
67 static UBYTE em_mm_trace_occured;
68 #endif /* FF_EM_MODE */
69
70 /*==== FUNCTIONS ==================================================*/
71
72 #ifdef FF_EM_MODE
73
74 /*
75 +------------------------------------------------------------------------------
76 | Function : em_write_buffer_2
77 +------------------------------------------------------------------------------
78 | Description : Perform buffer check and store corresponding data in it.
79 |
80 | Parameters : Event number
81 |
82 | Return : TRUE/FALSE
83 |
84 +------------------------------------------------------------------------------
85 */
86
87 GLOBAL UBYTE em_write_buffer_2 (UBYTE event_no)
88 {
89 TRACE_FUNCTION ("mm_em_write_buffer_2()");
90
91 if (check_write_index(2))
92 {
93 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
94 em_mm_event_buffer[em_mm_buffer_write++] = 0; /* Length: 0 means no value */
95 return FALSE; /* Data is stored inside buffer, reset flag */
96 }
97 else
98 return TRUE; /* No more space inside buffer, serve flag next time */
99 }
100
101 /*
102 +------------------------------------------------------------------------------
103 | Function : em_write_buffer_3
104 +------------------------------------------------------------------------------
105 | Description : Perform buffer check and store corresponding data in it.
106 |
107 | Parameters : Event number, data value
108 |
109 | Return : TRUE/FALSE
110 |
111 +------------------------------------------------------------------------------
112 */
113
114 GLOBAL UBYTE em_write_buffer_3 (UBYTE event_no, UBYTE value)
115 {
116 TRACE_FUNCTION ("mm_em_write_buffer_3()");
117
118 if (check_write_index(3))
119 {
120 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
121 em_mm_event_buffer[em_mm_buffer_write++] = 1; /* Length: 0 means no value */
122 em_mm_event_buffer[em_mm_buffer_write++] = value; /* Value: Data to be stored */
123 return FALSE; /* Data is stored inside buffer, reset flag */
124 }
125 else
126 return TRUE; /* No more space inside buffer, serve flag next time */
127 }
128
129 /*
130 +------------------------------------------------------------------------------
131 | Function : em_write_buffer_3a
132 +------------------------------------------------------------------------------
133 | Description : Perform buffer check and store corresponding data in it.
134 |
135 | Parameters : Event number, data value (USHORT)
136 |
137 | Return : TRUE/FALSE
138 |
139 +------------------------------------------------------------------------------
140 */
141
142 GLOBAL UBYTE em_write_buffer_3a (UBYTE event_no, USHORT value)
143 {
144 TRACE_FUNCTION ("mm_em_write_buffer_3a()");
145
146 if (check_write_index(4))
147 {
148 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
149 em_mm_event_buffer[em_mm_buffer_write++] = 2; /* Length: 0 means no value */
150
151 /* Value: Data to be stored. MSB first, LSB second */
152 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value >> 8);
153 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value);
154 return FALSE; /* Data is stored inside buffer, reset flag */
155 }
156 else
157 return TRUE; /* No more space inside buffer, serve flag next time */
158 }
159
160 /*
161 +------------------------------------------------------------------------------
162 | Function : em_write_buffer_3b
163 +------------------------------------------------------------------------------
164 | Description : Perform buffer check and store corresponding data in it.
165 |
166 | Parameters : Event number, data value (ULONG)
167 |
168 | Return : TRUE/FALSE
169 |
170 | Pupose : Used for storing TMSI
171 +------------------------------------------------------------------------------
172 */
173 #define RINGBUF_3B_LENGTH (2 + 4)
174 GLOBAL UBYTE em_write_buffer_3b (UBYTE event_no, ULONG value)
175 {
176 TRACE_FUNCTION ("mm_em_write_buffer_3b()");
177
178 if (check_write_index(RINGBUF_3B_LENGTH))
179 {
180 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
181 em_mm_event_buffer[em_mm_buffer_write++] = RINGBUF_3B_LENGTH-2; /* Length: 0 means no value */
182
183 /* Value: Data to be stored. MSB first, LSB second */
184 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value>>24); /* MSB first */
185 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value>>16); /* new TMSI */
186 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value>> 8);
187 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value); /* LSB last */
188 return FALSE; /* Data is stored inside buffer, reset flag */
189 }
190 else
191 return TRUE; /* No more space inside buffer, serve flag next time */
192 }
193 /*
194 +------------------------------------------------------------------------------
195 | Function : em_write_buffer_4
196 +------------------------------------------------------------------------------
197 | Description : Perform buffer check and store corresponding data in it.
198 |
199 | Parameters : Event number, data value1, data plmn (T_plmn)
200 |
201 | Return : TRUE/FALSE
202 |
203 | Pupose : Used for storing PLMN list
204 +------------------------------------------------------------------------------
205 */
206
207 GLOBAL UBYTE em_write_buffer_4 (UBYTE event_no, UBYTE value1, T_plmn *plmn)
208 {
209 UBYTE i;
210 UBYTE n = 2;
211
212 TRACE_FUNCTION ("mm_em_write_buffer_4()");
213
214 n += ((SIZE_MCC + SIZE_MNC) * value1); /*Compute exact size of data to be stored*/
215
216 if(check_write_index(n))
217 {
218 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
219 em_mm_event_buffer[em_mm_buffer_write++] = (n - 2); /* Length: 0 means no value */
220 for (i = 0; i < value1; i++) /*stores MCC and MNC of every available PLMN*/
221 {
222 if(plmn[i].v_plmn)
223 {
224 memcpy(&em_mm_event_buffer[em_mm_buffer_write], plmn[i].mcc, SIZE_MCC);
225 em_mm_buffer_write += SIZE_MCC;
226 memcpy(&em_mm_event_buffer[em_mm_buffer_write], plmn[i].mnc, SIZE_MNC);
227 em_mm_buffer_write += SIZE_MNC;
228 } /*valid*/
229 } /*for*/
230 return FALSE; /* Data is stored inside buffer, reset flag */
231 }/* check write index*/
232 else
233 {
234 return TRUE; /* No more space inside buffer, serve flag next time */
235 }
236 }
237 /*
238 +------------------------------------------------------------------------------
239 | Function : em_write_buffer_4a
240 +------------------------------------------------------------------------------
241 | Description : Perform buffer check and store corresponding data in it.
242 |
243 | Parameters : Event number, data value1 (UBYTE), data value2 (USHORT)
244 |
245 | Return : TRUE/FALSE
246 |
247 | Pupose : Used for storing Location Update Reject
248 +------------------------------------------------------------------------------
249 */
250 #define RINGBUF_4A_LENGTH (2 + 1 + 2)
251 GLOBAL UBYTE em_write_buffer_4a (UBYTE event_no, UBYTE value1, USHORT value2)
252 {
253 TRACE_FUNCTION ("mm_em_write_buffer_4a()");
254
255 if (check_write_index(RINGBUF_4A_LENGTH))
256 {
257 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
258 em_mm_event_buffer[em_mm_buffer_write++] = RINGBUF_4A_LENGTH-2; /* Length: 0 means no value */
259 em_mm_event_buffer[em_mm_buffer_write++] = value1;
260 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value2 >> 8);
261 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value2);
262
263 return FALSE; /* Data is stored inside buffer, reset flag */
264
265 }/* check write index*/
266 else
267 return TRUE; /* No more space inside buffer, serve flag next time */
268 }
269
270 /*
271 +------------------------------------------------------------------------------
272 | Function : em_write_buffer_4b
273 +------------------------------------------------------------------------------
274 | Description : Perform buffer check and store corresponding data in it.
275 |
276 | Parameters : Event number, data identity type (UBYTE), data value (UBYTE *)
277 |
278 | Return : TRUE/FALSE
279 |
280 | Pupose : Used for storing IMEI, IMEISV, IMSI during Identity Request/Response
281 +------------------------------------------------------------------------------
282 */
283
284 GLOBAL UBYTE em_write_buffer_4b (UBYTE event_no, UBYTE ident_type, UBYTE *value)
285 {
286
287 UBYTE n;
288 UBYTE digits;
289
290 TRACE_FUNCTION ("mm_em_write_buffer_4b()");
291
292 switch (ident_type) /*Creating length of data to be stored*/
293 {
294 case ID_TYPE_IMEI:
295 digits = 14; /*length of IMEI */
296 break;
297 case ID_TYPE_IMSI:
298 case ID_TYPE_IMEISV:
299 digits = 16; /*length of IMSI / IMEISV */
300 break;
301 default: /* Illegal mobile identity - not possible because of calling function*/
302 break;
303 } /*switch*/
304 n = 3 + digits; /* Tag + Length + Type + Digits */ /*lint !e644*/ /*for lint: Digits are
305 always initialized because of calling function*/
306
307 if (check_write_index(n))
308 {
309 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
310 em_mm_event_buffer[em_mm_buffer_write++] = (n - 2); /* Length: 0 means no value */
311 em_mm_event_buffer[em_mm_buffer_write++] = ident_type;
312 memcpy (&em_mm_event_buffer[em_mm_buffer_write], value, digits);
313 em_mm_buffer_write += digits;
314 return FALSE; /* Data is stored inside buffer, reset flag */
315
316 }/* check write index*/
317 else
318 return TRUE; /* No more space inside buffer, serve flag next time */
319 }
320
321 /*
322 +------------------------------------------------------------------------------
323 | Function : em_write_buffer_4c
324 +------------------------------------------------------------------------------
325 | Description : Perform buffer check and store corresponding data in it.
326 |
327 | Parameters : Event number, data identity type (UBYTE), data value (ULONG)
328 |
329 | Return : TRUE/FALSE
330 |
331 | Pupose : Used during Identity Request/Response for storing TMSI
332 +------------------------------------------------------------------------------
333 */
334 #define RINGBUF_4C_LENGTH (2 + 1 + 4)
335 GLOBAL UBYTE em_write_buffer_4c (UBYTE event_no, UBYTE ident_type, ULONG value)
336 {
337 TRACE_FUNCTION ("mm_em_write_buffer_4c()");
338 if (check_write_index(RINGBUF_4C_LENGTH))
339 {
340 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
341 em_mm_event_buffer[em_mm_buffer_write++] = (RINGBUF_4C_LENGTH - 2); /* Length: 0 means no value */
342 em_mm_event_buffer[em_mm_buffer_write++] = ident_type;
343 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value>>24); /* MSB first */
344 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value>>16);
345 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value>> 8);
346 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(value); /* LSB last */
347 return FALSE; /* Data is stored inside buffer, reset flag */
348 }/* check write index*/
349 else
350 return TRUE; /* No more space inside buffer, serve flag next time */
351 }
352
353 /*
354 +------------------------------------------------------------------------------
355 | Function : em_write_buffer_5a
356 +------------------------------------------------------------------------------
357 | Description : Perform buffer check and store corresponding data in it.
358 |
359 | Parameters : Event number, data value (UBYTE), data mcc (UBYTE), data mnc (UBYTE)
360 |
361 | Return : TRUE/FALSE
362 |
363 | Pupose : Used for storing Service Mode, MCC und MNC during registration
364 | Used for storing data during cell reselection
365 +------------------------------------------------------------------------------
366 */
367 #define RINGBUF_5A_LENGTH (2 + 1 + SIZE_MCC + SIZE_MNC)
368 GLOBAL UBYTE em_write_buffer_5a (UBYTE event_no, UBYTE value, UBYTE mcc[SIZE_MCC], UBYTE mnc[SIZE_MNC])
369 {
370 TRACE_FUNCTION ("mm_em_write_buffer_5a()");
371
372 if (check_write_index(RINGBUF_5A_LENGTH))
373 {
374 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
375 em_mm_event_buffer[em_mm_buffer_write++] = RINGBUF_5A_LENGTH-2; /* Length: 0 means no value */
376 em_mm_event_buffer[em_mm_buffer_write++] = value;
377
378 /*missing check for validy*/
379 memcpy(&em_mm_event_buffer[em_mm_buffer_write], mcc, SIZE_MCC);
380 em_mm_buffer_write += SIZE_MCC;
381 memcpy(&em_mm_event_buffer[em_mm_buffer_write], mnc, SIZE_MNC);
382 em_mm_buffer_write += SIZE_MNC;
383
384 return FALSE; /* Data is stored inside buffer, reset flag */
385 }/* check write index*/
386 else
387 return TRUE; /* No more space inside buffer, serve flag next time */
388 }
389
390 /*
391 +------------------------------------------------------------------------------
392 | Function : em_write_buffer_6
393 +------------------------------------------------------------------------------
394 | Description : Perform buffer check and store corresponding data in it.
395 |
396 | Parameters : Event number, data location update type (UBYTE), data lai (T_loc_area_ident)
397 |
398 | Return : TRUE/FALSE
399 |
400 | Pupose : Used for storing Location Update Type, MCC, MNC and LAC
401 +------------------------------------------------------------------------------
402 */
403 #define RINGBUF_6_LENGTH (2 + 1 + SIZE_MCC + SIZE_MNC + 2)
404 GLOBAL UBYTE em_write_buffer_6 (UBYTE event_no, UBYTE loc_upd_type, T_loc_area_ident lai)
405 {
406 TRACE_FUNCTION ("mm_em_write_buffer_6()");
407
408 if (check_write_index(RINGBUF_6_LENGTH))
409 {
410 em_mm_event_buffer[em_mm_buffer_write++] = event_no; /* Tag: Event number */
411 em_mm_event_buffer[em_mm_buffer_write++] = RINGBUF_6_LENGTH - 2; /* Length: 0 means no value */
412 em_mm_event_buffer[em_mm_buffer_write++] = loc_upd_type;
413 memcpy(&em_mm_event_buffer[em_mm_buffer_write], lai.mcc, SIZE_MCC); /*stores MCC*/
414 em_mm_buffer_write += SIZE_MCC;
415 memcpy(&em_mm_event_buffer[em_mm_buffer_write], lai.mnc, SIZE_MNC); /*stores MNC*/
416 em_mm_buffer_write += SIZE_MNC;
417 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(lai.lac >> 8); /*stores LAC*/
418 em_mm_event_buffer[em_mm_buffer_write++] = (UBYTE)(lai.lac);
419 return FALSE; /* Data is stored inside buffer, reset flag */
420 }/* check write index*/
421 else
422 return TRUE; /* No more space inside buffer, serve flag next time */
423 }
424
425 /*
426 +------------------------------------------------------------------------------
427 | Function : check_write_index
428 +------------------------------------------------------------------------------
429 | Description : Checks the write index inside the buffer. No reset when
430 | buffer is full.
431 |
432 | Parameters : Number of bytes to be stored in buffer
433 |
434 | Return : TRUE/FALSE
435 |
436 +------------------------------------------------------------------------------
437 */
438
439 GLOBAL UBYTE check_write_index (UBYTE n)
440 {
441 TRACE_FUNCTION ("mm_check_write_index()");
442
443 if (em_mm_buffer_write + n < EM_MM_BUFFER_SIZE)
444 {
445 /*
446 * ACI is informed about the first event trace,
447 * used for later data processing.
448 */
449 if (em_mm_trace_occured EQ 0)
450 {
451 PALLOC(data, EM_DATA_IND);
452 data->entity = EM_MM;
453 PSENDX(MMI, data);
454 em_mm_trace_occured++;
455 }
456 return TRUE;
457 }
458 else
459 return FALSE;
460 }
461
462 /*
463 +------------------------------------------------------------------------------
464 | Function : mm_em_mm_event_req
465 +------------------------------------------------------------------------------
466 | Description : Set the event tracing flags according the bitmask for dl
467 |
468 | Parameters : Primitive - Bitmask
469 |
470 | Return :
471 |
472 +------------------------------------------------------------------------------
473 */
474
475 GLOBAL void mm_em_dl_event_req (T_EM_DL_EVENT_REQ *em_dl_event_req)
476 {
477 TRACE_FUNCTION ("mm_em_dl_event_req()");
478
479 PSENDX(DL, em_dl_event_req);
480 }
481
482 /*
483 +------------------------------------------------------------------------------
484 | Function : em_init_mm_event_trace
485 +------------------------------------------------------------------------------
486 | Description : Initialize the event tracing flags for MM
487 |
488 | Parameters : void
489 |
490 | Return : void
491 |
492 +------------------------------------------------------------------------------
493 */
494 GLOBAL void em_init_mm_event_trace(void)
495 {
496 UBYTE i;
497
498 TRACE_FUNCTION ("em_init_mm_event_trace()");
499
500 for (i = 0; i < EM_MAX_MM_EVENTS; i++)
501 mm_v[i] = 0;
502
503 em_mm_buffer_write = 0;
504 }
505
506 /*
507 +------------------------------------------------------------------------------
508 | Function : mm_em_mm_event_req
509 +------------------------------------------------------------------------------
510 | Description : Set the event tracing flags according the bitmask
511 |
512 | Parameters : Primitive - Bitmask
513 |
514 | Return :
515 |
516 +------------------------------------------------------------------------------
517 */
518
519 GLOBAL void mm_em_mm_event_req (T_EM_MM_EVENT_REQ *em_mm_event_req)
520 {
521 UBYTE i;
522
523 TRACE_FUNCTION ("mm_em_mm_event_req()");
524
525 /*
526 * The event tracing flags are set according the bitmask. mm_v[i] are
527 * the flags belonging to the event number described in 8443.601
528 */
529 for(i = 1; i < EM_MAX_MM_EVENTS; i++)
530 mm_v[i] = ((em_mm_event_req->bitmask_mm & (0x01<<(i-1))) > 0) ? TRUE : FALSE;
531
532 /*
533 * A new event trace is generated therefore the flag is reset.
534 */
535 em_mm_trace_occured = 0;
536
537 PFREE(em_mm_event_req);
538 }
539 #endif /* FF_EM_MODE */
540
541 #endif /* MM_EM_C */