From 3a4422fb5ee58a09878772a29f524125b2d079d8 Mon Sep 17 00:00:00 2001 From: Niraj Kumar Goit Date: Tue, 25 Jul 2017 18:37:47 +0530 Subject: [PATCH] Added support to Add, Get and Remove VSIE data. Change-Id: I96282db0df1e310e8f1d8585bd50b8cd2505b6e1 Signed-off-by: Niraj Kumar Goit --- include/network_dbus.h | 3 + include/network_interface.h | 12 ++++ include/wifi_internal.h | 7 ++- include/wifi_manager_extension.h | 10 ++-- src/network_dbus.c | 88 ++++++++++++++++++++++++++++ src/network_interface.c | 111 +++++++++++++++++++++++++++++++++++ src/wifi_internal.c | 123 +++++++++++++++++++++++++++++++++++++++ src/wifi_manager.c | 39 +++++++++++++ test/wifi_manager_test.c | 100 +++++++++++++++++++++++++++++++ 9 files changed, 487 insertions(+), 6 deletions(-) diff --git a/include/network_dbus.h b/include/network_dbus.h index c78be3e..ecd4ae2 100755 --- a/include/network_dbus.h +++ b/include/network_dbus.h @@ -143,6 +143,9 @@ int _net_dbus_get_autoscanmode(unsigned int *autoscanmode); int _net_dbus_get_autoscan(gboolean *autoscan); +int _net_dbus_add_vsie(unsigned int frame_id, const char *vsie_str); +int _net_dbus_get_vsie(unsigned int frame_id, char **vsie_str); +int _net_dbus_remove_vsie(unsigned int frame_id, const char *vsie_str); #ifdef __cplusplus } diff --git a/include/network_interface.h b/include/network_interface.h index ec2c24c..28f248a 100755 --- a/include/network_interface.h +++ b/include/network_interface.h @@ -135,6 +135,14 @@ typedef enum { NET_STATE_ERROR_INVALID_KEY = 0x07, } net_error_state_type_e; +typedef enum { + NET_VSIE_FRAME_ASSOC_REQ = 13, + NET_VSIE_FRAME_PROBE_REQ = 14, + NET_VSIE_FRAME_REASSOC = 15, + NET_VSIE_FRAME_AUTH_REQ = 16, + NET_VSIE_FRAME_ACTION = 17, +} net_vsie_frames_e; + typedef struct { char ProfileName[NET_PROFILE_NAME_LEN_MAX+1]; /** Profile name */ net_state_type_e ProfileState; /** Service state */ @@ -237,6 +245,10 @@ int net_wifi_get_passpoint(int *enable); int net_wifi_set_passpoint(int enable); int net_wifi_get_scan_state(int *scan_state); +int net_wifi_add_vsie(unsigned int frame_id, const char *vsie_str); +int net_wifi_get_vsie(unsigned int frame_id, char **vsie_str); +int net_wifi_remove_vsie(unsigned int frame_id, const char *vsie_str); + int net_wifi_cancel_wps(void); int net_open_connection_with_wifi_info(const net_wifi_connection_info_s *wifi_info); diff --git a/include/wifi_internal.h b/include/wifi_internal.h index 709ca49..bb711ed 100755 --- a/include/wifi_internal.h +++ b/include/wifi_internal.h @@ -262,7 +262,12 @@ int _wifi_get_autoscanmode(wifi_manager_autoscan_mode_e *autoscanmode); int _wifi_get_module_state(wifi_manager_module_state_e *state); void _wifi_module_state_changed_cb(keynode_t *node, void *user_data); - +int _wifi_add_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, const char *vsie_str); +int _wifi_get_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, char **vsie_str); +int _wifi_remove_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, const char *vsie_str); /* WIFI Privilege Check */ int _wifi_check_get_privilege(); diff --git a/include/wifi_manager_extension.h b/include/wifi_manager_extension.h index e0da8c0..e0cd41a 100755 --- a/include/wifi_manager_extension.h +++ b/include/wifi_manager_extension.h @@ -58,27 +58,27 @@ typedef enum { /** * WiFi probe request frame */ - WIFI_MANGAER_VSIE_FRAME_PROB_REQ, + WIFI_MANAGER_VSIE_FRAME_PROBE_REQ, /** * WiFi assocition request frame */ - WIFI_MANGAER_VSIE_FRAME_ASSOC_REQ, + WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ, /** * WiFi re-assocition request frame */ - WIFI_MANGAER_VSIE_FRAME_REASSOC, + WIFI_MANAGER_VSIE_FRAME_REASSOC, /** * WiFi auth request frame */ - WIFI_MANGAER_VSIE_FRAME_AUTH_REQ, + WIFI_MANAGER_VSIE_FRAME_AUTH_REQ, /** * WiFi auth request frame */ - WIFI_MANGAER_VSIE_FRAME_ACTION, + WIFI_MANAGER_VSIE_FRAME_ACTION, } wifi_manager_vsie_frames_e; diff --git a/src/network_dbus.c b/src/network_dbus.c index 16619cc..8950d3d 100755 --- a/src/network_dbus.c +++ b/src/network_dbus.c @@ -1818,6 +1818,94 @@ int _net_dbus_set_passpoint(int enable) return Error; } +int _net_dbus_add_vsie(unsigned int frame_id, const char *vsie_str) +{ + __NETWORK_FUNC_ENTER__; + + GVariant *message = NULL; + GVariant *params = NULL; + net_err_e Error = NET_ERR_NONE; + + params = g_variant_new("(is)", frame_id, vsie_str); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, "AddVsie", params, + &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to add vsie"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully Added VSIE\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_get_vsie(unsigned int frame_id, char **vsie_str) +{ + __NETWORK_FUNC_ENTER__; + + GVariant *message = NULL; + GVariant *params = NULL; + const char *val = NULL; + net_err_e Error = NET_ERR_NONE; + + params = g_variant_new("(i)", frame_id); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, "GetVsie", params, + &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to get vsie"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + /** Check Reply */ + g_variant_get(message, "(&s)", &val); + if (val != NULL) + *vsie_str = g_strdup(val); + + WIFI_LOG(WIFI_INFO, "GetVsie result: %s", *vsie_str); + + g_variant_unref(message); + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int _net_dbus_remove_vsie(unsigned int frame_id, const char *vsie_str) +{ + __NETWORK_FUNC_ENTER__; + + GVariant *message = NULL; + GVariant *params = NULL; + net_err_e Error = NET_ERR_NONE; + + params = g_variant_new("(is)", frame_id, vsie_str); + + message = _net_invoke_dbus_method(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, "RemoveVsie", params, + &Error); + + if (message == NULL) { + WIFI_LOG(WIFI_ERROR, "Failed to remove vsie"); + __NETWORK_FUNC_EXIT__; + return Error; + } + + g_variant_unref(message); + WIFI_LOG(WIFI_INFO, "Successfully Added VSIE\n"); + + __NETWORK_FUNC_EXIT__; + return Error; +} + static void __net_wps_cancel_reply(GObject *source_object, GAsyncResult *res, gpointer user_data) { diff --git a/src/network_interface.c b/src/network_interface.c index 45fc48a..3f672ed 100755 --- a/src/network_interface.c +++ b/src/network_interface.c @@ -1527,6 +1527,117 @@ int net_wifi_set_passpoint(int enable) } //LCOV_EXCL_STOP +int net_wifi_add_vsie(unsigned int frame_id, const char *vsie_str) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + if (NetworkInfo.ref_count < 1) { + WIFI_LOG(WIFI_ERROR, "Application is not registered"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + if (NetworkInfo.wifi_state == WIFI_OFF) { + if ((NetworkInfo.wifi_state = _net_get_wifi_state(&Error)) == WIFI_OFF) { + WIFI_LOG(WIFI_ERROR, "Wi-Fi is powered off!"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_OPERATION; + } + } + + if (_net_dbus_is_pending_call_used() == TRUE) { + WIFI_LOG(WIFI_ERROR, "pending call in progress"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_OPERATION; + } + + Error = _net_dbus_add_vsie(frame_id, vsie_str); + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "_net_dbus_add_vsie() failed. Error [%s]", + _net_print_error(Error)); + } + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int net_wifi_get_vsie(unsigned int frame_id, char **vsie_str) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + if (NetworkInfo.ref_count < 1) { + WIFI_LOG(WIFI_ERROR, "Application is not registered"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + if (NetworkInfo.wifi_state == WIFI_OFF) { + if ((NetworkInfo.wifi_state = _net_get_wifi_state(&Error)) == WIFI_OFF) { + WIFI_LOG(WIFI_ERROR, "Wi-Fi is powered off!"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_OPERATION; + } + } + + if (_net_dbus_is_pending_call_used() == TRUE) { + WIFI_LOG(WIFI_ERROR, "pending call in progress"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_OPERATION; + } + + Error = _net_dbus_get_vsie(frame_id, vsie_str); + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "_net_dbus_add_vsie() failed. Error [%s]", + _net_print_error(Error)); + } + + __NETWORK_FUNC_EXIT__; + return Error; +} + +int net_wifi_remove_vsie(unsigned int frame_id, const char *vsie_str) +{ + __NETWORK_FUNC_ENTER__; + + net_err_e Error = NET_ERR_NONE; + + if (NetworkInfo.ref_count < 1) { + WIFI_LOG(WIFI_ERROR, "Application is not registered"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_APP_NOT_REGISTERED; + } + + if (NetworkInfo.wifi_state == WIFI_OFF) { + if ((NetworkInfo.wifi_state = _net_get_wifi_state(&Error)) == WIFI_OFF) { + WIFI_LOG(WIFI_ERROR, "Wi-Fi is powered off!"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_OPERATION; + } + } + + if (_net_dbus_is_pending_call_used() == TRUE) { + WIFI_LOG(WIFI_ERROR, "pending call in progress"); + __NETWORK_FUNC_EXIT__; + return NET_ERR_INVALID_OPERATION; + } + + Error = _net_dbus_remove_vsie(frame_id, vsie_str); + if (Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, + "_net_dbus_add_vsie() failed. Error [%s]", + _net_print_error(Error)); + } + + __NETWORK_FUNC_EXIT__; + return Error; +} + int net_open_connection_with_wifi_info(const net_wifi_connection_info_s *wifi_info) { __NETWORK_FUNC_ENTER__; diff --git a/src/wifi_internal.c b/src/wifi_internal.c index 1bb65a1..42020c9 100755 --- a/src/wifi_internal.c +++ b/src/wifi_internal.c @@ -1534,6 +1534,129 @@ int _wifi_bssid_scan_request(wifi_manager_h wifi, return WIFI_MANAGER_ERROR_OPERATION_FAILED; } +int _wifi_add_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, const char *vsie_str) +{ + int rv; + net_vsie_frames_e f_id; + + switch (frame_id) { + case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ: + f_id = NET_VSIE_FRAME_ASSOC_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ: + f_id = NET_VSIE_FRAME_PROBE_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_REASSOC: + f_id = NET_VSIE_FRAME_REASSOC; + break; + case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ: + f_id = NET_VSIE_FRAME_AUTH_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_ACTION: + f_id = NET_VSIE_FRAME_ACTION; + break; + default: + WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id); + return WIFI_MANAGER_ERROR_NOT_SUPPORTED; + } + rv = net_wifi_add_vsie(f_id, vsie_str); + + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv == NET_ERR_INVALID_OPERATION) { + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + } else if (rv == NET_ERR_NONE) { + return WIFI_MANAGER_ERROR_NONE; + } + + WIFI_LOG(WIFI_ERROR, "Operation Failed"); + return WIFI_MANAGER_ERROR_OPERATION_FAILED; +} + +int _wifi_get_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, char **vsie_str) +{ + int rv; + net_vsie_frames_e f_id; + + switch (frame_id) { + case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ: + f_id = NET_VSIE_FRAME_ASSOC_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ: + f_id = NET_VSIE_FRAME_PROBE_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_REASSOC: + f_id = NET_VSIE_FRAME_REASSOC; + break; + case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ: + f_id = NET_VSIE_FRAME_AUTH_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_ACTION: + f_id = NET_VSIE_FRAME_ACTION; + break; + default: + WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id); + return WIFI_MANAGER_ERROR_NOT_SUPPORTED; + } + rv = net_wifi_get_vsie(f_id, vsie_str); + + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv == NET_ERR_INVALID_OPERATION) { + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + } else if (rv == NET_ERR_NONE) { + return WIFI_MANAGER_ERROR_NONE; + } + + WIFI_LOG(WIFI_ERROR, "Operation Failed"); + return WIFI_MANAGER_ERROR_OPERATION_FAILED; +} + +int _wifi_remove_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, const char *vsie_str) +{ + int rv; + net_vsie_frames_e f_id; + + switch (frame_id) { + case WIFI_MANAGER_VSIE_FRAME_ASSOC_REQ: + f_id = NET_VSIE_FRAME_ASSOC_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_PROBE_REQ: + f_id = NET_VSIE_FRAME_PROBE_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_REASSOC: + f_id = NET_VSIE_FRAME_REASSOC; + break; + case WIFI_MANAGER_VSIE_FRAME_AUTH_REQ: + f_id = NET_VSIE_FRAME_AUTH_REQ; + break; + case WIFI_MANAGER_VSIE_FRAME_ACTION: + f_id = NET_VSIE_FRAME_ACTION; + break; + default: + WIFI_LOG(WIFI_ERROR, "Frame ID: [%d] not supported.", frame_id); + return WIFI_MANAGER_ERROR_NOT_SUPPORTED; + } + rv = net_wifi_remove_vsie(f_id, vsie_str); + + if (rv == NET_ERR_ACCESS_DENIED) { + WIFI_LOG(WIFI_ERROR, "Access denied"); + return WIFI_MANAGER_ERROR_PERMISSION_DENIED; + } else if (rv == NET_ERR_INVALID_OPERATION) { + return WIFI_MANAGER_ERROR_INVALID_OPERATION; + } else if (rv == NET_ERR_NONE) { + return WIFI_MANAGER_ERROR_NONE; + } + + WIFI_LOG(WIFI_ERROR, "Operation Failed"); + return WIFI_MANAGER_ERROR_OPERATION_FAILED; +} + int _wifi_get_connected_profile(wifi_manager_ap_h *ap) { int rv; diff --git a/src/wifi_manager.c b/src/wifi_manager.c index 92607fa..b8fe07b 100755 --- a/src/wifi_manager.c +++ b/src/wifi_manager.c @@ -957,3 +957,42 @@ EXPORT_API int wifi_manager_bssid_scan(wifi_manager_h wifi, return _wifi_bssid_scan_request(wifi, callback, user_data); } + +EXPORT_API int wifi_manager_add_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, const char *vsie_str) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (vsie_str == NULL || !(__wifi_check_handle_validity(wifi))) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + return _wifi_add_vsie(wifi, frame_id, vsie_str); +} + +EXPORT_API int wifi_manager_get_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, char **vsie_str) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (vsie_str == NULL || !(__wifi_check_handle_validity(wifi))) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + return _wifi_get_vsie(wifi, frame_id, vsie_str); +} + +EXPORT_API int wifi_manager_remove_vsie(wifi_manager_h wifi, + wifi_manager_vsie_frames_e frame_id, const char *vsie_str) +{ + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + + if (vsie_str == NULL || !(__wifi_check_handle_validity(wifi))) { + WIFI_LOG(WIFI_ERROR, "Invalid parameter"); + return WIFI_MANAGER_ERROR_INVALID_PARAMETER; + } + + return _wifi_remove_vsie(wifi, frame_id, vsie_str); +} diff --git a/test/wifi_manager_test.c b/test/wifi_manager_test.c index 42920dc..6fb8d98 100755 --- a/test/wifi_manager_test.c +++ b/test/wifi_manager_test.c @@ -2282,6 +2282,94 @@ int test_wifi_manager_get_scan_state(void) return 1; } +int test_wifi_manager_add_vsie(void) +{ + int rv = 0; + char *vsie = NULL; + unsigned int frame_id; + + printf("Input frame_id:\n"); + if (scanf(" %2u", &frame_id) < 1) + return -1; + + printf("Input vsie:\n"); + if (scanf(" %100ms", &vsie) < 1) + return -1; + + if (strlen(vsie) <= 0) + printf("invalid vsie !!\n"); + else + printf("vsie: [%s]\n", vsie); + + if ((strlen(vsie) > 0)) { + rv = wifi_manager_add_vsie(wifi, frame_id, vsie); + printf("wifi_manager_add_vsie() ret=[%d]\n", rv); + + g_free(vsie); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Failed to add vsie [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + } + + return 1; +} + +int test_wifi_manager_get_vsie(void) +{ + int rv = 0; + char *vsie = NULL; + unsigned int frame_id; + + printf("Input frame_id:\n"); + if (scanf(" %2u", &frame_id) < 1) + return -1; + + rv = wifi_manager_get_vsie(wifi, frame_id, &vsie); + printf("Received vsie [%s]\n", vsie ? vsie : "NULL"); + + g_free(vsie); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Failed to get vsie [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + return 1; +} + +int test_wifi_manager_remove_vsie(void) +{ + int rv = 0; + char *vsie = NULL; + unsigned int frame_id; + + printf("Input frame_id:\n"); + if (scanf(" %2u", &frame_id) < 1) + return -1; + + printf("Input vsie:\n"); + if (scanf(" %100ms", &vsie) < 1) + return -1; + + if (strlen(vsie) <= 0) + printf("invalid vsie !!\n"); + else + printf("vsie: [%s]\n", vsie); + + if ((strlen(vsie) > 0)) { + rv = wifi_manager_remove_vsie(wifi, frame_id, vsie); + printf("wifi_manager_remove_vsie() ret=[%d]\n", rv); + + g_free(vsie); + if (rv != WIFI_MANAGER_ERROR_NONE) { + printf("Failed to remove vsie [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + } + + return 1; +} + int main(int argc, char **argv) { GMainLoop *mainloop; @@ -2363,6 +2451,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("C - Disable TDLS Channel Switch Request\n"); printf("D - Get Wi-Fi Module State\n"); printf("E - BSSID Scan\n"); + printf("F - Add VSIE\n"); + printf("G - Get VSIE\n"); + printf("H - Remove VSIE\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); @@ -2491,6 +2582,15 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'E': rv = test_wifi_manager_bssid_scan(); break; + case 'F': + rv = test_wifi_manager_add_vsie(); + break; + case 'G': + rv = test_wifi_manager_get_vsie(); + break; + case 'H': + rv = test_wifi_manager_remove_vsie(); + break; default: break; } -- 2.7.4