K-FSW ec10f94
Modular flight software on Zephyr, for small satellites
Loading...
Searching...
No Matches
csp.h File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Data Structures

struct  kfsw_csp_info
 
struct  kfsw_csp_interface_info
 
struct  kfsw_csp_counters
 
struct  kfsw_csp_route_info
 
struct  kfsw_csp_interface_stats
 
struct  kfsw_csp_clock
 
struct  kfsw_csp_identity
 

Macros

#define KFSW_CSP_ROUTE_TABLE_MAX_LENGTH   99U
 
#define KFSW_CSP_SECURE_OVERHEAD   32U
 
#define KFSW_CSP_PAYLOAD_MAX   (CONFIG_CSP_BUFFER_SIZE - KFSW_CSP_SECURE_OVERHEAD)
 
#define KFSW_CSP_INTERFACE_NAME_SIZE   11U
 
#define KFSW_CSP_IDENTITY_HOSTNAME_SIZE   21U
 
#define KFSW_CSP_IDENTITY_MODEL_SIZE   31U
 
#define KFSW_CSP_IDENTITY_REVISION_SIZE   21U
 
#define KFSW_CSP_IDENTITY_DATE_SIZE   13U
 
#define KFSW_CSP_IDENTITY_TIME_SIZE   10U
 

Types

typedef bool(* kfsw_csp_interface_visitor_t) (const struct kfsw_csp_interface_info *interface_info, void *context)
 
typedef bool(* kfsw_csp_route_visitor_t) (const struct kfsw_csp_route_info *route_info, void *context)
 

Functions

void kfsw_csp_set_packet_trace (bool enabled)
 
bool kfsw_csp_get_packet_trace (void)
 
void kfsw_csp_set_revision (const char *revision)
 
int kfsw_csp_init (void)
 
int kfsw_csp_start (void)
 
void kfsw_csp_get_info (struct kfsw_csp_info *info)
 
void kfsw_csp_visit_interfaces (kfsw_csp_interface_visitor_t visitor, void *context)
 
void kfsw_csp_visit_routes (kfsw_csp_route_visitor_t visitor, void *context)
 
void kfsw_csp_get_counters (struct kfsw_csp_counters *counters)
 
void kfsw_csp_clear_counters (void)
 
const char * kfsw_csp_error_name (uint8_t code)
 
const char * kfsw_csp_can_error_name (uint8_t code)
 
int kfsw_csp_route_table_check (const char *route_table, size_t *entry_count)
 
int kfsw_csp_route_table_apply (const char *route_table)
 
int kfsw_csp_ping (uint16_t node, uint32_t timeout_ms, size_t payload_size, uint32_t *round_trip_ms)
 
int kfsw_csp_interface_stats_read (uint16_t node, const char *name, uint32_t timeout_ms, struct kfsw_csp_interface_stats *stats)
 
void kfsw_csp_clock_get (struct kfsw_csp_clock *clock)
 
bool kfsw_csp_clock_is_set (const struct kfsw_csp_clock *clock)
 
int kfsw_csp_clock_set (const struct kfsw_csp_clock *clock)
 
int kfsw_csp_clock_read (uint16_t node, uint32_t timeout_ms, struct kfsw_csp_clock *clock)
 
int kfsw_csp_clock_write (uint16_t node, uint32_t timeout_ms, struct kfsw_csp_clock *clock)
 
int kfsw_csp_identify (uint16_t node, uint32_t timeout_ms, struct kfsw_csp_identity *identity)
 

Description

CSP setup, routes, interfaces and ping.

Macro Documentation

◆ KFSW_CSP_INTERFACE_NAME_SIZE

#define KFSW_CSP_INTERFACE_NAME_SIZE   11U

Interface names in CMP have ten characters and a terminator.

◆ KFSW_CSP_PAYLOAD_MAX

#define KFSW_CSP_PAYLOAD_MAX   (CONFIG_CSP_BUFFER_SIZE - KFSW_CSP_SECURE_OVERHEAD)

Largest application payload that survives every K-FSW transport.

A service that sizes a full packet checks against this and not CSP_BUFFER_SIZE: the encrypted UHF link is the tightest and drops anything longer without reporting it.

◆ KFSW_CSP_ROUTE_TABLE_MAX_LENGTH

#define KFSW_CSP_ROUTE_TABLE_MAX_LENGTH   99U

Maximum route-table string length accepted by the pinned libcsp parser.

◆ KFSW_CSP_SECURE_OVERHEAD

#define KFSW_CSP_SECURE_OVERHEAD   32U

Framing the encrypted UHF link adds inside one CSP buffer: a 12-byte header, a 16-byte tag and a 4-byte checksum.

Function Documentation

◆ kfsw_csp_can_error_name()

const char * kfsw_csp_can_error_name ( uint8_t  code)

Name of a kfsw_csp_counters last_can_error code, or "unknown".

◆ kfsw_csp_clear_counters()

void kfsw_csp_clear_counters ( void  )

Clear the error counters.

◆ kfsw_csp_clock_get()

void kfsw_csp_clock_get ( struct kfsw_csp_clock *  clock)

