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