1 /*
2 * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for
6 * any purpose with or without fee is hereby granted, provided that the
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #include <osdep.h>
21 #include "wmi.h"
22 #include "wmi_unified_priv.h"
23 #include "wmi_unified_twt_param.h"
24 #include "wmi_unified_twt_api.h"
25
26 #if defined(WLAN_SUPPORT_TWT) && defined(WLAN_TWT_CONV_SUPPORTED)
send_twt_enable_cmd_tlv(wmi_unified_t wmi_handle,struct twt_enable_param * params)27 static QDF_STATUS send_twt_enable_cmd_tlv(wmi_unified_t wmi_handle,
28 struct twt_enable_param *params)
29 {
30 wmi_twt_enable_cmd_fixed_param *cmd;
31 wmi_buf_t buf;
32 QDF_STATUS status;
33
34 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
35 if (!buf) {
36 wmi_err("Failed to allocate memory");
37 return QDF_STATUS_E_FAILURE;
38 }
39
40 cmd = (wmi_twt_enable_cmd_fixed_param *)wmi_buf_data(buf);
41 WMITLV_SET_HDR(&cmd->tlv_header,
42 WMITLV_TAG_STRUC_wmi_twt_enable_cmd_fixed_param,
43 WMITLV_GET_STRUCT_TLVLEN
44 (wmi_twt_enable_cmd_fixed_param));
45
46 cmd->pdev_id =
47 wmi_handle->ops->convert_pdev_id_host_to_target(
48 wmi_handle,
49 params->pdev_id);
50 cmd->sta_cong_timer_ms = params->sta_cong_timer_ms;
51 cmd->mbss_support = params->mbss_support;
52 cmd->default_slot_size = params->default_slot_size;
53 cmd->congestion_thresh_setup = params->congestion_thresh_setup;
54 cmd->congestion_thresh_teardown = params->congestion_thresh_teardown;
55 cmd->congestion_thresh_critical = params->congestion_thresh_critical;
56 cmd->interference_thresh_teardown =
57 params->interference_thresh_teardown;
58 cmd->interference_thresh_setup = params->interference_thresh_setup;
59 cmd->min_no_sta_setup = params->min_no_sta_setup;
60 cmd->min_no_sta_teardown = params->min_no_sta_teardown;
61 cmd->no_of_bcast_mcast_slots = params->no_of_bcast_mcast_slots;
62 cmd->min_no_twt_slots = params->min_no_twt_slots;
63 cmd->max_no_sta_twt = params->max_no_sta_twt;
64 cmd->mode_check_interval = params->mode_check_interval;
65 cmd->add_sta_slot_interval = params->add_sta_slot_interval;
66 cmd->remove_sta_slot_interval = params->remove_sta_slot_interval;
67
68 TWT_EN_DIS_FLAGS_SET_BTWT(cmd->flags, params->b_twt_enable);
69 TWT_EN_DIS_FLAGS_SET_B_R_TWT(cmd->flags, params->r_twt_enable);
70 TWT_EN_DIS_FLAGS_SET_L_MBSSID(cmd->flags,
71 params->b_twt_legacy_mbss_enable);
72 TWT_EN_DIS_FLAGS_SET_AX_MBSSID(cmd->flags,
73 params->b_twt_ax_mbss_enable);
74 if (params->ext_conf_present) {
75 TWT_EN_DIS_FLAGS_SET_SPLIT_CONFIG(cmd->flags, 1);
76 TWT_EN_DIS_FLAGS_SET_REQ_RESP(cmd->flags, params->twt_role);
77 TWT_EN_DIS_FLAGS_SET_I_B_TWT(cmd->flags, params->twt_oper);
78 }
79
80 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
81 WMI_TWT_ENABLE_CMDID);
82 if (QDF_IS_STATUS_ERROR(status)) {
83 wmi_err("Failed to send WMI_TWT_ENABLE_CMDID");
84 wmi_buf_free(buf);
85 }
86
87 return status;
88 }
89
90 static WMI_DISABLE_TWT_REASON_T
wmi_convert_dis_reason_code(enum HOST_TWT_DISABLE_REASON reason)91 wmi_convert_dis_reason_code(enum HOST_TWT_DISABLE_REASON reason)
92 {
93 switch (reason) {
94 case HOST_TWT_DISABLE_REASON_NONE:
95 return WMI_DISABLE_TWT_REASON_NONE;
96 case HOST_TWT_DISABLE_REASON_CONCURRENCY_SCC:
97 return WMI_DISABLE_TWT_REASON_CONCURRENCY_SCC;
98 case HOST_TWT_DISABLE_REASON_CONCURRENCY_MCC:
99 return WMI_DISABLE_TWT_REASON_CONCURRENCY_MCC;
100 case HOST_TWT_DISABLE_REASON_CHANGE_CONGESTION_TIMEOUT:
101 return WMI_DISABLE_TWT_REASON_CHANGE_CONGESTION_TIMEOUT;
102 case HOST_TWT_DISABLE_REASON_P2P_GO_NOA:
103 return WMI_DISABLE_TWT_REASON_P2P_GO_NOA;
104 default:
105 return WMI_DISABLE_TWT_REASON_NONE;
106 }
107 }
108
send_twt_disable_cmd_tlv(wmi_unified_t wmi_handle,struct twt_disable_param * params)109 static QDF_STATUS send_twt_disable_cmd_tlv(wmi_unified_t wmi_handle,
110 struct twt_disable_param *params)
111 {
112 wmi_twt_disable_cmd_fixed_param *cmd;
113 wmi_buf_t buf;
114 QDF_STATUS status;
115
116 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
117 if (!buf) {
118 wmi_err("Failed to allocate memory");
119 return QDF_STATUS_E_FAILURE;
120 }
121
122 cmd = (wmi_twt_disable_cmd_fixed_param *)wmi_buf_data(buf);
123 WMITLV_SET_HDR(&cmd->tlv_header,
124 WMITLV_TAG_STRUC_wmi_twt_disable_cmd_fixed_param,
125 WMITLV_GET_STRUCT_TLVLEN
126 (wmi_twt_disable_cmd_fixed_param));
127
128 cmd->pdev_id =
129 wmi_handle->ops->convert_pdev_id_host_to_target(
130 wmi_handle,
131 params->pdev_id);
132 if (params->ext_conf_present) {
133 TWT_EN_DIS_FLAGS_SET_SPLIT_CONFIG(cmd->flags, 1);
134 TWT_EN_DIS_FLAGS_SET_REQ_RESP(cmd->flags, params->twt_role);
135 TWT_EN_DIS_FLAGS_SET_I_B_TWT(cmd->flags, params->twt_oper);
136 }
137
138 cmd->reason_code = wmi_convert_dis_reason_code(
139 params->dis_reason_code);
140 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
141 WMI_TWT_DISABLE_CMDID);
142 if (QDF_IS_STATUS_ERROR(status)) {
143 wmi_err("Failed to send WMI_TWT_DISABLE_CMDID");
144 wmi_buf_free(buf);
145 }
146
147 return status;
148 }
149
150 #ifdef WLAN_SUPPORT_BCAST_TWT
151 static void
twt_add_dialog_set_bcast_twt_params(struct twt_add_dialog_param * params,wmi_twt_add_dialog_cmd_fixed_param * cmd)152 twt_add_dialog_set_bcast_twt_params(struct twt_add_dialog_param *params,
153 wmi_twt_add_dialog_cmd_fixed_param *cmd)
154 {
155 TWT_FLAGS_SET_BTWT_ID0(cmd->flags, params->flag_b_twt_id0);
156 cmd->b_twt_persistence = params->b_twt_persistence;
157 cmd->b_twt_recommendation = params->b_twt_recommendation;
158 }
159 #else
160 static void
twt_add_dialog_set_bcast_twt_params(struct twt_add_dialog_param * params,wmi_twt_add_dialog_cmd_fixed_param * cmd)161 twt_add_dialog_set_bcast_twt_params(struct twt_add_dialog_param *params,
162 wmi_twt_add_dialog_cmd_fixed_param *cmd)
163 {
164 }
165 #endif
166
167 static QDF_STATUS
send_twt_add_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct twt_add_dialog_param * params)168 send_twt_add_dialog_cmd_tlv(wmi_unified_t wmi_handle,
169 struct twt_add_dialog_param *params)
170 {
171 wmi_twt_add_dialog_cmd_fixed_param *cmd;
172 wmi_buf_t buf;
173 QDF_STATUS status;
174
175 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
176 if (!buf) {
177 wmi_err("Failed to allocate memory");
178 return QDF_STATUS_E_FAILURE;
179 }
180
181 cmd = (wmi_twt_add_dialog_cmd_fixed_param *)wmi_buf_data(buf);
182 WMITLV_SET_HDR(&cmd->tlv_header,
183 WMITLV_TAG_STRUC_wmi_twt_add_dialog_cmd_fixed_param,
184 WMITLV_GET_STRUCT_TLVLEN
185 (wmi_twt_add_dialog_cmd_fixed_param));
186
187 cmd->vdev_id = params->vdev_id;
188 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr.bytes,
189 &cmd->peer_macaddr);
190 cmd->dialog_id = params->dialog_id;
191 cmd->wake_intvl_us = params->wake_intvl_us;
192 cmd->wake_intvl_mantis = params->wake_intvl_mantis;
193 cmd->wake_dura_us = params->wake_dura_us;
194 cmd->sp_offset_us = params->sp_offset_us;
195 cmd->min_wake_intvl_us = params->min_wake_intvl_us;
196 cmd->max_wake_intvl_us = params->max_wake_intvl_us;
197 cmd->min_wake_dura_us = params->min_wake_dura_us;
198 cmd->max_wake_dura_us = params->max_wake_dura_us;
199 cmd->sp_start_tsf_lo = (uint32_t)(params->wake_time_tsf & 0xFFFFFFFF);
200 cmd->sp_start_tsf_hi = (uint32_t)(params->wake_time_tsf >> 32);
201 cmd->announce_timeout_us = params->announce_timeout_us;
202 cmd->link_id_bitmap = params->link_id_bitmap;
203 cmd->r_twt_dl_tid_bitmap = params->r_twt_dl_tid_bitmap;
204 cmd->r_twt_ul_tid_bitmap = params->r_twt_ul_tid_bitmap;
205 TWT_FLAGS_SET_CMD(cmd->flags, params->twt_cmd);
206 TWT_FLAGS_SET_BROADCAST(cmd->flags, params->flag_bcast);
207 TWT_FLAGS_SET_TRIGGER(cmd->flags, params->flag_trigger);
208 TWT_FLAGS_SET_FLOW_TYPE(cmd->flags, params->flag_flow_type);
209 TWT_FLAGS_SET_PROTECTION(cmd->flags, params->flag_protection);
210
211 twt_add_dialog_set_bcast_twt_params(params, cmd);
212
213 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
214 WMI_TWT_ADD_DIALOG_CMDID);
215 if (QDF_IS_STATUS_ERROR(status)) {
216 wmi_err("Failed to send WMI_TWT_ADD_DIALOG_CMDID");
217 wmi_buf_free(buf);
218 }
219
220 return status;
221 }
222
223 #ifdef WLAN_SUPPORT_BCAST_TWT
224 static void
twt_del_dialog_set_bcast_twt_params(struct twt_del_dialog_param * params,wmi_twt_del_dialog_cmd_fixed_param * cmd)225 twt_del_dialog_set_bcast_twt_params(struct twt_del_dialog_param *params,
226 wmi_twt_del_dialog_cmd_fixed_param *cmd)
227 {
228 cmd->b_twt_persistence = params->b_twt_persistence;
229 }
230 #else
231 static void
twt_del_dialog_set_bcast_twt_params(struct twt_del_dialog_param * params,wmi_twt_del_dialog_cmd_fixed_param * cmd)232 twt_del_dialog_set_bcast_twt_params(struct twt_del_dialog_param *params,
233 wmi_twt_del_dialog_cmd_fixed_param *cmd)
234 {
235 }
236 #endif
237
238 static QDF_STATUS
send_twt_del_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct twt_del_dialog_param * params)239 send_twt_del_dialog_cmd_tlv(wmi_unified_t wmi_handle,
240 struct twt_del_dialog_param *params)
241 {
242 wmi_twt_del_dialog_cmd_fixed_param *cmd;
243 wmi_buf_t buf;
244 QDF_STATUS status;
245
246 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
247 if (!buf) {
248 wmi_err("Failed to allocate memory");
249 return QDF_STATUS_E_FAILURE;
250 }
251
252 cmd = (wmi_twt_del_dialog_cmd_fixed_param *)wmi_buf_data(buf);
253 WMITLV_SET_HDR(&cmd->tlv_header,
254 WMITLV_TAG_STRUC_wmi_twt_del_dialog_cmd_fixed_param,
255 WMITLV_GET_STRUCT_TLVLEN
256 (wmi_twt_del_dialog_cmd_fixed_param));
257
258 cmd->vdev_id = params->vdev_id;
259 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr.bytes,
260 &cmd->peer_macaddr);
261 cmd->dialog_id = params->dialog_id;
262
263 twt_del_dialog_set_bcast_twt_params(params, cmd);
264
265 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
266 WMI_TWT_DEL_DIALOG_CMDID);
267 if (QDF_IS_STATUS_ERROR(status)) {
268 wmi_err("Failed to send WMI_TWT_DEL_DIALOG_CMDID");
269 wmi_buf_free(buf);
270 }
271
272 return status;
273 }
274
275 static QDF_STATUS
send_twt_pause_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct twt_pause_dialog_cmd_param * params)276 send_twt_pause_dialog_cmd_tlv(wmi_unified_t wmi_handle,
277 struct twt_pause_dialog_cmd_param *params)
278 {
279 wmi_twt_pause_dialog_cmd_fixed_param *cmd;
280 wmi_buf_t buf;
281 QDF_STATUS status;
282
283 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
284 if (!buf) {
285 wmi_err("Failed to allocate memory");
286 return QDF_STATUS_E_FAILURE;
287 }
288
289 cmd = (wmi_twt_pause_dialog_cmd_fixed_param *)wmi_buf_data(buf);
290 WMITLV_SET_HDR(&cmd->tlv_header,
291 WMITLV_TAG_STRUC_wmi_twt_pause_dialog_cmd_fixed_param,
292 WMITLV_GET_STRUCT_TLVLEN
293 (wmi_twt_pause_dialog_cmd_fixed_param));
294
295 cmd->vdev_id = params->vdev_id;
296 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr.bytes,
297 &cmd->peer_macaddr);
298 cmd->dialog_id = params->dialog_id;
299
300 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
301 WMI_TWT_PAUSE_DIALOG_CMDID);
302 if (QDF_IS_STATUS_ERROR(status)) {
303 wmi_err("Failed to send WMI_TWT_PAUSE_DIALOG_CMDID");
304 wmi_buf_free(buf);
305 }
306
307 return status;
308 }
309
310 static QDF_STATUS
send_twt_nudge_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct twt_nudge_dialog_cmd_param * params)311 send_twt_nudge_dialog_cmd_tlv(wmi_unified_t wmi_handle,
312 struct twt_nudge_dialog_cmd_param *params)
313 {
314 wmi_twt_nudge_dialog_cmd_fixed_param *cmd;
315 wmi_buf_t buf;
316 QDF_STATUS status;
317
318 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
319 if (!buf)
320 return QDF_STATUS_E_FAILURE;
321
322 cmd = (wmi_twt_nudge_dialog_cmd_fixed_param *)wmi_buf_data(buf);
323 WMITLV_SET_HDR(&cmd->tlv_header,
324 WMITLV_TAG_STRUC_wmi_twt_nudge_dialog_cmd_fixed_param,
325 WMITLV_GET_STRUCT_TLVLEN
326 (wmi_twt_nudge_dialog_cmd_fixed_param));
327
328 cmd->vdev_id = params->vdev_id;
329 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr.bytes,
330 &cmd->peer_macaddr);
331 cmd->dialog_id = params->dialog_id;
332 cmd->suspend_duration_ms = params->suspend_duration / 1000;
333 cmd->next_twt_size = params->next_twt_size;
334 cmd->sp_start_offset = params->sp_start_offset;
335
336 wmi_debug("vdev_id: %d dialog_id: %d duration(in ms): %u next_twt_size: %d "
337 "peer_macaddr: " QDF_MAC_ADDR_FMT " sp_start_offset: %d",
338 cmd->vdev_id, cmd->dialog_id, cmd->suspend_duration_ms,
339 cmd->next_twt_size,
340 QDF_MAC_ADDR_REF(params->peer_macaddr.bytes),
341 cmd->sp_start_offset);
342
343 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
344 WMI_TWT_NUDGE_DIALOG_CMDID);
345 if (QDF_IS_STATUS_ERROR(status))
346 wmi_buf_free(buf);
347
348 return status;
349 }
350
send_twt_resume_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct twt_resume_dialog_cmd_param * params)351 static QDF_STATUS send_twt_resume_dialog_cmd_tlv(wmi_unified_t wmi_handle,
352 struct twt_resume_dialog_cmd_param *params)
353 {
354 wmi_twt_resume_dialog_cmd_fixed_param *cmd;
355 wmi_buf_t buf;
356 QDF_STATUS status;
357
358 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
359 if (!buf) {
360 wmi_err("Failed to allocate memory");
361 return QDF_STATUS_E_FAILURE;
362 }
363
364 cmd = (wmi_twt_resume_dialog_cmd_fixed_param *)wmi_buf_data(buf);
365 WMITLV_SET_HDR(&cmd->tlv_header,
366 WMITLV_TAG_STRUC_wmi_twt_resume_dialog_cmd_fixed_param,
367 WMITLV_GET_STRUCT_TLVLEN
368 (wmi_twt_resume_dialog_cmd_fixed_param));
369
370 cmd->vdev_id = params->vdev_id;
371 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr.bytes,
372 &cmd->peer_macaddr);
373 cmd->dialog_id = params->dialog_id;
374 cmd->sp_offset_us = params->sp_offset_us;
375 cmd->next_twt_size = params->next_twt_size;
376
377 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
378 WMI_TWT_RESUME_DIALOG_CMDID);
379 if (QDF_IS_STATUS_ERROR(status)) {
380 wmi_err("Failed to send WMI_TWT_RESUME_DIALOG_CMDID");
381 wmi_buf_free(buf);
382 }
383
384 return status;
385 }
386
387 #ifdef WLAN_SUPPORT_BCAST_TWT
388 static QDF_STATUS
send_twt_btwt_invite_sta_cmd_tlv(wmi_unified_t wmi_handle,struct twt_btwt_invite_sta_cmd_param * params)389 send_twt_btwt_invite_sta_cmd_tlv(wmi_unified_t wmi_handle,
390 struct twt_btwt_invite_sta_cmd_param *params)
391 {
392 wmi_twt_btwt_invite_sta_cmd_fixed_param *cmd;
393 wmi_buf_t buf;
394 QDF_STATUS status;
395
396 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
397 if (!buf) {
398 wmi_err("Failed to allocate memory");
399 return QDF_STATUS_E_FAILURE;
400 }
401
402 cmd = (wmi_twt_btwt_invite_sta_cmd_fixed_param *)wmi_buf_data(buf);
403 WMITLV_SET_HDR(&cmd->tlv_header,
404 WMITLV_TAG_STRUC_wmi_twt_btwt_invite_sta_cmd_fixed_param,
405 WMITLV_GET_STRUCT_TLVLEN
406 (wmi_twt_btwt_invite_sta_cmd_fixed_param));
407
408 cmd->vdev_id = params->vdev_id;
409 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr.bytes,
410 &cmd->peer_macaddr);
411 cmd->dialog_id = params->dialog_id;
412 cmd->r_twt_dl_tid_bitmap = params->r_twt_dl_tid_bitmap;
413 cmd->r_twt_ul_tid_bitmap = params->r_twt_ul_tid_bitmap;
414
415 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
416 WMI_TWT_BTWT_INVITE_STA_CMDID);
417 if (QDF_IS_STATUS_ERROR(status)) {
418 wmi_buf_free(buf);
419 wmi_err("Failed to send WMI_TWT_BTWT_INVITE_STA_CMDID");
420 }
421
422 return status;
423 }
424
425 static QDF_STATUS
send_twt_btwt_remove_sta_cmd_tlv(wmi_unified_t wmi_handle,struct twt_btwt_remove_sta_cmd_param * params)426 send_twt_btwt_remove_sta_cmd_tlv(wmi_unified_t wmi_handle,
427 struct twt_btwt_remove_sta_cmd_param
428 *params)
429 {
430 wmi_twt_btwt_remove_sta_cmd_fixed_param *cmd;
431 wmi_buf_t buf;
432 QDF_STATUS status;
433
434 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
435 if (!buf) {
436 wmi_err("Failed to allocate memory");
437 return QDF_STATUS_E_FAILURE;
438 }
439
440 cmd = (wmi_twt_btwt_remove_sta_cmd_fixed_param *)wmi_buf_data(buf);
441 WMITLV_SET_HDR(&cmd->tlv_header,
442 WMITLV_TAG_STRUC_wmi_twt_btwt_remove_sta_cmd_fixed_param,
443 WMITLV_GET_STRUCT_TLVLEN
444 (wmi_twt_btwt_remove_sta_cmd_fixed_param));
445
446 cmd->vdev_id = params->vdev_id;
447 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr.bytes,
448 &cmd->peer_macaddr);
449 cmd->dialog_id = params->dialog_id;
450 cmd->r_twt_dl_tid_bitmap = params->r_twt_dl_tid_bitmap;
451 cmd->r_twt_ul_tid_bitmap = params->r_twt_ul_tid_bitmap;
452
453 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
454 WMI_TWT_BTWT_REMOVE_STA_CMDID);
455 if (QDF_IS_STATUS_ERROR(status)) {
456 wmi_buf_free(buf);
457 wmi_err("Failed to send WMI_TWT_BTWT_REMOVE_STA_CMDID");
458 }
459
460 return status;
461 }
462 #endif
463
464 static enum HOST_TWT_ENABLE_STATUS
wmi_twt_enable_status_to_host_twt_status(WMI_ENABLE_TWT_STATUS_T status)465 wmi_twt_enable_status_to_host_twt_status(WMI_ENABLE_TWT_STATUS_T status)
466 {
467 switch (status) {
468 case WMI_ENABLE_TWT_STATUS_OK:
469 return HOST_TWT_ENABLE_STATUS_OK;
470 case WMI_ENABLE_TWT_STATUS_ALREADY_ENABLED:
471 return HOST_TWT_ENABLE_STATUS_ALREADY_ENABLED;
472 case WMI_ENABLE_TWT_STATUS_NOT_READY:
473 return HOST_TWT_ENABLE_STATUS_NOT_READY;
474 case WMI_ENABLE_TWT_INVALID_PARAM:
475 return HOST_TWT_ENABLE_INVALID_PARAM;
476 default:
477 return HOST_TWT_ENABLE_STATUS_UNKNOWN_ERROR;
478 }
479 }
480
extract_twt_enable_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_enable_complete_event_param * params)481 static QDF_STATUS extract_twt_enable_comp_event_tlv(wmi_unified_t wmi_handle,
482 uint8_t *evt_buf,
483 struct twt_enable_complete_event_param *params)
484 {
485 WMI_TWT_ENABLE_COMPLETE_EVENTID_param_tlvs *param_buf;
486 wmi_twt_enable_complete_event_fixed_param *ev;
487
488 param_buf = (WMI_TWT_ENABLE_COMPLETE_EVENTID_param_tlvs *)evt_buf;
489 if (!param_buf) {
490 wmi_err("evt_buf is NULL");
491 return QDF_STATUS_E_INVAL;
492 }
493
494 ev = param_buf->fixed_param;
495
496 params->pdev_id =
497 wmi_handle->ops->convert_pdev_id_target_to_host(wmi_handle,
498 ev->pdev_id);
499 params->status = wmi_twt_enable_status_to_host_twt_status(ev->status);
500
501 return QDF_STATUS_SUCCESS;
502 }
503
504 static enum HOST_TWT_DISABLE_STATUS
wmi_twt_disable_status_to_host_twt_status(WMI_DISABLE_TWT_STATUS_T status)505 wmi_twt_disable_status_to_host_twt_status(WMI_DISABLE_TWT_STATUS_T status)
506 {
507 switch (status) {
508 case WMI_DISABLE_TWT_STATUS_OK:
509 return HOST_TWT_DISABLE_STATUS_OK;
510 case WMI_DISABLE_TWT_STATUS_ROAM_IN_PROGRESS:
511 return HOST_TWT_DISABLE_STATUS_ROAM_IN_PROGRESS;
512 case WMI_DISABLE_TWT_STATUS_CHAN_SW_IN_PROGRESS:
513 return HOST_TWT_DISABLE_STATUS_CHAN_SW_IN_PROGRESS;
514 case WMI_DISABLE_TWT_STATUS_SCAN_IN_PROGRESS:
515 return HOST_TWT_DISABLE_STATUS_SCAN_IN_PROGRESS;
516 default:
517 return HOST_TWT_DISABLE_STATUS_UNKNOWN_ERROR;
518 }
519 }
520
extract_twt_disable_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_disable_complete_event_param * params)521 static QDF_STATUS extract_twt_disable_comp_event_tlv(wmi_unified_t wmi_handle,
522 uint8_t *evt_buf,
523 struct twt_disable_complete_event_param *params)
524 {
525 WMI_TWT_DISABLE_COMPLETE_EVENTID_param_tlvs *param_buf;
526 wmi_twt_disable_complete_event_fixed_param *ev;
527
528 param_buf = (WMI_TWT_DISABLE_COMPLETE_EVENTID_param_tlvs *)evt_buf;
529 if (!param_buf) {
530 wmi_err("evt_buf is NULL");
531 return QDF_STATUS_E_INVAL;
532 }
533
534 ev = param_buf->fixed_param;
535
536 params->pdev_id =
537 wmi_handle->ops->convert_pdev_id_target_to_host(wmi_handle,
538 ev->pdev_id);
539 params->status = wmi_twt_disable_status_to_host_twt_status(ev->status);
540
541 return QDF_STATUS_SUCCESS;
542 }
543
544 static enum HOST_TWT_ADD_STATUS
wmi_get_converted_twt_add_dialog_status(WMI_ADD_TWT_STATUS_T tgt_status)545 wmi_get_converted_twt_add_dialog_status(WMI_ADD_TWT_STATUS_T tgt_status)
546 {
547 switch (tgt_status) {
548 case WMI_ADD_TWT_STATUS_OK:
549 return HOST_TWT_ADD_STATUS_OK;
550 case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
551 return HOST_TWT_ADD_STATUS_TWT_NOT_ENABLED;
552 case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
553 return HOST_TWT_ADD_STATUS_USED_DIALOG_ID;
554 case WMI_ADD_TWT_STATUS_INVALID_PARAM:
555 return HOST_TWT_ADD_STATUS_INVALID_PARAM;
556 case WMI_ADD_TWT_STATUS_NOT_READY:
557 return HOST_TWT_ADD_STATUS_NOT_READY;
558 case WMI_ADD_TWT_STATUS_NO_RESOURCE:
559 return HOST_TWT_ADD_STATUS_NO_RESOURCE;
560 case WMI_ADD_TWT_STATUS_NO_ACK:
561 return HOST_TWT_ADD_STATUS_NO_ACK;
562 case WMI_ADD_TWT_STATUS_NO_RESPONSE:
563 return HOST_TWT_ADD_STATUS_NO_RESPONSE;
564 case WMI_ADD_TWT_STATUS_DENIED:
565 return HOST_TWT_ADD_STATUS_DENIED;
566 case WMI_ADD_TWT_STATUS_AP_PARAMS_NOT_IN_RANGE:
567 return HOST_TWT_ADD_STATUS_AP_PARAMS_NOT_IN_RANGE;
568 case WMI_ADD_TWT_STATUS_AP_IE_VALIDATION_FAILED:
569 return HOST_TWT_ADD_STATUS_AP_IE_VALIDATION_FAILED;
570 case WMI_ADD_TWT_STATUS_ROAM_IN_PROGRESS:
571 return HOST_TWT_ADD_STATUS_ROAM_IN_PROGRESS;
572 case WMI_ADD_TWT_STATUS_CHAN_SW_IN_PROGRESS:
573 return HOST_TWT_ADD_STATUS_CHAN_SW_IN_PROGRESS;
574 case WMI_ADD_TWT_STATUS_SCAN_IN_PROGRESS:
575 return HOST_TWT_ADD_STATUS_SCAN_IN_PROGRESS;
576 case WMI_ADD_TWT_STATUS_LINK_SWITCH_IN_PROGRESS:
577 return HOST_TWT_ADD_STATUS_LINK_SWITCH_IN_PROGRESS;
578 case WMI_ADD_TWT_STATUS_UNSUPPORTED_MODE_MLMR:
579 return HOST_TWT_ADD_STATUS_UNSUPPORTED_MODE_MLMR;
580 default:
581 return HOST_TWT_ADD_STATUS_UNKNOWN_ERROR;
582 }
583 }
584
585 /**
586 * extract_twt_add_dialog_comp_event_tlv - Extacts twt add dialog complete wmi
587 * event from firmware
588 * @wmi_handle: WMI handle
589 * @evt_buf: Pointer to wmi event buf of twt add dialog complete event
590 * @params: Pointer to store the extracted parameters
591 *
592 * Return: QDF_STATUS_SUCCESS on success or QDF STATUS error values on failure
593 */
extract_twt_add_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_add_dialog_complete_event_param * params)594 static QDF_STATUS extract_twt_add_dialog_comp_event_tlv(
595 wmi_unified_t wmi_handle,
596 uint8_t *evt_buf,
597 struct twt_add_dialog_complete_event_param *params)
598 {
599 WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
600 wmi_twt_add_dialog_complete_event_fixed_param *ev;
601
602 param_buf = (WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
603 if (!param_buf) {
604 wmi_err("evt_buf is NULL");
605 return QDF_STATUS_E_INVAL;
606 }
607
608 ev = param_buf->fixed_param;
609
610 params->vdev_id = ev->vdev_id;
611 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr,
612 params->peer_macaddr.bytes);
613 params->status = wmi_get_converted_twt_add_dialog_status(ev->status);
614 params->dialog_id = ev->dialog_id;
615 params->num_additional_twt_params = param_buf->num_twt_params;
616
617 return QDF_STATUS_SUCCESS;
618 }
619
620 /**
621 * extract_twt_add_dialog_comp_additional_parameters() - Extracts additional twt
622 * twt parameters, as part of add dialog completion event
623 * @wmi_handle: wmi handle
624 * @evt_buf: Pointer event buffer
625 * @evt_buf_len: length of the add dialog event buffer
626 * @idx: index of num_twt_params
627 * @additional_params: twt additional parameters to extract
628 *
629 * Return: QDF_STATUS_SUCCESS on success and QDF_STATUS_E_INVAL for failure
630 */
extract_twt_add_dialog_comp_additional_parameters(wmi_unified_t wmi_handle,uint8_t * evt_buf,uint32_t evt_buf_len,uint32_t idx,struct twt_add_dialog_additional_params * additional_params)631 static QDF_STATUS extract_twt_add_dialog_comp_additional_parameters
632 (
633 wmi_unified_t wmi_handle, uint8_t *evt_buf,
634 uint32_t evt_buf_len, uint32_t idx,
635 struct twt_add_dialog_additional_params *additional_params
636 )
637 {
638 WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
639 wmi_twt_add_dialog_complete_event_fixed_param *ev;
640 uint32_t flags = 0;
641 uint32_t expected_len;
642
643 param_buf = (WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
644 if (!param_buf) {
645 wmi_err("evt_buf is NULL");
646 return QDF_STATUS_E_INVAL;
647 }
648
649 ev = param_buf->fixed_param;
650
651 if (idx >= param_buf->num_twt_params) {
652 wmi_err("Invalid idx %d while num_twt_params = %d",
653 idx, param_buf->num_twt_params);
654 return QDF_STATUS_E_INVAL;
655 }
656
657 if (!param_buf->twt_params) {
658 wmi_err("Unable to extract additional twt parameters");
659 return QDF_STATUS_E_INVAL;
660 }
661
662 expected_len = (sizeof(wmi_twt_add_dialog_complete_event_fixed_param) +
663 WMI_TLV_HDR_SIZE + (param_buf->num_twt_params *
664 sizeof(wmi_twt_add_dialog_additional_params)));
665
666 if (evt_buf_len != expected_len) {
667 wmi_err("Got invalid len data from FW %d expected %d",
668 evt_buf_len, expected_len);
669 return QDF_STATUS_E_INVAL;
670 }
671
672 flags = param_buf->twt_params[idx].flags;
673 additional_params->twt_cmd = TWT_FLAGS_GET_CMD(flags);
674 additional_params->bcast = TWT_FLAGS_GET_BROADCAST(flags);
675 additional_params->trig_en = TWT_FLAGS_GET_TRIGGER(flags);
676 additional_params->announce = TWT_FLAGS_GET_FLOW_TYPE(flags);
677 additional_params->protection = TWT_FLAGS_GET_PROTECTION(flags);
678 additional_params->b_twt_id0 = TWT_FLAGS_GET_BTWT_ID0(flags);
679 additional_params->info_frame_disabled =
680 TWT_FLAGS_GET_TWT_INFO_FRAME_DISABLED(flags);
681 additional_params->wake_dur_us = param_buf->twt_params[idx].wake_dur_us;
682 additional_params->wake_intvl_us =
683 param_buf->twt_params[idx].wake_intvl_us;
684 additional_params->sp_offset_us =
685 param_buf->twt_params[idx].sp_offset_us;
686 additional_params->sp_tsf_us_lo =
687 param_buf->twt_params[idx].sp_tsf_us_lo;
688 additional_params->sp_tsf_us_hi =
689 param_buf->twt_params[idx].sp_tsf_us_hi;
690 additional_params->pm_responder_bit_valid =
691 TWT_FLAGS_GET_PM_RESPONDER_MODE_VALID(flags);
692 additional_params->pm_responder_bit =
693 TWT_FLAGS_GET_PM_RESPONDER_MODE(flags);
694
695 return QDF_STATUS_SUCCESS;
696 }
697
698 static enum HOST_TWT_DEL_STATUS
wmi_get_converted_twt_del_dialog_status(WMI_DEL_TWT_STATUS_T tgt_status)699 wmi_get_converted_twt_del_dialog_status(WMI_DEL_TWT_STATUS_T tgt_status)
700 {
701 switch (tgt_status) {
702 case WMI_DEL_TWT_STATUS_OK:
703 return HOST_TWT_DEL_STATUS_OK;
704 case WMI_DEL_TWT_STATUS_DIALOG_ID_NOT_EXIST:
705 return HOST_TWT_DEL_STATUS_DIALOG_ID_NOT_EXIST;
706 case WMI_DEL_TWT_STATUS_INVALID_PARAM:
707 return HOST_TWT_DEL_STATUS_INVALID_PARAM;
708 case WMI_DEL_TWT_STATUS_DIALOG_ID_BUSY:
709 return HOST_TWT_DEL_STATUS_DIALOG_ID_BUSY;
710 case WMI_DEL_TWT_STATUS_NO_RESOURCE:
711 return HOST_TWT_DEL_STATUS_NO_RESOURCE;
712 case WMI_DEL_TWT_STATUS_NO_ACK:
713 return HOST_TWT_DEL_STATUS_NO_ACK;
714 case WMI_DEL_TWT_STATUS_PEER_INIT_TEARDOWN:
715 return HOST_TWT_DEL_STATUS_PEER_INIT_TEARDOWN;
716 case WMI_DEL_TWT_STATUS_ROAMING:
717 return HOST_TWT_DEL_STATUS_ROAMING;
718 case WMI_DEL_TWT_STATUS_CONCURRENCY:
719 return HOST_TWT_DEL_STATUS_CONCURRENCY;
720 case WMI_DEL_TWT_STATUS_CHAN_SW_IN_PROGRESS:
721 return HOST_TWT_DEL_STATUS_CHAN_SW_IN_PROGRESS;
722 case WMI_DEL_TWT_STATUS_SCAN_IN_PROGRESS:
723 return HOST_TWT_DEL_STATUS_SCAN_IN_PROGRESS;
724 default:
725 return HOST_TWT_DEL_STATUS_UNKNOWN_ERROR;
726 }
727 }
728
extract_twt_del_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_del_dialog_complete_event_param * params)729 static QDF_STATUS extract_twt_del_dialog_comp_event_tlv(
730 wmi_unified_t wmi_handle,
731 uint8_t *evt_buf,
732 struct twt_del_dialog_complete_event_param *params)
733 {
734 WMI_TWT_DEL_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
735 wmi_twt_del_dialog_complete_event_fixed_param *ev;
736
737 param_buf = (WMI_TWT_DEL_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
738 if (!param_buf) {
739 wmi_err("evt_buf is NULL");
740 return QDF_STATUS_E_INVAL;
741 }
742
743 ev = param_buf->fixed_param;
744
745 params->vdev_id = ev->vdev_id;
746 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr,
747 params->peer_macaddr.bytes);
748 params->dialog_id = ev->dialog_id;
749 params->status = wmi_get_converted_twt_del_dialog_status(ev->status);
750
751 return QDF_STATUS_SUCCESS;
752 }
753
754 static enum HOST_TWT_PAUSE_STATUS
wmi_twt_pause_status_to_host_twt_status(WMI_PAUSE_TWT_STATUS_T status)755 wmi_twt_pause_status_to_host_twt_status(WMI_PAUSE_TWT_STATUS_T status)
756 {
757 switch (status) {
758 case WMI_PAUSE_TWT_STATUS_OK:
759 return HOST_TWT_PAUSE_STATUS_OK;
760 case WMI_PAUSE_TWT_STATUS_DIALOG_ID_NOT_EXIST:
761 return HOST_TWT_PAUSE_STATUS_DIALOG_ID_NOT_EXIST;
762 case WMI_PAUSE_TWT_STATUS_INVALID_PARAM:
763 return HOST_TWT_PAUSE_STATUS_INVALID_PARAM;
764 case WMI_PAUSE_TWT_STATUS_DIALOG_ID_BUSY:
765 return HOST_TWT_PAUSE_STATUS_DIALOG_ID_BUSY;
766 case WMI_PAUSE_TWT_STATUS_NO_RESOURCE:
767 return HOST_TWT_PAUSE_STATUS_NO_RESOURCE;
768 case WMI_PAUSE_TWT_STATUS_NO_ACK:
769 return HOST_TWT_PAUSE_STATUS_NO_ACK;
770 case WMI_PAUSE_TWT_STATUS_ALREADY_PAUSED:
771 return HOST_TWT_PAUSE_STATUS_ALREADY_PAUSED;
772 case WMI_PAUSE_TWT_STATUS_CHAN_SW_IN_PROGRESS:
773 return HOST_TWT_PAUSE_STATUS_CHAN_SW_IN_PROGRESS;
774 case WMI_PAUSE_TWT_STATUS_ROAM_IN_PROGRESS:
775 return HOST_TWT_PAUSE_STATUS_ROAM_IN_PROGRESS;
776 case WMI_PAUSE_TWT_STATUS_SCAN_IN_PROGRESS:
777 return HOST_TWT_PAUSE_STATUS_SCAN_IN_PROGRESS;
778 default:
779 return HOST_TWT_PAUSE_STATUS_UNKNOWN_ERROR;
780 }
781 }
782
extract_twt_pause_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_pause_dialog_complete_event_param * params)783 static QDF_STATUS extract_twt_pause_dialog_comp_event_tlv(
784 wmi_unified_t wmi_handle,
785 uint8_t *evt_buf,
786 struct twt_pause_dialog_complete_event_param *params)
787 {
788 WMI_TWT_PAUSE_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
789 wmi_twt_pause_dialog_complete_event_fixed_param *ev;
790
791 param_buf = (WMI_TWT_PAUSE_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
792 if (!param_buf) {
793 wmi_err("evt_buf is NULL");
794 return QDF_STATUS_E_INVAL;
795 }
796
797 ev = param_buf->fixed_param;
798
799 params->vdev_id = ev->vdev_id;
800 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr,
801 params->peer_macaddr.bytes);
802 params->status = wmi_twt_pause_status_to_host_twt_status(ev->status);
803 params->dialog_id = ev->dialog_id;
804
805 return QDF_STATUS_SUCCESS;
806 }
807
808 static enum HOST_TWT_NUDGE_STATUS
wmi_twt_nudge_status_to_host_twt_status(WMI_TWT_NUDGE_STATUS_T status)809 wmi_twt_nudge_status_to_host_twt_status(WMI_TWT_NUDGE_STATUS_T status)
810 {
811 switch (status) {
812 case WMI_NUDGE_TWT_STATUS_OK:
813 return HOST_TWT_NUDGE_STATUS_OK;
814 case WMI_NUDGE_TWT_STATUS_DIALOG_ID_NOT_EXIST:
815 return HOST_TWT_NUDGE_STATUS_DIALOG_ID_NOT_EXIST;
816 case WMI_NUDGE_TWT_STATUS_INVALID_PARAM:
817 return HOST_TWT_NUDGE_STATUS_INVALID_PARAM;
818 case WMI_NUDGE_TWT_STATUS_DIALOG_ID_BUSY:
819 return HOST_TWT_NUDGE_STATUS_DIALOG_ID_BUSY;
820 case WMI_NUDGE_TWT_STATUS_NO_RESOURCE:
821 return HOST_TWT_NUDGE_STATUS_NO_RESOURCE;
822 case WMI_NUDGE_TWT_STATUS_NO_ACK:
823 return HOST_TWT_NUDGE_STATUS_NO_ACK;
824 case WMI_NUDGE_TWT_STATUS_ALREADY_PAUSED:
825 return HOST_TWT_NUDGE_STATUS_ALREADY_PAUSED;
826 case WMI_NUDGE_TWT_STATUS_CHAN_SW_IN_PROGRESS:
827 return HOST_TWT_NUDGE_STATUS_CHAN_SW_IN_PROGRESS;
828 case WMI_NUDGE_TWT_STATUS_ROAM_IN_PROGRESS:
829 return HOST_TWT_NUDGE_STATUS_ROAM_IN_PROGRESS;
830 case WMI_NUDGE_TWT_STATUS_SCAN_IN_PROGRESS:
831 return HOST_TWT_NUDGE_STATUS_SCAN_IN_PROGRESS;
832 default:
833 return HOST_TWT_NUDGE_STATUS_UNKNOWN_ERROR;
834 }
835 }
836
extract_twt_nudge_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_nudge_dialog_complete_event_param * params)837 static QDF_STATUS extract_twt_nudge_dialog_comp_event_tlv(
838 wmi_unified_t wmi_handle,
839 uint8_t *evt_buf,
840 struct twt_nudge_dialog_complete_event_param *params)
841 {
842 WMI_TWT_NUDGE_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
843 wmi_twt_nudge_dialog_complete_event_fixed_param *ev;
844
845 param_buf = (WMI_TWT_NUDGE_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
846 if (!param_buf) {
847 wmi_err("evt_buf is NULL");
848 return QDF_STATUS_E_INVAL;
849 }
850
851 ev = param_buf->fixed_param;
852
853 params->vdev_id = ev->vdev_id;
854 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr,
855 params->peer_macaddr.bytes);
856 params->status = wmi_twt_nudge_status_to_host_twt_status(ev->status);
857 params->dialog_id = ev->dialog_id;
858 params->next_twt_tsf_us_lo = ev->sp_tsf_us_lo;
859 params->next_twt_tsf_us_hi = ev->sp_tsf_us_hi;
860
861 wmi_debug("vdev_id: %d dialog_id: %d tsf hi : %x tsf lo: %x",
862 params->vdev_id, params->dialog_id,
863 params->next_twt_tsf_us_hi, params->next_twt_tsf_us_lo);
864
865 return QDF_STATUS_SUCCESS;
866 }
867
868 static enum HOST_TWT_RESUME_STATUS
wmi_get_converted_twt_resume_dialog_status(WMI_RESUME_TWT_STATUS_T tgt_status)869 wmi_get_converted_twt_resume_dialog_status(WMI_RESUME_TWT_STATUS_T tgt_status)
870 {
871 switch (tgt_status) {
872 case WMI_RESUME_TWT_STATUS_OK:
873 return HOST_TWT_RESUME_STATUS_OK;
874 case WMI_RESUME_TWT_STATUS_DIALOG_ID_NOT_EXIST:
875 return HOST_TWT_RESUME_STATUS_DIALOG_ID_NOT_EXIST;
876 case WMI_RESUME_TWT_STATUS_INVALID_PARAM:
877 return HOST_TWT_RESUME_STATUS_INVALID_PARAM;
878 case WMI_RESUME_TWT_STATUS_DIALOG_ID_BUSY:
879 return HOST_TWT_RESUME_STATUS_DIALOG_ID_BUSY;
880 case WMI_RESUME_TWT_STATUS_NOT_PAUSED:
881 return HOST_TWT_RESUME_STATUS_NOT_PAUSED;
882 case WMI_RESUME_TWT_STATUS_NO_RESOURCE:
883 return HOST_TWT_RESUME_STATUS_NO_RESOURCE;
884 case WMI_RESUME_TWT_STATUS_NO_ACK:
885 return HOST_TWT_RESUME_STATUS_NO_ACK;
886 case WMI_RESUME_TWT_STATUS_CHAN_SW_IN_PROGRESS:
887 return HOST_TWT_RESUME_STATUS_CHAN_SW_IN_PROGRESS;
888 case WMI_RESUME_TWT_STATUS_ROAM_IN_PROGRESS:
889 return HOST_TWT_RESUME_STATUS_ROAM_IN_PROGRESS;
890 case WMI_RESUME_TWT_STATUS_SCAN_IN_PROGRESS:
891 return HOST_TWT_RESUME_STATUS_SCAN_IN_PROGRESS;
892 default:
893 return HOST_TWT_RESUME_STATUS_UNKNOWN_ERROR;
894 }
895 }
896
extract_twt_resume_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_resume_dialog_complete_event_param * params)897 static QDF_STATUS extract_twt_resume_dialog_comp_event_tlv(
898 wmi_unified_t wmi_handle,
899 uint8_t *evt_buf,
900 struct twt_resume_dialog_complete_event_param *params)
901 {
902 WMI_TWT_RESUME_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
903 wmi_twt_resume_dialog_complete_event_fixed_param *ev;
904
905 param_buf =
906 (WMI_TWT_RESUME_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
907 if (!param_buf) {
908 wmi_err("evt_buf is NULL");
909 return QDF_STATUS_E_INVAL;
910 }
911
912 ev = param_buf->fixed_param;
913
914 params->vdev_id = ev->vdev_id;
915 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr,
916 params->peer_macaddr.bytes);
917 params->status = wmi_get_converted_twt_resume_dialog_status(ev->status);
918 params->dialog_id = ev->dialog_id;
919
920 return QDF_STATUS_SUCCESS;
921 }
922
923 static enum HOST_TWT_NOTIFY_STATUS
wmi_get_converted_twt_notify_status(WMI_TWT_NOTIFICATION_ID_T tgt_status)924 wmi_get_converted_twt_notify_status(WMI_TWT_NOTIFICATION_ID_T tgt_status)
925 {
926 switch (tgt_status) {
927 case WMI_TWT_NOTIFY_EVENT_AP_TWT_REQ_BIT_SET:
928 return HOST_TWT_NOTIFY_EVENT_AP_TWT_REQ_BIT_SET;
929 case WMI_TWT_NOTIFY_EVENT_AP_TWT_REQ_BIT_CLEAR:
930 return HOST_TWT_NOTIFY_EVENT_AP_TWT_REQ_BIT_CLEAR;
931 default:
932 return HOST_TWT_NOTIFY_EVENT_READY;
933 }
934 }
935
extract_twt_notify_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_notify_event_param * params)936 static QDF_STATUS extract_twt_notify_event_tlv(
937 wmi_unified_t wmi_handle,
938 uint8_t *evt_buf,
939 struct twt_notify_event_param *params)
940 {
941 WMI_TWT_NOTIFY_EVENTID_param_tlvs *param_buf;
942 wmi_twt_notify_event_fixed_param *ev;
943
944 param_buf =
945 (WMI_TWT_NOTIFY_EVENTID_param_tlvs *)evt_buf;
946 if (!param_buf) {
947 wmi_err("evt_buf is NULL");
948 return QDF_STATUS_E_INVAL;
949 }
950
951 ev = param_buf->fixed_param;
952
953 if (ev->event_id > WMI_TWT_NOTIFY_EVENT_AP_TWT_REQ_BIT_CLEAR) {
954 wmi_debug("Incorrect TWT notify event vdev_id: %d, status: %d",
955 ev->vdev_id, ev->event_id);
956 return QDF_STATUS_E_INVAL;
957 }
958
959 params->vdev_id = ev->vdev_id;
960 params->status = wmi_get_converted_twt_notify_status(ev->event_id);
961
962 wmi_debug("Extract notify event vdev_id: %d, status: %d",
963 params->vdev_id, params->status);
964
965 return QDF_STATUS_SUCCESS;
966 }
967
968 #ifdef WLAN_SUPPORT_BCAST_TWT
969 static QDF_STATUS
extract_twt_btwt_invite_sta_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_btwt_invite_sta_complete_event_param * params)970 extract_twt_btwt_invite_sta_comp_event_tlv(
971 wmi_unified_t wmi_handle,
972 uint8_t *evt_buf,
973 struct
974 twt_btwt_invite_sta_complete_event_param
975 *params)
976 {
977 WMI_TWT_BTWT_INVITE_STA_COMPLETE_EVENTID_param_tlvs *param_buf;
978 wmi_twt_btwt_invite_sta_complete_event_fixed_param *ev;
979
980 param_buf =
981 (WMI_TWT_BTWT_INVITE_STA_COMPLETE_EVENTID_param_tlvs *)evt_buf;
982 if (!param_buf) {
983 wmi_err("evt_buf is NULL");
984 return QDF_STATUS_E_INVAL;
985 }
986
987 ev = param_buf->fixed_param;
988
989 params->vdev_id = ev->vdev_id;
990 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr,
991 params->peer_macaddr.bytes);
992 params->status = ev->status;
993 params->dialog_id = ev->dialog_id;
994
995 return QDF_STATUS_SUCCESS;
996 }
997
998 static QDF_STATUS
extract_twt_btwt_remove_sta_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_btwt_remove_sta_complete_event_param * params)999 extract_twt_btwt_remove_sta_comp_event_tlv(
1000 wmi_unified_t wmi_handle,
1001 uint8_t *evt_buf,
1002 struct
1003 twt_btwt_remove_sta_complete_event_param
1004 *params)
1005 {
1006 WMI_TWT_BTWT_REMOVE_STA_COMPLETE_EVENTID_param_tlvs *param_buf;
1007 wmi_twt_btwt_remove_sta_complete_event_fixed_param *ev;
1008
1009 param_buf =
1010 (WMI_TWT_BTWT_REMOVE_STA_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1011 if (!param_buf) {
1012 wmi_err("evt_buf is NULL");
1013 return QDF_STATUS_E_INVAL;
1014 }
1015
1016 ev = param_buf->fixed_param;
1017
1018 params->vdev_id = ev->vdev_id;
1019 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr,
1020 params->peer_macaddr.bytes);
1021 params->status = ev->status;
1022 params->dialog_id = ev->dialog_id;
1023
1024 return QDF_STATUS_SUCCESS;
1025 }
1026 #endif
1027
1028 #ifdef WLAN_SUPPORT_BCAST_TWT
1029 static void
wmi_twt_attach_bcast_twt_tlv(struct wmi_ops * ops)1030 wmi_twt_attach_bcast_twt_tlv(struct wmi_ops *ops)
1031 {
1032 ops->send_twt_btwt_invite_sta_cmd = send_twt_btwt_invite_sta_cmd_tlv;
1033 ops->send_twt_btwt_remove_sta_cmd = send_twt_btwt_remove_sta_cmd_tlv;
1034 ops->extract_twt_btwt_invite_sta_comp_event =
1035 extract_twt_btwt_invite_sta_comp_event_tlv;
1036 ops->extract_twt_btwt_remove_sta_comp_event =
1037 extract_twt_btwt_remove_sta_comp_event_tlv;
1038 }
1039 #else
1040 static void
wmi_twt_attach_bcast_twt_tlv(struct wmi_ops * ops)1041 wmi_twt_attach_bcast_twt_tlv(struct wmi_ops *ops)
1042 {
1043 }
1044 #endif
1045
1046 static QDF_STATUS
extract_twt_session_stats_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_session_stats_event_param * params)1047 extract_twt_session_stats_event_tlv(wmi_unified_t wmi_handle,
1048 uint8_t *evt_buf,
1049 struct twt_session_stats_event_param
1050 *params)
1051 {
1052 WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *param_buf;
1053 wmi_pdev_twt_session_stats_event_fixed_param *ev;
1054
1055 param_buf =
1056 (WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *)evt_buf;
1057 if (!param_buf) {
1058 wmi_err("evt_buf is NULL");
1059 return QDF_STATUS_E_INVAL;
1060 }
1061
1062 ev = param_buf->fixed_param;
1063 params->pdev_id = wmi_handle->ops->convert_pdev_id_target_to_host(
1064 wmi_handle,
1065 ev->pdev_id);
1066 params->num_sessions = param_buf->num_twt_sessions;
1067
1068 wmi_debug("pdev_id=%d, num of TWT sessions=%d",
1069 params->pdev_id, params->num_sessions);
1070
1071 return QDF_STATUS_SUCCESS;
1072 }
1073
1074 static QDF_STATUS
extract_twt_session_stats_event_data(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_session_stats_event_param * params,struct twt_session_stats_info * session,uint32_t idx)1075 extract_twt_session_stats_event_data(wmi_unified_t wmi_handle,
1076 uint8_t *evt_buf,
1077 struct twt_session_stats_event_param
1078 *params,
1079 struct twt_session_stats_info
1080 *session,
1081 uint32_t idx)
1082 {
1083 WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *param_buf;
1084 wmi_twt_session_stats_info *twt_session;
1085 uint32_t flags;
1086 wmi_mac_addr *m1;
1087 uint8_t *m2;
1088
1089 param_buf =
1090 (WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *)evt_buf;
1091 if (!param_buf) {
1092 wmi_err("evt_buf is NULL");
1093 return QDF_STATUS_E_INVAL;
1094 }
1095
1096 if (idx >= param_buf->num_twt_sessions) {
1097 wmi_err("wrong idx, idx=%d, num_sessions=%d",
1098 idx, param_buf->num_twt_sessions);
1099 return QDF_STATUS_E_INVAL;
1100 }
1101
1102 twt_session = ¶m_buf->twt_sessions[idx];
1103
1104 session->vdev_id = twt_session->vdev_id;
1105 m1 = &twt_session->peer_mac;
1106 m2 = session->peer_mac.bytes;
1107 WMI_MAC_ADDR_TO_CHAR_ARRAY(m1, m2);
1108 session->event_type = twt_session->event_type;
1109 flags = twt_session->flow_id_flags;
1110 session->flow_id = WMI_TWT_SESSION_FLAG_FLOW_ID_GET(flags);
1111 session->bcast = WMI_TWT_SESSION_FLAG_BCAST_TWT_GET(flags);
1112 session->trig = WMI_TWT_SESSION_FLAG_TRIGGER_TWT_GET(flags);
1113 session->announ = WMI_TWT_SESSION_FLAG_ANNOUN_TWT_GET(flags);
1114 session->protection = WMI_TWT_SESSION_FLAG_TWT_PROTECTION_GET(flags);
1115 session->info_frame_disabled =
1116 WMI_TWT_SESSION_FLAG_TWT_INFO_FRAME_DISABLED_GET(flags);
1117 session->pm_responder_bit =
1118 WMI_TWT_SESSION_FLAG_TWT_PM_RESPONDER_MODE_GET(flags);
1119 session->pm_responder_bit_valid =
1120 WMI_TWT_SESSION_FLAG_TWT_PM_RESPONDER_MODE_VALID_GET(flags);
1121 session->dialog_id = twt_session->dialog_id;
1122 session->wake_dura_us = twt_session->wake_dura_us;
1123 session->wake_intvl_us = twt_session->wake_intvl_us;
1124 session->sp_offset_us = twt_session->sp_offset_us;
1125 session->sp_tsf_us_lo = twt_session->sp_tsf_us_lo;
1126 session->sp_tsf_us_hi = twt_session->sp_tsf_us_hi;
1127 wmi_debug("type=%d id=%d bcast=%d trig=%d announ=%d diagid=%d wake_dur=%ul wake_int=%ul offset=%ul",
1128 session->event_type, session->flow_id,
1129 session->bcast, session->trig,
1130 session->announ, session->dialog_id, session->wake_dura_us,
1131 session->wake_intvl_us, session->sp_offset_us);
1132 wmi_debug("resp_pm_valid=%d resp_pm=%d",
1133 session->pm_responder_bit_valid, session->pm_responder_bit);
1134
1135 return QDF_STATUS_SUCCESS;
1136 }
1137
extract_twt_cap_service_ready_ext2_tlv(wmi_unified_t wmi_handle,uint8_t * event,struct wmi_twt_cap_bitmap_params * var)1138 static QDF_STATUS extract_twt_cap_service_ready_ext2_tlv(
1139 wmi_unified_t wmi_handle, uint8_t *event,
1140 struct wmi_twt_cap_bitmap_params *var)
1141 {
1142 WMI_SERVICE_READY_EXT2_EVENTID_param_tlvs *param_buf;
1143 wmi_twt_caps_params *twt_caps;
1144
1145 param_buf = (WMI_SERVICE_READY_EXT2_EVENTID_param_tlvs *)event;
1146 if (!param_buf)
1147 return QDF_STATUS_E_INVAL;
1148
1149 twt_caps = param_buf->twt_caps;
1150 if (!twt_caps)
1151 return QDF_STATUS_E_INVAL;
1152
1153 var->twt_ack_support_cap = WMI_GET_BITS(twt_caps->twt_capability_bitmap,
1154 0, 1);
1155
1156 return QDF_STATUS_SUCCESS;
1157 }
1158
1159 static enum WMI_HOST_TWT_CMD_FOR_ACK_EVENT
wmi_get_converted_twt_command_for_ack_event(WMI_CMD_ID tgt_cmd)1160 wmi_get_converted_twt_command_for_ack_event(WMI_CMD_ID tgt_cmd)
1161 {
1162 switch (tgt_cmd) {
1163 case WMI_TWT_ADD_DIALOG_CMDID:
1164 return WMI_HOST_TWT_ADD_DIALOG_CMDID;
1165 case WMI_TWT_DEL_DIALOG_CMDID:
1166 return WMI_HOST_TWT_DEL_DIALOG_CMDID;
1167 case WMI_TWT_PAUSE_DIALOG_CMDID:
1168 return WMI_HOST_TWT_PAUSE_DIALOG_CMDID;
1169 case WMI_TWT_RESUME_DIALOG_CMDID:
1170 return WMI_HOST_TWT_RESUME_DIALOG_CMDID;
1171 case WMI_TWT_NUDGE_DIALOG_CMDID:
1172 return WMI_HOST_TWT_NUDGE_DIALOG_CMDID;
1173 default:
1174 return WMI_HOST_TWT_UNKNOWN_CMDID;
1175 }
1176 }
1177
1178 static QDF_STATUS
extract_twt_ack_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct twt_ack_complete_event_param * var)1179 extract_twt_ack_comp_event_tlv(wmi_unified_t wmi_handle,
1180 uint8_t *evt_buf,
1181 struct twt_ack_complete_event_param *var)
1182 {
1183 WMI_TWT_ACK_EVENTID_param_tlvs *param_buf;
1184 wmi_twt_ack_event_fixed_param *ack_event;
1185
1186 param_buf = (WMI_TWT_ACK_EVENTID_param_tlvs *)evt_buf;
1187 if (!param_buf) {
1188 wmi_err("evt_buf is NULL");
1189 return QDF_STATUS_E_INVAL;
1190 }
1191
1192 ack_event = param_buf->fixed_param;
1193
1194 var->vdev_id = ack_event->vdev_id;
1195 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ack_event->peer_macaddr,
1196 var->peer_macaddr.bytes);
1197 var->dialog_id = ack_event->dialog_id;
1198 var->twt_cmd_ack = wmi_get_converted_twt_command_for_ack_event(
1199 ack_event->twt_cmd);
1200
1201 switch (ack_event->twt_cmd) {
1202 case WMI_TWT_ADD_DIALOG_CMDID:
1203 var->status = wmi_get_converted_twt_add_dialog_status(
1204 ack_event->status);
1205 break;
1206 case WMI_TWT_DEL_DIALOG_CMDID:
1207 var->status = wmi_get_converted_twt_del_dialog_status(
1208 ack_event->status);
1209 break;
1210 case WMI_TWT_PAUSE_DIALOG_CMDID:
1211 var->status = wmi_twt_pause_status_to_host_twt_status(
1212 ack_event->status);
1213 break;
1214 case WMI_TWT_RESUME_DIALOG_CMDID:
1215 var->status = wmi_get_converted_twt_resume_dialog_status(
1216 ack_event->status);
1217 break;
1218 case WMI_TWT_NUDGE_DIALOG_CMDID:
1219 var->status = wmi_twt_nudge_status_to_host_twt_status(
1220 ack_event->status);
1221 break;
1222 default:
1223 break;
1224 }
1225 return QDF_STATUS_SUCCESS;
1226 }
1227 #elif WLAN_SUPPORT_TWT
send_twt_enable_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_enable_param * params)1228 static QDF_STATUS send_twt_enable_cmd_tlv(wmi_unified_t wmi_handle,
1229 struct wmi_twt_enable_param *params)
1230 {
1231 wmi_twt_enable_cmd_fixed_param *cmd;
1232 wmi_buf_t buf;
1233 QDF_STATUS status;
1234
1235 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1236 if (!buf) {
1237 wmi_err("Failed to allocate memory");
1238 return QDF_STATUS_E_FAILURE;
1239 }
1240
1241 cmd = (wmi_twt_enable_cmd_fixed_param *) wmi_buf_data(buf);
1242 WMITLV_SET_HDR(&cmd->tlv_header,
1243 WMITLV_TAG_STRUC_wmi_twt_enable_cmd_fixed_param,
1244 WMITLV_GET_STRUCT_TLVLEN
1245 (wmi_twt_enable_cmd_fixed_param));
1246
1247 cmd->pdev_id =
1248 wmi_handle->ops->convert_pdev_id_host_to_target(
1249 wmi_handle,
1250 params->pdev_id);
1251 cmd->sta_cong_timer_ms = params->sta_cong_timer_ms;
1252 cmd->mbss_support = params->mbss_support;
1253 cmd->default_slot_size = params->default_slot_size;
1254 cmd->congestion_thresh_setup = params->congestion_thresh_setup;
1255 cmd->congestion_thresh_teardown = params->congestion_thresh_teardown;
1256 cmd->congestion_thresh_critical = params->congestion_thresh_critical;
1257 cmd->interference_thresh_teardown =
1258 params->interference_thresh_teardown;
1259 cmd->interference_thresh_setup = params->interference_thresh_setup;
1260 cmd->min_no_sta_setup = params->min_no_sta_setup;
1261 cmd->min_no_sta_teardown = params->min_no_sta_teardown;
1262 cmd->no_of_bcast_mcast_slots = params->no_of_bcast_mcast_slots;
1263 cmd->min_no_twt_slots = params->min_no_twt_slots;
1264 cmd->max_no_sta_twt = params->max_no_sta_twt;
1265 cmd->mode_check_interval = params->mode_check_interval;
1266 cmd->add_sta_slot_interval = params->add_sta_slot_interval;
1267 cmd->remove_sta_slot_interval = params->remove_sta_slot_interval;
1268
1269 TWT_EN_DIS_FLAGS_SET_BTWT(cmd->flags, params->b_twt_enable);
1270 TWT_EN_DIS_FLAGS_SET_B_R_TWT(cmd->flags, params->r_twt_enable);
1271 TWT_EN_DIS_FLAGS_SET_L_MBSSID(cmd->flags,
1272 params->b_twt_legacy_mbss_enable);
1273 TWT_EN_DIS_FLAGS_SET_AX_MBSSID(cmd->flags,
1274 params->b_twt_ax_mbss_enable);
1275 if (params->ext_conf_present) {
1276 TWT_EN_DIS_FLAGS_SET_SPLIT_CONFIG(cmd->flags, 1);
1277 TWT_EN_DIS_FLAGS_SET_REQ_RESP(cmd->flags, params->twt_role);
1278 TWT_EN_DIS_FLAGS_SET_I_B_TWT(cmd->flags, params->twt_oper);
1279 }
1280
1281 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1282 WMI_TWT_ENABLE_CMDID);
1283 if (QDF_IS_STATUS_ERROR(status)) {
1284 wmi_err("Failed to send WMI_TWT_ENABLE_CMDID");
1285 wmi_buf_free(buf);
1286 }
1287
1288 return status;
1289 }
1290
send_twt_disable_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_disable_param * params)1291 static QDF_STATUS send_twt_disable_cmd_tlv(wmi_unified_t wmi_handle,
1292 struct wmi_twt_disable_param *params)
1293 {
1294 wmi_twt_disable_cmd_fixed_param *cmd;
1295 wmi_buf_t buf;
1296 QDF_STATUS status;
1297
1298 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1299 if (!buf) {
1300 wmi_err("Failed to allocate memory");
1301 return QDF_STATUS_E_FAILURE;
1302 }
1303
1304 cmd = (wmi_twt_disable_cmd_fixed_param *) wmi_buf_data(buf);
1305 WMITLV_SET_HDR(&cmd->tlv_header,
1306 WMITLV_TAG_STRUC_wmi_twt_disable_cmd_fixed_param,
1307 WMITLV_GET_STRUCT_TLVLEN
1308 (wmi_twt_disable_cmd_fixed_param));
1309
1310 cmd->pdev_id =
1311 wmi_handle->ops->convert_pdev_id_host_to_target(
1312 wmi_handle,
1313 params->pdev_id);
1314 if (params->ext_conf_present) {
1315 TWT_EN_DIS_FLAGS_SET_SPLIT_CONFIG(cmd->flags, 1);
1316 TWT_EN_DIS_FLAGS_SET_REQ_RESP(cmd->flags, params->twt_role);
1317 TWT_EN_DIS_FLAGS_SET_I_B_TWT(cmd->flags, params->twt_oper);
1318 }
1319
1320 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1321 WMI_TWT_DISABLE_CMDID);
1322 if (QDF_IS_STATUS_ERROR(status)) {
1323 wmi_err("Failed to send WMI_TWT_DISABLE_CMDID");
1324 wmi_buf_free(buf);
1325 }
1326
1327 return status;
1328 }
1329
1330 #ifdef WLAN_SUPPORT_BCAST_TWT
1331 static void
twt_add_dialog_set_bcast_twt_params(struct wmi_twt_add_dialog_param * params,wmi_twt_add_dialog_cmd_fixed_param * cmd)1332 twt_add_dialog_set_bcast_twt_params(struct wmi_twt_add_dialog_param *params,
1333 wmi_twt_add_dialog_cmd_fixed_param *cmd)
1334 {
1335 TWT_FLAGS_SET_BTWT_ID0(cmd->flags, params->flag_b_twt_id0);
1336 cmd->b_twt_persistence = params->b_twt_persistence;
1337 cmd->b_twt_recommendation = params->b_twt_recommendation;
1338 }
1339 #else
1340 static void
twt_add_dialog_set_bcast_twt_params(struct wmi_twt_add_dialog_param * params,wmi_twt_add_dialog_cmd_fixed_param * cmd)1341 twt_add_dialog_set_bcast_twt_params(struct wmi_twt_add_dialog_param *params,
1342 wmi_twt_add_dialog_cmd_fixed_param *cmd)
1343 {
1344 }
1345 #endif
1346
1347 static QDF_STATUS
send_twt_add_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_add_dialog_param * params)1348 send_twt_add_dialog_cmd_tlv(wmi_unified_t wmi_handle,
1349 struct wmi_twt_add_dialog_param *params)
1350 {
1351 wmi_twt_add_dialog_cmd_fixed_param *cmd;
1352 wmi_buf_t buf;
1353 QDF_STATUS status;
1354
1355 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1356 if (!buf) {
1357 wmi_err("Failed to allocate memory");
1358 return QDF_STATUS_E_FAILURE;
1359 }
1360
1361 cmd = (wmi_twt_add_dialog_cmd_fixed_param *) wmi_buf_data(buf);
1362 WMITLV_SET_HDR(&cmd->tlv_header,
1363 WMITLV_TAG_STRUC_wmi_twt_add_dialog_cmd_fixed_param,
1364 WMITLV_GET_STRUCT_TLVLEN
1365 (wmi_twt_add_dialog_cmd_fixed_param));
1366
1367 cmd->vdev_id = params->vdev_id;
1368 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->peer_macaddr);
1369 cmd->dialog_id = params->dialog_id;
1370 cmd->wake_intvl_us = params->wake_intvl_us;
1371 cmd->wake_intvl_mantis = params->wake_intvl_mantis;
1372 cmd->wake_dura_us = params->wake_dura_us;
1373 cmd->sp_offset_us = params->sp_offset_us;
1374 cmd->min_wake_intvl_us = params->min_wake_intvl_us;
1375 cmd->max_wake_intvl_us = params->max_wake_intvl_us;
1376 cmd->min_wake_dura_us = params->min_wake_dura_us;
1377 cmd->max_wake_dura_us = params->max_wake_dura_us;
1378 cmd->sp_start_tsf_lo = (uint32_t)(params->wake_time_tsf & 0xFFFFFFFF);
1379 cmd->sp_start_tsf_hi = (uint32_t)(params->wake_time_tsf >> 32);
1380 cmd->announce_timeout_us = params->announce_timeout_us;
1381 cmd->link_id_bitmap = params->link_id_bitmap;
1382 cmd->r_twt_dl_tid_bitmap = params->r_twt_dl_tid_bitmap;
1383 cmd->r_twt_ul_tid_bitmap = params->r_twt_ul_tid_bitmap;
1384 TWT_FLAGS_SET_CMD(cmd->flags, params->twt_cmd);
1385 TWT_FLAGS_SET_BROADCAST(cmd->flags, params->flag_bcast);
1386 TWT_FLAGS_SET_TRIGGER(cmd->flags, params->flag_trigger);
1387 TWT_FLAGS_SET_FLOW_TYPE(cmd->flags, params->flag_flow_type);
1388 TWT_FLAGS_SET_PROTECTION(cmd->flags, params->flag_protection);
1389
1390 twt_add_dialog_set_bcast_twt_params(params, cmd);
1391
1392 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1393 WMI_TWT_ADD_DIALOG_CMDID);
1394 if (QDF_IS_STATUS_ERROR(status)) {
1395 wmi_err("Failed to send WMI_TWT_ADD_DIALOG_CMDID");
1396 wmi_buf_free(buf);
1397 }
1398
1399 return status;
1400 }
1401
1402 #ifdef WLAN_SUPPORT_BCAST_TWT
1403 static void
twt_del_dialog_set_bcast_twt_params(struct wmi_twt_del_dialog_param * params,wmi_twt_del_dialog_cmd_fixed_param * cmd)1404 twt_del_dialog_set_bcast_twt_params(struct wmi_twt_del_dialog_param *params,
1405 wmi_twt_del_dialog_cmd_fixed_param *cmd)
1406 {
1407 cmd->b_twt_persistence = params->b_twt_persistence;
1408 }
1409 #else
1410 static void
twt_del_dialog_set_bcast_twt_params(struct wmi_twt_del_dialog_param * params,wmi_twt_del_dialog_cmd_fixed_param * cmd)1411 twt_del_dialog_set_bcast_twt_params(struct wmi_twt_del_dialog_param *params,
1412 wmi_twt_del_dialog_cmd_fixed_param *cmd)
1413 {
1414 }
1415 #endif
1416
1417 static QDF_STATUS
send_twt_del_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_del_dialog_param * params)1418 send_twt_del_dialog_cmd_tlv(wmi_unified_t wmi_handle,
1419 struct wmi_twt_del_dialog_param *params)
1420 {
1421 wmi_twt_del_dialog_cmd_fixed_param *cmd;
1422 wmi_buf_t buf;
1423 QDF_STATUS status;
1424
1425 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1426 if (!buf) {
1427 wmi_err("Failed to allocate memory");
1428 return QDF_STATUS_E_FAILURE;
1429 }
1430
1431 cmd = (wmi_twt_del_dialog_cmd_fixed_param *) wmi_buf_data(buf);
1432 WMITLV_SET_HDR(&cmd->tlv_header,
1433 WMITLV_TAG_STRUC_wmi_twt_del_dialog_cmd_fixed_param,
1434 WMITLV_GET_STRUCT_TLVLEN
1435 (wmi_twt_del_dialog_cmd_fixed_param));
1436
1437 cmd->vdev_id = params->vdev_id;
1438 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->peer_macaddr);
1439 cmd->dialog_id = params->dialog_id;
1440
1441 twt_del_dialog_set_bcast_twt_params(params, cmd);
1442
1443 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1444 WMI_TWT_DEL_DIALOG_CMDID);
1445 if (QDF_IS_STATUS_ERROR(status)) {
1446 wmi_err("Failed to send WMI_TWT_DEL_DIALOG_CMDID");
1447 wmi_buf_free(buf);
1448 }
1449
1450 return status;
1451 }
1452
1453 static QDF_STATUS
send_twt_pause_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_pause_dialog_cmd_param * params)1454 send_twt_pause_dialog_cmd_tlv(wmi_unified_t wmi_handle,
1455 struct wmi_twt_pause_dialog_cmd_param *params)
1456 {
1457 wmi_twt_pause_dialog_cmd_fixed_param *cmd;
1458 wmi_buf_t buf;
1459 QDF_STATUS status;
1460
1461 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1462 if (!buf) {
1463 wmi_err("Failed to allocate memory");
1464 return QDF_STATUS_E_FAILURE;
1465 }
1466
1467 cmd = (wmi_twt_pause_dialog_cmd_fixed_param *) wmi_buf_data(buf);
1468 WMITLV_SET_HDR(&cmd->tlv_header,
1469 WMITLV_TAG_STRUC_wmi_twt_pause_dialog_cmd_fixed_param,
1470 WMITLV_GET_STRUCT_TLVLEN
1471 (wmi_twt_pause_dialog_cmd_fixed_param));
1472
1473 cmd->vdev_id = params->vdev_id;
1474 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->peer_macaddr);
1475 cmd->dialog_id = params->dialog_id;
1476
1477 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1478 WMI_TWT_PAUSE_DIALOG_CMDID);
1479 if (QDF_IS_STATUS_ERROR(status)) {
1480 wmi_err("Failed to send WMI_TWT_PAUSE_DIALOG_CMDID");
1481 wmi_buf_free(buf);
1482 }
1483
1484 return status;
1485 }
1486
1487 static QDF_STATUS
send_twt_nudge_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_nudge_dialog_cmd_param * params)1488 send_twt_nudge_dialog_cmd_tlv(wmi_unified_t wmi_handle,
1489 struct wmi_twt_nudge_dialog_cmd_param *params)
1490 {
1491 wmi_twt_nudge_dialog_cmd_fixed_param *cmd;
1492 wmi_buf_t buf;
1493 QDF_STATUS status;
1494
1495 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1496 if (!buf)
1497 return QDF_STATUS_E_FAILURE;
1498
1499 cmd = (wmi_twt_nudge_dialog_cmd_fixed_param *) wmi_buf_data(buf);
1500 WMITLV_SET_HDR(&cmd->tlv_header,
1501 WMITLV_TAG_STRUC_wmi_twt_nudge_dialog_cmd_fixed_param,
1502 WMITLV_GET_STRUCT_TLVLEN
1503 (wmi_twt_nudge_dialog_cmd_fixed_param));
1504
1505 cmd->vdev_id = params->vdev_id;
1506 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->peer_macaddr);
1507 cmd->dialog_id = params->dialog_id;
1508 cmd->suspend_duration_ms = params->suspend_duration / 1000;
1509 cmd->next_twt_size = params->next_twt_size;
1510
1511 wmi_debug("vdev_id: %d dialog_id: %d duration(in ms): %u next_twt_size: %d "
1512 "peer_macaddr: "QDF_MAC_ADDR_FMT, cmd->vdev_id,
1513 cmd->dialog_id, cmd->suspend_duration_ms, cmd->next_twt_size,
1514 QDF_MAC_ADDR_REF(params->peer_macaddr));
1515
1516 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1517 WMI_TWT_NUDGE_DIALOG_CMDID);
1518 if (QDF_IS_STATUS_ERROR(status))
1519 wmi_buf_free(buf);
1520
1521 return status;
1522 }
1523
send_twt_resume_dialog_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_resume_dialog_cmd_param * params)1524 static QDF_STATUS send_twt_resume_dialog_cmd_tlv(wmi_unified_t wmi_handle,
1525 struct wmi_twt_resume_dialog_cmd_param *params)
1526 {
1527 wmi_twt_resume_dialog_cmd_fixed_param *cmd;
1528 wmi_buf_t buf;
1529 QDF_STATUS status;
1530
1531 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1532 if (!buf) {
1533 wmi_err("Failed to allocate memory");
1534 return QDF_STATUS_E_FAILURE;
1535 }
1536
1537 cmd = (wmi_twt_resume_dialog_cmd_fixed_param *) wmi_buf_data(buf);
1538 WMITLV_SET_HDR(&cmd->tlv_header,
1539 WMITLV_TAG_STRUC_wmi_twt_resume_dialog_cmd_fixed_param,
1540 WMITLV_GET_STRUCT_TLVLEN
1541 (wmi_twt_resume_dialog_cmd_fixed_param));
1542
1543 cmd->vdev_id = params->vdev_id;
1544 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->peer_macaddr);
1545 cmd->dialog_id = params->dialog_id;
1546 cmd->sp_offset_us = params->sp_offset_us;
1547 cmd->next_twt_size = params->next_twt_size;
1548
1549 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1550 WMI_TWT_RESUME_DIALOG_CMDID);
1551 if (QDF_IS_STATUS_ERROR(status)) {
1552 wmi_err("Failed to send WMI_TWT_RESUME_DIALOG_CMDID");
1553 wmi_buf_free(buf);
1554 }
1555
1556 return status;
1557 }
1558
1559 #ifdef WLAN_SUPPORT_BCAST_TWT
1560 static QDF_STATUS
send_twt_btwt_invite_sta_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_btwt_invite_sta_cmd_param * params)1561 send_twt_btwt_invite_sta_cmd_tlv(wmi_unified_t wmi_handle,
1562 struct wmi_twt_btwt_invite_sta_cmd_param
1563 *params)
1564 {
1565 wmi_twt_btwt_invite_sta_cmd_fixed_param *cmd;
1566 wmi_buf_t buf;
1567 QDF_STATUS status;
1568
1569 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1570 if (!buf) {
1571 wmi_err("Failed to allocate memory");
1572 return QDF_STATUS_E_FAILURE;
1573 }
1574
1575 cmd = (wmi_twt_btwt_invite_sta_cmd_fixed_param *)wmi_buf_data(buf);
1576 WMITLV_SET_HDR(&cmd->tlv_header,
1577 WMITLV_TAG_STRUC_wmi_twt_btwt_invite_sta_cmd_fixed_param,
1578 WMITLV_GET_STRUCT_TLVLEN
1579 (wmi_twt_btwt_invite_sta_cmd_fixed_param));
1580
1581 cmd->vdev_id = params->vdev_id;
1582 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->peer_macaddr);
1583 cmd->dialog_id = params->dialog_id;
1584
1585 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1586 WMI_TWT_BTWT_INVITE_STA_CMDID);
1587 if (QDF_IS_STATUS_ERROR(status)) {
1588 wmi_buf_free(buf);
1589 }
1590
1591 return status;
1592 }
1593
1594 static QDF_STATUS
send_twt_btwt_remove_sta_cmd_tlv(wmi_unified_t wmi_handle,struct wmi_twt_btwt_remove_sta_cmd_param * params)1595 send_twt_btwt_remove_sta_cmd_tlv(wmi_unified_t wmi_handle,
1596 struct wmi_twt_btwt_remove_sta_cmd_param
1597 *params)
1598 {
1599 wmi_twt_btwt_remove_sta_cmd_fixed_param *cmd;
1600 wmi_buf_t buf;
1601 QDF_STATUS status;
1602
1603 buf = wmi_buf_alloc(wmi_handle, sizeof(*cmd));
1604 if (!buf) {
1605 wmi_err("Failed to allocate memory");
1606 return QDF_STATUS_E_FAILURE;
1607 }
1608
1609 cmd = (wmi_twt_btwt_remove_sta_cmd_fixed_param *)wmi_buf_data(buf);
1610 WMITLV_SET_HDR(&cmd->tlv_header,
1611 WMITLV_TAG_STRUC_wmi_twt_btwt_remove_sta_cmd_fixed_param,
1612 WMITLV_GET_STRUCT_TLVLEN
1613 (wmi_twt_btwt_remove_sta_cmd_fixed_param));
1614
1615 cmd->vdev_id = params->vdev_id;
1616 WMI_CHAR_ARRAY_TO_MAC_ADDR(params->peer_macaddr, &cmd->peer_macaddr);
1617 cmd->dialog_id = params->dialog_id;
1618
1619 status = wmi_unified_cmd_send(wmi_handle, buf, sizeof(*cmd),
1620 WMI_TWT_BTWT_REMOVE_STA_CMDID);
1621 if (QDF_IS_STATUS_ERROR(status)) {
1622 wmi_buf_free(buf);
1623 }
1624
1625 return status;
1626 }
1627 #endif
1628
extract_twt_enable_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_enable_complete_event_param * params)1629 static QDF_STATUS extract_twt_enable_comp_event_tlv(wmi_unified_t wmi_handle,
1630 uint8_t *evt_buf,
1631 struct wmi_twt_enable_complete_event_param *params)
1632 {
1633 WMI_TWT_ENABLE_COMPLETE_EVENTID_param_tlvs *param_buf;
1634 wmi_twt_enable_complete_event_fixed_param *ev;
1635
1636 param_buf = (WMI_TWT_ENABLE_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1637 if (!param_buf) {
1638 wmi_err("evt_buf is NULL");
1639 return QDF_STATUS_E_INVAL;
1640 }
1641
1642 ev = param_buf->fixed_param;
1643
1644 params->pdev_id =
1645 wmi_handle->ops->convert_pdev_id_target_to_host(wmi_handle,
1646 ev->pdev_id);
1647 params->status = ev->status;
1648
1649 return QDF_STATUS_SUCCESS;
1650 }
1651
extract_twt_disable_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_disable_complete_event * params)1652 static QDF_STATUS extract_twt_disable_comp_event_tlv(wmi_unified_t wmi_handle,
1653 uint8_t *evt_buf,
1654 struct wmi_twt_disable_complete_event *params)
1655 {
1656 WMI_TWT_DISABLE_COMPLETE_EVENTID_param_tlvs *param_buf;
1657 wmi_twt_disable_complete_event_fixed_param *ev;
1658
1659 param_buf = (WMI_TWT_DISABLE_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1660 if (!param_buf) {
1661 wmi_err("evt_buf is NULL");
1662 return QDF_STATUS_E_INVAL;
1663 }
1664
1665 ev = param_buf->fixed_param;
1666
1667 #if 0
1668 params->pdev_id =
1669 wmi_handle->ops->convert_pdev_id_target_to_host(wmi_handle,
1670 ev->pdev_id);
1671 params->status = ev->status;
1672 #endif
1673
1674 return QDF_STATUS_SUCCESS;
1675 }
1676
1677 static enum WMI_HOST_ADD_TWT_STATUS
wmi_get_converted_twt_add_dialog_status(WMI_ADD_TWT_STATUS_T tgt_status)1678 wmi_get_converted_twt_add_dialog_status(WMI_ADD_TWT_STATUS_T tgt_status)
1679 {
1680 switch (tgt_status) {
1681 case WMI_ADD_TWT_STATUS_OK:
1682 return WMI_HOST_ADD_TWT_STATUS_OK;
1683 case WMI_ADD_TWT_STATUS_TWT_NOT_ENABLED:
1684 return WMI_HOST_ADD_TWT_STATUS_TWT_NOT_ENABLED;
1685 case WMI_ADD_TWT_STATUS_USED_DIALOG_ID:
1686 return WMI_HOST_ADD_TWT_STATUS_USED_DIALOG_ID;
1687 case WMI_ADD_TWT_STATUS_INVALID_PARAM:
1688 return WMI_HOST_ADD_TWT_STATUS_INVALID_PARAM;
1689 case WMI_ADD_TWT_STATUS_NOT_READY:
1690 return WMI_HOST_ADD_TWT_STATUS_NOT_READY;
1691 case WMI_ADD_TWT_STATUS_NO_RESOURCE:
1692 return WMI_HOST_ADD_TWT_STATUS_NO_RESOURCE;
1693 case WMI_ADD_TWT_STATUS_NO_ACK:
1694 return WMI_HOST_ADD_TWT_STATUS_NO_ACK;
1695 case WMI_ADD_TWT_STATUS_NO_RESPONSE:
1696 return WMI_HOST_ADD_TWT_STATUS_NO_RESPONSE;
1697 case WMI_ADD_TWT_STATUS_DENIED:
1698 return WMI_HOST_ADD_TWT_STATUS_DENIED;
1699 case WMI_ADD_TWT_STATUS_AP_PARAMS_NOT_IN_RANGE:
1700 return WMI_HOST_ADD_TWT_STATUS_AP_PARAMS_NOT_IN_RANGE;
1701 case WMI_ADD_TWT_STATUS_AP_IE_VALIDATION_FAILED:
1702 return WMI_HOST_ADD_TWT_STATUS_AP_IE_VALIDATION_FAILED;
1703 case WMI_ADD_TWT_STATUS_ROAM_IN_PROGRESS:
1704 return WMI_HOST_ADD_TWT_STATUS_ROAM_IN_PROGRESS;
1705 case WMI_ADD_TWT_STATUS_CHAN_SW_IN_PROGRESS:
1706 return WMI_HOST_ADD_TWT_STATUS_CHAN_SW_IN_PROGRESS;
1707 case WMI_ADD_TWT_STATUS_SCAN_IN_PROGRESS:
1708 return WMI_HOST_ADD_TWT_STATUS_SCAN_IN_PROGRESS;
1709 case WMI_ADD_TWT_STATUS_LINK_SWITCH_IN_PROGRESS:
1710 return WMI_HOST_ADD_TWT_STATUS_LINK_SWITCH_IN_PROGRESS;
1711 case WMI_ADD_TWT_STATUS_UNSUPPORTED_MODE_MLMR:
1712 return WMI_HOST_ADD_TWT_STATUS_UNSUPPORTED_MODE_MLMR;
1713 default:
1714 return WMI_HOST_ADD_TWT_STATUS_UNKNOWN_ERROR;
1715 }
1716 }
1717
1718 /**
1719 * extract_twt_add_dialog_comp_event_tlv - Extacts twt add dialog complete wmi
1720 * event from firmware
1721 * @wmi_handle: WMI handle
1722 * @evt_buf: Pointer to wmi event buf of twt add dialog complete event
1723 * @params: Pointer to store the extracted parameters
1724 *
1725 * Return: QDF_STATUS_SUCCESS on success or QDF STATUS error values on failure
1726 */
extract_twt_add_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_add_dialog_complete_event_param * params)1727 static QDF_STATUS extract_twt_add_dialog_comp_event_tlv(
1728 wmi_unified_t wmi_handle,
1729 uint8_t *evt_buf,
1730 struct wmi_twt_add_dialog_complete_event_param *params)
1731 {
1732 WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
1733 wmi_twt_add_dialog_complete_event_fixed_param *ev;
1734
1735 param_buf = (WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1736 if (!param_buf) {
1737 wmi_err("evt_buf is NULL");
1738 return QDF_STATUS_E_INVAL;
1739 }
1740
1741 ev = param_buf->fixed_param;
1742
1743 params->vdev_id = ev->vdev_id;
1744 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr, params->peer_macaddr);
1745 params->status = wmi_get_converted_twt_add_dialog_status(ev->status);
1746 params->dialog_id = ev->dialog_id;
1747 params->num_additional_twt_params = param_buf->num_twt_params;
1748
1749 return QDF_STATUS_SUCCESS;
1750 }
1751
1752 /**
1753 * extract_twt_add_dialog_comp_additional_parameters() - Extracts additional twt
1754 * twt parameters, as part of add dialog completion event
1755 * @wmi_handle: wmi handle
1756 * @evt_buf: Pointer event buffer
1757 * @evt_buf_len: length of the add dialog event buffer
1758 * @idx: index of num_twt_params
1759 * @additional_params: twt additional parameters to extract
1760 *
1761 * Return: QDF_STATUS_SUCCESS on success and QDF_STATUS_E_INVAL for failure
1762 */
extract_twt_add_dialog_comp_additional_parameters(wmi_unified_t wmi_handle,uint8_t * evt_buf,uint32_t evt_buf_len,uint32_t idx,struct wmi_twt_add_dialog_additional_params * additional_params)1763 static QDF_STATUS extract_twt_add_dialog_comp_additional_parameters
1764 (
1765 wmi_unified_t wmi_handle, uint8_t *evt_buf,
1766 uint32_t evt_buf_len, uint32_t idx,
1767 struct wmi_twt_add_dialog_additional_params *additional_params
1768 )
1769 {
1770 WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
1771 wmi_twt_add_dialog_complete_event_fixed_param *ev;
1772 uint32_t flags = 0;
1773 uint32_t expected_len;
1774
1775 param_buf = (WMI_TWT_ADD_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1776 if (!param_buf) {
1777 wmi_err("evt_buf is NULL");
1778 return QDF_STATUS_E_INVAL;
1779 }
1780
1781 ev = param_buf->fixed_param;
1782
1783 if (idx >= param_buf->num_twt_params) {
1784 wmi_err("Invalid idx %d while num_twt_params = %d",
1785 idx, param_buf->num_twt_params);
1786 return QDF_STATUS_E_INVAL;
1787 }
1788
1789 if (!param_buf->twt_params) {
1790 wmi_err("Unable to extract additional twt parameters");
1791 return QDF_STATUS_E_INVAL;
1792 }
1793
1794 expected_len = (sizeof(wmi_twt_add_dialog_complete_event_fixed_param) +
1795 WMI_TLV_HDR_SIZE + (param_buf->num_twt_params *
1796 sizeof(wmi_twt_add_dialog_additional_params)));
1797
1798 if (evt_buf_len != expected_len) {
1799 wmi_err("Got invalid len data from FW %d expected %d",
1800 evt_buf_len, expected_len);
1801 return QDF_STATUS_E_INVAL;
1802 }
1803
1804 flags = param_buf->twt_params[idx].flags;
1805 additional_params->twt_cmd = TWT_FLAGS_GET_CMD(flags);
1806 additional_params->bcast = TWT_FLAGS_GET_BROADCAST(flags);
1807 additional_params->trig_en = TWT_FLAGS_GET_TRIGGER(flags);
1808 additional_params->announce = TWT_FLAGS_GET_FLOW_TYPE(flags);
1809 additional_params->protection = TWT_FLAGS_GET_PROTECTION(flags);
1810 additional_params->b_twt_id0 = TWT_FLAGS_GET_BTWT_ID0(flags);
1811 additional_params->info_frame_disabled =
1812 TWT_FLAGS_GET_TWT_INFO_FRAME_DISABLED(flags);
1813 additional_params->wake_dur_us = param_buf->twt_params[idx].wake_dur_us;
1814 additional_params->wake_intvl_us =
1815 param_buf->twt_params[idx].wake_intvl_us;
1816 additional_params->sp_offset_us =
1817 param_buf->twt_params[idx].sp_offset_us;
1818 additional_params->sp_tsf_us_lo =
1819 param_buf->twt_params[idx].sp_tsf_us_lo;
1820 additional_params->sp_tsf_us_hi =
1821 param_buf->twt_params[idx].sp_tsf_us_hi;
1822 additional_params->pm_responder_bit_valid =
1823 TWT_FLAGS_GET_PM_RESPONDER_MODE_VALID(flags);
1824 additional_params->pm_responder_bit =
1825 TWT_FLAGS_GET_PM_RESPONDER_MODE(flags);
1826
1827 return QDF_STATUS_SUCCESS;
1828 }
1829
1830 static enum WMI_HOST_DEL_TWT_STATUS
wmi_get_converted_twt_del_dialog_status(WMI_DEL_TWT_STATUS_T tgt_status)1831 wmi_get_converted_twt_del_dialog_status(WMI_DEL_TWT_STATUS_T tgt_status)
1832 {
1833 switch (tgt_status) {
1834 case WMI_DEL_TWT_STATUS_OK:
1835 return WMI_HOST_DEL_TWT_STATUS_OK;
1836 case WMI_DEL_TWT_STATUS_DIALOG_ID_NOT_EXIST:
1837 return WMI_HOST_DEL_TWT_STATUS_DIALOG_ID_NOT_EXIST;
1838 case WMI_DEL_TWT_STATUS_INVALID_PARAM:
1839 return WMI_HOST_DEL_TWT_STATUS_INVALID_PARAM;
1840 case WMI_DEL_TWT_STATUS_DIALOG_ID_BUSY:
1841 return WMI_HOST_DEL_TWT_STATUS_DIALOG_ID_BUSY;
1842 case WMI_DEL_TWT_STATUS_NO_RESOURCE:
1843 return WMI_HOST_DEL_TWT_STATUS_NO_RESOURCE;
1844 case WMI_DEL_TWT_STATUS_NO_ACK:
1845 return WMI_HOST_DEL_TWT_STATUS_NO_ACK;
1846 case WMI_DEL_TWT_STATUS_UNKNOWN_ERROR:
1847 return WMI_HOST_DEL_TWT_STATUS_UNKNOWN_ERROR;
1848 case WMI_DEL_TWT_STATUS_PEER_INIT_TEARDOWN:
1849 return WMI_HOST_DEL_TWT_STATUS_PEER_INIT_TEARDOWN;
1850 case WMI_DEL_TWT_STATUS_ROAMING:
1851 return WMI_HOST_DEL_TWT_STATUS_ROAMING;
1852 case WMI_DEL_TWT_STATUS_CONCURRENCY:
1853 return WMI_HOST_DEL_TWT_STATUS_CONCURRENCY;
1854 case WMI_DEL_TWT_STATUS_CHAN_SW_IN_PROGRESS:
1855 return WMI_HOST_DEL_TWT_STATUS_CHAN_SW_IN_PROGRESS;
1856 case WMI_DEL_TWT_STATUS_SCAN_IN_PROGRESS:
1857 return WMI_HOST_DEL_TWT_STATUS_SCAN_IN_PROGRESS;
1858 default:
1859 return WMI_HOST_DEL_TWT_STATUS_UNKNOWN_ERROR;
1860 }
1861
1862 return WMI_HOST_DEL_TWT_STATUS_UNKNOWN_ERROR;
1863 }
1864
extract_twt_del_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_del_dialog_complete_event_param * params)1865 static QDF_STATUS extract_twt_del_dialog_comp_event_tlv(
1866 wmi_unified_t wmi_handle,
1867 uint8_t *evt_buf,
1868 struct wmi_twt_del_dialog_complete_event_param *params)
1869 {
1870 WMI_TWT_DEL_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
1871 wmi_twt_del_dialog_complete_event_fixed_param *ev;
1872
1873 param_buf = (WMI_TWT_DEL_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1874 if (!param_buf) {
1875 wmi_err("evt_buf is NULL");
1876 return QDF_STATUS_E_INVAL;
1877 }
1878
1879 ev = param_buf->fixed_param;
1880
1881 params->vdev_id = ev->vdev_id;
1882 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr, params->peer_macaddr);
1883 params->dialog_id = ev->dialog_id;
1884 params->status = wmi_get_converted_twt_del_dialog_status(ev->status);
1885
1886 return QDF_STATUS_SUCCESS;
1887 }
1888
1889 static enum WMI_HOST_PAUSE_TWT_STATUS
wmi_twt_pause_status_to_host_twt_status(WMI_PAUSE_TWT_STATUS_T status)1890 wmi_twt_pause_status_to_host_twt_status(WMI_PAUSE_TWT_STATUS_T status)
1891 {
1892 switch (status) {
1893 case WMI_PAUSE_TWT_STATUS_OK:
1894 return WMI_HOST_PAUSE_TWT_STATUS_OK;
1895 case WMI_PAUSE_TWT_STATUS_DIALOG_ID_NOT_EXIST:
1896 return WMI_HOST_PAUSE_TWT_STATUS_DIALOG_ID_NOT_EXIST;
1897 case WMI_PAUSE_TWT_STATUS_INVALID_PARAM:
1898 return WMI_HOST_PAUSE_TWT_STATUS_INVALID_PARAM;
1899 case WMI_PAUSE_TWT_STATUS_DIALOG_ID_BUSY:
1900 return WMI_HOST_PAUSE_TWT_STATUS_DIALOG_ID_BUSY;
1901 case WMI_PAUSE_TWT_STATUS_NO_RESOURCE:
1902 return WMI_HOST_PAUSE_TWT_STATUS_NO_RESOURCE;
1903 case WMI_PAUSE_TWT_STATUS_NO_ACK:
1904 return WMI_HOST_PAUSE_TWT_STATUS_NO_ACK;
1905 case WMI_PAUSE_TWT_STATUS_UNKNOWN_ERROR:
1906 return WMI_HOST_PAUSE_TWT_STATUS_UNKNOWN_ERROR;
1907 case WMI_PAUSE_TWT_STATUS_ALREADY_PAUSED:
1908 return WMI_HOST_PAUSE_TWT_STATUS_ALREADY_PAUSED;
1909 case WMI_PAUSE_TWT_STATUS_CHAN_SW_IN_PROGRESS:
1910 return WMI_HOST_PAUSE_TWT_STATUS_CHAN_SW_IN_PROGRESS;
1911 case WMI_PAUSE_TWT_STATUS_ROAM_IN_PROGRESS:
1912 return WMI_HOST_PAUSE_TWT_STATUS_ROAM_IN_PROGRESS;
1913 case WMI_PAUSE_TWT_STATUS_SCAN_IN_PROGRESS:
1914 return WMI_HOST_PAUSE_TWT_STATUS_SCAN_IN_PROGRESS;
1915 default:
1916 return WMI_HOST_PAUSE_TWT_STATUS_UNKNOWN_ERROR;
1917 }
1918 }
1919
extract_twt_pause_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_pause_dialog_complete_event_param * params)1920 static QDF_STATUS extract_twt_pause_dialog_comp_event_tlv(
1921 wmi_unified_t wmi_handle,
1922 uint8_t *evt_buf,
1923 struct wmi_twt_pause_dialog_complete_event_param *params)
1924 {
1925 WMI_TWT_PAUSE_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
1926 wmi_twt_pause_dialog_complete_event_fixed_param *ev;
1927
1928 param_buf = (WMI_TWT_PAUSE_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1929 if (!param_buf) {
1930 wmi_err("evt_buf is NULL");
1931 return QDF_STATUS_E_INVAL;
1932 }
1933
1934 ev = param_buf->fixed_param;
1935
1936 params->vdev_id = ev->vdev_id;
1937 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr, params->peer_macaddr);
1938 params->status = wmi_twt_pause_status_to_host_twt_status(ev->status);
1939 params->dialog_id = ev->dialog_id;
1940
1941 return QDF_STATUS_SUCCESS;
1942 }
1943
1944 static enum WMI_HOST_NUDGE_TWT_STATUS
wmi_twt_nudge_status_to_host_twt_status(WMI_TWT_NUDGE_STATUS_T status)1945 wmi_twt_nudge_status_to_host_twt_status(WMI_TWT_NUDGE_STATUS_T status)
1946 {
1947 switch (status) {
1948 case WMI_NUDGE_TWT_STATUS_OK:
1949 return WMI_HOST_NUDGE_TWT_STATUS_OK;
1950 case WMI_NUDGE_TWT_STATUS_DIALOG_ID_NOT_EXIST:
1951 return WMI_HOST_NUDGE_TWT_STATUS_DIALOG_ID_NOT_EXIST;
1952 case WMI_NUDGE_TWT_STATUS_INVALID_PARAM:
1953 return WMI_HOST_NUDGE_TWT_STATUS_INVALID_PARAM;
1954 case WMI_NUDGE_TWT_STATUS_DIALOG_ID_BUSY:
1955 return WMI_HOST_NUDGE_TWT_STATUS_DIALOG_ID_BUSY;
1956 case WMI_NUDGE_TWT_STATUS_NO_RESOURCE:
1957 return WMI_HOST_NUDGE_TWT_STATUS_NO_RESOURCE;
1958 case WMI_NUDGE_TWT_STATUS_NO_ACK:
1959 return WMI_HOST_NUDGE_TWT_STATUS_NO_ACK;
1960 case WMI_NUDGE_TWT_STATUS_UNKNOWN_ERROR:
1961 return WMI_HOST_NUDGE_TWT_STATUS_UNKNOWN_ERROR;
1962 case WMI_NUDGE_TWT_STATUS_ALREADY_PAUSED:
1963 return WMI_HOST_NUDGE_TWT_STATUS_ALREADY_PAUSED;
1964 case WMI_NUDGE_TWT_STATUS_CHAN_SW_IN_PROGRESS:
1965 return WMI_HOST_NUDGE_TWT_STATUS_CHAN_SW_IN_PROGRESS;
1966 case WMI_NUDGE_TWT_STATUS_ROAM_IN_PROGRESS:
1967 return WMI_HOST_NUDGE_TWT_STATUS_ROAM_IN_PROGRESS;
1968 case WMI_NUDGE_TWT_STATUS_SCAN_IN_PROGRESS:
1969 return WMI_HOST_NUDGE_TWT_STATUS_SCAN_IN_PROGRESS;
1970 default:
1971 return WMI_HOST_NUDGE_TWT_STATUS_UNKNOWN_ERROR;
1972 }
1973 }
1974
extract_twt_nudge_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_nudge_dialog_complete_event_param * params)1975 static QDF_STATUS extract_twt_nudge_dialog_comp_event_tlv(
1976 wmi_unified_t wmi_handle,
1977 uint8_t *evt_buf,
1978 struct wmi_twt_nudge_dialog_complete_event_param *params)
1979 {
1980 WMI_TWT_NUDGE_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
1981 wmi_twt_nudge_dialog_complete_event_fixed_param *ev;
1982
1983 param_buf = (WMI_TWT_NUDGE_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
1984 if (!param_buf) {
1985 wmi_err("evt_buf is NULL");
1986 return QDF_STATUS_E_INVAL;
1987 }
1988
1989 ev = param_buf->fixed_param;
1990
1991 params->vdev_id = ev->vdev_id;
1992 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr, params->peer_macaddr);
1993 params->status = wmi_twt_nudge_status_to_host_twt_status(ev->status);
1994 params->dialog_id = ev->dialog_id;
1995 params->next_twt_tsf_us_lo = ev->sp_tsf_us_lo;
1996 params->next_twt_tsf_us_hi = ev->sp_tsf_us_hi;
1997
1998 wmi_debug("vdev_id: %d dialog_id: %d tsf hi : %x tsf lo: %x",
1999 params->vdev_id, params->dialog_id,
2000 params->next_twt_tsf_us_hi, params->next_twt_tsf_us_lo);
2001
2002 return QDF_STATUS_SUCCESS;
2003 }
2004
2005 static enum WMI_HOST_RESUME_TWT_STATUS
wmi_get_converted_twt_resume_dialog_status(WMI_RESUME_TWT_STATUS_T tgt_status)2006 wmi_get_converted_twt_resume_dialog_status(WMI_RESUME_TWT_STATUS_T tgt_status)
2007 {
2008 switch (tgt_status) {
2009 case WMI_RESUME_TWT_STATUS_OK:
2010 return WMI_HOST_RESUME_TWT_STATUS_OK;
2011 case WMI_RESUME_TWT_STATUS_DIALOG_ID_NOT_EXIST:
2012 return WMI_HOST_RESUME_TWT_STATUS_DIALOG_ID_NOT_EXIST;
2013 case WMI_RESUME_TWT_STATUS_INVALID_PARAM:
2014 return WMI_HOST_RESUME_TWT_STATUS_INVALID_PARAM;
2015 case WMI_RESUME_TWT_STATUS_DIALOG_ID_BUSY:
2016 return WMI_HOST_RESUME_TWT_STATUS_DIALOG_ID_BUSY;
2017 case WMI_RESUME_TWT_STATUS_NOT_PAUSED:
2018 return WMI_HOST_RESUME_TWT_STATUS_NOT_PAUSED;
2019 case WMI_RESUME_TWT_STATUS_NO_RESOURCE:
2020 return WMI_HOST_RESUME_TWT_STATUS_NO_RESOURCE;
2021 case WMI_RESUME_TWT_STATUS_NO_ACK:
2022 return WMI_HOST_RESUME_TWT_STATUS_NO_ACK;
2023 case WMI_RESUME_TWT_STATUS_CHAN_SW_IN_PROGRESS:
2024 return WMI_HOST_RESUME_TWT_STATUS_CHAN_SW_IN_PROGRESS;
2025 case WMI_RESUME_TWT_STATUS_ROAM_IN_PROGRESS:
2026 return WMI_HOST_RESUME_TWT_STATUS_ROAM_IN_PROGRESS;
2027 case WMI_RESUME_TWT_STATUS_SCAN_IN_PROGRESS:
2028 return WMI_HOST_RESUME_TWT_STATUS_SCAN_IN_PROGRESS;
2029 default:
2030 return WMI_HOST_RESUME_TWT_STATUS_UNKNOWN_ERROR;
2031 }
2032 }
2033
extract_twt_resume_dialog_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_resume_dialog_complete_event_param * params)2034 static QDF_STATUS extract_twt_resume_dialog_comp_event_tlv(
2035 wmi_unified_t wmi_handle,
2036 uint8_t *evt_buf,
2037 struct wmi_twt_resume_dialog_complete_event_param *params)
2038 {
2039 WMI_TWT_RESUME_DIALOG_COMPLETE_EVENTID_param_tlvs *param_buf;
2040 wmi_twt_resume_dialog_complete_event_fixed_param *ev;
2041
2042 param_buf =
2043 (WMI_TWT_RESUME_DIALOG_COMPLETE_EVENTID_param_tlvs *)evt_buf;
2044 if (!param_buf) {
2045 wmi_err("evt_buf is NULL");
2046 return QDF_STATUS_E_INVAL;
2047 }
2048
2049 ev = param_buf->fixed_param;
2050
2051 params->vdev_id = ev->vdev_id;
2052 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr, params->peer_macaddr);
2053 params->status = wmi_get_converted_twt_resume_dialog_status(ev->status);
2054 params->dialog_id = ev->dialog_id;
2055
2056 return QDF_STATUS_SUCCESS;
2057 }
2058
extract_twt_notify_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_notify_event_param * params)2059 static QDF_STATUS extract_twt_notify_event_tlv(
2060 wmi_unified_t wmi_handle,
2061 uint8_t *evt_buf,
2062 struct wmi_twt_notify_event_param *params)
2063 {
2064 WMI_TWT_NOTIFY_EVENTID_param_tlvs *param_buf;
2065 wmi_twt_notify_event_fixed_param *ev;
2066
2067 param_buf =
2068 (WMI_TWT_NOTIFY_EVENTID_param_tlvs *)evt_buf;
2069 if (!param_buf) {
2070 wmi_err("evt_buf is NULL");
2071 return QDF_STATUS_E_INVAL;
2072 }
2073
2074 ev = param_buf->fixed_param;
2075
2076 params->vdev_id = ev->vdev_id;
2077
2078 return QDF_STATUS_SUCCESS;
2079 }
2080
2081 #ifdef WLAN_SUPPORT_BCAST_TWT
2082 static QDF_STATUS
extract_twt_btwt_invite_sta_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_btwt_invite_sta_complete_event_param * params)2083 extract_twt_btwt_invite_sta_comp_event_tlv(
2084 wmi_unified_t wmi_handle,
2085 uint8_t *evt_buf,
2086 struct
2087 wmi_twt_btwt_invite_sta_complete_event_param
2088 *params)
2089 {
2090 WMI_TWT_BTWT_INVITE_STA_COMPLETE_EVENTID_param_tlvs *param_buf;
2091 wmi_twt_btwt_invite_sta_complete_event_fixed_param *ev;
2092
2093 param_buf =
2094 (WMI_TWT_BTWT_INVITE_STA_COMPLETE_EVENTID_param_tlvs *)evt_buf;
2095 if (!param_buf) {
2096 wmi_err("evt_buf is NULL");
2097 return QDF_STATUS_E_INVAL;
2098 }
2099
2100 ev = param_buf->fixed_param;
2101
2102 params->vdev_id = ev->vdev_id;
2103 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr, params->peer_macaddr);
2104 params->status = ev->status;
2105 params->dialog_id = ev->dialog_id;
2106
2107 return QDF_STATUS_SUCCESS;
2108 }
2109
2110 static QDF_STATUS
extract_twt_btwt_remove_sta_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_btwt_remove_sta_complete_event_param * params)2111 extract_twt_btwt_remove_sta_comp_event_tlv(
2112 wmi_unified_t wmi_handle,
2113 uint8_t *evt_buf,
2114 struct
2115 wmi_twt_btwt_remove_sta_complete_event_param
2116 *params)
2117 {
2118 WMI_TWT_BTWT_REMOVE_STA_COMPLETE_EVENTID_param_tlvs *param_buf;
2119 wmi_twt_btwt_remove_sta_complete_event_fixed_param *ev;
2120
2121 param_buf =
2122 (WMI_TWT_BTWT_REMOVE_STA_COMPLETE_EVENTID_param_tlvs *)evt_buf;
2123 if (!param_buf) {
2124 wmi_err("evt_buf is NULL");
2125 return QDF_STATUS_E_INVAL;
2126 }
2127
2128 ev = param_buf->fixed_param;
2129
2130 params->vdev_id = ev->vdev_id;
2131 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ev->peer_macaddr, params->peer_macaddr);
2132 params->status = ev->status;
2133 params->dialog_id = ev->dialog_id;
2134
2135 return QDF_STATUS_SUCCESS;
2136 }
2137 #endif
2138
2139 #ifdef WLAN_SUPPORT_BCAST_TWT
2140 static void
wmi_twt_attach_bcast_twt_tlv(struct wmi_ops * ops)2141 wmi_twt_attach_bcast_twt_tlv(struct wmi_ops *ops)
2142 {
2143 ops->send_twt_btwt_invite_sta_cmd = send_twt_btwt_invite_sta_cmd_tlv;
2144 ops->send_twt_btwt_remove_sta_cmd = send_twt_btwt_remove_sta_cmd_tlv;
2145 ops->extract_twt_btwt_invite_sta_comp_event =
2146 extract_twt_btwt_invite_sta_comp_event_tlv;
2147 ops->extract_twt_btwt_remove_sta_comp_event =
2148 extract_twt_btwt_remove_sta_comp_event_tlv;
2149 }
2150 #else
2151 static void
wmi_twt_attach_bcast_twt_tlv(struct wmi_ops * ops)2152 wmi_twt_attach_bcast_twt_tlv(struct wmi_ops *ops)
2153 {
2154 }
2155 #endif
2156
2157 static QDF_STATUS
extract_twt_session_stats_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_session_stats_event_param * params)2158 extract_twt_session_stats_event_tlv(wmi_unified_t wmi_handle,
2159 uint8_t *evt_buf,
2160 struct wmi_twt_session_stats_event_param
2161 *params)
2162 {
2163 WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *param_buf;
2164 wmi_pdev_twt_session_stats_event_fixed_param *ev;
2165
2166 param_buf =
2167 (WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *)evt_buf;
2168 if (!param_buf) {
2169 wmi_err("evt_buf is NULL");
2170 return QDF_STATUS_E_INVAL;
2171 }
2172
2173 ev = param_buf->fixed_param;
2174 params->pdev_id = wmi_handle->ops->convert_pdev_id_target_to_host(
2175 wmi_handle,
2176 ev->pdev_id);
2177 params->num_sessions = param_buf->num_twt_sessions;
2178
2179 wmi_debug("pdev_id=%d, num of TWT sessions=%d",
2180 params->pdev_id, params->num_sessions);
2181
2182 return QDF_STATUS_SUCCESS;
2183 }
2184
2185 static QDF_STATUS
extract_twt_session_stats_event_data(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_session_stats_event_param * params,struct wmi_host_twt_session_stats_info * session,uint32_t idx)2186 extract_twt_session_stats_event_data(wmi_unified_t wmi_handle,
2187 uint8_t *evt_buf,
2188 struct wmi_twt_session_stats_event_param
2189 *params,
2190 struct wmi_host_twt_session_stats_info
2191 *session,
2192 uint32_t idx)
2193 {
2194 WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *param_buf;
2195 wmi_twt_session_stats_info *twt_session;
2196 uint32_t flags;
2197 wmi_mac_addr *m1;
2198 uint8_t *m2;
2199
2200 param_buf =
2201 (WMI_TWT_SESSION_STATS_EVENTID_param_tlvs *)evt_buf;
2202 if (!param_buf) {
2203 wmi_err("evt_buf is NULL");
2204 return QDF_STATUS_E_INVAL;
2205 }
2206
2207 if (idx >= param_buf->num_twt_sessions) {
2208 wmi_err("wrong idx, idx=%d, num_sessions=%d",
2209 idx, param_buf->num_twt_sessions);
2210 return QDF_STATUS_E_INVAL;
2211 }
2212
2213 twt_session = ¶m_buf->twt_sessions[idx];
2214
2215 session->vdev_id = twt_session->vdev_id;
2216 m1 = &twt_session->peer_mac;
2217 m2 = session->peer_mac;
2218 WMI_MAC_ADDR_TO_CHAR_ARRAY(m1, m2);
2219 session->event_type = twt_session->event_type;
2220 flags = twt_session->flow_id_flags;
2221 session->flow_id = WMI_TWT_SESSION_FLAG_FLOW_ID_GET(flags);
2222 session->bcast = WMI_TWT_SESSION_FLAG_BCAST_TWT_GET(flags);
2223 session->trig = WMI_TWT_SESSION_FLAG_TRIGGER_TWT_GET(flags);
2224 session->announ = WMI_TWT_SESSION_FLAG_ANNOUN_TWT_GET(flags);
2225 session->protection = WMI_TWT_SESSION_FLAG_TWT_PROTECTION_GET(flags);
2226 session->info_frame_disabled =
2227 WMI_TWT_SESSION_FLAG_TWT_INFO_FRAME_DISABLED_GET(flags);
2228 session->pm_responder_bit =
2229 WMI_TWT_SESSION_FLAG_TWT_PM_RESPONDER_MODE_GET(flags);
2230 session->pm_responder_bit_valid =
2231 WMI_TWT_SESSION_FLAG_TWT_PM_RESPONDER_MODE_VALID_GET(flags);
2232 session->dialog_id = twt_session->dialog_id;
2233 session->wake_dura_us = twt_session->wake_dura_us;
2234 session->wake_intvl_us = twt_session->wake_intvl_us;
2235 session->sp_offset_us = twt_session->sp_offset_us;
2236 session->sp_tsf_us_lo = twt_session->sp_tsf_us_lo;
2237 session->sp_tsf_us_hi = twt_session->sp_tsf_us_hi;
2238 wmi_debug("type=%d id=%d bcast=%d trig=%d announ=%d diagid=%d wake_dur=%ul wake_int=%ul offset=%ul",
2239 session->event_type, session->flow_id,
2240 session->bcast, session->trig,
2241 session->announ, session->dialog_id, session->wake_dura_us,
2242 session->wake_intvl_us, session->sp_offset_us);
2243 wmi_debug("resp_pm_valid=%d resp_pm=%d",
2244 session->pm_responder_bit_valid, session->pm_responder_bit);
2245
2246 return QDF_STATUS_SUCCESS;
2247 }
2248
extract_twt_cap_service_ready_ext2_tlv(wmi_unified_t wmi_handle,uint8_t * event,struct wmi_twt_cap_bitmap_params * var)2249 static QDF_STATUS extract_twt_cap_service_ready_ext2_tlv(
2250 wmi_unified_t wmi_handle, uint8_t *event,
2251 struct wmi_twt_cap_bitmap_params *var)
2252 {
2253 WMI_SERVICE_READY_EXT2_EVENTID_param_tlvs *param_buf;
2254 wmi_twt_caps_params *twt_caps;
2255
2256 param_buf = (WMI_SERVICE_READY_EXT2_EVENTID_param_tlvs *)event;
2257 if (!param_buf)
2258 return QDF_STATUS_E_INVAL;
2259
2260 twt_caps = param_buf->twt_caps;
2261 if (!twt_caps)
2262 return QDF_STATUS_E_INVAL;
2263
2264 var->twt_ack_support_cap = WMI_GET_BITS(twt_caps->twt_capability_bitmap,
2265 0, 1);
2266
2267 return QDF_STATUS_SUCCESS;
2268 }
2269
2270 static enum WMI_HOST_TWT_CMD_FOR_ACK_EVENT
wmi_get_converted_twt_command_for_ack_event(WMI_CMD_ID tgt_cmd)2271 wmi_get_converted_twt_command_for_ack_event(WMI_CMD_ID tgt_cmd)
2272 {
2273 switch (tgt_cmd) {
2274 case WMI_TWT_ADD_DIALOG_CMDID:
2275 return WMI_HOST_TWT_ADD_DIALOG_CMDID;
2276 case WMI_TWT_DEL_DIALOG_CMDID:
2277 return WMI_HOST_TWT_DEL_DIALOG_CMDID;
2278 case WMI_TWT_PAUSE_DIALOG_CMDID:
2279 return WMI_HOST_TWT_PAUSE_DIALOG_CMDID;
2280 case WMI_TWT_RESUME_DIALOG_CMDID:
2281 return WMI_HOST_TWT_RESUME_DIALOG_CMDID;
2282 case WMI_TWT_NUDGE_DIALOG_CMDID:
2283 return WMI_HOST_TWT_NUDGE_DIALOG_CMDID;
2284 default:
2285 return WMI_HOST_TWT_UNKNOWN_CMDID;
2286 }
2287 }
2288
2289 static QDF_STATUS
extract_twt_ack_comp_event_tlv(wmi_unified_t wmi_handle,uint8_t * evt_buf,struct wmi_twt_ack_complete_event_param * var)2290 extract_twt_ack_comp_event_tlv(wmi_unified_t wmi_handle,
2291 uint8_t *evt_buf,
2292 struct wmi_twt_ack_complete_event_param *var)
2293 {
2294 WMI_TWT_ACK_EVENTID_param_tlvs *param_buf;
2295 wmi_twt_ack_event_fixed_param *ack_event;
2296
2297 param_buf = (WMI_TWT_ACK_EVENTID_param_tlvs *)evt_buf;
2298 if (!param_buf) {
2299 wmi_err("evt_buf is NULL");
2300 return QDF_STATUS_E_INVAL;
2301 }
2302
2303 ack_event = param_buf->fixed_param;
2304
2305 var->vdev_id = ack_event->vdev_id;
2306 WMI_MAC_ADDR_TO_CHAR_ARRAY(&ack_event->peer_macaddr,
2307 var->peer_macaddr.bytes);
2308 var->dialog_id = ack_event->dialog_id;
2309 var->twt_cmd_ack = wmi_get_converted_twt_command_for_ack_event(
2310 ack_event->twt_cmd);
2311
2312 switch (ack_event->twt_cmd) {
2313 case WMI_TWT_ADD_DIALOG_CMDID:
2314 var->status = wmi_get_converted_twt_add_dialog_status(
2315 ack_event->status);
2316 break;
2317 case WMI_TWT_DEL_DIALOG_CMDID:
2318 var->status = wmi_get_converted_twt_del_dialog_status(
2319 ack_event->status);
2320 break;
2321 case WMI_TWT_PAUSE_DIALOG_CMDID:
2322 var->status = wmi_twt_pause_status_to_host_twt_status(
2323 ack_event->status);
2324 break;
2325 case WMI_TWT_RESUME_DIALOG_CMDID:
2326 var->status = wmi_get_converted_twt_resume_dialog_status(
2327 ack_event->status);
2328 break;
2329 case WMI_TWT_NUDGE_DIALOG_CMDID:
2330 var->status = wmi_twt_nudge_status_to_host_twt_status(
2331 ack_event->status);
2332 break;
2333 default:
2334 break;
2335 }
2336 return QDF_STATUS_SUCCESS;
2337 }
2338 #endif
2339
wmi_twt_attach_tlv(wmi_unified_t wmi_handle)2340 void wmi_twt_attach_tlv(wmi_unified_t wmi_handle)
2341 {
2342 struct wmi_ops *ops = wmi_handle->ops;
2343
2344 ops->send_twt_enable_cmd = send_twt_enable_cmd_tlv;
2345 ops->send_twt_disable_cmd = send_twt_disable_cmd_tlv;
2346 ops->send_twt_add_dialog_cmd = send_twt_add_dialog_cmd_tlv;
2347 ops->send_twt_del_dialog_cmd = send_twt_del_dialog_cmd_tlv;
2348 ops->send_twt_pause_dialog_cmd = send_twt_pause_dialog_cmd_tlv;
2349 ops->send_twt_nudge_dialog_cmd = send_twt_nudge_dialog_cmd_tlv;
2350 ops->send_twt_resume_dialog_cmd = send_twt_resume_dialog_cmd_tlv;
2351 ops->extract_twt_enable_comp_event = extract_twt_enable_comp_event_tlv;
2352 ops->extract_twt_disable_comp_event =
2353 extract_twt_disable_comp_event_tlv;
2354 ops->extract_twt_add_dialog_comp_event =
2355 extract_twt_add_dialog_comp_event_tlv;
2356 ops->extract_twt_add_dialog_comp_additional_params =
2357 extract_twt_add_dialog_comp_additional_parameters;
2358 ops->extract_twt_del_dialog_comp_event =
2359 extract_twt_del_dialog_comp_event_tlv;
2360 ops->extract_twt_pause_dialog_comp_event =
2361 extract_twt_pause_dialog_comp_event_tlv;
2362 ops->extract_twt_nudge_dialog_comp_event =
2363 extract_twt_nudge_dialog_comp_event_tlv;
2364 ops->extract_twt_resume_dialog_comp_event =
2365 extract_twt_resume_dialog_comp_event_tlv;
2366 ops->extract_twt_session_stats_event =
2367 extract_twt_session_stats_event_tlv;
2368 ops->extract_twt_session_stats_data =
2369 extract_twt_session_stats_event_data;
2370 ops->extract_twt_notify_event =
2371 extract_twt_notify_event_tlv;
2372 ops->extract_twt_cap_service_ready_ext2 =
2373 extract_twt_cap_service_ready_ext2_tlv,
2374 ops->extract_twt_ack_comp_event = extract_twt_ack_comp_event_tlv;
2375 wmi_twt_attach_bcast_twt_tlv(ops);
2376 }
2377