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 VOID _nx_secure_dtls_receive_callback(NX_UDP_SOCKET *socket_ptr);
27 
28 /**************************************************************************/
29 /*                                                                        */
30 /*  FUNCTION                                               RELEASE        */
31 /*                                                                        */
32 /*    _nx_secure_dtls_server_start                        PORTABLE C      */
33 /*                                                           6.1          */
34 /*  AUTHOR                                                                */
35 /*                                                                        */
36 /*    Timothy Stapko, Microsoft Corporation                               */
37 /*                                                                        */
38 /*  DESCRIPTION                                                           */
39 /*                                                                        */
40 /*    This function starts a DTLS server on the internal UDP socket.      */
41 /*    It is assumed that the DTLS server instance was created previously  */
42 /*    and the UDP socket is ready to listen on the port specified in the  */
43 /*    create call.                                                        */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    server_ptr                            DTLS server control block     */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    status                                Completion status             */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    nx_udp_socket_bind                    Bind UDP socket to port       */
56 /*    nx_udp_socket_receive_notify          Set receive callback          */
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 /**************************************************************************/
_nx_secure_dtls_server_start(NX_SECURE_DTLS_SERVER * server_ptr)71 UINT _nx_secure_dtls_server_start(NX_SECURE_DTLS_SERVER *server_ptr)
72 {
73 #ifdef NX_SECURE_ENABLE_DTLS
74 UINT status;
75 
76     /* Bind the UDP socket to the assigned port. */
77     status =  nx_udp_socket_bind(&(server_ptr->nx_dtls_server_udp_socket), server_ptr->nx_dtls_server_listen_port,
78                                  server_ptr->nx_dtls_server_timeout);
79 
80     if(status != NX_SUCCESS)
81     {
82         return(status);
83     }
84 
85     /* Setup the UDP socket with our internal receive callback. */
86     nx_udp_socket_receive_notify(&(server_ptr->nx_dtls_server_udp_socket), _nx_secure_dtls_receive_callback);
87 
88     return(NX_SUCCESS);
89 #else
90     NX_PARAMETER_NOT_USED(server_ptr);
91 
92     return(NX_NOT_SUPPORTED);
93 #endif /* NX_SECURE_ENABLE_DTLS */
94 }
95 
96