Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 1 | /* |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 2 | * Copyright (c) 2012-2015 The Linux Foundation. All rights reserved. |
Kiet Lam | 842dad0 | 2014-02-18 18:44:02 -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. |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 20 | */ |
Kiet Lam | 842dad0 | 2014-02-18 18:44:02 -0800 | [diff] [blame] | 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 | |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 28 | #ifdef WLAN_OPEN_SOURCE |
| 29 | #include <wlan_hdd_includes.h> |
| 30 | #include <wlan_hdd_wowl.h> |
Mahesh A Saptasagar | d68eb28 | 2014-12-17 14:20:19 +0530 | [diff] [blame] | 31 | #include <vos_sched.h> |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 32 | |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 33 | #define MAX_USER_COMMAND_SIZE_WOWL_ENABLE 8 |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 34 | #define MAX_USER_COMMAND_SIZE_WOWL_PATTERN 512 |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 35 | #define MAX_USER_COMMAND_SIZE_FRAME 4096 |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 36 | |
Mahesh A Saptasagar | d68eb28 | 2014-12-17 14:20:19 +0530 | [diff] [blame] | 37 | static ssize_t __wcnss_wowenable_write(struct file *file, |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 38 | const char __user *buf, size_t count, loff_t *ppos) |
| 39 | { |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 40 | hdd_adapter_t *pAdapter; |
| 41 | hdd_context_t *pHddCtx; |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 42 | char cmd[MAX_USER_COMMAND_SIZE_WOWL_ENABLE + 1]; |
| 43 | char *sptr, *token; |
| 44 | v_U8_t wow_enable = 0; |
| 45 | v_U8_t wow_mp = 0; |
| 46 | v_U8_t wow_pbm = 0; |
| 47 | |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 48 | ENTER(); |
| 49 | |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 50 | pAdapter = (hdd_adapter_t *)file->private_data; |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 51 | if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)) |
| 52 | { |
| 53 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, |
| 54 | "%s: Invalid adapter or adapter has invalid magic.", |
| 55 | __func__); |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 56 | return -EINVAL; |
| 57 | } |
| 58 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 59 | if (0 != wlan_hdd_validate_context(pHddCtx)) |
| 60 | { |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 61 | return -EINVAL; |
| 62 | } |
| 63 | |
| 64 | if (!sme_IsFeatureSupportedByFW(WOW)) |
| 65 | { |
| 66 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 67 | "%s: Wake-on-Wireless feature is not supported " |
| 68 | "in firmware!", __func__); |
| 69 | |
| 70 | return -EINVAL; |
| 71 | } |
| 72 | |
| 73 | if (count > MAX_USER_COMMAND_SIZE_WOWL_ENABLE) |
| 74 | { |
| 75 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 76 | "%s: Command length is larger than %d bytes.", |
| 77 | __func__, MAX_USER_COMMAND_SIZE_WOWL_ENABLE); |
| 78 | |
| 79 | return -EINVAL; |
| 80 | } |
| 81 | |
| 82 | /* Get command from user */ |
| 83 | if (copy_from_user(cmd, buf, count)) |
| 84 | return -EFAULT; |
| 85 | cmd[count] = '\0'; |
| 86 | sptr = cmd; |
| 87 | |
| 88 | /* Get enable or disable wow */ |
| 89 | token = strsep(&sptr, " "); |
| 90 | if (!token) |
| 91 | return -EINVAL; |
| 92 | if (kstrtou8(token, 0, &wow_enable)) |
| 93 | return -EINVAL; |
| 94 | |
| 95 | /* Disable wow */ |
| 96 | if (!wow_enable) { |
c_hpothu | 01484c0 | 2014-05-16 14:05:15 +0530 | [diff] [blame] | 97 | if (!hdd_exit_wowl(pAdapter, eWOWL_EXIT_USER)) |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 98 | { |
| 99 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 100 | "%s: hdd_exit_wowl failed!", __func__); |
| 101 | |
| 102 | return -EFAULT; |
| 103 | } |
| 104 | |
| 105 | return count; |
| 106 | } |
| 107 | |
| 108 | /* Get enable or disable magic packet mode */ |
| 109 | token = strsep(&sptr, " "); |
| 110 | if (!token) |
| 111 | return -EINVAL; |
| 112 | if (kstrtou8(token, 0, &wow_mp)) |
| 113 | return -EINVAL; |
| 114 | if (wow_mp > 1) |
| 115 | wow_mp = 1; |
| 116 | |
| 117 | /* Get enable or disable pattern byte matching mode */ |
| 118 | token = strsep(&sptr, " "); |
| 119 | if (!token) |
| 120 | return -EINVAL; |
| 121 | if (kstrtou8(token, 0, &wow_pbm)) |
| 122 | return -EINVAL; |
| 123 | if (wow_pbm > 1) |
| 124 | wow_pbm = 1; |
| 125 | |
| 126 | if (!hdd_enter_wowl(pAdapter, wow_mp, wow_pbm)) |
| 127 | { |
| 128 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 129 | "%s: hdd_enter_wowl failed!", __func__); |
| 130 | |
| 131 | return -EFAULT; |
| 132 | } |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 133 | EXIT(); |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 134 | return count; |
| 135 | } |
| 136 | |
Mahesh A Saptasagar | d68eb28 | 2014-12-17 14:20:19 +0530 | [diff] [blame] | 137 | static ssize_t wcnss_wowenable_write(struct file *file, |
| 138 | const char __user *buf, size_t count, loff_t *ppos) |
| 139 | { |
| 140 | ssize_t ret; |
| 141 | |
| 142 | vos_ssr_protect(__func__); |
| 143 | ret = __wcnss_wowenable_write(file, buf, count, ppos); |
| 144 | vos_ssr_unprotect(__func__); |
| 145 | |
| 146 | return ret; |
| 147 | } |
| 148 | |
| 149 | static ssize_t __wcnss_wowpattern_write(struct file *file, |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 150 | const char __user *buf, size_t count, loff_t *ppos) |
| 151 | { |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 152 | hdd_adapter_t *pAdapter; |
| 153 | hdd_context_t *pHddCtx; |
Yue Ma | 63993e3 | 2013-10-21 23:10:53 -0700 | [diff] [blame] | 154 | char cmd[MAX_USER_COMMAND_SIZE_WOWL_PATTERN + 1]; |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 155 | char *sptr, *token; |
| 156 | v_U8_t pattern_idx = 0; |
| 157 | v_U8_t pattern_offset = 0; |
| 158 | char *pattern_buf; |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 159 | char *pattern_mask; |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 160 | |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 161 | ENTER(); |
| 162 | |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 163 | pAdapter = (hdd_adapter_t *)file->private_data; |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 164 | if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)) |
| 165 | { |
| 166 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, |
| 167 | "%s: Invalid adapter or adapter has invalid magic.", |
| 168 | __func__); |
| 169 | |
| 170 | return -EINVAL; |
| 171 | } |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 172 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 173 | if (0 != wlan_hdd_validate_context(pHddCtx)) |
| 174 | { |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 175 | return -EINVAL; |
| 176 | } |
Yue Ma | 55855df | 2013-08-26 10:59:03 -0700 | [diff] [blame] | 177 | if (!sme_IsFeatureSupportedByFW(WOW)) |
| 178 | { |
| 179 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 180 | "%s: Wake-on-Wireless feature is not supported " |
| 181 | "in firmware!", __func__); |
| 182 | |
| 183 | return -EINVAL; |
| 184 | } |
Yue Ma | 63993e3 | 2013-10-21 23:10:53 -0700 | [diff] [blame] | 185 | |
| 186 | if (count > MAX_USER_COMMAND_SIZE_WOWL_PATTERN) |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 187 | { |
| 188 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 189 | "%s: Command length is larger than %d bytes.", |
| 190 | __func__, MAX_USER_COMMAND_SIZE_WOWL_PATTERN); |
| 191 | |
| 192 | return -EINVAL; |
| 193 | } |
| 194 | |
| 195 | /* Get command from user */ |
| 196 | if (copy_from_user(cmd, buf, count)) |
| 197 | return -EFAULT; |
| 198 | cmd[count] = '\0'; |
| 199 | sptr = cmd; |
| 200 | |
| 201 | /* Get pattern idx */ |
| 202 | token = strsep(&sptr, " "); |
| 203 | if (!token) |
| 204 | return -EINVAL; |
| 205 | |
| 206 | if (kstrtou8(token, 0, &pattern_idx)) |
| 207 | return -EINVAL; |
| 208 | |
| 209 | /* Get pattern offset */ |
| 210 | token = strsep(&sptr, " "); |
| 211 | |
| 212 | /* Delete pattern if no further argument */ |
| 213 | if (!token) { |
| 214 | hdd_del_wowl_ptrn_debugfs(pAdapter, pattern_idx); |
| 215 | |
| 216 | return count; |
| 217 | } |
| 218 | |
| 219 | if (kstrtou8(token, 0, &pattern_offset)) |
| 220 | return -EINVAL; |
| 221 | |
| 222 | /* Get pattern */ |
| 223 | token = strsep(&sptr, " "); |
| 224 | if (!token) |
| 225 | return -EINVAL; |
| 226 | |
| 227 | pattern_buf = token; |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 228 | |
| 229 | /* Get pattern mask */ |
| 230 | token = strsep(&sptr, " "); |
| 231 | if (!token) |
| 232 | return -EINVAL; |
| 233 | |
| 234 | pattern_mask = token; |
| 235 | pattern_mask[strlen(pattern_mask) - 1] = '\0'; |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 236 | |
| 237 | hdd_add_wowl_ptrn_debugfs(pAdapter, pattern_idx, pattern_offset, |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 238 | pattern_buf, pattern_mask); |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 239 | EXIT(); |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 240 | return count; |
| 241 | } |
| 242 | |
Mahesh A Saptasagar | d68eb28 | 2014-12-17 14:20:19 +0530 | [diff] [blame] | 243 | static ssize_t wcnss_wowpattern_write(struct file *file, |
| 244 | const char __user *buf, size_t count, loff_t *ppos) |
| 245 | { |
| 246 | ssize_t ret; |
| 247 | |
| 248 | vos_ssr_protect(__func__); |
| 249 | ret = __wcnss_wowpattern_write(file, buf, count, ppos); |
| 250 | vos_ssr_unprotect(__func__); |
| 251 | |
| 252 | return ret; |
| 253 | } |
| 254 | |
| 255 | static ssize_t __wcnss_patterngen_write(struct file *file, |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 256 | const char __user *buf, size_t count, loff_t *ppos) |
| 257 | { |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 258 | hdd_adapter_t *pAdapter; |
Wilson Yang | 0025634 | 2013-10-10 23:13:38 -0700 | [diff] [blame] | 259 | hdd_context_t *pHddCtx; |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 260 | tSirAddPeriodicTxPtrn *addPeriodicTxPtrnParams; |
| 261 | tSirDelPeriodicTxPtrn *delPeriodicTxPtrnParams; |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 262 | char *cmd, *sptr, *token; |
| 263 | v_U8_t pattern_idx = 0; |
| 264 | v_U8_t pattern_duration = 0; |
| 265 | char *pattern_buf; |
| 266 | v_U16_t pattern_len = 0; |
| 267 | v_U16_t i = 0; |
| 268 | |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 269 | ENTER(); |
| 270 | |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 271 | pAdapter = (hdd_adapter_t *)file->private_data; |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 272 | if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)) |
| 273 | { |
| 274 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, |
| 275 | "%s: Invalid adapter or adapter has invalid magic.", |
| 276 | __func__); |
| 277 | |
| 278 | return -EINVAL; |
| 279 | } |
Wilson Yang | 0025634 | 2013-10-10 23:13:38 -0700 | [diff] [blame] | 280 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 281 | if (0 != wlan_hdd_validate_context(pHddCtx)) |
| 282 | { |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 283 | return -EINVAL; |
| 284 | } |
Wilson Yang | 0025634 | 2013-10-10 23:13:38 -0700 | [diff] [blame] | 285 | |
Yue Ma | 55855df | 2013-08-26 10:59:03 -0700 | [diff] [blame] | 286 | if (!sme_IsFeatureSupportedByFW(WLAN_PERIODIC_TX_PTRN)) |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 287 | { |
| 288 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Yue Ma | 55855df | 2013-08-26 10:59:03 -0700 | [diff] [blame] | 289 | "%s: Periodic Tx Pattern Offload feature is not supported " |
| 290 | "in firmware!", __func__); |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 291 | |
| 292 | return -EINVAL; |
| 293 | } |
| 294 | |
| 295 | /* Get command from user */ |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 296 | if (count <= MAX_USER_COMMAND_SIZE_FRAME) |
Yue Ma | 63993e3 | 2013-10-21 23:10:53 -0700 | [diff] [blame] | 297 | cmd = vos_mem_malloc(count + 1); |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 298 | else |
| 299 | { |
| 300 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
Jeff Johnson | 401c9ae | 2013-11-13 17:40:46 -0800 | [diff] [blame] | 301 | "%s: Command length is larger than %d bytes.", |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 302 | __func__, MAX_USER_COMMAND_SIZE_FRAME); |
| 303 | |
| 304 | return -EINVAL; |
| 305 | } |
| 306 | |
Yue Ma | 5ac60e7 | 2013-11-16 01:03:02 -0800 | [diff] [blame] | 307 | if (!cmd) |
| 308 | { |
| 309 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 310 | "%s: Memory allocation for cmd failed!", __func__); |
| 311 | |
| 312 | return -EFAULT; |
| 313 | } |
| 314 | |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 315 | if (copy_from_user(cmd, buf, count)) |
| 316 | { |
| 317 | vos_mem_free(cmd); |
| 318 | return -EFAULT; |
| 319 | } |
| 320 | cmd[count] = '\0'; |
| 321 | sptr = cmd; |
| 322 | |
| 323 | /* Get pattern idx */ |
| 324 | token = strsep(&sptr, " "); |
| 325 | if (!token) |
| 326 | goto failure; |
| 327 | if (kstrtou8(token, 0, &pattern_idx)) |
| 328 | goto failure; |
| 329 | |
| 330 | if (pattern_idx > (MAXNUM_PERIODIC_TX_PTRNS - 1)) |
| 331 | { |
| 332 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 333 | "%s: Pattern index %d is not in the range (0 ~ %d).", |
| 334 | __func__, pattern_idx, MAXNUM_PERIODIC_TX_PTRNS - 1); |
| 335 | |
| 336 | goto failure; |
| 337 | } |
| 338 | |
| 339 | /* Get pattern duration */ |
| 340 | token = strsep(&sptr, " "); |
| 341 | if (!token) |
| 342 | goto failure; |
| 343 | if (kstrtou8(token, 0, &pattern_duration)) |
| 344 | goto failure; |
| 345 | |
Yue Ma | 5ac60e7 | 2013-11-16 01:03:02 -0800 | [diff] [blame] | 346 | /* Delete pattern using index if duration is 0 */ |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 347 | if (!pattern_duration) |
| 348 | { |
| 349 | delPeriodicTxPtrnParams = |
| 350 | vos_mem_malloc(sizeof(tSirDelPeriodicTxPtrn)); |
Yue Ma | 5ac60e7 | 2013-11-16 01:03:02 -0800 | [diff] [blame] | 351 | if (!delPeriodicTxPtrnParams) |
| 352 | { |
| 353 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 354 | "%s: Memory allocation for delPeriodicTxPtrnParams " |
| 355 | "failed!", __func__); |
| 356 | |
| 357 | vos_mem_free(cmd); |
| 358 | return -EFAULT; |
| 359 | } |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 360 | |
| 361 | delPeriodicTxPtrnParams->ucPatternIdBitmap = 1 << pattern_idx; |
| 362 | vos_mem_copy(delPeriodicTxPtrnParams->macAddress, |
| 363 | pAdapter->macAddressCurrent.bytes, 6); |
| 364 | |
| 365 | /* Delete pattern */ |
| 366 | if (eHAL_STATUS_SUCCESS != sme_DelPeriodicTxPtrn(pHddCtx->hHal, |
| 367 | delPeriodicTxPtrnParams)) |
| 368 | { |
| 369 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 370 | "%s: sme_DelPeriodicTxPtrn() failed!", __func__); |
| 371 | |
| 372 | vos_mem_free(delPeriodicTxPtrnParams); |
| 373 | goto failure; |
| 374 | } |
| 375 | |
| 376 | vos_mem_free(delPeriodicTxPtrnParams); |
| 377 | vos_mem_free(cmd); |
| 378 | return count; |
| 379 | } |
| 380 | |
Yue Ma | 55855df | 2013-08-26 10:59:03 -0700 | [diff] [blame] | 381 | /* Check if it's in connected state only when adding patterns */ |
| 382 | if (!hdd_connIsConnected(WLAN_HDD_GET_STATION_CTX_PTR(pAdapter))) |
| 383 | { |
| 384 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 385 | "%s: Not in Connected state!", __func__); |
Yue Ma | 5ac60e7 | 2013-11-16 01:03:02 -0800 | [diff] [blame] | 386 | |
| 387 | goto failure; |
Yue Ma | 55855df | 2013-08-26 10:59:03 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 390 | /* Get pattern */ |
| 391 | token = strsep(&sptr, " "); |
| 392 | if (!token) |
| 393 | goto failure; |
| 394 | |
| 395 | pattern_buf = token; |
| 396 | pattern_buf[strlen(pattern_buf) - 1] = '\0'; |
| 397 | pattern_len = strlen(pattern_buf); |
| 398 | |
| 399 | /* Since the pattern is a hex string, 2 characters represent 1 byte. */ |
| 400 | if (pattern_len % 2) |
| 401 | { |
| 402 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 403 | "%s: Malformed pattern!", __func__); |
| 404 | |
| 405 | goto failure; |
| 406 | } |
| 407 | else |
| 408 | pattern_len >>= 1; |
| 409 | |
| 410 | if (pattern_len < 14 || pattern_len > PERIODIC_TX_PTRN_MAX_SIZE) |
| 411 | { |
| 412 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 413 | "%s: Not an 802.3 frame!", __func__); |
| 414 | |
| 415 | goto failure; |
| 416 | } |
| 417 | |
| 418 | addPeriodicTxPtrnParams = vos_mem_malloc(sizeof(tSirAddPeriodicTxPtrn)); |
Yue Ma | 5ac60e7 | 2013-11-16 01:03:02 -0800 | [diff] [blame] | 419 | if (!addPeriodicTxPtrnParams) |
| 420 | { |
| 421 | VOS_TRACE(VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 422 | "%s: Memory allocation for addPeriodicTxPtrnParams " |
| 423 | "failed!", __func__); |
| 424 | |
| 425 | vos_mem_free(cmd); |
| 426 | return -EFAULT; |
| 427 | } |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 428 | |
| 429 | addPeriodicTxPtrnParams->ucPtrnId = pattern_idx; |
| 430 | addPeriodicTxPtrnParams->usPtrnIntervalMs = pattern_duration * 500; |
| 431 | addPeriodicTxPtrnParams->ucPtrnSize = pattern_len; |
| 432 | vos_mem_copy(addPeriodicTxPtrnParams->macAddress, |
| 433 | pAdapter->macAddressCurrent.bytes, 6); |
| 434 | |
| 435 | /* Extract the pattern */ |
| 436 | for(i = 0; i < addPeriodicTxPtrnParams->ucPtrnSize; i++) |
| 437 | { |
| 438 | addPeriodicTxPtrnParams->ucPattern[i] = |
| 439 | (hdd_parse_hex(pattern_buf[0]) << 4) + hdd_parse_hex(pattern_buf[1]); |
| 440 | |
| 441 | /* Skip to next byte */ |
| 442 | pattern_buf += 2; |
| 443 | } |
| 444 | |
| 445 | /* Add pattern */ |
| 446 | if (eHAL_STATUS_SUCCESS != sme_AddPeriodicTxPtrn(pHddCtx->hHal, |
| 447 | addPeriodicTxPtrnParams)) |
| 448 | { |
| 449 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR, |
| 450 | "%s: sme_AddPeriodicTxPtrn() failed!", __func__); |
| 451 | |
| 452 | vos_mem_free(addPeriodicTxPtrnParams); |
| 453 | goto failure; |
| 454 | } |
| 455 | |
| 456 | vos_mem_free(addPeriodicTxPtrnParams); |
| 457 | vos_mem_free(cmd); |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 458 | EXIT(); |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 459 | return count; |
| 460 | |
| 461 | failure: |
| 462 | vos_mem_free(cmd); |
Sameer Thalappil | b492efd | 2013-10-23 14:21:51 -0700 | [diff] [blame] | 463 | return -EINVAL; |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Mahesh A Saptasagar | d68eb28 | 2014-12-17 14:20:19 +0530 | [diff] [blame] | 466 | static ssize_t wcnss_patterngen_write(struct file *file, |
| 467 | const char __user *buf, size_t count, loff_t *ppos) |
| 468 | { |
| 469 | ssize_t ret; |
| 470 | |
| 471 | vos_ssr_protect(__func__); |
| 472 | ret = __wcnss_patterngen_write(file, buf, count, ppos); |
| 473 | vos_ssr_unprotect(__func__); |
| 474 | |
| 475 | return ret; |
| 476 | |
| 477 | } |
| 478 | |
| 479 | static int __wcnss_debugfs_open(struct inode *inode, struct file *file) |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 480 | { |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 481 | hdd_adapter_t *pAdapter; |
| 482 | hdd_context_t *pHddCtx; |
| 483 | |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 484 | ENTER(); |
| 485 | |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 486 | pAdapter = (hdd_adapter_t *)file->private_data; |
| 487 | if ((NULL == pAdapter) || (WLAN_HDD_ADAPTER_MAGIC != pAdapter->magic)) |
| 488 | { |
| 489 | VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_FATAL, |
| 490 | "%s: Invalid adapter or adapter has invalid magic.", |
| 491 | __func__); |
| 492 | return -EINVAL; |
| 493 | } |
| 494 | pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 495 | if (0 != wlan_hdd_validate_context(pHddCtx)) |
| 496 | { |
Mahesh A Saptasagar | 7408839 | 2015-02-05 17:22:09 +0530 | [diff] [blame] | 497 | return -EINVAL; |
| 498 | } |
| 499 | |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 500 | if (inode->i_private) |
| 501 | { |
| 502 | file->private_data = inode->i_private; |
| 503 | } |
Hanumantha Reddy Pothula | 7dc0e6c | 2015-03-06 15:11:16 +0530 | [diff] [blame] | 504 | EXIT(); |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 505 | return 0; |
| 506 | } |
| 507 | |
Mahesh A Saptasagar | d68eb28 | 2014-12-17 14:20:19 +0530 | [diff] [blame] | 508 | static int wcnss_debugfs_open(struct inode *inode, struct file *file) |
| 509 | { |
| 510 | int ret; |
| 511 | |
| 512 | vos_ssr_protect(__func__); |
| 513 | ret = __wcnss_debugfs_open(inode, file); |
| 514 | vos_ssr_unprotect(__func__); |
| 515 | |
| 516 | return ret; |
| 517 | } |
| 518 | |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 519 | static const struct file_operations fops_wowenable = { |
| 520 | .write = wcnss_wowenable_write, |
| 521 | .open = wcnss_debugfs_open, |
| 522 | .owner = THIS_MODULE, |
| 523 | .llseek = default_llseek, |
| 524 | }; |
| 525 | |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 526 | static const struct file_operations fops_wowpattern = { |
| 527 | .write = wcnss_wowpattern_write, |
| 528 | .open = wcnss_debugfs_open, |
| 529 | .owner = THIS_MODULE, |
| 530 | .llseek = default_llseek, |
| 531 | }; |
| 532 | |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 533 | static const struct file_operations fops_patterngen = { |
| 534 | .write = wcnss_patterngen_write, |
| 535 | .open = wcnss_debugfs_open, |
| 536 | .owner = THIS_MODULE, |
| 537 | .llseek = default_llseek, |
| 538 | }; |
| 539 | |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 540 | VOS_STATUS hdd_debugfs_init(hdd_adapter_t *pAdapter) |
| 541 | { |
| 542 | hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter); |
| 543 | pHddCtx->debugfs_phy = debugfs_create_dir("wlan_wcnss", 0); |
| 544 | |
| 545 | if (NULL == pHddCtx->debugfs_phy) |
| 546 | return VOS_STATUS_E_FAILURE; |
| 547 | |
Yue Ma | ddad6a7 | 2013-11-19 12:40:59 -0800 | [diff] [blame] | 548 | if (NULL == debugfs_create_file("wow_enable", S_IRUSR | S_IWUSR, |
| 549 | pHddCtx->debugfs_phy, pAdapter, &fops_wowenable)) |
| 550 | return VOS_STATUS_E_FAILURE; |
| 551 | |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 552 | if (NULL == debugfs_create_file("wow_pattern", S_IRUSR | S_IWUSR, |
| 553 | pHddCtx->debugfs_phy, pAdapter, &fops_wowpattern)) |
| 554 | return VOS_STATUS_E_FAILURE; |
| 555 | |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 556 | if (NULL == debugfs_create_file("pattern_gen", S_IRUSR | S_IWUSR, |
| 557 | pHddCtx->debugfs_phy, pAdapter, &fops_patterngen)) |
| 558 | return VOS_STATUS_E_FAILURE; |
| 559 | |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 560 | return VOS_STATUS_SUCCESS; |
| 561 | } |
| 562 | |
| 563 | void hdd_debugfs_exit(hdd_context_t *pHddCtx) |
| 564 | { |
| 565 | debugfs_remove_recursive(pHddCtx->debugfs_phy); |
| 566 | } |
Yue Ma | b9c86f4 | 2013-08-14 15:59:08 -0700 | [diff] [blame] | 567 | #endif /* #ifdef WLAN_OPEN_SOURCE */ |
Yue Ma | 0d4891e | 2013-08-06 17:01:45 -0700 | [diff] [blame] | 568 | |