blob: a1ef3f087c2076d91d1cea3cf486d7d50101cf01 [file] [log] [blame]
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +05301/*
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 Yenuga744073f2017-03-09 17:31:25 +053028#include "wlan_hdd_packet_filter_rules.h"
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +053029
30int 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 Yenuga744073f2017-03-09 17:31:25 +053040 if (hdd_ctx->user_configured_pkt_filter_rules) {
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +053041 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 Johnson1b780e42017-10-31 14:11:45 -070054 adapter->session_id);
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +053055 filter_id++;
56 }
57 filters = filters >> 1;
58 i++;
59 }
60
61 return 0;
62}
63
64int 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 Yenuga744073f2017-03-09 17:31:25 +053077 if (hdd_ctx->user_configured_pkt_filter_rules) {
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +053078 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 Yenuga744073f2017-03-09 17:31:25 +053090 packet_filter_default_rules.filter_id = filter_id;
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +053091 wlan_hdd_set_filter(hdd_ctx,
92 &packet_filter_default_rules,
Jeff Johnson1b780e42017-10-31 14:11:45 -070093 adapter->session_id);
Hanumanth Reddy Pothula3def8942017-10-05 16:19:36 +053094 filter_id++;
95 }
96 filters = filters >> 1;
97 i++;
98 }
99
100 return 0;
101}