small change in the interface structure.

This commit is contained in:
Manoel R. Abranches 2010-04-29 17:56:09 -03:00
parent 066528b4b1
commit 8d402bc9a8
7 changed files with 48 additions and 35 deletions

View file

@ -26,8 +26,22 @@
struct grub_net_card; struct grub_net_card;
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
}protocol_type_t;
struct grub_net_card_driver struct grub_net_card_driver
{ {
grub_err_t (*init) (struct grub_net_card *dev);
grub_err_t (*fini) (struct grub_net_card *dev);
grub_err_t (*send) (struct grub_net_card *dev,struct grub_net_buff *nb); 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); grub_size_t (*recv) (struct grub_net_card *dev,struct grub_net_buff *nb);
}; };

View file

@ -2,16 +2,26 @@
#define GRUB_INTERFACE_HEADER #define GRUB_INTERFACE_HEADER
#include <grub/net.h> #include <grub/net.h>
#include <grub/net/protocol.h> #include <grub/net/protocol.h>
/*
extern struct grub_net_topprotocol; struct grub_net_protstack
{
struct grub_net_protstack *next;
struct grub_net_protocol* prot;
};
struct grub_net_interface struct grub_net_interface
{ {
struct grub_net_card *card; struct grub_net_card *card;
struct grub_net_topprotocol* topprot; struct grub_net_protstack* protstack;
char *path;
char *username;
char *password;
/*transport layer addres*/
struct grub_net_addr *tla; struct grub_net_addr *tla;
/*internet layer addres*/
struct grub_net_addr *ila; struct grub_net_addr *ila;
/*link layer addres*/
struct grub_net_addr *lla; struct grub_net_addr *lla;
}; };
*/
#endif #endif

View file

@ -4,47 +4,32 @@
#include <grub/net/protocol.h> #include <grub/net/protocol.h>
#include <grub/net/netbuff.h> #include <grub/net/netbuff.h>
#include <grub/net.h> #include <grub/net.h>
struct protocol_operations;
struct grub_net_protocol; struct grub_net_protocol;
struct grub_net_interface; struct grub_net_interface;
struct grub_net_protstack;
struct grub_net_protocol struct grub_net_protocol
{ {
struct grub_net_protocol *next; struct grub_net_protocol *next;
char *name; char *name;
grub_err_t (*open) (struct grub_net_interface* inf, grub_err_t (*open) (struct grub_net_interface* inf,
struct grub_net_protocol *prot, struct grub_net_buff *nb); struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*open_confirm) (struct grub_net_interface *inf, grub_err_t (*open_confirm) (struct grub_net_interface *inf,
struct grub_net_protocol *prot, struct grub_net_buff *nb); struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*get_payload) (struct grub_net_interface *inf, grub_err_t (*get_payload) (struct grub_net_interface *inf,
struct grub_net_protocol *prot, struct grub_net_buff *nb); struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf, grub_err_t (*get_payload_confirm) (struct grub_net_interface* inf,
struct grub_net_protocol *prot, struct grub_net_buff *nb); struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*close) (struct grub_net_interface *inf, grub_err_t (*close) (struct grub_net_interface *inf,
struct grub_net_protocol *prot, struct grub_net_buff *nb); struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*send) (struct grub_net_interface *inf , grub_err_t (*send) (struct grub_net_interface *inf ,
struct grub_net_protocol *prot, struct grub_net_buff *nb); struct grub_net_protstack *protstack, struct grub_net_buff *nb);
grub_err_t (*recv) (struct grub_net_interface *inf , grub_err_t (*recv) (struct grub_net_interface *inf ,
struct grub_net_protocol *prot, struct grub_net_buff *nb); struct grub_net_protstack *protstack, struct grub_net_buff *nb);
}; };
typedef struct grub_net_protocol *grub_net_protocol_t; 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_register (grub_net_protocol_t prot);
void grub_protocol_unregister (grub_net_protocol_t prot); void grub_protocol_unregister (grub_net_protocol_t prot);
#endif #endif

