-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
phys_gen_ppp.h
65 lines (45 loc) · 2.4 KB
/
phys_gen_ppp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// (C) 2022-2023 by folkert van heusden <[email protected]>, released under Apache License v2.0
#pragma once
#include <atomic>
#include <string>
#include <termios.h>
#include <thread>
#include "any_addr.h"
#include "network_layer.h"
#include "phys.h"
#include "stats.h"
any_addr gen_opponent_mac(const any_addr & my_mac);
std::vector<uint8_t> unwrap_ppp_frame(const std::vector<uint8_t> & payload, const std::vector<uint8_t> & ACCM);
class phys_gen_ppp : public phys
{
protected:
bool protocol_compression { false };
bool ac_field_compression { false };
bool lcp_options_acked { false };
bool ipcp_options_acked { false };
bool ipv6cp_options_acked { false };
uint32_t magic { 0x1234abcd };
std::vector<uint8_t> ACCM_tx;
std::vector<uint8_t> ACCM_rx;
const any_addr opponent_address;
uint16_t fcstab[256] { 0 };
void handle_lcp(const std::vector<uint8_t> & data);
void handle_ccp(const std::vector<uint8_t> & data);
void handle_ipcp(const std::vector<uint8_t> & data);
void handle_ipv6cp(const std::vector<uint8_t> & data);
void send_Xcp(const uint8_t code, const uint8_t identifier, const uint16_t protocol, const std::vector<uint8_t> & data);
void send_rej(const uint16_t protocol, const uint8_t identifier, const std::vector<uint8_t> & options);
void send_ack(const uint16_t protocol, const uint8_t identifier, const std::vector<uint8_t> & options);
void send_nak(const uint16_t protocol, const uint8_t identifier, const std::vector<uint8_t> & options);
std::vector<uint8_t> wrap_in_ppp_frame(const std::vector<uint8_t> & payload, const uint16_t protocol, const std::vector<uint8_t> & ACCM, const bool not_ppp_meta);
void process_incoming_packet(std::vector<uint8_t> packet_buffer, const struct timespec & ts);
virtual bool transmit_low(const std::vector<uint8_t> & payload, const uint16_t protocol, const std::vector<uint8_t> & ACCM, const bool not_ppp_meta) = 0;
public:
phys_gen_ppp(const size_t dev_index, stats *const s, const std::string & name, const any_addr & my_mac, const any_addr & opponent_address, router *const r);
phys_gen_ppp(const phys_gen_ppp &) = delete;
virtual ~phys_gen_ppp();
void start() override;
bool transmit_packet(const any_addr & dest_mac, const any_addr & src_mac, const uint16_t ether_type, const uint8_t *payload, const size_t pl_size) override;
any_addr::addr_family get_phys_type() override { return any_addr::mac; }
virtual void operator()() override = 0;
};