76 lines
1.8 KiB
C
76 lines
1.8 KiB
C
#include "shell.h"
|
|
|
|
#include "server.h"
|
|
#include "client.h"
|
|
|
|
#include <metalsvm/time.h>
|
|
|
|
static Server srv;
|
|
static int emac_id = -1;
|
|
|
|
static Client cli;
|
|
|
|
static int iamsrv = 0;
|
|
|
|
char shellbuffer[512];
|
|
|
|
|
|
void shelldebugprint(char* x)
|
|
{
|
|
kprintf("debugprinting : %s",x);
|
|
if (iamsrv)
|
|
srv_sendBuffer(&srv,emac_id,x,strlen(x));
|
|
else
|
|
cli_sendBuffer(&cli,x,strlen(x));
|
|
}
|
|
|
|
void shell_on_connect(ServerEventArgs* e)
|
|
{
|
|
kprintf("connection from %s:%d",inet_ntoa(srv.ConnectionsAddr[e->ClientID].sin_addr),ntohs(srv.ConnectionsAddr[e->ClientID].sin_port));
|
|
kprintf("connehx: 0x%.8X",srv.ConnectionsAddr[e->ClientID].sin_addr);
|
|
// if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr > 0xC0A80031 || srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr < 0xC0A80001)
|
|
if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr == 0xFE04A8C0)
|
|
{
|
|
emac_id = e->ClientID;
|
|
kprintf("bmc connected");
|
|
}
|
|
else
|
|
kprintf("link engaged\n");
|
|
}
|
|
|
|
void shell_on_disconnect(ServerEventArgs* e)
|
|
{
|
|
kprintf("connection lost from %s:%d",inet_ntoa(srv.ConnectionsAddr[e->ClientID].sin_addr),ntohs(srv.ConnectionsAddr[e->ClientID].sin_port));
|
|
}
|
|
|
|
void shell_on_read(ServerEventArgs* e)
|
|
{
|
|
if (emac_id != -1 && e->ClientID != emac_id)
|
|
srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen);
|
|
else
|
|
// else commandos oder so
|
|
srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen);
|
|
}
|
|
|
|
void shell_init(int srv_or_cli)
|
|
{
|
|
if (!srv_or_cli)
|
|
{
|
|
iamsrv = 1;
|
|
kprintf("server init");
|
|
server_init(&srv,23,49);
|
|
srv._OnConnect = shell_on_connect;
|
|
srv._OnDisconnect = shell_on_disconnect;
|
|
srv._OnRead = shell_on_read;
|
|
}
|
|
else
|
|
{
|
|
sleep(3);
|
|
kprintf("client init");
|
|
cli_init(&cli);
|
|
while (cli_ConnectTo(&cli,"192.168.0.1",23,0));
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|