From 49d2920855234a8f891f311a61f0ce175c2148d9 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Wed, 25 Feb 2009 16:49:03 +0100 Subject: [PATCH] hdt: Adding mac & ip adress detection --- com32/hdt/hdt-cli-pci.c | 7 +++++-- com32/hdt/hdt-cli-pxe.c | 18 ++++++++---------- com32/hdt/hdt-common.c | 18 +++++++++++++++--- com32/hdt/hdt-common.h | 8 ++++++-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/com32/hdt/hdt-cli-pci.c b/com32/hdt/hdt-cli-pci.c index ac73820..d7c2ad2 100644 --- a/com32/hdt/hdt-cli-pci.c +++ b/com32/hdt/hdt-cli-pci.c @@ -104,8 +104,11 @@ void show_pci_device(struct s_hardware *hardware, const char *item) { more_printf("PCI Bus : %02d\n",bus); more_printf("PCI Slot : %02d\n",slot); more_printf("PCI Func : %02d\n",func); - if ((hardware->pxe.pci_device != NULL) && (hardware->pxe.pci_device == pci_device)) { - more_printf("PXE : Current boot device\n",func); + + if (hardware->is_pxe_valid == true) { + more_printf("Mac Address : %s\n",hardware->pxe.mac_addr); + if ((hardware->pxe.pci_device != NULL) && (hardware->pxe.pci_device == pci_device)) + more_printf("PXE : Current boot device\n",func); } } diff --git a/com32/hdt/hdt-cli-pxe.c b/com32/hdt/hdt-cli-pxe.c index 4353b51..64b1502 100644 --- a/com32/hdt/hdt-cli-pxe.c +++ b/com32/hdt/hdt-cli-pxe.c @@ -49,19 +49,17 @@ void main_show_pxe(struct s_hardware *hardware,struct s_cli_mode *cli_mode) { more_printf(" PCI device no: %d \n", p->pci_device_pos); if (hardware->pci_ids_return_code == -ENOPCIIDS) { - snprintf(buffer,sizeof(buffer)," PCI ID : %04x:%04x[%04x:%04X] rev(%02x)\n", + snprintf(buffer,sizeof(buffer)," PCI ID : %04x:%04x[%04x:%04X] rev(%02x)\n", p->vendor_id, p->product_id, p->subvendor_id, p->subproduct_id, p->rev); - snprintf(buffer,sizeof(buffer)," PCI Bus pos. : %02x:%02x.%02x\n", + snprintf(buffer,sizeof(buffer)," PCI Bus pos. : %02x:%02x.%02x\n", p->pci_bus,p->pci_dev, p->pci_func); - - more_printf(buffer); + more_printf(buffer); } else { - snprintf(buffer,sizeof(buffer)," Manufacturer : %s \n", p->pci_device->dev_info->vendor_name); - more_printf(buffer); - snprintf(buffer,sizeof(buffer)," Product : %s \n", p->pci_device->dev_info->product_name); - more_printf(buffer); - + snprintf(buffer,sizeof(buffer)," Manufacturer : %s \n", p->pci_device->dev_info->vendor_name); + more_printf(buffer); + snprintf(buffer,sizeof(buffer)," Product : %s \n", p->pci_device->dev_info->product_name); + more_printf(buffer); } - + more_printf( " Addresses : %d.%d.%d.%d @ %s\n",p->ip_addr[0], p->ip_addr[1], p->ip_addr[2], p->ip_addr[3],p->mac_addr); } diff --git a/com32/hdt/hdt-common.c b/com32/hdt/hdt-common.c index 47f0970..46fde40 100644 --- a/com32/hdt/hdt-common.c +++ b/com32/hdt/hdt-common.c @@ -55,7 +55,7 @@ void init_hardware(struct s_hardware *hardware) { /* Detecting if a DMI table exist * if yes, let's parse it */ int detect_dmi(struct s_hardware *hardware) { - if (hardware->dmi_detection == true) return; + if (hardware->dmi_detection == true) return -1; hardware->dmi_detection=true; if (dmi_iterate(&hardware->dmi) == -ENODMITABLE ) { hardware->is_dmi_valid=false; @@ -80,6 +80,7 @@ void detect_disks(struct s_hardware *hardware) { int detect_pxe(struct s_hardware *hardware) { void *dhcpdata; + size_t dhcplen; const struct syslinux_version *sv; t_PXENV_UNDI_GET_NIC_TYPE gnt; @@ -98,6 +99,17 @@ int detect_pxe(struct s_hardware *hardware) { // printf("PXE: PXElinux detected\n"); if (!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) { + pxe_bootp_t *dhcp=&hardware->pxe.dhcpdata; + memcpy(&hardware->pxe.dhcpdata,dhcpdata,dhcplen); + snprintf(hardware->pxe.mac_addr, sizeof(hardware->pxe.mac_addr), "%02x:%02x:%02x:%02x:%02x:%02x", + dhcp->CAddr[0],dhcp->CAddr[1],dhcp->CAddr[2],dhcp->CAddr[3],dhcp->CAddr[4],dhcp->CAddr[5]); + + /* Saving Our IP address in a easy format*/ + hardware->pxe.ip_addr[0]= hardware->pxe.dhcpdata.yip & 0xff; + hardware->pxe.ip_addr[1]= hardware->pxe.dhcpdata.yip >>8 & 0xff; + hardware->pxe.ip_addr[2]= hardware->pxe.dhcpdata.yip >>16 & 0xff; + hardware->pxe.ip_addr[3]= hardware->pxe.dhcpdata.yip >>24 & 0xff; + if (!pxe_get_nic_type(&gnt)) { switch(gnt.NicType) { case PCI_NIC: @@ -133,7 +145,8 @@ int detect_pxe(struct s_hardware *hardware) { case PnP_NIC: default: return -1; break; } - if (hardware->pci_detection==false) detect_pci(hardware); + /* Let's try to find the associated pci device */ + detect_pci(hardware); hardware->pxe.pci_device=NULL; hardware->pxe.pci_device_pos=0; struct pci_device *pci_device; @@ -147,7 +160,6 @@ int detect_pxe(struct s_hardware *hardware) { (pci_device->product == hardware->pxe.product_id)) { hardware->pxe.pci_device=pci_device; hardware->pxe.pci_device_pos=pci_number; - // printf("PXE: PCI device %d is the current boot device\n", pci_number); } } } diff --git a/com32/hdt/hdt-common.h b/com32/hdt/hdt-common.h index d78b45b..04a46e4 100644 --- a/com32/hdt/hdt-common.h +++ b/com32/hdt/hdt-common.h @@ -66,9 +66,13 @@ struct s_pxe { uint8_t sub_class; uint8_t prog_intf; uint8_t nictype; + char mac_addr[18]; /* The current mac address */ + uint8_t ip_addr[4]; + + pxe_bootp_t dhcpdata; /* The dhcp answer */ + struct pci_device *pci_device; /* The matching pci device */ + uint8_t pci_device_pos; /* It position in our pci sorted list*/ - struct pci_device *pci_device; - uint8_t pci_device_pos; }; struct s_hardware { -- 2.7.4