aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/audit.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/audit.c')
-rw-r--r--kernel/audit.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/kernel/audit.c b/kernel/audit.c
index 4414e93d8750..ce6d8ea3131e 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -61,8 +61,11 @@
61 61
62#include "audit.h" 62#include "audit.h"
63 63
64/* No auditing will take place until audit_initialized != 0. 64/* No auditing will take place until audit_initialized == AUDIT_INITIALIZED.
65 * (Initialization happens after skb_init is called.) */ 65 * (Initialization happens after skb_init is called.) */
66#define AUDIT_DISABLED -1
67#define AUDIT_UNINITIALIZED 0
68#define AUDIT_INITIALIZED 1
66static int audit_initialized; 69static int audit_initialized;
67 70
68#define AUDIT_OFF 0 71#define AUDIT_OFF 0
@@ -965,6 +968,9 @@ static int __init audit_init(void)
965{ 968{
966 int i; 969 int i;
967 970
971 if (audit_initialized == AUDIT_DISABLED)
972 return 0;
973
968 printk(KERN_INFO "audit: initializing netlink socket (%s)\n", 974 printk(KERN_INFO "audit: initializing netlink socket (%s)\n",
969 audit_default ? "enabled" : "disabled"); 975 audit_default ? "enabled" : "disabled");
970 audit_sock = netlink_kernel_create(&init_net, NETLINK_AUDIT, 0, 976 audit_sock = netlink_kernel_create(&init_net, NETLINK_AUDIT, 0,
@@ -976,7 +982,7 @@ static int __init audit_init(void)
976 982
977 skb_queue_head_init(&audit_skb_queue); 983 skb_queue_head_init(&audit_skb_queue);
978 skb_queue_head_init(&audit_skb_hold_queue); 984 skb_queue_head_init(&audit_skb_hold_queue);
979 audit_initialized = 1; 985 audit_initialized = AUDIT_INITIALIZED;
980 audit_enabled = audit_default; 986 audit_enabled = audit_default;
981 audit_ever_enabled |= !!audit_default; 987 audit_ever_enabled |= !!audit_default;
982 988
@@ -999,13 +1005,21 @@ __initcall(audit_init);
999static int __init audit_enable(char *str) 1005static int __init audit_enable(char *str)
1000{ 1006{
1001 audit_default = !!simple_strtol(str, NULL, 0); 1007 audit_default = !!simple_strtol(str, NULL, 0);
1002 printk(KERN_INFO "audit: %s%s\n", 1008 if (!audit_default)
1003 audit_default ? "enabled" : "disabled", 1009 audit_initialized = AUDIT_DISABLED;
1004 audit_initialized ? "" : " (after initialization)"); 1010
1005 if (audit_initialized) { 1011 printk(KERN_INFO "audit: %s", audit_default ? "enabled" : "disabled");
1012
1013 if (audit_initialized == AUDIT_INITIALIZED) {
1006 audit_enabled = audit_default; 1014 audit_enabled = audit_default;
1007 audit_ever_enabled |= !!audit_default; 1015 audit_ever_enabled |= !!audit_default;
1016 } else if (audit_initialized == AUDIT_UNINITIALIZED) {
1017 printk(" (after initialization)");
1018 } else {
1019 printk(" (until reboot)");
1008 } 1020 }
1021 printk("\n");
1022
1009 return 1; 1023 return 1;
1010} 1024}
1011 1025
@@ -1107,9 +1121,7 @@ unsigned int audit_serial(void)
1107static inline void audit_get_stamp(struct audit_context *ctx, 1121static inline void audit_get_stamp(struct audit_context *ctx,
1108 struct timespec *t, unsigned int *serial) 1122 struct timespec *t, unsigned int *serial)
1109{ 1123{
1110 if (ctx) 1124 if (!ctx || !auditsc_get_stamp(ctx, t, serial)) {
1111 auditsc_get_stamp(ctx, t, serial);
1112 else {
1113 *t = CURRENT_TIME; 1125 *t = CURRENT_TIME;
1114 *serial = audit_serial(); 1126 *serial = audit_serial();
1115 } 1127 }
@@ -1146,7 +1158,7 @@ struct audit_buffer *audit_log_start(struct audit_context *ctx, gfp_t gfp_mask,
1146 int reserve; 1158 int reserve;
1147 unsigned long timeout_start = jiffies; 1159 unsigned long timeout_start = jiffies;
1148 1160
1149 if (!audit_initialized) 1161 if (audit_initialized != AUDIT_INITIALIZED)
1150 return NULL; 1162 return NULL;
1151 1163
1152 if (unlikely(audit_filter_type(type))) 1164 if (unlikely(audit_filter_type(type)))
f338a528f44fd90496adfbfd9c119401850'>4ee73f338a52
8318d78a44d4

c2d1560ad8c2
25d834e16294
c2d1560ad8c2
438b61b77082
25d834e16294
c2d1560ad8c2
8318d78a44d4
25d834e16294

bda3933a8ace
25d834e16294

438b61b77082
25d834e16294
8318d78a44d4
4ee73f338a52
438b61b77082
c2d1560ad8c2




32bfd35d4b63

e039fa4a4195
c2d1560ad8c2


25d834e16294
471b3efdfccc
2103dec14792
c2d1560ad8c2
2e92e6f2c50b

4ee73f338a52
c2d1560ad8c2
25d834e16294
7e9ed18874f0
e039fa4a4195
8318d78a44d4

25d834e16294

bda3933a8ace
25d834e16294

438b61b77082
25d834e16294
c2d1560ad8c2
2103dec14792

c2d1560ad8c2
2103dec14792
438b61b77082
c2d1560ad8c2
2103dec14792
438b61b77082
c2d1560ad8c2
2103dec14792
438b61b77082
c2d1560ad8c2




32bfd35d4b63

c2d1560ad8c2
e039fa4a4195
c2d1560ad8c2


25d834e16294
471b3efdfccc
2103dec14792
c2d1560ad8c2
2e92e6f2c50b

4ee73f338a52
c2d1560ad8c2
25d834e16294
7e9ed18874f0
e039fa4a4195
8318d78a44d4
25d834e16294

bda3933a8ace
25d834e16294

438b61b77082
25d834e16294
c2d1560ad8c2
2103dec14792

c2d1560ad8c2
2103dec14792
438b61b77082
e039fa4a4195
c2d1560ad8c2
2103dec14792
438b61b77082
c2d1560ad8c2





3a25a8c8b75b


a6f38ac3cc85



3a25a8c8b75b



f142c6b906da


3a25a8c8b75b






a6f38ac3cc85
3a25a8c8b75b










ce7c9111a974

c2d1560ad8c2


b5878a2dc5e7

e4e72fb4de93

ce7c9111a974
ada151252655


96f5e66e8a79





7236fe29fd72

3a25a8c8b75b
7236fe29fd72

3b8d81e020f7
c2d1560ad8c2
ce7c9111a974
96f5e66e8a79

ce7c9111a974













c2d1560ad8c2

ce7c9111a974

c2d1560ad8c2

cf0277e714a0
a6f38ac3cc85
c2d1560ad8c2
b5878a2dc5e7

e4e72fb4de93

96f5e66e8a79
ada151252655


2a577d98712a
cf0277e714a0
a6f38ac3cc85


cf0277e714a0
3a25a8c8b75b


f142c6b906da


a6f38ac3cc85
3a25a8c8b75b




cf0277e714a0
c2d1560ad8c2
ce7c9111a974
96f5e66e8a79

ce7c9111a974













c2d1560ad8c2

8f77f3849cc3




a7bc376c858e
3a25a8c8b75b
a7bc376c858e

d4fa14cd62bd
a7bc376c858e

8f77f3849cc3


3b8d81e020f7
8f77f3849cc3



b0b97a8ad5c4


8f77f3849cc3



b0b97a8ad5c4
8f77f3849cc3

8f77f3849cc3
a7bc376c858e


d4fa14cd62bd
a7bc376c858e


3a25a8c8b75b
4644ae890338



3b8d81e020f7
8f77f3849cc3

50a9432daeec


3b8d81e020f7
8f77f3849cc3

8f77f3849cc3
8f77f3849cc3

ce7c9111a974
445ea4e83ec5

c2d1560ad8c2
ce7c9111a974

c2d1560ad8c2

ce7c9111a974

445ea4e83ec5
ce7c9111a974






445ea4e83ec5
ce7c9111a974
c2d1560ad8c2


92ab85354993


3b8d81e020f7

96f5e66e8a79
e4e72fb4de93

96f5e66e8a79
3b8d81e020f7
2419ea14bb0d

3b8d81e020f7

92ab85354993


ce7c9111a974
445ea4e83ec5
ce7c9111a974
c2d1560ad8c2
ce7c9111a974

c2d1560ad8c2

ce7c9111a974

445ea4e83ec5
ce7c9111a974






445ea4e83ec5

c2d1560ad8c2

dabeb344f54a
39ecc01d1bbe





















445ea4e83ec5


39ecc01d1bbe
445ea4e83ec5


39ecc01d1bbe

32bfd35d4b63
8b2c98243e8d
32bfd35d4b63


dabeb344f54a



c771c9d8da1e
2f561feb386d


05c914fe330f
31eba5bc56a9


05c914fe330f
2f561feb386d
2ca27bcff712
2f561feb386d

8b2c98243e8d


9607e6b66a0d
47846c9b0c10
2f561feb386d


685fb72b63fa

8b2c98243e8d


685fb72b63fa

c771c9d8da1e
2f561feb386d



8b2c98243e8d
2f561feb386d






e38bad4766a1
dabeb344f54a
e38bad4766a1
51fb61e76d95
05c914fe330f
31eba5bc56a9


05c914fe330f
dabeb344f54a
2ca27bcff712
dabeb344f54a

8b2c98243e8d


9607e6b66a0d
47846c9b0c10
32bfd35d4b63
dabeb344f54a
e38bad4766a1
685fb72b63fa
8b2c98243e8d


685fb72b63fa

e38bad4766a1
dabeb344f54a
2f561feb386d
37ffc8da803a
42935ecaf4e7








ceb99fe071eb


42935ecaf4e7



























35d865afbbdf
dd76986b0e39



35d865afbbdf
dd76986b0e39
fcff4f108dce
b2e506bfc4d7
dd76986b0e39
fcff4f108dce
dd76986b0e39





fcff4f108dce
dd76986b0e39




fcff4f108dce

dd76986b0e39
fcff4f108dce

9690fb169b43



























85220d71bf3c
b2e506bfc4d7




9690fb169b43






fcff4f108dce
dd76986b0e39



fcff4f108dce

dd76986b0e39








dd76986b0e39
1cd8e88e1772



dd76986b0e39
dd76986b0e39



fcff4f108dce

dd76986b0e39
dd76986b0e39











441a33baf180
dd76986b0e39















1946bed95707



dd76986b0e39







fcff4f108dce

dd76986b0e39
074d46d1d23f


fcff4f108dce

dd76986b0e39
818255ea4770











bee7f58699a4





dd76986b0e39






fcff4f108dce

dd76986b0e39




3f52b7e328c5



dd76986b0e39














fcff4f108dce

dd76986b0e39

5bc1420b1190




dd76986b0e39
b4f286a1c0ad






85220d71bf3c






b2e506bfc4d7



























dd76986b0e39




761a48d2603c



dd76986b0e39
dd76986b0e39

79ba1d8910f5



dd76986b0e39




fcff4f108dce


5df45690e78f
fcff4f108dce
dd76986b0e39



fcff4f108dce


dd76986b0e39


3abead59fcde

5825fe100d65


55de908ab292
54bcbc695e2c
a8ce85442e8e
aa837e1d6bd1
5825fe100d65



54bcbc695e2c


5825fe100d65

55de908ab292


4bf88530be97
aa837e1d6bd1
55de908ab292
5825fe100d65
a8ce85442e8e






54bcbc695e2c
aa837e1d6bd1






a8ce85442e8e




































7ba10a8efe50

aa837e1d6bd1
aa837e1d6bd1
aa837e1d6bd1
5825fe100d65
ab13315af979

54bcbc695e2c

aa837e1d6bd1
e1b3ec1a2a33
f142c6b906da

a8ce85442e8e
3abead59fcde


d97349797fa7
5825fe100d65
e50db65c0dad
469002983fc9
700e8ea6770d
4a3cb702b058
1672c0e31917

469002983fc9



fffd0934b939
469002983fc9

65fc73ac4a31
d15b84590a1d
469002983fc9
d15b84590a1d
469002983fc9





efa6a09db6d6
47846c9b0c10
469002983fc9


700e8ea6770d
469002983fc9

469002983fc9
fffd0934b939





1672c0e31917

62ae67be31c2
469002983fc9

6ae16775d6bc






































de95a54b1aeb
c604b9f21942
651b52254fc0
2103dec14792
de95a54b1aeb

c604b9f21942
8e664fb3fd2b

8dcb20038ade


2103dec14792

de95a54b1aeb
4d36ec58239e
d811b3d5566f

de95a54b1aeb
2103dec14792


8dcb20038ade



2103dec14792





8dcb20038ade


8e664fb3fd2b
c604b9f21942

de95a54b1aeb
8e664fb3fd2b
8dcb20038ade

8e664fb3fd2b











c604b9f21942

8e664fb3fd2b




8dcb20038ade

c604b9f21942

8e664fb3fd2b
8dcb20038ade


8e664fb3fd2b

2103dec14792
c604b9f21942

651b52254fc0

2103dec14792

651b52254fc0

8e664fb3fd2b












c604b9f21942

8e664fb3fd2b


de95a54b1aeb

c604b9f21942


ef96a84202cc

c604b9f21942
5ef2d41afb7f
de95a54b1aeb




8e664fb3fd2b


c604b9f21942

8e664fb3fd2b

de95a54b1aeb

c604b9f21942


ba0afa2f22e1

c604b9f21942
ba0afa2f22e1
de95a54b1aeb
c604b9f21942


de95a54b1aeb

a619a4c0e1fd
85a237fe3084
6b77863b719a
a619a4c0e1fd
a806c558e017

469002983fc9

2103dec14792
469002983fc9

b9a9ada14aab
469002983fc9
a806c558e017




2103dec14792
a806c558e017
2103dec14792
a806c558e017
2103dec14792
651b52254fc0
7c12ce8b854d
b9a9ada14aab
5b2bbf75a24d
b9a9ada14aab




2103dec14792
b9a9ada14aab
7c12ce8b854d
469002983fc9
7c12ce8b854d
469002983fc9

469002983fc9
469002983fc9
62ae67be31c2
5b2bbf75a24d
a619a4c0e1fd




a806c558e017
1672c0e31917
55de908ab292
a619a4c0e1fd


fe94fe05e9fb
6b77863b719a
85a237fe3084
aad14ceb45f5
1672c0e31917
55de908ab292



aad14ceb45f5
469002983fc9

2103dec14792
469002983fc9
9ebb61a23d90
469002983fc9



2103dec14792





469002983fc9
4ee73f338a52

469002983fc9







9ebb61a23d90
469002983fc9





9ebb61a23d90





2103dec14792








469002983fc9
9ebb61a23d90



469002983fc9


f2753ddbadb0
84f6a01ce05f


67408c8c7b9d
84f6a01ce05f

84f6a01ce05f

678f415fdc53
84f6a01ce05f

153a5fc41079


















f2753ddbadb0



55de908ab292
f2753ddbadb0
2683d65bb016
d888130a024d

8f21b0adfe95
ceb99fe071eb

f2753ddbadb0
eecc48000afe
eecc48000afe
27b3eb9c06a7
eecc48000afe










d888130a024d
eecc48000afe

94f9b97be5b3


f2753ddbadb0
94f9b97be5b3











f2753ddbadb0

7f2819756011








94f9b97be5b3



f2753ddbadb0
4b6f1dd6a6fa

3c3e21e7443b

4b6f1dd6a6fa







f2753ddbadb0


1ed32e4fc8cf
7b7eab6fc1bc
f2753ddbadb0

55de908ab292
f0dea9c73a16





55de908ab292
6352c87ff69d
6352c87ff69d

153a5fc41079
6352c87ff69d

fe5f255930af
153a5fc41079

fe5f255930af
f2753ddbadb0
34e895075e21

2e8d397eeeb1
f09603a259ff
2e8d397eeeb1










f2753ddbadb0
34e895075e21
f2753ddbadb0
2683d65bb016
54bcbc695e2c





f6f3def323e5
54bcbc695e2c



f6f3def323e5
2683d65bb016
f2753ddbadb0


f2753ddbadb0
f2753ddbadb0


ac8dd506e40e

9607e6b66a0d
f2753ddbadb0
ac8dd506e40e








4ced3f74dae1
55de47f65f66
1ea6f9c0d48b

ac8dd506e40e
f2753ddbadb0

0d392e938b55
ab09587740fd

c65dd1477b6f
989c6505cdda


c65dd1477b6f
8d61ffa5e01c
ac8dd506e40e
8d61ffa5e01c
ac8dd506e40e
f2753ddbadb0
ac8dd506e40e

f2753ddbadb0
339afbf4819e
e7979ac7826e
1041638f2bba
e7979ac7826e

1041638f2bba



7827493b886c
f2753ddbadb0
8da349329ae5




f2753ddbadb0






98104fdeda63
f142c6b906da

f2753ddbadb0
2e161f78e5f6
2ca27bcff712

f2753ddbadb0




8e1b23b9ed42

2a419056c154
6e1b1b246096








20f544eea03d

6e1b1b246096




2e8d397eeeb1

















7b21aea04d08




c62094889f7b
04800ada2acc


3c3e21e7443b


6e1b1b246096
2a419056c154








74e2bd1fa3ae
2a419056c154


c82c4a80bbb9

c2c98fdeb5c8
74e2bd1fa3ae
2a419056c154

74e2bd1fa3ae
74e2bd1fa3ae
445ea4e83ec5

f2753ddbadb0
5bb644a0fd25



8f21b0adfe95
9214ad7f9a0b
8f21b0adfe95

5bb644a0fd25


ceb99fe071eb
5bb644a0fd25
ceb99fe071eb

5bb644a0fd25
b8360ab8d2ca






26d59535aa08
5bb644a0fd25


f2753ddbadb0

42935ecaf4e7
95acac61ba66


























04ecd2578e71
0f78231bffb8
04ecd2578e71


025e6be220e4
04ecd2578e71
0f78231bffb8
04ecd2578e71

0f78231bffb8
04ecd2578e71
5d8e4237d2dc
0f78231bffb8
04ecd2578e71

5d8e4237d2dc
04ecd2578e71
0f78231bffb8
8e664fb3fd2b























































615f7b9bb1f8







































768db3438b4b
ef96a84202cc
42e7aa771196













ef96a84202cc

42e7aa771196


ef96a84202cc

42e7aa771196












ba0afa2f22e1
cc3983d8ab17
ba0afa2f22e1



d4950281d72d

ba0afa2f22e1












074d46d1d23f
4bf88530be97
431e31542383
42e7aa771196
074d46d1d23f
42e7aa771196
074d46d1d23f


4bf88530be97










42e7aa771196
42e7aa771196
074d46d1d23f
42e7aa771196

aee286c2cf94
4bf88530be97

074d46d1d23f
ff3cc5f40f36
431e31542383
074d46d1d23f
42e7aa771196


074d46d1d23f

42e7aa771196
074d46d1d23f
42e7aa771196

4bf88530be97
4a3cb702b058
4bf88530be97
42e7aa771196


4bf88530be97




42e7aa771196
074d46d1d23f
42e7aa771196












4bf88530be97
42e7aa771196

2103dec14792





























fc8a7321d3d6
6b77863b719a

768db3438b4b
768db3438b4b

2103dec14792
768db3438b4b
fc8a7321d3d6
2103dec14792
768db3438b4b
2103dec14792

6b77863b719a
2103dec14792





768db3438b4b









657c3e0c4147
2103dec14792


657c3e0c4147

768db3438b4b
2103dec14792


768db3438b4b




fc8a7321d3d6
6b77863b719a

768db3438b4b
768db3438b4b

2103dec14792
768db3438b4b
fc8a7321d3d6
2103dec14792



768db3438b4b
6b77863b719a
2103dec14792






768db3438b4b











2103dec14792
768db3438b4b
657c3e0c4147
2103dec14792




657c3e0c4147

2103dec14792


768db3438b4b



1dae27f84baa





be6bcabc7919



3a7bba649eaa
1dae27f84baa
0d8a0a17288e
04ecd2578e71















f4bda337bbb6

































5614618ec498













f4bda337bbb6

2103dec14792






f4bda337bbb6

2103dec14792

f4bda337bbb6











164eb02d070a






























675a0b049abf
164eb02d070a












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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297














                                                                       
                         




                              
                         
                        
                              
                         
                          

                        
                       
                 
                 
                
                
                



                                                                     








                                                               
 
                                                              
                                                 
 
                                       
 

                                                               

                            
                                    

                                                                 

                                         
                                    


                                             
                                          




                                    

                                                                 
                                  



                                           
                                          

                                                
                                       
                                                    
                                                  

                                                    

                                                  
                                                                       

                         




                    
                                                             
 
                            

                                  
                                        

                                                                            
         

 
                                                                  

                                                                   









                                                                            


                                                                          

           
                                                 








                                                                              
                                                        


                                                          
                                                 

                                                                                





                                                                   





                                                                       




















                                                                             

                                                                  
                                                                 

                                                                    
 
                                            
                
                           
                                    
 
                

                                          
                                                                        

                                                                   
                                                     
         
 
                                                                           
                                                              




                                                

                                                                          
                                                                          


                                                        
                                            
                            
                                    
                

                                               
                                                          
 
                               
 
                                                                       

                

                                          
                                                                        

                                                                   
                                                     
         
 

                                                          
                          
                                                                
                                                                   
                                 
                                                                        
                                                                    
                          
                                                                 
                                                                    




                                      

                                                              
                                                     
                                                                                


                                                        
                                            
                            
                                    
                

                                               
                                                          
 
                               
 
                                                                       
                

                                          
                                                                        

                                                                   
                                                     
         
 

                                                          
                                 
                                                                       
                                                                   
                                                              
                                  
                                                                         
                                                                            





                                            


                                                                             



                                                 



                                                                  


                                 






                                                                         
                                                










                                                                         

                                                                      


                                                        

                                               

                                         
 


                                                                 





                                                               

                                                      
                                                             

                                  
                                                             
 
 

                                                                       













                                                                           

                                    

                                                                      

                                                        
                                            
                                      
 

                                               

                                         
 


                                                                
                                                             
 


                                                 
                        


                                                                  


                                 
                                                




                                                                    
                          
 
 

                                                                       













                                                                           

                                    




                                                             
                                                               
                                   

                                          
                                                      

                       


                                                                               
                                                      



                                                                               


                                                                      



                                             
                     

                                                                 
                                           


                                                                       
                                                              


                                 
                                       



                                                                     
                                                              

         


                         
                                        

                                                             
                                                                      

 
                                                             

                                                                   
 

                                                        

              

                                                                 
                                                






                                                                      
                                                                    
                                                                            


                                     


                                                               

                            
 

                                         
 
                                                                 

                                                          

                                                                      


                                       
                                                             
                                                          
                                                                   
 

                                                        

              

                                                                 
                                                






                                                                      

                                                                            

                                     
 





















                                                                     


                                                                            
                                        


                                                                            

 
                                         
                                                


                                                    



                                                        
                                       


                                                              
                                            


                                                                         
                                            
                                 
                        

                              


                                                                      
                                                   
                                                       


                                              

                                                                               


                                                            

                                                             
                                         



                                                       
                                                






                                                        
                        
 
                                                                  
                                          
                                            


                                                                         
                                            
                                 
                        

                              


                                                                      
                                                   
                                                       
                                              
         
 
                                                      


                                                            

                                                             
                          
 
                                                              
 








                                                                   


                                                                     



























                                                                            
                                                                        



                                                              
                              
                                    
                                        
                     
 
                                     





                                         
                                       




                              

                                                  
                              

                 



























                                                 
                                                       




                                                                                    






                                                          
                 



                                                                   

                                          








                                                     
                                        



                                                         
                              



                                                                      

                                                         
                              











                                                                               
                                                               















                                                                            



                                                         







                                                                    

                                                         
                              


                                                                          

                                                         
                              











                                                                           





                                                          






                                                                         

                                                         




                                                  



                                                                  














                                                                     

                                                         

                                             




                                                                             
                              






                                                                             






                                                                                



























                                                                               




                                                       



                                                         
                                                     

                                               



                                                                                 




                              


                                                  
                                                  
 



                             


                                          


                   

                                                                   


                                                     
                                                    
               
                                 
                           



                                 


                                                 

                                           


                                                                
                                                                          
                                                                   
                          
 






                                                                             
                                                    






                                                                      




































                                                                         

                                               
                                        
                                        
                 
 

                                     

                                                       
         
 

                                                           
                                                     


                                                                          
         
 
 
                                                             
                                                                   
                                                                         

                                                                                



                                                     
                

                                                         
                                                           
                 
                       
 





                                                                
                                       
                                                    


                                                                 
                                                       

                                                                  
 





                                                                               

                                                                         
                                     

 






































                                                                           
                                                                       
                                                                            
                                                                     
                                                               

                                               
                                                     

                                   


                          

                       
 
                                             

                                 
 


                                                           



                                                 





                                                                          


                                                  
 

                                           
                                     
                                

                                           











                                                                         

                                                 




                                                           

                                                   

                                                  
                                                 


                                                                   

         
                                                                  

                                     

                                            

                                                            

         












                                                                              

                                                 


                                                           

         


                                                                    

                                                                    
         
 




                                                     


                                          

                                                 

                                                           

         


                                                                     

                                                                      
         
 
                            


                                                        

 
                                                                              
                                                                
                                                                         
                                                                          

                                                                      

                                                     
                                         

                                    
                    
 




                                                                           
                                                          
                     
                                    
            
                                    
 
                                                             
                                                                   
                 




                                                                        
                                                               
                              
 
                  
                                                           

                                                   
         
 
                                                                        
 




                                                                           
                                                          
                                                                        
                                                                           


                            
                                                                      
                                                       
                                                              
                  
                                                         



                                                                                
         

 
                                                                
                                                           
                                                                       



                                               





                                                                                
 

                            







                                                      
                              





                                                            





                                                                                








                                                                        
                                                     



                                                               


                          
 


                                                         
                                                                             

                                                  

                                          
                        

 


















                                                                               



                                                     
                                      
                             
                   

                                            
                

                                       
 
                            
                                        
                                      










                                                             
                                              

         


                                                                 
 











                                                                     

         








                                                                 



                                                                      
                            

                                                       

                                                     







                                                                       


                                                                
                                                   
                                                              

         
                                  





                                                                    
 
                                                              

                                                    
                                                       

         
                                                       

                                                       
 
                           

                                                          
                                               
 










                                                                            
         
                                      
 
                                 





                                                                        
 



                                                                
         
 


                                       
                                          


                                                              

                            
                                                    
                                 








                                                                 
                                           
                                           

                                              
 

                                            
                                                      

                                                           
 


                                                                      
 
                                          
                                                                         
                                            
                              
                                          

                                                    
                                       
                                                                         
 
                                                                   

                                                                     



                                                                           
                                          
                                               




                                                                                 






                                            
                                               

                                                   
                                                
                                         

                                               




                                   

                                       
          








                                                                      

                                                     




                                                                 

















                                                                            




                                                            
         


                                   


                                                                        
          








                                                                  
                                                         


                                                                  

                                                                     
                                                               
                 

                                              
         
 

                                                                             
 



                                                              
                                                        
                                            

                              


                         
                                                      
                                 

                                
 






                                                              
                                                    


                   

                 
 


























                                                           
                                                               
 


                                                     
 
                                        
 

                                                                              
 
                                        
                            
 

                                                                             
        
                                          
 























































                                                                            







































                                                                               
 
                                                                           













                                                        

                                          


                                                               

                                                       












                                   
                                                                              
                                       



                                         

                                                         












                                                                 
                                                                            
                                                                       
                                             
 
                                               
                                  


                                                       










                                                                             
                      
                
                                                                    

                      
                                                             

                                                           
                                                                       
 
                                                         
                                     


                                                            

                                                      
 
                                                           

 
                                                                         
                                                                               
                                                                    


                                               




                                                              
 
                                                                        












                                                      
                                                                     

 





























                                                                            
                                                                

                                                                 
 

                                                     
                        
                          
                                                          
                       
 

                                                                                
                                             





                                                                          









                                          
                             


                                                                          

                                                       
                                                  


                                                               




                 
                                                                    

                                                                     
 

                                                     
                              
                            
                                                          



                                                                                
 
                                             






                                                                          











                                                 
                         
                                                         
                                     




                                                                   

                                                               


                                                                       



                 





                                                                



                                                                      
                                             
 
                                      















                                                                

































                                                                             













                                                                    

                                                       






                                                 

                                                             

                                                                    











                                               






























                                                                                
                                                 












                                                                            
/*
 * Copyright 2002-2005, Instant802 Networks, Inc.
 * Copyright 2005-2006, Devicescape Software, Inc.
 * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
 * Copyright 2007	Johannes Berg <johannes@sipsolutions.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * utilities for mac80211
 */

#include <net/mac80211.h>
#include <linux/netdevice.h>
#include <linux/export.h>
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/skbuff.h>
#include <linux/etherdevice.h>
#include <linux/if_arp.h>
#include <linux/bitmap.h>
#include <linux/crc32.h>
#include <net/net_namespace.h>
#include <net/cfg80211.h>
#include <net/rtnetlink.h>

#include "ieee80211_i.h"
#include "driver-ops.h"
#include "rate.h"
#include "mesh.h"
#include "wme.h"
#include "led.h"
#include "wep.h"

/* privid for wiphys to determine whether they belong to us or not */
void *mac80211_wiphy_privid = &mac80211_wiphy_privid;

struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
{
	struct ieee80211_local *local;
	BUG_ON(!wiphy);

	local = wiphy_priv(wiphy);
	return &local->hw;
}
EXPORT_SYMBOL(wiphy_to_ieee80211_hw);

u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
			enum nl80211_iftype type)
{
	__le16 fc = hdr->frame_control;

	 /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
	if (len < 16)
		return NULL;

	if (ieee80211_is_data(fc)) {
		if (len < 24) /* drop incorrect hdr len (data) */
			return NULL;

		if (ieee80211_has_a4(fc))
			return NULL;
		if (ieee80211_has_tods(fc))
			return hdr->addr1;
		if (ieee80211_has_fromds(fc))
			return hdr->addr2;

		return hdr->addr3;
	}

	if (ieee80211_is_mgmt(fc)) {
		if (len < 24) /* drop incorrect hdr len (mgmt) */
			return NULL;
		return hdr->addr3;
	}

	if (ieee80211_is_ctl(fc)) {
		if(ieee80211_is_pspoll(fc))
			return hdr->addr1;

		if (ieee80211_is_back_req(fc)) {
			switch (type) {
			case NL80211_IFTYPE_STATION:
				return hdr->addr2;
			case NL80211_IFTYPE_AP:
			case NL80211_IFTYPE_AP_VLAN:
				return hdr->addr1;
			default:
				break; /* fall through to the return */
			}
		}
	}

	return NULL;
}

void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
{
	struct sk_buff *skb;
	struct ieee80211_hdr *hdr;

	skb_queue_walk(&tx->skbs, skb) {
		hdr = (struct ieee80211_hdr *) skb->data;
		hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
	}
}

int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
			     int rate, int erp, int short_preamble,
			     int shift)
{
	int dur;

	/* calculate duration (in microseconds, rounded up to next higher
	 * integer if it includes a fractional microsecond) to send frame of
	 * len bytes (does not include FCS) at the given rate. Duration will
	 * also include SIFS.
	 *
	 * rate is in 100 kbps, so divident is multiplied by 10 in the
	 * DIV_ROUND_UP() operations.
	 *
	 * shift may be 2 for 5 MHz channels or 1 for 10 MHz channels, and
	 * is assumed to be 0 otherwise.
	 */

	if (band == IEEE80211_BAND_5GHZ || erp) {
		/*
		 * OFDM:
		 *
		 * N_DBPS = DATARATE x 4
		 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
		 *	(16 = SIGNAL time, 6 = tail bits)
		 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
		 *
		 * T_SYM = 4 usec
		 * 802.11a - 18.5.2: aSIFSTime = 16 usec
		 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
		 *	signal ext = 6 usec
		 */
		dur = 16; /* SIFS + signal ext */
		dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */
		dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */

		/* IEEE 802.11-2012 18.3.2.4: all values above are:
		 *  * times 4 for 5 MHz
		 *  * times 2 for 10 MHz
		 */
		dur *= 1 << shift;

		/* rates should already consider the channel bandwidth,
		 * don't apply divisor again.
		 */
		dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
					4 * rate); /* T_SYM x N_SYM */
	} else {
		/*
		 * 802.11b or 802.11g with 802.11b compatibility:
		 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
		 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
		 *
		 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
		 * aSIFSTime = 10 usec
		 * aPreambleLength = 144 usec or 72 usec with short preamble
		 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
		 */
		dur = 10; /* aSIFSTime = 10 usec */
		dur += short_preamble ? (72 + 24) : (144 + 48);

		dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
	}

	return dur;
}

/* Exported duration function for driver use */
__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
					struct ieee80211_vif *vif,
					enum ieee80211_band band,
					size_t frame_len,
					struct ieee80211_rate *rate)
{
	struct ieee80211_sub_if_data *sdata;
	u16 dur;
	int erp, shift = 0;
	bool short_preamble = false;

	erp = 0;
	if (vif) {
		sdata = vif_to_sdata(vif);
		short_preamble = sdata->vif.bss_conf.use_short_preamble;
		if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
			erp = rate->flags & IEEE80211_RATE_ERP_G;
		shift = ieee80211_vif_get_shift(vif);
	}

	dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
				       short_preamble, shift);

	return cpu_to_le16(dur);
}
EXPORT_SYMBOL(ieee80211_generic_frame_duration);

__le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
			      struct ieee80211_vif *vif, size_t frame_len,
			      const struct ieee80211_tx_info *frame_txctl)
{
	struct ieee80211_local *local = hw_to_local(hw);
	struct ieee80211_rate *rate;
	struct ieee80211_sub_if_data *sdata;
	bool short_preamble;
	int erp, shift = 0, bitrate;
	u16 dur;
	struct ieee80211_supported_band *sband;

	sband = local->hw.wiphy->bands[frame_txctl->band];

	short_preamble = false;

	rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];

	erp = 0;
	if (vif) {
		sdata = vif_to_sdata(vif);
		short_preamble = sdata->vif.bss_conf.use_short_preamble;
		if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
			erp = rate->flags & IEEE80211_RATE_ERP_G;
		shift = ieee80211_vif_get_shift(vif);
	}

	bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);

	/* CTS duration */
	dur = ieee80211_frame_duration(sband->band, 10, bitrate,
				       erp, short_preamble, shift);
	/* Data frame duration */
	dur += ieee80211_frame_duration(sband->band, frame_len, bitrate,
					erp, short_preamble, shift);
	/* ACK duration */
	dur += ieee80211_frame_duration(sband->band, 10, bitrate,
					erp, short_preamble, shift);

	return cpu_to_le16(dur);
}
EXPORT_SYMBOL(ieee80211_rts_duration);

