Quickly hacked to use a buffer rather than a processor.
These don't yet take advantage of the buffer functionality.
This commit is contained in:
parent
5fce946de4
commit
75a5374d79
|
@ -2,6 +2,16 @@
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "nic.h"
|
#include "nic.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IMPORTANT
|
||||||
|
*
|
||||||
|
* This file should be rewritten to avoid the use of a bitmap. Our
|
||||||
|
* buffer routines can cope with being handed blocks in an arbitrary
|
||||||
|
* order, duplicate blocks, etc. This code could be substantially
|
||||||
|
* simplified by taking advantage of these features.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#define SLAM_PORT 10000
|
#define SLAM_PORT 10000
|
||||||
#define SLAM_MULTICAST_IP ((239<<24)|(255<<16)|(1<<8)|(1<<0))
|
#define SLAM_MULTICAST_IP ((239<<24)|(255<<16)|(1<<8)|(1<<0))
|
||||||
#define SLAM_MULTICAST_PORT 10000
|
#define SLAM_MULTICAST_PORT 10000
|
||||||
|
@ -82,6 +92,7 @@ struct slam_state {
|
||||||
|
|
||||||
unsigned long received_packets;
|
unsigned long received_packets;
|
||||||
|
|
||||||
|
struct buffer *buffer;
|
||||||
unsigned char *image;
|
unsigned char *image;
|
||||||
unsigned char *bitmap;
|
unsigned char *bitmap;
|
||||||
} state;
|
} state;
|
||||||
|
@ -104,10 +115,8 @@ struct slam_info {
|
||||||
struct sockaddr_in server;
|
struct sockaddr_in server;
|
||||||
struct sockaddr_in local;
|
struct sockaddr_in local;
|
||||||
struct sockaddr_in multicast;
|
struct sockaddr_in multicast;
|
||||||
int ( * process ) ( unsigned char *data,
|
|
||||||
unsigned int blocknum,
|
|
||||||
unsigned int len, int eof );
|
|
||||||
int sent_nack;
|
int sent_nack;
|
||||||
|
struct buffer *buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SLAM_TIMEOUT 0
|
#define SLAM_TIMEOUT 0
|
||||||
|
@ -304,12 +313,11 @@ static unsigned char *reinit_slam_state(
|
||||||
printf("ALERT: slam blocksize to large\n");
|
printf("ALERT: slam blocksize to large\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (state.bitmap) {
|
|
||||||
forget(state.bitmap);
|
|
||||||
}
|
|
||||||
bitmap_len = (state.total_packets + 1 + 7)/8;
|
bitmap_len = (state.total_packets + 1 + 7)/8;
|
||||||
state.bitmap = allot(bitmap_len);
|
state.image = phys_to_virt ( state.buffer->start );
|
||||||
state.image = allot(total_bytes);
|
/* We don't use the buffer routines properly yet; fake it */
|
||||||
|
state.buffer->fill = total_bytes;
|
||||||
|
state.bitmap = state.image + total_bytes;
|
||||||
if ((unsigned long)state.image < 1024*1024) {
|
if ((unsigned long)state.image < 1024*1024) {
|
||||||
printf("ALERT: slam filesize to large for available memory\n");
|
printf("ALERT: slam filesize to large for available memory\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -440,6 +448,7 @@ static int proto_slam(struct slam_info *info)
|
||||||
long timeout;
|
long timeout;
|
||||||
|
|
||||||
init_slam_state();
|
init_slam_state();
|
||||||
|
state.buffer = info->buffer;
|
||||||
|
|
||||||
retry = -1;
|
retry = -1;
|
||||||
rx_qdrain();
|
rx_qdrain();
|
||||||
|
@ -504,15 +513,11 @@ static int proto_slam(struct slam_info *info)
|
||||||
leave_group(IGMP_SERVER);
|
leave_group(IGMP_SERVER);
|
||||||
/* FIXME don't overwrite myself */
|
/* FIXME don't overwrite myself */
|
||||||
/* load file to correct location */
|
/* load file to correct location */
|
||||||
return info->process(state.image, 1, state.total_bytes, 1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int url_slam ( char *url __unused,
|
static int url_slam ( char *url __unused, struct sockaddr_in *server,
|
||||||
struct sockaddr_in *server,
|
char *file, struct buffer *buffer ) {
|
||||||
char *file,
|
|
||||||
int ( * process ) ( unsigned char *data,
|
|
||||||
unsigned int blocknum,
|
|
||||||
unsigned int len, int eof ) ) {
|
|
||||||
struct slam_info info;
|
struct slam_info info;
|
||||||
/* Set the defaults */
|
/* Set the defaults */
|
||||||
info.server = *server;
|
info.server = *server;
|
||||||
|
@ -520,7 +525,7 @@ static int url_slam ( char *url __unused,
|
||||||
info.multicast.sin_port = SLAM_MULTICAST_PORT;
|
info.multicast.sin_port = SLAM_MULTICAST_PORT;
|
||||||
info.local.sin_addr.s_addr = arptable[ARP_CLIENT].ipaddr.s_addr;
|
info.local.sin_addr.s_addr = arptable[ARP_CLIENT].ipaddr.s_addr;
|
||||||
info.local.sin_port = SLAM_LOCAL_PORT;
|
info.local.sin_port = SLAM_LOCAL_PORT;
|
||||||
info.process = process;
|
info.buffer = buffer;
|
||||||
info.sent_nack = 0;
|
info.sent_nack = 0;
|
||||||
if (file[0]) {
|
if (file[0]) {
|
||||||
printf("\nBad url\n");
|
printf("\nBad url\n");
|
||||||
|
|
|
@ -35,6 +35,16 @@
|
||||||
* Indent Options: indent -kr -i8
|
* Indent Options: indent -kr -i8
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IMPORTANT
|
||||||
|
*
|
||||||
|
* This file should be rewritten to avoid the use of a bitmap. Our
|
||||||
|
* buffer routines can cope with being handed blocks in an arbitrary
|
||||||
|
* order, duplicate blocks, etc. This code could be substantially
|
||||||
|
* simplified by taking advantage of these features.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "etherboot.h"
|
#include "etherboot.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "nic.h"
|
#include "nic.h"
|
||||||
|
@ -43,9 +53,6 @@ struct tftm_info {
|
||||||
struct sockaddr_in server;
|
struct sockaddr_in server;
|
||||||
struct sockaddr_in local;
|
struct sockaddr_in local;
|
||||||
struct sockaddr_in multicast;
|
struct sockaddr_in multicast;
|
||||||
int ( * process ) ( unsigned char *data,
|
|
||||||
unsigned int blocknum,
|
|
||||||
unsigned int len, int eof );
|
|
||||||
int sent_nack;
|
int sent_nack;
|
||||||
const char *name; /* Filename */
|
const char *name; /* Filename */
|
||||||
};
|
};
|
||||||
|
@ -56,6 +63,7 @@ struct tftm_state {
|
||||||
unsigned long total_packets;
|
unsigned long total_packets;
|
||||||
char ismaster;
|
char ismaster;
|
||||||
unsigned long received_packets;
|
unsigned long received_packets;
|
||||||
|
struct buffer *buffer;
|
||||||
unsigned char *image;
|
unsigned char *image;
|
||||||
unsigned char *bitmap;
|
unsigned char *bitmap;
|
||||||
char recvd_oack;
|
char recvd_oack;
|
||||||
|
@ -221,17 +229,11 @@ static int proto_tftm(struct tftm_info *info)
|
||||||
bitmap_len =
|
bitmap_len =
|
||||||
(state.total_packets + 7) / 8;
|
(state.total_packets + 7) / 8;
|
||||||
if (!state.image) {
|
if (!state.image) {
|
||||||
state.bitmap =
|
state.image = phys_to_virt ( state.buffer->start );
|
||||||
allot(bitmap_len);
|
state.bitmap = state.image + filesize;
|
||||||
state.image =
|
/* We don't yet use the buffer routines; fake it */
|
||||||
allot(filesize);
|
state.buffer->fill = filesize;
|
||||||
|
|
||||||
if ((unsigned long) state.
|
|
||||||
image < 1024 * 1024) {
|
|
||||||
printf
|
|
||||||
("ALERT: tftp filesize to large for available memory\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
memset(state.bitmap, 0,
|
memset(state.bitmap, 0,
|
||||||
bitmap_len);
|
bitmap_len);
|
||||||
}
|
}
|
||||||
|
@ -360,7 +362,6 @@ static int proto_tftm(struct tftm_info *info)
|
||||||
TFTP_MIN_PACKET, &tp); /* ack */
|
TFTP_MIN_PACKET, &tp); /* ack */
|
||||||
}
|
}
|
||||||
/* We are done get out */
|
/* We are done get out */
|
||||||
forget(state.bitmap);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,15 +377,11 @@ static int proto_tftm(struct tftm_info *info)
|
||||||
}
|
}
|
||||||
/* Leave the multicast group */
|
/* Leave the multicast group */
|
||||||
leave_group(IGMP_SERVER);
|
leave_group(IGMP_SERVER);
|
||||||
return info->process(state.image, 1, filesize, 1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int url_tftm ( char *url __unused,
|
static int url_tftm ( char *url __unused, struct sockaddr_in *server,
|
||||||
struct sockaddr_in *server,
|
char *file, struct buffer *buffer ) {
|
||||||
char *file,
|
|
||||||
int ( * process ) ( unsigned char *data,
|
|
||||||
unsigned int blocknum,
|
|
||||||
unsigned int len, int eof ) ) {
|
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
struct tftm_info info;
|
struct tftm_info info;
|
||||||
|
@ -394,7 +391,6 @@ static int url_tftm ( char *url __unused,
|
||||||
info.local.sin_addr.s_addr = arptable[ARP_CLIENT].ipaddr.s_addr;
|
info.local.sin_addr.s_addr = arptable[ARP_CLIENT].ipaddr.s_addr;
|
||||||
info.local.sin_port = TFTM_PORT; /* Does not matter. */
|
info.local.sin_port = TFTM_PORT; /* Does not matter. */
|
||||||
info.multicast = info.local;
|
info.multicast = info.local;
|
||||||
info.process = process;
|
|
||||||
state.ismaster = 0;
|
state.ismaster = 0;
|
||||||
info.name = file;
|
info.name = file;
|
||||||
|
|
||||||
|
@ -402,6 +398,7 @@ static int url_tftm ( char *url __unused,
|
||||||
state.total_bytes = 0;
|
state.total_bytes = 0;
|
||||||
state.total_packets = 0;
|
state.total_packets = 0;
|
||||||
state.received_packets = 0;
|
state.received_packets = 0;
|
||||||
|
state.buffer = buffer;
|
||||||
state.image = 0;
|
state.image = 0;
|
||||||
state.bitmap = 0;
|
state.bitmap = 0;
|
||||||
state.recvd_oack = 0;
|
state.recvd_oack = 0;
|
||||||
|
|
Reference in New Issue