1 /*
2 * Copyright (c) 2022 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 /*
18 * DOC: contains CoAP south bound interface definitions
19 */
20
21 #include <wlan_coap_main.h>
22 #include <wlan_coap_tgt_api.h>
23 #include <wlan_lmac_if_def.h>
24 #include "wlan_objmgr_pdev_obj.h"
25
26 static inline struct wlan_lmac_if_coap_tx_ops *
wlan_psoc_get_coap_txops(struct wlan_objmgr_psoc * psoc)27 wlan_psoc_get_coap_txops(struct wlan_objmgr_psoc *psoc)
28 {
29 struct wlan_lmac_if_tx_ops *tx_ops;
30
31 tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
32 if (!tx_ops) {
33 coap_err("tx_ops is NULL");
34 return NULL;
35 }
36
37 return &tx_ops->coap_ops;
38 }
39
40 static inline struct wlan_lmac_if_coap_tx_ops *
wlan_vdev_get_coap_txops(struct wlan_objmgr_vdev * vdev)41 wlan_vdev_get_coap_txops(struct wlan_objmgr_vdev *vdev)
42 {
43 struct wlan_objmgr_psoc *psoc;
44
45 psoc = wlan_vdev_get_psoc(vdev);
46 if (!psoc) {
47 coap_err("NULL psoc");
48 return NULL;
49 }
50
51 return wlan_psoc_get_coap_txops(psoc);
52 }
53
tgt_coap_attach(struct wlan_objmgr_psoc * psoc)54 QDF_STATUS tgt_coap_attach(struct wlan_objmgr_psoc *psoc)
55 {
56 struct wlan_lmac_if_coap_tx_ops *coap_tx_ops;
57
58 if (!psoc) {
59 coap_err("psoc is null");
60 return QDF_STATUS_E_NULL_VALUE;
61 }
62
63 coap_tx_ops = wlan_psoc_get_coap_txops(psoc);
64 if (!coap_tx_ops) {
65 coap_err("tx_ops is null!");
66 return QDF_STATUS_E_NULL_VALUE;
67 }
68
69 if (!coap_tx_ops->attach) {
70 coap_err("attach function is null!");
71 return QDF_STATUS_E_NULL_VALUE;
72 }
73
74 return coap_tx_ops->attach(psoc);
75 }
76
tgt_coap_detach(struct wlan_objmgr_psoc * psoc)77 QDF_STATUS tgt_coap_detach(struct wlan_objmgr_psoc *psoc)
78 {
79 struct wlan_lmac_if_coap_tx_ops *coap_tx_ops;
80
81 if (!psoc) {
82 coap_err("psoc is null");
83 return QDF_STATUS_E_NULL_VALUE;
84 }
85
86 coap_tx_ops = wlan_psoc_get_coap_txops(psoc);
87 if (!coap_tx_ops) {
88 coap_err("tx_ops is null!");
89 return QDF_STATUS_E_NULL_VALUE;
90 }
91
92 if (!coap_tx_ops->detach) {
93 coap_err("coap_detach function is null!");
94 return QDF_STATUS_E_NULL_VALUE;
95 }
96
97 return coap_tx_ops->detach(psoc);
98 }
99
100 QDF_STATUS
tgt_send_coap_offload_reply_enable(struct wlan_objmgr_vdev * vdev,struct coap_offload_reply_param * param)101 tgt_send_coap_offload_reply_enable(struct wlan_objmgr_vdev *vdev,
102 struct coap_offload_reply_param *param)
103 {
104 struct wlan_lmac_if_coap_tx_ops *coap_ops;
105
106 if (!vdev) {
107 coap_err("NULL vdev");
108 return QDF_STATUS_E_NULL_VALUE;
109 }
110
111 coap_ops = wlan_vdev_get_coap_txops(vdev);
112 if (coap_ops && coap_ops->offload_reply_enable)
113 return coap_ops->offload_reply_enable(vdev, param);
114
115 return QDF_STATUS_SUCCESS;
116 }
117
118 QDF_STATUS
tgt_send_coap_offload_reply_disable(struct wlan_objmgr_vdev * vdev,uint32_t req_id)119 tgt_send_coap_offload_reply_disable(struct wlan_objmgr_vdev *vdev,
120 uint32_t req_id)
121 {
122 struct wlan_lmac_if_coap_tx_ops *coap_ops;
123
124 if (!vdev) {
125 coap_err("NULL vdev");
126 return QDF_STATUS_E_NULL_VALUE;
127 }
128
129 coap_ops = wlan_vdev_get_coap_txops(vdev);
130 if (coap_ops && coap_ops->offload_reply_disable)
131 return coap_ops->offload_reply_disable(vdev, req_id);
132
133 return QDF_STATUS_SUCCESS;
134 }
135
136 QDF_STATUS
tgt_send_coap_offload_periodic_tx_enable(struct wlan_objmgr_vdev * vdev,struct coap_offload_periodic_tx_param * param)137 tgt_send_coap_offload_periodic_tx_enable(struct wlan_objmgr_vdev *vdev,
138 struct coap_offload_periodic_tx_param *param)
139 {
140 struct wlan_lmac_if_coap_tx_ops *coap_ops;
141
142 if (!vdev) {
143 coap_err("NULL vdev");
144 return QDF_STATUS_E_NULL_VALUE;
145 }
146
147 coap_ops = wlan_vdev_get_coap_txops(vdev);
148 if (coap_ops && coap_ops->offload_periodic_tx_enable)
149 return coap_ops->offload_periodic_tx_enable(vdev, param);
150
151 return QDF_STATUS_SUCCESS;
152 }
153
154 QDF_STATUS
tgt_send_coap_offload_periodic_tx_disable(struct wlan_objmgr_vdev * vdev,uint32_t req_id)155 tgt_send_coap_offload_periodic_tx_disable(struct wlan_objmgr_vdev *vdev,
156 uint32_t req_id)
157 {
158 struct wlan_lmac_if_coap_tx_ops *coap_ops;
159
160 if (!vdev) {
161 coap_err("NULL vdev");
162 return QDF_STATUS_E_NULL_VALUE;
163 }
164
165 coap_ops = wlan_vdev_get_coap_txops(vdev);
166 if (coap_ops && coap_ops->offload_periodic_tx_disable)
167 return coap_ops->offload_periodic_tx_disable(vdev, req_id);
168
169 return QDF_STATUS_SUCCESS;
170 }
171
172 QDF_STATUS
tgt_send_coap_offload_cache_get(struct wlan_objmgr_vdev * vdev,uint32_t req_id)173 tgt_send_coap_offload_cache_get(struct wlan_objmgr_vdev *vdev, uint32_t req_id)
174 {
175 struct wlan_lmac_if_coap_tx_ops *coap_ops;
176
177 if (!vdev) {
178 coap_err("NULL vdev");
179 return QDF_STATUS_E_NULL_VALUE;
180 }
181
182 coap_ops = wlan_vdev_get_coap_txops(vdev);
183 if (coap_ops && coap_ops->offload_cache_get)
184 return coap_ops->offload_cache_get(vdev, req_id);
185
186 return QDF_STATUS_SUCCESS;
187 }
188