|
@@ -0,0 +1,95 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
|
|
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
|
+#include <string.h>
|
|
20
|
+#include <errno.h>
|
|
21
|
+#include <gpxe/dhcp.h>
|
|
22
|
+#include <gpxe/settings.h>
|
|
23
|
+#include <gpxe/netdevice.h>
|
|
24
|
+
|
|
25
|
+/** @file
|
|
26
|
+ *
|
|
27
|
+ * Network device configuration settings
|
|
28
|
+ *
|
|
29
|
+ */
|
|
30
|
+
|
|
31
|
+/**
|
|
32
|
+ * Store value of network device setting
|
|
33
|
+ *
|
|
34
|
+ * @v settings Settings block
|
|
35
|
+ * @v tag Setting tag number
|
|
36
|
+ * @v data Setting data, or NULL to clear setting
|
|
37
|
+ * @v len Length of setting data
|
|
38
|
+ * @ret rc Return status code
|
|
39
|
+ */
|
|
40
|
+static int netdev_store ( struct settings *settings, unsigned int tag,
|
|
41
|
+ const void *data, size_t len ) {
|
|
42
|
+ struct net_device *netdev =
|
|
43
|
+ container_of ( settings, struct net_device, settings );
|
|
44
|
+
|
|
45
|
+ switch ( tag ) {
|
|
46
|
+ case DHCP_EB_MAC:
|
|
47
|
+ if ( len != netdev->ll_protocol->ll_addr_len )
|
|
48
|
+ return -EINVAL;
|
|
49
|
+ memcpy ( netdev->ll_addr, data, len );
|
|
50
|
+ return 0;
|
|
51
|
+ default :
|
|
52
|
+ return simple_settings_store ( settings, tag, data, len );
|
|
53
|
+ }
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+/**
|
|
57
|
+ * Fetch value of network device setting
|
|
58
|
+ *
|
|
59
|
+ * @v settings Settings block
|
|
60
|
+ * @v tag Setting tag number
|
|
61
|
+ * @v data Setting data, or NULL to clear setting
|
|
62
|
+ * @v len Length of setting data
|
|
63
|
+ * @ret rc Return status code
|
|
64
|
+ */
|
|
65
|
+static int netdev_fetch ( struct settings *settings, unsigned int tag,
|
|
66
|
+ void *data, size_t len ) {
|
|
67
|
+ struct net_device *netdev =
|
|
68
|
+ container_of ( settings, struct net_device, settings );
|
|
69
|
+
|
|
70
|
+ switch ( tag ) {
|
|
71
|
+ case DHCP_EB_MAC:
|
|
72
|
+ if ( len > netdev->ll_protocol->ll_addr_len )
|
|
73
|
+ len = netdev->ll_protocol->ll_addr_len;
|
|
74
|
+ memcpy ( data, netdev->ll_addr, len );
|
|
75
|
+ return netdev->ll_protocol->ll_addr_len;
|
|
76
|
+ default :
|
|
77
|
+ return simple_settings_fetch ( settings, tag, data, len );
|
|
78
|
+ }
|
|
79
|
+}
|
|
80
|
+
|
|
81
|
+/** Network device configuration settings operations */
|
|
82
|
+struct settings_operations netdev_settings_operations = {
|
|
83
|
+ .store = netdev_store,
|
|
84
|
+ .fetch = netdev_fetch,
|
|
85
|
+};
|
|
86
|
+
|
|
87
|
+/** Network device named settings */
|
|
88
|
+struct named_setting netdev_named_settings[] __named_setting = {
|
|
89
|
+ {
|
|
90
|
+ .name = "mac",
|
|
91
|
+ .description = "MAC address",
|
|
92
|
+ .tag = DHCP_EB_MAC,
|
|
93
|
+ .type = &setting_type_hex,
|
|
94
|
+ },
|
|
95
|
+};
|