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_arp.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nx_arp_enable PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function enables the ARP management component for the */
45 /* specified IP instance. */
46 /* */
47 /* INPUT */
48 /* */
49 /* ip_ptr IP instance pointer */
50 /* arp_cache_memory Start of ARP cache memory */
51 /* arp_cache_size Size in bytes of cache memory */
52 /* memset Set the memory */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* status Completion status */
57 /* */
58 /* CALLS */
59 /* */
60 /* None */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Application Code */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
71 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_nx_arp_enable(NX_IP * ip_ptr,VOID * arp_cache_memory,ULONG arp_cache_size)75 UINT _nx_arp_enable(NX_IP *ip_ptr, VOID *arp_cache_memory, ULONG arp_cache_size)
76 {
77
78 #ifndef NX_DISABLE_IPV4
79 ULONG i;
80 ULONG arp_entries;
81 NX_ARP *entry_ptr;
82
83
84 /* If trace is enabled, insert this event into the trace buffer. */
85 NX_TRACE_IN_LINE_INSERT(NX_TRACE_ARP_ENABLE, ip_ptr, arp_cache_memory, arp_cache_size, 0, NX_TRACE_ARP_EVENTS, 0, 0);
86
87 /* Clear the entire ARP cache. */
88 memset((void *)arp_cache_memory, 0, arp_cache_size);
89
90 /* Pickup starting address of ARP entry array. */
91 entry_ptr = (NX_ARP *)arp_cache_memory;
92
93 /* Determine how many ARP entries will fit in this cache area. */
94 arp_entries = arp_cache_size / sizeof(NX_ARP);
95
96 /* Initialize the forward pointers of available ARP entries. */
97 for (i = 0; i < (arp_entries - 1); i++)
98 {
99 /* Setup each entry to point to the next entry. */
100 entry_ptr -> nx_arp_pool_next = entry_ptr + 1;
101 entry_ptr++;
102 }
103
104 /* The entry now points to the last entry in the ARP array. Set its
105 next pointer to the first entry. */
106 entry_ptr -> nx_arp_pool_next = (NX_ARP *)arp_cache_memory;
107
108 /* Initialize the backward pointers of available ARP entries. */
109 for (i = 0; i < (arp_entries - 1); i++)
110 {
111 /* Setup each entry to point to the previous entry. */
112 entry_ptr -> nx_arp_pool_previous = entry_ptr - 1;
113 entry_ptr--;
114 }
115
116 /* The entry now points to the first entry, set the previous pointer
117 to the last entry. */
118 entry_ptr -> nx_arp_pool_previous = (entry_ptr + (arp_entries - 1));
119
120 /* At this point, everything is okay in the ARP enable call.. populate the
121 information in the IP structure. */
122
123 /* Setup the list head pointers in the IP instance. At first all ARP
124 entries are associated with the dynamic ARP list. The static ARP list
125 is NULL until static ARP entry calls are made. */
126 ip_ptr -> nx_ip_arp_static_list = NX_NULL;
127 ip_ptr -> nx_ip_arp_dynamic_list = (NX_ARP *)arp_cache_memory;
128
129 /* Store the initial ARP cache information in the IP control block. */
130 ip_ptr -> nx_ip_arp_cache_memory = arp_cache_memory;
131 ip_ptr -> nx_ip_arp_total_entries = arp_entries;
132
133 /* Setup the ARP periodic update routine. */
134 ip_ptr -> nx_ip_arp_periodic_update = _nx_arp_periodic_update;
135
136 /* Setup the ARP queue process routine. */
137 ip_ptr -> nx_ip_arp_queue_process = _nx_arp_queue_process;
138
139 /* Setup the ARP send packet routine. */
140 ip_ptr -> nx_ip_arp_packet_send = _nx_arp_packet_send;
141
142 /* Setup the ARP allocate service request pointer. */
143 ip_ptr -> nx_ip_arp_allocate = _nx_arp_entry_allocate;
144
145 /* Return successful completion. */
146 return(NX_SUCCESS);
147 #else /* NX_DISABLE_IPV4 */
148 NX_PARAMETER_NOT_USED(ip_ptr);
149 NX_PARAMETER_NOT_USED(arp_cache_memory);
150 NX_PARAMETER_NOT_USED(arp_cache_size);
151
152 return(NX_NOT_SUPPORTED);
153 #endif /* !NX_DISABLE_IPV4 */
154 }
155
156