blob: 34f97eb862cc6c680326e05c09ed7d64745923e9 [file] [log] [blame]
Jeff Johnson2b0a7b82016-05-18 15:08:02 -07001/*
2 * Copyright (c) 2012-2016 The Linux Foundation. All rights reserved.
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 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: wlan_hdd_lpass.c
30 *
31 * WLAN Host Device Driver LPASS feature implementation
32 *
33 */
34
Jeff Johnson731f3a12016-05-19 07:05:06 -070035/* denote that this file does not allow legacy hddLog */
36#define HDD_DISALLOW_LEGACY_HDDLOG 1
37
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070038/* Include Files */
39#include "wlan_hdd_main.h"
40#include "wlan_hdd_lpass.h"
41#include <cds_utils.h>
42#include "qwlan_version.h"
43
Jeff Johnsonf96ef732016-05-18 16:38:06 -070044/**
45 * wlan_hdd_gen_wlan_status_pack() - Create lpass adapter status package
46 * @data: Status data record to be created
47 * @adapter: Adapter whose status is to being packaged
48 * @sta_ctx: Station-specific context of @adapter
49 * @is_on: Is wlan driver loaded?
50 * @is_connected: Is @adapater connected to an AP?
51 *
52 * Generate a wlan vdev status package. The status info includes wlan
53 * on/off status, vdev ID, vdev mode, supported channels, etc.
54 *
55 * Return: 0 if package was created, otherwise a negative errno
56 */
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070057static int wlan_hdd_gen_wlan_status_pack(struct wlan_status_data *data,
58 hdd_adapter_t *adapter,
Jeff Johnsond9dd4842016-05-18 16:49:29 -070059 hdd_station_ctx_t *sta_ctx,
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070060 uint8_t is_on, uint8_t is_connected)
61{
62 hdd_context_t *hdd_ctx = NULL;
63 uint8_t buflen = WLAN_SVC_COUNTRY_CODE_LEN;
64
65 if (!data) {
Jeff Johnson731f3a12016-05-19 07:05:06 -070066 hdd_err("invalid data pointer");
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070067 return -EINVAL;
68 }
69 if (!adapter) {
70 if (is_on) {
71 /* no active interface */
72 data->lpss_support = 0;
73 data->is_on = is_on;
74 return 0;
75 }
Jeff Johnson731f3a12016-05-19 07:05:06 -070076 hdd_err("invalid adapter pointer");
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070077 return -EINVAL;
78 }
79
80 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
81 if (hdd_ctx->lpss_support && hdd_ctx->config->enable_lpass_support)
82 data->lpss_support = 1;
83 else
84 data->lpss_support = 0;
85 data->numChannels = WLAN_SVC_MAX_NUM_CHAN;
86 sme_get_cfg_valid_channels(hdd_ctx->hHal, data->channel_list,
87 &data->numChannels);
88 sme_get_country_code(hdd_ctx->hHal, data->country_code, &buflen);
89 data->is_on = is_on;
90 data->vdev_id = adapter->sessionId;
91 data->vdev_mode = adapter->device_mode;
Jeff Johnsond9dd4842016-05-18 16:49:29 -070092 if (sta_ctx) {
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070093 data->is_connected = is_connected;
94 data->rssi = adapter->rssi;
95 data->freq =
Jeff Johnsond9dd4842016-05-18 16:49:29 -070096 cds_chan_to_freq(sta_ctx->conn_info.operationChannel);
Jeff Johnson2b0a7b82016-05-18 15:08:02 -070097 if (WLAN_SVC_MAX_SSID_LEN >=
Jeff Johnsond9dd4842016-05-18 16:49:29 -070098 sta_ctx->conn_info.SSID.SSID.length) {
99 data->ssid_len = sta_ctx->conn_info.SSID.SSID.length;
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700100 memcpy(data->ssid,
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700101 sta_ctx->conn_info.SSID.SSID.ssId,
102 sta_ctx->conn_info.SSID.SSID.length);
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700103 }
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700104 if (QDF_MAC_ADDR_SIZE >= sizeof(sta_ctx->conn_info.bssId))
105 memcpy(data->bssid, sta_ctx->conn_info.bssId.bytes,
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700106 QDF_MAC_ADDR_SIZE);
107 }
108 return 0;
109}
110
Jeff Johnsonf96ef732016-05-18 16:38:06 -0700111/**
112 * wlan_hdd_gen_wlan_version_pack() - Create lpass version package
113 * @data: Version data record to be created
114 * @fw_version: Version code from firmware
115 * @chip_id: WLAN chip ID
116 * @chip_name: WLAN chip name
117 *
118 * Generate a wlan software/hw version info package. The version info
119 * includes wlan host driver version, wlan fw driver version, wlan hw
120 * chip id & wlan hw chip name.
121 *
122 * Return: 0 if package was created, otherwise a negative errno
123 */
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700124static int wlan_hdd_gen_wlan_version_pack(struct wlan_version_data *data,
125 uint32_t fw_version,
126 uint32_t chip_id,
127 const char *chip_name)
128{
129 if (!data) {
Jeff Johnson731f3a12016-05-19 07:05:06 -0700130 hdd_err("invalid data pointer");
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700131 return -EINVAL;
132 }
133
134 data->chip_id = chip_id;
135 strlcpy(data->chip_name, chip_name, WLAN_SVC_MAX_STR_LEN);
136 if (strncmp(chip_name, "Unknown", 7))
137 strlcpy(data->chip_from, "Qualcomm", WLAN_SVC_MAX_STR_LEN);
138 else
139 strlcpy(data->chip_from, "Unknown", WLAN_SVC_MAX_STR_LEN);
140 strlcpy(data->host_version, QWLAN_VERSIONSTR, WLAN_SVC_MAX_STR_LEN);
141 scnprintf(data->fw_version, WLAN_SVC_MAX_STR_LEN, "%d.%d.%d.%d",
142 (fw_version & 0xf0000000) >> 28,
143 (fw_version & 0xf000000) >> 24,
144 (fw_version & 0xf00000) >> 20, (fw_version & 0x7fff));
145 return 0;
146}
147
Jeff Johnsonf96ef732016-05-18 16:38:06 -0700148/**
149 * wlan_hdd_send_status_pkg() - Send adapter status to lpass
150 * @adapter: Adapter whose status is to be sent to lpass
151 * @sta_ctx: Station-specific context of @adapter
152 * @is_on: Is @adapter enabled
153 * @is_connected: Is @adapater connected
154 *
155 * Generate wlan vdev status pacakge and send it to a user space
156 * daemon through netlink.
157 *
158 * Return: none
159 */
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700160void wlan_hdd_send_status_pkg(hdd_adapter_t *adapter,
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700161 hdd_station_ctx_t *sta_ctx,
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700162 uint8_t is_on, uint8_t is_connected)
163{
164 int ret = 0;
165 struct wlan_status_data data;
166
167 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
168 return;
169
170 memset(&data, 0, sizeof(struct wlan_status_data));
171 if (is_on)
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700172 ret = wlan_hdd_gen_wlan_status_pack(&data, adapter, sta_ctx,
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700173 is_on, is_connected);
174 if (!ret)
175 wlan_hdd_send_svc_nlink_msg(WLAN_SVC_WLAN_STATUS_IND,
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700176 &data, sizeof(data));
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700177}
178
Jeff Johnsonf96ef732016-05-18 16:38:06 -0700179/**
180 * wlan_hdd_send_version_pkg() - report version information to lpass
181 * @fw_version: Version code from firmware
182 * @chip_id: WLAN chip ID
183 * @chip_name: WLAN chip name
184 *
185 * Generate a wlan sw/hw version info package and send it to a user
186 * space daemon through netlink.
187 *
188 * Return: none
189 */
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700190void wlan_hdd_send_version_pkg(uint32_t fw_version,
191 uint32_t chip_id, const char *chip_name)
192{
193 int ret = 0;
194 struct wlan_version_data data;
195
196 if (QDF_GLOBAL_FTM_MODE == hdd_get_conparam())
197 return;
198
199 memset(&data, 0, sizeof(struct wlan_version_data));
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700200 ret = wlan_hdd_gen_wlan_version_pack(&data, fw_version, chip_id,
201 chip_name);
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700202 if (!ret)
203 wlan_hdd_send_svc_nlink_msg(WLAN_SVC_WLAN_VERSION_IND,
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700204 &data, sizeof(data));
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700205}
206
Jeff Johnsonf96ef732016-05-18 16:38:06 -0700207/**
208 * wlan_hdd_send_all_scan_intf_info() - report scan interfaces to lpass
209 * @hdd_ctx: The global HDD context
210 *
211 * This function iterates through all of the interfaces registered
212 * with HDD and indicates to lpass all that support scanning.
213 * If no interfaces support scanning then that fact is also indicated.
214 *
215 * Return: none
216 */
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700217void wlan_hdd_send_all_scan_intf_info(hdd_context_t *hdd_ctx)
218{
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700219 hdd_adapter_t *adapter = NULL;
220 hdd_adapter_list_node_t *node = NULL, *next = NULL;
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700221 bool scan_intf_found = false;
222 QDF_STATUS status;
223
224 if (!hdd_ctx) {
Jeff Johnson731f3a12016-05-19 07:05:06 -0700225 hdd_err("NULL pointer for hdd_ctx");
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700226 return;
227 }
228
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700229 status = hdd_get_front_adapter(hdd_ctx, &node);
230 while (NULL != node && QDF_STATUS_SUCCESS == status) {
231 adapter = node->pAdapter;
232 if (adapter) {
233 if (adapter->device_mode == QDF_STA_MODE
234 || adapter->device_mode == QDF_P2P_CLIENT_MODE
235 || adapter->device_mode ==
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700236 QDF_P2P_DEVICE_MODE) {
237 scan_intf_found = true;
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700238 wlan_hdd_send_status_pkg(adapter, NULL, 1, 0);
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700239 }
240 }
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700241 status = hdd_get_next_adapter(hdd_ctx, node, &next);
242 node = next;
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700243 }
244
245 if (!scan_intf_found)
Jeff Johnsond9dd4842016-05-18 16:49:29 -0700246 wlan_hdd_send_status_pkg(adapter, NULL, 1, 0);
Jeff Johnson2b0a7b82016-05-18 15:08:02 -0700247}