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 /** Address Resolution Protocol (ARP) */
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_arp.h"
31
32 #ifndef NX_DISABLE_IPV4
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _nx_arp_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 ARP packet from the link driver (usually */
46 /* the link driver's input ISR) and places it in the deferred receive */
47 /* ARP packet queue. This moves the minimal receive ARP 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 /* _nx_packet_release Packet release function */
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_arp_packet_deferred_receive(NX_IP * ip_ptr,NX_PACKET * packet_ptr)77 VOID _nx_arp_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 ARP is enabled on this IP instance. */
90 if (!ip_ptr -> nx_ip_arp_queue_process)
91 {
92
93 /* ARP is not enabled. */
94
95 #ifndef NX_DISABLE_ARP_INFO
96 /* Increment the ARP invalid messages count... */
97 ip_ptr -> nx_ip_arp_invalid_messages++;
98 #endif
99
100 /* Restore interrupts. */
101 TX_RESTORE
102
103 /* Since ARP 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 ARP deferred processing queue is empty. */
111 if (ip_ptr -> nx_ip_arp_deferred_received_packet_head)
112 {
113
114 /* Not empty, just place the packet at the end of the ARP deferred queue. */
115 (ip_ptr -> nx_ip_arp_deferred_received_packet_tail) -> nx_packet_queue_next = packet_ptr;
116 packet_ptr -> nx_packet_queue_next = NX_NULL;
117 ip_ptr -> nx_ip_arp_deferred_received_packet_tail = packet_ptr;
118
119 /* Restore interrupts. */
120 TX_RESTORE
121 }
122 else
123 {
124
125 /* Empty ARP deferred receive processing queue. Just setup the head pointers and
126 set the event flags to ensure the IP helper thread looks at the ARP deferred
127 processing queue. */
128 ip_ptr -> nx_ip_arp_deferred_received_packet_head = packet_ptr;
129 ip_ptr -> nx_ip_arp_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 ARP deferred receive. */
136 tx_event_flags_set(&(ip_ptr -> nx_ip_events), NX_IP_ARP_REC_EVENT, TX_OR);
137 }
138 }
139 #endif /* !NX_DISABLE_IPV4 */
140
141