Home | History | Annotate | Download | only in Tcp4Dxe
      1 /** @file
      2   Tcp driver function header.
      3 
      4 Copyright (c) 2005 - 2016, 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 _TCP4_DRIVER_H_
     16 #define _TCP4_DRIVER_H_
     17 
     18 #include <Protocol/ServiceBinding.h>
     19 #include <Library/IpIoLib.h>
     20 
     21 #define TCP4_DRIVER_SIGNATURE   SIGNATURE_32 ('T', 'C', 'P', '4')
     22 
     23 #define TCP4_PORT_KNOWN         1024
     24 #define TCP4_PORT_USER_RESERVED 65535
     25 
     26 #define TCP4_FROM_THIS(a) \
     27   CR ( \
     28   (a), \
     29   TCP4_SERVICE_DATA, \
     30   Tcp4ServiceBinding, \
     31   TCP4_DRIVER_SIGNATURE \
     32   )
     33 
     34 ///
     35 /// TCP heartbeat tick timer.
     36 ///
     37 typedef struct _TCP4_HEARTBEAT_TIMER {
     38   EFI_EVENT  TimerEvent;         ///< The event assoiated with the timer
     39   INTN       RefCnt;             ///< Number of reference
     40 } TCP4_HEARTBEAT_TIMER;
     41 
     42 ///
     43 /// TCP service data
     44 ///
     45 typedef struct _TCP4_SERVICE_DATA {
     46   UINT32                        Signature;
     47   EFI_HANDLE                    ControllerHandle;
     48   IP_IO                         *IpIo;  // IP Io consumed by TCP4
     49   EFI_SERVICE_BINDING_PROTOCOL  Tcp4ServiceBinding;
     50   EFI_HANDLE                    DriverBindingHandle;
     51   LIST_ENTRY                    SocketList;
     52 } TCP4_SERVICE_DATA;
     53 
     54 ///
     55 /// TCP protocol data
     56 ///
     57 typedef struct _TCP4_PROTO_DATA {
     58   TCP4_SERVICE_DATA *TcpService;
     59   TCP_CB            *TcpPcb;
     60 } TCP4_PROTO_DATA;
     61 
     62 
     63 /**
     64   Packet receive callback function provided to IP_IO, used to call
     65   the proper function to handle the packet received by IP.
     66 
     67   @param  Status      Status of the received packet.
     68   @param  IcmpErr     ICMP error number.
     69   @param  NetSession  Pointer to the net session of this packet.
     70   @param  Pkt         Pointer to the recieved packet.
     71   @param  Context     Pointer to the context configured in IpIoOpen(), not used
     72                       now.
     73 
     74   @return None
     75 
     76 **/
     77 VOID
     78 EFIAPI
     79 Tcp4RxCallback (
     80   IN EFI_STATUS                       Status,
     81   IN UINT8                            IcmpErr,
     82   IN EFI_NET_SESSION_DATA             *NetSession,
     83   IN NET_BUF                          *Pkt,
     84   IN VOID                             *Context    OPTIONAL
     85   );
     86 
     87 /**
     88   Send the segment to IP via IpIo function.
     89 
     90   @param  Tcb         Pointer to the TCP_CB of this TCP instance.
     91   @param  Nbuf        Pointer to the TCP segment to be sent.
     92   @param  Src         Source address of the TCP segment.
     93   @param  Dest        Destination address of the TCP segment.
     94 
     95   @retval 0           The segment was sent out successfully.
     96   @retval -1          The segment was failed to send.
     97 
     98 **/
     99 INTN
    100 TcpSendIpPacket (
    101   IN TCP_CB    *Tcb,
    102   IN NET_BUF   *Nbuf,
    103   IN UINT32    Src,
    104   IN UINT32    Dest
    105   );
    106 
    107 /**
    108   The procotol handler provided to the socket layer, used to
    109   dispatch the socket level requests by calling the corresponding
    110   TCP layer functions.
    111 
    112   @param  Sock                   Pointer to the socket of this TCP instance.
    113   @param  Request                The code of this operation request.
    114   @param  Data                   Pointer to the operation specific data passed in
    115                                  together with the operation request.
    116 
    117   @retval EFI_SUCCESS            The socket request is completed successfully.
    118   @retval other                  The error status returned by the corresponding TCP
    119                                  layer function.
    120 
    121 **/
    122 EFI_STATUS
    123 Tcp4Dispatcher (
    124   IN SOCKET                  *Sock,
    125   IN UINT8                   Request,
    126   IN VOID                    *Data    OPTIONAL
    127   );
    128 
    129 
    130 /**
    131   The entry point for Tcp4 driver, used to install Tcp4 driver on the ImageHandle.
    132 
    133   @param  ImageHandle   The firmware allocated handle for this
    134                         driver image.
    135   @param  SystemTable   Pointer to the EFI system table.
    136 
    137   @retval EFI_SUCCESS   Driver loaded.
    138   @retval other         Driver not loaded.
    139 
    140 **/
    141 EFI_STATUS
    142 EFIAPI
    143 Tcp4DriverEntryPoint (
    144   IN EFI_HANDLE        ImageHandle,
    145   IN EFI_SYSTEM_TABLE  *SystemTable
    146   );
    147 
    148 
    149 /**
    150   Tests to see if this driver supports a given controller.
    151 
    152   If a child device is provided, it further tests to see if this driver supports
    153   creating a handle for the specified child device.
    154 
    155   @param  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
    156   @param  ControllerHandle     The handle of the controller to test. This handle
    157                                must support a protocol interface that supplies
    158                                an I/O abstraction to the driver.
    159   @param  RemainingDevicePath  A pointer to the remaining portion of a device path.
    160                                This parameter is ignored by device drivers, and is optional for bus drivers.
    161 
    162 
    163   @retval EFI_SUCCESS          The device specified by ControllerHandle and
    164                                RemainingDevicePath is supported by the driver
    165                                specified by This.
    166   @retval EFI_ALREADY_STARTED  The device specified by ControllerHandle and
    167                                RemainingDevicePath is already being managed by
    168                                the driver specified by This.
    169   @retval EFI_ACCESS_DENIED    The device specified by ControllerHandle and
    170                                RemainingDevicePath is already being managed by a
    171                                different driver or an application that requires
    172                                exclusive access.
    173   @retval EFI_UNSUPPORTED      The device specified by ControllerHandle and
    174                                RemainingDevicePath is not supported by the driver
    175                                specified by This.
    176 
    177 **/
    178 EFI_STATUS
    179 EFIAPI
    180 Tcp4DriverBindingSupported (
    181   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
    182   IN EFI_HANDLE                   ControllerHandle,
    183   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
    184   );
    185 
    186 /**
    187   Start this driver on ControllerHandle.
    188 
    189   The Start() function is designed to be invoked from the EFI boot service
    190   ConnectController(). As a result, much of the error checking on the parameters
    191   to Start() has been moved into this common boot service. It is legal to call
    192   Start() from other locations, but the following calling restrictions must be
    193   followed or the system behavior will not be deterministic.
    194   1. ControllerHandle must be a valid EFI_HANDLE.
    195   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally
    196      aligned EFI_DEVICE_PATH_PROTOCOL.
    197   3. Prior to calling Start(), the Supported() function for the driver specified
    198      by This must have been called with the same calling parameters, and Supported()
    199      must have returned EFI_SUCCESS.
    200 
    201   @param  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
    202   @param  ControllerHandle     The handle of the controller to start. This handle
    203                                must support a protocol interface that supplies
    204                                an I/O abstraction to the driver.
    205   @param  RemainingDevicePath  A pointer to the remaining portion of a device path.
    206                                This parameter is ignored by device drivers, and is
    207                                optional for bus drivers.
    208 
    209   @retval EFI_SUCCESS          The device was started.
    210   @retval EFI_ALREADY_STARTED  The device could not be started due to a device error.
    211   @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack
    212                                of resources.
    213 
    214 **/
    215 EFI_STATUS
    216 EFIAPI
    217 Tcp4DriverBindingStart (
    218   IN EFI_DRIVER_BINDING_PROTOCOL  *This,
    219   IN EFI_HANDLE                   ControllerHandle,
    220   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath OPTIONAL
    221   );
    222 
    223 /**
    224   Stop this driver on ControllerHandle.
    225 
    226   The Stop() function is designed to be invoked from the EFI boot service
    227   DisconnectController(). As a result, much of the error checking on the parameters
    228   to Stop() has been moved into this common boot service. It is legal to call Stop()
    229   from other locations, but the following calling restrictions must be followed
    230   or the system behavior will not be deterministic.
    231   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call
    232      to this same driver's Start() function.
    233   2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
    234      EFI_HANDLE. In addition, all of these handles must have been created in this
    235      driver's Start() function, and the Start() function must have called OpenProtocol()
    236      on ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
    237 
    238   @param  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
    239   @param  ControllerHandle  A handle to the device being stopped. The handle must
    240                             support a bus specific I/O protocol for the driver
    241                             to use to stop the device.
    242   @param  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
    243   @param  ChildHandleBuffer An array of child handles to be freed. May be NULL if
    244                             NumberOfChildren is 0.
    245 
    246   @retval EFI_SUCCESS       The device was stopped.
    247   @retval EFI_DEVICE_ERROR  The device could not be stopped due to a device error.
    248 
    249 **/
    250 EFI_STATUS
    251 EFIAPI
    252 Tcp4DriverBindingStop (
    253   IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
    254   IN  EFI_HANDLE                   ControllerHandle,
    255   IN  UINTN                        NumberOfChildren,
    256   IN  EFI_HANDLE                   *ChildHandleBuffer
    257   );
    258 
    259 /**
    260   Open Ip4 and device path protocols for a created socket, and insert it in
    261   socket list.
    262 
    263   @param  This                Pointer to the socket just created
    264   @param  Context             Context of the socket
    265 
    266   @retval EFI_SUCCESS         This protocol is installed successfully.
    267   @retval other               Some error occured.
    268 
    269 **/
    270 EFI_STATUS
    271 Tcp4CreateSocketCallback (
    272   IN SOCKET  *This,
    273   IN VOID    *Context
    274   );
    275 
    276 /**
    277   Close Ip4 and device path protocols for a socket, and remove it from socket list.
    278 
    279   @param  This                Pointer to the socket to be removed
    280   @param  Context             Context of the socket
    281 
    282 **/
    283 VOID
    284 Tcp4DestroySocketCallback (
    285   IN SOCKET  *This,
    286   IN VOID    *Context
    287   );
    288 
    289 /**
    290   Creates a child handle and installs a protocol.
    291 
    292   The CreateChild() function installs a protocol on ChildHandle. If ChildHandle
    293   is a pointer to NULL, then a new handle is created and returned in ChildHandle.
    294   If ChildHandle is not a pointer to NULL, then the protocol installs on the existing
    295   ChildHandle.
    296 
    297   @param  This        Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
    298   @param  ChildHandle Pointer to the handle of the child to create. If it is NULL, then
    299                       a new handle is created. If it is a pointer to an existing UEFI
    300                       handle, then the protocol is added to the existing UEFI handle.
    301 
    302   @retval EFI_SUCCES            The protocol was added to ChildHandle.
    303   @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
    304   @retval EFI_OUT_OF_RESOURCES  There are not enough resources available to create
    305                                 the child.
    306   @retval other                 The child handle was not created.
    307 
    308 **/
    309 EFI_STATUS
    310 EFIAPI
    311 Tcp4ServiceBindingCreateChild (
    312   IN     EFI_SERVICE_BINDING_PROTOCOL  *This,
    313   IN OUT EFI_HANDLE                    *ChildHandle
    314   );
    315 
    316 /**
    317   Destroys a child handle with a protocol installed on it.
    318 
    319   The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
    320   that was installed by CreateChild() from ChildHandle. If the removed protocol is the
    321   last protocol on ChildHandle, then ChildHandle is destroyed.
    322 
    323   @param  This         Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
    324   @param  ChildHandle  Handle of the child to destroy
    325 
    326   @retval EFI_SUCCES            The protocol was removed from ChildHandle.
    327   @retval EFI_UNSUPPORTED       ChildHandle does not support the protocol that is
    328                                 being removed.
    329   @retval EFI_INVALID_PARAMETER Child handle is NULL.
    330   @retval EFI_ACCESS_DENIED     The protocol could not be removed from the ChildHandle
    331                                 because its services are being used.
    332   @retval other                 The child handle was not destroyed.
    333 
    334 **/
    335 EFI_STATUS
    336 EFIAPI
    337 Tcp4ServiceBindingDestroyChild (
    338   IN EFI_SERVICE_BINDING_PROTOCOL  *This,
    339   IN EFI_HANDLE                    ChildHandle
    340   );
    341 
    342 #endif
    343