API to get connection mode of connected network 48/189948/8
authorMilind Murhekar <m.murhekar@samsung.com>
Mon, 24 Sep 2018 12:13:36 +0000 (17:43 +0530)
committerMilind Murhekar <m.murhekar@samsung.com>
Fri, 5 Oct 2018 08:59:13 +0000 (14:29 +0530)
This patch adds the new API to get the IEEE 802.11
connection mode of an AP.
Ex:- 802.11b/g/n/a/ac modes

Change-Id: I031b824480373d507fba88635e7683e2b1debdd5
Signed-off-by: Milind Murhekar <m.murhekar@samsung.com>
include/network_interface.h
include/wifi-manager-extension.h
include/wifi_internal.h
src/network_interface.c
src/wifi_ap.c
src/wifi_internal.c
src/wifi_manager.c
test/wifi_manager_test.c

index 4061724a06968c844ccccffd3e987e9cb09e2a52..44fca44937ccecf5cb0b954139fc51c751e5477e 100755 (executable)
@@ -178,6 +178,7 @@ typedef struct {
        GSList *vsie_list;                      /** List of Vendor Specific Information Element of AP*/
        int assoc_status_code;                                                  /** Supplicant WiFi Association Status Code */
        char country_code[NET_WLAN_COUNTRY_CODE_LEN];                           /** Country code received from AP */
+       unsigned int connection_mode;                                   /** Connection mode (IEEE 802.11b/g/n/a/ac) */
        GSList *bssid_list;                     /** List if BSSID, strength and frequency of AP **/
 } net_profile_info_s;
 
index 0a3aae8e63b1252bb4ff2e2b5ec43fae74eeb9d0..c84c60d50e2c31b35166c0683d6e063b7b233f63 100755 (executable)
@@ -43,6 +43,19 @@ typedef enum {
        WIFI_MANAGER_AUTOSCAN_MODE_PERIODIC
 } wifi_manager_autoscan_mode_e;
 
+/**
+ * @brief Enumeration for the Wi-Fi Connection Mode.
+ * @since_tizen 5.0
+ */
+typedef enum {
+       WIFI_MANAGER_CONNECTION_MODE_UNKNOWN,     /**< Unknown */
+       WIFI_MANAGER_CONNECTION_MODE_80211_B,    /**< IEEE 802.11b 2.4 Ghz */
+       WIFI_MANAGER_CONNECTION_MODE_80211_G,    /**< IEEE 802.11g 2.4 Ghz */
+       WIFI_MANAGER_CONNECTION_MODE_80211_N,    /**< IEEE 802.11n 2.4/5 Ghz */
+       WIFI_MANAGER_CONNECTION_MODE_80211_A,    /**< IEEE 802.11a 5 Ghz */
+       WIFI_MANAGER_CONNECTION_MODE_80211_AC,   /**< IEEE 802.11ac 5 Ghz */
+} wifi_manager_connection_mode_e;
+
 /**
  * @brief The Wi-Fi netlink scan handle.
  * @since_tizen 5.0
@@ -442,6 +455,21 @@ int wifi_manager_initialize_cs(int tid, wifi_manager_h *wifi);
  */
 int wifi_manager_deinitialize_cs(int tid, wifi_manager_h wifi);
 
+/**
+ * @brief Gets IEEE 802.11 Connection mode of connected network.
+ * @since_tizen 5.0
+ * @param[in] wifi     Wi-Fi handle
+ * @param[out] mode    connection mode
+ * @return 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
+ * @retval #WIFI_MANAGER_ERROR_NO_CONNECTION        Not Connected
+ * @retval #WIFI_MANAGER_ERROR_NOT_INITIALIZED      Not initialized
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Not supported
+ */
+int wifi_manager_get_connection_mode(wifi_manager_h wifi,
+               wifi_manager_connection_mode_e *mode);
+
 /**
 * @}
 */
index bcf835f1e81a1b14b083f266c6cd2663be7c50dd..e97d5021a3f1a7897e7960706ab1c0abf5412733 100755 (executable)
@@ -383,6 +383,7 @@ int _wifi_set_ip_conflict_period(unsigned int initial_time);
 int _wifi_get_ip_conflict_state(wifi_manager_ip_conflict_state_e *state);
 int _wifi_get_ip_conflict_period(unsigned int* initial_time);
 int _wifi_get_wps_generated_pin(char **wps_pin);
