Permalink
Browse files

Files for Appendix A07 and A08, https://www.youtube.com/watch?v=j5Hum…

  • Loading branch information...
AlgorithMan-de committed Nov 9, 2016
1 parent c07440b commit c39f930e6a20379692f33d80059e6a3f2ae9db0c
Showing with 244 additions and 43 deletions.
  1. +25 −7 include/net/tcp.h
  2. +1 −0 makefile
  3. +33 −4 src/kernel.cpp
  4. +185 −32 src/net/tcp.cpp
View
@@ -2,6 +2,11 @@
#define __MYOS__NET__TCP_H
#include <common/types.h>
#include <net/ipv4.h>
#include <memorymanagement.h>
namespace myos
{
namespace net
@@ -22,8 +27,8 @@ namespace myos
CLOSING,
TIME_WAIT,
CLOSE_WAIT,
LAST_ACK,
CLOSE_WAIT
//LAST_ACK
};
enum TransmissionControlProtocolFlag
@@ -47,16 +52,26 @@ namespace myos
common::uint32_t sequenceNumber;
common::uint32_t acknowledgementNumber;
common::uint8_t reserved : 4;
common::uint8_t headerSize32 : 4;
common::uint8_t reserved : 3;
common::uint16_t flags : 9;
common::uint8_t flags;
common::uint16_t windowSize;
common::uint16_t checksum;
common::uint16_t urgentPtr;
common::uint32_t options;
} __attribute__((packed));
struct TransmissionControlProtocolPseudoHeader
{
common::uint32_t srcIP;
common::uint32_t dstIP;
common::uint16_t protocol;
common::uint16_t totalLength;
} __attribute__((packed));
class TransmissionControlProtocolSocket;
class TransmissionControlProtocolProvider;
@@ -68,7 +83,7 @@ namespace myos
public:
TransmissionControlProtocolHandler();
~TransmissionControlProtocolHandler();
virtual void HandleTransmissionControlProtocolMessage(TransmissionControlProtocolSocket* socket, common::uint8_t* data, common::uint16_t size);
virtual bool HandleTransmissionControlProtocolMessage(TransmissionControlProtocolSocket* socket, common::uint8_t* data, common::uint16_t size);
};
@@ -82,14 +97,16 @@ namespace myos
common::uint16_t localPort;
common::uint32_t localIP;
common::uint32_t sequenceNumber;
common::uint32_t acknowledgementNumber;
TransmissionControlProtocolProvider* backend;
TransmissionControlProtocolHandler* handler;
TransmissionControlProtocolSocketState state;
public:
TransmissionControlProtocolSocket(TransmissionControlProtocolProvider* backend);
~TransmissionControlProtocolSocket();
virtual void HandleTransmissionControlProtocolMessage(common::uint8_t* data, common::uint16_t size);
virtual bool HandleTransmissionControlProtocolMessage(common::uint8_t* data, common::uint16_t size);
virtual void Send(common::uint8_t* data, common::uint16_t size);
virtual void Disconnect();
};
@@ -111,7 +128,8 @@ namespace myos
virtual TransmissionControlProtocolSocket* Connect(common::uint32_t ip, common::uint16_t port);
virtual void Disconnect(TransmissionControlProtocolSocket* socket);
virtual void Send(TransmissionControlProtocolSocket* socket, common::uint8_t* data, common::uint16_t size);
virtual void Send(TransmissionControlProtocolSocket* socket, common::uint8_t* data, common::uint16_t size,
common::uint16_t flags = 0);
virtual TransmissionControlProtocolSocket* Listen(common::uint16_t port);
virtual void Bind(TransmissionControlProtocolSocket* socket, TransmissionControlProtocolHandler* handler);
View
@@ -29,6 +29,7 @@ objects = obj/loader.o \
obj/net/ipv4.o \
obj/net/icmp.o \
obj/net/udp.o \
obj/net/tcp.o \
obj/kernel.o
View
@@ -20,6 +20,8 @@
#include <net/ipv4.h>
#include <net/icmp.h>
#include <net/udp.h>
#include <net/tcp.h>
// #define GRAPHICSMODE
@@ -157,6 +159,23 @@ class PrintfUDPHandler : public UserDatagramProtocolHandler
};
class PrintfTCPHandler : public TransmissionControlProtocolHandler
{
public:
bool HandleTransmissionControlProtocolMessage(TransmissionControlProtocolSocket* socket, common::uint8_t* data, common::uint16_t size)
{
char* foo = " ";
for(int i = 0; i < size; i++)
{
foo[0] = data[i];
printf(foo);
}
return true;
}
};
void sysprintf(char* str)
{
asm("int $0x80" : : "a" (4), "b" (str));
@@ -329,22 +348,32 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
InternetProtocolProvider ipv4(&etherframe, &arp, gip_be, subnet_be);
InternetControlMessageProtocol icmp(&ipv4);
UserDatagramProtocolProvider udp(&ipv4);
TransmissionControlProtocolProvider tcp(&ipv4);
interrupts.Activate();
printf("\n\n\n\n\n\n\n\n\n\n");
arp.BroadcastMACAddress(gip_be);
icmp.RequestEchoReply(gip_be);
PrintfUDPHandler udphandler;
tcp.Connect(gip_be, 1234);
PrintfTCPHandler tcphandler;
TransmissionControlProtocolSocket* tcpsocket = tcp.Connect(gip_be, 1234);
tcp.Bind(tcpsocket, &tcphandler);
tcpsocket->Send((uint8_t*)"Hello TCP!", 10);
//icmp.RequestEchoReply(gip_be);
//PrintfUDPHandler udphandler;
//UserDatagramProtocolSocket* udpsocket = udp.Connect(gip_be, 1234);
//udp.Bind(udpsocket, &udphandler);
//udpsocket->Send((uint8_t*)"Hello UDP!", 10);
UserDatagramProtocolSocket* udpsocket = udp.Listen(1234);
udp.Bind(udpsocket, &udphandler);
//UserDatagramProtocolSocket* udpsocket = udp.Listen(1234);
//udp.Bind(udpsocket, &udphandler);
while(1)
Oops, something went wrong.

0 comments on commit c39f930

Please sign in to comment.