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
88
89
90
91
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
123
124
125
126
127
128
129
130
131
132
133
134
135
136
139
140
141
142
146
147
148
149
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
178
179
180
181
182
183
184
185
186
187
189
190
191
192
193
194
195
196
197
199
200
201
202
203
204
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
263
264
265
266
267
273
274
275
276
277
278
279
280
281
282
283
284
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "tx_thread.h"
#include "nx_packet.h"
...
...
UINT _nx_packet_allocate(NX_PACKET_POOL *pool_ptr, NX_PACKET **packet_ptr,
ULONG packet_type, ULONG wait_option)
{
TX_INTERRUPT_SAVE_AREA
UINT status;
TX_THREAD *thread_ptr;
NX_PACKET *work_ptr;
#ifdef TX_ENABLE_EVENT_TRACE
TX_TRACE_BUFFER_ENTRY *trace_event;
ULONG trace_timestamp;/* ... */
#endif
if (pool_ptr -> nx_packet_pool_payload_size < packet_type)
{
return(NX_INVALID_PARAMETERS);
}if (pool_ptr -> nx_packet_pool_payload_size < packet_type) { ... }
*packet_ptr = NX_NULL;
NX_TRACE_IN_LINE_INSERT(NX_TRACE_PACKET_ALLOCATE, pool_ptr, 0, packet_type, pool_ptr -> nx_packet_pool_available, NX_TRACE_PACKET_EVENTS, &trace_event, &trace_timestamp);
TX_DISABLE
if (pool_ptr -> nx_packet_pool_available)
{
pool_ptr -> nx_packet_pool_available--;
work_ptr = pool_ptr -> nx_packet_pool_available_list;
pool_ptr -> nx_packet_pool_available_list = work_ptr -> nx_packet_queue_next;
work_ptr -> nx_packet_queue_next = NX_NULL;
#ifndef NX_DISABLE_PACKET_CHAIN
work_ptr -> nx_packet_next = NX_NULL;
work_ptr -> nx_packet_last = NX_NULL;/* ... */
#endif
work_ptr -> nx_packet_length = 0;
work_ptr -> nx_packet_prepend_ptr = work_ptr -> nx_packet_data_start + packet_type;
work_ptr -> nx_packet_append_ptr = work_ptr -> nx_packet_prepend_ptr;
work_ptr -> nx_packet_address.nx_packet_interface_ptr = NX_NULL;
#ifdef NX_ENABLE_INTERFACE_CAPABILITY
work_ptr -> nx_packet_interface_capability_flag = 0;
#endif
work_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next = (NX_PACKET *)NX_PACKET_ALLOCATED;
#ifdef FEATURE_NX_IPV6
work_ptr -> nx_packet_option_state = 0;/* ... */
#endif
#ifdef NX_IPSEC_ENABLE
work_ptr -> nx_packet_ipsec_state = 0;
work_ptr -> nx_packet_ipsec_sa_ptr = NX_NULL;/* ... */
#endif
#ifndef NX_DISABLE_IPV4
work_ptr -> nx_packet_ip_version = NX_IP_VERSION_V4;/* ... */
#endif
work_ptr -> nx_packet_identical_copy = NX_FALSE;
work_ptr -> nx_packet_ip_header_length = 0;
#ifdef NX_ENABLE_THREAD
work_ptr -> nx_packet_type = 0;
#endif
*packet_ptr = work_ptr;
status = NX_SUCCESS;
NX_PACKET_DEBUG(__FILE__, __LINE__, work_ptr);
}if (pool_ptr -> nx_packet_pool_available) { ... }
else
{
#ifndef NX_DISABLE_PACKET_INFO
pool_ptr -> nx_packet_pool_empty_requests++;/* ... */
#endif
if (wait_option)
{
#ifndef NX_DISABLE_PACKET_INFO
pool_ptr -> nx_packet_pool_empty_suspensions++;/* ... */
#endif
thread_ptr = _tx_thread_current_ptr;
thread_ptr -> tx_thread_suspend_cleanup = _nx_packet_pool_cleanup;
/* ... */
thread_ptr -> tx_thread_suspend_control_block = (void *)pool_ptr;
thread_ptr -> tx_thread_additional_suspend_info = (void *)packet_ptr;
/* ... */
thread_ptr -> tx_thread_suspend_info = packet_type;
if (pool_ptr -> nx_packet_pool_suspension_list)
{
thread_ptr -> tx_thread_suspended_next =
pool_ptr -> nx_packet_pool_suspension_list;
thread_ptr -> tx_thread_suspended_previous =
(pool_ptr -> nx_packet_pool_suspension_list) -> tx_thread_suspended_previous;
((pool_ptr -> nx_packet_pool_suspension_list) -> tx_thread_suspended_previous) -> tx_thread_suspended_next =
thread_ptr;
(pool_ptr -> nx_packet_pool_suspension_list) -> tx_thread_suspended_previous = thread_ptr;
}if (pool_ptr -> nx_packet_pool_suspension_list) { ... }
else
{
/* ... */
pool_ptr -> nx_packet_pool_suspension_list = thread_ptr;
thread_ptr -> tx_thread_suspended_next = thread_ptr;
thread_ptr -> tx_thread_suspended_previous = thread_ptr;
}else { ... }
pool_ptr -> nx_packet_pool_suspended_count++;
thread_ptr -> tx_thread_state = TX_TCP_IP;
thread_ptr -> tx_thread_suspending = TX_TRUE;
_tx_thread_preempt_disable++;
thread_ptr -> tx_thread_timer.tx_timer_internal_remaining_ticks = wait_option;
TX_RESTORE
_tx_thread_system_suspend(thread_ptr);
NX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, NX_TRACE_PACKET_ALLOCATE, 0, *packet_ptr, 0, 0);
#ifdef NX_ENABLE_PACKET_DEBUG_INFO
if (thread_ptr -> tx_thread_suspend_status == NX_SUCCESS)
{
NX_PACKET_DEBUG(__FILE__, __LINE__, *packet_ptr);
}if (thread_ptr -> tx_thread_suspend_status == NX_SUCCESS) { ... }
/* ... */#endif
return(thread_ptr -> tx_thread_suspend_status);
}if (wait_option) { ... }
else
{
status = NX_NO_PACKET;
}else { ... }
}else { ... }
TX_RESTORE
NX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, NX_TRACE_PACKET_ALLOCATE, 0, *packet_ptr, 0, 0);
return(status);
}{ ... }