Hanumanth Reddy Pothula | 3def894 | 2017-10-05 16:19:36 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The Linux Foundation. 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_hdd_packet_filter.c |
| 21 | * |
| 22 | * WLAN Host Device Driver implementation |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* Include Files */ |
| 27 | #include "wlan_hdd_packet_filter_api.h" |
SaidiReddy Yenuga | 744073f | 2017-03-09 17:31:25 +0530 | [diff] [blame] | 28 | #include "wlan_hdd_packet_filter_rules.h" |
Hanumanth Reddy Pothula | 3def894 | 2017-10-05 16:19:36 +0530 | [diff] [blame] | 29 | |
| 30 | int hdd_enable_default_pkt_filters(struct hdd_adapter *adapter) |
| 31 | { |
| 32 | struct hdd_context *hdd_ctx; |
| 33 | uint8_t filters = 0, i = 0, filter_id = 1; |
| 34 | |
| 35 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 36 | if (hdd_ctx == NULL) { |
| 37 | hdd_err("HDD context is Null!!!"); |
| 38 | return -EINVAL; |
| 39 | } |
SaidiReddy Yenuga | 744073f | 2017-03-09 17:31:25 +0530 | [diff] [blame] | 40 | if (hdd_ctx->user_configured_pkt_filter_rules) { |
Hanumanth Reddy Pothula | 3def894 | 2017-10-05 16:19:36 +0530 | [diff] [blame] | 41 | hdd_info("user has defined pkt filter run hence skipping default packet filter rule"); |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | filters = hdd_ctx->config->packet_filters_bitmap; |
| 46 | |
| 47 | while (filters != 0) { |
| 48 | if (filters & 0x1) { |
| 49 | hdd_err("setting filter[%d], of id = %d", |
| 50 | i+1, filter_id); |
| 51 | packet_filter_default_rules[i].filter_id = filter_id; |
| 52 | wlan_hdd_set_filter(hdd_ctx, |
| 53 | &packet_filter_default_rules[i], |
Jeff Johnson | 1b780e4 | 2017-10-31 14:11:45 -0700 | [diff] [blame] | 54 | adapter->session_id); |
Hanumanth Reddy Pothula | 3def894 | 2017-10-05 16:19:36 +0530 | [diff] [blame] | 55 | filter_id++; |
| 56 | } |
| 57 | filters = filters >> 1; |
| 58 | i++; |
| 59 | } |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | int hdd_disable_default_pkt_filters(struct hdd_adapter *adapter) |
| 65 | { |
| 66 | struct hdd_context *hdd_ctx; |
| 67 | uint8_t filters = 0, i = 0, filter_id = 1; |
| 68 | |
| 69 | struct pkt_filter_cfg packet_filter_default_rules; |
| 70 | |
| 71 | hdd_ctx = WLAN_HDD_GET_CTX(adapter); |
| 72 | if (hdd_ctx == NULL) { |
| 73 | hdd_err("HDD context is Null!!!"); |
| 74 | return -EINVAL; |
| 75 | } |
| 76 | |
SaidiReddy Yenuga | 744073f | 2017-03-09 17:31:25 +0530 | [diff] [blame] | 77 | if (hdd_ctx->user_configured_pkt_filter_rules) { |
Hanumanth Reddy Pothula | 3def894 | 2017-10-05 16:19:36 +0530 | [diff] [blame] | 78 | hdd_info("user has defined pkt filter run hence skipping default packet filter rule"); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | filters = hdd_ctx->config->packet_filters_bitmap; |
| 83 | |
| 84 | while (filters != 0) { |
| 85 | if (filters & 0x1) { |
| 86 | hdd_err("Clearing filter[%d], of id = %d", |
| 87 | i+1, filter_id); |
| 88 | packet_filter_default_rules.filter_action = |
| 89 | HDD_RCV_FILTER_CLEAR; |
SaidiReddy Yenuga | 744073f | 2017-03-09 17:31:25 +0530 | [diff] [blame] | 90 | packet_filter_default_rules.filter_id = filter_id; |
Hanumanth Reddy Pothula | 3def894 | 2017-10-05 16:19:36 +0530 | [diff] [blame] | 91 | wlan_hdd_set_filter(hdd_ctx, |
| 92 | &packet_filter_default_rules, |
Jeff Johnson | 1b780e4 | 2017-10-31 14:11:45 -0700 | [diff] [blame] | 93 | adapter->session_id); |
Hanumanth Reddy Pothula | 3def894 | 2017-10-05 16:19:36 +0530 | [diff] [blame] | 94 | filter_id++; |
| 95 | } |
| 96 | filters = filters >> 1; |
| 97 | i++; |
| 98 | } |
| 99 | |
| 100 | return 0; |
| 101 | } |