blob: 30b60d6ae5463dae5838e4b85c21384445b02468 (
plain)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
// SPDX-License-Identifier: GPL-2.0+
/* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
#include <linux/nl80211.h>
#include "qlink_util.h"
u16 qlink_iface_type_to_nl_mask(u16 qlink_type)
{
u16 result = 0;
switch (qlink_type) {
case QLINK_IFTYPE_AP:
result |= BIT(NL80211_IFTYPE_AP);
break;
case QLINK_IFTYPE_STATION:
result |= BIT(NL80211_IFTYPE_STATION);
break;
case QLINK_IFTYPE_ADHOC:
result |= BIT(NL80211_IFTYPE_ADHOC);
break;
case QLINK_IFTYPE_MONITOR:
result |= BIT(NL80211_IFTYPE_MONITOR);
break;
case QLINK_IFTYPE_WDS:
result |= BIT(NL80211_IFTYPE_WDS);
break;
case QLINK_IFTYPE_AP_VLAN:
result |= BIT(NL80211_IFTYPE_AP_VLAN);
break;
}
return result;
}
u8 qlink_chan_width_mask_to_nl(u16 qlink_mask)
{
u8 result = 0;
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_5))
result |= BIT(NL80211_CHAN_WIDTH_5);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_10))
result |= BIT(NL80211_CHAN_WIDTH_10);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_20_NOHT))
result |= BIT(NL80211_CHAN_WIDTH_20_NOHT);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_20))
result |= BIT(NL80211_CHAN_WIDTH_20);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_40))
result |= BIT(NL80211_CHAN_WIDTH_40);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_80))
result |= BIT(NL80211_CHAN_WIDTH_80);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_80P80))
result |= BIT(NL80211_CHAN_WIDTH_80P80);
if (qlink_mask & BIT(QLINK_CHAN_WIDTH_160))
result |= BIT(NL80211_CHAN_WIDTH_160);
return result;
}
static enum nl80211_chan_width qlink_chanwidth_to_nl(u8 qlw)
{
switch (qlw) {
case QLINK_CHAN_WIDTH_20_NOHT:
return NL80211_CHAN_WIDTH_20_NOHT;
case QLINK_CHAN_WIDTH_20:
return NL80211_CHAN_WIDTH_20;
case QLINK_CHAN_WIDTH_40:
return NL80211_CHAN_WIDTH_40;
case QLINK_CHAN_WIDTH_80:
return NL80211_CHAN_WIDTH_80;
case QLINK_CHAN_WIDTH_80P80:
return NL80211_CHAN_WIDTH_80P80;
case QLINK_CHAN_WIDTH_160:
return NL80211_CHAN_WIDTH_160;
case QLINK_CHAN_WIDTH_5:
return NL80211_CHAN_WIDTH_5;
case QLINK_CHAN_WIDTH_10:
return NL80211_CHAN_WIDTH_10;
default:
return -1;
}
}
static u8 qlink_chanwidth_nl_to_qlink(enum nl80211_chan_width nlwidth)
{
switch (nlwidth) {
case NL80211_CHAN_WIDTH_20_NOHT:
return QLINK_CHAN_WIDTH_20_NOHT;
case NL80211_CHAN_WIDTH_20:
return QLINK_CHAN_WIDTH_20;
case NL80211_CHAN_WIDTH_40:
return QLINK_CHAN_WIDTH_40;
case NL80211_CHAN_WIDTH_80:
return QLINK_CHAN_WIDTH_80;
case NL80211_CHAN_WIDTH_80P80:
return QLINK_CHAN_WIDTH_80P80;
case NL80211_CHAN_WIDTH_160:
return QLINK_CHAN_WIDTH_160;
case NL80211_CHAN_WIDTH_5:
return QLINK_CHAN_WIDTH_5;
case NL80211_CHAN_WIDTH_10:
return QLINK_CHAN_WIDTH_10;
default:
return -1;
}
}
void qlink_chandef_q2cfg(struct wiphy *wiphy,
const struct qlink_chandef *qch,
struct cfg80211_chan_def *chdef)
{
struct ieee80211_channel *chan;
chan = ieee80211_get_channel(wiphy, le16_to_cpu(qch->chan.center_freq));
chdef->chan = chan;
chdef->center_freq1 = le16_to_cpu(qch->center_freq1);
chdef->center_freq2 = le16_to_cpu(qch->center_freq2);
chdef->width = qlink_chanwidth_to_nl(qch->width);
chdef->edmg.bw_config = 0;
chdef->edmg.channels = 0;
}
void qlink_chandef_cfg2q(const struct cfg80211_chan_def *chdef,
struct qlink_chandef *qch)
{
struct ieee80211_channel *chan = chdef->chan;
qch->chan.hw_value = cpu_to_le16(chan->hw_value);
qch->chan.center_freq = cpu_to_le16(chan->center_freq);
qch->chan.flags = cpu_to_le32(chan->flags);
qch->center_freq1 = cpu_to_le16(chdef->center_freq1);
qch->center_freq2 = cpu_to_le16(chdef->center_freq2);
qch->width = qlink_chanwidth_nl_to_qlink(chdef->width);
}
enum qlink_hidden_ssid qlink_hidden_ssid_nl2q(enum nl80211_hidden_ssid nl_val)
{
switch (nl_val) {
case NL80211_HIDDEN_SSID_ZERO_LEN:
return QLINK_HIDDEN_SSID_ZERO_LEN;
case NL80211_HIDDEN_SSID_ZERO_CONTENTS:
return QLINK_HIDDEN_SSID_ZERO_CONTENTS;
case NL80211_HIDDEN_SSID_NOT_IN_USE:
default:
return QLINK_HIDDEN_SSID_NOT_IN_USE;
}
}
bool qtnf_utils_is_bit_set(const u8 *arr, unsigned int bit,
unsigned int arr_max_len)
{
unsigned int idx = bit / BITS_PER_BYTE;
u8 mask = 1 << (bit - (idx * BITS_PER_BYTE));
if (idx >= arr_max_len)
return false;
return arr[idx] & mask;
}
void qlink_acl_data_cfg2q(const struct cfg80211_acl_data *acl,
struct qlink_acl_data *qacl)
{
switch (acl->acl_policy) {
case NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED:
qacl->policy =
cpu_to_le32(QLINK_ACL_POLICY_ACCEPT_UNLESS_LISTED);
break;
case NL80211_ACL_POLICY_DENY_UNLESS_LISTED:
qacl->policy = cpu_to_le32(QLINK_ACL_POLICY_DENY_UNLESS_LISTED);
break;
}
qacl->num_entries = cpu_to_le32(acl->n_acl_entries);
memcpy(qacl->mac_addrs, acl->mac_addrs,
acl->n_acl_entries * sizeof(*qacl->mac_addrs));
}
enum qlink_band qlink_utils_band_cfg2q(enum nl80211_band band)
{
switch (band) {
case NL80211_BAND_2GHZ:
return QLINK_BAND_2GHZ;
case NL80211_BAND_5GHZ:
return QLINK_BAND_5GHZ;
case NL80211_BAND_60GHZ:
return QLINK_BAND_60GHZ;
default:
return -EINVAL;
}
}
enum qlink_dfs_state qlink_utils_dfs_state_cfg2q(enum nl80211_dfs_state state)
{
switch (state) {
case NL80211_DFS_USABLE:
return QLINK_DFS_USABLE;
case NL80211_DFS_AVAILABLE:
return QLINK_DFS_AVAILABLE;
case NL80211_DFS_UNAVAILABLE:
default:
return QLINK_DFS_UNAVAILABLE;
}
}
u32 qlink_utils_chflags_cfg2q(u32 cfgflags)
{
u32 flags = 0;
if (cfgflags & IEEE80211_CHAN_DISABLED)
flags |= QLINK_CHAN_DISABLED;
if (cfgflags & IEEE80211_CHAN_NO_IR)
flags |= QLINK_CHAN_NO_IR;
if (cfgflags & IEEE80211_CHAN_RADAR)
flags |= QLINK_CHAN_RADAR;
if (cfgflags & IEEE80211_CHAN_NO_HT40PLUS)
flags |= QLINK_CHAN_NO_HT40PLUS;
if (cfgflags & IEEE80211_CHAN_NO_HT40MINUS)
flags |= QLINK_CHAN_NO_HT40MINUS;
if (cfgflags & IEEE80211_CHAN_NO_80MHZ)
flags |= QLINK_CHAN_NO_80MHZ;
if (cfgflags & IEEE80211_CHAN_NO_160MHZ)
flags |= QLINK_CHAN_NO_160MHZ;
return flags;
}
static u32 qtnf_reg_rule_flags_parse(u32 qflags)
{
u32 flags = 0;
if (qflags & QLINK_RRF_NO_OFDM)
flags |= NL80211_RRF_NO_OFDM;
if (qflags & QLINK_RRF_NO_CCK)
flags |= NL80211_RRF_NO_CCK;
if (qflags & QLINK_RRF_NO_INDOOR)
flags |= NL80211_RRF_NO_INDOOR;
if (qflags & QLINK_RRF_NO_OUTDOOR)
flags |= NL80211_RRF_NO_OUTDOOR;
if (qflags & QLINK_RRF_DFS)
flags |= NL80211_RRF_DFS;
if (qflags & QLINK_RRF_PTP_ONLY)
flags |= NL80211_RRF_PTP_ONLY;
if (qflags & QLINK_RRF_PTMP_ONLY)
flags |= NL80211_RRF_PTMP_ONLY;
if (qflags & QLINK_RRF_NO_IR)
flags |= NL80211_RRF_NO_IR;
if (qflags & QLINK_RRF_AUTO_BW)
flags |= NL80211_RRF_AUTO_BW;
if (qflags & QLINK_RRF_IR_CONCURRENT)
flags |= NL80211_RRF_IR_CONCURRENT;
if (qflags & QLINK_RRF_NO_HT40MINUS)
flags |= NL80211_RRF_NO_HT40MINUS;
if (qflags & QLINK_RRF_NO_HT40PLUS)
flags |= NL80211_RRF_NO_HT40PLUS;
if (qflags & QLINK_RRF_NO_80MHZ)
flags |= NL80211_RRF_NO_80MHZ;
if (qflags & QLINK_RRF_NO_160MHZ)
flags |= NL80211_RRF_NO_160MHZ;
return flags;
}
void qlink_utils_regrule_q2nl(struct ieee80211_reg_rule *rule,
const struct qlink_tlv_reg_rule *tlv)
{
rule->freq_range.start_freq_khz = le32_to_cpu(tlv->start_freq_khz);
rule->freq_range.end_freq_khz = le32_to_cpu(tlv->end_freq_khz);
rule->freq_range.max_bandwidth_khz =
le32_to_cpu(tlv->max_bandwidth_khz);
rule->power_rule.max_antenna_gain = le32_to_cpu(tlv->max_antenna_gain);
rule->power_rule.max_eirp = le32_to_cpu(tlv->max_eirp);
rule->dfs_cac_ms = le32_to_cpu(tlv->dfs_cac_ms);
rule->flags = qtnf_reg_rule_flags_parse(le32_to_cpu(tlv->flags));
}
|