|
K-FSW v1.2.1-59-gcaca356
KFSW: modular flight software on Zephyr, for small satellites
|
CubeSat Space Protocol provides node addresses, ports, routing and packet transport. kfsw-comms sets up libcsp, the interfaces, the routes and the router.
CSP is optional. With CONFIG_KFSW_CSP=n, local parameters, persistence, logging and the shell still work; remote parameters, FTP and the other network services need it.
Node. One CSP endpoint: a flight computer, a subsystem, a process or a ground tool. Its address is set by CONFIG_KFSW_CSP_ADDRESS. KFSW-Linux is node 1 by default and the NUCLEO-L496ZG node 2. Every node on a network needs its own address.
Protocol version. K-FSW uses CSP 2 by default: a six-byte header and 14-bit addresses, so nodes 1 to 16382, with 16383 as broadcast. Adding config/profiles/csp-v1.conf (CONFIG_KFSW_CSP_VERSION_1=y) selects CSP 1 for talking to older CSP 1 systems: a four-byte header and 5-bit addresses, so nodes 1 to 30, with 31 as broadcast. Every node on a link must use the same version. An address the selected version cannot carry stops the build. csp info prints the version in use as protocol: CSP vN.
CSP 1 is less exercised than CSP 2. The tests cover a two-node exchange, remote PARAM, multi-KISS, and firmware upload through FWU lite and FTP over clean and lossy pseudo-terminal links, plus NUCLEO builds with and without CAN. They do not cover physical CAN, RF, bootloader swaps, rollback or confirmation. This is libcsp 2.x in its CSP 1 mode; byte compatibility with a real libcsp 1.x node is untested.
Port. A service on a node: "node 2, port 9" is the file transfer service on node 2.
| Port | Service | Option |
|---|---|---|
| 0 | CSP management (CMP), which answers csp ident and csp ifstat | libcsp |
| 1 | Ping | libcsp |
| 8 | Remote shell execution | KFSW_REMEXEC_CSP_PORT |
| 9 | File transfer | KFSW_FTP_CSP_PORT |
| 10 | libparam values | KFSW_PARAM_PORT |
| 11 | Commands | KFSW_COMMAND_CSP_PORT |
| 12 | libparam descriptors | KFSW_PARAM_LIST_PORT |
| 13 | FWU lite uploads | KFSW_FWU_LITE_CSP_PORT |
| 14 | Housekeeping | KFSW_HK_CSP_PORT |
| 15 | Housekeeping beacons are sent to it; nothing on a node binds it | KFSW_HK_BEACON_PORT |
| 16 | Remote log (log history and journal) | KFSW_LOG_REMOTE_PORT |
Every node serves ports 0 and 1; libcsp's ports 2 to 6 are not served. Both ends of a link must use the same port numbers. libcsp binds 16 ports by default, which the service block 8 to 16 already fills, so app/Kconfig raises CSP_PORT_MAX_BIND to 32. A new service takes 17 or above, or port 7. Both CSP 1 and CSP 2 carry a six bit port, and libcsp places an outgoing source port at CSP_PORT_MAX_BIND + 1 + i for each of CSP_CONN_MAX connections, so 32 keeps those inside 63.
Packet. A CSP header (addresses, ports and flags such as CRC32 or RDP) and a payload. Packets come from a fixed buffer pool and stay datagrams, also with RDP.
Connection. libcsp state for a request and reply or an RDP exchange, taken from a fixed pool.
Interface. Carries packets over a link such as CAN, KISS or loopback, with an address and counters. Each KISS interface has its own UART, name, address and framing state.
Route. Maps an address prefix to an interface and, optionally, a next hop. The longest matching prefix wins. The router delivers packets for the local node and forwards the rest.
A composition names its routes with CONFIG_KFSW_CSP_ROUTE_TABLE. The Linux, NUCLEO and Pico W images use 0/0 KISS: every other node is reached over the serial link. Without a table the node loads 0/0 LOOP and reaches only itself, so a link is never picked by whichever interface came up first.
More detail is in the libcsp basic architecture, protocol stack and topology documents.
The radio module protects the KISS interface named by KFSW_RADIO_UHF_CRYPTO_INTERFACE (KISS by default). To set up an encrypted link:
CONFIG_KFSW_CSP_HMAC_KEY_FILE, ~/.config/kfsw/csp-hmac.key by default, for example with head -c 16 /dev/urandom. The profile turns on HMAC signing and the build fails without the file.config/profiles/radio-crypto.conf to both builds. On the NUCLEO, add nucleo-radio-crypto.overlay as well, for its hardware RNG.KFSW_CSP_UART_PEER_ADDRESS on each node to the other's address.openssl rand -hex 32.On each node's console, write the same key and check it was accepted:
comms uhf connect, then comms uhf status.The key reads back empty and can't be written from another node. Radio settings are saved outside the FTP directory.
uhf_encrypt_enable turns protection on or off, and uhf_encrypt_tx and uhf_encrypt_rx select the directions; both default to 1. With RX enabled, plaintext is rejected, and a missing key or session blocks traffic.
The link uses AES-256-GCM with a 16-byte tag, and the CSP header is authenticated too. Sessions and sequence numbers reject replayed frames, also after a reset. A replayed handshake can interrupt a session but can't restore an old key; comms uhf connect starts a new handshake. With the default 256-byte buffer and CRC32, an encrypted packet carries up to 220 bytes of data. Other interfaces are not encrypted.
Every packet a node sends or receives goes through one router thread. The services never touch a link: they bind a port, and the router decides which interface carries the packet.
flowchart LR
SERVICES["Services on their ports"]
ROUTER["Router thread: csp_route_work"]
TABLE["Route table: KFSW_CSP_ROUTE_TABLE"]
LOOP["LOOP: the node's own address"]
CODEC["Radio codec, optional"]
KISS["KISS interface, one per UART"]
CAN["CAN interface, CFP"]
UART["UART: USART3, or a PTY on Linux"]
CANHW["CAN controller, or SocketCAN on Linux"]
PEERS["Other nodes"]
SERVICES <--> ROUTER
ROUTER -- "longest prefix" --> TABLE
ROUTER <--> LOOP
ROUTER <-.-> CODEC
CODEC <-.-> KISS
ROUTER <--> KISS
ROUTER <--> CAN
KISS <--> UART
CAN <--> CANHW
UART <--> PEERS
CANHW <--> PEERS
kfsw_csp_init() (kfsw-comms/src/csp.c) builds this once. It sets the hostname, model, revision and address, calls csp_init(), opens every UART under a kfsw,csp-kiss-uarts devicetree node, or the single UART chosen as kfsw,csp-uart, as a KISS interface (src/uart.c), opens the controller chosen by kfsw,csp-can as a CAN interface (src/can.c), gives the loopback interface the node's address, then checks and loads the route table, and binds the ping handler. Services bind their ports after it returns. The router thread (kfsw_csp_router_thread, calling csp_route_work()) starts in kfsw_csp_start(), which main() calls after the PARAM server binds and before the other servers start.
A packet for the node's own address goes to LOOP and comes back in as if it had arrived. Any other destination is looked up in the route table, and the longest matching prefix names the interface. The table is fixed once the router starts: there is no route discovery and no failover.
The radio codec is only there with CONFIG_KFSW_RADIO_UHF_CRYPTO. It sits between the router and one named KISS interface: received packets go through its own thread to be decrypted before the router sees them (kfsw-comms/src/uart_codec.c), and outgoing ones are encrypted before KISS frames them.
Addresses belong to nodes, not to interfaces, with one exception. When a node forwards between two interfaces, each interface needs its own subnet, because libcsp does not forward a packet back into the subnet it came from. The multi-interface test below shows the layout.
On Linux the same code runs against host devices. A KISS UART is a native_sim pseudo-terminal, and a CAN interface is a SocketCAN device named at run time with --can-if, vcan0 for tests or can0 for an adapter. K-FSW has no ZMQ interface; two Linux nodes talk through a PTY pair or a virtual CAN bus.
On receive, the router hands the packet to the service bound to its port. Services never read UART bytes.
RDP is libcsp's reliable datagram transport: connection setup, a window, acknowledgements, retransmission, reordering and flow control. Data still moves as CSP datagrams; it is not TCP.
FTP doesn't retry on top of RDP. It adds the offsets, sizes, file CRC and temporary file that RDP can't check. See the libcsp RDP section.
libcsp uses preallocated buffers:
To retry, build a new packet.
csp interfaces and comms uart info show what each link carried since boot. csp counters shows libcsp's error counters:
| Counter | Raised when |
|---|---|
buffer_out | No packet buffer was free |
conn_out | No connection slot was free |
conn_ovf | A full connection queue dropped a packet |
conn_noroute | A packet had no route to its destination |
invalid_reply | A reply matched no open connection |
last_error | Code of the last libcsp error |
last_can_error | Code of the last CAN framing error |
The counters are 8-bit, wrap at 255, and libcsp updates them without locking, so read them as an indication. csp counters clear zeroes them before a run. Parameter table 4 carries the same values, so a ground station reads them like any other parameter.
Two table 4 parameters set tracing, locally or from the ground: packet_trace (0 off, 1 on) and rdp_trace (0 off, 1 errors, 2 with the protocol), the same settings as csp debug and csp rdp. Both take effect immediately and neither survives a reset.
csp ifstat 2 KISS reads a named interface on node 2 through CSP management. It reports packet and byte counts, transmit and receive errors, drops, authentication and framing errors, and the driver's interrupt count. The remote interface name must be known beforehand.
The query has a one-second timeout. An unknown interface also times out, because CMP has no not-found reply. Counts can wrap and change while read, and the query itself adds traffic.
kfsw-csp-tools is an optional host dependency pinned in west.yml. Its CAN/ZMQ transports, cspdump and csp-ping-server use CSP 1. Their four-byte headers and original Wireshark dissector do not match K-FSW's default CSP 2 configuration. The adapted csp-iperf also supports CSP 2 over KISS.
The fork's csp-kiss entry point supports only CSP 2. It works directly on the native Linux PTY or a serial KISS link. It implements ping, CMP interface statistics, node discovery, remote log retrieval and passive capture.
From k-fsw, with Rust 1.88 or newer installed:
Use the uart_1 connected to pseudotty path printed by that node in another terminal. One program uses that PTY at a time:
The source address defaults to 16; --baud defaults to 115200. Both KISS and CSP CRC32C checks are verified. An unanswered ping or interface query fails. A capture sends nothing and records packets transmitted by the node, such as HK beacons or pings issued from its shell. It fails if no packets arrive.
PCAP uses LINKTYPE_USER0 (147), with the original six-byte CSP 2 header and payload, including any CSP checksum. Only KISS framing and its outer checksum are removed. The old CSP 1/ZMQ dissector does not decode this format. Output files must be new. Host-tool builds are separate from firmware builds, and normal west updates leave the host-tools group disabled.
perf runs csp-iperf against the node's ping service; put perf before its options. The source address defaults to 30 (--src-addr) and the baud rate to 115200. The source must be unused and the link must have only one host reader.
The offered rate is CSP bytes per second, including the CSP header and checksum but not KISS framing. A reply must match both addresses, ports, a random run ID, the sequence and the full payload. RTT uses host monotonic time. The JSON reports unique replies, final loss, duplicate, reordered and late replies, and RTT. Silence and trailing loss count as loss; a reordered reply within its deadline fills its gap. The run ends after the sending duration and the reply drain, and exits 2 on any loss.
The TX rate uses the sending window; RX rates include the final drain, whose duration is elapsed_seconds. Native PTYs test the protocol; only a real link shows its capacity. Use 64-byte packets for the smoke test; larger sizes must fit the node's CSP buffers. --reply-size is for a separate CSP 1 echo server; K-FSW's ping echoes the original size. The bench fixture is in tests/hil/diagnostics/README.md.
discover queries explicit unicast addresses or an inclusive range, up to 64 addresses. It pings each node and then asks for CMP identity. It reports identified, reachable without a valid identity, no_reply, invalid_ping, or not_queried when the overall budget expires. An unanswered node is an inventory result; an unfinished inventory exits nonzero. Its final summary states whether every requested node was queried. --timeout-ms bounds each exchange and --budget-ms bounds the whole inventory. Ctrl-C stops either command; flushed records remain, without a successful completion marker.
The source address defaults to 16 and must not be among the requested nodes. The broadcast address, 16383, is excluded. discover finds only nodes reachable through the configured routes; it does not build a topology or detect duplicate addresses. It changes no configuration or clock.
A K-FSW shell reads another node's log and journal with log remote and journal remote (Logging). All integers below are big endian. Requests and replies require CSP CRC32C; the KISS link adds its own checksum. One request is served per connection.
| Message | Fields, in order |
|---|---|
| Request (12 bytes) | version u8 = 1, minimum severity u8, count u16 (1 to 32), nonce u64 |
| Reply header (10 bytes) | version u8 = 1, type u8, echoed nonce u64 |
| Start, type 0 (34 bytes total) | header, first sequence u64, exclusive end sequence u64, overwritten count u64 |
| Record, type 1 (30 to 220 bytes total) | header, sequence u64, uptime_ms u64, module u8, severity u8, truncated u8 (0/1), text length u8, up to 190 text bytes |
| End, type 2 (13 bytes total) | header, status u8, sent record count u16 |
End statuses: 0 finished, 1 a requested record was overwritten, 2 no packet buffer for a record. Invalid requests receive no response. An exhausted packet pool can also prevent start/end transmission, resulting in a client timeout. The nonce distinguishes separate reads; it is not authentication. Module IDs use enum kfsw_log_module from the services API. Reads do not generate a log message themselves.
The two-node software test connects two Linux processes through their simulated UARTs:
The second node uses tests/config/linux-node2.conf. On the NUCLEO bench, node 2 is the board, connected through USART3 and an FTDI cable.
The multi-interface test runs a router with two links and a node on each:
CONFIG_KFSW_CSP_ROUTE_TABLE uses the libcsp parser's syntax:
The prefix length counts address bits: 14 in CSP 2, 5 in CSP 1. No prefix matches one node and /0 every node, so a table written without prefixes or with /0 builds for either version; CSP 1 rejects a prefix above /5. Under CSP 1 the multi-KISS test router uses tests/config/multi-kiss-router-csp1.overlay for the interfaces' own /5 prefixes. Two entries with the same destination and prefix are both used, not tried in order. via is the link-layer next hop; KISS ignores it, but csp routes still shows it.
Ground node files can set the same table with KFSW_CSP_ROUTES. At startup the table is checked with csp_rtable_check(), the interface names, the parser's 99-character limit and the table size, and only then loaded. A bad table fails initialization.
KFSW_CSP_PEER in a ground node file sets the UART peer address (KFSW_CSP_UART_PEER_ADDRESS), the neighbour on that interface. It does not select routes; KFSW_CSP_ROUTES does, and csp routes shows the result.
With several UARTs, each one is a child of a kfsw,csp-kiss-uarts devicetree node. Interface names are one to nine characters from [A-Za-z0-9_-], which is the parser's limit.
KISS frames CSP packets on a UART, escapes reserved bytes and passes decoded packets to the router. KISS doesn't guarantee delivery or ordering; K-FSW uses CSP CRC32 to detect corruption and RDP for file transfers.
The reference profiles use 115200 8N1 and the Holybro profiles 57600. See the KISS interface in the libcsp fork the build uses.
CAN uses libcsp's CAN interface on the controller chosen with kfsw,csp-can. Under CSP 2 frames use CFP2, the CAN Fragmentation Protocol for 14-bit addresses, and CONFIG_KFSW_CSP_CAN_PREFIX_LENGTH defaults to 14; under CSP 1 they use CFP1 and its 5-bit addresses, and the default is 5. The fields are the CFP2_* and CFP_* definitions in csp_if_can.h. The NUCLEO uses CAN1 on PD0/PD1 with an external transceiver, and a Linux node uses a SocketCAN interface. Both ends of the bus need the same bitrate; the profiles use 500 kbit/s.
can_speed in table 1 changes the bitrate at run time: 125000, 250000, 500000, 800000 or 1000000. The node stops the CAN interface and opens it again at the new rate, so a change made over CAN cuts the link until the other nodes follow. If the stop fails, the driver keeps the interface, its queue and its receive thread, and the node stays at the old rate. Read can_speed back after writing it: it reports the rate in use, and writing the value again retries the stop.
Bring up a real SocketCAN adapter with:
The setup script sets and verifies txqueuelen 1000. Check qlen 1000 or higher before transmitting. For another interface name, configure its bitrate and set sudo ip link set dev <interface> txqueuelen 1000 before use. The default queue of 10 can fill during CFP1 firmware uploads. The native driver currently reports success on a refused write and then waits for a completion that never arrives, so CAN TX can stop until the ground process restarts. A longer queue reduces this risk; driver error handling and retry are still needed. The HIL preflight and CAN FWU scripts reject queues below 1000.
vcan carries CAN frames between processes on one host. To test two Linux nodes without hardware:
The first command needs root and only has to run once after a boot. The test runs a node at address 2 against the kfsw-gnd-can ground role at 17, pings both ways, reads remote parameters and checks the counters afterwards.
The interface name comes from --can-if at run time, so the same images run against a real adapter by naming can0. A virtual bus has no bit timing: it tests routing, framing and the services, not the wire. The default virtual bus has no transmit queue and does not exercise a real adapter's queue exhaustion. The physical CAN queue requirement does not apply to this software test.
The NUCLEO has two serial connections:
Don't mix them up: shell text on USART3 is invalid KISS, and KISS data on the ST-LINK console is binary noise. On Linux the shell uses stdin/stdout and CSP a separate PTY.
The UART hardware test connects KFSW-Linux node 1 to NUCLEO-L496ZG node 2 through an FTDI TTL-232R-3V3 on USART3, with the ST-LINK console connected too. It flashes the board, checks both serial connections, pings both ways, runs comms uart test, checks storage, transfers 4 KiB and 16 KiB files, reads a remote parameter and checks the KISS counters.
Only the encrypted radio link is authenticated by default. libcsp HMAC is available as CONFIG_KFSW_CSP_HMAC: it signs what the node sends, and CONFIG_KFSW_CSP_HMAC_REQUIRE then refuses unsigned packets on the ports that change state. config/profiles/radio-crypto.conf enables signing; the reference compositions leave it off. CRC32 only detects accidental corruption, and commands have no per-node authorization.
The optional host binaries can be fetched and built with tools/host-tools.sh (Rust required). KFSW_HOST_TOOLS=1 tools/ci/robot.sh opts into building them; prebuilt binaries are detected automatically. Set KFSW_OUTPUT_ROOT=/tmp/kfsw-ci to keep generated CI builds and reports outside the workspace.