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 /**   Reverse Address Resolution Protocol (RARP)                          */
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_ip.h"
30 #include "nx_packet.h"
31 #include "nx_rarp.h"
32 
33 #ifndef NX_DISABLE_IPV4
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nx_rarp_packet_deferred_receive                    PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function receives an RARP packet from the link driver (usually */
47 /*    the link driver's input ISR) and places it in the deferred receive  */
48 /*    RARP packet queue.  This moves the minimal receive RARP packet      */
49 /*    processing from the ISR to the IP helper thread.                    */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    ip_ptr                                Pointer to IP control block   */
54 /*    packet_ptr                            Pointer to packet to send     */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    tx_event_flags_set                    Wakeup IP helper thread       */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application I/O Driver                                              */
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_rarp_packet_deferred_receive(NX_IP * ip_ptr,NX_PACKET * packet_ptr)77 VOID  _nx_rarp_packet_deferred_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
78 {
79 
80 TX_INTERRUPT_SAVE_AREA
81 
82 
83     /* Disable interrupts.  */
84     TX_DISABLE
85 
86     /* Add debug information. */
87     NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
88 
89     /* Check to see if RARP is enabled on this IP instance.  */
90     if (!ip_ptr -> nx_ip_rarp_queue_process)
91     {
92 
93         /* RARP is not enabled.  */
94 
95 #ifndef NX_DISABLE_RARP_INFO
96         /* Increment the RARP invalid messages count...  */
97         ip_ptr -> nx_ip_rarp_invalid_messages++;
98 #endif
99 
100         /* Restore interrupts.  */
101         TX_RESTORE
102 
103         /* Since RARP is not enabled, just release the packet.  */
104         _nx_packet_release(packet_ptr);
105 
106         /* Return to caller.  */
107         return;
108     }
109 
110     /* Check to see if the RARP deferred processing queue is empty.  */
111     if (ip_ptr -> nx_ip_rarp_deferred_received_packet_head)
112     {
113 
114         /* Not empty, just place the packet at the end of the RARP deferred queue.  */
115         (ip_ptr -> nx_ip_rarp_deferred_received_packet_tail) -> nx_packet_queue_next =  packet_ptr;
116         packet_ptr -> nx_packet_queue_next =  NX_NULL;
117         ip_ptr -> nx_ip_rarp_deferred_received_packet_tail =  packet_ptr;
118 
119         /* Restore interrupts.  */
120         TX_RESTORE
121     }
122     else
123     {
124 
125         /* Empty RARP deferred receive processing queue.  Just setup the head pointers and
126            set the event flags to ensure the IP helper thread looks at the RARP deferred
127            processing queue.  */
128         ip_ptr -> nx_ip_rarp_deferred_received_packet_head =  packet_ptr;
129         ip_ptr -> nx_ip_rarp_deferred_received_packet_tail =  packet_ptr;
130         packet_ptr -> nx_packet_queue_next =                  NX_NULL;
131 
132         /* Restore interrupts.  */
133         TX_RESTORE
134 
135         /* Wakeup IP helper thread to process the RARP deferred receive.  */
136         tx_event_flags_set(&(ip_ptr -> nx_ip_events), NX_IP_RARP_REC_EVENT, TX_OR);
137     }
138 }
139 #endif /* !NX_DISABLE_IPV4  */
140 
141