From 02c5b73f6e3882ae2872ce9653289cda391e9cc5 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Mon, 20 Jan 2014 21:42:13 -0600 Subject: [PATCH] =?UTF-8?q?emulator:=20Fix=20CHLD=3D=3F=20not=20treated=20?= =?UTF-8?q?as=20part=20of=20SLC?= --- src/emulator.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/emulator.c b/src/emulator.c index 6171525e..95697d35 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -1073,16 +1073,11 @@ struct ofono_emulator_request { }; static void handler_proxy(GAtServer *server, GAtServerRequestType type, - GAtResult *result, gpointer userdata) + GAtResult *result, gpointer userdata) { struct handler *h = userdata; struct ofono_emulator_request req; - if (h->em->type == OFONO_EMULATOR_TYPE_HFP && h->em->slc == FALSE) { - g_at_server_send_final(h->em->server, G_AT_SERVER_RESULT_ERROR); - return; - } - switch (type) { case G_AT_SERVER_REQUEST_TYPE_COMMAND_ONLY: req.type = OFONO_EMULATOR_REQUEST_TYPE_COMMAND_ONLY; @@ -1103,6 +1098,33 @@ static void handler_proxy(GAtServer *server, GAtServerRequestType type, h->cb(h->em, &req, h->data); } +static void handler_proxy_need_slc(GAtServer *server, + GAtServerRequestType type, + GAtResult *result, gpointer userdata) +{ + struct handler *h = userdata; + + if (h->em->slc == FALSE) { + g_at_server_send_final(h->em->server, G_AT_SERVER_RESULT_ERROR); + return; + } + + handler_proxy(server, type, result, userdata); +} + +static void handler_proxy_chld(GAtServer *server, GAtServerRequestType type, + GAtResult *result, gpointer userdata) +{ + struct handler *h = userdata; + + if (h->em->slc == FALSE && type != G_AT_SERVER_REQUEST_TYPE_SUPPORT) { + g_at_server_send_final(h->em->server, G_AT_SERVER_RESULT_ERROR); + return; + } + + handler_proxy(server, type, result, userdata); +} + static void handler_destroy(gpointer userdata) { struct handler *h = userdata; @@ -1119,6 +1141,7 @@ ofono_bool_t ofono_emulator_add_handler(struct ofono_emulator *em, void *data, ofono_destroy_func destroy) { struct handler *h; + GAtServerNotifyFunc func = handler_proxy; h = g_new0(struct handler, 1); h->cb = cb; @@ -1126,7 +1149,14 @@ ofono_bool_t ofono_emulator_add_handler(struct ofono_emulator *em, h->destroy = destroy; h->em = em; - if (g_at_server_register(em->server, prefix, handler_proxy, h, + if (em->type == OFONO_EMULATOR_TYPE_HFP) { + func = handler_proxy_need_slc; + + if (!strcmp(prefix, "+CHLD")) + func = handler_proxy_chld; + } + + if (g_at_server_register(em->server, prefix, func, h, handler_destroy) == TRUE) return TRUE;