Ver código fonte

Added quick and dirty commands for testing the new NVO code.

tags/v0.9.3
Michael Brown 18 anos atrás
pai
commit
d9f32726b4
4 arquivos alterados com 81 adições e 4 exclusões
  1. 68
    0
      src/commandline/commands/nvo_cmd.c
  2. 1
    1
      src/core/main.c
  3. 8
    1
      src/core/nvo.c
  4. 4
    2
      src/include/cmdlist.h

+ 68
- 0
src/commandline/commands/nvo_cmd.c Ver arquivo

@@ -0,0 +1,68 @@
1
+#include <stdint.h>
2
+#include <stdlib.h>
3
+#include <string.h>
4
+#include <errno.h>
5
+#include <vsprintf.h>
6
+#include <command.h>
7
+#include <gpxe/nvo.h>
8
+#include <gpxe/dhcp.h>
9
+
10
+void nvo_cmd_req() {}
11
+
12
+extern struct nvo_block *ugly_nvo_hack;
13
+
14
+static int show_exec ( int argc, char **argv ) {
15
+
16
+	if ( ! ugly_nvo_hack ) {
17
+		printf ( "No non-volatile option storage available\n" );
18
+		return 1;
19
+	}
20
+
21
+	hex_dump ( ugly_nvo_hack->options->data,
22
+		   ugly_nvo_hack->options->len );
23
+}
24
+
25
+struct command show_command __command = {
26
+	.name = "show",
27
+	.usage = "show\n",
28
+	.desc = "Show stored options",
29
+	.exec = show_exec,
30
+};
31
+
32
+static int set_exec ( int argc, char **argv ) {
33
+	unsigned long tag;
34
+	struct dhcp_option *option;
35
+
36
+	if ( ! ugly_nvo_hack ) {
37
+		printf ( "No non-volatile option storage available\n" );
38
+		return 1;
39
+	}
40
+
41
+	if ( argc != 3 ) {
42
+		printf ( "Syntax: %s <option number> <option string>\n",
43
+			 argv[0] );
44
+		return 1;
45
+	}
46
+
47
+	tag = strtoul ( argv[1], NULL, 0 );
48
+	option = set_dhcp_option ( ugly_nvo_hack->options, tag, argv[2],
49
+				   strlen ( argv[2] ) );
50
+	if ( ! option ) {
51
+		printf ( "Could not set option %ld\n", tag );
52
+		return 1;
53
+	}
54
+
55
+	if ( nvo_save ( ugly_nvo_hack ) != 0 ) {
56
+		printf ( "Could not save options to non-volatile storage\n" );
57
+		return 1;
58
+	}
59
+
60
+	return 0;
61
+}
62
+
63
+struct command set_command __command = {
64
+	.name = "set",
65
+	.usage = "set <option number> <option string>\n",
66
+	.desc = "Set stored option",
67
+	.exec = set_exec,
68
+};

+ 1
- 1
src/core/main.c Ver arquivo

@@ -157,8 +157,8 @@ int main ( void ) {
157 157
 
158 158
 	netdev = next_netdev ();
159 159
 	if ( netdev ) {
160
+		cmdl_start();
160 161
 		test_dhcp ( netdev );
161
-		//cmdl_start();
162 162
 	} else {
163 163
 		printf ( "No network device found\n" );
164 164
 	}

+ 8
- 1
src/core/nvo.c Ver arquivo

@@ -28,6 +28,9 @@
28 28
  *
29 29
  */
30 30
 
31
+#warning "Temporary hack"
32
+struct nvo_block *ugly_nvo_hack = NULL;
33
+
31 34
 /**
32 35
  * Calculate checksum over non-volatile stored options
33 36
  *
@@ -83,7 +86,7 @@ int nvo_save ( struct nvo_block *nvo ) {
83 86
 	int rc;
84 87
 
85 88
 	/* Recalculate checksum */
86
-	checksum -= nvo_checksum ( nvo );
89
+	*checksum -= nvo_checksum ( nvo );
87 90
 
88 91
 	/* Write data a fragment at a time */
89 92
 	for ( fragment = nvo->fragments ; fragment->len ; fragment++ ) {
@@ -182,6 +185,8 @@ int nvo_register ( struct nvo_block *nvo ) {
182 185
 	nvo_init_dhcp ( nvo );
183 186
 	register_dhcp_options ( nvo->options );
184 187
 
188
+	ugly_nvo_hack = nvo;
189
+
185 190
 	return 0;
186 191
 	
187 192
  err:
@@ -201,4 +206,6 @@ void nvo_unregister ( struct nvo_block *nvo ) {
201 206
 		free_dhcp_options ( nvo->options );
202 207
 		nvo->options = NULL;
203 208
 	}
209
+
210
+	ugly_nvo_hack = NULL;
204 211
 }

+ 4
- 2
src/include/cmdlist.h Ver arquivo

@@ -4,12 +4,14 @@
4 4
 void test_req();
5 5
 void test2_req();
6 6
 void help_req();
7
+void nvo_cmd_req();
7 8
 
8 9
 void commandlist()
9 10
 {
10
-	test_req();
11
-	test2_req();
11
+	//	test_req();
12
+	//	test2_req();
12 13
 	help_req();
14
+	nvo_cmd_req();
13 15
 }
14 16
 
15 17
 #endif

Carregando…
Cancelar
Salvar