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