mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-29 10:39:22 +00:00
Initial Implementation of TFTP protocol and new protocol structs.
This commit is contained in:
1 parent
4931b0984b
commit
066528b4b1
23 files changed
+789
-6
No files matched your search
+102
@@ -0,0 +1,102 @@
|
||||
#include <grub/misc.h>
|
||||
#include <grub/net/tftp.h>
|
||||
#include <grub/net/udp.h>
|
||||
#include <grub/net/ip.h>
|
||||
#include <grub/net/ethernet.h>
|
||||
#include <grub/net/netbuff.h>
|
||||
#include <grub/net/protocol.h>
|
||||
#include <grub/net/ieee1275/interface.h>
|
||||
#include <grub/ieee1275/ieee1275.h>
|
||||
#include <grub/time.h>
|
||||
|
||||
/*send read request*/
|
||||
static grub_err_t
|
||||
send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,struct grub_net_buff *nb)
|
||||
{
|
||||
/*Start TFTP header*/
|
||||
|
||||
struct tftphdr *tftph;
|
||||
char *rrq;
|
||||
int rrqlen;
|
||||
int hdrlen;
|
||||
grub_err_t err;
|
||||
|
||||
if((err = grub_netbuff_push (nb,sizeof(*tftph))) != GRUB_ERR_NONE)
|
||||
return err;
|
||||
|
||||
tftph = (struct tftphdr *) nb->data;
|
||||
|
||||
rrq = (char *) tftph->u.rrq;
|
||||
rrqlen = 0;
|
||||
|
||||
tftph->opcode = TFTP_RRQ;
|
||||
grub_strcpy (rrq,inf->path);
|
||||
rrqlen += grub_strlen (inf->path) + 1;
|
||||
rrq += grub_strlen (inf->path) + 1;
|
||||
/*passar opcoes como parametro ou usar default?*/
|
||||
|
||||
grub_strcpy (rrq,"octet");
|
||||
rrqlen += grub_strlen ("octet") + 1;
|
||||
rrq += grub_strlen ("octet") + 1;
|
||||
|
||||
grub_strcpy (rrq,"blksize");
|
||||
rrqlen += grub_strlen("blksize") + 1;
|
||||
rrq += grub_strlen ("blksize") + 1;
|
||||
|
||||
grub_strcpy (rrq,"1024");
|
||||
rrqlen += grub_strlen ("1024") + 1;
|
||||
rrq += grub_strlen ("1024") + 1;
|
||||
|
||||
grub_strcpy (rrq,"tsize");
|
||||
rrqlen += grub_strlen ("tsize") + 1;
|
||||
rrq += grub_strlen ("tsize") + 1;
|
||||
|
||||
grub_strcpy (rrq,"0");
|
||||
rrqlen += grub_strlen ("0") + 1;
|
||||
rrq += grub_strlen ("0") + 1;
|
||||
hdrlen = sizeof (tftph->opcode) + rrqlen;
|
||||
|
||||
grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen));
|
||||
|
||||
return prot->next->send(inf,prot->next,nb);
|
||||
}
|
||||
|
||||
/*
|
||||
int send_tftp_ack(int block, int port){
|
||||
|
||||
tftp_t pckt;
|
||||
int pcktlen;
|
||||
pckt.opcode = TFTP_ACK;
|
||||
pckt.u.ack.block = block;
|
||||
pcktlen = sizeof (pckt.opcode) + sizeof (pckt.u.ack.block);
|
||||
|
||||
port = 4;
|
||||
return 0;// send_udp_packet (&pckt,pcktlen,TFTP_CLIENT_PORT,port);
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
static struct grub_net_protocol grub_tftp_protocol =
|
||||
{
|
||||
.name = "tftp",
|
||||
.open = send_tftp_rr
|
||||
|
||||
};
|
||||
|
||||
void tftp_ini(void)
|
||||
{
|
||||
grub_protocol_register (&grub_tftp_protocol);
|
||||
}
|
||||
|
||||
void tftp_fini(void)
|
||||
{
|
||||
grub_protocol_unregister (&grub_tftp_protocol);
|
||||
}
|
||||
/*
|
||||
int read_tftp_pckt (grub_uint16_t port, void *buffer, int &buff_len){
|
||||
|
||||
|
||||
read_udp_packet (port,buffer,buff_len);
|
||||
|
||||
|
||||
}*/
|
||||
Reference in new issue
Block a user