1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Secure Component                                                 */
16 /**                                                                       */
17 /**    Datagram Transport Layer Security (DTLS)                           */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SECURE_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "nx_secure_dtls.h"
28 
29 /* Bring in externs for caller checking code.  */
30 
31 NX_SECURE_CALLER_CHECKING_EXTERNS
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _nxe_secure_dtls_session_delete                     PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Timothy Stapko, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the DTLS session delete call.    */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    dtls_session                          DTLS session control block    */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    status                                Completion status             */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    _nx_secure_dtls_session_delete        Actual DTLS session delete    */
58 /*                                            call                        */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    Application Code                                                    */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
69 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_nxe_secure_dtls_session_delete(NX_SECURE_DTLS_SESSION * dtls_session)73 UINT _nxe_secure_dtls_session_delete(NX_SECURE_DTLS_SESSION *dtls_session)
74 {
75 #ifdef NX_SECURE_ENABLE_DTLS
76 UINT status;
77 NX_SECURE_DTLS_SESSION *session_ptr;
78 
79     if (dtls_session == NX_NULL)
80     {
81         return(NX_PTR_ERROR);
82     }
83 
84     session_ptr = _nx_secure_dtls_created_ptr;
85     for (;;)
86     {
87         if (session_ptr == NX_NULL)
88         {
89 
90             /* No session created. */
91             return(NX_PTR_ERROR);
92         }
93 
94         if (session_ptr == dtls_session)
95         {
96 
97             /* Found the session to delete. */
98             break;
99         }
100 
101         session_ptr = session_ptr -> nx_secure_dtls_created_next;
102 
103         if (session_ptr == _nx_secure_dtls_created_ptr)
104         {
105 
106             /* This session is not created. */
107             return(NX_PTR_ERROR);
108         }
109     }
110 
111     status =  _nx_secure_dtls_session_delete(dtls_session);
112 
113     /* Return completion status.  */
114     return(status);
115 #else
116     NX_PARAMETER_NOT_USED(dtls_session);
117 
118     return(NX_NOT_SUPPORTED);
119 #endif /* NX_SECURE_ENABLE_DTLS */
120 }
121 
122