hc
2024-03-25 edb30157bad0c0001c32b854271ace01d3b9a16a
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
/******************************************************************************
 *
 * Copyright(c) 2019 Realtek Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 *****************************************************************************/
#ifndef _PHL_TWT_H_
#define _PHL_TWT_H_
 
#ifdef CONFIG_PHL_TWT
#define MIN_TWT_ELE_LEN 15
#define MAX_NUM_HW_TWT_CONFIG 4
#define CONTROL_LENGTH 1
#define REQUEST_TYPE_LENGTH 2
#define NOMINAL_MINIMUM_TWT_WAKE_DURATION_LENGTH 1
#define TARGET_WAKE_TIME_LENGTH 8
#define NOMINAL_MIN_TWT_WAKE_DURATION_LENGTH 1
#define TWT_WAKE_INTERVAL_MANTISSA_LENGTH 2
#define TWT_CHANNEL_LENGTH 1
#define TWT_FLOW_FIELD_LENGTH 1
#define TOKEN_OFFSET 2
#define TOKEN_LENGTH 1
#define ELEM_ID_LEN 1 /* Length of element id*/
#define ELEM_LEN_LEN 1 /* Length of element Length*/
#define C2H_FUN_WAIT_ANNC 0x0
 
#define get_twt_info(_phl) (struct phl_twt_info *)(_phl->phl_twt_info)
#define set_config_state(_state, set_state) (_state = set_state)
#define twt_init(_phl) (NULL != (get_twt_info(_phl)))
#define twt_sup(_phl) (((struct phl_info_t *)_phl)->phl_com->dev_cap.twt_sup)
 
enum phl_operate_config_type {
   PHL_OP_TYPE_NONE = 0,
   PHL_GET_NEW_CONFIG,
   PHL_FREE_CONFIG,
   PHL_GET_CONFIG_BY_ID,
   PHL_GET_CONFIG_BY_ROLE,
   PHL_GET_CONFIG_BY_PARA,
   PHL_GET_NEXT_CONFIG,
   PHL_GET_HEAD_CONFIG
};
 
enum phl_twt_action {
   PHL_TWT_ACTION_NONE = 0,
   PHL_TWT_ACTION_FREE,
   PHL_TWT_ACTION_ALLOC,
   PHL_TWT_ACTION_ENABLE,
   PHL_TWT_ACTION_DISABLE,
   PHL_TWT_ACTION_UP_ERROR
};
 
enum phl_wait_annc_type {
   PHL_WAIT_ANNC_DISABLE = 0,
   PHL_WAIT_ANNC_ENABLE = 1
};
 
enum twt_config_state {
   twt_config_state_free = 0,
   twt_config_state_idle,
   twt_config_state_enable,
   twt_config_state_error,
   twt_config_state_unknown
};
 
struct phl_twt_config{
   u8 idx;
   enum twt_config_state state;
   struct rtw_wifi_role_t *role;
   struct rtw_phl_twt_info twt_info;
   struct phl_queue twt_sta_queue; /*struct rtw_twt_sta_info*/
};
 
struct phl_twt_cfg_info {
   u8 twt_cfg_num;
   void *twt_cfg_ring; /*struct phl_twt_config*/
};
 
struct phl_twt_info {
   struct phl_twt_cfg_info twt_cfg_info;
   struct phl_queue twt_annc_queue;/*struct _twt_announce_info*/
};
 
struct _twt_announce_info{
   _os_list list;
   u8 map_offset;
   u32 wait_macid_map;
};
 
struct _twt_compare {
   struct rtw_phl_twt_setup_info twt_setup;
   struct rtw_wifi_role_t *role;
};
 
struct _twt_teardown {
   struct rtw_phl_stainfo_t *phl_sta;
   enum rtw_phl_nego_type nego_type;
   u8 id;
};
 
