blob: cf9f39bbfb21e0d57387c8a647c232a1ff17fe4b [file] [log] [blame]
Ravi Joshideb5a8d2015-11-09 19:11:43 -08001/*
Anurag Chouhanfb54ab02016-02-18 18:00:46 +05302 * Copyright (c) 2015-2016 The Linux Foundation. All rights reserved.
Ravi Joshideb5a8d2015-11-09 19:11:43 -08003 *
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
45static const struct nla_policy
46 policy[QCA_WLAN_VENDOR_ATTR_GW_PARAM_CONFIG_MAX + 1] = {
47 [PARAM_MAC_ADDR] = {
48 .type = NLA_BINARY,
Anurag Chouhan6d760662016-02-20 16:05:43 +053049 .len = QDF_MAC_ADDR_SIZE
Ravi Joshideb5a8d2015-11-09 19:11:43 -080050 },
51 [PARAM_IPV4_ADDR] = {
52 .type = NLA_BINARY,
Anurag Chouhan6d760662016-02-20 16:05:43 +053053 .len = QDF_IPV4_ADDR_SIZE
Ravi Joshideb5a8d2015-11-09 19:11:43 -080054 },
55 [PARAM_IPV6_ADDR] = {
56 .type = NLA_BINARY,
Anurag Chouhan6d760662016-02-20 16:05:43 +053057 .len = QDF_IPV6_ADDR_SIZE
Ravi Joshideb5a8d2015-11-09 19:11:43 -080058 }
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 */
70static 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 Chouhanfb54ab02016-02-18 18:00:46 +053081 QDF_STATUS status;
Ravi Joshideb5a8d2015-11-09 19:11:43 -080082
Jeff Johnson1f61b612016-02-12 16:28:33 -080083 ENTER_DEV(dev);
Ravi Joshideb5a8d2015-11-09 19:11:43 -080084
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 */
Krunal Sonif07bb382016-03-10 13:02:11 -080098 if (QDF_STA_MODE != adapter->device_mode) {
Ravi Joshideb5a8d2015-11-09 19:11:43 -080099 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],
Anurag Chouhan6d760662016-02-20 16:05:43 +0530124 QDF_MAC_ADDR_SIZE);
Ravi Joshideb5a8d2015-11-09 19:11:43 -0800125
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],
Anurag Chouhan6d760662016-02-20 16:05:43 +0530131 QDF_IPV4_ADDR_SIZE);
Ravi Joshideb5a8d2015-11-09 19:11:43 -0800132 req.ipv4_addr_type = true;
133 }
134
135 if (tb[PARAM_IPV6_ADDR]) {
136 nla_memcpy(&req.ipv6_addr, tb[PARAM_IPV6_ADDR],
Anurag Chouhan6d760662016-02-20 16:05:43 +0530137 QDF_IPV6_ADDR_SIZE);
Ravi Joshideb5a8d2015-11-09 19:11:43 -0800138 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 Chouhanfb54ab02016-02-18 18:00:46 +0530159 if (!QDF_IS_STATUS_SUCCESS(status)) {
Ravi Joshideb5a8d2015-11-09 19:11:43 -0800160 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 */
181int 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