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