csp.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_H_
28 #define _CSP_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* Includes */
35 #include <stdint.h>
36 
37 #include <csp/csp_autoconfig.h>
38 
39 /* CSP includes */
40 #include "csp_types.h"
41 #include "csp_platform.h"
42 #include "csp_error.h"
43 #include "csp_debug.h"
44 #include "csp_buffer.h"
45 #include "csp_rtable.h"
46 #include "csp_iflist.h"
47 
52 int csp_init(uint8_t my_node_address);
53 
58 void csp_set_address(uint8_t addr);
59 
64 uint8_t csp_get_address(void);
65 
71 void csp_set_hostname(char *hostname);
72 
77 char *csp_get_hostname(void);
78 
84 void csp_set_model(char *model);
85 
90 char *csp_get_model(void);
91 
97 void csp_set_revision(char *revision);
98 
103 char *csp_get_revision(void);
104 
110 csp_socket_t *csp_socket(uint32_t opts);
111 
118 csp_conn_t *csp_accept(csp_socket_t *socket, uint32_t timeout);
119 
130 csp_packet_t *csp_read(csp_conn_t *conn, uint32_t timeout);
131 
139 int csp_send(csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout);
140 
153 int csp_send_prio(uint8_t prio, csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout);
154 
169 int csp_transaction(uint8_t prio, uint8_t dest, uint8_t port, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen);
170 
182 int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen);
183 
191 csp_packet_t *csp_recvfrom(csp_socket_t *socket, uint32_t timeout);
192 
204 int csp_sendto(uint8_t prio, uint8_t dest, uint8_t dport, uint8_t src_port, uint32_t opts, csp_packet_t *packet, uint32_t timeout);
205 
215 int csp_sendto_reply(csp_packet_t * request_packet, csp_packet_t * reply_packet, uint32_t opts, uint32_t timeout);
216 
229 csp_conn_t *csp_connect(uint8_t prio, uint8_t dest, uint8_t dport, uint32_t timeout, uint32_t opts);
230 
236 int csp_close(csp_conn_t *conn);
237 
242 int csp_conn_dport(csp_conn_t *conn);
243 
248 int csp_conn_sport(csp_conn_t *conn);
249 
254 int csp_conn_dst(csp_conn_t *conn);
255 
260 int csp_conn_src(csp_conn_t *conn);
261 
266 int csp_conn_flags(csp_conn_t *conn);
267 
273 
280 int csp_listen(csp_socket_t *socket, size_t conn_queue_length);
281 
288 int csp_bind(csp_socket_t *socket, uint8_t port);
289 
295 int csp_route_start_task(unsigned int task_stack_size, unsigned int priority);
296 
300 void csp_route_end_task();
301 
309 int csp_route_work(uint32_t timeout);
310 
319 int csp_bridge_start(unsigned int task_stack_size, unsigned int task_priority, csp_iface_t * _if_a, csp_iface_t * _if_b);
320 
330 int csp_promisc_enable(unsigned int buf_size);
331 
337 void csp_promisc_disable(void);
338 
347 csp_packet_t *csp_promisc_read(uint32_t timeout);
348 
360 int csp_sfp_send(csp_conn_t * conn, void * data, int totalsize, int mtu, uint32_t timeout);
361 
373 int csp_sfp_send_own_memcpy(csp_conn_t * conn, void * data, int totalsize, int mtu, uint32_t timeout, void * (*memcpyfcn)(void *, const void *, size_t));
374 
383 int csp_sfp_recv(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t timeout);
384 
394 int csp_sfp_recv_fp(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t timeout, csp_packet_t * first_packet);
395 
407 void csp_service_handler(csp_conn_t *conn, csp_packet_t *packet);
408 
417 int csp_ping(uint8_t node, uint32_t timeout, unsigned int size, uint8_t conn_options);
418 
423 void csp_ping_noreply(uint8_t node);
424 
431 void csp_ps(uint8_t node, uint32_t timeout);
432 
438 void csp_memfree(uint8_t node, uint32_t timeout);
439 
445 void csp_buf_free(uint8_t node, uint32_t timeout);
446 
451 void csp_reboot(uint8_t node);
452 
457 void csp_shutdown(uint8_t node);
458 
464 void csp_uptime(uint8_t node, uint32_t timeout);
465 
475 void csp_rdp_set_opt(unsigned int window_size, unsigned int conn_timeout_ms,
476  unsigned int packet_timeout_ms, unsigned int delayed_acks,
477  unsigned int ack_timeout, unsigned int ack_delay_count);
478 
488 void csp_rdp_get_opt(unsigned int *window_size, unsigned int *conn_timeout_ms,
489  unsigned int *packet_timeout_ms, unsigned int *delayed_acks,
490  unsigned int *ack_timeout, unsigned int *ack_delay_count);
491 
498 int csp_xtea_set_key(char *key, uint32_t keylen);
499 
506 int csp_hmac_set_key(char *key, uint32_t keylen);
507 
511 void csp_conn_print_table(void);
512 
516 void csp_buffer_print_table(void);
517 
518 #ifdef __AVR__
519 typedef uint32_t csp_memptr_t;
520 #else
521 typedef void * csp_memptr_t;
522 #endif
523 
526 
531 #include <stdarg.h>
532 typedef void (*csp_debug_hook_func_t)(csp_debug_level_t level, const char *format, va_list args);
534 
535 #ifdef __cplusplus
536 } /* extern "C" */
537 #endif
538 
539 #endif // _CSP_H_
540 
541 /* @} */
void * csp_memptr_t
Definition: csp.h:521
int csp_send(csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout)
Send a packet on an already established connection.
int csp_transaction(uint8_t prio, uint8_t dest, uint8_t port, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen)
Perform an entire request/reply transaction Copies both input buffer and reply to output buffeer...
csp_packet_t * csp_read(csp_conn_t *conn, uint32_t timeout)
Read data from a connection This fuction uses the RX queue of a connection to receive a packet If no ...
Interface struct.
Definition: csp_types.h:190
char * csp_get_hostname(void)
csp_get_hostname Get current subsystem hostname.
void(* csp_debug_hook_func_t)(csp_debug_level_t level, const char *format, va_list args)
Set csp_debug hook function.
Definition: csp.h:532
void csp_debug_hook_set(csp_debug_hook_func_t f)
int csp_conn_sport(csp_conn_t *conn)
int csp_bridge_start(unsigned int task_stack_size, unsigned int task_priority, csp_iface_t *_if_a, csp_iface_t *_if_b)
Start the bridge task.
void csp_cmp_set_memcpy(csp_memcpy_fnc_t fnc)
int csp_sfp_send_own_memcpy(csp_conn_t *conn, void *data, int totalsize, int mtu, uint32_t timeout, void *(*memcpyfcn)(void *, const void *, size_t))
Same as csp_sfp_send but with option to supply your own memcpy function.
char * csp_get_model(void)
csp_get_model Get current model name.
void csp_buffer_print_table(void)
Print buffer usage table.
int csp_conn_dport(csp_conn_t *conn)
int csp_conn_dst(csp_conn_t *conn)
void csp_shutdown(uint8_t node)
Shutdown subsystem.
int csp_sfp_recv(csp_conn_t *conn, void **dataout, int *datasize, uint32_t timeout)
This is the counterpart to the csp_sfp_send function.
void csp_rdp_get_opt(unsigned int *window_size, unsigned int *conn_timeout_ms, unsigned int *packet_timeout_ms, unsigned int *delayed_acks, unsigned int *ack_timeout, unsigned int *ack_delay_count)
Get RDP options.
int csp_sfp_send(csp_conn_t *conn, void *data, int totalsize, int mtu, uint32_t timeout)
Send multiple packets using the simple fragmentation protocol CSP will add total size and offset to a...
struct csp_conn_s csp_socket_t
Forward declaration of socket and connection structures.
Definition: csp_types.h:217
int csp_route_start_task(unsigned int task_stack_size, unsigned int priority)
Start the router task.
void csp_reboot(uint8_t node)
Reboot subsystem.
int csp_sendto_reply(csp_packet_t *request_packet, csp_packet_t *reply_packet, uint32_t opts, uint32_t timeout)
Send a packet as a direct reply to the source of an incoming packet, but still without holding an ent...
struct csp_conn_s csp_conn_t
Definition: csp_types.h:218
csp_packet_t * csp_promisc_read(uint32_t timeout)
Get packet from promiscuous mode packet queue Returns the first packet from the promiscuous mode pack...
int csp_init(uint8_t my_node_address)
csp_init Start up the can-space protocol
int csp_close(csp_conn_t *conn)
csp_close Closes a given connection and frees buffers used.
csp_memptr_t(* csp_memcpy_fnc_t)(csp_memptr_t, const csp_memptr_t, size_t)
Definition: csp.h:524
int csp_promisc_enable(unsigned int buf_size)
Enable promiscuous mode packet queue This function is used to enable promiscuous mode for the router...
void csp_buf_free(uint8_t node, uint32_t timeout)
Request number of free buffer elements.
csp_debug_level_t
Debug levels.
Definition: csp_debug.h:38
csp_socket_t * csp_socket(uint32_t opts)
csp_socket Create CSP socket endpoint
void csp_ps(uint8_t node, uint32_t timeout)
Request process list.
uint8_t csp_get_address(void)
csp_get_address Get the systems own address
int csp_hmac_set_key(char *key, uint32_t keylen)
Set HMAC key.
void csp_set_revision(char *revision)
csp_set_revision Set subsystem revision.
void csp_memfree(uint8_t node, uint32_t timeout)
Request amount of free memory.
csp_conn_t * csp_connect(uint8_t prio, uint8_t dest, uint8_t dport, uint32_t timeout, uint32_t opts)
csp_connect Used to establish outgoing connections This function searches the port table for free slo...
void csp_promisc_disable(void)
Disable promiscuous mode.
void csp_set_address(uint8_t addr)
csp_set_address Set the systems own address
int csp_listen(csp_socket_t *socket, size_t conn_queue_length)
Set socket to listen for incoming connections.
void csp_conn_print_table(void)
Print connection table.
csp_conn_t * csp_accept(csp_socket_t *socket, uint32_t timeout)
Wait for a new connection on a socket created by csp_socket.
int csp_send_prio(uint8_t prio, csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout)
Send a packet on an already established connection, and change the default priority of the connection...
int csp_sendto(uint8_t prio, uint8_t dest, uint8_t dport, uint8_t src_port, uint32_t opts, csp_packet_t *packet, uint32_t timeout)
Send a packet without previously opening a connection.
int csp_conn_src(csp_conn_t *conn)
void csp_rdp_set_opt(unsigned int window_size, unsigned int conn_timeout_ms, unsigned int packet_timeout_ms, unsigned int delayed_acks, unsigned int ack_timeout, unsigned int ack_delay_count)
Set RDP options.
void csp_route_end_task()
Ends the router task.
int csp_route_work(uint32_t timeout)
Call the router worker function manually (without the router task) This must be run inside a loop or ...
void csp_service_handler(csp_conn_t *conn, csp_packet_t *packet)
If the given packet is a service-request (that is uses one of the csp service ports) it will be handl...
csp_packet_t * csp_recvfrom(csp_socket_t *socket, uint32_t timeout)
Read data from a connection-less server socket This fuction uses the socket directly to receive a fra...
int csp_xtea_set_key(char *key, uint32_t keylen)
Set XTEA key.
int csp_sfp_recv_fp(csp_conn_t *conn, void **dataout, int *datasize, uint32_t timeout, csp_packet_t *first_packet)
This is the counterpart to the csp_sfp_send function.
int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen)
Use an existing connection to perform a transaction, This is only possible if the next packet is on t...
char * csp_get_revision(void)
csp_get_revision Get subsystem revision.
CSP PACKET STRUCTURE Note: This structure is constructed to fit with all interface frame types in ord...
Definition: csp_types.h:174
void csp_uptime(uint8_t node, uint32_t timeout)
Request subsystem uptime.
int csp_bind(csp_socket_t *socket, uint8_t port)
Bind port to socket.
int csp_ping(uint8_t node, uint32_t timeout, unsigned int size, uint8_t conn_options)
Send a single ping/echo packet.
int csp_conn_check_alive(csp_conn_t *conn)
void csp_set_model(char *model)
csp_set_model Set subsystem model name.
void csp_set_hostname(char *hostname)
csp_set_hostname Set subsystem hostname.
void csp_ping_noreply(uint8_t node)
Send a single ping/echo packet without waiting for reply.
int csp_conn_flags(csp_conn_t *conn)