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