1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
/** @file
Copyright (c) 2004 - 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
bc.h
Abstract:
**/
#ifndef _BC_H
#define _BC_H
#include <PiDxe.h>
#include <Guid/SmBios.h>
#include <IndustryStandard/SmBios.h>
#include <Protocol/Bis.h>
#include <Protocol/PxeBaseCode.h>
#include <Protocol/PxeBaseCodeCallBack.h>
#include <Protocol/NetworkInterfaceIdentifier.h>
#include <Protocol/SimpleNetwork.h>
#include <Protocol/LoadFile.h>
#include <Protocol/DevicePath.h>
#include <Protocol/Tcp.h>
#include <Protocol/LoadedImage.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/UefiLib.h>
#define CALLBACK_INTERVAL 100 // ten times a second
#define FILTER_BITS (EFI_PXE_BASE_CODE_IP_FILTER_STATION_IP | \
EFI_PXE_BASE_CODE_IP_FILTER_BROADCAST | \
EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS | \
EFI_PXE_BASE_CODE_IP_FILTER_PROMISCUOUS_MULTICAST \
)
#define WAIT_TX_TIMEOUT 1000
#define SUPPORT_IPV6 0
#define PXE_BASECODE_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('p', 'x', 'e', 'd')
//
// Determine the classes of IPv4 address
//
#define IS_CLASSA_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0x80) == 0x00)
#define IS_CLASSB_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0xc0) == 0x80)
#define IS_CLASSC_IPADDR(x) ((((EFI_IP_ADDRESS*)x)->v4.Addr[0] & 0xe0) == 0xc0)
#define IS_INADDR_UNICAST(x) ((IS_CLASSA_IPADDR(x) || IS_CLASSB_IPADDR(x) || IS_CLASSC_IPADDR(x)) && (((EFI_IP_ADDRESS*)x)->Addr[0] != 0) )
//
// Definitions for internet group management protocol version 2 message
// structure
// Per RFC 2236, November 1997
//
#pragma pack(1)
typedef struct {
UINT8 Type;
UINT8 MaxRespTime; // in tenths of a second
UINT16 Checksum; // ones complement of ones complement sum of
// 16 bit words of message
UINT32 GroupAddress; // for general query, all systems group,
// for group specific, the group
} IGMPV2_MESSAGE;
#define IGMP_TYPE_QUERY 0x11
#define IGMP_TYPE_REPORT 0x16
#define IGMP_TYPE_V1REPORT 0x12
#define IGMP_TYPE_LEAVE_GROUP 0x17
#define IGMP_DEFAULT_MAX_RESPONSE_TIME 10 // 10 second default
#pragma pack()
#define MAX_MCAST_GROUPS 8 // most we allow ourselves to join at once
#define MAX_OFFERS 16
typedef struct {
UINTN Signature;
EFI_LOCK Lock;
BOOLEAN ShowErrorMessages;
EFI_TCP_PROTOCOL Tcp;
EFI_PXE_BASE_CODE_PROTOCOL EfiBc;
EFI_PXE_BASE_CODE_CALLBACK_PROTOCOL *CallbackProtocolPtr;
EFI_HANDLE Handle;
EFI_NETWORK_INTERFACE_IDENTIFIER_PROTOCOL *NiiPtr;
EFI_SIMPLE_NETWORK_PROTOCOL *SimpleNetwork;
UINT8 *TransmitBufferPtr;
UINT8 *ReceiveBufferPtr;
EFI_PXE_BASE_CODE_FUNCTION Function;
UINTN OldestArpEntry;
UINTN MCastGroupCount;
EFI_EVENT Igmpv1TimeoutEvent;
BOOLEAN UseIgmpv1Reporting;
EFI_EVENT IgmpGroupEvent[MAX_MCAST_GROUPS];
UINT16 RandomPort;
#if SUPPORT_IPV6
//
// TBD
//
#else
UINT32 MCastGroup[MAX_MCAST_GROUPS];
#endif
BOOLEAN GoodStationIp;
BOOLEAN DidTransmit;
UINTN IpLength;
VOID *DhcpPacketBuffer;
UINTN FileSize;
VOID *BootServerReceiveBuffer;
EFI_IP_ADDRESS ServerIp;
//
// work area
// for dhcp
//
VOID *ReceiveBuffers;
VOID *TransmitBuffer;
UINTN NumOffersReceived;
UINT16 TotalSeconds;
//
// arrays for different types of offers
//
UINT8 ServerCount[4];
UINT8 OfferCount[4][MAX_OFFERS];
UINT8 GotBootp;
UINT8 GotProxy[4];
UINT8 BinlProxies[MAX_OFFERS];
UINT8 *ArpBuffer;
UINT8 *TftpAckBuffer;
UINT8 *TftpErrorBuffer;
IGMPV2_MESSAGE IgmpMessage;
BOOLEAN BigBlkNumFlag;
UINT8 Timeout;
UINT16 RandomSeed;
} PXE_BASECODE_DEVICE;
//
// type index
//
#define DHCP_ONLY_IX 0
#define PXE10_IX 1
#define WfM11a_IX 2
#define BINL_IX 3
#define PXE_RND_PORT_LOW 2070
//
//
//
#define LOADFILE_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('p', 'x', 'e', 'l')
typedef struct {
UINTN Signature;
EFI_LOCK Lock;
EFI_LOAD_FILE_PROTOCOL LoadFile;
PXE_BASECODE_DEVICE *Private;
} LOADFILE_DEVICE;
#define EFI_BASE_CODE_DEV_FROM_THIS(a) CR (a, PXE_BASECODE_DEVICE, efi_bc, PXE_BASECODE_DEVICE_SIGNATURE);
#define EFI_BASE_CODE_DEV_FROM_TCP(a) CR (a, PXE_BASECODE_DEVICE, Tcp, PXE_BASECODE_DEVICE_SIGNATURE);
#define EFI_LOAD_FILE_DEV_FROM_THIS(a) CR (a, LOADFILE_DEVICE, LoadFile, LOADFILE_DEVICE_SIGNATURE)
EFI_BIS_PROTOCOL *
PxebcBisStart (
PXE_BASECODE_DEVICE *Private,
BIS_APPLICATION_HANDLE *BisAppHandle,
EFI_BIS_DATA **BisDataSigInfo
)
;
VOID
PxebcBisStop (
EFI_BIS_PROTOCOL *Bis,
BIS_APPLICATION_HANDLE BisAppHandle,
EFI_BIS_DATA *BisDataSigInfo
)
;
BOOLEAN
PxebcBisVerify (
PXE_BASECODE_DEVICE *Private,
VOID *FileBuffer,
UINTN FileBufferLength,
VOID *CredentialBuffer,
UINTN CredentialBufferLength
)
;
BOOLEAN
PxebcBisDetect (
PXE_BASECODE_DEVICE *Private
)
;
//
// Global Variables
//
extern EFI_COMPONENT_NAME_PROTOCOL gPxeBcComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gPxeBcComponentName2;
//
// //////////////////////////////////////////////////////////
//
// prototypes
//
/**
Initialize the base code drivers and install the driver binding
Standard EFI Image Entry
@retval EFI_SUCCESS This driver was successfully bound
**/
EFI_STATUS
EFIAPI
InitializeBCDriver (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
;
EFI_STATUS
EFIAPI
BcStart (
IN EFI_PXE_BASE_CODE_PROTOCOL *This,
IN BOOLEAN UseIpv6
)
;
EFI_STATUS
EFIAPI
BcStop (
IN EFI_PXE_BASE_CODE_PROTOCOL *This
)
;
EFI_STATUS
EFIAPI
BcDhcp (
IN EFI_PXE_BASE_CODE_PROTOCOL *This,
IN BOOLEAN SortOffers
)
;
EFI_STATUS
EFIAPI
BcDiscover (
IN EFI_PXE_BASE_CODE_PROTOCOL * This,
IN UINT16 Type,
IN UINT16 *Layer,
IN BOOLEAN UseBis,
IN EFI_PXE_BASE_CODE_DISCOVER_INFO * Info OPTIONAL
)
;
EFI_STATUS
EFIAPI
BcMtftp (
IN EFI_PXE_BASE_CODE_PROTOCOL * This,
IN EFI_PXE_BASE_CODE_TFTP_OPCODE Operation,
IN OUT VOID *BufferPtr,
IN BOOLEAN Overwrite,
IN OUT UINT64 *BufferSize,
IN UINTN *BlockSize OPTIONAL,
IN EFI_IP_ADDRESS * ServerIp,
IN UINT8 *Filename,
IN EFI_PXE_BASE_CODE_MTFTP_INFO * Info OPTIONAL,
IN BOOLEAN DontUseBuffer
)
;
EFI_STATUS
EFIAPI
BcUdpWrite (
IN EFI_PXE_BASE_CODE_PROTOCOL *This,
IN UINT16 OpFlags,
IN EFI_IP_ADDRESS *DestIp,
IN EFI_PXE_BASE_CODE_UDP_PORT *DestPort,
IN EFI_IP_ADDRESS *GatewayIp, OPTIONAL
IN EFI_IP_ADDRESS *SrcIp, OPTIONAL
IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort, OPTIONAL
IN UINTN *HeaderSize, OPTIONAL
IN VOID *HeaderPtr, OPTIONAL
IN UINTN *BufferSize,
IN VOID *BufferPtr
)
;
EFI_STATUS
EFIAPI
BcUdpRead (
IN EFI_PXE_BASE_CODE_PROTOCOL *This,
IN UINT16 OpFlags,
IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL
IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort, OPTIONAL
IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL
IN OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort, OPTIONAL
IN UINTN *HeaderSize, OPTIONAL
IN VOID *HeaderPtr, OPTIONAL
IN OUT UINTN *BufferSize,
IN VOID *BufferPtr
)
;
EFI_STATUS
EFIAPI
BcTcpWrite (
IN EFI_PXE_BASE_CODE_PROTOCOL *This,
IN UINT16 OpFlags,
IN UINT16 *UrgentPointer,
IN UINT32 *SequenceNumber,
IN UINT32 *AckNumber,
IN UINT16 *HlenResCode,
IN UINT16 *Window,
IN EFI_IP_ADDRESS *DestIp,
IN EFI_PXE_BASE_CODE_TCP_PORT *DestPort,
IN EFI_IP_ADDRESS *GatewayIp, OPTIONAL
IN EFI_IP_ADDRESS *SrcIp, OPTIONAL
IN OUT EFI_PXE_BASE_CODE_TCP_PORT *SrcPort, OPTIONAL
IN UINTN *HeaderSize, OPTIONAL
IN VOID *HeaderPtr, OPTIONAL
IN UINTN *BufferSize,
IN VOID *BufferPtr
)
;
EFI_STATUS
EFIAPI
BcTcpRead (
IN EFI_PXE_BASE_CODE_PROTOCOL *This,
IN UINT16 OpFlags,
IN OUT EFI_IP_ADDRESS *DestIp, OPTIONAL
IN OUT EFI_PXE_BASE_CODE_TCP_PORT *DestPort, OPTIONAL
IN OUT EFI_IP_ADDRESS *SrcIp, OPTIONAL
IN OUT EFI_PXE_BASE_CODE_TCP_PORT *SrcPort, OPTIONAL
IN UINTN *HeaderSize, OPTIONAL
IN VOID *HeaderPtr, OPTIONAL
IN OUT UINTN *BufferSize,
IN VOID *BufferPtr
)
;
EFI_STATUS
EFIAPI
BcArp (
IN EFI_PXE_BASE_CODE_PROTOCOL * This,
IN EFI_IP_ADDRESS * IpAddr,
IN EFI_MAC_ADDRESS * MacAddr OPTIONAL
)
;
EFI_STATUS
EFIAPI
BcIpFilter (
IN EFI_PXE_BASE_CODE_PROTOCOL *This,
IN EFI_PXE_BASE_CODE_IP_FILTER *NewFilter
)
;
EFI_STATUS
EFIAPI
BcSetParameters (
IN EFI_PXE_BASE_CODE_PROTOCOL * This,
IN BOOLEAN *NewAutoArp, OPTIONAL
IN BOOLEAN *NewSendGUID, OPTIONAL
IN UINT8 *NewTTL, OPTIONAL
IN UINT8 *NewToS, OPTIONAL
IN BOOLEAN *NewMakeCallback OPTIONAL
)
;
EFI_STATUS
EFIAPI
BcSetStationIP (
IN EFI_PXE_BASE_CODE_PROTOCOL * This,
IN EFI_IP_ADDRESS * NewStationIp, OPTIONAL
IN EFI_IP_ADDRESS * NewSubnetMask OPTIONAL
)
;
EFI_STATUS
EFIAPI
BcSetPackets (
IN EFI_PXE_BASE_CODE_PROTOCOL * This,
BOOLEAN *NewDhcpDiscoverValid, OPTIONAL
BOOLEAN *NewDhcpAckReceived, OPTIONAL
BOOLEAN *NewProxyOfferReceived, OPTIONAL
BOOLEAN *NewPxeDiscoverValid, OPTIONAL
BOOLEAN *NewPxeReplyReceived, OPTIONAL
BOOLEAN *NewPxeBisReplyReceived, OPTIONAL
IN EFI_PXE_BASE_CODE_PACKET * NewDhcpDiscover, OPTIONAL
IN EFI_PXE_BASE_CODE_PACKET * NewDhcpAck, OPTIONAL
IN EFI_PXE_BASE_CODE_PACKET * NewProxyOffer, OPTIONAL
IN EFI_PXE_BASE_CODE_PACKET * NewPxeDiscover, OPTIONAL
IN EFI_PXE_BASE_CODE_PACKET * NewPxeReply, OPTIONAL
IN EFI_PXE_BASE_CODE_PACKET * NewPxeBisReply OPTIONAL
)
;
EFI_STATUS
EFIAPI
LoadFile (
IN EFI_LOAD_FILE_PROTOCOL *This,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
IN BOOLEAN BootPolicy,
IN OUT UINTN *BufferSize,
IN VOID *Buffer
)
;
EFI_STATUS
PxeBcLibGetSmbiosSystemGuidAndSerialNumber (
IN EFI_GUID *SystemGuid,
OUT CHAR8 **SystemSerialNumber
)
;
#include "Ip.h"
#include "Dhcp.h"
#include "Tftp.h"
#endif /* _BC_H */
/* EOF - bc.h */
|