Commit 6f7961f0 authored by Alessandro Rubini's avatar Alessandro Rubini

arch-bare-linux: make it compile (but not link, yet)

This fixes the "ppi->ch.fd" using the two descriptors
in the new net_path structure. It also istantiates a static
net_patch to avoid malloc in the freestanding environment.

The program is not linking because some functions called by
the protocol are still missing in this architecture.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 66d77e01
......@@ -4,17 +4,18 @@
/* Socket interface for bare Linux */
#include <pproto/pproto.h>
#include <pproto/diag.h>
#include "bare-linux.h"
/* Receive and send is trivial */
/* FIXME: which socket we receive and send with? */
int bare_recv_packet(struct pp_instance *ppi, void *pkt, int len)
{
return sys_recv(ppi->ch.fd, pkt, len, 0);
return sys_recv(ppi->net_path->gen_ch.fd, pkt, len, 0);
}
int bare_send_packet(struct pp_instance *ppi, void *pkt, int len)
{
return sys_send(ppi->ch.fd, pkt, len, 0);
return sys_send(ppi->net_path->gen_ch.fd, pkt, len, 0);
}
int pp_recv_packet(struct pp_instance *ppi, void *pkt, int len)
......@@ -52,7 +53,8 @@ int bare_open_ch(struct pp_instance *ppi, char *ifname)
pp_diag_error(ppi, bare_errno);
pp_diag_fatal(ppi, "ioctl(GIFHWADDR)", "");
}
memcpy(ppi->ch.addr, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
memcpy(ppi->net_path->gen_ch.addr, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
memcpy(ppi->net_path->evt_ch.addr, ifr.ifr_ifru.ifru_hwaddr.sa_data, 6);
/* bind and setsockopt */
memset(&addr, 0, sizeof(addr));
......@@ -64,6 +66,7 @@ int bare_open_ch(struct pp_instance *ppi, char *ifname)
pp_diag_fatal(ppi, "bind", "");
}
ppi->ch.fd = sock;
ppi->net_path->gen_ch.fd = sock;
ppi->net_path->evt_ch.fd = sock;
return 0;
}
......@@ -7,6 +7,7 @@
* It must also clear the BSS as I'm too lazy to do that in asm
*/
#include <pproto/pproto.h>
#include <pproto/diag.h>
#include "bare-linux.h"
extern int __bss_start, __bss_end;
......@@ -20,6 +21,7 @@ void pproto_clear_bss(void)
}
static struct pp_instance ppi_static;
static struct pp_net_path net_path_static;
void pproto_main(void)
{
......@@ -27,6 +29,7 @@ void pproto_main(void)
pp_puts("bare: starting. Compiled on " __DATE__ "\n");
ppi->net_path = &net_path_static;
if (bare_open_ch(ppi, "eth0")) {
pp_diag_error(ppi, bare_errno);
pp_diag_fatal(ppi, "open_ch", "");
......
......@@ -30,7 +30,7 @@ void bare_main_loop(struct pp_instance *ppi)
delay_ms = pp_state_machine(ppi, NULL, 0);
while (1) {
bare_fd_set set;
int i;
int i, maxfd;
struct bare_timeval tv;
unsigned char packet[1500];
......@@ -40,8 +40,13 @@ void bare_main_loop(struct pp_instance *ppi)
again:
FD_ZERO(&set);
FD_SET(ppi->ch.fd, &set);
i = sys_select(ppi->ch.fd + 1, &set, NULL, NULL, &tv);
FD_SET(ppi->net_path->gen_ch.fd, &set);
FD_SET(ppi->net_path->evt_ch.fd, &set);
maxfd = ppi->net_path->gen_ch.fd;
if (ppi->net_path->evt_ch.fd > maxfd)
maxfd = ppi->net_path->evt_ch.fd;
i = sys_select(maxfd + 1, &set, NULL, NULL, &tv);
if (i < 0 && bare_errno != 4 /* EINTR */)
sys_exit(__LINE__);
if (i < 0)
......@@ -54,14 +59,12 @@ void bare_main_loop(struct pp_instance *ppi)
/*
* We got a packet. If it's not ours, continue consuming
* the pending timeout
* the pending timeout.
*
* FIXME: we don't know which socket to receive from
*/
i = bare_recv_packet(ppi, packet, sizeof(packet));
/* FIXME
if (i < sizeof(struct pp_packet))
goto again;
*/
/* Warning: PP_PROTO_NR is endian-agnostic by design */
/* FIXME: PP_PROTO_NR is a legacy number */
if ( ((struct bare_ethhdr *)packet)->h_proto
!= htons(PP_PROTO_NR))
goto again;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment