blob: c26b730587c035d51d092773098ebcc9b900a15a [file] [log] [blame]
Tushar Mathurff8741b2015-12-02 20:28:59 +05301/*
2 **************************************************************************
Stephen Wangaed46332016-12-12 17:29:03 -08003 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Tushar Mathurff8741b2015-12-02 20:28:59 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17#include "nss_tx_rx_common.h"
18#include "nss_dtls_stats.h"
19
20#define NSS_DTLS_TX_TIMEOUT 3000 /* 3 Seconds */
21
22/*
23 * Data structures to store DTLS nss debug stats
24 */
25static DEFINE_SPINLOCK(nss_dtls_session_debug_stats_lock);
26static struct nss_stats_dtls_session_debug nss_dtls_session_debug_stats[NSS_MAX_DTLS_SESSIONS];
27
28/*
29 * Private data structure
30 */
31static struct nss_dtls_pvt {
32 struct semaphore sem;
33 struct completion complete;
34 int response;
35 void *cb;
36 void *app_data;
37} dtls_pvt;
38
Tushar Mathurff8741b2015-12-02 20:28:59 +053039/*
40 * nss_dtls_verify_if_num()
41 * Verify if_num passed to us.
42 */
43static bool nss_dtls_verify_if_num(uint32_t if_num)
44{
45 if (nss_is_dynamic_interface(if_num) == false)
46 return false;
47
Stephen Wange8b8d0d2017-02-24 17:05:22 -080048 if (nss_dynamic_interface_get_type(nss_dtls_get_context(), if_num)
Tushar Mathurff8741b2015-12-02 20:28:59 +053049 != NSS_DYNAMIC_INTERFACE_TYPE_DTLS)
50 return false;
51
52 return true;
53}
54
55/*
56 * nss_dtls_session_stats_sync
57 * Per DTLS session debug stats
58 */
59static void nss_dtls_session_stats_sync(struct nss_ctx_instance *nss_ctx,
60 struct nss_dtls_session_stats *stats_msg,
61 uint16_t if_num)
62{
63 int i;
64 struct nss_stats_dtls_session_debug *s = NULL;
65
66 NSS_VERIFY_CTX_MAGIC(nss_ctx);
67
68 spin_lock_bh(&nss_dtls_session_debug_stats_lock);
69 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
70 if (nss_dtls_session_debug_stats[i].if_num != if_num) {
71 continue;
72 }
73
74 s = &nss_dtls_session_debug_stats[i];
75 break;
76 }
77
78 if (!s) {
79 spin_unlock_bh(&nss_dtls_session_debug_stats_lock);
80 return;
81 }
82
83 s->stats[NSS_STATS_DTLS_SESSION_RX_PKTS] += stats_msg->node_stats.rx_packets;
84 s->stats[NSS_STATS_DTLS_SESSION_TX_PKTS] += stats_msg->node_stats.tx_packets;
85 s->stats[NSS_STATS_DTLS_SESSION_RX_DROPPED] += stats_msg->node_stats.rx_dropped;
86 s->stats[NSS_STATS_DTLS_SESSION_RX_AUTH_DONE] += stats_msg->rx_auth_done;
87 s->stats[NSS_STATS_DTLS_SESSION_TX_AUTH_DONE] += stats_msg->tx_auth_done;
88 s->stats[NSS_STATS_DTLS_SESSION_RX_CIPHER_DONE] += stats_msg->rx_cipher_done;
89 s->stats[NSS_STATS_DTLS_SESSION_TX_CIPHER_DONE] += stats_msg->tx_cipher_done;
90 s->stats[NSS_STATS_DTLS_SESSION_RX_CBUF_ALLOC_FAIL] += stats_msg->rx_cbuf_alloc_fail;
91 s->stats[NSS_STATS_DTLS_SESSION_TX_CBUF_ALLOC_FAIL] += stats_msg->tx_cbuf_alloc_fail;
92 s->stats[NSS_STATS_DTLS_SESSION_TX_CENQUEUE_FAIL] += stats_msg->tx_cenqueue_fail;
93 s->stats[NSS_STATS_DTLS_SESSION_RX_CENQUEUE_FAIL] += stats_msg->rx_cenqueue_fail;
94 s->stats[NSS_STATS_DTLS_SESSION_TX_DROPPED_HROOM] += stats_msg->tx_dropped_hroom;
95 s->stats[NSS_STATS_DTLS_SESSION_TX_DROPPED_TROOM] += stats_msg->tx_dropped_troom;
96 s->stats[NSS_STATS_DTLS_SESSION_TX_FORWARD_ENQUEUE_FAIL] += stats_msg->tx_forward_enqueue_fail;
97 s->stats[NSS_STATS_DTLS_SESSION_RX_FORWARD_ENQUEUE_FAIL] += stats_msg->rx_forward_enqueue_fail;
98 s->stats[NSS_STATS_DTLS_SESSION_RX_INVALID_VERSION] += stats_msg->rx_invalid_version;
99 s->stats[NSS_STATS_DTLS_SESSION_RX_INVALID_EPOCH] += stats_msg->rx_invalid_epoch;
100 s->stats[NSS_STATS_DTLS_SESSION_RX_MALFORMED] += stats_msg->rx_malformed;
101 s->stats[NSS_STATS_DTLS_SESSION_RX_CIPHER_FAIL] += stats_msg->rx_cipher_fail;
102 s->stats[NSS_STATS_DTLS_SESSION_RX_AUTH_FAIL] += stats_msg->rx_auth_fail;
103 s->stats[NSS_STATS_DTLS_SESSION_RX_CAPWAP_CLASSIFY_FAIL] += stats_msg->rx_capwap_classify_fail;
104 s->stats[NSS_STATS_DTLS_SESSION_RX_SINGLE_REC_DGRAM] += stats_msg->rx_single_rec_dgram;
105 s->stats[NSS_STATS_DTLS_SESSION_RX_MULTI_REC_DGRAM] += stats_msg->rx_multi_rec_dgram;
106 s->stats[NSS_STATS_DTLS_SESSION_RX_REPLAY_FAIL] += stats_msg->rx_replay_fail;
107 s->stats[NSS_STATS_DTLS_SESSION_RX_REPLAY_DUPLICATE] += stats_msg->rx_replay_duplicate;
108 s->stats[NSS_STATS_DTLS_SESSION_RX_REPLAY_OUT_OF_WINDOW] += stats_msg->rx_replay_out_of_window;
109 s->stats[NSS_STATS_DTLS_SESSION_OUTFLOW_QUEUE_FULL] += stats_msg->outflow_queue_full;
110 s->stats[NSS_STATS_DTLS_SESSION_DECAP_QUEUE_FULL] += stats_msg->decap_queue_full;
111 s->stats[NSS_STATS_DTLS_SESSION_PBUF_ALLOC_FAIL] += stats_msg->pbuf_alloc_fail;
112 s->stats[NSS_STATS_DTLS_SESSION_PBUF_COPY_FAIL] += stats_msg->pbuf_copy_fail;
113 s->stats[NSS_STATS_DTLS_SESSION_EPOCH] = stats_msg->epoch;
114 s->stats[NSS_STATS_DTLS_SESSION_TX_SEQ_HIGH] = stats_msg->tx_seq_high;
115 s->stats[NSS_STATS_DTLS_SESSION_TX_SEQ_LOW] = stats_msg->tx_seq_low;
116 spin_unlock_bh(&nss_dtls_session_debug_stats_lock);
117}
118
119/*
120 * nss_dtls_session_debug_stats_get()
121 * Get session DTLS statitics.
122 */
123void nss_dtls_session_debug_stats_get(struct nss_stats_dtls_session_debug *stats)
124{
125 int i;
126
127 if (!stats) {
128 nss_warning("No memory to copy dtls session stats");
129 return;
130 }
131
132 spin_lock_bh(&nss_dtls_session_debug_stats_lock);
133 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
134 if (nss_dtls_session_debug_stats[i].valid) {
135 memcpy(stats, &nss_dtls_session_debug_stats[i],
136 sizeof(struct nss_stats_dtls_session_debug));
137 stats++;
138 }
139 }
140 spin_unlock_bh(&nss_dtls_session_debug_stats_lock);
141}
142
143/*
144 * nss_dtls_handler()
145 * Handle NSS -> HLOS messages for dtls tunnel
146 */
147static void nss_dtls_handler(struct nss_ctx_instance *nss_ctx,
148 struct nss_cmn_msg *ncm,
149 __attribute__((unused))void *app_data)
150{
151 struct nss_dtls_msg *ntm = (struct nss_dtls_msg *)ncm;
152 void *ctx;
153
154 nss_dtls_msg_callback_t cb;
155
156 NSS_VERIFY_CTX_MAGIC(nss_ctx);
157 BUG_ON(!nss_dtls_verify_if_num(ncm->interface));
158
159 /*
160 * Is this a valid request/response packet?
161 */
162 if (ncm->type >= NSS_DTLS_MSG_MAX) {
163 nss_warning("%p: received invalid message %d "
164 "for DTLS interface %d",
165 nss_ctx, ncm->type, ncm->interface);
166 return;
167 }
168
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800169 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_dtls_msg)) {
Tushar Mathurff8741b2015-12-02 20:28:59 +0530170 nss_warning("%p: dtls message length is invalid: %d",
171 nss_ctx, ncm->len);
172 return;
173 }
174
175 switch (ntm->cm.type) {
176 case NSS_DTLS_MSG_SESSION_STATS:
177 nss_dtls_session_stats_sync(nss_ctx,
178 &ntm->msg.stats,
179 ncm->interface);
180 break;
181 }
182
183 /*
184 * Update the callback and app_data for NOTIFY messages
185 */
186 if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800187 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->dtls_msg_callback;
Stephen Wang84e0e992016-09-07 12:31:40 -0700188 ncm->app_data = (nss_ptr_t)nss_ctx->subsys_dp_register[ncm->interface].app_data;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530189 }
190
191 /*
192 * Log failures
193 */
194 nss_core_log_msg_failures(nss_ctx, ncm);
195
196 /*
197 * callback
198 */
199 cb = (nss_dtls_msg_callback_t)ncm->cb;
200 ctx = (void *)ncm->app_data;
201
202 /*
203 * call dtls session callback
204 */
205 if (!cb) {
206 nss_warning("%p: No callback for dtls session interface %d",
207 nss_ctx, ncm->interface);
208 return;
209 }
210
211 cb(ctx, ntm);
212}
213
214/*
215 * nss_dtls_callback()
216 * Callback to handle the completion of NSS->HLOS messages.
217 */
218static void nss_dtls_callback(void *app_data, struct nss_dtls_msg *nim)
219{
220 nss_dtls_msg_callback_t callback = (nss_dtls_msg_callback_t)dtls_pvt.cb;
221 void *data = dtls_pvt.app_data;
222
223 dtls_pvt.cb = NULL;
224 dtls_pvt.app_data = NULL;
225
226 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
227 nss_warning("dtls Error response %d\n", nim->cm.response);
228
229 dtls_pvt.response = NSS_TX_FAILURE;
230 if (callback) {
231 callback(data, nim);
232 }
233
234 complete(&dtls_pvt.complete);
235 return;
236 }
237
238 dtls_pvt.response = NSS_TX_SUCCESS;
239 if (callback) {
240 callback(data, nim);
241 }
242
243 complete(&dtls_pvt.complete);
244}
245
246/*
247 * nss_dtls_tx_buf()
248 * Transmit buffer over DTLS interface
249 */
250nss_tx_status_t nss_dtls_tx_buf(struct sk_buff *skb, uint32_t if_num,
251 struct nss_ctx_instance *nss_ctx)
252{
253 int32_t status;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530254
255 NSS_VERIFY_CTX_MAGIC(nss_ctx);
256
257 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
258 nss_warning("%p: 'DTLS If Tx' core not ready", nss_ctx);
259 return NSS_TX_FAILURE_NOT_READY;
260 }
261
262 BUG_ON(!nss_dtls_verify_if_num(if_num));
263
Tushar Mathurff8741b2015-12-02 20:28:59 +0530264 status = nss_core_send_buffer(nss_ctx, if_num, skb,
265 NSS_IF_DATA_QUEUE_0,
266 H2N_BUFFER_PACKET,
267 H2N_BIT_FLAG_VIRTUAL_BUFFER);
268 if (unlikely(status != NSS_CORE_STATUS_SUCCESS)) {
269 nss_warning("%p: Unable to enqueue 'DTLS If Tx' packet\n", nss_ctx);
270 if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
271 return NSS_TX_FAILURE_QUEUE;
272 }
273
274 return NSS_TX_FAILURE;
275 }
276
Stephen Wang90c67de2016-04-26 15:15:59 -0700277 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530278
279 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_PACKET]);
280 return NSS_TX_SUCCESS;
281}
282EXPORT_SYMBOL(nss_dtls_tx_buf);
283
284/*
285 * nss_dtls_tx_msg()
286 * Transmit a DTLS message to NSS firmware
287 */
288nss_tx_status_t nss_dtls_tx_msg(struct nss_ctx_instance *nss_ctx,
289 struct nss_dtls_msg *msg)
290{
291 struct nss_dtls_msg *nm;
292 struct nss_cmn_msg *ncm = &msg->cm;
293 struct sk_buff *nbuf;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530294 int32_t status;
295
296 NSS_VERIFY_CTX_MAGIC(nss_ctx);
297 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
298 nss_warning("%p: dtls msg dropped as core not ready", nss_ctx);
299 return NSS_TX_FAILURE_NOT_READY;
300 }
301
302 /*
303 * Sanity check the message
304 */
305 BUG_ON(!nss_dtls_verify_if_num(ncm->interface));
306
Tushar Mathurff8741b2015-12-02 20:28:59 +0530307 if (ncm->type > NSS_DTLS_MSG_MAX) {
308 nss_warning("%p: dtls message type out of range: %d",
309 nss_ctx, ncm->type);
310 return NSS_TX_FAILURE;
311 }
312
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800313 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_dtls_msg)) {
Tushar Mathurff8741b2015-12-02 20:28:59 +0530314 nss_warning("%p: dtls message length is invalid: %d",
315 nss_ctx, ncm->len);
316 return NSS_TX_FAILURE;
317 }
318
319 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
320 if (unlikely(!nbuf)) {
321 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
322 nss_warning("%p: dtls msg dropped as command "
323 "allocation failed", nss_ctx);
324 return NSS_TX_FAILURE;
325 }
326
327 /*
328 * Copy the message to our skb
329 */
330 nm = (struct nss_dtls_msg *)skb_put(nbuf, sizeof(struct nss_dtls_msg));
331 memcpy(nm, msg, sizeof(struct nss_dtls_msg));
332
333 status = nss_core_send_buffer(nss_ctx, 0, nbuf,
334 NSS_IF_CMD_QUEUE,
335 H2N_BUFFER_CTRL, 0);
336 if (status != NSS_CORE_STATUS_SUCCESS) {
337 dev_kfree_skb_any(nbuf);
338 nss_warning("%p: Unable to enqueue 'dtls message'\n", nss_ctx);
339 if (status == NSS_CORE_STATUS_FAILURE_QUEUE) {
340 return NSS_TX_FAILURE_QUEUE;
341 }
342 return NSS_TX_FAILURE;
343 }
344
Stephen Wang90c67de2016-04-26 15:15:59 -0700345 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530346
347 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
348 return NSS_TX_SUCCESS;
349}
350EXPORT_SYMBOL(nss_dtls_tx_msg);
351
352/*
353 * nss_dtls_tx_msg()
354 * Transmit a DTLS message to NSS firmware synchronously.
355 */
356nss_tx_status_t nss_dtls_tx_msg_sync(struct nss_ctx_instance *nss_ctx, struct nss_dtls_msg *msg)
357{
358
359 nss_tx_status_t status;
360 int ret = 0;
361
362 down(&dtls_pvt.sem);
363 dtls_pvt.cb = (void *)msg->cm.cb;
364 dtls_pvt.app_data = (void *)msg->cm.app_data;
365
Stephen Wangaed46332016-12-12 17:29:03 -0800366 msg->cm.cb = (nss_ptr_t)nss_dtls_callback;
367 msg->cm.app_data = (nss_ptr_t)NULL;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530368
369 status = nss_dtls_tx_msg(nss_ctx, msg);
370 if (status != NSS_TX_SUCCESS) {
371 nss_warning("%p: dtls_tx_msg failed\n", nss_ctx);
372 up(&dtls_pvt.sem);
373 return status;
374 }
375
376 ret = wait_for_completion_timeout(&dtls_pvt.complete, msecs_to_jiffies(NSS_DTLS_TX_TIMEOUT));
377
378 if (!ret) {
379 nss_warning("%p: DTLS msg tx failed due to timeout\n", nss_ctx);
380 dtls_pvt.response = NSS_TX_FAILURE;
381 }
382
383 status = dtls_pvt.response;
384 up(&dtls_pvt.sem);
385 return status;
386}
387EXPORT_SYMBOL(nss_dtls_tx_msg_sync);
388
389/*
390 ***********************************
391 * Register/Unregister/Miscellaneous APIs
392 ***********************************
393 */
394
395/*
396 * nss_dtls_register_if()
397 */
398struct nss_ctx_instance *nss_dtls_register_if(uint32_t if_num,
399 nss_dtls_data_callback_t cb,
400 nss_dtls_msg_callback_t ev_cb,
401 struct net_device *netdev,
402 uint32_t features,
403 void *app_ctx)
404{
405 int32_t i;
406
407 struct nss_ctx_instance *nss_ctx = nss_dtls_get_context();
408
409 BUG_ON(!nss_dtls_verify_if_num(if_num));
410
411 spin_lock_bh(&nss_dtls_session_debug_stats_lock);
412 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
413 if (!nss_dtls_session_debug_stats[i].valid) {
414 nss_dtls_session_debug_stats[i].valid = true;
415 nss_dtls_session_debug_stats[i].if_num = if_num;
416 nss_dtls_session_debug_stats[i].if_index = netdev->ifindex;
417 break;
418 }
419 }
420 spin_unlock_bh(&nss_dtls_session_debug_stats_lock);
421
422 if (i == NSS_MAX_DTLS_SESSIONS) {
423 nss_warning("%p: Cannot find free slot for "
424 "DTLS session stats, I/F:%u\n", nss_ctx, if_num);
425 return NULL;
426 }
427
Stephen Wang84e0e992016-09-07 12:31:40 -0700428 if (nss_ctx->subsys_dp_register[if_num].ndev) {
Tushar Mathurff8741b2015-12-02 20:28:59 +0530429 nss_warning("%p: Cannot find free slot for "
430 "DTLS NSS I/F:%u\n", nss_ctx, if_num);
431
432 return NULL;
433 }
434
Stephen Wang84e0e992016-09-07 12:31:40 -0700435 nss_ctx->subsys_dp_register[if_num].ndev = netdev;
436 nss_ctx->subsys_dp_register[if_num].cb = cb;
437 nss_ctx->subsys_dp_register[if_num].app_data = app_ctx;
438 nss_ctx->subsys_dp_register[if_num].features = features;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530439
440 nss_top_main.dtls_msg_callback = ev_cb;
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700441 nss_core_register_handler(nss_ctx, if_num, nss_dtls_handler, app_ctx);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530442
Stephen Wang90c67de2016-04-26 15:15:59 -0700443 return nss_ctx;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530444}
445EXPORT_SYMBOL(nss_dtls_register_if);
446
447/*
448 * nss_dtls_unregister_if()
449 */
450void nss_dtls_unregister_if(uint32_t if_num)
451{
Stephen Wang84e0e992016-09-07 12:31:40 -0700452 struct nss_ctx_instance *nss_ctx = nss_dtls_get_context();
Tushar Mathurff8741b2015-12-02 20:28:59 +0530453 int32_t i;
454
Tushar Mathurff8741b2015-12-02 20:28:59 +0530455 BUG_ON(!nss_dtls_verify_if_num(if_num));
456
457 spin_lock_bh(&nss_dtls_session_debug_stats_lock);
458 for (i = 0; i < NSS_MAX_DTLS_SESSIONS; i++) {
459 if (nss_dtls_session_debug_stats[i].if_num == if_num) {
460 memset(&nss_dtls_session_debug_stats[i], 0,
461 sizeof(struct nss_stats_dtls_session_debug));
462 break;
463 }
464 }
465 spin_unlock_bh(&nss_dtls_session_debug_stats_lock);
466
467 if (i == NSS_MAX_DTLS_SESSIONS) {
Stephen Wang84e0e992016-09-07 12:31:40 -0700468 nss_warning("%p: Cannot find debug stats for DTLS session %d\n", nss_ctx, if_num);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530469 return;
470 }
471
Stephen Wang84e0e992016-09-07 12:31:40 -0700472 if (!nss_ctx->subsys_dp_register[if_num].ndev) {
473 nss_warning("%p: Cannot find registered netdev for DTLS NSS I/F:%u\n", nss_ctx, if_num);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530474
475 return;
476 }
477
Stephen Wang84e0e992016-09-07 12:31:40 -0700478 nss_ctx->subsys_dp_register[if_num].ndev = NULL;
479 nss_ctx->subsys_dp_register[if_num].cb = NULL;
480 nss_ctx->subsys_dp_register[if_num].app_data = NULL;
481 nss_ctx->subsys_dp_register[if_num].features = 0;
Tushar Mathurff8741b2015-12-02 20:28:59 +0530482
483 nss_top_main.dtls_msg_callback = NULL;
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700484 nss_core_unregister_handler(nss_ctx, if_num);
Tushar Mathurff8741b2015-12-02 20:28:59 +0530485}
486EXPORT_SYMBOL(nss_dtls_unregister_if);
487
488/*
489 * nss_get_dtls_context()
490 */
491struct nss_ctx_instance *nss_dtls_get_context(void)
492{
493 return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.dtls_handler_id];
494}
495EXPORT_SYMBOL(nss_dtls_get_context);
496
497/*
498 * nss_dtls_msg_init()
499 * Initialize nss_dtls msg.
500 */
501void nss_dtls_msg_init(struct nss_dtls_msg *ncm, uint16_t if_num,
502 uint32_t type, uint32_t len, void *cb, void *app_data)
503{
504 nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data);
505}
506EXPORT_SYMBOL(nss_dtls_msg_init);
507
508/*
509 * nss_dtls_get_ifnum_with_coreid()
510 */
511int32_t nss_dtls_get_ifnum_with_coreid(int32_t if_num)
512{
513 struct nss_ctx_instance *nss_ctx = nss_dtls_get_context();
514
515 NSS_VERIFY_CTX_MAGIC(nss_ctx);
516 return NSS_INTERFACE_NUM_APPEND_COREID(nss_ctx, if_num);
517}
518EXPORT_SYMBOL(nss_dtls_get_ifnum_with_coreid);
519
520/*
521 * nss_dtls_register_handler()
522 */
523void nss_dtls_register_handler(void)
524{
525 sema_init(&dtls_pvt.sem, 1);
526 init_completion(&dtls_pvt.complete);
527}