According to V.250 5.3.1, the basic command is either a single
character or the '&' followed by a single character.
---
 gatchat/gatserver.c |   99 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index 8e7955c..2c53d84 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -197,16 +197,111 @@ static gboolean is_basic_command_prefix(const char *buf)
        return FALSE;
 }
 
+static gboolean at_command_notify(GAtServer *server, char *command,
+                                               char *prefix)
+{
+       return FALSE;
+}
+
 static void parse_extended_command(GAtServer *server, char *buf,
                                        unsigned int *len)
 {
        g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
 }
 
-static void parse_basic_command(GAtServer *server, char *buf,
+static gboolean get_basic_prefix(const char *buf, char *prefix)
+{
+       char c = *buf;
+
+       if (!g_ascii_isalpha(c) && c != '&')
+               return FALSE;
+
+       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';
+               }
+       }
+
+       if (c == '&') {
+               prefix[0] = '&';
+               prefix[1] = g_ascii_toupper(buf[1]);
+               prefix[2] = '\0';
+       }
+
+       return TRUE;
+}
+
+static unsigned int get_basic_length(const char *buf, char *prefix, char t)
+{
+       unsigned int i;
+
+       i = strlen(prefix);
+
+       if (*buf == 'D' || *buf == 'd') {
+               /* All following characters are the part of the call */
+               while (buf[i] && buf[i] != t)
+                       i++;
+       } else {
+               /* Match '?', '=', '=?' or '=123' */
+               if (buf[i] == '=')
+                       i++;
+
+               if (buf[i] == '?')
+                       i++;
+               else {
+                       /* V.250 5.3.1 The subparameter are all digits */
+                       while (g_ascii_isdigit(buf[i]))
+                               i++;
+               }
+       }
+
+       return i;
+}
+
+static void parse_basic_command(GAtServer *server, const char *buf,
                                        unsigned int *len)
 {
-       g_at_server_send_final(server, G_AT_SERVER_RESULT_ERROR);
+       char *command = NULL;
+       char prefix[20];
+       unsigned int i = 0;
+
+       if (!get_basic_prefix(buf, prefix))
+               goto done;
+
+       i = get_basic_length(buf, prefix, server->v250.s3);
+
+       command = g_strndup(buf, i);
+
+       if (!at_command_notify(server, command, prefix)) {
+               i = 0;
+               goto done;
+       }
+
+       /* Commands like ATA, ATD, ATZ cause the remainder line
+        * to be ignored.
+        */
+       if (*prefix == 'A' || *prefix == 'D' || *prefix == 'Z')
+               i = 0;
+
+done:
+       if (command)
+               g_free(command);
+
+       *len = i;
 }
 
 static void server_parse_line(GAtServer *server, char *line)
-- 
1.6.6.1

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to