From 502f3945957eda4f312704fa70a0e2fc53bbd6af Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Tue, 24 Feb 2009 22:47:10 +0100 Subject: [PATCH] hdt: Basic pxe implementation --- com32/hdt/Makefile | 2 +- com32/hdt/hdt-cli-net.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ com32/hdt/hdt-cli.c | 3 +++ com32/hdt/hdt-cli.h | 5 +++++ com32/hdt/hdt-common.c | 32 +++++++++++++++++++++++++-- com32/hdt/hdt-common.h | 7 ++++++ 6 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 com32/hdt/hdt-cli-net.c diff --git a/com32/hdt/Makefile b/com32/hdt/Makefile index 37f85c6..d637f5d 100644 --- a/com32/hdt/Makefile +++ b/com32/hdt/Makefile @@ -43,7 +43,7 @@ all: hdt.c32 $(LIB) hdt.elf: hdt.o hdt-ata.o hdt-menu.o hdt-menu-pci.o hdt-menu-kernel.o \ hdt-menu-disk.o hdt-menu-dmi.o hdt-menu-processor.o hdt-menu-syslinux.o hdt-menu-about.o \ - hdt-cli.o hdt-common.o hdt-cli-pci.o hdt-cli-dmi.o hdt-cli-cpu.o\ + hdt-cli.o hdt-common.o hdt-cli-pci.o hdt-cli-dmi.o hdt-cli-cpu.o hdt-cli-net.o\ $(com32)/modules/cpuid.o $(com32)/modules/dmi.o $(topdir)/menu/libmenu/libmenu.a $(LIB) $(C_LIBS) $(LD) $(LDFLAGS) -o $@ $^ diff --git a/com32/hdt/hdt-cli-net.c b/com32/hdt/hdt-cli-net.c new file mode 100644 index 0000000..9e6aaf6 --- /dev/null +++ b/com32/hdt/hdt-cli-net.c @@ -0,0 +1,59 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2009 Erwan Velu - All Rights Reserved + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall + * be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * ----------------------------------------------------------------------- +*/ + +#include "hdt-cli.h" +#include "hdt-common.h" +#include +#include +#include +#include +#include + +void main_show_net(struct s_hardware *hardware,struct s_cli_mode *cli_mode) { + char buffer[1024]; + memset(buffer,0,sizeof(buffer)); + + if (hardware->pxe_detection==false) detect_pxe(hardware); + if (hardware->is_pxe_valid==false) { + more_printf("No valid PXE rom found\n"); + return; + } + t_PXENV_UNDI_GET_NIC_TYPE *g = &hardware->gnt; + switch(hardware->gnt.NicType) { + case PCI_NIC: more_printf("PCI NIC: %04x:%04x[%04x:%04X] rev(%02x) Bus(%02x:%02x.%02x) %02x.%02x %02x %02x\n", + g->info.pci.Vendor_ID, g->info.pci.Dev_ID, g->info.pci.SubVendor_ID, g->info.pci.SubDevice_ID, + g->info.pci.Rev, (g->info.pci.BusDevFunc >> 8) & 0xff, (g->info.pci.BusDevFunc >> 3) & 0x7, + g->info.pci.BusDevFunc & 0x03, + g->info.pci.Base_Class, + g->info.pci.Sub_Class, g->info.pci.Prog_Intf);break; + case PnP_NIC: break; + case CardBus_NIC:break; + } +} + + diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 6560d53..2640d38 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -141,6 +141,7 @@ void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]) { int do_exit(struct s_cli_mode *cli_mode) { switch (cli_mode->mode) { case HDT_MODE: return EXIT_MODE; + case NET_MODE: case PCI_MODE: case DMI_MODE: case CPU_MODE: return HDT_MODE; @@ -154,6 +155,7 @@ switch (cli_mode->mode) { case HDT_MODE: printf("Available commands are : %s %s %s %s %s %s\n",CLI_CLEAR, CLI_EXIT,CLI_HELP,CLI_SHOW, CLI_PCI, CLI_DMI); break; + case NET_MODE: case CPU_MODE: case PCI_MODE: case DMI_MODE: @@ -168,4 +170,5 @@ void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_m if (!strncmp(item,CLI_PCI, sizeof (CLI_PCI))) main_show_pci(hardware); if (!strncmp(item,CLI_DMI, sizeof (CLI_DMI))) main_show_dmi(hardware,cli_mode); if (!strncmp(item,CLI_CPU, sizeof (CLI_CPU))) main_show_cpu(hardware,cli_mode); + if (!strncmp(item,CLI_NET, sizeof (CLI_NET))) main_show_net(hardware,cli_mode); } diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index 9b1bed1..5e1cbe7 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -37,6 +37,7 @@ #define CLI_SHOW "show" #define CLI_HDT "hdt" #define CLI_PCI "pci" +#define CLI_NET "net" #define CLI_COMMANDS "commands" #define CLI_DMI "dmi" #define CLI_CPU "cpu" @@ -48,6 +49,7 @@ typedef enum { PCI_MODE, DMI_MODE, CPU_MODE, + NET_MODE, } cli_mode_t; struct s_cli_mode { @@ -94,4 +96,7 @@ void cli_detect_pci(struct s_hardware *hardware); void main_show_cpu(struct s_hardware *hardware,struct s_cli_mode *cli_mode); void handle_cpu_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_hardware *hardware); void cpu_show(char *item, struct s_hardware *hardware); + +//NET STUFF +void main_show_net(struct s_hardware *hardware,struct s_cli_mode *cli_mode); #endif diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index 19ddbad..d71f215 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -30,6 +30,7 @@ #include #include #include +#include "syslinux/config.h" void init_hardware(struct s_hardware *hardware) { hardware->pci_ids_return_code=0; @@ -38,14 +39,17 @@ void init_hardware(struct s_hardware *hardware) { hardware->pci_detection=false; hardware->disk_detection=false; hardware->dmi_detection=false; + hardware->pxe_detection=false; hardware->nb_pci_devices=0; hardware->is_dmi_valid=false; + hardware->is_pxe_valid=false; hardware->pci_domain=NULL; /* Cleaning structures */ memset(hardware->disk_info,0,sizeof(hardware->disk_info)); - memset(&hardware->dmi,0,sizeof(hardware->dmi)); - memset(&hardware->cpu,0,sizeof(hardware->cpu)); + memset(&hardware->dmi,0,sizeof(s_dmi)); + memset(&hardware->cpu,0,sizeof(s_cpu)); + memset(&hardware->gnt,0,sizeof(t_PXENV_UNDI_GET_NIC_TYPE)); } /* Detecting if a DMI table exist @@ -73,6 +77,30 @@ void detect_disks(struct s_hardware *hardware) { } } +int detect_pxe(struct s_hardware *hardware) { + void *dhcpdata; + size_t dhcplen; + const struct syslinux_version *sv; + + hardware->pxe_detection=true; + memset(&hardware->gnt,0, sizeof(t_PXENV_UNDI_GET_NIC_TYPE)); + + sv = syslinux_version(); + /* This code can only work if pxelinux is loaded*/ + if (sv->filesystem != SYSLINUX_FS_PXELINUX) { + printf("No valid PXE Rom found\n"); + return -1; + } + printf("PXE: PXElinux detected, Detecting parameters\n"); + + if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) { + if (!pxe_get_nic_type(&hardware->gnt)) { + hardware->is_pxe_valid=true; + } + } + return 0; +} + void detect_pci(struct s_hardware *hardware) { hardware->pci_detection=true; printf("PCI: Detecting Devices\n"); diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h index 51a2b35..5c3282c 100644 --- a/com32/hdt/hdt-common.h +++ b/com32/hdt/hdt-common.h @@ -32,6 +32,7 @@ #include "sys/pci.h" #include "cpuid.h" #include "dmi/dmi.h" +#include #include "hdt-ata.h" /* This two values are used for switching for the menu to the CLI mode*/ @@ -57,14 +58,19 @@ struct s_hardware { s_cpu cpu; /* CPU information */ struct pci_domain *pci_domain; /* PCI Devices */ struct diskinfo disk_info[256]; /* Disk Information*/ + t_PXENV_UNDI_GET_NIC_TYPE gnt; + int pci_ids_return_code; int modules_pcimap_return_code; int nb_pci_devices; bool is_dmi_valid; + bool is_pxe_valid; + bool dmi_detection; /* Does the dmi stuff have been already detected */ bool pci_detection; /* Does the pci stuff have been already detected */ bool cpu_detection; /* Does the cpu stuff have been already detected */ bool disk_detection; /* Does the disk stuff have been already detected */ + bool pxe_detection; /* Does the pxe stuff have been already detected*/ }; char *find_argument(const char **argv, const char *argument); @@ -72,6 +78,7 @@ int detect_dmi(struct s_hardware *hardware); void detect_disks(struct s_hardware *hardware); void detect_pci(struct s_hardware *hardware); void cpu_detect(struct s_hardware *hardware); +int detect_pxe(struct s_hardware *hardware); void init_hardware(struct s_hardware *hardware); void clear_screen(void); #endif -- 2.7.4