From 5bd54ba3c372614c362427ec118755bb3ac70787 Mon Sep 17 00:00:00 2001 From: Aaron Kling Date: Sat, 3 Jul 2021 00:50:53 -0500 Subject: [PATCH] Update to android 10 wifi hal --- wlan/Android.mk | 3 + wlan/wifi_hal/Android.mk | 16 +- wlan/wifi_hal/common.h | 2 +- .../{gscan.cpp => rtw_wifi_gscan.cpp} | 2 +- .../{wifi_hal.cpp => rtw_wifi_hal.cpp} | 25 +- ...k_layer_stats.cpp => rtw_wifi_llstats.cpp} | 146 ++----- .../{wifi_logger.cpp => rtw_wifi_logger.cpp} | 41 -- ...{wifi_offload.cpp => rtw_wifi_offload.cpp} | 3 +- wlan/wifi_hal/{rtt.cpp => rtw_wifi_rtt.cpp} | 2 +- wlan/wifi_hal/version.h | 6 + wlan/wpa_supplicant_8_lib/Android.mk | 71 ++++ wlan/wpa_supplicant_8_lib/MODULE_LICENSE_BSD | 0 wlan/wpa_supplicant_8_lib/NOTICE | 43 ++ .../wpa_supplicant_8_lib/driver_cmd_nl80211.c | 224 ++++++++++ wlan/wpa_supplicant_8_lib/driver_cmd_wext.c | 396 ++++++++++++++++++ wlan/wpa_supplicant_8_lib/driver_cmd_wext.h | 37 ++ wlan/wpa_supplicant_8_lib/driver_nl80211.h | 251 +++++++++++ wlan/wpa_supplicant_8_lib/rtw_version.h | 4 + 18 files changed, 1104 insertions(+), 168 deletions(-) create mode 100644 wlan/Android.mk rename wlan/wifi_hal/{gscan.cpp => rtw_wifi_gscan.cpp} (99%) rename wlan/wifi_hal/{wifi_hal.cpp => rtw_wifi_hal.cpp} (99%) rename wlan/wifi_hal/{link_layer_stats.cpp => rtw_wifi_llstats.cpp} (62%) rename wlan/wifi_hal/{wifi_logger.cpp => rtw_wifi_logger.cpp} (98%) rename wlan/wifi_hal/{wifi_offload.cpp => rtw_wifi_offload.cpp} (98%) rename wlan/wifi_hal/{rtt.cpp => rtw_wifi_rtt.cpp} (99%) create mode 100644 wlan/wifi_hal/version.h create mode 100644 wlan/wpa_supplicant_8_lib/Android.mk create mode 100644 wlan/wpa_supplicant_8_lib/MODULE_LICENSE_BSD create mode 100644 wlan/wpa_supplicant_8_lib/NOTICE create mode 100644 wlan/wpa_supplicant_8_lib/driver_cmd_nl80211.c create mode 100644 wlan/wpa_supplicant_8_lib/driver_cmd_wext.c create mode 100644 wlan/wpa_supplicant_8_lib/driver_cmd_wext.h create mode 100644 wlan/wpa_supplicant_8_lib/driver_nl80211.h create mode 100644 wlan/wpa_supplicant_8_lib/rtw_version.h diff --git a/wlan/Android.mk b/wlan/Android.mk new file mode 100644 index 0000000..644f883 --- /dev/null +++ b/wlan/Android.mk @@ -0,0 +1,3 @@ +ifeq ($(BOARD_WLAN_DEVICE), realtek) + include $(call all-subdir-makefiles) +endif diff --git a/wlan/wifi_hal/Android.mk b/wlan/wifi_hal/Android.mk index fc8267e..43683c8 100644 --- a/wlan/wifi_hal/Android.mk +++ b/wlan/wifi_hal/Android.mk @@ -26,22 +26,24 @@ LOCAL_CFLAGS := \ -Wno-unused-function \ -Wno-unused-parameter \ -Wno-unused-private-field \ - -Wno-unused-variable \ + -Wno-unused-variable +# -DCONFIG_WIFI_HAL_DEBUG LOCAL_C_INCLUDES += \ external/libnl/include \ $(call include-path-for, libhardware_legacy)/hardware_legacy \ external/wpa_supplicant_8/src/drivers +LOCAL_HEADER_LIBRARIES := libutils_headers liblog_headers LOCAL_SRC_FILES := \ - wifi_hal.cpp \ - rtt.cpp \ + rtw_wifi_hal.cpp \ + rtw_wifi_rtt.cpp \ common.cpp \ cpp_bindings.cpp \ - gscan.cpp \ - link_layer_stats.cpp \ - wifi_logger.cpp \ - wifi_offload.cpp + rtw_wifi_gscan.cpp \ + rtw_wifi_llstats.cpp \ + rtw_wifi_logger.cpp \ + rtw_wifi_offload.cpp LOCAL_MODULE := libwifi-hal-rtk LOCAL_PROPRIETARY_MODULE := true diff --git a/wlan/wifi_hal/common.h b/wlan/wifi_hal/common.h index a8d60b7..27101b7 100644 --- a/wlan/wifi_hal/common.h +++ b/wlan/wifi_hal/common.h @@ -21,7 +21,7 @@ #define LOG_TAG "WifiHAL" -#include +#include #include "nl80211_copy.h" #include "sync.h" diff --git a/wlan/wifi_hal/gscan.cpp b/wlan/wifi_hal/rtw_wifi_gscan.cpp similarity index 99% rename from wlan/wifi_hal/gscan.cpp rename to wlan/wifi_hal/rtw_wifi_gscan.cpp index d33ac93..10b588a 100644 --- a/wlan/wifi_hal/gscan.cpp +++ b/wlan/wifi_hal/rtw_wifi_gscan.cpp @@ -36,7 +36,7 @@ #define LOG_TAG "WifiHAL" //#define LOG_NDEBUG 0 //uncomment to enable verbose logging -#include +#include #include "wifi_hal.h" #include "common.h" diff --git a/wlan/wifi_hal/wifi_hal.cpp b/wlan/wifi_hal/rtw_wifi_hal.cpp similarity index 99% rename from wlan/wifi_hal/wifi_hal.cpp rename to wlan/wifi_hal/rtw_wifi_hal.cpp index cfc5e23..c5d47eb 100644 --- a/wlan/wifi_hal/wifi_hal.cpp +++ b/wlan/wifi_hal/rtw_wifi_hal.cpp @@ -37,16 +37,21 @@ #include #include +#include +#include + #include "sync.h" #define LOG_TAG "WifiHAL" -#include +#include +#include "version.h" #include "wifi_hal.h" #include "common.h" #include "cpp_bindings.h" #include "rtt.h" + /* BUGBUG: normally, libnl allocates ports for all connections it makes; but being a static library, it doesn't really know how many other netlink connections @@ -209,7 +214,7 @@ wifi_error wifi_initialize(wifi_handle *handle) { srand(getpid()); - ALOGI("Initializing wifi"); + ALOGI("Initializing wifi, version : %s", RTW_WIFI_HAL_VERSION); hal_info *info = (hal_info *)malloc(sizeof(hal_info)); if (info == NULL) { ALOGE("Could not allocate hal_info"); @@ -1240,12 +1245,8 @@ wifi_error wifi_get_concurrency_matrix(wifi_interface_handle handle, int set_siz wifi_error wifi_set_scanning_mac_oui(wifi_interface_handle handle, oui scan_oui) { -#if 0 SetPnoMacAddrOuiCommand command(handle, scan_oui); return (wifi_error)command.start(); -#endif - return WIFI_SUCCESS; - } wifi_error wifi_set_nodfs_flag(wifi_interface_handle handle, u32 nodfs) @@ -1256,11 +1257,8 @@ wifi_error wifi_set_nodfs_flag(wifi_interface_handle handle, u32 nodfs) wifi_error wifi_set_country_code(wifi_interface_handle handle, const char *country_code) { -#if 0 SetCountryCodeCommand command(handle, country_code); return (wifi_error) command.requestResponse(); -#endif - return WIFI_SUCCESS ; } static wifi_error wifi_start_rssi_monitoring(wifi_request_id id, wifi_interface_handle @@ -1281,7 +1279,7 @@ static wifi_error wifi_start_rssi_monitoring(wifi_request_id id, wifi_interface_ cmd->releaseRef(); return result; } - return result; + return WIFI_ERROR_UNKNOWN; } static wifi_error wifi_stop_rssi_monitoring(wifi_request_id id, wifi_interface_handle iface) @@ -1300,7 +1298,8 @@ static wifi_error wifi_stop_rssi_monitoring(wifi_request_id id, wifi_interface_h cmd->releaseRef(); return WIFI_SUCCESS; } - return wifi_cancel_cmd(id, iface); + wifi_cancel_cmd(id, iface); + return WIFI_ERROR_UNKNOWN; } static wifi_error wifi_get_packet_filter_capabilities(wifi_interface_handle handle, @@ -1333,11 +1332,8 @@ static wifi_error wifi_set_packet_filter(wifi_interface_handle handle, static wifi_error wifi_configure_nd_offload(wifi_interface_handle handle, u8 enable) { -#if 0 SetNdoffloadCommand command(handle, enable); return (wifi_error) command.requestResponse(); -#endif - return WIFI_SUCCESS; } static wifi_error wifi_get_wake_reason_stats (wifi_interface_handle handle, @@ -1345,5 +1341,4 @@ static wifi_error wifi_get_wake_reason_stats (wifi_interface_handle handle, return WIFI_SUCCESS; } - ///////////////////////////////////////////////////////////////////////////// diff --git a/wlan/wifi_hal/link_layer_stats.cpp b/wlan/wifi_hal/rtw_wifi_llstats.cpp similarity index 62% rename from wlan/wifi_hal/link_layer_stats.cpp rename to wlan/wifi_hal/rtw_wifi_llstats.cpp index 31e43e6..93efb54 100644 --- a/wlan/wifi_hal/link_layer_stats.cpp +++ b/wlan/wifi_hal/rtw_wifi_llstats.cpp @@ -35,7 +35,7 @@ #define LOG_TAG "WifiHAL" -#include +#include #include "wifi_hal.h" #include "common.h" @@ -59,8 +59,6 @@ typedef struct { enum { LSTATS_SUBCMD_GET_INFO = ANDROID_NL80211_SUBCMD_LSTATS_RANGE_START, - LSTATS_SUBCMD_SET_INFO, - LSTATS_SUBCMD_CLEAR_INFO, }; class GetLinkStatsCommand : public WifiCommand @@ -100,19 +98,25 @@ protected: void *data = reply.get_vendor_data(); int len = reply.get_vendor_data_len(); - wifi_radio_stat *radio_stat = (wifi_radio_stat *)data; + wifi_radio_stat *radio_stat = + convertToExternalRadioStatStructure((wifi_radio_stat_internal *)data); + if (!radio_stat) { + ALOGE("Invalid stats pointer received"); + return NL_SKIP; + } + +#ifdef CONFIG_WIFI_HAL_DEBUG ALOGE("radio: = %d", radio_stat->radio); ALOGE("on_time: = %u ms", radio_stat->on_time); ALOGE("tx_time: = %u ms", radio_stat->tx_time); ALOGE("num_tx_levels: = %u", radio_stat->num_tx_levels); - radio_stat->tx_time_per_levels = (u32*)((char*)data + sizeof(wifi_radio_stat) + sizeof(wifi_iface_stat)); - ALOGE("tx_time_per_levels: = %u ms", radio_stat->tx_time_per_levels[0]); ALOGE("rx_time: = %u ms", radio_stat->rx_time); ALOGE("on_time_scan: = %u ms", radio_stat->on_time_scan); ALOGE("on_time_nbd: = %u ms", radio_stat->on_time_nbd); ALOGE("on_time_gscan: = %u ms", radio_stat->on_time_gscan); ALOGE("on_time_pno_scan: = %u ms", radio_stat->on_time_pno_scan); ALOGE("on_time_hs20: = %u ms", radio_stat->on_time_hs20); +#endif if (!radio_stat) { ALOGE("Invalid stats pointer received"); return NL_SKIP; @@ -140,92 +144,37 @@ protected: } else { (*mHandler.on_link_stats_results)(id, iface_stat, 1, radio_stat); } - //free(radio_stat); + free(radio_stat); return NL_OK; } - -}; - -class SetLinkStatsCommand : public WifiCommand -{ - wifi_stats_result_handler mHandler; -public: - SetLinkStatsCommand(wifi_interface_handle iface) - : WifiCommand("SetLinkStatsCommand", iface, 0) - { } - - virtual int create() { - // ALOGI("Creating message to get link statistics; iface = %d", mIfaceInfo->id); - - int ret = mMsg.create(GOOGLE_OUI, LSTATS_SUBCMD_SET_INFO); - if (ret < 0) { - ALOGE("Failed to create %x - %d", LSTATS_SUBCMD_SET_INFO, ret); - return ret; +private: + wifi_radio_stat *convertToExternalRadioStatStructure(wifi_radio_stat_internal *internal_stat_ptr) { + wifi_radio_stat *external_stat_ptr = NULL; + if (internal_stat_ptr) { + uint32_t channel_size = internal_stat_ptr->num_channels * sizeof(wifi_channel_stat); + uint32_t total_size = sizeof(wifi_radio_stat) + channel_size; + external_stat_ptr = (wifi_radio_stat *)malloc(total_size); + if (external_stat_ptr) { + external_stat_ptr->radio = internal_stat_ptr->radio; + external_stat_ptr->on_time = internal_stat_ptr->on_time; + external_stat_ptr->tx_time = internal_stat_ptr->tx_time; + external_stat_ptr->rx_time = internal_stat_ptr->rx_time; + external_stat_ptr->tx_time_per_levels = NULL; + external_stat_ptr->num_tx_levels = 0; + external_stat_ptr->on_time_scan = internal_stat_ptr->on_time_scan; + external_stat_ptr->on_time_nbd = internal_stat_ptr->on_time_nbd; + external_stat_ptr->on_time_gscan = internal_stat_ptr->on_time_gscan; + external_stat_ptr->on_time_roam_scan = internal_stat_ptr->on_time_roam_scan; + external_stat_ptr->on_time_pno_scan = internal_stat_ptr->on_time_pno_scan; + external_stat_ptr->on_time_hs20 = internal_stat_ptr->on_time_hs20; + external_stat_ptr->num_channels = internal_stat_ptr->num_channels; + if (internal_stat_ptr->num_channels) { + memcpy(&(external_stat_ptr->channels), &(internal_stat_ptr->channels), + channel_size); + } + } } - - return ret; - } - -protected: - virtual int handleResponse(WifiEvent& reply) { - - // ALOGI("In GetLinkStatsCommand::handleResponse"); - - if (reply.get_cmd() != NL80211_CMD_VENDOR) { - ALOGD("Ignoring reply with cmd = %d", reply.get_cmd()); - return NL_SKIP; - } - - int id = reply.get_vendor_id(); - int subcmd = reply.get_vendor_subcmd(); - - // ALOGI("Id = %0x, subcmd = %d", id, subcmd); - - void *data = reply.get_vendor_data(); - int len = reply.get_vendor_data_len(); - return NL_OK; - } - -}; - -class ClearLinkStatsCommand : public WifiCommand -{ - wifi_stats_result_handler mHandler; -public: - ClearLinkStatsCommand(wifi_interface_handle iface) - : WifiCommand("ClearLinkStatsCommand", iface, 0) - { } - - virtual int create() { - // ALOGI("Creating message to get link statistics; iface = %d", mIfaceInfo->id); - - int ret = mMsg.create(GOOGLE_OUI, LSTATS_SUBCMD_CLEAR_INFO); - if (ret < 0) { - ALOGE("Failed to create %x - %d", LSTATS_SUBCMD_CLEAR_INFO, ret); - return ret; - } - - return ret; - } - -protected: - virtual int handleResponse(WifiEvent& reply) { - - // ALOGI("In GetLinkStatsCommand::handleResponse"); - - if (reply.get_cmd() != NL80211_CMD_VENDOR) { - ALOGD("Ignoring reply with cmd = %d", reply.get_cmd()); - return NL_SKIP; - } - - int id = reply.get_vendor_id(); - int subcmd = reply.get_vendor_subcmd(); - - // ALOGI("Id = %0x, subcmd = %d", id, subcmd); - - void *data = reply.get_vendor_data(); - int len = reply.get_vendor_data_len(); - return NL_OK; + return external_stat_ptr; } }; @@ -238,19 +187,16 @@ wifi_error wifi_get_link_stats(wifi_request_id id, } wifi_error wifi_set_link_stats( - wifi_interface_handle iface, wifi_link_layer_params params) + wifi_interface_handle /* iface */, wifi_link_layer_params /* params */) { - - SetLinkStatsCommand command(iface); - return (wifi_error) command.requestResponse(); - //return WIFI_SUCCESS; + /* Return success here since bcom HAL does not need set link stats. */ + return WIFI_SUCCESS; } -wifi_error wifi_clear_link_stats(wifi_interface_handle iface, - u32 stats_clear_req_mask, u32 *stats_clear_rsp_mask, u8 stop_req, u8 *stop_rsp) +wifi_error wifi_clear_link_stats( + wifi_interface_handle /* iface */, u32 /* stats_clear_req_mask */, + u32 * /* stats_clear_rsp_mask */, u8 /* stop_req */, u8 * /* stop_rsp */) { - - ClearLinkStatsCommand command(iface); - return (wifi_error) command.requestResponse(); - //return WIFI_SUCCESS; + /* Return success here since bcom HAL does not support clear link stats. */ + return WIFI_SUCCESS; } diff --git a/wlan/wifi_hal/wifi_logger.cpp b/wlan/wifi_hal/rtw_wifi_logger.cpp similarity index 98% rename from wlan/wifi_hal/wifi_logger.cpp rename to wlan/wifi_hal/rtw_wifi_logger.cpp index d53a010..2e214dd 100644 --- a/wlan/wifi_hal/wifi_logger.cpp +++ b/wlan/wifi_hal/rtw_wifi_logger.cpp @@ -400,7 +400,6 @@ public: wifi_error wifi_get_firmware_version(wifi_interface_handle iface, char *buffer, int buffer_size) { -#if 0 if (buffer && (buffer_size > 0)) { DebugCommand *cmd = new DebugCommand(iface, buffer, &buffer_size, GET_FW_VER); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); @@ -411,16 +410,11 @@ wifi_error wifi_get_firmware_version(wifi_interface_handle iface, char *buffer, ALOGE("FW version buffer NULL"); return WIFI_ERROR_INVALID_ARGS; } -#endif - std::string pFirmwareVer = "RTK_FIRMWARE"; - memcpy(buffer, pFirmwareVer.c_str(), pFirmwareVer.length()+1); - return WIFI_SUCCESS; } /* API to collect a driver version string */ wifi_error wifi_get_driver_version(wifi_interface_handle iface, char *buffer, int buffer_size) { -#if 0 if (buffer && (buffer_size > 0)) { DebugCommand *cmd = new DebugCommand(iface, buffer, &buffer_size, GET_DRV_VER); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); @@ -431,30 +425,22 @@ wifi_error wifi_get_driver_version(wifi_interface_handle iface, char *buffer, in ALOGE("Driver version buffer NULL"); return WIFI_ERROR_INVALID_ARGS; } -#endif - std::string pDriverVer = "RTK_DRIVER"; - memcpy(buffer, pDriverVer.c_str(), pDriverVer.length()+1); - return WIFI_SUCCESS; } /* API to collect driver records */ wifi_error wifi_get_ring_data(wifi_interface_handle iface, char *ring_name) { -#if 0 DebugCommand *cmd = new DebugCommand(iface, ring_name, GET_RING_DATA); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); wifi_error result = (wifi_error)cmd->start(); cmd->releaseRef(); return result; -#endif - return WIFI_SUCCESS; } /* API to get the status of all ring buffers supported by driver */ wifi_error wifi_get_ring_buffers_status(wifi_interface_handle iface, u32 *num_rings, wifi_ring_buffer_status *status) { -#if 0 if (status && num_rings) { DebugCommand *cmd = new DebugCommand(iface, num_rings, status, GET_RING_STATUS); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); @@ -465,13 +451,6 @@ wifi_error wifi_get_ring_buffers_status(wifi_interface_handle iface, ALOGE("Ring status buffer NULL"); return WIFI_ERROR_INVALID_ARGS; } -#endif - wifi_ring_buffer_status* pLocalstatus = NULL; - std::string from = "RTK_RING"; - memcpy(status->name, from.c_str(), strlen(from.c_str())+1); - *num_rings = 1; - - return WIFI_SUCCESS; } /* API to get supportable feature */ @@ -479,15 +458,10 @@ wifi_error wifi_get_logger_supported_feature_set(wifi_interface_handle iface, unsigned int *support) { if (support) { - wifi_error result = WIFI_SUCCESS; - #if 0 DebugCommand *cmd = new DebugCommand(iface, support, GET_FEATURE); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); wifi_error result = (wifi_error)cmd->start(); cmd->releaseRef(); - #endif - *support = WIFI_LOGGER_MEMORY_DUMP_SUPPORTED; - return result; } else { ALOGE("Get support buffer NULL"); @@ -498,7 +472,6 @@ wifi_error wifi_get_logger_supported_feature_set(wifi_interface_handle iface, wifi_error wifi_start_logging(wifi_interface_handle iface, u32 verbose_level, u32 flags, u32 max_interval_sec, u32 min_data_size, char *ring_name) { -#if 0 if (ring_name) { DebugCommand *cmd = new DebugCommand(iface, verbose_level, flags, max_interval_sec, min_data_size, ring_name, START_RING_LOG); @@ -510,8 +483,6 @@ wifi_error wifi_start_logging(wifi_interface_handle iface, u32 verbose_level, ALOGE("Ring name NULL"); return WIFI_ERROR_INVALID_ARGS; } -#endif - return WIFI_SUCCESS; } @@ -933,14 +904,11 @@ public: wifi_error wifi_get_firmware_memory_dump( wifi_interface_handle iface, wifi_firmware_memory_dump_handler handler) { -#if 0 MemoryDumpCommand *cmd = new MemoryDumpCommand(iface, handler); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); wifi_error result = (wifi_error)cmd->start(); cmd->releaseRef(); return result; -#endif - return WIFI_SUCCESS; } class PacketFateCommand: public WifiCommand @@ -1107,42 +1075,33 @@ public: wifi_error wifi_start_pkt_fate_monitoring(wifi_interface_handle handle) { -#if 0 PacketFateCommand *cmd = new PacketFateCommand(handle); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); wifi_error result = (wifi_error)cmd->start(); cmd->releaseRef(); return result; -#endif - return WIFI_SUCCESS; } wifi_error wifi_get_tx_pkt_fates(wifi_interface_handle handle, wifi_tx_report *tx_report_bufs, size_t n_requested_fates, size_t *n_provided_fates) { -#if 0 PacketFateCommand *cmd = new PacketFateCommand(handle, tx_report_bufs, n_requested_fates, n_provided_fates); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); wifi_error result = (wifi_error)cmd->start(); cmd->releaseRef(); return result; -#endif - return WIFI_SUCCESS; } wifi_error wifi_get_rx_pkt_fates(wifi_interface_handle handle, wifi_rx_report *rx_report_bufs, size_t n_requested_fates, size_t *n_provided_fates) { -#if 0 PacketFateCommand *cmd = new PacketFateCommand(handle, rx_report_bufs, n_requested_fates, n_provided_fates); NULL_CHECK_RETURN(cmd, "memory allocation failure", WIFI_ERROR_OUT_OF_MEMORY); wifi_error result = (wifi_error)cmd->start(); cmd->releaseRef(); return result; -#endif - return WIFI_SUCCESS; } diff --git a/wlan/wifi_hal/wifi_offload.cpp b/wlan/wifi_hal/rtw_wifi_offload.cpp similarity index 98% rename from wlan/wifi_hal/wifi_offload.cpp rename to wlan/wifi_hal/rtw_wifi_offload.cpp index 397b792..51720c6 100644 --- a/wlan/wifi_hal/wifi_offload.cpp +++ b/wlan/wifi_hal/rtw_wifi_offload.cpp @@ -211,10 +211,9 @@ public: } }; - /* API to send specified mkeep_alive packet periodically. */ wifi_error wifi_start_sending_offloaded_packet(wifi_request_id index, wifi_interface_handle iface, - u8 *ip_packet, u16 ip_packet_len, u8 *src_mac_addr, u8 *dst_mac_addr, u32 period_msec) + u16 /* ether_type */, u8 *ip_packet, u16 ip_packet_len, u8 *src_mac_addr, u8 *dst_mac_addr, u32 period_msec) { if ((index > 0 && index <= N_AVAIL_ID) && (ip_packet != NULL) && (src_mac_addr != NULL) && (dst_mac_addr != NULL) && (period_msec > 0) diff --git a/wlan/wifi_hal/rtt.cpp b/wlan/wifi_hal/rtw_wifi_rtt.cpp similarity index 99% rename from wlan/wifi_hal/rtt.cpp rename to wlan/wifi_hal/rtw_wifi_rtt.cpp index 048f339..813be0e 100644 --- a/wlan/wifi_hal/rtt.cpp +++ b/wlan/wifi_hal/rtw_wifi_rtt.cpp @@ -38,7 +38,7 @@ #define LOG_TAG "WifiHAL" -#include +#include #include #include "wifi_hal.h" diff --git a/wlan/wifi_hal/version.h b/wlan/wifi_hal/version.h new file mode 100644 index 0000000..ad2e795 --- /dev/null +++ b/wlan/wifi_hal/version.h @@ -0,0 +1,6 @@ +#ifndef VERSION_H +#define VERSION_H + +#define RTW_WIFI_HAL_VERSION "v1.0.3" + +#endif /* VERSION_H */ diff --git a/wlan/wpa_supplicant_8_lib/Android.mk b/wlan/wpa_supplicant_8_lib/Android.mk new file mode 100644 index 0000000..09d862c --- /dev/null +++ b/wlan/wpa_supplicant_8_lib/Android.mk @@ -0,0 +1,71 @@ +# +# Copyright (C) 2008 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +LOCAL_PATH := $(call my-dir) + +ifeq ($(WPA_SUPPLICANT_VERSION),VER_0_8_X) + +ifneq ($(BOARD_WPA_SUPPLICANT_DRIVER),) + CONFIG_DRIVER_$(BOARD_WPA_SUPPLICANT_DRIVER) := y +endif + +WPA_SUPPL_DIR = external/wpa_supplicant_8 +WPA_SRC_FILE := + +include $(WPA_SUPPL_DIR)/wpa_supplicant/android.config + +WPA_SUPPL_DIR_INCLUDE = $(WPA_SUPPL_DIR)/src \ + $(WPA_SUPPL_DIR)/src/common \ + $(WPA_SUPPL_DIR)/src/drivers \ + $(WPA_SUPPL_DIR)/src/l2_packet \ + $(WPA_SUPPL_DIR)/src/utils \ + $(WPA_SUPPL_DIR)/src/wps \ + $(WPA_SUPPL_DIR)/wpa_supplicant + +ifdef CONFIG_DRIVER_NL80211 +WPA_SUPPL_DIR_INCLUDE += external/libnl/include +WPA_SRC_FILE += driver_cmd_nl80211.c +endif + +ifdef CONFIG_DRIVER_WEXT +WPA_SRC_FILE += driver_cmd_wext.c +endif + +ifeq ($(TARGET_ARCH),arm) +# To force sizeof(enum) = 4 +L_CFLAGS += -mabi=aapcs-linux +endif + +ifdef CONFIG_ANDROID_LOG +L_CFLAGS += -DCONFIG_ANDROID_LOG +endif + +ifdef CONFIG_P2P +L_CFLAGS += -DCONFIG_P2P +endif +######################## + +include $(CLEAR_VARS) +LOCAL_MODULE := lib_driver_cmd_rtl +LOCAL_SHARED_LIBRARIES := libc libcutils +LOCAL_CFLAGS := $(L_CFLAGS) +LOCAL_SRC_FILES := $(WPA_SRC_FILE) +LOCAL_C_INCLUDES := $(WPA_SUPPL_DIR_INCLUDE) +LOCAL_VENDOR_MODULE := true +include $(BUILD_STATIC_LIBRARY) + +######################## + +endif diff --git a/wlan/wpa_supplicant_8_lib/MODULE_LICENSE_BSD b/wlan/wpa_supplicant_8_lib/MODULE_LICENSE_BSD new file mode 100644 index 0000000..e69de29 diff --git a/wlan/wpa_supplicant_8_lib/NOTICE b/wlan/wpa_supplicant_8_lib/NOTICE new file mode 100644 index 0000000..f9d25ea --- /dev/null +++ b/wlan/wpa_supplicant_8_lib/NOTICE @@ -0,0 +1,43 @@ + +Copyright (c) 2005-2010, The Android Open Source Project +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + * Neither the name of The Android Open Source Project nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. + + * Copyright (c) 2002-2010, Jouni Malinen + * Copyright (c) 2003-2004, Instant802 Networks, Inc. + * Copyright (c) 2005-2006, Devicescape Software, Inc. + * Copyright (c) 2007, Johannes Berg + * Copyright (c) 2009-2010, Atheros Communications + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Alternatively, this software may be distributed under the terms of BSD + * license. diff --git a/wlan/wpa_supplicant_8_lib/driver_cmd_nl80211.c b/wlan/wpa_supplicant_8_lib/driver_cmd_nl80211.c new file mode 100644 index 0000000..c0fa3bc --- /dev/null +++ b/wlan/wpa_supplicant_8_lib/driver_cmd_nl80211.c @@ -0,0 +1,224 @@ +/* + * Driver interaction with extended Linux CFG8021 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Alternatively, this software may be distributed under the terms of BSD + * license. + * + */ + +#include "includes.h" +#include +#include +#include + +#include "common.h" +#include "linux_ioctl.h" +#include "driver_nl80211.h" +#include "rtw_version.h" +#ifdef PURE_LINUX +#ifndef SIOCDEVPRIVATE +#define SIOCDEVPRIVATE 0x89F0 /* to 89FF */ +#endif +#ifndef __unused +#if __GNUC_PREREQ(2, 95) || defined(__INTEL_COMPILER) +#define __unused __attribute__((__unused__)) +#else +#define __unused +#endif +#endif +#endif /* PURE_LINUX */ +#include "wpa_supplicant_i.h" +#include "config.h" +#ifdef ANDROID +#include "android_drv.h" +#endif + +typedef struct android_wifi_priv_cmd { + char *bufaddr; + int used_len; + int total_len; +} android_wifi_priv_cmd; + +static int drv_errors = 0; + +static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data *drv) +{ + drv_errors++; + if (drv_errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { + drv_errors = 0; + wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); + } +} + +static void wpa_driver_notify_country_change(void *ctx, char *cmd) +{ + if ((os_strncasecmp(cmd, "COUNTRY", 7) == 0) || + (os_strncasecmp(cmd, "SETBAND", 7) == 0)) { + union wpa_event_data event; + + os_memset(&event, 0, sizeof(event)); + event.channel_list_changed.initiator = REGDOM_SET_BY_USER; + if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) { + event.channel_list_changed.type = REGDOM_TYPE_COUNTRY; + if (os_strlen(cmd) > 9) { + event.channel_list_changed.alpha2[0] = cmd[8]; + event.channel_list_changed.alpha2[1] = cmd[9]; + } + } else { + event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN; + } + wpa_supplicant_event(ctx, EVENT_CHANNEL_LIST_CHANGED, &event); + } +} + +int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf, + size_t buf_len ) +{ + struct i802_bss *bss = priv; + struct wpa_driver_nl80211_data *drv = bss->drv; + struct ifreq ifr; + android_wifi_priv_cmd priv_cmd; + int ret = 0; + + if (bss->ifindex <= 0 && bss->wdev_id > 0) { + /* DRIVER CMD received on the DEDICATED P2P Interface which doesn't + * have an NETDEVICE associated with it. So we have to re-route the + * command to the parent NETDEVICE + */ + struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)(drv->ctx); + + wpa_printf(MSG_DEBUG, "Re-routing DRIVER cmd to parent iface"); + if (wpa_s && wpa_s->parent) { + /* Update the nl80211 pointers corresponding to parent iface */ + bss = wpa_s->parent->drv_priv; + drv = bss->drv; + wpa_printf(MSG_DEBUG, "Re-routing command to iface: %s" + " cmd (%s)", bss->ifname, cmd); + } + } + + if (os_strcasecmp(cmd, "STOP") == 0) { + linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0); + wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STOPPED"); + } else if (os_strcasecmp(cmd, "START") == 0) { + linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); + wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STARTED"); + } else if (os_strcasecmp(cmd, "lib_version") == 0) { + wpa_msg(drv->ctx, MSG_INFO, RTW_VERSION); + } else if (os_strcasecmp(cmd, "P2P_DISABLE") == 0) { + os_memcpy(buf, "P2P_DISABLE", 12); + wpa_printf(MSG_DEBUG, "P2P_DISABLE"); + } else if (os_strcasecmp(cmd, "MACADDR") == 0) { + u8 macaddr[ETH_ALEN] = {}; + + ret = linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, macaddr); + if (!ret) + ret = os_snprintf(buf, buf_len, + "Macaddr = " MACSTR "\n", MAC2STR(macaddr)); + } else { /* Use private command */ + os_memcpy(buf, cmd, strlen(cmd) + 1); + memset(&ifr, 0, sizeof(ifr)); + memset(&priv_cmd, 0, sizeof(priv_cmd)); + os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ); + priv_cmd.bufaddr = buf; + priv_cmd.used_len = buf_len; + priv_cmd.total_len = buf_len; + ifr.ifr_data = (void *)&priv_cmd; + + if ((ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr)) < 0) { + wpa_printf(MSG_ERROR, "%s: failed to issue private command: %s", __func__, cmd); + wpa_driver_send_hang_msg(drv); + } else { + drv_errors = 0; + ret = 0; + if ((os_strcasecmp(cmd, "LINKSPEED") == 0) || + (os_strcasecmp(cmd, "RSSI") == 0) || + (os_strcasecmp(cmd, "GETBAND") == 0) || + (os_strncasecmp(cmd, "WLS_BATCHING", 12) == 0)) + ret = strlen(buf); + wpa_driver_notify_country_change(drv->ctx, cmd); + wpa_printf(MSG_DEBUG, "%s %s len = %d, %zu", __func__, buf, ret, strlen(buf)); + } + } + return ret; +} + +int wpa_driver_set_p2p_noa(void *priv, u8 count, int start, int duration) +{ + char buf[MAX_DRV_CMD_SIZE]; + + memset(buf, 0, sizeof(buf)); + wpa_printf(MSG_DEBUG, "%s: Entry", __func__); + snprintf(buf, sizeof(buf), "P2P_SET_NOA %d %d %d", count, start, duration); + return wpa_driver_nl80211_driver_cmd(priv, buf, buf, strlen(buf)+1); +} + +int wpa_driver_get_p2p_noa(void *priv __unused, u8 *buf __unused, size_t len __unused) +{ + /* Return 0 till we handle p2p_presence request completely in the driver */ + return 0; +} + +int wpa_driver_set_p2p_ps(void *priv, int legacy_ps, int opp_ps, int ctwindow) +{ + char buf[MAX_DRV_CMD_SIZE]; + + memset(buf, 0, sizeof(buf)); + wpa_printf(MSG_DEBUG, "%s: Entry", __func__); + snprintf(buf, sizeof(buf), "P2P_SET_PS %d %d %d", legacy_ps, opp_ps, ctwindow); + return wpa_driver_nl80211_driver_cmd(priv, buf, buf, strlen(buf) + 1); +} + +int wpa_driver_set_ap_wps_p2p_ie(void *priv, const struct wpabuf *beacon, + const struct wpabuf *proberesp, + const struct wpabuf *assocresp) +{ + char *buf; + const struct wpabuf *ap_wps_p2p_ie = NULL; + + char *_cmd = "SET_AP_WPS_P2P_IE"; + char *pbuf; + int ret = 0; + int i, buf_len; + struct cmd_desc { + int cmd; + const struct wpabuf *src; + } cmd_arr[] = { + {0x1, beacon}, + {0x2, proberesp}, + {0x4, assocresp}, + {-1, NULL} + }; + + wpa_printf(MSG_DEBUG, "%s: Entry", __func__); + for (i = 0; cmd_arr[i].cmd != -1; i++) { + ap_wps_p2p_ie = cmd_arr[i].src; + if (ap_wps_p2p_ie) { + buf_len = strlen(_cmd) + 3 + wpabuf_len(ap_wps_p2p_ie); + buf = os_zalloc(buf_len); + if (NULL == buf) { + wpa_printf(MSG_ERROR, "%s: Out of memory", + __func__); + ret = -1; + break; + } + } else { + continue; + } + pbuf = buf; + pbuf += snprintf(pbuf, buf_len - wpabuf_len(ap_wps_p2p_ie), + "%s %d",_cmd, cmd_arr[i].cmd); + *pbuf++ = '\0'; + os_memcpy(pbuf, wpabuf_head(ap_wps_p2p_ie), wpabuf_len(ap_wps_p2p_ie)); + ret = wpa_driver_nl80211_driver_cmd(priv, buf, buf, buf_len); + os_free(buf); + if (ret < 0) + break; + } + + return ret; +} diff --git a/wlan/wpa_supplicant_8_lib/driver_cmd_wext.c b/wlan/wpa_supplicant_8_lib/driver_cmd_wext.c new file mode 100644 index 0000000..3734cb0 --- /dev/null +++ b/wlan/wpa_supplicant_8_lib/driver_cmd_wext.c @@ -0,0 +1,396 @@ +/* + * Driver interaction with extended Linux Wireless Extensions + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Alternatively, this software may be distributed under the terms of BSD + * license. + * + */ + +#include "includes.h" +#include +#include +#include + +#include "linux_wext.h" +#include "common.h" +#include "driver.h" +#include "eloop.h" +#include "priv_netlink.h" +#include "driver_wext.h" +#include "ieee802_11_defs.h" +#include "wpa_common.h" +#include "wpa_ctrl.h" +#include "wpa_supplicant_i.h" +#include "config.h" +#include "linux_ioctl.h" +#include "scan.h" + +#include "driver_cmd_wext.h" +#ifdef ANDROID +#include "android_drv.h" +#endif /* ANDROID */ + +#define RSSI_CMD "RSSI" +#define LINKSPEED_CMD "LINKSPEED" + +/** + * wpa_driver_wext_set_scan_timeout - Set scan timeout to report scan completion + * @priv: Pointer to private wext data from wpa_driver_wext_init() + * + * This function can be used to set registered timeout when starting a scan to + * generate a scan completed event if the driver does not report this. + */ +static void wpa_driver_wext_set_scan_timeout(void *priv) +{ + struct wpa_driver_wext_data *drv = priv; + int timeout = 10; /* In case scan A and B bands it can be long */ + + /* Not all drivers generate "scan completed" wireless event, so try to + * read results after a timeout. */ + if (drv->scan_complete_events) { + /* + * The driver seems to deliver SIOCGIWSCAN events to notify + * when scan is complete, so use longer timeout to avoid race + * conditions with scanning and following association request. + */ + timeout = 30; + } + wpa_printf(MSG_DEBUG, "Scan requested - scan timeout %d seconds", + timeout); + eloop_cancel_timeout(wpa_driver_wext_scan_timeout, drv, drv->ctx); + eloop_register_timeout(timeout, 0, wpa_driver_wext_scan_timeout, drv, + drv->ctx); +} + +/** + * wpa_driver_wext_combo_scan - Request the driver to initiate combo scan + * @priv: Pointer to private wext data from wpa_driver_wext_init() + * @params: Scan parameters + * Returns: 0 on success, -1 on failure + */ +int wpa_driver_wext_combo_scan(void *priv, struct wpa_driver_scan_params *params) +{ + char buf[WEXT_CSCAN_BUF_LEN]; + struct wpa_driver_wext_data *drv = priv; + struct iwreq iwr; + int ret, bp; + unsigned i; + + if (!drv->driver_is_started) { + wpa_printf(MSG_DEBUG, "%s: Driver stopped", __func__); + return 0; + } + + wpa_printf(MSG_DEBUG, "%s: Start", __func__); + + /* Set list of SSIDs */ + bp = WEXT_CSCAN_HEADER_SIZE; + os_memcpy(buf, WEXT_CSCAN_HEADER, bp); + for(i=0; i < params->num_ssids; i++) { + if ((bp + IW_ESSID_MAX_SIZE + 10) >= (int)sizeof(buf)) + break; + wpa_printf(MSG_DEBUG, "For Scan: %s", params->ssids[i].ssid); + buf[bp++] = WEXT_CSCAN_SSID_SECTION; + buf[bp++] = params->ssids[i].ssid_len; + os_memcpy(&buf[bp], params->ssids[i].ssid, params->ssids[i].ssid_len); + bp += params->ssids[i].ssid_len; + } + + /* Set list of channels */ + buf[bp++] = WEXT_CSCAN_CHANNEL_SECTION; + buf[bp++] = 0; + + /* Set passive dwell time (default is 250) */ + buf[bp++] = WEXT_CSCAN_PASV_DWELL_SECTION; + buf[bp++] = (u8)WEXT_CSCAN_PASV_DWELL_TIME; + buf[bp++] = (u8)(WEXT_CSCAN_PASV_DWELL_TIME >> 8); + + /* Set home dwell time (default is 40) */ + buf[bp++] = WEXT_CSCAN_HOME_DWELL_SECTION; + buf[bp++] = (u8)WEXT_CSCAN_HOME_DWELL_TIME; + buf[bp++] = (u8)(WEXT_CSCAN_HOME_DWELL_TIME >> 8); + + os_memset(&iwr, 0, sizeof(iwr)); + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ); + iwr.u.data.pointer = buf; + iwr.u.data.length = bp; + + if ((ret = ioctl(drv->ioctl_sock, SIOCSIWPRIV, &iwr)) < 0) { + if (!drv->bgscan_enabled) + wpa_printf(MSG_ERROR, "ioctl[SIOCSIWPRIV] (cscan): %d", ret); + else + ret = 0; /* Hide error in case of bg scan */ + } + return ret; +} + +static int wpa_driver_wext_set_cscan_params(char *buf, size_t buf_len, char *cmd) +{ + char *pasv_ptr; + int bp, i; + u16 pasv_dwell = WEXT_CSCAN_PASV_DWELL_TIME_DEF; + u8 channel; + + wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd); + + /* Get command parameters */ + pasv_ptr = os_strstr(cmd, ",TIME="); + if (pasv_ptr) { + *pasv_ptr = '\0'; + pasv_ptr += 6; + pasv_dwell = (u16)atoi(pasv_ptr); + if (pasv_dwell == 0) + pasv_dwell = WEXT_CSCAN_PASV_DWELL_TIME_DEF; + } + channel = (u8)atoi(cmd + 5); + + bp = WEXT_CSCAN_HEADER_SIZE; + os_memcpy(buf, WEXT_CSCAN_HEADER, bp); + + /* Set list of channels */ + buf[bp++] = WEXT_CSCAN_CHANNEL_SECTION; + buf[bp++] = channel; + if (channel != 0) { + i = (pasv_dwell - 1) / WEXT_CSCAN_PASV_DWELL_TIME_DEF; + for (; i > 0; i--) { + if ((size_t)(bp + 12) >= buf_len) + break; + buf[bp++] = WEXT_CSCAN_CHANNEL_SECTION; + buf[bp++] = channel; + } + } else { + if (pasv_dwell > WEXT_CSCAN_PASV_DWELL_TIME_MAX) + pasv_dwell = WEXT_CSCAN_PASV_DWELL_TIME_MAX; + } + + /* Set passive dwell time (default is 250) */ + buf[bp++] = WEXT_CSCAN_PASV_DWELL_SECTION; + if (channel != 0) { + buf[bp++] = (u8)WEXT_CSCAN_PASV_DWELL_TIME_DEF; + buf[bp++] = (u8)(WEXT_CSCAN_PASV_DWELL_TIME_DEF >> 8); + } else { + buf[bp++] = (u8)pasv_dwell; + buf[bp++] = (u8)(pasv_dwell >> 8); + } + + /* Set home dwell time (default is 40) */ + buf[bp++] = WEXT_CSCAN_HOME_DWELL_SECTION; + buf[bp++] = (u8)WEXT_CSCAN_HOME_DWELL_TIME; + buf[bp++] = (u8)(WEXT_CSCAN_HOME_DWELL_TIME >> 8); + + /* Set cscan type */ + buf[bp++] = WEXT_CSCAN_TYPE_SECTION; + buf[bp++] = WEXT_CSCAN_TYPE_PASSIVE; + return bp; +} + +static char *wpa_driver_get_country_code(int channels) +{ + char *country = "US"; /* WEXT_NUMBER_SCAN_CHANNELS_FCC */ + + if (channels == WEXT_NUMBER_SCAN_CHANNELS_ETSI) + country = "EU"; + else if( channels == WEXT_NUMBER_SCAN_CHANNELS_MKK1) + country = "JP"; + return country; +} + +static int wpa_driver_set_backgroundscan_params(void *priv) +{ + struct wpa_driver_wext_data *drv = priv; + struct wpa_supplicant *wpa_s; + struct iwreq iwr; + int ret = 0, i = 0, bp; + char buf[WEXT_PNO_MAX_COMMAND_SIZE]; + struct wpa_ssid *ssid_conf; + + if (drv == NULL) { + wpa_printf(MSG_ERROR, "%s: drv is NULL. Exiting", __func__); + return -1; + } + if (drv->ctx == NULL) { + wpa_printf(MSG_ERROR, "%s: drv->ctx is NULL. Exiting", __func__); + return -1; + } + wpa_s = (struct wpa_supplicant *)(drv->ctx); + if (wpa_s->conf == NULL) { + wpa_printf(MSG_ERROR, "%s: wpa_s->conf is NULL. Exiting", __func__); + return -1; + } + ssid_conf = wpa_s->conf->ssid; + + bp = WEXT_PNOSETUP_HEADER_SIZE; + os_memcpy(buf, WEXT_PNOSETUP_HEADER, bp); + buf[bp++] = WEXT_PNO_TLV_PREFIX; + buf[bp++] = WEXT_PNO_TLV_VERSION; + buf[bp++] = WEXT_PNO_TLV_SUBVERSION; + buf[bp++] = WEXT_PNO_TLV_RESERVED; + + while ((i < WEXT_PNO_AMOUNT) && (ssid_conf != NULL)) { + /* Check that there is enough space needed for 1 more SSID, the other sections and null termination */ + if ((bp + WEXT_PNO_SSID_HEADER_SIZE + IW_ESSID_MAX_SIZE + WEXT_PNO_NONSSID_SECTIONS_SIZE + 1) >= (int)sizeof(buf)) + break; + if ((!ssid_conf->disabled) && (ssid_conf->ssid_len <= IW_ESSID_MAX_SIZE)){ + wpa_printf(MSG_DEBUG, "For PNO Scan: %s", ssid_conf->ssid); + buf[bp++] = WEXT_PNO_SSID_SECTION; + buf[bp++] = ssid_conf->ssid_len; + os_memcpy(&buf[bp], ssid_conf->ssid, ssid_conf->ssid_len); + bp += ssid_conf->ssid_len; + i++; + } + ssid_conf = ssid_conf->next; + } + + buf[bp++] = WEXT_PNO_SCAN_INTERVAL_SECTION; + os_snprintf(&buf[bp], WEXT_PNO_SCAN_INTERVAL_LENGTH + 1, "%x", WEXT_PNO_SCAN_INTERVAL); + bp += WEXT_PNO_SCAN_INTERVAL_LENGTH; + + buf[bp++] = WEXT_PNO_REPEAT_SECTION; + os_snprintf(&buf[bp], WEXT_PNO_REPEAT_LENGTH + 1, "%x", WEXT_PNO_REPEAT); + bp += WEXT_PNO_REPEAT_LENGTH; + + buf[bp++] = WEXT_PNO_MAX_REPEAT_SECTION; + os_snprintf(&buf[bp], WEXT_PNO_MAX_REPEAT_LENGTH + 1, "%x", WEXT_PNO_MAX_REPEAT); + bp += WEXT_PNO_MAX_REPEAT_LENGTH + 1; + + os_memset(&iwr, 0, sizeof(iwr)); + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ); + iwr.u.data.pointer = buf; + iwr.u.data.length = bp; + + ret = ioctl(drv->ioctl_sock, SIOCSIWPRIV, &iwr); + + if (ret < 0) { + wpa_printf(MSG_ERROR, "ioctl[SIOCSIWPRIV] (pnosetup): %d", ret); + drv->errors++; + if (drv->errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { + drv->errors = 0; + wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); + } + } else { + drv->errors = 0; + } + return ret; + +} + +int wpa_driver_wext_driver_cmd( void *priv, char *cmd, char *buf, size_t buf_len ) +{ + struct wpa_driver_wext_data *drv = priv; + struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)(drv->ctx); + struct iwreq iwr; + int ret = 0, flags; + + wpa_printf(MSG_DEBUG, "%s %s len = %d", __func__, cmd, buf_len); + + if (!drv->driver_is_started && (os_strcasecmp(cmd, "START") != 0)) { + wpa_printf(MSG_ERROR,"WEXT: Driver not initialized yet"); + return -1; + } + + if (os_strcasecmp(cmd, "RSSI-APPROX") == 0) { + os_strlcpy(cmd, RSSI_CMD, MAX_DRV_CMD_SIZE); + } else if( os_strncasecmp(cmd, "SCAN-CHANNELS", 13) == 0 ) { + int no_of_chan; + + no_of_chan = atoi(cmd + 13); + os_snprintf(cmd, MAX_DRV_CMD_SIZE, "COUNTRY %s", + wpa_driver_get_country_code(no_of_chan)); + } else if (os_strcasecmp(cmd, "STOP") == 0) { + linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0); + } else if( os_strcasecmp(cmd, "RELOAD") == 0 ) { + wpa_printf(MSG_DEBUG,"Reload command"); + wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); + return ret; + } else if( os_strcasecmp(cmd, "BGSCAN-START") == 0 ) { + ret = wpa_driver_set_backgroundscan_params(priv); + if (ret < 0) { + return ret; + } + os_strlcpy(cmd, "PNOFORCE 1", MAX_DRV_CMD_SIZE); + drv->bgscan_enabled = 1; + } else if( os_strcasecmp(cmd, "BGSCAN-STOP") == 0 ) { + os_strlcpy(cmd, "PNOFORCE 0", MAX_DRV_CMD_SIZE); + drv->bgscan_enabled = 0; + } + + os_memset(&iwr, 0, sizeof(iwr)); + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ); + os_memcpy(buf, cmd, strlen(cmd) + 1); + iwr.u.data.pointer = buf; + iwr.u.data.length = buf_len; + + if( os_strncasecmp(cmd, "CSCAN", 5) == 0 ) { + if (!wpa_s->scanning && ((wpa_s->wpa_state <= WPA_SCANNING) || + (wpa_s->wpa_state >= WPA_COMPLETED))) { + iwr.u.data.length = wpa_driver_wext_set_cscan_params(buf, buf_len, cmd); + } else { + wpa_printf(MSG_ERROR, "Ongoing Scan action..."); + return ret; + } + } + + ret = ioctl(drv->ioctl_sock, SIOCSIWPRIV, &iwr); + + if (ret < 0) { + wpa_printf(MSG_ERROR, "%s failed (%d): %s", __func__, ret, cmd); + drv->errors++; + if (drv->errors > DRV_NUMBER_SEQUENTIAL_ERRORS) { + drv->errors = 0; + wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED"); + } + } else { + drv->errors = 0; + ret = 0; + if ((os_strcasecmp(cmd, RSSI_CMD) == 0) || + (os_strcasecmp(cmd, LINKSPEED_CMD) == 0) || + (os_strcasecmp(cmd, "MACADDR") == 0) || + (os_strcasecmp(cmd, "GETPOWER") == 0) || + (os_strcasecmp(cmd, "GETBAND") == 0)) { + ret = strlen(buf); + } else if (os_strcasecmp(cmd, "START") == 0) { + drv->driver_is_started = TRUE; + linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1); + /* os_sleep(0, WPA_DRIVER_WEXT_WAIT_US); + wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STARTED"); */ + } else if (os_strcasecmp(cmd, "STOP") == 0) { + drv->driver_is_started = FALSE; + /* wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STOPPED"); */ + } else if (os_strncasecmp(cmd, "CSCAN", 5) == 0) { + wpa_driver_wext_set_scan_timeout(priv); + wpa_supplicant_notify_scanning(wpa_s, 1); + } + wpa_printf(MSG_DEBUG, "%s %s len = %d, %d", __func__, buf, ret, strlen(buf)); + } + return ret; +} + +int wpa_driver_signal_poll(void *priv, struct wpa_signal_info *si) +{ + char buf[MAX_DRV_CMD_SIZE]; + struct wpa_driver_wext_data *drv = priv; + char *prssi; + int res; + + os_memset(si, 0, sizeof(*si)); + res = wpa_driver_wext_driver_cmd(priv, RSSI_CMD, buf, sizeof(buf)); + /* Answer: SSID rssi -Val */ + if (res < 0) + return res; + prssi = strcasestr(buf, RSSI_CMD); + if (!prssi) + return -1; + si->current_signal = atoi(prssi + strlen(RSSI_CMD) + 1); + + res = wpa_driver_wext_driver_cmd(priv, LINKSPEED_CMD, buf, sizeof(buf)); + /* Answer: LinkSpeed Val */ + if (res < 0) + return res; + si->current_txrate = atoi(buf + strlen(LINKSPEED_CMD) + 1) * 1000; + + return 0; +} diff --git a/wlan/wpa_supplicant_8_lib/driver_cmd_wext.h b/wlan/wpa_supplicant_8_lib/driver_cmd_wext.h new file mode 100644 index 0000000..56d54fc --- /dev/null +++ b/wlan/wpa_supplicant_8_lib/driver_cmd_wext.h @@ -0,0 +1,37 @@ +/* + * Driver interaction with extended Linux Wireless Extensions + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Alternatively, this software may be distributed under the terms of BSD + * license. + * + */ +#ifndef DRIVER_CMD_WEXT_H +#define DRIVER_CMD_WEXT_H + +#define WEXT_NUMBER_SCAN_CHANNELS_FCC 11 +#define WEXT_NUMBER_SCAN_CHANNELS_ETSI 13 +#define WEXT_NUMBER_SCAN_CHANNELS_MKK1 14 + +#define WPA_DRIVER_WEXT_WAIT_US 400000 +#define WEXT_CSCAN_BUF_LEN 360 +#define WEXT_CSCAN_HEADER "CSCAN S\x01\x00\x00S\x00" +#define WEXT_CSCAN_HEADER_SIZE 12 +#define WEXT_CSCAN_SSID_SECTION 'S' +#define WEXT_CSCAN_CHANNEL_SECTION 'C' +#define WEXT_CSCAN_NPROBE_SECTION 'N' +#define WEXT_CSCAN_ACTV_DWELL_SECTION 'A' +#define WEXT_CSCAN_PASV_DWELL_SECTION 'P' +#define WEXT_CSCAN_HOME_DWELL_SECTION 'H' +#define WEXT_CSCAN_TYPE_SECTION 'T' +#define WEXT_CSCAN_TYPE_DEFAULT 0 +#define WEXT_CSCAN_TYPE_PASSIVE 1 +#define WEXT_CSCAN_PASV_DWELL_TIME 130 +#define WEXT_CSCAN_PASV_DWELL_TIME_DEF 250 +#define WEXT_CSCAN_PASV_DWELL_TIME_MAX 3000 +#define WEXT_CSCAN_HOME_DWELL_TIME 130 + +#endif /* DRIVER_CMD_WEXT_H */ diff --git a/wlan/wpa_supplicant_8_lib/driver_nl80211.h b/wlan/wpa_supplicant_8_lib/driver_nl80211.h new file mode 100644 index 0000000..081eee3 --- /dev/null +++ b/wlan/wpa_supplicant_8_lib/driver_nl80211.h @@ -0,0 +1,251 @@ +/* + * Driver interaction with Linux nl80211/cfg80211 + * Copyright (c) 2002-2014, Jouni Malinen + * Copyright (c) 2003-2004, Instant802 Networks, Inc. + * Copyright (c) 2005-2006, Devicescape Software, Inc. + * Copyright (c) 2007, Johannes Berg + * Copyright (c) 2009-2010, Atheros Communications + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +#ifndef _DRIVER_NL80211_H_ +#define _DRIVER_NL80211_H_ + +#include "includes.h" +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef CONFIG_LIBNL3_ROUTE +#include +#endif /* CONFIG_LIBNL3_ROUTE */ +#include +#include +#include +#include +#include "nl80211_copy.h" + +#include "common.h" +#include "eloop.h" +#include "utils/list.h" +#include "common/qca-vendor.h" +#include "common/qca-vendor-attr.h" +#include "common/ieee802_11_defs.h" +#include "common/ieee802_11_common.h" +#include "l2_packet/l2_packet.h" +#include "netlink.h" +#include "linux_ioctl.h" +#include "radiotap.h" +#include "radiotap_iter.h" +#include "rfkill.h" +#include "driver.h" + +#ifdef CONFIG_LIBNL20 +/* libnl 2.0 compatibility code */ +#define nl_handle nl_sock +#define nl80211_handle_alloc nl_socket_alloc_cb +#define nl80211_handle_destroy nl_socket_free +#endif /* CONFIG_LIBNL20 */ + +#ifndef IFF_LOWER_UP +#define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ +#endif +#ifndef IFF_DORMANT +#define IFF_DORMANT 0x20000 /* driver signals dormant */ +#endif + +#ifndef IF_OPER_DORMANT +#define IF_OPER_DORMANT 5 +#endif +#ifndef IF_OPER_UP +#define IF_OPER_UP 6 +#endif + +struct nl80211_global { + void *ctx; + struct dl_list interfaces; + int if_add_ifindex; + u64 if_add_wdevid; + int if_add_wdevid_set; + struct netlink_data *netlink; + struct nl_cb *nl_cb; + struct nl_handle *nl; + int nl80211_id; + int ioctl_sock; /* socket for ioctl() use */ + + struct nl_handle *nl_event; +}; + +struct nl80211_wiphy_data { + struct dl_list list; + struct dl_list bsss; + struct dl_list drvs; + + struct nl_handle *nl_beacons; + struct nl_cb *nl_cb; + + int wiphy_idx; +}; + +struct i802_bss { + struct wpa_driver_nl80211_data *drv; + struct i802_bss *next; + int ifindex; + int br_ifindex; + u64 wdev_id; + char ifname[IFNAMSIZ + 1]; + char brname[IFNAMSIZ]; + unsigned int beacon_set:1; + unsigned int added_if_into_bridge:1; + unsigned int added_bridge:1; + unsigned int in_deinit:1; + unsigned int wdev_id_set:1; + unsigned int added_if:1; + unsigned int static_ap:1; + + u8 addr[ETH_ALEN]; + + int freq; + int bandwidth; + int if_dynamic; + + void *ctx; + struct nl_handle *nl_preq, *nl_mgmt; + struct nl_cb *nl_cb; + + struct nl80211_wiphy_data *wiphy_data; + struct dl_list wiphy_list; +}; + +struct wpa_driver_nl80211_data { + struct nl80211_global *global; + struct dl_list list; + struct dl_list wiphy_list; + char phyname[32]; + unsigned int wiphy_idx; + u8 perm_addr[ETH_ALEN]; + void *ctx; + int ifindex; + int if_removed; + int if_disabled; + int ignore_if_down_event; + struct rfkill_data *rfkill; + struct wpa_driver_capa capa; + u8 *extended_capa, *extended_capa_mask; + unsigned int extended_capa_len; + int has_capability; + + int operstate; + + int scan_complete_events; + enum scan_states { + NO_SCAN, SCAN_REQUESTED, SCAN_STARTED, SCAN_COMPLETED, + SCAN_ABORTED, SCHED_SCAN_STARTED, SCHED_SCAN_STOPPED, + SCHED_SCAN_RESULTS + } scan_state; + + //struct nl_cb *nl_cb; + + u8 auth_bssid[ETH_ALEN]; + u8 auth_attempt_bssid[ETH_ALEN]; + u8 bssid[ETH_ALEN]; + u8 prev_bssid[ETH_ALEN]; + int associated; + u8 ssid[32]; + size_t ssid_len; + enum nl80211_iftype nlmode; + enum nl80211_iftype ap_scan_as_station; + unsigned int assoc_freq; + + int monitor_sock; + int monitor_ifidx; + int monitor_refcount; + + unsigned int disabled_11b_rates:1; + unsigned int pending_remain_on_chan:1; + unsigned int in_interface_list:1; + unsigned int device_ap_sme:1; + unsigned int poll_command_supported:1; + unsigned int data_tx_status:1; + unsigned int scan_for_auth:1; + unsigned int retry_auth:1; + unsigned int use_monitor:1; + unsigned int ignore_next_local_disconnect:1; + unsigned int ignore_next_local_deauth:1; + //unsigned int allow_p2p_device:1; + unsigned int hostapd:1; + unsigned int start_mode_ap:1; + unsigned int start_iface_up:1; + unsigned int test_use_roc_tx:1; + unsigned int ignore_deauth_event:1; + unsigned int vendor_cmd_test_avail:1; + unsigned int roaming_vendor_cmd_avail:1; + unsigned int dfs_vendor_cmd_avail:1; + unsigned int have_low_prio_scan:1; + unsigned int force_connect_cmd:1; + unsigned int addr_changed:1; + unsigned int get_features_vendor_cmd_avail:1; + unsigned int set_rekey_offload:1; + unsigned int p2p_go_ctwindow_supported:1; + unsigned int setband_vendor_cmd_avail:1; + unsigned int get_pref_freq_list:1; + unsigned int set_prob_oper_freq:1; + unsigned int scan_vendor_cmd_avail:1; + unsigned int connect_reassoc:1; + + u64 vendor_scan_cookie; + u64 remain_on_chan_cookie; + u64 send_action_cookie; +#define MAX_SEND_ACTION_COOKIES 20 + u64 send_action_cookies[MAX_SEND_ACTION_COOKIES]; + unsigned int num_send_action_cookies; + + unsigned int last_mgmt_freq; + + struct wpa_driver_scan_filter *filter_ssids; + size_t num_filter_ssids; + + struct i802_bss *first_bss; + + int eapol_tx_sock; + + int eapol_sock; /* socket for EAPOL frames */ + + struct nl_handle *rtnl_sk; /* nl_sock for NETLINK_ROUTE */ + + int default_if_indices[16]; + /* the AP/AP_VLAN iface that is in this bridge */ + int default_if_indices_reason[16]; + int *if_indices; + int *if_indices_reason; + int num_if_indices; + + /* From failed authentication command */ + int auth_freq; + u8 auth_bssid_[ETH_ALEN]; + u8 auth_ssid[32]; + size_t auth_ssid_len; + int auth_alg; + u8 *auth_ie; + size_t auth_ie_len; + u8 auth_wep_key[4][16]; + size_t auth_wep_key_len[4]; + int auth_wep_tx_keyidx; + int auth_local_state_change; + int auth_p2p; + + /* + * Tells whether the last scan issued from wpa_supplicant was a normal + * scan (NL80211_CMD_TRIGGER_SCAN) or a vendor scan + * (NL80211_CMD_VENDOR). 0 if no pending scan request. + */ + int last_scan_cmd; +}; + +#endif diff --git a/wlan/wpa_supplicant_8_lib/rtw_version.h b/wlan/wpa_supplicant_8_lib/rtw_version.h new file mode 100644 index 0000000..48edbdc --- /dev/null +++ b/wlan/wpa_supplicant_8_lib/rtw_version.h @@ -0,0 +1,4 @@ +#ifndef RTW_VERSION_H + #define RTW_VERSION_H + #define RTW_VERSION "rtw_r26589.20180227" +#endif /* RTW_VERSION_H */ -- 2.20.1