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 #include "nx_secure_dtls.h"
25 
26 /**************************************************************************/
27 /*                                                                        */
28 /*  FUNCTION                                               RELEASE        */
29 /*                                                                        */
30 /*    _nxe_secure_dtls_packet_allocate                    PORTABLE C      */
31 /*                                                           6.1          */
32 /*  AUTHOR                                                                */
33 /*                                                                        */
34 /*    Timothy Stapko, Microsoft Corporation                               */
35 /*                                                                        */
36 /*  DESCRIPTION                                                           */
37 /*                                                                        */
38 /*    This function checks for errors in DTLS packet allocate call.       */
39 /*                                                                        */
40 /*  INPUT                                                                 */
41 /*                                                                        */
42 /*    dtls_session                          DTLS control block            */
43 /*    pool_ptr                              Pool to allocate packet from  */
44 /*    packet_ptr                            Pointer to place allocated    */
45 /*                                            packet pointer              */
46 /*    wait_option                           Suspension option             */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    status                                Completion status             */
51 /*                                                                        */
52 /*  CALLS                                                                 */
53 /*                                                                        */
54 /*    _nx_secure_dtls_packet_allocate       Actual packet allocate call.  */
55 /*                                                                        */
56 /*  CALLED BY                                                             */
57 /*                                                                        */
58 /*    Application                                                         */
59 /*                                                                        */
60 /*  RELEASE HISTORY                                                       */
61 /*                                                                        */
62 /*    DATE              NAME                      DESCRIPTION             */
63 /*                                                                        */
64 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
65 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
66 /*                                            resulting in version 6.1    */
67 /*                                                                        */
68 /**************************************************************************/
_nxe_secure_dtls_packet_allocate(NX_SECURE_DTLS_SESSION * dtls_session,NX_PACKET_POOL * pool_ptr,NX_PACKET ** packet_ptr,ULONG wait_option)69 UINT _nxe_secure_dtls_packet_allocate(NX_SECURE_DTLS_SESSION *dtls_session, NX_PACKET_POOL *pool_ptr,
70                                       NX_PACKET **packet_ptr, ULONG wait_option)
71 {
72 #ifdef NX_SECURE_ENABLE_DTLS
73 UINT status;
74 
75     if ((dtls_session == NX_NULL) || (pool_ptr == NX_NULL) || (packet_ptr == NX_NULL))
76     {
77         return(NX_PTR_ERROR);
78     }
79 
80     /* Make sure the session is initialized. */
81     if(dtls_session->nx_secure_dtls_tls_session.nx_secure_tls_id != NX_SECURE_TLS_ID)
82     {
83         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
84     }
85 
86     status =  _nx_secure_dtls_packet_allocate(dtls_session, pool_ptr, packet_ptr, wait_option);
87 
88     return(status);
89 #else
90     NX_PARAMETER_NOT_USED(dtls_session);
91     NX_PARAMETER_NOT_USED(pool_ptr);
92     NX_PARAMETER_NOT_USED(packet_ptr);
93     NX_PARAMETER_NOT_USED(wait_option);
94 
95     return(NX_NOT_SUPPORTED);
96 #endif /* NX_SECURE_ENABLE_DTLS */
97 }
98 
99