1 /*
2 * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include "wmi_unified.h"
18 #include "wmi_unified_param.h"
19 #include <wmi_unified_priv.h>
20 #include <wmi.h>
21 #include "wmi_unified_ll_sap_tlv.h"
22
23 static WMI_AUDIO_TRANSPORT_SWITCH_RESPONSE_STATUS
wmi_convert_host_to_target_audio_switch_status(enum bearer_switch_status status)24 wmi_convert_host_to_target_audio_switch_status(enum bearer_switch_status status)
25 {
26 if (status == WLAN_BS_STATUS_COMPLETED)
27 return WMI_AUDIO_TRANSPORT_SWITCH_STATUS_SUCCESS;
28 else if (status == WLAN_BS_STATUS_REJECTED)
29 return WMI_AUDIO_TRANSPORT_SWITCH_STATUS_FAIL;
30 else
31 return WMI_AUDIO_TRANSPORT_SWITCH_STATUS_TIMEOUT;
32 }
33
34 static WMI_AUDIO_TRANSPORT_SWITCH_TYPE
wmi_convert_host_to_target_audio_switch_type(enum bearer_switch_req_type req_type)35 wmi_convert_host_to_target_audio_switch_type(
36 enum bearer_switch_req_type req_type)
37 {
38 if (req_type == WLAN_BS_REQ_TO_NON_WLAN)
39 return WMI_AUDIO_TRANSPORT_SWITCH_TYPE_NON_WLAN;
40 else
41 return WMI_AUDIO_TRANSPORT_SWITCH_TYPE_WLAN;
42 }
43
44 static enum bearer_switch_req_type
wmi_convert_target_to_host_audio_switch_type(uint32_t req_type)45 wmi_convert_target_to_host_audio_switch_type(uint32_t req_type)
46 {
47 if (req_type == WMI_AUDIO_TRANSPORT_SWITCH_TYPE_NON_WLAN)
48 return WLAN_BS_REQ_TO_NON_WLAN;
49 else if (req_type == WMI_AUDIO_TRANSPORT_SWITCH_TYPE_WLAN)
50 return WLAN_BS_REQ_TO_WLAN;
51 else
52 return WLAN_BS_REQ_INVALID;
53 }
54
audio_transport_switch_resp_tlv(wmi_unified_t wmi_hdl,enum bearer_switch_req_type req_type,enum bearer_switch_status status)55 QDF_STATUS audio_transport_switch_resp_tlv(
56 wmi_unified_t wmi_hdl,
57 enum bearer_switch_req_type req_type,
58 enum bearer_switch_status status)
59 {
60 wmi_audio_transport_switch_resp_status_cmd_fixed_param *cmd;
61 wmi_buf_t buf;
62 QDF_STATUS qdf_status;
63
64 buf = wmi_buf_alloc(wmi_hdl, sizeof(*cmd));
65 if (!buf)
66 return QDF_STATUS_E_FAILURE;
67
68 cmd = (wmi_audio_transport_switch_resp_status_cmd_fixed_param *)wmi_buf_data(buf);
69
70 WMITLV_SET_HDR(
71 &cmd->tlv_header,
72 WMITLV_TAG_STRUC_wmi_audio_transport_switch_resp_status_cmd_fixed_param,
73 WMITLV_GET_STRUCT_TLVLEN
74 (wmi_audio_transport_switch_resp_status_cmd_fixed_param));
75
76 cmd->switch_type = wmi_convert_host_to_target_audio_switch_type(
77 req_type);
78 cmd->switch_response_status =
79 wmi_convert_host_to_target_audio_switch_status(status);
80
81 wmi_nofl_debug("LL_LT_SAP Audio switch type %d status %d",
82 cmd->switch_type, cmd->switch_response_status);
83
84 qdf_status = wmi_unified_cmd_send(
85 wmi_hdl, buf, sizeof(*cmd),
86 WMI_AUDIO_TRANSPORT_SWITCH_RESP_STATUS_CMDID);
87
88 if (QDF_IS_STATUS_ERROR(qdf_status))
89 wmi_buf_free(buf);
90
91 return qdf_status;
92 }
93
94 QDF_STATUS
extract_audio_transport_switch_req_event_tlv(wmi_unified_t wmi_handle,uint8_t * event,uint32_t len,enum bearer_switch_req_type * req_type)95 extract_audio_transport_switch_req_event_tlv(
96 wmi_unified_t wmi_handle,
97 uint8_t *event, uint32_t len,
98 enum bearer_switch_req_type *req_type)
99 {
100 WMI_AUDIO_TRANSPORT_SWITCH_TYPE_EVENTID_param_tlvs *param_buf = NULL;
101 wmi_audio_transport_switch_type_event_fixed_param *fixed_param = NULL;
102
103 if (!event || !len) {
104 wmi_debug("Empty transport switch request event");
105 return QDF_STATUS_E_FAILURE;
106 }
107
108 param_buf = (WMI_AUDIO_TRANSPORT_SWITCH_TYPE_EVENTID_param_tlvs *)event;
109 if (!param_buf) {
110 wmi_err("received null buf from target");
111 return QDF_STATUS_E_INVAL;
112 }
113
114 fixed_param = (wmi_audio_transport_switch_type_event_fixed_param *)
115 param_buf->fixed_param;
116 if (!fixed_param) {
117 wmi_err("received null event data from target");
118 return QDF_STATUS_E_INVAL;
119 }
120
121 *req_type = wmi_convert_target_to_host_audio_switch_type(
122 fixed_param->switch_type);
123
124 wmi_nofl_debug("LL_LT_SAP FW requested bearer switch to %d", *req_type);
125
126 if (*req_type == WLAN_BS_REQ_TO_WLAN)
127 return QDF_STATUS_E_INVAL;
128
129 return QDF_STATUS_SUCCESS;
130 }
131