__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
				    struct ieee80211_vif *vif,
				    size_t frame_len,
				    const struct ieee80211_tx_info *frame_txctl)
{
	struct ieee80211_local *local = hw_to_local(hw);
	struct ieee80211_rate *rate;
	struct ieee80211_sub_if_data *sdata;
	bool short_preamble;
	int erp, shift = 0, bitrate;
	u16 dur;
	struct ieee80211_supported_band *sband;

	sband = local->hw.wiphy->bands[frame_txctl->band];

	short_preamble = false;

	rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
	erp = 0;
	if (vif) {
		sdata = vif_to_sdata(vif);
		short_preamble = sdata->vif.bss_conf.use_short_preamble;
		if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
			erp = rate->flags & IEEE80211_RATE_ERP_G;
		shift = ieee80211_vif_get_shift(vif);
	}

	bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);

	/* Data frame duration */
	dur = ieee80211_frame_duration(sband->band, frame_len, bitrate,
				       erp, short_preamble, shift);
	if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
		/* ACK duration */
		dur += ieee80211_frame_duration(sband->band, 10, bitrate,
						erp, short_preamble, shift);
	}

	return cpu_to_le16(dur);
}
EXPORT_SYMBOL(ieee80211_ctstoself_duration);

void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
{
	struct ieee80211_sub_if_data *sdata;
	int n_acs = IEEE80211_NUM_ACS;

	if (local->hw.queues < IEEE80211_NUM_ACS)
		n_acs = 1;

	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
		int ac;

		if (!sdata->dev)
			continue;

		if (test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
			continue;

		if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE &&
		    local->queue_stop_reasons[sdata->vif.cab_queue] != 0)
			continue;

		for (ac = 0; ac < n_acs; ac++) {
			int ac_queue = sdata->vif.hw_queue[ac];

			if (ac_queue == queue ||
			    (sdata->vif.cab_queue == queue &&
			     local->queue_stop_reasons[ac_queue] == 0 &&
			     skb_queue_empty(&local->pending[ac_queue])))
				netif_wake_subqueue(sdata->dev, ac);
		}
	}
}

