-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtwt.h
More file actions
427 lines (385 loc) · 12.3 KB
/
Copy pathtwt.h
File metadata and controls
427 lines (385 loc) · 12.3 KB
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
/*
* Copyright 2022 Morse Micro
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
#ifndef _TWT_H_
#define _TWT_H_
#include <linux/types.h>
#include <linux/list.h>
#include <linux/workqueue.h>
#include <net/netlink.h>
#include "morse.h"
#include "dot11ah/dot11ah.h"
/* For now limit to maximum as defined in P802.11REVme_D1.1 Section 9.4.2.199 */
#define MORSE_TWT_AGREEMENTS_MAX_PER_STA (8)
#define TWT_WAKE_DURATION_UNIT (256)
#define TWT_WAKE_INTERVAL_EXPONENT_MAX_VAL (31)
#define TWT_WAKE_DURATION_MAX_US (__UINT8_MAX__ * TWT_WAKE_DURATION_UNIT)
#define TWT_AGREEMENT_REQUEST_TYPE_OFFSET (1)
#define TWT_AGREEMENT_TARGET_WAKE_TIME_OFFSET (3)
#define TWT_AGREEMENT_WAKE_DURATION_OFFSET (11)
#define TWT_AGREEMENT_WAKE_INTERVAL_MANTISSA_OFFSET (12)
#define TWT_TEARDOWN_FLOW_ID_MASK GENMASK(2, 0)
enum morse_twt_state {
MORSE_TWT_STATE_NO_AGREEMENT,
MORSE_TWT_STATE_CONSIDER_REQUEST,
MORSE_TWT_STATE_CONSIDER_SUGGEST,
MORSE_TWT_STATE_CONSIDER_DEMAND,
MORSE_TWT_STATE_CONSIDER_GROUPING,
MORSE_TWT_STATE_AGREEMENT,
};
/**
* struct morse_twt_sta_vif - contains STA VIF's specific TWT state information
*
* @active_agreement_bitmap Bitmap of active TWT agreement for each of flow ids
* @cmd_work Work queue struct to defer install/uninstall of twt agreementss.
* @to_install_uninstall A queue of TWT agreements to install/uninstall to the chip.
*/
struct morse_twt_sta_vif {
unsigned long active_agreement_bitmap;
struct work_struct cmd_work;
struct list_head to_install_uninstall;
};
/**
* struct morse_twt - TWT state and configuration information
*
* @stas List of structures containing agreements for STA.
* @wake_intervals List of structures used as heads for lists of agreements with the same
* wake interval. These are arranged in order from the smallest to largest wake
* intervals.
* @events A queue of TWT events to be processed.
* @tx A queue of TWT data to be sent.
* @req_event_tx A TWT request event to be sent in the (re)assoc request frame.
* @work Work queue struct to defer processing of events.
* @lock Spinlock used to control access to lists/memory.
* @requester Whether or not the VIF is a TWT Requester.
* @responder Whether or not the VIF is a TWT Responder.
* @dialog_token Dialog token of Tx action frames.
* @sta_vif STA VIF specific data
*/
struct morse_twt {
struct list_head stas;
struct list_head wake_intervals;
struct list_head events;
struct list_head tx;
u8 *req_event_tx;
struct work_struct work;
/* Protect TWT operations */
spinlock_t lock;
bool requester;
bool responder;
u8 dialog_token;
/* STA VIF specific data */
struct morse_twt_sta_vif sta_vif;
};
/* This structure is packed as control and params form the TWT IE. This allows the use of memcpy. */
struct morse_twt_agreement_data {
/** First wakeup time in us with reference to the TSF */
u64 wake_time_us;
/** Interval between wake ups in us */
u64 wake_interval_us;
/** Wake nominal minimum duration in us */
u32 wake_duration_us;
/** TWT control field */
u8 control;
/** TWT agreement parameters */
struct ieee80211_twt_params params;
} __packed;
struct morse_twt_agreement {
struct list_head list;
enum morse_twt_state state;
struct morse_twt_agreement_data data;
};
struct morse_twt_config {
/** Operation code */
u8 opcode;
/** The flow (TWT) identifier for this agreement */
u8 flow_id;
/** TWT agreement data of the Requestor */
struct morse_twt_agreement_data agreement;
};
enum morse_twt_event_type {
MORSE_TWT_EVENT_SETUP,
MORSE_TWT_EVENT_TEARDOWN
};
struct morse_twt_event {
struct list_head list;
enum morse_twt_event_type type;
u8 addr[ETH_ALEN];
u8 flow_id;
union {
struct {
enum ieee80211_twt_setup_cmd cmd;
struct morse_twt_agreement_data *agr_data;
} setup;
/* TODO Implement teardown. */
struct {
bool teardown;
} teardown;
};
};
/*
* S1G action frame TWT action Category
*/
struct morse_dot11ah_s1g_twt_action {
__le16 frame_control;
__le16 duration;
u8 da[ETH_ALEN];
u8 sa[ETH_ALEN];
u8 bssid[ETH_ALEN];
__le16 seq_ctrl;
u8 category;
union {
struct {
u8 action_code;
u8 dialog_token;
u8 variable[];
} __packed twt_action_setup;
struct {
u8 action_code;
u8 flow;
} __packed twt_action_teardown;
} u;
} __packed;
struct morse_twt_sta {
struct list_head list;
u8 addr[ETH_ALEN];
/* dialog token of pending action frame */
u8 dialog_token;
/* flag to notify pending action frame */
bool action_is_pending;
struct morse_twt_agreement agreements[MORSE_TWT_AGREEMENTS_MAX_PER_STA];
};
struct morse_twt_wake_interval {
struct list_head list;
struct list_head agreements;
};
/**
* @morse_twt_is_enabled() - Check if TWT is enabled on a VIF
*
* @mors_vif Morse virtual interface
*
* Return: True if TWT is enabled
*/
bool morse_twt_is_enabled(struct morse_vif *mors_vif);
/**
* @morse_twt_event_queue_purge() - Remove all events for a STA addr from the event queue
*
* @mors Morse device
* @mors_vif Morse virtual interface
* @addr Address of the STA to remove events for
*/
void morse_twt_event_queue_purge(struct morse *mors, struct morse_vif *mors_vif, u8 *addr);
/**
* morse_twt_sta_remove_addr() - Remove a station's TWT agreement.
*
* @mors Morse device
* @mors_vif Morse virtual interface
* @skb The sk_buff which should contain a (re)assoc frame
*
* Return: 0 on success or relevant error.
*/
int morse_twt_sta_remove_addr(struct morse *mors, struct morse_vif *mors_vif, u8 *addr);
/**
* morse_twt_insert_ie() - Insert a TWT IE into an sk_buff
*
* @mors Morse device
* @tx The TWT data to send
* @ies_mask Array of information elements.
* @size Size of the TWT IE (can be found using morse_twt_get_ie_size())
*/
void morse_twt_insert_ie(struct morse *mors,
struct morse_twt_event *tx, struct dot11ah_ies_mask *ies_mask, u8 size);
/**
* morse_twt_dequeue_tx() - removes TX data from the queue it is in. It will also handle
* freeing the associated memory.
*
*
* @mors Morse device
* @event The event or TX data to get the TWT IE size of
* @tx The transmitted event to remove from the queue.
*
* Return: Positive size of the TWT on success or negative error code
*/
int morse_twt_dequeue_tx(struct morse *mors, struct morse_vif *mors_vif,
struct morse_twt_event *tx);
/**
* morse_twt_get_ie_size() - Gets the size of a TWT IE for an event or TX data
*
* @mors Morse device
* @event The event or TX data to get the TWT IE size of
*
* Return: Positive size of the TWT IE on success or negative error code
*/
int morse_twt_get_ie_size(struct morse *mors, struct morse_twt_event *event);
/**
* morse_twt_peek_tx() - Get TWT TX data from the queue without removing it
*
* @mors Morse device
* @mors_vif Morse virtual interface
* @addr Destination address to get TX data for
* @flow_id Flow id to match if not NULL
*
* Return: TX data for the destination address or NULL if none available or error
*/
struct morse_twt_event *morse_twt_peek_tx(struct morse *mors,
struct morse_vif *mors_vif,
const u8 *addr, const u8 *flow_id);
/**
* morse_twt_parse_ie() - Parse a TWT IE and fills out an event
*
* @mors_vif Morse virtual interface
* @ie The TWT IE to parse.
* @event The event to fill.
* @src_addr Address of the device sending the IE.
*
* @return 0 on success, else error code
*/
int morse_twt_parse_ie(struct morse_vif *mors_vif, struct ie_element *ie,
struct morse_twt_event *event, const u8 *src_addr);
/**
* morse_twt_dump_element() - Prints out the information for an event
*
* @mors Morse device
* @event The twt event to dump
*/
void morse_twt_dump_event(struct morse *mors, struct morse_twt_event *event);
/**
* morse_twt_dump_wake_interval_tree() - Print the tree of wake intervals/agreements to debugfs
*
* @file Seq file to print debug to
* @mors_vif Morse virtual interface
*/
void morse_twt_dump_wake_interval_tree(struct seq_file *file, struct morse_vif *mors_vif);
/**
* morse_twt_dump_sta_agreements() - Print the tree of stations/agreements to debugfs
*
* @file Seq file to print debug to
* @mors_vif Morse virtual interface
*/
void morse_twt_dump_sta_agreements(struct seq_file *file, struct morse_vif *mors_vif);
/**
* morse_twt_process_pending_cmds() - Installs/Uninstalls pending agreements to the firmware
*
* @mors Morse device
* @mors_vif Morse virtual interface
*/
void morse_twt_process_pending_cmds(struct morse *mors, struct morse_vif *mors_vif);
/**
* morse_twt_handle_event() - Process a TWT event
*
* @mors_vif Morse virtual interface
* @addr Address to filter on, if NULL proccess all events
*/
void morse_twt_handle_event(struct morse_vif *mors_vif, u8 *addr);
/**
* @morse_mac_process_rx_twt_mgmt() - Process TWT IEs in management frames
*
* @mors Morse device
* @vif VIF struct
* @skb Rx management SKB
* @ies_mask IEs Mask
*
* Return: -EACCESS to avoid forwarding, 0 to forward to mac80211, or an error code.
*/
int morse_mac_process_rx_twt_mgmt(struct morse *mors, struct ieee80211_vif *vif,
const struct sk_buff *skb, struct dot11ah_ies_mask *ies_mask);
/**
* @morse_mac_process_twt_action_tx_finish() - Process Tx completion of TWT action frames
*
* @mors Morse device
* @vif VIF struct
* @skb Tx TWT action SKB
*/
void morse_mac_process_twt_action_tx_finish(struct morse *mors, struct ieee80211_vif *vif,
const struct sk_buff *skb);
/**
* morse_twt_init_vif() - Initialise TWT for a VIF
*
* @mors Morse device
* @mors_vif Morse virtual interface
* @enable_twt True if TWT is configured
* @is_ap True if the interface is in AP mode
* @is_sta True if the interface is in STA mode
* @connection_monitor_is_enabled True if the MAC80211 connection monitor is enabled
*/
void morse_twt_init_vif(struct morse *mors, struct morse_vif *mors_vif,
bool enable_twt, bool is_ap, bool is_sta,
bool connection_monitor_is_enabled);
/**
* morse_twt_finish_vif() - Initialise TWT for a VIF
*
* @mors Morse device
* @mors_vif Morse virtual interface
*/
void morse_twt_finish_vif(struct morse *mors, struct morse_vif *mors_vif);
/**
* morse_twt_initialise_agreement() - Initialises the twt agreement that needs to be sent to the FW
* This is only used when we want to directly set the twt params in the FW bypassing the TWT IE
* insertion
*
* @twt_conf The twt configuration struct
* @agreement pointer to the agreement that need to be sent to the FW
*
* Return: The agreement length
*/
int morse_twt_initialise_agreement(struct morse_twt_agreement_data *twt_data, u8 *agreement);
/**
* morse_twt_reconfig() - Restore TWT configuration after HW assert
*
* @mors Global morse structure
* @mors_vif Morse VIF
*/
void morse_twt_reconfig(struct morse *mors, struct morse_vif *mors_vif);
/**
* morse_dot11_is_twt_setup_action_frame() - Checks if TWT setup action frame
*
* @twt_action pointer to mgmt frame
*
* @return true, if TWT setup action frame, else false
*/
static inline bool morse_dot11_is_twt_setup_action_frame
(struct morse_dot11ah_s1g_twt_action *twt_action)
{
u8 action_code = twt_action->u.twt_action_setup.action_code;
/*
* Check for TWT Setup frame
*/
return ((twt_action->category == WLAN_CATEGORY_S1G_PROTECTED &&
(action_code == WLAN_S1G_PROTECTED_TWT_SETUP)) ||
(twt_action->category == WLAN_CATEGORY_S1G_UNPROTECTED &&
(action_code == WLAN_S1G_TWT_SETUP)));
}
/**
* morse_dot11_is_twt_teardown_action_frame() - Checks if TWT teardown action frame
*
* @twt_action pointer to mgmt frame
*
* @return true, if TWT teardown action frame, else false
*/
static inline bool morse_dot11_is_twt_teardown_action_frame
(struct morse_dot11ah_s1g_twt_action *twt_action)
{
u8 action_code = twt_action->u.twt_action_setup.action_code;
/*
* Check for TWT teardown frame only as TWT Teardown will not have IEs
*/
return ((twt_action->category == WLAN_CATEGORY_S1G_PROTECTED &&
(action_code == WLAN_S1G_PROTECTED_TWT_TEARDOWN)) ||
(twt_action->category == WLAN_CATEGORY_S1G_UNPROTECTED &&
(action_code == WLAN_S1G_TWT_TEARDOWN)));
}
/**
* morse_dot11_twt_action_ie_pos() - Get the position of the IE in TWT setup action frame
*
* @twt_action pointer to mgmt frame
*
* @return position of IE in TWT setup action frame
*/
static inline u8 *morse_dot11_twt_action_ie_pos(struct morse_dot11ah_s1g_twt_action *twt_action)
{
return twt_action->u.twt_action_setup.variable;
}
#endif