Brandon Kim | dab96f1 | 2021-02-18 11:21:37 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 Google LLC |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
William A. Kennington III | 7d6fa42 | 2021-02-08 17:04:02 -0800 | [diff] [blame] | 17 | #ifndef PLATFORMS_NEMORA_PORTABLE_NET_TYPES_H_ |
| 18 | #define PLATFORMS_NEMORA_PORTABLE_NET_TYPES_H_ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | // Buffer big enough for largest frame we expect |
| 23 | // to receive from EMAC (in bytes) |
| 24 | // 1500 (max payload IEEE 802.3) + |
| 25 | // 14 (header) + |
| 26 | // 4 (crc, if not stripped by EMAC) + |
| 27 | // 4 (optional VLAN tag, if not stripped by EMAC) |
| 28 | #define ETH_BUFFER_SIZE 1522 |
| 29 | #define IPV4_ETHERTYPE 0x0800 |
| 30 | #define IPV6_ADDR_SIZE 16 |
| 31 | #define MAC_ADDR_SIZE 6 |
| 32 | |
| 33 | #ifndef __packed |
| 34 | #define __packed __attribute__((packed)) |
| 35 | #endif |
| 36 | |
| 37 | /* MAC address */ |
| 38 | typedef struct __packed { |
| 39 | uint8_t octet[MAC_ADDR_SIZE]; // network order |
| 40 | } mac_addr_t; |
| 41 | |
| 42 | /* |
| 43 | * Ethernet header. |
| 44 | * Note: This assumes a packet without VLAN tags. |
| 45 | * TODO: configure HW to strip VLAN field. |
| 46 | */ |
| 47 | typedef struct __packed { |
| 48 | mac_addr_t dest; |
| 49 | mac_addr_t src; |
| 50 | uint16_t ethertype; |
| 51 | } eth_hdr_t; |
| 52 | |
| 53 | #endif // PLATFORMS_NEMORA_PORTABLE_NET_TYPES_H_ |