static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
				   enum queue_stop_reason reason)
{
	struct ieee80211_local *local = hw_to_local(hw);

	trace_wake_queue(local, queue, reason);

	if (WARN_ON(queue >= hw->queues))
		return;

	if (!test_bit(reason, &local->queue_stop_reasons[queue]))
		return;

	__clear_bit(reason, &local->queue_stop_reasons[queue]);

	if (local->queue_stop_reasons[queue] != 0)
		/* someone still has this queue stopped */
		return;

	if (skb_queue_empty(&local->pending[queue])) {
		rcu_read_lock();
		ieee80211_propagate_queue_wake(local, queue);
		rcu_read_unlock();
	} else
		tasklet_schedule(&local->tx_pending_tasklet);
}

void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
				    enum queue_stop_reason reason)
{
	struct ieee80211_local *local = hw_to_local(hw);
	unsigned long flags;

	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
	__ieee80211_wake_queue(hw, queue, reason);
	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
}

void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
{
	ieee80211_wake_queue_by_reason(hw, queue,
				       IEEE80211_QUEUE_STOP_REASON_DRIVER);
}
EXPORT_SYMBOL(ieee80211_wake_queue);

static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
				   enum queue_stop_reason reason)
{
	struct ieee80211_local *local = hw_to_local(hw);
	struct ieee80211_sub_if_data *sdata;
	int n_acs = IEEE80211_NUM_ACS;

