Browse Source

[efi] Expose DHCP packets via the Apple NetBoot protocol

Mac OS X uses non-standard EFI protocols to obtain the DHCP packets
from the UEFI firmware.

Originally-implemented-by: Michael Kuron <m.kuron@gmx.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
aa4b038c70

+ 46
- 0
src/include/ipxe/efi/Protocol/AppleNetBoot.h View File

@@ -0,0 +1,46 @@
1
+#ifndef __EFI_APPLE_NET_BOOT_PROTOCOL_H__
2
+#define __EFI_APPLE_NET_BOOT_PROTOCOL_H__
3
+
4
+/** @file
5
+ *
6
+ * Apple Net Boot Protocol
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( BSD3 );
11
+
12
+#define EFI_APPLE_NET_BOOT_PROTOCOL_GUID				\
13
+	{ 0x78ee99fb, 0x6a5e, 0x4186,					\
14
+	{ 0x97, 0xde, 0xcd, 0x0a, 0xba, 0x34, 0x5a, 0x74 } }
15
+
16
+typedef struct _EFI_APPLE_NET_BOOT_PROTOCOL EFI_APPLE_NET_BOOT_PROTOCOL;
17
+
18
+/**
19
+  Get a DHCP packet obtained by the firmware during NetBoot.
20
+
21
+  @param  This		A pointer to the APPLE_NET_BOOT_PROTOCOL instance.
22
+  @param  BufferSize	A pointer to the size of the buffer in bytes.
23
+  @param  DataBuffer	The memory buffer to copy the packet to. If it is
24
+			NULL, then the size of the packet is returned
25
+			in BufferSize.
26
+  @retval EFI_SUCCESS		The packet was copied.
27
+  @retval EFI_BUFFER_TOO_SMALL	The BufferSize is too small to read the
28
+				current packet. BufferSize has been
29
+				updated with the size needed to
30
+				complete the request.
31
+**/
32
+typedef
33
+EFI_STATUS
34
+(EFIAPI *GET_DHCP_RESPONSE) (
35
+  IN EFI_APPLE_NET_BOOT_PROTOCOL	*This,
36
+  IN OUT UINTN				*BufferSize,
37
+  OUT VOID				*DataBuffer
38
+  );
39
+
40
+struct _EFI_APPLE_NET_BOOT_PROTOCOL
41
+{
42
+  GET_DHCP_RESPONSE	GetDhcpResponse;
43
+  GET_DHCP_RESPONSE	GetBsdpResponse;
44
+};
45
+
46
+#endif /*__EFI_APPLE_NET_BOOT_PROTOCOL_H__ */

+ 1
- 0
src/include/ipxe/efi/efi.h View File

