---
 Makefile.am                     |    1 +
 drivers/isimodem/isimodem.c     |    4 +
 drivers/isimodem/isimodem.h     |    3 +
 drivers/isimodem/radio-access.c |  444 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 452 insertions(+), 0 deletions(-)
 create mode 100644 drivers/isimodem/radio-access.c

diff --git a/Makefile.am b/Makefile.am
index 5f67878..235aa86 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -103,6 +103,7 @@ builtin_sources += $(gisi_sources) \
                                drivers/isimodem/call-barring.c \
                                drivers/isimodem/call-meter.c \
                                drivers/isimodem/ss.h \
+                               drivers/isimodem/radio-access.c \
                                drivers/isimodem/gss.h
 endif
 
diff --git a/drivers/isimodem/isimodem.c b/drivers/isimodem/isimodem.c
index 48f41c3..4b65d21 100644
--- a/drivers/isimodem/isimodem.c
+++ b/drivers/isimodem/isimodem.c
@@ -49,6 +49,7 @@
 #include <ofono/call-settings.h>
 #include <ofono/call-barring.h>
 #include <ofono/call-meter.h>
+#include <ofono/radio-access.h>
 
 #include "isimodem.h"
 #include "isiutil.h"
@@ -310,6 +311,7 @@ static void isi_modem_post_sim(struct ofono_modem *modem)
        ofono_call_settings_create(isi->modem, 0, "isimodem", isi->idx);
        ofono_call_barring_create(isi->modem, 0, "isimodem", isi->idx);
        ofono_call_meter_create(isi->modem, 0, "isimodem", isi->idx);