	trace_stop_queue(local, queue, reason);

	if (WARN_ON(queue >= hw->queues))
		return;

	if (test_bit(reason, &local->queue_stop_reasons[queue]))
		return;

	__set_bit(reason, &local->queue_stop_reasons[queue]);

	if (local->hw.queues < IEEE80211_NUM_ACS)
		n_acs = 1;

	rcu_read_lock();
	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
		int ac;

		if (!sdata->dev)
			continue;

		for (ac = 0; ac < n_acs; ac++) {
			if (sdata->vif.hw_queue[ac] == queue ||
			    sdata->vif.cab_queue == queue)
				netif_stop_subqueue(sdata->dev, ac);
		}
	}
	rcu_read_unlock();
}

void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
				    enum queue_stop_reason reason)
{
	struct ieee80211_local *local = hw_to_local(hw);
	unsigned long flags;

	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
	__ieee80211_stop_queue(hw, queue, reason);
	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
}

void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
{
	ieee80211_stop_queue_by_reason(hw, queue,
				       IEEE80211_QUEUE_STOP_REASON_DRIVER);
}
EXPORT_SYMBOL(ieee80211_stop_queue);

void ieee80211_add_pending_skb(struct ieee80211_local *local,
			       struct sk_buff *skb)
{
	struct ieee80211_hw *hw = &local->hw;
	unsigned long flags;
	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
	int queue = info->hw_queue;

