]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Rrq.c
Fix a bug that mtftp4 driver reply 2 ACK in answer to incoming No.65535 block data...
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Rrq.c
1 /** @file
2 Routines to process Rrq (download).
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php<BR>
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "Mtftp4Impl.h"
17
18
19 /**
20 The packet process callback for MTFTP download.
21
22 @param UdpPacket The packet received
23 @param EndPoint The local/remote access point of the packet
24 @param IoStatus The status of the receiving
25 @param Context Opaque parameter, which is the MTFTP session
26
27 **/
28 VOID
29 EFIAPI
30 Mtftp4RrqInput (
31 IN NET_BUF *UdpPacket,
32 IN UDP_END_POINT *EndPoint,
33 IN EFI_STATUS IoStatus,
34 IN VOID *Context
35 );
36
37
38 /**
39 Start the MTFTP session to download.
40
41 It will first initialize some of the internal states then build and send a RRQ
42 reqeuest packet, at last, it will start receive for the downloading.
43
44 @param Instance The Mtftp session
45 @param Operation The MTFTP opcode, it may be a EFI_MTFTP4_OPCODE_RRQ
46 or EFI_MTFTP4_OPCODE_DIR.
47
48 @retval EFI_SUCCESS The mtftp download session is started.
49 @retval Others Failed to start downloading.
50
51 **/
52 EFI_STATUS
53 Mtftp4RrqStart (
54 IN MTFTP4_PROTOCOL *Instance,
55 IN UINT16 Operation
56 )
57 {
58 EFI_STATUS Status;
59
60 //
61 // The valid block number range are [1, 0xffff]. For example:
62 // the client sends an RRQ request to the server, the server
63 // transfers the DATA1 block. If option negoitation is ongoing,
64 // the server will send back an OACK, then client will send ACK0.
65 //
66 Status = Mtftp4InitBlockRange (&Instance->Blocks, 1, 0xffff);
67
68 if (EFI_ERROR (Status)) {
69 return Status;
70 }
71
72 Status = Mtftp4SendRequest (Instance);
73
74 if (EFI_ERROR (Status)) {
75 return Status;
76 }
77
78 return UdpIoRecvDatagram (Instance->UnicastPort, Mtftp4RrqInput, Instance, 0);
79 }
80
81
82 /**
83 Build and send a ACK packet for the download session.
84
85 @param Instance The Mtftp session
86 @param BlkNo The BlkNo to ack.
87
88 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the packet
89 @retval EFI_SUCCESS The ACK has been sent
90 @retval Others Failed to send the ACK.
91
92 **/
93 EFI_STATUS
94 Mtftp4RrqSendAck (
95 IN MTFTP4_PROTOCOL *Instance,
96 IN UINT16 BlkNo
97 )
98 {
99 EFI_MTFTP4_PACKET *Ack;
100 NET_BUF *Packet;
101
102 Packet = NetbufAlloc (sizeof (EFI_MTFTP4_ACK_HEADER));
103 if (Packet == NULL) {
104 return EFI_OUT_OF_RESOURCES;
105 }
106
107 Ack = (EFI_MTFTP4_PACKET *) NetbufAllocSpace (
108 Packet,
109 sizeof (EFI_MTFTP4_ACK_HEADER),
110 FALSE
111 );
112 ASSERT (Ack != NULL);
113
114 Ack->Ack.OpCode = HTONS (EFI_MTFTP4_OPCODE_ACK);
115 Ack->Ack.Block[0] = HTONS (BlkNo);
116
117 return Mtftp4SendPacket (Instance, Packet);
118 }
119
120
121 /**
122 Deliver the received data block to the user, which can be saved
123 in the user provide buffer or through the CheckPacket callback.
124
125 @param Instance The Mtftp session
126 @param Packet The received data packet
127 @param Len The packet length
128
129 @retval EFI_SUCCESS The data is saved successfully
130 @retval EFI_ABORTED The user tells to abort by return an error through
131 CheckPacket
132 @retval EFI_BUFFER_TOO_SMALL The user's buffer is too small and buffer length is
133 updated to the actual buffer size needed.
134
135 **/
136 EFI_STATUS
137 Mtftp4RrqSaveBlock (
138 IN OUT MTFTP4_PROTOCOL *Instance,
139 IN EFI_MTFTP4_PACKET *Packet,
140 IN UINT32 Len
141 )
142 {
143 EFI_MTFTP4_TOKEN *Token;
144 EFI_STATUS Status;
145 UINT16 Block;
146 UINT64 Start;
147 UINT32 DataLen;
148 UINT64 TotalBlock;
149 BOOLEAN Completed;
150
151 Completed = FALSE;
152 Token = Instance->Token;
153 Block = NTOHS (Packet->Data.Block);
154 DataLen = Len - MTFTP4_DATA_HEAD_LEN;
155
156 //
157 // This is the last block, save the block no
158 //
159 if (DataLen < Instance->BlkSize) {
160 Completed = TRUE;
161 Instance->LastBlock = Block;
162 Mtftp4SetLastBlockNum (&Instance->Blocks, Block);
163 }
164
165 //
166 // Remove this block number from the file hole. If Mtftp4RemoveBlockNum
167 // returns EFI_NOT_FOUND, the block has been saved, don't save it again.
168 // Note that : For bigger files, allowing the block counter to roll over
169 // to accept transfers of unlimited size. So TotalBlock is memorised as
170 // continuous block counter.
171 //
172 Status = Mtftp4RemoveBlockNum (&Instance->Blocks, Block, Completed, &TotalBlock);
173
174 if (Status == EFI_NOT_FOUND) {
175 return EFI_SUCCESS;
176 } else if (EFI_ERROR (Status)) {
177 return Status;
178 }
179
180 if (Token->CheckPacket != NULL) {
181 Status = Token->CheckPacket (&Instance->Mtftp4, Token, (UINT16) Len, Packet);
182
183 if (EFI_ERROR (Status)) {
184 Mtftp4SendError (
185 Instance,
186 EFI_MTFTP4_ERRORCODE_ILLEGAL_OPERATION,
187 (UINT8 *) "User aborted download"
188 );
189
190 return EFI_ABORTED;
191 }
192 }
193
194 if (Token->Buffer != NULL) {
195 Start = MultU64x32 (TotalBlock - 1, Instance->BlkSize);
196
197 if (Start + DataLen <= Token->BufferSize) {
198 CopyMem ((UINT8 *) Token->Buffer + Start, Packet->Data.Data, DataLen);
199
200 //
201 // Update the file size when received the last block
202 //
203 if ((Instance->LastBlock == Block) && Completed) {
204 Token->BufferSize = Start + DataLen;
205 }
206
207 } else if (Instance->LastBlock != 0) {
208 //
209 // Don't save the data if the buffer is too small, return
210 // EFI_BUFFER_TOO_SMALL if received the last packet. This
211 // will give a accurate file length.
212 //
213 Token->BufferSize = Start + DataLen;
214
215 Mtftp4SendError (
216 Instance,
217 EFI_MTFTP4_ERRORCODE_DISK_FULL,
218 (UINT8 *) "User provided memory block is too small"
219 );
220
221 return EFI_BUFFER_TOO_SMALL;
222 }
223 }
224
225 return EFI_SUCCESS;
226 }
227
228
229 /**
230 Function to process the received data packets.
231
232 It will save the block then send back an ACK if it is active.
233
234 @param Instance The downloading MTFTP session
235 @param Packet The packet received
236 @param Len The length of the packet
237 @param Multicast Whether this packet is multicast or unicast
238 @param Completed Return whether the download has completed
239
240 @retval EFI_SUCCESS The data packet is successfully processed
241 @retval EFI_ABORTED The download is aborted by the user
242 @retval EFI_BUFFER_TOO_SMALL The user provided buffer is too small
243
244 **/
245 EFI_STATUS
246 Mtftp4RrqHandleData (
247 IN MTFTP4_PROTOCOL *Instance,
248 IN EFI_MTFTP4_PACKET *Packet,
249 IN UINT32 Len,
250 IN BOOLEAN Multicast,
251 OUT BOOLEAN *Completed
252 )
253 {
254 EFI_STATUS Status;
255 UINT16 BlockNum;
256 INTN Expected;
257
258 *Completed = FALSE;
259 BlockNum = NTOHS (Packet->Data.Block);
260 Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
261
262 ASSERT (Expected >= 0);
263
264 //
265 // If we are active and received an unexpected packet, retransmit
266 // the last ACK then restart receiving. If we are passive, save
267 // the block.
268 //
269 if (Instance->Master && (Expected != BlockNum)) {
270 Mtftp4Retransmit (Instance);
271 return EFI_SUCCESS;
272 }
273
274 Status = Mtftp4RrqSaveBlock (Instance, Packet, Len);
275
276 if (EFI_ERROR (Status)) {
277 return Status;
278 }
279
280 //
281 // Reset the passive client's timer whenever it received a
282 // valid data packet.
283 //
284 if (!Instance->Master) {
285 Mtftp4SetTimeout (Instance);
286 }
287
288 //
289 // Check whether we have received all the blocks. Send the ACK if we
290 // are active (unicast client or master client for multicast download).
291 // If we have received all the blocks, send an ACK even if we are passive
292 // to tell the server that we are done.
293 //
294 Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
295
296 if (Instance->Master || (Expected < 0)) {
297 if (Expected < 0) {
298 //
299 // If we are passive client, then the just received Block maybe
300 // isn't the last block. We need to send an ACK to the last block
301 // to inform the server that we are done. If we are active client,
302 // the Block == Instance->LastBlock.
303 //
304 BlockNum = Instance->LastBlock;
305 *Completed = TRUE;
306
307 } else {
308 BlockNum = (UINT16) (Expected - 1);
309 }
310
311 Mtftp4RrqSendAck (Instance, BlockNum);
312 }
313
314 return EFI_SUCCESS;
315 }
316
317
318 /**
319 Validate whether the options received in the server's OACK packet is valid.
320
321 The options are valid only if:
322 1. The server doesn't include options not requested by us
323 2. The server can only use smaller blksize than that is requested
324 3. The server can only use the same timeout as requested
325 4. The server doesn't change its multicast channel.
326
327 @param This The downloading Mtftp session
328 @param Reply The options in the OACK packet
329 @param Request The requested options
330
331 @retval TRUE The options in the OACK is OK.
332 @retval FALSE The options in the OACK is invalid.
333
334 **/
335 BOOLEAN
336 Mtftp4RrqOackValid (
337 IN MTFTP4_PROTOCOL *This,
338 IN MTFTP4_OPTION *Reply,
339 IN MTFTP4_OPTION *Request
340 )
341 {
342
343 //
344 // It is invalid for server to return options we don't request
345 //
346 if ((Reply->Exist &~Request->Exist) != 0) {
347 return FALSE;
348 }
349
350 //
351 // Server can only specify a smaller block size to be used and
352 // return the timeout matches that requested.
353 //
354 if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) != 0)&& (Reply->BlkSize > Request->BlkSize)) ||
355 (((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout))) {
356 return FALSE;
357 }
358
359 //
360 // The server can send ",,master" to client to change its master
361 // setting. But if it use the specific multicast channel, it can't
362 // change the setting.
363 //
364 if (((Reply->Exist & MTFTP4_MCAST_EXIST) != 0) && (This->McastIp != 0)) {
365 if ((Reply->McastIp != 0) && (Reply->McastIp != This->McastIp)) {
366 return FALSE;
367 }
368
369 if ((Reply->McastPort != 0) && (Reply->McastPort != This->McastPort)) {
370 return FALSE;
371 }
372 }
373
374 return TRUE;
375 }
376
377
378 /**
379 Configure a UDP IO port to receive the multicast.
380
381 @param McastIo The UDP IO to configure
382 @param Context The opaque parameter to the function which is the
383 MTFTP session.
384
385 @retval EFI_SUCCESS The UDP child is successfully configured.
386 @retval Others Failed to configure the UDP child.
387
388 **/
389 EFI_STATUS
390 EFIAPI
391 Mtftp4RrqConfigMcastPort (
392 IN UDP_IO *McastIo,
393 IN VOID *Context
394 )
395 {
396 MTFTP4_PROTOCOL *Instance;
397 EFI_MTFTP4_CONFIG_DATA *Config;
398 EFI_UDP4_CONFIG_DATA UdpConfig;
399 EFI_IPv4_ADDRESS Group;
400 EFI_STATUS Status;
401 IP4_ADDR Ip;
402
403 Instance = (MTFTP4_PROTOCOL *) Context;
404 Config = &Instance->Config;
405
406 UdpConfig.AcceptBroadcast = FALSE;
407 UdpConfig.AcceptPromiscuous = FALSE;
408 UdpConfig.AcceptAnyPort = FALSE;
409 UdpConfig.AllowDuplicatePort = FALSE;
410 UdpConfig.TypeOfService = 0;
411 UdpConfig.TimeToLive = 64;
412 UdpConfig.DoNotFragment = FALSE;
413 UdpConfig.ReceiveTimeout = 0;
414 UdpConfig.TransmitTimeout = 0;
415 UdpConfig.UseDefaultAddress = Config->UseDefaultSetting;
416 UdpConfig.StationAddress = Config->StationIp;
417 UdpConfig.SubnetMask = Config->SubnetMask;
418 UdpConfig.StationPort = Instance->McastPort;
419 UdpConfig.RemotePort = 0;
420
421 Ip = HTONL (Instance->ServerIp);
422 CopyMem (&UdpConfig.RemoteAddress, &Ip, sizeof (EFI_IPv4_ADDRESS));
423
424 Status = McastIo->Protocol.Udp4->Configure (McastIo->Protocol.Udp4, &UdpConfig);
425
426 if (EFI_ERROR (Status)) {
427 return Status;
428 }
429
430 if (!Config->UseDefaultSetting &&
431 !EFI_IP4_EQUAL (&mZeroIp4Addr, &Config->GatewayIp)) {
432 //
433 // The station IP address is manually configured and the Gateway IP is not 0.
434 // Add the default route for this UDP instance.
435 //
436 Status = McastIo->Protocol.Udp4->Routes (
437 McastIo->Protocol.Udp4,
438 FALSE,
439 &mZeroIp4Addr,
440 &mZeroIp4Addr,
441 &Config->GatewayIp
442 );
443
444 if (EFI_ERROR (Status)) {
445 McastIo->Protocol.Udp4->Configure (McastIo->Protocol.Udp4, NULL);
446 return Status;
447 }
448 }
449
450 //
451 // join the multicast group
452 //
453 Ip = HTONL (Instance->McastIp);
454 CopyMem (&Group, &Ip, sizeof (EFI_IPv4_ADDRESS));
455
456 return McastIo->Protocol.Udp4->Groups (McastIo->Protocol.Udp4, TRUE, &Group);
457 }
458
459
460 /**
461 Function to process the OACK.
462
463 It will first validate the OACK packet, then update the various negotiated parameters.
464
465 @param Instance The download MTFTP session
466 @param Packet The packet received
467 @param Len The packet length
468 @param Multicast Whether this packet is received as a multicast
469 @param Completed Returns whether the download has completed. NOT
470 used by this function.
471
472 @retval EFI_DEVICE_ERROR Failed to create/start a multicast UDP child
473 @retval EFI_TFTP_ERROR Some error happened during the process
474 @retval EFI_SUCCESS The OACK is successfully processed.
475
476 **/
477 EFI_STATUS
478 Mtftp4RrqHandleOack (
479 IN OUT MTFTP4_PROTOCOL *Instance,
480 IN EFI_MTFTP4_PACKET *Packet,
481 IN UINT32 Len,
482 IN BOOLEAN Multicast,
483 OUT BOOLEAN *Completed
484 )
485 {
486 MTFTP4_OPTION Reply;
487 EFI_STATUS Status;
488 INTN Expected;
489
490 *Completed = FALSE;
491
492 //
493 // If already started the master download, don't change the
494 // setting. Master download always succeeds.
495 //
496 Expected = Mtftp4GetNextBlockNum (&Instance->Blocks);
497 ASSERT (Expected != -1);
498
499 if (Instance->Master && (Expected != 1)) {
500 return EFI_SUCCESS;
501 }
502
503 //
504 // Parse and validate the options from server
505 //
506 ZeroMem (&Reply, sizeof (MTFTP4_OPTION));
507
508 Status = Mtftp4ParseOptionOack (Packet, Len, &Reply);
509
510 if (EFI_ERROR (Status) ||
511 !Mtftp4RrqOackValid (Instance, &Reply, &Instance->RequestOption)) {
512 //
513 // Don't send an ERROR packet if the error is EFI_OUT_OF_RESOURCES.
514 //
515 if (Status != EFI_OUT_OF_RESOURCES) {
516 Mtftp4SendError (
517 Instance,
518 EFI_MTFTP4_ERRORCODE_ILLEGAL_OPERATION,
519 (UINT8 *) "Mal-formated OACK packet"
520 );
521 }
522
523 return EFI_TFTP_ERROR;
524 }
525
526 if ((Reply.Exist & MTFTP4_MCAST_EXIST) != 0) {
527
528 //
529 // Save the multicast info. Always update the Master, only update the
530 // multicast IP address, block size, timeoute at the first time. If IP
531 // address is updated, create a UDP child to receive the multicast.
532 //
533 Instance->Master = Reply.Master;
534
535 if (Instance->McastIp == 0) {
536 if ((Reply.McastIp == 0) || (Reply.McastPort == 0)) {
537 Mtftp4SendError (
538 Instance,
539 EFI_MTFTP4_ERRORCODE_ILLEGAL_OPERATION,
540 (UINT8 *) "Illegal multicast setting"
541 );
542
543 return EFI_TFTP_ERROR;
544 }
545
546 //
547 // Create a UDP child then start receive the multicast from it.
548 //
549 Instance->McastIp = Reply.McastIp;
550 Instance->McastPort = Reply.McastPort;
551 Instance->McastUdpPort = UdpIoCreateIo (
552 Instance->Service->Controller,
553 Instance->Service->Image,
554 Mtftp4RrqConfigMcastPort,
555 UDP_IO_UDP4_VERSION,
556 Instance
557 );
558
559 if (Instance->McastUdpPort == NULL) {
560 return EFI_DEVICE_ERROR;
561 }
562
563 Status = UdpIoRecvDatagram (Instance->McastUdpPort, Mtftp4RrqInput, Instance, 0);
564
565 if (EFI_ERROR (Status)) {
566 Mtftp4SendError (
567 Instance,
568 EFI_MTFTP4_ERRORCODE_ACCESS_VIOLATION,
569 (UINT8 *) "Failed to create socket to receive multicast packet"
570 );
571
572 return Status;
573 }
574
575 //
576 // Update the parameters used.
577 //
578 if (Reply.BlkSize != 0) {
579 Instance->BlkSize = Reply.BlkSize;
580 }
581
582 if (Reply.Timeout != 0) {
583 Instance->Timeout = Reply.Timeout;
584 }
585 }
586
587 } else {
588 Instance->Master = TRUE;
589
590 if (Reply.BlkSize != 0) {
591 Instance->BlkSize = Reply.BlkSize;
592 }
593
594 if (Reply.Timeout != 0) {
595 Instance->Timeout = Reply.Timeout;
596 }
597 }
598
599 //
600 // Send an ACK to (Expected - 1) which is 0 for unicast download,
601 // or tell the server we want to receive the Expected block.
602 //
603 return Mtftp4RrqSendAck (Instance, (UINT16) (Expected - 1));
604 }
605
606
607 /**
608 The packet process callback for MTFTP download.
609
610 @param UdpPacket The packet received
611 @param EndPoint The local/remote access point of the packet
612 @param IoStatus The status of the receiving
613 @param Context Opaque parameter, which is the MTFTP session
614
615 **/
616 VOID
617 EFIAPI
618 Mtftp4RrqInput (
619 IN NET_BUF *UdpPacket,
620 IN UDP_END_POINT *EndPoint,
621 IN EFI_STATUS IoStatus,
622 IN VOID *Context
623 )
624 {
625 MTFTP4_PROTOCOL *Instance;
626 EFI_MTFTP4_PACKET *Packet;
627 BOOLEAN Completed;
628 BOOLEAN Multicast;
629 EFI_STATUS Status;
630 UINT16 Opcode;
631 UINT32 Len;
632
633 Instance = (MTFTP4_PROTOCOL *) Context;
634 NET_CHECK_SIGNATURE (Instance, MTFTP4_PROTOCOL_SIGNATURE);
635
636 Status = EFI_SUCCESS;
637 Packet = NULL;
638 Completed = FALSE;
639 Multicast = FALSE;
640
641 if (EFI_ERROR (IoStatus)) {
642 Status = IoStatus;
643 goto ON_EXIT;
644 }
645
646 ASSERT (UdpPacket != NULL);
647
648 //
649 // Find the port this packet is from to restart receive correctly.
650 //
651 Multicast = (BOOLEAN) (EndPoint->LocalAddr.Addr[0] == Instance->McastIp);
652
653 if (UdpPacket->TotalSize < MTFTP4_OPCODE_LEN) {
654 goto ON_EXIT;
655 }
656
657 //
658 // Client send initial request to server's listening port. Server
659 // will select a UDP port to communicate with the client. The server
660 // is required to use the same port as RemotePort to multicast the
661 // data.
662 //
663 if (EndPoint->RemotePort != Instance->ConnectedPort) {
664 if (Instance->ConnectedPort != 0) {
665 goto ON_EXIT;
666 } else {
667 Instance->ConnectedPort = EndPoint->RemotePort;
668 }
669 }
670
671 //
672 // Copy the MTFTP packet to a continuous buffer if it isn't already so.
673 //
674 Len = UdpPacket->TotalSize;
675
676 if (UdpPacket->BlockOpNum > 1) {
677 Packet = AllocatePool (Len);
678
679 if (Packet == NULL) {
680 Status = EFI_OUT_OF_RESOURCES;
681 goto ON_EXIT;
682 }
683
684 NetbufCopy (UdpPacket, 0, Len, (UINT8 *) Packet);
685
686 } else {
687 Packet = (EFI_MTFTP4_PACKET *) NetbufGetByte (UdpPacket, 0, NULL);
688 }
689
690 Opcode = NTOHS (Packet->OpCode);
691
692 //
693 // Call the user's CheckPacket if provided. Abort the transmission
694 // if CheckPacket returns an EFI_ERROR code.
695 //
696 if ((Instance->Token->CheckPacket != NULL) &&
697 ((Opcode == EFI_MTFTP4_OPCODE_OACK) || (Opcode == EFI_MTFTP4_OPCODE_ERROR))) {
698
699 Status = Instance->Token->CheckPacket (
700 &Instance->Mtftp4,
701 Instance->Token,
702 (UINT16) Len,
703 Packet
704 );
705
706 if (EFI_ERROR (Status)) {
707 //
708 // Send an error message to the server to inform it
709 //
710 if (Opcode != EFI_MTFTP4_OPCODE_ERROR) {
711 Mtftp4SendError (
712 Instance,
713 EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,
714 (UINT8 *) "User aborted the transfer"
715 );
716 }
717
718 Status = EFI_ABORTED;
719 goto ON_EXIT;
720 }
721 }
722
723 switch (Opcode) {
724 case EFI_MTFTP4_OPCODE_DATA:
725 if ((Len > (UINT32) (MTFTP4_DATA_HEAD_LEN + Instance->BlkSize)) ||
726 (Len < (UINT32) MTFTP4_DATA_HEAD_LEN)) {
727 goto ON_EXIT;
728 }
729
730 Status = Mtftp4RrqHandleData (Instance, Packet, Len, Multicast, &Completed);
731 break;
732
733 case EFI_MTFTP4_OPCODE_OACK:
734 if (Multicast || (Len <= MTFTP4_OPCODE_LEN)) {
735 goto ON_EXIT;
736 }
737
738 Status = Mtftp4RrqHandleOack (Instance, Packet, Len, Multicast, &Completed);
739 break;
740
741 case EFI_MTFTP4_OPCODE_ERROR:
742 Status = EFI_TFTP_ERROR;
743 break;
744
745 default:
746 break;
747 }
748
749 ON_EXIT:
750
751 //
752 // Free the resources, then if !EFI_ERROR (Status), restart the
753 // receive, otherwise end the session.
754 //
755 if ((Packet != NULL) && (UdpPacket->BlockOpNum > 1)) {
756 FreePool (Packet);
757 }
758
759 if (UdpPacket != NULL) {
760 NetbufFree (UdpPacket);
761 }
762
763 if (!EFI_ERROR (Status) && !Completed) {
764 if (Multicast) {
765 Status = UdpIoRecvDatagram (Instance->McastUdpPort, Mtftp4RrqInput, Instance, 0);
766 } else {
767 Status = UdpIoRecvDatagram (Instance->UnicastPort, Mtftp4RrqInput, Instance, 0);
768 }
769 }
770
771 if (EFI_ERROR (Status) || Completed) {
772 Mtftp4CleanOperation (Instance, Status);
773 }
774 }