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 /**   User Datagram Protocol (UDP)                                        */
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_udp.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_udp_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 /*    a packet is received on the socket.  If a NULL pointer is supplied, */
46 /*    the receive notify function is disabled.                            */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    socket_ptr                            Pointer to UDP socket         */
51 /*    udp_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_udp_socket_receive_notify(NX_UDP_SOCKET * socket_ptr,VOID (* udp_receive_notify)(NX_UDP_SOCKET * socket_ptr))76 UINT  _nx_udp_socket_receive_notify(NX_UDP_SOCKET *socket_ptr,
77                                     VOID (*udp_receive_notify)(NX_UDP_SOCKET *socket_ptr))
78 {
79 TX_INTERRUPT_SAVE_AREA
80 
81 
82     /* Disable interrupts.  */
83     TX_DISABLE
84 
85     /* Setup the receive notify function pointer.  */
86     socket_ptr -> nx_udp_receive_callback =  udp_receive_notify;
87 
88     /* Restore interrupts.  */
89     TX_RESTORE
90 
91     /* If trace is enabled, insert this event into the trace buffer.  */
92     NX_TRACE_IN_LINE_INSERT(NX_TRACE_UDP_SOCKET_RECEIVE_NOTIFY, socket_ptr -> nx_udp_socket_ip_ptr, socket_ptr, udp_receive_notify, 0, NX_TRACE_UDP_EVENTS, 0, 0);
93 
94     /* Return successful completion.  */
95     return(NX_SUCCESS);
96 }
97 
98