comparison g23m/condat/ms/src/aci/ati_pdu.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-F&D (8411)
4 | Modul : ATI
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 : AT Command Interpreter Extension for SMS PDU mode
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ATI_PDU_C
22 #define ATI_PDU_C
23
24 #undef DUMMY_ATI_STRINGS
25
26 #include "aci_all.h"
27
28 #include "aci_cmh.h"
29 #include "ati_cmd.h"
30 #include "aci_io.h"
31 #include "aci_cmd.h"
32 #include "aci.h"
33 #include "psa.h"
34 #include "psa_sms.h"
35 #include "aci_lst.h"
36
37 #include "cmh.h"
38 #include "cmh_sms.h"
39 #include "gdi.h"
40 #include "audio.h"
41 #include "p_sim.h"
42 #include "p_aci.h"
43 #include "aoc.h"
44 #include "aci.h"
45 #include "pcm.h"
46 #include "rx.h"
47 #include "pwr.h"
48
49 #include "aci_cmd.h"
50 #include "aci_mem.h"
51 #include "aci_prs.h"
52
53 #include "ati_int.h"
54
55 #ifdef FF_ATI_BAT
56
57 #include "typedefs.h"
58 #include "gdd.h"
59 #include "bat.h"
60
61 #include "ati_bat.h"
62
63 #endif /*FF_ATI_BAT*/
64
65 GLOBAL USHORT GsmToHex (UBYTE in, char * buffer, USHORT pos);
66 // GLOBAL USHORT HexAdress (CHAR * adress, UBYTE ton, UBYTE npi, char * buffer, USHORT pos);
67 // GLOBAL USHORT HexAdressTP (CHAR * adress, UBYTE ton, UBYTE npi, char * buffer, USHORT pos);
68 // GLOBAL USHORT HexScts (T_ACI_VP_ABS * scts, char * buffer, USHORT pos);
69 // GLOBAL USHORT HexMessage (T_ACI_SM_DATA * data, UBYTE length, char * buffer, USHORT pos);
70 // GLOBAL char * GSMAddress (char * cl, char * address, T_ACI_TOA *tosca);
71 GLOBAL char * HexToGsm (char * cl, UBYTE * value);
72
73 #ifdef WIN32
74 EXTERN T_ACI_SMS_READ smsReadMode;
75 #endif
76
77 LOCAL SHORT length_of_pdu_message = 0;
78 LOCAL UBYTE pdu_error_detected = FALSE;
79
80
81 /*
82 +--------------------------------------------------------------------+
83 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
84 | STATE : code ROUTINE : atPlusCMGSPdu |
85 +--------------------------------------------------------------------+
86
87 PURPOSE : +CMGS command (SEND Message) in PDU mode.
88 */
89
90 #if defined (SMS_PDU_SUPPORT)
91
92 GLOBAL T_ATI_RSLT atPlusCMGSPdu (char *cl, UBYTE srcId)
93 {
94 T_ACI_RETURN ret = AT_FAIL;
95 T_ACI_SM_DATA pdu;
96 T_SMS_SET_PRM * pSMSSetPrm; /* points to SMS parameter set */
97
98 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
99
100 pdu.len = 0;
101
102 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
103
104 TRACE_FUNCTION("atPlusCMGSPdu()");
105
106 if (src_params->text_mode EQ CMD_MODE)
107 {
108 /*
109 * Extract the length (excluding SCA octets) outto be parsed from
110 * the input pointer cl
111 */
112 cl = parse (cl,"r",&length_of_pdu_message);
113 if ( !cl OR length_of_pdu_message EQ 0)
114 {
115 cmdCmsError(CMS_ERR_OpNotAllowed);
116 return (ATI_FAIL);
117 }
118 src_params->text_mode = TXT_MODE;
119 return (ATI_EXCT);
120 } /* end of if (src_params->text_mode EQ CMD_MODE) */
121 else
122 {
123 UBYTE i = 0;
124 UBYTE sca_len = 0;
125 UBYTE offset = 0;
126 UBYTE pdu_message_octets_lenth = 0;
127
128 src_params->text_mode = CMD_MODE;
129 /*
130 * Input line with pdu is given
131 */
132 pdu_error_detected = FALSE;
133
134 HexToGsm (cl, &sca_len);
135
136 TRACE_EVENT_P1("%d",sca_len);
137
138 if (sca_len > ((MAX_SMS_ADDR_DIG+1)/2) + 1)
139 {
140 TRACE_ERROR("SCA too long !!!");
141 cmdCmsError(CMS_ERR_OpNotAllowed);
142 return (ATI_FAIL);
143 }
144
145 /*
146 calculation of the real length of PDU string
147
148 The first octet in the input is an indicator of the length of the SMSC information supplied.
149
150 And this Octet and the SMSC content do not count in the real length of PDU string.
151
152 so here, the length of the input needs to minus 2 + sca_len*2 and then divide 2.
153 */
154 pdu_message_octets_lenth = (strlen(cl)-2-sca_len*2)/2;
155
156 TRACE_EVENT_P1("pdu_message_octets_lenth == %d",pdu_message_octets_lenth);
157
158 if(pdu_message_octets_lenth NEQ length_of_pdu_message)
159 {
160 cmdCmsError (CMS_ERR_OpNotAllowed);
161 TRACE_EVENT("ERROR: input pdu message length do not match the real length!");
162 return (ATI_FAIL);
163 }
164
165 if (sca_len EQ 0) /* no SCA given */
166 {
167 offset = CodeRPAddress(pdu.data,
168 pSMSSetPrm -> sca.c_num,
169 pSMSSetPrm -> sca.ton,
170 pSMSSetPrm -> sca.npi,
171 pSMSSetPrm -> sca.num);
172
173 pdu.len = length_of_pdu_message + offset;
174 cl += 2;
175 }
176 else
177 {
178 pdu.len = length_of_pdu_message + sca_len + 1;
179 }
180
181 for (i=offset; i<pdu.len AND *cl NEQ '\0' AND i<MAX_SM_LEN; i++)
182 {
183 cl = HexToGsm (cl, &pdu.data[i]);
184 }
185
186 #ifdef FF_ATI_BAT
187 {
188 T_BAT_cmd_send cmd;
189 T_BAT_cmd_set_plus_cmgs cmgs;
190
191 /*
192 * Check that BAT can handle this size of PDU.
193 */
194 if (pdu.len>BAT_MAX_SM_LEN)
195 {
196 TRACE_EVENT("ERROR: PDU too big for BAT");
197 cmdCmsError(CMS_ERR_UnknownErr);
198 return (ATI_FAIL);
199 }
200
201 cmd.ctrl_params=BAT_CMD_SET_PLUS_CMGS;
202 cmd.params.ptr_set_plus_cmgs=&cmgs;
203
204 /*
205 * Copy in the PDU data, secure in the knowledge that we have
206 * enough room for it.
207 */
208 memcpy(&cmgs.pdu,pdu.data,BAT_MAX_SM_LEN);
209
210 cmgs.length=(U8)pdu.len;
211 cmgs.c_pdu=(U8)pdu.len;
212
213 bat_send(ati_bat_get_client(srcId), &cmd);
214 }
215
216 #else /* no FF_ATI_BAT */
217
218 /*
219 * send the SMS message using extracted values
220 */
221 ret = sAT_PlusCMGSPdu ( srcId, &pdu );
222
223 if ( ret NEQ AT_EXCT )
224 {
225 cmdCmsError (CMS_ERR_NotPresent); // use aciErrDesc
226 return (ATI_FAIL);
227 }
228
229 #endif /* no FF_ATI_BAT */
230
231 /*
232 * rCI_OK will emitting +CMGS: <mr>[,<ackpdu>]
233 */
234 src_params->curAtCmd = AT_CMD_CMGS;
235 return ATI_EXCT;
236 }
237 }
238
239
240 #endif
241
242 /*
243 +--------------------------------------------------------------------+
244 | PROJECT : GSM-F&D (8411) MODULE : ACI_CMD |
245 | STATE : code ROUTINE : atPlusCNMAPdu |
246 +--------------------------------------------------------------------+
247
248 PURPOSE : +CNMA command (new message acknowledgement) in PDU mode
249 */
250
251 #if defined (SMS_PDU_SUPPORT)
252
253 GLOBAL T_ATI_RSLT atPlusCNMAPdu (char *cl, UBYTE srcId)
254 {
255 UBYTE msg_type;
256 static SHORT n = -1;
257 USHORT tp_fcs;
258 T_ACI_SM_DATA pdu = {0};
259 T_ACI_RETURN ret = AT_FAIL;
260 UBYTE pdu_message_octets_lenth = 0;
261 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
262
263
264
265
266 TRACE_FUNCTION("atPlusCNMAPdu()");
267
268
269
270 if (src_params->text_mode EQ CMD_MODE)
271 {
272 /*
273 * normal command line
274 */
275 if (*cl EQ '\0')
276 {
277 /*
278 * no parameters, like text mode
279 */
280 n = 1;
281 tp_fcs = 0;
282 }
283 else
284 {
285 /*
286 * Extract the acknowledge parameter n
287 */
288 length_of_pdu_message = 0;
289 cl = parse(cl,"rr",&n, &length_of_pdu_message);
290 if ( !cl)
291 {
292 cmdCmsError(CMS_ERR_OpNotAllowed);
293 return (ATI_FAIL);
294 }
295
296
297
298 switch (n)
299 {
300 case -1:
301 case 0:
302 case 1:
303 n = 1;
304 tp_fcs = 0;
305 if (length_of_pdu_message)
306 {
307 src_params->text_mode = TXT_MODE;
308 return (ATI_EXCT);
309 }
310 break;
311 case 2:
312 if (length_of_pdu_message)
313 {
314 src_params->text_mode = TXT_MODE;
315 return (ATI_EXCT);
316 }
317 else
318 {
319 tp_fcs = 0xFF;
320 }
321 break;
322 default:
323 cmdCmsError(CMS_ERR_OpNotAllowed);
324 return (ATI_FAIL);
325 }
326 }
327 } /* end of if (src_params->text_mode EQ CMD_MODE) */
328 else
329 {
330 src_params->text_mode = CMD_MODE;
331
332 /*
333 calculation of the real length of PDU string
334
335 The entering of PDU is done similarly as specified in command Send Message +CMGS,
336 except that the format of <ackpdu> is used instead of <pdu>
337 (i.e. SMSC address field is not present).
338
339 so here, the length of the input needs to divide 2.
340 */
341
342
343 pdu_message_octets_lenth = strlen(cl)/2;
344
345 TRACE_EVENT_P1("pdu_message_octets_lenth == %d",pdu_message_octets_lenth);
346
347 if(pdu_message_octets_lenth NEQ length_of_pdu_message)
348 {
349 cmdCmsError (CMS_ERR_OpNotAllowed);
350 TRACE_EVENT("ERROR: input pdu message length do not match the real length!");
351 return (ATI_FAIL);
352 }
353
354 /*
355 * Input line with pdu is given
356 */
357 pdu_error_detected = FALSE;
358 /*
359 * get the message type
360 */
361 HexToGsm (cl, &msg_type);
362
363 if ((msg_type & 3) EQ 0) // SMS_DELIVER_REPORT
364 {
365 int i;
366 pdu.len = (UBYTE)length_of_pdu_message;
367 for (i=0; i<length_of_pdu_message; i++)
368 {
369 cl = HexToGsm (cl, &pdu.data[i]);
370 }
371 }
372 else
373 pdu_error_detected = TRUE;
374
375 if (pdu_error_detected)
376 {
377 cmdCmsError ( CMS_ERR_InValPduMod );
378 return (ATI_FAIL);
379 }
380 }
381
382
383
384 /*
385 * send the SMS command using extracted values
386 */
387 ret = sAT_PlusCNMAPdu (srcId, n, &pdu);
388 switch(ret)
389 {
390 case AT_FAIL:
391 cmdCmsError (CMS_ERR_NotPresent); // use aciErrDesc
392 /*
393 * no break
394 */
395 case AT_CMPL:
396 break;
397 default:
398 TRACE_EVENT("atPlusCNMAPdu() : Error !! Not AT_FAIL or AT_COMPL");
399 break;
400 }
401 return (map_aci_2_ati_rslt(ret));
402 }
403 #endif
404
405
406 /*
407 +--------------------------------------------------------------------+
408 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
409 | STATE : code ROUTINE : atPlusCMGWPdu |
410 +--------------------------------------------------------------------+
411
412 PURPOSE : +CMGW command (Write message to memory) in PDU mode.
413 */
414
415 #if defined (SMS_PDU_SUPPORT)
416
417 GLOBAL T_ATI_RSLT atPlusCMGWPdu (char *cl, UBYTE srcId)
418 {
419 T_ACI_SMS_STAT stat;
420 T_ACI_RETURN ret = AT_FAIL;
421 static UBYTE message_status = NOT_PRESENT_8BIT;
422 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
423 T_ACI_SM_DATA pdu;
424 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
425
426 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
427
428 TRACE_FUNCTION("atPlusCMGWPdu()");
429
430 if (src_params->text_mode EQ CMD_MODE)
431 {
432 /*
433 * normal command line
434 */
435 stat = SMS_STAT_StoUnsent; /* STO UNSENT as default */
436 /*
437 * Extract the length and status to be parsed from the input pointer cl
438 */
439 cl = parse(cl,"rd",&length_of_pdu_message,&stat);
440 if ( !cl OR length_of_pdu_message EQ 0)
441 {
442 cmdCmsError(CMS_ERR_OpNotAllowed);
443 return (ATI_FAIL);
444 }
445
446 if (stat < SMS_STAT_RecUnread OR stat > SMS_STAT_All)
447 {
448 cmdCmsError(CMS_ERR_OpNotAllowed);
449 return (ATI_FAIL);
450 }
451 else
452 {
453 message_status = (UBYTE)stat;
454 }
455 /*
456 * wait for next input containing the PDU_is_given
457 */
458 src_params->text_mode = TXT_MODE;
459 return (ATI_EXCT);
460 } /* end of if (src_params->text_mode EQ CMD_MODE) */
461 else
462 {
463 UBYTE offset = 0;
464 UBYTE sca_len;
465 UBYTE i;
466 UBYTE pdu_message_octets_lenth = 0;
467
468 src_params->text_mode = CMD_MODE;
469 /*
470 * Input line with pdu is given
471 */
472
473 /* if the character sent is ESC, then abort command CLB 16.11.00 */
474 if (*cl EQ 0x1B)
475 {
476 TRACE_EVENT("Send message command cancelled by user");
477
478 return ATI_CMPL_NO_OUTPUT;
479 }
480
481 pdu_error_detected = FALSE;
482
483 HexToGsm (cl, &sca_len);
484
485 if (sca_len > ((MAX_SMS_ADDR_DIG+1)/2) + 1)
486 {
487 TRACE_ERROR("SCA too long !!!");
488 cmdCmsError(CMS_ERR_OpNotAllowed);
489 return (ATI_FAIL);
490 }
491
492 /*
493 calculation of the real length of PDU string
494
495 The first octet in the input is an indicator of the length of the SMSC information supplied.
496
497 And this Octet and the SMSC content do not count in the real length of PDU string.
498
499 so here, the length of the input needs to minus 2 + sca_len*2 and then divide 2.
500 */
501 pdu_message_octets_lenth = (strlen(cl)-2-sca_len*2)/2;
502
503 TRACE_EVENT_P1("pdu_message_octets_lenth == %d",pdu_message_octets_lenth);
504
505 if(pdu_message_octets_lenth NEQ length_of_pdu_message)
506 {
507 cmdCmsError (CMS_ERR_OpNotAllowed);
508 TRACE_EVENT("ERROR: input pdu message length do not match the real length!");
509 return (ATI_FAIL);
510 }
511
512
513 if (sca_len EQ 0) /* no SCA given */
514 {
515 offset = CodeRPAddress(pdu.data,
516 pSMSSetPrm -> sca.c_num,
517 pSMSSetPrm -> sca.ton,
518 pSMSSetPrm -> sca.npi,
519 pSMSSetPrm -> sca.num);
520 cl += 2;
521 pdu.len = length_of_pdu_message + offset;
522 }
523 else
524 {
525 pdu.len = length_of_pdu_message + sca_len + 1;
526 }
527
528 for (i=offset; i<pdu.len AND *cl NEQ '\0' AND i<MAX_SM_LEN; i++)
529 {
530 cl = HexToGsm (cl, &pdu.data[i]);
531 }
532
533 ret = sAT_PlusCMGWPdu ( srcId, message_status, &pdu);
534
535 if ( ret NEQ AT_EXCT )
536 {
537 cmdCmsError (CMS_ERR_NotPresent); // use aciErrDesc
538 return (ATI_FAIL);
539 }
540 /*
541 * rCI_OK will emitting +CMGW: <index>
542 */
543 src_params->curAtCmd = AT_CMD_CMGW;
544 return ATI_EXCT;
545 }
546 }
547 #endif
548
549 /*
550 +--------------------------------------------------------------------+
551 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
552 | STATE : code ROUTINE : atPlusCMGCPdu |
553 +--------------------------------------------------------------------+
554
555 PURPOSE : +CMGC command (Send SMS command) in PDU mode
556 */
557
558 #if defined (SMS_PDU_SUPPORT)
559
560 GLOBAL T_ATI_RSLT atPlusCMGCPdu (char *cl, UBYTE srcId)
561 {
562 T_ACI_RETURN ret = AT_FAIL;
563 T_ACI_SM_DATA pdu;
564 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
565 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
566
567 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
568
569 pdu.len = 0;
570
571 TRACE_FUNCTION("atPlusCMGCPdu()");
572
573 if (src_params->text_mode EQ CMD_MODE)
574 {
575 /*
576 * normal command line
577 */
578 /*
579 * Extract the length to be parsed from the input pointer cl
580 */
581 cl = parse(cl,"r",&length_of_pdu_message);
582 if ( !cl OR length_of_pdu_message EQ 0)
583 {
584 cmdCmsError(CMS_ERR_OpNotAllowed);
585 return (ATI_FAIL);
586 }
587 /*
588 * wait for next input containing the PDU_is_given
589 */
590 src_params->text_mode = TXT_MODE;
591 return (ATI_EXCT);
592 } /* end of if (src_params->text_mode EQ CMD_MODE) */
593 else
594 {
595 UBYTE offset = 0;
596 UBYTE sca_len;
597 UBYTE i;
598 UBYTE pdu_message_octets_lenth = 0;
599
600 src_params->text_mode = CMD_MODE;
601 /*
602 * Input line with pdu is given
603 */
604
605 pdu_error_detected = FALSE;
606
607 HexToGsm (cl, &sca_len);
608
609 if (sca_len > ((MAX_SMS_ADDR_DIG+1)/2) + 1)
610 {
611 TRACE_ERROR("SCA too long !!!");
612 cmdCmsError(CMS_ERR_OpNotAllowed);
613 return (ATI_FAIL);
614 }
615
616 /*
617 calculation of the real length of PDU string
618
619 The first octet in the input is an indicator of the length of the SMSC information supplied.
620
621 And this Octet and the SMSC content do not count in the real length of PDU string.
622
623 so here, the length of the input needs to minus 2 + sca_len*2 and then divide 2.
624 */
625 pdu_message_octets_lenth = (strlen(cl)-2-sca_len*2)/2;
626
627 TRACE_EVENT_P1("pdu_message_octets_lenth == %d",pdu_message_octets_lenth);
628
629 if(pdu_message_octets_lenth NEQ length_of_pdu_message)
630 {
631 cmdCmsError (CMS_ERR_OpNotAllowed);
632 TRACE_EVENT("ERROR: input pdu message length do not match the real length!");
633 return (ATI_FAIL);
634 }
635
636 if (sca_len EQ 0) /* no SCA given */
637 {
638 offset = CodeRPAddress(pdu.data,
639 pSMSSetPrm -> sca.c_num,
640 pSMSSetPrm -> sca.ton,
641 pSMSSetPrm -> sca.npi,
642 pSMSSetPrm -> sca.num);
643 cl += 2;
644 pdu.len = length_of_pdu_message + offset;
645 }
646 else
647 {
648 pdu.len = length_of_pdu_message + sca_len + 1;
649 }
650
651 for (i=offset; i<pdu.len AND *cl NEQ '\0' AND i<MAX_SM_LEN; i++)
652 {
653 cl = HexToGsm (cl, &pdu.data[i]);
654 }
655
656 ret = sAT_PlusCMGCPdu (srcId, &pdu);
657
658 if ( ret NEQ AT_EXCT )
659 {
660 cmdCmsError (CMS_ERR_NotPresent); // use aciErrDesc
661 return (ATI_FAIL);
662 }
663 /*
664 * rCI_OK will emitting +CMGC: <mr>[,<ackpdu>]
665 */
666 src_params->curAtCmd = AT_CMD_CMGC;
667 return ATI_EXCT;
668 }
669 }
670 #endif
671
672 /*
673 +--------------------------------------------------------------------+
674 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
675 | STATE : code ROUTINE : rCI_PlusCMGLPdu |
676 +--------------------------------------------------------------------+
677
678 PURPOSE : handles AT_PlusCMGL call back in PDU mode
679
680 */
681
682 #if defined (SMS_PDU_SUPPORT)
683
684 GLOBAL void rCI_Plus_Percent_CMGLPdu ( T_MNSMS_READ_CNF *mnsms_read_cnf,
685 T_ACI_AT_CMD cmd )
686 {
687 T_ACI_SMS_STAT stat;
688
689 USHORT i = 0;
690 USHORT pos = 0;
691 UBYTE sca_len;
692 UBYTE length_sms, length=0;
693 UBYTE fo, addr_len, dcs, vp_format=TP_VPF_ABSOLUTE;
694 UBYTE *data_ptr;
695
696 UBYTE srcId = srcId_cb;
697
698 #ifndef FF_ATI_BAT
699 CHAR cvtdAlpha[2*MAX_ALPHA_LEN];
700 USHORT lenCvtdAlpha;
701 T_ACI_PB_TEXT alpha;
702 #endif
703
704 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
705
706 TRACE_FUNCTION("rCI_Plus_Percent_CMGLPdu()");
707
708 src_params->curAtCmd = AT_CMD_NONE;
709
710 /* convert status from PSA type to CMH type */
711 cmhSMS_getStatCmh ( mnsms_read_cnf->status, &stat );
712
713 /*
714 * print response and index, status of SMS message
715 */
716 if (cmd EQ AT_CMD_CMGL )
717 {
718 pos = sprintf ( g_sa, "+CMGL: ");
719 }
720 else
721 {
722 pos=sprintf (g_sa, " %s: ", "%CMGL");
723 }
724 pos += sprintf ( g_sa + pos, "%d,%d,", mnsms_read_cnf->rec_num, stat);
725
726 #ifdef FF_ATI_BAT
727
728 /*
729 * Extracting the alphanumeric data from the phonebook at this point
730 * would defeat the object (testing the BAT message). Having this
731 * data stored globally represents an easier solution to the
732 * problem of conveying it here.
733 */
734 if (smsShrdPrm.alpha_len)
735 {
736 pos+=sprints(g_sa+pos,smsShrdPrm.alpha,smsShrdPrm.alpha_len);
737 }
738
739 #else
740
741 cmhSMS_getPhbEntry( mnsms_read_cnf->sms_sdu.buf, &alpha, stat);
742
743 /*
744 * print alpha if available
745 */
746 if ( alpha.len NEQ 0 )
747 {
748 utl_chsetFromGsm ( (UBYTE*)alpha.data,
749 alpha.len,
750 (UBYTE*)cvtdAlpha,
751 sizeof(cvtdAlpha),
752 &lenCvtdAlpha,
753 GSM_ALPHA_Def );
754 pos += sprints ( g_sa + pos, cvtdAlpha, lenCvtdAlpha );
755 }
756
757 #endif /*FF_ATI_BAT*/
758
759 /* length of SCA including length byte and TOA byte */
760 sca_len = mnsms_read_cnf->sms_sdu.buf[0] + 1;
761
762 data_ptr = &mnsms_read_cnf->sms_sdu.buf[sca_len];
763 fo = *data_ptr++;
764 length++;
765
766 if ((fo & TP_MTI_MASK) NEQ TP_MTI_SMS_STATUS_REP)
767 {
768 if ((fo & TP_MTI_MASK) EQ TP_MTI_SMS_SUBMIT)
769 {
770 /* SMS-SUBMIT */
771 data_ptr++;
772 length++;
773 vp_format = fo & TP_VPF_MASK;
774 }
775
776 addr_len = *data_ptr;
777 length += 4 + (addr_len+1)/2;
778
779 /* data_ptr points to TP-DCS now */
780 data_ptr += 3 + (addr_len+1)/2;
781
782 dcs = *data_ptr++;
783
784 switch (vp_format)
785 {
786 /*
787 * Check validity period format bit 4 and 3
788 */
789 case TP_VPF_NOT_PRESENT: // TP-VP not present
790 break;
791 case TP_VPF_RELATIVE: // TP-VP relative format
792 length++;
793 data_ptr++;
794 break;
795 case TP_VPF_ENHANCED: // TP-VP enhanced format
796 case TP_VPF_ABSOLUTE: // TP-VP absolute format
797 length += 7;
798 data_ptr += 7;
799 break;
800 }
801
802 /* data_ptr points to TP-UDL now,
803 * calculate the length excluding SCA octets
804 */
805 if (cmhSMS_getAlphabetPp (dcs) EQ 0)
806 length_sms = length + (*data_ptr * 7 + 7)/8 + 1; // 7 bit alphabet
807 else
808 length_sms = length + *data_ptr + 1;
809
810 pos += sprintf ( g_sa + pos, ",%d", length_sms );
811 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
812 pos = 0;
813 }
814 else
815 {
816 length_sms=((mnsms_read_cnf->sms_sdu.l_buf+7)/8);
817 pos += sprintf ( g_sa + pos, ",%d,", length_sms-sca_len );
818 sca_len = 0;
819 }
820
821 /*
822 * Print PDU + service centre address
823 */
824 for (i=0;i<(USHORT)(sca_len+length_sms);i++)
825 pos = GsmToHex (mnsms_read_cnf->sms_sdu.buf[i], g_sa, pos);
826
827 /*
828 * Send response
829 */
830 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
831 }
832
833 /*
834 +--------------------------------------------------------------------+
835 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
836 | STATE : code ROUTINE : rCI_PlusCMGRPdu |
837 +--------------------------------------------------------------------+
838
839 PURPOSE : handles AT_PlusCMGR call back in PDU mode
840
841 */
842
843 #if defined (SMS_PDU_SUPPORT)
844
845 GLOBAL void rCI_Plus_Percent_CMGRPdu (T_MNSMS_READ_CNF * mnsms_read_cnf,
846 T_ACI_AT_CMD cmd)
847 {
848 USHORT pos = 0;
849 T_ACI_SMS_STAT stat;
850 USHORT i;
851
852 UBYTE sca_len;
853 UBYTE length_sms, length=0;
854 UBYTE fo, addr_len, dcs, vp_format=TP_VPF_ABSOLUTE;
855 UBYTE *data_ptr;
856
857 UBYTE srcId = srcId_cb;
858
859 #ifndef FF_ATI_BAT
860 CHAR cvtdAlpha[2*MAX_ALPHA_LEN];
861 USHORT lenCvtdAlpha;
862 T_ACI_PB_TEXT alpha;
863 #endif
864
865 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
866
867 TRACE_FUNCTION("rCI_Plus_Percent_CMGRPdu()");
868
869 src_params->curAtCmd = AT_CMD_NONE;
870
871 /*
872 * print response for SMS message
873 */
874 if (cmd EQ AT_CMD_CMGR)
875 {
876 pos = sprintf ( g_sa, "+CMGR: ");
877 }
878 else
879 {
880 pos=sprintf (g_sa, " %s: ", "%CMGR");
881 }
882
883 /* convert status from PSA type to CMH type */
884 cmhSMS_getStatCmh ( mnsms_read_cnf->status, &stat );
885
886 /*
887 * print status of the message
888 */
889 pos += sprintf ( g_sa + pos, "%d,", stat );
890
891 #ifdef FF_ATI_BAT
892
893 /*
894 * Extracting the alphanumeric data from the phonebook at this point
895 * would defeat the object (testing the BAT message). Having this
896 * data stored globally represents a quick and dirty solution to the
897 * problem of conveying it here.
898 */
899 if (smsShrdPrm.alpha_len)
900 {
901 pos+=sprints(g_sa+pos,smsShrdPrm.alpha,smsShrdPrm.alpha_len);
902 }
903
904 #else
905
906 cmhSMS_getPhbEntry( mnsms_read_cnf->sms_sdu.buf, &alpha, stat);
907
908 /*
909 * print alpha if available
910 */
911 if ( alpha.len NEQ 0 )
912 {
913 utl_chsetFromGsm ( (UBYTE*)alpha.data,
914 alpha.len,
915 (UBYTE*)cvtdAlpha,
916 sizeof(cvtdAlpha),
917 &lenCvtdAlpha,
918 GSM_ALPHA_Def );
919 pos += sprints ( g_sa + pos, cvtdAlpha, lenCvtdAlpha );
920 }
921
922 #endif
923
924 /* length of SCA including length byte and TOA byte */
925 sca_len = mnsms_read_cnf->sms_sdu.buf[0] + 1;
926
927 data_ptr = &mnsms_read_cnf->sms_sdu.buf[sca_len];
928 fo = *data_ptr++;
929 length++;
930
931 if ((fo & TP_MTI_MASK) NEQ TP_MTI_SMS_STATUS_REP)
932 {
933 if ((fo & TP_MTI_MASK) EQ TP_MTI_SMS_SUBMIT)
934 {
935 /* SMS-SUBMIT */
936 data_ptr++;
937 length++;
938 vp_format = fo & TP_VPF_MASK;
939 }
940
941 addr_len = *data_ptr;
942 length += 4 + (addr_len+1)/2;
943
944 /* data_ptr points to TP-DCS now */
945 data_ptr += 3 + (addr_len+1)/2;
946
947 dcs = *data_ptr++;
948
949 switch (vp_format)
950 {
951 /*
952 * Check validity period format bit 4 and 3
953 */
954 case TP_VPF_NOT_PRESENT: // TP-VP not present
955 break;
956 case TP_VPF_RELATIVE: // TP-VP relative format
957 length++;
958 data_ptr++;
959 break;
960 case TP_VPF_ENHANCED: // TP-VP enhanced format
961 case TP_VPF_ABSOLUTE: // TP-VP absolute format
962 length += 7;
963 data_ptr += 7;
964 break;
965 }
966
967 /* data_ptr points to TP-UDL now,
968 * calculate the length excluding SCA octets
969 */
970 if (cmhSMS_getAlphabetPp (dcs) EQ 0)
971 length_sms = length + (*data_ptr * 7 + 7)/8 + 1; // 7 bit alphabet
972 else
973 length_sms = length + *data_ptr + 1;
974
975 pos += sprintf ( g_sa + pos, ",%d", length_sms );
976 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
977 pos = 0;
978 }
979 else
980 {
981 length_sms=((mnsms_read_cnf->sms_sdu.l_buf+7)/8);
982 pos += sprintf ( g_sa + pos, ",%d,", length_sms-sca_len );
983 sca_len = 0;
984 }
985
986 /*
987 * Print PDU + service centre address
988 */
989 for (i=0;i<(USHORT)(sca_len+length_sms);i++)
990 pos = GsmToHex (mnsms_read_cnf->sms_sdu.buf[i], g_sa, pos);
991
992 /*
993 * Send response
994 */
995 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
996 }
997 #endif
998
999 /*
1000 +--------------------------------------------------------------------+
1001 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1002 | STATE : code ROUTINE : rCI_PlusCMSSPdu |
1003 +--------------------------------------------------------------------+
1004
1005 PURPOSE : handles AT_PlusCMSS call back in PDU mode
1006
1007 */
1008
1009 GLOBAL void rCI_PlusCMSSPdu (T_MNSMS_SUBMIT_CNF * mnsms_submit_cnf)
1010 {
1011 USHORT pos = 0;
1012 UBYTE length;
1013 USHORT i;
1014 UBYTE srcId = srcId_cb;
1015 UBYTE sca_len;
1016 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1017
1018 TRACE_FUNCTION("rCI_PlusCMSSPdu()");
1019
1020 src_params->curAtCmd = AT_CMD_NONE;
1021
1022 pos=sprintf(g_sa,"+CMSS: %d", mnsms_submit_cnf->tp_mr);
1023
1024
1025 if (smsShrdPrm.CSMSservice EQ CSMS_SERV_GsmPh2Plus)
1026 {
1027 if (mnsms_submit_cnf->sms_sdu.l_buf)
1028 {
1029 pos+=sprintf(g_sa+pos, ",\""); /* parameter shall be bounded by double quote characters, see 07.07 <ackpdu> */
1030 sca_len = mnsms_submit_cnf->sms_sdu.buf[0] + 1;
1031 length = ((mnsms_submit_cnf->sms_sdu.l_buf+7)/8);
1032
1033 /*
1034 * Print ACK PDU (without SCA field)
1035 */
1036 for (i=sca_len; i<length; i++)
1037 pos = GsmToHex (mnsms_submit_cnf->sms_sdu.buf[i], g_sa, pos);
1038
1039 pos+=sprintf(g_sa+pos, "\"");
1040 }
1041 }
1042
1043 /*
1044 * Send response
1045 */
1046 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
1047 }
1048
1049 /*
1050 +--------------------------------------------------------------------+
1051 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1052 | STATE : code ROUTINE : rCI_PlusCMGSPdu |
1053 +--------------------------------------------------------------------+
1054
1055 PURPOSE : handles AT_PlusCMGS call back in PDU mode
1056
1057 */
1058
1059 GLOBAL void rCI_PlusCMGSPdu (T_MNSMS_SUBMIT_CNF * mnsms_submit_cnf)
1060 {
1061 USHORT pos = 0;
1062 UBYTE length;
1063 UBYTE srcId = srcId_cb;
1064 USHORT i;
1065 UBYTE sca_len;
1066 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1067
1068 TRACE_FUNCTION("rCI_PlusCMGSPdu()");
1069
1070
1071 src_params->curAtCmd = AT_CMD_NONE;
1072
1073 pos=sprintf(g_sa,"+CMGS: %d", mnsms_submit_cnf->tp_mr);
1074
1075
1076 if (smsShrdPrm.CSMSservice EQ CSMS_SERV_GsmPh2Plus)
1077 {
1078 if (mnsms_submit_cnf->sms_sdu.l_buf)
1079 {
1080 pos+=sprintf(g_sa+pos, ",\""); /* parameter shall be bounded by double quote characters, see 07.07 <ackpdu> */
1081 sca_len = mnsms_submit_cnf->sms_sdu.buf[0] + 1;
1082 length = ((mnsms_submit_cnf->sms_sdu.l_buf+7)/8);
1083
1084 /*
1085 * Print ACK PDU (without SCA field)
1086 */
1087 for (i=sca_len; i<length; i++)
1088 pos = GsmToHex (mnsms_submit_cnf->sms_sdu.buf[i], g_sa, pos);
1089
1090 pos+=sprintf(g_sa+pos, "\"");
1091 }
1092 }
1093
1094 /*
1095 * Send response
1096 */
1097 io_sendMessageEx( srcId, g_sa,
1098 ATI_NORMAL_OUTPUT |
1099 ATI_BEGIN_CRLF_OUTPUT |
1100 ATI_END_CRLF_OUTPUT);
1101
1102 }
1103
1104 /*
1105 +--------------------------------------------------------------------+
1106 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1107 | STATE : code ROUTINE : rCI_PlusCMGCPdu |
1108 +--------------------------------------------------------------------+
1109
1110 PURPOSE : handles AT_PlusCMGC call back in PDU mode
1111
1112 */
1113
1114 GLOBAL void rCI_PlusCMGCPdu (T_MNSMS_COMMAND_CNF * mnsms_command_cnf)
1115 {
1116 USHORT pos = 0;
1117 UBYTE length;
1118 UBYTE srcId = srcId_cb;
1119 USHORT i;
1120 UBYTE sca_len;
1121 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1122
1123 TRACE_FUNCTION("rCI_PlusCMGCPdu()");
1124
1125 src_params->curAtCmd = AT_CMD_NONE;
1126
1127 pos=sprintf(g_sa,"+CMGC: %d", mnsms_command_cnf->tp_mr);
1128
1129 if (smsShrdPrm.CSMSservice EQ CSMS_SERV_GsmPh2Plus)
1130 {
1131 if (mnsms_command_cnf->sms_sdu.l_buf)
1132 {
1133 pos+=sprintf(g_sa+pos, ",\""); /* parameter shall be bounded by double quote characters, see 07.07 <ackpdu> */
1134 sca_len = mnsms_command_cnf->sms_sdu.buf[0] + 1;
1135 length = ((mnsms_command_cnf->sms_sdu.l_buf+7)/8);
1136
1137 /*
1138 * Print ACK PDU (without SCA field)
1139 */
1140 for (i=sca_len; i<length; i++)
1141 pos = GsmToHex (mnsms_command_cnf->sms_sdu.buf[i], g_sa, pos);
1142
1143 pos+=sprintf(g_sa+pos, "\"");
1144 }
1145 }
1146
1147 /*
1148 * Send response
1149 */
1150 io_sendMessageEx( srcId, g_sa,
1151 ATI_NORMAL_OUTPUT |
1152 ATI_BEGIN_CRLF_OUTPUT |
1153 ATI_END_CRLF_OUTPUT);
1154 }
1155
1156 /*
1157 +--------------------------------------------------------------------+
1158 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1159 | STATE : code ROUTINE : rCI_PlusCMTPdu |
1160 +--------------------------------------------------------------------+
1161
1162 PURPOSE : handles AT_PlusCMT unsolicited message in PDU mode
1163
1164 */
1165
1166 #if defined (SMS_PDU_SUPPORT)
1167
1168 GLOBAL void rCI_PlusCMTPdu (T_MNSMS_MESSAGE_IND * mnsms_message_ind)
1169 {
1170 USHORT pos = 0;
1171 UBYTE l_sms_with_sca;
1172 UBYTE l_sms_without_sca;
1173 UBYTE srcId = srcId_cb;
1174
1175 #ifndef FF_ATI_BAT
1176 CHAR cvtdAlpha[2*MAX_ALPHA_LEN];
1177 USHORT lenCvtdAlpha;
1178 T_ACI_PB_TEXT alpha;
1179 T_ACI_SMS_STAT stat;
1180 #endif
1181
1182 USHORT i;
1183 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1184
1185 UBYTE sca_len = mnsms_message_ind->sms_sdu.buf[0] + 1;
1186
1187 TRACE_FUNCTION("rCI_PlusCMTPdu()");
1188
1189 src_params->curAtCmd = AT_CMD_NONE;
1190
1191 /*
1192 * print response for SMS message
1193 */
1194 pos = sprintf ( g_sa, "+CMT: ");
1195
1196 /*
1197 * print alpha if available
1198 */
1199 #ifdef FF_ATI_BAT
1200
1201 /*
1202 * Extracting the alphanumeric data from the phonebook at this point
1203 * would defeat the object (testing the BAT message). Having this
1204 * data stored globally represents a quick and dirty solution to the
1205 * problem of conveying it here.
1206 */
1207 if (smsShrdPrm.alpha_len)
1208 {
1209 pos+=sprints(g_sa+pos,smsShrdPrm.alpha,smsShrdPrm.alpha_len);
1210 }
1211
1212 #else
1213
1214 /* convert status from PSA type to CMH type */
1215 cmhSMS_getStatCmh ( mnsms_message_ind->status, &stat );
1216
1217 cmhSMS_getPhbEntry( mnsms_message_ind->sms_sdu.buf, &alpha, stat);
1218
1219
1220 if ( alpha.len NEQ 0 )
1221 {
1222 utl_chsetFromGsm ( (UBYTE*)alpha.data,
1223 alpha.len,
1224 (UBYTE*)cvtdAlpha,
1225 sizeof(cvtdAlpha),
1226 &lenCvtdAlpha,
1227 GSM_ALPHA_Def );
1228 pos += sprints ( g_sa + pos, cvtdAlpha, lenCvtdAlpha );
1229 }
1230
1231 #endif /*FF_ATI_BAT*/
1232
1233 l_sms_with_sca = ((mnsms_message_ind->sms_sdu.l_buf+7)/8);
1234 l_sms_without_sca = l_sms_with_sca - sca_len;
1235
1236 pos += sprintf ( g_sa + pos, ",%d", l_sms_without_sca );
1237 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1238
1239 pos = 0;
1240
1241 /*
1242 * Print PDU + service centre address field
1243 */
1244 for (i=0;i<(USHORT)l_sms_with_sca;i++)
1245 pos = GsmToHex (mnsms_message_ind->sms_sdu.buf[i], g_sa, pos);
1246
1247 /*
1248 * Send response
1249 */
1250 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1251
1252 }
1253 #endif
1254
1255 /*
1256 +--------------------------------------------------------------------+
1257 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1258 | STATE : code ROUTINE : rCI_PlusCBMPdu |
1259 +--------------------------------------------------------------------+
1260
1261 PURPOSE : handles Cell Broadcast unsolicited message in PDU mode
1262
1263 */
1264
1265 #if defined (SMS_PDU_SUPPORT)
1266
1267 GLOBAL void rCI_PlusCBMPdu (T_MMI_CBCH_IND * mmi_cbch_ind)
1268 {
1269 int i;
1270 USHORT pos = 0;
1271 UBYTE srcId = srcId_cb;
1272 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1273
1274 TRACE_FUNCTION("rCI_PlusCBMPdu()");
1275
1276 src_params->curAtCmd = AT_CMD_NONE;
1277
1278 /*
1279 * print response for CBM message
1280 */
1281 pos = sprintf ( g_sa, "+CBM: ");
1282 pos += sprintf ( g_sa + pos, "%d", (int)mmi_cbch_ind->cbch_len );
1283
1284 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1285
1286 pos = 0;
1287
1288 for (i = 0; i < (int)mmi_cbch_ind->cbch_len; i++)
1289 pos = GsmToHex (mmi_cbch_ind->cbch_msg[i], g_sa, pos);
1290
1291 io_sendMessageEx ( srcId, g_sa, ATI_INDICATION_OUTPUT +
1292 ATI_FORCED_OUTPUT +
1293 ATI_END_CRLF_OUTPUT );
1294
1295 }
1296 #endif
1297
1298
1299 #if defined (SMS_PDU_SUPPORT)
1300 /*
1301 +--------------------------------------------------------------------+
1302 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1303 | STATE : code ROUTINE : rCI_PlusCDSPdu |
1304 +--------------------------------------------------------------------+
1305
1306 PURPOSE : handles Status Indication unsolicited message in PDU mode
1307
1308 */
1309 GLOBAL void rCI_PlusCDSPdu (T_MNSMS_STATUS_IND * mnsms_status_ind)
1310 {
1311 USHORT pos = 0;
1312 UBYTE l_sms_with_sca;
1313 UBYTE l_sms_without_sca;
1314 UBYTE sca_len = mnsms_status_ind->sms_sdu.buf[0] + 1;
1315 USHORT i;
1316 UBYTE srcId = srcId_cb;
1317 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1318
1319
1320 TRACE_FUNCTION("rCI_PlusCDSPdu()");
1321
1322 src_params->curAtCmd = AT_CMD_NONE;
1323
1324 /*
1325 * print response for SMS message
1326 */
1327 pos = sprintf ( g_sa, "+CDS: ");
1328
1329 l_sms_with_sca = ((mnsms_status_ind->sms_sdu.l_buf+7)/8);
1330 l_sms_without_sca = l_sms_with_sca - sca_len;
1331
1332 pos += sprintf ( g_sa + pos, "%d", l_sms_without_sca );
1333
1334 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1335
1336 pos = 0;
1337
1338 /*
1339 * Print PDU + service centre address field
1340 */
1341 for (i=0;i<(USHORT)l_sms_with_sca;i++)
1342 pos = GsmToHex (mnsms_status_ind->sms_sdu.buf[i], g_sa, pos);
1343
1344 /*
1345 * Send response
1346 */
1347 io_sendMessageEx ( srcId, g_sa, ATI_INDICATION_OUTPUT +
1348 ATI_FORCED_OUTPUT +
1349 ATI_END_CRLF_OUTPUT );
1350
1351 }
1352 #endif /* SMS_PDU_SUPPORT */
1353
1354
1355
1356 /*
1357 +--------------------------------------------------------------------+
1358 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1359 | STATE : code ROUTINE : HexMessage |
1360 +--------------------------------------------------------------------+
1361
1362 PURPOSE : converts a sms message to HEX and fill it into a buffer.
1363
1364 */
1365
1366 /* does not seem to be used */
1367 /*GLOBAL USHORT HexMessage (T_ACI_SM_DATA * data, UBYTE length, char * buffer, USHORT pos)
1368 {
1369 int i;
1370
1371 pos = GsmToHex (data->len, buffer, pos);
1372
1373 for (i=0;i<(int)length;i++)
1374 pos = GsmToHex (data->data[i], buffer, pos);
1375
1376 return pos;
1377 } */
1378
1379
1380 /*
1381 +--------------------------------------------------------------------+
1382 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1383 | STATE : code ROUTINE : HexScts |
1384 +--------------------------------------------------------------------+
1385
1386 PURPOSE : converts a service centre timestamp to HEX and fill it into a buffer.
1387
1388 */
1389
1390 /* doesn't seem to be used... */
1391 /*GLOBAL USHORT HexScts (T_ACI_VP_ABS * scts, char * buffer, USHORT pos)
1392 {
1393 UBYTE tz;
1394
1395 TRACE_EVENT_P1("TZ =%x", scts->timezone);
1396
1397 pos = GsmToHex ((UBYTE)((scts->year[1]<<4)+scts->year[0]),
1398 buffer, pos);
1399 pos = GsmToHex ((UBYTE)((scts->month[1]<<4)+scts->month[0]),
1400 buffer, pos);
1401 pos = GsmToHex ((UBYTE)((scts->day[1]<<4)+scts->day[0]),
1402 buffer, pos);
1403 pos = GsmToHex ((UBYTE)((scts->hour[1]<<4)+scts->hour[0]),
1404 buffer, pos);
1405 pos = GsmToHex ((UBYTE)((scts->minute[1]<<4)+scts->minute[0]),
1406 buffer, pos);
1407 pos = GsmToHex ((UBYTE)((scts->second[1]<<4)+scts->second[0]),
1408 buffer, pos);
1409
1410 tz = cmhSMS_setTimezone(scts->timezone);
1411 pos = GsmToHex (tz, buffer, pos);
1412
1413 return pos;
1414 }*/
1415
1416
1417 /*
1418 +--------------------------------------------------------------------+
1419 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1420 | STATE : code ROUTINE : GsmToHex |
1421 +--------------------------------------------------------------------+
1422
1423 PURPOSE : converts a GSM character to HEX and fill it into a buffer.
1424
1425 */
1426
1427 GLOBAL USHORT GsmToHex (UBYTE in, char * buffer, USHORT pos)
1428 {
1429 const UBYTE hexVal[17] = {"0123456789ABCDEF"};
1430
1431 buffer[pos] = hexVal[ in >> 4 ];
1432 buffer[pos+1] = hexVal[ in & 0x0F ];
1433 buffer[pos+2] = '\0';
1434 return pos+2;
1435 }
1436
1437 /*
1438 +--------------------------------------------------------------------+
1439 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1440 | STATE : code ROUTINE : HexAdress |
1441 +--------------------------------------------------------------------+
1442
1443 PURPOSE : converts a adress to HEX and fill it into a buffer.
1444
1445 */
1446
1447 #if 0
1448 GLOBAL USHORT HexAdress (CHAR * adress, UBYTE ton, UBYTE npi, char * buffer, USHORT pos)
1449 {
1450 int i;
1451 int len;
1452
1453 len = (strlen (adress)+1)/2;
1454
1455 pos = GsmToHex ((UBYTE)(len+1), buffer, pos);
1456
1457 pos = GsmToHex ((UBYTE)(0x80 + (ton<<4) + npi), buffer, pos);
1458
1459 for (i=0;i<len;i++)
1460 {
1461 if (i EQ len-1)
1462 {
1463 /*
1464 * last two digits
1465 */
1466 if (strlen(adress) & 1)
1467 {
1468 pos = GsmToHex ((UBYTE)(0xF0 + (adress[2*i] - 0x30)), buffer, pos);
1469 continue;
1470 }
1471 }
1472 pos = GsmToHex ((UBYTE)(((adress [2*i+1]-0x30) << 4) +
1473 (adress [2*i] - 0x30)), buffer, pos);
1474 }
1475 return pos;
1476 }
1477 #endif /* 0 */
1478
1479 /*
1480 +--------------------------------------------------------------------+
1481 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1482 | STATE : code ROUTINE : HexAdressTP |
1483 +--------------------------------------------------------------------+
1484
1485 PURPOSE : converts a adress to HEX and fill it into a buffer for TP-adresses.
1486
1487 */
1488
1489 #if 0
1490 GLOBAL USHORT HexAdressTP (CHAR * adress, UBYTE ton, UBYTE npi, char * buffer, USHORT pos)
1491 {
1492 int i;
1493 int len;
1494
1495 len = (strlen (adress)+1)/2;
1496
1497 if ( ton EQ 0x05 AND strlen (adress) NEQ 4 ) /* PATCH VO - if (patch) else ... */
1498 pos = GsmToHex ((UBYTE)(strlen (adress) * 2), g_sa, pos);
1499 else
1500 pos = GsmToHex ((UBYTE)strlen(adress), g_sa, pos);
1501
1502 pos = GsmToHex ((UBYTE)(0x80 + (ton<<4) + npi), g_sa, pos);
1503
1504 if ( ton EQ 0x05 AND strlen (adress) NEQ 4 ) /* PATCH VO - if (patch) else ... */
1505 {
1506 for (i=0;i<(int)strlen (adress);i++)
1507 pos = GsmToHex ((UBYTE)adress[i], g_sa, pos);
1508 }
1509 else
1510 {
1511 for (i=0;i<len;i++)
1512 {
1513 if (i EQ len-1)
1514 {
1515 /*
1516 * last two digits
1517 */
1518 if (strlen(adress) & 1)
1519 {
1520 pos = GsmToHex ((UBYTE)(0xF0 + (adress[2*i] - 0x30)), g_sa, pos);
1521 continue;
1522 }
1523 }
1524 pos = GsmToHex ((UBYTE)(((adress [2*i+1]-0x30) << 4) + (adress [2*i] - 0x30)),
1525 g_sa, pos);
1526 }
1527 }
1528 return pos;
1529 }
1530 #endif /* 0 */
1531 /*
1532 +--------------------------------------------------------------------+
1533 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1534 | STATE : code ROUTINE : HexToGsm |
1535 +--------------------------------------------------------------------+
1536
1537 PURPOSE : converts a HEX value to the GSM character.
1538
1539 */
1540
1541 GLOBAL char * HexToGsm (char * cl, UBYTE * value)
1542 {
1543 int i;
1544 UBYTE character;
1545
1546 /*
1547 * initialise the output value
1548 */
1549 *value = 0;
1550
1551 /*
1552 * for both nibbles
1553 */
1554 for (i=0;i<2;i++)
1555 {
1556 /*
1557 * shift the result of the last loop
1558 */
1559 *value = (*value) << 4;
1560
1561 /*
1562 * Isolate next nibble in ASCII
1563 */
1564 character = toupper(*cl++);
1565
1566 /*
1567 * convert Nibble character to value
1568 */
1569 switch (character)
1570 {
1571 case 'A':
1572 case 'B':
1573 case 'C':
1574 case 'D':
1575 case 'E':
1576 case 'F':
1577 *value = *value + (character - 'A' + 10);
1578 break;
1579 default:
1580 /*
1581 * 0-9
1582 */
1583 *value = *value + (character - '0');
1584 break;
1585 }
1586 }
1587
1588 /*
1589 * return pointer to the rest of PDU
1590 */
1591 return cl;
1592 }
1593
1594 /*
1595 +--------------------------------------------------------------------+
1596 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1597 | STATE : code ROUTINE : GSMAddress |
1598 +--------------------------------------------------------------------+
1599
1600 PURPOSE : converts a adress coded with HEX values to the internal
1601 data structures.
1602
1603 */
1604
1605 /* does not seem to be used */
1606 #if 0
1607 GLOBAL char * GSMAddress (char * cl, char * address, T_ACI_TOA *tosca)
1608 {
1609 int i, j;
1610 UBYTE value;
1611 UBYTE len;
1612 UBYTE digit;
1613
1614 /*
1615 * calculate the number of octets which are used for the address
1616 */
1617
1618 cl = HexToGsm (cl, &value);
1619 if (value EQ 0) /* SCA not given */
1620 {
1621 address[0] = 0;
1622 return cl;
1623 }
1624 len = value - 1;
1625
1626 /*
1627 * check against maximum value
1628 */
1629 if (len > MAX_SMS_ADDR_DIG/2)
1630 {
1631 pdu_error_detected = TRUE;
1632 return cl;
1633 }
1634
1635 /*
1636 * calculate the type of number and numbering plan identification
1637 */
1638 cl = HexToGsm (cl, &value);
1639
1640 tosca->ton = (value >> 4) & 7;
1641 tosca->npi = value & 0x0F;
1642
1643
1644 /*
1645 * convert the digits
1646 */
1647 j = 0;
1648 for (i = 0; i < (int)len; i++)
1649 {
1650 cl = HexToGsm (cl, &value);
1651
1652 /*
1653 * check digit n
1654 */
1655 address[j++] = (value & 0x0F) + 0x30;
1656 /*
1657 * check digit n+1
1658 */
1659 digit = (value >> 4) & 0x0F;
1660 if (digit < 10)
1661 address[j++] = digit + 0x30;
1662 }
1663 /*
1664 * string termination
1665 */
1666 address[j] = 0;
1667
1668 /*
1669 * return pointer to the rest of the PDU
1670 */
1671 return cl;
1672 }
1673 #endif /* 0 */
1674 /*
1675 +--------------------------------------------------------------------+
1676 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1677 | STATE : code ROUTINE : GSMAddressTP |
1678 +--------------------------------------------------------------------+
1679
1680 PURPOSE : converts a TP-adress coded with HEX values to the internal
1681 data structures.
1682
1683 */
1684
1685 /* does not seem to be used */
1686 #if 0
1687 GLOBAL char * GSMAddressTP (char * cl, char * address, T_ACI_TOA *toda)
1688 {
1689 int i, j;
1690 UBYTE value;
1691 UBYTE len;
1692 UBYTE digit;
1693
1694 /*
1695 * calculate the number of octets which are used for the address
1696 */
1697 cl = HexToGsm (cl, &value);
1698 len = (value + 1)/2;
1699
1700 /*
1701 * check against maximum value
1702 */
1703 if (len > MAX_SMS_ADDR_DIG/2)
1704 {
1705 pdu_error_detected = TRUE;
1706 return cl;
1707 }
1708 /*
1709 * calculate the type of number and numbering plan identification
1710 */
1711 cl = HexToGsm (cl, &value);
1712
1713 toda->ton = (value >> 4) & 7;
1714 toda->npi = value & 0x0F;
1715
1716 /*
1717 * convert the digits
1718 */
1719 j = 0;
1720 for (i=0;i<(int)len;i++)
1721 {
1722 cl = HexToGsm (cl, &value);
1723
1724 /*
1725 * check digit n
1726 */
1727 address[j++] = (value & 0x0F) + 0x30;
1728 /*
1729 * check digit n+1
1730 */
1731 digit = (value >> 4) & 0x0F;
1732 if (digit < 10)
1733 address[j++] = digit + 0x30;
1734 }
1735 /*
1736 * string termination
1737 */
1738 address[j] = 0;
1739
1740 /*
1741 * return pointer to the rest of the PDU
1742 */
1743 return cl;
1744 }
1745 #endif /* 0 */
1746
1747 /*
1748 +--------------------------------------------------------------------+
1749 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1750 | STATE : code ROUTINE : GSMMessage |
1751 +--------------------------------------------------------------------+
1752
1753 PURPOSE : converts a sms message from HEX and fill it into a buffer.
1754
1755 */
1756
1757 #if 0
1758 GLOBAL char *GSMMessage (char *cl, UBYTE *data, SHORT oct_length, SHORT max_length)
1759 {
1760 SHORT i;
1761
1762 /*
1763 * check against maximum value
1764 */
1765 if (oct_length > max_length)
1766 {
1767 pdu_error_detected = TRUE;
1768 return cl;
1769 }
1770 memset (data, 0, max_length);
1771
1772 /*
1773 * copy message
1774 */
1775 for (i = 0; i < oct_length; i++)
1776 cl = HexToGsm (cl, &data[i]);
1777
1778 return cl;
1779 }
1780 #endif /* 0 */
1781
1782 #endif
1783
1784 #endif /* ATI_PDU_C */