+
+API int tethering_wifi_set_txpower(tethering_h tethering, unsigned int txpower)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ GError *error = NULL;
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
+ TETHERING_ERROR_NOT_ENABLED,
+ "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
+ __tethering_h *th = (__tethering_h *)tethering;
+ th->txpower = txpower;
+
+ g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_set_txpower",
+ g_variant_new("(u)", txpower),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, th->cancellable, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+ g_clear_error(&error);
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_txpower(tethering_h tethering, unsigned int *txpower)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ GError *error = NULL;
+ GVariant *result = NULL;
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(txpower == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(txpower) is NULL\n");
+ _retvm_if(tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) == false,
+ TETHERING_ERROR_NOT_ENABLED,
+ "tethering type[%d] is not enabled\n", TETHERING_TYPE_WIFI);
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ result = g_dbus_proxy_call_sync(th->client_bus_proxy, "hostapd_get_txpower",
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, th->cancellable, &error);
+
+ if (result != NULL) {
+ g_variant_get(result, "(u)", txpower);
+ g_variant_unref(result);
+ } else {
+ if (error)
+ ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+ g_clear_error(&error);
+ return TETHERING_ERROR_OPERATION_FAILED;
+ }
+ g_clear_error(&error);
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_set_mtu(tethering_h tethering, unsigned int mtu)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "set_mtu",
+ g_variant_new("(u)", mtu),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+
+ g_variant_unref(parameters);
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_change_mac(tethering_h tethering, char *mac)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(mac == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(mac) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "change_mac",
+ g_variant_new("(s)", mac),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ if (result == MOBILE_AP_ERROR_NOT_PERMITTED)
+ return TETHERING_ERROR_NOT_SUPPORT_API;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_set_max_connected_device(tethering_h tethering, int max_device)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ th->wifi_max_connected = max_device;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_max_connected_device(tethering_h tethering, int *max_device)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(max_device == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(max_device) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ *max_device = th->wifi_max_connected;
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_enable_port_forwarding(tethering_h tethering, bool enable)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "enable_port_forwarding",
+ g_variant_new("(b)", enable),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ th->port_forwarding = true;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_add_port_forwarding_rule(tethering_h tethering, char *ifname, char *protocol, char *org_ip, int org_port, char *final_ip, int final_port)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(ifname == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(ifname) is NULL\n");
+ _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(protocol) is NULL\n");
+ _retvm_if(org_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(org_ip) is NULL\n");
+ _retvm_if(final_ip == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(final_ip) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+ char cmd[MAX_BUF_SIZE] = { 0, };
+ char *list = NULL;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "add_port_forwarding_rule",
+ g_variant_new("(sssisi)", ifname, protocol, org_ip, org_port, final_ip, final_port),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ snprintf(cmd, sizeof(cmd), "%s "PORT_FORWARD_RULE_STR, IPTABLES, TABLE_NAT, TETH_NAT_PRE, ifname, protocol, org_ip, org_port, final_ip, final_port);
+
+ list = strdup(cmd);
+ if (list == NULL) {
+ ERR("strdup failed\n");
+ return TETHERING_ERROR_OUT_OF_MEMORY;
+ }
+
+ port_forwarding = g_slist_append(port_forwarding, list);
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_reset_port_forwarding_rule(tethering_h tethering)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "reset_port_forwarding_rule",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+
+ g_variant_unref(parameters);
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_is_port_forwarding_enabled(tethering_h tethering, bool *forwarding_enabled)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(forwarding_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(forwarding_enabled) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ *forwarding_enabled = th->port_forwarding;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_port_forwarding_rule(tethering_h tethering, void **port_forwarding_list)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(port_forwarding_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(port_forwarding_list) is NULL\n");
+
+ *port_forwarding_list = g_slist_copy(port_forwarding);
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_enable_port_filtering(tethering_h tethering, bool enable)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "enable_port_filtering",
+ g_variant_new("(b)", enable),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ th->port_filtering = true;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_add_port_filtering_rule(tethering_h tethering, int port, char *protocol, bool allow)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(protocol) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+ char *list = NULL;
+ int ret;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "add_port_filtering_rule",
+ g_variant_new("(isb)", port, protocol, allow),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ if (allow)
+ ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_ACCEPT);
+ else
+ ret = asprintf(&list, "%s "FILTERING_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port, ACTION_DROP);
+
+ if (ret == -1 || list == NULL) {
+ ERR("asprintf failed\n");
+ return TETHERING_ERROR_OUT_OF_MEMORY;
+ }
+
+ DBG("cmd:%s", list);
+
+ port_filtering = g_slist_append(port_filtering, list);
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_add_custom_port_filtering_rule(tethering_h tethering, int port1, int port2, char *protocol, bool allow)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(protocol == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(protocol) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+ char *list = NULL;
+ int ret;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "add_custom_port_filtering_rule",
+ g_variant_new("(iisb)", port1, port2, protocol, allow),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+ g_variant_unref(parameters);
+
+ if (allow)
+ ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_ACCEPT);
+ else
+ ret = asprintf(&list, "%s "FILTERING_MULTIPORT_RULE_STR, IPTABLES, TABLE_FILTER, TETH_FILTER_FW, protocol, port1, port2, ACTION_DROP);
+
+ if (ret == -1 || list == NULL) {
+ ERR("asprintf failed\n");
+ return TETHERING_ERROR_OUT_OF_MEMORY;
+ }
+
+ DBG("cmd:%s", list);
+
+ custom_port_filtering = g_slist_append(custom_port_filtering, list);
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_port_filtering_rule(tethering_h tethering, void **port_filtering_list)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(port_filtering_list) is NULL\n");
+
+ *port_filtering_list = g_slist_copy(port_filtering);
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_custom_port_filtering_rule(tethering_h tethering, void **custom_port_filtering_list)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(custom_port_filtering_list == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(custom_port_filtering_list) is NULL\n");
+
+ *custom_port_filtering_list = g_slist_copy(custom_port_filtering);
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_is_port_filtering_enabled(tethering_h tethering, bool *filtering_enabled)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(filtering_enabled == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(filtering_enabled) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ *filtering_enabled = th->port_filtering;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_set_vpn_passthrough_rule(tethering_h tethering, tethering_vpn_passthrough_type_e type, bool enable)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ GVariant *parameters;
+ GError *error = NULL;
+ guint result;
+
+ __tethering_h *th = (__tethering_h *)tethering;
+
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "set_vpn_passthrough_rule",
+ g_variant_new("(ib)", type, enable),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ result = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ result = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return result;
+ }
+
+ g_variant_get(parameters, "(u)", &result);
+
+ g_variant_unref(parameters);
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_push_wps_button(tethering_h tethering)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL");
+ __tethering_h *th = (__tethering_h *)tethering;
+ GDBusProxy *proxy = th->client_bus_proxy;
+ GVariant *parameters = NULL;
+ int ret = 0;
+ GError *error = NULL;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "push_wps_button",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ ret = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return ret;
+ }
+
+ if (parameters != NULL) {
+ g_variant_get(parameters, "(u)", &ret);
+ g_variant_unref(parameters);
+ }
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_set_wps_pin(tethering_h tethering, const char *wps_pin)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL");
+ _retvm_if(wps_pin == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(wps_pin) is NULL");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ GDBusProxy *proxy = th->client_bus_proxy;
+ GVariant *parameters = NULL;
+ int ret = 0;
+ GError *error = NULL;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "set_wps_pin",
+ g_variant_new("(s)", wps_pin), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ ret = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ return ret;
+ }
+
+ if (parameters != NULL) {
+ g_variant_get(parameters, "(u)", &ret);
+ g_variant_unref(parameters);
+ }
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_is_sharing_supported(tethering_h tethering, bool *supported)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(supported == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(supported) is NULL\n");
+
+ /** Check if wifi-sharing is supported */
+ __tethering_h *th = (__tethering_h *)tethering;
+ GDBusProxy *proxy = th->client_bus_proxy;
+
+ int ret = TETHERING_ERROR_NONE;
+ int count = 0;
+ gchar *key = NULL;
+ GVariant *value = NULL;
+ GVariantIter *iter = NULL;
+ GVariantIter *sub_iter = NULL;
+ GVariant *parameters = NULL;
+ GError *error = NULL;
+
+ parameters = g_dbus_proxy_call_sync(proxy, "get_wifi_interfaces",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (error) {
+ ERR("g_dbus_proxy_call_sync failed because %s\n", error->message);
+
+ if (error->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = TETHERING_ERROR_PERMISSION_DENIED;
+ else
+ ret = TETHERING_ERROR_OPERATION_FAILED;
+
+ g_error_free(error);
+ goto error;
+ }
+
+ g_variant_get(parameters, "(a(a{sv}))", &iter);
+ if (iter == NULL) {
+ g_variant_unref(parameters);
+ ret = TETHERING_ERROR_OPERATION_FAILED;
+ goto error;
+ }
+
+ while (g_variant_iter_loop(iter, "(a{sv})", &sub_iter)) {
+ while (g_variant_iter_loop(sub_iter, "{sv}", &key, &value)) {
+ if (g_strcmp0(key, "IfName") == 0) {
+ const gchar *interface = g_variant_get_string(value, NULL);
+ ERR("interface: %s\n", interface);
+ if (strncmp(interface, "wlan", 4) == 0)
+ count++;
+ }
+ }
+ }
+ g_variant_unref(parameters);
+
+ if (count > 1)
+ *supported = true;
+ else
+ *supported = false;
+
+error:
+ return ret;
+}
+
+API int tethering_wifi_set_sharing(tethering_h tethering, bool sharing)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ th->wifi_sharing = sharing;
+
+ return TETHERING_ERROR_NONE;
+}
+
+API int tethering_wifi_get_sharing(tethering_h tethering, bool *sharing)
+{
+ CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE);
+ CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE);
+
+ _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(tethering) is NULL\n");
+ _retvm_if(sharing == NULL, TETHERING_ERROR_INVALID_PARAMETER,
+ "parameter(sharing) is NULL\n");
+
+ __tethering_h *th = (__tethering_h *)tethering;
+ *sharing = th->wifi_sharing;
+
+ return TETHERING_ERROR_NONE;
+}