|
|
1.1 root 1: /*
2: * Copyright (C) 2008 Michael Brown <[email protected]>.
3: *
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.
8: *
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.
13: *
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.
17: */
18:
19: FILE_LICENCE ( GPL2_OR_LATER );
20:
21: #include <string.h>
22: #include <errno.h>
23: #include <byteswap.h>
24: #include <ipxe/dhcp.h>
25: #include <ipxe/dhcpopts.h>
26: #include <ipxe/settings.h>
27: #include <ipxe/device.h>
28: #include <ipxe/netdevice.h>
29:
30: /** @file
31: *
32: * Network device configuration settings
33: *
34: */
35:
36: /** Network device named settings */
37: struct setting mac_setting __setting ( SETTING_NETDEV ) = {
38: .name = "mac",
39: .description = "MAC address",
40: .type = &setting_type_hex,
41: .tag = NETDEV_SETTING_TAG_MAC,
42: };
43: struct setting busid_setting __setting ( SETTING_NETDEV ) = {
44: .name = "busid",
45: .description = "Bus ID",
46: .type = &setting_type_hex,
47: .tag = NETDEV_SETTING_TAG_BUS_ID,
48: };
49:
50: /**
51: * Check applicability of network device setting
52: *
53: * @v settings Settings block
54: * @v setting Setting
55: * @ret applies Setting applies within this settings block
56: */
57: static int netdev_applies ( struct settings *settings __unused,
58: struct setting *setting ) {
59:
60: return ( IS_NETDEV_SETTING_TAG ( setting->tag ) ||
61: dhcpopt_applies ( setting->tag ) );
62: }
63:
64: /**
65: * Store value of network device setting
66: *
67: * @v settings Settings block
68: * @v setting Setting to store
69: * @v data Setting data, or NULL to clear setting
70: * @v len Length of setting data
71: * @ret rc Return status code
72: */
73: static int netdev_store ( struct settings *settings, struct setting *setting,
74: const void *data, size_t len ) {
75: struct net_device *netdev = container_of ( settings, struct net_device,
76: settings.settings );
77:
78: if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
79: if ( len != netdev->ll_protocol->ll_addr_len )
80: return -EINVAL;
81: memcpy ( netdev->ll_addr, data, len );
82: return 0;
83: }
84: if ( setting_cmp ( setting, &busid_setting ) == 0 )
85: return -ENOTSUP;
86:
87: return generic_settings_store ( settings, setting, data, len );
88: }
89:
90: /**
91: * Fetch value of network device setting
92: *
93: * @v settings Settings block
94: * @v setting Setting to fetch
95: * @v data Setting data, or NULL to clear setting
96: * @v len Length of setting data
97: * @ret rc Return status code
98: */
99: static int netdev_fetch ( struct settings *settings, struct setting *setting,
100: void *data, size_t len ) {
101: struct net_device *netdev = container_of ( settings, struct net_device,
102: settings.settings );
103: struct device_description *desc = &netdev->dev->desc;
104: struct dhcp_netdev_desc dhcp_desc;
105:
106: if ( setting_cmp ( setting, &mac_setting ) == 0 ) {
107: if ( len > netdev->ll_protocol->ll_addr_len )
108: len = netdev->ll_protocol->ll_addr_len;
109: memcpy ( data, netdev->ll_addr, len );
110: return netdev->ll_protocol->ll_addr_len;
111: }
112: if ( setting_cmp ( setting, &busid_setting ) == 0 ) {
113: dhcp_desc.type = desc->bus_type;
114: dhcp_desc.vendor = htons ( desc->vendor );
115: dhcp_desc.device = htons ( desc->device );
116: if ( len > sizeof ( dhcp_desc ) )
117: len = sizeof ( dhcp_desc );
118: memcpy ( data, &dhcp_desc, len );
119: return sizeof ( dhcp_desc );
120: }
121:
122: return generic_settings_fetch ( settings, setting, data, len );
123: }
124:
125: /**
126: * Clear network device settings
127: *
128: * @v settings Settings block
129: */
130: static void netdev_clear ( struct settings *settings ) {
131: generic_settings_clear ( settings );
132: }
133:
134: /** Network device configuration settings operations */
135: struct settings_operations netdev_settings_operations = {
136: .applies = netdev_applies,
137: .store = netdev_store,
138: .fetch = netdev_fetch,
139: .clear = netdev_clear,
140: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.