]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | The helper routines to access UDP service. It is used by both\r | |
3 | DHCP and MTFTP.\r | |
4 | \r | |
5 | Copyright (c) 2006 - 2008, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef _UDP4IO_H_\r | |
17 | #define _UDP4IO_H_\r | |
18 | \r | |
19 | #include <Protocol/Udp4.h>\r | |
20 | \r | |
21 | #include <Library/UdpIoLib.h>\r | |
22 | #include <Library/NetLib.h>\r | |
23 | \r | |
24 | typedef struct _UDP_IO_PORT UDP_IO_PORT;\r | |
25 | \r | |
26 | typedef enum {\r | |
27 | UDP_IO_RX_SIGNATURE = SIGNATURE_32 ('U', 'D', 'P', 'R'),\r | |
28 | UDP_IO_TX_SIGNATURE = SIGNATURE_32 ('U', 'D', 'P', 'T'),\r | |
29 | UDP_IO_SIGNATURE = SIGNATURE_32 ('U', 'D', 'P', 'I')\r | |
30 | } UDP_IO_SIGNATURE_TYPE;\r | |
31 | \r | |
32 | typedef struct {\r | |
33 | IP4_ADDR LocalAddr;\r | |
34 | UINT16 LocalPort;\r | |
35 | IP4_ADDR RemoteAddr;\r | |
36 | UINT16 RemotePort;\r | |
37 | } UDP_POINTS;\r | |
38 | \r | |
39 | //\r | |
40 | // This prototype is used by both receive and transmission.\r | |
41 | // When receiving Netbuf is allocated by UDP access point, and\r | |
42 | // released by user. When transmitting, the NetBuf is from user,\r | |
43 | // and provided to the callback as a reference.\r | |
44 | //\r | |
45 | typedef\r | |
46 | VOID\r | |
47 | (*UDP_IO_CALLBACK) (\r | |
48 | IN NET_BUF *Packet,\r | |
49 | IN UDP_POINTS *Points,\r | |
50 | IN EFI_STATUS IoStatus,\r | |
51 | IN VOID *Context\r | |
52 | );\r | |
53 | \r | |
54 | //\r | |
55 | // Each receive request is wrapped in an UDP_RX_TOKEN. Upon completion,\r | |
56 | // the CallBack will be called. Only one receive request is send to UDP.\r | |
57 | // HeadLen gives the length of the application's header. UDP_IO will\r | |
58 | // make the application's header continous before delivery up.\r | |
59 | //\r | |
60 | typedef struct {\r | |
61 | UINT32 Signature;\r | |
62 | UDP_IO_PORT *UdpIo;\r | |
63 | \r | |
64 | UDP_IO_CALLBACK CallBack;\r | |
65 | VOID *Context;\r | |
66 | \r | |
67 | UINT32 HeadLen;\r | |
68 | EFI_UDP4_COMPLETION_TOKEN UdpToken;\r | |
69 | } UDP_RX_TOKEN;\r | |
70 | \r | |
71 | //\r | |
72 | // Each transmit request is wrapped in an UDP_TX_TOKEN. Upon completion,\r | |
73 | // the CallBack will be called. There can be several transmit requests.\r | |
74 | //\r | |
75 | typedef struct {\r | |
76 | UINT32 Signature;\r | |
77 | LIST_ENTRY Link;\r | |
78 | UDP_IO_PORT *UdpIo;\r | |
79 | \r | |
80 | UDP_IO_CALLBACK CallBack;\r | |
81 | NET_BUF *Packet;\r | |
82 | VOID *Context;\r | |
83 | \r | |
84 | EFI_UDP4_SESSION_DATA UdpSession;\r | |
85 | EFI_IPv4_ADDRESS Gateway;\r | |
86 | \r | |
87 | EFI_UDP4_COMPLETION_TOKEN UdpToken;\r | |
88 | EFI_UDP4_TRANSMIT_DATA UdpTxData;\r | |
89 | } UDP_TX_TOKEN;\r | |
90 | \r | |
91 | struct _UDP_IO_PORT {\r | |
92 | UINT32 Signature;\r | |
93 | LIST_ENTRY Link;\r | |
94 | INTN RefCnt;\r | |
95 | \r | |
96 | //\r | |
97 | // Handle used to create/destory UDP child\r | |
98 | //\r | |
99 | EFI_HANDLE Controller;\r | |
100 | EFI_HANDLE Image;\r | |
101 | EFI_HANDLE UdpHandle;\r | |
102 | \r | |
103 | EFI_UDP4_PROTOCOL *Udp;\r | |
104 | EFI_UDP4_CONFIG_DATA UdpConfig;\r | |
105 | EFI_SIMPLE_NETWORK_MODE SnpMode;\r | |
106 | \r | |
107 | LIST_ENTRY SentDatagram;\r | |
108 | UDP_RX_TOKEN *RecvRequest;\r | |
109 | };\r | |
110 | \r | |
111 | typedef\r | |
112 | EFI_STATUS\r | |
113 | (*UDP_IO_CONFIG) (\r | |
114 | IN UDP_IO_PORT *UdpIo,\r | |
115 | IN VOID *Context\r | |
116 | );\r | |
117 | \r | |
118 | typedef\r | |
119 | BOOLEAN\r | |
120 | (*UDP_IO_TO_CANCEL) (\r | |
121 | IN UDP_TX_TOKEN *Token,\r | |
122 | IN VOID *Context\r | |
123 | );\r | |
124 | \r | |
125 | /**\r | |
126 | Create a UDP IO port to access the UDP service. It will\r | |
127 | create and configure a UDP child.\r | |
128 | \r | |
129 | @param Controller The controller that has the UDP service binding\r | |
130 | protocol installed.\r | |
131 | @param Image The image handle for the driver.\r | |
132 | @param Configure The function to configure the created UDP child\r | |
133 | @param Context The opaque parameter for the Configure funtion.\r | |
134 | \r | |
135 | @return A point to just created UDP IO port or NULL if some error happened.\r | |
136 | \r | |
137 | **/\r | |
138 | UDP_IO_PORT *\r | |
139 | EFIAPI\r | |
140 | UdpIoCreatePort (\r | |
141 | IN EFI_HANDLE Controller,\r | |
142 | IN EFI_HANDLE Image,\r | |
143 | IN UDP_IO_CONFIG Configure,\r | |
144 | IN VOID *Context\r | |
145 | );\r | |
146 | \r | |
147 | /**\r | |
148 | Free the UDP IO port and all its related resources including\r | |
149 | all the transmitted packet.\r | |
150 | \r | |
151 | @param UdpIo The UDP IO port to free.\r | |
152 | \r | |
153 | @retval EFI_SUCCESS The UDP IO port is freed.\r | |
154 | \r | |
155 | **/\r | |
156 | EFI_STATUS\r | |
157 | EFIAPI\r | |
158 | UdpIoFreePort (\r | |
159 | IN UDP_IO_PORT *UdpIo\r | |
160 | );\r | |
161 | \r | |
162 | /**\r | |
163 | Clean up the UDP IO port. It will release all the transmitted\r | |
164 | datagrams and receive request. It will also configure NULL the\r | |
165 | UDP child.\r | |
166 | \r | |
167 | @param UdpIo UDP IO port to clean up.\r | |
168 | \r | |
169 | **/\r | |
170 | VOID\r | |
171 | EFIAPI\r | |
172 | UdpIoCleanPort (\r | |
173 | IN UDP_IO_PORT *UdpIo\r | |
174 | );\r | |
175 | \r | |
176 | /**\r | |
177 | Send a packet through the UDP IO port.\r | |
178 | \r | |
179 | @param UdpIo The UDP IO Port to send the packet through\r | |
180 | @param Packet The packet to send\r | |
181 | @param EndPoint The local and remote access point\r | |
182 | @param Gateway The gateway to use\r | |
183 | @param CallBack The call back function to call when packet is\r | |
184 | transmitted or failed.\r | |
185 | @param Context The opque parameter to the CallBack\r | |
186 | \r | |
187 | @retval EFI_OUT_OF_RESOURCES Failed to allocate resource for the packet\r | |
188 | @retval EFI_SUCCESS The packet is successfully delivered to UDP for\r | |
189 | transmission.\r | |
190 | \r | |
191 | **/\r | |
192 | EFI_STATUS\r | |
193 | EFIAPI\r | |
194 | UdpIoSendDatagram (\r | |
195 | IN UDP_IO_PORT *UdpIo,\r | |
196 | IN NET_BUF *Packet,\r | |
197 | IN UDP_POINTS *EndPoint, OPTIONAL\r | |
198 | IN IP4_ADDR Gateway,\r | |
199 | IN UDP_IO_CALLBACK CallBack,\r | |
200 | IN VOID *Context\r | |
201 | );\r | |
202 | \r | |
203 | /**\r | |
204 | Cancel a single sent datagram.\r | |
205 | \r | |
206 | @param UdpIo The UDP IO port to cancel the packet from\r | |
207 | @param Packet The packet to cancel\r | |
208 | \r | |
209 | **/\r | |
210 | VOID\r | |
211 | EFIAPI\r | |
212 | UdpIoCancelSentDatagram (\r | |
213 | IN UDP_IO_PORT *UdpIo,\r | |
214 | IN NET_BUF *Packet\r | |
215 | );\r | |
216 | \r | |
217 | /**\r | |
218 | Issue a receive request to the UDP IO port.\r | |
219 | \r | |
220 | @param UdpIo The UDP IO port to recieve the packet from.\r | |
221 | @param CallBack The call back function to execute when receive\r | |
222 | finished.\r | |
223 | @param Context The opque context to the call back\r | |
224 | @param HeadLen The lenght of the application's header\r | |
225 | \r | |
226 | @retval EFI_ALREADY_STARTED There is already a pending receive request. Only\r | |
227 | one receive request is supported.\r | |
228 | @retval EFI_OUT_OF_RESOURCES Failed to allocate some resource.\r | |
229 | @retval EFI_SUCCESS The receive request is issued successfully.\r | |
230 | \r | |
231 | **/\r | |
232 | EFI_STATUS\r | |
233 | EFIAPI\r | |
234 | UdpIoRecvDatagram (\r | |
235 | IN UDP_IO_PORT *UdpIo,\r | |
236 | IN UDP_IO_CALLBACK CallBack,\r | |
237 | IN VOID *Context,\r | |
238 | IN UINT32 HeadLen\r | |
239 | );\r | |
240 | #endif\r |