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) {
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 ||
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("+");
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("+");
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("+");
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,
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);
+}
* 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;
+}
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-
#include <vconf.h>
+#include <time.h>
#include "softap.h"
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, ×tamp) != SOFTAP_ERROR_NONE)
+ g_print("softap_client_get_hostname is failed\n");
+ /* End of getting information */
+
+ t = localtime(×tamp);
+
+ 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;
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;
}
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;
}
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)
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);
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;
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");
}
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)