comparison src/g23m-gsm/sms/sms_tlp.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 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : SMS_TLP
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 functions for the transfer layer
18 | capability of the module Short Message Service.
19 +-----------------------------------------------------------------------------
20 */
21 #ifndef SMS_TLP_C
22 #define SMS_TLP_C
23
24 #define ENTITY_SMS
25
26 /*==== INCLUDES ===================================================*/
27
28 #include <string.h>
29 #include <stdlib.h>
30 #include <stddef.h>
31 #include "typedefs.h"
32 #include "pcm.h"
33 #include "vsi.h"
34 #include "custom.h"
35 #include "gsm.h"
36 #include "message.h"
37 #include "ccdapi.h"
38 #include "prim.h"
39 #include "cus_sms.h"
40 #include "cnf_sms.h"
41 #include "mon_sms.h"
42 #include "pei.h"
43 #include "tok.h"
44 #include "sms.h"
45 #include "gdi.h"
46 #include "sms_em.h"
47
48 /*==== EXPORT =====================================================*/
49
50 /*==== PRIVAT =====================================================*/
51
52 /*==== VARIABLES ==================================================*/
53
54 /*==== TEST =======================================================*/
55
56 /*==== FUNCTIONS ==================================================*/
57
58 /* Implements Measure# 7 */
59 /*
60 +----------------------------------------------------------------------------------+
61 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
62 | STATE : code ROUTINE : tl_sim_rd_record_update_state |
63 +----------------------------------------------------------------------------------+
64
65 PURPOSE : This routine process primitive SIM_READ_RECORD_CONF for the
66 cases MMI_FIND_FIRST and MMI_FIND_NEXT
67
68 */
69
70 LOCAL BOOL tl_sim_rd_record_update_state(T_SIM_READ_RECORD_CNF *read_cnf)
71 {
72 GET_INSTANCE_DATA;
73 TRACE_FUNCTION("tl_sim_rd_record_update_state()");
74
75 if ((GET_STATE(STATE_MMI) EQ MMI_FIND_FIRST
76 AND sms_data->sim_mem_update)
77 OR (GET_STATE(STATE_MMI) EQ MMI_STATE_UPDATE
78 AND sms_data->sim_mem_update))
79 {
80 /*
81 * Either the SMS record has been changed or both the SMS record
82 * and the SMS status have been changed
83 */
84 PFREE (read_cnf);
85 sms_data->stored_mmi_state = MMI_IDLE;
86 return TRUE; /* return; */
87 }
88 else if (GET_STATE(STATE_MMI) EQ MMI_STATE_UPDATE)
89 {
90 /*
91 * Only SMS record's status has been changed.
92 */
93 sms_data->stored_read_cnf = read_cnf;
94 return TRUE; /* return; */
95 }
96 sms_data->stored_mmi_state = MMI_IDLE;
97
98 return FALSE;
99 }
100
101
102
103 /*
104 +--------------------------------------------------------------------+
105 | PROJECT : GSM-PS (8410) MODULE : SMS_CP |
106 | STATE : code ROUTINE : tl_init |
107 +--------------------------------------------------------------------+
108
109 PURPOSE : Initialize the transfer layer.
110
111 */
112
113 GLOBAL void tl_init ()
114 {
115 GET_INSTANCE_DATA;
116
117 TRACE_FUNCTION ("tl_init()");
118
119 SMS_ENT_STATE(sms_data) = SMS_STATE_NOT_AVAILABLE;
120
121 memset (sms_data->data, 0, sizeof (sms_data->data));
122
123 /* This is only for simulation tests*/
124 sms_data->data[INST_MO].ti = 6;
125
126 SMS_SIM_MEM_AVAIL(sms_data) = TRUE;
127 SMS_MEM_CFG(sms_data) = MEM_SM;
128 SMS_MT_HANDLING(sms_data) = MT_DEF;
129 SMS_ST_REPORT(sms_data) = DS0;
130 SMS_SIM_PHASE(sms_data) = PHASE_2_SIM;
131 SMS_MT_ACK_MODE(sms_data) = SMS_MHC_DEF;
132 SMS_NETWORK(sms_data) = NW_SIM_NONE;
133
134 sms_data->init_done = FALSE;
135
136 SMS_SIM_PROP(sms_data).status_field = sms_data->sim_status_field;
137 SMS_SIM_PROP(sms_data).pid_field = sms_data->sim_pid_field;
138 SMS_SIM_PROP(sms_data).mem_type = MEM_SM;
139 SMS_SIM_PROP(sms_data).max_record = 0;
140 SMS_SIM_PROP(sms_data).any_valid = FALSE;
141 /* SMS_ME_PROP(sms_data).status_and_pid = sms_data->me_status_field; */
142 /* SMS_ME_PROP(sms_data).status_and_pid = sms_data->me_pid_field; */
143 SMS_ME_PROP(sms_data).status_field = NULL;
144 SMS_ME_PROP(sms_data).pid_field = NULL;
145 SMS_ME_PROP(sms_data).mem_type = MEM_ME;
146 SMS_ME_PROP(sms_data).max_record = 0;
147 SMS_ME_PROP(sms_data).any_valid = FALSE;
148 sms_data->sim_mem_update = FALSE;
149 #ifdef SIM_TOOLKIT
150 sms_data->download_sms = FALSE;
151 sms_data->file_update_ind = NULL;
152 sms_data->stored_mmi_state = MMI_IDLE;
153 sms_data->stored_read_cnf = NULL;
154 #endif
155 SMS_RP_RCVD(sms_data) = NULL;
156 #ifdef FF_CPHS
157 SMS_CPHS(sms_data) = FALSE;
158 #endif
159 #ifdef GPRS
160 SMS_ROUTE_PREF(sms_data) = GPRS_SMS_CCT_ONLY;
161 #endif
162 sms_data->pr_cntrl.delivery_state = SMS_DELIVER_STATUS_RESUME;
163 sms_data->concat_cntrl.concatenation = FALSE;
164 }
165
166 /*
167 +--------------------------------------------------------------------+
168 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
169 | STATE : code ROUTINE : tl_sim_abort_to_mmi |
170 +--------------------------------------------------------------------+
171
172 PURPOSE : Abort a SIM related SMS command to MMI.
173
174 */
175
176 LOCAL void tl_sim_abort_to_mmi (USHORT error)
177 {
178 GET_INSTANCE_DATA;
179 switch (GET_STATE (STATE_MMI))
180 {
181 case MMI_REPLACE:
182 #ifdef REL99
183 if(SMS_INST.failed_msg_retx EQ FALSE)
184 {
185 #endif
186
187 tl_mnsms_submit_cnf (SMS_INST.act_mem, SMS_INST.act_record,
188 SMS_INST.tp_mr_ret, error, NULL);
189 #ifdef REL99
190 }
191 else
192 {
193 tl_mnsms_retrans_cnf (SMS_INST.act_mem, SMS_INST.act_record,
194 SMS_INST.tp_mr_ret, error, NULL);
195 }
196 #endif
197 break;
198 case MMI_READ:
199 tl_mnsms_read_cnf (SMS_INST.act_mem,
200 SMS_INST.act_record, NULL, error);
201 break;
202 case MMI_WRITE:
203 tl_mnsms_store_cnf (SMS_INST.act_mem, SMS_INST.act_record, error);
204 break;
205 case MMI_DELETE:
206 tl_mnsms_delete_cnf (SMS_INST.act_mem, SMS_INST.act_record, 0, error);
207 break;
208 default:
209 break;
210 }
211 if (sms_data->access_fifo[1] EQ ACCESS_BY_MMI)
212 {
213 sms_data->access_fifo[1] = ACCESS_EMPTY;
214 }
215 else if (sms_data->access_fifo[0] EQ ACCESS_BY_MMI)
216 {
217 sms_data->access_fifo[0] = ACCESS_EMPTY;
218 }
219 SET_STATE (STATE_MMI, MMI_IDLE);
220 #ifdef SIM_TOOLKIT
221 if (sms_data->file_update_ind NEQ NULL)
222 {
223 T_SIM_FILE_UPDATE_IND *file_update_ind = sms_data->file_update_ind;
224 sms_data->file_update_ind = NULL;
225 tl_sim_file_update_ind (file_update_ind);
226 }
227 if (sms_data->stored_read_cnf NEQ NULL)
228 {
229 /*
230 * Resets the stored MMI state & read_cnf primitive
231 */
232 sms_data->stored_mmi_state = MMI_IDLE;
233 PFREE (sms_data->stored_read_cnf);
234 sms_data->stored_read_cnf = NULL;
235 }
236 #endif
237 }
238
239 /*---- PRIMITIVES --------------------------------------------------*/
240
241 /*
242 +--------------------------------------------------------------------+
243 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
244 | STATE : code ROUTINE : tl_mnsms_configure_req |
245 +--------------------------------------------------------------------+
246
247 PURPOSE : Process the primitive MNSMS_CONFIGURE_REQ.
248
249 */
250
251 GLOBAL void tl_mnsms_configure_req (T_MNSMS_CONFIGURE_REQ *configure_req)
252 {
253 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE (0);
254
255 TRACE_FUNCTION ("tl_mnsms_configure_req()");
256
257 if (sms_data)
258 {
259 sms_data->mem3 = configure_req->pref_mem_3;
260 sms_data->mt = (configure_req->mt < MT_DEF)? configure_req->mt:
261 MT_DEF;
262 sms_data->ds = configure_req->ds;
263 sms_data->mhc = configure_req->mhc;
264
265 /*
266 * If CMMS mode is enabled, store the current value of cmms_mode in sms_data
267 */
268 if(configure_req->v_cmms_mode)
269 {
270 sms_data->cmms_mode = configure_req->cmms_mode;
271 }
272
273 /*
274 * For CMMS if user has set the value for TMMS timer then store that
275 * value in sms_data
276 */
277 if(configure_req->v_tmms_val)
278 {
279 sms_data->timer_values[TMMS] = configure_req->tmms_val;
280 }
281 }
282 PFREE (configure_req);
283 }
284
285 /*
286 +--------------------------------------------------------------------+
287 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
288 | STATE : code ROUTINE : tl_mnsms_mo_serv_req |
289 +--------------------------------------------------------------------+
290
291 PURPOSE : Process the primitive MNSMS_MO_SERV_REQ.
292 (set preferred destination (GPRS/GSM) for MO SM)
293
294 */
295 #if defined GPRS
296 GLOBAL void tl_mnsms_mo_serv_req (T_MNSMS_MO_SERV_REQ *mo_serv_req)
297 {
298 GET_INSTANCE_DATA;
299
300 TRACE_FUNCTION ("tl_mnsms_mo_serv_req()");
301 /*
302 * send MNSMS_MO_SERV_CNF with configured pref. dst
303 */
304 {
305 PALLOC (mo_serv_cnf, MNSMS_MO_SERV_CNF);
306 memset (mo_serv_cnf, 0, sizeof (T_MNSMS_MO_SERV_CNF));
307
308 if (sms_data) /*lint !e774 always True*/
309 {
310 sms_data->mo_dst_pref = mo_serv_req->mo_sms_serv;
311 mo_serv_cnf->mo_sms_serv = sms_data->mo_dst_pref;
312
313 TRACE_EVENT_P1("MO Path: %d", sms_data->mo_dst_pref);
314 }
315 else
316 {
317 mo_serv_cnf->mo_sms_serv = NOT_PRESENT_8BIT;
318 }
319 PSENDX (MMI, mo_serv_cnf);
320 }
321 PFREE (mo_serv_req);
322 }
323 #endif /* GPRS */
324
325 /*
326 +--------------------------------------------------------------------+
327 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
328 | STATE : code ROUTINE : tl_mnsms_command_cnf |
329 +--------------------------------------------------------------------+
330
331 PURPOSE : Generate a response to the primitive MNSMS_COMMAND_REQ.
332 */
333
334 GLOBAL void tl_mnsms_command_cnf (UBYTE tp_mr,
335 USHORT cause,
336 T_sms_sdu *sms_sdu)
337 {
338 PALLOC (command_cnf, MNSMS_COMMAND_CNF);
339
340 command_cnf->tp_mr = tp_mr;
341 command_cnf->cause = cause;
342
343 if (sms_sdu NEQ NULL)
344 memcpy (&command_cnf->sms_sdu, sms_sdu, sizeof (T_sms_sdu));
345 else
346 memset (&command_cnf->sms_sdu, 0, sizeof (T_sms_sdu));
347
348 PSENDX (MMI, command_cnf);
349 }
350
351 /*
352 +--------------------------------------------------------------------+
353 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
354 | STATE : code ROUTINE : tl_mnsms_command_req |
355 +--------------------------------------------------------------------+
356
357 PURPOSE : Process the primitive MNSMS_COMMAND_REQ.
358
359 */
360
361 GLOBAL void tl_mnsms_command_req (T_MNSMS_COMMAND_REQ *command_req)
362 {
363 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE (0);
364
365 TRACE_FUNCTION ("tl_mnsms_command_req()");
366
367 if (sms_data)
368 {
369 switch (SMS_INST_GET_STATE (STATE_TL))
370 {
371 case TL_IDLE:
372 if (sms_timer_check(TRAM))
373 {
374 tl_mnsms_command_cnf (NOT_PRESENT_8BIT, SMS_CAUSE_ENTITY_BUSY, NULL);
375 }
376 else
377 {
378 #ifdef REL99
379 SMS_INST.failed_msg_retx = FALSE;
380 if(command_req->auto_rep_flag EQ AUTO_REP_FLAG_ENABLED)
381 {
382 SMS_INST.tl_retx = 0;
383 }
384 else
385 {
386 /* Set to the max value so that retransmission will not be done */
387 SMS_INST.tl_retx = TL_MAX_RETANS;
388 }
389 #endif
390 /*
391 * save sdu
392 */
393 if (SMS_SDU(sms_data) NEQ NULL)
394 {
395 MFREE (SMS_SDU(sms_data));
396 }
397 MALLOC (SMS_SDU(sms_data), sizeof(T_sms_sdu));
398 memcpy (SMS_SDU(sms_data), &command_req->sms_sdu, sizeof(T_sms_sdu));
399 /*
400 * TL state transition TL_ESTABLISH
401 * EST state transition EST_CMD
402 */
403 SMS_INST_SET_STATE (STATE_TL, TL_ESTABLISH);
404 SET_STATE (STATE_EST, EST_CMD);
405 /*
406 * establish connection
407 */
408 tl_establish_connection(TRUE);
409 }
410 break;
411
412 default:
413 tl_mnsms_command_cnf (NOT_PRESENT_8BIT, SMS_CAUSE_ENTITY_BUSY, NULL);
414 }
415 }
416 else
417 {
418 tl_mnsms_command_cnf (NOT_PRESENT_8BIT, SMS_CAUSE_ENTITY_BUSY, NULL);
419 }
420 PFREE (command_req);
421 }
422
423 /*
424 +--------------------------------------------------------------------+
425 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
426 | STATE : code ROUTINE : tl_mnsms_delete_cnf |
427 +--------------------------------------------------------------------+
428
429 PURPOSE : Generate a response to the primitive MNSMS_DELETE_REQ.
430 */
431
432 GLOBAL void tl_mnsms_delete_cnf (UBYTE mem_type,
433 UBYTE record,
434 UBYTE next_rec,
435 USHORT error)
436 {
437 PALLOC (delete_cnf, MNSMS_DELETE_CNF);
438
439 delete_cnf->mem_type = mem_type;
440 delete_cnf->rec_num = record;
441 delete_cnf->cause = error;
442 delete_cnf->delete_rec_next = next_rec;
443
444 SMS_EM_DELETE_SHORT_MESSAGE;
445
446 PSENDX (MMI, delete_cnf);
447 }
448
449 /*
450 +--------------------------------------------------------------------+
451 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
452 | STATE : code ROUTINE : tl_mnsms_delete_req |
453 +--------------------------------------------------------------------+
454
455 PURPOSE : Process the primitive MNSMS_DELETE_REQ.
456
457 */
458
459 GLOBAL void tl_mnsms_delete_req (T_MNSMS_DELETE_REQ *delete_req)
460 {
461 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE(0);
462 UBYTE rec_num;
463
464 TRACE_FUNCTION ("tl_mnsms_delete_req()");
465
466 #ifdef REL99
467 /* Check if the last failed message is getting deleted */
468 if( ( delete_req->rec_num EQ SMS_INST.failed_msg_rec_num) AND
469 ( delete_req->mem_type EQ SMS_INST.failed_msg_mem ) AND
470 SMS_DATA_REQ(sms_data) NEQ NULL )
471 {
472 PFREE (SMS_DATA_REQ(sms_data));
473 SMS_DATA_REQ(sms_data) = NULL;
474 }
475 #endif
476
477 if (sms_data NEQ NULL)
478 {
479 switch (SMS_INST_GET_STATE (STATE_TL))
480 {
481 case TL_IDLE:
482 switch (delete_req->mem_type)
483 {
484 case MEM_ME:
485 /*
486 * Mobile Equipment Memory
487 */
488 if(delete_req->delete_status NEQ CMGD_DEL_INDEX)
489 {
490 if(delete_req->rec_num EQ 0)
491 {
492 /* Status value is given. Find the first record satisfying this status value */
493 rec_num = tl_search_record_for_delete (&SMS_ME_PROP(sms_data), 1,
494 delete_req->delete_status);
495 if(rec_num EQ SMS_RECORD_NOT_EXIST)
496 {
497 tl_mnsms_delete_cnf (delete_req->mem_type, 0, 0, SIM_NO_ERROR);
498 break;
499 }
500 }
501 else
502 {
503 if(delete_req->rec_num > sms_data->me_backup.max_record)
504 {
505 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
506 (USHORT)((SMS_ME_PROP(sms_data).max_record EQ 0)?
507 SMS_CAUSE_MEM_FAIL: SMS_CAUSE_INV_INDEX));
508 break;
509 }
510 else
511 {
512 /* Use the record number that ACI has given */
513 rec_num = delete_req->rec_num;
514 }
515 }
516 }
517 else
518 {
519 /* There should be a valid rec_num */
520 if(delete_req->rec_num EQ 0 || delete_req->rec_num > sms_data->me_backup.max_record)
521 {
522 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
523 (USHORT)((SMS_ME_PROP(sms_data).max_record EQ 0)?
524 SMS_CAUSE_MEM_FAIL: SMS_CAUSE_INV_INDEX));
525 break;
526 }
527 else
528 {
529 rec_num = delete_req->rec_num;
530 }
531 }
532
533 if (tl_get_status (&SMS_ME_PROP(sms_data), rec_num-1) & 1)
534 {
535 /*
536 * entry is used
537 */
538 UBYTE data[SIZE_EF_SMS];
539 UBYTE next_rec_num = 0;
540
541 data[0] = 0;
542 memset (&data[1], 0xFF, SIZE_EF_SMS-1);
543 tl_store_status (&SMS_ME_PROP(sms_data), rec_num-1, SIM_SMS_FREE);
544 /* Implements Measure#32: Row 95 */
545 pcm_WriteRecord ((UBYTE *)ef_sms_id, rec_num,
546 SIZE_EF_SMS, data);
547
548 TRACE_EVENT_P1 ("mem cap avail %d", sms_data->mem_cap_avail);
549
550 if (!sms_data->mem_cap_avail)
551 {
552 SMS_SEL_MEM(sms_data) = delete_req->mem_type;
553 SMS_SEL_REC(sms_data) = delete_req->rec_num;
554
555 GET_MO_INSTANCE(sms_data);
556 /*
557 * TL state transition TL_ESTABLISH
558 * EST state transition EST_SMMA
559 * MMI state transition MMI_DELETE
560 *
561 */
562 SET_STATE (STATE_MMI, MMI_DELETE);
563 SET_STATE (STATE_EST, EST_SMMA);
564 SMS_INST_SET_STATE (STATE_TL, TL_ESTABLISH);
565 /*
566 * 1st shot
567 */
568 SMS_INST.retrans = FALSE;
569 /*
570 * establish connection
571 */
572 tl_establish_connection(FALSE);
573 /*
574 * wait for processing of RP-SMMA
575 */
576 PFREE (delete_req);
577 return;
578 }
579
580 if(delete_req->delete_status NEQ CMGD_DEL_INDEX)
581 {
582 /* Status value is given. Find the next record satisfying this status value */
583 next_rec_num = tl_search_record_for_delete (&SMS_ME_PROP(sms_data), rec_num,
584 delete_req->delete_status);
585 }
586
587 tl_mnsms_delete_cnf (delete_req->mem_type, rec_num, next_rec_num, SIM_NO_ERROR);
588 }
589 else
590 {
591 tl_mnsms_delete_cnf (delete_req->mem_type, rec_num, 0, SMS_CAUSE_INV_INDEX);
592 }
593
594 break;
595
596 case MEM_SM:
597 /*
598 * SIM memory
599 */
600 if(delete_req->delete_status NEQ CMGD_DEL_INDEX)
601 {
602 if(delete_req->rec_num EQ 0)
603 {
604 /* Status value is given. Find the first record satisfying this status value */
605 rec_num = tl_search_record_for_delete (&SMS_SIM_PROP(sms_data), 1,
606 delete_req->delete_status);
607
608 if(rec_num EQ SMS_RECORD_NOT_EXIST)
609 {
610 tl_mnsms_delete_cnf (delete_req->mem_type, 0, 0, SIM_NO_ERROR);
611 break;
612 }
613
614 }
615 else
616 {
617 if(delete_req->rec_num > sms_data->sim_backup.max_record)
618 {
619 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
620 SMS_CAUSE_INV_INDEX);
621 break;
622 }
623 else
624 {
625 /* Use the record number that he has given */
626 rec_num = delete_req->rec_num;
627 }
628 }
629 }
630 else
631 {
632 /* There should be a valid rec_num */
633 if(delete_req->rec_num EQ 0 || delete_req->rec_num > sms_data->sim_backup.max_record)
634 {
635 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
636 SMS_CAUSE_INV_INDEX);
637 break;
638 }
639 else
640 {
641 rec_num = delete_req->rec_num;
642 }
643 }
644
645 if (tl_get_status (&SMS_SIM_PROP(sms_data), rec_num-1) & 1)
646 {
647 /*
648 * entry is used
649 */
650 SMS_SEL_MEM(sms_data) = delete_req->mem_type;
651 SMS_SEL_REC(sms_data) = rec_num;
652 SMS_REC_STATUS(sms_data) = delete_req->delete_status;
653
654 tl_set_access_fifo (ACCESS_BY_MMI);
655 SET_STATE (STATE_MMI, MMI_DELETE);
656 SMS_INST_SET_STATE (STATE_TL, TL_OTHER);
657 tl_sim_update_req (rec_num, SMS_RECORD_FREE, NULL);
658 }
659 else
660 {
661 tl_mnsms_delete_cnf (delete_req->mem_type, rec_num, 0, SMS_CAUSE_INV_INDEX);
662 }
663
664 break;
665
666 case MEM_SR:
667 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
668 SMS_CAUSE_MEM_FAIL);
669 break;
670
671 default:
672 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
673 SMS_CAUSE_PARAM_WRONG);
674 break;
675 }
676 break;
677
678 default:
679 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
680 SMS_CAUSE_ENTITY_BUSY);
681 break;
682 }
683 }
684 else
685 tl_mnsms_delete_cnf (delete_req->mem_type, delete_req->rec_num, 0,
686 SMS_CAUSE_ENTITY_BUSY);
687 PFREE (delete_req);
688 }
689
690 /*
691 +--------------------------------------------------------------------+
692 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
693 | STATE : code ROUTINE : tl_mnsms_read_cnf |
694 +--------------------------------------------------------------------+
695
696 PURPOSE : Generate an error response to the primitive
697 MNSMS_READ_REQ.
698 */
699
700 GLOBAL void tl_mnsms_read_cnf (UBYTE mem_type,
701 UBYTE record,
702 UBYTE *data,
703 USHORT error)
704 {
705 GET_INSTANCE_DATA;
706 PALLOC (read_cnf, MNSMS_READ_CNF); /* T_MNSMS_READ_CNF */
707
708 read_cnf->mem_type = mem_type;
709 read_cnf->rec_num = record;
710 switch (mem_type)
711 {
712 case MEM_SM:
713 if (sms_data->init_done)
714 {
715 read_cnf->rec_next = tl_search_record (&SMS_SIM_PROP(sms_data),
716 (USHORT)(record + 1),
717 SMS_REC_STATUS(sms_data));
718 read_cnf->rec_max = SMS_SIM_PROP(sms_data).max_record;
719 }
720 else
721 {
722 read_cnf->rec_next = SMS_RECORD_NOT_EXIST;
723 read_cnf->rec_max = SMS_RECORD_NOT_EXIST;
724 }
725 break;
726 case MEM_ME:
727 read_cnf->rec_next = tl_search_record (&SMS_ME_PROP(sms_data),
728 (USHORT)(record + 1),
729 SMS_REC_STATUS(sms_data));
730 read_cnf->rec_max = SMS_ME_PROP(sms_data).max_record;
731 break;
732 default:
733 read_cnf->rec_next = SMS_RECORD_NOT_EXIST;
734 read_cnf->rec_max = SMS_RECORD_NOT_EXIST;
735 break;
736 }
737 read_cnf->cause = error;
738 read_cnf->rec_status = SMS_RECORD_NOT_EXIST; /* ffs */
739
740 if (data NEQ NULL)
741 {
742 read_cnf->status = data[0];
743 read_cnf->sms_sdu.l_buf = SIM_PDU_BIT_LEN;
744 read_cnf->sms_sdu.o_buf = 0;
745 memcpy (read_cnf->sms_sdu.buf, &data[1], SIM_PDU_LEN);
746 tl_adjust_message_len (SMS_VT_SIM_PDU, (BUF_tpdu *)&read_cnf->sms_sdu);
747 }
748 else
749 {
750 if (record EQ SMS_RECORD_NOT_EXIST)
751 {
752 read_cnf->status = SMS_RECORD_FREE;
753 }
754 else
755 {
756 switch (mem_type)
757 {
758 case MEM_ME:
759 read_cnf->status = tl_get_status (&SMS_ME_PROP(sms_data), record-1);
760 break;
761 case MEM_SM:
762 read_cnf->status = tl_get_status (&SMS_SIM_PROP(sms_data), record-1);
763 break;
764 default:
765 read_cnf->status = SMS_RECORD_FREE;
766 break;
767 }
768 }
769 memset (&read_cnf->sms_sdu, 0, sizeof(T_sms_sdu));
770 }
771 PSENDX (MMI, read_cnf);
772 }
773
774 /*
775 +--------------------------------------------------------------------+
776 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
777 | STATE : code ROUTINE : tl_mnsms_read_req |
778 +--------------------------------------------------------------------+
779
780 PURPOSE : Process the primitive MNSMS_READ_REQ.
781
782 */
783
784 GLOBAL void tl_mnsms_read_req (T_MNSMS_READ_REQ *read_req)
785 {
786 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE(0);
787
788 TRACE_FUNCTION ("tl_mnsms_read_req()");
789
790 if (sms_data)
791 {
792 switch (SMS_INST_GET_STATE (STATE_TL))
793 {
794 case TL_IDLE:
795 SMS_READ_MODE(sms_data) = read_req->read_mode;
796 switch (read_req->mem_type)
797 {
798 case MEM_ME: /* Mobile Equipment Memory */
799 tl_read_me_memory (read_req->rec_num,
800 read_req->status);
801 break;
802 case MEM_SM: /* SIM memory */
803 if (sms_data->init_done)
804 {
805 tl_read_sim_memory (read_req->rec_num,
806 read_req->status);
807 }
808 else
809 {
810 tl_mnsms_read_cnf (read_req->mem_type,
811 read_req->rec_num, NULL, SMS_CAUSE_ENTITY_BUSY);
812 }
813 break;
814 case MEM_SR:
815 tl_mnsms_read_cnf (read_req->mem_type,
816 read_req->rec_num, NULL,
817 SMS_CAUSE_MEM_FAIL);
818 break;
819 default:
820 tl_mnsms_read_cnf (read_req->mem_type,
821 read_req->rec_num, NULL,
822 SMS_CAUSE_PARAM_WRONG);
823 break;
824 }
825 break;
826
827 default:
828 tl_mnsms_read_cnf (read_req->mem_type,
829 read_req->rec_num, NULL, SMS_CAUSE_ENTITY_BUSY);
830 break;
831 }
832 }
833 else
834 tl_mnsms_read_cnf (read_req->mem_type,
835 read_req->rec_num, NULL, SMS_CAUSE_ENTITY_BUSY);
836
837 PFREE (read_req);
838 }
839
840 /*
841 +--------------------------------------------------------------------+
842 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
843 | STATE : code ROUTINE : tl_mnsms_store_cnf |
844 +--------------------------------------------------------------------+
845
846 PURPOSE : Generate a response to the primitive MNSMS_STORE_REQ.
847 */
848
849 GLOBAL void tl_mnsms_store_cnf (UBYTE mem_type,
850 UBYTE record,
851 USHORT error)
852 {
853 PALLOC (store_cnf, MNSMS_STORE_CNF);
854
855 store_cnf->mem_type = mem_type;
856 store_cnf->rec_num = record;
857 store_cnf->cause = error;
858
859 PSENDX (MMI, store_cnf);
860 }
861
862 /*
863 +--------------------------------------------------------------------+
864 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
865 | STATE : code ROUTINE : tl_mnsms_store_req |
866 +--------------------------------------------------------------------+
867
868 PURPOSE : Process the primitive MNSMS_STORE_REQ.
869
870 */
871
872 GLOBAL void tl_mnsms_store_req (T_MNSMS_STORE_REQ *store_req)
873 {
874 USHORT index;
875 UBYTE dummy;
876 int byte_len;
877 BOOL mem_full = FALSE;
878 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE(0);
879
880 TRACE_FUNCTION ("tl_mnsms_store_req()");
881
882 #ifdef REL99
883 /* Check if the last failed message is getting replaced */
884 if( ( store_req->condx NEQ SMS_CONDX_OVR_NON ) AND
885 ( store_req->rec_num EQ SMS_INST.failed_msg_rec_num ) AND
886 ( store_req->mem_type EQ SMS_INST.failed_msg_mem ) AND
887 SMS_DATA_REQ(sms_data) NEQ NULL )
888 {
889 PFREE (SMS_DATA_REQ(sms_data));
890 SMS_DATA_REQ(sms_data) = NULL;
891 }
892 #endif
893
894 if (sms_data NEQ NULL)
895 {
896 switch (SMS_INST_GET_STATE (STATE_TL))
897 {
898 case TL_IDLE:
899 if (tl_check_status_value (store_req->status) EQ NOT_PRESENT_8BIT)
900 { /* invalid status value */
901 tl_mnsms_store_cnf (store_req->mem_type, store_req->rec_num,
902 SMS_CAUSE_PARAM_WRONG);
903 break;
904 }
905 switch (store_req->mem_type)
906 {
907 case MEM_SM:
908 if (store_req->rec_num EQ SMS_RECORD_NOT_EXIST)
909 {
910 if ((index = tl_get_free_space (MEM_SM)) EQ 0)
911 mem_full = TRUE;
912
913 SMS_EM_SET_CHANGE_FLAG_1;
914
915 }
916 else
917 {
918 if (store_req->rec_num > SMS_SIM_PROP(sms_data).max_record)
919 index = 0;
920 else if (store_req->condx EQ SMS_CONDX_OVR_NON)
921 {
922 if ((tl_get_status (&SMS_SIM_PROP(sms_data), store_req->rec_num-1) & 1)
923 EQ SMS_RECORD_FREE)
924 index = store_req->rec_num;
925 else
926 index = 0;
927 }
928 else if (store_req->condx EQ SMS_CONDX_OVR_MO)
929 {
930 switch (tl_get_status (&SMS_SIM_PROP(sms_data), store_req->rec_num-1) & 7)
931 {
932 case SMS_RECORD_STO_UNSENT:
933 case SMS_RECORD_STO_SENT:
934 index = store_req->rec_num;
935 break;
936
937 default:
938 index = 0;
939 break;
940 }
941 }
942 else
943 index = store_req->rec_num;
944
945 SMS_EM_SET_CHANGE_FLAG_2;
946
947 }
948 break;
949
950 case MEM_ME:
951 if (store_req->rec_num EQ SMS_RECORD_NOT_EXIST)
952 {
953 if ((index = tl_get_free_space (MEM_ME)) EQ 0)
954 mem_full = TRUE;
955
956
957 SMS_EM_SET_CHANGE_FLAG_1;
958
959 }
960 else
961 {
962 if (store_req->condx EQ SMS_CONDX_OVR_NON)
963 {
964 if ((tl_get_status (&SMS_ME_PROP(sms_data), store_req->rec_num-1) & 1)
965 EQ SMS_RECORD_FREE)
966 index = store_req->rec_num;
967 else
968 index = 0;
969 }
970 else if (store_req->condx EQ SMS_CONDX_OVR_MO)
971 {
972 switch (tl_get_status (&SMS_ME_PROP(sms_data), store_req->rec_num-1) & 7)
973 {
974 case SMS_RECORD_STO_UNSENT:
975 case SMS_RECORD_STO_SENT:
976 index = store_req->rec_num;
977 break;
978
979 default:
980 index = 0;
981 break;
982 }
983 }
984 else
985 index = store_req->rec_num;
986
987 SMS_EM_SET_CHANGE_FLAG_2;
988
989 }
990 break;
991
992 case MEM_SR:
993 tl_mnsms_store_cnf (store_req->mem_type, store_req->rec_num,
994 SMS_CAUSE_MEM_FAIL);
995 PFREE (store_req);
996 return;
997
998 default:
999 tl_mnsms_store_cnf (store_req->mem_type, store_req->rec_num,
1000 SMS_CAUSE_PARAM_WRONG);
1001 PFREE (store_req);
1002 return;
1003 }
1004 if (index > 0)
1005 {
1006 /*
1007 * storage available
1008 */
1009 byte_len = (int)store_req->sms_sdu.l_buf >> 3;
1010
1011 if (store_req->mem_type EQ MEM_SM)
1012 {
1013 /*
1014 * SIM card memory
1015 */
1016 tl_store_status (&SMS_SIM_PROP(sms_data), index-1, SIM_SMS_PENDING);
1017 SMS_REC_STATUS(sms_data) = store_req->status;
1018 tl_get_pid_dcs (store_req->status,
1019 &store_req->sms_sdu,
1020 &SMS_PID(sms_data),
1021 &dummy);
1022
1023 memset (&store_req->sms_sdu.buf[byte_len],
1024 NOT_PRESENT_8BIT,
1025 (SIM_LENGTH_SMS_RECORD-1) - byte_len);
1026
1027 tl_set_access_fifo (ACCESS_BY_MMI);
1028 SET_STATE (STATE_MMI, MMI_WRITE);
1029 SMS_INST_SET_STATE (STATE_TL, TL_OTHER);
1030 tl_sim_update_req ((UBYTE)index, store_req->status,
1031 store_req->sms_sdu.buf);
1032 break;
1033 }
1034 else
1035 {
1036 /*
1037 * memory type is mobile memory
1038 */
1039 UBYTE data[SIZE_EF_SMS];
1040
1041 data[0] = store_req->status;
1042 memcpy (&data[1], store_req->sms_sdu.buf, byte_len);
1043 memset (&data[byte_len + 1],
1044 NOT_PRESENT_8BIT,
1045 (SIM_LENGTH_SMS_RECORD-1) - byte_len);
1046
1047 /* Implements Measure#32: Row 97 */
1048 if (pcm_WriteRecord ((UBYTE *)ef_sms_id, index,
1049 SIZE_EF_SMS, data) EQ PCM_OK)
1050 {
1051 UBYTE pid;
1052
1053 SMS_EM_STORE_MO_SHORT_MESSAGE;
1054
1055 SMS_EM_CHANGE_SHORT_MESSAGE;
1056
1057 tl_store_status (&SMS_ME_PROP(sms_data), index-1, store_req->status);
1058 tl_get_pid_dcs (store_req->status,
1059 &store_req->sms_sdu,
1060 &pid,
1061 &dummy);
1062 tl_store_pid (&SMS_ME_PROP(sms_data), index-1, pid);
1063 tl_mnsms_store_cnf (store_req->mem_type, (UBYTE)index,
1064 SMS_NO_ERROR);
1065 }
1066 else
1067 tl_mnsms_store_cnf (store_req->mem_type, (UBYTE)index,
1068 SMS_CAUSE_MEM_FAIL);
1069 }
1070 }
1071 else
1072 tl_mnsms_store_cnf (store_req->mem_type, store_req->rec_num,
1073 (USHORT)((mem_full)? SMS_CAUSE_MEM_FULL:
1074 SMS_CAUSE_INV_INDEX));
1075 break;
1076
1077 default:
1078 tl_mnsms_store_cnf (store_req->mem_type, store_req->rec_num,
1079 SMS_CAUSE_ENTITY_BUSY);
1080 break;
1081 }
1082 }
1083 else
1084 tl_mnsms_store_cnf (store_req->mem_type, store_req->rec_num,
1085 SMS_CAUSE_ENTITY_BUSY);
1086
1087 PFREE (store_req);
1088 }
1089
1090 /*
1091 +--------------------------------------------------------------------+
1092 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1093 | STATE : code ROUTINE : tl_mnsms_submit_cnf |
1094 +--------------------------------------------------------------------+
1095
1096 PURPOSE : Generate a response to the primitive MNSMS_SUBMIT_REQ.
1097 */
1098
1099 GLOBAL void tl_mnsms_submit_cnf (UBYTE mem_type,
1100 UBYTE record,
1101 UBYTE tp_mr,
1102 USHORT cause,
1103 T_sms_sdu *sms_sdu)
1104 {
1105 PALLOC (submit_cnf, MNSMS_SUBMIT_CNF);
1106
1107 TRACE_EVENT_P1 ("cause = %04x", cause);
1108
1109 submit_cnf->mem_type = mem_type;
1110 submit_cnf->rec_num = record;
1111 submit_cnf->tp_mr = tp_mr;
1112 submit_cnf->cause = cause;
1113
1114 if (sms_sdu NEQ NULL)
1115 memcpy (&submit_cnf->sms_sdu, sms_sdu, sizeof (T_sms_sdu));
1116 else
1117 memset (&submit_cnf->sms_sdu, 0, sizeof (T_sms_sdu));
1118
1119 PSENDX (MMI, submit_cnf);
1120 }
1121
1122 /*
1123 +--------------------------------------------------------------------+
1124 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1125 | STATE : code ROUTINE : tl_mnsms_submit_req |
1126 +--------------------------------------------------------------------+
1127
1128 PURPOSE : Process the primitive MNSMS_SUBMIT_REQ.
1129 */
1130
1131
1132 GLOBAL void tl_mnsms_submit_req (T_MNSMS_SUBMIT_REQ *submit_req)
1133 {
1134 UBYTE ti;
1135 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE(0);
1136
1137 TRACE_FUNCTION ("tl_mnsms_submit_req()");
1138
1139 TRACE_EVENT_P2 ("mem_type = %02X, rec_num = %02X",
1140 submit_req->mem_type, submit_req->rec_num);
1141
1142 if (sms_data)
1143 {
1144 switch (SMS_INST_GET_STATE (STATE_TL))
1145 {
1146 case TL_SEND_CONTD:
1147 /*
1148 * stop timer TLCT
1149 */
1150 sms_timer_stop(TLCT);
1151 /*
1152 * stop timer TMMS
1153 */
1154 sms_timer_stop(TMMS);
1155
1156 case TL_IDLE:
1157 if (sms_timer_check(TRAM))
1158 {
1159 /*
1160 * MNSMS_SUBMIT_CNF
1161 */
1162 tl_mnsms_submit_cnf (submit_req->mem_type, submit_req->rec_num,
1163 NOT_PRESENT_8BIT, SMS_CAUSE_ENTITY_BUSY, NULL);
1164 break;
1165 }
1166 /*
1167 * save submit request with sms sdu
1168 */
1169 SMS_SEL_MEM(sms_data) = submit_req->mem_type;
1170 SMS_SEL_REC(sms_data) = submit_req->rec_num;
1171 SMS_CONDX(sms_data) = submit_req->condx;
1172 SMS_MODIFY(sms_data) = submit_req->modify;
1173
1174 if (SMS_SDU(sms_data) NEQ NULL)
1175 {
1176 MFREE (SMS_SDU(sms_data));
1177 }
1178 MALLOC (SMS_SDU(sms_data), sizeof(T_sms_sdu));
1179 memcpy (SMS_SDU(sms_data), &submit_req->sms_sdu, sizeof(T_sms_sdu));
1180 /*
1181 * check whether concatenated
1182 */
1183 if (!tl_concat_check(SMS_SDU(sms_data)))
1184 {
1185 /*
1186 * error understanding the sdu
1187 */
1188 TRACE_ERROR ("error with concat sim pdu");
1189 /*
1190 * negative response MNSMS_SUBMIT_CNF
1191 */
1192 tl_mnsms_submit_cnf (submit_req->mem_type, submit_req->rec_num,
1193 NOT_PRESENT_8BIT, SMS_CAUSE_PARAM_WRONG, NULL);
1194 /*
1195 * Send MNSMS_REPORT_IND if cmms_mode is equal 1or 2
1196 */
1197 if(CMMS_ACTIVE)
1198 {
1199 tl_mnsms_cmms_end_ind();
1200 }
1201 /*
1202 * give up
1203 */
1204 MFREE (SMS_SDU(sms_data));
1205 PFREE (submit_req);
1206 return;
1207 }
1208 #ifdef REL99
1209 /* Check whether MO msg is sent thru retransmission request. Initially False */
1210 SMS_INST.failed_msg_retx = FALSE;
1211 if(submit_req->auto_rep_flag EQ AUTO_REP_FLAG_ENABLED)
1212 {
1213 SMS_INST.tl_retx = 0;
1214 }
1215 else
1216 {
1217 /* Set to the max value so that retransmission will not be done */
1218 SMS_INST.tl_retx = TL_MAX_RETANS;
1219 }
1220 #endif
1221
1222
1223 /*
1224 * TL state transition TL_ESTABLISH
1225 * EST state transition EST_SEND
1226 */
1227 SMS_INST_SET_STATE (STATE_TL, TL_ESTABLISH);
1228 SET_STATE (STATE_EST, EST_SEND);
1229 /*
1230 * establish connection
1231 */
1232 ti = SMS_INST.ti;
1233 tl_establish_connection(TRUE);
1234 /*
1235 * concat control: if needed, release previous connection
1236 */
1237 if ((sms_data->concat_cntrl.concatenation EQ TRUE) AND
1238 (sms_data->concat_cntrl.release_pending EQ TRUE))
1239 {
1240 sms_data->concat_cntrl.release_pending = FALSE;
1241 /*
1242 * RL_RELEASE_REQ ==>
1243 */
1244 rl_release_req(ti);
1245 /*
1246 * check for end of concatenation
1247 */
1248 if (sms_data->concat_cntrl.end EQ TRUE)
1249 {
1250 /*
1251 * end of concatenation
1252 */
1253 sms_data->concat_cntrl.concatenation = FALSE;
1254 }
1255 break;
1256 }
1257 /*
1258 * cmms control: if needed, release previous connection
1259 */
1260 if(sms_data->cmms_release_pending EQ TRUE)
1261 {
1262 sms_data->cmms_release_pending = FALSE;
1263 /*
1264 * Release the previous active MM connection
1265 */
1266 rl_release_req(ti);
1267 }
1268 break;
1269
1270 default:
1271 /*
1272 * MNSMS_SUBMIT_CNF
1273 */
1274 tl_mnsms_submit_cnf (submit_req->mem_type, submit_req->rec_num,
1275 NOT_PRESENT_8BIT, SMS_CAUSE_ENTITY_BUSY, NULL);
1276 }
1277 }
1278 else
1279 {
1280 /*
1281 * MNSMS_SUBMIT_CNF
1282 */
1283 tl_mnsms_submit_cnf (submit_req->mem_type, submit_req->rec_num,
1284 NOT_PRESENT_8BIT, SMS_CAUSE_ENTITY_BUSY, NULL);
1285 }
1286 PFREE (submit_req);
1287 }
1288
1289
1290 /*
1291 +--------------------------------------------------------------------+
1292 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1293 | STATE : code ROUTINE : tl_mnsms_error_ind |
1294 +--------------------------------------------------------------------+
1295
1296 PURPOSE : Build and send the primitive MNSMS_ERROR_IND.
1297 */
1298
1299 GLOBAL void tl_mnsms_error_ind (USHORT error)
1300 {
1301 PALLOC (error_ind, MNSMS_ERROR_IND);
1302
1303 error_ind->cause = error;
1304
1305 PSENDX (MMI, error_ind);
1306 }
1307
1308 /*
1309 +--------------------------------------------------------------------+
1310 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1311 | STATE : code ROUTINE : tl_mnsms_ack_res |
1312 +--------------------------------------------------------------------+
1313
1314 PURPOSE : Process the primitive MNSMS_ACK_RES.
1315 */
1316
1317 GLOBAL void tl_mnsms_ack_res (T_MNSMS_ACK_RES *ack_res)
1318 {
1319 GET_INSTANCE_DATA;
1320
1321 TRACE_FUNCTION ("tl_mnsms_ack_res()");
1322
1323 if (sms_data) /*lint !e774 always True*/
1324 {
1325 GET_MT_INSTANCE(sms_data); /* MT operation */
1326
1327 if (SMS_MT_ACK_MODE(sms_data) NEQ SMS_MHC_PH2PLUS)
1328 {
1329 tl_mnsms_error_ind (SMS_CAUSE_OPER_NOT_ALLW);
1330 }
1331 else switch (SMS_INST_GET_STATE (STATE_TL))
1332 {
1333 case TL_RECEIVE:
1334 if (sms_timer_check(TR2M))
1335 {
1336 T_rp_user_data *rp_ud;
1337 int sdu_ofs;
1338 MALLOC (rp_ud, sizeof(T_rp_user_data));
1339
1340 CCD_START;
1341
1342 sdu_ofs = ack_res->sms_sdu.buf[ack_res->sms_sdu.o_buf >> 3] + 1;
1343 rp_ud->tpdu.o_tpdu = 0;
1344 if (ack_res->sms_sdu.l_buf >= (sdu_ofs << 3) + 2) /* TP-MTI present */
1345 {
1346 rp_ud->tpdu.l_tpdu = ack_res->sms_sdu.l_buf - (sdu_ofs << 3);
1347 memcpy (rp_ud->tpdu.b_tpdu, &ack_res->sms_sdu.buf[sdu_ofs],
1348 rp_ud->tpdu.l_tpdu >> 3);
1349 rp_ud->tp_mti = rp_ud->tpdu.b_tpdu[0] & 3;
1350 rp_ud->v_tpdu = TRUE;
1351 }
1352 else
1353 {
1354 rp_ud->tpdu.l_tpdu = 0;
1355 rp_ud->tp_mti = NOT_PRESENT_8BIT;
1356 rp_ud->v_tpdu = FALSE;
1357 }
1358 if (ack_res->resp EQ SMS_RP_ACK)
1359 rl_report_req_ack (rp_ud);
1360 else
1361 {
1362 if (!rp_ud->v_tpdu)
1363 {
1364 rp_ud->tp_mti = rp_ud->tpdu.b_tpdu[0] = SMS_DELIVER_REPORT;
1365 rp_ud->tpdu.b_tpdu[1] = SMS_FCS_UNSPECIFIED; /* TP-FCS */
1366 rp_ud->tpdu.b_tpdu[2] = 0; /* TP-PI */
1367 rp_ud->tpdu.l_tpdu = 24; /* 3 bytes */
1368 rp_ud->v_tpdu = TRUE;
1369 }
1370 rl_report_req_error (SMS_RP_CS_PROTOCOL_ERROR, rp_ud);
1371 /*
1372 * RL_RELEASE_REQ ==>
1373 */
1374 rl_release_req(SMS_INST.ti);
1375 }
1376 CCD_END;
1377 MFREE (rp_ud);
1378
1379 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
1380 break;
1381 }
1382 /*FALLTHROUGH*/ /*lint -fallthrough*/
1383 default:
1384 tl_mnsms_error_ind (SMS_CAUSE_UNEXP_CNMA);
1385 break;
1386 }
1387 }
1388 PFREE (ack_res);
1389 }
1390
1391 /*
1392 +--------------------------------------------------------------------+
1393 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1394 | STATE : code ROUTINE : tl_mnsms_pause_req |
1395 +--------------------------------------------------------------------+
1396
1397 PURPOSE : Process the primitive MNSMS_PAUSE_REQ.
1398 */
1399 GLOBAL void tl_mnsms_pause_req (T_MNSMS_PAUSE_REQ *pause_req)
1400 {
1401
1402 TRACE_FUNCTION ("tl_mnsms_pause_req()");
1403
1404 tl_pause();
1405
1406 PFREE (pause_req);
1407 }
1408
1409 /*
1410 +--------------------------------------------------------------------+
1411 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1412 | STATE : code ROUTINE : tl_mnsms_resume_req |
1413 +--------------------------------------------------------------------+
1414
1415 PURPOSE : Process the primitive MNSMS_RESUME_REQ.
1416 */
1417 GLOBAL void tl_mnsms_resume_req (T_MNSMS_RESUME_REQ *resume_req)
1418 {
1419
1420 TRACE_FUNCTION ("tl_mnsms_resume_req()");
1421
1422 tl_resume();
1423
1424 PFREE (resume_req);
1425 }
1426
1427 /*
1428 +--------------------------------------------------------------------+
1429 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1430 | STATE : code ROUTINE : tl_mnsms_query_req |
1431 +--------------------------------------------------------------------+
1432
1433 PURPOSE : Process the primitive MNSMS_QUERY_REQ.
1434 */
1435 GLOBAL void tl_mnsms_query_req (T_MNSMS_QUERY_REQ *query_req)
1436 {
1437
1438 TRACE_FUNCTION ("tl_mnsms_query_req()");
1439
1440 switch (query_req->query_type)
1441 {
1442 case SMS_QUERY_DELIVER_STATUS:
1443 tl_query_deliver_status();
1444 break;
1445 default:
1446 TRACE_ERROR("sms query type unknown!");
1447 }
1448
1449 PFREE (query_req);
1450 }
1451
1452 /*
1453 +--------------------------------------------------------------------+
1454 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1455 | STATE : code ROUTINE : tl_mnsms_resume_cnf |
1456 +--------------------------------------------------------------------+
1457
1458 PURPOSE : Generate a response to the primitive MNSMS_RESUME_REQ.
1459 */
1460
1461 GLOBAL void tl_mnsms_resume_cnf ( USHORT cause )
1462 {
1463 PALLOC (resume_cnf, MNSMS_RESUME_CNF);
1464
1465 resume_cnf->cause = cause;
1466
1467 PSENDX (MMI, resume_cnf);
1468 }
1469
1470 /*
1471 +--------------------------------------------------------------------+
1472 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1473 | STATE : code ROUTINE : tl_mnsms_query_cnf |
1474 +--------------------------------------------------------------------+
1475
1476 PURPOSE : Generate a response to the primitive MNSMS_QUERY_REQ.
1477 */
1478
1479 GLOBAL void tl_mnsms_query_cnf ( U8 query_type, U8 status )
1480 {
1481
1482 switch (query_type)
1483 {
1484 case SMS_QUERY_DELIVER_STATUS:
1485 {
1486 PALLOC (query_cnf, MNSMS_QUERY_CNF);
1487
1488 query_cnf->query_type = SMS_QUERY_DELIVER_STATUS;
1489 query_cnf->v_deliver_status = 1;
1490 query_cnf->deliver_status = status;
1491
1492 PSENDX (MMI, query_cnf);
1493 }
1494 break;
1495 default:
1496 TRACE_ERROR("sms query type unknown!");
1497 }
1498
1499 }
1500
1501 /*
1502 +--------------------------------------------------------------------+
1503 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1504 | STATE : code ROUTINE : tl_sim_sms_insert_ind |
1505 +--------------------------------------------------------------------+
1506
1507 PURPOSE : Process the primitive SIM_SMS_INSERT_IND.
1508
1509 */
1510
1511 GLOBAL void tl_sim_sms_insert_ind (T_SIM_SMS_INSERT_IND *insert_ind)
1512 {
1513 UBYTE i;
1514 GET_INSTANCE_DATA;
1515
1516 TRACE_FUNCTION ("tl_sim_sms_insert_ind()");
1517
1518 if (sms_data) /*lint !e774 always True*/
1519 {
1520 tl_sim_abort_to_mmi (SMS_CAUSE_SIM_BUSY);
1521 sms_data->init_done = FALSE;
1522 tl_mnsms_report_ind (SMS_ENT_STATE(sms_data) = SMS_STATE_INITIALISING);
1523 /*
1524 * copy SMS initialisation parameter
1525 */
1526 SMS_SIM_PHASE(sms_data) = insert_ind->phase;
1527 SMS_INST.tp_mr = insert_ind->tp_mr;
1528 /*
1529 * memory capacity exceeded notification flag
1530 */
1531 switch (insert_ind->mem_cap_avail)
1532 {
1533 case SIM_SMS_MEM_FULL:
1534 /*
1535 * Notification Flag = TRUE
1536 */
1537 TRACE_EVENT("SIM_SMS_MEM_FULL => Notification Flag = TRUE");
1538 break;
1539 case SIM_SMS_MEM_AVAIL:
1540 /*
1541 * Notification Flag = FALSE
1542 */
1543 TRACE_EVENT("SIM_SMS_MEM_AVAIL => Notification Flag = FALSE");
1544 break;
1545 case SIM_SMS_NO_MEM:
1546 /*
1547 * SMS storage on SIM not present
1548 */
1549 TRACE_EVENT("SIM_SMS_NO_MEM");
1550 break;
1551 default:
1552 TRACE_ERROR("invalid mem cap avail information from sim");
1553 }
1554 SMS_SIM_MEM_AVAIL(sms_data) = insert_ind->mem_cap_avail & 1;
1555 SMS_SAT_DWNLD(sms_data) = insert_ind->download_sms;
1556
1557 /*
1558 * scan status and protocol identifier for all SMS entries
1559 * first one in tl_find_first, the rest with the for loop
1560 * in mobile memory
1561 */
1562 tl_find_first (MEM_ME);
1563 for (i = 2; i <= sms_data->me_backup.max_record; i++)
1564 tl_find_next (MEM_ME, i);
1565
1566 /*
1567 * check for existing but empty memory
1568 */
1569 if (SMS_ME_PROP(sms_data).max_record > 0
1570 AND !SMS_ME_PROP(sms_data).any_valid)
1571 tl_message_ind_from_sim (MEM_ME, 0,
1572 SMS_ME_PROP(sms_data).max_record,
1573 NULL);
1574 /*
1575 * scan status and protocol identifier for all SMS entries
1576 * in sim memory
1577 */
1578 #ifdef FF_CPHS
1579 SET_STATE (STATE_MMI, MMI_FIND_FIRST);
1580 tl_sim_read_req (SIM_CPHS_VMW, 1);
1581 #elif defined FF_SMS_NW_RCG_SIM
1582 SET_STATE (STATE_MMI, MMI_FIND_FIRST);
1583 tl_sim_read_req (SIM_IMSI, 9);
1584 #else
1585 tl_find_first (MEM_SM);
1586 #endif
1587 }
1588 PFREE (insert_ind);
1589 }
1590
1591 /*
1592 +--------------------------------------------------------------------+
1593 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
1594 | STATE : code ROUTINE : tl_sim_read_cnf |
1595 +--------------------------------------------------------------------+
1596
1597 PURPOSE : Process the primitive SIM_READ_CNF.
1598 */
1599 #if defined(SIM_TOOLKIT) OR defined(FF_CPHS) OR defined(FF_SMS_NW_RCG_SIM)
1600 GLOBAL void tl_sim_read_cnf (T_SIM_READ_CNF *read_cnf)
1601 {
1602 GET_INSTANCE_DATA;
1603 USHORT datafield;
1604
1605 TRACE_FUNCTION ("tl_sim_file_update_ind()");
1606
1607 datafield = sms_data->sms_sim_access_info[read_cnf->req_id].datafield;
1608 sms_data->sms_sim_access_info[read_cnf->req_id].entry_used = FALSE;
1609
1610 if (sms_data)
1611 {
1612 switch (GET_STATE (STATE_MMI))
1613 {
1614 case MMI_STATE_UPDATE:
1615 /*
1616 * EF_SMSS has been updated by SAT.
1617 */
1618 if (read_cnf->cause EQ SIM_NO_ERROR)
1619 {
1620 /* Fetch TP-MR value out of EF_SMSS */
1621 SMS_INST.tp_mr = read_cnf->trans_data[0];
1622
1623 if (sms_data->mem_cap_avail NEQ (read_cnf->trans_data[1] & 1))
1624 {
1625 /*
1626 * The memory capacity available flag has been changed.
1627 * Re-read EF_SMS also even in case this has not been announced
1628 * by the SIM application.
1629 */
1630 sms_data->mem_cap_avail = read_cnf->trans_data[1] & 1;
1631 sms_data->sim_mem_update = TRUE;
1632 }
1633 else
1634 {
1635 SET_STATE (STATE_MMI, MMI_IDLE);
1636 }
1637 }
1638 if (sms_data->sim_mem_update)
1639 {
1640 tl_mnsms_report_ind (SMS_ENT_STATE(sms_data) = SMS_STATE_INITIALISING);
1641 tl_find_first (MEM_SM);
1642 #ifdef SIM_TOOLKIT
1643 if (sms_data->stored_read_cnf NEQ NULL)
1644 {
1645 /*
1646 * Resets the stored MMI state & read_cnf primitive
1647 */
1648 sms_data->stored_mmi_state = MMI_IDLE;
1649 PFREE (sms_data->stored_read_cnf);
1650 sms_data->stored_read_cnf = NULL;
1651 }
1652 #endif /* SIM_TOOLKIT */
1653 }
1654 else
1655 {
1656 PALLOC (file_update_res, SIM_FILE_UPDATE_RES);
1657 file_update_res->fu_rsc = SIM_FU_SUCCESS;
1658 file_update_res->source = SRC_SMS;
1659 PSENDX (SIM, file_update_res);
1660 }
1661 #ifdef SIM_TOOLKIT
1662 /*
1663 * If the SMS has not yet completed reading all the records, start from
1664 * the place where it has left earlier.
1665 */
1666 if( sms_data->stored_read_cnf NEQ NULL)
1667 {
1668 SET_STATE(STATE_MMI, sms_data->stored_mmi_state);
1669 tl_set_access_fifo (ACCESS_BY_MMI);
1670 tl_sim_read_record_cnf(sms_data->stored_read_cnf);
1671 sms_data->stored_mmi_state = MMI_IDLE;
1672 sms_data->stored_read_cnf = NULL;
1673 }
1674 #endif /* SIM_TOOLKIT */
1675
1676 break;
1677 #ifdef FF_CPHS
1678 case MMI_FIND_FIRST: /* CPHS Voice Message Waiting flag existent? */
1679 #ifdef FF_SMS_NW_RCG_SIM
1680 if ( datafield EQ SIM_CPHS_VMW)
1681 {
1682 SMS_CPHS(sms_data) = read_cnf->cause EQ SIM_NO_ERROR;
1683 tl_sim_read_req (SIM_IMSI, 9);
1684 break;
1685 }
1686 else if (datafield EQ SIM_IMSI
1687 AND read_cnf->cause EQ SIM_NO_ERROR)
1688 {
1689 tl_check_network_on_sim (read_cnf->trans_data);
1690 }
1691 tl_find_first (MEM_SM);
1692 #else
1693 SMS_CPHS(sms_data) = datafield EQ SIM_CPHS_VMW
1694 AND read_cnf->cause EQ SIM_NO_ERROR;
1695 tl_find_first (MEM_SM);
1696 #endif
1697 #elif defined FF_SMS_NW_RCG_SIM
1698 case MMI_FIND_FIRST: /* SIM operator determination required? */
1699 if (read_cnf->cause EQ SIM_NO_ERROR)
1700 tl_check_network_on_sim (read_cnf->trans_data);
1701 tl_find_first (MEM_SM);
1702 break;
1703 #endif
1704 default:
1705 break;
1706 }
1707 }
1708 PFREE (read_cnf);
1709 }
1710 #endif /* SIM_TOOLKIT OR FF_CPHS */
1711
1712 /*
1713 +--------------------------------------------------------------------+
1714 | PROJECT : GSM-PS (8410) MODULE : SMS_TLF |
1715 | STATE : code ROUTINE : tl_sim_update_rec_cnf_mmi |
1716 +--------------------------------------------------------------------+
1717
1718 PURPOSE : Processing the function TL_SIM_UPDATE_REC_CNF_MMI.
1719
1720 */
1721
1722 LOCAL void tl_sim_update_rec_cnf_mmi (
1723 T_SIM_UPDATE_RECORD_CNF *update_cnf)
1724 {
1725 GET_INSTANCE_DATA;
1726 UBYTE next_rec_num=0,record;
1727 TRACE_FUNCTION ("tl_sim_update_rec_cnf_mmi()");
1728
1729 record = sms_data->sms_sim_access_info[update_cnf->req_id].rec_num;
1730 sms_data->sms_sim_access_info[update_cnf->req_id].entry_used = FALSE;
1731
1732 switch (GET_STATE (STATE_MMI))
1733 {
1734 case MMI_READ_STATE_UPDATE:
1735 if (update_cnf->cause EQ SIM_NO_ERROR AND
1736 record EQ SMS_SEL_REC(sms_data))
1737 {
1738 /*
1739 * update status byte
1740 */
1741 tl_store_status (&SMS_SIM_PROP(sms_data), record-1,
1742 SMS_RECORD_REC_READ);
1743 }
1744 if (SMS_READ_MODE(sms_data) EQ READ_STATUS_CHANGE)
1745 {
1746 tl_mnsms_read_cnf (MEM_SM, SMS_SEL_REC(sms_data),
1747 NULL, SIM_NO_ERROR);
1748 }
1749 else
1750 {
1751 tl_mnsms_read_cnf (MEM_SM, SMS_SEL_REC(sms_data),
1752 SMS_SIM_READ(sms_data)->linear_data,
1753 SIM_NO_ERROR);
1754 PFREE (SMS_SIM_READ(sms_data));
1755 SMS_SIM_READ(sms_data) = NULL;
1756 }
1757 SMS_READ_MODE(sms_data) = READ_NORMAL;
1758 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
1759 break;
1760
1761 case MMI_WRITE:
1762 if (update_cnf->cause EQ SIM_NO_ERROR)
1763 {
1764 /*
1765 * update status byte
1766 */
1767 tl_store_status (&SMS_SIM_PROP(sms_data), record-1,
1768 SMS_REC_STATUS(sms_data));
1769 tl_store_pid (&SMS_SIM_PROP(sms_data), record-1,
1770 SMS_PID(sms_data));
1771
1772
1773 SMS_EM_STORE_MO_SHORT_MESSAGE_2;
1774
1775 SMS_EM_CHANGE_SHORT_MESSAGE_2;
1776
1777 }
1778 else
1779 {
1780 tl_store_status (&SMS_SIM_PROP(sms_data), record-1, SIM_SMS_FREE);
1781 }
1782 tl_mnsms_store_cnf (MEM_SM, record, update_cnf->cause);
1783 SMS_READ_MODE(sms_data) = READ_NORMAL;
1784 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
1785 break;
1786
1787 case MMI_DELETE:
1788 if (record EQ SMS_SEL_REC(sms_data))
1789 {
1790 if (update_cnf->cause EQ SIM_NO_ERROR)
1791 {
1792 tl_store_status (&SMS_SIM_PROP(sms_data), record-1, SIM_SMS_FREE);
1793
1794 TRACE_EVENT_P1 ("mem cap avail %d", sms_data->mem_cap_avail);
1795
1796 if (!sms_data->mem_cap_avail)
1797 {
1798 GET_MO_INSTANCE(sms_data);
1799 /*
1800 * TL state transition TL_ESTABLISH
1801 * EST state transition EST_SMMA
1802 */
1803 SET_STATE (STATE_EST, EST_SMMA);
1804 SMS_INST_SET_STATE (STATE_TL, TL_ESTABLISH);
1805 /*
1806 * 1st shot
1807 */
1808 SMS_INST.retrans = FALSE;
1809 /*
1810 * establish connection
1811 */
1812 tl_establish_connection(FALSE);
1813 /*
1814 * wait for processing of RP-SMMA
1815 */
1816 return;
1817 }
1818 if(SMS_REC_STATUS(sms_data) NEQ CMGD_DEL_INDEX)
1819 {
1820 /* Status value is given. Find the next record satisfying this status value */
1821 next_rec_num = tl_search_record_for_delete (&SMS_SIM_PROP(sms_data),
1822 record,
1823 SMS_REC_STATUS(sms_data));
1824
1825
1826 TRACE_EVENT_P1 ("tl_sim_update_rec_cnf_mmi :: next_rec_num=%d", next_rec_num);
1827 }
1828 tl_mnsms_delete_cnf (MEM_SM, record, next_rec_num, SIM_NO_ERROR);
1829 }
1830 else
1831 tl_mnsms_delete_cnf (MEM_SM, record, 0, update_cnf->cause);
1832 }
1833 else
1834 tl_mnsms_delete_cnf (MEM_SM, record, 0, SMS_CAUSE_INV_INDEX);
1835
1836 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
1837 break;
1838
1839 case MMI_REPLACE:
1840 if (record EQ SMS_SEL_REC(sms_data))
1841 {
1842 if (update_cnf->cause EQ SIM_NO_ERROR)
1843 {
1844 #ifdef REL99
1845 if(SMS_INST.failed_msg_retx EQ FALSE)
1846 {
1847 #endif
1848 tl_mnsms_submit_cnf (MEM_SM, record,
1849 SMS_TP_REF_RET(sms_data),
1850 SMS_NO_ERROR, SMS_SDU(sms_data));
1851 #ifdef REL99
1852 }
1853 else
1854 {
1855 tl_mnsms_retrans_cnf (MEM_SM, record,
1856 SMS_TP_REF_RET(sms_data),
1857 SMS_NO_ERROR, SMS_SDU(sms_data));
1858 }
1859 #endif
1860
1861 /*
1862 * update status byte
1863 */
1864 tl_store_status (&SMS_SIM_PROP(sms_data), record-1,
1865 SMS_RECORD_STO_SENT);
1866 tl_store_pid (&SMS_SIM_PROP(sms_data), record-1,
1867 SMS_PID_DEFAULT);
1868 }
1869 else
1870 {
1871 #ifdef REL99
1872 if(SMS_INST.failed_msg_retx EQ FALSE)
1873 {
1874 #endif
1875 tl_mnsms_submit_cnf (MEM_SM, SMS_RECORD_NOT_EXIST,
1876 SMS_TP_REF_RET(sms_data),
1877 update_cnf->cause, SMS_SDU(sms_data));
1878 #ifdef REL99
1879 }
1880 else
1881 {
1882 tl_mnsms_retrans_cnf (MEM_SM, SMS_RECORD_NOT_EXIST,
1883 SMS_TP_REF_RET(sms_data),
1884 update_cnf->cause, SMS_SDU(sms_data));
1885 }
1886 #endif
1887 tl_store_status (&SMS_SIM_PROP(sms_data), record-1,
1888 SMS_RECORD_FREE); /* reset reservation */
1889 }
1890 }
1891 else
1892 tl_mnsms_submit_cnf (MEM_SM, record,
1893 SMS_TP_REF_RET(sms_data),
1894 SMS_CAUSE_INV_INDEX, SMS_SDU(sms_data));
1895
1896 if (SMS_SDU(sms_data) NEQ NULL)
1897 {
1898 MFREE (SMS_SDU(sms_data));
1899 SMS_SDU(sms_data) = NULL;
1900 }
1901 SMS_SEL_REC(sms_data) = SMS_RECORD_NOT_EXIST;
1902 /*
1903 * concat control
1904 */
1905 if (sms_data->concat_cntrl.concatenation EQ TRUE)
1906 {
1907 /*
1908 * start timer TLCT for next submit req supervision
1909 */
1910 sms_timer_start(TLCT);
1911 /*
1912 * TL State Transition TL_SEND_CONTD
1913 */
1914 SMS_INST_SET_STATE (STATE_TL, TL_SEND_CONTD);
1915 /*
1916 * remember to release connection
1917 */
1918 sms_data->concat_cntrl.release_pending = TRUE;
1919 }
1920 else
1921 {
1922 /*
1923 * TL State Transition TL_IDLE
1924 */
1925 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
1926 }
1927 break;
1928
1929 default:
1930 assert (GET_STATE (STATE_MMI) EQ MMI_IDLE); /* illegal state */
1931 break;
1932 }
1933 SET_STATE (STATE_MMI, MMI_IDLE);
1934 #ifdef SIM_TOOLKIT
1935 if (sms_data->file_update_ind NEQ NULL)
1936 {
1937 T_SIM_FILE_UPDATE_IND *file_update_ind = sms_data->file_update_ind;
1938 sms_data->file_update_ind = NULL;
1939 tl_sim_file_update_ind (file_update_ind);
1940 }
1941 #endif
1942 }
1943
1944 /*
1945 +--------------------------------------------------------------------+
1946 | PROJECT : GSM-PS (8410) MODULE : SMS_TLF |
1947 | STATE : code ROUTINE : tl_sim_update_rec_cnf_net |
1948 +--------------------------------------------------------------------+
1949
1950 PURPOSE : Processing the function TL_SIM_UPDATE_REC_CNF_NET.
1951
1952 */
1953
1954 LOCAL void tl_sim_update_rec_cnf_net (T_SIM_UPDATE_RECORD_CNF *update_cnf)
1955 {
1956 GET_INSTANCE_DATA;
1957 UBYTE record;
1958 UBYTE data[SIZE_EF_SMS];
1959
1960 TRACE_FUNCTION ("tl_sim_update_rec_cnf_net()");
1961
1962 record = sms_data->sms_sim_access_info[update_cnf->req_id].rec_num;
1963 sms_data->sms_sim_access_info[update_cnf->req_id].entry_used = FALSE;
1964
1965
1966 CCD_START;
1967
1968 switch (GET_STATE (STATE_NET))
1969 {
1970 case NET_WRITE:
1971 if (update_cnf->cause EQ SIM_NO_ERROR)
1972 {
1973 /*
1974 * update status byte
1975 */
1976 tl_store_status (&SMS_SIM_PROP(sms_data), record-1,
1977 SMS_RECORD_REC_UNREAD);
1978 tl_store_pid (&SMS_SIM_PROP(sms_data), record-1, SMS_PID(sms_data));
1979 /*
1980 * send indication to MMI
1981 */
1982 tl_message_ind_from_net (MEM_SM, record,
1983 SMS_SIM_PROP(sms_data).max_record,
1984 SMS_RP_RCVD(sms_data));
1985
1986 rl_report_req_ack (NULL);
1987 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
1988 }
1989 else switch (sms_data->use_mem_b) // check alternative B
1990 {
1991 case DISPLAY:
1992 /*
1993 * Only display of the message
1994 */
1995 tl_message_ind_from_net (NOT_PRESENT_8BIT, 0, 0,
1996 SMS_RP_RCVD(sms_data));
1997 {
1998 if (sms_data->mhc NEQ SMS_MHC_PH2PLUS)
1999 {
2000 rl_report_req_ack (NULL);
2001 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2002 }
2003 }
2004 break;
2005
2006 case MEM_ME:
2007 /*
2008 * memory type is mobile memory
2009 */
2010 record = tl_get_free_space (MEM_ME);
2011 if (record)
2012 {
2013 /*
2014 * store in mobile memory
2015 */
2016 /* Implements Measure#32: Row 104 */
2017 if (pcm_WriteRecord ((UBYTE *)ef_sms_id, record,
2018 SIZE_EF_SMS, data) EQ PCM_OK)
2019 {
2020 /*
2021 * update status byte
2022 */
2023 tl_store_status (&SMS_ME_PROP(sms_data), record-1, SMS_RECORD_REC_UNREAD);
2024 tl_store_pid (&SMS_ME_PROP(sms_data), record-1, SMS_PID(sms_data));
2025 /*
2026 * send indication to MMI
2027 */
2028 tl_message_ind_from_net (MEM_ME, record,
2029 SMS_ME_PROP(sms_data).max_record,
2030 SMS_RP_RCVD(sms_data));
2031 /*
2032 * acknowledge to the infrastructure
2033 */
2034 rl_report_req_ack (NULL);
2035 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2036 break;
2037 }
2038 }
2039 /*FALLTHROUGH*/ /*lint -fallthrough*/
2040 default:
2041 if (tl_get_free_space (MEM_ME) OR tl_get_free_space (MEM_SM))
2042 {
2043 /*
2044 * error to the infrastructure
2045 */
2046 rl_report_req_error (SMS_RP_CS_PROTOCOL_ERROR, NULL);
2047 /*
2048 * RL_RELEASE_REQ ==>
2049 */
2050 rl_release_req(SMS_INST.ti);
2051
2052 }
2053 else
2054 {
2055 if (update_cnf->cause NEQ SIM_CAUSE_DRV_TEMPFAIL)
2056 {
2057 /* change mem_cap_avail flag on SIM and return error */
2058 tl_sms_memo_exceeded (FALSE);
2059 }
2060 else
2061 {
2062 /*
2063 * RP_ERROR =>
2064 */
2065 rl_report_req_error (
2066 SMS_RP_CS_PROTOCOL_ERROR, NULL);
2067 /*
2068 * RL_RELEASE_REQ ==>
2069 */
2070 rl_release_req(SMS_INST.ti);
2071 }
2072 }
2073 tl_store_status (&SMS_SIM_PROP(sms_data), record-1, SIM_SMS_FREE);
2074 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2075 break;
2076
2077 case IGNORE:
2078 rl_report_req_ack (NULL);
2079 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2080
2081 MFREE (SMS_RP_RCVD(sms_data));
2082 SMS_RP_RCVD(sms_data) = NULL;
2083 break;
2084 }
2085 sms_data->use_mem_b = NOTHING;
2086
2087 MFREE (SMS_RP_RCVD(sms_data));
2088 SMS_RP_RCVD(sms_data) = NULL;
2089 break;
2090
2091 case NET_23430_WRITE:
2092 if (update_cnf->cause EQ SIM_NO_ERROR)
2093 {
2094 CCD_END;
2095
2096 tl_sim_update_req (record,
2097 SMS_RECORD_FREE, NULL);
2098
2099 tl_set_access_fifo (ACCESS_BY_NET);
2100 SET_STATE (STATE_NET, NET_23430_DELETE);
2101 return;
2102 }
2103 tl_store_status (&SMS_SIM_PROP(sms_data), record-1, SIM_SMS_FREE);
2104
2105 tl_sms_memo_exceeded (FALSE);
2106 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2107 break;
2108
2109 case NET_23430_DELETE:
2110 tl_store_status (&SMS_SIM_PROP(sms_data), record-1, SIM_SMS_FREE);
2111 rl_report_req_ack (NULL);
2112 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2113 break;
2114
2115 default:
2116 assert (GET_STATE (STATE_NET) EQ NET_IDLE); /* illegal state */
2117 // SET_STATE (STATE_NET, NET_IDLE);
2118 break;
2119 }
2120 CCD_END;
2121
2122 SET_STATE (STATE_NET, NET_IDLE);
2123 }
2124
2125 /*
2126 +--------------------------------------------------------------------+
2127 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2128 | STATE : code ROUTINE : tl_sim_update_cnf |
2129 +--------------------------------------------------------------------+
2130
2131 PURPOSE : After updating of EF(SMSS) the Entity state is checked
2132 and a MNSMS_REPORT_IND is sent to indicate the Ready
2133 State
2134 */
2135
2136 GLOBAL void tl_sim_update_cnf (T_SIM_UPDATE_CNF *update_cnf)
2137 {
2138 GET_INSTANCE_DATA;
2139 UBYTE next_rec_num = 0;
2140
2141 TRACE_FUNCTION ("tl_sim_update_cnf()");
2142 sms_data->sms_sim_access_info[update_cnf->req_id].entry_used = FALSE;
2143
2144 switch (tl_read_access_fifo ())
2145 {
2146 case ACCESS_BY_MMI:
2147 if (sms_data->sms_sim_access_info[update_cnf->req_id].datafield EQ SIM_SMSS AND
2148 SMS_ENT_STATE(sms_data) EQ SMS_STATE_INITIALISING)
2149 {
2150 tl_mnsms_report_ind (SMS_ENT_STATE(sms_data) = SMS_STATE_READY);
2151 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2152 PFREE (update_cnf);
2153 return;
2154 }
2155 if (GET_STATE (STATE_MMI) EQ MMI_DELETE)
2156 {
2157 GET_MO_INSTANCE(sms_data);
2158 /*
2159 * confirm deletion to user
2160 */
2161 if(SMS_REC_STATUS(sms_data) NEQ CMGD_DEL_INDEX)
2162 {
2163 /* Status value is given. Find the next record satisfying this status value */
2164 next_rec_num = tl_search_record_for_delete (((SMS_SEL_MEM(sms_data) EQ MEM_ME)?
2165 &SMS_ME_PROP(sms_data):&SMS_SIM_PROP(sms_data)),
2166 SMS_SEL_REC(sms_data),
2167 SMS_REC_STATUS(sms_data));
2168 }
2169 tl_mnsms_delete_cnf (SMS_SEL_MEM(sms_data), SMS_SEL_REC(sms_data), next_rec_num, SIM_NO_ERROR);
2170 SET_STATE (STATE_MMI, MMI_IDLE);
2171 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2172 }
2173 else if (GET_STATE (STATE_MMI) EQ MMI_RESUME)
2174 {
2175 /*
2176 * confirm resumption to user
2177 */
2178 if (sms_data->pr_cntrl.save_cause EQ SMS_NO_ERROR)
2179 {
2180 if (update_cnf->cause == SIM_NO_ERROR)
2181 {
2182 tl_mnsms_resume_cnf(SMS_NO_ERROR);
2183 }
2184 else
2185 {
2186 tl_mnsms_resume_cnf(update_cnf->cause);
2187 }
2188 }
2189 else
2190 {
2191 tl_mnsms_resume_cnf(sms_data->pr_cntrl.save_cause);
2192 }
2193 SET_STATE (STATE_MMI, MMI_IDLE);
2194 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2195 }
2196 break;
2197
2198 case ACCESS_BY_NET:
2199 TRACE_EVENT ("SIM_UPDATE_CNF ignored");
2200 break;
2201
2202 default:
2203 TRACE_ERROR ("Unexpected Error Value");
2204 break;
2205 }
2206 #ifdef SIM_TOOLKIT
2207 if (sms_data->file_update_ind NEQ NULL)
2208 {
2209 T_SIM_FILE_UPDATE_IND *file_update_ind = sms_data->file_update_ind;
2210 sms_data->file_update_ind = NULL;
2211 tl_sim_file_update_ind (file_update_ind);
2212 }
2213 #endif
2214 PFREE (update_cnf);
2215 }
2216
2217 /*
2218 +--------------------------------------------------------------------+
2219 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2220 | STATE : code ROUTINE : tl_sim_update_record_cnf |
2221 +--------------------------------------------------------------------+
2222
2223 PURPOSE : Process the primitive SIM_UPDATE_RECORD_CNF.
2224
2225 */
2226
2227 GLOBAL void tl_sim_update_record_cnf (T_SIM_UPDATE_RECORD_CNF *update_cnf)
2228 {
2229 GET_INSTANCE_DATA;
2230
2231 TRACE_FUNCTION ("tl_sim_update_record_cnf()");
2232
2233 switch (tl_read_access_fifo ())
2234 {
2235 case ACCESS_BY_NET:
2236 GET_MT_INSTANCE(sms_data); /* MT */
2237 tl_sim_update_rec_cnf_net (update_cnf);
2238 break;
2239
2240 case ACCESS_BY_MMI:
2241 GET_MO_INSTANCE(sms_data); /* MO */
2242 tl_sim_update_rec_cnf_mmi (update_cnf);
2243 break;
2244
2245 default:
2246 assert (0); /* impossible case */
2247 break;
2248 }
2249 PFREE (update_cnf);
2250 }
2251
2252 /*
2253 +--------------------------------------------------------------------+
2254 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2255 | STATE : code ROUTINE : tl_sim_read_record_cnf |
2256 +--------------------------------------------------------------------+
2257
2258 PURPOSE : Process the primitive SIM_READ_RECORD_CNF.
2259
2260 */
2261
2262 GLOBAL void tl_sim_read_record_cnf (T_SIM_READ_RECORD_CNF *read_cnf)
2263 {
2264 T_SIM_PDU *sim_pdu;
2265 GET_INSTANCE_DATA;
2266 UBYTE record;
2267 TRACE_FUNCTION ("tl_sim_read_record_cnf()");
2268
2269 record = sms_data->sms_sim_access_info[read_cnf->req_id].rec_num;
2270 sms_data->sms_sim_access_info[read_cnf->req_id].entry_used = FALSE;
2271
2272 if (sms_data) /*lint !e774 always True*/
2273 {
2274 switch (tl_read_access_fifo ())
2275 {
2276 case ACCESS_BY_MMI:
2277 GET_MO_INSTANCE(sms_data); /* MO */
2278 switch (GET_STATE (STATE_MMI))
2279 {
2280 case MMI_READ:
2281 /*
2282 * read attempt from MMI
2283 */
2284 if (read_cnf->cause EQ SIM_NO_ERROR AND
2285 record EQ SMS_SEL_REC(sms_data))
2286 {
2287 tl_store_status (&SMS_SIM_PROP(sms_data), record-1,
2288 read_cnf->linear_data[0]);
2289 if (SMS_INST_GET_STATE (STATE_TL) EQ TL_SEND)
2290 {
2291 MCAST (cp_data, U_CP_DATA);
2292
2293 MALLOC (sim_pdu, sizeof(T_SIM_PDU));
2294 CCD_START;
2295 if (tl_modify_submit (sim_pdu, SMS_MODIFY(sms_data),
2296 SMS_SDU(sms_data),
2297 read_cnf->linear_data) AND
2298 tl_prepare_submit (sim_pdu, cp_data))
2299 {
2300 /*
2301 * RL_DATA_REQ
2302 */
2303 if (!rl_data_req (SMS_INST.tp_mr, cp_data))
2304 {
2305 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2306 /*
2307 * release connection
2308 */
2309 rl_release_req(SMS_INST.ti);
2310 /*
2311 * send not successful but we confirm with no error ???!!
2312 */
2313 tl_mnsms_submit_cnf (MEM_SM, record,
2314 NOT_PRESENT_8BIT, SMS_NO_ERROR, NULL);
2315 }
2316 }
2317 else
2318 {
2319 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2320 tl_mnsms_submit_cnf (MEM_SM, record,
2321 NOT_PRESENT_8BIT, SMS_CAUSE_PARAM_WRONG, NULL);
2322 }
2323 CCD_END;
2324 MFREE (sim_pdu);
2325 MFREE (SMS_SDU(sms_data));
2326 SMS_SDU(sms_data) = NULL;
2327
2328 SET_STATE (STATE_MMI, MMI_IDLE);
2329 break;
2330 }
2331 if ((read_cnf->linear_data[0] & 1) EQ SMS_RECORD_FREE)
2332 {
2333 tl_mnsms_read_cnf (MEM_SM, 0,
2334 NULL, SMS_CAUSE_INV_INDEX);
2335 }
2336 else if (((read_cnf->linear_data[0] & 7) EQ SMS_RECORD_REC_UNREAD)
2337 AND SMS_READ_MODE(sms_data) NEQ READ_PREVIEW)
2338 {
2339 tl_set_access_fifo (ACCESS_BY_MMI);
2340 SET_STATE (STATE_MMI, MMI_READ_STATE_UPDATE);
2341 SMS_INST_SET_STATE (STATE_TL, TL_OTHER);
2342 tl_sim_update_req (record, SMS_RECORD_REC_READ,
2343 &read_cnf->linear_data[1]);
2344
2345 if (SMS_READ_MODE(sms_data) NEQ READ_STATUS_CHANGE)
2346 {
2347 // read_cnf->linear_data[0] = SMS_RECORD_REC_READ;
2348 /*
2349 * keep read data until reception of UPDATE CONFIRM
2350 */
2351 if (SMS_SIM_READ(sms_data) NEQ 0)
2352 PFREE(SMS_SIM_READ(sms_data));
2353 SMS_SIM_READ(sms_data) = read_cnf;
2354 return; /* read_cnf not to be deallocated */
2355 }
2356 PFREE (read_cnf);
2357 return; /* keep states */
2358 }
2359 else
2360 {
2361
2362 SMS_EM_READ_SHORT_MESSAGE_2;
2363
2364 tl_mnsms_read_cnf (MEM_SM, record,
2365 ((SMS_READ_MODE(sms_data) EQ READ_STATUS_CHANGE)?
2366 NULL: read_cnf->linear_data),
2367 SIM_NO_ERROR);
2368 }
2369 }
2370 else
2371 {
2372 if (SMS_INST_GET_STATE (STATE_TL) EQ TL_SEND)
2373 {
2374 if (read_cnf->cause EQ SIM_NO_ERROR)
2375 tl_mnsms_submit_cnf (MEM_SM, record,
2376 NOT_PRESENT_8BIT, SMS_CAUSE_INV_INDEX, NULL);
2377 else
2378 tl_mnsms_submit_cnf (MEM_SM, record,
2379 NOT_PRESENT_8BIT, read_cnf->cause, NULL);
2380 }
2381 else
2382 tl_mnsms_read_cnf (MEM_SM, 0,
2383 NULL, SMS_CAUSE_INV_INDEX);
2384 }
2385 SET_STATE (STATE_MMI, MMI_IDLE);
2386 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2387 break;
2388
2389 case MMI_FIND_FIRST:
2390 #ifdef SIM_TOOLKIT
2391 if (sms_data->file_update_ind NEQ NULL)
2392 {
2393 T_SIM_FILE_UPDATE_IND *file_update_ind = sms_data->file_update_ind;
2394 /*
2395 * Take a backup of the current status of the MMI_STATE
2396 */
2397 sms_data->stored_mmi_state = GET_STATE(STATE_MMI);
2398 SET_STATE (STATE_MMI, MMI_IDLE);
2399 sms_data->file_update_ind = NULL;
2400 tl_sim_file_update_ind (file_update_ind);
2401
2402 /* Implements Measure# 7 */
2403 if( tl_sim_rd_record_update_state(read_cnf) )
2404 return;
2405 }
2406 #endif
2407 /*
2408 * first record is scanned
2409 */
2410 if (read_cnf->cause EQ SIM_NO_ERROR)
2411 {
2412 /* Store max. supported records of the SIM */
2413 SMS_SIM_PROP(sms_data).max_record = read_cnf->max_record;
2414
2415 if (SMS_SIM_PROP(sms_data).max_record > MAX_RECORD_SIM)
2416 {
2417 /* The number of supported records is limited by SMS */
2418 SMS_SIM_PROP(sms_data).max_record = MAX_RECORD_SIM;
2419 }
2420 else if (SMS_SIM_PROP(sms_data).max_record EQ 0)
2421 {
2422 /* We have at least one record as we successfully read it
2423 * regardless of the returned value from the SIM */
2424 SMS_SIM_PROP(sms_data).max_record = 1;
2425 }
2426 /*
2427 * continue with MMI_FIND_NEXT
2428 */
2429 }
2430 else
2431 {
2432 /*
2433 * No EF_SMS field on the SIM.
2434 */
2435 SMS_SIM_PROP(sms_data).max_record = 0;
2436 SET_STATE (STATE_MMI, MMI_IDLE);
2437 /*
2438 * init done
2439 */
2440 tl_init_complete();
2441 break;
2442 }
2443 /*FALLTHROUGH*/ /*lint -fallthrough*/
2444 case MMI_FIND_NEXT:
2445
2446 #ifdef SIM_TOOLKIT
2447 /*
2448 * Take a backup of the current status of the MMI_STATE
2449 */
2450 sms_data->stored_mmi_state = GET_STATE(STATE_MMI);
2451 #endif /* SIM_TOOLKIT */
2452
2453 SET_STATE (STATE_MMI, MMI_IDLE);
2454
2455 #ifdef SIM_TOOLKIT
2456
2457 if (sms_data->file_update_ind NEQ NULL)
2458 {
2459 T_SIM_FILE_UPDATE_IND *file_update_ind = sms_data->file_update_ind;
2460 sms_data->file_update_ind = NULL;
2461 tl_sim_file_update_ind (file_update_ind);
2462
2463 /* Implements Measure# 7 */
2464 if( tl_sim_rd_record_update_state(read_cnf) )
2465 return;
2466 }
2467 #endif
2468 /*
2469 * next record is scanned
2470 */
2471 if (read_cnf->cause EQ SIM_NO_ERROR)
2472 {
2473 if (tl_find_status_pid (MEM_SM,
2474 record,
2475 read_cnf->linear_data,
2476 &SMS_SIM_PROP(sms_data)))
2477 tl_message_ind_from_sim (MEM_SM, record,
2478 read_cnf->max_record,
2479 read_cnf->linear_data);
2480 if (record < SMS_SIM_PROP(sms_data).max_record)
2481 tl_find_next (MEM_SM, (UBYTE)(record + 1));
2482 else
2483 {
2484 #ifdef SIM_TOOLKIT
2485 if (sms_data->sim_mem_update)
2486 {
2487 PALLOC (file_update_res, SIM_FILE_UPDATE_RES);
2488 file_update_res->source = SRC_SMS;
2489 file_update_res->fu_rsc = SIM_FU_SUCCESS;
2490 PSENDX (SIM, file_update_res);
2491 sms_data->sim_mem_update = FALSE;
2492 }
2493 #endif
2494 /*
2495 * check for existing but empty memory
2496 */
2497 if (SMS_SIM_PROP(sms_data).max_record > 0
2498 AND !SMS_SIM_PROP(sms_data).any_valid)
2499 tl_message_ind_from_sim (MEM_SM, 0,
2500 SMS_SIM_PROP(sms_data).max_record,
2501 NULL);
2502
2503 /*
2504 * init done
2505 */
2506 tl_init_complete();
2507 }
2508 }
2509 else
2510 {
2511 /*
2512 * declare only successful read
2513 * entries as available
2514 */
2515 SMS_SIM_PROP(sms_data).max_record = record - 1;
2516 // must be doubled
2517 /*
2518 * init done
2519 */
2520 tl_init_complete();
2521 }
2522 break;
2523
2524 default:
2525 assert (GET_STATE (STATE_MMI) EQ MMI_IDLE); /* illegal state */
2526 break;
2527 }
2528 #ifdef SIM_TOOLKIT
2529 if (sms_data->file_update_ind NEQ NULL)
2530 {
2531 T_SIM_FILE_UPDATE_IND *file_update_ind = sms_data->file_update_ind;
2532 sms_data->file_update_ind = NULL;
2533 tl_sim_file_update_ind (file_update_ind);
2534 }
2535 #endif
2536 break;
2537
2538 case ACCESS_BY_NET:
2539 GET_MT_INSTANCE(sms_data); /* MT */
2540 switch (GET_STATE (STATE_NET))
2541 {
2542 case NET_READ:
2543 if (tl_check_replace_entry (&SMS_RP_RCVD(sms_data)->rp_user_data.tpdu.b_tpdu[1],
2544 &read_cnf->linear_data[1]))
2545 {
2546 /*
2547 *record shall be replaced
2548 */
2549 tl_sim_conv_update_req (record, SMS_RP_RCVD(sms_data));
2550
2551 SMS_EM_REPLACE_SMS_IN_SIM;
2552
2553 tl_set_access_fifo (ACCESS_BY_NET);
2554 SET_STATE (STATE_NET, NET_WRITE);
2555 }
2556 else
2557 {
2558 int i;
2559
2560 i = tl_check_mt_pid (&SMS_SIM_PROP(sms_data),
2561 record + 1,
2562 SMS_PID(sms_data));
2563 if (i > 0)
2564 {
2565 tl_set_access_fifo (ACCESS_BY_NET);
2566 tl_sim_read_record_req((UBYTE)i);
2567 }
2568 else
2569 {
2570 MCAST (sms_deliver, TP_DELIVER);
2571
2572 SET_STATE (STATE_NET, NET_IDLE);
2573
2574 CCD_START;
2575 ccd_decodeMsg (CCDENT_SMS,
2576 DOWNLINK,
2577 (T_MSGBUF *)&SMS_RP_RCVD(sms_data)->rp_user_data.tpdu,
2578 (UBYTE *)sms_deliver,
2579 TP_DELIVER);
2580 tl_handle_message (sms_deliver);
2581 CCD_END;
2582 }
2583 }
2584 break;
2585
2586 default:
2587 assert (GET_STATE (STATE_NET) EQ NET_IDLE); /* illegal state */
2588 break;
2589 }
2590 break;
2591
2592 default:
2593 assert (0); /* impossible case */
2594 break;
2595 }
2596 }
2597 PFREE (read_cnf);
2598 }
2599
2600 /*
2601 +--------------------------------------------------------------------+
2602 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2603 | STATE : code ROUTINE : tl_sim_remove_ind |
2604 +--------------------------------------------------------------------+
2605
2606 PURPOSE : Process the primitive SIM_REMOVE_IND.
2607
2608 */
2609
2610 GLOBAL void tl_sim_remove_ind (T_SIM_REMOVE_IND *remove_ind)
2611 {
2612 USHORT error;
2613 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE (0);
2614
2615 TRACE_FUNCTION ("tl_sim_remove_ind()");
2616 if (sms_data)
2617 {
2618 error = (remove_ind->cause EQ SIM_NO_ERROR)?
2619 SMS_CAUSE_SIM_BUSY: remove_ind->cause;
2620
2621 tl_sim_abort_to_mmi (error);
2622
2623 sms_data->init_done = FALSE;
2624 SMS_SIM_PROP(sms_data).max_record = 0;
2625 sms_data->me_backup.max_record = 0;
2626 sms_data->sim_mem_update = FALSE;
2627 }
2628 PFREE (remove_ind);
2629 }
2630
2631 #if defined(SIM_TOOLKIT)
2632 /*
2633 +--------------------------------------------------------------------+
2634 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2635 | STATE : code ROUTINE : tl_sim_toolkit_cnf |
2636 +--------------------------------------------------------------------+
2637
2638 PURPOSE : Process the primitive SIM_TOOLKIT_CNF.
2639
2640 */
2641
2642 GLOBAL void tl_sim_toolkit_cnf (T_SIM_TOOLKIT_CNF *toolkit_cnf)
2643 {
2644 GET_INSTANCE_DATA;
2645
2646 TRACE_FUNCTION ("tl_sim_toolkit_cnf()");
2647
2648 switch (tl_read_access_fifo ())
2649 {
2650 case ACCESS_BY_NET:
2651 GET_MT_INSTANCE(sms_data); /* MT */
2652 tl_sim_toolkit_confirm (toolkit_cnf);
2653 break;
2654
2655 default:
2656 assert(0);
2657 break;
2658 }
2659 PFREE (toolkit_cnf);
2660 }
2661
2662 /*
2663 +--------------------------------------------------------------------+
2664 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2665 | STATE : code ROUTINE : tl_sim_file_update_ind |
2666 +--------------------------------------------------------------------+
2667
2668 PURPOSE : Process the primitive SIM_FILE_UPDATE_IND.
2669
2670 */
2671
2672 GLOBAL void tl_sim_file_update_ind (T_SIM_FILE_UPDATE_IND *file_update_ind)
2673 {
2674 USHORT i;
2675 BOOL found_sms = FALSE; /* short messages changed by SAT */
2676 BOOL found_smss = FALSE; /* short message status changed by SAT */
2677 register T_SMS_DATA *sms_data = GET_SMS_INSTANCE (0);
2678
2679 TRACE_FUNCTION ("tl_sim_file_update_ind()");
2680
2681 if (sms_data)
2682 {
2683 /*
2684 * avoid interference with active MMI procedure
2685 */
2686 switch (GET_STATE (STATE_MMI))
2687 {
2688 case MMI_IDLE:
2689 break;
2690
2691 default:
2692 if (sms_data->file_update_ind NEQ NULL)
2693 PFREE (sms_data->file_update_ind);
2694 /* store primitive for delayed reaction */
2695 sms_data->file_update_ind = file_update_ind;
2696 return;
2697 }
2698
2699 for (i = 0; i < file_update_ind->val_nr; i++)
2700 {
2701 if((file_update_ind->file_info[i].v_path_info EQ TRUE) AND
2702 (file_update_ind->file_info[i].path_info.df_level1 EQ SIM_DF_TELECOM) AND
2703 (file_update_ind->file_info[i].path_info.v_df_level2 EQ FALSE))
2704 {
2705 if (file_update_ind->file_info[i].datafield EQ SIM_SMS)
2706 {
2707 /* short messages changed by SAT */
2708 found_sms = TRUE;
2709 sms_data->sim_mem_update = TRUE;
2710 }
2711 else if (file_update_ind->file_info[i].datafield EQ SIM_SMSS)
2712 {
2713 /* short message status changed by SAT */
2714 found_smss = TRUE;
2715 }
2716 }
2717
2718 if (found_sms AND found_smss)
2719 break;
2720 }
2721
2722 if (found_smss)
2723 {
2724 /* short message status changed by SAT */
2725 tl_sim_read_req (SIM_SMSS, 2);
2726 sms_data->sim_mem_update = found_sms NEQ FALSE;
2727
2728 SET_STATE (STATE_MMI, MMI_STATE_UPDATE);
2729 }
2730 else if (found_sms)
2731 {
2732 /* short messages changed by SAT */
2733 sms_data->init_done = FALSE;
2734 SMS_SIM_PROP(sms_data).max_record = 0;
2735 tl_mnsms_report_ind (SMS_ENT_STATE(sms_data) = SMS_STATE_INITIALISING);
2736 sms_data->sim_mem_update = TRUE;
2737 tl_find_first (MEM_SM);
2738 }
2739 else
2740 {
2741 /* Nothing to do, indicate success to SAT */
2742 PALLOC (file_update_res, SIM_FILE_UPDATE_RES); /* T_SIM_FILE_UPDATE_RES */
2743 file_update_res->source = SRC_SMS;
2744 file_update_res->fu_rsc = SIM_FU_SUCCESS;
2745 PSENDX (SIM, file_update_res);
2746 }
2747 }
2748 PFREE (file_update_ind);
2749 }
2750
2751 #endif // SIM_TOOLKIT
2752
2753 /*
2754 +--------------------------------------------------------------------+
2755 | PROJECT : GSM-PS (8410) MODULE : SMS_TLF |
2756 | STATE : code ROUTINE : tl_mnsms_cmms_end_ind |
2757 +--------------------------------------------------------------------+
2758
2759 PURPOSE : Function used for sending MNSMS_REPORT_IND.Primitive to ACI
2760 when cmms_mode is eqaul to 1.
2761
2762 */
2763
2764 GLOBAL void tl_mnsms_cmms_end_ind(void)
2765 {
2766 GET_INSTANCE_DATA;
2767 PALLOC (report_ind, MNSMS_REPORT_IND);
2768
2769 TRACE_FUNCTION ("tl_mnsms_cmms_end_ind()");
2770
2771 if(sms_data->cmms_mode EQ CMMS_MODE_ONE)
2772 {
2773 sms_data->cmms_mode = CMMS_MODE_DEF;
2774 report_ind->state = SMS_STATE_READY;
2775 report_ind->v_cmms_mode = TRUE;
2776 report_ind->cmms_mode = sms_data->cmms_mode;
2777 PSENDX (MMI, report_ind);
2778 }
2779 }
2780
2781 #ifdef SIM_PERS_OTA
2782 /*
2783 +--------------------------------------------------------------------+
2784 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2785 | STATE : code ROUTINE : tl_mnsms_OTA_message_res |
2786 +--------------------------------------------------------------------+
2787
2788 PURPOSE : Process the primitive MNSMS_OTA_MESSAGE_RES.
2789
2790 */
2791
2792 GLOBAL void tl_mnsms_OTA_message_res ( T_MNSMS_OTA_MESSAGE_RES *mnsms_OTA_message_res )
2793 {
2794
2795 T_SMS_DATA *sms_data = GET_INSTANCE(0);
2796
2797 TRACE_FUNCTION ("tl_mnsms_OTA_message_res()");
2798
2799 if (sms_data) /*lint !e774 always True*/
2800 {
2801 GET_MT_INSTANCE(sms_data); /* MT operation */
2802
2803 switch (SMS_INST_GET_STATE (STATE_TL))
2804 {
2805 case TL_RECEIVE:
2806 if (sms_timer_check(TR2M))
2807 {
2808 T_TP_DLVR_REP_ACK *rep_ack ;
2809 T_rp_user_data *rp_ud;
2810 MALLOC(rep_ack, sizeof(T_TP_DLVR_REP_ACK));
2811 MALLOC(rp_ud, sizeof(T_rp_user_data));
2812
2813 rep_ack->tp_vt_mti = SMS_VT_DLVR_REP_ACK;
2814 rep_ack->tp_udhi = SMS_UDHI_NOT_INCLUDED;
2815 rep_ack->tp_mti = SMS_DELIVER_REPORT;
2816 rep_ack->v_tp_udh_inc = FALSE;
2817
2818 memcpy(rep_ack->tp_ud.data, mnsms_OTA_message_res->data,mnsms_OTA_message_res->len);
2819
2820 rep_ack->tp_ud.c_data =mnsms_OTA_message_res->len; //No of octets
2821 rep_ack->tp_ud.length = mnsms_OTA_message_res->packedlen; /*Since default alphabet is used as per 23.040 sec. 9.2.3.16
2822 the length contains no of septets of data returned */
2823
2824 rep_ack->tp_ext = SMS_EXT_NOT_INCLUDED;
2825 rep_ack->v_tp_ud = TRUE;
2826 rep_ack->tp_udl_p = SMS_UD_INCLUDED;
2827 rep_ack->tp_dcs = mnsms_OTA_message_res->tp_dcs;
2828 rep_ack->v_tp_dcs = TRUE;
2829 rep_ack->tp_dcs_p = SMS_DCS_INCLUDED;
2830 rep_ack->tp_pid = mnsms_OTA_message_res->tp_pid;
2831 rep_ack->v_tp_pid = TRUE;
2832 rep_ack->tp_pid_p = SMS_PID_INCLUDED;
2833 rp_ud->tpdu.o_tpdu = 0;
2834 rp_ud->tpdu.l_tpdu = TPDU_BIT_LEN;
2835 rp_ud->v_tpdu = (ccd_codeMsg (CCDENT_SMS, UPLINK,
2836 (T_MSGBUF *)&rp_ud->tpdu,
2837 (UBYTE *)rep_ack,
2838 SMS_VT_DLVR_REP_ACK) EQ ccdOK);
2839 rp_ud->tp_mti = SMS_DELIVER_REPORT;
2840
2841 MFREE (rep_ack);
2842 rl_report_req_ack (rp_ud);
2843 MFREE (rp_ud);
2844 SMS_INST_SET_STATE (STATE_TL, TL_IDLE);
2845 }
2846 else
2847 {
2848 /*TR2M TIM EXPIRE -ACI NOT RESPONDED WITHIN TR2M */
2849 }
2850 break;
2851
2852 default:
2853 /* INVALID SMS TL STATE IN MNSMS_OTA_MESSAGE_RES */
2854 break;
2855
2856 }
2857 }
2858 PFREE (mnsms_OTA_message_res);
2859
2860 }
2861 #endif /* End OTA */
2862 /*
2863 +--------------------------------------------------------------------+
2864 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2865 | STATE : code ROUTINE : tl_mnsms_retrans_req |
2866 +--------------------------------------------------------------------+
2867
2868 PURPOSE : Handles the primitive MNSMS_RETRANS_REQ. This will support user
2869 requested retransmission of the last failed message as per
2870 23.040 R99 Section 9.2.3.6.
2871 */
2872 #ifdef REL99
2873 GLOBAL void tl_mnsms_retrans_req (T_MNSMS_RETRANS_REQ *mnsms_retrans_req)
2874 {
2875 GET_INSTANCE_DATA;
2876
2877 TRACE_FUNCTION ("tl_mnsms_retrans_req()");
2878
2879 switch (SMS_INST_GET_STATE (STATE_TL))
2880 {
2881 case TL_SEND_CONTD:
2882 /*
2883 * stop timer TLCT
2884 */
2885 sms_timer_stop(TLCT);
2886 /*FALLTHROUGH*/ /*lint -fallthrough*/
2887 case TL_IDLE:
2888 if (sms_timer_check(TRAM))
2889 {
2890 /*
2891 * MNSMS_SUBMIT_CNF
2892 */
2893 tl_mnsms_retrans_cnf (SMS_SEL_MEM(sms_data), SMS_SEL_REC(sms_data),
2894 NOT_PRESENT_8BIT, SMS_CAUSE_ENTITY_BUSY, NULL);
2895 break;
2896 }
2897
2898 /* Check if MO message is present(stored CPDU data available?) */
2899 if (SMS_DATA_REQ(sms_data) NEQ NULL)
2900 {
2901 if(mnsms_retrans_req->auto_rep_flag EQ AUTO_REP_FLAG_ENABLED)
2902 {
2903 SMS_INST.tl_retx = 0;
2904 }
2905 else
2906 {
2907 /* Set to the max value so that retransmission will not be done */
2908 SMS_INST.tl_retx = TL_MAX_RETANS;
2909 }
2910
2911 SMS_INST_SET_STATE (STATE_TL, TL_SEND);
2912
2913 /* Restore the record number and storage type */
2914 SMS_SEL_REC(sms_data) = SMS_INST.failed_msg_rec_num;
2915 SMS_SEL_MEM(sms_data) = SMS_INST.failed_msg_mem;
2916 SMS_INST.failed_msg_retx = TRUE;
2917
2918 /*
2919 * TL state transition TL_ESTABLISH
2920 * EST state transition EST_SEND
2921 */
2922 SMS_INST_SET_STATE (STATE_TL, TL_ESTABLISH);
2923 SET_STATE (STATE_EST, EST_RTX);
2924 /*
2925 * establish connection
2926 */
2927 tl_establish_connection(FALSE);
2928 }
2929 else
2930 {
2931 tl_mnsms_retrans_cnf (SMS_SEL_MEM(sms_data),SMS_SEL_REC(sms_data),
2932 SMS_TP_REF_RET(sms_data),
2933 SMS_CAUSE_FAILED_MSG_NOT_FOUND, NULL);
2934 }
2935 break;
2936
2937 default:
2938 tl_mnsms_retrans_cnf (SMS_SEL_MEM(sms_data),SMS_SEL_REC(sms_data),
2939 SMS_TP_REF_RET(sms_data),
2940 SMS_CAUSE_ENTITY_BUSY, NULL);
2941 break;
2942 }
2943
2944 PFREE(mnsms_retrans_req);
2945
2946 return;
2947 }
2948 /*
2949 +--------------------------------------------------------------------+
2950 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2951 | STATE : code ROUTINE : tl_mnsms_retrans_cnf |
2952 +--------------------------------------------------------------------+
2953
2954 PURPOSE : Generate a response to the primitive MNSMS_RETRANS_REQ.
2955 */
2956
2957 GLOBAL void tl_mnsms_retrans_cnf ( UBYTE mem_type,
2958 UBYTE record,
2959 UBYTE tp_mr,
2960 USHORT cause,
2961 T_sms_sdu *sms_sdu )
2962 {
2963 TRACE_FUNCTION ("tl_mnsms_retrans_cnf()");
2964 {
2965 PALLOC (retrans_cnf, MNSMS_RETRANS_CNF);
2966 retrans_cnf->mem_type = mem_type;
2967 retrans_cnf->rec_num = record;
2968 retrans_cnf->tp_mr = tp_mr;
2969 retrans_cnf->cause = cause;
2970
2971 if (sms_sdu NEQ NULL)
2972 {
2973 memcpy (&retrans_cnf->sms_sdu, sms_sdu, sizeof (T_sms_sdu));
2974 }
2975 else
2976 {
2977 memset (&retrans_cnf->sms_sdu, 0, sizeof (T_sms_sdu));
2978 }
2979
2980 PSENDX (MMI, retrans_cnf);
2981 }
2982 }
2983
2984 /*
2985 +--------------------------------------------------------------------+
2986 | PROJECT : GSM-PS (8410) MODULE : SMS_TLP |
2987 | STATE : code ROUTINE : tl_mnsms_send_prog_ind |
2988 +--------------------------------------------------------------------+
2989
2990 PURPOSE : Send the primitive MNSMS_SEND_PROG_IND.
2991 */
2992 GLOBAL void tl_mnsms_send_prog_ind (void)
2993 {
2994 GET_INSTANCE_DATA;
2995 TRACE_FUNCTION ("tl_mnsms_send_prog_ind ()");
2996 {
2997 PALLOC (send_prog_ind, MNSMS_SEND_PROG_IND);
2998 send_prog_ind->resend_count = sms_data->data[INST_MO].tl_retx;
2999 send_prog_ind->max_retrans = TL_MAX_RETANS;
3000 PSENDX (MMI, send_prog_ind);
3001 }
3002 }
3003 #endif /* REL99 */
3004
3005 #endif