Add new dbus method to get SoftAP Config options 55/145455/1
authorsaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:07:34 +0000 (19:07 +0900)
committersaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:07:34 +0000 (19:07 +0900)
This patch reads softAP config options from hostapd config file when
dbus method to get softAP option is invoked

Change-Id: Iaca0ae4be6ae197ed3d450518b0b3f894ef5c868
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
include/wmesh-request.h
include/wmesh-softap.h
introspection/wmesh.xml
src/wmesh-request.c
src/wmesh-service-interface.c
src/wmesh-softap.c

index 158ee5a..3c625c0 100644 (file)
@@ -59,6 +59,9 @@ int wmesh_request_remove_bridge_interface(const char* bridge_interface,
 int wmesh_request_set_softap_config(const char* softap_interface,
                const char *ssid, const char* mode, int channel, int visibility,
                int max_sta, int security, const char* passphrase);
+int wmesh_request_get_softap_config(char **softap_interface, char **ssid,
+                       char **mode, int *channel, int *visibility,
+               int *max_sta, int *security, char **passphrase);
 int wmesh_request_enable_softap(
                const char* bridge_interface, const char* softap_interface);
 int wmesh_request_disable_softap(
index 027b0ea..cb62828 100644 (file)
@@ -26,6 +26,9 @@ extern "C" {
 int wmesh_softap_set_configuration(const char* softap_interface,
                const char *ssid, const char* mode, int channel, int visibility,
                int max_sta, int security, const char* passphrase);
+int wmesh_softap_get_configuration(char **softap_interface, char **ssid,
+                       char **mode, int *channel, int *visibility,
+               int *max_sta, int *security, char **passphrase);
 int wmesh_softap_enable_softap();
 int wmesh_softap_disable_softap();
 
index d2c94ec..c3391b3 100644 (file)
                        <arg type="i" name="security" direction="in"/>\r
                        <arg type="i" name="result" direction="out"/>\r
                </method>\r
+               <method name="get_softap">\r
+                       <arg type="s" name="ssid" direction="out"/>\r
+                       <arg type="s" name="mode" direction="out"/>\r
+                       <arg type="i" name="channel" direction="out"/>\r
+                       <arg type="i" name="visibility" direction="out"/>\r
+                       <arg type="i" name="max_sta" direction="out"/>\r
+                       <arg type="i" name="security" direction="out"/>\r
+                       <arg type="s" name="passphrase" direction="out"/>\r
+                       <arg type="i" name="result" direction="out"/>\r
+               </method>\r
                <method name="enable_softap">\r
                        <arg type="i" name="result" direction="out"/>\r
                </method>\r
index 9c3cffe..854b372 100644 (file)
@@ -179,6 +179,24 @@ int wmesh_request_set_softap_config(const char* softap_interface,
        return ret;
 }
 
+int wmesh_request_get_softap_config(char **softap_interface, char **ssid,
+                       char **mode, int *channel, int *visibility,
+               int *max_sta, int *security, char **passphrase)
+{
+       int ret = WMESHD_ERROR_NONE;
+
+       WMESH_LOGD("Get configuration for SoftAP");
+
+       ret = wmesh_softap_get_configuration(softap_interface, ssid, mode, channel,
+                       visibility, max_sta, security, passphrase);
+       if (WMESHD_ERROR_NONE != ret) {
+               WMESH_LOGE("Failed to get Configuration for SoftAP");
+               return ret;
+       }
+
+       return ret;
+}
+
 int wmesh_request_enable_softap(
                const char* bridge_interface, const char* softap_interface)
 {
index ab84d8a..6e52253 100644 (file)
@@ -651,6 +651,42 @@ static gboolean _wmeshd_dbus_handle_set_softap(NetWmesh *object,
        return TRUE;
 }
 
+static gboolean _wmeshd_dbus_handle_get_softap(NetWmesh *object,
+               GDBusMethodInvocation *invocation, gpointer user_data)
+{
+       int ret = WMESHD_ERROR_NONE;
+       wmesh_service *service = (wmesh_service *)user_data;
+       char *interface, *ssid, *mode, *passphrase;
+       int channel, visibility, max_sta, security;
+       (void) service; // unused
+
+       /* Get softAP information */
+       ret = wmesh_request_get_softap_config(&interface, &ssid, &mode, &channel,
+                                               &visibility, &max_sta, &security, &passphrase);
+       if (WMESHD_ERROR_NONE != ret) {
+               WMESH_LOGE("Failed to wmesh_request_get_softap_config [%d]", ret);
+               net_wmesh_complete_get_softap(object, invocation, "", "", 0, 0, 0, 0,
+                                                               "", ret);
+       }
+
+       WMESH_LOGD("SSID      : %s", ssid);
+       WMESH_LOGD("mode      : %s", mode);
+       WMESH_LOGD("channel   : %d", channel);
+       WMESH_LOGD("visibility: %d", visibility);
+       WMESH_LOGD("max_sta   : %d", max_sta);
+       WMESH_LOGD("security  : %d", security);
+       WMESH_LOGD("Passphrase  : %s", passphrase ? passphrase : "NULL");
+
+       if (security == 1)
+               net_wmesh_complete_get_softap(object, invocation, ssid, mode, channel,
+                                                               visibility, max_sta, security, passphrase, ret);
+       else
+               net_wmesh_complete_get_softap(object, invocation, ssid, mode, channel,
+                                                               visibility, max_sta, security, "", ret);
+
+       return TRUE;
+}
+
 static gboolean _wmeshd_dbus_handle_enable_softap(NetWmesh *object,
                GDBusMethodInvocation *invocation, gpointer user_data)
 {
@@ -1124,6 +1160,8 @@ static void _wmeshd_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *nam
                        G_CALLBACK(_wmeshd_dbus_handle_unset_gate), service);
        g_signal_connect(meshd_dbus_object, "handle-set-softap",
                        G_CALLBACK(_wmeshd_dbus_handle_set_softap), service);
+       g_signal_connect(meshd_dbus_object, "handle-get-softap",
+                       G_CALLBACK(_wmeshd_dbus_handle_get_softap), service);
        g_signal_connect(meshd_dbus_object, "handle-enable-softap",
                        G_CALLBACK(_wmeshd_dbus_handle_enable_softap), service);
        g_signal_connect(meshd_dbus_object, "handle-disable-softap",
index 726e63f..194ef7b 100644 (file)
@@ -73,6 +73,7 @@
 #define MAX_BUF_SIZE           (256u)
 
 static int hostapd_ctrl_fd = 0;
+static char *g_passphrase = NULL;
 
 static int __get_psk_hexascii(const char *pass, const unsigned char *salt,
                char *psk, unsigned int psk_len)
@@ -182,6 +183,56 @@ static int __config_hostapd(const char *softap_interface, const char *ssid,
        return WMESHD_ERROR_NONE;
 }
 
+static int __read_hostapd_config(char **softap_interface, char **ssid,
+               char **mode, int *channel, int *visibility, int *max_sta, int *security,
+               char **passphrase)
+{
+       FILE *fp = NULL;
+       char buf[256];
+
+       fp = fopen(HOSTAPD_MESH_CONF_FILE, "r");
+       if (fp == NULL) {
+               WMESH_LOGE("Failed to read file");
+               return WMESHD_ERROR_IO_ERROR;
+       }
+
+       if (!softap_interface || !ssid || !security || !passphrase || !mode ||
+               !channel || !visibility || !max_sta)
+               return WMESHD_ERROR_INVALID_PARAMETER;
+
+       *security = 0;
+
+       while (NULL != fgets(buf, sizeof(buf), fp)) {
+               if (strncmp(buf, "interface", strlen("interface")) == 0) {
+                       *softap_interface = g_strdup(strrchr(buf, '=') + 1);
+                       WMESH_LOGD("Interface: %s", *softap_interface);
+               } else if (strncmp(buf, "ssid", strlen("ssid")) == 0) {
+                       *ssid = g_strdup(strrchr(buf, '=') + 1);
+                       WMESH_LOGD("SSID: %s", *ssid);
+               } else if (strncmp(buf, "hw_mode", strlen("hw_mode")) == 0) {
+                       *mode = g_strdup(strrchr(buf, '=') + 1);
+                       WMESH_LOGD("Mode: %s", *mode);
+               } else if (strncmp(buf, "channel", strlen("channel")) == 0) {
+                       *channel = atoi(strrchr(buf, '=') + 1);
+                       WMESH_LOGD("Channel: %d", *channel);
+               } else if (strncmp(buf, "ignore_broadcast_ssid",
+                                                  strlen("ignore_broadcast_ssid")) == 0) {
+                       *visibility = atoi(strrchr(buf, '=') + 1) == 0 ? 1 : 0;
+                       WMESH_LOGD("Visibility: %d", *visibility);
+               } else if (strncmp(buf, "max_num_sta", strlen("max_num_sta")) == 0) {
+                       *max_sta = atoi(strrchr(buf, '=') + 1);
+                       WMESH_LOGD("Max Station: %d", *max_sta);
+               } else if (strncmp(buf, "wpa=", strlen("wpa=")) == 0) {
+                       *security = 1;
+                       *passphrase = g_strdup(g_passphrase);
+                       WMESH_LOGD("Security: %d", *security);
+                       WMESH_LOGD("Passphrase: %s", *passphrase);
+               }
+       }
+
+       return WMESHD_ERROR_NONE;
+}
+
 static int __open_hostapd_intf(const char* softap_interface, int *fd,
                const char *intf)
 {
@@ -367,6 +418,23 @@ int wmesh_softap_set_configuration(const char* softap_interface,
        ret = __config_hostapd(softap_interface, ssid, sec, passphrase,
                        mode, channel, visibility, mac_filter, max_sta);
 
+       if (ret == WMESHD_ERROR_NONE) {
+               g_free(g_passphrase);
+               g_passphrase = g_strdup(passphrase);
+       }
+
+       return ret;
+}
+
+int wmesh_softap_get_configuration(char **softap_interface, char **ssid,
+                       char **mode, int *channel, int *visibility,
+               int *max_sta, int *security, char **passphrase)
+{
+       int ret = WMESHD_ERROR_NONE;
+
+       ret = __read_hostapd_config(softap_interface, ssid, mode, channel,
+                                                       visibility, max_sta, security, passphrase);
+
        return ret;
 }