Read this node's RTC clock.

◆ kfsw_csp_clock_is_set()

bool kfsw_csp_clock_is_set ( const struct kfsw_csp_clock *  clock)

Whether a clock reading has been set.

◆ kfsw_csp_clock_read()

int kfsw_csp_clock_read ( uint16_t  node,
uint32_t  timeout_ms,
struct kfsw_csp_clock *  clock 
)

Read another node's RTC clock.

Returns 0 and fills clock, or a negative errno. A node whose clock was never set answers zero seconds.

◆ kfsw_csp_clock_set()

int kfsw_csp_clock_set ( const struct kfsw_csp_clock *  clock)

Set this node's RTC clock.

Returns 0 on success, -ENOTSUP where the composition carries no real-time clock, and -EINVAL for a time the platform will not accept.

◆ kfsw_csp_clock_write()

int kfsw_csp_clock_write ( uint16_t  node,
uint32_t  timeout_ms,
struct kfsw_csp_clock *  clock 
)

Set another node's clock.

clock is filled with the time the node reads back after setting it. The link delay is not compensated.

◆ kfsw_csp_error_name()

const char * kfsw_csp_error_name ( uint8_t  code)

Name of a kfsw_csp_counters last_error code, or "unknown".

◆ kfsw_csp_get_counters()

void kfsw_csp_get_counters ( struct kfsw_csp_counters *  counters)

Copy libcsp's error counters.

Safe before initialization; they read zero.

◆ kfsw_csp_get_info()

void kfsw_csp_get_info ( struct kfsw_csp_info *  info)

Copy the current local CSP identity information.

◆ kfsw_csp_get_packet_trace()

bool kfsw_csp_get_packet_trace ( void  )

Whether packet tracing is currently on.

◆ kfsw_csp_identify()

int kfsw_csp_identify ( uint16_t  node,
uint32_t  timeout_ms,
struct kfsw_csp_identity *  identity 
)

Ask a remote node to identify itself.

Gets the hostname, model, revision, and build date and time.

Parameters
nodeRemote CSP address.
timeout_msReply timeout in milliseconds.
[out]identityDestination identity.
Return values
CSP_ERR_NONEThe node answered.
CSP_ERR_INVALCSP is not running, identity is NULL, or the address is out of range.
CSP_ERR_TIMEDOUTNo answer arrived in time.

◆ kfsw_csp_init()

int kfsw_csp_init ( void  )

Initialize libcsp, the configured interfaces, and static routes once.

◆ kfsw_csp_interface_stats_read()

int kfsw_csp_interface_stats_read ( uint16_t  node,
const char *  name,
uint32_t  timeout_ms,
struct kfsw_csp_interface_stats *  stats 
)

Read a named interface through CSP management.

Returns 0, -EINVAL for invalid arguments, -ENETDOWN before router start, -ETIMEDOUT for no complete reply (including unknown interfaces), or -EBADMSG for an inconsistent reply. Output is unchanged on failure. The query itself contributes traffic; counters are an observation, not an atomic snapshot.

◆ kfsw_csp_ping()

int kfsw_csp_ping ( uint16_t  node,
uint32_t  timeout_ms,
size_t  payload_size,
uint32_t *  round_trip_ms 
)

Send a standard CSP ping using CRC32 and return its round-trip time.

◆ kfsw_csp_route_table_apply()

int kfsw_csp_route_table_apply ( const char *  route_table)

Validate and replace routes after initialization, before router start.

Parameters
route_tableTable in libcsp's CIDR syntax.
Return values
0The table is loaded.
CSP_ERR_NOTSUPThe router is running; routes remain unchanged.
CSP_ERR_INVALCSP is not initialized or the table is invalid.
Returns
A negative libcsp error when the table is malformed, too large for CONFIG_CSP_RTABLE_SIZE, or fails to load.

◆ kfsw_csp_route_table_check()

int kfsw_csp_route_table_check ( const char *  route_table,
size_t *  entry_count 
)

Check a route table without applying it.

Returns 0 when the table is well formed, -ENETDOWN when CSP has not been initialised yet and the interfaces a table names do not exist, and a libcsp error otherwise.

◆ kfsw_csp_set_packet_trace()

void kfsw_csp_set_packet_trace ( bool  enabled)

Print every packet the router receives and every packet this node sends.

Each line has the source and destination node and port, priority, flags and size. Off by default.

Parameters
enabledTrue to trace, false to stop.

◆ kfsw_csp_set_revision()

void kfsw_csp_set_revision ( const char *  revision)

Set the revision this node reports.

Call before CSP is initialised.

◆ kfsw_csp_start()

int kfsw_csp_start ( void  )

Start the CSP router thread.

◆ kfsw_csp_visit_interfaces()

void kfsw_csp_visit_interfaces ( kfsw_csp_interface_visitor_t  visitor,
void *  context 
)

Call visitor for each registered interface, under libcsp's lock.

Return false from visitor to stop early.

◆ kfsw_csp_visit_routes()

void kfsw_csp_visit_routes ( kfsw_csp_route_visitor_t  visitor,
void *  context 
)

Call visitor for each static route.

Return false to stop early.