Commit 0c664b92 authored by Martin Vítek's avatar Martin Vítek

Add some UDP

parent f4990c30
......@@ -3,10 +3,12 @@
#include <cstdint>
#include "ethernet_frame.h"
#include "NetworkTypes.h"
#include "USART.h"
#include "Debug.h"
IP_protocol::IP_protocol()
IP_protocol::IP_protocol(const IP& local_ip): udp(),
local_ip(local_ip)
{
}
......@@ -14,5 +16,23 @@ void IP_protocol::decode(const ethernet_payload& payload)
{
IP_packet* packet = (IP_packet*) payload.data;
debug.ip_packet(packet);
//Trash not IPv4 packets
if (IP(packet->version) != 4) return;
//Trash not mine IP destinations
if (IP(packet->dst_address) != local_ip) return;
switch (packet->protocol)
{
case ICMP:
break;
case TCP:
break;
case UDP: udp.decode(packet->data, packet->tl - (packet->ihl*4));
break;
}
}
......@@ -3,6 +3,8 @@
#include <cstdint>
#include "ethernet_frame.h"
#include "NetworkTypes.h"
#include "UDP_protocol.h"
enum IP_protocols
{
......@@ -45,19 +47,23 @@ struct IP_packet
*/
uint8_t ttl :8;
uint8_t protocol :8;
uint16_t checksum :16;
uint32_t src_address ;
uint32_t dst_address ;
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
uint32_t src_address;
uint32_t dst_address;
uint8_t data[];
};
#pragma pack(pop)
class IP_protocol
{
private:
UDP_protocol udp;
const IP& local_ip;
public:
IP_protocol();
IP_protocol(const IP& local_ip);
void decode(const ethernet_payload& payload);
......
......@@ -24,7 +24,7 @@ NixieStack::NixieStack(ENC28J60& eth): eth(eth),
gateway(0),
link_is_up(false),
arp(mac, ip),
ipv4(),
ipv4(ip),
rx_buffer(),
tx_buffer()
{
......
#include "UDP_protocol.h"
#include "USART.h"
#include "Debug.h"
UDP_protocol::UDP_protocol()
{
}
void UDP_protocol::decode(const uint8_t* data, const uint16_t length)
{
for (uint16_t i=0; i<length; i++)
{
uart.send_hex8(data[i]);
uart.send(' ');
}
uart.send_new_line();
}
#pragma once
#include <cstdint>
struct UDP_packet
{
uint16_t src_port;
uint16_t dst_port;
uint16_t length;
uint16_t checksum;
uint8_t data[];
};
class UDP_protocol
{
public:
UDP_protocol();
void decode(const uint8_t* data, const uint16_t length);
};
......@@ -81,10 +81,10 @@ int main(void)
//Init UART - 500 000baud, 8N1
uart.init();
//nixie.display.init();
//nixie.separator.init();
//boost.init();
boost.disable();
nixie.display.init();
nixie.separator.init();
boost.init();
//boost.disable();
eth.init(MAC({0x54, 0x10, 0xEC, 0x20, 0xE5, 0xBD}));
......
......@@ -256,12 +256,6 @@
<Compile Include="GPIO.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="ICMP_protocol.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="ICMP_protocol.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="IP_protocol.cpp">
<SubType>compile</SubType>
</Compile>
......@@ -319,6 +313,12 @@
<Compile Include="System.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="UDP_protocol.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="UDP_protocol.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="USART.h">
<SubType>compile</SubType>
</Compile>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment