40 UdpPacket =
NetbufAlloc (Instance->BlkSize + MTFTP4_DATA_HEAD_LEN);
42 if (UdpPacket ==
NULL) {
43 return EFI_OUT_OF_RESOURCES;
47 ASSERT (Packet !=
NULL);
49 Packet->
Data.OpCode = HTONS (EFI_MTFTP4_OPCODE_DATA);
50 Packet->
Data.Block = HTONS (BlockNum);
55 Token = Instance->Token;
56 DataLen = Instance->BlkSize;
59 Start =
MultU64x32 (BlockNum - 1, Instance->BlkSize);
61 if (Token->
BufferSize < Start + Instance->BlkSize) {
63 Instance->LastBlock = BlockNum;
83 if (EFI_ERROR (Status) || (DataLen > Instance->BlkSize)) {
84 if (DataBuf !=
NULL) {
88 if (UdpPacket !=
NULL) {
94 EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,
95 (UINT8 *)
"User aborted the transfer"
101 if (DataLen < Instance->BlkSize) {
102 Instance->LastBlock = BlockNum;
137 OUT BOOLEAN *Completed
145 AckNum = NTOHS (Packet->Ack.Block[0]);
148 ASSERT (Expected >= 0);
154 if (Expected != AckNum) {
173 if (Instance->LastBlock == AckNum) {
174 ASSERT (Instance->LastBlock >= 1);
180 EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,
181 (UINT8 *)
"Block number rolls back, not supported, try blksize option"
184 return EFI_TFTP_ERROR;
216 if ((Reply->Exist & ~Request->Exist) != 0) {
224 if ((((Reply->Exist & MTFTP4_BLKSIZE_EXIST) != 0) && (Reply->BlkSize > Request->BlkSize)) ||
225 (((Reply->Exist & MTFTP4_TIMEOUT_EXIST) != 0) && (Reply->Timeout != Request->Timeout)))
253 OUT BOOLEAN *Completed
283 if (Status != EFI_OUT_OF_RESOURCES) {
286 EFI_MTFTP4_ERRORCODE_ILLEGAL_OPERATION,
287 (UINT8 *)
"Malformatted OACK packet"
291 return EFI_TFTP_ERROR;
294 if (Reply.BlkSize != 0) {
295 Instance->BlkSize = Reply.BlkSize;
298 if (Reply.Timeout != 0) {
299 Instance->Timeout = Reply.Timeout;
306 Bogus.
Ack.OpCode = HTONS (EFI_MTFTP4_OPCODE_ACK);
307 Bogus.
Ack.Block[0] = 0;
345 NET_CHECK_SIGNATURE (Instance, MTFTP4_PROTOCOL_SIGNATURE);
351 if (EFI_ERROR (IoStatus)) {
356 ASSERT (UdpPacket !=
NULL);
358 if (UdpPacket->TotalSize < MTFTP4_OPCODE_LEN) {
366 if (EndPoint->RemotePort != Instance->ConnectedPort) {
367 if (Instance->ConnectedPort != 0) {
370 Instance->ConnectedPort = EndPoint->RemotePort;
377 Len = UdpPacket->TotalSize;
379 if (UdpPacket->BlockOpNum > 1) {
382 if (Packet ==
NULL) {
383 Status = EFI_OUT_OF_RESOURCES;
387 NetbufCopy (UdpPacket, 0, Len, (UINT8 *)Packet);
390 ASSERT (Packet !=
NULL);
393 Opcode = NTOHS (Packet->
OpCode);
400 ((Opcode == EFI_MTFTP4_OPCODE_OACK) || (Opcode == EFI_MTFTP4_OPCODE_ERROR)))
409 if (EFI_ERROR (Status)) {
413 if (Opcode != EFI_MTFTP4_OPCODE_ERROR) {
416 EFI_MTFTP4_ERRORCODE_REQUEST_DENIED,
417 (UINT8 *)
"User aborted the transfer"
421 Status = EFI_ABORTED;
427 case EFI_MTFTP4_OPCODE_ACK:
428 if (Len != MTFTP4_OPCODE_LEN + MTFTP4_BLKNO_LEN) {
435 case EFI_MTFTP4_OPCODE_OACK:
436 if (Len <= MTFTP4_OPCODE_LEN) {
443 case EFI_MTFTP4_OPCODE_ERROR:
444 Status = EFI_TFTP_ERROR;
456 if ((Packet !=
NULL) && (UdpPacket->BlockOpNum > 1)) {
460 if (UdpPacket !=
NULL) {
464 if (!EFI_ERROR (Status) && !Completed) {
471 if (EFI_ERROR (Status) || Completed) {
506 if (EFI_ERROR (Status)) {
512 if (EFI_ERROR (Status)) {
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID Mtftp4CleanOperation(IN OUT MTFTP4_PROTOCOL *Instance, IN EFI_STATUS Result)
EFI_STATUS Mtftp4ParseOptionOack(IN EFI_MTFTP4_PACKET *Packet, IN UINT32 PacketLen, IN UINT16 Operation, OUT MTFTP4_OPTION *MtftpOption)
EFI_STATUS Mtftp4InitBlockRange(IN LIST_ENTRY *Head, IN UINT16 Start, IN UINT16 End)
VOID Mtftp4SetLastBlockNum(IN LIST_ENTRY *Head, IN UINT16 Last)
EFI_STATUS Mtftp4SendRequest(IN MTFTP4_PROTOCOL *Instance)
INTN Mtftp4GetNextBlockNum(IN LIST_ENTRY *Head)
EFI_STATUS Mtftp4SendError(IN MTFTP4_PROTOCOL *Instance, IN UINT16 ErrCode, IN UINT8 *ErrInfo)
EFI_STATUS Mtftp4RemoveBlockNum(IN LIST_ENTRY *Head, IN UINT16 Num, IN BOOLEAN Completed, OUT UINT64 *BlockCounter)
EFI_STATUS Mtftp4SendPacket(IN OUT MTFTP4_PROTOCOL *Instance, IN OUT NET_BUF *Packet)
EFI_STATUS Mtftp4WrqHandleAck(IN MTFTP4_PROTOCOL *Instance, IN EFI_MTFTP4_PACKET *Packet, IN UINT32 Len, OUT BOOLEAN *Completed)
EFI_STATUS Mtftp4WrqHandleOack(IN OUT MTFTP4_PROTOCOL *Instance, IN EFI_MTFTP4_PACKET *Packet, IN UINT32 Len, OUT BOOLEAN *Completed)
EFI_STATUS Mtftp4WrqStart(IN MTFTP4_PROTOCOL *Instance, IN UINT16 Operation)
VOID EFIAPI Mtftp4WrqInput(IN NET_BUF *UdpPacket, IN UDP_END_POINT *EndPoint, IN EFI_STATUS IoStatus, IN VOID *Context)
BOOLEAN Mtftp4WrqOackValid(IN MTFTP4_OPTION *Reply, IN MTFTP4_OPTION *Request)
EFI_STATUS Mtftp4WrqSendBlock(IN OUT MTFTP4_PROTOCOL *Instance, IN UINT16 BlockNum)
VOID EFIAPI NetbufFree(IN NET_BUF *Nbuf)
UINT32 EFIAPI NetbufCopy(IN NET_BUF *Nbuf, IN UINT32 Offset, IN UINT32 Len, IN UINT8 *Dest)
NET_BUF *EFIAPI NetbufAlloc(IN UINT32 Len)
UINT8 *EFIAPI NetbufAllocSpace(IN OUT NET_BUF *Nbuf, IN UINT32 Len, IN BOOLEAN FromHead)
UINT8 *EFIAPI NetbufGetByte(IN NET_BUF *Nbuf, IN UINT32 Offset, OUT UINT32 *Index OPTIONAL)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS EFIAPI UdpIoRecvDatagram(IN UDP_IO *UdpIo, IN UDP_IO_CALLBACK CallBack, IN VOID *Context, IN UINT32 HeadLen)
EFI_MTFTP4_CHECK_PACKET CheckPacket
EFI_MTFTP4_PACKET_NEEDED PacketNeeded
EFI_MTFTP4_DATA_HEADER Data
EFI_MTFTP4_ACK_HEADER Ack