csp_types.h
Go to the documentation of this file.
1 /*
2 Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
3 Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
4 Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
27 #ifndef CSP_TYPES_H_
28 #define CSP_TYPES_H_
29 
30 #include <csp/csp_autoconfig.h>
31 
32 /* Make bool for compilers without stdbool.h */
33 #ifdef CSP_HAVE_STDBOOL_H
34 #include <stdbool.h>
35 #else
36 #define bool int
37 #define false 0
38 #define true !false
39 #endif
40 
46  CSP_CMP = 0,
47  CSP_PING = 1,
48  CSP_PS = 2,
53  CSP_ANY = (CSP_MAX_BIND_PORT + 1),
54  CSP_PROMISC = (CSP_MAX_BIND_PORT + 2)
55 };
56 
57 typedef enum {
62 } csp_prio_t;
63 
64 #define CSP_PRIORITIES (1 << CSP_ID_PRIO_SIZE)
65 
66 #ifdef CSP_USE_QOS
67 #define CSP_RX_QUEUE_LENGTH (CSP_CONN_QUEUE_LENGTH / CSP_PRIORITIES)
68 #define CSP_ROUTE_FIFOS CSP_PRIORITIES
69 #define CSP_RX_QUEUES CSP_PRIORITIES
70 #else
71 #define CSP_RX_QUEUE_LENGTH CSP_CONN_QUEUE_LENGTH
72 #define CSP_ROUTE_FIFOS 1
73 #define CSP_RX_QUEUES 1
74 #endif
75 
77 #define CSP_ID_PRIO_SIZE 2
78 #define CSP_ID_HOST_SIZE 5
79 #define CSP_ID_PORT_SIZE 6
80 #define CSP_ID_FLAGS_SIZE 8
81 
82 #define CSP_HEADER_BITS (CSP_ID_PRIO_SIZE + 2 * CSP_ID_HOST_SIZE + 2 * CSP_ID_PORT_SIZE + CSP_ID_FLAGS_SIZE)
83 #define CSP_HEADER_LENGTH (CSP_HEADER_BITS/8)
84 
85 #if CSP_HEADER_BITS != 32 && __GNUC__
86 #error "Header length must be 32 bits"
87 #endif
88 
90 #define CSP_ID_PRIO_MAX ((1 << (CSP_ID_PRIO_SIZE)) - 1)
91 #define CSP_ID_HOST_MAX ((1 << (CSP_ID_HOST_SIZE)) - 1)
92 #define CSP_ID_PORT_MAX ((1 << (CSP_ID_PORT_SIZE)) - 1)
93 #define CSP_ID_FLAGS_MAX ((1 << (CSP_ID_FLAGS_SIZE)) - 1)
94 
96 #define CSP_ID_PRIO_MASK ((uint32_t) CSP_ID_PRIO_MAX << (CSP_ID_FLAGS_SIZE + 2 * CSP_ID_PORT_SIZE + 2 * CSP_ID_HOST_SIZE))
97 #define CSP_ID_SRC_MASK ((uint32_t) CSP_ID_HOST_MAX << (CSP_ID_FLAGS_SIZE + 2 * CSP_ID_PORT_SIZE + 1 * CSP_ID_HOST_SIZE))
98 #define CSP_ID_DST_MASK ((uint32_t) CSP_ID_HOST_MAX << (CSP_ID_FLAGS_SIZE + 2 * CSP_ID_PORT_SIZE))
99 #define CSP_ID_DPORT_MASK ((uint32_t) CSP_ID_PORT_MAX << (CSP_ID_FLAGS_SIZE + 1 * CSP_ID_PORT_SIZE))
100 #define CSP_ID_SPORT_MASK ((uint32_t) CSP_ID_PORT_MAX << (CSP_ID_FLAGS_SIZE))
101 #define CSP_ID_FLAGS_MASK ((uint32_t) CSP_ID_FLAGS_MAX << (0))
102 
103 #define CSP_ID_CONN_MASK (CSP_ID_SRC_MASK | CSP_ID_DST_MASK | CSP_ID_DPORT_MASK | CSP_ID_SPORT_MASK)
104 
106 typedef union {
107  uint32_t ext;
108  struct __attribute__((__packed__)) {
109 #if defined(CSP_BIG_ENDIAN) && !defined(CSP_LITTLE_ENDIAN)
110  unsigned int pri : CSP_ID_PRIO_SIZE;
111  unsigned int src : CSP_ID_HOST_SIZE;
112  unsigned int dst : CSP_ID_HOST_SIZE;
113  unsigned int dport : CSP_ID_PORT_SIZE;
114  unsigned int sport : CSP_ID_PORT_SIZE;
115  unsigned int flags : CSP_ID_FLAGS_SIZE;
116 #elif defined(CSP_LITTLE_ENDIAN) && !defined(CSP_BIG_ENDIAN)
117  unsigned int flags : CSP_ID_FLAGS_SIZE;
118  unsigned int sport : CSP_ID_PORT_SIZE;
119  unsigned int dport : CSP_ID_PORT_SIZE;
120  unsigned int dst : CSP_ID_HOST_SIZE;
121  unsigned int src : CSP_ID_HOST_SIZE;
122  unsigned int pri : CSP_ID_PRIO_SIZE;
123 #else
124  #error "Must define one of CSP_BIG_ENDIAN or CSP_LITTLE_ENDIAN in csp_platform.h"
125 #endif
126  };
127 } csp_id_t;
128 
130 #define CSP_BROADCAST_ADDR CSP_ID_HOST_MAX
131 
133 #define CSP_DEFAULT_ROUTE (CSP_ID_HOST_MAX + 1)
134 
136 #define CSP_FRES1 0x80 // Reserved for future use
137 #define CSP_FRES2 0x40 // Reserved for future use
138 #define CSP_FRES3 0x20 // Reserved for future use
139 #define CSP_FFRAG 0x10 // Use fragmentation
140 #define CSP_FHMAC 0x08 // Use HMAC verification
141 #define CSP_FXTEA 0x04 // Use XTEA encryption
142 #define CSP_FRDP 0x02 // Use RDP protocol
143 #define CSP_FCRC32 0x01 // Use CRC32 checksum
144 
146 #define CSP_SO_NONE 0x0000 // No socket options
147 #define CSP_SO_RDPREQ 0x0001 // Require RDP
148 #define CSP_SO_RDPPROHIB 0x0002 // Prohibit RDP
149 #define CSP_SO_HMACREQ 0x0004 // Require HMAC
150 #define CSP_SO_HMACPROHIB 0x0008 // Prohibit HMAC
151 #define CSP_SO_XTEAREQ 0x0010 // Require XTEA
152 #define CSP_SO_XTEAPROHIB 0x0020 // Prohibit HMAC
153 #define CSP_SO_CRC32REQ 0x0040 // Require CRC32
154 #define CSP_SO_CRC32PROHIB 0x0080 // Prohibit CRC32
155 #define CSP_SO_CONN_LESS 0x0100 // Enable Connection Less mode
156 
158 #define CSP_O_NONE CSP_SO_NONE // No connection options
159 #define CSP_O_RDP CSP_SO_RDPREQ // Enable RDP
160 #define CSP_O_NORDP CSP_SO_RDPPROHIB // Disable RDP
161 #define CSP_O_HMAC CSP_SO_HMACREQ // Enable HMAC
162 #define CSP_O_NOHMAC CSP_SO_HMACPROHIB // Disable HMAC
163 #define CSP_O_XTEA CSP_SO_XTEAREQ // Enable XTEA
164 #define CSP_O_NOXTEA CSP_SO_XTEAPROHIB // Disable XTEA
165 #define CSP_O_CRC32 CSP_SO_CRC32REQ // Enable CRC32
166 #define CSP_O_NOCRC32 CSP_SO_CRC32PROHIB // Disable CRC32
167 
174 typedef struct __attribute__((__packed__)) {
175  uint8_t padding[CSP_PADDING_BYTES];
176  uint16_t length;
178  union {
179  uint8_t data[0];
180  uint16_t data16[0];
181  uint32_t data32[0];
182  };
183 } csp_packet_t;
184 
186 struct csp_iface_s;
187 typedef int (*nexthop_t)(struct csp_iface_s * interface, csp_packet_t *packet, uint32_t timeout);
188 
190 typedef struct csp_iface_s {
191  const char *name;
192  void * driver;
194  uint16_t mtu;
196  uint32_t tx;
197  uint32_t rx;
198  uint32_t tx_error;
199  uint32_t rx_error;
200  uint32_t drop;
201  uint32_t autherr;
202  uint32_t frame;
203  uint32_t txbytes;
204  uint32_t rxbytes;
205  uint32_t irq;
206  struct csp_iface_s *next;
207 } csp_iface_t;
208 
214 #define CSP_BUFFER_PACKET_OVERHEAD (sizeof(csp_packet_t) - sizeof(((csp_packet_t *)0)->data))
215 
217 typedef struct csp_conn_s csp_socket_t;
218 typedef struct csp_conn_s csp_conn_t;
219 
220 #define CSP_HOSTNAME_LEN 20
221 #define CSP_MODEL_LEN 30
222 
223 /* CSP_REBOOT magic values */
224 #define CSP_REBOOT_MAGIC 0x80078007
225 #define CSP_REBOOT_SHUTDOWN_MAGIC 0xD1E5529A
226 
227 #endif /* CSP_TYPES_H_ */
228 
229 /* @} */
#define CSP_ID_HOST_SIZE
Definition: csp_types.h:78
uint32_t rx
Successfully received packets.
Definition: csp_types.h:197
uint32_t txbytes
Transmitted bytes.
Definition: csp_types.h:203
Definition: csp_types.h:47
uint32_t ext
Definition: csp_types.h:107
Interface struct.
Definition: csp_types.h:190
Definition: csp_types.h:53
Definition: csp_types.h:46
#define CSP_ID_FLAGS_SIZE
Definition: csp_types.h:80
uint32_t tx_error
Transmit errors.
Definition: csp_types.h:198
uint32_t frame
Frame format errors.
Definition: csp_types.h:202
struct csp_iface_s * next
Next interface.
Definition: csp_types.h:206
Definition: csp_types.h:48
csp_id_t id
CSP id must be just before data.
Definition: csp_types.h:177
uint32_t irq
Interrupts.
Definition: csp_types.h:205
uint16_t mtu
Maximum Transmission Unit of interface.
Definition: csp_types.h:194
uint32_t drop
Dropped packets.
Definition: csp_types.h:200
Definition: csp_types.h:61
void * driver
Pointer to interface handler structure.
Definition: csp_types.h:192
struct csp_conn_s csp_socket_t
Forward declaration of socket and connection structures.
Definition: csp_types.h:217
csp_reserved_ports_e
RESERVED PORTS (SERVICES)
Definition: csp_types.h:45
uint32_t tx
Successfully transmitted packets.
Definition: csp_types.h:196
const char * name
Interface name (keep below 10 bytes)
Definition: csp_types.h:191
struct csp_conn_s csp_conn_t
Definition: csp_types.h:218
Definition: csp_types.h:59
uint32_t autherr
Authentication errors.
Definition: csp_types.h:201
csp_prio_t
Definition: csp_types.h:57
Definition: csp_types.h:58
#define CSP_ID_PRIO_SIZE
Size of bit-fields in CSP header.
Definition: csp_types.h:77
uint16_t length
Length field must be just before CSP ID.
Definition: csp_types.h:176
uint32_t rx_error
Receive errors.
Definition: csp_types.h:199
Definition: csp_types.h:52
Definition: csp_types.h:50
Definition: csp_types.h:49
Definition: csp_types.h:51
nexthop_t nexthop
Next hop function.
Definition: csp_types.h:193
int(* nexthop_t)(struct csp_iface_s *interface, csp_packet_t *packet, uint32_t timeout)
Definition: csp_types.h:187
This union defines a CSP identifier and allows access to the individual fields or the entire identifi...
Definition: csp_types.h:106
struct csp_iface_s csp_iface_t
Interface struct.
CSP PACKET STRUCTURE Note: This structure is constructed to fit with all interface frame types in ord...
Definition: csp_types.h:174
uint8_t split_horizon_off
Disable the route-loop prevention on if.
Definition: csp_types.h:195
uint32_t rxbytes
Received bytes.
Definition: csp_types.h:204
Definition: csp_types.h:54
#define CSP_ID_PORT_SIZE
Definition: csp_types.h:79
Definition: csp_types.h:60