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 /**************************************************************************/
30 /*                                                                        */
31 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*    _nxe_secure_dtls_client_protocol_version_override   PORTABLE C      */
34 /*                                                           6.1          */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    Timothy Stapko, Microsoft Corporation                               */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    This function checks for errors in DTLS client protocol version     */
42 /*    override call.                                                      */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    dtls_session                          Pointer to DTLS session       */
47 /*    protocol_version                      Version of DTLS to use        */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    status                                Completion status             */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    _nx_secure_dtls_client_protocol_version_override                    */
56 /*                                          Override DTLS protocol version*/
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Application Code                                                    */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
67 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*                                                                        */
70 /**************************************************************************/
_nxe_secure_dtls_client_protocol_version_override(NX_SECURE_DTLS_SESSION * dtls_session,USHORT protocol_version)71 UINT _nxe_secure_dtls_client_protocol_version_override(NX_SECURE_DTLS_SESSION *dtls_session,
72                                                        USHORT protocol_version)
73 {
74 #ifdef NX_SECURE_ENABLE_DTLS
75 UINT status;
76 
77     /* Check pointers. */
78     if (dtls_session == NX_NULL)
79     {
80         return(NX_PTR_ERROR);
81     }
82 
83     /* Make sure the session is initialized. */
84     if (dtls_session->nx_secure_dtls_tls_session.nx_secure_tls_id != NX_SECURE_TLS_ID)
85     {
86         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
87     }
88 
89     /* Make sure the version supplied is known and supported. */
90     switch (protocol_version)
91     {
92     /* Supported DTLS versions. */
93     case NX_SECURE_DTLS_VERSION_1_0:
94     case NX_SECURE_DTLS_VERSION_1_2:
95         break;
96     default:
97         return(NX_PTR_ERROR);
98     }
99 
100     status = _nx_secure_dtls_client_protocol_version_override(dtls_session, protocol_version);
101 
102     /* Return completion status.  */
103     return(status);
104 #else
105     NX_PARAMETER_NOT_USED(dtls_session);
106     NX_PARAMETER_NOT_USED(protocol_version);
107 
108     return(NX_NOT_SUPPORTED);
109 #endif
110 }
111 
112