2 * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gpxe/dhcp.h>
22 #include <gpxe/settings.h>
23 #include <gpxe/netdevice.h>
27 * Network device configuration settings
31 /** Network device named settings */
32 struct setting mac_setting __setting
= {
34 .description
= "MAC address",
35 .type
= &setting_type_hex
,
39 * Store value of network device setting
41 * @v settings Settings block
42 * @v setting Setting to store
43 * @v data Setting data, or NULL to clear setting
44 * @v len Length of setting data
45 * @ret rc Return status code
47 static int netdev_store ( struct settings
*settings
, struct setting
*setting
,
48 const void *data
, size_t len
) {
49 struct net_device
*netdev
= container_of ( settings
, struct net_device
,
52 if ( setting_cmp ( setting
, &mac_setting
) == 0 ) {
53 if ( len
!= netdev
->ll_protocol
->ll_addr_len
)
55 memcpy ( netdev
->ll_addr
, data
, len
);
58 return simple_settings_store ( settings
, setting
, data
, len
);
63 * Fetch value of network device setting
65 * @v settings Settings block
66 * @v setting Setting to fetch
67 * @v data Setting data, or NULL to clear setting
68 * @v len Length of setting data
69 * @ret rc Return status code
71 static int netdev_fetch ( struct settings
*settings
, struct setting
*setting
,
72 void *data
, size_t len
) {
73 struct net_device
*netdev
= container_of ( settings
, struct net_device
,
76 if ( setting_cmp ( setting
, &mac_setting
) == 0 ) {
77 if ( len
> netdev
->ll_protocol
->ll_addr_len
)
78 len
= netdev
->ll_protocol
->ll_addr_len
;
79 memcpy ( data
, netdev
->ll_addr
, len
);
80 return netdev
->ll_protocol
->ll_addr_len
;
82 return simple_settings_fetch ( settings
, setting
, data
, len
);
86 /** Network device configuration settings operations */
87 struct settings_operations netdev_settings_operations
= {
88 .store
= netdev_store
,
89 .fetch
= netdev_fetch
,