1 /* 2 * Copyright (c) 2019 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef SHELL_TELNET_H__ 8 #define SHELL_TELNET_H__ 9 10 #include <shell/shell.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 extern const struct shell_transport_api shell_telnet_transport_api; 17 18 /** Line buffer structure. */ 19 struct shell_telnet_line_buf { 20 /** Line buffer. */ 21 char buf[CONFIG_SHELL_TELNET_LINE_BUF_SIZE]; 22 23 /** Current line length. */ 24 uint16_t len; 25 }; 26 27 /** TELNET-based shell transport. */ 28 struct shell_telnet { 29 /** Handler function registered by shell. */ 30 shell_transport_handler_t shell_handler; 31 32 /** Context registered by shell. */ 33 void *shell_context; 34 35 /** Buffer for outgoing line. */ 36 struct shell_telnet_line_buf line_out; 37 38 /** Network context of TELNET client. */ 39 struct net_context *client_ctx; 40 41 /** RX packet FIFO. */ 42 struct k_fifo rx_fifo; 43 44 /** The delayed work is used to send non-lf terminated output that has 45 * been around for "too long". This will prove to be useful 46 * to send the shell prompt for instance. 47 */ 48 struct k_work_delayable send_work; 49 struct k_work_sync work_sync; 50 51 /** If set, no output is sent to the TELNET client. */ 52 bool output_lock; 53 }; 54 55 #define SHELL_TELNET_DEFINE(_name) \ 56 static struct shell_telnet _name##_shell_telnet; \ 57 struct shell_transport _name = { \ 58 .api = &shell_telnet_transport_api, \ 59 .ctx = (struct shell_telnet *)&_name##_shell_telnet \ 60 } 61 62 /** 63 * @brief This function provides pointer to shell telnet backend instance. 64 * 65 * Function returns pointer to the shell telnet instance. This instance can be 66 * next used with shell_execute_cmd function in order to test commands behavior. 67 * 68 * @returns Pointer to the shell instance. 69 */ 70 const struct shell *shell_backend_telnet_get_ptr(void); 71 72 #ifdef __cplusplus 73 } 74 #endif 75 76 #endif /* SHELL_TELNET_H__ */ 77