Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_packet.h"
...
...
_nx_packet_data_adjust(NX_PACKET *, ULONG)
Files
loading...
CodeScopeSTM32 Libraries and Samplesnetxduocommon/src/nx_packet_data_adjust.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
101
102
103
104
105
106
107
108
109
110
111
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
142
143
144
145
146
147
148
149
150
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Packet Pool Management (Packet) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_packet.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_packet_data_adjust PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function adjusts the packet data to fill the specified header. */ /* */ /* INPUT */ /* */ /* packet_ptr Pointer to the source packet */ /* header_size The size of header */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _nx_packet_allocate Allocate data packet */ /* _nx_packet_data_append Packet data append service */ /* _nx_packet_release Release data packet */ /* */ /* CALLED BY */ /* */ /* _nx_ip_forward_packet_process Forward IP packet */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), and */ /* verified memcpy use cases, */ /* verified memmove use cases, */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _nx_packet_data_adjust(NX_PACKET *packet_ptr, ULONG header_size) { ULONG available_size; ULONG shift_size; #ifndef NX_DISABLE_PACKET_CHAIN UINT status; ULONG append_size; UCHAR *data_start; NX_PACKET *work_ptr;/* ... */ #endif /* !NX_DISABLE_PACKET_CHAIN */ /* Add debug information. */ NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr); /* The header must be filled in one packet. */ if (((ALIGN_TYPE)packet_ptr -> nx_packet_data_end - (ALIGN_TYPE)packet_ptr -> nx_packet_data_start) < header_size) { return(NX_UNDERFLOW); }if (((ALIGN_TYPE)packet_ptr -> nx_packet_data_end - (ALIGN_TYPE)packet_ptr -> nx_packet_data_start) < header_size) { ... } /* 1. Check if there is enough space to add header. */ if (((ALIGN_TYPE)packet_ptr -> nx_packet_prepend_ptr - (ALIGN_TYPE)packet_ptr -> nx_packet_data_start) >= header_size) { /* Yes. Just return success. */ return(NX_SUCCESS); }if (((ALIGN_TYPE)packet_ptr -> nx_packet_prepend_ptr - (ALIGN_TYPE)packet_ptr -> nx_packet_data_start) >= header_size) { ... } /* Compute the total avilable size in this packet. */ available_size = (ULONG)(((ALIGN_TYPE)packet_ptr -> nx_packet_prepend_ptr - (ALIGN_TYPE)packet_ptr -> nx_packet_data_start) + ((ALIGN_TYPE)packet_ptr -> nx_packet_data_end - (ALIGN_TYPE)packet_ptr -> nx_packet_append_ptr)); /* 2. Would the header fit into the available space? */ if (available_size >= header_size) { /* Yes, adjust the data. */ /* Calculate the shift data size. */ shift_size = (ULONG)((ALIGN_TYPE)packet_ptr -> nx_packet_append_ptr - (ALIGN_TYPE)packet_ptr -> nx_packet_prepend_ptr); /* Move the data, */ memmove(packet_ptr -> nx_packet_data_start + header_size, packet_ptr -> nx_packet_prepend_ptr, shift_size); /* Use case of memmove is verified. */ /* Update the prepend and append pointer. */ packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_data_start + header_size; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + shift_size; }if (available_size >= header_size) { ... } else { #ifndef NX_DISABLE_PACKET_CHAIN /* 3. Current packet does not have enough space to fill the header. Allocate a new packet to fill the overflowing data and chain the packet. *//* ... */ /* Odd value of header_size is not supported now. * In _nx_ip_checksum_compute(), nx_packet_append_ptr must not be odd value. *//* ... */ if (header_size & 1) { return(NX_NOT_SUPPORTED); }if (header_size & 1) { ... } /* Calculate the append data size. */ append_size = header_size - available_size; /* Set the append data pointer. */ data_start = packet_ptr -> nx_packet_append_ptr - append_size; /* Allocate a packet. */ status = _nx_packet_allocate(packet_ptr -> nx_packet_pool_owner, &work_ptr, 0, NX_NO_WAIT); /* Check status. */ if (status) { return(status); }if (status) { ... } /* Firstly, append the overflowing data to the new packet.. */ memcpy(work_ptr -> nx_packet_prepend_ptr, data_start, append_size); /* Use case of memcpy is verified. */ work_ptr -> nx_packet_append_ptr = (UCHAR *)((ALIGN_TYPE)work_ptr -> nx_packet_prepend_ptr + append_size); /* Secondly, calculate the shift data size. */ shift_size = (ULONG)(((ALIGN_TYPE)packet_ptr -> nx_packet_append_ptr - (ALIGN_TYPE)packet_ptr -> nx_packet_prepend_ptr) - append_size); /* Move the data. */ memmove(packet_ptr -> nx_packet_data_start + header_size, packet_ptr -> nx_packet_prepend_ptr, shift_size); /* Use case of memmove is verified. */ /* Update the prepend and append pointer. */ packet_ptr -> nx_packet_prepend_ptr = packet_ptr -> nx_packet_data_start + header_size; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + shift_size; /* At this point, all the necessary packets have been allocated. We need to link this new packet to the next of the supplied packet. *//* ... */ work_ptr -> nx_packet_next = packet_ptr -> nx_packet_next; packet_ptr -> nx_packet_next = work_ptr; /* Update the last packet pointer. */ if (packet_ptr -> nx_packet_last == NX_NULL) { packet_ptr -> nx_packet_last = work_ptr; }if (packet_ptr -> nx_packet_last == NX_NULL) { ... } /* ... */#else /* NX_DISABLE_PACKET_CHAIN */ /* Return error code. */ return(NX_UNDERFLOW);/* ... */ #endif /* !NX_DISABLE_PACKET_CHAIN */ }else { ... } /* Return successful completion. */ return(NX_SUCCESS); }{ ... }