metalsvm/kernel/shell.c

77 lines
1.6 KiB
C
Raw Normal View History

2011-07-12 14:39:23 +02:00
#include "shell.h"
#include "server.h"
#include "client.h"
2011-07-12 15:04:43 +02:00
#include <metalsvm/time.h>
2011-07-12 14:39:23 +02:00
static Server srv;
static int emac_id = -1;
static Client cli;
2011-07-12 15:15:55 +02:00
static int iamsrv = 0;
#include <metalsvm/stdio.h>
void shelldebugprintf(char* x,...)
{
2011-07-12 15:18:34 +02:00
kprintf("debugprinting");
2011-07-12 15:15:55 +02:00
if (iamsrv)
srv_sendBuffer(&srv,emac_id,x,strlen(x));
else
2011-07-12 15:16:37 +02:00
cli_sendBuffer(&cli,x,strlen(x));
2011-07-12 15:15:55 +02:00
}
2011-07-12 14:39:23 +02:00
void shell_on_connect(ServerEventArgs* e)
{
if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr > 0xC0A80031 || srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr < 0xC0A80001)
2011-07-12 15:21:15 +02:00
{
2011-07-12 14:39:23 +02:00
emac_id = e->ClientID;
2011-07-12 15:21:15 +02:00
kprintf("bmc connected");
}
2011-07-12 14:39:23 +02:00
kprintf("link engaged\n");
}
void shell_on_disconnect(ServerEventArgs* e)
{
2011-07-12 15:04:24 +02:00
kprintf("connection lost from %s:%d",inet_ntoa(srv.ConnectionsAddr[e->ClientID].sin_addr),ntohs(srv.ConnectionsAddr[e->ClientID].sin_port));
2011-07-12 14:39:23 +02:00
}
void shell_on_read(ServerEventArgs* e)
{
if (emac_id != -1 && e->ClientID != emac_id)
srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen);
// else commandos oder so
}
void shell_init(int srv_or_cli)
{
2011-07-12 15:01:10 +02:00
if (!srv_or_cli)
2011-07-12 14:39:23 +02:00
{
2011-07-12 15:15:55 +02:00
iamsrv = 1;
2011-07-12 15:07:09 +02:00
kprintf("server init");
2011-07-12 15:21:15 +02:00
server_init(&srv,23,49);
2011-07-12 14:39:23 +02:00
srv._OnConnect = shell_on_connect;
srv._OnDisconnect = shell_on_disconnect;
srv._OnRead = shell_on_read;
}
else
{
2011-07-12 15:07:09 +02:00
sleep(3);
kprintf("client init");
2011-07-12 14:39:23 +02:00
cli_init(&cli);
2011-07-12 15:21:15 +02:00
while (cli_ConnectTo(&cli,"192.168.0.1",23,0));
2011-07-12 14:39:23 +02:00
sleep(1);
2011-07-12 15:09:48 +02:00
sleep(5);
2011-07-12 15:16:23 +02:00
shelldebugprintf("sleeped 5 seconds\n");
2011-07-12 15:09:48 +02:00
sleep(5);
2011-07-12 15:16:54 +02:00
shelldebugprintf("sleeped another 5 seconds\n");
2011-07-12 14:39:23 +02:00
}
}