Add new CAPI to get softAP config options 66/145466/1
authorsaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:26:27 +0000 (19:26 +0900)
committersaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:26:27 +0000 (19:26 +0900)
Change-Id: If1f867b0e1bf32f34da123b8ab0690870513a8fd
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
include/wifi-mesh.h
include/wifi-mesh_dbus.h
src/wifi-mesh-dbus.c
src/wifi-mesh.c
test/wifi-mesh-network.c

index 7c73c5b28890a9a23ea77d97c2b6ace295467967..9ea778cc09899e7528095cdf31e84aa26214389f 100644 (file)
@@ -972,6 +972,35 @@ int wifi_mesh_get_joined_network(wifi_mesh_h handle, wifi_mesh_network_h* networ
 int wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid, const char* key,
        int channel, bool visibility, int max_stations, int security);
 
+/**
+ * @brief Gets softap options
+ * @details This function gets softap options.
+ *
+ * @since_tizen 4.0
+ *
+ * @param[in] handle The Wi-Fi mesh handle
+ * @param[out] ssid The SSID
+ * @param[out] channel The operating channel number
+ * @param[out] visibility The broadcast option (1:Broadcast SSID, 2:Hidden)
+ * @param[out] max_stations The maximum allowable number of stations (default:10)
+ * @param[out] security Security option (1:WPA1, 2:WPA2)
+ * @param[out] key The pre-shared key
+ *
+ *
+ * @return 0 on success, otherwise a negative error value.
+ * @retval #WIFI_MESH_ERROR_NONE Successful
+ * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error
+ *
+ * @see wifi_mesh_set_softap()
+ * @see wifi_mesh_enable_softap()
+ * @see wifi_mesh_disable_softap()
+ *
+ */
+int wifi_mesh_get_softap(wifi_mesh_h handle, char **ssid, int *channel,
+               bool *visibility, int *max_stations,
+               int *security, char **key);
+
 /**
  * @brief Enables softap
  * @details This function enables softap.
index 16dc20d0ce959760191b480fb2e7faa379a1b74f..73d1faa554b8d4f9b71e67756fd964b7e2775fc2 100644 (file)
@@ -58,6 +58,8 @@ int _wifi_mesh_set_gate(wifi_mesh_h handle, bool gate_announce, int hwmp_root_mo
 int _wifi_mesh_unset_gate(wifi_mesh_h handle);
 int _wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid, const char* key, const char* mode,
                int channel, int visibility, int max_stations, int security);
+int _wifi_mesh_get_softap(wifi_mesh_h handle, char **ssid, int *channel,
+               bool *visibility, int *max_stations, int *security, char **key);
 int _wifi_mesh_enable_softap(wifi_mesh_h handle);
 int _wifi_mesh_disable_softap(wifi_mesh_h handle);
 int _mesh_create_network(wifi_mesh_h handle, wifi_mesh_network_h _network);
index d3674db3c170382528af16e00d2c17fdce9192ec..29c1654582370ba1fe0ae457d3994db27fa68a2c 100644 (file)
@@ -1318,6 +1318,59 @@ int _wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid,
        return result;
 }
 
+int _wifi_mesh_get_softap(wifi_mesh_h handle, char **ssid, int *channel,
+               bool *visibility, int *max_stations, int *security, char **key)
+{
+       GVariant *variant = NULL;
+       int result = WIFI_MESH_ERROR_NONE;
+       GError *error = NULL;
+       struct mesh_handle *h = handle;
+
+       if (NULL == h) {
+               /* LCOV_EXCL_START */
+               LOGE("Invaild parameter");
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
+
+       if (NULL == h->dbus_connection || NULL == _gproxy_mesh_service) {
+               /* LCOV_EXCL_START */
+               LOGE("I/O error");
+               return WIFI_MESH_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_softap", NULL,
+                               G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+       if (variant) {
+               char *_ssid = NULL, *_mode = NULL, *_key = NULL;
+               int _channel = -1, _visibility = -1, _max_sta = -1, _security = -1;
+               g_variant_get(variant, "(ssiiiisi)", &_ssid, &_mode, &_channel,
+                                         &_visibility, &_max_sta, &_security, &_key, &result);
+               LOGD("get_softap status 0x%x", result);
+               result = __convert_service_error_type(result);
+
+               if (result == WIFI_MESH_ERROR_NONE) {
+                       *ssid = g_strdup(_ssid);
+                       *channel = _channel;
+                       *visibility = _visibility == 1 ? 1 : 0;
+                       *max_stations = _max_sta;
+                       *security = _security;
+                       if (_security == 1)
+                               *key = g_strdup(_key);
+               }
+
+       } else if (error) {
+               /* LCOV_EXCL_START */
+               LOGE("Failed DBus call [%s]", error->message);
+               g_error_free(error);
+               return WIFI_MESH_ERROR_IO_ERROR;
+               /* LCOV_EXCL_STOP */
+       }
+
+       return result;
+}
+
 int _wifi_mesh_enable_softap(wifi_mesh_h handle)
 {
        GVariant *variant = NULL;
index c7658bcb76049d7c22af31e7f6a526b1cd7d60ce..a9ae35a07ea7f9bc9a52ee56ed9ba3923967748f 100644 (file)
@@ -717,6 +717,28 @@ EXPORT_API int wifi_mesh_set_softap(wifi_mesh_h handle, const char* ssid,
        return rv;
 }
 
+EXPORT_API int wifi_mesh_get_softap(wifi_mesh_h handle, char **ssid,
+               int *channel, bool *visibility, int *max_stations,
+               int *security, char **key)
+{
+       int rv = 0;
+       CHECK_FEATURE_SUPPORTED(MESH_FEATURE);
+
+       if (NULL == handle || ssid == NULL || channel == NULL ||
+                               visibility == NULL || max_stations == NULL ||
+                               security == NULL || key == NULL) {
+               /* LCOV_EXCL_START */
+               LOGE("Invalid parameter");
+               return WIFI_MESH_ERROR_INVALID_PARAMETER;
+               /* LCOV_EXCL_STOP */
+       }
+
+       rv = _wifi_mesh_get_softap(handle, ssid, channel, visibility, max_stations,
+                                                          security, key);
+
+       return rv;
+}
+
 EXPORT_API int wifi_mesh_enable_softap(wifi_mesh_h handle)
 {
        int rv = 0;
index fa8b7084d6e11352e7e5e14c37bd080165e7f033..fb601ab6a46ce991e93a228c9150ad67b28f7fb6 100644 (file)
@@ -605,6 +605,28 @@ static int run_set_softap(MManager *mm, struct menu_data *menu)
        }
        msg(" - wifi_mesh_set_softap() ret: [0x%X] [%s]", ret, wifi_mesh_error_to_string(ret));
 
+       msg("Get SoftAp Option");
+       char *g_ssid, *g_key;
+       int g_channel, g_max_stations, g_security;
+       bool g_visibility;
+       ret = wifi_mesh_get_softap(mesh, &g_ssid, &g_channel, &g_visibility,
+                                                          &g_max_stations, &g_security, &g_key);
+       if (WIFI_MESH_ERROR_NONE != ret) {
+               msgr("Failed to get softap options: [%s(0x%X)]",
+                       wifi_mesh_error_to_string(ret), ret);
+               return RET_FAILURE;
+       }
+
+       msg("SSID: %s", g_ssid);
+       msg("Channel: %d", g_channel);
+       msg("Visibility: %d", g_visibility);
+       msg("Max Stations: %d", g_max_stations);
+       msg("Security: %d", g_security);
+       msg("Key: %s", g_security ? g_key : "NULL");
+
+       g_free(g_ssid);
+       g_free(g_key);
+
        return RET_SUCCESS;
 }