Parse the security and encryption mode in the netlink scan results. 67/172867/1
authorNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 16 Mar 2018 09:52:02 +0000 (15:22 +0530)
committerNiraj Kumar Goit <niraj.g@samsung.com>
Fri, 16 Mar 2018 09:52:02 +0000 (15:22 +0530)
Change-Id: I52d41db29315a629daf073df0a26752b974998cd
Signed-off-by: Niraj Kumar Goit <niraj.g@samsung.com>
include/network_interface.h
src/network_signal.c
src/wifi_internal.c
test/wifi_manager_test.c

index 11c2935..0ec7a68 100755 (executable)
@@ -210,6 +210,8 @@ typedef struct {
        char vsie[NET_WLAN_MAX_VSIE_LEN + 1];
        int freq;
        int rssi;
+       int security_type;
+       int encryption_type;
 } net_netlink_scan_bss_info_s;
 
 typedef struct {
index 49fc485..8d69f3a 100755 (executable)
@@ -429,6 +429,10 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param)
        const gchar *vsie = NULL;
        int freq = 0;
        int rssi = 0;
+       int sec_type = 0;
+       int enc_type = 0;
+       gboolean security_found = FALSE;
+       gboolean encryption_found = FALSE;
        gboolean ssid_found = FALSE;
        gboolean bssid_found = FALSE;
        gboolean freq_found = FALSE;
@@ -450,12 +454,19 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param)
                } else if (g_strcmp0(key, "rssi") == 0) {
                        rssi = g_variant_get_int32(value);
                        rssi_found = TRUE;
+               } else if (g_strcmp0(key, "security") == 0) {
+                       sec_type = g_variant_get_int32(value);
+                       security_found = TRUE;
+               } else if (g_strcmp0(key, "encryption") == 0) {
+                       enc_type = g_variant_get_int32(value);
+                       encryption_found = TRUE;
                } else if (g_strcmp0(key, "vsie") == 0) {
                        vsie = g_variant_get_string(value, NULL);
                        vsie_found = TRUE;
                }
 
                if (ssid_found == TRUE && bssid_found == TRUE &&
+                       security_found == TRUE && encryption_found == TRUE &&
                        freq_found == TRUE && rssi_found == TRUE && vsie_found == TRUE) {
                        net_netlink_scan_bss_info_s *bss = NULL;
                        bss = g_try_new0(net_netlink_scan_bss_info_s, 1);
@@ -473,8 +484,13 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param)
                        g_strlcpy(bss->bssid, bssid, NET_WLAN_BSSID_LEN+1);
                        bss->freq = freq;
                        bss->rssi = rssi;
+                       bss->security_type = sec_type;
+                       bss->encryption_type = enc_type;
+
+                       WIFI_LOG(WIFI_INFO, "BSSID: %s, Freq: %d, rssi: %d, SSID: %s,"
+                                       "Security type : %d, Encryption type: %d", bssid, freq, rssi, ssid,
+                                       sec_type, enc_type);
 
-                       WIFI_LOG(WIFI_INFO, "BSSID: %s, Freq: %d, rssi: %d, SSID: %s", bssid, freq, rssi, ssid);
                        if (strncmp(vsie, "dd", 2) == 0) {
                                WIFI_LOG(WIFI_INFO, "vsie: %s", vsie);
                                g_strlcpy(bss->vsie, vsie, strlen(vsie)+1);
@@ -483,6 +499,7 @@ static int __net_handle_wifi_netlink_scan_rsp(GVariant *param)
                        bss_info_list = g_slist_append(bss_info_list, bss);
 
                        ssid_found = bssid_found = freq_found = rssi_found = vsie_found = FALSE;
+                       security_found = encryption_found = FALSE;
                }
        }
        g_variant_iter_free(iter);
index b02159b..bf9a518 100755 (executable)
@@ -410,6 +410,48 @@ static void __update_netlink_scan_profile_iterator(GSList *bss_list)
                profile->frequency = (unsigned int)ap->freq;
                profile->Strength = 120 + ap->rssi;
 
