]>
Commit | Line | Data |
---|---|---|
572287f8 | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2010, Apple, Inc. All rights reserved.<BR>\r | |
d7dd9387 | 4 | Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r |
572287f8 | 5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | Module Name:\r | |
15 | \r | |
16 | EmuSnp.c\r | |
17 | \r | |
18 | Abstract:\r | |
19 | \r | |
20 | -**/\r | |
21 | \r | |
22 | #include "EmuSnpDxe.h"\r | |
23 | \r | |
24 | \r | |
25 | \r | |
26 | EFI_SIMPLE_NETWORK_PROTOCOL gEmuSnpTemplate = {\r | |
d18d8a1d | 27 | EFI_SIMPLE_NETWORK_PROTOCOL_REVISION,\r |
28 | EmuSnpStart,\r | |
29 | EmuSnpStop,\r | |
30 | EmuSnpInitialize,\r | |
31 | EmuSnpReset,\r | |
32 | EmuSnpShutdown,\r | |
33 | EmuSnpReceiveFilters,\r | |
34 | EmuSnpStationAddress,\r | |
35 | EmuSnpStatistics,\r | |
36 | EmuSnpMcastIptoMac,\r | |
37 | EmuSnpNvdata,\r | |
38 | EmuSnpGetStatus,\r | |
39 | EmuSnpTransmit,\r | |
40 | EmuSnpReceive,\r | |
572287f8 | 41 | NULL, // WaitForPacket\r |
42 | NULL // Mode\r | |
43 | };\r | |
44 | \r | |
45 | \r | |
46 | \r | |
47 | \r | |
48 | /**\r | |
49 | Changes the state of a network interface from "stopped" to "started".\r | |
50 | \r | |
51 | @param This Protocol instance pointer.\r | |
52 | \r | |
53 | @retval EFI_SUCCESS Always succeeds.\r | |
54 | \r | |
55 | **/\r | |
56 | EFI_STATUS\r | |
57 | EFIAPI\r | |
58 | EmuSnpStart(\r | |
59 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
60 | )\r | |
61 | {\r | |
62 | EFI_STATUS Status;\r | |
63 | EMU_SNP_PRIVATE_DATA *Private;\r | |
64 | \r | |
65 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
66 | \r | |
67 | Status = Private->Io->Start (Private->Io);\r | |
68 | return Status;\r | |
69 | }\r | |
70 | \r | |
71 | \r | |
72 | /**\r | |
73 | Changes the state of a network interface from "started" to "stopped".\r | |
74 | \r | |
75 | @param This Protocol instance pointer.\r | |
76 | \r | |
77 | @retval EFI_SUCCESS Always succeeds.\r | |
78 | \r | |
79 | **/\r | |
80 | EFI_STATUS\r | |
81 | EFIAPI\r | |
82 | EmuSnpStop (\r | |
83 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
84 | )\r | |
85 | {\r | |
86 | EFI_STATUS Status;\r | |
87 | EMU_SNP_PRIVATE_DATA *Private;\r | |
88 | \r | |
89 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
90 | \r | |
91 | Status = Private->Io->Stop (Private->Io);\r | |
92 | return Status;\r | |
93 | }\r | |
94 | \r | |
95 | \r | |
96 | /**\r | |
d18d8a1d | 97 | Resets a network adapter and allocates the transmit and receive buffers\r |
98 | required by the network interface; optionally, also requests allocation\r | |
572287f8 | 99 | of additional transmit and receive buffers.\r |
100 | \r | |
101 | @param This Protocol instance pointer.\r | |
102 | @param ExtraRxBufferSize The size, in bytes, of the extra receive buffer space\r | |
103 | that the driver should allocate for the network interface.\r | |
104 | Some network interfaces will not be able to use the extra\r | |
105 | buffer, and the caller will not know if it is actually\r | |
106 | being used.\r | |
107 | @param ExtraTxBufferSize The size, in bytes, of the extra transmit buffer space\r | |
108 | that the driver should allocate for the network interface.\r | |
109 | Some network interfaces will not be able to use the extra\r | |
110 | buffer, and the caller will not know if it is actually\r | |
111 | being used.\r | |
112 | \r | |
113 | @retval EFI_SUCCESS Always succeeds.\r | |
114 | \r | |
115 | **/\r | |
116 | EFI_STATUS\r | |
117 | EFIAPI\r | |
118 | EmuSnpInitialize (\r | |
119 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
120 | IN UINTN ExtraRxBufferSize OPTIONAL,\r | |
121 | IN UINTN ExtraTxBufferSize OPTIONAL\r | |
122 | )\r | |
123 | {\r | |
124 | EFI_STATUS Status;\r | |
125 | EMU_SNP_PRIVATE_DATA *Private;\r | |
126 | \r | |
127 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
128 | \r | |
129 | Status = Private->Io->Initialize (Private->Io, ExtraRxBufferSize, ExtraTxBufferSize);\r | |
130 | return Status;\r | |
131 | }\r | |
132 | \r | |
133 | /**\r | |
d18d8a1d | 134 | Resets a network adapter and re-initializes it with the parameters that were\r |
135 | provided in the previous call to Initialize().\r | |
572287f8 | 136 | \r |
137 | @param This Protocol instance pointer.\r | |
138 | @param ExtendedVerification Indicates that the driver may perform a more\r | |
139 | exhaustive verification operation of the device\r | |
140 | during reset.\r | |
141 | \r | |
142 | @retval EFI_SUCCESS Always succeeds.\r | |
143 | \r | |
144 | **/\r | |
145 | EFI_STATUS\r | |
146 | EFIAPI\r | |
147 | EmuSnpReset (\r | |
148 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
149 | IN BOOLEAN ExtendedVerification\r | |
150 | )\r | |
151 | {\r | |
152 | EFI_STATUS Status;\r | |
153 | EMU_SNP_PRIVATE_DATA *Private;\r | |
154 | \r | |
155 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
156 | \r | |
157 | Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r | |
158 | return Status;\r | |
159 | }\r | |
160 | \r | |
161 | /**\r | |
d18d8a1d | 162 | Resets a network adapter and leaves it in a state that is safe for\r |
572287f8 | 163 | another driver to initialize.\r |
164 | \r | |
165 | @param This Protocol instance pointer.\r | |
166 | \r | |
167 | @retval EFI_SUCCESS Always succeeds.\r | |
168 | \r | |
169 | **/\r | |
170 | EFI_STATUS\r | |
171 | EFIAPI\r | |
172 | EmuSnpShutdown (\r | |
173 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This\r | |
174 | )\r | |
175 | {\r | |
176 | EFI_STATUS Status;\r | |
177 | EMU_SNP_PRIVATE_DATA *Private;\r | |
178 | \r | |
179 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
180 | \r | |
181 | Status = Private->Io->Shutdown (Private->Io);\r | |
182 | return Status;\r | |
183 | }\r | |
184 | \r | |
185 | /**\r | |
186 | Manages the multicast receive filters of a network interface.\r | |
187 | \r | |
188 | @param This Protocol instance pointer.\r | |
189 | @param EnableBits A bit mask of receive filters to enable on the network interface.\r | |
190 | @param DisableBits A bit mask of receive filters to disable on the network interface.\r | |
191 | @param ResetMcastFilter Set to TRUE to reset the contents of the multicast receive\r | |
192 | filters on the network interface to their default values.\r | |
193 | @param McastFilterCount Number of multicast HW MAC addresses in the new\r | |
194 | MCastFilter list. This value must be less than or equal to\r | |
195 | the MCastFilterCnt field of EFI_SIMPLE_NETWORK_MODE. This\r | |
196 | field is optional if ResetMCastFilter is TRUE.\r | |
197 | @param McastFilter A pointer to a list of new multicast receive filter HW MAC\r | |
198 | addresses. This list will replace any existing multicast\r | |
199 | HW MAC address list. This field is optional if\r | |
200 | ResetMCastFilter is TRUE.\r | |
201 | \r | |
202 | @retval EFI_SUCCESS The multicast receive filter list was updated.\r | |
203 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
204 | \r | |
205 | **/\r | |
206 | EFI_STATUS\r | |
207 | EFIAPI\r | |
208 | EmuSnpReceiveFilters (\r | |
209 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
210 | IN UINT32 EnableBits,\r | |
211 | IN UINT32 DisableBits,\r | |
212 | IN BOOLEAN ResetMcastFilter,\r | |
213 | IN UINTN McastFilterCount OPTIONAL,\r | |
214 | IN EFI_MAC_ADDRESS *McastFilter OPTIONAL\r | |
215 | )\r | |
216 | {\r | |
217 | EFI_STATUS Status;\r | |
218 | EMU_SNP_PRIVATE_DATA *Private;\r | |
219 | \r | |
220 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
221 | \r | |
222 | Status = Private->Io->ReceiveFilters (\r | |
223 | Private->Io,\r | |
224 | EnableBits,\r | |
225 | DisableBits,\r | |
226 | ResetMcastFilter,\r | |
227 | McastFilterCount,\r | |
228 | McastFilter\r | |
229 | );\r | |
230 | return Status;\r | |
231 | }\r | |
232 | \r | |
233 | /**\r | |
234 | Modifies or resets the current station address, if supported.\r | |
235 | \r | |
236 | @param This Protocol instance pointer.\r | |
237 | @param Reset Flag used to reset the station address to the network interfaces\r | |
238 | permanent address.\r | |
239 | @param NewMacAddr New station address to be used for the network interface.\r | |
240 | \r | |
241 | @retval EFI_UNSUPPORTED Not supported yet.\r | |
242 | \r | |
243 | **/\r | |
244 | EFI_STATUS\r | |
245 | EFIAPI\r | |
246 | EmuSnpStationAddress (\r | |
247 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
248 | IN BOOLEAN Reset,\r | |
249 | IN EFI_MAC_ADDRESS *NewMacAddr OPTIONAL\r | |
250 | )\r | |
251 | {\r | |
252 | EFI_STATUS Status;\r | |
253 | EMU_SNP_PRIVATE_DATA *Private;\r | |
254 | \r | |
255 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
256 | \r | |
257 | Status = Private->Io->StationAddress (Private->Io, Reset, NewMacAddr);\r | |
258 | return Status;\r | |
259 | }\r | |
260 | \r | |
261 | /**\r | |
262 | Resets or collects the statistics on a network interface.\r | |
263 | \r | |
264 | @param This Protocol instance pointer.\r | |
265 | @param Reset Set to TRUE to reset the statistics for the network interface.\r | |
266 | @param StatisticsSize On input the size, in bytes, of StatisticsTable. On\r | |
267 | output the size, in bytes, of the resulting table of\r | |
268 | statistics.\r | |
269 | @param StatisticsTable A pointer to the EFI_NETWORK_STATISTICS structure that\r | |
270 | contains the statistics.\r | |
271 | \r | |
272 | @retval EFI_SUCCESS The statistics were collected from the network interface.\r | |
273 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
274 | @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r | |
275 | size needed to hold the statistics is returned in\r | |
276 | StatisticsSize.\r | |
277 | @retval EFI_UNSUPPORTED Not supported yet.\r | |
278 | \r | |
279 | **/\r | |
280 | EFI_STATUS\r | |
281 | EFIAPI\r | |
282 | EmuSnpStatistics (\r | |
283 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
284 | IN BOOLEAN Reset,\r | |
285 | IN OUT UINTN *StatisticsSize OPTIONAL,\r | |
286 | OUT EFI_NETWORK_STATISTICS *StatisticsTable OPTIONAL\r | |
287 | )\r | |
288 | {\r | |
289 | EFI_STATUS Status;\r | |
290 | EMU_SNP_PRIVATE_DATA *Private;\r | |
291 | \r | |
292 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
293 | \r | |
294 | Status = Private->Io->Statistics (Private->Io, Reset, StatisticsSize, StatisticsTable);\r | |
295 | return Status;\r | |
296 | }\r | |
297 | \r | |
298 | /**\r | |
299 | Converts a multicast IP address to a multicast HW MAC address.\r | |
300 | \r | |
301 | @param This Protocol instance pointer.\r | |
302 | @param Ipv6 Set to TRUE if the multicast IP address is IPv6 [RFC 2460]. Set\r | |
303 | to FALSE if the multicast IP address is IPv4 [RFC 791].\r | |
304 | @param Ip The multicast IP address that is to be converted to a multicast\r | |
305 | HW MAC address.\r | |
306 | @param Mac The multicast HW MAC address that is to be generated from IP.\r | |
307 | \r | |
308 | @retval EFI_SUCCESS The multicast IP address was mapped to the multicast\r | |
309 | HW MAC address.\r | |
310 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
311 | @retval EFI_BUFFER_TOO_SMALL The Statistics buffer was too small. The current buffer\r | |
312 | size needed to hold the statistics is returned in\r | |
313 | StatisticsSize.\r | |
314 | @retval EFI_UNSUPPORTED Not supported yet.\r | |
315 | \r | |
316 | **/\r | |
317 | EFI_STATUS\r | |
318 | EFIAPI\r | |
319 | EmuSnpMcastIptoMac (\r | |
320 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
321 | IN BOOLEAN Ipv6,\r | |
322 | IN EFI_IP_ADDRESS *Ip,\r | |
323 | OUT EFI_MAC_ADDRESS *Mac\r | |
324 | )\r | |
325 | {\r | |
326 | EFI_STATUS Status;\r | |
327 | EMU_SNP_PRIVATE_DATA *Private;\r | |
328 | \r | |
329 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
330 | \r | |
331 | Status = Private->Io->MCastIpToMac (Private->Io, Ipv6, Ip, Mac);\r | |
332 | return Status;\r | |
333 | }\r | |
334 | \r | |
335 | \r | |
336 | /**\r | |
d18d8a1d | 337 | Performs read and write operations on the NVRAM device attached to a\r |
572287f8 | 338 | network interface.\r |
339 | \r | |
340 | @param This Protocol instance pointer.\r | |
341 | @param ReadOrWrite TRUE for read operations, FALSE for write operations.\r | |
342 | @param Offset Byte offset in the NVRAM device at which to start the read or\r | |
343 | write operation. This must be a multiple of NvRamAccessSize and\r | |
344 | less than NvRamSize.\r | |
345 | @param BufferSize The number of bytes to read or write from the NVRAM device.\r | |
346 | This must also be a multiple of NvramAccessSize.\r | |
347 | @param Buffer A pointer to the data buffer.\r | |
348 | \r | |
349 | @retval EFI_UNSUPPORTED Not supported yet.\r | |
350 | \r | |
351 | **/\r | |
352 | EFI_STATUS\r | |
353 | EFIAPI\r | |
354 | EmuSnpNvdata (\r | |
355 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
356 | IN BOOLEAN ReadOrWrite,\r | |
357 | IN UINTN Offset,\r | |
358 | IN UINTN BufferSize,\r | |
359 | IN OUT VOID *Buffer\r | |
360 | )\r | |
361 | {\r | |
362 | EFI_STATUS Status;\r | |
363 | EMU_SNP_PRIVATE_DATA *Private;\r | |
364 | \r | |
365 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
366 | \r | |
367 | Status = Private->Io->NvData (Private->Io, ReadOrWrite, Offset, BufferSize, Buffer);\r | |
368 | return Status;\r | |
369 | }\r | |
370 | \r | |
371 | \r | |
372 | /**\r | |
d18d8a1d | 373 | Reads the current interrupt status and recycled transmit buffer status from\r |
572287f8 | 374 | a network interface.\r |
375 | \r | |
376 | @param This Protocol instance pointer.\r | |
377 | @param InterruptStatus A pointer to the bit mask of the currently active interrupts\r | |
378 | If this is NULL, the interrupt status will not be read from\r | |
379 | the device. If this is not NULL, the interrupt status will\r | |
380 | be read from the device. When the interrupt status is read,\r | |
381 | it will also be cleared. Clearing the transmit interrupt\r | |
382 | does not empty the recycled transmit buffer array.\r | |
383 | @param TxBuffer Recycled transmit buffer address. The network interface will\r | |
384 | not transmit if its internal recycled transmit buffer array\r | |
385 | is full. Reading the transmit buffer does not clear the\r | |
386 | transmit interrupt. If this is NULL, then the transmit buffer\r | |
387 | status will not be read. If there are no transmit buffers to\r | |
388 | recycle and TxBuf is not NULL, * TxBuf will be set to NULL.\r | |
389 | \r | |
390 | @retval EFI_SUCCESS Always succeeds.\r | |
391 | \r | |
392 | **/\r | |
393 | EFI_STATUS\r | |
394 | EFIAPI\r | |
395 | EmuSnpGetStatus (\r | |
396 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
397 | OUT UINT32 *InterruptStatus,\r | |
398 | OUT VOID **TxBuffer\r | |
399 | )\r | |
400 | {\r | |
401 | EFI_STATUS Status;\r | |
402 | EMU_SNP_PRIVATE_DATA *Private;\r | |
403 | \r | |
404 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
405 | \r | |
406 | Status = Private->Io->GetStatus (Private->Io, InterruptStatus, TxBuffer);\r | |
407 | return Status;\r | |
408 | }\r | |
409 | \r | |
410 | \r | |
411 | /**\r | |
412 | Places a packet in the transmit queue of a network interface.\r | |
413 | \r | |
414 | @param This Protocol instance pointer.\r | |
415 | @param HeaderSize The size, in bytes, of the media header to be filled in by\r | |
416 | the Transmit() function. If HeaderSize is non-zero, then it\r | |
417 | must be equal to This->Mode->MediaHeaderSize and the DestAddr\r | |
418 | and Protocol parameters must not be NULL.\r | |
419 | @param BufferSize The size, in bytes, of the entire packet (media header and\r | |
420 | data) to be transmitted through the network interface.\r | |
421 | @param Buffer A pointer to the packet (media header followed by data) to be\r | |
422 | transmitted. This parameter cannot be NULL. If HeaderSize is zero,\r | |
423 | then the media header in Buffer must already be filled in by the\r | |
424 | caller. If HeaderSize is non-zero, then the media header will be\r | |
425 | filled in by the Transmit() function.\r | |
426 | @param SrcAddr The source HW MAC address. If HeaderSize is zero, then this parameter\r | |
427 | is ignored. If HeaderSize is non-zero and SrcAddr is NULL, then\r | |
428 | This->Mode->CurrentAddress is used for the source HW MAC address.\r | |
429 | @param DestAddr The destination HW MAC address. If HeaderSize is zero, then this\r | |
430 | parameter is ignored.\r | |
431 | @param Protocol The type of header to build. If HeaderSize is zero, then this\r | |
432 | parameter is ignored. See RFC 1700, section "Ether Types", for\r | |
433 | examples.\r | |
434 | \r | |
435 | @retval EFI_SUCCESS The packet was placed on the transmit queue.\r | |
436 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
437 | @retval EFI_INVALID_PARAMETER One or more of the parameters has an unsupported value.\r | |
438 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
439 | \r | |
440 | **/\r | |
441 | EFI_STATUS\r | |
442 | EFIAPI\r | |
443 | EmuSnpTransmit (\r | |
444 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
445 | IN UINTN HeaderSize,\r | |
446 | IN UINTN BufferSize,\r | |
447 | IN VOID* Buffer,\r | |
448 | IN EFI_MAC_ADDRESS *SrcAddr OPTIONAL,\r | |
449 | IN EFI_MAC_ADDRESS *DestAddr OPTIONAL,\r | |
450 | IN UINT16 *Protocol OPTIONAL\r | |
451 | )\r | |
452 | {\r | |
453 | EFI_STATUS Status;\r | |
454 | EMU_SNP_PRIVATE_DATA *Private;\r | |
455 | \r | |
456 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
457 | \r | |
458 | Status = Private->Io->Transmit (\r | |
459 | Private->Io,\r | |
460 | HeaderSize,\r | |
461 | BufferSize,\r | |
462 | Buffer,\r | |
463 | SrcAddr,\r | |
464 | DestAddr,\r | |
465 | Protocol\r | |
466 | );\r | |
467 | return Status;\r | |
468 | }\r | |
469 | \r | |
470 | /**\r | |
471 | Receives a packet from a network interface.\r | |
472 | \r | |
473 | @param This Protocol instance pointer.\r | |
474 | @param HeaderSize The size, in bytes, of the media header received on the network\r | |
475 | interface. If this parameter is NULL, then the media header size\r | |
476 | will not be returned.\r | |
477 | @param BuffSize On entry, the size, in bytes, of Buffer. On exit, the size, in\r | |
478 | bytes, of the packet that was received on the network interface.\r | |
479 | @param Buffer A pointer to the data buffer to receive both the media header and\r | |
480 | the data.\r | |
481 | @param SourceAddr The source HW MAC address. If this parameter is NULL, the\r | |
482 | HW MAC source address will not be extracted from the media\r | |
483 | header.\r | |
484 | @param DestinationAddr The destination HW MAC address. If this parameter is NULL,\r | |
485 | the HW MAC destination address will not be extracted from the\r | |
486 | media header.\r | |
487 | @param Protocol The media header type. If this parameter is NULL, then the\r | |
488 | protocol will not be extracted from the media header. See\r | |
489 | RFC 1700 section "Ether Types" for examples.\r | |
490 | \r | |
491 | @retval EFI_SUCCESS The received data was stored in Buffer, and BufferSize has\r | |
492 | been updated to the number of bytes received.\r | |
493 | @retval EFI_NOT_READY The network interface is too busy to accept this transmit\r | |
494 | request.\r | |
495 | @retval EFI_NOT_STARTED The network interface has not been started.\r | |
496 | @retval EFI_BUFFER_TOO_SMALL The BufferSize parameter is too small.\r | |
497 | @retval EFI_DEVICE_ERROR The command could not be sent to the network interface.\r | |
498 | \r | |
499 | **/\r | |
500 | EFI_STATUS\r | |
501 | EFIAPI\r | |
502 | EmuSnpReceive (\r | |
503 | IN EFI_SIMPLE_NETWORK_PROTOCOL *This,\r | |
504 | OUT UINTN *HeaderSize OPTIONAL,\r | |
505 | IN OUT UINTN *BuffSize,\r | |
506 | OUT VOID *Buffer,\r | |
507 | OUT EFI_MAC_ADDRESS *SourceAddr OPTIONAL,\r | |
508 | OUT EFI_MAC_ADDRESS *DestinationAddr OPTIONAL,\r | |
509 | OUT UINT16 *Protocol OPTIONAL\r | |
510 | )\r | |
511 | {\r | |
512 | EFI_STATUS Status;\r | |
513 | EMU_SNP_PRIVATE_DATA *Private;\r | |
514 | \r | |
515 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (This);\r | |
516 | \r | |
517 | Status = Private->Io->Receive (\r | |
518 | Private->Io,\r | |
519 | HeaderSize,\r | |
520 | BuffSize,\r | |
521 | Buffer,\r | |
522 | SourceAddr,\r | |
523 | DestinationAddr,\r | |
524 | Protocol\r | |
525 | );\r | |
526 | return Status;\r | |
527 | }\r | |
528 | \r | |
529 | \r | |
530 | \r | |
531 | /**\r | |
532 | Test to see if this driver supports ControllerHandle. This service\r | |
533 | is called by the EFI boot service ConnectController(). In\r | |
534 | order to make drivers as small as possible, there are a few calling\r | |
535 | restrictions for this service. ConnectController() must\r | |
536 | follow these calling restrictions. If any other agent wishes to call\r | |
537 | Supported() it must also follow these calling restrictions.\r | |
538 | \r | |
539 | @param This Protocol instance pointer.\r | |
540 | @param ControllerHandle Handle of device to test\r | |
541 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
542 | device to start.\r | |
543 | \r | |
544 | @retval EFI_SUCCESS This driver supports this device\r | |
545 | @retval EFI_UNSUPPORTED This driver does not support this device\r | |
546 | \r | |
547 | **/\r | |
548 | EFI_STATUS\r | |
549 | EFIAPI\r | |
550 | EmuSnpDriverBindingSupported (\r | |
551 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
552 | IN EFI_HANDLE ControllerHandle,\r | |
553 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
554 | )\r | |
555 | {\r | |
556 | EFI_STATUS Status;\r | |
557 | EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r | |
558 | MAC_ADDR_DEVICE_PATH *Node;\r | |
559 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
560 | \r | |
561 | if (RemainingDevicePath != NULL) {\r | |
562 | if (!IsDevicePathEnd (RemainingDevicePath)) {\r | |
563 | Node = (MAC_ADDR_DEVICE_PATH *)RemainingDevicePath;\r | |
564 | if (Node->Header.Type != MESSAGING_DEVICE_PATH ||\r | |
565 | Node->Header.SubType != MSG_MAC_ADDR_DP) {\r | |
566 | // If the remaining device path does not match we don't support the request\r | |
567 | return EFI_UNSUPPORTED;\r | |
568 | }\r | |
569 | }\r | |
570 | }\r | |
d18d8a1d | 571 | \r |
572 | \r | |
572287f8 | 573 | //\r |
574 | // Open the IO Abstraction(s) needed to perform the supported test\r | |
575 | //\r | |
576 | Status = gBS->OpenProtocol (\r | |
577 | ControllerHandle,\r | |
578 | &gEmuIoThunkProtocolGuid,\r | |
579 | (VOID **)&EmuIoThunk,\r | |
580 | This->DriverBindingHandle,\r | |
581 | ControllerHandle,\r | |
582 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
583 | );\r | |
584 | if (EFI_ERROR (Status)) {\r | |
585 | return Status;\r | |
586 | }\r | |
587 | \r | |
588 | //\r | |
589 | // Make sure GUID is for a File System handle.\r | |
590 | //\r | |
591 | Status = EFI_UNSUPPORTED;\r | |
592 | if (CompareGuid (EmuIoThunk->Protocol, &gEmuSnpProtocolGuid)) {\r | |
593 | Status = EFI_SUCCESS;\r | |
594 | }\r | |
595 | \r | |
596 | //\r | |
597 | // Close the I/O Abstraction(s) used to perform the supported test\r | |
598 | //\r | |
599 | gBS->CloseProtocol (\r | |
600 | ControllerHandle,\r | |
601 | &gEmuIoThunkProtocolGuid,\r | |
602 | This->DriverBindingHandle,\r | |
603 | ControllerHandle\r | |
604 | );\r | |
d18d8a1d | 605 | \r |
606 | \r | |
572287f8 | 607 | //\r |
608 | // Open the EFI Device Path protocol needed to perform the supported test\r | |
609 | //\r | |
610 | Status = gBS->OpenProtocol (\r | |
611 | ControllerHandle,\r | |
612 | &gEfiDevicePathProtocolGuid,\r | |
613 | (VOID **) &ParentDevicePath,\r | |
614 | This->DriverBindingHandle,\r | |
615 | ControllerHandle,\r | |
616 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
617 | );\r | |
618 | if (Status == EFI_ALREADY_STARTED) {\r | |
619 | return EFI_SUCCESS;\r | |
620 | }\r | |
621 | \r | |
622 | if (EFI_ERROR (Status)) {\r | |
623 | return Status;\r | |
624 | }\r | |
625 | \r | |
626 | //\r | |
627 | // Close protocol, don't use device path protocol in the Support() function\r | |
628 | //\r | |
629 | gBS->CloseProtocol (\r | |
630 | ControllerHandle,\r | |
631 | &gEfiDevicePathProtocolGuid,\r | |
632 | This->DriverBindingHandle,\r | |
633 | ControllerHandle\r | |
634 | );\r | |
635 | \r | |
636 | return Status;\r | |
637 | }\r | |
638 | \r | |
639 | \r | |
640 | /**\r | |
641 | Start this driver on ControllerHandle. This service is called by the\r | |
642 | EFI boot service ConnectController(). In order to make\r | |
643 | drivers as small as possible, there are a few calling restrictions for\r | |
644 | this service. ConnectController() must follow these\r | |
645 | calling restrictions. If any other agent wishes to call Start() it\r | |
646 | must also follow these calling restrictions.\r | |
647 | \r | |
648 | @param This Protocol instance pointer.\r | |
649 | @param ControllerHandle Handle of device to bind driver to\r | |
650 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
651 | device to start.\r | |
652 | \r | |
653 | @retval EFI_SUCCESS Always succeeds.\r | |
654 | \r | |
655 | **/\r | |
656 | EFI_STATUS\r | |
657 | EFIAPI\r | |
658 | EmuSnpDriverBindingStart (\r | |
659 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
660 | IN EFI_HANDLE ControllerHandle,\r | |
661 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r | |
662 | )\r | |
663 | {\r | |
664 | EFI_STATUS Status;\r | |
665 | EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r | |
666 | EMU_SNP_PRIVATE_DATA *Private;\r | |
667 | MAC_ADDR_DEVICE_PATH Node;\r | |
668 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
669 | \r | |
54e0b04c | 670 | Private = NULL;\r |
671 | \r | |
572287f8 | 672 | //\r |
673 | // Grab the protocols we need\r | |
674 | //\r | |
572287f8 | 675 | Status = gBS->OpenProtocol(\r |
676 | ControllerHandle,\r | |
677 | &gEfiDevicePathProtocolGuid,\r | |
678 | ( VOID ** ) &ParentDevicePath,\r | |
679 | This->DriverBindingHandle,\r | |
680 | ControllerHandle,\r | |
681 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
682 | );\r | |
683 | if (EFI_ERROR (Status) && Status) {\r | |
684 | return Status;\r | |
685 | }\r | |
686 | \r | |
687 | Status = gBS->OpenProtocol (\r | |
688 | ControllerHandle,\r | |
689 | &gEmuIoThunkProtocolGuid,\r | |
690 | (VOID **)&EmuIoThunk,\r | |
691 | This->DriverBindingHandle,\r | |
692 | ControllerHandle,\r | |
693 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
694 | );\r | |
695 | if (EFI_ERROR (Status)) {\r | |
696 | return Status;\r | |
697 | }\r | |
698 | \r | |
699 | if (!CompareGuid (EmuIoThunk->Protocol, &gEmuSnpProtocolGuid)) {\r | |
700 | return EFI_UNSUPPORTED;\r | |
701 | }\r | |
702 | \r | |
703 | Status = EmuIoThunk->Open (EmuIoThunk);\r | |
704 | if (EFI_ERROR (Status)) {\r | |
705 | goto Done;\r | |
706 | }\r | |
707 | \r | |
708 | //\r | |
709 | // Allocate the private data.\r | |
710 | //\r | |
711 | Private = AllocateZeroPool (sizeof (EMU_SNP_PRIVATE_DATA));\r | |
712 | if (Private == NULL) {\r | |
713 | Status = EFI_OUT_OF_RESOURCES;\r | |
714 | goto Done;\r | |
715 | }\r | |
716 | \r | |
717 | CopyMem (&Private->Snp, &gEmuSnpTemplate, sizeof (EFI_SIMPLE_NETWORK_PROTOCOL));\r | |
718 | \r | |
719 | Private->Signature = EMU_SNP_PRIVATE_DATA_SIGNATURE;\r | |
720 | Private->IoThunk = EmuIoThunk;\r | |
721 | Private->Io = EmuIoThunk->Interface;\r | |
722 | Private->EfiHandle = ControllerHandle;\r | |
723 | Private->DeviceHandle = NULL;\r | |
724 | Private->Snp.Mode = &Private->Mode;\r | |
725 | Private->ControllerNameTable = NULL;\r | |
726 | \r | |
d18d8a1d | 727 | \r |
572287f8 | 728 | Status = Private->Io->CreateMapping (Private->Io, &Private->Mode);\r |
729 | if (EFI_ERROR (Status)) {\r | |
730 | goto Done;\r | |
731 | }\r | |
732 | \r | |
733 | //\r | |
734 | // Build the device path by appending the MAC node to the ParentDevicePath\r | |
735 | // from the EmuIo handle.\r | |
736 | //\r | |
737 | ZeroMem (&Node, sizeof (MAC_ADDR_DEVICE_PATH));\r | |
738 | \r | |
739 | Node.Header.Type = MESSAGING_DEVICE_PATH;\r | |
740 | Node.Header.SubType = MSG_MAC_ADDR_DP;\r | |
741 | Node.IfType = Private->Mode.IfType;\r | |
742 | \r | |
743 | SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL * )&Node, sizeof (MAC_ADDR_DEVICE_PATH));\r | |
744 | \r | |
745 | CopyMem (&Node.MacAddress, &Private->Mode.CurrentAddress, sizeof (EFI_MAC_ADDRESS));\r | |
746 | \r | |
747 | //\r | |
748 | // Build the device path by appending the MAC node to the ParentDevicePath from the EmuIo handle.\r | |
749 | //\r | |
750 | Private->DevicePath = AppendDevicePathNode (ParentDevicePath, (EFI_DEVICE_PATH_PROTOCOL *)&Node);\r | |
751 | if ( Private->DevicePath == NULL ) {\r | |
752 | Status = EFI_OUT_OF_RESOURCES;\r | |
753 | goto Done;\r | |
754 | }\r | |
755 | \r | |
756 | AddUnicodeString2 (\r | |
757 | "eng",\r | |
758 | gEmuSnpDriverComponentName.SupportedLanguages,\r | |
759 | &Private->ControllerNameTable,\r | |
760 | EmuIoThunk->ConfigString,\r | |
761 | TRUE\r | |
762 | );\r | |
d18d8a1d | 763 | \r |
572287f8 | 764 | AddUnicodeString2 (\r |
765 | "en",\r | |
766 | gEmuSnpDriverComponentName2.SupportedLanguages,\r | |
767 | &Private->ControllerNameTable,\r | |
768 | EmuIoThunk->ConfigString,\r | |
769 | FALSE\r | |
770 | );\r | |
771 | \r | |
772 | //\r | |
773 | // Create Child Handle\r | |
774 | //\r | |
775 | Status = gBS->InstallMultipleProtocolInterfaces(\r | |
776 | &Private->DeviceHandle,\r | |
777 | &gEfiSimpleNetworkProtocolGuid, &Private->Snp,\r | |
778 | &gEfiDevicePathProtocolGuid, Private->DevicePath,\r | |
779 | NULL\r | |
780 | );\r | |
781 | if (EFI_ERROR (Status)) {\r | |
782 | goto Done;\r | |
783 | }\r | |
784 | \r | |
785 | //\r | |
786 | // Open For Child Device\r | |
787 | //\r | |
788 | Status = gBS->OpenProtocol (\r | |
789 | ControllerHandle,\r | |
790 | &gEmuIoThunkProtocolGuid,\r | |
791 | (VOID **)&EmuIoThunk,\r | |
792 | This->DriverBindingHandle,\r | |
793 | Private->DeviceHandle,\r | |
794 | EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r | |
795 | );\r | |
796 | \r | |
797 | Done:\r | |
798 | if (EFI_ERROR (Status)) {\r | |
799 | if (Private != NULL) {\r | |
800 | FreePool (Private);\r | |
801 | }\r | |
802 | if (ParentDevicePath != NULL) {\r | |
803 | gBS->CloseProtocol(\r | |
804 | ControllerHandle,\r | |
805 | &gEfiDevicePathProtocolGuid,\r | |
806 | This->DriverBindingHandle,\r | |
807 | ControllerHandle\r | |
808 | );\r | |
809 | }\r | |
810 | }\r | |
811 | \r | |
812 | return Status;\r | |
813 | }\r | |
814 | \r | |
815 | /**\r | |
816 | Stop this driver on ControllerHandle. This service is called by the\r | |
817 | EFI boot service DisconnectController(). In order to\r | |
818 | make drivers as small as possible, there are a few calling\r | |
819 | restrictions for this service. DisconnectController()\r | |
820 | must follow these calling restrictions. If any other agent wishes\r | |
821 | to call Stop() it must also follow these calling restrictions.\r | |
d18d8a1d | 822 | \r |
572287f8 | 823 | @param This Protocol instance pointer.\r |
824 | @param ControllerHandle Handle of device to stop driver on\r | |
825 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r | |
826 | children is zero stop the entire bus driver.\r | |
827 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
828 | \r | |
829 | @retval EFI_SUCCESS Always succeeds.\r | |
830 | \r | |
831 | **/\r | |
832 | EFI_STATUS\r | |
833 | EFIAPI\r | |
834 | EmuSnpDriverBindingStop (\r | |
835 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
836 | IN EFI_HANDLE ControllerHandle,\r | |
837 | IN UINTN NumberOfChildren,\r | |
838 | IN EFI_HANDLE *ChildHandleBuffer\r | |
839 | )\r | |
840 | {\r | |
841 | EFI_STATUS Status;\r | |
842 | EMU_SNP_PRIVATE_DATA *Private = NULL;\r | |
843 | EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r | |
572287f8 | 844 | \r |
845 | //\r | |
846 | // Complete all outstanding transactions to Controller.\r | |
847 | // Don't allow any new transaction to Controller to be started.\r | |
848 | //\r | |
849 | if (NumberOfChildren == 0) {\r | |
850 | //\r | |
851 | // Close the bus driver\r | |
852 | //\r | |
853 | Status = gBS->CloseProtocol (\r | |
854 | ControllerHandle,\r | |
855 | &gEmuIoThunkProtocolGuid,\r | |
856 | This->DriverBindingHandle,\r | |
857 | ControllerHandle\r | |
858 | );\r | |
859 | \r | |
860 | Status = gBS->CloseProtocol (\r | |
861 | ControllerHandle,\r | |
862 | &gEfiDevicePathProtocolGuid,\r | |
863 | This->DriverBindingHandle,\r | |
864 | ControllerHandle\r | |
865 | );\r | |
866 | return Status;\r | |
867 | }\r | |
868 | \r | |
869 | ASSERT (NumberOfChildren == 1);\r | |
d18d8a1d | 870 | \r |
871 | \r | |
572287f8 | 872 | //\r |
873 | // Get our context back.\r | |
874 | //\r | |
875 | Status = gBS->OpenProtocol(\r | |
876 | ChildHandleBuffer[0],\r | |
877 | &gEfiSimpleNetworkProtocolGuid,\r | |
878 | ( VOID ** ) &Snp,\r | |
879 | This->DriverBindingHandle,\r | |
880 | ControllerHandle,\r | |
881 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
882 | );\r | |
883 | if (EFI_ERROR (Status)) {\r | |
884 | return EFI_DEVICE_ERROR;\r | |
885 | }\r | |
886 | \r | |
887 | Private = EMU_SNP_PRIVATE_DATA_FROM_SNP_THIS (Snp);\r | |
888 | Status = Private->IoThunk->Close (Private->IoThunk);\r | |
889 | \r | |
890 | Status = gBS->CloseProtocol(\r | |
891 | ChildHandleBuffer[0],\r | |
892 | &gEmuIoThunkProtocolGuid,\r | |
893 | This->DriverBindingHandle,\r | |
894 | Private->DeviceHandle\r | |
895 | );\r | |
896 | \r | |
897 | Status = gBS->UninstallMultipleProtocolInterfaces(\r | |
898 | ChildHandleBuffer[0],\r | |
899 | &gEfiSimpleNetworkProtocolGuid, &Private->Snp,\r | |
900 | &gEfiDevicePathProtocolGuid, Private->DevicePath,\r | |
901 | NULL\r | |
902 | );\r | |
903 | \r | |
904 | FreePool (Private->DevicePath);\r | |
905 | FreeUnicodeStringTable (Private->ControllerNameTable);\r | |
906 | FreePool (Private);\r | |
907 | \r | |
908 | return EFI_SUCCESS;\r | |
909 | }\r | |
910 | \r | |
911 | \r | |
912 | EFI_DRIVER_BINDING_PROTOCOL gEmuSnpDriverBinding = {\r | |
913 | EmuSnpDriverBindingSupported,\r | |
914 | EmuSnpDriverBindingStart,\r | |
915 | EmuSnpDriverBindingStop,\r | |
916 | 0xA,\r | |
917 | NULL,\r | |
918 | NULL\r | |
919 | };\r | |
920 | \r | |
921 | \r | |
922 | \r | |
923 | /**\r | |
924 | This is the declaration of an EFI image entry point. This entry point is\r | |
925 | the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r | |
926 | both device drivers and bus drivers.\r | |
927 | \r | |
928 | @param ImageHandle The firmware allocated handle for the UEFI image.\r | |
929 | @param SystemTable A pointer to the EFI System Table.\r | |
930 | \r | |
931 | @retval EFI_SUCCESS The operation completed successfully.\r | |
932 | @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r | |
933 | \r | |
934 | **/\r | |
935 | EFI_STATUS\r | |
936 | EFIAPI\r | |
937 | InitializeEmuSnpDriver (\r | |
938 | IN EFI_HANDLE ImageHandle,\r | |
939 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
940 | )\r | |
941 | {\r | |
942 | EFI_STATUS Status;\r | |
943 | \r | |
944 | //\r | |
945 | // Install the Driver Protocols\r | |
946 | //\r | |
947 | \r | |
948 | Status = EfiLibInstallDriverBindingComponentName2(\r | |
949 | ImageHandle,\r | |
950 | SystemTable,\r | |
951 | &gEmuSnpDriverBinding,\r | |
952 | ImageHandle,\r | |
953 | &gEmuSnpDriverComponentName,\r | |
954 | &gEmuSnpDriverComponentName2\r | |
955 | );\r | |
956 | \r | |
957 | return Status;\r | |
958 | }\r |