[settings] Add Bus ID setting
authorShao Miller <shao.miller@yrdsb.edu.on.ca>
Mon, 9 Nov 2009 13:57:23 +0000 (08:57 -0500)
committerStefan Hajnoczi <stefanha@gmail.com>
Mon, 14 Dec 2009 17:54:53 +0000 (17:54 +0000)
Users can find the bus type and PCI IDs for a network interface with:

netX/busid

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
src/include/gpxe/settings.h
src/net/netdev_settings.c
src/net/udp/dhcp.c

index 09934b6..efefe73 100644 (file)
@@ -242,6 +242,7 @@ extern struct setting priority_setting __setting;
 extern struct setting uuid_setting __setting;
 extern struct setting next_server_setting __setting;
 extern struct setting mac_setting __setting;
+extern struct setting busid_setting __setting;
 extern struct setting user_class_setting __setting;
 
 /**
index b9220f5..d814193 100644 (file)
@@ -20,8 +20,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
 
 #include <string.h>
 #include <errno.h>
+#include <byteswap.h>
 #include <gpxe/dhcp.h>
 #include <gpxe/settings.h>
+#include <gpxe/device.h>
 #include <gpxe/netdevice.h>
 
 /** @file
@@ -36,6 +38,11 @@ struct setting mac_setting __setting = {
        .description = "MAC address",
        .type = &setting_type_hex,
 };
+struct setting busid_setting __setting = {
+       .name = "busid",
+       .description = "Bus ID",
+       .type = &setting_type_hex,
+};
 
 /**
  * Store value of network device setting
@@ -74,6 +81,8 @@ static int netdev_fetch ( struct settings *settings, struct setting *setting,
                          void *data, size_t len ) {
        struct net_device *netdev = container_of ( settings, struct net_device,
                                                   settings.settings );
+       struct device_description *desc = &netdev->dev->desc;
+       struct dhcp_netdev_desc dhcp_desc;
 
        if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
                if ( len > netdev->ll_protocol->ll_addr_len )
@@ -81,6 +90,15 @@ static int netdev_fetch ( struct settings *settings, struct setting *setting,
                memcpy ( data, netdev->ll_addr, len );
                return netdev->ll_protocol->ll_addr_len;
        }
+       if ( setting_cmp ( setting, &busid_setting ) == 0 ) {
+               dhcp_desc.type = desc->bus_type;
+               dhcp_desc.vendor = htons ( desc->vendor );
+               dhcp_desc.device = htons ( desc->device );
+               if ( len > sizeof ( dhcp_desc ) )
+                       len = sizeof ( dhcp_desc );
+               memcpy ( data, &dhcp_desc, len );
+               return sizeof ( dhcp_desc );
+       }
 
        return generic_settings_fetch ( settings, setting, data, len );
 }
index 2483ec2..17e543a 100644 (file)
@@ -932,7 +932,6 @@ int dhcp_create_packet ( struct dhcp_packet *dhcppkt,
 int dhcp_create_request ( struct dhcp_packet *dhcppkt,
                          struct net_device *netdev, unsigned int msgtype,
                          struct in_addr ciaddr, void *data, size_t max_len ) {
-       struct device_description *desc = &netdev->dev->desc;
        struct dhcp_netdev_desc dhcp_desc;
        struct dhcp_client_id client_id;
        struct dhcp_client_uuid client_uuid;
@@ -966,9 +965,8 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
        }
 
        /* Add options to identify the network device */
-       dhcp_desc.type = desc->bus_type;
-       dhcp_desc.vendor = htons ( desc->vendor );
-       dhcp_desc.device = htons ( desc->device );
+       fetch_setting ( &netdev->settings.settings, &busid_setting, &dhcp_desc,
+               sizeof ( dhcp_desc ) );
        if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
                                    sizeof ( dhcp_desc ) ) ) != 0 ) {
                DBG ( "DHCP could not set bus ID option: %s\n",