Home | History | Annotate | Download | only in sys
      1 #include <string.h>
      2 
      3 #include <sys/gpxe.h>
      4 #include <syslinux/config.h>
      5 #include <syslinux/pxe_api.h>
      6 
      7 bool is_gpxe(void)
      8 {
      9     const struct syslinux_version *sv;
     10     struct s_PXENV_FILE_CHECK_API *fca;
     11     bool gpxe;
     12     int err;
     13 
     14     sv = syslinux_version();
     15     if (sv->filesystem != SYSLINUX_FS_PXELINUX)
     16         return false;           /* Not PXELINUX */
     17 
     18     fca = lzalloc(sizeof *fca);
     19     if (!fca)
     20 	return false;
     21 
     22     fca->Size = sizeof *fca;
     23     fca->Magic = 0x91d447b2;
     24 
     25     err = pxe_call(PXENV_FILE_API_CHECK, fca);
     26 
     27     gpxe = true;
     28 
     29     if (err)
     30 	gpxe = false;           /* Cannot invoke PXE stack */
     31 
     32     if (fca->Status)
     33         gpxe = false;           /* PXE failure */
     34 
     35     if (fca->Magic != 0xe9c17b20)
     36         gpxe = false;           /* Incorrect magic */
     37 
     38     if (fca->Size < sizeof *fca)
     39         gpxe = false;           /* Short return */
     40 
     41     /* XXX: The APIs to test for should be a passed-in option */
     42     if (!(fca->APIMask & (1 << 5)))
     43 	gpxe = false;           /* No FILE EXEC */
     44 
     45     lfree(fca);
     46     return gpxe;
     47 }
     48