+int _wifi_get_connection_mode(wifi_manager_connection_mode_e *mode);
 
 void __clear_profile_list(GSList **iterator);
 
index cce9a723eae2d72a043caca355f929188ca1c667..1a3ca6f46e5cab5193a866b10b76e60fa1e7618d 100755 (executable)
@@ -978,6 +978,9 @@ static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_s* Prof
                } else if (g_strcmp0(key, "Frequency") == 0) {
                        ProfInfo->frequency = (unsigned int)g_variant_get_uint16(var);
 
+               } else if (g_strcmp0(key, "ConnMode") == 0) {
+                       ProfInfo->connection_mode = (unsigned int)g_variant_get_uint16(var);
+
                } else if (g_strcmp0(key, "Vsie") == 0) {
                        const unsigned char *vsie_bytes = NULL;
                        unsigned char *vsie = NULL;
index 4f5b0862b09b5fcf4e5fda221b032337b963dd26..17da3a004f810e7c32728371d0769855b23d4ccd 100755 (executable)
@@ -2467,4 +2467,3 @@ EXPORT_API int wifi_manager_ap_get_error_state(wifi_manager_ap_h ap, wifi_manage
 
        return WIFI_MANAGER_ERROR_NONE;
 }
-
index c92391888d1b5ec2b1c58b3e81c1c60548f25d5e..e7dd41f1d5c2ab64159ca361818ea0047dc7bb8a 100755 (executable)
@@ -3438,3 +3438,32 @@ int _wifi_start_multi_scan(wifi_manager_h wifi,
 
        return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
 }
+
+int _wifi_get_connection_mode(wifi_manager_connection_mode_e *mode)
+{
+       int rv;
+       GSList *list;
+       net_profile_info_s *prof_info = NULL;
+
+       rv = __update_profile_iterator();
+       if (rv == NET_ERR_ACCESS_DENIED) {
+               WIFI_LOG(WIFI_ERROR, "Access denied");
+               return WIFI_MANAGER_ERROR_PERMISSION_DENIED;
+       }
+
+       for (list = profile_iterator; list; list = list->next) {
+               prof_info = (net_profile_info_s *)list->data;
+               if (prof_info->ProfileState == NET_STATE_TYPE_ONLINE ||
+                   prof_info->ProfileState == NET_STATE_TYPE_READY)
+                       break;
+       }
+
+       if (prof_info == NULL) {
+               WIFI_LOG(WIFI_ERROR, "There is no connected AP");
+               return WIFI_MANAGER_ERROR_NO_CONNECTION;
+       }
+
+       *mode = (wifi_manager_connection_mode_e)prof_info->connection_mode;
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
index 7b57216df104663fe05c2242a0c775ffdf261e71..95692e472a1ebdb5184f71438b96bdad6dea600d 100755 (executable)
@@ -1764,3 +1764,27 @@ EXPORT_API int wifi_manager_specific_ap_start_multi_scan(wifi_manager_h wifi,
        __NETWORK_CAPI_FUNC_EXIT__;
        return _wifi_start_multi_scan(wifi, specific_scan, callback, user_data);
 }
+
+EXPORT_API int wifi_manager_get_connection_mode(wifi_manager_h wifi,
+               wifi_manager_connection_mode_e *mode)
+{
+       __NETWORK_CAPI_FUNC_ENTER__;
+
+       int rv;
+
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       RET_ERR_IF_HANDLE_IS_NOT_VALID_OR_NOT_INITIALIZED(wifi, __NETWORK_CAPI_FUNC_EXIT__);
+
+       if (mode == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter");
+               __NETWORK_CAPI_FUNC_EXIT__;
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+       }
+
+       rv = _wifi_get_connection_mode(mode);
+       WIFI_LOG(WIFI_INFO, "Connection mode %d", *mode);
+
+       __NETWORK_CAPI_FUNC_EXIT__;
+       return rv;
+}
index 8da2109ec2379846e8a3b87c6938da56cf512518..8d478fd86b7c04e8ab96b54457222b1b7c7fcdf3 100755 (executable)
@@ -109,6 +109,26 @@ static const char *__test_convert_error_to_string(wifi_manager_error_e err_type)
        }
 }
 
