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_send                       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 send call.      */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    dtls_session                          DTLS control block            */
50 /*    packet_ptr                            Pointer to packet data        */
51 /*    ip_address                            Remote IP address             */
52 /*    port                                  Remote port                   */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _nx_secure_dtls_session_send          Actual DTLS session send call.*/
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
71 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_nxe_secure_dtls_session_send(NX_SECURE_DTLS_SESSION * dtls_session,NX_PACKET * packet_ptr,NXD_ADDRESS * ip_address,UINT port)75 UINT _nxe_secure_dtls_session_send(NX_SECURE_DTLS_SESSION *dtls_session, NX_PACKET *packet_ptr,
76                                    NXD_ADDRESS *ip_address, UINT port)
77 {
78 #ifdef NX_SECURE_ENABLE_DTLS
79 UINT status;
80 
81     if ((dtls_session == NX_NULL) || (packet_ptr == NX_NULL) || (ip_address == NX_NULL))
82     {
83         return(NX_PTR_ERROR);
84     }
85 
86     /* Make sure the session is initialized. */
87     if (dtls_session->nx_secure_dtls_tls_session.nx_secure_tls_id != NX_SECURE_TLS_ID)
88     {
89         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
90     }
91 
92     status =  _nx_secure_dtls_session_send(dtls_session, packet_ptr, ip_address, port);
93 
94     /* Return completion status.  */
95     return(status);
96 #else
97     NX_PARAMETER_NOT_USED(dtls_session);
98     NX_PARAMETER_NOT_USED(packet_ptr);
99     NX_PARAMETER_NOT_USED(ip_address);
100     NX_PARAMETER_NOT_USED(port);
101 
102     return(NX_NOT_SUPPORTED);
103 #endif /* NX_SECURE_ENABLE_DTLS */
104 }
105 
106