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 #include "nx_secure_tls.h"
26 
27 /**************************************************************************/
28 /*                                                                        */
29 /*  FUNCTION                                               RELEASE        */
30 /*                                                                        */
31 /*    _nx_secure_tls_session_send                         PORTABLE C      */
32 /*                                                           6.1          */
33 /*  AUTHOR                                                                */
34 /*                                                                        */
35 /*    Timothy Stapko, Microsoft Corporation                               */
36 /*                                                                        */
37 /*  DESCRIPTION                                                           */
38 /*                                                                        */
39 /*    This function sends data using an active TLS session, handling      */
40 /*    all encryption and hashing before sending data over the established */
41 /*    TCP socket connection.                    .                         */
42 /*                                                                        */
43 /*  INPUT                                                                 */
44 /*                                                                        */
45 /*    tls_session                           TLS control block             */
46 /*    packet_ptr                            Pointer to packet data        */
47 /*    wait_option                           Indicates behavior if TCP     */
48 /*                                          socket cannot send packet     */
49 /*                                                                        */
50 /*  OUTPUT                                                                */
51 /*                                                                        */
52 /*    status                                Completion status             */
53 /*                                                                        */
54 /*  CALLS                                                                 */
55 /*                                                                        */
56 /*    _nx_secure_tls_send_record            Send TLS encrypted record     */
57 /*    tx_mutex_get                          Get protection mutex          */
58 /*    tx_mutex_put                          Put protection mutex          */
59 /*                                                                        */
60 /*  CALLED BY                                                             */
61 /*                                                                        */
62 /*    Application Code                                                    */
63 /*                                                                        */
64 /*  RELEASE HISTORY                                                       */
65 /*                                                                        */
66 /*    DATE              NAME                      DESCRIPTION             */
67 /*                                                                        */
68 /*  05-19-2020     Timothy Stapko           Initial Version 6.0           */
69 /*  09-30-2020     Timothy Stapko           Modified comment(s),          */
70 /*                                            resulting in version 6.1    */
71 /*                                                                        */
72 /**************************************************************************/
_nx_secure_tls_session_send(NX_SECURE_TLS_SESSION * tls_session,NX_PACKET * packet_ptr,ULONG wait_option)73 UINT _nx_secure_tls_session_send(NX_SECURE_TLS_SESSION *tls_session, NX_PACKET *packet_ptr,
74                                  ULONG wait_option)
75 {
76 UINT status;
77 
78 
79     /* Get the protection. */
80     tx_mutex_get(&_nx_secure_tls_protection, TX_WAIT_FOREVER);
81 
82     status = _nx_secure_tls_send_record(tls_session, packet_ptr, NX_SECURE_TLS_APPLICATION_DATA, wait_option);
83 
84     if(status != NX_SUCCESS)
85     {
86         /* Make sure we clear keys on errors. */
87         _nx_secure_tls_session_reset(tls_session);
88     }
89 
90     /* Release the protection. */
91     tx_mutex_put(&_nx_secure_tls_protection);
92 
93     return(status);
94 }
95 
96