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