EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

StdLib/EfiSocketLib/UseEfiSocketLib.c

Go to the documentation of this file.
00001 
00015 #include "Socket.h"
00016 
00017 
00026 CONST EFI_GUID mEslIp4ServiceGuid = {
00027   0x9c756011, 0x5d44, 0x4ee0, { 0xbc, 0xe7, 0xc3, 0x82, 0x18, 0xfe, 0x39, 0x8d }
00028 };
00029 
00030 
00034 CONST EFI_GUID mEslTcp4ServiceGuid = {
00035   0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
00036 };
00037 
00038 
00042 CONST EFI_GUID mEslUdp4ServiceGuid = {
00043   0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
00044 };
00045 
00046 
00065 int
00066 EslServiceGetProtocol (
00067   IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
00068   )
00069 {
00070   EFI_HANDLE ChildHandle;
00071   ESL_SOCKET * pSocket;
00072   int RetVal;
00073   EFI_STATUS Status;
00074 
00075   DBG_ENTER ( );
00076 
00077   //
00078   //  Assume success
00079   //
00080   RetVal = 0;
00081 
00082   //
00083   //  Locate the socket protocol
00084   //
00085   ChildHandle = NULL;
00086   Status = EslSocketAllocate ( &ChildHandle,
00087                                DEBUG_SOCKET,
00088                                &pSocket );
00089   if ( !EFI_ERROR ( Status )) {
00090     *ppSocketProtocol = &pSocket->SocketProtocol;
00091   }
00092   else {
00093     //
00094     //  No resources
00095     //
00096     RetVal = ENOMEM;
00097   }
00098 
00099   //
00100   //  Return the operation status
00101   //
00102   DBG_EXIT_DEC ( RetVal );
00103   return RetVal;
00104 }
00105 
00106 
00123 EFI_STATUS
00124 EslServiceNetworkConnect (
00125   VOID
00126   )
00127 {
00128   BOOLEAN bSomethingFound;
00129   UINTN HandleCount;
00130   UINTN Index;
00131   CONST ESL_SOCKET_BINDING * pEnd;
00132   EFI_HANDLE * pHandles;
00133   CONST ESL_SOCKET_BINDING * pSocketBinding;
00134   EFI_STATUS Status;
00135 
00136   DBG_ENTER ( );
00137 
00138   //
00139   //  Initialize the socket layer
00140   //
00141   Status = EFI_SUCCESS;
00142   bSomethingFound = FALSE;
00143   EslServiceLoad ( gImageHandle );
00144 
00145   //
00146   //  Connect the network devices
00147   //
00148   pSocketBinding = &cEslSocketBinding[0];
00149   pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
00150   while ( pEnd > pSocketBinding ) {
00151     //
00152     //  Attempt to locate the network adapters
00153     //
00154     HandleCount = 0;
00155     pHandles = NULL;
00156     Status = gBS->LocateHandleBuffer ( ByProtocol,
00157                                        pSocketBinding->pNetworkBinding,
00158                                        NULL,
00159                                        &HandleCount,
00160                                        &pHandles );
00161     if ( EFI_ERROR ( Status )) {
00162       DEBUG (( DEBUG_ERROR,
00163                "ERROR with %s layer, Status: %r\r\n",
00164                pSocketBinding->pName,
00165                Status ));
00166     }
00167     else {
00168       if ( NULL != pHandles ) {
00169         //
00170         //  Attempt to connect to this network adapter
00171         //
00172         for ( Index = 0; HandleCount > Index; Index++ ) {
00173           Status = EslServiceConnect ( gImageHandle,
00174                                        pHandles[ Index ]);
00175           if ( EFI_ERROR ( Status )) {
00176             break;
00177           }
00178           bSomethingFound = TRUE;
00179         }
00180 
00181         //
00182         //  Done with the handles
00183         //
00184         gBS->FreePool ( pHandles );
00185       }
00186     }
00187 
00188     //
00189     //  Set the next network protocol
00190     //
00191     pSocketBinding += 1;
00192   }
00193 
00194   //
00195   //  Return the network connection status
00196   //
00197   if ( bSomethingFound ) {
00198     Status = EFI_SUCCESS;
00199   }
00200   DBG_EXIT_STATUS ( Status );
00201   return Status;
00202 }
00203 
00204 
00220 EFI_STATUS
00221 EslServiceNetworkDisconnect (
00222   VOID
00223   )
00224 {
00225   UINTN HandleCount;
00226   UINTN Index;
00227   CONST ESL_SOCKET_BINDING * pEnd;
00228   EFI_HANDLE * pHandles;
00229   CONST ESL_SOCKET_BINDING * pSocketBinding;
00230   EFI_STATUS Status;
00231 
00232   DBG_ENTER ( );
00233 
00234   //
00235   //  Assume success
00236   //
00237   Status = EFI_SUCCESS;
00238 
00239   //
00240   //  Disconnect the network devices
00241   //
00242   pSocketBinding = &cEslSocketBinding[0];
00243   pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
00244   while ( pEnd > pSocketBinding ) {
00245     //
00246     //  Attempt to locate the network adapters
00247     //
00248     HandleCount = 0;
00249     pHandles = NULL;
00250     Status = gBS->LocateHandleBuffer ( ByProtocol,
00251                                        pSocketBinding->pNetworkBinding,
00252                                        NULL,
00253                                        &HandleCount,
00254                                        &pHandles );
00255     if ( EFI_ERROR ( Status )) {
00256       break;
00257     }
00258     if ( NULL != pHandles ) {
00259       //
00260       //  Attempt to disconnect from this network adapter
00261       //
00262       for ( Index = 0; HandleCount > Index; Index++ ) {
00263         Status = EslServiceDisconnect ( gImageHandle,
00264                                         pHandles[ Index ]);
00265         if ( EFI_ERROR ( Status )) {
00266           break;
00267         }
00268       }
00269 
00270       //
00271       //  Done with the handles
00272       //
00273       gBS->FreePool ( pHandles );
00274     }
00275 
00276     //
00277     //  Set the next network protocol
00278     //
00279     pSocketBinding += 1;
00280   }
00281 
00282   //
00283   //  Finish the disconnect operation
00284   //
00285   if ( !EFI_ERROR ( Status )) {
00286     EslServiceUnload ( );
00287   }
00288 
00289   //
00290   //  Return the network connection status
00291   //
00292   DBG_EXIT_STATUS ( Status );
00293   return Status;
00294 }
00295 
00296 
00300 CONST EFI_SERVICE_BINDING_PROTOCOL mEfiServiceBinding = {
00301   NULL,
00302   NULL
00303 };
00304 
00305 
00311 PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect;    
00312 PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect;  
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines