Add API to get the RSSI level 24/141924/13
authortaesub kim <taesub.kim@samsung.com>
Wed, 2 Aug 2017 04:26:14 +0000 (13:26 +0900)
committertaesub kim <taesub.kim@samsung.com>
Thu, 3 Aug 2017 23:15:34 +0000 (08:15 +0900)
Change-Id: I921590441282351a4cc0f7f957f78831195889e1
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
include/wifi-manager.h
src/wifi_ap.c
test/wifi_manager_test.c

index 940bdc0..8fa729a 100755 (executable)
@@ -206,11 +206,11 @@ typedef enum {
  * @since_tizen 3.0
  */
 typedef enum {
-       WIFI_MANAGER_RSSI_LEVEL_0 = 0,      /**< level 0 */
-       WIFI_MANAGER_RSSI_LEVEL_1 = 1,      /**< level 1 */
-       WIFI_MANAGER_RSSI_LEVEL_2 = 2,      /**< level 2 */
-       WIFI_MANAGER_RSSI_LEVEL_3 = 3,      /**< level 3 */
-       WIFI_MANAGER_RSSI_LEVEL_4 = 4,      /**< level 4 */
+       WIFI_MANAGER_RSSI_LEVEL_0 = 0,      /**< No signal */
+       WIFI_MANAGER_RSSI_LEVEL_1 = 1,      /**< Very weak signal ~ -83dBm */
+       WIFI_MANAGER_RSSI_LEVEL_2 = 2,      /**< Weak signal -82 ~ -75dBm */
+       WIFI_MANAGER_RSSI_LEVEL_3 = 3,      /**< Strong signal -74 ~ -64dBm */
+       WIFI_MANAGER_RSSI_LEVEL_4 = 4,      /**< Very strong signal -63dBm ~ */
 } wifi_manager_rssi_level_e;
 
 /**
@@ -1800,7 +1800,7 @@ int wifi_manager_ap_get_bssid(wifi_manager_ap_h ap, char **bssid);
  * @brief Gets the RSSI.
  * @since_tizen 3.0
  * @param[in] ap              The access point handle
- * @param[out] rssi           The RSSI
+ * @param[out] rssi           The RSSI value (in dBm)
  * @return 0 on success, otherwise negative error value
  * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
  * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
@@ -1810,6 +1810,19 @@ int wifi_manager_ap_get_bssid(wifi_manager_ap_h ap, char **bssid);
 int wifi_manager_ap_get_rssi(wifi_manager_ap_h ap, int *rssi);
 
 /**
+ * @brief Gets the RSSI level.
+ * @since_tizen 4.0
+ * @param[in] ap              The access point handle
+ * @param[out] rssi_level     The RSSI level
+ * @return 0 on success, otherwise negative error value
+ * @retval #WIFI_MANAGER_ERROR_NONE                 Successful
+ * @retval #WIFI_MANAGER_ERROR_INVALID_PARAMETER    Invalid parameter
+ * @retval #WIFI_MANAGER_ERROR_OPERATION_FAILED     Operation failed
+ * @retval #WIFI_MANAGER_ERROR_NOT_SUPPORTED        Not supported
+ */
+int wifi_manager_ap_get_rssi_level(wifi_manager_ap_h ap, wifi_manager_rssi_level_e *rssi_level);
+
+/**
  * @brief Gets the frequency band (MHz).
  * @since_tizen 3.0
  * @param[in] ap              The access point handle
index ffc3c1e..124d8bd 100755 (executable)
@@ -431,6 +431,43 @@ EXPORT_API int wifi_manager_ap_get_rssi(wifi_manager_ap_h ap, int *rssi)
        return WIFI_MANAGER_ERROR_NONE;
 }
 
+EXPORT_API int wifi_manager_ap_get_rssi_level(wifi_manager_ap_h ap, wifi_manager_rssi_level_e *rssi_level)
+{
+       CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
+
+       int rssi_dbm = 0;
+
+       if (_wifi_check_ap_validity(ap) == false || rssi_level == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Invalid parameter"); //LCOV_EXCL_LINE
+               return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
+
+       net_profile_info_s *profile_info = ap;
+       rssi_dbm = (int)(profile_info->Strength - 120);
+
+       /* Wi-Fi Signal Strength Display
+        *
+        * No signal : 0
+        * Excellent : -63 ~
+        * Good      : -74 ~ -64
+        * Weak      : -82 ~ -75
+        * Very weak : -83 ~
+        */
+
+       if (rssi_dbm == 0)
+               *rssi_level = WIFI_MANAGER_RSSI_LEVEL_0;
+       else if (rssi_dbm >= -63)
+               *rssi_level = WIFI_MANAGER_RSSI_LEVEL_4;
+       else if (rssi_dbm >= -74)
+               *rssi_level = WIFI_MANAGER_RSSI_LEVEL_3;
+       else if (rssi_dbm >= -82)
+               *rssi_level = WIFI_MANAGER_RSSI_LEVEL_2;
+       else
+               *rssi_level = WIFI_MANAGER_RSSI_LEVEL_1;
+
+       return WIFI_MANAGER_ERROR_NONE;
+}
+
 EXPORT_API int wifi_manager_ap_get_frequency(wifi_manager_ap_h ap, int *frequency)
 {
        CHECK_FEATURE_SUPPORTED(WIFI_FEATURE);
index 6fb8d98..7be77f4 100755 (executable)
@@ -908,6 +908,7 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user
        bool bool_value;
        char *ap_name_part = (char*)user_data;
        wifi_manager_disconnect_reason_e disconnect_reason;
+       wifi_manager_rssi_level_e rssi_level;
 
        rv = wifi_manager_ap_get_essid(ap, &ap_name);
        if (rv != WIFI_MANAGER_ERROR_NONE) {
@@ -931,6 +932,11 @@ static bool __test_found_print_ap_info_callback(wifi_manager_ap_h ap, void *user
                else
                        printf("Fail to get RSSI\n");
 
+               if (wifi_manager_ap_get_rssi_level(ap, &rssi_level) == WIFI_MANAGER_ERROR_NONE)
+                       printf("RSSI level : %d\n", rssi_level);
+               else
+                       printf("Fail to get RSSI level\n");
+
                if (wifi_manager_ap_get_frequency(ap, &int_value) == WIFI_MANAGER_ERROR_NONE)
                        printf("Frequency : %d\n", int_value);
                else