Browse Source

Quickly hacked to use a buffer rather than a processor.

These don't yet take advantage of the buffer functionality.
tags/v0.9.3
Michael Brown 19 years ago
parent
commit
75a5374d79
2 changed files with 41 additions and 39 deletions
  1. 21
    16
      src/proto/slam.c
  2. 20
    23
      src/proto/tftm.c

+ 21
- 16
src/proto/slam.c View File

2
 #include "proto.h"
2
 #include "proto.h"
3
 #include "nic.h"
3
 #include "nic.h"
4
 
4
 
5
+/*
6
+ * IMPORTANT
7
+ *
8
+ * This file should be rewritten to avoid the use of a bitmap.  Our
9
+ * buffer routines can cope with being handed blocks in an arbitrary
10
+ * order, duplicate blocks, etc.  This code could be substantially
11
+ * simplified by taking advantage of these features.
12
+ *
13
+ */
14
+
5
 #define SLAM_PORT 10000
15
 #define SLAM_PORT 10000
6
 #define SLAM_MULTICAST_IP ((239<<24)|(255<<16)|(1<<8)|(1<<0))
16
 #define SLAM_MULTICAST_IP ((239<<24)|(255<<16)|(1<<8)|(1<<0))
7
 #define SLAM_MULTICAST_PORT 10000
17
 #define SLAM_MULTICAST_PORT 10000
82
 
92
 
83
 	unsigned long received_packets;
93
 	unsigned long received_packets;
84
 
94
 
95
+	struct buffer *buffer;
85
 	unsigned char *image;
96
 	unsigned char *image;
86
 	unsigned char *bitmap;
97
 	unsigned char *bitmap;
87
 } state;
98
 } state;
104
 	struct sockaddr_in server;
115
 	struct sockaddr_in server;
105
 	struct sockaddr_in local;
116
 	struct sockaddr_in local;
106
 	struct sockaddr_in multicast;
117
 	struct sockaddr_in multicast;
107
-	int ( * process ) ( unsigned char *data,
108
-			    unsigned int blocknum,
109
-			    unsigned int len, int eof );
110
 	int sent_nack;
118
 	int sent_nack;
119
+	struct buffer *buffer;
111
 };
120
 };
112
 
121
 
113
 #define SLAM_TIMEOUT 0
122
 #define SLAM_TIMEOUT 0
304
 		printf("ALERT: slam blocksize to large\n");
313
 		printf("ALERT: slam blocksize to large\n");
305
 		return 0;
314
 		return 0;
306
 	}
315
 	}
307
-	if (state.bitmap) {
308
-		forget(state.bitmap);
309
-	}
310
 	bitmap_len   = (state.total_packets + 1 + 7)/8;
316
 	bitmap_len   = (state.total_packets + 1 + 7)/8;
311
-	state.bitmap = allot(bitmap_len);
312
-	state.image  = allot(total_bytes);
317
+	state.image  = phys_to_virt ( state.buffer->start );
318
+	/* We don't use the buffer routines properly yet; fake it */
319
+	state.buffer->fill = total_bytes;
320
+	state.bitmap = state.image + total_bytes;
313
 	if ((unsigned long)state.image < 1024*1024) {
321
 	if ((unsigned long)state.image < 1024*1024) {
314
 		printf("ALERT: slam filesize to large for available memory\n");
322
 		printf("ALERT: slam filesize to large for available memory\n");
315
 		return 0;
323
 		return 0;
440
 	long timeout;
448
 	long timeout;
441
 
449
 
442
 	init_slam_state();
450
 	init_slam_state();
451
+	state.buffer = info->buffer;
443
 
452
 
444
 	retry = -1;
453
 	retry = -1;
445
 	rx_qdrain();
454
 	rx_qdrain();
504
 	leave_group(IGMP_SERVER);
513
 	leave_group(IGMP_SERVER);
505
 	/* FIXME don't overwrite myself */
514
 	/* FIXME don't overwrite myself */
506
 	/* load file to correct location */
515
 	/* load file to correct location */
507
-	return info->process(state.image, 1, state.total_bytes, 1);
516
+	return 1;
508
 }
517
 }
509
 
518
 
