1 /* 2 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: wlan_cfg80211_wifi_pos.c 21 * defines wifi-pos module related driver functions interfacing with linux 22 * kernel 23 */ 24 #include "wlan_cfg80211.h" 25 #include "wlan_objmgr_psoc_obj.h" 26 #include "wlan_cfg80211_wifi_pos.h" 27 #include "wlan_cmn_ieee80211.h" 28 #include "wifi_pos_ucfg_i.h" 29 30 #if defined(WIFI_POS_CONVERGED) && defined(WLAN_FEATURE_RTT_11AZ_SUPPORT) 31 32 u8 wlan_extended_caps_iface[WLAN_EXTCAP_IE_MAX_LEN] = {0}; 33 u8 wlan_extended_caps_iface_mask[WLAN_EXTCAP_IE_MAX_LEN] = {0}; 34 35 struct wiphy_iftype_ext_capab iftype_ext_cap; 36 37 #define WLAN_EXT_RANGING_CAP_IDX 11 38 void 39 wlan_wifi_pos_cfg80211_set_wiphy_ext_feature(struct wiphy *wiphy, 40 struct wlan_objmgr_psoc *psoc) 41 { 42 bool enable_rsta_11az_ranging; 43 44 enable_rsta_11az_ranging = ucfg_wifi_pos_get_rsta_11az_ranging_cap(); 45 if (!enable_rsta_11az_ranging) 46 return; 47 48 if (wlan_psoc_nif_fw_ext_cap_get(psoc, WLAN_RTT_11AZ_NTB_SUPPORT)) { 49 wlan_extended_caps_iface[WLAN_EXT_RANGING_CAP_IDX] |= 50 WLAN_EXT_CAPA11_NTB_RANGING_RESPONDER; 51 wlan_extended_caps_iface_mask[WLAN_EXT_RANGING_CAP_IDX] |= 52 WLAN_EXT_CAPA11_NTB_RANGING_RESPONDER; 53 } 54 55 if (wlan_psoc_nif_fw_ext2_cap_get(psoc, WLAN_RTT_11AZ_TB_SUPPORT)) { 56 wlan_extended_caps_iface[WLAN_EXT_RANGING_CAP_IDX] |= 57 WLAN_EXT_CAPA11_TB_RANGING_RESPONDER; 58 wlan_extended_caps_iface_mask[WLAN_EXT_RANGING_CAP_IDX] |= 59 WLAN_EXT_CAPA11_TB_RANGING_RESPONDER; 60 } 61 62 iftype_ext_cap.iftype = NL80211_IFTYPE_AP; 63 iftype_ext_cap.extended_capabilities = 64 wlan_extended_caps_iface, 65 iftype_ext_cap.extended_capabilities_mask = 66 wlan_extended_caps_iface_mask, 67 iftype_ext_cap.extended_capabilities_len = 68 ARRAY_SIZE(wlan_extended_caps_iface), 69 70 wiphy->num_iftype_ext_capab = 0; 71 wiphy->iftype_ext_capab = &iftype_ext_cap; 72 wiphy->num_iftype_ext_capab++; 73 } 74 75 #define NUM_BITS_IN_BYTE 8 76 static void 77 wlan_wifi_pos_set_feature_flags(uint8_t *feature_flags, 78 enum qca_wlan_vendor_features feature) 79 { 80 uint32_t index; 81 uint8_t bit_mask; 82 83 index = feature / NUM_BITS_IN_BYTE; 84 bit_mask = 1 << (feature % NUM_BITS_IN_BYTE); 85 feature_flags[index] |= bit_mask; 86 } 87 88 void wlan_wifi_pos_cfg80211_set_features(struct wlan_objmgr_psoc *psoc, 89 uint8_t *feature_flags) 90 { 91 bool rsta_secure_ltf_support, enable_rsta_11az_ranging; 92 93 enable_rsta_11az_ranging = ucfg_wifi_pos_get_rsta_11az_ranging_cap(); 94 rsta_secure_ltf_support = enable_rsta_11az_ranging && 95 wifi_pos_get_rsta_sec_ltf_cap(); 96 if (wlan_psoc_nif_fw_ext2_cap_get(psoc, 97 WLAN_RTT_11AZ_MAC_PHY_SEC_SUPPORT)) { 98 wlan_wifi_pos_set_feature_flags(feature_flags, 99 QCA_WLAN_VENDOR_FEATURE_SECURE_LTF_STA); 100 if (rsta_secure_ltf_support) 101 wlan_wifi_pos_set_feature_flags(feature_flags, 102 QCA_WLAN_VENDOR_FEATURE_SECURE_LTF_AP); 103 } 104 105 if (wlan_psoc_nif_fw_ext2_cap_get(psoc, 106 WLAN_RTT_11AZ_MAC_SEC_SUPPORT)) { 107 wlan_wifi_pos_set_feature_flags(feature_flags, 108 QCA_WLAN_VENDOR_FEATURE_PROT_RANGE_NEGO_AND_MEASURE_STA); 109 if (rsta_secure_ltf_support) 110 wlan_wifi_pos_set_feature_flags(feature_flags, 111 QCA_WLAN_VENDOR_FEATURE_PROT_RANGE_NEGO_AND_MEASURE_AP); 112 } 113 } 114 #endif 115