From adb87b83c3ccd6e5dbfafccfde39f5bc9f73722c Mon Sep 17 00:00:00 2001 From: Yang Gu Date: Tue, 17 Nov 2009 17:30:17 +0800 Subject: [PATCH] Support vendor specific terminator --- gatchat/gatchat.c | 44 ++++++++++++++++++++++++++++---------------- gatchat/gatchat.h | 3 +++ plugins/huawei.c | 1 + 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c index 320150a..f9238f8 100644 --- a/gatchat/gatchat.c +++ b/gatchat/gatchat.c @@ -88,6 +88,7 @@ struct _GAtChat { GTimer *wakeup_timer; /* Keep track of elapsed time */ GAtSyntax *syntax; gboolean destroyed; /* Re-entrancy guard */ + GSList *terminator_table; }; static gint at_notify_node_compare_by_id(gconstpointer a, gconstpointer b) @@ -251,6 +252,10 @@ static void g_at_chat_cleanup(GAtChat *chat) chat->syntax = NULL; chat->channel = NULL; + + g_slist_foreach(chat->terminator_table, (GFunc)g_free, NULL); + g_slist_free(chat->terminator_table); + chat->terminator_table = NULL; } static void read_watcher_destroy_notify(GAtChat *chat) @@ -365,29 +370,25 @@ struct terminator_info { gboolean success; }; -static struct terminator_info terminator_table[] = { - { "OK", -1, TRUE }, - { "ERROR", -1, FALSE }, - { "NO DIALTONE", -1, FALSE }, - { "BUSY", -1, FALSE }, - { "NO CARRIER", -1, FALSE }, - { "CONNECT", -1, TRUE }, - { "NO ANSWER", -1, FALSE }, - { "+CMS ERROR:", 11, FALSE }, - { "+CME ERROR:", 11, FALSE }, - { "+EXT ERROR:", 11, FALSE } -}; +void g_at_chat_add_terminator(GAtChat *chat, const char *terminator, + int len, gboolean success) +{ + struct terminator_info *ti = g_new0(struct terminator_info, 1); + ti->terminator = terminator; + ti->len = len; + ti->success = success; + chat->terminator_table = g_slist_prepend(chat->terminator_table, ti); +} static gboolean g_at_chat_handle_command_response(GAtChat *p, struct at_command *cmd, char *line) { - int i; - int size = sizeof(terminator_table) / sizeof(struct terminator_info); + GSList *l; int hint; - for (i = 0; i < size; i++) { - struct terminator_info *info = &terminator_table[i]; + for (l = p->terminator_table; l; l = l->next) { + struct terminator_info *info = l->data; if (info->len == -1 && !strcmp(line, info->terminator)) { g_at_chat_finish_command(p, info->success, line); @@ -951,6 +952,17 @@ GAtChat *g_at_chat_new(GIOChannel *channel, GAtSyntax *syntax) chat->syntax = g_at_syntax_ref(syntax); + g_at_chat_add_terminator(chat, "+EXT ERROR:", 11, FALSE); + g_at_chat_add_terminator(chat, "+CME ERROR:", 11, FALSE); + g_at_chat_add_terminator(chat, "+CMS ERROR:", 11, FALSE); + g_at_chat_add_terminator(chat, "NO ANSWER", -1, FALSE); + g_at_chat_add_terminator(chat, "CONNECT", -1, TRUE); + g_at_chat_add_terminator(chat, "NO CARRIER", -1, FALSE); + g_at_chat_add_terminator(chat, "BUSY", -1, FALSE); + g_at_chat_add_terminator(chat, "NO DIALTONE", -1, FALSE); + g_at_chat_add_terminator(chat, "ERROR", -1, FALSE); + g_at_chat_add_terminator(chat, "OK", -1, TRUE); + return chat; error: diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h index fe5b97b..b191f1b 100644 --- a/gatchat/gatchat.h +++ b/gatchat/gatchat.h @@ -128,6 +128,9 @@ gboolean g_at_chat_unregister(GAtChat *chat, guint id); gboolean g_at_chat_set_wakeup_command(GAtChat *chat, const char *cmd, guint timeout, guint msec); +void g_at_chat_add_terminator(GAtChat *chat, const char *terminator, + int len, gboolean success); + #ifdef __cplusplus } diff --git a/plugins/huawei.c b/plugins/huawei.c index 28b7650..df8ef40 100644 --- a/plugins/huawei.c +++ b/plugins/huawei.c @@ -107,6 +107,7 @@ static int huawei_enable(struct ofono_modem *modem) syntax = g_at_syntax_new_gsmv1(); data->chat = g_at_chat_new(channel, syntax); + g_at_chat_add_terminator(data->chat, "COMMAND NOT SUPPORT", -1, FALSE); g_at_syntax_unref(syntax); g_io_channel_unref(channel); -- 1.6.2.5