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 definitions for CoAP core functions
19 */
20
21 #include <wlan_coap_tgt_api.h>
22 #include <wlan_coap_main.h>
23 #include <wlan_objmgr_global_obj.h>
24
wlan_coap_enable(struct wlan_objmgr_psoc * psoc)25 QDF_STATUS wlan_coap_enable(struct wlan_objmgr_psoc *psoc)
26 {
27 return tgt_coap_attach(psoc);
28 }
29
wlan_coap_disable(struct wlan_objmgr_psoc * psoc)30 QDF_STATUS wlan_coap_disable(struct wlan_objmgr_psoc *psoc)
31 {
32 return tgt_coap_detach(psoc);
33 }
34
35 static QDF_STATUS
wlan_coap_vdev_obj_create_handler(struct wlan_objmgr_vdev * vdev,void * arg)36 wlan_coap_vdev_obj_create_handler(struct wlan_objmgr_vdev *vdev, void *arg)
37 {
38 struct wlan_coap_comp_priv *coap_priv;
39 QDF_STATUS status;
40
41 if (!vdev)
42 return QDF_STATUS_E_INVAL;
43
44 coap_priv = qdf_mem_malloc(sizeof(struct wlan_coap_comp_priv));
45 if (!coap_priv)
46 return QDF_STATUS_E_NOMEM;
47
48 status = wlan_objmgr_vdev_component_obj_attach(vdev,
49 WLAN_UMAC_COMP_COAP,
50 (void *)coap_priv,
51 QDF_STATUS_SUCCESS);
52 if (QDF_IS_STATUS_ERROR(status))
53 qdf_mem_free(coap_priv);
54
55 return status;
56 }
57
58 static QDF_STATUS
wlan_coap_vdev_obj_destroy_handler(struct wlan_objmgr_vdev * vdev,void * arg)59 wlan_coap_vdev_obj_destroy_handler(struct wlan_objmgr_vdev *vdev, void *arg)
60 {
61 void *coap_priv;
62
63 if (!vdev) {
64 coap_err("Vdev NULL");
65 return QDF_STATUS_E_INVAL;
66 }
67
68 coap_priv = wlan_get_vdev_coap_obj(vdev);
69 if (!coap_priv) {
70 coap_err("coap_priv NULL");
71 return QDF_STATUS_E_INVAL;
72 }
73
74 wlan_objmgr_vdev_component_obj_detach(vdev, WLAN_UMAC_COMP_COAP,
75 coap_priv);
76 qdf_mem_free(coap_priv);
77 return QDF_STATUS_SUCCESS;
78 }
79
wlan_coap_init(void)80 QDF_STATUS wlan_coap_init(void)
81 {
82 QDF_STATUS status = QDF_STATUS_SUCCESS;
83
84 status = wlan_objmgr_register_vdev_create_handler(WLAN_UMAC_COMP_COAP,
85 wlan_coap_vdev_obj_create_handler, NULL);
86 if (status != QDF_STATUS_SUCCESS)
87 return status;
88
89 status = wlan_objmgr_register_vdev_destroy_handler(WLAN_UMAC_COMP_COAP,
90 wlan_coap_vdev_obj_destroy_handler, NULL);
91 if (QDF_IS_STATUS_SUCCESS(status))
92 return status;
93
94 wlan_objmgr_unregister_vdev_create_handler(WLAN_UMAC_COMP_COAP,
95 wlan_coap_vdev_obj_create_handler, NULL);
96 return status;
97 }
98
wlan_coap_deinit(void)99 QDF_STATUS wlan_coap_deinit(void)
100 {
101 wlan_objmgr_unregister_vdev_create_handler(WLAN_UMAC_COMP_COAP,
102 wlan_coap_vdev_obj_create_handler, NULL);
103 wlan_objmgr_unregister_vdev_destroy_handler(WLAN_UMAC_COMP_COAP,
104 wlan_coap_vdev_obj_destroy_handler, NULL);
105 return QDF_STATUS_SUCCESS;
106 }
107
108 QDF_STATUS
wlan_coap_offload_reply_enable(struct wlan_objmgr_vdev * vdev,struct coap_offload_reply_param * params)109 wlan_coap_offload_reply_enable(struct wlan_objmgr_vdev *vdev,
110 struct coap_offload_reply_param *params)
111 {
112 return tgt_send_coap_offload_reply_enable(vdev, params);
113 }
114
115 QDF_STATUS
wlan_coap_offload_reply_disable(struct wlan_objmgr_vdev * vdev,uint32_t req_id,coap_cache_get_callback cbk,void * context)116 wlan_coap_offload_reply_disable(struct wlan_objmgr_vdev *vdev, uint32_t req_id,
117 coap_cache_get_callback cbk, void *context)
118 {
119 struct wlan_coap_comp_priv *coap_priv;
120
121 if (!vdev) {
122 coap_err("Vdev NULL");
123 return QDF_STATUS_E_INVAL;
124 }
125
126 coap_priv = wlan_get_vdev_coap_obj(vdev);
127 coap_priv->req_id = req_id;
128 coap_priv->cache_get_context = context;
129 coap_priv->cache_get_cbk = cbk;
130 return tgt_send_coap_offload_reply_disable(vdev, req_id);
131 }
132
133 QDF_STATUS
wlan_coap_offload_periodic_tx_enable(struct wlan_objmgr_vdev * vdev,struct coap_offload_periodic_tx_param * params)134 wlan_coap_offload_periodic_tx_enable(struct wlan_objmgr_vdev *vdev,
135 struct coap_offload_periodic_tx_param *params)
136 {
137 return tgt_send_coap_offload_periodic_tx_enable(vdev, params);
138 }
139
140 QDF_STATUS
wlan_coap_offload_periodic_tx_disable(struct wlan_objmgr_vdev * vdev,uint32_t req_id)141 wlan_coap_offload_periodic_tx_disable(struct wlan_objmgr_vdev *vdev,
142 uint32_t req_id)
143 {
144 return tgt_send_coap_offload_periodic_tx_disable(vdev, req_id);
145 }
146
147 QDF_STATUS
wlan_coap_offload_cache_get(struct wlan_objmgr_vdev * vdev,uint32_t req_id,coap_cache_get_callback cbk,void * context)148 wlan_coap_offload_cache_get(struct wlan_objmgr_vdev *vdev, uint32_t req_id,
149 coap_cache_get_callback cbk, void *context)
150 {
151 struct wlan_coap_comp_priv *coap_priv;
152
153 if (!vdev) {
154 coap_err("Vdev NULL");
155 return QDF_STATUS_E_INVAL;
156 }
157
158 coap_priv = wlan_get_vdev_coap_obj(vdev);
159 coap_priv->req_id = req_id;
160 coap_priv->cache_get_context = context;
161 coap_priv->cache_get_cbk = cbk;
162 return tgt_send_coap_offload_cache_get(vdev, req_id);
163 }
164