Commit bed94236 authored by Martin Vítek's avatar Martin Vítek

Changed assembly_request to handle whole packet

parent 9a9153a2
......@@ -48,9 +48,15 @@ bool ARP_class::search(const uint8_t (&IP)[4], uint8_t (&MAC)[6])
return false;
}
void ARP_class::assembly_request(const uint8_t (&IP)[4], uint8_t* payload)
void ARP_class::assembly_request(const uint8_t (&IP)[4], ethernet_frame& frame)
{
arp_packet* arp = (arp_packet*)payload;
arp_packet* arp = (arp_packet*)frame.payload.data;
memcpy(frame.dest_address, broadcast_mac, 6);
memcpy(frame.src_address, my_mac, 6);
frame.type_length = __htons(ARP);
frame.payload.length = sizeof(arp_packet);
arp->hw_type = __htons(ETHERNET);
arp->protocol_type = __htons(IPV4);
......@@ -60,11 +66,16 @@ void ARP_class::assembly_request(const uint8_t (&IP)[4], uint8_t* payload)
uint8_t myIP[4] = {192, 168, 1, 2};
//My MAC
memcpy(arp->MAC_sender, my_mac, 6);
memset(arp->MAC_target, 0, 6);
//memcpy(arp->IP_sender, my_IP, 4);
//memset(arp->IP_sender, 0, 4);
//My IP (it can be 0.0.0.0 if IP address is not assigned yet)
memcpy(arp->IP_sender, myIP, 4);
//Target MAC in question -> 00:00:00:00:00:00
memset(arp->MAC_target, 0, 6);
//Target IP
memcpy(arp->IP_target, IP, 4);
}
......
......@@ -2,6 +2,8 @@
#include <cstdint>
#include "ethernet_frame.h"
struct arp_cache_item
{
uint8_t MAC[6];
......@@ -69,6 +71,9 @@ class ARP_class
void save(const uint8_t (&IP)[4], const uint8_t (&MAC)[6]);
bool get(const uint8_t (&IP)[4], uint8_t (&MAC)[6]);
bool search(const uint8_t (&IP)[4], uint8_t (&MAC)[6]);
void assembly_request(const uint8_t (&IP)[4], uint8_t* payload);
void assembly_request(const uint8_t (&IP)[4], ethernet_frame& frame);
void assembly_reply(const uint8_t (&IP)[4], uint8_t* payload); //TODO: ARP reply
bool decode(uint8_t* payload);
};
......@@ -78,10 +78,6 @@ int main(void)
nixie.print_eeprom();
nixie.get_mac();
uart.send("ARP frame: ");
uart.send_dec(sizeof(arp_packet));
uart.send_new_line();
uint8_t i = 0;
time_t old = 0;
bool up = true;
......@@ -90,14 +86,9 @@ int main(void)
uint8_t pc_mac[6] = {0x00, 0x30, 0x4f, 0x08, 0x35, 0x9c};
ethernet_frame arp_frame;
memcpy(arp_frame.src_address, my_mac, 6);
memcpy(arp_frame.dest_address, broadcast_mac, 6);
arp_frame.type_length = __htons(ARP);
ARP_class arp(my_mac);
arp.assembly_request({192, 168, 1, 1}, arp_frame.payload.data);
arp_frame.payload.length = 28;
arp.assembly_request({192, 168, 1, 1}, arp_frame);
debug.frame(arp_frame);
......
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