Ravi Joshi | deb5a8d | 2015-11-09 19:11:43 -0800 | [diff] [blame] | 1 | /* |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 2 | * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved. |
Ravi Joshi | deb5a8d | 2015-11-09 19:11:43 -0800 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /** |
| 23 | * DOC: wlan_hdd_subnet_detect.c |
| 24 | * |
| 25 | * WLAN Host Device Driver subnet detect API implementation |
| 26 | */ |
| 27 | |
| 28 | #include <linux/version.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/kernel.h> |
| 31 | #include <net/cfg80211.h> |
| 32 | #include <ani_global.h> |
| 33 | #include "sme_api.h" |
| 34 | #include "wlan_hdd_main.h" |
| 35 | #include "wlan_hdd_subnet_detect.h" |
| 36 | |
| 37 | /* |
| 38 | * define short names for the global vendor params |
| 39 | * used by __wlan_hdd_cfg80211_set_gateway_params() |
| 40 | */ |
| 41 | #define PARAM_MAC_ADDR QCA_WLAN_VENDOR_ATTR_GW_PARAM_CONFIG_GW_MAC_ADDR |
| 42 | #define PARAM_IPV4_ADDR QCA_WLAN_VENDOR_ATTR_GW_PARAM_CONFIG_IPV4_ADDR |
| 43 | #define PARAM_IPV6_ADDR QCA_WLAN_VENDOR_ATTR_GW_PARAM_CONFIG_IPV6_ADDR |
| 44 | |
| 45 | static const struct nla_policy |
| 46 | policy[QCA_WLAN_VENDOR_ATTR_GW_PARAM_CONFIG_MAX + 1] = { |
| 47 | [PARAM_MAC_ADDR] = { |
| 48 | .type = NLA_BINARY, |
| 49 | .len = CDF_MAC_ADDR_SIZE |
| 50 | }, |
| 51 | [PARAM_IPV4_ADDR] = { |
| 52 | .type = NLA_BINARY, |
| 53 | .len = CDF_IPV4_ADDR_SIZE |
| 54 | }, |
| 55 | [PARAM_IPV6_ADDR] = { |
| 56 | .type = NLA_BINARY, |
| 57 | .len = CDF_IPV6_ADDR_SIZE |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * __wlan_hdd_cfg80211_set_gateway_params() - set gateway params |
| 63 | * @wiphy: Pointer to wireless phy |
| 64 | * @wdev: Pointer to wireless device |
| 65 | * @data: Pointer to data |
| 66 | * @data_len: Data length |
| 67 | * |
| 68 | * Return: 0 on success, negative errno on failure |
| 69 | */ |
| 70 | static int __wlan_hdd_cfg80211_set_gateway_params(struct wiphy *wiphy, |
| 71 | struct wireless_dev *wdev, |
| 72 | const void *data, |
| 73 | int data_len) |
| 74 | { |
| 75 | struct net_device *dev = wdev->netdev; |
| 76 | hdd_adapter_t *adapter = WLAN_HDD_GET_PRIV_PTR(dev); |
| 77 | hdd_context_t *hdd_ctx = wiphy_priv(wiphy); |
| 78 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_GW_PARAM_CONFIG_MAX + 1]; |
| 79 | struct gateway_param_update_req req = { 0 }; |
| 80 | int ret; |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 81 | QDF_STATUS status; |
Ravi Joshi | deb5a8d | 2015-11-09 19:11:43 -0800 | [diff] [blame] | 82 | |
| 83 | ENTER(); |
| 84 | |
| 85 | ret = wlan_hdd_validate_context(hdd_ctx); |
| 86 | if (0 != ret) |
| 87 | return ret; |
| 88 | |
| 89 | /* user may have disabled the feature in INI */ |
| 90 | if (!hdd_ctx->config->enable_lfr_subnet_detection) { |
| 91 | hdd_info("LFR Subnet Detection disabled in INI"); |
| 92 | return -ENOTSUPP; |
| 93 | } |
| 94 | |
| 95 | /* The gateway parameters are only valid in the STA persona |
| 96 | * and only in the connected state. |
| 97 | */ |
| 98 | if (WLAN_HDD_INFRA_STATION != adapter->device_mode) { |
| 99 | hdd_err("Received GW param update for non-STA mode adapter"); |
| 100 | return -ENOTSUPP; |
| 101 | } |
| 102 | |
| 103 | if (!hdd_conn_is_connected(WLAN_HDD_GET_STATION_CTX_PTR(adapter))) { |
| 104 | hdd_err("Received GW param update in disconnected state!"); |
| 105 | return -ENOTSUPP; |
| 106 | } |
| 107 | |
| 108 | /* Extract NL parameters |
| 109 | * mac_addr: 6 bytes |
| 110 | * ipv4 addr: 4 bytes |
| 111 | * ipv6 addr: 16 bytes |
| 112 | */ |
| 113 | if (nla_parse(tb, QCA_WLAN_VENDOR_ATTR_GW_PARAM_CONFIG_MAX, |
| 114 | data, data_len, policy)) { |
| 115 | hdd_err("Invalid ATTR list"); |
| 116 | return -EINVAL; |
| 117 | } |
| 118 | |
| 119 | if (!tb[PARAM_MAC_ADDR]) { |
| 120 | hdd_err("request mac addr failed"); |
| 121 | return -EINVAL; |
| 122 | } |
| 123 | nla_memcpy(req.gw_mac_addr.bytes, tb[PARAM_MAC_ADDR], |
| 124 | CDF_MAC_ADDR_SIZE); |
| 125 | |
| 126 | /* req ipv4_addr_type and ipv6_addr_type are initially false due |
| 127 | * to zeroing the struct |
| 128 | */ |
| 129 | if (tb[PARAM_IPV4_ADDR]) { |
| 130 | nla_memcpy(req.ipv4_addr, tb[PARAM_IPV4_ADDR], |
| 131 | CDF_IPV4_ADDR_SIZE); |
| 132 | req.ipv4_addr_type = true; |
| 133 | } |
| 134 | |
| 135 | if (tb[PARAM_IPV6_ADDR]) { |
| 136 | nla_memcpy(&req.ipv6_addr, tb[PARAM_IPV6_ADDR], |
| 137 | CDF_IPV6_ADDR_SIZE); |
| 138 | req.ipv6_addr_type = true; |
| 139 | } |
| 140 | |
| 141 | if (!req.ipv4_addr_type && !req.ipv6_addr_type) { |
| 142 | hdd_err("invalid ipv4 or ipv6 gateway address"); |
| 143 | return -EINVAL; |
| 144 | } |
| 145 | |
| 146 | req.max_retries = 3; |
| 147 | req.timeout = 100; /* in milliseconds */ |
| 148 | req.session_id = adapter->sessionId; |
| 149 | |
| 150 | hdd_info("**** Gateway Parameters: ****"); |
| 151 | hdd_info("session id: %d", req.session_id); |
| 152 | hdd_info("ipv4 addr type: %d", req.ipv4_addr_type); |
| 153 | hdd_info("ipv6 addr type: %d", req.ipv6_addr_type); |
| 154 | hdd_info("gw mac addr: %pM", req.gw_mac_addr.bytes); |
| 155 | hdd_info("ipv4 addr: %pI4", req.ipv4_addr); |
| 156 | hdd_info("ipv6 addr: %pI6c", req.ipv6_addr); |
| 157 | |
| 158 | status = sme_gateway_param_update(hdd_ctx->hHal, &req); |
Anurag Chouhan | fb54ab0 | 2016-02-18 18:00:46 +0530 | [diff] [blame] | 159 | if (!QDF_IS_STATUS_SUCCESS(status)) { |
Ravi Joshi | deb5a8d | 2015-11-09 19:11:43 -0800 | [diff] [blame] | 160 | hdd_err("sme_gateway_param_update failed(err=%d)", status); |
| 161 | ret = -EINVAL; |
| 162 | } |
| 163 | |
| 164 | EXIT(); |
| 165 | return ret; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * wlan_hdd_cfg80211_set_gateway_params() - set gateway parameters |
| 170 | * @wiphy: wiphy structure pointer |
| 171 | * @wdev: Wireless device structure pointer |
| 172 | * @data: Pointer to the data received |
| 173 | * @data_len: Length of @data |
| 174 | * |
| 175 | * The API is invoked by the user space to set the gateway parameters |
| 176 | * such as mac address and the IP address which is used for detecting |
| 177 | * the IP subnet change |
| 178 | * |
| 179 | * Return: 0 on success; errno on failure |
| 180 | */ |
| 181 | int wlan_hdd_cfg80211_set_gateway_params(struct wiphy *wiphy, |
| 182 | struct wireless_dev *wdev, const void *data, int data_len) |
| 183 | { |
| 184 | int ret; |
| 185 | |
| 186 | cds_ssr_protect(__func__); |
| 187 | |
| 188 | ret = __wlan_hdd_cfg80211_set_gateway_params( |
| 189 | wiphy, wdev, data, data_len); |
| 190 | cds_ssr_unprotect(__func__); |
| 191 | return ret; |
| 192 | } |
| 193 | #undef PARAM_MAC_ADDR |
| 194 | #undef PARAM_IPV4_ADDR |
| 195 | #undef PARAM_IPV6_ADDR |