+       ofono_radio_access_create(isi->modem, 0, "isimodem", isi->idx);
 }
 
 static struct ofono_modem_driver driver = {
@@ -339,6 +341,7 @@ static int isimodem_init(void)
        isi_call_settings_init();
        isi_call_barring_init();
        isi_call_meter_init();
+       isi_radio_access_init();
 
        ofono_modem_driver_register(&driver);
 
@@ -379,6 +382,7 @@ static void isimodem_exit(void)
        isi_call_settings_exit();
        isi_call_barring_exit();
        isi_call_meter_exit();
+       isi_radio_access_exit();
 }
 
 OFONO_PLUGIN_DEFINE(isimodem, "PhoNet / ISI modem driver", VERSION,
diff --git a/drivers/isimodem/isimodem.h b/drivers/isimodem/isimodem.h
index 3eb2fbe..2b3d756 100644
--- a/drivers/isimodem/isimodem.h
+++ b/drivers/isimodem/isimodem.h
@@ -57,3 +57,6 @@ extern void isi_call_barring_exit();
 
 extern void isi_call_meter_init();
 extern void isi_call_meter_exit();
+
+extern void isi_radio_access_init();
+extern void isi_radio_access_exit();
diff --git a/drivers/isimodem/radio-access.c b/drivers/isimodem/radio-access.c
new file mode 100644
index 0000000..010c747
--- /dev/null
+++ b/drivers/isimodem/radio-access.c
@@ -0,0 +1,444 @@
+/*
+ * This file is part of oFono - Open Source Telephony
+ *
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <glib.h>
+
+#include <gisi/client.h>
+#include <gisi/iter.h>
+
+#include <ofono/log.h>
+#include <ofono/modem.h>
+#include <ofono/radio-access.h>
+
+#include "isimodem.h"
+#include "isiutil.h"
+#include "debug.h"
+#include "gss.h"
+#include "network.h"
+
+struct access_data {
+       GIsiClient *net_client;
+       GIsiClient *gss_client;
+       int net_ok:1;
+       int gss_ok:1;
+};
+
+static enum ofono_radio_access_mode isi_mode_to_ofono_mode(guint8 mode)
+{
+       switch (mode) {
+       case GSS_DUAL_RAT:
+               return OFONO_RADIO_ACCESS_MODE_2G_3G;
+       case GSS_GSM_RAT:
+               return OFONO_RADIO_ACCESS_MODE_2G;
+       case GSS_UMTS_RAT:
+               return OFONO_RADIO_ACCESS_MODE_3G;
+       default:
+               return -1;
+       }
+}
+
+static guint8 ofono_mode_to_isi_mode(enum ofono_radio_access_mode mode)
+{
+       switch (mode) {
+       case OFONO_RADIO_ACCESS_MODE_3G_2G:
+       case OFONO_RADIO_ACCESS_MODE_2G_3G:
+               return GSS_DUAL_RAT;
+       case OFONO_RADIO_ACCESS_MODE_2G:
+               return GSS_GSM_RAT;
+       case OFONO_RADIO_ACCESS_MODE_3G:
+               return GSS_UMTS_RAT;
+       default:
+               return -1;
+       }
+}
+
+static enum ofono_radio_access_state isi_state_to_ofono_state(guint state)
+{
+       switch (state) {
+       case NET_UTRAN_RADIO_IDLE:
+               return OFONO_RADIO_ACCESS_STATE_IDLE;
+       case NET_UTRAN_RADIO_CELL_DCH:
+               return OFONO_RADIO_ACCESS_STATE_ACTIVE;
+       default:
+               return -1;
+       }
+}
+
+static bool rat_mode_read_resp_cb(GIsiClient *client, const void *restrict 
data,
+                                       size_t len, uint16_t object, void 
*opaque)
+{
+       const unsigned char *msg = data;
+       struct isi_cb_data *cbd = opaque;
+       ofono_radio_access_mode_query_cb_t cb = cbd->cb;
+       int mode = -1;
+
+       if (!msg) {
+               DBG("ISI client error: %d", g_isi_client_error(client));
+               goto error;
+       }
+
+       if (len < 3) {
+               DBG("truncated message");
+               return false;
+       }
+
+       if (msg[0] == GSS_CS_SERVICE_FAIL_RESP)
+               goto error;
+
+       if (msg[0] == GSS_CS_SERVICE_RESP) {
+               GIsiSubBlockIter iter;
+
+               for (g_isi_sb_iter_init(&iter, msg, len, 3);
+                       g_isi_sb_iter_is_valid(&iter);
+                       g_isi_sb_iter_next(&iter)) {
+
+                       switch (g_isi_sb_iter_get_id(&iter)) {
+
+                       case GSS_RAT_INFO: {
+                               guint8 info;
+
+                               if (!g_isi_sb_iter_get_byte(&iter, &info, 2))
+                                       goto error;
+
+                               mode = isi_mode_to_ofono_mode(info);
+
+                               break;
+                       }
+                       default:
+                               DBG("Skipping sub-block: %s (%zu bytes)",
+                                       
gss_subblock_name(g_isi_sb_iter_get_id(&iter)),
+                                       g_isi_sb_iter_get_len(&iter));
+                               break;
+                       }
+               }
+
+               CALLBACK_WITH_SUCCESS(cb, mode, cbd->data);
+               goto out;
+       }
+
+       return false;
+
+error:
+       CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+
+out:
+       g_free(cbd);
+       return true;
+}
+
+static void isi_query_mode(struct ofono_radio_access *ra,
+                               ofono_radio_access_mode_query_cb_t cb,
+                               void *data)
+{
+       struct access_data *access = ofono_radio_access_get_data(ra);
+       struct isi_cb_data *cbd = isi_cb_data_new(access, cb, data);
+
+       const unsigned char msg[] = {
+               GSS_CS_SERVICE_REQ,
+               GSS_SELECTED_RAT_READ,
+               0x00 /* subblock count */
+       };
+
+       if (!cbd)
+               goto error;
+
+       if (g_isi_request_make(access->gss_client, msg, sizeof(msg),
+                               GSS_TIMEOUT, rat_mode_read_resp_cb, cbd))
+               return;
+
+error:
+       CALLBACK_WITH_FAILURE(cb, -1, data);
+       g_free(cbd);
+}
+
+static bool rat_mode_write_resp_cb(GIsiClient *client, const void *restrict 
data,
+                                       size_t len, uint16_t object, void 
*opaque)
+{
+       const unsigned char *msg = data;
+       struct isi_cb_data *cbd = opaque;
+       ofono_radio_access_mode_set_cb_t cb = cbd->cb;
+
+       if (!msg) {
+               DBG("ISI client error: %d", g_isi_client_error(client));
+               goto error;
+       }
+
+       if (len < 3) {
+               DBG("truncated message");
+               return false;
+       }
+
+       if (msg[0] == GSS_CS_SERVICE_FAIL_RESP)
+               goto error;
+
+       if (msg[0] == GSS_CS_SERVICE_RESP) {
+               CALLBACK_WITH_SUCCESS(cb, cbd->data);
+               goto out;
+       }
+
+       return false;
+
+error:
+       CALLBACK_WITH_FAILURE(cb, cbd->data);
+
+out:
+       g_free(cbd);
+       return true;
+}
+
+static void isi_set_mode(struct ofono_radio_access *ra,
+                               enum ofono_radio_access_mode mode,
+                               ofono_radio_access_mode_set_cb_t cb,
+                               void *data)
+{
+       struct access_data *access = ofono_radio_access_get_data(ra);
+       struct isi_cb_data *cbd = isi_cb_data_new(access, cb, data);
+
+       const unsigned char msg[] = {
+               GSS_CS_SERVICE_REQ,
+               GSS_SELECTED_RAT_WRITE,
+               0x01, /* subblock count */
+               GSS_RAT_INFO,
+               0x04, /* subblock length */
+               ofono_mode_to_isi_mode(mode),
+               0x00 /* filler */
+       };
+
+       if (!cbd)
+               goto error;
+
+       if (g_isi_request_make(access->gss_client, msg, sizeof(msg),
+                               GSS_TIMEOUT, rat_mode_write_resp_cb, cbd))
+               return;
+
+error:
+       CALLBACK_WITH_FAILURE(cb, data);
+       g_free(cbd);
+}
+
+static void rat_mode_ind_cb(GIsiClient *client, const void *restrict data,
+                               size_t len, uint16_t object, void *opaque)
+{
+       const unsigned char *msg = data;
+       struct ofono_radio_access *ra = opaque;
+
+       if (!msg || len < 3 || msg[0] != GSS_SELECTED_RAT_IND)
+               return;
+
+       ofono_radio_access_mode_notify(ra, msg[1]);
+}
+
+static void radio_info_ind_cb(GIsiClient *client, const void *restrict data,
+                               size_t len, uint16_t object, void *opaque)
+{
+       const unsigned char *msg = data;
+       struct ofono_radio_access *ra = opaque;
+       GIsiSubBlockIter iter;
+       int state = -1;
+
+       if (!msg || len < 3 || msg[0] != NET_RADIO_INFO_IND)
+               return;
+
+       for (g_isi_sb_iter_init(&iter, msg, len, 3);
+               g_isi_sb_iter_is_valid(&iter);
+               g_isi_sb_iter_next(&iter)) {
+
+               switch (g_isi_sb_iter_get_id(&iter)) {
+
+               case NET_UTRAN_RADIO_INFO: {
+                       guint8 info = 0;
+
+                       if (!g_isi_sb_iter_get_byte(&iter, &info, 2))
+                               return;
+
+                       state = isi_state_to_ofono_state(info);
+
+                       break;
+               }
+               default:
+                       DBG("Skipping sub-block: %s (%zu bytes)",
+                               net_subblock_name(g_isi_sb_iter_get_id(&iter)),
+                               g_isi_sb_iter_get_len(&iter));
+                       break;
+               }
+       }
+
+       ofono_radio_access_state_notify(ra, state);
+}
+
+static void rat_ind_cb(GIsiClient *client, const void *restrict data,
+                       size_t len, uint16_t object, void *opaque)
+{
+       const unsigned char *msg = data;
+       struct ofono_radio_access *ra = opaque;
+       GIsiSubBlockIter iter;
+       guint8 rat = 0;
+
+       if (!msg || len < 3 || msg[0] != NET_RAT_IND)
+               return;
+
+       for (g_isi_sb_iter_init(&iter, msg, len, 3);
+               g_isi_sb_iter_is_valid(&iter);
+               g_isi_sb_iter_next(&iter)) {
+
+               switch (g_isi_sb_iter_get_id(&iter)) {
+
+               case NET_RAT_INFO:
+
+                       if (!g_isi_sb_iter_get_byte(&iter, &rat, 2))
+                               return;
+                       break;
+
+               default:
+                       DBG("Skipping sub-block: %s (%zu bytes)",
+                               net_subblock_name(g_isi_sb_iter_get_id(&iter)),
+                               g_isi_sb_iter_get_len(&iter));
+                       break;
+               }
+       }
+
+       /* GSS only reports on UTRAN radio state */
+       if (rat != NET_UMTS_RAT)
+               ofono_radio_access_state_notify(ra, -1);
+}
+
+static gboolean isi_radio_access_register(gpointer user)
+{
+       struct ofono_radio_access *ra = user;
+       struct access_data *access = ofono_radio_access_get_data(ra);
+
+       const char *debug = getenv("OFONO_ISI_DEBUG");
+
+       if (debug && (g_strcmp0(debug, "all") == 0
+               || g_strcmp0(debug, "gss") == 0))
+               g_isi_client_set_debug(access->gss_client, gss_debug, NULL);
+
+       g_isi_subscribe(access->gss_client, GSS_SELECTED_RAT_IND,
+                       rat_mode_ind_cb, ra);
+
+       if (debug && (g_strcmp0(debug, "all") == 0
+               || g_strcmp0(debug, "net") == 0))
+               g_isi_client_set_debug(access->net_client, net_debug, NULL);
+
+       g_isi_subscribe(access->net_client, NET_RAT_IND, rat_ind_cb, ra);
+       g_isi_subscribe(access->net_client, NET_RADIO_INFO_IND,
+                       radio_info_ind_cb, ra);
+
+       ofono_radio_access_register(ra);
+
+       return FALSE;
+}
+
+static void reachable_cb(GIsiClient *client, bool alive, uint16_t object,
+                               void *opaque)
+{
+       struct ofono_radio_access *ra = opaque;
+       struct access_data *ad = ofono_radio_access_get_data(ra);
+       uint8_t resource = g_isi_client_resource(client);
+
+       if (!alive) {
+               DBG("radio access driver bootstrap failed");
+               return;
+       }
+
+       DBG("%s (v%03d.%03d) reachable",
+               pn_resource_name(resource),
+               g_isi_version_major(client),
+               g_isi_version_minor(client));
+
+       if (resource == PN_NETWORK)
+               ad->net_ok = 1;
+
+       if (resource == PN_GSS)
+               ad->gss_ok = 1;
+
+       if (ad->net_ok && ad->gss_ok)
+               g_idle_add(isi_radio_access_register, ra);
+}
+
+static int isi_radio_access_probe(struct ofono_radio_access *ra, unsigned int 
vendor,
+                                       void *user)
+{
+       GIsiModem *idx = user;
+       struct access_data *data = g_try_new0(struct access_data, 1);
+
+       if (!data)
+               return -ENOMEM;
+
+       data->gss_client = g_isi_client_create(idx, PN_GSS);
+       if (!data->gss_client) {
+               g_free(data);
+               return -ENOMEM;
+       }
+
+       data->net_client = g_isi_client_create(idx, PN_NETWORK);
+       if (!data->net_client) {
+               g_isi_client_destroy(data->gss_client);
+               g_free(data);
+               return -ENOMEM;
+       }
+
+       ofono_radio_access_set_data(ra, data);
+
+       g_isi_verify(data->gss_client, reachable_cb, ra);
+       g_isi_verify(data->net_client, reachable_cb, ra);
+
+       return 0;
+}
+
+static void isi_radio_access_remove(struct ofono_radio_access *ra)
+{
+       struct access_data *data = ofono_radio_access_get_data(ra);
+
+       if (data) {
+               g_isi_client_destroy(data->gss_client);
+               g_isi_client_destroy(data->net_client);
+               g_free(data);
+       }
+}
+
+static struct ofono_radio_access_driver driver = {
+       .name                   = "isimodem",
+       .probe                  = isi_radio_access_probe,
+       .remove                 = isi_radio_access_remove,
+       .query_mode             = isi_query_mode,
+       .set_mode               = isi_set_mode
+};
+
+void isi_radio_access_init()
+{
+       ofono_radio_access_driver_register(&driver);
+}
+
+void isi_radio_access_exit()
+{
+       ofono_radio_access_driver_unregister(&driver);
+}
-- 
1.6.3.3

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

Reply via email to