-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys/net/application_layer: add telnet server module
- Loading branch information
Showing
9 changed files
with
422 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2021 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @defgroup net_telnet basic Telnet server implementation | ||
* @ingroup net_ipv6 | ||
* @brief Telnet server functions | ||
* @{ | ||
* | ||
* @file | ||
* @brief Telnet server ([RFC 855](https://tools.ietf.org/html/rfc855)) implementation | ||
* @note This implementation only supports a single client | ||
* | ||
* @author Benjamin Valentin <[email protected]> | ||
*/ | ||
#ifndef NET_TELNET_H | ||
#define NET_TELNET_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief The port for the Telnet server to listen on | ||
*/ | ||
#ifndef TELNET_PORT | ||
#define TELNET_PORT (23) | ||
#endif | ||
|
||
/** | ||
* @brief Start the Telnet server thread | ||
* | ||
* @return 0 on success, error otherwise | ||
*/ | ||
int telnet_server_start(void); | ||
|
||
/** | ||
* @brief Write data to the telnet client | ||
* | ||
* @params[in] buffer The buffer to send to the client | ||
* @params[in] len The length of the buffer | ||
* | ||
* @return 0 on success, error otherwise | ||
*/ | ||
int telnet_server_write(const void* buffer, size_t len); | ||
|
||
/** | ||
* @brief Read data from the telnet client, will block until data is available. | ||
* | ||
* @params[out] buffer The buffer to write data from the client | ||
* @params[in] count Number of bytes to read | ||
* | ||
* @return number of bytes read, error otherwise | ||
*/ | ||
int telnet_server_read(void* buffer, size_t count); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* NET_TELNET_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2021 ML!PA Consulting GmbH | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup sys | ||
* @{ | ||
* | ||
* @file | ||
* @brief STDIO over Telnet implementation | ||
* | ||
* This file implements STDIO via a Telnet server with fallback UART output | ||
* | ||
* @author Benjamin Valentin <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <errno.h> | ||
|
||
#include "board.h" | ||
#include "kernel_defines.h" | ||
#include "net/telnet.h" | ||
#if IS_USED(MODULE_PERIPH_UART) | ||
#include "stdio_uart.h" | ||
#include "periph/uart.h" | ||
#endif | ||
#if IS_USED(MODULE_VFS) | ||
#include "vfs.h" | ||
#endif | ||
|
||
#define ENABLE_DEBUG 0 | ||
#include "debug.h" | ||
|
||
static inline void _init_fallback(void) | ||
{ | ||
#if defined(STDIO_UART_DEV) && IS_USED(MODULE_PERIPH_UART) | ||
uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, NULL, NULL); | ||
#endif | ||
} | ||
|
||
static inline int _write_fallback(const void* buffer, size_t len) | ||
{ | ||
#if defined(STDIO_UART_DEV) && IS_USED(MODULE_PERIPH_UART) | ||
uart_write(STDIO_UART_DEV, buffer, len); | ||
#else | ||
(void)buffer; | ||
#endif | ||
|
||
return len; | ||
} | ||
|
||
void stdio_init(void) | ||
{ | ||
_init_fallback(); | ||
|
||
#if IS_USED(MODULE_VFS) | ||
vfs_bind_stdio(); | ||
#endif | ||
} | ||
|
||
ssize_t stdio_read(void* buffer, size_t count) | ||
{ | ||
return telnet_server_read(buffer, count); | ||
} | ||
|
||
ssize_t stdio_write(const void* buffer, size_t len) | ||
{ | ||
int res = telnet_server_write(buffer, len); | ||
if (res != -ENOTCONN) { | ||
return res; | ||
} | ||
|
||
return _write_fallback(buffer, len); | ||
} |
Oops, something went wrong.