/*************************************************************************** * Copyright (c) 2024 Microsoft Corporation * Copyright (c) 2025-present Eclipse ThreadX Contributors * * This program and the accompanying materials are made available under the * terms of the MIT License which is available at * https://opensource.org/licenses/MIT. * * SPDX-License-Identifier: MIT **************************************************************************/ /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Secure Component */ /** */ /** Transport Layer Security (TLS) */ /** */ /**************************************************************************/ /**************************************************************************/ #define NX_SECURE_SOURCE_CODE #include "nx_secure_tls.h" /* Bring in externs for caller checking code. */ NX_SECURE_CALLER_CHECKING_EXTERNS /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nxe_secure_tls_packet_allocate PORTABLE C */ /* 6.4.3 */ /* AUTHOR */ /* */ /* Timothy Stapko, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function checks for errors in TLS packet allocate call. */ /* */ /* INPUT */ /* */ /* tls_session TLS control block */ /* pool_ptr Pool to allocate packet from */ /* packet_ptr Pointer to place allocated */ /* packet pointer */ /* wait_option Suspension option */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _nx_secure_tls_packet_allocate Actual packet allocate call. */ /* */ /* CALLED BY */ /* */ /* Application */ /* */ /**************************************************************************/ UINT _nxe_secure_tls_packet_allocate(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET_POOL *pool_ptr, NX_PACKET **packet_ptr, ULONG wait_option) { UINT status; /* Verify tls_session is valid. */ /* Make sure the session is initialized. */ if(tls_session -> nx_secure_tls_id != NX_SECURE_TLS_ID) { return(NX_SECURE_TLS_SESSION_UNINITIALIZED); } /* Verify the TCP socket valid and is connected. */ if (tls_session -> nx_secure_tls_tcp_socket == NX_NULL) { return(NX_SECURE_TLS_SESSION_UNINITIALIZED); } if ((tls_session -> nx_secure_tls_tcp_socket -> nx_tcp_socket_connect_ip.nxd_ip_version != NX_IP_VERSION_V4) && (tls_session -> nx_secure_tls_tcp_socket -> nx_tcp_socket_connect_ip.nxd_ip_version != NX_IP_VERSION_V6)) { return(NX_SECURE_TLS_SESSION_UNINITIALIZED); } if (tls_session -> nx_secure_tls_tcp_socket -> nx_tcp_socket_state != NX_TCP_ESTABLISHED) { return(NX_SECURE_TLS_SESSION_UNINITIALIZED); } /* Check for appropriate caller. */ NX_THREADS_ONLY_CALLER_CHECKING status = _nx_secure_tls_packet_allocate(tls_session, pool_ptr, packet_ptr, wait_option); return(status); }