/* TWT element */
/*Control*/
#define SET_TWT_CONTROL_NDP_PAGING_INDICATOR(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 0, 1, _val)
#define SET_TWT_CONTROL_RESPONDER_PM_MODE(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 1, 1, _val)
#define SET_TWT_CONTROL_NEGOTIATION_TYPE(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 2, 2, _val)
#define SET_TWT_CONTROL_TWT_INFORMATION_FRAME_DISABLE(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 4, 1, _val)
#define SET_TWT_CONTROL_WAKE_DURATION_UNIT(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 5, 1, _val)
 
/*Individual TWT Parameter Set field*/
/*Request Type*/
#define SET_TWT_REQ_TYPE_TWT_REQUEST(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 0, 1, _val)
#define SET_TWT_REQ_TYPE_TWT_SETUP_COMMAND(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 1, 3, _val)
#define SET_TWT_REQ_TYPE_TRIGGER(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 4, 1, _val)
#define SET_TWT_REQ_TYPE_IMPLICIT(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 5, 1, _val)
#define SET_TWT_REQ_TYPE_FLOW_TYPE(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 6, 1, _val)
#define SET_TWT_REQ_TYPE_TWT_FLOW_IDENTIFER(_ele_start, _val) \
   SET_BITS_TO_LE_2BYTE(_ele_start, 7, 3, _val)
#define SET_TWT_REQ_TYPE_TWT_WAKE_INTERVAL_EXPONENT(_ele_start, _val) \
   SET_BITS_TO_LE_2BYTE(_ele_start, 10, 5, _val)
#define SET_TWT_REQ_TYPE_TWT_PROTECTION(_ele_start, _val) \
   SET_BITS_TO_LE_2BYTE(_ele_start, 15, 1, _val)
 
#define SET_TWT_TARGET_WAKE_TIME_L(_ele_start, _val) \
   SET_BITS_TO_LE_4BYTE((_ele_start) + 2, 0, 32, _val)
 
#define SET_TWT_TARGET_WAKE_TIME_H(_ele_start, _val) \
   SET_BITS_TO_LE_4BYTE((_ele_start) + 6, 0, 32, _val)
/*twt group assignment*/
 
 
#define SET_TWT_NOMINAL_MINIMUM_TWT_WAKE_DURATION(_ele_start, _offset, _val) \
   SET_BITS_TO_LE_1BYTE((_ele_start) + _offset, 0, 8, _val)
#define SET_TWT_TWT_WAKE_INTERVAL_MANTISSA(_ele_start, _offset, _val) \
   SET_BITS_TO_LE_2BYTE((_ele_start) + _offset, 0, 16, _val)
#define SET_TWT_TWT_CHANNEL(_ele_start, _offset, _val) \
   SET_BITS_TO_LE_1BYTE((_ele_start) + _offset, 0, 8, _val)
 
 
/*Broadcast TWT Parameter Set field*/
 
 
/*TWT FLOW field*/
#define SET_TWT_FLOW_ID(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 0, 3, _val)
#define SET_NEGOTIATION_TYPE(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 5, 2, _val)
#define SET_TEARDOWN_ALL_TWT(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 7, 1, _val)
 
#define SET_BROADCAST_TWT_ID(_ele_start, _val) \
   SET_BITS_TO_LE_1BYTE(_ele_start, 0, 5, _val)
 
/*Control*/
/*Bit0*/
#define GET_TWT_CONTROL_NDP_PAGING_INDICATOR(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0, 1)
/*Bit1*/
#define GET_TWT_CONTROL_RESPONDER_PM_MODE(_buf) \
   LE_BITS_TO_1BYTE(_buf, 1, 1)
/*Bit2-3*/
#define GET_TWT_CONTROL_NEGOTIATION_TYPE(_buf) \
   LE_BITS_TO_1BYTE(_buf, 2, 2)
/*Bit4*/
#define GET_TWT_CONTROL_TWT_INFORMATION_FRAME_DISABLE(_buf) \
   LE_BITS_TO_1BYTE(_buf, 4, 1)
/*Bit5*/
#define GET_TWT_CONTROL_WAKE_DURATION_UNIT(_buf) \
   LE_BITS_TO_1BYTE(_buf, 5, 1)
 
