2008-03-20 22:06:03 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <gpxe/dhcp.h>
|
|
|
|
#include <gpxe/settings.h>
|
|
|
|
#include <gpxe/netdevice.h>
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Network device configuration settings
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-03-25 21:46:16 +01:00
|
|
|
/** Network device named settings */
|
|
|
|
struct setting mac_setting __setting = {
|
|
|
|
.name = "mac",
|
|
|
|
.description = "MAC address",
|
|
|
|
.type = &setting_type_hex,
|
|
|
|
};
|
|
|
|
|
2008-03-20 22:06:03 +01:00
|
|
|
/**
|
|
|
|
* Store value of network device setting
|
|
|
|
*
|
|
|
|
* @v settings Settings block
|
2008-03-25 21:46:16 +01:00
|
|
|
* @v setting Setting to store
|
2008-03-20 22:06:03 +01:00
|
|
|
* @v data Setting data, or NULL to clear setting
|
|
|
|
* @v len Length of setting data
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
2008-03-25 21:46:16 +01:00
|
|
|
static int netdev_store ( struct settings *settings, struct setting *setting,
|
2008-03-20 22:06:03 +01:00
|
|
|
const void *data, size_t len ) {
|
2008-03-22 01:24:50 +01:00
|
|
|
struct net_device *netdev = container_of ( settings, struct net_device,
|
|
|
|
settings.settings );
|
2008-03-20 22:06:03 +01:00
|
|
|
|
2008-03-25 21:46:16 +01:00
|
|
|
if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
|
2008-03-20 22:06:03 +01:00
|
|
|
if ( len != netdev->ll_protocol->ll_addr_len )
|
|
|
|
return -EINVAL;
|
|
|
|
memcpy ( netdev->ll_addr, data, len );
|
|
|
|
return 0;
|
2008-03-25 21:46:16 +01:00
|
|
|
} else {
|
|
|
|
return simple_settings_store ( settings, setting, data, len );
|
2008-03-20 22:06:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch value of network device setting
|
|
|
|
*
|
|
|
|
* @v settings Settings block
|
2008-03-25 21:46:16 +01:00
|
|
|
* @v setting Setting to fetch
|
2008-03-20 22:06:03 +01:00
|
|
|
* @v data Setting data, or NULL to clear setting
|
|
|
|
* @v len Length of setting data
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
2008-03-25 21:46:16 +01:00
|
|
|
static int netdev_fetch ( struct settings *settings, struct setting *setting,
|
2008-03-20 22:06:03 +01:00
|
|
|
void *data, size_t len ) {
|
2008-03-22 01:24:50 +01:00
|
|
|
struct net_device *netdev = container_of ( settings, struct net_device,
|
|
|
|
settings.settings );
|
2008-03-20 22:06:03 +01:00
|
|
|
|
2008-03-25 21:46:16 +01:00
|
|
|
if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
|
2008-03-20 22:06:03 +01:00
|
|
|
if ( len > netdev->ll_protocol->ll_addr_len )
|
|
|
|
len = netdev->ll_protocol->ll_addr_len;
|
|
|
|
memcpy ( data, netdev->ll_addr, len );
|
|
|
|
return netdev->ll_protocol->ll_addr_len;
|
2008-03-25 21:46:16 +01:00
|
|
|
} else {
|
|
|
|
return simple_settings_fetch ( settings, setting, data, len );
|
2008-03-20 22:06:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Network device configuration settings operations */
|
|
|
|
struct settings_operations netdev_settings_operations = {
|
|
|
|
.store = netdev_store,
|
|
|
|
.fetch = netdev_fetch,
|
|
|
|
};
|