Add interface struct for communication between protocols and protocols stack.

Changed the protocols structs to use one struct for each layer.
This commit is contained in:
Manoel R. Abranches 2010-06-21 19:05:14 -03:00
parent 8d402bc9a8
commit d17a9fea4a
8 changed files with 194 additions and 68 deletions

View file

@ -2,7 +2,7 @@
#define GRUB_NET_ARP_HEADER 1
#include <grub/net/ethernet.h>
struct arprequest {
struct arphdr{
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) */
@ -14,10 +14,4 @@ struct arprequest {
grub_uint32_t tipaddr; /* target's IP address */
}__attribute__ ((packed));
struct arp_pkt{
struct etherhdr ether;
struct arprequest arpr;
} __attribute__ ((packed));
#endif

View file

@ -4,17 +4,15 @@
#include <grub/misc.h>
#include <grub/ieee1275/ieee1275.h>
#include <grub/ieee1275/ofnet.h>
#include <grub/net/netbuff.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);
grub_ofnet_t grub_net;
int send_card_buffer (void *buffer,int buff_len);
int get_card_buffer (void *buffer,int buff_len);
grub_bootp_t bootp_pckt;
int send_card_buffer (struct grub_net_buff *pack);
int get_card_packet (struct grub_net_buff *pack);
int card_open (void);
int card_close (void);

View file

@ -1,27 +1,70 @@
#ifndef GRUB_INTERFACE_HEADER
#define GRUB_INTERFACE_HEADER
#include <grub/net.h>
#include <grub/net/protocol.h>
//#include <grub/net.h>
#include <grub/net/type_net.h>
#include <grub/list.h>
#include <grub/misc.h>
struct grub_net_protstack
struct grub_net_protocol_stack
{
struct grub_net_protstack *next;
struct grub_net_protocol* prot;
struct grub_net_protocol_stack *next;
char *name;
grub_net_protocol_id_t id;
void *interface;
};
struct grub_net_interface
struct grub_net_application_transport_interface
{
struct grub_net_card *card;
struct grub_net_protstack* protstack;
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;
struct grub_net_transport_network_interface *inner_layer;
void *data;
struct grub_net_application_layer_protocol *app_prot;
struct grub_net_transport_layer_protocol *trans_prot;
};
struct grub_net_transport_network_interface
{
struct grub_net_network_link_interface *inner_layer;
void *data;
struct grub_net_transport_layer_protocol *trans_prot;
struct grub_net_network_layer_protocol *net_prot;
};
struct grub_net_network_link_interface
{
void *data;
struct grub_net_network_layer_protocol *net_prot;
struct grub_net_link_layer_protocol *link_prot;
};
extern struct grub_net_protocol_stack *grub_net_protocol_stacks;
static inline void
grub_net_stack_register (struct grub_net_protocol_stack *stack)
{
grub_list_push (GRUB_AS_LIST_P (&grub_net_protocol_stacks),
GRUB_AS_LIST (stack));
}
/*
void grub_net_stack_unregister (struct grub_net_protocol_stack *stack)
{
grub_list_remove (GRUB_AS_LIST_P (&grub_net_protocol_stacks),
GRUB_AS_LIST (stack));
}*/
struct grub_net_protocol_stack *grub_net_protocol_stack_get (char *name);
/*
static inline void
grub_net_interface_application_transport_register (struct grub_net_application_transport_interface);
static inline void
grub_net_interface_application_transport_unregister (struct grub_net_application_transport_interface);
static inline void
grub_net_interface_transport_network_register (struct grub_net_transport_network_interface);
static inline void
grub_net_interface_transport_network_unregister (struct grub_net_transport_network_interface);
static inline void
grub_net_interface_network_link_register (struct grub_net_network_link_interface);
static inline void
grub_net_interface_network_link_unregister (struct grub_net_network_link_interface);*/
#endif

View file

@ -23,5 +23,8 @@ 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);
grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff);
struct grub_net_buff * grub_netbuff_alloc ( grub_size_t len );
grub_err_t grub_netbuff_free (struct grub_net_buff *net_buff);
grub_err_t grub_netbuff_clear (struct grub_net_buff *net_buff);
#endif

View file

