comparison g23m/condat/ms/src/aci/cmh_smsf.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-PS (6147)
4 | Modul : CMH_SMSF
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This module defines the functions used by the command
18 | handler for the short message service.
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef CMH_SMSF_C
23 #define CMH_SMSF_C
24 #endif
25
26 #include "aci_all.h"
27 /*==== INCLUDES ===================================================*/
28 #include "aci_cmh.h"
29 #include "ati_cmd.h"
30 #include "aci_cmd.h"
31
32 #ifdef FAX_AND_DATA
33 #include "aci_fd.h"
34 #endif /* of #ifdef FAX_AND_DATA */
35
36 #include "aci.h"
37 #include "aci_lst.h"
38 #include "aci_mem.h"
39 #include "psa.h"
40 #include "psa_cc.h"
41 #ifdef SIM_TOOLKIT
42 #include "psa_sat.h"
43 #endif
44 #include "psa_sms.h"
45 #include "psa_sim.h"
46 #include "psa_mmi.h"
47 #include "psa_util.h"
48 #include "phb.h"
49 #include "cmh.h"
50 #include "cmh_sms.h"
51 #include "pcm.h"
52
53 #include "aci_lst.h"
54
55 #if (defined (MFW) AND !defined (FF_MMI_RIV)) OR defined (_CONC_TESTING_)
56 #include "conc_sms.h"
57 #endif /* ##if (defined (MFW) AND !defined (FF_MMI_RIV)) OR defined (_CONC_TESTING_)*/
58
59
60 #ifdef UART
61 #include "dti_conn_mng.h"
62 #endif
63
64 #include "cmh_sim.h"
65 #ifndef _SIMULATION_
66
67 /* temporary solution to get ffs.h included without GPRS to be set ! */
68 #ifdef GPRS
69 #include "ffs/ffs.h"
70 #else
71 #include "ffs/ffs.h"
72 #undef GPRS
73 #endif /* GPRS */
74
75 #include "ffs_coat.h"
76
77 #endif /* !_SIMULATION_ */
78
79 #ifdef FF_CPHS
80 #include "cphs.h"
81 #endif /* FF_CPHS */
82
83 /*==== CONSTANTS ==================================================*/
84
85 #define SMS_CMH_YEAR_MAX (99) /* maximum value for year in */
86 /* absolute validity period */
87 #define SMS_CMH_YEAR_MIN (0) /* minimum value for year in */
88 /* absolute validity period */
89 #define SMS_CMH_MONTH_MAX (12) /* maximum value for month in */
90 /* absolute validity period */
91 #define SMS_CMH_MONTH_MIN (1) /* minimum value for month in */
92 /* absolute validity period */
93 #define SMS_CMH_DAY_MAX (31) /* maximum value for day in */
94 /* absolute validity period */
95 #define SMS_CMH_DAY_MIN (1) /* minimum value for day in */
96 /* absolute validity period */
97 #define SMS_CMH_HOUR_MAX (23) /* maximum value for hour in */
98 /* absolute validity period */
99 #define SMS_CMH_HOUR_MIN (0) /* minimum value for hour in */
100 /* absolute validity period */
101 #define SMS_CMH_MINUTE_MAX (59) /* maximum value for minute in */
102 /* absolute validity period */
103 #define SMS_CMH_MINUTE_MIN (0) /* minimum value for minute in */
104 /* absolute validity period */
105 #define SMS_CMH_SECOND_MAX (59) /* maximum value for second in */
106 /* absolute validity period */
107 #define SMS_CMH_SECOND_MIN (0) /* minimum value for second in */
108 /* absolute validity period */
109
110 #define SMS_CMH_TZ_MAX (47) /* maximum value for a time */
111 /* zone in absolute validity */
112 /* period */
113 #define SMS_CMH_TZ_MIN (-47) /* minimum value for a time */
114 /* zone in absolute validity */
115 /* period */
116
117
118 /* macro for converting a two digit BCD into an UBYTE */
119 #define BCD2UBYTE(bcd) (UBYTE)(10 * bcd[0] + bcd[1])
120
121 /* macro for testing whether any digit of a two digit */
122 /* BCD lies outside of a predefined value range */
123 #define NOTBCD(bcd) (bcd[0] > 9 OR\
124 bcd[1] > 9 )
125
126
127 #define L_MAX_UD 140
128 #define L_MAX_UD_CONC 134
129
130 /*==== TYPES ======================================================*/
131
132 /*==== EXPORT =====================================================*/
133 EXTERN T_ACI_LIST *set_prm_list;
134
135 /*==== VARIABLES ==================================================*/
136
137 const char * const ffs_smsprfl_fname[] = { FFS_SMSPRFL_FNAME01,
138 FFS_SMSPRFL_FNAME02,
139 FFS_SMSPRFL_FNAME03,
140 FFS_SMSPRFL_FNAME04 };
141
142 /*==== FUNCTIONS ==================================================*/
143
144 /*
145 +--------------------------------------------------------------------+
146 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
147 | STATE : code ROUTINE : aci_encodeVpenh |
148 +--------------------------------------------------------------------+
149
150 PURPOSE : This function encodes a given T_ACI_VP_ENH type to a
151 string.
152 */
153 GLOBAL void aci_encodeVpenh ( CHAR* vpenh_str,
154 T_ACI_VP_ENH* vpenh )
155 {
156 UBYTE pos;
157
158 /* functionality indicator */
159 utl_binToHex (&vpenh->func_ind, 1, vpenh_str);
160 pos = 2;
161
162 /* extension octet */
163 if (vpenh->func_ind & TP_VPF_ENH_EXT_BIT_MASK)
164 {
165 utl_binToHex (&vpenh->ext_oct, 1, vpenh_str+pos);
166 pos += 2;
167 }
168
169 /* process validity period values */
170 if ((vpenh->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_REL)
171 {
172 utl_binToHex (&vpenh->val.vpenh_relative, 1, vpenh_str+pos );
173 pos += 2;
174 }
175 else if ((vpenh->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_SEC)
176 {
177 utl_binToHex (&vpenh->val.vpenh_seconds, 1, vpenh_str+pos );
178 pos += 2;
179 }
180 else if ((vpenh->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_HRS)
181 {
182 vpenh_str[pos++] = vpenh->val.vpenh_hours.hour[1] + '0';
183 vpenh_str[pos++] = vpenh->val.vpenh_hours.hour[0] + '0';
184
185 vpenh_str[pos++] = vpenh->val.vpenh_hours.minute[1] + '0';
186 vpenh_str[pos++] = vpenh->val.vpenh_hours.minute[0] + '0';
187
188 vpenh_str[pos++] = vpenh->val.vpenh_hours.second[1] + '0';
189 vpenh_str[pos++] = vpenh->val.vpenh_hours.second[0] + '0';
190 }
191
192 /* fill the rest with zeros */
193 while (pos < 14)
194 {
195 vpenh_str[pos++] = '0';
196 }
197
198 /* string terminator */
199 vpenh_str[pos] = '\0';
200 }
201
202 /*
203 +-------------------------------------------------------------------+
204 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
205 | STATE : code ROUTINE : cmhSMS_getNType |
206 +-------------------------------------------------------------------+
207
208 PURPOSE : This function calculates the 'numbering type' out of the
209 current 'type of numbering'.
210 */
211 GLOBAL UBYTE cmhSMS_getNType ( T_ACI_TOA_TON ton )
212 {
213 switch( ton )
214 {
215 case( TON_International ):
216 case( TON_National ):
217 case( TON_NetSpecific ):
218 case( TON_DedAccess ):
219 case( TON_Alphanumeric ):
220 case( TON_Abbreviated ): return (UBYTE)ton;
221 default: return SMS_TON_UNKNOWN;
222 }
223 }
224
225
226 GLOBAL BOOL cmhSMS_findPrflId ( UBYTE critrerium, void* elem )
227 {
228 T_SMS_SET_PRM *compared = (T_SMS_SET_PRM*)elem;
229 if ( compared->prflId == critrerium )
230 return TRUE;
231 else
232 return FALSE;
233 }
234
235 /*
236 +-------------------------------------------------------------------+
237 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
238 | STATE : code ROUTINE : cmhSMS_getTon |
239 +-------------------------------------------------------------------+
240
241 PURPOSE : This function calculates the 'type of numbering' out of
242 the current 'numbering type'.
243 */
244 GLOBAL T_ACI_TOA_TON cmhSMS_getTon ( UBYTE ntype )
245 {
246 switch( ntype )
247 {
248 case( SMS_TON_UNKNOWN ):
249 case( SMS_TON_INTERNATIONAL ):
250 case( SMS_TON_NATIONAL ):
251 case( SMS_TON_NETWORK_SPEC ):
252 case( SMS_TON_SUBSCRIBER ):
253 case( SMS_TON_ALPHANUMERIC ):
254 case( SMS_TON_ABBREVIATED ): return (T_ACI_TOA_TON)ntype;
255 default: return TON_NotPresent;
256 }
257 }
258
259 /*
260 +-------------------------------------------------------------------+
261 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
262 | STATE : code ROUTINE : cmhSMS_getNPlan |
263 +-------------------------------------------------------------------+
264
265 PURPOSE : This function calculates the 'numbering plan' out of the
266 current 'numbering plan identification'.
267 */
268 GLOBAL UBYTE cmhSMS_getNPlan ( T_ACI_TOA_NPI npi )
269 {
270 switch( npi )
271 {
272 case( NPI_IsdnTelephony ):
273 case( NPI_Data ):
274 case( NPI_Telex ):
275 case( NPI_National ):
276 case( NPI_Private ): return (UBYTE)npi;
277 default: return NPI_Unknown;
278 }
279 }
280
281 /*
282 +-------------------------------------------------------------------+
283 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
284 | STATE : code ROUTINE : cmhSMS_getNpi |
285 +-------------------------------------------------------------------+
286
287 PURPOSE : This function calculates the 'numbering plan
288 identification' out of the current 'numbering plan'.
289 */
290 GLOBAL T_ACI_TOA_NPI cmhSMS_getNpi ( UBYTE nplan )
291 {
292 switch( nplan )
293 {
294 case( SMS_TON_UNKNOWN ):
295 case( SMS_NPI_ISDN ):
296 case( SMS_NPI_X121 ):
297 case( SMS_NPI_F69 ):
298 case( SMS_NPI_NATIONAL ):
299 case( SMS_NPI_PRIVATE ): return (T_ACI_TOA_NPI)nplan;
300 default: return NPI_NotPresent;
301 }
302 }
303
304 /*
305 +-------------------------------------------------------------------+
306 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
307 | STATE : code ROUTINE : cmhSMS_getStatCmh |
308 +-------------------------------------------------------------------+
309
310 PURPOSE : This function converts the message status from
311 PSA type to CMH type.
312 */
313 GLOBAL void cmhSMS_getStatCmh ( UBYTE inStat,
314 T_ACI_SMS_STAT* outStat )
315 {
316 switch( inStat & STAT_MASK )
317 {
318 case( REC_UNREAD ): *outStat = SMS_STAT_RecUnread; break;
319 case( REC_READ ): *outStat = SMS_STAT_RecRead; break;
320 case( STO_UNSENT ): *outStat = SMS_STAT_StoUnsent; break;
321 case( STO_SENT ): *outStat = SMS_STAT_StoSent; break;
322 default: *outStat = SMS_STAT_NotPresent;
323 }
324 }
325
326 /*
327 +-------------------------------------------------------------------+
328 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
329 | STATE : code ROUTINE : cmhSMS_getStatPsa |
330 +-------------------------------------------------------------------+
331
332 PURPOSE : This function converts the message status from
333 CMH type to PSA type.
334 */
335 GLOBAL BOOL cmhSMS_getStatPsa ( T_ACI_SMS_STAT inStat,
336 UBYTE* outStat )
337 {
338 switch( inStat )
339 {
340 case( SMS_STAT_RecUnread ): *outStat = REC_UNREAD; break;
341 case( SMS_STAT_RecRead ): *outStat = REC_READ; break;
342 case( SMS_STAT_StoUnsent ): *outStat = STO_UNSENT; break;
343 case( SMS_STAT_StoSent ): *outStat = STO_SENT; break;
344 default : return (FALSE);
345 }
346
347 return ( TRUE );
348 }
349
350 /*
351 +-------------------------------------------------------------------+
352 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
353 | STATE : code ROUTINE : cmhSMS_isVpabsVld |
354 +-------------------------------------------------------------------+
355
356 PURPOSE : This function is used to process whether the given
357 absolute validity period is valid.
358
359 Note: This function checks whether every individual
360 time value is within a valid range. It does not
361 check whether the whole expression is valid.
362 */
363 GLOBAL BOOL cmhSMS_isVpabsVld ( T_ACI_VP_ABS* vpabs )
364 {
365 if ( BCD2UBYTE ( vpabs -> year ) > SMS_CMH_YEAR_MAX OR
366 BCD2UBYTE ( vpabs -> month ) < SMS_CMH_MONTH_MIN OR
367 BCD2UBYTE ( vpabs -> month ) > SMS_CMH_MONTH_MAX OR
368 BCD2UBYTE ( vpabs -> day ) < SMS_CMH_DAY_MIN OR
369 BCD2UBYTE ( vpabs -> day ) > SMS_CMH_DAY_MAX OR
370 BCD2UBYTE ( vpabs -> hour ) > SMS_CMH_HOUR_MAX OR
371 BCD2UBYTE ( vpabs -> minute ) > SMS_CMH_MINUTE_MAX OR
372 BCD2UBYTE ( vpabs -> second ) > SMS_CMH_SECOND_MAX OR
373 vpabs -> timezone < SMS_CMH_TZ_MIN OR
374 vpabs -> timezone > SMS_CMH_TZ_MAX OR
375 NOTBCD ( vpabs -> year ) OR
376 NOTBCD ( vpabs -> month ) OR
377 NOTBCD ( vpabs -> day ) OR
378 NOTBCD ( vpabs -> hour ) OR
379 NOTBCD ( vpabs -> minute ) OR
380 NOTBCD ( vpabs -> second ) )
381
382 return ( FALSE );
383
384 return ( TRUE );
385 }
386
387 /*
388 +-------------------------------------------------------------------+
389 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
390 | STATE : code ROUTINE : cmhSMS_isVpenhVld |
391 +-------------------------------------------------------------------+
392
393 PURPOSE : This function is used to process whether the given
394 enhanced validity period is valid.
395
396 Note: This function checks whether every individual
397 time value is within a valid range. It does not
398 check whether the whole expression is valid.
399 */
400 GLOBAL BOOL cmhSMS_isVpenhVld ( T_ACI_VP_ENH* vpenh )
401 {
402 if ((vpenh->func_ind & TP_VPF_ENH_FORMAT_MASK) > TP_VPF_ENH_HRS)
403 {
404 return FALSE;
405 }
406
407 if ((vpenh->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_HRS)
408 {
409 if ( BCD2UBYTE ( vpenh->val.vpenh_hours.minute ) > SMS_CMH_MINUTE_MAX OR
410 BCD2UBYTE ( vpenh->val.vpenh_hours.second ) > SMS_CMH_SECOND_MAX OR
411 NOTBCD ( vpenh->val.vpenh_hours.hour ) OR
412 NOTBCD ( vpenh->val.vpenh_hours.minute ) OR
413 NOTBCD ( vpenh->val.vpenh_hours.second ) )
414 {
415 return ( FALSE );
416 }
417 }
418
419 return ( TRUE );
420 }
421
422 /*
423 +-------------------------------------------------------------------+
424 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
425 | STATE : code ROUTINE : cmhSMS_setVpabsPsa |
426 +-------------------------------------------------------------------+
427
428 PURPOSE : This function is used to copy the elements of the
429 absolute validity period structure of the ACI to the
430 corresponding structure of the PSA.
431
432 Note: Copying of the structure elements might be
433 dangerous when array size of time elements differ
434 from MAX_VP_ABS_DIGIT due to changes in PSA
435 declaration.
436 */
437 GLOBAL void cmhSMS_setVpabsPsa ( T_tp_vp_abs* psaVp,
438 T_ACI_VP_ABS* cmhVp )
439 {
440 USHORT i; /* used for counting */
441 BOOL isNegative = ( cmhVp->timezone & 0x8000 );
442 SHORT tz = ( UBYTE ) cmhVp->timezone;
443
444 for (i = 0; i < MAX_VP_ABS_DIGITS; i++)
445 {
446 psaVp -> year [i] = cmhVp -> year [i];
447 psaVp -> month [i] = cmhVp -> month [i];
448 psaVp -> day [i] = cmhVp -> day [i];
449 psaVp -> hour [i] = cmhVp -> hour [i];
450 psaVp -> minute[i] = cmhVp -> minute[i];
451 psaVp -> second[i] = cmhVp -> second[i];
452 }
453
454 if ( isNegative )
455 {
456 tz = -tz;
457 psaVp -> tz_sign = 1;
458 }
459 else
460 {
461 psaVp -> tz_sign = 0;
462 }
463
464 psaVp -> tz_lsb = tz & 0x000F;
465 psaVp -> tz_msb = tz & 0x00F0;
466 }
467
468 /*
469 +-------------------------------------------------------------------+
470 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
471 | STATE : code ROUTINE : cmhSMS_setVpenhPsa |
472 +-------------------------------------------------------------------+
473
474 PURPOSE : This function is used to copy the elements of the
475 enhanced validity period structure of the ACI to the
476 corresponding structure of the PSA.
477 */
478 GLOBAL void cmhSMS_setVpenhPsa ( T_tp_vp_enh* psaVp,
479 T_ACI_VP_ENH* cmhVp )
480 {
481 memset(psaVp, 0, sizeof(T_tp_vp_enh));
482
483 if (cmhVp->func_ind & TP_VPF_ENH_EXT_BIT_MASK)
484 {
485 psaVp->tp_ext = SMS_EXT_INCLUDED;
486 psaVp->v_tp_rsrvd = 1;
487 psaVp->tp_rsrvd = cmhVp->ext_oct;
488 }
489
490 if (cmhVp->func_ind & TP_VPF_ENH_SINGLE_SHOT_MASK)
491 {
492 psaVp->tp_ss = SMS_SS_SET;
493 }
494
495 if ((cmhVp->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_NOT_PRESENT)
496 {
497 psaVp->tvpf = SMS_TVPF_NOT_PRESENT;
498 }
499 else if ((cmhVp->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_REL)
500 {
501 psaVp->tvpf = SMS_TVPF_RELATIVE;
502 psaVp->v_tp_vp_rel = 1;
503 psaVp->tp_vp_rel = cmhVp->val.vpenh_relative;
504 }
505 else if ((cmhVp->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_SEC)
506 {
507 psaVp->tvpf = SMS_TVPF_SECONDS;
508 psaVp->v_tp_vp_sec = 1;
509 psaVp->tp_vp_sec = cmhVp->val.vpenh_seconds;
510 }
511 else if ((cmhVp->func_ind & TP_VPF_ENH_FORMAT_MASK) EQ TP_VPF_ENH_HRS)
512 {
513 psaVp->tvpf = SMS_TVPF_HOURS;
514 psaVp->v_hour = 1;
515 psaVp->hour[0] = cmhVp->val.vpenh_hours.hour[0];
516 psaVp->hour[1] = cmhVp->val.vpenh_hours.hour[1];
517 psaVp->v_minute = 1;
518 psaVp->minute[0] = cmhVp->val.vpenh_hours.minute[0];
519 psaVp->minute[1] = cmhVp->val.vpenh_hours.minute[1];
520 psaVp->v_second = 1;
521 psaVp->second[0] = cmhVp->val.vpenh_hours.second[0];
522 psaVp->second[1] = cmhVp->val.vpenh_hours.second[1];
523 }
524 else
525 {
526 TRACE_EVENT("[ERR] cmhSMS_setVpenhPsa: wrong type of validity period format");
527 }
528 }
529
530 /*
531 +-------------------------------------------------------------------+
532 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
533 | STATE : code ROUTINE : cmhSMS_setVpabsCmh |
534 +-------------------------------------------------------------------+
535
536 PURPOSE : This function is used to copy the elements of the
537 absolute validity period structure of the PSA to the
538 corresponding structure of the ACI.
539
540 Note: Copying of the structure elements might be
541 dangerous when array size of time elements differ
542 from MAX_VP_ABS_DIGIT due to changes in PSA
543 declaration.
544 */
545 GLOBAL void cmhSMS_setVpabsCmh ( T_ACI_VP_ABS* cmhVp,
546 T_tp_vp_abs* psaVp )
547 {
548 USHORT i; /* used for counting */
549 SHORT tz;
550
551 for (i = 0; i < MAX_VP_ABS_DIGITS; i++)
552 {
553 cmhVp -> year [i] = psaVp -> year [i];
554 cmhVp -> month [i] = psaVp -> month [i];
555 cmhVp -> day [i] = psaVp -> day [i];
556 cmhVp -> hour [i] = psaVp -> hour [i];
557 cmhVp -> minute[i] = psaVp -> minute[i];
558 cmhVp -> second[i] = psaVp -> second[i];
559 }
560
561 tz = ((psaVp->tz_msb & 0x07) * 10) + psaVp->tz_lsb; /* BCD */
562
563 if (psaVp->tz_sign)
564 cmhVp -> timezone = -tz;
565 else
566 cmhVp -> timezone = tz;
567 }
568
569 /*
570 +-------------------------------------------------------------------+
571 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
572 | STATE : code ROUTINE : cmhSMS_setVpenhCmh |
573 +-------------------------------------------------------------------+
574
575 PURPOSE : This function is used to copy the elements of the
576 enhanced validity period structure of the PSA to the
577 corresponding structure of the ACI.
578
579 */
580 GLOBAL void cmhSMS_setVpenhCmh ( T_ACI_VP_ENH* cmhVp,
581 T_tp_vp_enh* psaVp )
582 {
583 memset(cmhVp, 0, sizeof(T_ACI_VP_ENH));
584
585 cmhVp->func_ind = psaVp->tvpf;
586
587 if ((psaVp->tp_ext EQ SMS_EXT_INCLUDED) AND (psaVp->v_tp_rsrvd))
588 {
589 cmhVp->func_ind |= TP_VPF_ENH_EXT_BIT_MASK;
590 cmhVp->ext_oct = psaVp->tp_rsrvd;
591 }
592
593 if (psaVp->tp_ss EQ SMS_SS_SET)
594 {
595 cmhVp->func_ind |= TP_VPF_ENH_SINGLE_SHOT_MASK;
596 }
597
598 if (psaVp->tvpf EQ SMS_TVPF_NOT_PRESENT)
599 {
600 /* do nothing */
601 }
602 else if ((psaVp->tvpf EQ SMS_TVPF_RELATIVE) AND (psaVp->v_tp_vp_rel))
603 {
604 cmhVp->val.vpenh_relative = psaVp->tp_vp_rel;
605 }
606 else if ((psaVp->tvpf EQ SMS_TVPF_SECONDS) AND (psaVp->v_tp_vp_sec))
607 {
608 cmhVp->val.vpenh_seconds = psaVp->tp_vp_sec;
609 }
610 else if (psaVp->tvpf EQ SMS_TVPF_HOURS)
611 {
612 if (psaVp->v_hour)
613 {
614 cmhVp->val.vpenh_hours.hour[0] = psaVp->hour[0];
615 cmhVp->val.vpenh_hours.hour[1] = psaVp->hour[1];
616 }
617 if (psaVp->v_minute)
618 {
619 cmhVp->val.vpenh_hours.minute[0] = psaVp->minute[0];
620 cmhVp->val.vpenh_hours.minute[1] = psaVp->minute[1];
621 }
622 if (psaVp->v_second)
623 {
624 cmhVp->val.vpenh_hours.second[0] = psaVp->second[0];
625 cmhVp->val.vpenh_hours.second[1] = psaVp->second[1];
626 }
627 }
628 else
629 {
630 TRACE_EVENT("[ERR] cmhSMS_setVpenhCmh: wrong type of validity period format");
631 }
632 }
633
634 /*
635 +--------------------------------------------------------------------+
636 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
637 | STATE : code ROUTINE : cmhSMS_getAdrStr |
638 +--------------------------------------------------------------------+
639
640 PURPOSE : This function is used to convert the service center
641 address in BCD to the service center address as a string.
642 */
643 GLOBAL UBYTE cmhSMS_getAdrStr ( CHAR* pStr,
644 UBYTE maxIdx,
645 UBYTE* pBcd,
646 UBYTE numDigits )
647 {
648 UBYTE bcdIdx;
649 UBYTE strIdx = 0;
650
651 memset(pStr, 0x00, maxIdx);
652
653 for(bcdIdx = 0; bcdIdx < numDigits AND strIdx < maxIdx; bcdIdx++)
654 {
655 switch (pBcd[bcdIdx])
656 {
657 case 0:
658 case 1:
659 case 2:
660 case 3:
661 case 4:
662 case 5:
663 case 6:
664 case 7:
665 case 8:
666 case 9:
667 pStr[strIdx++] = pBcd[bcdIdx] + '0';
668 break;
669
670 case BCD_ASTSK:
671 pStr[strIdx++] = '*';
672 break;
673
674 case BCD_PND:
675 pStr[strIdx++] = '#';
676 break;
677
678 case BCD_A:
679 pStr[strIdx++] = 'A';
680 break;
681
682 case BCD_B:
683 pStr[strIdx++] = 'B';
684 break;
685
686 case BCD_C:
687 pStr[strIdx++] = 'C';
688 break;
689 }
690 }
691
692 pStr[strIdx] = '\0';
693
694 return ( strIdx );
695 }
696
697 /*
698 +--------------------------------------------------------------------+
699 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
700 | STATE : code ROUTINE : cmhSMS_getAdrBcd |
701 +--------------------------------------------------------------------+
702
703 PURPOSE : This function is used to convert the service center
704 address as a string to the service center address in BCD.
705 */
706 GLOBAL void cmhSMS_getAdrBcd ( UBYTE* pBcd,
707 UBYTE* pNumDigits,
708 UBYTE maxDigits,
709 CHAR* pStr )
710 {
711 UBYTE bcdIdx = 0;
712 UBYTE strIdx;
713
714 for(strIdx = 0; bcdIdx < maxDigits AND pStr[strIdx] NEQ '\0'; strIdx++)
715 {
716 switch (pStr[strIdx])
717 {
718 case '0':
719 case '1':
720 case '2':
721 case '3':
722 case '4':
723 case '5':
724 case '6':
725 case '7':
726 case '8':
727 case '9':
728 pBcd[bcdIdx++] = pStr[strIdx] - '0';
729 break;
730
731 case '*':
732 pBcd[bcdIdx++] = BCD_ASTSK;
733 break;
734
735 case '#':
736 pBcd[bcdIdx++] = BCD_PND;
737 break;
738
739 case 'A':
740 pBcd[bcdIdx++] = BCD_A;
741 break;
742
743 case 'B':
744 pBcd[bcdIdx++] = BCD_B;
745 break;
746
747 case 'C':
748 pBcd[bcdIdx++] = BCD_C;
749 break;
750 }
751 }
752
753 *pNumDigits = bcdIdx;
754 }
755
756 /*
757 +-------------------------------------------------------------------+
758 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
759 | STATE : code ROUTINE : cmhSMS_getMemCmh |
760 +-------------------------------------------------------------------+
761
762 PURPOSE : This function converts the preferred memory from
763 PSA type to CMH type.
764 */
765 GLOBAL void cmhSMS_getMemCmh ( UBYTE inMem, T_ACI_SMS_STOR* outMem )
766 {
767 switch( inMem )
768 {
769 case( MEM_ME ): *outMem = SMS_STOR_Me; break;
770 case( MEM_SM ): *outMem = SMS_STOR_Sm; break;
771 }
772 }
773
774 /*
775 +-------------------------------------------------------------------+
776 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
777 | STATE : code ROUTINE : cmhSMS_getMemPsa |
778 +-------------------------------------------------------------------+
779
780 PURPOSE : This function converts the preferred memory from
781 CMH type to PSA type.
782
783 returns: TRUE if conversion was successfull,
784 otherwise FALSE
785 */
786 GLOBAL BOOL cmhSMS_getMemPsa ( T_ACI_SMS_STOR inMem, UBYTE* outMem )
787 {
788 switch( inMem )
789 {
790 case( SMS_STOR_Me ): *outMem = MEM_ME; break;
791 case( SMS_STOR_Sm ): *outMem = MEM_SM; break;
792 default : return ( FALSE );
793 }
794
795 return ( TRUE );
796 }
797
798 /*
799 +--------------------------------------------------------------------+
800 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
801 | STATE : code ROUTINE : cmhSMS_getAlphabetPp |
802 +--------------------------------------------------------------------+
803
804 PURPOSE : This function is used to extract the used alphabet out
805 of the data coding scheme for point-to-point SMS.
806 */
807 GLOBAL UBYTE cmhSMS_getAlphabetPp ( UBYTE dcs )
808 {
809 UBYTE alphabet = 0; /* means 7 bit default alphabet */
810
811 switch (dcs & 0xF0)
812 {
813 case( 0x30 ):
814 case( 0x20 ):
815 alphabet = 0x01; /* compressed, counts as 8 bit data */
816 break;
817 case( 0x10 ):
818 case( 0x00 ):
819 alphabet = (dcs & 0x0C) >> 2;
820 if (alphabet EQ 3)
821 alphabet = 0; /* reserved coding */
822 break;
823 case( 0xE0 ):
824 alphabet = 0x02; /* UCS2 */
825 break;
826 case( 0xF0 ):
827 alphabet = (dcs & 0x04) >> 2;
828 break;
829 }
830
831 return alphabet;
832 }
833
834 /*
835 +-------------------------------------------------------------------+
836 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
837 | STATE : code ROUTINE : cmhSMS_expdSmsPp |
838 +-------------------------------------------------------------------+
839
840 PURPOSE : This function expands a point-to-point SMS from
841 7 to 8 bit.
842 */
843 GLOBAL void cmhSMS_expdSmsPp ( UBYTE byte_offset,
844 UBYTE dcs,
845 UBYTE* source,
846 UBYTE source_len,
847 UBYTE* dest,
848 UBYTE* dest_len )
849 {
850 UBYTE alphabet;
851 UBYTE bit_offset = 0;
852
853 TRACE_FUNCTION ("cmhSMS_expdSmsPp ()");
854
855
856 alphabet = cmhSMS_getAlphabetPp ( dcs );
857
858 switch (alphabet)
859 {
860 case( 0 ): /* 7 bit alphabet */
861
862 if ( byte_offset % 7 NEQ 0 )
863 {
864 bit_offset = 7 - ((byte_offset*8) % 7);
865 }
866
867 *dest_len = source_len - ((byte_offset*8+6)/7); /* adjust byte_offset to septets */
868
869 /* In 7-Bit mode we get number of septets but we need octets */
870 source_len = (source_len*7+7)/8; /* round up to next octet*/
871 source_len -= byte_offset;
872
873 utl_cvt7To8 ( source, source_len, dest, bit_offset);
874
875
876 break;
877
878 default: /* 8 bit alphabet, UCS2, reserved */
879
880 *dest_len = source_len-byte_offset;
881 memcpy ( (CHAR*) dest, (CHAR*)source, *dest_len );
882 break;
883 }
884 }
885
886 /*
887 +-------------------------------------------------------------------+
888 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
889 | STATE : code ROUTINE : cmhSMS_rdcSmsPp |
890 +-------------------------------------------------------------------+
891
892 PURPOSE : This function reduces a point-to-point SMS from
893 8 to 7 bit.
894 */
895 GLOBAL void cmhSMS_rdcSmsPp ( UBYTE byte_offset,
896 UBYTE dcs,
897 UBYTE* source,
898 UBYTE source_len,
899 UBYTE* dest,
900 UBYTE* dest_len )
901 {
902 UBYTE data_len;
903 UBYTE alphabet;
904 UBYTE bit_offset = 0;
905
906 TRACE_FUNCTION ("cmhSMS_rdcSmsPp ()");
907
908 if (source_len EQ 0)
909 {
910 *dest_len = source_len;
911 return;
912 }
913
914 alphabet = cmhSMS_getAlphabetPp ( dcs );
915
916 switch (alphabet)
917 {
918 case( 0 ): /* 7 bit alphabet */
919
920 if ( byte_offset % 7 NEQ 0 )
921 {
922 bit_offset = 7 - ((byte_offset*8) % 7);
923 }
924
925 data_len = MINIMUM (source_len, (SMS_MSG_LEN * 8) / 7);
926
927 data_len = utl_cvt8To7 ( source, data_len, dest, bit_offset );
928 break;
929
930 default: /* 8 bit alphabet, UCS2, reserved */
931 data_len = MINIMUM ( source_len, SMS_MSG_LEN );
932
933 memcpy ( ( CHAR * ) dest, ( CHAR * ) source, data_len );
934 break;
935 }
936
937 *dest_len = data_len;
938 }
939
940 /*
941 +--------------------------------------------------------------------+
942 | PROJECT : GSM-PS (6147) MODULE : CMF_SMSF |
943 | STATE : code ROUTINE : cmhSMS_getAlphabetCb |
944 +--------------------------------------------------------------------+
945
946 PURPOSE : This function is used to extract the used alphabet out
947 of the data coding scheme for cell broadcast SMS.
948 */
949 GLOBAL UBYTE cmhSMS_getAlphabetCb ( UBYTE dcs )
950 {
951 UBYTE alphabet = 0; /* means 7 bit default alphabet */
952
953 switch (dcs & 0xF0)
954 {
955 case( 0x10 ):
956 if (dcs EQ 0x11)
957 alphabet = 2;
958 break;
959
960 case( 0x70 ):
961 case( 0x60 ):
962 case( 0x50 ):
963 case( 0x40 ):
964 alphabet = (dcs & 0x0C) >> 2;
965 /* According to 03.38, "Any reserved codings shall be assumed
966 * to be the GSM 7 bit default alphabet by a receiving entity".
967 */
968 if (alphabet EQ 3)
969 alphabet = 0;
970 break;
971
972 case( 0xF0 ):
973 alphabet = (dcs & 0x04) >> 2;
974 break;
975 }
976
977 return alphabet;
978 }
979
980 /*
981 +--------------------------------------------------------------------+
982 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
983 | STATE : code ROUTINE : cmhSMS_expdSmsCb |
984 +--------------------------------------------------------------------+
985
986 PURPOSE : This function expands a cell broadcast SMS from
987 7 to 8 bit.
988 */
989 GLOBAL void cmhSMS_expdSmsCb ( UBYTE dcs,
990 UBYTE *source,
991 UBYTE source_len,
992 UBYTE *dest,
993 UBYTE *dest_len )
994 {
995 UBYTE alphabet;
996
997 TRACE_FUNCTION ("cmhSMS_expdSmsCb()");
998
999 alphabet = cmhSMS_getAlphabetCb ( dcs );
1000
1001 switch (alphabet)
1002 {
1003 case( 0 ): /* 7 bit alphabet */
1004 /* PATCH Add bit_offset parameter to function cvt7To8 */
1005 /* utl_cvt7To8 ( source, source_len, dest ); */
1006 utl_cvt7To8 ( source, source_len, dest, 0);
1007 /* PATCH END */
1008
1009 *dest_len = ( source_len * 8 ) / 7;
1010 break;
1011
1012 default: /* 8 bit alphabet, UCS2, reserved */
1013 memcpy ( ( CHAR * ) dest, ( CHAR * ) source, source_len );
1014
1015 *dest_len = source_len;
1016 break;
1017 }
1018 }
1019
1020 /*
1021 +--------------------------------------------------------------------+
1022 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1023 | STATE : code ROUTINE : cmhSMS_setToaDef |
1024 +--------------------------------------------------------------------+
1025
1026 PURPOSE : This function sets the type of address to default values
1027 (when the first character of address is '+' or the first
1028 two characters are '0' default is 145 otherwise default
1029 is 129)
1030 */
1031 GLOBAL CHAR* cmhSMS_setToaDef ( CHAR* number,
1032 UBYTE* ntype,
1033 UBYTE* nplan )
1034 {
1035 *nplan = SMS_NPI_ISDN;
1036
1037 if ( *number EQ '+' )
1038 {
1039 *ntype = SMS_TON_INTERNATIONAL;
1040 return number+1;
1041 }
1042 else
1043 {
1044 *ntype = SMS_TON_UNKNOWN;
1045 return number;
1046 }
1047 }
1048
1049 /*
1050 +--------------------------------------------------------------------+
1051 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1052 | STATE : code ROUTINE : cmhSMS_setTimezone |
1053 +--------------------------------------------------------------------+
1054
1055 PURPOSE : Codes the timezone format used in entity SMS.
1056
1057 */
1058 GLOBAL UBYTE cmhSMS_setTimezone (SHORT timezone)
1059 {
1060 UBYTE local_tz = ( UBYTE ) timezone;
1061 BOOL isNegative = ( local_tz & 0x80 );
1062
1063 if ( isNegative )
1064 local_tz = ~local_tz + 1;
1065
1066 local_tz = ( local_tz / 10 ) + ( ( local_tz % 10 ) << 4 );
1067
1068 return ( ( isNegative ) ? local_tz | 0x08 : local_tz );
1069 }
1070
1071 /*
1072 +--------------------------------------------------------------------+
1073 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1074 | STATE : code ROUTINE : cmhSMS_getTimezone |
1075 +--------------------------------------------------------------------+
1076
1077 PURPOSE : Decodes the timezone format used in entity SMS.
1078
1079 */
1080 GLOBAL SHORT cmhSMS_getTimezone (UBYTE timezone)
1081 {
1082 signed char local_tz;
1083
1084 local_tz = ( timezone & 0x07 ) * 10 + ( ( timezone & 0xF0 ) >> 4 );
1085
1086 return ( SHORT ) (( timezone & 0x08 ) ? -local_tz : local_tz );
1087 }
1088
1089 /*
1090 +--------------------------------------------------------------------+
1091 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1092 | STATE : code ROUTINE : cmhSMS_setStorOcc |
1093 +--------------------------------------------------------------------+
1094
1095 PURPOSE : Fills the T_ACI_SMS_STOR_OCC structure with data from the
1096 shared parameter buffer.
1097
1098 */
1099 GLOBAL void cmhSMS_setStorOcc ( T_ACI_SMS_STOR_OCC* outMem,
1100 UBYTE inMem )
1101 {
1102 cmhSMS_getMemCmh ( inMem, &outMem -> mem );
1103
1104 if ( outMem -> mem EQ SMS_STOR_Sm )
1105 {
1106 outMem -> used = smsShrdPrm.aci_sms_parameter.simUsed;
1107 outMem -> total = smsShrdPrm.aci_sms_parameter.simTotal;
1108 }
1109 else
1110 {
1111 outMem -> used = smsShrdPrm.aci_sms_parameter.meUsed;
1112 outMem -> total = smsShrdPrm.aci_sms_parameter.meTotal;
1113 }
1114 }
1115
1116 /*
1117 +-------------------------------------------------------------------+
1118 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1119 | ROUTINE : cmhSMS_GetCmsFromSim |
1120 +-------------------------------------------------------------------+
1121
1122 PURPOSE : Mapping of SIM error code to ACI error code.
1123
1124 */
1125 GLOBAL T_ACI_CMS_ERR cmhSMS_GetCmsFromSim ( USHORT errCode )
1126 {
1127 switch ( errCode )
1128 {
1129 case SIM_NO_ERROR:
1130 return CMS_ERR_NotPresent;
1131
1132 case SIM_CAUSE_PIN1_EXPECT:
1133 return CMS_ERR_SimPinReq;
1134
1135 case SIM_CAUSE_PIN2_EXPECT:
1136 return CMS_ERR_SimPin2Req;
1137
1138 case SIM_CAUSE_PUK1_EXPECT:
1139 case SIM_CAUSE_PIN1_BLOCKED:
1140 return CMS_ERR_SimPukReq;
1141
1142 case SIM_CAUSE_PUK2_EXPECT:
1143 case SIM_CAUSE_PIN2_BLOCKED:
1144 return CMS_ERR_SimPuk2Req;
1145
1146 case SIM_CAUSE_PUK1_BLOCKED:
1147 case SIM_CAUSE_PUK2_BLOCKED:
1148 return CMS_ERR_SimWrong;
1149
1150 case SIM_CAUSE_UNKN_FILE_ID:
1151 case SIM_CAUSE_DNL_ERROR:
1152 return CMS_ERR_UnknownErr;
1153
1154 case SIM_CAUSE_EF_INVALID:
1155 return CMS_ERR_OpNotSup;
1156
1157 case SIM_CAUSE_ADDR_WRONG:
1158 return CMS_ERR_InValMemIdx;
1159
1160 case SIM_CAUSE_CMD_INCONSIST:
1161 case SIM_CAUSE_MAX_INCREASE:
1162 case SIM_CAUSE_CHV_NOTSET:
1163 case SIM_CAUSE_CHV_VALIDATED:
1164 case SIM_CAUSE_ACCESS_PROHIBIT:
1165 return CMS_ERR_OpNotAllowed;
1166
1167 case SIM_CAUSE_CARD_REMOVED:
1168 case SIM_CAUSE_DRV_NOCARD:
1169 return CMS_ERR_SimNotIns;
1170
1171 case SIM_CAUSE_NO_SELECT:
1172 case SIM_CAUSE_CLA_WRONG:
1173 case SIM_CAUSE_INS_WRONG:
1174 case SIM_CAUSE_P1P2_WRONG:
1175 case SIM_CAUSE_P3_WRONG:
1176 case SIM_CAUSE_PARAM_WRONG:
1177 return CMS_ERR_MeFail;
1178
1179 case SIM_CAUSE_SAT_BUSY:
1180 return CMS_ERR_SimBsy;
1181
1182 case SIM_CAUSE_DRV_TEMPFAIL:
1183 return CMS_ERR_SimFail;
1184
1185 default:
1186 if (GET_CAUSE_DEFBY(errCode) EQ DEFBY_CONDAT AND
1187 GET_CAUSE_ORIGSIDE(errCode) EQ ORIGSIDE_MS)
1188 {
1189 return CMS_ERR_UnknownErr;
1190 }
1191 return CMS_ERR_UnknownErr;
1192 }
1193 }
1194
1195
1196
1197 /*
1198 +-------------------------------------------------------------------+
1199 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1200 | ROUTINE : cmhSMS_GetCmsFromSms |
1201 +-------------------------------------------------------------------+
1202
1203 PURPOSE : Mapping of SMS causes (MNSMS.doc) to ACI error code.
1204
1205 */
1206 GLOBAL T_ACI_CMS_ERR cmhSMS_GetCmsFromSms ( USHORT errCode )
1207 {
1208 switch ( errCode )
1209 {
1210 case SMS_NO_ERROR: /* No error */
1211 return CMS_ERR_NotPresent;
1212
1213 case SMS_CAUSE_PARAM_WRONG: /* Wrong parameter in primitive */
1214
1215 case SMS_CAUSE_ENTITY_BUSY: /* Entity is busy */
1216 return CMS_ERR_SimBsy;
1217
1218 case SMS_CAUSE_OPER_NOT_ALLW: /* Operation not allowed */
1219 return CMS_ERR_OpNotAllowed;
1220
1221 case SMS_CAUSE_OPER_NOT_SUPP: /* Operation not supported */
1222 return CMS_ERR_OpNotSup;
1223
1224 case SMS_CAUSE_SIM_BUSY: /* SIM busy */
1225 return CMS_ERR_SimBsy;
1226 default:
1227 break;
1228 }
1229
1230 /*
1231 * The switch must be splitted because of a compiler bug
1232 * - asm files can not compiled
1233 *
1234 * TMS470 ANSI C Compiler Version 1.22e
1235 *
1236 * brz, 2004.02.14
1237 */
1238
1239 switch(errCode) {
1240 case SMS_CAUSE_MEM_FAIL: /* Memory failure */
1241 return CMS_ERR_MemFail;
1242
1243 case SMS_CAUSE_INV_INDEX: /* Invalid memory index */
1244 return CMS_ERR_InValMemIdx;
1245
1246 case SMS_CAUSE_MEM_FULL: /* Memory full */
1247 return CMS_ERR_MemFull;
1248
1249 case SMS_CAUSE_NO_SERVICE: /* No network service */
1250 return CMS_ERR_NoNetServ;
1251
1252 case SMS_CAUSE_NET_TIMEOUT: /* Network timeout */
1253 return CMS_ERR_NetTimeOut;
1254
1255 case SMS_CAUSE_UNEXP_CNMA: /* No +CNMA acknowledgement expected */
1256 return CMS_ERR_NoCnmaAckExpect;
1257
1258 case SMS_CAUSE_OTHER_ERROR: /* Any other error */
1259 return CMS_ERR_UnknownErr;
1260
1261 default:
1262 return ((T_ACI_CMS_ERR) (errCode & 0xFF)); /* cmdCmsError(errCode) will figure out other error values from the first byte of the error code */
1263 }
1264 }
1265
1266
1267
1268
1269
1270
1271 /*
1272 +-------------------------------------------------------------------+
1273 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1274 | STATE : code ROUTINE : cmhSMS_ready |
1275 +-------------------------------------------------------------------+
1276
1277 PURPOSE : This function notifies SMS_READY to all sources.
1278 */
1279 GLOBAL void cmhSMS_ready ( void )
1280 {
1281 int idx;
1282 T_opl_field * ptr_opl;
1283
1284 TRACE_FUNCTION ("cmhSMS_ready()");
1285
1286 smsShrdPrm.accessEnabled = TRUE;
1287 ptr_opl = cmhSIM_GetOPL();
1288 ptr_opl->opl_status = FALSE;
1289
1290 cmhSIM_UpdateOperatorName(NOT_PRESENT_16BIT); /* start EF_PNN and EF_OPL reading */
1291
1292 pb_start_build(FALSE); /* start phonebook reading, no guarantees */
1293
1294 percentCSTAT_indication(STATE_MSG_SMS, ENTITY_STATUS_Ready);
1295
1296 for( idx = 0; idx < CMD_SRC_MAX; idx++ )
1297 {
1298 R_AT( RAT_SMS_READY, idx )();
1299 }
1300
1301 }
1302
1303
1304 /*
1305 +-------------------------------------------------------------------+
1306 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1307 | STATE : code ROUTINE : cmhSMS_disableAccess |
1308 +-------------------------------------------------------------------+
1309
1310 PURPOSE : This function disables access to all SMS functions.
1311 */
1312 GLOBAL void cmhSMS_disableAccess (void)
1313 {
1314 smsShrdPrm.accessEnabled = FALSE;
1315 }
1316
1317 /*
1318 +-------------------------------------------------------------------+
1319 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1320 | STATE : code ROUTINE : cmhSMS_checkSIM |
1321 +-------------------------------------------------------------------+
1322
1323 PURPOSE : This function checks if SMS is initialized. If not, the
1324 SIM state is checked. AN error code dependent of the
1325 SIM state is stored.
1326 */
1327 GLOBAL BOOL cmhSMS_checkSIM (void)
1328 {
1329 if (smsShrdPrm.accessEnabled)
1330 return TRUE; /* SMS is accessible*/
1331 /*
1332 *-----------------------------------------------------------------
1333 * check SIM status
1334 *-----------------------------------------------------------------
1335 */
1336
1337 switch (simShrdPrm.SIMStat)
1338 {
1339 case NO_VLD_SS:
1340 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimNotIns );
1341 break;
1342 case SS_INV:
1343 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimFail );
1344 break;
1345 /* case SS_BLKD:
1346 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimPukReq );
1347 break; */
1348 case SS_URCHB:
1349 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimWrong );
1350 break;
1351 case SS_OK:
1352 switch (simShrdPrm.PINStat)
1353 {
1354 case PS_PIN1:
1355 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimPinReq);
1356 break;
1357
1358 case PS_PIN2:
1359 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimPin2Req);
1360 break;
1361
1362 case PS_PUK1:
1363 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimPukReq);
1364 break;
1365
1366 case PS_PUK2:
1367 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimPuk2Req);
1368 break;
1369
1370 default:
1371 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimBsy );
1372 break;
1373 }
1374 break;
1375 default:
1376 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_SimBsy );
1377 break;
1378 }
1379 return FALSE;
1380 }
1381 /*
1382 +-------------------------------------------------------------------+
1383 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1384 | STATE : code ROUTINE : cmhSMS_checkAccess |
1385 +-------------------------------------------------------------------+
1386
1387 PURPOSE : This function checks if SMS is accessible. If an error
1388 condition is found, then *ret is set to either AT_FAIL or
1389 AT_BUSY, otherwise it remains unaffected. The error code
1390 is stored.
1391 */
1392 GLOBAL BOOL cmhSMS_checkAccess (T_ACI_CMD_SRC srcId,
1393 T_ACI_RETURN *ret)
1394 {
1395 /*
1396 *-----------------------------------------------------------------
1397 * check command source
1398 *-----------------------------------------------------------------
1399 */
1400 if(!cmh_IsVldCmdSrc (srcId) AND (srcId NEQ OWN_SAT))
1401 {
1402 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Parameter );
1403 TRACE_ERROR ("[cmhSMS_checkAccess]: Cmd Src not valid");
1404 *ret = AT_FAIL;
1405 return FALSE;
1406 }
1407
1408 /*
1409 *-----------------------------------------------------------------
1410 * check entity status
1411 *-----------------------------------------------------------------
1412 */
1413 if( smsShrdPrm.smsEntStat.curCmd NEQ AT_CMD_NONE )
1414 {
1415 ACI_ERR_DESC( ACI_ERR_CLASS_Ext, EXT_ERR_Internal );
1416 TRACE_ERROR ("[cmhSMS_checkAccess]: Entity is busy");
1417 *ret = AT_BUSY;
1418 return FALSE;
1419 }
1420
1421 /*
1422 *-----------------------------------------------------------------
1423 * check SMS access status
1424 *-----------------------------------------------------------------
1425 */
1426 if (cmhSMS_checkSIM ())
1427 return TRUE;
1428
1429 TRACE_ERROR ("[cmhSMS_checkAccess]: Wrong SIM status");
1430
1431 *ret = AT_FAIL;
1432 return FALSE;
1433 }
1434
1435 /*
1436 +-------------------------------------------------------------------+
1437 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1438 | STATE : code ROUTINE : cmhSMS_getPrfRge |
1439 +-------------------------------------------------------------------+
1440
1441 PURPOSE : This function gets the number of available profiles for
1442 SMS related parameters. First, the SIM is checked. If
1443 there is no space, then PCM ist checked.
1444 */
1445 GLOBAL SHORT cmhSMS_getPrfRge ( void )
1446 {
1447 /* TEMPORARY, ONLY FOR TEST PURPOSES: Pretend that the SIM has no SMSP !!! */
1448 /* smsShrdPrm.aci_sms_parameter.smsParamMaxRec = 0;*/
1449
1450 if (smsShrdPrm.aci_sms_parameter.smsParamMaxRec > 0)
1451 {
1452 return (SHORT)smsShrdPrm.aci_sms_parameter.smsParamMaxRec;
1453 }
1454 else
1455 {
1456 return (MAX_FFS_SMSPRFLS);
1457 }
1458 }
1459
1460 /*
1461 +-------------------------------------------------------------------+
1462 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1463 | STATE : code ROUTINE : cmhSMS_ReadPrmFFS |
1464 +-------------------------------------------------------------------+
1465
1466 PURPOSE : This function reads one record of EF_SMSPRFL_ID from FFS.
1467 The processed parameters are controlled by bits in
1468 'access'.
1469 */
1470 static T_ACI_RETURN cmhSMS_ReadPrmFFS (T_ACI_CMD_SRC srcId,
1471 SHORT recNr,
1472 int access)
1473 {
1474 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
1475 int i;
1476 T_SMS_SET_PRM *elem;
1477 T_ACI_FFS_SMSPRFL smsPrfl;
1478 #ifndef _SIMULATION_
1479 T_FFS_RET ffs_ret;
1480 T_FFS_SIZE ffs_size;
1481 #endif
1482
1483 TRACE_FUNCTION ("cmhSMS_ReadPrmFFS()");
1484
1485 #ifdef _SIMULATION_
1486 smsPrfl.vldFlag = FFS_SMSPRFL_INVLD; /* trigger a failure since nothing can be read in simulation */
1487 #else
1488 ffs_size = FFS_fread(ffs_smsprfl_fname[recNr-1], (void*)&smsPrfl, SIZE_FSS_SMSPRFL);
1489 /*
1490 Don't check FFS return for only specif ERRORS, as ACI will not know what
1491 ERROR FFS may send. So, it's walyws better to check for ERROR OK
1492 i.e EFFS_OK Considering this in mind the below condition is changes to
1493 do the same.
1494 */
1495 if ( ffs_size < EFFS_OK )
1496 {
1497 TRACE_EVENT_P1("error when reading FFS object \"%s\"", ffs_smsprfl_fname[recNr-1]);
1498 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_MemFail );
1499 return AT_FAIL;
1500 }
1501 #endif
1502
1503 if ( smsPrfl.vldFlag EQ FFS_SMSPRFL_INVLD )
1504 {
1505 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_OpNotAllowed );
1506 return AT_FAIL;
1507 }
1508
1509 if (access & ACI_PCM_ACCESS_SMSP)
1510 {
1511 if (srcId >= CMD_SRC_MAX)
1512 {
1513 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_UnknownErr );
1514 return AT_FAIL;
1515 }
1516 else
1517 {
1518 if (set_prm_list EQ NULL)
1519 {
1520 set_prm_list = new_list();
1521 }
1522
1523 elem = find_element(set_prm_list, (UBYTE)recNr, cmhSMS_findPrflId);
1524 if (elem EQ NULL)
1525 {
1526 ACI_MALLOC(elem, sizeof(T_SMS_SET_PRM));
1527 memset(elem, 0, sizeof(T_SMS_SET_PRM));
1528 insert_list(set_prm_list, elem);
1529 }
1530 if (srcId <= CMD_SRC_NONE)
1531 {
1532 elem->numOfRefs = OWN_MAX;
1533 for (i=0; i < OWN_MAX; i++)
1534 {
1535 smsShrdPrm.pSetPrm[i] = (T_SMS_SET_PRM*) elem;
1536 }
1537 }
1538 else
1539 {
1540 smsShrdPrm.pSetPrm[srcId] = (T_SMS_SET_PRM*) elem;
1541 (smsShrdPrm.pSetPrm[srcId])->numOfRefs++;
1542 }
1543 }
1544
1545 pSMSSetPrm = (T_SMS_SET_PRM*) elem;
1546 pSMSSetPrm->prflId = (UBYTE)recNr;
1547
1548 #ifndef _SIMULATION_
1549 /*
1550 *-------------------------------------------------------------
1551 * restore the service center address
1552 *-------------------------------------------------------------
1553 */
1554 pSMSSetPrm->sca.c_num = MINIMUM (smsPrfl.CSCAlenSca, MAX_SMS_ADDR_DIG);
1555 memcpy ( pSMSSetPrm->sca.num, smsPrfl.CSCAsca, pSMSSetPrm->sca.c_num);
1556 pSMSSetPrm->sca.ton = smsPrfl.CSCAton;
1557 pSMSSetPrm->sca.npi = smsPrfl.CSCAnpi;
1558 pSMSSetPrm->sca.v_ton = TRUE;
1559 pSMSSetPrm->sca.v_npi = TRUE;
1560
1561 /*
1562 *-------------------------------------------------------------
1563 * restore the text mode parameters
1564 *-------------------------------------------------------------
1565 */
1566 pSMSSetPrm->vpRel = smsPrfl.CSMPvprel;
1567 memcpy ( &pSMSSetPrm->vpAbs, smsPrfl.CSMPvpabs, SIZE_FFS_SMSPRFL_VPABS );
1568 memcpy ( &pSMSSetPrm->vpEnh, smsPrfl.CSMPvpenh, SIZE_FFS_SMSPRFL_VPENH );
1569
1570 pSMSSetPrm->msgType = smsPrfl.CSMPfo;
1571 pSMSSetPrm->pid = smsPrfl.CSMPpid;
1572 pSMSSetPrm->dcs = smsPrfl.CSMPdcs;
1573 #endif
1574 }
1575
1576 #ifndef _SIMULATION_
1577 if (access & ACI_PCM_ACCESS_CBMP)
1578 {
1579 /*
1580 *-------------------------------------------------------------
1581 * restore the cell broadcast message types and data coding
1582 * schemes
1583 *-------------------------------------------------------------
1584 */
1585 smsShrdPrm.cbmPrm.cbmMode = smsPrfl.CSCBmode;
1586
1587 { /* default setting */
1588 memset (smsShrdPrm.cbmPrm.msgId, DEF_MID_RANGE, sizeof (smsShrdPrm.cbmPrm.msgId));
1589 memset (smsShrdPrm.cbmPrm.dcsId, DEF_DCS_RANGE, sizeof(smsShrdPrm.cbmPrm.dcsId));
1590 }
1591
1592 for ( i = 0; i < MINIMUM(MAX_IDENTS,SIZE_FFS_SMSPRFL_MIDS/2); i++ )
1593 {
1594 smsShrdPrm.cbmPrm.msgId[i] = ( USHORT )smsPrfl.CSCBmids[2*i] << 8;
1595 smsShrdPrm.cbmPrm.msgId[i] |= ( USHORT )smsPrfl.CSCBmids[2*i+1];
1596 }
1597
1598 memcpy ( smsShrdPrm.cbmPrm.dcsId, smsPrfl.CSCBdcss,
1599 MINIMUM(MAX_IDENTS,SIZE_FFS_SMSPRFL_DCSS) );
1600
1601 memcpy (smsShrdPrm.cbmPrm.IMSI, smsPrfl.IMSI, MAX_IMSI);
1602 }
1603 #endif
1604 return AT_CMPL;
1605 }
1606
1607 /*
1608 +-------------------------------------------------------------------+
1609 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1610 | STATE : code ROUTINE : cmhSMS_WritePrmFFS |
1611 +-------------------------------------------------------------------+
1612
1613 PURPOSE : This function writes one record of EF_SMSPRFL_ID to FFS.
1614 The processed parameters are controlled by bits in
1615 'access'.
1616 */
1617 static T_ACI_RETURN cmhSMS_WritePrmFFS (T_ACI_CMD_SRC srcId,
1618 SHORT recNr,
1619 int access)
1620 {
1621 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
1622 T_ACI_FFS_SMSPRFL smsPrfl;
1623 int i;
1624 #ifndef _SIMULATION_
1625 T_FFS_RET ffs_ret;
1626 T_FFS_SIZE ffs_size;
1627 #endif
1628
1629 TRACE_FUNCTION ("cmhSMS_WritePrmFFS()");
1630
1631 if (access & ACI_PCM_ACCESS_SMSP)
1632 {
1633 if (srcId > CMD_SRC_NONE AND srcId < CMD_SRC_MAX)
1634 {
1635 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
1636
1637 /*
1638 *-------------------------------------------------------------
1639 * save the service center address
1640 *-------------------------------------------------------------
1641 */
1642 smsPrfl.CSCAlenSca = MINIMUM ( pSMSSetPrm->sca.c_num, SIZE_FFS_SMSPRFL_SCA );
1643 memcpy ( smsPrfl.CSCAsca, pSMSSetPrm->sca.num, smsPrfl.CSCAlenSca );
1644
1645 i = (int)smsPrfl.CSCAlenSca;
1646 while ( i < SIZE_FFS_SMSPRFL_SCA )
1647 smsPrfl.CSCAsca[i++] = 0xFF;
1648
1649 smsPrfl.CSCAton = pSMSSetPrm->sca.ton;
1650 smsPrfl.CSCAnpi = pSMSSetPrm->sca.npi;
1651
1652 /*
1653 *-------------------------------------------------------------
1654 * store the text mode parameters
1655 *-------------------------------------------------------------
1656 */
1657 smsPrfl.CSMPfo = pSMSSetPrm->msgType;
1658
1659 smsPrfl.CSMPvprel = pSMSSetPrm->vpRel;
1660 memcpy ( smsPrfl.CSMPvpabs, &pSMSSetPrm->vpAbs, SIZE_FFS_SMSPRFL_VPABS );
1661 memcpy ( smsPrfl.CSMPvpenh, &pSMSSetPrm->vpEnh, SIZE_FFS_SMSPRFL_VPENH );
1662
1663 smsPrfl.CSMPpid = pSMSSetPrm->pid;
1664 smsPrfl.CSMPdcs = pSMSSetPrm->dcs;
1665
1666 /*
1667 *-------------------------------------------------------------
1668 * set the valid flag
1669 *-------------------------------------------------------------
1670 */
1671 smsPrfl.vldFlag = FFS_SMSPRFL_VLD;
1672 }
1673 else
1674 {
1675 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_UnknownErr );
1676 return AT_FAIL;
1677 }
1678 }
1679 if (access & ACI_PCM_ACCESS_CBMP)
1680 {
1681 /*
1682 *-------------------------------------------------------------
1683 * save the cell broadcast message types
1684 *-------------------------------------------------------------
1685 */
1686 smsPrfl.CSCBmode = smsShrdPrm.cbmPrm.cbmMode;
1687
1688 { /* default setting */
1689 memset (smsPrfl.CSCBmids, 0xFF, sizeof(smsPrfl.CSCBmids));
1690 memset (smsPrfl.CSCBdcss, 0xFF, sizeof(smsPrfl.CSCBdcss));
1691 }
1692
1693 for ( i = 0; i < MINIMUM(MAX_IDENTS*2,SIZE_FFS_SMSPRFL_MIDS)-1; i += 2 )
1694 {
1695 smsPrfl.CSCBmids[i] = (UBYTE)(smsShrdPrm.cbmPrm.msgId[i/2] >> 8);
1696 smsPrfl.CSCBmids[i+1] = (UBYTE)smsShrdPrm.cbmPrm.msgId[i/2];
1697 }
1698
1699 memcpy ( smsPrfl.CSCBdcss, smsShrdPrm.cbmPrm.dcsId,
1700 MINIMUM(MAX_IDENTS,SIZE_FFS_SMSPRFL_DCSS) );
1701
1702 /*
1703 * Save IMSI also in FFS
1704 */
1705 memcpy (smsPrfl.IMSI, simShrdPrm.imsi.field, simShrdPrm.imsi.c_field);
1706 smsPrfl.vldFlag = FFS_SMSPRFL_VLD;
1707 }
1708
1709 #ifndef _SIMULATION_
1710 ffs_ret = FFS_mkdir(FFS_SMSPRFL_PATH);
1711 if (ffs_ret EQ EFFS_OK)
1712 {
1713 TRACE_EVENT_P1("FFS directory \"%s\" successfully created", FFS_SMSPRFL_PATH);
1714 }
1715 else if (ffs_ret EQ EFFS_EXISTS)
1716 {
1717 TRACE_EVENT_P1("FFS directory \"%s\" already exists", FFS_SMSPRFL_PATH);
1718 }
1719 else
1720 {
1721 TRACE_EVENT_P1("error when creating FFS directory \"%s\"", FFS_SMSPRFL_PATH);
1722 }
1723
1724 ffs_ret = FFS_fwrite(ffs_smsprfl_fname[recNr-1], (void*)&smsPrfl, SIZE_FSS_SMSPRFL);
1725 if (ffs_ret NEQ EFFS_OK)
1726 {
1727 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_MemFail );
1728 TRACE_EVENT_P1("error when writing FFS object \"%s\"", ffs_smsprfl_fname[recNr-1]);
1729 return AT_FAIL;
1730 }
1731 #endif
1732
1733 return AT_CMPL;
1734 }
1735
1736 /*
1737 +-------------------------------------------------------------------+
1738 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1739 | STATE : code ROUTINE : cmhSMS_ReadParams |
1740 +-------------------------------------------------------------------+
1741
1742 PURPOSE : This function reads parameters from SIM and/or PCM.
1743 In case of AT command +CFUN the first record is read to
1744 be informed about storage capability of SIM.
1745 */
1746 GLOBAL T_ACI_RETURN cmhSMS_ReadParams (T_ACI_CMD_SRC srcId,
1747 T_ACI_AT_CMD cmd,
1748 SHORT recNr)
1749 {
1750 T_ACI_RETURN ret = AT_CMPL;
1751 int access = 0;
1752
1753 TRACE_FUNCTION ("cmhSMS_ReadParams()");
1754
1755 smsShrdPrm.smsEntStat.curCmd = cmd;
1756 smsShrdPrm.smsEntStat.entOwn = smsShrdPrm.owner = srcId;
1757
1758
1759 if (cmd EQ AT_CMD_CFUN)
1760 {
1761 /* initialization */
1762
1763 /*
1764 * Always read CSCB params from FFS so that previously stored mode and dcss
1765 * can also be restored from FFS
1766 */
1767 access |= ACI_PCM_ACCESS_CBMP;
1768 /*if (!psaSIM_ChkSIMSrvSup( SRV_SMS_Parms ))*/
1769 access |= ACI_PCM_ACCESS_SMSP;
1770 if (access NEQ 0)
1771 ret = cmhSMS_ReadPrmFFS (CMD_SRC_NONE, 1, access);
1772
1773 if (psaSIM_ChkSIMSrvSup( SRV_SMS_Parms ))
1774 {
1775 smsShrdPrm.prmRdSeq = SMS_READ_SIM_SMSP;
1776 ret = cmhSIM_ReadRecordEF (CMD_SRC_NONE, cmd,
1777 SIM_SMSP, 1, 255,
1778 NULL, cmhSMS_InitSMSP);
1779 }
1780 else if (psaSIM_ChkSIMSrvSup( SRV_CBMIdRnge ))
1781 {
1782 smsShrdPrm.prmRdSeq = SMS_READ_SIM_CBMIR;
1783 ret = cmhSIM_ReadTranspEF (CMD_SRC_NONE, cmd,
1784 SIM_CBMIR, 0, 255,
1785 NULL, cmhSMS_InitSMSP);
1786 }
1787 else if (psaSIM_ChkSIMSrvSup( SRV_CBM_Ident ))
1788 {
1789 smsShrdPrm.prmRdSeq = SMS_READ_SIM_CBMI;
1790 ret = cmhSIM_ReadTranspEF (CMD_SRC_NONE, cmd,
1791 SIM_CBMI, 0, 255,
1792 NULL, cmhSMS_InitSMSP);
1793 }
1794 #ifdef SIM_TOOLKIT
1795 else if ((psaSIM_ChkSIMSrvSup( SRV_DtaDownlCB )) AND
1796 smsShrdPrm.owner EQ OWN_SAT )
1797 {
1798 smsShrdPrm.prmRdSeq = SMS_READ_SIM_CBMID;
1799 ret = cmhSIM_ReadTranspEF (CMD_SRC_NONE, cmd,
1800 SIM_CBMID, 0, 255,
1801 NULL, cmhSMS_InitSMSP);
1802 }
1803 #endif /* of SIM_TOOLKIT */
1804 }
1805 else
1806 {
1807
1808 /* TEMPORARY, ONLY FOR TEST PURPOSES: Pretend that the SIM has no SMSP !!! */
1809 /* smsShrdPrm.aci_sms_parameter.smsParamMaxRec = 0; */
1810
1811 /*
1812 * Always read CSCB params from FFS so that previously stored mode and dcss
1813 * can also be restored from FFS
1814 */
1815 /* normal operation */
1816 access |= ACI_PCM_ACCESS_CBMP;
1817 /* if (smsShrdPrm.aci_sms_parameter.smsParamMaxRec EQ 0)*/
1818 access |= ACI_PCM_ACCESS_SMSP;
1819 if (access NEQ 0)
1820 ret = cmhSMS_ReadPrmFFS (srcId, recNr, access);
1821
1822 if (smsShrdPrm.aci_sms_parameter.smsParamMaxRec > 0)
1823 {
1824 if (recNr <= 0
1825 OR recNr > (SHORT)smsShrdPrm.aci_sms_parameter.smsParamMaxRec)
1826 {
1827 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_InValMemIdx );
1828 ret= AT_FAIL;
1829 }
1830 else
1831 {
1832 smsShrdPrm.prmRdSeq = SMS_READ_SIM_SMSP;
1833 return cmhSIM_ReadRecordEF (CMD_SRC_NONE, cmd, SIM_SMSP,
1834 (UBYTE)(recNr),
1835 smsShrdPrm.aci_sms_parameter.smsParamRecLen,
1836 NULL, cmhSMS_RdCnfCRES);
1837 }
1838 }
1839 if (smsShrdPrm.cbmPrm.cbmSIMmaxIdRge > 0)
1840 {
1841 smsShrdPrm.prmRdSeq = SMS_READ_SIM_CBMIR;
1842 return cmhSIM_ReadTranspEF (CMD_SRC_NONE, cmd, SIM_CBMIR,
1843 0, smsShrdPrm.cbmPrm.cbmSIMmaxIdRge,
1844 NULL, cmhSMS_RdCnfCRES);
1845 }
1846 if (smsShrdPrm.cbmPrm.cbmSIMmaxId > 0)
1847 {
1848 smsShrdPrm.prmRdSeq = SMS_READ_SIM_CBMI;
1849 return cmhSIM_ReadTranspEF (CMD_SRC_NONE, cmd, SIM_CBMI,
1850 0, smsShrdPrm.cbmPrm.cbmSIMmaxId,
1851 NULL, cmhSMS_RdCnfCRES);
1852 }
1853 }
1854 if (ret NEQ AT_EXCT)
1855 {
1856 smsShrdPrm.smsEntStat.curCmd = AT_CMD_NONE;
1857 smsShrdPrm.smsEntStat.entOwn = smsShrdPrm.owner = OWN_NONE;
1858
1859 smsShrdPrm.cbmPrm.cbchOwner = srcId;
1860 psaMMI_Cbch();
1861 smsShrdPrm.cbmPrm.cbchOwner = OWN_NONE;
1862 }
1863 return ret;
1864 }
1865
1866 /*
1867 +-------------------------------------------------------------------+
1868 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1869 | STATE : code ROUTINE : cmhSMS_WriteParams |
1870 +-------------------------------------------------------------------+
1871
1872 PURPOSE : This function reads parameters from SIM and/or PCM.
1873 In case of AT command +CFUN the first record is read to
1874 be informed about storage capability of SIM.
1875 */
1876 GLOBAL T_ACI_RETURN cmhSMS_WriteParams (T_ACI_CMD_SRC srcId,
1877 T_ACI_AT_CMD cmd,
1878 SHORT recNr)
1879 {
1880 T_ACI_RETURN ret = AT_CMPL;
1881 int access = 0;
1882 UBYTE data[MAX_SIM_CMD];
1883
1884 TRACE_FUNCTION ("cmhSMS_WriteParams()");
1885
1886 smsShrdPrm.smsEntStat.curCmd = cmd;
1887 smsShrdPrm.smsEntStat.entOwn = smsShrdPrm.owner = srcId;
1888
1889 /* TEMPORARY, ONLY FOR TEST PURPOSES: Pretend that the SIM has no SMSP !!! */
1890 /* smsShrdPrm.aci_sms_parameter.smsParamMaxRec = 0; */
1891
1892 /*
1893 * Always write CSCB params to FFS so that mode and dcss
1894 * can later be restored from FFS
1895 */
1896 access |= ACI_PCM_ACCESS_CBMP;
1897 /*if (smsShrdPrm.aci_sms_parameter.smsParamMaxRec EQ 0)*/
1898 access |= ACI_PCM_ACCESS_SMSP;
1899 if (access NEQ 0)
1900 ret = cmhSMS_WritePrmFFS (srcId, recNr, access);
1901
1902 if (smsShrdPrm.aci_sms_parameter.smsParamMaxRec > 0)
1903 {
1904 if (recNr <= 0 OR recNr > (SHORT)smsShrdPrm.aci_sms_parameter.smsParamMaxRec)
1905 {
1906 ACI_ERR_DESC( ACI_ERR_CLASS_Cms, CMS_ERR_InValMemIdx );
1907 ret= AT_FAIL;
1908 }
1909 else
1910 {
1911 smsShrdPrm.prmRdSeq = SMS_READ_SIM_SMSP;
1912 cmhSMS_PutPrmSIM (srcId, data,
1913 (int)smsShrdPrm.aci_sms_parameter.smsParamRecLen);
1914 return cmhSIM_WriteRecordEF (CMD_SRC_NONE, cmd, SIM_SMSP,
1915 (UBYTE)(recNr),
1916 smsShrdPrm.aci_sms_parameter.smsParamRecLen,
1917 data, cmhSMS_WrCnfCSAS);
1918 }
1919 }
1920 if (smsShrdPrm.cbmPrm.cbmSIMmaxIdRge > 0)
1921 {
1922 smsShrdPrm.prmRdSeq = SMS_READ_SIM_CBMIR;
1923 cmhSMS_PutCbmirSIM (srcId, data,
1924 (int)smsShrdPrm.cbmPrm.cbmSIMmaxIdRge * 4);
1925
1926 return cmhSIM_WriteTranspEF (CMD_SRC_NONE, cmd, SIM_CBMIR,
1927 0, (UBYTE)(smsShrdPrm.cbmPrm.cbmSIMmaxIdRge * 4),
1928 data, cmhSMS_WrCnfCSAS);
1929 }
1930 if (smsShrdPrm.cbmPrm.cbmSIMmaxId > 0)
1931 {
1932 smsShrdPrm.prmRdSeq = SMS_READ_SIM_CBMI;
1933 cmhSMS_PutCbmiSIM (srcId, data,
1934 (int)smsShrdPrm.cbmPrm.cbmSIMmaxId * 2);
1935
1936 return cmhSIM_WriteTranspEF (CMD_SRC_NONE, cmd, SIM_CBMI,
1937 0, (UBYTE)(smsShrdPrm.cbmPrm.cbmSIMmaxId * 2),
1938 data, cmhSMS_WrCnfCSAS);
1939 }
1940 if (ret NEQ AT_EXCT)
1941 {
1942 smsShrdPrm.smsEntStat.curCmd = AT_CMD_NONE;
1943 smsShrdPrm.smsEntStat.entOwn = smsShrdPrm.owner = OWN_NONE;
1944 }
1945 return ret;
1946 }
1947
1948 /*
1949 +-------------------------------------------------------------------+
1950 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
1951 | STATE : code ROUTINE : cmhSMS_GetPrmSIM |
1952 +-------------------------------------------------------------------+
1953
1954 PURPOSE : This function extracts the parameters of one record of
1955 EF(SMSP) read from SIM.
1956 */
1957 GLOBAL BOOL cmhSMS_GetPrmSIM (T_ACI_CMD_SRC srcId,
1958 UBYTE *data,
1959 int dataLen)
1960 {
1961 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
1962 T_ACI_SMS_SIM_PARAMS *smsprm;
1963
1964 TRACE_FUNCTION ("cmhSMS_GetPrmSIM ()");
1965
1966 if (data NEQ NULL)
1967 {
1968 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
1969
1970 smsprm = (T_ACI_SMS_SIM_PARAMS *)&data[(dataLen <= MIN_SMS_PRM_LEN)?
1971 0: dataLen - MIN_SMS_PRM_LEN];
1972
1973 if (smsprm->par_ind EQ NOT_PRESENT_8BIT)
1974 {
1975
1976 /* ACI-SPR-16431: reset sca number */
1977 pSMSSetPrm->sca.c_num = 0;
1978 memset(pSMSSetPrm->sca.num, 0xFF, sizeof(pSMSSetPrm->sca.num));
1979 /* end of ACI-SPR-16431: reset sca number */
1980
1981 return TRUE; /* record is empty */
1982 }
1983
1984 if ((smsprm->par_ind & SIM_SMSP_V_SCA) EQ 0)
1985 {
1986 cmh_demergeTOA (smsprm->sca_ton_npi, &pSMSSetPrm->sca.ton,
1987 &pSMSSetPrm->sca.npi);
1988 pSMSSetPrm->sca.c_num = (UBYTE)cmh_unpackBCD (pSMSSetPrm->sca.num,
1989 smsprm->sca_addr,
1990 (USHORT)(smsprm->sca_length - 1));
1991 pSMSSetPrm->sca.v_ton = TRUE;
1992 pSMSSetPrm->sca.v_npi = TRUE;
1993
1994 }
1995 if ((smsprm->par_ind & SIM_SMSP_V_PID) EQ 0)
1996 pSMSSetPrm->pid = smsprm->pid;
1997
1998 if ((smsprm->par_ind & SIM_SMSP_V_DCS) EQ 0)
1999 pSMSSetPrm->dcs = smsprm->dcs;
2000
2001 if ((smsprm->par_ind & SIM_SMSP_V_VPREL) EQ 0)
2002 {
2003 pSMSSetPrm->vpRel = smsprm->vp_rel;
2004 pSMSSetPrm->msgType &= ~TP_VPF_MASK;
2005 pSMSSetPrm->msgType |= TP_VPF_RELATIVE;
2006 }
2007 else if ((pSMSSetPrm->msgType & TP_VPF_MASK) EQ TP_VPF_RELATIVE)
2008 pSMSSetPrm->msgType &= ~TP_VPF_MASK;
2009
2010 return TRUE;
2011 }
2012 return FALSE;
2013 }
2014
2015 /*
2016 +-------------------------------------------------------------------+
2017 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
2018 | STATE : code ROUTINE : cmhSMS_PutPrmSIM |
2019 +-------------------------------------------------------------------+
2020
2021 PURPOSE : This function conbiness the parameters for one record of
2022 EF(SMSP) to be written to SIM.
2023 */
2024 GLOBAL BOOL cmhSMS_PutPrmSIM (T_ACI_CMD_SRC srcId,
2025 UBYTE *data,
2026 int maxDataLen)
2027 {
2028 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
2029 T_ACI_SMS_SIM_PARAMS *smsprm;
2030 size_t datalen;
2031
2032 TRACE_FUNCTION ("cmhSMS_PutPrmSIM ()");
2033
2034 if (data NEQ NULL)
2035 {
2036 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
2037
2038 if (maxDataLen < MIN_SMS_PRM_LEN)
2039 {
2040 datalen = MIN_SMS_PRM_LEN;
2041 smsprm = (T_ACI_SMS_SIM_PARAMS *)data;
2042 }
2043 else
2044 {
2045 datalen = (size_t)maxDataLen;
2046 smsprm = (T_ACI_SMS_SIM_PARAMS *)&data[datalen - MIN_SMS_PRM_LEN];
2047 }
2048 memset (data, NOT_PRESENT_8BIT, datalen);
2049
2050 /*
2051 *-------------------------------------------------------------
2052 * set the service center address
2053 *-------------------------------------------------------------
2054 */
2055 if (pSMSSetPrm->sca.c_num > 0)
2056 {
2057 smsprm->sca_ton_npi = cmh_mergeTOA (pSMSSetPrm->sca.ton,
2058 pSMSSetPrm->sca.npi);
2059 smsprm->sca_length = (UBYTE)cmh_packBCD (smsprm->sca_addr,
2060 pSMSSetPrm->sca.num,
2061 (USHORT)MINIMUM(pSMSSetPrm->sca.c_num,
2062 MAX_SMS_ADDR_DIG)) + 1;
2063 smsprm->par_ind &= ~SIM_SMSP_V_SCA;
2064 }
2065
2066 /*
2067 *-------------------------------------------------------------
2068 * set PID, DCS and VP-REL
2069 *-------------------------------------------------------------
2070 */
2071
2072 smsprm->pid = pSMSSetPrm->pid;
2073 smsprm->par_ind &= ~SIM_SMSP_V_PID;
2074
2075 smsprm->dcs = pSMSSetPrm->dcs;
2076 smsprm->par_ind &= ~SIM_SMSP_V_DCS;
2077
2078 if ((pSMSSetPrm->msgType & TP_VPF_MASK) EQ TP_VPF_RELATIVE)
2079 {
2080 smsprm->vp_rel = pSMSSetPrm->vpRel;
2081 smsprm->par_ind &= ~SIM_SMSP_V_VPREL;
2082 }
2083 return TRUE;
2084 }
2085 return FALSE;
2086 }
2087
2088 /*
2089 +-------------------------------------------------------------------+
2090 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
2091 | STATE : code ROUTINE : cmhSMS_GetCbmirSIM |
2092 +-------------------------------------------------------------------+
2093
2094 PURPOSE : This function extracts the parameters of EF(CBMIR)
2095 read from SIM.
2096 */
2097 GLOBAL BOOL cmhSMS_GetCbmirSIM (T_ACI_CMD_SRC srcId,
2098 UBYTE *data,
2099 int dataLen)
2100 {
2101 T_ACI_CBM_SIM_MID_RANGE *mid_range;
2102 USHORT lower_mid, upper_mid;
2103 int mid_entry;
2104
2105 TRACE_FUNCTION ("cmhSMS_GetCbmirSIM ()");
2106
2107 if (data NEQ NULL)
2108 {
2109 /* Please be aware that to keep simulation test cases as less changed as
2110 possible lets assume that IMSI and CBMs stored in the FFS and from SIM
2111 card are the same, since we cannot access FFS under SIMULATION*/
2112 #ifndef _SIMULATION_
2113 /*
2114 * The CSCB parameters read from FFS should be restored only if the same SIM
2115 * is inserted ( check IMSI to ensure the same SIM), otherwise reset the CSCB
2116 * parameters to default values
2117 */
2118 if (memcmp (smsShrdPrm.cbmPrm.IMSI, simShrdPrm.imsi.field, simShrdPrm.imsi.c_field) NEQ 0)
2119 {
2120 smsShrdPrm.cbmPrm.cbmMode = CBCH_ACCEPT;
2121 memset (smsShrdPrm.cbmPrm.msgId, DEF_MID_RANGE,
2122 sizeof (smsShrdPrm.cbmPrm.msgId));
2123 memset (smsShrdPrm.cbmPrm.dcsId, DEF_DCS_RANGE,
2124 sizeof(smsShrdPrm.cbmPrm.dcsId));
2125 return FALSE;
2126 }
2127 #endif
2128 mid_range = (T_ACI_CBM_SIM_MID_RANGE *)data;
2129 mid_entry = 0;
2130
2131 while (smsShrdPrm.cbmPrm.cbmFoundIds < MAX_IDENTS/2 AND
2132 mid_entry < dataLen)
2133 {
2134 lower_mid = (USHORT)mid_range->lowerLSB |
2135 ((USHORT)mid_range->lowerMSB << 8);
2136 upper_mid = (USHORT)mid_range->upperLSB |
2137 ((USHORT)mid_range->upperMSB << 8);
2138 mid_range++;
2139 mid_entry += 4;
2140
2141 if (lower_mid NEQ NOT_PRESENT_16BIT OR
2142 upper_mid NEQ NOT_PRESENT_16BIT)
2143 {
2144 /* Please be aware that to keep simulation test cases as less changed as
2145 possible lets assume that CBMs stored in the FFS and from SIM
2146 card are the same, since we cannot access FFS under SIMULATION*/
2147 #ifndef _SIMULATION_
2148
2149 /*
2150 * If the msg ids are same that in FFS and SIM, then restore else reset
2151 * to default values
2152 */
2153 if (smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2] EQ lower_mid
2154 AND smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2 + 1] EQ upper_mid)
2155 {
2156 smsShrdPrm.cbmPrm.cbmFoundIds++;
2157 }
2158 else
2159 {
2160 smsShrdPrm.cbmPrm.cbmMode = CBCH_ACCEPT;
2161 memset (smsShrdPrm.cbmPrm.msgId, DEF_MID_RANGE,
2162 sizeof (smsShrdPrm.cbmPrm.msgId));
2163 memset (smsShrdPrm.cbmPrm.dcsId, DEF_DCS_RANGE,
2164 sizeof(smsShrdPrm.cbmPrm.dcsId));
2165
2166 smsShrdPrm.cbmPrm.cbmFoundIds = 0;
2167 return FALSE;
2168 }
2169 #else /* Just for simulation - copy data, received from SIM */
2170 smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2] = lower_mid;
2171 smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2 + 1] = upper_mid;
2172 smsShrdPrm.cbmPrm.cbmFoundIds++;
2173 #endif
2174 }
2175 }
2176 return TRUE;
2177 }
2178 return FALSE;
2179 }
2180
2181 /*
2182 +-------------------------------------------------------------------+
2183 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
2184 | STATE : code ROUTINE : cmhSMS_PutCbmirSIM |
2185 +-------------------------------------------------------------------+
2186
2187 PURPOSE : This function conbines the parameters of EF(CBMIR)
2188 to be written to SIM.
2189 */
2190 GLOBAL BOOL cmhSMS_PutCbmirSIM (T_ACI_CMD_SRC srcId,
2191 UBYTE *data,
2192 int maxDataLen)
2193 {
2194 T_ACI_CBM_SIM_MID_RANGE *mid_range;
2195 USHORT lower_mid, upper_mid;
2196 int mid_entry;
2197
2198 TRACE_FUNCTION ("cmhSMS_PutCbmirSIM ()");
2199
2200 if (data NEQ NULL)
2201 {
2202 memset (data, NOT_PRESENT_8BIT, maxDataLen);
2203
2204 mid_range = (T_ACI_CBM_SIM_MID_RANGE *)data;
2205 mid_entry = 0;
2206
2207 while (smsShrdPrm.cbmPrm.cbmFoundIds < MAX_IDENTS/2 AND
2208 mid_entry < maxDataLen)
2209 {
2210 lower_mid = smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2];
2211 upper_mid = smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2 + 1];
2212 smsShrdPrm.cbmPrm.cbmFoundIds++;
2213
2214 if (lower_mid NEQ NOT_PRESENT_16BIT OR
2215 upper_mid NEQ NOT_PRESENT_16BIT)
2216 {
2217 mid_range->lowerLSB = (UBYTE)lower_mid;
2218 mid_range->lowerMSB = (UBYTE)(lower_mid >> 8);
2219 mid_range->upperLSB = (UBYTE)upper_mid;
2220 mid_range->upperMSB = (UBYTE)(upper_mid >> 8);
2221 mid_range++;
2222 mid_entry += 4;
2223 }
2224 }
2225 return TRUE;
2226 }
2227 return FALSE;
2228 }
2229
2230 /*
2231 +-------------------------------------------------------------------+
2232 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
2233 | STATE : code ROUTINE : cmhSMS_GetCbmiSIM |
2234 +-------------------------------------------------------------------+
2235
2236 PURPOSE : This function extracts the parameters of one record of
2237 EF(SMSP) read from SIM.
2238 */
2239 GLOBAL BOOL cmhSMS_GetCbmiSIM (T_ACI_CMD_SRC srcId,
2240 UBYTE *data,
2241 int dataLen)
2242 {
2243 T_ACI_CBM_SIM_MID_LIST **mid_list;
2244 USHORT mid;
2245 int mid_entry;
2246
2247 TRACE_FUNCTION ("cmhSMS_GetCbmiSIM ()");
2248
2249 if (data NEQ NULL)
2250 {
2251
2252 /* Please be aware that to keep simulation test cases as less changed as
2253 possible lets assume that IMSI and CBMs stored in the FFS and from SIM
2254 card are the same, since we cannot access FFS under SIMULATION*/
2255 #ifndef _SIMULATION_
2256 /*
2257 * The CSCB parameters read from FFS should be restored only if the same SIM
2258 * is inserted ( check IMSI to ensure the same SIM), otherwise reset the CSCB
2259 * parameters to default values
2260 */
2261 if (memcmp (smsShrdPrm.cbmPrm.IMSI, simShrdPrm.imsi.field, simShrdPrm.imsi.c_field)
2262 NEQ 0)
2263 {
2264 smsShrdPrm.cbmPrm.cbmMode = CBCH_ACCEPT;
2265 memset (smsShrdPrm.cbmPrm.msgId, DEF_MID_RANGE,
2266 sizeof (smsShrdPrm.cbmPrm.msgId));
2267 memset (smsShrdPrm.cbmPrm.dcsId, DEF_DCS_RANGE,
2268 sizeof(smsShrdPrm.cbmPrm.dcsId));
2269 return FALSE;
2270 }
2271 #endif
2272 mid_list = (T_ACI_CBM_SIM_MID_LIST **)&data;
2273 mid_entry = 0;
2274
2275 while (smsShrdPrm.cbmPrm.cbmFoundIds < MAX_IDENTS/2 AND
2276 mid_entry < dataLen)
2277 {
2278 mid = (USHORT)(*mid_list)->LSB |
2279 ((USHORT)(*mid_list)->MSB << 8);
2280 data += 2; /* overcome TI alignment problem */
2281 mid_entry += 2;
2282
2283 if (mid NEQ NOT_PRESENT_16BIT)
2284 {
2285 /* Please be aware that to keep simulation test cases as less changed as
2286 possible lets assume that CBMs stored in the FFS and from SIM
2287 card are the same, since we cannot access FFS under SIMULATION*/
2288 #ifndef _SIMULATION_
2289 /*
2290 * If the msg ids are same that in FFS and SIM, then restore else reset
2291 * to default values
2292 */
2293 if (smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2] EQ mid
2294 AND smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2 + 1] EQ mid)
2295 {
2296 smsShrdPrm.cbmPrm.cbmFoundIds++;
2297 }
2298 else
2299 {
2300 smsShrdPrm.cbmPrm.cbmMode = CBCH_ACCEPT;
2301 memset (smsShrdPrm.cbmPrm.msgId, DEF_MID_RANGE,
2302 sizeof (smsShrdPrm.cbmPrm.msgId));
2303 memset (smsShrdPrm.cbmPrm.dcsId, DEF_DCS_RANGE,
2304 sizeof(smsShrdPrm.cbmPrm.dcsId));
2305
2306 smsShrdPrm.cbmPrm.cbmFoundIds = 0;
2307 return FALSE;
2308 }
2309 #else /* Just for simulation - copy data, received from SIM */
2310 smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2] =
2311 smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2 + 1] = mid;
2312 smsShrdPrm.cbmPrm.cbmFoundIds++;
2313 #endif
2314 }
2315 }
2316 return TRUE;
2317 }
2318 return FALSE;
2319 }
2320
2321 /*
2322 +-------------------------------------------------------------------+
2323 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
2324 | STATE : code ROUTINE : cmhSMS_PutCbmiSIM |
2325 +-------------------------------------------------------------------+
2326
2327 PURPOSE : This function conbines the parameters of EF(CBMI)
2328 to be written to SIM.
2329 */
2330 GLOBAL BOOL cmhSMS_PutCbmiSIM (T_ACI_CMD_SRC srcId,
2331 UBYTE *data,
2332 int maxDataLen)
2333 {
2334 T_ACI_CBM_SIM_MID_LIST **mid_list;
2335 USHORT lower_mid, upper_mid;
2336 UBYTE mid_entry;
2337
2338 TRACE_FUNCTION ("cmhSMS_PutCbmiSIM ()");
2339
2340 if (data NEQ NULL)
2341 {
2342 memset (data, NOT_PRESENT_8BIT, maxDataLen);
2343
2344 mid_list = (T_ACI_CBM_SIM_MID_LIST **)&data;
2345 mid_entry = 0;
2346
2347 while (smsShrdPrm.cbmPrm.cbmFoundIds < MAX_IDENTS/2 AND
2348 mid_entry < maxDataLen)
2349 {
2350 lower_mid = smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2];
2351 upper_mid = smsShrdPrm.cbmPrm.msgId[smsShrdPrm.cbmPrm.cbmFoundIds * 2 + 1];
2352 smsShrdPrm.cbmPrm.cbmFoundIds++;
2353
2354 if (lower_mid NEQ NOT_PRESENT_16BIT OR
2355 upper_mid NEQ NOT_PRESENT_16BIT)
2356 {
2357 while (lower_mid <= upper_mid AND mid_entry < maxDataLen)
2358 {
2359 (*mid_list)->LSB = (UBYTE)lower_mid;
2360 (*mid_list)->MSB = (UBYTE)(lower_mid >> 8);
2361 lower_mid++;
2362 data += 2; /* overcome TI alignment problem */
2363 mid_entry += 2;
2364 }
2365 }
2366 }
2367 return TRUE;
2368 }
2369 return FALSE;
2370 }
2371
2372 #ifdef SIM_TOOLKIT
2373
2374 /*
2375 +-------------------------------------------------------------------+
2376 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
2377 | STATE : code ROUTINE : cmhSMS_FileUpdate |
2378 +-------------------------------------------------------------------+
2379
2380 PURPOSE : This function processes the primitive SIM_FILE_UPDATE_IND
2381 to update the SMS parameters stored on the SIM.
2382 */
2383 GLOBAL BOOL cmhSMS_FileUpdate (int ref, T_SIM_FILE_UPDATE_IND *fu)
2384 {
2385 BOOL found = FALSE;
2386 int i;
2387
2388 TRACE_FUNCTION ("cmhSMS_FileUpdate ()");
2389
2390 for (i = 0; i < (int)fu->val_nr; i++)
2391 {
2392 if (!found AND
2393 (fu->file_id[i] EQ SIM_SMSP OR
2394 fu->file_id[i] EQ SIM_CBMI OR
2395 fu->file_id[i] EQ SIM_CBMIR OR
2396 fu->file_id[i] EQ SIM_CBMID))
2397 {
2398 found = TRUE;
2399 }
2400 if (fu->file_id[i] EQ SIM_SMS)
2401 {
2402 smsShrdPrm.aci_sms_parameter.simTotal = 0;
2403 smsShrdPrm.aci_sms_parameter.simUsed = 0;
2404 }
2405 }
2406 if (found)
2407 {
2408 smsShrdPrm.cbmPrm.cbmFoundIds = 0; /* new CBMI(R) */
2409
2410 if (cmhSMS_ReadParams (OWN_SAT, AT_CMD_CFUN, 1) EQ AT_EXCT)
2411 {
2412 smsShrdPrm.accessEnabled = FALSE;
2413
2414 simShrdPrm.fuRef = ref;
2415 return FALSE; /* reading files */
2416 }
2417 else
2418 return TRUE; /* nothing to do */
2419 }
2420 else
2421 {
2422 simShrdPrm.fuRef = -1; /* nothing to do */
2423 return TRUE;
2424 }
2425 }
2426
2427 /*
2428 +-------------------------------------------------------------------+
2429 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
2430 | STATE : code ROUTINE : cmhSMS_GetCbDtaDwnlSIM |
2431 +-------------------------------------------------------------------+
2432
2433 PURPOSE : This function extracts the parameters of CBMID record of
2434 EF(CBMID) read from SIM.
2435 */
2436 GLOBAL BOOL cmhSMS_GetCbDtaDwnlSIM (T_ACI_CMD_SRC srcId,
2437 UBYTE *data,
2438 int dataLen)
2439 {
2440 T_ACI_CBM_SIM_MID_LIST **mid_list;
2441 USHORT mid;
2442 int mid_entry;
2443
2444 TRACE_FUNCTION ("cmhSMS_GetCbDtaDwnlSIM ()");
2445
2446 if (data NEQ NULL)
2447 {
2448 smsShrdPrm.cbmPrm.CBDtaDwnlFoundIds = 0;
2449 memset (smsShrdPrm.cbmPrm.CBDtaDwnlIdent, NOT_PRESENT_8BIT,
2450 sizeof (smsShrdPrm.cbmPrm.CBDtaDwnlIdent));
2451
2452 mid_list = (T_ACI_CBM_SIM_MID_LIST **)&data;
2453 mid_entry = 0;
2454
2455 while (smsShrdPrm.cbmPrm.CBDtaDwnlFoundIds < MAX_IDENTS_SAT AND
2456 mid_entry < dataLen)
2457 {
2458 mid = (USHORT)(*mid_list)->LSB |
2459 ((USHORT)(*mid_list)->MSB << 8);
2460 data += 2; /* overcome TI alignment problem */
2461 mid_entry += 2;
2462
2463 if (mid NEQ NOT_PRESENT_16BIT)
2464 {
2465 smsShrdPrm.cbmPrm.CBDtaDwnlIdent[smsShrdPrm.cbmPrm.CBDtaDwnlFoundIds] = mid;
2466 smsShrdPrm.cbmPrm.CBDtaDwnlFoundIds++;
2467 }
2468 }
2469 return TRUE;
2470 }
2471 return FALSE;
2472 }
2473
2474 #endif /*of SIM_TOOLKIT */
2475
2476
2477
2478
2479 /*
2480 +--------------------------------------------------------------------+
2481 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
2482 | STATE : code ROUTINE : cmhSMS_decodeMsg |
2483 +--------------------------------------------------------------------+
2484
2485 PURPOSE : decodes a SM in two steps
2486
2487 */
2488 GLOBAL UBYTE* cmhSMS_decodeMsg (T_sms_sdu *sms_sdu, T_rp_addr* rp_addr,
2489 UBYTE vt_mti)
2490 {
2491 UBYTE ccdRet;
2492 UBYTE direction;
2493 UBYTE recover_from_error;
2494
2495 BUF_tpdu sim_buf; /* source for the second decoding */
2496
2497 TRACE_FUNCTION("cmhSMS_decodeMsg ()");
2498
2499 if( sms_sdu->l_buf EQ 0)
2500 {
2501 TRACE_EVENT("empty SDU: no decoding");
2502 return(NULL);
2503 }
2504
2505 CCD_START;
2506 {
2507
2508 MCAST( sim_pdu, SIM_PDU ); /* sim_pdu points to _decodedMsg */
2509 /*memset( sim_pdu, 0, sizeof (T_SIM_PDU) ); */
2510
2511 /* decoding outer layer */
2512 ccdRet = ccd_decodeMsg ( CCDENT_SMS,
2513 BOTH /* doesn't work with DOWNLINK!!! */,
2514 (T_MSGBUF *) sms_sdu,
2515 (UBYTE *) _decodedMsg, /* target */
2516 SMS_VT_SIM_PDU);
2517
2518 if ( (ccdRet NEQ ccdOK) OR (!sim_pdu->v_tpdu)
2519 OR (_decodedMsg[0] NEQ SMS_VT_SIM_PDU) )
2520 {
2521 TRACE_EVENT_P1("CCD Decoding Error: %d", ccdRet);
2522 CCD_END;
2523 return NULL;
2524 }
2525
2526 memcpy(rp_addr, &sim_pdu->rp_addr, sizeof(T_rp_addr) );
2527
2528 memcpy(&sim_buf, &sim_pdu->tpdu, sizeof(BUF_tpdu) );
2529
2530 /*memset( _decodedMsg, 0, sizeof (T_TP_SUBMIT) ); */
2531
2532 if (vt_mti EQ SMS_VT_SUBMIT)
2533 {
2534 /* for decoding of SMS-SUBMIT (in response to +CMGR, +CMGL) */
2535 direction = UPLINK;
2536 }
2537 else
2538 {
2539 direction = DOWNLINK;
2540 }
2541
2542 /* decoding inner layer */
2543 ccdRet = ccd_decodeMsg ( CCDENT_SMS,
2544 direction,
2545 (T_MSGBUF *) &sim_buf,
2546 (UBYTE *) _decodedMsg, /* target */
2547 vt_mti );
2548
2549 if (ccdRet EQ ccdWarning)
2550 recover_from_error = TRUE; /* Try to recover if a ccdWarning occoured */
2551 else
2552 recover_from_error = FALSE;
2553
2554 if ((ccdRet EQ ccdError) OR (ccdRet EQ ccdWarning))
2555 {
2556 UBYTE ccd_err;
2557 USHORT parlist [6];
2558
2559 TRACE_EVENT_P1 ("ccd_decodeMsg(): %02x", ccdRet);
2560 /*
2561 * get the first error
2562 */
2563 ccd_err = ccd_getFirstError (CCDENT_SMS, parlist);
2564
2565 /*
2566 * Error Handling
2567 */
2568 do
2569 {
2570 #ifndef NTRACE /* save some ROM */
2571 char *errstr;
2572
2573 switch (ccd_err)
2574 {
2575 case ERR_NO_MORE_ERROR: errstr= "the end of the error list is reached";break;
2576 case ERR_INVALID_CALC: errstr= "calculation of the element repeat value failed";break;
2577 case ERR_PATTERN_MISMATCH:errstr= "a bit pattern was not expected";break;
2578 case ERR_COMPREH_REQUIRED:errstr= "check for comprehension required failed";break;
2579 case ERR_IE_NOT_EXPECTED: errstr= "an information element was not expected";break;
2580 case ERR_IE_SEQUENCE: errstr= "wrong sequence of information elements";break;
2581 case ERR_MAX_IE_EXCEED: errstr= "maximum amount of repeatable information elements has exceeded";break;
2582 case ERR_MAX_REPEAT: errstr= "a repeatable element occurs too often in the message";break;
2583 case ERR_MAND_ELEM_MISS: errstr= "a mandatory information element is missing";break;
2584 case ERR_INVALID_MID: errstr= "the message ID is not correct";break;
2585 case ERR_INVALID_TYPE: errstr= "the information element is not a spare padding";break;
2586 case ERR_EOC_TAG_MISSING: errstr= "indefinite length is specified for the ASN.1-BER but the end tag is missing";break;
2587 case ERR_INTERNAL_ERROR: errstr= "an internal CCD error occured ";break;
2588 default: errstr= "unknown error";break;
2589 }
2590 if (ccdRet EQ ccdError)
2591 {
2592 TRACE_EVENT_P2 ("ERR: %u %s", ccd_err, errstr);
2593 }
2594 else if (ccdRet EQ ccdWarning)
2595 {
2596 TRACE_EVENT_P2 ("WRN: %u %s", ccd_err, errstr);
2597 }
2598 #endif /* NTRACE */
2599
2600 if (ccdRet EQ ccdWarning)
2601 {
2602 switch (ccd_err)
2603 {
2604 case ERR_PATTERN_MISMATCH: /* recoverable warnings */
2605 case ERR_COMPREH_REQUIRED:
2606 case ERR_INTERNAL_ERROR:
2607 break;
2608 default:
2609 recover_from_error = FALSE; /* in all other cases reset the recover flag */
2610 }
2611 }
2612
2613 ccd_err = ccd_getNextError (CCDENT_SMS, parlist);
2614 }while (ccd_err NEQ ERR_NO_MORE_ERROR);
2615 }
2616
2617 if ( (ccdRet EQ ccdError) OR
2618 ((ccdRet EQ ccdWarning) AND (recover_from_error EQ FALSE)) OR /* not possible to recover */
2619 (_decodedMsg[0] NEQ vt_mti) )
2620 {
2621 TRACE_EVENT_P1("CCD Decoding Error Stage 2: %d", ccdRet);
2622 CCD_END;
2623 return NULL;
2624 }
2625 else if ((ccdRet EQ ccdWarning) AND (recover_from_error EQ TRUE))
2626 {
2627 TRACE_EVENT ("recovered from warning");
2628 }
2629 }
2630 CCD_END;
2631
2632 return _decodedMsg;
2633 }
2634
2635
2636
2637 /*
2638 +--------------------------------------------------------------------+
2639 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
2640 | STATE : code ROUTINE : cmhSMS_codeMsg |
2641 +--------------------------------------------------------------------+
2642
2643 PURPOSE : encodes a SM in two steps
2644
2645 */
2646 GLOBAL void cmhSMS_codeMsg (T_sms_sdu *sms_sdu, UBYTE tp_vt_mti,
2647 T_rp_addr* sc_addr, UBYTE tp_mti,
2648 UBYTE* decoded_pdu )
2649 {
2650 BUF_tpdu sim_buf; /* target for first coding */
2651 UBYTE direction;
2652
2653 TRACE_FUNCTION ("cmhSMS_codeMsg()");
2654
2655
2656 CCD_START;
2657 {
2658 UBYTE ccdRet;
2659
2660 MCAST( sim_pdu, SIM_PDU );
2661
2662 /* source of outer encoding */
2663 memset( sim_pdu, 0, sizeof (T_SIM_PDU) );
2664
2665 /* target of outer encoding */
2666 /* memset( sms_sdu, 0, sizeof (T_sms_sdu) ); */
2667 sms_sdu->o_buf = 0;
2668 sms_sdu->l_buf = SIM_PDU_LEN << 3;
2669
2670 sim_pdu->tp_vt_mti = SMS_VT_SIM_PDU;
2671 sim_pdu->tp_mti = tp_mti;
2672
2673 /* service center address exists */
2674 if (sc_addr)
2675 {
2676 memcpy(&sim_pdu->rp_addr, sc_addr, sizeof(T_rp_addr));
2677 sim_pdu->rp_addr.v_ton = 1;
2678 sim_pdu->rp_addr.v_npi = 1;
2679 }
2680
2681 /* pdu data exists */
2682 if (decoded_pdu)
2683 {
2684 /* target of inner encoding */
2685 /* memset(sim_buf, 0, sizeof(BUF_tpdu)); */
2686 sim_buf.o_tpdu = 0;
2687 sim_buf.l_tpdu = (sizeof(BUF_tpdu)) << 3;
2688
2689 if (tp_vt_mti EQ SMS_VT_DELIVER)
2690 {
2691 /* for encoding of SMS-DELIVER (only in +CMGW) */
2692 direction = DOWNLINK;
2693 }
2694 else
2695 {
2696 direction = UPLINK;
2697 }
2698
2699 /* encoding inner layer */
2700 ccdRet = ccd_codeMsg (CCDENT_SMS,
2701 direction,
2702 (T_MSGBUF *) &sim_buf, /* target */
2703 (UBYTE *) decoded_pdu,
2704 tp_vt_mti);
2705
2706 if ( ccdRet NEQ ccdOK )
2707 {
2708 TRACE_EVENT_P1("CCD Coding Error: %d", ccdRet);
2709 CCD_END;
2710 return;
2711 }
2712 if (sim_buf.l_tpdu EQ 0)
2713 {
2714 TRACE_EVENT("Encoded length is zero");
2715 }
2716
2717 memcpy(&sim_pdu->tpdu, &sim_buf, sizeof(BUF_tpdu));
2718 sim_pdu->v_tpdu = 1; /* set validy flag */
2719 }
2720
2721 /* encoding outer layer */
2722 ccdRet = ccd_codeMsg (CCDENT_SMS,
2723 UPLINK,
2724 (T_MSGBUF *) sms_sdu, /* target */
2725 (UBYTE *) sim_pdu,
2726 SMS_VT_SIM_PDU);
2727
2728 if ( ccdRet NEQ ccdOK )
2729 {
2730 TRACE_EVENT_P1("CCD Coding Error: %d", ccdRet);
2731 CCD_END;
2732 return;
2733 }
2734 if (sms_sdu->l_buf EQ 0)
2735 {
2736 TRACE_EVENT("Encoded length is zero");
2737 }
2738 }
2739 CCD_END;
2740 }
2741
2742
2743
2744 /*
2745 +--------------------------------------------------------------------+
2746 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
2747 | STATE : code ROUTINE : cmhSMS_cpyDeliver |
2748 +--------------------------------------------------------------------+
2749
2750 PURPOSE : converts a SMS-DELIVER message to the T_ACI_CMGL_SM
2751 structure
2752
2753 */
2754 GLOBAL BOOL cmhSMS_cpyDeliver ( T_ACI_CMGL_SM * sm, T_sms_sdu * sms_sdu )
2755 {
2756 T_rp_addr rp_addr;
2757 UBYTE* message;
2758 T_TP_DELIVER *sms_deliver;
2759 UBYTE alphabet;
2760
2761 TRACE_FUNCTION("cmhSMS_cpyDeliver()");
2762
2763 message = cmhSMS_decodeMsg(sms_sdu, &rp_addr, SMS_VT_DELIVER);
2764
2765 if (message EQ NULL)
2766 {
2767 sm->stat = SMS_STAT_Invalid;
2768 return (FALSE);
2769 }
2770
2771 if ( message[0] NEQ SMS_VT_DELIVER)
2772 {
2773 TRACE_EVENT_P1("wrong VTI = %x", message[0]);
2774 }
2775
2776 sms_deliver = (T_TP_DELIVER*)message;
2777
2778 /*
2779 *-----------------------------------------------------------------
2780 * process originator address
2781 *-----------------------------------------------------------------
2782 */
2783 if (sms_deliver->tp_oa.ton EQ SMS_TON_ALPHANUMERIC)
2784 {
2785 UBYTE i,j = 0;
2786 UBYTE dest_len;
2787 CHAR address_buf[MAX_SMS_ADDR_DIG/2];
2788
2789 for (i = 0 ; i < sms_deliver->tp_oa.digits ; i=i+2)
2790 {
2791 address_buf[j] = (UBYTE)(sms_deliver->tp_oa.num[i+1] << 4) + (UBYTE)(sms_deliver->tp_oa.num[i]);
2792 j++;
2793 }
2794
2795 dest_len = utl_cvt7To8 ( (UBYTE*)address_buf, j, (UBYTE*)sm->adress, 0);
2796 sm -> adress[dest_len] = '\0';
2797 }
2798 else
2799 cmhSMS_getAdrStr ( sm -> adress,
2800 MAX_SMS_NUM_LEN - 1,
2801 sms_deliver->tp_oa.num,
2802 sms_deliver->tp_oa.digits );
2803
2804 sm -> toa.ton = cmhSMS_getTon ( sms_deliver->tp_oa.ton );
2805 sm -> toa.npi = cmhSMS_getNpi ( sms_deliver->tp_oa.npi );
2806
2807 /*
2808 *-----------------------------------------------------------------
2809 * process service center address
2810 *-----------------------------------------------------------------
2811 */
2812 cmhSMS_getAdrStr ( sm -> sca,
2813 MAX_SMS_NUM_LEN - 1,
2814 rp_addr.num,
2815 rp_addr.c_num);
2816
2817 sm -> tosca.ton = cmhSMS_getTon ( rp_addr.ton );
2818 sm -> tosca.npi = cmhSMS_getNpi ( rp_addr.npi );
2819
2820
2821 /*
2822 *-----------------------------------------------------------------
2823 * process alphanumerical phonebook entry
2824 *-----------------------------------------------------------------
2825 */
2826 psaCC_phbMfwSrchNumPlnTxt ( sm -> adress, &sm -> alpha );
2827
2828 /*
2829 *-----------------------------------------------------------------
2830 * process first octet
2831 *-----------------------------------------------------------------
2832 */
2833 sm -> fo = sms_sdu->buf[sms_sdu->buf[0] + 1];
2834
2835 /*
2836 *-----------------------------------------------------------------
2837 * process protocol identifier
2838 *-----------------------------------------------------------------
2839 */
2840 sm -> pid = sms_deliver->tp_pid;
2841
2842 /*
2843 *-----------------------------------------------------------------
2844 * process data coding scheme
2845 *-----------------------------------------------------------------
2846 */
2847 sm -> dcs = sms_deliver->tp_dcs;
2848
2849
2850 /*
2851 *-----------------------------------------------------------------
2852 * process short message data, expanding from 7 to 8 bit
2853 *-----------------------------------------------------------------
2854 */
2855
2856 if (sms_deliver->v_tp_ud)
2857 {
2858 /* user data */
2859 cmhSMS_expdSmsPp ( 0,
2860 sms_deliver->tp_dcs,
2861 sms_deliver->tp_ud.data,
2862 sms_deliver->tp_ud.length,
2863 sm -> data.data,
2864 &sm->data.len );
2865
2866 sm->udh.len = 0;
2867 }
2868 else
2869 {
2870 alphabet = cmhSMS_getAlphabetPp ( sms_deliver->tp_dcs );
2871
2872 /* user data header */
2873 memcpy (sm->udh.data, sms_deliver->tp_udh_inc.tp_udh.data,
2874 sms_deliver->tp_udh_inc.tp_udh.c_data);
2875 sm->udh.len = sms_deliver->tp_udh_inc.tp_udh.c_data;
2876
2877 /* user data (only user data can be 7bit data!!!) */
2878 cmhSMS_expdSmsPp ( (UBYTE)(sm->udh.len+1),
2879 sms_deliver->tp_dcs,
2880 sms_deliver->tp_udh_inc.data,
2881 sms_deliver->tp_udh_inc.length, /* ACI-SPR-9440 */
2882 sm->data.data,
2883 &sm->data.len );
2884
2885 /* 7-bit data */
2886 if (alphabet EQ 0x00)
2887 {
2888 sm->data.len = sms_deliver->tp_udh_inc.length - ((sm->udh.len+1)*8)/7;
2889
2890 /* minus space for the fill bits */
2891 if (((sm->udh.len+1)*8)%7 NEQ 0) sm->data.len--;
2892 }
2893 /* 8-bit data */
2894 else
2895 {
2896 sm->data.len = sms_deliver->tp_udh_inc.length-(sm->udh.len+1);
2897 }
2898 }
2899
2900 /*
2901 *-----------------------------------------------------------------
2902 * process service center time stamp
2903 *-----------------------------------------------------------------
2904 */
2905 sm -> vp_rel = 0;
2906 memset ( &sm->vp_enh, 0, sizeof(T_ACI_VP_ENH) );
2907
2908 cmhSMS_setVpabsCmh ( &sm -> scts,
2909 (T_tp_vp_abs*) &sms_deliver->tp_scts );
2910
2911 return (TRUE);
2912 }
2913
2914
2915 /*
2916 +--------------------------------------------------------------------+
2917 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
2918 | STATE : code ROUTINE : cmhSMS_cpySubmit |
2919 +--------------------------------------------------------------------+
2920
2921 PURPOSE : converts a SMS-SUBMIT message to the T_ACI_CMGL_SM
2922 structure
2923
2924 */
2925 GLOBAL BOOL cmhSMS_cpySubmit ( T_ACI_CMGL_SM * sm, T_sms_sdu * sms_sdu )
2926 {
2927 T_rp_addr rp_addr;
2928 UBYTE* message;
2929 T_TP_SUBMIT *sms_submit;
2930 UBYTE alphabet;
2931
2932 TRACE_FUNCTION("cmhSMS_cpySubmit()");
2933
2934 message = cmhSMS_decodeMsg(sms_sdu, &rp_addr, SMS_VT_SUBMIT);
2935
2936 if (message EQ NULL)
2937 {
2938 sm->stat = SMS_STAT_Invalid;
2939 return (FALSE);
2940 }
2941
2942 if ( message[0] NEQ SMS_VT_SUBMIT)
2943 {
2944 TRACE_EVENT_P1("wrong VTI = %x", message[0]);
2945 }
2946
2947 sms_submit = (T_TP_SUBMIT*)message;
2948
2949
2950 /*
2951 *-----------------------------------------------------------------
2952 * process recepient address
2953 *-----------------------------------------------------------------
2954 */
2955 if (sms_submit->tp_da.ton EQ SMS_TON_ALPHANUMERIC)
2956 {
2957 UBYTE i,j = 0;
2958 UBYTE dest_len;
2959 CHAR address_buf[MAX_SMS_ADDR_DIG/2];
2960
2961 for (i = 0 ; i < sms_submit->tp_da.digits ; i=i+2)
2962 {
2963 address_buf[j] = (UBYTE)(sms_submit->tp_da.num[i+1] << 4) + (UBYTE)(sms_submit->tp_da.num[i]);
2964 j++;
2965 }
2966
2967 dest_len = utl_cvt7To8 ( (UBYTE*)address_buf, j, (UBYTE*)sm->adress, 0);
2968 sm -> adress[dest_len] = '\0';
2969 }
2970 else
2971 cmhSMS_getAdrStr ( sm -> adress,
2972 MAX_SMS_NUM_LEN - 1,
2973 sms_submit->tp_da.num,
2974 sms_submit->tp_da.digits );
2975
2976 sm -> toa.ton = cmhSMS_getTon ( sms_submit->tp_da.ton );
2977 sm -> toa.npi = cmhSMS_getNpi ( sms_submit->tp_da.npi );
2978
2979 /*
2980 *-----------------------------------------------------------------
2981 * process service center address
2982 *-----------------------------------------------------------------
2983 */
2984 cmhSMS_getAdrStr ( sm -> sca,
2985 MAX_SMS_NUM_LEN - 1,
2986 rp_addr.num,
2987 rp_addr.c_num);
2988
2989 sm -> tosca.ton = cmhSMS_getTon ( rp_addr.ton );
2990 sm -> tosca.npi = cmhSMS_getNpi ( rp_addr.npi );
2991
2992
2993 /*
2994 *-----------------------------------------------------------------
2995 * process alphanumerical phonebook entry
2996 *-----------------------------------------------------------------
2997 */
2998 psaCC_phbMfwSrchNumPlnTxt ( sm -> adress, &sm -> alpha );
2999
3000 /*
3001 *-----------------------------------------------------------------
3002 * process first octet
3003 *-----------------------------------------------------------------
3004 */
3005 sm -> fo = sms_sdu->buf[sms_sdu->buf[0] + 1];
3006
3007 /*
3008 *-----------------------------------------------------------------
3009 * process protocol identifier
3010 *-----------------------------------------------------------------
3011 */
3012 sm -> pid = sms_submit->tp_pid;
3013
3014 /*
3015 *-----------------------------------------------------------------
3016 * process data coding scheme
3017 *-----------------------------------------------------------------
3018 */
3019 sm -> dcs = sms_submit->tp_dcs;
3020
3021 /*
3022 *-----------------------------------------------------------------
3023 * process short message data, expanding from 7 to 8 bit
3024 *-----------------------------------------------------------------
3025 */
3026
3027 if (sms_submit->v_tp_ud)
3028 {
3029 /* user data */
3030 cmhSMS_expdSmsPp ( 0,
3031 sms_submit->tp_dcs,
3032 sms_submit->tp_ud.data,
3033 sms_submit->tp_ud.length, /* ACI-SPR-9440 */
3034 sm->data.data,
3035 &sm->data.len );
3036
3037 sm->udh.len = 0;
3038 }
3039 else
3040 {
3041 alphabet = cmhSMS_getAlphabetPp ( sms_submit->tp_dcs );
3042
3043 /* user data header */
3044 memcpy (sm->udh.data, sms_submit->tp_udh_inc.tp_udh.data,
3045 sms_submit->tp_udh_inc.tp_udh.c_data);
3046 sm->udh.len = sms_submit->tp_udh_inc.tp_udh.c_data;
3047
3048 /* user data (only user data can be 7bit data!!!) */
3049 cmhSMS_expdSmsPp ( (UBYTE)(sm->udh.len+1),
3050 sms_submit->tp_dcs,
3051 sms_submit->tp_udh_inc.data,
3052 sms_submit->tp_udh_inc.length, /* ACI-SPR-9440 */
3053 sm->data.data,
3054 &sm->data.len );
3055
3056 /* 7-bit data */
3057 if (alphabet EQ 0x00)
3058 {
3059 sm->data.len = sms_submit->tp_udh_inc.length - ((sm->udh.len+1)*8)/7;
3060
3061 /* minus space for the fill bits */
3062 if (((sm->udh.len+1)*8)%7 NEQ 0) sm->data.len--;
3063 }
3064 /* 8-bit data */
3065 else
3066 {
3067 sm->data.len = sms_submit->tp_udh_inc.length-(sm->udh.len+1);
3068 }
3069 }
3070
3071 /*
3072 *-----------------------------------------------------------------
3073 * process validity period
3074 *-----------------------------------------------------------------
3075 */
3076 if (sms_submit->v_tp_vp_abs)
3077 {
3078 cmhSMS_setVpabsCmh ( &sm->scts, &sms_submit->tp_vp_abs );
3079 sm -> vp_rel = 0;
3080 memset ( &sm->vp_enh, 0, sizeof(T_ACI_VP_ENH) );
3081 }
3082 else if (sms_submit->v_tp_vp_enh)
3083 {
3084 cmhSMS_setVpenhCmh ( &sm->vp_enh, &sms_submit->tp_vp_enh );
3085 sm -> vp_rel = 0;
3086 memset ( &sm->scts, 0, sizeof(T_ACI_VP_ABS) );
3087 }
3088 else
3089 {
3090 sm -> vp_rel = sms_submit->tp_vp_rel;
3091 memset ( &sm -> scts, 0, sizeof(T_ACI_VP_ABS) );
3092 memset ( &sm -> vp_enh, 0, sizeof(T_ACI_VP_ENH) );
3093 }
3094 return (TRUE);
3095 }
3096
3097
3098 /*
3099 +--------------------------------------------------------------------+
3100 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3101 | STATE : code ROUTINE : cmhSMS_cpyMsgInd |
3102 +--------------------------------------------------------------------+
3103
3104 PURPOSE : handles a message indication
3105
3106 */
3107 GLOBAL BOOL cmhSMS_cpyMsgInd ( T_ACI_CMGL_SM * sm,
3108 T_MNSMS_MESSAGE_IND * mnsms_message_ind)
3109 {
3110 BOOL ret = FALSE;
3111 TRACE_FUNCTION("cmhSMS_cpyMsgInd()");
3112
3113 /*
3114 *-----------------------------------------------------------------
3115 * decode SMS-DELIVER or SMS-SUBMIT
3116 *-----------------------------------------------------------------
3117 */
3118
3119 /*
3120 * ACI-SPR-17004: set RFU bits of status to 0 if present since these
3121 * should be ignored in a GSM session (GSM 11.11 section 9.3)
3122 */
3123 cmhSMS_removeStatusRFUBits( &mnsms_message_ind->status );
3124
3125 switch (mnsms_message_ind->status)
3126 {
3127 case SMS_RECORD_REC_UNREAD:
3128 case SMS_RECORD_REC_READ:
3129 ret = cmhSMS_cpyDeliver ( sm, &mnsms_message_ind->sms_sdu );
3130 break;
3131 case SMS_RECORD_STO_UNSENT:
3132 case SMS_RECORD_STO_SENT:
3133 /* ACI-SPR-17003: Handle unsupported statuses */
3134 case SMS_RECORD_STAT_UNRCVD:
3135 case SMS_RECORD_STAT_UNSTRD:
3136 case SMS_RECORD_STAT_STRD:
3137 ret = cmhSMS_cpySubmit ( sm, &mnsms_message_ind->sms_sdu );
3138 break;
3139 /* 21.Mar.2003 currently not used by SMS entity */
3140 /*
3141 * case SMS_RECORD_INVALID:
3142 * ret = FALSE;
3143 * break;
3144 */
3145 default:
3146 TRACE_EVENT("incorrect status");
3147 }
3148
3149 /*
3150 *-----------------------------------------------------------------
3151 * process status (convert from PSA type to CMH type)
3152 *-----------------------------------------------------------------
3153 */
3154 if (sm->stat NEQ SMS_STAT_Invalid)
3155 {
3156 cmhSMS_getStatCmh ( mnsms_message_ind->status, &sm -> stat );
3157 }
3158
3159 /*
3160 *-----------------------------------------------------------------
3161 * process message reference
3162 *-----------------------------------------------------------------
3163 */
3164 sm -> msg_ref = mnsms_message_ind->rec_num;
3165
3166 /*
3167 *-----------------------------------------------------------------
3168 * process tp_status
3169 *-----------------------------------------------------------------
3170 */
3171 sm ->tp_status = -1;
3172
3173 return (ret);
3174 }
3175
3176
3177 /*
3178 +--------------------------------------------------------------------+
3179 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3180 | STATE : code ROUTINE : cmhSMS_cpyReadCnf |
3181 +--------------------------------------------------------------------+
3182
3183 PURPOSE : handles a read confirmation
3184
3185 */
3186 GLOBAL BOOL cmhSMS_cpyReadCnf ( T_ACI_CMGL_SM * sm, T_MNSMS_READ_CNF * mnsms_read_cnf )
3187 {
3188 BOOL ret = FALSE;
3189 TRACE_FUNCTION("cmhSMS_cpyReadCnf()");
3190
3191 /*
3192 * ACI-SPR-17004: set RFU bits of status to 0 if present since these
3193 * should be ignored in a GSM session (GSM 11.11 section 9.3)
3194 */
3195 cmhSMS_removeStatusRFUBits( &mnsms_read_cnf->status );
3196
3197 switch (mnsms_read_cnf->status)
3198 {
3199 case SMS_RECORD_REC_UNREAD:
3200 case SMS_RECORD_REC_READ:
3201 ret = cmhSMS_cpyDeliver ( sm, &mnsms_read_cnf->sms_sdu );
3202 break;
3203 case SMS_RECORD_STO_UNSENT:
3204 case SMS_RECORD_STO_SENT:
3205 /* ACI-SPR-17003: Handle unsupported statuses */
3206 case SMS_RECORD_STAT_UNRCVD:
3207 case SMS_RECORD_STAT_UNSTRD:
3208 case SMS_RECORD_STAT_STRD:
3209 ret = cmhSMS_cpySubmit ( sm, &mnsms_read_cnf->sms_sdu );
3210 break;
3211 /* 21.Mar.2003 currently not used by SMS entity */
3212 /*
3213 * case SMS_RECORD_INVALID:
3214 * ret = FALSE;
3215 * break;
3216 */
3217 default:
3218 TRACE_EVENT("incorrect status");
3219 }
3220
3221 /*
3222 *-----------------------------------------------------------------
3223 * process status (PSA format -> CMH format)
3224 *-----------------------------------------------------------------
3225 */
3226 if (sm->stat NEQ SMS_STAT_Invalid)
3227 {
3228 cmhSMS_getStatCmh ( mnsms_read_cnf->status, &sm -> stat );
3229 }
3230
3231 /*
3232 *-----------------------------------------------------------------
3233 * process message reference
3234 *-----------------------------------------------------------------
3235 */
3236 sm -> msg_ref = mnsms_read_cnf->rec_num;
3237
3238 /*
3239 *-----------------------------------------------------------------
3240 * process tp_status
3241 *-----------------------------------------------------------------
3242 */
3243 sm ->tp_status = -1;
3244
3245 return (ret);
3246 }
3247
3248
3249 /*
3250 +--------------------------------------------------------------------+
3251 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3252 | STATE : code ROUTINE : cmhSMS_cpyStatInd |
3253 +--------------------------------------------------------------------+
3254
3255 PURPOSE : handles a status indication
3256
3257 */
3258 GLOBAL BOOL cmhSMS_cpyStatInd ( T_ACI_CDS_SM * sm,
3259 T_MNSMS_STATUS_IND *mnsms_status_ind )
3260 {
3261 T_rp_addr rp_addr;
3262 UBYTE* message;
3263 T_TP_STATUS *sms_status;
3264
3265 TRACE_FUNCTION("cmhSMS_cpyStatInd()");
3266
3267 message = cmhSMS_decodeMsg(&mnsms_status_ind->sms_sdu, &rp_addr, SMS_VT_STATUS);
3268
3269 if (message EQ NULL)
3270 {
3271 return (FALSE);
3272 }
3273
3274 if ( message[0] NEQ SMS_VT_STATUS)
3275 {
3276 TRACE_EVENT_P1("wrong VTI = %x", message[0]);
3277 }
3278
3279 sms_status = (T_TP_STATUS*)message;
3280
3281
3282 /*
3283 *-----------------------------------------------------------------
3284 * process message type
3285 *-----------------------------------------------------------------
3286 */
3287 sm -> fo = mnsms_status_ind->sms_sdu.buf[mnsms_status_ind->sms_sdu.buf[0]+1];
3288
3289 /*
3290 *-----------------------------------------------------------------
3291 * process message reference
3292 *-----------------------------------------------------------------
3293 */
3294 sm -> msg_ref = sms_status->tp_mr;
3295
3296 /*
3297 *-----------------------------------------------------------------
3298 * process recipient address
3299 *-----------------------------------------------------------------
3300 */
3301 cmhSMS_getAdrStr ( sm->addr,
3302 MAX_SMS_ADDR_DIG - 1,
3303 sms_status->tp_ra.num,
3304 sms_status->tp_ra.digits);
3305
3306 sm->toa.ton = cmhSMS_getTon ( sms_status->tp_ra.ton );
3307 sm->toa.npi = cmhSMS_getNpi ( sms_status->tp_ra.npi );
3308
3309 /*
3310 *-----------------------------------------------------------------
3311 * process service center time stamp
3312 *-----------------------------------------------------------------
3313 */
3314 cmhSMS_setVpabsCmh ( &sm->vpabs_scts, (T_tp_vp_abs*) &sms_status->tp_scts );
3315
3316 /*
3317 *-----------------------------------------------------------------
3318 * process discharge time
3319 *-----------------------------------------------------------------
3320 */
3321 cmhSMS_setVpabsCmh ( &sm->vpabs_dt, (T_tp_vp_abs*) &sms_status->tp_dt );
3322
3323 /*
3324 *-----------------------------------------------------------------
3325 * process status
3326 *-----------------------------------------------------------------
3327 */
3328 sm -> tp_status = sms_status->tp_st;
3329
3330 return (TRUE);
3331 }
3332
3333
3334 /*
3335 +--------------------------------------------------------------------+
3336 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3337 | STATE : code ROUTINE : cmhSMS_getPhbEntry |
3338 +--------------------------------------------------------------------+
3339
3340 PURPOSE : gets phone book entry from coded SM
3341
3342 */
3343 GLOBAL void cmhSMS_getPhbEntry( UBYTE *buf,
3344 T_ACI_PB_TEXT *alpha,
3345 T_ACI_SMS_STAT status )
3346 {
3347 UBYTE *p_data;
3348 UBYTE sca_len;
3349 UBYTE nplan;
3350 UBYTE no_bcd;
3351 UBYTE bcd[MAX_SMS_ADDR_DIG];
3352 CHAR addr[MAX_SMS_ADDR_DIG+1]; /* for '\0' */
3353 USHORT octets;
3354
3355 alpha->len = 0;
3356
3357 p_data = &buf[0];
3358 sca_len = buf[0];
3359
3360 switch (status)
3361 {
3362 case SMS_STAT_RecUnread:
3363 case SMS_STAT_RecRead:
3364 if ((*(p_data+sca_len+1) & TP_MTI_MASK) EQ TP_MTI_SMS_STATUS_REP)
3365 {
3366 p_data++;
3367 }
3368 p_data += (sca_len+1) + 1; /* sms-deliver */
3369 break;
3370 case SMS_STAT_StoUnsent:
3371 case SMS_STAT_StoSent:
3372 p_data += (sca_len+1) + 2; /* sms-submit */
3373 break;
3374 default:
3375 return;
3376 }
3377
3378 /* process originator/destination address */
3379 no_bcd = *p_data++;
3380 no_bcd = MINIMUM(no_bcd, MAX_SMS_ADDR_DIG);
3381
3382 nplan = *p_data++ & 0x0F; /* npi */
3383
3384 octets = (no_bcd+1)/2;
3385
3386 no_bcd = (UBYTE)cmh_unpackBCD (bcd, p_data, octets);
3387
3388 if (nplan EQ 0x05) /* VO patch - if (patch) else ... */
3389 {
3390 UBYTE i,j = 0;
3391 for (i = 0 ; i < no_bcd; i=i+2)
3392 {
3393 addr[j] = (UBYTE)(bcd[i+1] << 4) + (UBYTE)(bcd[i]);
3394 j++;
3395 }
3396 addr[j] = '\0';
3397 }
3398 else
3399 {
3400 cmhSMS_getAdrStr ( addr,
3401 MAX_SMS_ADDR_DIG,
3402 bcd,
3403 no_bcd );
3404 }
3405
3406 /*
3407 *-----------------------------------------------------------------
3408 * process alphanumerical phonebook entry
3409 *-----------------------------------------------------------------
3410 */
3411 psaCC_phbMfwSrchNumPlnTxt ( addr, alpha );
3412 }
3413
3414
3415 /*
3416 +--------------------------------------------------------------------+
3417 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3418 | STATE : code ROUTINE : cmhSMS_codeDelRep |
3419 +--------------------------------------------------------------------+
3420
3421 PURPOSE : codes RP-ACK for SMS-DELIVER-REPORT (without PID, DCS, UD)
3422
3423 */
3424 GLOBAL void cmhSMS_codeDelRep(T_sms_sdu *sms_sdu, T_rp_addr *sc_addr)
3425 {
3426 UBYTE sca_len; /* SCA len incl. length byte and toa */
3427 UBYTE sca_buf[MAX_SMS_ADDR_DIG/2 + 2];
3428
3429 sca_len = CodeRPAddress( sca_buf,
3430 sc_addr->c_num,
3431 sc_addr->ton,
3432 sc_addr->npi,
3433 sc_addr->num );
3434
3435 sms_sdu->l_buf = (sca_len+2)<<3;
3436 sms_sdu->o_buf = 0;
3437
3438 memcpy ( sms_sdu->buf, sca_buf, sca_len);
3439 memset ( sms_sdu->buf+sca_len, 0, 2);
3440 }
3441
3442
3443 /*
3444 +--------------------------------------------------------------------+
3445 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3446 | STATE : code ROUTINE : CodeRPAddress |
3447 +--------------------------------------------------------------------+
3448
3449 PURPOSE : converts address (in BCD format) to semi-octet representation
3450 (including address-length, ton and npi),
3451 for RP addresses (e.g SCA)
3452
3453 returns number of octets including address-length,
3454 ton and npi
3455
3456 */
3457 GLOBAL UBYTE CodeRPAddress( UBYTE *buf, UBYTE numDigits, UBYTE ton,
3458 UBYTE npi, UBYTE *bcd )
3459 {
3460 UBYTE length;
3461
3462 if (numDigits EQ 0)
3463 {
3464 length = 1;
3465 *buf = 0x00;
3466 }
3467 else
3468 {
3469 *buf++ = (numDigits+1)/2 + 1;
3470 *buf++ = (ton << 4) + npi + 0x80;
3471
3472 length = (UBYTE)cmh_packBCD ( buf, bcd, numDigits );
3473
3474 /* add length of length field, ton and npi */
3475 length += 2;
3476 }
3477
3478 return length;
3479 }
3480
3481
3482 /*
3483 +--------------------------------------------------------------------+
3484 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3485 | STATE : code ROUTINE : CodeTPAddress |
3486 +--------------------------------------------------------------------+
3487
3488 PURPOSE : converts address (in BCD format) to semi-octet representation
3489 (including address-length, ton and npi),
3490 for TP addresses (e.g OA or DA)
3491
3492 returns number of octets including including address-length,
3493 ton and npi
3494
3495 */
3496 GLOBAL UBYTE CodeTPAddress( UBYTE *buf, UBYTE numDigits, UBYTE ton,
3497 UBYTE npi, UBYTE *bcd )
3498 {
3499 UBYTE length;
3500
3501 *buf++ = numDigits;
3502 *buf++ = (ton << 4) + npi + 0x80;
3503
3504 length = (UBYTE)cmh_packBCD ( buf, bcd, numDigits );
3505
3506 /* add length of length field, to and npi */
3507 length += 2;
3508
3509 return length;
3510 }
3511
3512
3513 /*
3514 +--------------------------------------------------------------------+
3515 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3516 | STATE : code ROUTINE : DecodeRPAddress |
3517 +--------------------------------------------------------------------+
3518
3519 PURPOSE : converts RP address (SC address) from semi-octet
3520 representation to address in BCD format (including
3521 address-length, ton and npi)
3522
3523 returns number of processed octets in buf
3524
3525 */
3526 GLOBAL UBYTE DecodeRPAddress(UBYTE *c_num, UBYTE *ton,
3527 UBYTE *npi, UBYTE *bcd, UBYTE *buf)
3528 {
3529 UBYTE sca_length; /* sca length is lenth in bytes plus TOA-octet */
3530 UBYTE processed_octets;
3531
3532 sca_length = *buf++;
3533 *ton = (*buf & 0x70)>>4;
3534 *npi = *buf++ & 0x0F;
3535
3536 *c_num = (UBYTE)cmh_unpackBCD (bcd, buf, (USHORT)(sca_length-1));
3537
3538 processed_octets = (*c_num+1)/2 + 2;
3539
3540 return processed_octets;
3541 }
3542
3543 /*
3544 +--------------------------------------------------------------------+
3545 | PROJECT : GSM-F&D (8411) MODULE : CMH_SMSF |
3546 | STATE : code ROUTINE : DecodeTPAddress |
3547 +--------------------------------------------------------------------+
3548
3549 PURPOSE : converts TP address (DA, OA)from semi-octet
3550 representation to address in BCD format (including
3551 address-length, ton and npi)
3552
3553 returns number of processed octets in buf
3554
3555 */
3556 GLOBAL UBYTE DecodeTPAddress(UBYTE *c_num, UBYTE *ton,
3557 UBYTE *npi, UBYTE *bcd, UBYTE *buf)
3558 {
3559 UBYTE digits;
3560 UBYTE processed_octets;
3561
3562 digits = *buf++;
3563 *ton = (*buf & 0x70)>>4;
3564 *npi = *buf++ & 0x0F;
3565
3566 *c_num = (UBYTE)cmh_unpackBCD (bcd, buf, (USHORT)((digits+1)/2));
3567
3568 processed_octets = (*c_num+1)/2 + 2;
3569
3570 return processed_octets;
3571 }
3572
3573
3574
3575
3576 /*
3577 +--------------------------------------------------------------------+
3578 | PROJECT : MODULE : CMH_SMSF |
3579 | STATE : code ROUTINE : cmhSMS_fillTpSubmit |
3580 +--------------------------------------------------------------------+
3581
3582 PURPOSE : fills a T_TP_SUBMIT
3583
3584 */
3585 GLOBAL void cmhSMS_fillTpSubmit (T_TP_SUBMIT* tp_submit,
3586 T_ACI_CMD_SRC srcId,
3587 UBYTE msgType,
3588 UBYTE mr,
3589 T_tp_da* da_addr,
3590 T_ACI_SM_DATA* data,
3591 UBYTE septets,
3592 T_ACI_UDH_DATA* udh )
3593 {
3594 T_SMS_SET_PRM * pSMSSetPrm; /* points to SMS parameter set */
3595 UBYTE alphabet;
3596
3597 TRACE_FUNCTION ("cmhSMS_fillTpSubmit()");
3598
3599 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
3600
3601 memset(tp_submit, 0, sizeof(T_TP_SUBMIT));
3602
3603 tp_submit->tp_vt_mti = SMS_VT_SUBMIT;
3604 tp_submit->tp_rp = (msgType & TP_RP_MASK) ? 1 : 0;
3605 tp_submit->tp_mti = SMS_SUBMIT;
3606 tp_submit->tp_mr = mr;
3607 tp_submit->tp_srr = (msgType & TP_SRR_MASK) ? 1 : 0;
3608
3609 if (da_addr->digits NEQ 0x00)
3610 memcpy(&tp_submit->tp_da, da_addr, sizeof(T_tp_da));
3611
3612 tp_submit->tp_pid = pSMSSetPrm -> pid;
3613 tp_submit->tp_dcs = pSMSSetPrm -> dcs;
3614
3615 switch (msgType & VPF_MASK)
3616 {
3617
3618 case VPF_RELATIVE: /* validity period relative */
3619 tp_submit->v_tp_vp_rel = 1;
3620 tp_submit->tp_vpf = SMS_VPF_RELATIVE;
3621 tp_submit->tp_vp_rel = pSMSSetPrm -> vpRel;
3622 break;
3623
3624 case VPF_ABSOLUTE: /* validity period absolute */
3625 tp_submit->v_tp_vp_abs = 1;
3626 tp_submit->tp_vpf = SMS_VPF_ABSOLUTE;
3627 memcpy(&tp_submit->tp_vp_abs, &pSMSSetPrm -> vpAbs, sizeof(T_tp_vp_abs));
3628 break;
3629
3630 case VPF_ENHANCED: /* validity period enhanced */
3631 tp_submit->v_tp_vp_enh = 1;
3632 tp_submit->tp_vpf = SMS_VPF_ENHANCED;
3633 memcpy(&tp_submit->tp_vp_enh, &pSMSSetPrm -> vpEnh, sizeof(T_tp_vp_enh));
3634 break;
3635
3636 default: /* validity period not present */
3637 break;
3638 }
3639
3640
3641 alphabet = cmhSMS_getAlphabetPp ( pSMSSetPrm -> dcs );
3642
3643 if ((udh) AND (udh->len))
3644 {
3645 tp_submit->tp_udhi = 1;
3646 tp_submit->v_tp_udh_inc = 1;
3647 tp_submit->tp_udh_inc.tp_udh.c_data = udh->len;
3648 memcpy(tp_submit->tp_udh_inc.tp_udh.data, udh->data, udh->len);
3649
3650 /* copy user data */
3651 if ((data) AND (data->len))
3652 {
3653 tp_submit->tp_udh_inc.c_data = data->len;
3654 memcpy(tp_submit->tp_udh_inc.data, data->data, data->len);
3655 }
3656
3657 /* 7-bit data */
3658 if (alphabet EQ 0x00)
3659 {
3660 tp_submit->tp_udh_inc.length = septets + (((udh->len+1)*8)/7);
3661
3662 /* space for the fill bits */
3663 if (((udh->len+1)*8)%7 NEQ 0)
3664 {
3665 tp_submit->tp_udh_inc.length++;
3666 if ((data EQ NULL) OR (data->len EQ 0))
3667 {
3668 tp_submit->tp_udh_inc.c_data = 1;
3669 tp_submit->tp_udh_inc.data[0] = 0; /* redundant */
3670 }
3671 }
3672 }
3673 /* 8-bit data */
3674 else
3675 {
3676 tp_submit->tp_udh_inc.length = tp_submit->tp_udh_inc.c_data+udh->len+1; /* UDH length should be also added */
3677 }
3678 }
3679 else
3680 {
3681 /* validity flag set for both normal SMS and empty SMS */
3682 tp_submit->v_tp_ud = 1;
3683
3684 if ((data) AND (data->len))
3685 {
3686 tp_submit->tp_ud.length = septets;
3687 tp_submit->tp_ud.c_data = data->len;
3688 memcpy(tp_submit->tp_ud.data, data->data, data->len);
3689 }
3690 else
3691 {
3692 /* enters when zero character SMS to be sent */
3693 }
3694 }
3695 }
3696
3697
3698
3699 /*
3700 +--------------------------------------------------------------------+
3701 | PROJECT : MODULE : CMH_SMSF |
3702 | STATE : code ROUTINE : cmhSMS_fillTpDeliver |
3703 +--------------------------------------------------------------------+
3704
3705 PURPOSE : fills a T_TP_DELIVER (only used by +CMGW)
3706
3707 */
3708 GLOBAL void cmhSMS_fillTpDeliver (T_TP_DELIVER* tp_deliver,
3709 T_ACI_CMD_SRC srcId,
3710 UBYTE msgType,
3711 T_tp_oa* oa_addr,
3712 T_ACI_SM_DATA* data,
3713 UBYTE septets,
3714 T_ACI_UDH_DATA* udh )
3715 {
3716 T_SMS_SET_PRM * pSMSSetPrm; /* points to SMS parameter set */
3717 UBYTE alphabet;
3718
3719 TRACE_FUNCTION ("cmhSMS_fillTpDeliver()");
3720
3721 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
3722
3723 memset(tp_deliver, 0, sizeof(T_TP_DELIVER));
3724
3725 tp_deliver->tp_vt_mti = SMS_VT_DELIVER;
3726 tp_deliver->tp_rp = (msgType & TP_RP_MASK) ? 1 : 0;
3727 tp_deliver->tp_mti = SMS_DELIVER;
3728
3729 if (oa_addr->digits NEQ 0x00)
3730 memcpy(&tp_deliver->tp_oa, oa_addr, sizeof(T_tp_oa));
3731
3732 tp_deliver->tp_pid = pSMSSetPrm -> pid;
3733 tp_deliver->tp_dcs = pSMSSetPrm -> dcs;
3734
3735 memcpy(&tp_deliver->tp_scts, &pSMSSetPrm -> vpAbs, sizeof(T_tp_scts));
3736
3737 if ((data) AND (data->len))
3738 {
3739 alphabet = cmhSMS_getAlphabetPp ( pSMSSetPrm -> dcs );
3740
3741 if ((udh) AND (udh->len))
3742 {
3743 tp_deliver->tp_udhi = 1;
3744 tp_deliver->v_tp_udh_inc = 1;
3745 tp_deliver->tp_udh_inc.tp_udh.c_data = udh->len;
3746 memcpy(tp_deliver->tp_udh_inc.tp_udh.data, udh->data, udh->len);
3747
3748 /* copy user data */
3749 tp_deliver->tp_udh_inc.c_data = data->len;
3750 memcpy(tp_deliver->tp_udh_inc.data, data->data, data->len);
3751
3752 /* 7-bit data */
3753 if (alphabet EQ 0x00)
3754 {
3755 tp_deliver->tp_udh_inc.length = septets + (((udh->len+1)*8)/7);
3756
3757 /* space for the fill bits */
3758 if (((udh->len+1)*8)%7 NEQ 0) tp_deliver->tp_udh_inc.length++;
3759 }
3760 /* 8-bit data */
3761 else
3762 {
3763 tp_deliver->tp_udh_inc.length = tp_deliver->tp_udh_inc.c_data;
3764 }
3765 }
3766 else
3767 {
3768 tp_deliver->v_tp_ud = 1;
3769 tp_deliver->tp_ud.length = septets;
3770 tp_deliver->tp_ud.c_data = data->len;
3771 memcpy(tp_deliver->tp_ud.data, data->data, data->len);
3772 }
3773 }
3774 else /* if ((data) AND (data->len)) */
3775 {
3776 tp_deliver->v_tp_ud = 1;
3777 tp_deliver->tp_ud.length = 0;
3778 }
3779 }
3780
3781
3782 /*
3783 +--------------------------------------------------------------------+
3784 | PROJECT : MODULE : CMH_SMSF |
3785 | STATE : code ROUTINE : cmhSMS_fillTpCommand |
3786 +--------------------------------------------------------------------+
3787
3788 PURPOSE : fills a T_TP_COMMAND
3789
3790 */
3791 GLOBAL void cmhSMS_fillTpCommand ( T_TP_COMMAND* tp_command,
3792 UBYTE fo,
3793 UBYTE ct,
3794 UBYTE mr,
3795 UBYTE pid,
3796 UBYTE mn,
3797 T_tp_da* da_addr,
3798 T_ACI_CMD_DATA* data,
3799 T_ACI_UDH_DATA* udh)
3800
3801 {
3802 TRACE_FUNCTION ("cmhSMS_fillTpCommand()");
3803
3804 memset(tp_command, 0, sizeof(T_TP_COMMAND));
3805
3806 tp_command->tp_vt_mti = SMS_VT_COMMAND;
3807 tp_command->tp_srr = (fo & TP_SRR_MASK) ? 1 : 0;
3808 tp_command->tp_mti = SMS_COMMAND;
3809 tp_command->tp_mr = mr;
3810 tp_command->tp_pid = pid;
3811 tp_command->tp_ct = ct;
3812 tp_command->tp_mn = mn;
3813
3814 if (da_addr->digits NEQ 0x00)
3815 memcpy(&tp_command->tp_da, da_addr, sizeof(T_tp_da));
3816
3817 if ((data) AND (data->len))
3818 {
3819 if ((udh) AND (udh->len))
3820 {
3821 tp_command->tp_udhi = 1;
3822 tp_command->v_tp_cdh_inc = 1;
3823 tp_command->tp_cdh_inc.tp_udh.c_data = udh->len;
3824 memcpy(tp_command->tp_cdh_inc.tp_udh.data, udh->data, udh->len);
3825 tp_command->tp_cdh_inc.c_data = data->len;
3826 memcpy(tp_command->tp_cdh_inc.data, data->data, data->len);
3827 }
3828 else
3829 {
3830 tp_command->v_tp_cd = 1;
3831 tp_command->tp_cd.c_data = data->len;
3832 memcpy(tp_command->tp_cd.data, data->data, data->len);
3833 }
3834 }
3835 else
3836 {
3837 /* command length field must be present */
3838 tp_command->v_tp_cd = 1;
3839 tp_command->tp_cd.c_data = 0;
3840 }
3841
3842 }
3843 #ifdef FF_CPHS
3844
3845 /*
3846 +----------------------------------------------------------------------+
3847 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
3848 | ROUTINE : cmhSMS_check_voice_mail_ind|
3849 +----------------------------------------------------------------------+
3850
3851 PURPOSE :
3852 */
3853
3854 LOCAL BOOL cmhSMS_check_voice_mail_ind( T_TP_DELIVER *sms_deliver )
3855 {
3856 TRACE_FUNCTION("cmhSMS_check_voice_mail_ind()");
3857
3858 if ( sms_deliver->tp_oa.digits NEQ 4 OR
3859 sms_deliver->tp_oa.ton NEQ SMS_TON_ALPHANUMERIC )
3860 {
3861 TRACE_EVENT_P2("no vmi -> oa... digits:%d ton:%d",
3862 sms_deliver->tp_oa.digits, sms_deliver->tp_oa.ton);
3863 return FALSE;
3864 }
3865
3866 switch (sms_deliver->tp_dcs & 0xF0)
3867 {
3868 case SMS_DCS_GRP_DEF:
3869 case SMS_DCS_GRP_CLASS:
3870 if ( (sms_deliver->tp_dcs & 0xF) EQ 0 OR
3871 (sms_deliver->tp_dcs & 0xF) EQ 0xC )
3872 {
3873 break; /* GSM Default Alphabet */
3874 }
3875 /* no break, if FALSE */
3876 /*lint -fallthrough*/
3877 case SMS_DCS_GRP_COMPR:
3878 case SMS_DCS_GRP_CLASS_COMPR:
3879 case SMS_DCS_GRP_MW_STORE_UCS2:
3880 TRACE_EVENT_P1("no vmi -> dcs: %d", sms_deliver->tp_dcs);
3881 return FALSE; /* no GSM Default Alphabet */
3882 case SMS_DCS_DATA_CLASS:
3883 if (sms_deliver->tp_dcs & 0x4)
3884 {
3885 TRACE_EVENT_P1("no vmi -> dcs: %d", sms_deliver->tp_dcs);
3886 return FALSE; /* no GSM Default Alphabet */
3887 }
3888 }
3889
3890 if (!sms_deliver->v_tp_ud)
3891 {
3892 TRACE_EVENT("no vmi -> no ud");
3893 return FALSE; /* not only text present */
3894 }
3895 if ( ( sms_deliver->tp_ud.length NEQ 1 ) OR
3896 ( (sms_deliver->tp_ud.data[0] & 0x7F) NEQ ' ') )
3897 {
3898 TRACE_EVENT_P2("no vmi -> ud... length:%d data[0]:%d",
3899 sms_deliver->tp_ud.length, sms_deliver->tp_ud.data[0]);
3900 return FALSE; /* no single space */
3901 }
3902
3903 TRACE_FUNCTION ("CPHS VWI: send to cphs module");
3904
3905 return TRUE;
3906 }
3907
3908
3909 /*
3910 +-------------------------------------------------------------------------+
3911 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
3912 | ROUTINE : cmhSMS_voice_mail_ind_get_line|
3913 +-------------------------------------------------------------------------+
3914
3915 PURPOSE :
3916 */
3917 LOCAL void cmhSMS_voice_mail_ind_get_data( T_TP_DELIVER *sms_deliver,
3918 UBYTE *flag_set,
3919 T_CPHS_LINES *line )
3920 {
3921 TRACE_FUNCTION("cmhSMS_voice_mail_ind_get_line()");
3922
3923 /* get flag set, which is send in the first bit of the first
3924 byte of the originating address number. Due to the decoding
3925 each byte of the originating address number is now splitted
3926 into 2 bytes, so that the first 4 bits of the former first
3927 byte can be found in byte 1 */
3928 *flag_set = sms_deliver->tp_oa.num[0] & 0x1;
3929
3930 /* line is coded in character 1 bit 1 of GSM originating address.
3931 the originating address of T_TP_DELIVER is allready decoded
3932 so that this information is to be found in byte 3 of the
3933 originating address number */
3934
3935 if (sms_deliver->tp_oa.num[2] & 0x1)
3936 {
3937 *line = CPHS_LINE2;
3938 }
3939 else
3940 {
3941 *line = CPHS_LINE1;
3942 }
3943 }
3944
3945
3946 /*
3947 +----------------------------------------------------------------------+
3948 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
3949 | ROUTINE : cmhSMS_voice_mail_ind |
3950 +----------------------------------------------------------------------+
3951
3952 PURPOSE :
3953 */
3954
3955 GLOBAL BOOL cmhSMS_voice_mail_ind( T_sms_sdu *sms_sdu)
3956 {
3957 T_TP_DELIVER *sms_deliver;
3958 T_rp_addr rp_addr;
3959 T_CPHS_LINES line;
3960 UBYTE flag_set;
3961 UBYTE *message;
3962
3963 TRACE_FUNCTION("cmhSMS_voice_mail_ind()");
3964
3965 /* check if cphs is active */
3966
3967
3968 /* check if indication is voice mail indication */
3969 if ( sms_sdu )
3970 {
3971 message = cmhSMS_decodeMsg(sms_sdu, &rp_addr, SMS_VT_DELIVER);
3972
3973 if (message EQ NULL)
3974 return FALSE;
3975
3976 if ( message[0] NEQ SMS_VT_DELIVER)
3977 {
3978 TRACE_EVENT_P1("wrong VTI = %x", message[0]);
3979 }
3980
3981 sms_deliver = (T_TP_DELIVER*)message;
3982
3983 if ( cphs_check_status() EQ CPHS_OK )
3984 {
3985 if ( cmhSMS_check_voice_mail_ind(sms_deliver) )
3986 {
3987 cmhSMS_voice_mail_ind_get_data(sms_deliver, &flag_set, &line);
3988
3989 cphs_voice_mail_ind(flag_set, line);
3990
3991 return TRUE;
3992 }
3993 }
3994 }
3995 return FALSE;
3996 }
3997
3998 #endif /* FF_CPHS*/
3999
4000
4001 /*
4002 +----------------------------------------------------------------------+
4003 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
4004 | ROUTINE : cmhSMS_resetMtDsCnmiParam |
4005 +----------------------------------------------------------------------+
4006 PURPOSE : this function resets the <mt> and <ds> parameter for the
4007 SMS acknowledge in Phase2+ mode (+CNMA).
4008 */
4009 GLOBAL void cmhSMS_resetMtDsCnmiParam(void)
4010 {
4011 smsShrdPrm.mtHndl = 0; /* reset <mt> and <ds> param in error case */
4012 smsShrdPrm.srHndl = 0;
4013
4014 smsShrdPrm.CNMImt = 0;
4015 smsShrdPrm.CNMIds = 0;
4016 { /* inform the SMS entity about the parameter changes */
4017 PALLOC (mnsms_configure_req, MNSMS_CONFIGURE_REQ);
4018
4019 /* fill in primitive parameter: command request */
4020 mnsms_configure_req -> pref_mem_3 = smsShrdPrm.mem3;
4021 mnsms_configure_req -> mt = smsShrdPrm.mtHndl;
4022 mnsms_configure_req -> ds = smsShrdPrm.srHndl;
4023 mnsms_configure_req -> mhc = (smsShrdPrm.CSMSservice NEQ CSMS_SERV_GsmPh2Plus)
4024 ? SMS_MHC_PH2 : SMS_MHC_PH2PLUS;
4025 mnsms_configure_req->v_cmms_mode = FALSE;
4026 mnsms_configure_req->v_tmms_val = FALSE;
4027
4028 PSENDX (SMS, mnsms_configure_req);
4029 }
4030 }
4031
4032 /*
4033 +-------------------------------------------------------------------+
4034 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSS |
4035 | STATE : code ROUTINE : sAT_PlusCMGWPdu |
4036 +-------------------------------------------------------------------+
4037
4038 PURPOSE : This is the internal function which is responsible for
4039 storing messages into the mobile station or SIM card.
4040 AT command which is responsible for writing a short
4041 message to memory in PDU mode.
4042 */
4043 GLOBAL BOOL cmhSMS_storePduToSim( T_ACI_CMD_SRC srcId,
4044 UBYTE stat,
4045 T_ACI_SM_DATA *pdu )
4046 {
4047 T_ACI_RETURN ret;
4048
4049 TRACE_FUNCTION ("cmhSMS_storePduToSim()");
4050
4051 /* check if command executable */
4052 if(!cmhSMS_checkAccess (srcId, &ret))
4053 {
4054 return FALSE;
4055 }
4056
4057 {
4058 PALLOC (mnsms_store_req, MNSMS_STORE_REQ);
4059
4060 mnsms_store_req -> mem_type = smsShrdPrm.mem2;
4061 mnsms_store_req -> rec_num = CMGW_IDX_FREE_ENTRY;
4062 mnsms_store_req -> condx = SMS_CONDX_OVR_NON;
4063 mnsms_store_req -> status = stat;
4064
4065 if ( (pdu->len > 0) AND (pdu->len <= SIM_PDU_LEN) )
4066 {
4067 mnsms_store_req->sms_sdu.l_buf = pdu->len * 8;
4068 mnsms_store_req->sms_sdu.o_buf = 0;
4069 memcpy (mnsms_store_req->sms_sdu.buf, pdu->data, pdu->len);
4070 }
4071 else
4072 {
4073 TRACE_FUNCTION ("cmhSMS_storePduToSim() : wrong PDU len");
4074 PFREE (mnsms_store_req);
4075 return FALSE;
4076 }
4077
4078 PSENDX (SMS, mnsms_store_req);
4079 }
4080
4081 smsShrdPrm.smsEntStat.curCmd = AT_CMD_CMGW;
4082 smsShrdPrm.smsEntStat.entOwn = smsShrdPrm.owner = srcId;
4083 smsShrdPrm.uiInternalSmsStorage = srcId;
4084
4085 return TRUE;
4086 }
4087
4088 /*
4089 +--------------------------------------------------------------------+
4090 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
4091 | STATE : code ROUTINE : cmhSMS_removeStatusRFUBits |
4092 +--------------------------------------------------------------------+
4093
4094 PURPOSE : ACI-SPR-17004: Method for removing of SMS RFU status
4095 bits as defined by GSM 11.11 section 9.3
4096
4097 */
4098 GLOBAL void cmhSMS_removeStatusRFUBits ( UBYTE* status )
4099 {
4100 TRACE_FUNCTION("cmhSMS_removeStatusRFUBits()");
4101
4102 /* See GSM 11.11 section 10.5.3 for position of RFU bits in status */
4103
4104 /* test the pattern of the three lowest bits, match for "101" */
4105 if ((*status & 0x07) EQ 0x05)
4106 {
4107 /* set the highest three bits to 0 */
4108 *status &= 0x1F;
4109 }
4110 else
4111 {
4112 /* set the highest five bits to 0 */
4113 *status &= 0x07;
4114 }
4115
4116 }
4117
4118 /*
4119 +-------------------------------------------------------------------------+
4120 | PROJECT : GSM-PS (6147) MODULE : CMH_SMSF |
4121 | STATE : code ROUTINE : cmhSMS_convertDeliverStatusToACI|
4122 +-------------------------------------------------------------------------+
4123
4124 PURPOSE : converts the SMS delivery status to ACI CPRSM status.
4125
4126 */
4127 GLOBAL T_ACI_CPRSM_MOD cmhSMS_convertDeliverStatusToACI ( UBYTE status )
4128 {
4129 T_ACI_CPRSM_MOD mode;
4130
4131 TRACE_FUNCTION("cmhSMS_convertDeliverStatusToACI()");
4132
4133 switch (status)
4134 {
4135 case SMS_DELIVER_STATUS_PAUSE:
4136 mode = CPRSM_MOD_Pause;
4137 break;
4138 case SMS_DELIVER_STATUS_RESUME:
4139 mode = CPRSM_MOD_Resume;
4140 break;
4141 default:
4142 mode = CPRSM_MOD_NotPresent;
4143 }
4144 return mode;
4145 }
4146
4147 /*==== EOF ========================================================*/