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