aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/sys/gpxe.c
blob: 3cc2b845dcb9bd4f38283485b772ecbd6daebfa2 (plain)
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
#include <string.h>

#include <sys/gpxe.h>
#include <syslinux/config.h>
#include <syslinux/pxe_api.h>

bool is_gpxe(void)
{
    const struct syslinux_version *sv;
    struct s_PXENV_FILE_CHECK_API *fca;
    bool gpxe;
    int err;

    sv = syslinux_version();
    if (sv->filesystem != SYSLINUX_FS_PXELINUX)
        return false;           /* Not PXELINUX */

    fca = lzalloc(sizeof *fca);
    if (!fca)
	return false;

    fca->Size = sizeof *fca;
    fca->Magic = 0x91d447b2;

    err = pxe_call(PXENV_FILE_API_CHECK, fca);

    gpxe = true;

    if (err)
	gpxe = false;           /* Cannot invoke PXE stack */

    if (fca->Status)
        gpxe = false;           /* PXE failure */

    if (fca->Magic != 0xe9c17b20)
        gpxe = false;           /* Incorrect magic */

    if (fca->Size < sizeof *fca)
        gpxe = false;           /* Short return */

    /* XXX: The APIs to test for should be a passed-in option */
    if (!(fca->APIMask & (1 << 5)))
	gpxe = false;           /* No FILE EXEC */

    lfree(fca);
    return gpxe;
}