comparison src/g23m-gsm/mm/mm_em.c @ 104:27a4235405c6

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