Initial Implementation of TFTP protocol and new protocol structs.
This commit is contained in:
parent
4931b0984b
commit
066528b4b1
23 changed files with 789 additions and 6 deletions
|
@ -22,15 +22,20 @@
|
|||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/list.h>
|
||||
#include <grub/net/netbuff.h>
|
||||
|
||||
struct grub_net_card;
|
||||
|
||||
struct grub_net_card_driver
|
||||
{
|
||||
grub_err_t (*send) (struct grub_net_card *dev, void *buf,
|
||||
grub_size_t buflen);
|
||||
grub_size_t (*recv) (struct grub_net_card *dev, void *buf,
|
||||
grub_size_t buflen);
|
||||
grub_err_t (*send) (struct grub_net_card *dev,struct grub_net_buff *nb);
|
||||
grub_size_t (*recv) (struct grub_net_card *dev,struct grub_net_buff *nb);
|
||||
};
|
||||
|
||||
struct grub_net_addr
|
||||
{
|
||||
grub_uint8_t *addr;
|
||||
grub_size_t len;
|
||||
};
|
||||
|
||||
struct grub_net_card
|
||||
|
@ -38,6 +43,12 @@ struct grub_net_card
|
|||
struct grub_net_card *next;
|
||||
char *name;
|
||||
struct grub_net_card_driver *driver;
|
||||
/*transport layer address*/
|
||||
struct grub_net_addr *tla;
|
||||
/*internet layer address*/
|
||||
struct grub_net_addr *ila;
|
||||
/*link layer address*/
|
||||
struct grub_net_addr *lla;
|
||||
void *data;
|
||||
};
|
||||
|
||||
|
|
23
include/grub/net/arp.h
Normal file
23
include/grub/net/arp.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef GRUB_NET_ARP_HEADER
|
||||
#define GRUB_NET_ARP_HEADER 1
|
||||
|
||||
#include <grub/net/ethernet.h>
|
||||
struct arprequest {
|
||||
grub_int16_t hwtype; /* hardware type (must be ARPHRD_ETHER) */
|
||||
grub_int16_t protocol; /* protocol type (must be ETH_P_IP) */
|
||||
grub_int8_t hwlen; /* hardware address length (must be 6) */
|
||||
grub_int8_t protolen; /* protocol address length (must be 4) */
|
||||
grub_uint16_t opcode; /* ARP opcode */
|
||||
grub_uint8_t shwaddr[6]; /* sender's hardware address */
|
||||
grub_uint32_t sipaddr; /* sender's IP address */
|
||||
grub_uint8_t thwaddr[6]; /* target's hardware address */
|
||||
grub_uint32_t tipaddr; /* target's IP address */
|
||||
}__attribute__ ((packed));
|
||||
|
||||
|
||||
struct arp_pkt{
|
||||
struct etherhdr ether;
|
||||
struct arprequest arpr;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#endif
|
7
include/grub/net/device.h
Normal file
7
include/grub/net/device.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
struct grub_net_card
|
||||
{
|
||||
struct grub_net_card *next;
|
||||
char *name;
|
||||
struct grub_net_card_driver *driver;
|
||||
void *data;
|
||||
};
|
12
include/grub/net/ethernet.h
Normal file
12
include/grub/net/ethernet.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef GRUB_NET_ETHERNET_HEADER
|
||||
#define GRUB_NET_ETHERNET_HEADER 1
|
||||
#include <grub/misc.h>
|
||||
struct etherhdr {
|
||||
grub_uint8_t dst[6];
|
||||
grub_uint8_t src[6];
|
||||
grub_uint16_t type;
|
||||
} __attribute__ ((packed)) ;
|
||||
|
||||
void ethernet_ini(void);
|
||||
void ethernet_fini(void);
|
||||
#endif
|
21
include/grub/net/ieee1275/interface.h
Normal file
21
include/grub/net/ieee1275/interface.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef GRUB_IEEE1275_INTERFACE_HEADER
|
||||
#define GRUB_IEEE1275_INTERFACE_HEADER 1
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/ieee1275/ieee1275.h>
|
||||
#include <grub/ieee1275/ofnet.h>
|
||||
|
||||
grub_ofnet_t EXPORT_VAR(grub_net);
|
||||
|
||||
grub_bootp_t EXPORT_VAR(bootp_pckt);
|
||||
grub_uint32_t get_server_ip(void);
|
||||
grub_uint32_t get_client_ip(void);
|
||||
grub_uint8_t* get_server_mac (void);
|
||||
grub_uint8_t* get_client_mac (void);
|
||||
|
||||
int send_card_buffer (void *buffer,int buff_len);
|
||||
int get_card_buffer (void *buffer,int buff_len);
|
||||
int card_open (void);
|
||||
int card_close (void);
|
||||
|
||||
#endif
|
17
include/grub/net/interface.h
Normal file
17
include/grub/net/interface.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef GRUB_INTERFACE_HEADER
|
||||
#define GRUB_INTERFACE_HEADER
|
||||
#include <grub/net.h>
|
||||
#include <grub/net/protocol.h>
|
||||
/*
|
||||
extern struct grub_net_topprotocol;
|
||||
|
||||
struct grub_net_interface
|
||||
{
|
||||
struct grub_net_card *card;
|
||||
struct grub_net_topprotocol* topprot;
|
||||
struct grub_net_addr *tla;
|
||||
struct grub_net_addr *ila;
|
||||
struct grub_net_addr *lla;
|
||||
};
|
||||
*/
|
||||
#endif
|
25
include/grub/net/ip.h
Normal file
25
include/grub/net/ip.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef GRUB_NET_IP_HEADER
|
||||
#define GRUB_NET_IP_HEADER 1
|
||||
#include <grub/misc.h>
|
||||
|
||||
|
||||
struct iphdr {
|
||||
grub_uint8_t verhdrlen;
|
||||
grub_uint8_t service;
|
||||
grub_uint16_t len;
|
||||
grub_uint16_t ident;
|
||||
grub_uint16_t frags;
|
||||
grub_uint8_t ttl;
|
||||
grub_uint8_t protocol;
|
||||
grub_uint16_t chksum;
|
||||
grub_uint32_t src;
|
||||
grub_uint32_t dest;
|
||||
} __attribute__ ((packed)) ;
|
||||
|
||||
#define IP_UDP 17 /* UDP protocol */
|
||||
#define IP_BROADCAST 0xFFFFFFFF
|
||||
|
||||
grub_uint16_t ipchksum(void *ipv, int len);
|
||||
void ipv4_ini(void);
|
||||
void ipv4_fini(void);
|
||||
#endif
|
27
include/grub/net/netbuff.h
Normal file
27
include/grub/net/netbuff.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
#ifndef GRUB_NETBUFF_HEADER
|
||||
#define GRUB_NETBUFF_HEADER
|
||||
|
||||
#include <grub/misc.h>
|
||||
|
||||
#define NETBUFF_ALIGN 2048
|
||||
#define NETBUFFMINLEN 64
|
||||
|
||||
struct grub_net_buff
|
||||
{
|
||||
/*Pointer to the start of the buffer*/
|
||||
char *head;
|
||||
/*Pointer to the data */
|
||||
char *data;
|
||||
/*Pointer to the tail */
|
||||
char *tail;
|
||||
/*Pointer to the end of the buffer*/
|
||||
char *end;
|
||||
};
|
||||
|
||||
grub_err_t grub_netbuff_put (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_unput (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_push (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_pull (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
grub_err_t grub_netbuff_reserve (struct grub_net_buff *net_buff ,grub_size_t len);
|
||||
struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len );
|
||||
#endif
|
50
include/grub/net/protocol.h
Normal file
50
include/grub/net/protocol.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef GRUB_PROTOCOL_HEADER
|
||||
#define GRUB_PROTOCOL_HEADER
|
||||
#include <grub/err.h>
|
||||
#include <grub/net/protocol.h>
|
||||
#include <grub/net/netbuff.h>
|
||||
#include <grub/net.h>
|
||||
struct protocol_operations;
|
||||
struct grub_net_protocol;
|
||||
struct grub_net_interface;
|
||||
|
||||
struct grub_net_protocol
|
||||
{
|
||||
struct grub_net_protocol *next;
|
||||
char *name;
|
||||
grub_err_t (*open) (struct grub_net_interface* inf,
|
||||
struct grub_net_protocol *prot, struct grub_net_buff *nb);
|
||||
grub_err_t (*open_confirm) (struct grub_net_interface *inf,
|
||||
struct grub_net_protocol *prot, struct grub_net_buff *nb);
|
||||
grub_err_t (*get_payload) (struct grub_net_interface *inf,
|
||||
struct grub_net_protocol *prot, struct grub_net_buff *nb);
|
||||
grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf,
|
||||
struct grub_net_protocol *prot, struct grub_net_buff *nb);
|
||||
grub_err_t (*close) (struct grub_net_interface *inf,
|
||||
struct grub_net_protocol *prot, struct grub_net_buff *nb);
|
||||
grub_err_t (*send) (struct grub_net_interface *inf ,
|
||||
struct grub_net_protocol *prot, struct grub_net_buff *nb);
|
||||
grub_err_t (*recv) (struct grub_net_interface *inf ,
|
||||
struct grub_net_protocol *prot, struct grub_net_buff *nb);
|
||||
};
|
||||
|
||||
typedef struct grub_net_protocol *grub_net_protocol_t;
|
||||
|
||||
struct grub_net_interface
|
||||
{
|
||||
struct grub_net_card *card;
|
||||
struct grub_net_protocol* prot;
|
||||
char *path;
|
||||
char *username;
|
||||
char *password;
|
||||
/*transport layer addres*/
|
||||
struct grub_net_addr *tla;
|
||||
/*internet layer addres*/
|
||||
struct grub_net_addr *ila;
|
||||
/*link layer addres*/
|
||||
struct grub_net_addr *lla;
|
||||
};
|
||||
|
||||
void grub_protocol_register (grub_net_protocol_t prot);
|
||||
void grub_protocol_unregister (grub_net_protocol_t prot);
|
||||
#endif
|
74
include/grub/net/tftp.h
Normal file
74
include/grub/net/tftp.h
Normal file
|
@ -0,0 +1,74 @@
|
|||
#ifndef GRUB_NET_TFTP_HEADER
|
||||
#define GRUB_NET_TFTP_HEADER 1
|
||||
|
||||
#include <grub/misc.h>
|
||||
#include <grub/net/ethernet.h>
|
||||
#include <grub/net/udp.h>
|
||||
|
||||
/* IP port for the MTFTP server used for Intel's PXE */
|
||||
#define MTFTP_SERVER_PORT 75
|
||||
#define MTFTP_CLIENT_PORT 76
|
||||
|
||||
#define TFTP_DEFAULTSIZE_PACKET 512
|
||||
#define TFTP_MAX_PACKET 1432
|
||||
|
||||
/* IP port for the TFTP server */
|
||||
#define TFTP_SERVER_PORT 69
|
||||
#define TFTP_CLIENT_PORT 2000
|
||||
|
||||
|
||||
/* We define these based on what's in arpa/tftp.h. We just like our
|
||||
* names better, cause they're clearer */
|
||||
#define TFTP_RRQ 1
|
||||
#define TFTP_WRQ 2
|
||||
#define TFTP_DATA 3
|
||||
#define TFTP_ACK 4
|
||||
#define TFTP_ERROR 5
|
||||
#define TFTP_OACK 6
|
||||
|
||||
#define TFTP_CODE_EOF 1
|
||||
#define TFTP_CODE_MORE 2
|
||||
#define TFTP_CODE_ERROR 3
|
||||
#define TFTP_CODE_BOOT 4
|
||||
#define TFTP_CODE_CFG 5
|
||||
|
||||
#define TFTP_EUNDEF 0 /* not defined */
|
||||
#define TFTP_ENOTFOUND 1 /* file not found */
|
||||
#define TFTP_EACCESS 2 /* access violation */
|
||||
#define TFTP_ENOSPACE 3 /* disk full or allocation exceeded */
|
||||
#define TFTP_EBADOP 4 /* illegal TFTP operation */
|
||||
#define TFTP_EBADID 5 /* unknown transfer ID */
|
||||
#define TFTP_EEXISTS 6 /* file already exists */
|
||||
#define TFTP_ENOUSER 7 /* no such user */
|
||||
#define TFTP_DEFAULT_FILENAME "kernel"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* * own here because this is cleaner, and maps to the same data layout.
|
||||
* */
|
||||
struct tftphdr {
|
||||
grub_uint16_t opcode;
|
||||
union {
|
||||
grub_int8_t rrq[TFTP_DEFAULTSIZE_PACKET];
|
||||
struct {
|
||||
grub_uint16_t block;
|
||||
grub_int8_t download[TFTP_MAX_PACKET];
|
||||
} data;
|
||||
struct {
|
||||
grub_uint16_t block;
|
||||
} ack;
|
||||
struct {
|
||||
grub_uint16_t errcode;
|
||||
grub_int8_t errmsg[TFTP_DEFAULTSIZE_PACKET];
|
||||
} err;
|
||||
struct {
|
||||
grub_int8_t data[TFTP_DEFAULTSIZE_PACKET+2];
|
||||
} oack;
|
||||
} u;
|
||||
} __attribute__ ((packed)) ;
|
||||
|
||||
void tftp_ini(void);
|
||||
void tftp_fini(void);
|
||||
#endif
|
7
include/grub/net/type_net.h
Normal file
7
include/grub/net/type_net.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef GRUB_TYPES_NET_HEADER
|
||||
#define GRUB_TYPES_NET_HEADER 1
|
||||
|
||||
#define UDP_PCKT 0x11
|
||||
#define IP_PCKT 0x0800
|
||||
|
||||
#endif
|
22
include/grub/net/udp.h
Normal file
22
include/grub/net/udp.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef GRUB_NET_UDP_HEADER
|
||||
#define GRUB_NET_UDP_HEADER 1
|
||||
#include <grub/misc.h>
|
||||
/*
|
||||
typedef enum
|
||||
{
|
||||
GRUB_PROT_TFTP
|
||||
} protocol_type;
|
||||
*/
|
||||
|
||||
#define GRUB_PROT_TFTP 1
|
||||
|
||||
struct udphdr {
|
||||
grub_uint16_t src;
|
||||
grub_uint16_t dst;
|
||||
grub_uint16_t len;
|
||||
grub_uint16_t chksum;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
void udp_ini(void);
|
||||
void udp_fini(void);
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue