|  | @@ -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 */
 |