510
-static int url_slam ( char *url __unused,
511
-		      struct sockaddr_in *server,
512
-		      char *file,
513
-		      int ( * process ) ( unsigned char *data,
514
-					  unsigned int blocknum,
515
-					  unsigned int len, int eof ) ) {
519
+static int url_slam ( char *url __unused, struct sockaddr_in *server,
520
+		      char *file, struct buffer *buffer ) {
516
 	struct slam_info info;
521
 	struct slam_info info;
517
 	/* Set the defaults */
522
 	/* Set the defaults */
518
 	info.server = *server;
523
 	info.server = *server;
520
 	info.multicast.sin_port      = SLAM_MULTICAST_PORT;
525
 	info.multicast.sin_port      = SLAM_MULTICAST_PORT;
521
 	info.local.sin_addr.s_addr   = arptable[ARP_CLIENT].ipaddr.s_addr;
526
 	info.local.sin_addr.s_addr   = arptable[ARP_CLIENT].ipaddr.s_addr;
522
 	info.local.sin_port          = SLAM_LOCAL_PORT;
527
 	info.local.sin_port          = SLAM_LOCAL_PORT;
523
-	info.process                 = process;
528
+	info.buffer                  = buffer;
524
 	info.sent_nack = 0;
529
 	info.sent_nack = 0;
525
 	if (file[0]) {
530
 	if (file[0]) {
526
 		printf("\nBad url\n");
531
 		printf("\nBad url\n");

+ 20
- 23
src/proto/tftm.c View File

35
 *    Indent Options: indent -kr -i8
35
 *    Indent Options: indent -kr -i8
36
 ***************************************************************************/
36
 ***************************************************************************/
37
 
37
 
38
+/*
39
+ * IMPORTANT
40
+ *
41
+ * This file should be rewritten to avoid the use of a bitmap.  Our
42
+ * buffer routines can cope with being handed blocks in an arbitrary
43
+ * order, duplicate blocks, etc.  This code could be substantially
44
+ * simplified by taking advantage of these features.
45
+ *
46
+ */
47
+
38
 #include "etherboot.h"
48
 #include "etherboot.h"
39
 #include "proto.h"
49
 #include "proto.h"
40
 #include "nic.h"
50
 #include "nic.h"
43
 	struct sockaddr_in server;
53
 	struct sockaddr_in server;
44
 	struct sockaddr_in local;
54
 	struct sockaddr_in local;
45
 	struct sockaddr_in multicast;
55
 	struct sockaddr_in multicast;
46
-	int ( * process ) ( unsigned char *data,
47
-			    unsigned int blocknum,
48
-			    unsigned int len, int eof );
49
 	int sent_nack;
56
 	int sent_nack;
50
 	const char *name;	/* Filename */
57
 	const char *name;	/* Filename */
51
 };
58
 };
56
 	unsigned long total_packets;
63
 	unsigned long total_packets;
57
 	char ismaster;
64
 	char ismaster;
58
 	unsigned long received_packets;
65
 	unsigned long received_packets;
66
+	struct buffer *buffer;
59
 	unsigned char *image;
67
 	unsigned char *image;
60
 	unsigned char *bitmap;
68
 	unsigned char *bitmap;
61
 	char recvd_oack;
69
 	char recvd_oack;
221
 					bitmap_len =
229
 					bitmap_len =
222
 					    (state.total_packets + 7) / 8;
230
 					    (state.total_packets + 7) / 8;
223
 					if (!state.image) {
231
 					if (!state.image) {
224
-						state.bitmap =
225
-						    allot(bitmap_len);
226
-						state.image =
227
-						    allot(filesize);
228
-
229
-						if ((unsigned long) state.
230
-						    image < 1024 * 1024) {
231
-							printf
232
-							    ("ALERT: tftp filesize to large for available memory\n");
233
-							return 0;
234
-						}
232
+						state.image = phys_to_virt ( state.buffer->start );
233
+						state.bitmap = state.image + filesize;
234
+						/* We don't yet use the buffer routines; fake it */
235
+						state.buffer->fill = filesize;
236
+
235
 						memset(state.bitmap, 0,
237
 						memset(state.bitmap, 0,
236
 						       bitmap_len);
238
 						       bitmap_len);
237
 					}
239
 					}
360
 					     TFTP_MIN_PACKET, &tp); /* ack */
362
 					     TFTP_MIN_PACKET, &tp); /* ack */
361
 			}
363
 			}
362
 			/* We are done get out */
364
 			/* We are done get out */
363
-			forget(state.bitmap);
364
 			break;
365
 			break;
365
 		}
366
 		}
366
 
367
 
376
 	}
377
 	}
377
 	/* Leave the multicast group */
378
 	/* Leave the multicast group */
378
 	leave_group(IGMP_SERVER);
379
 	leave_group(IGMP_SERVER);
379
-	return info->process(state.image, 1, filesize, 1);
380
+	return 1;
380
 }
381
 }
381
 
382
 
382
-static int url_tftm ( char *url __unused,
383
-		      struct sockaddr_in *server,
384
-		      char *file,
385
-		      int ( * process ) ( unsigned char *data,
386
-					  unsigned int blocknum,
387
-					  unsigned int len, int eof ) ) {
383
+static int url_tftm ( char *url __unused, struct sockaddr_in *server,
384
+		      char *file, struct buffer *buffer ) {
388
 
385
 
389
 	int ret;
386
 	int ret;
390
 	struct tftm_info info;
387
 	struct tftm_info info;
394
 	info.local.sin_addr.s_addr = arptable[ARP_CLIENT].ipaddr.s_addr;
391
 	info.local.sin_addr.s_addr = arptable[ARP_CLIENT].ipaddr.s_addr;
395
 	info.local.sin_port = TFTM_PORT; /* Does not matter. */
392
 	info.local.sin_port = TFTM_PORT; /* Does not matter. */
396
 	info.multicast = info.local;
393
 	info.multicast = info.local;
397
-	info.process = process;
398
 	state.ismaster = 0;
394
 	state.ismaster = 0;
399
 	info.name = file;
395
 	info.name = file;
400
 
396
 
402
 	state.total_bytes = 0;
398
 	state.total_bytes = 0;
403
 	state.total_packets = 0;
399
 	state.total_packets = 0;
404
 	state.received_packets = 0;
400
 	state.received_packets = 0;
401
+	state.buffer = buffer;
405
 	state.image = 0;
402
 	state.image = 0;
406
 	state.bitmap = 0;
403
 	state.bitmap = 0;
407
 	state.recvd_oack = 0;
404
 	state.recvd_oack = 0;

Loading…
Cancel
Save