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 /* _nxe_secure_dtls_session_client_info_get PORTABLE C */
32 /* 6.1 */
33 /* AUTHOR */
34 /* */
35 /* Timothy Stapko, Microsoft Corporation */
36 /* */
37 /* DESCRIPTION */
38 /* */
39 /* This function checks for errors when getting DTLS client info. */
40 /* */
41 /* INPUT */
42 /* */
43 /* dtls_session DTLS session control block */
44 /* client_ip_address Return remote host IP address */
45 /* client_port Return remote host UDP port */
46 /* local_port Return local UDP port */
47 /* */
48 /* OUTPUT */
49 /* */
50 /* status Completion status */
51 /* */
52 /* CALLS */
53 /* */
54 /* _nx_secure_dtls_session_client_info_get */
55 /* Actual function call */
56 /* */
57 /* CALLED BY */
58 /* */
59 /* Application Code */
60 /* */
61 /* RELEASE HISTORY */
62 /* */
63 /* DATE NAME DESCRIPTION */
64 /* */
65 /* 05-19-2020 Timothy Stapko Initial Version 6.0 */
66 /* 09-30-2020 Timothy Stapko Modified comment(s), */
67 /* resulting in version 6.1 */
68 /* */
69 /**************************************************************************/
_nxe_secure_dtls_session_client_info_get(NX_SECURE_DTLS_SESSION * dtls_session,NXD_ADDRESS * client_ip_address,UINT * client_port,UINT * local_port)70 UINT _nxe_secure_dtls_session_client_info_get(NX_SECURE_DTLS_SESSION *dtls_session,
71 NXD_ADDRESS *client_ip_address, UINT *client_port, UINT *local_port)
72 {
73 #ifdef NX_SECURE_ENABLE_DTLS
74 NX_UDP_SOCKET *socket_ptr;
75 UINT status;
76
77 /* Check pointers. */
78 if (dtls_session == NX_NULL || client_ip_address == NX_NULL ||
79 client_port == NX_NULL || local_port == NX_NULL)
80 {
81 return(NX_PTR_ERROR);
82 }
83
84 /* Make sure the session is initialized. */
85 if (dtls_session->nx_secure_dtls_tls_session.nx_secure_tls_id != NX_SECURE_TLS_ID)
86 {
87 return(NX_SECURE_TLS_SESSION_UNINITIALIZED);
88 }
89
90 /* Get our UDP socket. */
91 socket_ptr = dtls_session->nx_secure_dtls_udp_socket;
92
93 /* Check UDP socket. */
94 if (socket_ptr == NX_NULL)
95 {
96 return(NX_INVALID_SOCKET);
97 }
98
99 /* Call actual function. */
100 status = _nx_secure_dtls_session_client_info_get(dtls_session, client_ip_address, client_port, local_port);
101
102 return(status);
103 #else
104 NX_PARAMETER_NOT_USED(dtls_session);
105 NX_PARAMETER_NOT_USED(client_ip_address);
106 NX_PARAMETER_NOT_USED(client_port);
107 NX_PARAMETER_NOT_USED(local_port);
108
109 return(NX_NOT_SUPPORTED);
110 #endif /* NX_SECURE_ENABLE_DTLS */
111 }
112
113