Set APN before connecting via oFono plugin
authorMartin Xu <martin.xu@intel.com>
Fri, 22 Jan 2010 05:30:47 +0000 (13:30 +0800)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 23 Jan 2010 09:45:48 +0000 (10:45 +0100)
plugins/ofono.c
src/service.c

index a35ae3f..4e92aa9 100644 (file)
@@ -417,11 +417,77 @@ static int set_network_active(struct connman_network *network,
        return 0;
 }
 
+static void set_apn_reply(DBusPendingCall *call, void *user_data)
+{
+       DBusMessage *reply;
+       DBusError error;
+
+       reply = dbus_pending_call_steal_reply(call);
+
+       dbus_error_init(&error);
+       if (dbus_set_error_from_message(&error, reply)) {
+               connman_error("%s", error.message);
+
+               dbus_error_free(&error);
+       }
+
+       dbus_message_unref(reply);
+
+       dbus_pending_call_unref(call);
+}
+
+static void set_apn(struct connman_network *network)
+{
+       DBusMessage *message;
+       DBusPendingCall *call;
+       DBusMessageIter iter;
+       const char *apn, *path;
+
+       apn = connman_network_get_string(network, "Cellular.APN");
+       if (apn == NULL)
+               return;
+
+       path = connman_network_get_string(network, "Path");
+       if (path == NULL)
+               return;
+
+       DBG("path %s, apn %s", path, apn);
+
+       message = dbus_message_new_method_call(OFONO_SERVICE, path,
+                               OFONO_PRI_CONTEXT_INTERFACE, SET_PROPERTY);
+       if (message == NULL)
+               return;
+
+       dbus_message_set_auto_start(message, FALSE);
+
+       dbus_message_iter_init_append(message, &iter);
+       connman_dbus_property_append_basic(&iter, "AccessPointName",
+                                               DBUS_TYPE_STRING, &apn);
+
+       if (dbus_connection_send_with_reply(connection, message,
+                                       &call, TIMEOUT) == FALSE) {
+               dbus_message_unref(message);
+               return;
+       }
+
+       if (call == NULL) {
+               connman_error("D-Bus connection not available");
+               dbus_message_unref(message);
+               return;
+       }
+
+       dbus_pending_call_set_notify(call, set_apn_reply, NULL, NULL);
+
+       dbus_message_unref(message);
+}
+
 static int network_connect(struct connman_network *network)
 {
        if (connman_network_get_index(network) >= 0)
                return -EISCONN;
 
+       set_apn(network);
+
        return set_network_active(network, TRUE);
 }
 
index aa0599b..4e5a43f 100644 (file)
@@ -1658,8 +1658,8 @@ static connman_bool_t prepare_network(struct connman_service *service)
        case CONNMAN_NETWORK_TYPE_WIMAX:
        case CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN:
        case CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN:
-       case CONNMAN_NETWORK_TYPE_CELLULAR:
                break;
+       case CONNMAN_NETWORK_TYPE_CELLULAR:
        case CONNMAN_NETWORK_TYPE_MBM:
        case CONNMAN_NETWORK_TYPE_HSO:
                connman_network_set_string(service->network,