Add Soft AP APIs #2 50/62950/2
authorSeonah Moon <seonah1.moon@samsung.com>
Mon, 21 Mar 2016 07:57:10 +0000 (16:57 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Mon, 21 Mar 2016 07:58:00 +0000 (16:58 +0900)
- set/unset callbacks
- set/get ssid/visibility/security mode
- get client info APIs

Change-Id: I092e73cd4664e28b892068eae30d791f6fd5b44e
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
packaging/capi-network-softap.spec
src/softap.c
src/softap_client.c
test/softap_test.c

index 8ccea2fffd347d40ef8b826877a75740150fe41c..31d86fe59a54c2b9bc7c2e5dcf01ecfc51177d04 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-softap
 Summary:       Softap Framework
-Version:       0.0.2
+Version:       0.0.3
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index cb2895a535dedb2386f3899ac798f4d7a1a3d3e7..7aac5f91aa0c7043e60c2958a025de12e251f62b 100755 (executable)
@@ -76,6 +76,26 @@ static __softap_sig_t sigs[] = {
 
 static int retry = 0;
 
+static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg)
+{
+       if (conn == NULL || signal_name == NULL)
+               return;
+
+       GVariant *message = NULL;
+       GError *error = NULL;
+
+       if (arg)
+               message = g_variant_new("(s)", arg);
+
+       g_dbus_connection_emit_signal(conn, NULL, SOFTAP_SERVICE_OBJECT_PATH,
+                                       SOFTAP_SERVICE_INTERFACE, signal_name, message, &error);
+       if (error) {
+               ERR("g_dbus_connection_emit_signal is failed because  %s\n", error->message);
+               g_error_free(error);
+       }
+       g_variant_unref(message);
+}
+
 static int __get_common_ssid(char *ssid, unsigned int size)
 {
        if (ssid == NULL) {
@@ -99,6 +119,54 @@ static int __get_common_ssid(char *ssid, unsigned int size)
        return SOFTAP_ERROR_NONE;
 }
 
+static softap_error_e __get_security_type(softap_security_type_e *security_type)
+{
+       if (security_type == NULL) {
+               ERR("Invalid param\n");
+               return SOFTAP_ERROR_INVALID_PARAMETER;
+       }
+
+       if (vconf_get_int(VCONFKEY_SOFTAP_SECURITY,
+                               (int *)security_type) < 0) {
+               ERR("vconf_get_int is failed\n");
+               return SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
+static softap_error_e __set_visibility(bool visible)
+{
+       if (vconf_set_int(VCONFKEY_SOFTAP_HIDE, visible ? 0 : 1) < 0) {
+                       ERR("vconf_set_int is failed\n");
+                       return SOFTAP_ERROR_OPERATION_FAILED;
+               }
+
+               return SOFTAP_ERROR_NONE;
+}
+
+static softap_error_e __get_visibility(bool *visible)
+{
+       if (visible == NULL) {
+               ERR("Invalid param\n");
+               return SOFTAP_ERROR_INVALID_PARAMETER;
+       }
+
+       int hide = 0;
+
+       if (vconf_get_int(VCONFKEY_SOFTAP_HIDE, &hide) < 0) {
+               ERR("vconf_get_int is failed\n");
+               return SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       if (hide)
+               *visible = false;
+       else
+               *visible = true;
+
+       return SOFTAP_ERROR_NONE;
+}
+
 static int __get_initial_passphrase(char *passphrase, unsigned int size)
 {
        if (passphrase == NULL ||
@@ -503,6 +571,44 @@ static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res,
        return;
 }
 
+
+static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res,
+               gpointer user_data)
+{
+       DBG("+\n");
+
+       _retm_if(user_data == NULL, "parameter(user_data) is NULL\n");
+       GError *g_error = NULL;
+       GVariant *g_var;
+       guint info;
+       __softap_h *sa = (__softap_h *)user_data;
+       softap_error_e softap_error;
+
+       g_var  = g_dbus_proxy_call_finish(sa->client_bus_proxy, res, &g_error);
+       if (g_error) {
+               ERR("DBus fail [%s]\n", g_error->message);
+               if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED)
+                       softap_error = SOFTAP_ERROR_PERMISSION_DENIED;
+               else
+                       softap_error = SOFTAP_ERROR_OPERATION_FAILED;
+               g_error_free(g_error);
+       }
+       if (sa->settings_reloaded_cb == NULL) {
+               DBG("There is no settings_reloaded_cb\n-\n");
+               return;
+       }
+       g_variant_get(g_var, "(u)", &info);
+       softap_error = __get_error(info);
+       g_variant_unref(g_var);
+
+       sa->settings_reloaded_cb(softap_error,
+                       sa->settings_reloaded_user_data);
+
+       sa->settings_reloaded_cb = NULL;
+       sa->settings_reloaded_user_data = NULL;
+       DBG("-\n");
+}
+
 static int __prepare_softap_settings(softap_h softap, _softap_settings_t *set)
 {
        DBG("+");
@@ -561,6 +667,43 @@ static void __disconnect_signals(softap_h softap)
        DBG("-");
 }
 
+static softap_error_e __set_security_type(const softap_security_type_e security_type)
+{
+       if (security_type != SOFTAP_SECURITY_TYPE_NONE &&
+                       security_type != SOFTAP_SECURITY_TYPE_WPA2_PSK) {
+               ERR("Invalid param\n");
+               return SOFTAP_ERROR_INVALID_PARAMETER;
+       }
+
+       if (vconf_set_int(VCONFKEY_SOFTAP_SECURITY, security_type) < 0) {
+               ERR("vconf_set_int is failed\n");
+               return SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
+static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size)
+{
+       if (path == NULL || ssid == NULL || size == 0)
+               return false;
+
+       char *ptr = NULL;
+       char *ptr_tmp = NULL;
+
+       ptr = vconf_get_str(path);
+       if (ptr == NULL)
+               return false;
+
+       if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp))
+               *ptr_tmp = '\0';
+
+       g_strlcpy(ssid, ptr, size);
+       free(ptr);
+
+       return true;
+}
+
 API int softap_create(softap_h *softap)
 {
        DBG("+");
@@ -713,6 +856,43 @@ API int softap_disable(softap_h softap)
        return SOFTAP_ERROR_NONE;
 }
 
+API int softap_reload_settings(softap_h softap, softap_settings_reloaded_cb callback, void *user_data)
+
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(callback == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(callback) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+       _softap_settings_t set = {"", "", 0, false};
+       GDBusProxy *proxy = sa->client_bus_proxy;
+       int ret = 0;
+
+       DBG("+");
+
+       if (sa->settings_reloaded_cb) {
+               ERR("Operation in progress\n");
+               return SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       ret = __prepare_softap_settings(softap, &set);
+       if (ret != SOFTAP_ERROR_NONE) {
+               ERR("softap settings initialization failed\n");
+               return SOFTAP_ERROR_OPERATION_FAILED;
+       }
+
+       sa->settings_reloaded_cb = callback;
+       sa->settings_reloaded_user_data = user_data;
+
+       g_dbus_proxy_call(proxy, "reload_settings",
+                       g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type),
+                       G_DBUS_CALL_FLAGS_NONE, -1, sa->cancellable,
+                       (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)softap);
+
+       return SOFTAP_ERROR_NONE;
+}
+
 API int softap_is_enabled(softap_h softap, bool *enable)
 {
        DBG("+");
@@ -885,6 +1065,91 @@ API int softap_get_subnet_mask(softap_h softap, softap_address_family_e address_
        return SOFTAP_ERROR_NONE;
 }
 
+API int softap_foreach_connected_clients(softap_h softap, softap_connected_client_cb callback, void *user_data)
+{
+       DBG("+\n");
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(callback == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(callback) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+       __softap_client_h client = {"", };
+       gchar *ip = NULL;
+       gchar *mac = NULL;
+       gchar *hostname = NULL;
+       guint timestamp = 0;
+       GError *error = NULL;
+       GVariant *result = NULL;
+       GVariantIter *outer_iter = NULL;
+       GVariantIter *inner_iter = NULL;
+       GVariant *station = NULL;
+       GVariant *value = NULL;
+       gchar *key = NULL;
+       int interface = 0;
+
+       result = g_dbus_proxy_call_sync(sa->client_bus_proxy, "get_station_info",
+                       NULL, G_DBUS_CALL_FLAGS_NONE,
+                       -1, sa->cancellable, &error);
+       if (error)
+               ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message);
+       g_variant_get(result, "(a(a{sv}))", &outer_iter);
+
+       while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) {
+               g_variant_get(station, "a{sv}", &inner_iter);
+
+               while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) {
+                       if (g_strcmp0(key, "Type") == 0) {
+                               interface = g_variant_get_int32(value);
+                               if (interface != 3) {
+                                       g_free(key);
+                                       g_variant_unref(value);
+                                       break;
+                               }
+                       }
+                       if (g_strcmp0(key, "IP") == 0) {
+                               g_variant_get(value, "s", &ip);
+                               SDBG("ip is %s\n", ip);
+                               g_strlcpy(client.ip, ip, sizeof(client.ip));
+                       } else if (g_strcmp0(key, "MAC") == 0) {
+                               g_variant_get(value, "s", &mac);
+                               SDBG("mac is %s\n", mac);
+                               g_strlcpy(client.mac, mac, sizeof(client.mac));
+                       } else if (g_strcmp0(key, "Name") == 0) {
+                               g_variant_get(value, "s", &hostname);
+                               SDBG("hsotname is %s\n", hostname);
+                               if (hostname)
+                                       client.hostname = g_strdup(hostname);
+                       } else if (g_strcmp0(key, "Time") == 0) {
+                               timestamp = g_variant_get_int32(value);
+                               DBG("timestamp is %d\n", timestamp);
+                               client.tm = (time_t)timestamp;
+                       } else {
+                               ERR("Key %s not required\n", key);
+                       }
+               }
+               g_free(hostname);
+               g_free(ip);
+               g_free(mac);
+               g_variant_iter_free(inner_iter);
+               if (callback((softap_client_h)&client, user_data) == false) {
+                       DBG("iteration is stopped\n");
+                       g_free(client.hostname);
+                       g_variant_iter_free(outer_iter);
+                       g_variant_unref(station);
+                       g_variant_unref(result);
+                       DBG("-\n");
+                       return SOFTAP_ERROR_OPERATION_FAILED;
+               }
+               g_free(client.hostname);
+       }
+       g_variant_iter_free(outer_iter);
+       g_variant_unref(station);
+       g_variant_unref(result);
+       DBG("-\n");
+       return SOFTAP_ERROR_NONE;
+}
+
 API int softap_set_enabled_cb(softap_h softap, softap_enabled_cb callback, void *user_data)
 {
        _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
@@ -940,3 +1205,218 @@ API int softap_unset_disabled_cb(softap_h softap)
 
        return SOFTAP_ERROR_NONE;
 }
+
+API int softap_set_client_connection_state_changed_cb(softap_h softap, softap_client_connection_state_changed_cb callback, void *user_data)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(callback == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(callback) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+
+       sa->changed_cb = callback;
+       sa->changed_user_data = user_data;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_unset_client_connection_state_changed_cb(softap_h softap)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+
+       sa->changed_cb = NULL;
+       sa->changed_user_data = NULL;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+
+API int softap_set_security_type_changed_cb(softap_h softap, softap_security_type_changed_cb callback, void *user_data)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(callback == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(callback) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+
+       sa->security_type_changed_cb = callback;
+       sa->security_type_user_data = user_data;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_unset_security_type_changed_cb(softap_h softap)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+
+       sa->security_type_changed_cb = NULL;
+       sa->security_type_user_data = NULL;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_set_ssid_visibility_changed_cb(softap_h softap, softap_ssid_visibility_changed_cb callback, void *user_data)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(callback == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(callback) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+
+       sa->ssid_visibility_changed_cb = callback;
+       sa->ssid_visibility_user_data = user_data;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_unset_ssid_visibility_changed_cb(softap_h softap)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+
+       sa->ssid_visibility_changed_cb = NULL;
+       sa->ssid_visibility_user_data = NULL;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_set_security_type(softap_h softap, softap_security_type_e type)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *) softap;
+       softap_error_e ret = SOFTAP_ERROR_NONE;
+
+       ret = __set_security_type(type);
+       if (ret == SOFTAP_ERROR_NONE) {
+
+               __send_dbus_signal(sa->client_bus,
+                               SIGNAL_NAME_SECURITY_TYPE_CHANGED,
+                               type == SOFTAP_SECURITY_TYPE_NONE ?
+                               SOFTAP_SECURITY_TYPE_OPEN_STR :
+                               SOFTAP_SECURITY_TYPE_WPA2_PSK_STR);
+       }
+       return ret;
+}
+
+
+API int softap_get_security_type(softap_h softap, softap_security_type_e *type)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                               "parameter(softap) is NULL\n");
+       _retvm_if(type == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                               "parameter(type) is NULL\n");
+
+       return __get_security_type(type);
+}
+
+API int softap_set_ssid(softap_h softap, const char *ssid)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(ssid == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(ssid) is NULL\n");
+
+       __softap_h *sa = (__softap_h *) softap;
+       char *p_ssid = NULL;
+       int ssid_len = 0;
+
+       ssid_len = strlen(ssid);
+       if (ssid_len > SOFTAP_SSID_MAX_LEN) {
+               ERR("parameter(ssid) is too long");
+               return SOFTAP_ERROR_INVALID_PARAMETER;
+       }
+
+       p_ssid = strdup(ssid);
+       if (p_ssid == NULL) {
+               ERR("strdup failed\n");
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       if (sa->ssid)
+               g_free(sa->ssid);
+       sa->ssid = p_ssid;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_get_ssid(softap_h softap, char **ssid)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(ssid == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(ssid) is NULL\n");
+
+       __softap_h *sa = (__softap_h *) softap;
+
+       char val[SOFTAP_SSID_MAX_LEN + 1] = {0, };
+       bool enable;
+
+       softap_is_enabled(softap, &enable);
+
+       if (!enable) {
+               if (sa->ssid != NULL) {
+                       DBG("Private SSID is set\n");
+                       *ssid = strdup(sa->ssid);
+               } else {
+                       if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
+                                               val, sizeof(val)) == false) {
+                               return SOFTAP_ERROR_OPERATION_FAILED;
+                       }
+                       *ssid = strdup(val);
+               }
+       } else {
+               if (__get_ssid_from_vconf(VCONFKEY_SOFTAP_SSID,
+                                       val, sizeof(val)) == false) {
+                       return SOFTAP_ERROR_OPERATION_FAILED;
+               }
+               *ssid = strdup(val);
+       }
+       if (*ssid == NULL) {
+               ERR("strdup is failed\n");
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_set_ssid_visibility(softap_h softap, bool visible)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+
+       __softap_h *sa = (__softap_h *) softap;
+       softap_error_e ret = SOFTAP_ERROR_NONE;
+
+       ret = __set_visibility(visible);
+       if (ret == SOFTAP_ERROR_NONE) {
+               __send_dbus_signal(sa->client_bus,
+                               SIGNAL_NAME_SSID_VISIBILITY_CHANGED,
+                               visible ? SIGNAL_MSG_SSID_VISIBLE :
+                               SIGNAL_MSG_SSID_HIDE);
+       }
+
+       return ret;
+}
+
+API int softap_get_ssid_visibility(softap_h softap, bool *visible)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(visible == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                               "parameter(visible) is NULL\n");
+
+       return __get_visibility(visible);
+}
index 9e79f66eaed1eaa4b7d02001f7e0978647fd06a5..a156b9283e39e2e095cee8b3ac5a075bd2a2865e 100755 (executable)
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
+
+#include <stdlib.h>
+#include <string.h>
+#include "softap_private.h"
+
+API int softap_client_clone(softap_client_h *dest, softap_client_h origin)
+{
+       _retvm_if(dest == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(dest) is NULL\n");
+
+       __softap_client_h *si = NULL;
+       __softap_client_h *source = NULL;
+
+       source = (__softap_client_h *)origin;
+
+       si = malloc(sizeof(__softap_client_h));
+       if (si == NULL) {
+               ERR("malloc is failed\n");
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       memcpy(si, source, sizeof(__softap_client_h));
+       si->hostname = g_strdup(source->hostname);
+       if (si->hostname == NULL) {
+               ERR("malloc is failed\n");
+               free(si);
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       *dest = (softap_client_h)si;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_client_destroy(softap_client_h client)
+{
+       _retvm_if(client == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(client) is NULL\n");
+
+       __softap_client_h *si = NULL;
+
+       si = (__softap_client_h *)client;
+
+       g_free(si->hostname);
+
+       free(client);
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_client_get_name(softap_client_h client, char **name)
+{
+       _retvm_if(client == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(client) is NULL\n");
+       _retvm_if(name == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(name) is NULL\n");
+
+       __softap_client_h *si = (__softap_client_h *)client;
+
+       *name = strdup(si->hostname);
+       if (*name == NULL) {
+               ERR("strdup is failed\n");
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_client_get_ip_address(softap_client_h client, softap_address_family_e address_family, char **ip_address)
+{
+       _retvm_if(client == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(client) is NULL\n");
+       _retvm_if(ip_address == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(ip_address) is NULL\n");
+
+       __softap_client_h *si = (__softap_client_h *)client;
+
+       *ip_address = strdup(si->ip);
+       if (*ip_address == NULL) {
+               ERR("strdup is failed\n");
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_client_get_mac_address(softap_client_h client, char **mac_address)
+{
+       _retvm_if(client == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(client) is NULL\n");
+       _retvm_if(mac_address == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(mac_address) is NULL\n");
+
+       __softap_client_h *si = (__softap_client_h *)client;
+
+       *mac_address = strdup(si->mac);
+       if (*mac_address == NULL) {
+               ERR("strdup is failed\n");
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_client_get_time(softap_client_h client, time_t *timestamp)
+{
+       _retvm_if(client == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "Parameter(client) is NULL\n");
+
+       __softap_client_h *si = (__softap_client_h *)client;
+
+       *timestamp = si->tm;
+
+       return SOFTAP_ERROR_NONE;
+}
index b983d7975150d0a5c512fca1d0f44646377aae72..bb5b93db5b510920f6915dcb6961052cd61ec73e 100755 (executable)
@@ -23,8 +23,8 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-
 #include <vconf.h>
+#include <time.h>
 
 #include "softap.h"
 
@@ -110,6 +110,127 @@ static void __disabled_cb(softap_error_e error, softap_disabled_cause_e code, vo
        return;
 }
 
+static void __settings_reloaded_cb(softap_error_e result, void *user_data)
+{
+       g_print("__settings_reloaded_cb\n");
+
+       if (result != SOFTAP_ERROR_NONE) {
+               g_print("softap_reload_settings is failed. error[0x%X]\n", result);
+               return;
+       }
+
+       printf("## Soft AP setting is reloaded\n");
+
+       return;
+}
+
+static void __security_changed_cb(softap_security_type_e changed_type, void *user_data)
+{
+       g_print("Security type is changed to [%s]\n",
+                       changed_type == SOFTAP_SECURITY_TYPE_NONE ?
+                               "open" : "wpa2-psk");
+               return;
+}
+
+static void __ssid_visibility_changed_cb(bool changed_visible, void *user_data)
+{
+       g_print("SSID visibility forSoftap changed to [%s]\n",
+                       changed_visible ? "visible" : "invisible");
+       return;
+}
+
+static bool __clients_foreach_cb(softap_client_h client, void *data)
+{
+       softap_client_h clone = NULL;
+       char *ip_address = NULL;
+       char *mac_address = NULL;
+       char *hostname = NULL;
+       time_t timestamp;
+       struct tm *t;
+
+       /* Clone internal information */
+       if (softap_client_clone(&clone, client) != SOFTAP_ERROR_NONE) {
+               g_print("softap_client_clone is failed\n");
+               return false;
+       }
+
+       /* Get information */
+       if (softap_client_get_ip_address(clone, SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_ip_address is failed\n");
+
+       if (softap_client_get_mac_address(clone, &mac_address) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_mac_address is failed\n");
+
+       if (softap_client_get_name(clone, &hostname) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_hostname is failed\n");
+
+       if (softap_client_get_time(clone, &timestamp) != SOFTAP_ERROR_NONE)
+               g_print("softap_client_get_hostname is failed\n");
+       /* End of getting information */
+
+       t = localtime(&timestamp);
+
+       g_print("\n< Client Info. >\n");
+       g_print("\tIP Address %s\n", ip_address);
+       g_print("\tMAC Address : %s\n", mac_address);
+       g_print("\tHostname : %s\n", hostname);
+       g_print("\tTime stamp : %04d-%02d-%02d %02d:%02d:%02d",
+                       t->tm_year + 1900, t->tm_mon + 1,
+                       t->tm_mday, t->tm_hour,
+                       t->tm_min, t->tm_sec);
+
+       /* Destroy cloned objects */
+       if (ip_address)
+               free(ip_address);
+       if (mac_address)
+               free(mac_address);
+       if (hostname)
+               free(hostname);
+
+       softap_client_destroy(clone);
+
+       /* Continue iteration */
+       return true;
+}
+
+static void __connection_state_changed_cb(softap_client_h client, bool open, void *data)
+{
+       softap_client_h clone = NULL;
+       char *ip_address = NULL;
+       char *mac_address = NULL;
+       char *hostname = NULL;
+
+       softap_client_clone(&clone, client);
+       if (clone == NULL) {
+               g_print("tetheirng_client_clone is failed\n");
+               return;
+       }
+
+       softap_client_get_ip_address(clone,
+                       SOFTAP_ADDRESS_FAMILY_IPV4, &ip_address);
+       softap_client_get_mac_address(clone, &mac_address);
+       softap_client_get_name(clone, &hostname);
+
+       if (open) {
+               g_print("## New station IP [%s], MAC [%s], hostname [%s]\n",
+                               ip_address, mac_address, hostname);
+       } else {
+               g_print("## Disconnected station IP [%s], MAC [%s], hostname [%s]\n",
+                               ip_address, mac_address, hostname);
+       }
+
+       if (ip_address)
+               free(ip_address);
+       if (mac_address)
+               free(mac_address);
+       if (hostname)
+               free(hostname);
+
+       softap_client_destroy(clone);
+
+       return;
+}
+
 static void __register_cbs(void)
 {
        int ret = SOFTAP_ERROR_NONE;
@@ -122,6 +243,18 @@ static void __register_cbs(void)
        if (ret != SOFTAP_ERROR_NONE)
                printf("Fail to set disabled callback!!\n");
 
+       ret = softap_set_security_type_changed_cb(sa, __security_changed_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set security changed callback!!\n");
+
+       ret = softap_set_ssid_visibility_changed_cb(sa, __ssid_visibility_changed_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set visibility changed callback!!\n");
+
+       ret = softap_set_client_connection_state_changed_cb(sa, __connection_state_changed_cb, NULL);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to set visibility changed callback!!\n");
+
        return;
 }
 
@@ -135,7 +268,19 @@ static void __deregister_cbs(void)
 
        ret = softap_unset_disabled_cb(sa);
        if (ret != SOFTAP_ERROR_NONE)
-               printf("Fail to set disabled callback!!\n");
+               printf("Fail to unset disabled callback!!\n");
+
+       ret = softap_unset_security_type_changed_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset security changed callback!!\n");
+
+       ret = softap_unset_ssid_visibility_changed_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset visibility changed callback!!\n");
+
+       ret = softap_unset_client_connection_state_changed_cb(sa);
+       if (ret != SOFTAP_ERROR_NONE)
+               printf("Fail to unset visibility changed callback!!\n");
 
        return;
 }
@@ -196,11 +341,26 @@ static int test_softap_is_enabled(void)
 static int test_softap_get_settings(void)
 {
        int ret = SOFTAP_ERROR_NONE;
+       char *ssid = NULL;
        char *mac_address = NULL;
        char *interface_name = NULL;
        char *ip_address = NULL;
        char *gateway_address = NULL;
        char *subnet_mask = NULL;
+       bool visible = 0;
+       softap_security_type_e security_type = SOFTAP_SECURITY_TYPE_NONE;
+
+       ret = softap_get_ssid(sa, &ssid);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       ret = softap_get_ssid_visibility(sa, &visible);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       ret = softap_get_security_type(sa, &security_type);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
 
        ret = softap_get_mac_address(sa, &mac_address);
        if (ret != SOFTAP_ERROR_NONE)
@@ -223,12 +383,16 @@ static int test_softap_get_settings(void)
                return 0;
 
 
+       printf("* SSID: %s\n", ssid);
+       printf("* SSID visibility: %d\n", visible);
+       printf("* Security type: %d\n", security_type);
        printf("* MAC address: %s\n", mac_address);
        printf("* Network Interface: %s\n", interface_name);
        printf("* IP address: %s\n", ip_address);
        printf("* gateway_address: %s\n", gateway_address);
        printf("* subnet_mask: %s\n", subnet_mask);
 
+       if (ssid)       g_free(ssid);
        if (mac_address)        g_free(mac_address);
        if (interface_name)     g_free(interface_name);
        if (ip_address)         g_free(ip_address);
@@ -238,6 +402,85 @@ static int test_softap_get_settings(void)
        return 1;
 }
 
+static int test_softap_set_ssid(void)
+{
+       int ret;
+       char ssid[100];
+
+       printf("Input SSID for Softap: ");
+       ret = scanf("%99s", ssid);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       ret = softap_set_ssid(sa, ssid);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_ssid_visibility(void)
+{
+       int ret;
+       int visibility;
+
+       printf("Input visibility for Soft AP (0:invisible, 1:visible)");
+       ret = scanf("%9d", &visibility);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       ret = softap_set_ssid_visibility(sa, visibility);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_set_security_type(void)
+{
+       int ret;
+       int security_type;
+
+       printf("Input security type for Soft AP (0:NONE, 1:WPA2_PSK)");
+       ret = scanf("%9d", &security_type);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return -1;
+       }
+
+       ret = softap_set_security_type(sa, security_type);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_reload_settings(void)
+{
+       int ret = softap_reload_settings(sa, __settings_reloaded_cb, NULL);
+
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
+       return 1;
+}
+
+static int test_softap_get_client_info(void)
+{
+       int ret;
+
+       ret = softap_foreach_connected_clients(sa, __clients_foreach_cb, NULL);
+
+       if (ret != SOFTAP_ERROR_NONE)
+                       return 0;
+
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -276,6 +519,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("4       - SoftAP disable\n");
                printf("5       - Is Soft AP enabled?\n");
                printf("6       - Get Soft AP settings\n");
+               printf("7       - Set Soft AP SSID\n");
+               printf("8       - Set Soft AP SSID visibility\n");
+               printf("9       - Set Soft AP security type\n");
+               printf("a       - Set Soft AP passpharse\n");
+               printf("b       - Get Soft AP client information\n");
+               printf("c       - SoftAP reload settings\n");
                printf("0       - Exit \n");
                printf("ENTER  - Show options menu.......\n");
        }
@@ -299,6 +548,21 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case '6':
                rv = test_softap_get_settings();
                break;
+       case '7':
+               rv = test_softap_set_ssid();
+               break;
+       case '8':
+               rv = test_softap_set_ssid_visibility();
+               break;
+       case '9':
+               rv = test_softap_set_security_type();
+               break;
+       case 'b':
+               rv = test_softap_get_client_info();
+               break;
+       case 'c':
+               rv = test_softap_reload_settings();
+               break;
        }
 
        if (rv == 1)