1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
102
103
104
105
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
145
146
147
148
149
150
151
152
153
154
155
156
157
158
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
206
207
208
209
210
211
212
213
214
215
216
217
218
222
223
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
248
249
250
252
253
254
255
256
257
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
295
296
297
298
299
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_system.h"
...
...
UINT _nx_ip_create(NX_IP *ip_ptr, CHAR *name, ULONG ip_address, ULONG network_mask,
NX_PACKET_POOL *default_pool, VOID (*ip_link_driver)(struct NX_IP_DRIVER_STRUCT *),
VOID *memory_ptr, ULONG memory_size, UINT priority)
{
TX_INTERRUPT_SAVE_AREA
NX_IP *tail_ptr;
UINT i;
UINT old_threshold = 0;
TX_THREAD *current_thread;
#ifdef NX_DISABLE_IPV4
NX_PARAMETER_NOT_USED(ip_address);
NX_PARAMETER_NOT_USED(network_mask);/* ... */
#endif
if (((ULONG)_nx_system_build_options_1 | (ULONG)_nx_system_build_options_2 | (ULONG)_nx_system_build_options_3 |
(ULONG)_nx_system_build_options_4 | (ULONG)_nx_system_build_options_5 | (ULONG)_nx_version_id[0]) == 0)
{
return(NX_NOT_IMPLEMENTED);
}if (((ULONG)_nx_system_build_options_1 | (ULONG)_nx_system_build_options_2 | (ULONG)_nx_system_build_options_3 | (ULONG)_nx_system_build_options_4 | (ULONG)_nx_system_build_options_5 | (ULONG)_nx_version_id[0]) == 0) { ... }
memset((void *)ip_ptr, 0, sizeof(NX_IP));
ip_ptr -> nx_ip_interface[0].nx_interface_valid = 1;
#ifndef NX_DISABLE_IPV4
ip_ptr -> nx_ip_interface[0].nx_interface_ip_address = ip_address;
ip_ptr -> nx_ip_interface[0].nx_interface_ip_network_mask = network_mask;
ip_ptr -> nx_ip_interface[0].nx_interface_ip_network = ip_address & network_mask;
ip_ptr -> nx_ip_interface[0].nx_interface_arp_defend_timeout = 0;/* ... */
#endif
ip_ptr -> nx_ip_interface[0].nx_interface_link_driver_entry = ip_link_driver;
ip_ptr -> nx_ip_interface[0].nx_interface_name = (CHAR *)"PRI";
for (i = 0; i < NX_MAX_IP_INTERFACES; i++)
{
ip_ptr -> nx_ip_interface[i].nx_interface_index = (UCHAR)i;
}for (i = 0; i < NX_MAX_IP_INTERFACES; i++) { ... }
#ifndef NX_DISABLE_LOOPBACK_INTERFACE
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_name = (CHAR *)"Internal IP Loopback";
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_valid = 1;
#ifndef NX_DISABLE_IPV4
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_ip_address = 0x7F000001;
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_ip_network_mask = 0xFF000000;
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_ip_network = 0x7F000000;/* ... */
#endif
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_link_driver_entry = NX_NULL;
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_address_mapping_needed = 0;
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_ip_mtu_size = 65535;
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_link_up = 1;
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
ip_ptr -> nx_ip_interface[NX_LOOPBACK_INTERFACE].nx_interface_capability_flag = (NX_INTERFACE_CAPABILITY_IPV4_TX_CHECKSUM |
NX_INTERFACE_CAPABILITY_IPV4_RX_CHECKSUM |
NX_INTERFACE_CAPABILITY_TCP_TX_CHECKSUM |
NX_INTERFACE_CAPABILITY_TCP_RX_CHECKSUM |
NX_INTERFACE_CAPABILITY_UDP_TX_CHECKSUM |
NX_INTERFACE_CAPABILITY_UDP_RX_CHECKSUM |
NX_INTERFACE_CAPABILITY_ICMPV4_TX_CHECKSUM |
NX_INTERFACE_CAPABILITY_ICMPV4_RX_CHECKSUM |
NX_INTERFACE_CAPABILITY_ICMPV6_RX_CHECKSUM |
NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM |
NX_INTERFACE_CAPABILITY_IGMP_TX_CHECKSUM |
NX_INTERFACE_CAPABILITY_IGMP_RX_CHECKSUM);/* ... */
#endif
/* ... */
#endif
ip_ptr -> nx_ip_name = name;
ip_ptr -> nx_ip_packet_id = NX_INIT_PACKET_ID;
ip_ptr -> nx_ip_default_packet_pool = default_pool;
#ifdef NX_ENABLE_DUAL_PACKET_POOL
ip_ptr -> nx_ip_auxiliary_packet_pool = default_pool;/* ... */
#endif
tx_mutex_create(&(ip_ptr -> nx_ip_protection), name, TX_NO_INHERIT);
tx_event_flags_create(&(ip_ptr -> nx_ip_events), name);
current_thread = tx_thread_identify();
if (current_thread)
{
tx_thread_preemption_change(current_thread, priority, &old_threshold);
}if (current_thread) { ... }
/* ... */
tx_thread_create(&(ip_ptr -> nx_ip_thread), name, _nx_ip_thread_entry, (ULONG)(ALIGN_TYPE)(ip_ptr),
memory_ptr, memory_size, priority, priority, 1, TX_AUTO_START);
NX_THREAD_EXTENSION_PTR_SET(&(ip_ptr -> nx_ip_thread), ip_ptr)
tx_timer_create(&(ip_ptr -> nx_ip_periodic_timer), name,
_nx_ip_periodic_timer_entry, (ULONG)(ALIGN_TYPE)ip_ptr,
NX_IP_PERIODIC_RATE, NX_IP_PERIODIC_RATE, TX_AUTO_ACTIVATE);
NX_TIMER_EXTENSION_PTR_SET(&(ip_ptr -> nx_ip_periodic_timer), ip_ptr)
NX_TRACE_OBJECT_REGISTER(NX_TRACE_OBJECT_TYPE_IP, ip_ptr, name, memory_ptr, memory_size);
NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_CREATE, ip_ptr, ip_address, network_mask, default_pool, NX_TRACE_IP_EVENTS, 0, 0);
#ifndef NX_DISABLE_IPV4
ip_ptr -> nx_ipv4_packet_receive = _nx_ipv4_packet_receive;/* ... */
#endif
/* ... */
TX_DISABLE
ip_ptr -> nx_ip_id = NX_IP_ID;
/* ... */
if (_nx_ip_created_ptr)
{
tail_ptr = _nx_ip_created_ptr -> nx_ip_created_previous;
_nx_ip_created_ptr -> nx_ip_created_previous = ip_ptr;
tail_ptr -> nx_ip_created_next = ip_ptr;
ip_ptr -> nx_ip_created_previous = tail_ptr;
ip_ptr -> nx_ip_created_next = _nx_ip_created_ptr;
}if (_nx_ip_created_ptr) { ... }
else
{
_nx_ip_created_ptr = ip_ptr;
ip_ptr -> nx_ip_created_next = ip_ptr;
ip_ptr -> nx_ip_created_previous = ip_ptr;
}else { ... }
_nx_ip_created_count++;
TX_RESTORE
if (current_thread)
{
tx_thread_preemption_change(current_thread, old_threshold, &old_threshold);
}if (current_thread) { ... }
return(NX_SUCCESS);
}{ ... }