+static const char *__test_convert_connection_mode_to_string(wifi_manager_connection_mode_e mode)
+{
+       switch (mode) {
+       case WIFI_MANAGER_CONNECTION_MODE_80211_B:
+               return "802.11b";
+       case WIFI_MANAGER_CONNECTION_MODE_80211_G:
+               return "802.11g";
+       case WIFI_MANAGER_CONNECTION_MODE_80211_N:
+               return "802.11n";
+       case WIFI_MANAGER_CONNECTION_MODE_80211_A:
+               return "802.11a";
+       case WIFI_MANAGER_CONNECTION_MODE_80211_AC:
+               return "802.11ac";
+       case WIFI_MANAGER_CONNECTION_MODE_UNKNOWN:
+               return "Uknown";
+       default:
+               return "Uknown";
+       }
+}
+
 static void __test_device_state_callback(wifi_manager_device_state_e state, void* user_data)
 {
        printf("[%s] Device state changed callback", (char *)user_data);
@@ -2163,16 +2183,16 @@ int test_wifi_manager_config_save(void)
                        rv = scanf("%39s", ip_addr);
                        if (rv > 0) {
                                switch (ip_addr[0]) {
-                                       case 'x':
-                                               rv = WIFI_MANAGER_ERROR_NONE;
-                                               break;
-                                       case '0':
-                                               rv = wifi_manager_config_set_subnet_mask(config, address_type,
-                                                               NULL);
-                                               break;
-                                       default:
-                                               rv = wifi_manager_config_set_subnet_mask(config, address_type,
-                                                               ip_addr);
+                               case 'x':
+                                       rv = WIFI_MANAGER_ERROR_NONE;
+                                       break;
+                               case '0':
+                                       rv = wifi_manager_config_set_subnet_mask(config, address_type,
+                                                       NULL);
+                                       break;
+                               default:
+                                       rv = wifi_manager_config_set_subnet_mask(config, address_type,
+                                                       ip_addr);
                                }
 
                                if (rv != WIFI_MANAGER_ERROR_NONE) {
@@ -3379,6 +3399,48 @@ int test_wifi_manager_get_passpoint_state(void)
        return 1;
 }
 
+int test_wifi_manager_get_connection_mode(void)
+{
+       int rv, int_value;
+       wifi_manager_connection_mode_e mode;
+       char *ap_name = NULL;
+       wifi_manager_ap_h ap_h;
+
+       rv = wifi_manager_get_connected_ap(wifi, &ap_h);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to get connected AP [%s]\n", __test_convert_error_to_string(rv));
+               return -1;
+       }
+
+       rv = wifi_manager_ap_get_essid(ap_h, &ap_name);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to get essid [%s]\n", __test_convert_error_to_string(rv));
+               wifi_manager_ap_destroy(ap_h);
+               return -1;
+       }
+
+       rv = wifi_manager_ap_get_max_speed(ap_h, &int_value);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to get max speed[%s]\n", __test_convert_error_to_string(rv));
+               wifi_manager_ap_destroy(ap_h);
+               return -1;
+       }
+
+       rv = wifi_manager_get_connection_mode(wifi, &mode);
+       if (rv != WIFI_MANAGER_ERROR_NONE) {
+               printf("Fail to get connection mode[%s]\n", __test_convert_error_to_string(rv));
+               wifi_manager_ap_destroy(ap_h);
+               return -1;
+       }
+
+       printf("Connected AP : %s\n", ap_name);
+       printf("Connection mode : %s\n", __test_convert_connection_mode_to_string(mode));
+       printf("Link speed : %d\n", int_value);
+       g_free(ap_name);
+       wifi_manager_ap_destroy(ap_h);
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -3481,6 +3543,7 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("V   - Netlink Scan Normal/Specific-AP\n");
                printf("W   - Get passpoint state\n");
                printf("X   - Set passpoint on/off\n");
+               printf("Y   - Get Access Point Hardware Mode\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
 
                printf("ENTER  - Show options menu.......\n");
@@ -3667,6 +3730,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'X':
                rv = test_wifi_manager_set_passpoint_enable();
                break;
+       case 'Y':
+               rv = test_wifi_manager_get_connection_mode();
+               break;
        default:
                break;
        }