	if (WARN_ON(!info->control.vif)) {
		ieee80211_free_txskb(&local->hw, skb);
		return;
	}

	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
	__ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
	__skb_queue_tail(&local->pending[queue], skb);
	__ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
}

void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
				   struct sk_buff_head *skbs,
				   void (*fn)(void *data), void *data)
{
	struct ieee80211_hw *hw = &local->hw;
	struct sk_buff *skb;
	unsigned long flags;
	int queue, i;

	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
	while ((skb = skb_dequeue(skbs))) {
		struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);

		if (WARN_ON(!info->control.vif)) {
			ieee80211_free_txskb(&local->hw, skb);
			continue;
		}

		queue = info->hw_queue;

		__ieee80211_stop_queue(hw, queue,
				IEEE80211_QUEUE_STOP_REASON_SKB_ADD);

		__skb_queue_tail(&local->pending[queue], skb);
	}

	if (fn)
		fn(data);

	for (i = 0; i < hw->queues; i++)
		__ieee80211_wake_queue(hw, i,
			IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
}

void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
				     unsigned long queues,
				     enum queue_stop_reason reason)
{
	struct ieee80211_local *local = hw_to_local(hw);
	unsigned long flags;
	int i;

	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);

	for_each_set_bit(i, &queues, hw->queues)
		__ieee80211_stop_queue(hw, i, reason);

	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
}

