CAPI/NAP: Implement function bt_nap_activate() 74/19174/1
authorWu Jiangbo <jiangbox.wu@intel.com>
Tue, 8 Apr 2014 07:46:30 +0000 (15:46 +0800)
committerWu Jiangbo <jiangbox.wu@intel.com>
Tue, 8 Apr 2014 08:48:01 +0000 (16:48 +0800)
Change-Id: Id7bb3d69e10fdef2f12bc9ac6b462d8383ab6f2d
Signed-off-by: Wu Jiangbo <jiangbox.wu@intel.com>
capi/bluetooth.c
test/bluez-capi-test.c

index 4faffc6..7afc6af 100644 (file)
@@ -38,6 +38,8 @@
 #define BLUETOOTH_IDENT_LEN 6
 #define CONNMAN_DBUS_NAME "net.connman"
 #define CONNMAN_BLUETOOTH_SERVICE_PREFIX "/net/connman/service/bluetooth_"
+#define CONNMAN_BLUETOOTH_TECHNOLOGY_PATH "/net/connman/technology/bluetooth"
+#define CONNMAN_BLUETOTOH_TECHNOLOGY_INTERFACE "net.connman.Technology"
 
 static bool initialized;
 static bool bt_service_init;
@@ -3712,3 +3714,43 @@ int bt_panu_unset_connection_state_changed_cb(void)
 
        return BT_SUCCESS;
 }
+
+static int connman_set_tethering(bool tethering)
+{
+       GDBusConnection *connection;
+       GVariant *tethering_val;
+       GError *error = NULL;
+
+       if (initialized == false)
+               return BT_ERROR_NOT_INITIALIZED;
+
+       if (default_adapter == NULL)
+               return BT_ERROR_ADAPTER_NOT_FOUND;
+
+       connection = get_system_dbus_connect();
+       if (connection == NULL)
+               return BT_ERROR_OPERATION_FAILED;
+
+       tethering_val = g_variant_new("b", tethering);
+
+       g_dbus_connection_call_sync(connection, CONNMAN_DBUS_NAME,
+                               CONNMAN_BLUETOOTH_TECHNOLOGY_PATH,
+                               CONNMAN_BLUETOTOH_TECHNOLOGY_INTERFACE,
+                               "SetProperty",
+                               g_variant_new("(sv)",
+                                       "Tethering", tethering_val),
+                               NULL, 0, -1, NULL, &error);
+
+       if (error) {
+               DBG("error %s", error->message);
+               g_error_free(error);
+               return BT_ERROR_OPERATION_FAILED;
+       }
+
+       return BT_SUCCESS;
+}
+
+int bt_nap_activate(void)
+{
+       return connman_set_tethering(true);
+}
index 718bf0b..fafb654 100644 (file)
@@ -1483,6 +1483,17 @@ static int panu_disconnect(const char *p1, const char *p2)
        return 0;
 }
 
+static int nap_activate(const char *p1, const char *p2)
+{
+       int ret;
+
+       ret = bt_nap_activate();
+       if (ret != BT_SUCCESS)
+               DBG("bt_nap_activate failed %d", ret);
+
+       return 0;
+}
+
 struct {
        const char *command;
        int (*function)(const char *p1, const char *p2);
@@ -1683,6 +1694,9 @@ struct {
        {"panu_disconnect", panu_disconnect,
                "Usage: panu_disconnect 70:F9:27:64:DF:65\n\tdisconnect address for panu"},
 
+       {"nap_activate", nap_activate,
+               "Usage: nap_activate\n\tactivate NAP"},
+
        {"q", quit,
                "Usage: q\n\tQuit"},