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