aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/usrp3/include/u3_net_stack.h
blob: cbf714e204ef0e56bad69851764001cc45d0a3c9 (plain)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright 2012-2013 Ettus Research LLC

#ifndef INCLUDED_U3_NET_STACK_H
#define INCLUDED_U3_NET_STACK_H

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <wb_pkt_iface64.h>

//----------------------------------------------------------------------

#include <lwip/ip_addr.h>
#include <lwip/ip.h>
#include <lwip/udp.h>
#include <lwip/icmp.h>
#include <if_arp.h>
#include <ethertype.h>

typedef struct
{
    uint8_t addr[6];
} eth_mac_addr_t;

typedef struct
{
    uint8_t ethno;
    uint8_t pad[5];
    eth_mac_addr_t dst;
    eth_mac_addr_t src;
    uint16_t ethertype;
} padded_eth_hdr_t;

//------------------ init stuff ------------------------------------

void u3_net_stack_init(wb_pkt_iface64_config_t *config);

void u3_net_stack_init_eth(const uint8_t ethno, const eth_mac_addr_t *mac, const struct ip_addr *ip, const struct ip_addr *subnet);

const struct ip_addr *u3_net_stack_get_ip_addr(const uint8_t ethno);

const struct ip_addr *u3_net_stack_get_subnet(const uint8_t ethno);

const struct ip_addr *u3_net_stack_get_bcast(const uint8_t ethno);

const eth_mac_addr_t *u3_net_stack_get_mac_addr(const uint8_t ethno);

uint32_t u3_net_stack_get_stat_counts(const uint8_t ethno);

//------------------ udp handling ------------------------------------

typedef void (*u3_net_stack_udp_handler_t)(
    const uint8_t,
    const struct ip_addr *, const struct ip_addr *,
    const uint16_t, const uint16_t,
    const void *, const size_t
);

void u3_net_stack_register_udp_handler(
    const uint16_t port,
    const u3_net_stack_udp_handler_t handler
);

void u3_net_stack_send_udp_pkt(
    const uint8_t ethno,
    const struct ip_addr *dst,
    const uint16_t src_port,
    const uint16_t dst_port,
    const void *buff,
    const size_t num_bytes
);

//------------------ icmp handling ------------------------------------

typedef void (*u3_net_stack_icmp_handler_t)(
    const uint8_t,
    const struct ip_addr *, const struct ip_addr *,
    const uint16_t, const uint16_t,
    const void *, const size_t
);

void u3_net_stack_register_icmp_handler(
    const uint8_t type,
    const uint8_t code,
    const u3_net_stack_icmp_handler_t handler
);

void u3_net_stack_send_icmp_pkt(
    const uint8_t ethno,
    const uint8_t type,
    const uint8_t code,
    const uint16_t id,
    const uint16_t seq,
    const struct ip_addr *dst,
    const void *buff,
    const size_t num_bytes
);

//------------------ entry point ------------------------------------

void u3_net_stack_handle_one(void);

//------------------ arp handling ------------------------------------

void u3_net_stack_send_arp_request(const uint8_t ethno, const struct ip_addr *addr);

//commented out to make private - do we need cache update outside this module?
//void u3_net_stack_arp_cache_update(const struct ip_addr *ip_addr, const eth_mac_addr_t *mac_addr, const uint8_t ethno);

const eth_mac_addr_t *u3_net_stack_arp_cache_lookup(const struct ip_addr *ip_addr);

#endif /* INCLUDED_U3_NET_STACK_H */