[06295a9] | 1 | /*
|
---|
[b4edc96] | 2 | * Copyright (c) 2021 Jiri Svoboda
|
---|
[06295a9] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[1493811] | 29 | /** @addtogroup ethip
|
---|
[06295a9] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * @brief
|
---|
| 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef ETHIP_H_
|
---|
| 38 | #define ETHIP_H_
|
---|
| 39 |
|
---|
[1493811] | 40 | #include <adt/list.h>
|
---|
| 41 | #include <async.h>
|
---|
[02a09ed] | 42 | #include <inet/addr.h>
|
---|
[b4edc96] | 43 | #include <inet/eth_addr.h>
|
---|
| 44 | #include <inet/iplink_srv.h>
|
---|
[1493811] | 45 | #include <loc.h>
|
---|
[8d2dd7f2] | 46 | #include <stddef.h>
|
---|
| 47 | #include <stdint.h>
|
---|
[1493811] | 48 |
|
---|
[56792a2] | 49 | typedef struct {
|
---|
[65f991e] | 50 | link_t link;
|
---|
[02a09ed] | 51 | inet_addr_t addr;
|
---|
[56792a2] | 52 | } ethip_link_addr_t;
|
---|
| 53 |
|
---|
[06295a9] | 54 | typedef struct ethip_nic {
|
---|
[65f991e] | 55 | link_t link;
|
---|
[06295a9] | 56 | service_id_t svc_id;
|
---|
| 57 | char *svc_name;
|
---|
| 58 | async_sess_t *sess;
|
---|
| 59 |
|
---|
| 60 | iplink_srv_t iplink;
|
---|
[bc38578] | 61 | service_id_t iplink_sid;
|
---|
[962f03b] | 62 |
|
---|
[56792a2] | 63 | /** MAC address */
|
---|
[b4edc96] | 64 | eth_addr_t mac_addr;
|
---|
[a35b458] | 65 |
|
---|
[65f991e] | 66 | /**
|
---|
| 67 | * List of IP addresses configured on this link
|
---|
| 68 | * (of the type ethip_link_addr_t)
|
---|
| 69 | */
|
---|
| 70 | list_t addr_list;
|
---|
[06295a9] | 71 | } ethip_nic_t;
|
---|
| 72 |
|
---|
[1493811] | 73 | /** Ethernet frame */
|
---|
| 74 | typedef struct {
|
---|
| 75 | /** Destination Address */
|
---|
[b4edc96] | 76 | eth_addr_t dest;
|
---|
[1493811] | 77 | /** Source Address */
|
---|
[b4edc96] | 78 | eth_addr_t src;
|
---|
[1493811] | 79 | /** Ethertype or Length */
|
---|
| 80 | uint16_t etype_len;
|
---|
| 81 | /** Payload */
|
---|
| 82 | void *data;
|
---|
| 83 | /** Payload size */
|
---|
| 84 | size_t size;
|
---|
| 85 | } eth_frame_t;
|
---|
| 86 |
|
---|
[87e5658c] | 87 | /** ARP opcode */
|
---|
| 88 | typedef enum {
|
---|
| 89 | /** Request */
|
---|
| 90 | aop_request,
|
---|
| 91 | /** Reply */
|
---|
| 92 | aop_reply
|
---|
| 93 | } arp_opcode_t;
|
---|
| 94 |
|
---|
| 95 | /** ARP packet (for 48-bit MAC addresses and IPv4)
|
---|
| 96 | *
|
---|
| 97 | * Internal representation
|
---|
| 98 | */
|
---|
| 99 | typedef struct {
|
---|
| 100 | /** Opcode */
|
---|
| 101 | arp_opcode_t opcode;
|
---|
| 102 | /** Sender hardware address */
|
---|
[b4edc96] | 103 | eth_addr_t sender_hw_addr;
|
---|
[87e5658c] | 104 | /** Sender protocol address */
|
---|
[d8b47eca] | 105 | addr32_t sender_proto_addr;
|
---|
[87e5658c] | 106 | /** Target hardware address */
|
---|
[b4edc96] | 107 | eth_addr_t target_hw_addr;
|
---|
[87e5658c] | 108 | /** Target protocol address */
|
---|
[d8b47eca] | 109 | addr32_t target_proto_addr;
|
---|
[87e5658c] | 110 | } arp_eth_packet_t;
|
---|
| 111 |
|
---|
[f9d3dd4] | 112 | /** Address translation table element */
|
---|
| 113 | typedef struct {
|
---|
| 114 | link_t atrans_list;
|
---|
[d8b47eca] | 115 | addr32_t ip_addr;
|
---|
[b4edc96] | 116 | eth_addr_t mac_addr;
|
---|
[f9d3dd4] | 117 | } ethip_atrans_t;
|
---|
| 118 |
|
---|
[b7fd2a0] | 119 | extern errno_t ethip_iplink_init(ethip_nic_t *);
|
---|
| 120 | extern errno_t ethip_received(iplink_srv_t *, void *, size_t);
|
---|
[1493811] | 121 |
|
---|
[06295a9] | 122 | #endif
|
---|
| 123 |
|
---|
| 124 | /** @}
|
---|
| 125 | */
|
---|