Permalink
Browse files

Files for Appendix A09, https://www.youtube.com/watch?v=EuNJ2q0mqtw

  • Loading branch information...
AlgorithMan-de committed Nov 9, 2016
1 parent c39f930 commit 22bf3f7df7ad8abdb4a49053428f0dd961fffd91
Showing with 57 additions and 18 deletions.
  1. +4 −4 src/drivers/amd_am79c973.cpp
  2. +23 −4 src/kernel.cpp
  3. +30 −10 src/net/tcp.cpp
@@ -173,8 +173,8 @@ void amd_am79c973::Send(uint8_t* buffer, int size)
src >= buffer; src--, dst--)
*dst = *src;
printf("\nSENDING: ");
for(int i = 0; i < (size>64?64:size); i++)
printf("\nSEND: ");
for(int i = 14+20; i < (size>64?64:size); i++)
{
printfHex(buffer[i]);
printf(" ");
@@ -190,7 +190,7 @@ void amd_am79c973::Send(uint8_t* buffer, int size)
void amd_am79c973::Receive()
{
printf("\nRECEIVING: ");
printf("\nRECV: ");
for(; (recvBufferDescr[currentRecvBuffer].flags & 0x80000000) == 0;
currentRecvBuffer = (currentRecvBuffer + 1) % 8)
@@ -205,7 +205,7 @@ void amd_am79c973::Receive()
uint8_t* buffer = (uint8_t*)(recvBufferDescr[currentRecvBuffer].address);
for(int i = 0; i < (size>64?64:size); i++)
for(int i = 14+20; i < (size>64?64:size); i++)
{
printfHex(buffer[i]);
printf(" ");
View
@@ -171,6 +171,26 @@ class PrintfTCPHandler : public TransmissionControlProtocolHandler
printf(foo);
}
if(size > 9
&& data[0] == 'G'
&& data[1] == 'E'
&& data[2] == 'T'
&& data[3] == ' '
&& data[4] == '/'
&& data[5] == ' '
&& data[6] == 'H'
&& data[7] == 'T'
&& data[8] == 'T'
&& data[9] == 'P'
)
{
socket->Send((uint8_t*)"HTTP/1.1 200 OK\r\nServer: MyOS\r\nContent-Type: text/html\r\n\r\n<html><head><title>My Operating System</title></head><body><b>My Operating System</b> http://www.AlgorithMan.de</body></html>\r\n",184);
socket->Disconnect();
}
return true;
}
};
@@ -353,16 +373,15 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
interrupts.Activate();
printf("\n\n\n\n\n\n\n\n\n\n");
printf("\n\n\n\n");
arp.BroadcastMACAddress(gip_be);
tcp.Connect(gip_be, 1234);
PrintfTCPHandler tcphandler;
TransmissionControlProtocolSocket* tcpsocket = tcp.Connect(gip_be, 1234);
TransmissionControlProtocolSocket* tcpsocket = tcp.Listen(1234);
tcp.Bind(tcpsocket, &tcphandler);
tcpsocket->Send((uint8_t*)"Hello TCP!", 10);
//tcpsocket->Send((uint8_t*)"Hello TCP!", 10);
//icmp.RequestEchoReply(gip_be);
View
@@ -45,7 +45,10 @@ bool TransmissionControlProtocolSocket::HandleTransmissionControlProtocolMessage
void TransmissionControlProtocolSocket::Send(uint8_t* data, uint16_t size)
{
backend->Send(this, data, size);
while(state != ESTABLISHED)
{
}
backend->Send(this, data, size, PSH|ACK);
}
void TransmissionControlProtocolSocket::Disconnect()
@@ -78,10 +81,10 @@ TransmissionControlProtocolProvider::~TransmissionControlProtocolProvider()
uint32_t bigEndian32(uint32_t x)
{
return (x & 0xFF000000) >> 24
| (x & 0x00FF0000) >> 8
| (x & 0x0000FF00) << 8
| (x & 0x000000FF) << 24;
return ((x & 0xFF000000) >> 24)
| ((x & 0x00FF0000) >> 8)
| ((x & 0x0000FF00) << 8)
| ((x & 0x000000FF) << 24);
}
@@ -103,7 +106,7 @@ bool TransmissionControlProtocolProvider::OnInternetProtocolReceived(uint32_t sr
if( sockets[i]->localPort == msg->dstPort
&& sockets[i]->localIP == dstIP_BE
&& sockets[i]->state == LISTEN
&& ((msg -> flags) & (SYN | ACK) == SYN))
&& (((msg -> flags) & (SYN | ACK)) == SYN))
socket = sockets[i];
else if( sockets[i]->localPort == msg->dstPort
&& sockets[i]->localIP == dstIP_BE
@@ -198,7 +201,7 @@ bool TransmissionControlProtocolProvider::OnInternetProtocolReceived(uint32_t sr
else if(socket->state == CLOSE_WAIT)
{
socket->state = CLOSED;
return false;
break;
}
if(msg->flags == ACK)
@@ -214,7 +217,11 @@ bool TransmissionControlProtocolProvider::OnInternetProtocolReceived(uint32_t sr
size - msg->headerSize32*4));
if(!reset)
{
socket->acknowledgementNumber += size-msg->headerSize32*4;
int x = 0;
for(int i = msg->headerSize32*4; i < size; i++)
if(internetprotocolPayload[i] != 0)
x = i;
socket->acknowledgementNumber += x - msg->headerSize32*4 + 1;
Send(socket, 0,0, ACK);
}
}
@@ -230,8 +237,21 @@ bool TransmissionControlProtocolProvider::OnInternetProtocolReceived(uint32_t sr
if(reset)
{
return true;
if(socket != 0)
{
Send(socket, 0,0, RST);
}
else
{
TransmissionControlProtocolSocket socket(this);
socket.remotePort = msg->srcPort;
socket.remoteIP = srcIP_BE;
socket.localPort = msg->dstPort;
socket.localIP = dstIP_BE;
socket.sequenceNumber = bigEndian32(msg->acknowledgementNumber);
socket.acknowledgementNumber = bigEndian32(msg->sequenceNumber) + 1;
Send(&socket, 0,0, RST);
}
}

0 comments on commit 22bf3f7

Please sign in to comment.