@@ -154,6 +154,7 @@ struct efi_config_table {
154 154
 #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
155 155
 
156 156
 extern EFI_GUID efi_absolute_pointer_protocol_guid;
157
+extern EFI_GUID efi_apple_net_boot_protocol_guid;
157 158
 extern EFI_GUID efi_arp_protocol_guid;
158 159
 extern EFI_GUID efi_arp_service_binding_protocol_guid;
159 160
 extern EFI_GUID efi_block_io_protocol_guid;

+ 2
- 0
src/interface/efi/efi_debug.c View File

@@ -71,6 +71,8 @@ struct efi_well_known_guid {
71 71
 static struct efi_well_known_guid efi_well_known_guids[] = {
72 72
 	{ &efi_absolute_pointer_protocol_guid,
73 73
 	  "AbsolutePointer" },
74
+	{ &efi_apple_net_boot_protocol_guid,
75
+	  "AppleNetBoot" },
74 76
 	{ &efi_arp_protocol_guid,
75 77
 	  "Arp" },
76 78
 	{ &efi_arp_service_binding_protocol_guid,

+ 5
- 0
src/interface/efi/efi_guid.c View File

@@ -25,6 +25,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 25
 
26 26
 #include <ipxe/efi/efi.h>
27 27
 #include <ipxe/efi/Protocol/AbsolutePointer.h>
28
+#include <ipxe/efi/Protocol/AppleNetBoot.h>
28 29
 #include <ipxe/efi/Protocol/Arp.h>
29 30
 #include <ipxe/efi/Protocol/BlockIo.h>
30 31
 #include <ipxe/efi/Protocol/BusSpecificDriverOverride.h>
@@ -84,6 +85,10 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
84 85
 EFI_GUID efi_absolute_pointer_protocol_guid
85 86
 	= EFI_ABSOLUTE_POINTER_PROTOCOL_GUID;
86 87
 
88
+/** Apple NetBoot protocol GUID */
89
+EFI_GUID efi_apple_net_boot_protocol_guid
90
+	= EFI_APPLE_NET_BOOT_PROTOCOL_GUID;
91
+
87 92
 /** ARP protocol GUID */
88 93
 EFI_GUID efi_arp_protocol_guid
89 94
 	= EFI_ARP_PROTOCOL_GUID;

+ 91
- 3
src/interface/efi/efi_pxe.c View File

@@ -42,6 +42,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
42 42
 #include <ipxe/efi/efi_snp.h>
43 43
 #include <ipxe/efi/efi_pxe.h>
44 44
 #include <ipxe/efi/Protocol/PxeBaseCode.h>
45
+#include <ipxe/efi/Protocol/AppleNetBoot.h>
45 46
 #include <usr/ifmgmt.h>
46 47
 #include <config/general.h>
47 48
 
@@ -80,6 +81,8 @@ struct efi_pxe {
80 81
 	EFI_PXE_BASE_CODE_PROTOCOL base;
81 82
 	/** PXE base code mode */
82 83
 	EFI_PXE_BASE_CODE_MODE mode;
84
+	/** Apple NetBoot protocol */
85
+	EFI_APPLE_NET_BOOT_PROTOCOL apple;
83 86
 
84 87
 	/** TCP/IP network-layer protocol */
85 88
 	struct tcpip_net_protocol *tcpip;
@@ -1498,6 +1501,83 @@ static EFI_PXE_BASE_CODE_PROTOCOL efi_pxe_base_code_protocol = {
1498 1501
 	.SetPackets	= efi_pxe_set_packets,
1499 1502
 };
1500 1503
 
1504
+/******************************************************************************
1505
+ *
1506
+ * Apple NetBoot protocol
1507
+ *
1508
+ ******************************************************************************
1509
+ */
1510
+
1511
+/**
1512
+ * Get DHCP/BSDP response
1513
+ *
1514
+ * @v packet		Packet
1515
+ * @v len		Length of data buffer
1516
+ * @v data		Data buffer
1517
+ * @ret efirc		EFI status code
1518
+ */
1519
+static EFI_STATUS EFIAPI
1520
+efi_apple_get_response ( EFI_PXE_BASE_CODE_PACKET *packet, UINTN *len,
1521
+			 VOID *data ) {
1522
+
1523
+	/* Check length */
1524
+	if ( *len < sizeof ( *packet ) ) {
1525
+		*len = sizeof ( *packet );
1526
+		return EFI_BUFFER_TOO_SMALL;
1527
+	}
1528
+
1529
+	/* Copy packet */
1530
+	memcpy ( data, packet, sizeof ( *packet ) );
1531
+	*len = sizeof ( *packet );
1532
+
1533
+	return EFI_SUCCESS;
1534
+}
1535
+
1536
+/**
1537
+ * Get DHCP response
1538
+ *
1539
+ * @v apple		Apple NetBoot protocol
1540
+ * @v len		Length of data buffer
1541
+ * @v data		Data buffer
1542
+ * @ret efirc		EFI status code
1543
+ */
1544
+static EFI_STATUS EFIAPI
1545
+efi_apple_get_dhcp_response ( EFI_APPLE_NET_BOOT_PROTOCOL *apple,
1546
+			      UINTN *len, VOID *data ) {
1547
+	struct efi_pxe *pxe = container_of ( apple, struct efi_pxe, apple );
1548
+
1549
+	return efi_apple_get_response ( &pxe->mode.DhcpAck, len, data );
1550
+}
1551
+
1552
+/**
1553
+ * Get BSDP response
1554
+ *
1555
+ * @v apple		Apple NetBoot protocol
1556
+ * @v len		Length of data buffer
1557
+ * @v data		Data buffer
1558
+ * @ret efirc		EFI status code
1559
+ */
1560
+static EFI_STATUS EFIAPI
1561
+efi_apple_get_bsdp_response ( EFI_APPLE_NET_BOOT_PROTOCOL *apple,
1562
+			      UINTN *len, VOID *data ) {
1563
+	struct efi_pxe *pxe = container_of ( apple, struct efi_pxe, apple );
1564
+
1565
+	return efi_apple_get_response ( &pxe->mode.PxeReply, len, data );
1566
+}
1567
+
1568
+/** Apple NetBoot protocol */
1569
+static EFI_APPLE_NET_BOOT_PROTOCOL efi_apple_net_boot_protocol = {
1570
+	.GetDhcpResponse = efi_apple_get_dhcp_response,
1571
+	.GetBsdpResponse = efi_apple_get_bsdp_response,
1572
+};
1573
+
1574
+/******************************************************************************
1575
+ *
1576
+ * Installer
1577
+ *
1578
+ ******************************************************************************
1579
+ */
1580
+
1501 1581
 /**
1502 1582
  * Install PXE base code protocol
1503 1583
  *
@@ -1526,6 +1606,8 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
1526 1606
 	pxe->handle = handle;
1527 1607
 	memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base ));
1528 1608
 	pxe->base.Mode = &pxe->mode;
1609
+	memcpy ( &pxe->apple, &efi_apple_net_boot_protocol,
1610
+		 sizeof ( pxe->apple ) );
1529 1611
 	pxe->buf.op = &efi_pxe_buf_operations;
1530 1612
 	intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
1531 1613
 	intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
@@ -1545,7 +1627,9 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
1545 1627
 
1546 1628
 	/* Install PXE base code protocol */
1547 1629
 	if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1548
-			&handle, &efi_pxe_base_code_protocol_guid, &pxe->base,
1630
+			&handle,
1631
+			&efi_pxe_base_code_protocol_guid, &pxe->base,
1632
+			&efi_apple_net_boot_protocol_guid, &pxe->apple,
1549 1633
 			NULL ) ) != 0 ) {
1550 1634
 		rc = -EEFI ( efirc );
1551 1635
 		DBGC ( pxe, "PXE %s could not install base code protocol: %s\n",
@@ -1560,7 +1644,9 @@ int efi_pxe_install ( EFI_HANDLE handle, struct net_device *netdev ) {
1560 1644
 	return 0;
1561 1645
 
1562 1646
 	bs->UninstallMultipleProtocolInterfaces (
1563
-			handle, &efi_pxe_base_code_protocol_guid, &pxe->base,
1647
+			handle,
1648
+			&efi_pxe_base_code_protocol_guid, &pxe->base,
1649
+			&efi_apple_net_boot_protocol_guid, &pxe->apple,
1564 1650
 			NULL );
1565 1651
  err_install_protocol:
1566 1652
 	ref_put ( &pxe->refcnt );
@@ -1590,7 +1676,9 @@ void efi_pxe_uninstall ( EFI_HANDLE handle ) {
1590 1676
 
1591 1677
 	/* Uninstall PXE base code protocol */
1592 1678
 	bs->UninstallMultipleProtocolInterfaces (
1593
-			handle, &efi_pxe_base_code_protocol_guid, &pxe->base,
1679
+			handle,
1680
+			&efi_pxe_base_code_protocol_guid, &pxe->base,
1681
+			&efi_apple_net_boot_protocol_guid, &pxe->apple,
1594 1682
 			NULL );
1595 1683
 
1596 1684
 	/* Remove from list and drop list's reference */

Loading…
Cancel
Save