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 #include "nx_ipv6.h"
26
27 /**************************************************************************/
28 /* */
29 /* FUNCTION RELEASE */
30 /* */
31 /* _nx_secure_dtls_client_session_start PORTABLE C */
32 /* 6.1 */
33 /* AUTHOR */
34 /* */
35 /* Timothy Stapko, Microsoft Corporation */
36 /* */
37 /* DESCRIPTION */
38 /* */
39 /* This function starts a DTLS session for a DTLS client given a UDP */
40 /* socket. The client session must have been previously initialized. */
41 /* */
42 /* INPUT */
43 /* */
44 /* dtls_session DTLS control block */
45 /* udp_socket UDP socket pointer */
46 /* wait_option Suspension option */
47 /* ip_address Address of remote server */
48 /* port Port on remote server */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* status Completion status */
53 /* */
54 /* CALLS */
55 /* */
56 /* _nx_secure_dtls_session_start Start the DTLS session */
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_client_session_start(NX_SECURE_DTLS_SESSION * dtls_session,NX_UDP_SOCKET * udp_socket,NXD_ADDRESS * ip_address,UINT port,UINT wait_option)71 UINT _nx_secure_dtls_client_session_start(NX_SECURE_DTLS_SESSION *dtls_session, NX_UDP_SOCKET *udp_socket, NXD_ADDRESS *ip_address, UINT port, UINT wait_option)
72 {
73 #ifdef NX_SECURE_ENABLE_DTLS
74 UINT status;
75 NXD_ADDRESS *remote_ip;
76
77 /* Get our local IP address for the deep copy below. */
78 remote_ip = &(dtls_session->nx_secure_dtls_remote_ip_address);
79
80 /* Copy address version. */
81 remote_ip -> nxd_ip_version = ip_address -> nxd_ip_version;
82
83 #ifndef NX_DISABLE_IPV4
84 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V4)
85 {
86 /* Pickup the source IP address. */
87 remote_ip -> nxd_ip_address.v4 = ip_address -> nxd_ip_address.v4;
88
89 }
90 #endif /* NX_DISABLE_IPV4 */
91
92 #ifdef FEATURE_NX_IPV6
93 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V6)
94 {
95 COPY_IPV6_ADDRESS(ip_address -> nxd_ip_address.v6,
96 remote_ip -> nxd_ip_address.v6);
97
98 }
99 #endif /* FEATURE_NX_IPV6 */
100
101 /* Assign port to session. */
102 dtls_session->nx_secure_dtls_remote_port = port;
103
104 /* Session is in use. */
105 dtls_session -> nx_secure_dtls_session_in_use = NX_TRUE;
106
107 /* Call old API for now. */
108 status = _nx_secure_dtls_session_start(dtls_session, udp_socket, NX_TRUE, wait_option);
109
110 return(status);
111 #else
112 NX_PARAMETER_NOT_USED(dtls_session);
113 NX_PARAMETER_NOT_USED(udp_socket);
114 NX_PARAMETER_NOT_USED(wait_option);
115 NX_PARAMETER_NOT_USED(ip_address);
116 NX_PARAMETER_NOT_USED(port);
117
118 return(NX_NOT_SUPPORTED);
119 #endif /* NX_SECURE_ENABLE_DTLS */
120 }
121