void ieee80211_stop_queues(struct ieee80211_hw *hw)
{
	ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
					IEEE80211_QUEUE_STOP_REASON_DRIVER);
}
EXPORT_SYMBOL(ieee80211_stop_queues);

int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
{
	struct ieee80211_local *local = hw_to_local(hw);
	unsigned long flags;
	int ret;

	if (WARN_ON(queue >= hw->queues))
		return true;

	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
	ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
		       &local->queue_stop_reasons[queue]);
	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
	return ret;
}
EXPORT_SYMBOL(ieee80211_queue_stopped);

void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
				     unsigned long queues,
				     enum queue_stop_reason reason)
{
	struct ieee80211_local *local = hw_to_local(hw);
	unsigned long flags;
	int i;

	spin_lock_irqsave(&local->queue_stop_reason_lock, flags);

	for_each_set_bit(i, &queues, hw->queues)
		__ieee80211_wake_queue(hw, i, reason);

	spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
}

void ieee80211_wake_queues(struct ieee80211_hw *hw)
{
	ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
					IEEE80211_QUEUE_STOP_REASON_DRIVER);
}
EXPORT_SYMBOL(ieee80211_wake_queues);

void ieee80211_flush_queues(struct ieee80211_local *local,
			    struct ieee80211_sub_if_data *sdata)
{
	u32 queues;

