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

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
 #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
154
 #define EEFI( efirc ) EPLATFORM ( EINFO_EPLATFORM, efirc )
155
 
155
 
156
 extern EFI_GUID efi_absolute_pointer_protocol_guid;
156
 extern EFI_GUID efi_absolute_pointer_protocol_guid;
157
+extern EFI_GUID efi_apple_net_boot_protocol_guid;
157
 extern EFI_GUID efi_arp_protocol_guid;
158
 extern EFI_GUID efi_arp_protocol_guid;
158
 extern EFI_GUID efi_arp_service_binding_protocol_guid;
159
 extern EFI_GUID efi_arp_service_binding_protocol_guid;
159
 extern EFI_GUID efi_block_io_protocol_guid;
160
 extern EFI_GUID efi_block_io_protocol_guid;

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

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

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

25
 
25
 
26
 #include <ipxe/efi/efi.h>
26
 #include <ipxe/efi/efi.h>
27
 #include <ipxe/efi/Protocol/AbsolutePointer.h>
27
 #include <ipxe/efi/Protocol/AbsolutePointer.h>
28
+#include <ipxe/efi/Protocol/AppleNetBoot.h>
28
 #include <ipxe/efi/Protocol/Arp.h>
29
 #include <ipxe/efi/Protocol/Arp.h>
29
 #include <ipxe/efi/Protocol/BlockIo.h>
30
 #include <ipxe/efi/Protocol/BlockIo.h>
30
 #include <ipxe/efi/Protocol/BusSpecificDriverOverride.h>
31
 #include <ipxe/efi/Protocol/BusSpecificDriverOverride.h>
84
 EFI_GUID efi_absolute_pointer_protocol_guid
85
 EFI_GUID efi_absolute_pointer_protocol_guid
85
 	= EFI_ABSOLUTE_POINTER_PROTOCOL_GUID;
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
 /** ARP protocol GUID */
92
 /** ARP protocol GUID */
88
 EFI_GUID efi_arp_protocol_guid
93
 EFI_GUID efi_arp_protocol_guid
89
 	= EFI_ARP_PROTOCOL_GUID;
94
 	= EFI_ARP_PROTOCOL_GUID;

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

42
 #include <ipxe/efi/efi_snp.h>
42
 #include <ipxe/efi/efi_snp.h>
43
 #include <ipxe/efi/efi_pxe.h>
43
 #include <ipxe/efi/efi_pxe.h>
44
 #include <ipxe/efi/Protocol/PxeBaseCode.h>
44
 #include <ipxe/efi/Protocol/PxeBaseCode.h>
45
+#include <ipxe/efi/Protocol/AppleNetBoot.h>
45
 #include <usr/ifmgmt.h>
46
 #include <usr/ifmgmt.h>
46
 #include <config/general.h>
47
 #include <config/general.h>
47
 
48
 
80
 	EFI_PXE_BASE_CODE_PROTOCOL base;
81
 	EFI_PXE_BASE_CODE_PROTOCOL base;
81
 	/** PXE base code mode */
82
 	/** PXE base code mode */
82
 	EFI_PXE_BASE_CODE_MODE mode;
83
 	EFI_PXE_BASE_CODE_MODE mode;
84
+	/** Apple NetBoot protocol */
85
+	EFI_APPLE_NET_BOOT_PROTOCOL apple;
83
 
86
 
84
 	/** TCP/IP network-layer protocol */
87
 	/** TCP/IP network-layer protocol */
85
 	struct tcpip_net_protocol *tcpip;
88
 	struct tcpip_net_protocol *tcpip;
1498
 	.SetPackets	= efi_pxe_set_packets,
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
  * Install PXE base code protocol
1582
  * Install PXE base code protocol
1503
  *
1583
  *
1526
 	pxe->handle = handle;
1606
 	pxe->handle = handle;
1527
 	memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base ));
1607
 	memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base ));
1528
 	pxe->base.Mode = &pxe->mode;
1608
 	pxe->base.Mode = &pxe->mode;
1609
+	memcpy ( &pxe->apple, &efi_apple_net_boot_protocol,
1610
+		 sizeof ( pxe->apple ) );
1529
 	pxe->buf.op = &efi_pxe_buf_operations;
1611
 	pxe->buf.op = &efi_pxe_buf_operations;
1530
 	intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
1612
 	intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
1531
 	intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
1613
 	intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
1545
 
1627
 
1546
 	/* Install PXE base code protocol */
1628
 	/* Install PXE base code protocol */
1547
 	if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
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
 			NULL ) ) != 0 ) {
1633
 			NULL ) ) != 0 ) {
1550
 		rc = -EEFI ( efirc );
1634
 		rc = -EEFI ( efirc );
1551
 		DBGC ( pxe, "PXE %s could not install base code protocol: %s\n",
1635
 		DBGC ( pxe, "PXE %s could not install base code protocol: %s\n",
1560
 	return 0;
1644
 	return 0;
1561
 
1645
 
1562
 	bs->UninstallMultipleProtocolInterfaces (
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
 			NULL );
1650
 			NULL );
1565
  err_install_protocol:
1651
  err_install_protocol:
1566
 	ref_put ( &pxe->refcnt );
1652
 	ref_put ( &pxe->refcnt );
1590
 
1676
 
1591
 	/* Uninstall PXE base code protocol */
1677
 	/* Uninstall PXE base code protocol */
1592
 	bs->UninstallMultipleProtocolInterfaces (
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
 			NULL );
1682
 			NULL );
1595
 
1683
 
1596
 	/* Remove from list and drop list's reference */
1684
 	/* Remove from list and drop list's reference */

Loading…
Cancel
Save