Add Soft AP APIs #3 27/63627/2
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 25 Mar 2016 04:30:43 +0000 (13:30 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Fri, 25 Mar 2016 04:33:42 +0000 (13:33 +0900)
- Get/Set passphrase

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

index 31d86fe59a54c2b9bc7c2e5dcf01ecfc51177d04..9d0ea933d548da79e5922680c65caa312da84734 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-softap
 Summary:       Softap Framework
-Version:       0.0.3
+Version:       0.0.4
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 7aac5f91aa0c7043e60c2958a025de12e251f62b..98c3b61d22dfaafd4e784aaf9e31c8e8c439f862 100755 (executable)
@@ -1291,6 +1291,34 @@ API int softap_unset_ssid_visibility_changed_cb(softap_h softap)
        return SOFTAP_ERROR_NONE;
 }
 
+API int softap_set_passphrase_changed_cb(softap_h softap, softap_passphrase_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->passphrase_changed_cb = callback;
+       sa->passphrase_user_data = user_data;
+
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_unset_passphrase_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->passphrase_changed_cb = NULL;
+       sa->passphrase_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,
@@ -1416,7 +1444,65 @@ 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");
+                       "parameter(visible) is NULL\n");
 
        return __get_visibility(visible);
 }
+
+API int softap_set_passphrase(softap_h softap, const char *passphrase)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(passphrase == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(passphrase) is NULL\n");
+
+       __softap_h *sa = (__softap_h *)softap;
+       int passphrase_len = 0;
+
+       DBG("+");
+       passphrase_len = strlen(passphrase);
+       if (passphrase_len < SOFTAP_KEY_MIN_LEN ||
+                       passphrase_len > SOFTAP_KEY_MAX_LEN) {
+               ERR("parameter(passphrase) is too short or long\n");
+               return SOFTAP_ERROR_INVALID_PARAMETER;
+       }
+
+       g_strlcpy(sa->passphrase, passphrase, sizeof(sa->passphrase));
+
+       DBG("-");
+       return SOFTAP_ERROR_NONE;
+}
+
+API int softap_get_passphrase(softap_h softap, char **passphrase)
+{
+       _retvm_if(softap == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(softap) is NULL\n");
+       _retvm_if(passphrase == NULL, SOFTAP_ERROR_INVALID_PARAMETER,
+                       "parameter(passphrase) is NULL\n");
+
+       __softap_h *sa = (__softap_h *) softap;
+
+       char val[SOFTAP_KEY_MAX_LEN + 1] = {0, };
+       bool enable;
+
+       softap_is_enabled(softap, &enable);
+
+       if (!enable) {
+               if (sa->passphrase != NULL) {
+                       *passphrase = strdup(sa->passphrase);
+               } else {
+                       g_strlcpy(val, vconf_get_str(VCONFKEY_SOFTAP_KEY), sizeof(val));
+                       *passphrase = strdup(val);
+               }
+       } else {
+               g_strlcpy(val, vconf_get_str(VCONFKEY_SOFTAP_KEY), sizeof(val));
+               *passphrase = strdup(val);
+       }
+
+       if (*passphrase == NULL) {
+               ERR("strdup is failed\n");
+               return SOFTAP_ERROR_OUT_OF_MEMORY;
+       }
+
+       return SOFTAP_ERROR_NONE;
+}
index bb5b93db5b510920f6915dcb6961052cd61ec73e..6798c9166286ba41689f94d91e897f6f773015b7 100755 (executable)
@@ -342,6 +342,7 @@ static int test_softap_get_settings(void)
 {
        int ret = SOFTAP_ERROR_NONE;
        char *ssid = NULL;
+       char *passphrase = NULL;
        char *mac_address = NULL;
        char *interface_name = NULL;
        char *ip_address = NULL;
@@ -354,6 +355,10 @@ static int test_softap_get_settings(void)
        if (ret != SOFTAP_ERROR_NONE)
                return 0;
 
+       ret = softap_get_passphrase(sa, &passphrase);
+       if (ret != SOFTAP_ERROR_NONE)
+               return 0;
+
        ret = softap_get_ssid_visibility(sa, &visible);
        if (ret != SOFTAP_ERROR_NONE)
                return 0;
@@ -386,6 +391,7 @@ static int test_softap_get_settings(void)
        printf("* SSID: %s\n", ssid);
        printf("* SSID visibility: %d\n", visible);
        printf("* Security type: %d\n", security_type);
+       printf("* Passphrase: %s\n", passphrase);
        printf("* MAC address: %s\n", mac_address);
        printf("* Network Interface: %s\n", interface_name);
        printf("* IP address: %s\n", ip_address);
@@ -393,6 +399,7 @@ static int test_softap_get_settings(void)
        printf("* subnet_mask: %s\n", subnet_mask);
 
        if (ssid)       g_free(ssid);
+       if (passphrase) g_free(passphrase);
        if (mac_address)        g_free(mac_address);
        if (interface_name)     g_free(interface_name);
        if (ip_address)         g_free(ip_address);
@@ -459,6 +466,25 @@ static int test_softap_set_security_type(void)
        return 1;
 }
 
+static int test_softap_set_passphrase(void)
+{
+       int ret;
+       char passphrase[65];
+
+       printf("Input passphrase for Softap: ");
+       ret = scanf("%64s", passphrase);
+       if (ret < 0) {
+               printf("scanf is failed!!\n");
+               return 0;
+       }
+
+       ret = softap_set_passphrase(sa, passphrase);
+       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);
@@ -557,6 +583,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case '9':
                rv = test_softap_set_security_type();
                break;
+       case 'a':
+               rv = test_softap_set_passphrase();
+               break;
        case 'b':
                rv = test_softap_get_client_info();
                break;