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 /** Address Resolution Protocol (ARP) */
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_arp.h"
32
33 #ifndef NX_DISABLE_IPV4
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _nx_arp_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 ARP packet from the link driver (usually */
47 /* the link driver's input ISR) and places it in the deferred receive */
48 /* ARP packet queue. This moves the minimal receive ARP 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 /* _nx_packet_release Packet release function */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application I/O Driver */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
74 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* */
77 /**************************************************************************/
_nx_arp_packet_deferred_receive(NX_IP * ip_ptr,NX_PACKET * packet_ptr)78 VOID _nx_arp_packet_deferred_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
79 {
80
81 TX_INTERRUPT_SAVE_AREA
82
83
84 /* Disable interrupts. */
85 TX_DISABLE
86
87 /* Add debug information. */
88 NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
89
90 /* Check to see if ARP is enabled on this IP instance. */
91 if (!ip_ptr -> nx_ip_arp_queue_process)
92 {
93
94 /* ARP is not enabled. */
95
96 #ifndef NX_DISABLE_ARP_INFO
97 /* Increment the ARP invalid messages count... */
98 ip_ptr -> nx_ip_arp_invalid_messages++;
99 #endif
100
101 /* Restore interrupts. */
102 TX_RESTORE
103
104 /* Since ARP is not enabled, just release the packet. */
105 _nx_packet_release(packet_ptr);
106
107 /* Return to caller. */
108 return;
109 }
110
111 /* Check to see if the ARP deferred processing queue is empty. */
112 if (ip_ptr -> nx_ip_arp_deferred_received_packet_head)
113 {
114
115 /* Not empty, just place the packet at the end of the ARP deferred queue. */
116 (ip_ptr -> nx_ip_arp_deferred_received_packet_tail) -> nx_packet_queue_next = packet_ptr;
117 packet_ptr -> nx_packet_queue_next = NX_NULL;
118 ip_ptr -> nx_ip_arp_deferred_received_packet_tail = packet_ptr;
119
120 /* Restore interrupts. */
121 TX_RESTORE
122 }
123 else
124 {
125
126 /* Empty ARP deferred receive processing queue. Just setup the head pointers and
127 set the event flags to ensure the IP helper thread looks at the ARP deferred
128 processing queue. */
129 ip_ptr -> nx_ip_arp_deferred_received_packet_head = packet_ptr;
130 ip_ptr -> nx_ip_arp_deferred_received_packet_tail = packet_ptr;
131 packet_ptr -> nx_packet_queue_next = NX_NULL;
132
133 /* Restore interrupts. */
134 TX_RESTORE
135
136 /* Wakeup IP helper thread to process the ARP deferred receive. */
137 tx_event_flags_set(&(ip_ptr -> nx_ip_events), NX_IP_ARP_REC_EVENT, TX_OR);
138 }
139 }
140 #endif /* !NX_DISABLE_IPV4 */
141
142