comparison gsm-fw/g23m-gsm/sms/sms_time.c @ 673:2f7df7a314f8

gsm-fw/g23m-gsm subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 28 Sep 2014 23:20:04 +0000
parents
children 6a5dca88b619
comparison
equal deleted inserted replaced
672:0dc6f9e8e980 673:2f7df7a314f8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : SMS_TIME
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 Modul defines the timer handling functions
18 | for the component SMS of the mobile station
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef SMS_TIM_C
23 #define SMS_TIM_C
24
25 #define ENTITY_SMS
26
27 /*==== INCLUDES ===================================================*/
28
29 #include <string.h>
30 #include <stdlib.h>
31 #include <stddef.h>
32 #include "typedefs.h"
33 #include "pcm.h"
34 #include "vsi.h"
35 #include "custom.h"
36 #include "gsm.h"
37 #include "message.h"
38 #include "ccdapi.h"
39 #include "prim.h"
40 #include "cus_sms.h"
41 #include "cnf_sms.h"
42 #include "mon_sms.h"
43 #include "pei.h"
44 #include "tok.h"
45 #include "sms.h"
46 #include "sms_em.h"
47
48 /*==== EXPORT ======================================================*/
49
50 /*==== PRIVAT ======================================================*/
51
52 /*==== VARIABLES ===================================================*/
53
54 /*==== FUNCTIONS ===================================================*/
55
56 /*
57 +--------------------------------------------------------------------+
58 | PROJECT : GSM-PS (6147) MODULE : SMS_TIM |
59 | STATE : code ROUTINE : tim_exec_timeout |
60 +--------------------------------------------------------------------+
61
62 PURPOSE : execute timeout
63
64 */
65
66 GLOBAL void tim_exec_timeout (USHORT index)
67 {
68 GET_INSTANCE_DATA;
69 USHORT timer;
70 int instance;
71
72 /* TRACE_FUNCTION ("tim_exec_timeout()"); */
73
74 timer = index / MAX_SMS_CALLS;
75 instance = index % MAX_SMS_CALLS;
76 sms_data->inst = (UBYTE)instance;
77
78 if (timer < MAX_SMS_TIMER)
79 {
80
81 /* Implements Measure#36 */
82 #ifdef NCONFIG
83 /* partab is not defined when NCONFIG is defined */
84 TRACE_EVENT_P1 ("Expired TIMER: timer %d", timer);
85 #else /* not NCONFIG */
86 #ifdef OPTION_TIMER
87 TRACE_EVENT_P1 ("Expired TIMER %s", partab[timer].keyword);
88 #endif
89 #endif /* NCONFIG */
90
91 sms_data->data[instance].t_running[timer] = FALSE;
92
93 switch (timer)
94 {
95 case TC1M:
96 tim_tc1m ();
97 break;
98 case TR1M:
99 tim_tr1m ();
100 break;
101 case TR2M:
102 tim_tr2m ();
103 break;
104 case TRAM:
105 tim_tram ();
106 break;
107 case TLCT:
108 tim_tlct ();
109 break;
110 case TMMS:
111 tim_tmms ();
112 break;
113 default: /* Not reached */
114 break;
115 }
116 }
117 }
118
119
120 /*
121 +--------------------------------------------------------------------+
122 | PROJECT : GSM-PS (6147) MODULE : SMS_TIM |
123 | STATE : code ROUTINE : tim_stop_timer |
124 +--------------------------------------------------------------------+
125
126 PURPOSE : stop timer
127
128 */
129
130 GLOBAL void tim_stop_timer (USHORT index)
131 {
132 GET_INSTANCE_DATA;
133 USHORT timer;
134 USHORT instance;
135
136 /* TRACE_FUNCTION ("tim_stop_timer()"); */
137
138 timer = index / MAX_SMS_CALLS;
139 instance = index % MAX_SMS_CALLS;
140
141 /* Implements Measure#36 */
142 #ifdef NCONFIG
143 /* partab is not defined when NCONFIG is defined */
144 TRACE_EVENT_P1 ("Stop TIMER: timer %d", timer);
145 #else /* not NCONFIG */
146 #ifdef OPTION_TIMER
147 TRACE_EVENT_P1 ("Stop TIMER %s", partab[timer].keyword);
148 #endif
149 #endif /* NCONFIG */
150
151 sms_data->data[instance].t_running[timer] = FALSE;
152 TIMER_STOP (sms_handle, index);
153 }
154
155 /*
156 +--------------------------------------------------------------------+
157 | PROJECT : GSM-PS (6147) MODULE : RR_TIM |
158 | STATE : code ROUTINE : tim_start_timer |
159 +--------------------------------------------------------------------+
160
161 PURPOSE : start timer
162
163 */
164
165 GLOBAL void tim_start_timer (USHORT index, T_TIME value)
166 {
167 GET_INSTANCE_DATA;
168 USHORT timer;
169 USHORT instance;
170
171 /* TRACE_FUNCTION ("tim_start_timer()"); */
172
173 timer = index / MAX_SMS_CALLS;
174 instance = index % MAX_SMS_CALLS;
175
176 /* Implements Measure#36 */
177 #ifdef NCONFIG
178 /* partab is not defined when NCONFIG is defined */
179 TRACE_EVENT_P1 ("Start TIMER: timer %d", timer);
180 #else /* not NCONFIG */
181 #ifdef OPTION_TIMER
182 TRACE_EVENT_P1 ("Start TIMER %s", partab[timer].keyword);
183 #endif
184 #endif /* NCONFIG */
185
186 sms_data->data[instance].t_running[timer] = TRUE;
187 TIMER_START (sms_handle, index, value);
188 }
189
190 /*
191 +--------------------------------------------------------------------+
192 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
193 | STATE : code ROUTINE : tim_tc1m |
194 +--------------------------------------------------------------------+
195
196 PURPOSE : Timeout of timer TC1M
197
198 */
199
200 GLOBAL void tim_tc1m (void)
201 {
202 GET_INSTANCE_DATA;
203
204 TRACE_FUNCTION ("tim_tc1m()");
205
206 SMS_EM_TIMEOUT_TC1M;
207
208 if (sms_data) /*lint !e774 always True*/
209 {
210 switch (SMS_INST_GET_STATE (STATE_CP))
211 {
212 case CP_WAIT_FOR_ACK:
213 #if defined (GPRS)
214 case CP_GSMS_MO_WAIT_FOR_CP_ACK:
215 case CP_GSMS_MT_WAIT_FOR_CP_ACK:
216 #endif
217 {
218 if (SMS_RETX(sms_data) >= MAX_RETRANS)
219 {
220 cp_send_release_req (SMS_INST.ti);
221
222 SMS_INST_SET_STATE (STATE_CP, CP_IDLE);
223
224 SMS_INST.r_flag = FALSE;
225
226 rl_error_ind (SMS_CAUSE_NET_TIMEOUT);
227
228 /*FREE_SMS_INSTANCE (SMS_INST.ti);*/
229 break;
230 }
231 else
232 {
233 #if defined (GPRS)
234 if (SMS_INST.downlink NEQ SMS_DOWNLINK_LL)
235 {
236 #endif
237 USHORT bsize_message = D_SDU_OFF (SMS_DATA_REQ(sms_data))+
238 D_SDU_LEN (SMS_DATA_REQ(sms_data));
239 PALLOC_SDU (data_req, MMSMS_DATA_REQ, bsize_message );
240
241 SMS_SDU_COPY (data_req, SMS_DATA_REQ(sms_data), MMSMS_DATA_REQ);
242 TRACE_BINDUMP(sms_handle,
243 TC_USER4,
244 "U_CP_DATA",
245 (&(data_req->sdu.buf[0]) + ((data_req->sdu.o_buf >> 3) -1)),
246 ((data_req->sdu.l_buf >> 3) + 1));
247 PSENDX (MM, data_req);
248
249 #if defined (GPRS)
250 }
251 else
252 {
253 if (SMS_LLC_FLOW(sms_data) EQ SMS_LLC_AVAILABLE)
254 {
255 /*
256 * retransmit on downlink LL
257 */
258 cp_send_data_gsms ();
259
260 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY;
261 }
262 else
263 {
264 SMS_LLC_FLOW(sms_data) = SMS_LLC_BUSY_WAITING;
265 }
266 }
267 #endif /* GPRS */
268 SMS_RETX(sms_data)++;
269 /*
270 * start timer TC1M
271 */
272 sms_timer_start(TC1M);
273 break;
274 }
275 }
276 }
277 }
278 }
279
280 /*
281 +--------------------------------------------------------------------+
282 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
283 | STATE : code ROUTINE : tim_tr1m |
284 +--------------------------------------------------------------------+
285
286 PURPOSE : Timeout of timer TR1M
287
288 */
289
290 GLOBAL void tim_tr1m (void)
291 {
292 GET_INSTANCE_DATA;
293
294 TRACE_FUNCTION ("tim_tr1m()");
295
296 SMS_EM_TIMEOUT_TR1M;
297
298 if (sms_data) /*lint !e774 always True*/
299 {
300 switch (SMS_INST_GET_STATE (STATE_RL))
301 {
302 case RL_ESTABLISH:
303
304 TRACE_FUNCTION ("tim_tr1m: RL_ESTABLISH");
305 sms_data->data[INST_MO].ti = sms_data->timer_ti;
306 /*
307 * RL state transition
308 */
309 SMS_INST_SET_STATE (STATE_RL, RL_IDLE);
310 /*
311 * CP_ABORT_REQ
312 */
313 cp_abort_req();
314 /*
315 * TL_TIMEOUT_IND
316 */
317 tl_timeout_ind (TR1M);
318 break;
319
320 case RL_WAIT_FOR_ACK:
321
322 TRACE_FUNCTION ("tim_tr1m: RL_WAIT_FOR_ACK");
323 /*
324 * RL state transition
325 */
326 SMS_INST_SET_STATE (STATE_RL, RL_IDLE);
327 /*
328 * CP_ABORT_REQ
329 */
330 cp_abort_req ();
331 /*
332 * TL_TIMEOUT_IND
333 */
334 tl_timeout_ind (TR1M);
335
336 break;
337
338 case RL_WAIT_FOR_SMMA_ACK:
339 TRACE_FUNCTION ("tim_tr1m: RL_WAIT_FOR_SMMA_ACK");
340
341 if (SMS_INST.retrans)
342 {
343 SMS_INST.retrans = FALSE;
344 /*
345 * RL state transition RL_IDLE
346 */
347 SMS_INST_SET_STATE (STATE_RL, RL_IDLE);
348 /*
349 * TL_REPORT_IND =>
350 */
351 tl_report_ind (NULL, SMS_CAUSE_NET_TIMEOUT);
352 /*
353 * SIM_UPDATE_REQ =>
354 */
355 tl_sms_memo_exceeded (TRUE);
356
357 }
358 else
359 {
360 SMS_INST.retrans = TRUE;
361 /*
362 * RL state transition RL_WAIT_FOR_RETRANS_TIMER
363 */
364 SMS_INST_SET_STATE (STATE_RL, RL_WAIT_FOR_RETRANS_TIMER);
365 /*
366 * start timer TRAM
367 */
368 sms_timer_start(TRAM);
369 /*
370 * CP_RELEASE_REQ =>
371 */
372 TRACE_EVENT("CP_RELEASE_REQ_19");
373 cp_release_req (SMS_INST.ti);
374 }
375
376 break;
377 }
378 }
379 }
380
381 /*
382 +--------------------------------------------------------------------+
383 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
384 | STATE : code ROUTINE : tim_tr2m |
385 +--------------------------------------------------------------------+
386
387 PURPOSE : Timeout of timer TR2M
388
389 */
390
391 GLOBAL void tim_tr2m (void)
392 {
393 GET_INSTANCE_DATA;
394
395 TRACE_FUNCTION ("tim_tr2m");
396
397 SMS_EM_TIMEOUT_TR2M;
398
399 if (sms_data) /*lint !e774 always True*/
400 {
401 switch (SMS_INST_GET_STATE (STATE_RL))
402 {
403 case RL_WAIT_FOR_SEND_ACK:
404 /*
405 * RP_ERROR =>
406 */
407 rl_report_req_error (SMS_RP_CS_PROTOCOL_ERROR, NULL);
408 /*
409 * TL_REPORT_IND =>
410 */
411 tl_report_ind (NULL, SMS_CAUSE_NET_TIMEOUT);
412 /*
413 * RL state transition RL_IDLE
414 */
415 SMS_INST_SET_STATE (STATE_RL, RL_IDLE);
416 break;
417
418 default:
419 break;
420 }
421 }
422 }
423
424 /*
425 +--------------------------------------------------------------------+
426 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
427 | STATE : code ROUTINE : tim_tram |
428 +--------------------------------------------------------------------+
429
430 PURPOSE : Timeout of timer TRAM
431
432 */
433
434 GLOBAL void tim_tram (void)
435 {
436 GET_INSTANCE_DATA;
437
438 TRACE_FUNCTION ("tim_tram");
439
440 if (sms_data) /*lint !e774 always True*/
441 {
442 switch (SMS_INST_GET_STATE (STATE_RL))
443 {
444 case RL_WAIT_FOR_RETRANS_TIMER:
445 /*
446 * RL state transition RL_IDLE
447 */
448 SMS_INST_SET_STATE (STATE_RL, RL_IDLE);
449 /*
450 * TL_TIMEOUT_IND
451 */
452 tl_timeout_ind (TRAM);
453 break;
454 default:
455 TRACE_ERROR("TRAM expired in wrong state!");
456 }
457 }
458 }
459
460 /*
461 +--------------------------------------------------------------------+
462 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
463 | STATE : code ROUTINE : tim_tlct |
464 +--------------------------------------------------------------------+
465
466 PURPOSE : Timeout of timer TLCT - concatenation supervision timer
467
468 */
469
470 GLOBAL void tim_tlct (void)
471 {
472 GET_INSTANCE_DATA;
473
474 TRACE_FUNCTION ("tim_tlct()");
475
476 switch (SMS_INST_GET_STATE (STATE_TL))
477 {
478 default:
479
480 TRACE_ERROR("Timer TLCT in wrong state");
481
482 case TL_SEND_CONTD:
483 /*
484 * reset concatenation
485 */
486 sms_data->concat_cntrl.concatenation = FALSE;
487 sms_data->concat_cntrl.release_pending = FALSE;
488 /*
489 * clean up instance
490 */
491 if (SMS_SDU(sms_data) NEQ NULL)
492 {
493 MFREE (SMS_SDU(sms_data));
494 SMS_SDU(sms_data) = NULL;
495 }
496 SMS_SEL_REC(sms_data) = SMS_RECORD_NOT_EXIST;
497 /*
498 * TL State Transition TL_IDLE
499 */
500 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
501 /*
502 * RL_RELEASE_REQ ==>
503 */
504 rl_release_req(SMS_INST.ti);
505 break;
506
507 }
508
509 }
510
511 /*
512 +--------------------------------------------------------------------+
513 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
514 | STATE : code ROUTINE : tim_tmms |
515 +--------------------------------------------------------------------+
516
517 PURPOSE : Timeout of timer TMMS - More Message Send timer
518
519 */
520 GLOBAL void tim_tmms(void)
521 {
522
523 GET_INSTANCE_DATA;
524
525 TRACE_FUNCTION ("tim_tmms()");
526
527 switch (SMS_INST_GET_STATE (STATE_TL))
528 {
529 default:
530
531 TRACE_ERROR("Timer TMMS in wrong state");
532
533 case TL_SEND_CONTD:
534
535 if(CMMS_ACTIVE)
536 {
537 sms_data->cmms_release_pending = FALSE;
538 }
539 /*
540 * Send the Primitive MNSMS_REPORT_IND to ACI
541 */
542 tl_mnsms_cmms_end_ind();
543 /*
544 * TL State Transition TL_IDLE
545 */
546 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
547 /*
548 * RL_RELEASE_REQ ==>
549 */
550 rl_release_req(SMS_INST.ti);
551 break;
552 }
553 }
554
555
556 /*
557 +--------------------------------------------------------------------+
558 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
559 | STATE : code ROUTINE : sms_timer_start |
560 +--------------------------------------------------------------------+
561
562 PURPOSE : start sms timer
563
564 */
565 GLOBAL void sms_timer_start (USHORT id)
566 {
567 GET_INSTANCE_DATA;
568 T_TIME value;
569
570 value = sms_data->timer_values[id];
571
572 tim_start_timer (((USHORT)(id*MAX_SMS_CALLS+sms_data->inst)), value);
573 }
574
575 /*
576 +--------------------------------------------------------------------+
577 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
578 | STATE : code ROUTINE : sms_timer_stop |
579 +--------------------------------------------------------------------+
580
581 PURPOSE : stop sms timer
582
583 */
584 GLOBAL void sms_timer_stop (USHORT id)
585 {
586 GET_INSTANCE_DATA;
587 tim_stop_timer (((USHORT)(id*MAX_SMS_CALLS+sms_data->inst)));
588 }
589
590 /*
591 +--------------------------------------------------------------------+
592 | PROJECT : GSM-PS (8410) MODULE : SMS_TIM |
593 | STATE : code ROUTINE : sms_timer_check |
594 +--------------------------------------------------------------------+
595
596 PURPOSE : check sms timer whether currently running
597 returns TRUE if given timer running
598
599 */
600 GLOBAL BOOL sms_timer_check (USHORT id)
601 {
602 GET_INSTANCE_DATA;
603 TRACE_FUNCTION ("sms_timer_check()");
604
605 return (SMS_INST.t_running[id]);
606 }
607
608 #endif /* #ifndef SMS_TIM_C */