]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Support.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Mtftp4Dxe / Mtftp4Support.h
CommitLineData
83cbd279 1/** @file\r
dab714aa 2 Support routines for MTFTP.\r
d1102dba 3\r
0e2a5749 4Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
83cbd279 6\r
83cbd279 7**/\r
8\r
9#ifndef __EFI_MTFTP4_SUPPORT_H__\r
10#define __EFI_MTFTP4_SUPPORT_H__\r
11\r
12//\r
13// The structure representing a range of block numbers, [Start, End].\r
14// It is used to remember the holes in the MTFTP block space. If all\r
15// the holes are filled in, then the download or upload has completed.\r
16//\r
17typedef struct {\r
e48e37fc 18 LIST_ENTRY Link;\r
83cbd279 19 INTN Start;\r
20 INTN End;\r
f1f11ea2 21 INTN Round;\r
22 INTN Bound;\r
83cbd279 23} MTFTP4_BLOCK_RANGE;\r
24\r
25\r
dab714aa 26/**\r
d1102dba
LG
27 Initialize the block range for either RRQ or WRQ.\r
28\r
29 RRQ and WRQ have different requirements for Start and End.\r
30 For example, during start up, WRQ initializes its whole valid block range\r
31 to [0, 0xffff]. This is bacause the server will send us a ACK0 to inform us\r
32 to start the upload. When the client received ACK0, it will remove 0 from the\r
dab714aa 33 range, get the next block number, which is 1, then upload the BLOCK1. For RRQ\r
d1102dba
LG
34 without option negotiation, the server will directly send us the BLOCK1 in\r
35 response to the client's RRQ. When received BLOCK1, the client will remove\r
36 it from the block range and send an ACK. It also works if there is option\r
dab714aa 37 negotiation.\r
38\r
39 @param Head The block range head to initialize\r
40 @param Start The Start block number.\r
41 @param End The last block number.\r
42\r
43 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for initial block range\r
44 @retval EFI_SUCCESS The initial block range is created.\r
45\r
46**/\r
83cbd279 47EFI_STATUS\r
48Mtftp4InitBlockRange (\r
e48e37fc 49 IN LIST_ENTRY *Head,\r
83cbd279 50 IN UINT16 Start,\r
51 IN UINT16 End\r
52 );\r
53\r
dab714aa 54/**\r
55 Get the first valid block number on the range list.\r
56\r
57 @param Head The block range head\r
58\r
d1102dba 59 @return The first valid block number, -1 if the block range is empty.\r
dab714aa 60\r
61**/\r
83cbd279 62INTN\r
63Mtftp4GetNextBlockNum (\r
e48e37fc 64 IN LIST_ENTRY *Head\r
83cbd279 65 );\r
66\r
dab714aa 67/**\r
d1102dba
LG
68 Set the last block number of the block range list.\r
69\r
dab714aa 70 It will remove all the blocks after the Last. MTFTP initialize the block range\r
d1102dba 71 to the maximum possible range, such as [0, 0xffff] for WRQ. When it gets the\r
dab714aa 72 last block number, it will call this function to set the last block number.\r
73\r
74 @param Head The block range list\r
75 @param Last The last block number\r
76\r
77**/\r
83cbd279 78VOID\r
79Mtftp4SetLastBlockNum (\r
e48e37fc 80 IN LIST_ENTRY *Head,\r
83cbd279 81 IN UINT16 Last\r
82 );\r
83\r
dab714aa 84/**\r
85 Remove the block number from the block range list.\r
86\r
87 @param Head The block range list to remove from\r
88 @param Num The block number to remove\r
9202304c
JW
89 @param Completed Whether Num is the last block number.\r
90 @param BlockCounter The continuous block counter instead of the value after roll-over.\r
dab714aa 91\r
92 @retval EFI_NOT_FOUND The block number isn't in the block range list\r
93 @retval EFI_SUCCESS The block number has been removed from the list\r
94 @retval EFI_OUT_OF_RESOURCES Failed to allocate resource\r
95\r
96**/\r
83cbd279 97EFI_STATUS\r
98Mtftp4RemoveBlockNum (\r
e48e37fc 99 IN LIST_ENTRY *Head,\r
f1f11ea2 100 IN UINT16 Num,\r
49fd66cb 101 IN BOOLEAN Completed,\r
9202304c 102 OUT UINT64 *BlockCounter\r
83cbd279 103 );\r
104\r
dab714aa 105/**\r
106 Set the timeout for the instance. User a longer time for passive instances.\r
107\r
108 @param Instance The Mtftp session to set time out\r
109\r
110**/\r
83cbd279 111VOID\r
112Mtftp4SetTimeout (\r
dab714aa 113 IN OUT MTFTP4_PROTOCOL *Instance\r
83cbd279 114 );\r
115\r
dab714aa 116/**\r
d1102dba
LG
117 Send the packet for the instance.\r
118\r
119 It will first save a reference to the packet for later retransmission.\r
120 Then determine the destination port, listen port for requests, and connected\r
dab714aa 121 port for others. At last, send the packet out.\r
122\r
123 @param Instance The Mtftp instance\r
124 @param Packet The packet to send\r
125\r
126 @retval EFI_SUCCESS The packet is sent out\r
127 @retval Others Failed to transmit the packet.\r
128\r
129**/\r
83cbd279 130EFI_STATUS\r
131Mtftp4SendPacket (\r
dab714aa 132 IN OUT MTFTP4_PROTOCOL *Instance,\r
133 IN OUT NET_BUF *Packet\r
83cbd279 134 );\r
135\r
dab714aa 136/**\r
137 Build then transmit the request packet for the MTFTP session.\r
138\r
139 @param Instance The Mtftp session\r
140\r
141 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the request\r
142 @retval EFI_SUCCESS The request is built and sent\r
143 @retval Others Failed to transmit the packet.\r
144\r
145**/\r
83cbd279 146EFI_STATUS\r
147Mtftp4SendRequest (\r
148 IN MTFTP4_PROTOCOL *Instance\r
149 );\r
150\r
dab714aa 151/**\r
152 Build then send an error message.\r
153\r
154 @param Instance The MTFTP session\r
d1102dba 155 @param ErrCode The error code\r
dab714aa 156 @param ErrInfo The error message\r
157\r
158 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory for the error packet\r
159 @retval EFI_SUCCESS The error packet is transmitted.\r
160 @retval Others Failed to transmit the packet.\r
161\r
162**/\r
83cbd279 163EFI_STATUS\r
164Mtftp4SendError (\r
165 IN MTFTP4_PROTOCOL *Instance,\r
166 IN UINT16 ErrCode,\r
dab714aa 167 IN UINT8 *ErrInfo\r
83cbd279 168 );\r
169\r
83cbd279 170\r
0e2a5749
FS
171/**\r
172 The timer ticking function in TPL_NOTIFY level for the Mtftp service instance.\r
173\r
174 @param Event The ticking event\r
175 @param Context The Mtftp service instance\r
176\r
177**/\r
178VOID\r
179EFIAPI\r
180Mtftp4OnTimerTickNotifyLevel (\r
181 IN EFI_EVENT Event,\r
182 IN VOID *Context\r
183 );\r
184\r
dab714aa 185/**\r
186 The timer ticking function for the Mtftp service instance.\r
187\r
188 @param Event The ticking event\r
189 @param Context The Mtftp service instance\r
190\r
191**/\r
83cbd279 192VOID\r
193EFIAPI\r
194Mtftp4OnTimerTick (\r
195 IN EFI_EVENT Event,\r
196 IN VOID *Context\r
197 );\r
198#endif\r