comparison gsm-fw/g23m-aci/aci/ati_pdu.c @ 775:eedbf248bac0

gsm-fw/g23m-aci subtree: initial import from LoCosto source
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 12 Oct 2014 01:45:14 +0000
parents
children 09382de17df9
comparison
equal deleted inserted replaced
774:40a721fd9854 775:eedbf248bac0
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 ( (T_ACI_CMD_SRC)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 T_ACI_SM_DATA pdu = {0};
258 T_ACI_RETURN ret = AT_FAIL;
259 UBYTE pdu_message_octets_lenth = 0;
260 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
261
262
263
264
265 TRACE_FUNCTION("atPlusCNMAPdu()");
266
267
268
269 if (src_params->text_mode EQ CMD_MODE)
270 {
271 /*
272 * normal command line
273 */
274 if (*cl EQ '\0')
275 {
276 /*
277 * no parameters, like text mode
278 */
279 n = 1;
280 }
281 else
282 {
283 /*
284 * Extract the acknowledge parameter n
285 */
286 length_of_pdu_message = 0;
287 cl = parse(cl,"rr",&n, &length_of_pdu_message);
288 if ( !cl)
289 {
290 cmdCmsError(CMS_ERR_OpNotAllowed);
291 return (ATI_FAIL);
292 }
293
294
295
296 switch (n)
297 {
298 case -1:
299 case 0:
300 case 1:
301 n = 1;
302 if (length_of_pdu_message)
303 {
304 src_params->text_mode = TXT_MODE;
305 return (ATI_EXCT);
306 }
307 break;
308 case 2:
309 if (length_of_pdu_message)
310 {
311 src_params->text_mode = TXT_MODE;
312 return (ATI_EXCT);
313 }
314 break;
315 default:
316 cmdCmsError(CMS_ERR_OpNotAllowed);
317 return (ATI_FAIL);
318 }
319 }
320 } /* end of if (src_params->text_mode EQ CMD_MODE) */
321 else
322 {
323 src_params->text_mode = CMD_MODE;
324
325 /*
326 calculation of the real length of PDU string
327
328 The entering of PDU is done similarly as specified in command Send Message +CMGS,
329 except that the format of <ackpdu> is used instead of <pdu>
330 (i.e. SMSC address field is not present).
331
332 so here, the length of the input needs to divide 2.
333 */
334
335
336 pdu_message_octets_lenth = strlen(cl)/2;
337
338 TRACE_EVENT_P1("pdu_message_octets_lenth == %d",pdu_message_octets_lenth);
339
340 if(pdu_message_octets_lenth NEQ length_of_pdu_message)
341 {
342 cmdCmsError (CMS_ERR_OpNotAllowed);
343 TRACE_EVENT("ERROR: input pdu message length do not match the real length!");
344 return (ATI_FAIL);
345 }
346
347 /*
348 * Input line with pdu is given
349 */
350 pdu_error_detected = FALSE;
351 /*
352 * get the message type
353 */
354 HexToGsm (cl, &msg_type);
355
356 if ((msg_type & 3) EQ 0) // SMS_DELIVER_REPORT
357 {
358 int i;
359 pdu.len = (UBYTE)length_of_pdu_message;
360 for (i=0; i<length_of_pdu_message; i++)
361 {
362 cl = HexToGsm (cl, &pdu.data[i]);
363 }
364 }
365 else
366 pdu_error_detected = TRUE;
367
368 if (pdu_error_detected)
369 {
370 cmdCmsError ( CMS_ERR_InValPduMod );
371 return (ATI_FAIL);
372 }
373 }
374
375
376
377 /*
378 * send the SMS command using extracted values
379 */
380 ret = sAT_PlusCNMAPdu ((T_ACI_CMD_SRC)srcId, n, &pdu);
381 switch(ret)
382 {
383 case AT_FAIL:
384 cmdCmsError (CMS_ERR_NotPresent); // use aciErrDesc
385 /*
386 * no break
387 */
388 /*lint -fallthrough */
389 case AT_CMPL:
390 break;
391 default:
392 TRACE_EVENT("atPlusCNMAPdu() : Error !! Not AT_FAIL or AT_COMPL");
393 break;
394 }
395 return (map_aci_2_ati_rslt(ret));
396 }
397 #endif
398
399
400 /*
401 +--------------------------------------------------------------------+
402 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
403 | STATE : code ROUTINE : atPlusCMGWPdu |
404 +--------------------------------------------------------------------+
405
406 PURPOSE : +CMGW command (Write message to memory) in PDU mode.
407 */
408
409 #if defined (SMS_PDU_SUPPORT)
410
411 GLOBAL T_ATI_RSLT atPlusCMGWPdu (char *cl, UBYTE srcId)
412 {
413 T_ACI_SMS_STAT stat;
414 T_ACI_RETURN ret = AT_FAIL;
415 static UBYTE message_status = NOT_PRESENT_8BIT;
416 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
417 T_ACI_SM_DATA pdu;
418 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
419
420 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
421
422 TRACE_FUNCTION("atPlusCMGWPdu()");
423
424 if (src_params->text_mode EQ CMD_MODE)
425 {
426 /*
427 * normal command line
428 */
429 stat = SMS_STAT_StoUnsent; /* STO UNSENT as default */
430 /*
431 * Extract the length and status to be parsed from the input pointer cl
432 */
433 cl = parse(cl,"rd",&length_of_pdu_message,&stat);
434 if ( !cl OR length_of_pdu_message EQ 0)
435 {
436 cmdCmsError(CMS_ERR_OpNotAllowed);
437 return (ATI_FAIL);
438 }
439
440 if (stat < SMS_STAT_RecUnread OR stat > SMS_STAT_All)
441 {
442 cmdCmsError(CMS_ERR_OpNotAllowed);
443 return (ATI_FAIL);
444 }
445 else
446 {
447 message_status = (UBYTE)stat;
448 }
449 /*
450 * wait for next input containing the PDU_is_given
451 */
452 src_params->text_mode = TXT_MODE;
453 return (ATI_EXCT);
454 } /* end of if (src_params->text_mode EQ CMD_MODE) */
455 else
456 {
457 UBYTE offset = 0;
458 UBYTE sca_len;
459 UBYTE i;
460 UBYTE pdu_message_octets_lenth = 0;
461
462 src_params->text_mode = CMD_MODE;
463 /*
464 * Input line with pdu is given
465 */
466
467 /* if the character sent is ESC, then abort command CLB 16.11.00 */
468 if (*cl EQ 0x1B)
469 {
470 TRACE_EVENT("Send message command cancelled by user");
471
472 return ATI_CMPL_NO_OUTPUT;
473 }
474
475 pdu_error_detected = FALSE;
476
477 HexToGsm (cl, &sca_len);
478
479 if (sca_len > ((MAX_SMS_ADDR_DIG+1)/2) + 1)
480 {
481 TRACE_ERROR("SCA too long !!!");
482 cmdCmsError(CMS_ERR_OpNotAllowed);
483 return (ATI_FAIL);
484 }
485
486 /*
487 calculation of the real length of PDU string
488
489 The first octet in the input is an indicator of the length of the SMSC information supplied.
490
491 And this Octet and the SMSC content do not count in the real length of PDU string.
492
493 so here, the length of the input needs to minus 2 + sca_len*2 and then divide 2.
494 */
495 pdu_message_octets_lenth = (strlen(cl)-2-sca_len*2)/2;
496
497 TRACE_EVENT_P1("pdu_message_octets_lenth == %d",pdu_message_octets_lenth);
498
499 if(pdu_message_octets_lenth NEQ length_of_pdu_message)
500 {
501 cmdCmsError (CMS_ERR_OpNotAllowed);
502 TRACE_EVENT("ERROR: input pdu message length do not match the real length!");
503 return (ATI_FAIL);
504 }
505
506
507 if (sca_len EQ 0) /* no SCA given */
508 {
509 offset = CodeRPAddress(pdu.data,
510 pSMSSetPrm -> sca.c_num,
511 pSMSSetPrm -> sca.ton,
512 pSMSSetPrm -> sca.npi,
513 pSMSSetPrm -> sca.num);
514 cl += 2;
515 pdu.len = length_of_pdu_message + offset;
516 }
517 else
518 {
519 pdu.len = length_of_pdu_message + sca_len + 1;
520 }
521
522 for (i=offset; i<pdu.len AND *cl NEQ '\0' AND i<MAX_SM_LEN; i++)
523 {
524 cl = HexToGsm (cl, &pdu.data[i]);
525 }
526
527 ret = sAT_PlusCMGWPdu ( (T_ACI_CMD_SRC)srcId, message_status, &pdu);
528
529 if ( ret NEQ AT_EXCT )
530 {
531 cmdCmsError (CMS_ERR_NotPresent); // use aciErrDesc
532 return (ATI_FAIL);
533 }
534 /*
535 * rCI_OK will emitting +CMGW: <index>
536 */
537 src_params->curAtCmd = AT_CMD_CMGW;
538 return ATI_EXCT;
539 }
540 }
541 #endif
542
543 /*
544 +--------------------------------------------------------------------+
545 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
546 | STATE : code ROUTINE : atPlusCMGCPdu |
547 +--------------------------------------------------------------------+
548
549 PURPOSE : +CMGC command (Send SMS command) in PDU mode
550 */
551
552 #if defined (SMS_PDU_SUPPORT)
553
554 GLOBAL T_ATI_RSLT atPlusCMGCPdu (char *cl, UBYTE srcId)
555 {
556 T_ACI_RETURN ret = AT_FAIL;
557 T_ACI_SM_DATA pdu;
558 T_SMS_SET_PRM *pSMSSetPrm; /* points to SMS parameter set */
559 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
560
561 pSMSSetPrm = smsShrdPrm.pSetPrm[srcId];
562
563 pdu.len = 0;
564
565 TRACE_FUNCTION("atPlusCMGCPdu()");
566
567 if (src_params->text_mode EQ CMD_MODE)
568 {
569 /*
570 * normal command line
571 */
572 /*
573 * Extract the length to be parsed from the input pointer cl
574 */
575 cl = parse(cl,"r",&length_of_pdu_message);
576 if ( !cl OR length_of_pdu_message EQ 0)
577 {
578 cmdCmsError(CMS_ERR_OpNotAllowed);
579 return (ATI_FAIL);
580 }
581 /*
582 * wait for next input containing the PDU_is_given
583 */
584 src_params->text_mode = TXT_MODE;
585 return (ATI_EXCT);
586 } /* end of if (src_params->text_mode EQ CMD_MODE) */
587 else
588 {
589 UBYTE offset = 0;
590 UBYTE sca_len;
591 UBYTE i;
592 UBYTE pdu_message_octets_lenth = 0;
593
594 src_params->text_mode = CMD_MODE;
595 /*
596 * Input line with pdu is given
597 */
598
599 pdu_error_detected = FALSE;
600
601 HexToGsm (cl, &sca_len);
602
603 if (sca_len > ((MAX_SMS_ADDR_DIG+1)/2) + 1)
604 {
605 TRACE_ERROR("SCA too long !!!");
606 cmdCmsError(CMS_ERR_OpNotAllowed);
607 return (ATI_FAIL);
608 }
609
610 /*
611 calculation of the real length of PDU string
612
613 The first octet in the input is an indicator of the length of the SMSC information supplied.
614
615 And this Octet and the SMSC content do not count in the real length of PDU string.
616
617 so here, the length of the input needs to minus 2 + sca_len*2 and then divide 2.
618 */
619 pdu_message_octets_lenth = (strlen(cl)-2-sca_len*2)/2;
620
621 TRACE_EVENT_P1("pdu_message_octets_lenth == %d",pdu_message_octets_lenth);
622
623 if(pdu_message_octets_lenth NEQ length_of_pdu_message)
624 {
625 cmdCmsError (CMS_ERR_OpNotAllowed);
626 TRACE_EVENT("ERROR: input pdu message length do not match the real length!");
627 return (ATI_FAIL);
628 }
629
630 if (sca_len EQ 0) /* no SCA given */
631 {
632 offset = CodeRPAddress(pdu.data,
633 pSMSSetPrm -> sca.c_num,
634 pSMSSetPrm -> sca.ton,
635 pSMSSetPrm -> sca.npi,
636 pSMSSetPrm -> sca.num);
637 cl += 2;
638 pdu.len = length_of_pdu_message + offset;
639 }
640 else
641 {
642 pdu.len = length_of_pdu_message + sca_len + 1;
643 }
644
645 for (i=offset; i<pdu.len AND *cl NEQ '\0' AND i<MAX_SM_LEN; i++)
646 {
647 cl = HexToGsm (cl, &pdu.data[i]);
648 }
649
650 ret = sAT_PlusCMGCPdu ((T_ACI_CMD_SRC)srcId, &pdu);
651
652 if ( ret NEQ AT_EXCT )
653 {
654 cmdCmsError (CMS_ERR_NotPresent); // use aciErrDesc
655 return (ATI_FAIL);
656 }
657 /*
658 * rCI_OK will emitting +CMGC: <mr>[,<ackpdu>]
659 */
660 src_params->curAtCmd = AT_CMD_CMGC;
661 return ATI_EXCT;
662 }
663 }
664 #endif
665
666 /*
667 +--------------------------------------------------------------------+
668 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
669 | STATE : code ROUTINE : rCI_PlusCMGLPdu |
670 +--------------------------------------------------------------------+
671
672 PURPOSE : handles AT_PlusCMGL call back in PDU mode
673
674 */
675
676 #if defined (SMS_PDU_SUPPORT)
677
678 GLOBAL void rCI_Plus_Percent_CMGLPdu ( T_MNSMS_READ_CNF *mnsms_read_cnf,
679 T_ACI_AT_CMD cmd )
680 {
681 T_ACI_SMS_STAT stat;
682
683 USHORT i = 0;
684 USHORT pos = 0;
685 UBYTE sca_len;
686 UBYTE length_sms, length=0;
687 UBYTE fo, addr_len, dcs, vp_format=TP_VPF_ABSOLUTE;
688 UBYTE *data_ptr;
689
690 UBYTE srcId = srcId_cb;
691
692 #ifndef FF_ATI_BAT
693 CHAR cvtdAlpha[2*MAX_ALPHA_LEN];
694 USHORT lenCvtdAlpha;
695 T_ACI_PB_TEXT alpha;
696 #endif
697
698 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
699
700 TRACE_FUNCTION("rCI_Plus_Percent_CMGLPdu()");
701
702 src_params->curAtCmd = AT_CMD_NONE;
703
704 /* convert status from PSA type to CMH type */
705 cmhSMS_getStatCmh ( mnsms_read_cnf->status, &stat );
706
707 /*
708 * print response and index, status of SMS message
709 */
710 if (cmd EQ AT_CMD_CMGL )
711 {
712 pos = sprintf ( g_sa, "+CMGL: ");
713 }
714 else
715 {
716 pos=sprintf (g_sa, " %s: ", "%CMGL");
717 }
718 pos += sprintf ( g_sa + pos, "%d,%d,", mnsms_read_cnf->rec_num, stat);
719
720 #ifdef FF_ATI_BAT
721
722 /*
723 * Extracting the alphanumeric data from the phonebook at this point
724 * would defeat the object (testing the BAT message). Having this
725 * data stored globally represents an easier solution to the
726 * problem of conveying it here.
727 */
728 if (smsShrdPrm.alpha_len)
729 {
730 pos+=sprints(g_sa+pos,smsShrdPrm.alpha,smsShrdPrm.alpha_len);
731 }
732
733 #else
734
735 cmhSMS_getPhbEntry( mnsms_read_cnf->sms_sdu.buf, &alpha, stat);
736
737 /*
738 * print alpha if available
739 */
740 if ( alpha.len NEQ 0 )
741 {
742 utl_chsetFromGsm ( (UBYTE*)alpha.data,
743 alpha.len,
744 (UBYTE*)cvtdAlpha,
745 sizeof(cvtdAlpha),
746 &lenCvtdAlpha,
747 GSM_ALPHA_Def );
748 pos += sprints ( g_sa + pos, cvtdAlpha, lenCvtdAlpha );
749 }
750
751 #endif /*FF_ATI_BAT*/
752
753 /* length of SCA including length byte and TOA byte */
754 sca_len = mnsms_read_cnf->sms_sdu.buf[0] + 1;
755
756 data_ptr = &mnsms_read_cnf->sms_sdu.buf[sca_len];
757 fo = *data_ptr++;
758 length++;
759
760 if ((fo & TP_MTI_MASK) NEQ TP_MTI_SMS_STATUS_REP)
761 {
762 if ((fo & TP_MTI_MASK) EQ TP_MTI_SMS_SUBMIT)
763 {
764 /* SMS-SUBMIT */
765 data_ptr++;
766 length++;
767 vp_format = fo & TP_VPF_MASK;
768 }
769
770 addr_len = *data_ptr;
771 length += 4 + (addr_len+1)/2;
772
773 /* data_ptr points to TP-DCS now */
774 data_ptr += 3 + (addr_len+1)/2;
775
776 dcs = *data_ptr++;
777
778 switch (vp_format)
779 {
780 /*
781 * Check validity period format bit 4 and 3
782 */
783 case TP_VPF_NOT_PRESENT: // TP-VP not present
784 break;
785 case TP_VPF_RELATIVE: // TP-VP relative format
786 length++;
787 data_ptr++;
788 break;
789 case TP_VPF_ENHANCED: // TP-VP enhanced format
790 case TP_VPF_ABSOLUTE: // TP-VP absolute format
791 length += 7;
792 data_ptr += 7;
793 break;
794 }
795
796 /* data_ptr points to TP-UDL now,
797 * calculate the length excluding SCA octets
798 */
799 if (cmhSMS_getAlphabetPp (dcs) EQ 0)
800 length_sms = length + (*data_ptr * 7 + 7)/8 + 1; // 7 bit alphabet
801 else
802 length_sms = length + *data_ptr + 1;
803
804 pos += sprintf ( g_sa + pos, ",%d", length_sms );
805 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
806 pos = 0;
807 }
808 else
809 {
810 length_sms=((mnsms_read_cnf->sms_sdu.l_buf+7)/8);
811 pos += sprintf ( g_sa + pos, ",%d,", length_sms-sca_len );
812 sca_len = 0;
813 }
814
815 /*
816 * Print PDU + service centre address
817 */
818 for (i=0;i<(USHORT)(sca_len+length_sms);i++)
819 pos = GsmToHex (mnsms_read_cnf->sms_sdu.buf[i], g_sa, pos);
820
821 /*
822 * Send response
823 */
824 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
825 }
826
827 /*
828 +--------------------------------------------------------------------+
829 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
830 | STATE : code ROUTINE : rCI_PlusCMGRPdu |
831 +--------------------------------------------------------------------+
832
833 PURPOSE : handles AT_PlusCMGR call back in PDU mode
834
835 */
836
837 #if defined (SMS_PDU_SUPPORT)
838
839 GLOBAL void rCI_Plus_Percent_CMGRPdu (T_MNSMS_READ_CNF * mnsms_read_cnf,
840 T_ACI_AT_CMD cmd)
841 {
842 USHORT pos = 0;
843 T_ACI_SMS_STAT stat;
844 USHORT i;
845
846 UBYTE sca_len;
847 UBYTE length_sms, length=0;
848 UBYTE fo, addr_len, dcs, vp_format=TP_VPF_ABSOLUTE;
849 UBYTE *data_ptr;
850
851 UBYTE srcId = srcId_cb;
852
853 #ifndef FF_ATI_BAT
854 CHAR cvtdAlpha[2*MAX_ALPHA_LEN];
855 USHORT lenCvtdAlpha;
856 T_ACI_PB_TEXT alpha;
857 #endif
858
859 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
860
861 TRACE_FUNCTION("rCI_Plus_Percent_CMGRPdu()");
862
863 src_params->curAtCmd = AT_CMD_NONE;
864
865 /*
866 * print response for SMS message
867 */
868 if (cmd EQ AT_CMD_CMGR)
869 {
870 pos = sprintf ( g_sa, "+CMGR: ");
871 }
872 else
873 {
874 pos=sprintf (g_sa, " %s: ", "%CMGR");
875 }
876
877 /* convert status from PSA type to CMH type */
878 cmhSMS_getStatCmh ( mnsms_read_cnf->status, &stat );
879
880 /*
881 * print status of the message
882 */
883 pos += sprintf ( g_sa + pos, "%d,", stat );
884
885 #ifdef FF_ATI_BAT
886
887 /*
888 * Extracting the alphanumeric data from the phonebook at this point
889 * would defeat the object (testing the BAT message). Having this
890 * data stored globally represents a quick and dirty solution to the
891 * problem of conveying it here.
892 */
893 if (smsShrdPrm.alpha_len)
894 {
895 pos+=sprints(g_sa+pos,smsShrdPrm.alpha,smsShrdPrm.alpha_len);
896 }
897
898 #else
899
900 cmhSMS_getPhbEntry( mnsms_read_cnf->sms_sdu.buf, &alpha, stat);
901
902 /*
903 * print alpha if available
904 */
905 if ( alpha.len NEQ 0 )
906 {
907 utl_chsetFromGsm ( (UBYTE*)alpha.data,
908 alpha.len,
909 (UBYTE*)cvtdAlpha,
910 sizeof(cvtdAlpha),
911 &lenCvtdAlpha,
912 GSM_ALPHA_Def );
913 pos += sprints ( g_sa + pos, cvtdAlpha, lenCvtdAlpha );
914 }
915
916 #endif
917
918 /* length of SCA including length byte and TOA byte */
919 sca_len = mnsms_read_cnf->sms_sdu.buf[0] + 1;
920
921 data_ptr = &mnsms_read_cnf->sms_sdu.buf[sca_len];
922 fo = *data_ptr++;
923 length++;
924
925 if ((fo & TP_MTI_MASK) NEQ TP_MTI_SMS_STATUS_REP)
926 {
927 if ((fo & TP_MTI_MASK) EQ TP_MTI_SMS_SUBMIT)
928 {
929 /* SMS-SUBMIT */
930 data_ptr++;
931 length++;
932 vp_format = fo & TP_VPF_MASK;
933 }
934
935 addr_len = *data_ptr;
936 length += 4 + (addr_len+1)/2;
937
938 /* data_ptr points to TP-DCS now */
939 data_ptr += 3 + (addr_len+1)/2;
940
941 dcs = *data_ptr++;
942
943 switch (vp_format)
944 {
945 /*
946 * Check validity period format bit 4 and 3
947 */
948 case TP_VPF_NOT_PRESENT: // TP-VP not present
949 break;
950 case TP_VPF_RELATIVE: // TP-VP relative format
951 length++;
952 data_ptr++;
953 break;
954 case TP_VPF_ENHANCED: // TP-VP enhanced format
955 case TP_VPF_ABSOLUTE: // TP-VP absolute format
956 length += 7;
957 data_ptr += 7;
958 break;
959 }
960
961 /* data_ptr points to TP-UDL now,
962 * calculate the length excluding SCA octets
963 */
964 if (cmhSMS_getAlphabetPp (dcs) EQ 0)
965 length_sms = length + (*data_ptr * 7 + 7)/8 + 1; // 7 bit alphabet
966 else
967 length_sms = length + *data_ptr + 1;
968
969 pos += sprintf ( g_sa + pos, ",%d", length_sms );
970 io_sendMessage ( srcId, g_sa, ATI_NORMAL_OUTPUT );
971 pos = 0;
972 }
973 else
974 {
975 length_sms=((mnsms_read_cnf->sms_sdu.l_buf+7)/8);
976 pos += sprintf ( g_sa + pos, ",%d,", length_sms-sca_len );
977 sca_len = 0;
978 }
979
980 /*
981 * Print PDU + service centre address
982 */
983 /*If the SMS length recevied incorrectly (length_sms > SIM_PDU_LEN)
984 then there is a chance of reading the buf[] beyond SIM_PDU_LEN.
985 By using the MINIMUM macro the max length limit
986 to SIM_PDU_LEN if the length of SMS is greater than SIM_PDU_LEN
987 */
988 length_sms = MINIMUM (sca_len+length_sms, SIM_PDU_LEN);
989 for (i=0;i<(USHORT)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 (T_ATI_OUTPUT_TYPE) (ATI_NORMAL_OUTPUT |
1099 ATI_BEGIN_CRLF_OUTPUT |
1100 ATI_END_CRLF_OUTPUT));
1101
1102 }
1103
1104 #ifdef REL99
1105 /*
1106 +--------------------------------------------------------------------+
1107 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1108 | STATE : code ROUTINE : rCI_PercentCMGRSPdu|
1109 +--------------------------------------------------------------------+
1110
1111 PURPOSE : handles AT_PlusCMGRS call back in PDU mode
1112
1113 */
1114
1115 GLOBAL void rCI_PercentCMGRSPdu ( UBYTE mode,
1116 T_MNSMS_RETRANS_CNF * mnsms_retrans_cnf,
1117 T_MNSMS_SEND_PROG_IND * mnsms_send_prog_ind )
1118 {
1119 USHORT pos = 0;
1120 UBYTE length;
1121 UBYTE srcId = srcId_cb;
1122 USHORT i;
1123 UBYTE sca_len = mnsms_retrans_cnf->sms_sdu.buf[0] + 1;
1124 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1125
1126 TRACE_FUNCTION("rCI_PercentCMGRSPdu()");
1127
1128
1129 src_params->curAtCmd = AT_CMD_NONE;
1130
1131 if (mode EQ CMGRS_MODE_MANUAL_RETRANS AND mnsms_retrans_cnf NEQ NULL)
1132 {
1133 pos=sprintf(g_sa,"%s: %d", "%CMGRS", mnsms_retrans_cnf->tp_mr);
1134
1135
1136 if (smsShrdPrm.CSMSservice EQ CSMS_SERV_GsmPh2Plus)
1137 {
1138 pos+=sprintf(g_sa+pos, ",");
1139 length = ((mnsms_retrans_cnf->sms_sdu.l_buf+7)/8) - sca_len;
1140
1141 /*
1142 * Print ACK PDU (without SCA field)
1143 */
1144 for (i=sca_len;i<length;i++)
1145 pos = GsmToHex (mnsms_retrans_cnf->sms_sdu.buf[i], g_sa, pos);
1146 }
1147 }
1148 else if (mode EQ CMGRS_MODE_ENABLE_AUTO_RETRANS AND mnsms_send_prog_ind NEQ NULL)
1149 {
1150 pos=sprintf(g_sa,"%s: 1,%d,%d", "%CMGRS",
1151 mnsms_send_prog_ind->resend_count,
1152 mnsms_send_prog_ind->max_retrans);
1153 }
1154 else
1155 {
1156 TRACE_ERROR("%CMGRS: wrong combination of parameters");
1157 return;
1158 }
1159
1160 /*
1161 * Send response
1162 */
1163 io_sendMessageEx( srcId, g_sa,
1164 (T_ATI_OUTPUT_TYPE)(ATI_NORMAL_OUTPUT |
1165 ATI_BEGIN_CRLF_OUTPUT |
1166 ATI_END_CRLF_OUTPUT));
1167
1168 }
1169 #endif
1170 /*
1171 +--------------------------------------------------------------------+
1172 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1173 | STATE : code ROUTINE : rCI_PlusCMGCPdu |
1174 +--------------------------------------------------------------------+
1175
1176 PURPOSE : handles AT_PlusCMGC call back in PDU mode
1177
1178 */
1179
1180 GLOBAL void rCI_PlusCMGCPdu (T_MNSMS_COMMAND_CNF * mnsms_command_cnf)
1181 {
1182 USHORT pos = 0;
1183 UBYTE length;
1184 UBYTE srcId = srcId_cb;
1185 USHORT i;
1186 UBYTE sca_len;
1187 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1188
1189 TRACE_FUNCTION("rCI_PlusCMGCPdu()");
1190
1191 src_params->curAtCmd = AT_CMD_NONE;
1192
1193 pos=sprintf(g_sa,"+CMGC: %d", mnsms_command_cnf->tp_mr);
1194
1195 if (smsShrdPrm.CSMSservice EQ CSMS_SERV_GsmPh2Plus)
1196 {
1197 if (mnsms_command_cnf->sms_sdu.l_buf)
1198 {
1199 pos+=sprintf(g_sa+pos, ",\""); /* parameter shall be bounded by double quote characters, see 07.07 <ackpdu> */
1200 sca_len = mnsms_command_cnf->sms_sdu.buf[0] + 1;
1201 length = ((mnsms_command_cnf->sms_sdu.l_buf+7)/8);
1202
1203 /*
1204 * Print ACK PDU (without SCA field)
1205 */
1206 for (i=sca_len; i<length; i++)
1207 pos = GsmToHex (mnsms_command_cnf->sms_sdu.buf[i], g_sa, pos);
1208
1209 pos+=sprintf(g_sa+pos, "\"");
1210 }
1211 }
1212
1213 /*
1214 * Send response
1215 */
1216 io_sendMessageEx( srcId, g_sa,
1217 (T_ATI_OUTPUT_TYPE) (ATI_NORMAL_OUTPUT |
1218 ATI_BEGIN_CRLF_OUTPUT |
1219 ATI_END_CRLF_OUTPUT));
1220 }
1221
1222 /*
1223 +--------------------------------------------------------------------+
1224 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1225 | STATE : code ROUTINE : rCI_PlusCMTPdu |
1226 +--------------------------------------------------------------------+
1227
1228 PURPOSE : handles AT_PlusCMT unsolicited message in PDU mode
1229
1230 */
1231
1232 #if defined (SMS_PDU_SUPPORT)
1233
1234 GLOBAL void rCI_PlusCMTPdu (T_MNSMS_MESSAGE_IND * mnsms_message_ind)
1235 {
1236 USHORT pos = 0;
1237 UBYTE l_sms_with_sca;
1238 UBYTE l_sms_without_sca;
1239 UBYTE srcId = srcId_cb;
1240
1241 #ifndef FF_ATI_BAT
1242 CHAR cvtdAlpha[2*MAX_ALPHA_LEN];
1243 USHORT lenCvtdAlpha;
1244 T_ACI_PB_TEXT alpha;
1245 T_ACI_SMS_STAT stat;
1246 #endif
1247
1248 USHORT i;
1249 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1250
1251 UBYTE sca_len = mnsms_message_ind->sms_sdu.buf[0] + 1;
1252
1253 TRACE_FUNCTION("rCI_PlusCMTPdu()");
1254
1255 src_params->curAtCmd = AT_CMD_NONE;
1256
1257 /*
1258 * print response for SMS message
1259 */
1260 pos = sprintf ( g_sa, "+CMT: ");
1261
1262 /*
1263 * print alpha if available
1264 */
1265 #ifdef FF_ATI_BAT
1266
1267 /*
1268 * Extracting the alphanumeric data from the phonebook at this point
1269 * would defeat the object (testing the BAT message). Having this
1270 * data stored globally represents a quick and dirty solution to the
1271 * problem of conveying it here.
1272 */
1273 if (smsShrdPrm.alpha_len)
1274 {
1275 pos+=sprints(g_sa+pos,smsShrdPrm.alpha,smsShrdPrm.alpha_len);
1276 }
1277
1278 #else
1279
1280 /* convert status from PSA type to CMH type */
1281 cmhSMS_getStatCmh ( mnsms_message_ind->status, &stat );
1282
1283 cmhSMS_getPhbEntry( mnsms_message_ind->sms_sdu.buf, &alpha, stat);
1284
1285
1286 if ( alpha.len NEQ 0 )
1287 {
1288 utl_chsetFromGsm ( (UBYTE*)alpha.data,
1289 alpha.len,
1290 (UBYTE*)cvtdAlpha,
1291 sizeof(cvtdAlpha),
1292 &lenCvtdAlpha,
1293 GSM_ALPHA_Def );
1294 pos += sprints ( g_sa + pos, cvtdAlpha, lenCvtdAlpha );
1295 }
1296
1297 #endif /*FF_ATI_BAT*/
1298
1299 l_sms_with_sca = ((mnsms_message_ind->sms_sdu.l_buf+7)/8);
1300 l_sms_without_sca = l_sms_with_sca - sca_len;
1301
1302 pos += sprintf ( g_sa + pos, ",%d", l_sms_without_sca );
1303 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1304
1305 pos = 0;
1306
1307 /*
1308 * Print PDU + service centre address field
1309 */
1310 for (i=0;i<(USHORT)l_sms_with_sca;i++)
1311 pos = GsmToHex (mnsms_message_ind->sms_sdu.buf[i], g_sa, pos);
1312
1313 /*
1314 * Send response
1315 */
1316 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1317
1318 }
1319 #endif
1320
1321 /*
1322 +--------------------------------------------------------------------+
1323 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1324 | STATE : code ROUTINE : rCI_PlusCBMPdu |
1325 +--------------------------------------------------------------------+
1326
1327 PURPOSE : handles Cell Broadcast unsolicited message in PDU mode
1328
1329 */
1330
1331 #if defined (SMS_PDU_SUPPORT)
1332
1333 GLOBAL void rCI_PlusCBMPdu (T_MMI_CBCH_IND * mmi_cbch_ind)
1334 {
1335 int i;
1336 USHORT pos = 0;
1337 UBYTE srcId = srcId_cb;
1338 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1339
1340 TRACE_FUNCTION("rCI_PlusCBMPdu()");
1341
1342 src_params->curAtCmd = AT_CMD_NONE;
1343
1344 /*
1345 * print response for CBM message
1346 */
1347 pos = sprintf ( g_sa, "+CBM: ");
1348 pos += sprintf ( g_sa + pos, "%d", (int)mmi_cbch_ind->cbch_len );
1349
1350 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1351
1352 pos = 0;
1353
1354 for (i = 0; i < (int)mmi_cbch_ind->cbch_len; i++)
1355 pos = GsmToHex (mmi_cbch_ind->cbch_msg[i], g_sa, pos);
1356
1357 io_sendMessageEx ( srcId, g_sa, (T_ATI_OUTPUT_TYPE)(ATI_INDICATION_OUTPUT +
1358 ATI_FORCED_OUTPUT +
1359 ATI_END_CRLF_OUTPUT ));
1360
1361 }
1362 #endif
1363
1364
1365 #if defined (SMS_PDU_SUPPORT)
1366 /*
1367 +--------------------------------------------------------------------+
1368 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1369 | STATE : code ROUTINE : rCI_PlusCDSPdu |
1370 +--------------------------------------------------------------------+
1371
1372 PURPOSE : handles Status Indication unsolicited message in PDU mode
1373
1374 */
1375 GLOBAL void rCI_PlusCDSPdu (T_MNSMS_STATUS_IND * mnsms_status_ind)
1376 {
1377 USHORT pos = 0;
1378 UBYTE l_sms_with_sca;
1379 UBYTE l_sms_without_sca;
1380 UBYTE sca_len = mnsms_status_ind->sms_sdu.buf[0] + 1;
1381 USHORT i;
1382 UBYTE srcId = srcId_cb;
1383 T_ATI_SRC_PARAMS *src_params = find_element (ati_src_list, srcId, search_ati_src_id);
1384
1385
1386 TRACE_FUNCTION("rCI_PlusCDSPdu()");
1387
1388 src_params->curAtCmd = AT_CMD_NONE;
1389
1390 /*
1391 * print response for SMS message
1392 */
1393 pos = sprintf ( g_sa, "+CDS: ");
1394
1395 l_sms_with_sca = ((mnsms_status_ind->sms_sdu.l_buf+7)/8);
1396 l_sms_without_sca = l_sms_with_sca - sca_len;
1397
1398 pos += sprintf ( g_sa + pos, "%d", l_sms_without_sca );
1399
1400 io_sendIndication ( srcId, g_sa, ATI_FORCED_OUTPUT );
1401
1402 pos = 0;
1403
1404 /*
1405 * Print PDU + service centre address field
1406 */
1407 for (i=0;i<(USHORT)l_sms_with_sca;i++)
1408 pos = GsmToHex (mnsms_status_ind->sms_sdu.buf[i], g_sa, pos);
1409
1410 /*
1411 * Send response
1412 */
1413 io_sendMessageEx ( srcId, g_sa, (T_ATI_OUTPUT_TYPE)(ATI_INDICATION_OUTPUT +
1414 ATI_FORCED_OUTPUT +
1415 ATI_END_CRLF_OUTPUT) );
1416
1417 }
1418 #endif /* SMS_PDU_SUPPORT */
1419
1420
1421
1422 /*
1423 +--------------------------------------------------------------------+
1424 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1425 | STATE : code ROUTINE : HexMessage |
1426 +--------------------------------------------------------------------+
1427
1428 PURPOSE : converts a sms message to HEX and fill it into a buffer.
1429
1430 */
1431
1432 /* does not seem to be used */
1433 /*GLOBAL USHORT HexMessage (T_ACI_SM_DATA * data, UBYTE length, char * buffer, USHORT pos)
1434 {
1435 int i;
1436
1437 pos = GsmToHex (data->len, buffer, pos);
1438
1439 for (i=0;i<(int)length;i++)
1440 pos = GsmToHex (data->data[i], buffer, pos);
1441
1442 return pos;
1443 } */
1444
1445
1446 /*
1447 +--------------------------------------------------------------------+
1448 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1449 | STATE : code ROUTINE : HexScts |
1450 +--------------------------------------------------------------------+
1451
1452 PURPOSE : converts a service centre timestamp to HEX and fill it into a buffer.
1453
1454 */
1455
1456 /* doesn't seem to be used... */
1457 /*GLOBAL USHORT HexScts (T_ACI_VP_ABS * scts, char * buffer, USHORT pos)
1458 {
1459 UBYTE tz;
1460
1461 TRACE_EVENT_P1("TZ =%x", scts->timezone);
1462
1463 pos = GsmToHex ((UBYTE)((scts->year[1]<<4)+scts->year[0]),
1464 buffer, pos);
1465 pos = GsmToHex ((UBYTE)((scts->month[1]<<4)+scts->month[0]),
1466 buffer, pos);
1467 pos = GsmToHex ((UBYTE)((scts->day[1]<<4)+scts->day[0]),
1468 buffer, pos);
1469 pos = GsmToHex ((UBYTE)((scts->hour[1]<<4)+scts->hour[0]),
1470 buffer, pos);
1471 pos = GsmToHex ((UBYTE)((scts->minute[1]<<4)+scts->minute[0]),
1472 buffer, pos);
1473 pos = GsmToHex ((UBYTE)((scts->second[1]<<4)+scts->second[0]),
1474 buffer, pos);
1475
1476 tz = cmhSMS_setTimezone(scts->timezone);
1477 pos = GsmToHex (tz, buffer, pos);
1478
1479 return pos;
1480 }*/
1481
1482
1483 /*
1484 +--------------------------------------------------------------------+
1485 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1486 | STATE : code ROUTINE : GsmToHex |
1487 +--------------------------------------------------------------------+
1488
1489 PURPOSE : converts a GSM character to HEX and fill it into a buffer.
1490
1491 */
1492
1493 GLOBAL USHORT GsmToHex (UBYTE in, char * buffer, USHORT pos)
1494 {
1495 const UBYTE hexVal[17] = {"0123456789ABCDEF"};
1496
1497 buffer[pos] = hexVal[ in >> 4 ];
1498 buffer[pos+1] = hexVal[ in & 0x0F ];
1499 buffer[pos+2] = '\0';
1500 return pos+2;
1501 }
1502
1503 /*
1504 +--------------------------------------------------------------------+
1505 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1506 | STATE : code ROUTINE : HexAdress |
1507 +--------------------------------------------------------------------+
1508
1509 PURPOSE : converts a adress to HEX and fill it into a buffer.
1510
1511 */
1512
1513 #if 0
1514 GLOBAL USHORT HexAdress (CHAR * adress, UBYTE ton, UBYTE npi, char * buffer, USHORT pos)
1515 {
1516 int i;
1517 int len;
1518
1519 len = (strlen (adress)+1)/2;
1520
1521 pos = GsmToHex ((UBYTE)(len+1), buffer, pos);
1522
1523 pos = GsmToHex ((UBYTE)(0x80 + (ton<<4) + npi), buffer, pos);
1524
1525 for (i=0;i<len;i++)
1526 {
1527 if (i EQ len-1)
1528 {
1529 /*
1530 * last two digits
1531 */
1532 if (strlen(adress) & 1)
1533 {
1534 pos = GsmToHex ((UBYTE)(0xF0 + (adress[2*i] - 0x30)), buffer, pos);
1535 continue;
1536 }
1537 }
1538 pos = GsmToHex ((UBYTE)(((adress [2*i+1]-0x30) << 4) +
1539 (adress [2*i] - 0x30)), buffer, pos);
1540 }
1541 return pos;
1542 }
1543 #endif /* 0 */
1544
1545 /*
1546 +--------------------------------------------------------------------+
1547 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1548 | STATE : code ROUTINE : HexAdressTP |
1549 +--------------------------------------------------------------------+
1550
1551 PURPOSE : converts a adress to HEX and fill it into a buffer for TP-adresses.
1552
1553 */
1554
1555 #if 0
1556 GLOBAL USHORT HexAdressTP (CHAR * adress, UBYTE ton, UBYTE npi, char * buffer, USHORT pos)
1557 {
1558 int i;
1559 int len;
1560
1561 len = (strlen (adress)+1)/2;
1562
1563 if ( ton EQ 0x05 AND strlen (adress) NEQ 4 ) /* PATCH VO - if (patch) else ... */
1564 pos = GsmToHex ((UBYTE)(strlen (adress) * 2), g_sa, pos);
1565 else
1566 pos = GsmToHex ((UBYTE)strlen(adress), g_sa, pos);
1567
1568 pos = GsmToHex ((UBYTE)(0x80 + (ton<<4) + npi), g_sa, pos);
1569
1570 if ( ton EQ 0x05 AND strlen (adress) NEQ 4 ) /* PATCH VO - if (patch) else ... */
1571 {
1572 for (i=0;i<(int)strlen (adress);i++)
1573 pos = GsmToHex ((UBYTE)adress[i], g_sa, pos);
1574 }
1575 else
1576 {
1577 for (i=0;i<len;i++)
1578 {
1579 if (i EQ len-1)
1580 {
1581 /*
1582 * last two digits
1583 */
1584 if (strlen(adress) & 1)
1585 {
1586 pos = GsmToHex ((UBYTE)(0xF0 + (adress[2*i] - 0x30)), g_sa, pos);
1587 continue;
1588 }
1589 }
1590 pos = GsmToHex ((UBYTE)(((adress [2*i+1]-0x30) << 4) + (adress [2*i] - 0x30)),
1591 g_sa, pos);
1592 }
1593 }
1594 return pos;
1595 }
1596 #endif /* 0 */
1597 /*
1598 +--------------------------------------------------------------------+
1599 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1600 | STATE : code ROUTINE : HexToGsm |
1601 +--------------------------------------------------------------------+
1602
1603 PURPOSE : converts a HEX value to the GSM character.
1604
1605 */
1606
1607 GLOBAL char * HexToGsm (char * cl, UBYTE * value)
1608 {
1609 int i;
1610 UBYTE character;
1611
1612 /*
1613 * initialise the output value
1614 */
1615 *value = 0;
1616
1617 /*
1618 * for both nibbles
1619 */
1620 for (i=0;i<2;i++)
1621 {
1622 /*
1623 * shift the result of the last loop
1624 */
1625 *value = (*value) << 4;
1626
1627 /*
1628 * Isolate next nibble in ASCII
1629 */
1630 character = toupper(*cl++);
1631
1632 /*
1633 * convert Nibble character to value
1634 */
1635 switch (character)
1636 {
1637 case 'A':
1638 case 'B':
1639 case 'C':
1640 case 'D':
1641 case 'E':
1642 case 'F':
1643 *value = *value + (character - 'A' + 10);
1644 break;
1645 default:
1646 /*
1647 * 0-9
1648 */
1649 *value = *value + (character - '0');
1650 break;
1651 }
1652 }
1653
1654 /*
1655 * return pointer to the rest of PDU
1656 */
1657 return cl;
1658 }
1659
1660 /*
1661 +--------------------------------------------------------------------+
1662 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1663 | STATE : code ROUTINE : GSMAddress |
1664 +--------------------------------------------------------------------+
1665
1666 PURPOSE : converts a adress coded with HEX values to the internal
1667 data structures.
1668
1669 */
1670
1671 /* does not seem to be used */
1672 #if 0
1673 GLOBAL char * GSMAddress (char * cl, char * address, T_ACI_TOA *tosca)
1674 {
1675 int i, j;
1676 UBYTE value;
1677 UBYTE len;
1678 UBYTE digit;
1679
1680 /*
1681 * calculate the number of octets which are used for the address
1682 */
1683
1684 cl = HexToGsm (cl, &value);
1685 if (value EQ 0) /* SCA not given */
1686 {
1687 address[0] = 0;
1688 return cl;
1689 }
1690 len = value - 1;
1691
1692 /*
1693 * check against maximum value
1694 */
1695 if (len > MAX_SMS_ADDR_DIG/2)
1696 {
1697 pdu_error_detected = TRUE;
1698 return cl;
1699 }
1700
1701 /*
1702 * calculate the type of number and numbering plan identification
1703 */
1704 cl = HexToGsm (cl, &value);
1705
1706 tosca->ton = (value >> 4) & 7;
1707 tosca->npi = value & 0x0F;
1708
1709
1710 /*
1711 * convert the digits
1712 */
1713 j = 0;
1714 for (i = 0; i < (int)len; i++)
1715 {
1716 cl = HexToGsm (cl, &value);
1717
1718 /*
1719 * check digit n
1720 */
1721 address[j++] = (value & 0x0F) + 0x30;
1722 /*
1723 * check digit n+1
1724 */
1725 digit = (value >> 4) & 0x0F;
1726 if (digit < 10)
1727 address[j++] = digit + 0x30;
1728 }
1729 /*
1730 * string termination
1731 */
1732 address[j] = 0;
1733
1734 /*
1735 * return pointer to the rest of the PDU
1736 */
1737 return cl;
1738 }
1739 #endif /* 0 */
1740 /*
1741 +--------------------------------------------------------------------+
1742 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1743 | STATE : code ROUTINE : GSMAddressTP |
1744 +--------------------------------------------------------------------+
1745
1746 PURPOSE : converts a TP-adress coded with HEX values to the internal
1747 data structures.
1748
1749 */
1750
1751 /* does not seem to be used */
1752 #if 0
1753 GLOBAL char * GSMAddressTP (char * cl, char * address, T_ACI_TOA *toda)
1754 {
1755 int i, j;
1756 UBYTE value;
1757 UBYTE len;
1758 UBYTE digit;
1759
1760 /*
1761 * calculate the number of octets which are used for the address
1762 */
1763 cl = HexToGsm (cl, &value);
1764 len = (value + 1)/2;
1765
1766 /*
1767 * check against maximum value
1768 */
1769 if (len > MAX_SMS_ADDR_DIG/2)
1770 {
1771 pdu_error_detected = TRUE;
1772 return cl;
1773 }
1774 /*
1775 * calculate the type of number and numbering plan identification
1776 */
1777 cl = HexToGsm (cl, &value);
1778
1779 toda->ton = (value >> 4) & 7;
1780 toda->npi = value & 0x0F;
1781
1782 /*
1783 * convert the digits
1784 */
1785 j = 0;
1786 for (i=0;i<(int)len;i++)
1787 {
1788 cl = HexToGsm (cl, &value);
1789
1790 /*
1791 * check digit n
1792 */
1793 address[j++] = (value & 0x0F) + 0x30;
1794 /*
1795 * check digit n+1
1796 */
1797 digit = (value >> 4) & 0x0F;
1798 if (digit < 10)
1799 address[j++] = digit + 0x30;
1800 }
1801 /*
1802 * string termination
1803 */
1804 address[j] = 0;
1805
1806 /*
1807 * return pointer to the rest of the PDU
1808 */
1809 return cl;
1810 }
1811 #endif /* 0 */
1812
1813 /*
1814 +--------------------------------------------------------------------+
1815 | PROJECT : GSM-F&D (8411) MODULE : ACI_PDU |
1816 | STATE : code ROUTINE : GSMMessage |
1817 +--------------------------------------------------------------------+
1818
1819 PURPOSE : converts a sms message from HEX and fill it into a buffer.
1820
1821 */
1822
1823 #if 0
1824 GLOBAL char *GSMMessage (char *cl, UBYTE *data, SHORT oct_length, SHORT max_length)
1825 {
1826 SHORT i;
1827
1828 /*
1829 * check against maximum value
1830 */
1831 if (oct_length > max_length)
1832 {
1833 pdu_error_detected = TRUE;
1834 return cl;
1835 }
1836 memset (data, 0, max_length);
1837
1838 /*
1839 * copy message
1840 */
1841 for (i = 0; i < oct_length; i++)
1842 cl = HexToGsm (cl, &data[i]);
1843
1844 return cl;
1845 }
1846 #endif /* 0 */
1847
1848 #endif
1849
1850 #endif /* ATI_PDU_C */