1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Secure Component                                                 */
17 /**                                                                       */
18 /**    Transport Layer Security (TLS)                                     */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SECURE_SOURCE_CODE
24 
25 
26 #include "nx_secure_tls.h"
27 
28 /* Bring in externs for caller checking code.  */
29 
30 NX_SECURE_CALLER_CHECKING_EXTERNS
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nxe_secure_tls_session_server_callback_set         PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Timothy Stapko, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function checks for errors when setting the TLS server         */
45 /*    callback function.                                                  */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    tls_session                           TLS control block             */
50 /*    func_ptr                              Pointer to callback function  */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                                Completion status             */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    _nx_secure_tls_session_server_callback_set                          */
59 /*                                          Actual set function           */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
70 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_nxe_secure_tls_session_server_callback_set(NX_SECURE_TLS_SESSION * tls_session,ULONG (* func_ptr)(NX_SECURE_TLS_SESSION * tls_session,NX_SECURE_TLS_HELLO_EXTENSION * extensions,UINT num_extensions))74 UINT _nxe_secure_tls_session_server_callback_set(NX_SECURE_TLS_SESSION *tls_session,
75                                                  ULONG (*func_ptr)(NX_SECURE_TLS_SESSION *tls_session,
76                                                                    NX_SECURE_TLS_HELLO_EXTENSION *extensions,
77                                                                    UINT num_extensions))
78 {
79 UINT status;
80 
81 
82     if (tls_session == NX_NULL || func_ptr == NX_NULL)
83     {
84         return(NX_PTR_ERROR);
85     }
86 
87     /* Make sure the session is initialized. */
88     if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID)
89     {
90         return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
91     }
92 
93     /* Check for appropriate caller.  */
94     NX_THREADS_ONLY_CALLER_CHECKING
95 
96     /* Set the function pointer in the TLS session. */
97     status = _nx_secure_tls_session_server_callback_set(tls_session, func_ptr);
98 
99     return(status);
100 }
101 
102