@ -1,35 +1,101 @@
#ifndef GRUB_PROTOCOL_HEADER
#define GRUB_PROTOCOL_HEADER
#include <grub/err.h>
#include <grub/net/protocol.h>
#include <grub/net/interface.h>
#include <grub/net/netbuff.h>
#include <grub/net.h>
#include <grub/net/type_net.h>
struct grub_net_protocol;
struct grub_net_interface;
struct grub_net_protstack;
struct grub_net_protocol_stack;
struct grub_net_network_layer_interface;
struct grub_net_protocol
typedef enum grub_network_layer_protocol_id
{
struct grub_net_protocol *next;
GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4
} grub_network_layer_protocol_id_t;
struct grub_net_application_layer_protocol
{
struct grub_net_application_layer_protocol *next;
char *name;
grub_err_t (*open) (struct grub_net_interface* inf,
struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*open_confirm) (struct grub_net_interface *inf,
struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*get_payload) (struct grub_net_interface *inf,
struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf,
struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*close) (struct grub_net_interface *inf,
struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*send) (struct grub_net_interface *inf ,
struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*recv) (struct grub_net_interface *inf ,
struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_net_protocol_id_t id;
int (*get_file_size) (struct grub_net_network_layer_interface* inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename);
grub_err_t (*open) (struct grub_net_network_layer_interface* inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb,char *filename);
grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
grub_err_t (*send) (struct grub_net_network_layer_interface *inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
grub_err_t (*recv) (struct grub_net_network_layer_interface *inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
grub_err_t (*close) (struct grub_net_network_layer_interface *inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
};
struct grub_net_transport_layer_protocol
{
struct grub_net_transport_layer_protocol *next;
char *name;
grub_net_protocol_id_t id;
//grub_transport_layer_protocol_id_t id;
grub_err_t (*open) (struct grub_net_network_layer_interface* inf,
struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb);
grub_err_t (*send_ack) (struct grub_net_network_layer_interface* inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
grub_err_t (*send) (struct grub_net_network_layer_interface *inf,
struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb);
grub_err_t (*recv) (struct grub_net_network_layer_interface *inf,
struct grub_net_application_transport_interface *app_trans_inf, struct grub_net_buff *nb);
grub_err_t (*close) (struct grub_net_network_layer_interface *inf,
struct grub_net_protocol_stack *protocol_stack, struct grub_net_buff *nb);
};
struct grub_net_network_layer_protocol
{
struct grub_net_network_layer_protocol *next;
char *name;
grub_net_protocol_id_t id;
//grub_network_layer_protocol_id_t id;
grub_err_t (*ntoa) (char *name, grub_net_network_layer_address_t *addr);
char * (*aton) (union grub_net_network_layer_address addr);
grub_err_t (*net_ntoa) (char *name,
grub_net_network_layer_netaddress_t *addr);
char * (*net_aton) (grub_net_network_layer_netaddress_t addr);
int (* match_net) (grub_net_network_layer_netaddress_t net,
grub_net_network_layer_address_t addr);
grub_err_t (*send) (struct grub_net_network_layer_interface *inf ,
struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb);
grub_err_t (*recv) (struct grub_net_network_layer_interface *inf ,
struct grub_net_transport_network_interface *trans_net_inf, struct grub_net_buff *nb);
};
struct grub_net_link_layer_protocol
{
struct grub_net_link_layer_protocol *next;
char *name;
grub_net_protocol_id_t id;
grub_err_t (*send) (struct grub_net_network_layer_interface *inf ,
struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb);
grub_err_t (*recv) (struct grub_net_network_layer_interface *inf ,
struct grub_net_network_link_interface *net_link_inf, struct grub_net_buff *nb);
};
extern struct grub_net_network_layer_protocol *grub_net_network_layer_protocols;
typedef struct grub_net_protocol *grub_net_protocol_t;
void grub_protocol_register (grub_net_protocol_t prot);
void grub_protocol_unregister (grub_net_protocol_t prot);
void grub_net_application_layer_protocol_register (struct grub_net_application_layer_protocol *prot);
void grub_net_application_layer_protocol_unregister (struct grub_net_application_layer_protocol *prot);
struct grub_net_application_layer_protocol *grub_net_application_layer_protocol_get (grub_net_protocol_id_t id);
void grub_net_transport_layer_protocol_register (struct grub_net_transport_layer_protocol *prot);
void grub_net_transport_layer_protocol_unregister (struct grub_net_transport_layer_protocol *prot);
struct grub_net_transport_layer_protocol *grub_net_transport_layer_protocol_get (grub_net_protocol_id_t id);
void grub_net_network_layer_protocol_register (struct grub_net_network_layer_protocol *prot);
void grub_net_network_layer_protocol_unregister (struct grub_net_network_layer_protocol *prot);
struct grub_net_network_layer_protocol *grub_net_network_layer_protocol_get (grub_net_protocol_id_t id);
void grub_net_link_layer_protocol_register (struct grub_net_link_layer_protocol *prot);
void grub_net_link_layer_protocol_unregister (struct grub_net_link_layer_protocol *prot);
struct grub_net_link_layer_protocol *grub_net_link_layer_protocol_get (grub_net_protocol_id_t id);
#endif

View file

@ -14,7 +14,7 @@
/* IP port for the TFTP server */
#define TFTP_SERVER_PORT 69
#define TFTP_CLIENT_PORT 2000
#define TFTP_CLIENT_PORT 26300
/* We define these based on what's in arpa/tftp.h. We just like our
@ -42,10 +42,6 @@
#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 {

View file

@ -1,7 +1,32 @@
#ifndef GRUB_TYPES_NET_HEADER
#define GRUB_TYPES_NET_HEADER 1
#include <grub/misc.h>
#define UDP_PCKT 0x11
#define IP_PCKT 0x0800
typedef enum
{
GRUB_NET_TFTP_ID,
GRUB_NET_UDP_ID,
GRUB_NET_IPV4_ID,
GRUB_NET_IPV6_ID,
GRUB_NET_ETHERNET_ID,
GRUB_NET_ARP_ID,
GRUB_NET_DHCP_ID
}grub_net_protocol_id_t;
typedef union grub_net_network_layer_address
{
grub_uint32_t ipv4;
} grub_net_network_layer_netaddress_t;
typedef union grub_net_network_layer_netaddress
{
struct {
grub_uint32_t base;
int masksize;
} ipv4;
} grub_net_network_layer_address_t;
#endif

View file

@ -1,22 +1,23 @@
#ifndef GRUB_NET_UDP_HEADER
#define GRUB_NET_UDP_HEADER 1
#include <grub/misc.h>
/*
typedef enum
struct udphdr
{
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));
struct udp_interf
{
grub_uint16_t src;
grub_uint16_t dst;
};
void udp_ini(void);
void udp_fini(void);
#endif