#include <chan.h>
#include <stddef.h>
#include <par.h>
// Stack includes
#include "stack.h"
/*
** Called by stack to post informative and
** error messages to application.
*/
void slog(char *text)
{
char *type[] = {"INFO ", "ERROR", "DEBUG", "PANIC"};
par_printf("LOG %s: %s",type[text[1]-'0'], text);
}
/*
** Called by stack if important change of stack
** status occures. Most offen change is Link
** status change. It indicates if the cable is
** plugged and speed of link.
*/
void supdate(struct stackStatus *s)
{
char *LinkStr[] = {
"No Link",
"10Mb/s Half Duplex",
"10Mb/s Full Duplex",
"100Mb/s Half Duplex",
"100Mb/s Full Duplex",
"1000Mb/s Full Duplex"
};
par_printf(
"statUpdate:\n"
"Link status: %s (%d)\n"
"Stack status: %d\n",
LinkStr[s->linkStatus],
s->linkStatus,
s->stackStatus
);
}
const char MACADDRESS[] = {00, 01, 02, 03, 04, 05};
// Define my IP address, netmask and gateway if necessary
char myIP[] = "192.168.1.5";
char netmask[] = "255.255.255.0";
char gateway[] = "192.168.1.1";
main(int argc, char *argv[], char *envp[], CHAN *in_ports[], int ins, CHAN *out_ports[], int outs)
{
struct stack_cfg scfg;
// Attach EMAC device to stack
eth_emac_attach(1, MACADDRESS);
// Callback functions configuration
scfg.log = slog;
scfg.statusUpdate = supdate;
// Init TCP/IP stack
init_stack(&scfg);
// Set IP address of ethernet interface (le0)
UpdateIP("le0", myIP, netmask);
// Add static record to routing table
add_route("0.0.0.0", gateway, "0.0.0.0", RTF_GATEWAY | RTF_STATIC | RTF_UP);
}
|