/*Request Type*/
/*Bit0*/
#define GET_TWT_REQ_TYPE_TWT_REQUEST(_buf) \
   LE_BITS_TO_2BYTE(_buf, 0, 1)
/*Bit1-3*/
#define GET_TWT_REQ_TYPE_TWT_SETUP_COMMAND(_buf) \
   LE_BITS_TO_2BYTE(_buf, 1, 3)
/*Bit4*/
#define GET_TWT_REQ_TYPE_TRIGGER(_buf) \
   LE_BITS_TO_2BYTE(_buf, 4, 1)
/*Bit5*/
#define GET_TWT_REQ_TYPE_IMPLICIT(_buf) \
   LE_BITS_TO_2BYTE(_buf, 5, 1)
/*Bit6*/
#define GET_TWT_REQ_TYPE_FLOW_TYPE(_buf) \
   LE_BITS_TO_2BYTE(_buf, 6, 1)
/*Bit7-9*/
#define GET_TWT_REQ_TYPE_TWT_FLOW_IDENTIFER(_buf) \
   LE_BITS_TO_2BYTE(_buf, 7, 3)
/*Bit10-14*/
#define GET_TWT_REQ_TYPE_TWT_WAKE_INTERVAL_EXPONENT(_buf) \
   LE_BITS_TO_2BYTE(_buf, 10, 5)
/*Bit15*/
#define GET_TWT_REQ_TYPE_TWT_PROTECTION(_buf) \
   LE_BITS_TO_2BYTE(_buf, 15, 1)
 
#define GET_TWT_TARGET_WAKE_TIME_L(_buf) \
   LE_BITS_TO_4BYTE(_buf, 0, 32)
#define GET_TWT_TARGET_WAKE_TIME_H(_buf) \
   LE_BITS_TO_4BYTE((_buf) + 4, 0, 32)
#define GET_TWT_NOMINAL_MINIMUM_TWT_WAKE_DURATION(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0 , 8);
#define GET_TWT_TWT_WAKE_INTERVAL_MANTISSA(_buf) \
   LE_BITS_TO_2BYTE(_buf, 0, 16);
#define GET_TWT_TWT_CHANNEL(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0 ,8);
 
/*TWT FLOW field*/
/*Bit0-2*/
#define GET_TWT_FLOW_ID(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0, 3)
/*Bit5-6*/
#define GET_NEGOTIATION_TYPE(_buf) \
   LE_BITS_TO_1BYTE(_buf, 5 , 2);
/*Bit7*/
#define GET_TEARDOWN_ALL_TWT(_buf) \
   LE_BITS_TO_1BYTE(_buf, 7, 1)
/*Bit0-4*/
#define GET_BROADCAST_TWT_ID(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0, 5)
 
 
#define GET_ELE_ID(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0, 8);
#define GET_ELE_LEN(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0, 8);
#define GET_DIALOG_TOKEN(_buf) \
   LE_BITS_TO_1BYTE(_buf, 0, 8);
 
 
enum rtw_phl_status phl_twt_init(void *phl);
 
void phl_twt_deinit(void *phl);
 
enum rtw_phl_status
rtw_phl_twt_disable_all_twt_by_role(void *phl, struct rtw_wifi_role_t *role);
 
enum rtw_phl_status rtw_phl_twt_alloc_twt_config(void *phl, struct rtw_wifi_role_t *role,
       struct rtw_phl_twt_setup_info setup_info, u8 benable, u8 *id);
 
enum rtw_phl_status rtw_phl_twt_free_twt_config(void *phl, u8 id);
 
enum rtw_phl_status rtw_phl_twt_add_sta_info(void *phl, struct rtw_phl_stainfo_t *phl_sta,
           u8 config_id, u8 id);
 
#else
 
#define phl_twt_init(_phl) RTW_PHL_STATUS_SUCCESS
#define phl_twt_deinit(_phl)
 
#endif /* CONFIG_PHL_TWT */
#endif /*_PHL_TWT_H_*/