View file

@ -6,9 +6,10 @@
#include <grub/net/ieee1275/interface.h> #include <grub/net/ieee1275/interface.h>
#include <grub/net/netbuff.h> #include <grub/net/netbuff.h>
#include <grub/net/protocol.h> #include <grub/net/protocol.h>
#include <grub/net/interface.h>
static grub_err_t static grub_err_t
send_ethernet_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot __attribute__ ((unused)) send_ethernet_packet (struct grub_net_interface *inf,struct grub_net_protstack *protstack __attribute__ ((unused))
,struct grub_net_buff *nb) ,struct grub_net_buff *nb)
{ {

View file

@ -5,6 +5,7 @@
#include <grub/net/ethernet.h> #include <grub/net/ethernet.h>
#include <grub/net/netbuff.h> #include <grub/net/netbuff.h>
#include <grub/net/protocol.h> #include <grub/net/protocol.h>
#include <grub/net/interface.h>
#include <grub/mm.h> #include <grub/mm.h>
struct grub_net_protocol *grub_ipv4_prot; struct grub_net_protocol *grub_ipv4_prot;
@ -28,7 +29,7 @@ ipchksum(void *ipv, int len)
static grub_err_t static grub_err_t
send_ip_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb ) send_ip_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb )
{ {
struct iphdr *iph; struct iphdr *iph;
@ -57,7 +58,7 @@ send_ip_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot,
iph->chksum = ipchksum((void *)nb->head, sizeof(*iph)); iph->chksum = ipchksum((void *)nb->head, sizeof(*iph));
return prot->next->send(inf,prot->next,nb); return protstack->next->prot->send(inf,protstack->next,nb);
} }
static struct grub_net_protocol grub_ipv4_protocol = static struct grub_net_protocol grub_ipv4_protocol =

View file

@ -8,10 +8,11 @@
#include <grub/net/ieee1275/interface.h> #include <grub/net/ieee1275/interface.h>
#include <grub/ieee1275/ieee1275.h> #include <grub/ieee1275/ieee1275.h>
#include <grub/time.h> #include <grub/time.h>
#include <grub/net/interface.h>
/*send read request*/ /*send read request*/
static grub_err_t static grub_err_t
send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,struct grub_net_buff *nb) send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protstack *protstack,struct grub_net_buff *nb)
{ {
/*Start TFTP header*/ /*Start TFTP header*/
@ -58,7 +59,7 @@ send_tftp_rr (struct grub_net_interface *inf, struct grub_net_protocol *prot,str
grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen)); grub_netbuff_unput (nb,nb->tail - (nb->data+hdrlen));
return prot->next->send(inf,prot->next,nb); return protstack->next->prot->send(inf,protstack->next,nb);
} }
/* /*

View file

@ -3,9 +3,10 @@
#include <grub/net/type_net.h> #include <grub/net/type_net.h>
#include <grub/net/netbuff.h> #include <grub/net/netbuff.h>
#include <grub/net/protocol.h> #include <grub/net/protocol.h>
#include <grub/net/interface.h>
/*Assumes that there is allocated memory to the header before the buffer address. */ /*Assumes that there is allocated memory to the header before the buffer address. */
static grub_err_t static grub_err_t
send_udp_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot, struct grub_net_buff *nb) send_udp_packet (struct grub_net_interface *inf, struct grub_net_protstack *protstack, struct grub_net_buff *nb)
{ {
struct udphdr *udph; struct udphdr *udph;
@ -21,7 +22,7 @@ send_udp_packet (struct grub_net_interface *inf, struct grub_net_protocol *prot,
udph->chksum = 0; udph->chksum = 0;
udph->len = sizeof (sizeof (*udph)) + nb->end - nb->head; udph->len = sizeof (sizeof (*udph)) + nb->end - nb->head;
return prot->next->send(inf,prot->next,nb); return protstack->next->prot->send(inf,protstack->next,nb);
} }
static struct grub_net_protocol grub_udp_protocol = static struct grub_net_protocol grub_udp_protocol =