|
| 1 | +/* |
| 2 | + * Copyright (C) 2014 Martin Lenders |
| 3 | + * |
| 4 | + * This file is subject to the terms and conditions of the GNU Lesser General |
| 5 | + * Public License. See the file LICENSE in the top level directory for more |
| 6 | + * details. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * @defgroup uart_net UART transceiver |
| 11 | + * @ingroup net |
| 12 | + * @{ |
| 13 | + * |
| 14 | + * @file uart_net.h |
| 15 | + * @brief Provides a transceiver over the UART interface. Use |
| 16 | + * `dist/tools/linux-border_router` to border route the packets |
| 17 | + * on a Linux machine |
| 18 | + * |
| 19 | + * @author Martine Lenders <[email protected]> |
| 20 | + * |
| 21 | + * @} |
| 22 | + */ |
| 23 | + |
| 24 | +#ifndef __UART_NET_H_ |
| 25 | +#define __UART_NET_H_ |
| 26 | + |
| 27 | +#include <stdint.h> |
| 28 | + |
| 29 | +#include "periph/uart.h" |
| 30 | +#include "basic_net.h" |
| 31 | + |
| 32 | +#include "ipv6.h" |
| 33 | + |
| 34 | +#if !UART_NUMOF |
| 35 | +/** |
| 36 | + * @brief Guard type in the case that the board does not implement the new |
| 37 | + * driver model |
| 38 | + */ |
| 39 | +typedef uint8_t uart_t; |
| 40 | +#endif |
| 41 | + |
| 42 | +/** |
| 43 | + * @brief Type to define packet type. |
| 44 | + */ |
| 45 | +typedef uint8_t uart_net_packet_type_t; |
| 46 | + |
| 47 | +#define UART_NET_PACKET_RAW_TYPE (0) /**< Raw packet type */ |
| 48 | +#define UART_NET_PACKET_CONF_TYPE (2) /**< configuration packet type */ |
| 49 | +#define UART_NET_PACKET_L3_TYPE (3) /**< Layer 3 packet type */ |
| 50 | + |
| 51 | +/** |
| 52 | + * @brief Type to define configuration type |
| 53 | + */ |
| 54 | +typedef uint8_t uart_net_conf_type_byte_t; |
| 55 | + |
| 56 | +/** |
| 57 | + * @brief A 6LoWPAN header compression context. |
| 58 | + * @see <a href="http://tools.ietf.org/html/rfc6775#section-7.2"> |
| 59 | + * RFC 6775, section 7.2 |
| 60 | + * </a> |
| 61 | + * @see <a href="http://tools.ietf.org/html/rfc6282#section-3.1.2"> |
| 62 | + * RFC 6282, section 3.1.2 |
| 63 | + * </a> |
| 64 | + */ |
| 65 | +struct { |
| 66 | + uint16_t version; /**< version of the context */ |
| 67 | + uint8_t cid; /**< context identifier */ |
| 68 | + ipv6_addr_t prefix; /**< prefix associated to CID */ |
| 69 | + uint8_t length; /**< length of the prefix */ |
| 70 | + uint8_t comp; /**< compression flag */ |
| 71 | + uint16_t lifetime; /**< lifetime of validity */ |
| 72 | +} uart_net_6lp_context_t; |
| 73 | + |
| 74 | +/** |
| 75 | + * @brief Type to configure a 6LoWPAN context |
| 76 | + * @see @ref sixlowpan |
| 77 | + */ |
| 78 | +#define UART_NET_CONF_BYTE_6LP_CONTEXT (2) |
| 79 | +#define UART_NET_CONF_BYTE_IPV6_ADDR (3) /**< Type to set IPv6 address */ |
| 80 | + |
| 81 | +/** |
| 82 | + * @brief Basic packet type definition |
| 83 | + */ |
| 84 | +typedef struct __attribute__((packet)) { |
| 85 | + uint8_t null; /**< Marker. Must always be 0 to deferentiate |
| 86 | + between `uart_net` packets and normal |
| 87 | + stdout. */ |
| 88 | + uart_net_packet_type_t type; /**< Type of the packet */ |
| 89 | + uint8_t seq_num; /**< Sequence number of the packet */ |
| 90 | +} uart_net_packet_t; |
| 91 | + |
| 92 | +/** |
| 93 | + * @brief Layer 3 packet type definition |
| 94 | + * @extends uart_net_packet_t |
| 95 | + */ |
| 96 | +typedef struct __attribute__((packet)) { |
| 97 | + uint8_t null; /**< Marker. Must always be 0 to deferentiate |
| 98 | + between `uart_net` packets and normal |
| 99 | + stdout. */ |
| 100 | + uart_net_packet_type_t type; /**< Type of the packet */ |
| 101 | + uint8_t seq_num; /**< Sequence number of the packet */ |
| 102 | + |
| 103 | + /** |
| 104 | + * @brief Type of the layer 3 packet, identified by EtherType |
| 105 | + * @see <a href="http://standards.ieee.org/develop/regauth/ethertype/eth.txt"> |
| 106 | + * IEEE public EtherTypes |
| 107 | + * </a> |
| 108 | + */ |
| 109 | + uint16_t eth; |
| 110 | +} uart_net_l3_t; |
| 111 | + |
| 112 | +/** |
| 113 | + * @brief Configuration packet type definition |
| 114 | + * @extends uart_net_packet_t |
| 115 | + */ |
| 116 | +typedef struct __attribute__((packed)) { |
| 117 | + uint8_t null; /**< Marker. Must always be 0 to deferentiate |
| 118 | + between `uart_net` packets and normal |
| 119 | + stdout. */ |
| 120 | + uart_net_packet_type_t type; /**< Type of the packet */ |
| 121 | + uint8_t seq_num; /**< Sequence number of the packet */ |
| 122 | + uart_net_conf_type_byte_t conf_type; /**< Configuration type. */ |
| 123 | +} uart_net_conf_t; |
| 124 | + |
| 125 | +/** |
| 126 | + * @brief Configuration packet type for 6LoWPAN context |
| 127 | + * @extends uart_net_conf_t |
| 128 | + */ |
| 129 | +typedef struct __attribute__((packet)) { |
| 130 | + uint8_t null; /**< Marker. Must always be 0 to deferentiate |
| 131 | + between `uart_net` packets and normal |
| 132 | + stdout. */ |
| 133 | + uart_net_packet_type_t type; /**< Type of the packet */ |
| 134 | + uint8_t seq_num; /**< Sequence number of the packet */ |
| 135 | + uart_net_conf_type_byte_t conf_type; /**< Configuration type. */ |
| 136 | + uart_net_conf_6lc_t context; /**< The context. */ |
| 137 | +} uart_net_conf_6lc_t; |
| 138 | + |
| 139 | +/** |
| 140 | + * @brief Configuration packet type for IPv6 address |
| 141 | + * @extends uart_net_conf_t |
| 142 | + */ |
| 143 | +typedef struct __attribute__((packet)) |
| 144 | +{ |
| 145 | + uint8_t null; /**< Marker. Must always be 0 to deferentiate |
| 146 | + between `uart_net` packets and normal |
| 147 | + stdout. */ |
| 148 | + uart_net_packet_type_t type; /**< Type of the packet */ |
| 149 | + uint8_t seq_num; /**< Sequence number of the packet */ |
| 150 | + uart_net_conf_type_t conf_type; /**< Configuration type. */ |
| 151 | + ipv6_addr_t addr; /**< The IPv6 address */ |
| 152 | +} uart_net_conf_ipv6_t; |
| 153 | + |
| 154 | +/** |
| 155 | + * Initializes a new @ref uart_net control thread for UART device *uart*. If |
| 156 | + * the board does not support the uart_t type it falls back to using |
| 157 | + * board_uart0.h |
| 158 | + * |
| 159 | + * @param[in] uart The UART device, ignored if UART_NUMOF == 0 or not defined |
| 160 | + * |
| 161 | + * @return The PID of the @ref uart_net control thread |
| 162 | + */ |
| 163 | +kernel_pid_t uart_net_init(uart_t uart); |
| 164 | + |
| 165 | +/** |
| 166 | + * @brief Send a layer 3 packet over the UART device |
| 167 | + * |
| 168 | + * @param[in] pid The PID for the @ref uart_net control thread |
| 169 | + * @param[in] upper_layer_hdrs All upper layer headers including layer 3. |
| 170 | + * @param[in] data Data (*without* all upper layer headers) to send |
| 171 | + * over the UART device |
| 172 | + */ |
| 173 | +static inline int uart_net_send_l3_packet(kernel_pid_t pid, |
| 174 | + net_dev_hlist_t *upper_layer_hdrs, |
| 175 | + void *data, size_t data_len) |
| 176 | +{ |
| 177 | + return basic_net_send_data2(pid, upper_layer_hdrs, NULL, 0, data, data_len); |
| 178 | +} |
| 179 | + |
| 180 | +#endif /* __UART_NET_H_ */ |
0 commit comments