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