]>
Commit | Line | Data |
---|---|---|
83cbd279 | 1 | /** @file\r |
2 | \r | |
dfc1f033 | 3 | Copyright (c) 2005 - 2006, Intel Corporation<BR>\r |
83cbd279 | 4 | All rights reserved. This program and the accompanying materials\r |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
dfc1f033 | 7 | http://opensource.org/licenses/bsd-license.php<BR>\r |
83cbd279 | 8 | \r |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
83cbd279 | 12 | **/\r |
13 | \r | |
14 | #ifndef _SOCKET_H_\r | |
15 | #define _SOCKET_H_\r | |
16 | \r | |
8a67d61d | 17 | #include <PiDxe.h>\r |
18 | \r | |
eaf343ff | 19 | #include <Protocol/Ip4.h>\r |
83cbd279 | 20 | #include <Protocol/Tcp4.h>\r |
8a67d61d | 21 | #include <Protocol/Udp4.h>\r |
83cbd279 | 22 | \r |
8a67d61d | 23 | #include <Library/NetLib.h>\r |
24 | #include <Library/DebugLib.h>\r | |
25 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
26 | #include <Library/UefiDriverEntryPoint.h>\r | |
27 | #include <Library/UefiBootServicesTableLib.h>\r | |
28 | #include <Library/BaseLib.h>\r | |
83cbd279 | 29 | #include <Library/UefiLib.h>\r |
30 | #include <Library/MemoryAllocationLib.h>\r | |
31 | #include <Library/BaseMemoryLib.h>\r | |
32 | \r | |
33 | #define SOCK_SND_BUF 0\r | |
34 | #define SOCK_RCV_BUF 1\r | |
35 | \r | |
dfc1f033 | 36 | #define SOCK_BUFF_LOW_WATER (2 * 1024)\r |
37 | #define SOCK_RCV_BUFF_SIZE (8 * 1024)\r | |
38 | #define SOCK_SND_BUFF_SIZE (8 * 1024)\r | |
83cbd279 | 39 | #define SOCK_BACKLOG 5\r |
40 | \r | |
41 | #define PROTO_RESERVED_LEN 20\r | |
42 | \r | |
43 | #define SO_NO_MORE_DATA 0x0001\r | |
44 | \r | |
45 | //\r | |
46 | //\r | |
47 | //\r | |
48 | // When a socket is created it enters into SO_UNCONFIGURED,\r | |
49 | // no actions can be taken on this socket, only after calling\r | |
50 | // SockConfigure. The state transition diagram of socket is\r | |
51 | // as following:\r | |
52 | //\r | |
53 | // SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING\r | |
54 | // ^ | |\r | |
55 | // | ---> SO_LISTENING |\r | |
56 | // | |\r | |
57 | // |------------------SO_DISCONNECTING<-- SO_CONNECTED\r | |
58 | //\r | |
59 | // A passive socket can only go into SO_LISTENING and\r | |
60 | // SO_UNCONFIGURED state. SO_XXXING state is a middle state\r | |
61 | // when a socket is undergoing a protocol procedure such\r | |
62 | // as requesting a TCP connection.\r | |
63 | //\r | |
64 | //\r | |
65 | //\r | |
dfc1f033 | 66 | \r |
67 | ///\r | |
68 | /// Socket state\r | |
69 | ///\r | |
83cbd279 | 70 | typedef enum {\r |
71 | SO_CLOSED = 0,\r | |
72 | SO_LISTENING,\r | |
73 | SO_CONNECTING,\r | |
74 | SO_CONNECTED,\r | |
75 | SO_DISCONNECTING\r | |
76 | } SOCK_STATE;\r | |
77 | \r | |
dfc1f033 | 78 | ///\r |
79 | /// Socket configure state\r | |
80 | ///\r | |
83cbd279 | 81 | typedef enum {\r |
82 | SO_UNCONFIGURED = 0,\r | |
83 | SO_CONFIGURED_ACTIVE,\r | |
84 | SO_CONFIGURED_PASSIVE,\r | |
85 | SO_NO_MAPPING\r | |
86 | } SOCK_CONFIGURE_STATE;\r | |
87 | \r | |
88 | #define SOCK_NO_MORE_DATA(Sock) ((Sock)->Flag |= SO_NO_MORE_DATA)\r | |
89 | \r | |
90 | #define SOCK_IS_UNCONFIGURED(Sock) ((Sock)->ConfigureState == SO_UNCONFIGURED)\r | |
91 | \r | |
92 | #define SOCK_IS_CONFIGURED(Sock) \\r | |
93 | (((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE) || \\r | |
94 | ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE))\r | |
95 | \r | |
96 | #define SOCK_IS_CONFIGURED_ACTIVE(Sock) \\r | |
97 | ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)\r | |
98 | \r | |
99 | #define SOCK_IS_CONNECTED_PASSIVE(Sock) \\r | |
100 | ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)\r | |
101 | \r | |
102 | #define SOCK_IS_NO_MAPPING(Sock) \\r | |
103 | ((Sock)->ConfigureState == SO_NO_MAPPING)\r | |
104 | \r | |
dfc1f033 | 105 | #define SOCK_IS_CLOSED(Sock) ((Sock)->State == SO_CLOSED)\r |
83cbd279 | 106 | \r |
dfc1f033 | 107 | #define SOCK_IS_LISTENING(Sock) ((Sock)->State == SO_LISTENING)\r |
83cbd279 | 108 | \r |
dfc1f033 | 109 | #define SOCK_IS_CONNECTING(Sock) ((Sock)->State == SO_CONNECTING)\r |
83cbd279 | 110 | \r |
dfc1f033 | 111 | #define SOCK_IS_CONNECTED(Sock) ((Sock)->State == SO_CONNECTED)\r |
83cbd279 | 112 | \r |
dfc1f033 | 113 | #define SOCK_IS_DISCONNECTING(Sock) ((Sock)->State == SO_DISCONNECTING)\r |
83cbd279 | 114 | \r |
dfc1f033 | 115 | #define SOCK_IS_NO_MORE_DATA(Sock) (0 != ((Sock)->Flag & SO_NO_MORE_DATA))\r |
83cbd279 | 116 | \r |
7dc2fc3d | 117 | #define SOCK_SIGNATURE SIGNATURE_32 ('S', 'O', 'C', 'K')\r |
83cbd279 | 118 | \r |
dfc1f033 | 119 | #define SOCK_FROM_THIS(a) CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)\r |
83cbd279 | 120 | \r |
121 | #define SET_RCV_BUFFSIZE(Sock, Size) ((Sock)->RcvBuffer.HighWater = (Size))\r | |
122 | \r | |
123 | #define GET_RCV_BUFFSIZE(Sock) ((Sock)->RcvBuffer.HighWater)\r | |
124 | \r | |
125 | #define GET_RCV_DATASIZE(Sock) (((Sock)->RcvBuffer.DataQueue)->BufSize)\r | |
126 | \r | |
127 | #define SET_SND_BUFFSIZE(Sock, Size) ((Sock)->SndBuffer.HighWater = (Size))\r | |
128 | \r | |
129 | #define GET_SND_BUFFSIZE(Sock) ((Sock)->SndBuffer.HighWater)\r | |
130 | \r | |
131 | #define GET_SND_DATASIZE(Sock) (((Sock)->SndBuffer.DataQueue)->BufSize)\r | |
132 | \r | |
133 | #define SET_BACKLOG(Sock, Value) ((Sock)->BackLog = (Value))\r | |
134 | \r | |
135 | #define GET_BACKLOG(Sock) ((Sock)->BackLog)\r | |
136 | \r | |
137 | #define SOCK_ERROR(Sock, Error) ((Sock)->SockError = (Error))\r | |
138 | \r | |
139 | #define SND_BUF_HDR_LEN(Sock) \\r | |
140 | ((SockBufFirst (&((Sock)->SndBuffer)))->TotalSize)\r | |
141 | \r | |
142 | #define RCV_BUF_HDR_LEN(Sock) \\r | |
143 | ((SockBufFirst (&((Sock)->RcvBuffer)))->TotalSize)\r | |
144 | \r | |
145 | #define SOCK_FROM_TOKEN(Token) (((SOCK_TOKEN *) (Token))->Sock)\r | |
146 | \r | |
147 | #define PROTO_TOKEN_FORM_SOCK(SockToken, Type) \\r | |
148 | ((Type *) (((SOCK_TOKEN *) (SockToken))->Token))\r | |
149 | \r | |
150 | typedef struct _SOCKET SOCKET;\r | |
151 | \r | |
dfc1f033 | 152 | ///\r |
153 | /// Socket completion token\r | |
154 | ///\r | |
83cbd279 | 155 | typedef struct _SOCK_COMPLETION_TOKEN {\r |
dfc1f033 | 156 | EFI_EVENT Event; ///< The event to be issued\r |
157 | EFI_STATUS Status; ///< The status to be issued\r | |
83cbd279 | 158 | } SOCK_COMPLETION_TOKEN;\r |
159 | \r | |
dfc1f033 | 160 | ///\r |
161 | /// The application token with data packet\r | |
162 | ///\r | |
83cbd279 | 163 | typedef struct _SOCK_IO_TOKEN {\r |
164 | SOCK_COMPLETION_TOKEN Token;\r | |
165 | union {\r | |
166 | VOID *RxData;\r | |
167 | VOID *TxData;\r | |
168 | } Packet;\r | |
169 | } SOCK_IO_TOKEN;\r | |
170 | \r | |
dfc1f033 | 171 | ///\r |
172 | /// The request issued from socket layer to protocol layer. \r | |
173 | ///\r | |
83cbd279 | 174 | typedef enum {\r |
dfc1f033 | 175 | SOCK_ATTACH, ///< Attach current socket to a new PCB\r |
176 | SOCK_DETACH, ///< Detach current socket from the PCB\r | |
177 | SOCK_CONFIGURE, ///< Configure attached PCB\r | |
178 | SOCK_FLUSH, ///< Flush attached PCB\r | |
179 | SOCK_SND, ///< Need protocol to send something\r | |
180 | SOCK_SNDPUSH, ///< Need protocol to send pushed data\r | |
181 | SOCK_SNDURG, ///< Need protocol to send urgent data\r | |
182 | SOCK_CONSUMED, ///< Application has retrieved data from socket\r | |
183 | SOCK_CONNECT, ///< Need to connect to a peer\r | |
184 | SOCK_CLOSE, ///< Need to close the protocol process\r | |
185 | SOCK_ABORT, ///< Need to reset the protocol process\r | |
186 | SOCK_POLL, ///< Need to poll to the protocol layer\r | |
187 | SOCK_ROUTE, ///< Need to add a route information\r | |
188 | SOCK_MODE, ///< Need to get the mode data of the protocol\r | |
189 | SOCK_GROUP ///< Need to join a mcast group\r | |
83cbd279 | 190 | } SOCK_REQUEST;\r |
191 | \r | |
dfc1f033 | 192 | ///\r |
193 | /// The socket type.\r | |
194 | ///\r | |
83cbd279 | 195 | typedef enum {\r |
dfc1f033 | 196 | SOCK_DGRAM, ///< This socket providing datagram service\r |
197 | SOCK_STREAM ///< This socket providing stream service\r | |
83cbd279 | 198 | } SOCK_TYPE;\r |
199 | \r | |
dfc1f033 | 200 | ///\r |
201 | /// The buffer structure of rcvd data and send data used by socket.\r | |
202 | ///\r | |
83cbd279 | 203 | typedef struct _SOCK_BUFFER {\r |
dfc1f033 | 204 | UINT32 HighWater; ///< The buffersize upper limit of sock_buffer\r |
205 | UINT32 LowWater; ///< The low warter mark of sock_buffer\r | |
206 | NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data\r | |
83cbd279 | 207 | } SOCK_BUFFER;\r |
208 | \r | |
276dcc1b | 209 | /**\r |
210 | The handler of protocol for request from socket.\r | |
211 | \r | |
212 | @param Socket The socket issuing the request to protocol\r | |
213 | @param Request The request issued by socket\r | |
214 | @param RequestData The request related data\r | |
215 | \r | |
216 | @retval EFI_SUCCESS The socket request is completed successfully.\r | |
217 | @retval other The error status returned by the corresponding TCP\r | |
218 | layer function.\r | |
219 | \r | |
220 | **/\r | |
221 | typedef\r | |
222 | EFI_STATUS\r | |
223 | (*SOCK_PROTO_HANDLER) (\r | |
224 | IN SOCKET *Socket,\r | |
225 | IN SOCK_REQUEST Request,\r | |
226 | IN VOID *RequestData\r | |
227 | );\r | |
228 | \r | |
229 | \r | |
83cbd279 | 230 | //\r |
dfc1f033 | 231 | // Socket provided oprerations for low layer protocol\r |
83cbd279 | 232 | //\r |
233 | \r | |
234 | //\r | |
dfc1f033 | 235 | // Socket provided operations for user interface\r |
83cbd279 | 236 | //\r |
dfc1f033 | 237 | \r |
238 | /**\r | |
239 | Set the state of the socket.\r | |
240 | \r | |
241 | @param Sock Pointer to the socket.\r | |
242 | @param State The new state to be set.\r | |
243 | \r | |
244 | **/\r | |
83cbd279 | 245 | VOID\r |
246 | SockSetState (\r | |
247 | IN SOCKET *Sock,\r | |
248 | IN SOCK_STATE State\r | |
249 | );\r | |
250 | \r | |
dfc1f033 | 251 | /**\r |
252 | Called by the low layer protocol to indicate the socket a connection is \r | |
276dcc1b | 253 | established. \r |
254 | \r | |
255 | This function just changes the socket's state to SO_CONNECTED \r | |
dfc1f033 | 256 | and signals the token used for connection establishment.\r |
257 | \r | |
258 | @param Sock Pointer to the socket associated with the\r | |
259 | established connection.\r | |
260 | \r | |
261 | **/\r | |
83cbd279 | 262 | VOID\r |
263 | SockConnEstablished (\r | |
264 | IN SOCKET *Sock\r | |
265 | );\r | |
266 | \r | |
dfc1f033 | 267 | /**\r |
276dcc1b | 268 | Called by the low layer protocol to indicate the connection is closed.\r |
269 | \r | |
270 | This function flushes the socket, sets the state to SO_CLOSED and signals \r | |
271 | the close token.\r | |
dfc1f033 | 272 | \r |
273 | @param Sock Pointer to the socket associated with the closed\r | |
274 | connection.\r | |
275 | \r | |
276 | **/\r | |
83cbd279 | 277 | VOID\r |
278 | SockConnClosed (\r | |
279 | IN SOCKET *Sock\r | |
280 | );\r | |
281 | \r | |
dfc1f033 | 282 | /**\r |
276dcc1b | 283 | Called by low layer protocol to indicate that some data is sent or processed.\r |
284 | \r | |
dfc1f033 | 285 | This function trims the sent data in the socket send buffer, signals the data \r |
286 | token if proper.\r | |
287 | \r | |
288 | @param Sock Pointer to the socket.\r | |
289 | @param Count The length of the data processed or sent, in bytes.\r | |
290 | \r | |
291 | **/\r | |
83cbd279 | 292 | VOID\r |
293 | SockDataSent (\r | |
dfc1f033 | 294 | IN SOCKET *Sock,\r |
295 | IN UINT32 Count\r | |
83cbd279 | 296 | );\r |
297 | \r | |
dfc1f033 | 298 | /**\r |
299 | Called by the low layer protocol to copy some data in socket send\r | |
300 | buffer starting from the specific offset to a buffer provided by\r | |
301 | the caller.\r | |
302 | \r | |
303 | @param Sock Pointer to the socket.\r | |
304 | @param Offset The start point of the data to be copied.\r | |
305 | @param Len The length of the data to be copied.\r | |
306 | @param Dest Pointer to the destination to copy the data.\r | |
307 | \r | |
308 | @return The data size copied.\r | |
309 | \r | |
310 | **/\r | |
83cbd279 | 311 | UINT32\r |
312 | SockGetDataToSend (\r | |
dfc1f033 | 313 | IN SOCKET *Sock,\r |
314 | IN UINT32 Offset,\r | |
315 | IN UINT32 Len,\r | |
316 | IN UINT8 *Dest\r | |
83cbd279 | 317 | );\r |
318 | \r | |
dfc1f033 | 319 | /**\r |
320 | Called by the low layer protocol to indicate that there\r | |
276dcc1b | 321 | will be no more data from the communication peer.\r |
322 | \r | |
323 | This function set the socket's state to SO_NO_MORE_DATA and\r | |
324 | signal all queued IO tokens with the error status EFI_CONNECTION_FIN.\r | |
dfc1f033 | 325 | \r |
326 | @param Sock Pointer to the socket.\r | |
327 | \r | |
328 | **/\r | |
83cbd279 | 329 | VOID\r |
330 | SockNoMoreData (\r | |
331 | IN SOCKET *Sock\r | |
332 | );\r | |
333 | \r | |
dfc1f033 | 334 | /**\r |
276dcc1b | 335 | Called by the low layer protocol to deliver received data to socket layer.\r |
336 | \r | |
dfc1f033 | 337 | This function will append the data to the socket receive buffer, set ther \r |
338 | urgent data length and then check if any receive token can be signaled.\r | |
339 | \r | |
340 | @param Sock Pointer to the socket.\r | |
341 | @param NetBuffer Pointer to the buffer that contains the received\r | |
342 | data.\r | |
343 | @param UrgLen The length of the urgent data in the received data.\r | |
344 | \r | |
345 | **/\r | |
83cbd279 | 346 | VOID\r |
347 | SockDataRcvd (\r | |
348 | IN SOCKET *Sock,\r | |
349 | IN NET_BUF *NetBuffer,\r | |
dfc1f033 | 350 | IN UINT32 UrgLen\r |
83cbd279 | 351 | );\r |
352 | \r | |
dfc1f033 | 353 | /**\r |
354 | Get the length of the free space of the specific socket buffer.\r | |
355 | \r | |
356 | @param Sock Pointer to the socket.\r | |
357 | @param Which Flag to indicate which socket buffer to check,\r | |
358 | either send buffer or receive buffer.\r | |
359 | \r | |
360 | @return The length of the free space, in bytes.\r | |
361 | \r | |
362 | **/\r | |
83cbd279 | 363 | UINT32\r |
364 | SockGetFreeSpace (\r | |
dfc1f033 | 365 | IN SOCKET *Sock,\r |
366 | IN UINT32 Which\r | |
83cbd279 | 367 | );\r |
368 | \r | |
dfc1f033 | 369 | /**\r |
370 | Clone a new socket including its associated protocol control block.\r | |
371 | \r | |
372 | @param Sock Pointer to the socket to be cloned.\r | |
373 | \r | |
374 | @return Pointer to the newly cloned socket. If NULL, error condition occurred.\r | |
375 | \r | |
376 | **/\r | |
377 | SOCKET *\r | |
83cbd279 | 378 | SockClone (\r |
379 | IN SOCKET *Sock\r | |
380 | );\r | |
381 | \r | |
dfc1f033 | 382 | /**\r |
383 | Signal the receive token with the specific error or\r | |
384 | set socket error code after error is received.\r | |
385 | \r | |
386 | @param Sock Pointer to the socket.\r | |
387 | @param Error The error code received.\r | |
388 | \r | |
389 | **/\r | |
83cbd279 | 390 | VOID\r |
391 | SockRcvdErr (\r | |
392 | IN SOCKET *Sock,\r | |
393 | IN EFI_STATUS Error\r | |
394 | );\r | |
395 | \r | |
dfc1f033 | 396 | ///\r |
397 | /// Proto type of the create callback\r | |
398 | ///\r | |
4f6e31e4 | 399 | typedef\r |
400 | EFI_STATUS\r | |
401 | (*SOCK_CREATE_CALLBACK) (\r | |
402 | IN SOCKET *This,\r | |
403 | IN VOID *Context\r | |
404 | );\r | |
dfc1f033 | 405 | \r |
406 | ///\r | |
407 | /// Proto type of the destroy callback \r | |
408 | ///\r | |
4f6e31e4 | 409 | typedef\r |
410 | VOID\r | |
411 | (*SOCK_DESTROY_CALLBACK) (\r | |
412 | IN SOCKET *This,\r | |
413 | IN VOID *Context\r | |
414 | );\r | |
415 | \r | |
dfc1f033 | 416 | ///\r |
417 | /// The initialize data for create a new socket.\r | |
418 | ///\r | |
4f6e31e4 | 419 | typedef struct _SOCK_INIT_DATA {\r |
420 | SOCK_TYPE Type;\r | |
421 | SOCK_STATE State;\r | |
422 | \r | |
dfc1f033 | 423 | SOCKET *Parent; ///< The parent of this socket\r |
424 | UINT32 BackLog; ///< The connection limit for listening socket\r | |
425 | UINT32 SndBufferSize; ///< The high warter mark of send buffer\r | |
426 | UINT32 RcvBufferSize; ///< The high warter mark of receive buffer\r | |
427 | VOID *Protocol; ///< The pointer to protocol function template\r | |
428 | ///< wanted to install on socket\r | |
4f6e31e4 | 429 | \r |
430 | //\r | |
431 | // Callbacks after socket is created and before socket is to be destroyed.\r | |
432 | //\r | |
dfc1f033 | 433 | SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created\r |
434 | SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroied\r | |
435 | VOID *Context; ///< The context of the callback\r | |
4f6e31e4 | 436 | \r |
437 | //\r | |
438 | // Opaque protocol data.\r | |
439 | //\r | |
440 | VOID *ProtoData;\r | |
441 | UINT32 DataSize;\r | |
442 | \r | |
dfc1f033 | 443 | SOCK_PROTO_HANDLER ProtoHandler; ///< The handler of protocol for socket request\r |
4f6e31e4 | 444 | \r |
dfc1f033 | 445 | EFI_HANDLE DriverBinding; ///< The driver binding handle\r |
4f6e31e4 | 446 | } SOCK_INIT_DATA;\r |
85511ddf | 447 | \r |
dfc1f033 | 448 | ///\r |
449 | /// The union type of TCP and UDP protocol.\r | |
450 | /// \r | |
451 | typedef union _NET_PROTOCOL {\r | |
452 | EFI_TCP4_PROTOCOL TcpProtocol; ///< Tcp protocol\r | |
453 | EFI_UDP4_PROTOCOL UdpProtocol; ///< Udp protocol\r | |
85511ddf | 454 | } NET_PROTOCOL;\r |
dfc1f033 | 455 | \r |
456 | ///\r | |
457 | /// The socket structure representing a network service access point\r | |
458 | ///\r | |
83cbd279 | 459 | struct _SOCKET {\r |
460 | \r | |
461 | //\r | |
dfc1f033 | 462 | // Socket description information\r |
83cbd279 | 463 | //\r |
dfc1f033 | 464 | UINT32 Signature; ///< Signature of the socket\r |
465 | EFI_HANDLE SockHandle; ///< The virtual handle of the socket\r | |
466 | EFI_HANDLE DriverBinding; ///< Socket's driver binding protocol\r | |
83cbd279 | 467 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r |
468 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
e48e37fc | 469 | LIST_ENTRY Link; \r |
83cbd279 | 470 | SOCK_CONFIGURE_STATE ConfigureState;\r |
471 | SOCK_TYPE Type;\r | |
472 | SOCK_STATE State;\r | |
473 | UINT16 Flag;\r | |
dfc1f033 | 474 | EFI_LOCK Lock; ///< The lock of socket\r |
475 | SOCK_BUFFER SndBuffer; ///< Send buffer of application's data\r | |
476 | SOCK_BUFFER RcvBuffer; ///< Receive buffer of received data\r | |
477 | EFI_STATUS SockError; ///< The error returned by low layer protocol\r | |
83cbd279 | 478 | BOOLEAN IsDestroyed;\r |
479 | \r | |
480 | //\r | |
dfc1f033 | 481 | // Fields used to manage the connection request\r |
83cbd279 | 482 | //\r |
dfc1f033 | 483 | UINT32 BackLog; ///< the limit of connection to this socket\r |
484 | UINT32 ConnCnt; ///< the current count of connections to it\r | |
485 | SOCKET *Parent; ///< listening parent that accept the connection\r | |
486 | LIST_ENTRY ConnectionList; ///< the connections maintained by this socket\r | |
487 | \r | |
83cbd279 | 488 | //\r |
dfc1f033 | 489 | // The queue to buffer application's asynchronous token\r |
83cbd279 | 490 | //\r |
e48e37fc | 491 | LIST_ENTRY ListenTokenList;\r |
492 | LIST_ENTRY RcvTokenList;\r | |
493 | LIST_ENTRY SndTokenList;\r | |
494 | LIST_ENTRY ProcessingSndTokenList;\r | |
83cbd279 | 495 | \r |
dfc1f033 | 496 | SOCK_COMPLETION_TOKEN *ConnectionToken; ///< app's token to signal if connected\r |
497 | SOCK_COMPLETION_TOKEN *CloseToken; ///< app's token to signal if closed\r | |
83cbd279 | 498 | \r |
499 | //\r | |
dfc1f033 | 500 | // Interface for low level protocol\r |
83cbd279 | 501 | //\r |
dfc1f033 | 502 | SOCK_PROTO_HANDLER ProtoHandler; ///< The request handler of protocol\r |
503 | UINT8 ProtoReserved[PROTO_RESERVED_LEN]; ///< Data fields reserved for protocol\r | |
504 | NET_PROTOCOL NetProtocol; ///< TCP or UDP protocol socket used\r | |
4f6e31e4 | 505 | \r |
506 | //\r | |
dfc1f033 | 507 | // Callbacks after socket is created and before socket is to be destroyed.\r |
4f6e31e4 | 508 | //\r |
dfc1f033 | 509 | SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created\r |
510 | SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroied\r | |
511 | VOID *Context; ///< The context of the callback\r | |
83cbd279 | 512 | };\r |
513 | \r | |
dfc1f033 | 514 | ///\r |
515 | /// The token structure buffered in socket layer.\r | |
516 | ///\r | |
83cbd279 | 517 | typedef struct _SOCK_TOKEN {\r |
dfc1f033 | 518 | LIST_ENTRY TokenList; ///< The entry to add in the token list\r |
519 | SOCK_COMPLETION_TOKEN *Token; ///< The application's token\r | |
520 | UINT32 RemainDataLen; ///< Unprocessed data length\r | |
521 | SOCKET *Sock; ///< The poninter to the socket this token\r | |
522 | ///< belongs to\r | |
83cbd279 | 523 | } SOCK_TOKEN;\r |
524 | \r | |
dfc1f033 | 525 | ///\r |
526 | /// Reserved data to access the NET_BUF delivered by UDP driver.\r | |
527 | ///\r | |
83cbd279 | 528 | typedef struct _UDP_RSV_DATA {\r |
529 | EFI_TIME TimeStamp;\r | |
530 | EFI_UDP4_SESSION_DATA Session;\r | |
531 | } UDP_RSV_DATA;\r | |
532 | \r | |
dfc1f033 | 533 | ///\r |
534 | /// Reserved data to access the NET_BUF delivered by TCP driver.\r | |
535 | ///\r | |
83cbd279 | 536 | typedef struct _TCP_RSV_DATA {\r |
537 | UINT32 UrgLen;\r | |
538 | } TCP_RSV_DATA;\r | |
539 | \r | |
dfc1f033 | 540 | /**\r |
541 | Create a socket and its associated protocol control block\r | |
542 | with the intial data SockInitData and protocol specific\r | |
543 | data ProtoData.\r | |
544 | \r | |
545 | @param SockInitData Inital data to setting the socket.\r | |
546 | \r | |
547 | @return Pointer to the newly created socket. If NULL, error condition occured.\r | |
548 | \r | |
549 | **/\r | |
550 | SOCKET *\r | |
83cbd279 | 551 | SockCreateChild (\r |
4f6e31e4 | 552 | IN SOCK_INIT_DATA *SockInitData\r |
83cbd279 | 553 | );\r |
554 | \r | |
dfc1f033 | 555 | /**\r |
556 | Destory the socket Sock and its associated protocol control block.\r | |
557 | \r | |
558 | @param Sock The socket to be destroyed.\r | |
559 | \r | |
560 | @retval EFI_SUCCESS The socket Sock is destroyed successfully.\r | |
561 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.\r | |
562 | \r | |
563 | **/\r | |
83cbd279 | 564 | EFI_STATUS\r |
565 | SockDestroyChild (\r | |
dfc1f033 | 566 | IN SOCKET *Sock\r |
83cbd279 | 567 | );\r |
568 | \r | |
dfc1f033 | 569 | /**\r |
570 | Configure the specific socket Sock using configuration data ConfigData.\r | |
571 | \r | |
572 | @param Sock Pointer to the socket to be configured.\r | |
573 | @param ConfigData Pointer to the configuration data.\r | |
574 | \r | |
575 | @retval EFI_SUCCESS The socket is configured successfully.\r | |
576 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket or the\r | |
577 | socket is already configured.\r | |
578 | \r | |
579 | **/\r | |
83cbd279 | 580 | EFI_STATUS\r |
581 | SockConfigure (\r | |
582 | IN SOCKET *Sock,\r | |
583 | IN VOID *ConfigData\r | |
584 | );\r | |
585 | \r | |
dfc1f033 | 586 | /**\r |
587 | Initiate a connection establishment process.\r | |
588 | \r | |
589 | @param Sock Pointer to the socket to initiate the initate the\r | |
590 | connection.\r | |
591 | @param Token Pointer to the token used for the connection\r | |
592 | operation.\r | |
593 | \r | |
594 | @retval EFI_SUCCESS The connection is initialized successfully.\r | |
595 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the\r | |
596 | socket is closed, or the socket is not configured to\r | |
597 | be an active one, or the token is already in one of\r | |
598 | this socket's lists.\r | |
599 | @retval EFI_NO_MAPPING The IP address configuration operation is not\r | |
600 | finished.\r | |
601 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
602 | \r | |
603 | **/\r | |
83cbd279 | 604 | EFI_STATUS\r |
605 | SockConnect (\r | |
606 | IN SOCKET *Sock,\r | |
607 | IN VOID *Token\r | |
608 | );\r | |
609 | \r | |
dfc1f033 | 610 | /**\r |
611 | Issue a listen token to get an existed connected network instance\r | |
612 | or wait for a connection if there is none.\r | |
613 | \r | |
614 | @param Sock Pointer to the socket to accept connections.\r | |
615 | @param Token The token to accept a connection.\r | |
616 | \r | |
617 | @retval EFI_SUCCESS Either a connection is accpeted or the Token is\r | |
618 | buffered for further acception.\r | |
619 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the\r | |
620 | socket is closed, or the socket is not configured to\r | |
621 | be a passive one, or the token is already in one of\r | |
622 | this socket's lists.\r | |
623 | @retval EFI_NO_MAPPING The IP address configuration operation is not\r | |
624 | finished.\r | |
625 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
626 | @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory limit.\r | |
627 | \r | |
628 | **/\r | |
83cbd279 | 629 | EFI_STATUS\r |
630 | SockAccept (\r | |
631 | IN SOCKET *Sock,\r | |
632 | IN VOID *Token\r | |
633 | );\r | |
634 | \r | |
dfc1f033 | 635 | /**\r |
636 | Issue a token with data to the socket to send out.\r | |
637 | \r | |
638 | @param Sock Pointer to the socket to process the token with\r | |
639 | data.\r | |
640 | @param Token The token with data that needs to send out.\r | |
641 | \r | |
642 | @retval EFI_SUCCESS The token is processed successfully.\r | |
643 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the\r | |
644 | socket is closed, or the socket is not in a\r | |
645 | synchronized state , or the token is already in one\r | |
646 | of this socket's lists.\r | |
647 | @retval EFI_NO_MAPPING The IP address configuration operation is not\r | |
648 | finished.\r | |
649 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
650 | @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory limit.\r | |
651 | \r | |
652 | **/\r | |
83cbd279 | 653 | EFI_STATUS\r |
654 | SockSend (\r | |
655 | IN SOCKET *Sock,\r | |
656 | IN VOID *Token\r | |
657 | );\r | |
658 | \r | |
dfc1f033 | 659 | /**\r |
660 | Issue a token to get data from the socket.\r | |
661 | \r | |
662 | @param Sock Pointer to the socket to get data from.\r | |
663 | @param Token The token to store the received data from the\r | |
664 | socket.\r | |
665 | \r | |
666 | @retval EFI_SUCCESS The token is processed successfully.\r | |
667 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the\r | |
668 | socket is closed, or the socket is not in a\r | |
669 | synchronized state , or the token is already in one\r | |
670 | of this socket's lists.\r | |
671 | @retval EFI_NO_MAPPING The IP address configuration operation is not\r | |
672 | finished.\r | |
673 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
674 | @retval EFI_CONNECTION_FIN The connection is closed and there is no more data.\r | |
675 | @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to memory limit.\r | |
676 | \r | |
677 | **/\r | |
83cbd279 | 678 | EFI_STATUS\r |
679 | SockRcv (\r | |
680 | IN SOCKET *Sock,\r | |
681 | IN VOID *Token\r | |
682 | );\r | |
683 | \r | |
dfc1f033 | 684 | /**\r |
685 | Reset the socket and its associated protocol control block.\r | |
686 | \r | |
687 | @param Sock Pointer to the socket to be flushed.\r | |
688 | \r | |
689 | @retval EFI_SUCCESS The socket is flushed successfully.\r | |
690 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.\r | |
691 | \r | |
692 | **/\r | |
83cbd279 | 693 | EFI_STATUS\r |
694 | SockFlush (\r | |
695 | IN SOCKET *Sock\r | |
696 | );\r | |
697 | \r | |
dfc1f033 | 698 | /**\r |
699 | Close or abort the socket associated connection.\r | |
700 | \r | |
701 | @param Sock Pointer to the socket of the connection to close or\r | |
702 | abort.\r | |
703 | @param Token The token for close operation.\r | |
704 | @param OnAbort TRUE for aborting the connection, FALSE to close it.\r | |
705 | \r | |
706 | @retval EFI_SUCCESS The close or abort operation is initialized\r | |
707 | successfully.\r | |
708 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the\r | |
709 | socket is closed, or the socket is not in a\r | |
710 | synchronized state , or the token is already in one\r | |
711 | of this socket's lists.\r | |
712 | @retval EFI_NO_MAPPING The IP address configuration operation is not\r | |
713 | finished.\r | |
714 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
715 | \r | |
716 | **/\r | |
83cbd279 | 717 | EFI_STATUS\r |
718 | SockClose (\r | |
719 | IN SOCKET *Sock,\r | |
720 | IN VOID *Token,\r | |
721 | IN BOOLEAN OnAbort\r | |
722 | );\r | |
723 | \r | |
dfc1f033 | 724 | /**\r |
725 | Get the mode data of the low layer protocol.\r | |
726 | \r | |
727 | @param Sock Pointer to the socket to get mode data from.\r | |
728 | @param Mode Pointer to the data to store the low layer mode\r | |
729 | information.\r | |
730 | \r | |
731 | @retval EFI_SUCCESS The mode data is got successfully.\r | |
732 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
733 | \r | |
734 | **/\r | |
83cbd279 | 735 | EFI_STATUS\r |
736 | SockGetMode (\r | |
276dcc1b | 737 | IN SOCKET *Sock,\r |
738 | IN OUT VOID *Mode\r | |
83cbd279 | 739 | );\r |
740 | \r | |
dfc1f033 | 741 | /**\r |
742 | Configure the low level protocol to join a multicast group for\r | |
743 | this socket's connection.\r | |
744 | \r | |
745 | @param Sock Pointer to the socket of the connection to join the\r | |
746 | specific multicast group.\r | |
747 | @param GroupInfo Pointer to the multicast group info.\r | |
748 | \r | |
749 | @retval EFI_SUCCESS The configuration is done successfully.\r | |
750 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.\r | |
751 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
752 | \r | |
753 | **/\r | |
83cbd279 | 754 | EFI_STATUS\r |
755 | SockGroup (\r | |
756 | IN SOCKET *Sock,\r | |
757 | IN VOID *GroupInfo\r | |
758 | );\r | |
759 | \r | |
dfc1f033 | 760 | /**\r |
761 | Add or remove route information in IP route table associated\r | |
762 | with this socket.\r | |
763 | \r | |
764 | @param Sock Pointer to the socket associated with the IP route\r | |
765 | table to operate on.\r | |
766 | @param RouteInfo Pointer to the route information to be processed.\r | |
767 | \r | |
768 | @retval EFI_SUCCESS The route table is updated successfully.\r | |
769 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.\r | |
770 | @retval EFI_NO_MAPPING The IP address configuration operation is not\r | |
771 | finished.\r | |
772 | @retval EFI_NOT_STARTED The socket is not configured.\r | |
773 | \r | |
774 | **/\r | |
83cbd279 | 775 | EFI_STATUS\r |
776 | SockRoute (\r | |
777 | IN SOCKET *Sock,\r | |
778 | IN VOID *RouteInfo\r | |
779 | );\r | |
780 | \r | |
781 | //\r | |
782 | // Supporting function to operate on socket buffer\r | |
783 | //\r | |
dfc1f033 | 784 | \r |
785 | /**\r | |
786 | Get the first buffer block in the specific socket buffer.\r | |
787 | \r | |
788 | @param Sockbuf Pointer to the socket buffer.\r | |
789 | \r | |
790 | @return Pointer to the first buffer in the queue. NULL if the queue is empty.\r | |
791 | \r | |
792 | **/\r | |
83cbd279 | 793 | NET_BUF *\r |
794 | SockBufFirst (\r | |
795 | IN SOCK_BUFFER *Sockbuf\r | |
796 | );\r | |
797 | \r | |
dfc1f033 | 798 | /**\r |
799 | Get the next buffer block in the specific socket buffer.\r | |
800 | \r | |
801 | @param Sockbuf Pointer to the socket buffer.\r | |
802 | @param SockEntry Pointer to the buffer block prior to the required\r | |
803 | one.\r | |
804 | \r | |
805 | @return Pointer to the buffer block next to SockEntry. NULL if SockEntry is \r | |
806 | the tail or head entry.\r | |
807 | \r | |
808 | **/\r | |
83cbd279 | 809 | NET_BUF *\r |
810 | SockBufNext (\r | |
811 | IN SOCK_BUFFER *Sockbuf,\r | |
812 | IN NET_BUF *SockEntry\r | |
813 | );\r | |
814 | \r | |
815 | #endif\r |