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