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 Component                                                        */
16 /**                                                                       */
17 /**   Transmission Control Protocol (TCP)                                 */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "nx_api.h"
28 #include "nx_tcp.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_tcp_socket_receive_notify                       PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function sets the receive notify function pointer to the       */
44 /*    function specified by the application, which is called whenever     */
45 /*    one or more receive packets is available for the socket.  If a      */
46 /*    NULL pointer is supplied, the receive notify function is disabled.  */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    socket_ptr                            Pointer to TCP socket         */
51 /*    tcp_receive_notify                    Routine to call when one or   */
52 /*                                            receive packets are         */
53 /*                                            available for the socket    */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    None                                                                */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*    Application Code                                                    */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nx_tcp_socket_receive_notify(NX_TCP_SOCKET * socket_ptr,VOID (* tcp_receive_notify)(NX_TCP_SOCKET * socket_ptr))76 UINT  _nx_tcp_socket_receive_notify(NX_TCP_SOCKET *socket_ptr,
77                                     VOID (*tcp_receive_notify)(NX_TCP_SOCKET *socket_ptr))
78 {
79 TX_INTERRUPT_SAVE_AREA
80 
81     /* If trace is enabled, insert this event into the trace buffer.  */
82     NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_RECEIVE_NOTIFY, socket_ptr -> nx_tcp_socket_ip_ptr, socket_ptr, tcp_receive_notify, 0, NX_TRACE_TCP_EVENTS, 0, 0);
83 
84     /* Get mutex protection.  */
85     tx_mutex_get(&(socket_ptr -> nx_tcp_socket_ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
86 
87     /* Disable interrupts.  */
88     TX_DISABLE
89 
90     /* Setup the receive notify function pointer.  */
91     socket_ptr -> nx_tcp_receive_callback =  tcp_receive_notify;
92 
93     /* Restore interrupts.  */
94     TX_RESTORE
95 
96     /* Release protection.  */
97     tx_mutex_put(&(socket_ptr -> nx_tcp_socket_ip_ptr -> nx_ip_protection));
98 
99     /* Return successful completion.  */
100     return(NX_SUCCESS);
101 }
102 
103