According to V.250 5.3.1, the basic command is either a single
character or the '&' followed by a single character except for 'D'
and 'S'.
The subparameter should be the numbers.
---
gatchat/gatserver.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 66 insertions(+), 1 deletions(-)
diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index c54170e..b3c3f5f 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -211,9 +211,68 @@ static char *parse_extended_command(GAtServer *server, char *buf,
return NULL;
}
+static gboolean get_basic_prefix(char *buf, char *prefix)
+{
+ char c = buf[0];
+
+ if (g_ascii_isalpha(c)) {
+ c = g_ascii_toupper(c);
+
+ if (c == 'S') {
+ int i = 0;
+
+ prefix[0] = 'S';
+
+ /* V.250 5.3.2 'S' command follows with
+ * a parameter number.
+ */
+ while (g_ascii_isdigit(buf[++i]))
+ prefix[i] = buf[i];
+
+ prefix[i] = '\0';
+ } else {
+ prefix[0] = c;
+ prefix[1] = '\0';
+ }
+ } else if (c == '&') {
+ prefix[0] = '&';
+ prefix[1] = g_ascii_toupper(buf[1]);
+ prefix[2] = '\0';
+ } else
+ return FALSE;
+
+ return TRUE;
+}
+
static char *parse_basic_command(GAtServer *server, char *buf, char *prefix)
{
- return NULL;
+ int i = 0;
+ char t = server->v250.s3;
+ char c = g_ascii_toupper(buf[0]);
+
+ if (!get_basic_prefix(buf, prefix))
+ return NULL;
+
+ i = strlen(prefix);
+
+ if (c == 'D') {
+ /* All following characters are the part of the call */
+ while (buf[i] && buf[i] != t && buf[i] != ';')
+ i++;
+ } else {
+ /* V.250 5.3.2 Skip '=' for S-parameters if have */
+ if (c == 'S' && buf[i] == '=')
+ i++;
+
+ if (buf[i] == '?')
+ i++;
+
+ /* V.250 5.3.1 The subparameter are all digits if have */
+ while (g_ascii_isdigit(buf[i]))
+ i++;
+ }
+
+ return g_strndup(buf, i);
}
static char *server_parse_next_command(GAtServer *server, char *buf,
@@ -258,6 +317,12 @@ static GAtServerResult server_parse_line(GAtServer *server, char
*line)
if (res != G_AT_SERVER_RESULT_OK)
break;
+ /* Commands like ATA, ATD cause the remainder line
+ * to be ignored.
+ */
+ if (!strcmp(prefix, "A") || !strcmp(prefix, "D"))
+ break;
+
line += strlen(command);
g_free(command);
--
1.6.6.1