comparison g23m-aci/aci/line_split.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : line
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This modul ...
18 +-----------------------------------------------------------------------------
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <ctype.h>
25
26 #include "config.h"
27 #include "fixedconf.h"
28 #include "condat-features.h"
29 #include "aci_conf.h"
30
31 #include "typedefs.h"
32 #include "vsi.h"
33 #include "pei.h"
34 #include "aci_mem.h"
35 #include "p_aci.val"
36
37 #include "line_edit.h"
38 #include "line_edit_intern.h"
39 #include "line_split_intern.h"
40
41 static T_LEDIT_CHAR_TYPE ledit_lookAhead (char c);
42 static UBYTE ledit_check_valid_basic_cmd (char c);
43 static UBYTE ledit_check_valid_and_cmd (char c);
44 static USHORT ledit_get_para_len (T_LEDIT_INTERN *leditInt, USHORT searchLen);
45 static USHORT ledit_get_name_len (T_LEDIT_INTERN *leditInt, T_LEDIT_NAME_TYPE nType);
46 static T_LEDIT_RSLT ledit_get_memory (T_LEDIT_ATCMD_M **cmdm, int size, int name);
47 static T_LEDIT_RSLT ledit_get_cmd_mem (T_LEDIT_INTERN *leditInt);
48 static T_LEDIT_RSLT ledit_assign_name (T_LEDIT_INTERN *leditInt, int len);
49 static T_LEDIT_RSLT ledit_assign_param (T_LEDIT_INTERN *leditInt, T_LEDIT_PARAM_TYPE pType);
50 static T_LEDIT_ATCMD_SUBTYPE ledit_extended_type (T_LEDIT_INTERN *leditInt);
51 static T_LEDIT_RSLT ledit_extended_cmd (T_LEDIT_INTERN *leditInt);
52 static T_LEDIT_RSLT ledit_s_cmd (T_LEDIT_INTERN *leditInt);
53 static T_LEDIT_RSLT ledit_dial (T_LEDIT_INTERN *leditInt);
54 static T_LEDIT_RSLT ledit_and_basic_cmd (T_LEDIT_INTERN *leditInt);
55 static T_LEDIT_RSLT ledit_basic_cmd (T_LEDIT_INTERN *leditInt);
56
57 static T_LEDIT_RSLT ledit_restore_dial_string (char *procDialString,
58 int procDialStringLen,
59 char *origCommandLine,
60 int origCommandLineLen);
61
62
63 static const UBYTE basic_ATcmd [26][2] =
64 {
65 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* A */
66 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* B */
67 {BATCMD_NO_SUPP, ANDCMD_SUPPORT}, /* C */
68 {BATCMD_DIAL , ANDCMD_SUPPORT}, /* D <---- SPECIAL */
69 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* E */
70 {BATCMD_SUPPORT, ANDCMD_SUPPORT}, /* F */
71 {BATCMD_NO_SUPP, ANDCMD_NO_SUPP}, /* G */
72 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* H */
73 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* I */
74 {BATCMD_NO_SUPP, ANDCMD_NO_SUPP}, /* J */
75 {BATCMD_NO_SUPP, ANDCMD_SUPPORT}, /* K */
76 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* L */
77 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* M */
78 {BATCMD_NO_SUPP, ANDCMD_NO_SUPP}, /* N */
79 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* O */
80 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* P */
81 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* Q */
82 {BATCMD_NO_SUPP, ANDCMD_NO_SUPP}, /* R */
83 {BATCMD_S_PARAM, ANDCMD_NO_SUPP}, /* S <---- SPECIAL */
84 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* T */
85 {BATCMD_NO_SUPP, ANDCMD_NO_SUPP}, /* U */
86 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* V */
87 {BATCMD_SUPPORT, ANDCMD_SUPPORT}, /* W */
88 {BATCMD_SUPPORT, ANDCMD_NO_SUPP}, /* X */
89 {BATCMD_NO_SUPP, ANDCMD_NO_SUPP}, /* Y */
90 {BATCMD_SUPPORT, ANDCMD_NO_SUPP} /* Z */
91 };
92
93
94 /*
95 +--------------------------------------------------------------------+
96 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
97 | STATE : code ROUTINE : ledit_check_valid_basic_cmd |
98 +--------------------------------------------------------------------+
99
100 PURPOSE : -
101 */
102 static UBYTE ledit_check_valid_basic_cmd (char c)
103 {
104 return basic_ATcmd [(int)(c-'A')][0];
105 }
106
107 /*
108 +--------------------------------------------------------------------+
109 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
110 | STATE : code ROUTINE : ledit_check_valid_and_cmd |
111 +--------------------------------------------------------------------+
112
113 PURPOSE : -
114 */
115 static UBYTE ledit_check_valid_and_cmd (char c)
116 {
117 return basic_ATcmd [(int)(c-'A')][1];
118 }
119
120
121 /*
122 +--------------------------------------------------------------------+
123 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
124 | STATE : code ROUTINE : ledit_lookAhead |
125 +--------------------------------------------------------------------+
126
127 PURPOSE : - qualify the character at the look ahead position
128 */
129
130 static T_LEDIT_CHAR_TYPE ledit_lookAhead (char c)
131 {
132 if (c EQ '\0')
133 return LEDIT_CHAR_TERMINATED;
134
135 switch (c)
136 {
137 case '%':
138 return LEDIT_CHAR_PERCENT;
139 case '&':
140 return LEDIT_CHAR_AND;
141 case '+':
142 return LEDIT_CHAR_PLUS;
143 case ',':
144 return LEDIT_CHAR_COMMA;
145 case '=':
146 return LEDIT_CHAR_SET;
147 case ';':
148 return LEDIT_CHAR_SEPARATOR;
149 case '?':
150 return LEDIT_CHAR_READ;
151 default:
152 {
153 if ((c-'0') < 10 AND (c - '0') >=0)
154 return LEDIT_CHAR_NUMBER;
155 if ((c>='A') && (c<='Z'))
156 return LEDIT_CHAR_CHAR;
157 if (((c >= '!') AND (c <= '_')) OR ((c >= 123) AND ((unsigned char)c <= 127)))
158 /*the rest of characters*/
159 return LEDIT_CHAR_EXT;
160 return LEDIT_CHAR_INVALID;
161 }
162 }
163 }
164
165
166 /*
167 +--------------------------------------------------------------------+
168 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
169 | STATE : code ROUTINE : ledit_get_para_len |
170 +--------------------------------------------------------------------+
171
172 PURPOSE : - calculate length of an AT command parameter
173 */
174 static USHORT ledit_get_para_len (T_LEDIT_INTERN *leditInt, USHORT searchLen)
175 {
176 USHORT i = 0;
177 #ifdef _SIMULATION_
178 TRACE_FUNCTION("ledit_get_para_len()");
179 #endif
180 if (searchLen EQ SEARCH_BAT_LEN)
181 {
182 /* basic AT command can have numbers only e.g.: ATF123 */
183 i = leditInt->execBufIter; /* start with first number */
184 while (isdigit(leditInt->execBuffer[i]))
185 {
186 ++i;
187 }
188 return (i - leditInt->execBufIter);
189 }
190 else
191 {
192 /*
193 * dial string finish with ';'
194 * extended AT command is terminated by ';' or by '\0' if last one in cmd line
195 */
196 i = leditInt->execBufIter;
197
198 while (';' != leditInt->execBuffer[i])
199 {
200 ++i;
201 if (leditInt->execBuffer[i] EQ '\0')
202 {
203 break;
204 }
205 }
206 if ((searchLen EQ SEARCH_DIAL_LEN) AND (';' EQ leditInt->execBuffer[i]))
207 {
208 ++i; /* for dial the ';' is important */
209 }
210 return (i - leditInt->execBufIter);
211 }
212 }
213
214 /*
215 +--------------------------------------------------------------------+
216 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
217 | STATE : code ROUTINE : ledit_get_name_len |
218 +--------------------------------------------------------------------+
219
220 PURPOSE : - get the length of an extended AT command or ATSnn where nn := 0..99
221 extended name starts with '+', '%', '$' ... or every other char which is not [a-zA-Z][0-9]
222 after prefix must start with [A-Z] and then up to further 15 characters
223 of [A-Z][0-9]!%-./:_ according to V.25 ter chapter 5.4.1
224 */
225 static USHORT ledit_get_name_len (T_LEDIT_INTERN *leditInt, T_LEDIT_NAME_TYPE nType)
226 {
227 USHORT i = leditInt->execBufIter;
228
229 if (nType EQ LEDIT_EXT_NAME)
230 {
231 ++i; /* skip prefix of extended name */
232 }
233 /*
234 * first char (after extended prefix) must be [A-Z] (to capital letter done by ledit_collect())
235 */
236 if (isupper (leditInt->execBuffer[i]))
237 {
238 while (leditInt->execBuffer[i])
239 {
240 if ((nType EQ LEDIT_S_NAME) AND (i > leditInt->execBufIter))
241 {
242 if (isdigit(leditInt->execBuffer[i]) EQ 0)
243 {
244 return 0; /* invalid name for ATSnn, where nn must be [0-9]+ */
245 }
246 if ((i - leditInt->execBufIter) > LEDIT_MAX_S_NAME_LEN)
247 {
248 return 0; /* invalid name for ATSnn, where nn is too large */
249 }
250 }
251 ++i;
252 switch (leditInt->execBuffer[i])
253 {
254 case '\0':
255 {
256 return (i - leditInt->execBufIter);
257 }
258 case '=':
259 {
260 if (leditInt->execBuffer[i+1] NEQ '?')
261 {
262 return (i - leditInt->execBufIter);
263 }
264 else /* AT+XXX=? */
265 {
266 if ((leditInt->execBuffer[i+2] NEQ '\0') AND (leditInt->execBuffer[i+2] NEQ ';'))
267 {
268 return 0; /* after =? must be ';' or terminated */
269 }
270 return (i - leditInt->execBufIter);
271 }
272 }
273 case '?':
274 {
275 if ((leditInt->execBuffer[i+1] NEQ '\0') AND (leditInt->execBuffer[i+1] NEQ ';'))
276 {
277 return 0; /* after ? must be ';' or terminated */
278 }
279 return (i - leditInt->execBufIter);
280 }
281 case ';':
282 {
283 /*
284 * there are several extended AT cmds without "=parameter" or "=?" or "?" after the name, e.g.: +CGMM;+CGMI;+CGMR;+CGSN;...
285 * the ";" after the name will be parsed in ledit_get_para_len()
286 */
287 return (i - leditInt->execBufIter);
288 }
289 }
290 } /* end of while (leditInt->execBuffer[i]) */
291 }
292 return 0; /* invalid name */
293 }
294
295
296 /*
297 +--------------------------------------------------------------------+
298 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
299 | STATE : code ROUTINE : ledit_free_cmd |
300 +--------------------------------------------------------------------+
301
302 PURPOSE : -
303 */
304 void ledit_free_cmd (T_LEDIT_INTERN *leditInt)
305 {
306
307 T_LEDIT_ATCMD_M *tmp = NULL;
308 #ifdef _SIMULATION_
309 TRACE_FUNCTION("ledit_free_cmd()");
310 #endif
311 while (leditInt->cmdm)
312 {
313 tmp = leditInt->cmdm->next;
314 if (leditInt->cmdm->cmd)
315 {
316 if (leditInt->cmdm->cmd->name)
317 {
318 ACI_MFREE(leditInt->cmdm->cmd->name);
319 }
320 if (leditInt->cmdm->cmd->params)
321 {
322 ACI_MFREE (leditInt->cmdm->cmd->params);
323 }
324 ACI_MFREE (leditInt->cmdm->cmd);
325 }
326 /* if (leditInt->cmdm) ... always true */
327 {
328 ACI_MFREE (leditInt->cmdm);
329 }
330 leditInt->cmdm = tmp;
331 }
332 }
333
334
335 /*
336 +--------------------------------------------------------------------+
337 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
338 | STATE : code ROUTINE : ledit_get_cmd_mem |
339 +--------------------------------------------------------------------+
340
341 PURPOSE : - allocate some memory for T_LEDIT_ATCMD
342 */
343
344 static T_LEDIT_RSLT ledit_get_cmd_mem (T_LEDIT_INTERN *leditInt)
345 {
346 ACI_MALLOC(leditInt->cmdm,sizeof(T_LEDIT_ATCMD_M));
347 if (leditInt->cmdm EQ NULL)
348 {
349 return LEDIT_FAIL;
350 }
351 memset(leditInt->cmdm, '\0', sizeof(T_LEDIT_ATCMD_M));
352 leditInt->cmdm->next = NULL;
353
354 ACI_MALLOC(leditInt->cmdm->cmd,sizeof(T_LEDIT_ATCMD));
355 if (leditInt->cmdm->cmd EQ NULL)
356 {
357 return LEDIT_FAIL;
358 }
359 memset(leditInt->cmdm->cmd, '\0', sizeof(T_LEDIT_ATCMD));
360
361 leditInt->cmdm->cmd->type.mType = LEDIT_ATCMD_NIL;
362 leditInt->cmdm->cmd->type.sType = (T_LEDIT_ATCMD_SUBTYPE) LEDIT_ATCMD_NIL;
363 /* Initializing flag here BUG 11920 */
364 leditInt->cmdm->cmd->type.append_Flag = FALSE;
365 leditInt->cmdm->cmd->name = NULL;
366 leditInt->cmdm->cmd->params = NULL;
367 return LEDIT_CMPL;
368 }
369
370 /*
371 +--------------------------------------------------------------------+
372 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
373 | STATE : code ROUTINE : ledit_get_memory |
374 +--------------------------------------------------------------------+
375
376 PURPOSE : - allocate some memory (for char *)
377 */
378
379 static T_LEDIT_RSLT ledit_get_memory (T_LEDIT_ATCMD_M **cmdm, int size, int name)
380 {
381
382 T_LEDIT_ATCMD_M **tmp = cmdm;
383 if (name)
384 {
385 ACI_MALLOC((*tmp)->cmd->name,size * sizeof(char));
386 if ((*tmp)->cmd->name EQ NULL)
387 {
388 return LEDIT_FAIL;
389 }
390 (*tmp)->cmd->name[0]='\0';
391 }
392 else
393 {
394 ACI_MALLOC((*tmp)->cmd->params,size * sizeof(char));
395 if ((*tmp)->cmd->params EQ NULL)
396 {
397 TRACE_FUNCTION("ledit_get_memory(): returning fail");
398 return LEDIT_FAIL;
399 }
400 (*tmp)->cmd->params[0]='\0';
401 }
402 return LEDIT_CMPL;
403 }
404
405
406 /*
407 +--------------------------------------------------------------------+
408 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
409 | STATE : code ROUTINE : ledit_assign_name |
410 +--------------------------------------------------------------------+
411
412 PURPOSE : - extract the name of an AT command from command line
413 and put it into T_LEDIT_ATCMD member name
414 */
415
416 static T_LEDIT_RSLT ledit_assign_name (T_LEDIT_INTERN *leditInt, int len)
417 {
418 if(ledit_get_memory (&(leditInt->cmdm), len+1, 1) EQ LEDIT_FAIL)
419 {
420 leditInt->err.code = LEDIT_ERR_NoMemory;
421 leditInt->err.msg = ledit_err[LEDIT_ERR_NoMemory].msg;
422 return LEDIT_FAIL;
423 }
424 memcpy (leditInt->cmdm->cmd->name, leditInt->execBuffer+leditInt->execBufIter, len);
425 *(leditInt->cmdm->cmd->name+len) = '\0'; /* terminate name */
426 leditInt->execBufIter += len; /* update iterator in execBuffer */
427 return LEDIT_CMPL;
428 }
429
430 /*
431 +--------------------------------------------------------------------+
432 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
433 | STATE : code ROUTINE : ledit_assign_param |
434 +--------------------------------------------------------------------+
435
436 PURPOSE : - extract the param(s) of an AT command from command line
437 and put it into T_LEDIT_ATCMD member param
438 - can be empty
439 */
440
441 static T_LEDIT_RSLT ledit_assign_param (T_LEDIT_INTERN *leditInt, T_LEDIT_PARAM_TYPE pType)
442 {
443 int len = 0;
444 #ifdef _SIMULATION_
445 TRACE_FUNCTION("ledit_assign_param()");
446 #endif
447 if (pType EQ LEDIT_BASIC_PARAM)
448 {
449 len = ledit_get_para_len (leditInt, SEARCH_BAT_LEN);
450 }
451 else
452 if (pType EQ LEDIT_DIAL_PARAM) /* dial parameter, we need the possible ';' */
453 {
454 len = ledit_get_para_len (leditInt, SEARCH_DIAL_LEN);
455 /*
456 * If there were any 'g' or 'i' characters in a dial string that have
457 * been turned into 'G' or 'I' characters on conversion to upper case
458 * by the ledit_collect function...
459 * Turn them back into the lower case characters so that they affect
460 * CUG and CLIR in the way they were intended to.
461 */
462 ledit_restore_dial_string ( &leditInt->execBuffer[leditInt->execBufIter],
463 len,
464 leditInt->origBuffer,
465 strlen(leditInt->origBuffer));
466 }
467 else /* extended AT cmd params */
468 {
469 len = ledit_get_para_len (leditInt, SEARCH_EXT_LEN);
470 }
471 if(ledit_get_memory (&(leditInt->cmdm), len+1, 0) EQ LEDIT_FAIL)
472 {
473 leditInt->err.code = LEDIT_ERR_NoMemory;
474 leditInt->err.msg = ledit_err[LEDIT_ERR_NoMemory].msg;
475 return LEDIT_FAIL;
476 }
477 memcpy (leditInt->cmdm->cmd->params, leditInt->execBuffer+leditInt->execBufIter, len);
478 *(leditInt->cmdm->cmd->params+len) = '\0';
479
480 /*
481 * update iterator in execBuffer
482 * for extended cmds skip the ';'
483 */
484 if (pType EQ LEDIT_EXT_PARAM)
485 {
486 if (leditInt->execBuffer[leditInt->execBufIter+len] EQ '\0')
487 {
488 leditInt->execBufIter += len;
489 }
490 else
491 {
492 leditInt->execBufIter += len+1; /* skip the ';' */
493 }
494 }
495 else
496 {
497 leditInt->execBufIter += len;
498 }
499
500 return LEDIT_CMPL;
501 }
502
503 /*
504 +--------------------------------------------------------------------+
505 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
506 | STATE : code ROUTINE : ledit_extended_type |
507 +--------------------------------------------------------------------+
508
509 PURPOSE : -
510 */
511 static T_LEDIT_ATCMD_SUBTYPE ledit_extended_type (T_LEDIT_INTERN *leditInt)
512 {
513 #ifdef _SIMULATION_
514 TRACE_FUNCTION("ledit_extended_type()");
515 #endif
516 switch (ledit_lookAhead(leditInt->execBuffer[leditInt->execBufIter]))
517 {
518 case LEDIT_CHAR_SET:
519 {
520 ++(leditInt->execBufIter);
521 if (ledit_lookAhead(leditInt->execBuffer[leditInt->execBufIter]) EQ LEDIT_CHAR_READ)
522 {
523 ++(leditInt->execBufIter);
524 /*Setting flag as 1*/
525 leditInt->cmdm->cmd->type.append_Flag = TRUE;
526 /* bug 11920*/
527 return LEDIT_ATCMD_TEST;
528 }
529 /*Setting flag as 1*/
530 leditInt->cmdm->cmd->type.append_Flag = TRUE;
531 /* bug 11920*/
532 return LEDIT_ATCMD_SET;
533 }
534 case LEDIT_CHAR_READ:
535 {
536 ++(leditInt->execBufIter);
537 /*Setting flag as 1*/
538 leditInt->cmdm->cmd->type.append_Flag = TRUE;
539 /* bug 11920*/
540 return LEDIT_ATCMD_QUERY;
541 }
542 default:
543 {
544 /* return LEDIT_ATCMD_NIL; */
545 /*Setting flag as 0.
546 These types need not be appended with the characters later on while reconstructing
547 command in leedit_fwrd_extension*/
548 leditInt->cmdm->cmd->type.append_Flag = FALSE;
549 /* bug 11920*/
550
551 return LEDIT_ATCMD_SET; /* if after name no parameters e.g.: AT+CMGL; */
552 }
553 }
554 }
555
556 /*
557 +--------------------------------------------------------------------+
558 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
559 | STATE : code ROUTINE : ledit_extended_cmd |
560 +--------------------------------------------------------------------+
561
562 PURPOSE : - split cmd line into single canonical commands
563 */
564 static T_LEDIT_RSLT ledit_extended_cmd (T_LEDIT_INTERN *leditInt)
565 {
566 int len = 0;
567 #ifdef _SIMULATION_
568 TRACE_FUNCTION ("ledit_extended_cmd()");
569 #endif
570 /*
571 * get name lenght
572 */
573 len = ledit_get_name_len (leditInt, LEDIT_EXT_NAME);
574 if(len)
575 {
576 if (ledit_assign_name(leditInt, len) NEQ LEDIT_CMPL)
577 {
578 return LEDIT_FAIL;
579 }
580 leditInt->cmdm->cmd->type.mType = LEDIT_ATCMD_EXTENDED;
581 leditInt->cmdm->cmd->type.sType = ledit_extended_type(leditInt);
582 if (ledit_assign_param (leditInt, LEDIT_EXT_PARAM) NEQ LEDIT_CMPL)
583 {
584 return LEDIT_FAIL;
585 }
586 }
587 else
588 {
589 leditInt->err.code = LEDIT_ERR_NoValidCommand;
590 leditInt->err.msg = ledit_err[LEDIT_ERR_NoValidCommand].msg;
591 return LEDIT_FAIL;
592 }
593 return LEDIT_CMPL;
594 }
595
596 /*
597 +--------------------------------------------------------------------+
598 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
599 | STATE : code ROUTINE : ledit_s_cmd |
600 +--------------------------------------------------------------------+
601
602 PURPOSE : - special basic AT command ATS
603 with own syntax similiar to extended AT commands
604 e.g.: ATS0? <-- query register S0
605 ATS0=123 <-- set new value for register S0
606 but the parameter is basic cmd like
607 */
608 static T_LEDIT_RSLT ledit_s_cmd (T_LEDIT_INTERN *leditInt)
609 {
610 int len = 0;
611 #ifdef _SIMULATION_
612 TRACE_FUNCTION ("ledit_s_cmd()");
613 #endif
614 /*
615 * get name length, support for up to ATS99, but not ATS100 !
616 */
617 len = ledit_get_name_len (leditInt, LEDIT_S_NAME);
618 if(len)
619 {
620 if (ledit_assign_name(leditInt, len) NEQ LEDIT_CMPL)
621 {
622 return LEDIT_FAIL;
623 }
624 leditInt->cmdm->cmd->type.mType = LEDIT_ATCMD_S;
625 leditInt->cmdm->cmd->type.sType = ledit_extended_type(leditInt); /* after Sx must be [?|=] */
626 if (ledit_assign_param (leditInt, LEDIT_BASIC_PARAM) NEQ LEDIT_CMPL)
627 {
628 return LEDIT_FAIL;
629 }
630 }
631 else
632 {
633 leditInt->err.code = LEDIT_ERR_NoValidCommand;
634 leditInt->err.msg = ledit_err[LEDIT_ERR_NoValidCommand].msg;
635 return LEDIT_FAIL;
636 }
637 return LEDIT_CMPL;
638 }
639
640 /*
641 +--------------------------------------------------------------------+
642 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
643 | STATE : code ROUTINE : ledit_dial |
644 +--------------------------------------------------------------------+
645
646 PURPOSE : - ATD12345; , but also ATD(030)12345; or ATD!; ATD@; ...
647 - semantic of ATD paramter has to be checked by ATI
648 */
649 static T_LEDIT_RSLT ledit_dial (T_LEDIT_INTERN *leditInt)
650 {
651 #ifdef _SIMULATION_
652 TRACE_FUNCTION ("ledit_dial()");
653 #endif
654 leditInt->cmdm->cmd->type.mType = LEDIT_ATCMD_DIAL;
655 leditInt->cmdm->cmd->type.sType = LEDIT_ATCMD_SET;
656 /*Setting flag as 0*/
657 leditInt->cmdm->cmd->type.append_Flag = FALSE;
658 /*Issue 11920*/
659 if (ledit_assign_name(leditInt, 1) NEQ LEDIT_CMPL)
660 {
661 return LEDIT_FAIL;
662 }
663 /*
664 * dial paramter ends with ';' -> LEDIT_EXT_PARAM
665 */
666 if (ledit_assign_param (leditInt, LEDIT_DIAL_PARAM) NEQ LEDIT_CMPL)
667 {
668 return LEDIT_FAIL;
669 }
670 if (leditInt->execBuffer[leditInt->execBufIter])
671 {
672 return LEDIT_FAIL; /* dial command is not the last on cmd line */
673 }
674 return LEDIT_CMPL;
675 }
676
677
678 /*
679 +--------------------------------------------------------------------+
680 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
681 | STATE : code ROUTINE : ledit_and_basic_cmd |
682 +--------------------------------------------------------------------+
683
684 PURPOSE : -
685 */
686 static T_LEDIT_RSLT ledit_and_basic_cmd (T_LEDIT_INTERN *leditInt)
687 {
688 USHORT rv = ANDCMD_NO_SUPP;
689 #ifdef _SIMULATION_
690 TRACE_FUNCTION ("ledit_and_basic_cmd()");
691 #endif
692 ++(leditInt->execBufIter); /* skip the & */
693
694 rv = ledit_check_valid_and_cmd (leditInt->execBuffer[leditInt->execBufIter]);
695 if(rv EQ ANDCMD_SUPPORT)
696 {
697 leditInt->cmdm->cmd->type.mType = LEDIT_ATCMD_AND;
698 leditInt->cmdm->cmd->type.sType = LEDIT_ATCMD_QUERY;
699
700 /*Setting flag as 0*/
701 leditInt->cmdm->cmd->type.append_Flag = FALSE;
702 /* bug 11920*/
703
704 if (ledit_assign_name(leditInt, 1) NEQ LEDIT_CMPL)
705 {
706 return LEDIT_FAIL;
707 }
708 if (ledit_assign_param (leditInt, LEDIT_BASIC_PARAM) NEQ LEDIT_CMPL)
709 {
710 return LEDIT_FAIL;
711 }
712 }
713 else
714 {
715 leditInt->err.code = LEDIT_ERR_NoValidCommand;
716 leditInt->err.msg = ledit_err[LEDIT_ERR_NoValidCommand].msg;
717 return LEDIT_FAIL;
718 }
719 return LEDIT_CMPL;
720 }
721 /*
722 +--------------------------------------------------------------------+
723 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
724 | STATE : code ROUTINE : ledit_basic_cmd |
725 +--------------------------------------------------------------------+
726
727 PURPOSE : - check for basic command
728 - check for dial command
729 */
730 static T_LEDIT_RSLT ledit_basic_cmd (T_LEDIT_INTERN *leditInt)
731 {
732 USHORT rv = BATCMD_NO_SUPP;
733 #ifdef _SIMULATION_
734 TRACE_FUNCTION ("ledit_basic_cmd()");
735 #endif
736 rv = ledit_check_valid_basic_cmd (leditInt->execBuffer[leditInt->execBufIter]);
737 if (rv EQ BATCMD_SUPPORT)
738 {
739 leditInt->cmdm->cmd->type.mType = LEDIT_ATCMD_BASIC;
740 leditInt->cmdm->cmd->type.sType = LEDIT_ATCMD_SET;
741
742 /* Setting flag as 0*/
743 leditInt->cmdm->cmd->type.append_Flag = FALSE;
744 /* Issue 11920*/
745
746 if (ledit_assign_name(leditInt, 1) NEQ LEDIT_CMPL)
747 {
748 return LEDIT_FAIL;
749 }
750 if (ledit_assign_param (leditInt, LEDIT_BASIC_PARAM) NEQ LEDIT_CMPL)
751 {
752 return LEDIT_FAIL;
753 }
754 }
755 else if (rv EQ BATCMD_DIAL)
756 {
757 if (ledit_dial(leditInt) NEQ LEDIT_CMPL)
758 {
759 return LEDIT_FAIL;
760 }
761 }
762 else if (rv EQ BATCMD_S_PARAM)
763 {
764 if (ledit_s_cmd(leditInt) NEQ LEDIT_CMPL)
765 {
766 return LEDIT_FAIL;
767 }
768 }
769 else
770 {
771 leditInt->err.code = LEDIT_ERR_NoValidCommand;
772 leditInt->err.msg = ledit_err[LEDIT_ERR_NoValidCommand].msg;
773 return LEDIT_FAIL;
774 }
775 return LEDIT_CMPL;
776 }
777
778
779 /*
780 +--------------------------------------------------------------------+
781 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
782 | STATE : code ROUTINE : ledit_split |
783 +--------------------------------------------------------------------+
784
785 PURPOSE : - split cmd line into single canonical commands
786 */
787 T_LEDIT_RSLT ledit_split (T_LEDIT_INTERN *leditInt)
788 {
789
790 char c = leditInt->execBuffer[leditInt->execBufIter];
791 TRACE_FUNCTION("ledit_split");
792
793 /*
794 * check first character of a command: has to be valid basic command letter, "&" or
795 * any extension sign "+", "%" , "$" or what ever else
796 */
797 if(c)
798 {
799 if (ledit_get_cmd_mem (leditInt) EQ LEDIT_FAIL)
800 {
801 return LEDIT_FAIL;
802 }
803 if (isalpha(c))
804 {
805 if (ledit_basic_cmd (leditInt) EQ LEDIT_FAIL)
806 {
807 return LEDIT_FAIL;
808 }
809 }
810 else if (c EQ '&')
811 {
812 if (ledit_and_basic_cmd (leditInt) EQ LEDIT_FAIL)
813 {
814 return LEDIT_FAIL;
815 }
816 }
817 else
818 {
819 if (ledit_extended_cmd (leditInt) EQ LEDIT_FAIL)
820 {
821 return LEDIT_FAIL;
822 }
823 }
824
825 /* here we should peek into the next character to see if command is valid */
826 switch (ledit_lookAhead(leditInt->execBuffer[leditInt->execBufIter]))
827 {
828 /* legal characters */
829 case LEDIT_CHAR_PERCENT: /* '%' */
830 case LEDIT_CHAR_AND: /* '&' */
831 case LEDIT_CHAR_PLUS: /* '+' */
832 case LEDIT_CHAR_CHAR: /* 'A' symbolic for A..Z*/
833 case LEDIT_CHAR_EXT: /*The rest of the characters*/
834 leditInt->cmdIndex++; /* More commands will follow */
835 /*lint -fallthrough */
836 case LEDIT_CHAR_TERMINATED: /* '\0' */
837 return LEDIT_CMPL;
838
839 /* illegal characters */
840 #if 0
841 case LEDIT_CHAR_COMMA: /* ',' */
842 case LEDIT_CHAR_NUMBER: /* '0' symbolic for 0..9 */
843 case LEDIT_CHAR_SEPARATOR: /* ';' */
844 case LEDIT_CHAR_SET: /* '=' */
845 case LEDIT_CHAR_READ: /* '?' */
846 case LEDIT_CHAR_INVALID:
847 #endif
848 default:
849 {
850 return LEDIT_FAIL;
851 }
852 }
853 }
854 else
855 {
856 TRACE_ERROR ("ledit_split: unexp. EOF execBuffer");
857 }
858 return LEDIT_FAIL;
859 }
860
861 /*
862 +--------------------------------------------------------------------+
863 | PROJECT : GSM-F&D (8411) MODULE : LINE_EDIT_LIB |
864 | STATE : code ROUTINE : ledit_restore_dial_string |
865 +--------------------------------------------------------------------+
866
867 PURPOSE : -
868 If there were any 'g' or 'i' characters in a dial string that have
869 been turned into 'G' or 'I' characters on conversion to upper case
870 by the ledit_collect function...
871 Turn them back into the lower case characters so that they affect
872 CUG and CLIR in the way they were intended to.
873 */
874 static T_LEDIT_RSLT ledit_restore_dial_string (char *procDialString,
875 int procDialStringLen,
876 char *origCommandLine,
877 int origCommandLineLen)
878 {
879 int procDialStringIndex = 0; /* Loop index to procDialString array */
880 int origCommandLineIndex = 0; /* Loop index to origCommandLine array */
881 char *origDialString; /* Pointer to original dial string array in origCommandLine */
882 int origDialStringIndex; /* Loop index to origDialString array */
883
884 TRACE_FUNCTION("ledit_restore_dial_string");
885
886 if ((procDialString == NULL) OR
887 (procDialStringLen == 0) OR
888 (origCommandLine == NULL) OR
889 (origCommandLineLen == 0))
890 {
891 TRACE_ERROR("FAILURE: Invalid parameter");
892 if (procDialString == NULL)
893 TRACE_EVENT_P1("procDialString = %p", procDialString);
894 if (procDialStringLen == 0)
895 TRACE_EVENT_P1("procDialStringLen = %d", procDialStringLen);
896 if (origCommandLine == NULL)
897 TRACE_EVENT_P1("origCommandLine = %p", origCommandLine);
898 if (origCommandLineLen == 0)
899 TRACE_EVENT_P1("origCommandLineLen = %d", origCommandLineLen);
900 return LEDIT_FAIL;
901 }
902
903 /* Look for a 'G' or 'I' character in the processed dial string */
904 for (procDialStringIndex = 0;
905 procDialStringIndex < procDialStringLen;
906 procDialStringIndex++)
907 {
908 if ((procDialString[procDialStringIndex] EQ 'G') OR
909 (procDialString[procDialStringIndex] EQ 'I'))
910 {
911 /* 'G' or 'I' found, so we have something to do */
912 break;
913 }
914 }
915
916 if (procDialStringIndex EQ procDialStringLen)
917 {
918 /* No 'G' or 'I' found, so we have nothing to do */
919 TRACE_EVENT("SUCCESS: Nothing to do");
920 return LEDIT_CMPL;
921 }
922
923 /*
924 * Look for the start of the original dial string in the original command
925 * line by looking for 'd' or 'D' characters
926 */
927 for (origCommandLineIndex = 0;
928 origCommandLineIndex < origCommandLineLen;
929 origCommandLineIndex++)
930 {
931 if ((origCommandLine[origCommandLineIndex] EQ 'd') OR
932 (origCommandLine[origCommandLineIndex] EQ 'D'))
933 {
934 /* Found the possible start of the original dial string */
935 origDialString = &origCommandLine[origCommandLineIndex+1];
936 origDialStringIndex = 0;
937
938 for (procDialStringIndex = 0;
939 procDialStringIndex < procDialStringLen;
940 procDialStringIndex++)
941 {
942 /* Ignore any spaces in the original dial string */
943 while (isspace(origDialString[origDialStringIndex]))
944 {
945 origDialStringIndex++;
946 }
947
948 /* Do we have a matching character? */
949 if (origDialString[origDialStringIndex] NEQ procDialString[procDialStringIndex])
950 {
951 /* No: Is the mismatch just on the alphabetic case? */
952 if (isalpha(origDialString[origDialStringIndex]) AND
953 isalpha(procDialString[procDialStringIndex]) AND
954 (toupper(origDialString[origDialStringIndex]) EQ
955 toupper(procDialString[procDialStringIndex])))
956 {
957 /* Yes, so ignore mismatch */;
958 }
959 else
960 { /* No, so not the original dial string */
961 break;
962 }
963 }
964 origDialStringIndex++;
965 }
966
967 /* Have we found the original dial string? */
968 if (procDialStringIndex EQ procDialStringLen)
969 {
970 /* Yes, so copy 'G'/'g' and 'I'/'i' characters from the original dial string */
971 origDialStringIndex = 0;
972 for (procDialStringIndex = 0;
973 procDialStringIndex < procDialStringLen;
974 procDialStringIndex++)
975 {
976 /* Ignore any spaces in the original dial string */
977 while (isspace(origDialString[origDialStringIndex]))
978 {
979 origDialStringIndex++;
980 }
981
982 if ((procDialString[procDialStringIndex] EQ 'G') OR
983 (procDialString[procDialStringIndex] EQ 'I'))
984 { /* Copy the 'G'/'g' or 'I'/'i' character from the original dial string */
985 procDialString[procDialStringIndex] = origDialString[origDialStringIndex];
986 }
987 origDialStringIndex++;
988 }
989
990 TRACE_EVENT("SUCCESS");
991 return LEDIT_CMPL;
992 }
993 }
994 }
995 /* If we get this far then we haven't found the original dial string */
996 TRACE_ERROR("FAILURE: Could not find original dial string");
997 return LEDIT_FAIL;
998 }
999
1000