1 | /** @file
|
---|
2 | Implementation of transmitting a packet.
|
---|
3 |
|
---|
4 | Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
6 |
|
---|
7 | **/
|
---|
8 |
|
---|
9 | #include "Snp.h"
|
---|
10 |
|
---|
11 | /**
|
---|
12 | Call UNDI to create the meadia header for the given data buffer.
|
---|
13 |
|
---|
14 | @param Snp Pointer to SNP driver structure.
|
---|
15 | @param MacHeaderPtr Address where the media header will be filled in.
|
---|
16 | @param HeaderSize Size of the memory at MacHeaderPtr.
|
---|
17 | @param Buffer Data buffer pointer.
|
---|
18 | @param BufferSize Size of data in the Buffer
|
---|
19 | @param DestAddr Address of the destination mac address buffer.
|
---|
20 | @param SrcAddr Address of the source mac address buffer.
|
---|
21 | @param ProtocolPtr Address of the protocol type.
|
---|
22 |
|
---|
23 | @retval EFI_SUCCESS Successfully completed the undi call.
|
---|
24 | @retval Other Error return from undi call.
|
---|
25 |
|
---|
26 | **/
|
---|
27 | EFI_STATUS
|
---|
28 | PxeFillHeader (
|
---|
29 | SNP_DRIVER *Snp,
|
---|
30 | VOID *MacHeaderPtr,
|
---|
31 | UINTN HeaderSize,
|
---|
32 | VOID *Buffer,
|
---|
33 | UINTN BufferSize,
|
---|
34 | EFI_MAC_ADDRESS *DestAddr,
|
---|
35 | EFI_MAC_ADDRESS *SrcAddr,
|
---|
36 | UINT16 *ProtocolPtr
|
---|
37 | )
|
---|
38 | {
|
---|
39 | PXE_CPB_FILL_HEADER_FRAGMENTED *Cpb;
|
---|
40 |
|
---|
41 | Cpb = Snp->Cpb;
|
---|
42 | if (SrcAddr != NULL) {
|
---|
43 | CopyMem (
|
---|
44 | (VOID *)Cpb->SrcAddr,
|
---|
45 | (VOID *)SrcAddr,
|
---|
46 | Snp->Mode.HwAddressSize
|
---|
47 | );
|
---|
48 | } else {
|
---|
49 | CopyMem (
|
---|
50 | (VOID *)Cpb->SrcAddr,
|
---|
51 | (VOID *)&(Snp->Mode.CurrentAddress),
|
---|
52 | Snp->Mode.HwAddressSize
|
---|
53 | );
|
---|
54 | }
|
---|
55 |
|
---|
56 | CopyMem (
|
---|
57 | (VOID *)Cpb->DestAddr,
|
---|
58 | (VOID *)DestAddr,
|
---|
59 | Snp->Mode.HwAddressSize
|
---|
60 | );
|
---|
61 |
|
---|
62 | //
|
---|
63 | // we need to do the byte swapping
|
---|
64 | //
|
---|
65 | Cpb->Protocol = (UINT16)PXE_SWAP_UINT16 (*ProtocolPtr);
|
---|
66 |
|
---|
67 | Cpb->PacketLen = (UINT32)(BufferSize);
|
---|
68 | Cpb->MediaHeaderLen = (UINT16)HeaderSize;
|
---|
69 |
|
---|
70 | Cpb->FragCnt = 2;
|
---|
71 | Cpb->reserved = 0;
|
---|
72 |
|
---|
73 | Cpb->FragDesc[0].FragAddr = (UINT64)(UINTN)MacHeaderPtr;
|
---|
74 | Cpb->FragDesc[0].FragLen = (UINT32)HeaderSize;
|
---|
75 | Cpb->FragDesc[1].FragAddr = (UINT64)(UINTN)Buffer;
|
---|
76 | Cpb->FragDesc[1].FragLen = (UINT32)BufferSize;
|
---|
77 |
|
---|
78 | Cpb->FragDesc[0].reserved = Cpb->FragDesc[1].reserved = 0;
|
---|
79 |
|
---|
80 | Snp->Cdb.OpCode = PXE_OPCODE_FILL_HEADER;
|
---|
81 | Snp->Cdb.OpFlags = PXE_OPFLAGS_FILL_HEADER_FRAGMENTED;
|
---|
82 |
|
---|
83 | Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;
|
---|
84 | Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;
|
---|
85 |
|
---|
86 | Snp->Cdb.CPBsize = (UINT16)sizeof (PXE_CPB_FILL_HEADER_FRAGMENTED);
|
---|
87 | Snp->Cdb.CPBaddr = (UINT64)(UINTN)Cpb;
|
---|
88 |
|
---|
89 | Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
---|
90 | Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
---|
91 | Snp->Cdb.IFnum = Snp->IfNum;
|
---|
92 | Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
---|
93 |
|
---|
94 | //
|
---|
95 | // Issue UNDI command and check result.
|
---|
96 | //
|
---|
97 | DEBUG ((DEBUG_NET, "\nSnp->undi.fill_header() "));
|
---|
98 |
|
---|
99 | (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
|
---|
100 |
|
---|
101 | switch (Snp->Cdb.StatCode) {
|
---|
102 | case PXE_STATCODE_SUCCESS:
|
---|
103 | return EFI_SUCCESS;
|
---|
104 |
|
---|
105 | case PXE_STATCODE_INVALID_PARAMETER:
|
---|
106 | DEBUG (
|
---|
107 | (DEBUG_ERROR,
|
---|
108 | "\nSnp->undi.fill_header() %xh:%xh\n",
|
---|
109 | Snp->Cdb.StatFlags,
|
---|
110 | Snp->Cdb.StatCode)
|
---|
111 | );
|
---|
112 |
|
---|
113 | return EFI_INVALID_PARAMETER;
|
---|
114 |
|
---|
115 | default:
|
---|
116 | DEBUG (
|
---|
117 | (DEBUG_ERROR,
|
---|
118 | "\nSnp->undi.fill_header() %xh:%xh\n",
|
---|
119 | Snp->Cdb.StatFlags,
|
---|
120 | Snp->Cdb.StatCode)
|
---|
121 | );
|
---|
122 |
|
---|
123 | return EFI_DEVICE_ERROR;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | This routine calls undi to transmit the given data buffer
|
---|
129 |
|
---|
130 | @param Snp pointer to SNP driver structure
|
---|
131 | @param Buffer data buffer pointer
|
---|
132 | @param BufferSize Size of data in the Buffer
|
---|
133 |
|
---|
134 | @retval EFI_SUCCESS if successfully completed the undi call
|
---|
135 | @retval Other error return from undi call.
|
---|
136 |
|
---|
137 | **/
|
---|
138 | EFI_STATUS
|
---|
139 | PxeTransmit (
|
---|
140 | SNP_DRIVER *Snp,
|
---|
141 | VOID *Buffer,
|
---|
142 | UINTN BufferSize
|
---|
143 | )
|
---|
144 | {
|
---|
145 | PXE_CPB_TRANSMIT *Cpb;
|
---|
146 | EFI_STATUS Status;
|
---|
147 |
|
---|
148 | Cpb = Snp->Cpb;
|
---|
149 | Cpb->FrameAddr = (UINT64)(UINTN)Buffer;
|
---|
150 | Cpb->DataLen = (UINT32)BufferSize;
|
---|
151 |
|
---|
152 | Cpb->MediaheaderLen = 0;
|
---|
153 | Cpb->reserved = 0;
|
---|
154 |
|
---|
155 | Snp->Cdb.OpFlags = PXE_OPFLAGS_TRANSMIT_WHOLE;
|
---|
156 |
|
---|
157 | Snp->Cdb.CPBsize = (UINT16)sizeof (PXE_CPB_TRANSMIT);
|
---|
158 | Snp->Cdb.CPBaddr = (UINT64)(UINTN)Cpb;
|
---|
159 |
|
---|
160 | Snp->Cdb.OpCode = PXE_OPCODE_TRANSMIT;
|
---|
161 | Snp->Cdb.DBsize = PXE_DBSIZE_NOT_USED;
|
---|
162 | Snp->Cdb.DBaddr = PXE_DBADDR_NOT_USED;
|
---|
163 |
|
---|
164 | Snp->Cdb.StatCode = PXE_STATCODE_INITIALIZE;
|
---|
165 | Snp->Cdb.StatFlags = PXE_STATFLAGS_INITIALIZE;
|
---|
166 | Snp->Cdb.IFnum = Snp->IfNum;
|
---|
167 | Snp->Cdb.Control = PXE_CONTROL_LAST_CDB_IN_LIST;
|
---|
168 |
|
---|
169 | //
|
---|
170 | // Issue UNDI command and check result.
|
---|
171 | //
|
---|
172 | DEBUG ((DEBUG_NET, "\nSnp->undi.transmit() "));
|
---|
173 | DEBUG ((DEBUG_NET, "\nSnp->Cdb.OpCode == %x", Snp->Cdb.OpCode));
|
---|
174 | DEBUG ((DEBUG_NET, "\nSnp->Cdb.CPBaddr == %LX", Snp->Cdb.CPBaddr));
|
---|
175 | DEBUG ((DEBUG_NET, "\nSnp->Cdb.DBaddr == %LX", Snp->Cdb.DBaddr));
|
---|
176 | DEBUG ((DEBUG_NET, "\nCpb->FrameAddr == %LX\n", Cpb->FrameAddr));
|
---|
177 |
|
---|
178 | (*Snp->IssueUndi32Command)((UINT64)(UINTN)&Snp->Cdb);
|
---|
179 |
|
---|
180 | DEBUG ((DEBUG_NET, "\nexit Snp->undi.transmit() "));
|
---|
181 |
|
---|
182 | //
|
---|
183 | // we will unmap the buffers in get_status call, not here
|
---|
184 | //
|
---|
185 | switch (Snp->Cdb.StatCode) {
|
---|
186 | case PXE_STATCODE_SUCCESS:
|
---|
187 | return EFI_SUCCESS;
|
---|
188 |
|
---|
189 | case PXE_STATCODE_BUFFER_FULL:
|
---|
190 | case PXE_STATCODE_QUEUE_FULL:
|
---|
191 | case PXE_STATCODE_BUSY:
|
---|
192 | Status = EFI_NOT_READY;
|
---|
193 | DEBUG (
|
---|
194 | (DEBUG_NET,
|
---|
195 | "\nSnp->undi.transmit() %xh:%xh\n",
|
---|
196 | Snp->Cdb.StatFlags,
|
---|
197 | Snp->Cdb.StatCode)
|
---|
198 | );
|
---|
199 | break;
|
---|
200 |
|
---|
201 | default:
|
---|
202 | DEBUG (
|
---|
203 | (DEBUG_ERROR,
|
---|
204 | "\nSnp->undi.transmit() %xh:%xh\n",
|
---|
205 | Snp->Cdb.StatFlags,
|
---|
206 | Snp->Cdb.StatCode)
|
---|
207 | );
|
---|
208 | Status = EFI_DEVICE_ERROR;
|
---|
209 | }
|
---|
210 |
|
---|
211 | return Status;
|
---|
212 | }
|
---|
213 |
|
---|
214 | /**
|
---|
215 | Places a packet in the transmit queue of a network interface.
|
---|
216 |
|
---|
217 | This function places the packet specified by Header and Buffer on the transmit
|
---|
218 | queue. If HeaderSize is nonzero and HeaderSize is not equal to
|
---|
219 | This->Mode->MediaHeaderSize, then EFI_INVALID_PARAMETER will be returned. If
|
---|
220 | BufferSize is less than This->Mode->MediaHeaderSize, then EFI_BUFFER_TOO_SMALL
|
---|
221 | will be returned. If Buffer is NULL, then EFI_INVALID_PARAMETER will be
|
---|
222 | returned. If HeaderSize is nonzero and DestAddr or Protocol is NULL, then
|
---|
223 | EFI_INVALID_PARAMETER will be returned. If the transmit engine of the network
|
---|
224 | interface is busy, then EFI_NOT_READY will be returned. If this packet can be
|
---|
225 | accepted by the transmit engine of the network interface, the packet contents
|
---|
226 | specified by Buffer will be placed on the transmit queue of the network
|
---|
227 | interface, and EFI_SUCCESS will be returned. GetStatus() can be used to
|
---|
228 | determine when the packet has actually been transmitted. The contents of the
|
---|
229 | Buffer must not be modified until the packet has actually been transmitted.
|
---|
230 | The Transmit() function performs nonblocking I/O. A caller who wants to perform
|
---|
231 | blocking I/O, should call Transmit(), and then GetStatus() until the
|
---|
232 | transmitted buffer shows up in the recycled transmit buffer.
|
---|
233 | If the driver has not been initialized, EFI_DEVICE_ERROR will be returned.
|
---|
234 |
|
---|
235 | @param This A pointer to the EFI_SIMPLE_NETWORK_PROTOCOL instance.
|
---|
236 | @param HeaderSize The size, in bytes, of the media header to be filled in by the
|
---|
237 | Transmit() function. If HeaderSize is nonzero, then it must
|
---|
238 | be equal to This->Mode->MediaHeaderSize and the DestAddr and
|
---|
239 | Protocol parameters must not be NULL.
|
---|
240 | @param BufferSize The size, in bytes, of the entire packet (media header and
|
---|
241 | data) to be transmitted through the network interface.
|
---|
242 | @param Buffer A pointer to the packet (media header followed by data) to be
|
---|
243 | transmitted. This parameter cannot be NULL. If HeaderSize is
|
---|
244 | zero, then the media header in Buffer must already be filled
|
---|
245 | in by the caller. If HeaderSize is nonzero, then the media
|
---|
246 | header will be filled in by the Transmit() function.
|
---|
247 | @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this
|
---|
248 | parameter is ignored. If HeaderSize is nonzero and SrcAddr
|
---|
249 | is NULL, then This->Mode->CurrentAddress is used for the
|
---|
250 | source HW MAC address.
|
---|
251 | @param DestAddr The destination HW MAC address. If HeaderSize is zero, then
|
---|
252 | this parameter is ignored.
|
---|
253 | @param Protocol The type of header to build. If HeaderSize is zero, then this
|
---|
254 | parameter is ignored. See RFC 1700, section "Ether Types,"
|
---|
255 | for examples.
|
---|
256 |
|
---|
257 | @retval EFI_SUCCESS The packet was placed on the transmit queue.
|
---|
258 | @retval EFI_NOT_STARTED The network interface has not been started.
|
---|
259 | @retval EFI_NOT_READY The network interface is too busy to accept this
|
---|
260 | transmit request.
|
---|
261 | @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.
|
---|
262 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported
|
---|
263 | value.
|
---|
264 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.
|
---|
265 | @retval EFI_UNSUPPORTED This function is not supported by the network interface.
|
---|
266 |
|
---|
267 | **/
|
---|
268 | EFI_STATUS
|
---|
269 | EFIAPI
|
---|
270 | SnpUndi32Transmit (
|
---|
271 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,
|
---|
272 | IN UINTN HeaderSize,
|
---|
273 | IN UINTN BufferSize,
|
---|
274 | IN VOID *Buffer,
|
---|
275 | IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,
|
---|
276 | IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,
|
---|
277 | IN UINT16 *Protocol OPTIONAL
|
---|
278 | )
|
---|
279 | {
|
---|
280 | SNP_DRIVER *Snp;
|
---|
281 | EFI_STATUS Status;
|
---|
282 | EFI_TPL OldTpl;
|
---|
283 |
|
---|
284 | if (This == NULL) {
|
---|
285 | return EFI_INVALID_PARAMETER;
|
---|
286 | }
|
---|
287 |
|
---|
288 | Snp = EFI_SIMPLE_NETWORK_DEV_FROM_THIS (This);
|
---|
289 |
|
---|
290 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
|
---|
291 |
|
---|
292 | if (Snp == NULL) {
|
---|
293 | return EFI_DEVICE_ERROR;
|
---|
294 | }
|
---|
295 |
|
---|
296 | switch (Snp->Mode.State) {
|
---|
297 | case EfiSimpleNetworkInitialized:
|
---|
298 | break;
|
---|
299 |
|
---|
300 | case EfiSimpleNetworkStopped:
|
---|
301 | Status = EFI_NOT_STARTED;
|
---|
302 | goto ON_EXIT;
|
---|
303 |
|
---|
304 | default:
|
---|
305 | Status = EFI_DEVICE_ERROR;
|
---|
306 | goto ON_EXIT;
|
---|
307 | }
|
---|
308 |
|
---|
309 | if (Buffer == NULL) {
|
---|
310 | Status = EFI_INVALID_PARAMETER;
|
---|
311 | goto ON_EXIT;
|
---|
312 | }
|
---|
313 |
|
---|
314 | if (BufferSize < Snp->Mode.MediaHeaderSize) {
|
---|
315 | Status = EFI_BUFFER_TOO_SMALL;
|
---|
316 | goto ON_EXIT;
|
---|
317 | }
|
---|
318 |
|
---|
319 | //
|
---|
320 | // if the HeaderSize is non-zero, we need to fill up the header and for that
|
---|
321 | // we need the destination address and the protocol
|
---|
322 | //
|
---|
323 | if (HeaderSize != 0) {
|
---|
324 | if ((HeaderSize != Snp->Mode.MediaHeaderSize) || (DestAddr == 0) || (Protocol == 0)) {
|
---|
325 | Status = EFI_INVALID_PARAMETER;
|
---|
326 | goto ON_EXIT;
|
---|
327 | }
|
---|
328 |
|
---|
329 | Status = PxeFillHeader (
|
---|
330 | Snp,
|
---|
331 | Buffer,
|
---|
332 | HeaderSize,
|
---|
333 | (UINT8 *)Buffer + HeaderSize,
|
---|
334 | BufferSize - HeaderSize,
|
---|
335 | DestAddr,
|
---|
336 | SrcAddr,
|
---|
337 | Protocol
|
---|
338 | );
|
---|
339 |
|
---|
340 | if (EFI_ERROR (Status)) {
|
---|
341 | goto ON_EXIT;
|
---|
342 | }
|
---|
343 | }
|
---|
344 |
|
---|
345 | Status = PxeTransmit (Snp, Buffer, BufferSize);
|
---|
346 |
|
---|
347 | ON_EXIT:
|
---|
348 | gBS->RestoreTPL (OldTpl);
|
---|
349 |
|
---|
350 | return Status;
|
---|
351 | }
|
---|