ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
telnet.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file telnet.h
6 * @brief Layer 6/7 - minimal RFC 854 Telnet server (PC_ENABLE_TELNET).
7 *
8 * A zero-heap line-oriented Telnet console dispatched from the session layer's
9 * ConnProto::PROTO_TELNET arms (the same way SSH is dispatched to ssh_conn). On connect it
10 * negotiates server-side echo + suppress-go-ahead (so the client runs in
11 * character mode and the server draws the line), accumulates a line, echoes
12 * keystrokes (with backspace handling), and hands each completed line to a
13 * command callback. Output can be pushed to all connected clients.
14 *
15 * Telnet is plaintext - no authentication or encryption. Use it only on a
16 * trusted network; prefer SSH or the WebSocket terminal otherwise.
17 *
18 * Usage:
19 * @code
20 * server.listen(23, ConnProto::PROTO_TELNET); // open the Telnet port
21 * pc_telnet_on_command(my_cmd_handler); // void(const char *line, uint8_t id)
22 * @endcode
23 */
24
25#ifndef PROTOCORE_TELNET_H
26#define PROTOCORE_TELNET_H
27
28#include "protocore_config.h"
30#include <stddef.h>
31#include <stdint.h>
32
33#if PC_ENABLE_TELNET
34
35/** @brief Called with each completed input line (NUL-terminated, no CR/LF) and its client id. */
36typedef void (*TelnetCommandCb)(const char *line, uint8_t conn_id);
37
38// ---- Application API ------------------------------------------------------
39
40/** @brief Register the per-line command handler. */
41void pc_telnet_on_command(TelnetCommandCb cb);
42
43/** @brief Send text to every connected Telnet client (no trailing newline added). */
44void pc_telnet_print(const char *s);
45
46/** @brief Send text + CRLF to every connected Telnet client. */
47void pc_telnet_println(const char *s);
48
49/**
50 * @brief Build @p spec and broadcast it to every connected Telnet client.
51 *
52 * The message shape is a `static const pc_field[]` the caller declares, so a console line costs a
53 * table walk rather than a format-string parse, and a line longer than TELNET_BUF_SIZE is dropped
54 * rather than clipped mid-word.
55 *
56 * @code
57 * static const pc_field HEAP[] = {{PC_FK_LIT, 0, 11, "free heap: "}, PC_U32,
58 * {PC_FK_LIT, 0, 8, " bytes\r\n"}, PC_END};
59 * pc_telnet_frame(HEAP, ESP.getFreeHeap());
60 * @endcode
61 */
62void pc_telnet_frame(const pc_field *spec, ...);
63
64/** @brief Number of connected Telnet clients. */
65uint8_t pc_telnet_client_count();
66
67// ---- Connection layer (called by the session layer for ConnProto::PROTO_TELNET slots) -
68
69/** @brief A Telnet connection was accepted on TCP slot @p slot. */
70void pc_telnet_accept(uint8_t slot);
71
72/** @brief Drain and process received bytes for the Telnet connection on @p slot. */
73void pc_telnet_rx(uint8_t slot);
74
75/** @brief The Telnet connection on @p slot closed; release its state. */
76void pc_telnet_close(uint8_t slot);
77
78/** @brief The Telnet ProtoHandler (accessor; installed by the builtins list, no session dep). */
79struct ProtoHandler;
80const struct ProtoHandler *pc_telnet_proto_handler(void);
81
82#endif // PC_ENABLE_TELNET
83
84#endif // PROTOCORE_TELNET_H
Declarative frame builder: a frame is a static table of typed fields, built by one engine.
User-facing configuration for ProtoCore.
Per-protocol connection event/poll callbacks (Layer 5 dispatch vtable).
One field of a frame. Frames are static const pc_field[], so they live in rodata.
Definition frame.h:80