+               switch (ap->security_type) {
+               case 0:
+                       profile->security_info.sec_mode = WLAN_SEC_MODE_NONE;
+                       break;
+               case 1:
+                       profile->security_info.sec_mode = WLAN_SEC_MODE_WEP;
+                       break;
+               case 2:
+                       profile->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
+                       break;
+               case 3:
+                       profile->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
+                       break;
+               case 4:
+                       profile->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
+                       break;
+               default:
+                       profile->security_info.sec_mode = WLAN_SEC_MODE_NONE;
+                       break;
+               }
+
+               switch (ap->encryption_type) {
+               case 0:
+                       profile->security_info.enc_mode = WLAN_ENC_MODE_NONE;
+                       break;
+               case 1:
+                       profile->security_info.enc_mode = WLAN_ENC_MODE_WEP;
+                       break;
+               case 2:
+                       profile->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
+                       break;
+               case 3:
+                       profile->security_info.enc_mode = WLAN_ENC_MODE_AES;
+                       break;
+               case 4:
+                       profile->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
+                       break;
+               default:
+                       profile->security_info.enc_mode = WLAN_ENC_MODE_NONE;
+                       break;
+               }
+
                bss_profile_iterator = g_slist_append(bss_profile_iterator,
                                        (net_profile_info_s *)profile);
        }
index 3929f18..c48a82b 100755 (executable)
@@ -2549,6 +2549,8 @@ static bool __test_get_netlink_scan_list(wifi_manager_ap_h ap, void *user_data)
        char *essid = NULL;
        int freq;
        int rssi;
+       wifi_manager_security_type_e sec_type;
+       wifi_manager_encryption_type_e enc_type;
 
        if (wifi_manager_ap_get_bssid(ap, &bssid) != WIFI_MANAGER_ERROR_NONE) {
                printf("Failed to get bssid for ap\n");
@@ -2578,7 +2580,61 @@ static bool __test_get_netlink_scan_list(wifi_manager_ap_h ap, void *user_data)
                return false;
        }
 
+       if (wifi_manager_ap_get_security_type(ap, &sec_type) != WIFI_MANAGER_ERROR_NONE) {
+               printf("Failed to get security type for ap\n");
+               g_free(bssid);
+               g_free(essid);
+               return false;
+       }
+
+       if (wifi_manager_ap_get_encryption_type(ap, &enc_type) != WIFI_MANAGER_ERROR_NONE) {
+               printf("Failed to get encryption type for ap\n");
+               g_free(bssid);
+               g_free(essid);
+               return false;
+       }
+
        printf("%s, %d, %d, %s\n", bssid, freq, rssi, essid);
+       printf("Security type : ");
+       switch (sec_type) {
+       case WIFI_MANAGER_SECURITY_TYPE_NONE:
+               printf("NONE, ");
+               break;
+       case WIFI_MANAGER_SECURITY_TYPE_WEP:
+               printf("WEP, ");
+               break;
+       case WIFI_MANAGER_SECURITY_TYPE_WPA_PSK:
+               printf("WPAPSK, ");
+               break;
+       case WIFI_MANAGER_SECURITY_TYPE_WPA2_PSK:
+               printf("WPA2PSK, ");
+               break;
+       case WIFI_MANAGER_SECURITY_TYPE_EAP:
+               printf("EAP, ");
+               break;
+       default:
+               break;
+       }
+       printf("Encryption type : ");
+       switch (enc_type) {
+       case WIFI_MANAGER_ENCRYPTION_TYPE_NONE:
+               printf("NONE\n");
+               break;
+       case WIFI_MANAGER_ENCRYPTION_TYPE_WEP:
+               printf("WEP\n");
+               break;
+       case WIFI_MANAGER_ENCRYPTION_TYPE_TKIP:
+               printf("TKIP\n");
+               break;
+       case WIFI_MANAGER_ENCRYPTION_TYPE_AES:
+               printf("CCMP\n");
+               break;
+       case WIFI_MANAGER_ENCRYPTION_TYPE_TKIP_AES_MIXED:
+               printf("Mixed\n");
+               break;
+       default:
+               break;
+       }
 
        g_free(bssid);
        g_free(essid);