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 
54 void csp_terminate(void);
55 
60 void csp_set_address(uint8_t addr);
61 
66 uint8_t csp_get_address(void);
67 
73 void csp_set_hostname(char *hostname);
74 
79 char *csp_get_hostname(void);
80 
86 void csp_set_model(char *model);
87 
92 char *csp_get_model(void);
93 
99 void csp_set_revision(char *revision);
100 
105 char *csp_get_revision(void);
106 
112 csp_socket_t *csp_socket(uint32_t opts);
113 
120 csp_conn_t *csp_accept(csp_socket_t *socket, uint32_t timeout);
121 
132 csp_packet_t *csp_read(csp_conn_t *conn, uint32_t timeout);
133 
141 int csp_send(csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout);
142 
155 int csp_send_prio(uint8_t prio, csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout);
156 
171 int csp_transaction(uint8_t prio, uint8_t dest, uint8_t port, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen);
172 
184 int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen);
185 
193 csp_packet_t *csp_recvfrom(csp_socket_t *socket, uint32_t timeout);
194 
206 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);
207 
217 int csp_sendto_reply(csp_packet_t * request_packet, csp_packet_t * reply_packet, uint32_t opts, uint32_t timeout);
218 
231 csp_conn_t *csp_connect(uint8_t prio, uint8_t dest, uint8_t dport, uint32_t timeout, uint32_t opts);
232 
238 int csp_close(csp_conn_t *conn);
239 
244 void csp_close_socket(csp_socket_t * socket);
245 
250 int csp_conn_dport(csp_conn_t *conn);
251 
256 int csp_conn_sport(csp_conn_t *conn);
257 
262 int csp_conn_dst(csp_conn_t *conn);
263 
268 int csp_conn_src(csp_conn_t *conn);
269 
274 int csp_conn_flags(csp_conn_t *conn);
275 
281 
288 int csp_listen(csp_socket_t *socket, size_t conn_queue_length);
289 
296 int csp_bind(csp_socket_t *socket, uint8_t port);
297 
303 int csp_route_start_task(unsigned int task_stack_size, unsigned int priority);
304 
308 void csp_route_end_task();
309 
317 int csp_route_work(uint32_t timeout);
318 
327 int csp_bridge_start(unsigned int task_stack_size, unsigned int task_priority, csp_iface_t * _if_a, csp_iface_t * _if_b);
328 
338 int csp_promisc_enable(unsigned int buf_size);
339 
345 void csp_promisc_disable(void);
346 
355 csp_packet_t *csp_promisc_read(uint32_t timeout);
356 
368 int csp_sfp_send(csp_conn_t * conn, void * data, int totalsize, int mtu, uint32_t timeout);
369 
381 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));
382 
391 int csp_sfp_recv(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t timeout);
392 
402 int csp_sfp_recv_fp(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t timeout, csp_packet_t * first_packet);
403 
415 void csp_service_handler(csp_conn_t *conn, csp_packet_t *packet);
416 
425 int csp_ping(uint8_t node, uint32_t timeout, unsigned int size, uint8_t conn_options);
426 
431 void csp_ping_noreply(uint8_t node);
432 
439 void csp_ps(uint8_t node, uint32_t timeout);
440 
446 void csp_memfree(uint8_t node, uint32_t timeout);
447 
453 void csp_buf_free(uint8_t node, uint32_t timeout);
454 
459 void csp_reboot(uint8_t node);
460 
465 void csp_shutdown(uint8_t node);
466 
472 void csp_uptime(uint8_t node, uint32_t timeout);
473 
483 void csp_rdp_set_opt(unsigned int window_size, unsigned int conn_timeout_ms,
484  unsigned int packet_timeout_ms, unsigned int delayed_acks,
485  unsigned int ack_timeout, unsigned int ack_delay_count);
486 
496 void csp_rdp_get_opt(unsigned int *window_size, unsigned int *conn_timeout_ms,
497  unsigned int *packet_timeout_ms, unsigned int *delayed_acks,
498  unsigned int *ack_timeout, unsigned int *ack_delay_count);
499 
506 int csp_xtea_set_key(char *key, uint32_t keylen);
507 
514 int csp_hmac_set_key(char *key, uint32_t keylen);
515 
519 void csp_conn_print_table(void);
520 
524 void csp_buffer_print_table(void);
525 
526 #ifdef __AVR__
527 typedef uint32_t csp_memptr_t;
528 #else
529 typedef void * csp_memptr_t;
530 #endif
531 
534 
539 #include <stdarg.h>
540 typedef void (*csp_debug_hook_func_t)(csp_debug_level_t level, const char *format, va_list args);
542 
543 #ifdef __cplusplus
544 } /* extern "C" */
545 #endif
546 
547 #endif // _CSP_H_
548 
549 /* @} */
void * csp_memptr_t
Definition: csp.h:529
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:540
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:532
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...
void csp_close_socket(csp_socket_t *socket)
Closes a given socket and frees queue used.
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.
void csp_terminate(void)
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)