Home | History | Annotate | Download | only in UefiPxeBcDxe
      1 /** @file
      2   This EFI_PXE_BASE_CODE_PROTOCOL and EFI_LOAD_FILE_PROTOCOL.
      3   interfaces declaration.
      4 
      5   Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
      6 
      7   This program and the accompanying materials
      8   are licensed and made available under the terms and conditions of the BSD License
      9   which accompanies this distribution.  The full text of the license may be found at
     10   http://opensource.org/licenses/bsd-license.php.
     11 
     12   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     13   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     14 
     15 **/
     16 
     17 #ifndef __EFI_PXEBC_IMPL_H__
     18 #define __EFI_PXEBC_IMPL_H__
     19 
     20 #include <Uefi.h>
     21 
     22 #include <Guid/SmBios.h>
     23 #include <IndustryStandard/SmBios.h>
     24 #include <IndustryStandard/Dhcp.h>
     25 #include <Protocol/NetworkInterfaceIdentifier.h>
     26 #include <Protocol/Arp.h>
     27 #include <Protocol/Ip4.h>
     28 #include <Protocol/Ip4Config2.h>
     29 #include <Protocol/Ip6.h>
     30 #include <Protocol/Ip6Config.h>
     31 #include <Protocol/Udp4.h>
     32 #include <Protocol/Udp6.h>
     33 #include <Protocol/Dhcp4.h>
     34 #include <Protocol/Dhcp6.h>
     35 #include <Protocol/Dns6.h>
     36 #include <Protocol/Mtftp4.h>
     37 #include <Protocol/Mtftp6.h>
     38 #include <Protocol/PxeBaseCode.h>
     39 #include <Protocol/LoadFile.h>
     40 #include <Protocol/PxeBaseCodeCallBack.h>
     41 #include <Protocol/ServiceBinding.h>
     42 #include <Protocol/DriverBinding.h>
     43 #include <Protocol/AdapterInformation.h>
     44 
     45 #include <Library/DebugLib.h>
     46 #include <Library/BaseMemoryLib.h>
     47 #include <Library/MemoryAllocationLib.h>
     48 #include <Library/UefiDriverEntryPoint.h>
     49 #include <Library/UefiBootServicesTableLib.h>
     50 #include <Library/UefiRuntimeServicesTableLib.h>
     51 #include <Library/UefiLib.h>
     52 #include <Library/BaseLib.h>
     53 #include <Library/NetLib.h>
     54 #include <Library/DpcLib.h>
     55 #include <Library/DevicePathLib.h>
     56 #include <Library/PcdLib.h>
     57 
     58 typedef struct _PXEBC_PRIVATE_DATA  PXEBC_PRIVATE_DATA;
     59 typedef struct _PXEBC_PRIVATE_PROTOCOL PXEBC_PRIVATE_PROTOCOL;
     60 typedef struct _PXEBC_VIRTUAL_NIC   PXEBC_VIRTUAL_NIC;
     61 
     62 #include "PxeBcDriver.h"
     63 #include "PxeBcDhcp4.h"
     64 #include "PxeBcDhcp6.h"
     65 #include "PxeBcMtftp.h"
     66 #include "PxeBcBoot.h"
     67 #include "PxeBcSupport.h"
     68 
     69 #define PXEBC_DEFAULT_HOPLIMIT        64
     70 #define PXEBC_DEFAULT_LIFETIME        50000    // 50 ms, unit is microsecond
     71 #define PXEBC_UDP_TIMEOUT             30000000 // 3 seconds, unit is 100nanosecond
     72 #define PXEBC_DAD_ADDITIONAL_DELAY    30000000 // 3 seconds
     73 #define PXEBC_MTFTP_TIMEOUT           4
     74 #define PXEBC_MTFTP_RETRIES           6
     75 #define PXEBC_DHCP_RETRIES            4        // refers to mPxeDhcpTimeout, also by PXE2.1 spec.
     76 #define PXEBC_MENU_MAX_NUM            24
     77 #define PXEBC_OFFER_MAX_NUM           16
     78 
     79 #define PXEBC_PRIVATE_DATA_SIGNATURE          SIGNATURE_32 ('P', 'X', 'E', 'P')
     80 #define PXEBC_VIRTUAL_NIC_SIGNATURE           SIGNATURE_32 ('P', 'X', 'E', 'V')
     81 #define PXEBC_PRIVATE_DATA_FROM_PXEBC(a)      CR (a, PXEBC_PRIVATE_DATA, PxeBc, PXEBC_PRIVATE_DATA_SIGNATURE)
     82 #define PXEBC_PRIVATE_DATA_FROM_ID(a)         CR (a, PXEBC_PRIVATE_DATA, Id, PXEBC_PRIVATE_DATA_SIGNATURE)
     83 #define PXEBC_VIRTUAL_NIC_FROM_LOADFILE(a)    CR (a, PXEBC_VIRTUAL_NIC, LoadFile, PXEBC_VIRTUAL_NIC_SIGNATURE)
     84 
     85 typedef union {
     86   PXEBC_DHCP4_PACKET_CACHE            Dhcp4;
     87   PXEBC_DHCP6_PACKET_CACHE            Dhcp6;
     88 } PXEBC_DHCP_PACKET_CACHE;
     89 
     90 struct _PXEBC_PRIVATE_PROTOCOL {
     91   UINT64                                    Reserved;
     92 };
     93 
     94 struct _PXEBC_VIRTUAL_NIC {
     95   UINT32                                    Signature;
     96   EFI_HANDLE                                Controller;
     97   EFI_LOAD_FILE_PROTOCOL                    LoadFile;
     98   EFI_DEVICE_PATH_PROTOCOL                  *DevicePath;
     99   PXEBC_PRIVATE_DATA                        *Private;
    100 };
    101 
    102 struct _PXEBC_PRIVATE_DATA {
    103   UINT32                                    Signature;
    104   EFI_HANDLE                                Controller;
    105   EFI_HANDLE                                Image;
    106 
    107   PXEBC_PRIVATE_PROTOCOL                    Id;
    108   EFI_SIMPLE_NETWORK_PROTOCOL               *Snp;
    109 
    110   PXEBC_VIRTUAL_NIC                         *Ip4Nic;
    111   PXEBC_VIRTUAL_NIC                         *Ip6Nic;
    112 
    113   EFI_HANDLE                                ArpChild;
    114   EFI_HANDLE                                Ip4Child;
    115   EFI_HANDLE                                Dhcp4Child;
    116   EFI_HANDLE                                Mtftp4Child;
    117   EFI_HANDLE                                Udp4ReadChild;
    118   EFI_HANDLE                                Udp4WriteChild;
    119 
    120   EFI_ARP_PROTOCOL                          *Arp;
    121   EFI_IP4_PROTOCOL                          *Ip4;
    122   EFI_IP4_CONFIG2_PROTOCOL                  *Ip4Config2;
    123   EFI_DHCP4_PROTOCOL                        *Dhcp4;
    124   EFI_MTFTP4_PROTOCOL                       *Mtftp4;
    125   EFI_UDP4_PROTOCOL                         *Udp4Read;
    126   EFI_UDP4_PROTOCOL                         *Udp4Write;
    127 
    128   EFI_HANDLE                                Ip6Child;
    129   EFI_HANDLE                                Dhcp6Child;
    130   EFI_HANDLE                                Mtftp6Child;
    131   EFI_HANDLE                                Udp6ReadChild;
    132   EFI_HANDLE                                Udp6WriteChild;
    133 
    134   EFI_IP6_PROTOCOL                          *Ip6;
    135   EFI_IP6_CONFIG_PROTOCOL                   *Ip6Cfg;
    136   EFI_DHCP6_PROTOCOL                        *Dhcp6;
    137   EFI_MTFTP6_PROTOCOL                       *Mtftp6;
    138   EFI_UDP6_PROTOCOL                         *Udp6Read;
    139   EFI_UDP6_PROTOCOL                         *Udp6Write;
    140   EFI_DNS6_PROTOCOL                         *Dns6;
    141 
    142   EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *Nii;
    143   EFI_PXE_BASE_CODE_PROTOCOL                PxeBc;
    144   EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL       LoadFileCallback;
    145   EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL       *PxeBcCallback;
    146   EFI_DEVICE_PATH_PROTOCOL                  *DevicePath;
    147 
    148   EFI_PXE_BASE_CODE_MODE                    Mode;
    149   EFI_PXE_BASE_CODE_FUNCTION                Function;
    150   UINT32                                    Ip6Policy;
    151   UINT32                                    SolicitTimes;
    152   UINT64                                    ElapsedTime;
    153 
    154   EFI_UDP4_CONFIG_DATA                      Udp4CfgData;
    155   EFI_UDP6_CONFIG_DATA                      Udp6CfgData;
    156   EFI_IP4_CONFIG_DATA                       Ip4CfgData;
    157   EFI_IP6_CONFIG_DATA                       Ip6CfgData;
    158 
    159   EFI_EVENT                                 UdpTimeOutEvent;
    160   EFI_EVENT                                 ArpUpdateEvent;
    161   EFI_IP4_COMPLETION_TOKEN                  IcmpToken;
    162   EFI_IP6_COMPLETION_TOKEN                  Icmp6Token;
    163 
    164   BOOLEAN                                   IsAddressOk;
    165   BOOLEAN                                   IsOfferSorted;
    166   BOOLEAN                                   IsProxyRecved;
    167   BOOLEAN                                   IsDoDiscover;
    168 
    169   EFI_IP_ADDRESS                            TmpStationIp;
    170   EFI_IP_ADDRESS                            StationIp;
    171   EFI_IP_ADDRESS                            SubnetMask;
    172   EFI_IP_ADDRESS                            GatewayIp;
    173   EFI_IP_ADDRESS                            ServerIp;
    174   EFI_IPv6_ADDRESS                          *DnsServer;
    175   UINT16                                    CurSrcPort;
    176   UINT32                                    IaId;
    177 
    178   UINT32                                    Ip4MaxPacketSize;
    179   UINT32                                    Ip6MaxPacketSize;
    180   UINT8                                     *BootFileName;
    181   UINTN                                     BootFileSize;
    182   UINTN                                     BlockSize;
    183 
    184   PXEBC_DHCP_PACKET_CACHE                   ProxyOffer;
    185   PXEBC_DHCP_PACKET_CACHE                   DhcpAck;
    186   PXEBC_DHCP_PACKET_CACHE                   PxeReply;
    187   EFI_DHCP6_PACKET                          *Dhcp6Request;
    188   EFI_DHCP4_PACKET                          SeedPacket;
    189 
    190   //
    191   // OfferIndex records the index of DhcpOffer[] buffer, and OfferCount records the num of each type of offer.
    192   //
    193   // It supposed that
    194   //
    195   //   OfferNum:    8
    196   //   OfferBuffer: [ProxyBinl, ProxyBinl, DhcpOnly, ProxyPxe10, DhcpOnly, DhcpPxe10, DhcpBinl, ProxyBinl]
    197   //   (OfferBuffer is 0-based.)
    198   //
    199   // And assume that (DhcpPxe10 is the first priority actually.)
    200   //
    201   //   SelectIndex:     2
    202   //   SelectProxyType: PXEBC_OFFER_TYPE_PROXY_BINL
    203   //   (SelectIndex is 1-based, and 0 means no one is selected.)
    204   //
    205   // So it should be
    206   //
    207   //                 DhcpOnly  DhcpPxe10  DhcpWfm11a  DhcpBinl  ProxyPxe10  ProxyWfm11a  ProxyBinl  Bootp
    208   //   OfferCount:  [    2(n),      1(n),       0(n),     1(n),       1(1),        0(1),      3(n),  1(1)]
    209   //
    210   //   OfferIndex: {[       2,         5,          0,        6,          3,           0,        *0,     0]
    211   //                [       4,         0,          0,        0,          0,           0,         1,     0]
    212   //                [       0,         0,          0,        0,          0,           0,         7,     0]
    213   //                ...                                                                                  ]}
    214   //   (OfferIndex is 0-based.)
    215   //
    216   //
    217   UINT32                                    SelectIndex;
    218   UINT32                                    SelectProxyType;
    219   PXEBC_DHCP_PACKET_CACHE                   OfferBuffer[PXEBC_OFFER_MAX_NUM];
    220   UINT32                                    OfferNum;
    221   UINT32                                    OfferCount[PxeOfferTypeMax];
    222   UINT32                                    OfferIndex[PxeOfferTypeMax][PXEBC_OFFER_MAX_NUM];
    223 };
    224 
    225 extern EFI_PXE_BASE_CODE_PROTOCOL           gPxeBcProtocolTemplate;
    226 extern EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL  gPxeBcCallBackTemplate;
    227 extern EFI_LOAD_FILE_PROTOCOL               gLoadFileProtocolTemplate;
    228 
    229 #endif
    230