]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/SocketDxe/DriverBinding.c
Add Socket Library applications.
[mirror_edk2.git] / StdLib / SocketDxe / DriverBinding.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the driver binding protocol for the socket layer.\r
3\r
4 Copyright (c) 2011, Intel Corporation\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\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#include "Socket.h"\r
16\r
17/**\r
18 Verify the controller type\r
19\r
20 Determine if any of the network service binding protocols exist on\r
21 the controller handle. If so, verify that these protocols are not\r
22 already in use. Call ::DriverStart for any network service binding\r
23 protocol that is not in use.\r
24\r
25 @param [in] pThis Protocol instance pointer.\r
26 @param [in] Controller Handle of device to test.\r
27 @param [in] pRemainingDevicePath Not used.\r
28\r
29 @retval EFI_SUCCESS This driver supports this device.\r
30 @retval other This driver does not support this device.\r
31\r
32**/\r
33EFI_STATUS\r
34EFIAPI\r
35DriverSupported (\r
36 IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r
37 IN EFI_HANDLE Controller,\r
38 IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath\r
39 )\r
40{\r
41 CONST DT_SOCKET_BINDING * pEnd;\r
42 VOID * pInterface;\r
43 CONST DT_SOCKET_BINDING * pSocketBinding;\r
44 EFI_STATUS Status;\r
45\r
46 //\r
47 // Assume the list is empty\r
48 //\r
49 Status = EFI_UNSUPPORTED;\r
50\r
51 //\r
52 // Walk the list of network connection points\r
53 //\r
54 pSocketBinding = &cEslSocketBinding[0];\r
55 pEnd = &pSocketBinding[ cEslSocketBindingEntries ];\r
56 while ( pEnd > pSocketBinding ) {\r
57 //\r
58 // Determine if the controller supports the network protocol\r
59 //\r
60 Status = gBS->OpenProtocol (\r
61 Controller,\r
62 pSocketBinding->pNetworkBinding,\r
63 &pInterface,\r
64 pThis->DriverBindingHandle,\r
65 Controller,\r
66 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
67 );\r
68 if ( !EFI_ERROR ( Status )) {\r
69 //\r
70 // Determine if the driver is already connected\r
71 //\r
72 Status = gBS->OpenProtocol (\r
73 Controller,\r
74 (EFI_GUID *)pSocketBinding->pTagGuid,\r
75 &pInterface,\r
76 pThis->DriverBindingHandle,\r
77 Controller,\r
78 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
79 );\r
80 if ( !EFI_ERROR ( Status )) {\r
81 Status = EFI_ALREADY_STARTED;\r
82 }\r
83 else {\r
84 if ( EFI_UNSUPPORTED == Status ) {\r
85 //\r
86 // Connect the driver since the tag is not present\r
87 //\r
88 Status = EFI_SUCCESS;\r
89 }\r
90 }\r
91 }\r
92\r
93 //\r
94 // Set the next network protocol\r
95 //\r
96 pSocketBinding += 1;\r
97 }\r
98\r
99 //\r
100 // Return the device supported status\r
101 //\r
102 return Status;\r
103}\r
104\r
105\r
106/**\r
107 Connect to the network service bindings\r
108\r
109 Walk the network service protocols on the controller handle and\r
110 locate any that are not in use. Create service structures to\r
111 manage the service binding for the socket driver.\r
112\r
113 @param [in] pThis Protocol instance pointer.\r
114 @param [in] Controller Handle of device to work with.\r
115 @param [in] pRemainingDevicePath Not used, always produce all possible children.\r
116\r
117 @retval EFI_SUCCESS This driver is added to Controller.\r
118 @retval other This driver does not support this device.\r
119\r
120**/\r
121EFI_STATUS\r
122EFIAPI\r
123DriverStart (\r
124 IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r
125 IN EFI_HANDLE Controller,\r
126 IN EFI_DEVICE_PATH_PROTOCOL * pRemainingDevicePath\r
127 )\r
128{\r
129 EFI_STATUS Status;\r
130\r
131 DBG_ENTER ( );\r
132\r
133 //\r
134 // Connect to this network adapter\r
135 //\r
136 Status = EslServiceConnect ( pThis->DriverBindingHandle,\r
137 Controller );\r
138\r
139 //\r
140 // Display the driver start status\r
141 //\r
142 DBG_EXIT_STATUS ( Status );\r
143 return Status;\r
144}\r
145\r
146\r
147/**\r
148 Stop this driver on Controller by removing NetworkInterfaceIdentifier protocol and\r
149 closing the DevicePath and PciIo protocols on Controller.\r
150\r
151 @param [in] pThis Protocol instance pointer.\r
152 @param [in] Controller Handle of device to stop driver on.\r
153 @param [in] NumberOfChildren How many children need to be stopped.\r
154 @param [in] pChildHandleBuffer Not used.\r
155\r
156 @retval EFI_SUCCESS This driver is removed Controller.\r
157 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
158 @retval other This driver was not removed from this device.\r
159\r
160**/\r
161EFI_STATUS\r
162EFIAPI\r
163DriverStop (\r
164 IN EFI_DRIVER_BINDING_PROTOCOL * pThis,\r
165 IN EFI_HANDLE Controller,\r
166 IN UINTN NumberOfChildren,\r
167 IN EFI_HANDLE * pChildHandleBuffer\r
168 )\r
169{\r
170 EFI_STATUS Status;\r
171 \r
172 DBG_ENTER ( );\r
173\r
174 //\r
175 // Disconnect the network adapters\r
176 //\r
177 Status = EslServiceDisconnect ( pThis->DriverBindingHandle,\r
178 Controller );\r
179\r
180 //\r
181 // Display the driver start status\r
182 //\r
183 DBG_EXIT_STATUS ( Status );\r
184 return Status;\r
185}\r
186\r
187\r
188/**\r
189 Driver binding protocol definition\r
190**/\r
191EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = {\r
192 DriverSupported,\r
193 DriverStart,\r
194 DriverStop,\r
195 0xa,\r
196 NULL,\r
197 NULL\r
198};\r