-
Notifications
You must be signed in to change notification settings - Fork 119
/
utils.h
170 lines (138 loc) · 4.17 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright (C) 2006-2018, Marvell International Ltd.
*
* This software file (the "File") is distributed by Marvell International
* Ltd. under the terms of the GNU General Public License Version 2, June 1991
* (the "License"). You may use, redistribute and/or modify this File in
* accordance with the terms and conditions of the License, a copy of which
* is available by writing to the Free Software Foundation, Inc.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
*/
/* Description: This file defines common utility functions. */
#ifndef _UTILS_H_
#define _UTILS_H_
#include <net/arp.h>
#include <net/ip.h>
#include <net/udp.h>
#include <net/icmp.h>
/* DHCP message types */
#define DHCPDISCOVER 1
#define DHCPOFFER 2
#define DHCPREQUEST 3
#define DHCPDECLINE 4
#define DHCPACK 5
#define DHCPNAK 6
#define DHCPRELEASE 7
#define DHCPINFORM 8
static inline bool utils_is_crypted(struct ieee80211_hdr *wh)
{
if (!ieee80211_has_protected(wh->frame_control))
return false;
if (ieee80211_is_auth(wh->frame_control))
return false;
return true;
}
static inline int utils_tid_to_ac(u8 tid)
{
switch (tid) {
case 0:
case 3:
return IEEE80211_AC_BE;
case 1:
case 2:
return IEEE80211_AC_BK;
case 4:
case 5:
return IEEE80211_AC_VI;
case 6:
case 7:
return IEEE80211_AC_VO;
default:
break;
}
return -1;
}
static inline void utils_add_basic_rates(int band, struct sk_buff *skb)
{
struct ieee80211_mgmt *mgmt;
int len;
u8 *pos;
mgmt = (struct ieee80211_mgmt *)skb->data;
len = skb->len - ieee80211_hdrlen(mgmt->frame_control);
len -= 4;
pos = (u8 *)cfg80211_find_ie(WLAN_EID_SUPP_RATES,
mgmt->u.assoc_req.variable,
len);
if (pos) {
pos++;
len = *pos++;
while (len) {
if (band == NL80211_BAND_2GHZ) {
if ((*pos == 2) || (*pos == 4) ||
(*pos == 11) || (*pos == 22))
*pos |= 0x80;
} else {
if ((*pos == 12) || (*pos == 24) ||
(*pos == 48))
*pos |= 0x80;
}
pos++;
len--;
}
}
}
static inline int utils_assign_stnid(struct mwl_priv *priv, int macid, u16 aid)
{
int stnid;
int i;
spin_lock_bh(&priv->stnid_lock);
stnid = priv->available_stnid;
if (stnid >= priv->stnid_num) {
spin_unlock_bh(&priv->stnid_lock);
return 0;
}
priv->stnid[stnid].macid = macid;
priv->stnid[stnid].aid = aid;
stnid++;
for (i = stnid; i < priv->stnid_num; i++) {
if (!priv->stnid[i].aid)
break;
}
priv->available_stnid = i;
spin_unlock_bh(&priv->stnid_lock);
return stnid;
}
static inline void utils_free_stnid(struct mwl_priv *priv, u16 stnid)
{
spin_lock_bh(&priv->stnid_lock);
if (stnid && (stnid <= priv->stnid_num)) {
stnid--;
priv->stnid[stnid].macid = 0;
priv->stnid[stnid].aid = 0;
if (priv->available_stnid > stnid)
priv->available_stnid = stnid;
}
spin_unlock_bh(&priv->stnid_lock);
}
int utils_get_phy_rate(u8 format, u8 bandwidth, u8 short_gi, u8 mcs_id);
u8 utils_get_rate_id(u8 rate);
u32 utils_get_init_tx_rate(struct mwl_priv *priv, struct ieee80211_conf *conf,
struct ieee80211_sta *sta);
struct mwl_vif *utils_find_vif_bss(struct mwl_priv *priv, u8 *bssid);
struct mwl_sta *utils_find_sta(struct mwl_priv *priv, u8 *addr);
struct mwl_sta *utils_find_sta_by_aid(struct mwl_priv *priv, u16 aid);
struct mwl_sta *utils_find_sta_by_id(struct mwl_priv *priv, u16 stnid);
void utils_dump_data_info(const char *prefix_str, const void *buf, size_t len);
void utils_dump_data_debug(const char *prefix_str, const void *buf, size_t len);
bool utils_is_non_amsdu_packet(const void *packet, bool mac80211);
bool utils_is_arp(const void *packet, bool mac80211, u16 *arp_op);
bool utils_is_icmp_echo(const void *packet, bool mac80211, u8 *type);
bool utils_is_dhcp(const void *packet, bool mac80211, u8 *op, u8 *dhcp_client);
void utils_dump_arp(const void *packet, bool mac80211, size_t len);
void utils_dump_icmp_echo(const void *packet, bool mac80211, size_t len);
void utils_dump_dhcp(const void *packet, bool mac80211, size_t len);
#endif /* _UTILS_H_ */