	if (!local->ops->flush)
		return;

	if (sdata && local->hw.flags & IEEE80211_HW_QUEUE_CONTROL) {
		int ac;

		queues = 0;

		for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
			queues |= BIT(sdata->vif.hw_queue[ac]);
		if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE)
			queues |= BIT(sdata->vif.cab_queue);
	} else {
		/* all queues */
		queues = BIT(local->hw.queues) - 1;
	}

	ieee80211_stop_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
					IEEE80211_QUEUE_STOP_REASON_FLUSH);

	drv_flush(local, queues, false);

	ieee80211_wake_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
					IEEE80211_QUEUE_STOP_REASON_FLUSH);
}

void ieee80211_iterate_active_interfaces(
	struct ieee80211_hw *hw, u32 iter_flags,
	void (*iterator)(void *data, u8 *mac,
			 struct ieee80211_vif *vif),
	void *data)
{
	struct ieee80211_local *local = hw_to_local(hw);
	struct ieee80211_sub_if_data *sdata;

	mutex_lock(&local->iflist_mtx);

	list_for_each_entry(sdata, &local->interfaces, list) {
		switch (sdata->vif.type) {
		case NL80211_IFTYPE_MONITOR:
			if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
				continue;
			break;
		case NL80211_IFTYPE_AP_VLAN:
			continue;
		default:
			break;
		}
		if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) &&
		    !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
			continue;
		if (ieee80211_sdata_running(sdata))
			iterator(data, sdata->vif.addr,
				 &sdata->vif);
	}

	sdata = rcu_dereference_protected(local->monitor_sdata,
					  lockdep_is_held(&local->iflist_mtx));
	if (sdata &&
	    (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL ||
	     sdata->flags & IEEE80211_SDATA_IN_DRIVER))
		iterator(data, sdata->vif.addr, &sdata->vif);

	mutex_unlock(&local->iflist_mtx);
}
EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);

void ieee80211_iterate_active_interfaces_atomic(
	struct ieee80211_hw *hw, u32 iter_flags,
	void (*iterator)(void *data, u8 *mac,
			 struct ieee80211_vif *vif),
	void *data)
{
	struct ieee80211_local *local = hw_to_local(hw);
	struct ieee80211_sub_if_data *sdata;

	rcu_read_lock();

	list_for_each_entry_rcu(sdata, &local->interfaces, list) {