VT100 Terminal App
Circle VT100 module documentation
Loading...
Searching...
No Matches
TWlanLog.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Module: CTWlanLog
3// Description: Provides a WLAN-backed logging sink and telnet-style mirror.
4// Author: R. Zuehlsdorff, ralf.zuehlsdorff@t-online.de
5// Created: 2026-02-02
6// License: MIT License (https://opensource.org/license/mit/)
7//------------------------------------------------------------------------------
8// Change Log:
9// 2026-02-02 R. Zuehlsdorff Initial creation
10//------------------------------------------------------------------------------
11
12#pragma once
13
14// Circle core components
15#include <circle/device.h>
16#include <circle/net/ipaddress.h>
17#include <circle/net/netsubsystem.h>
18#include <circle/net/socket.h>
19#include <circle/sched/task.h>
20#include <circle/spinlock.h>
21#include <circle/string.h>
22#include <circle/types.h>
23
33// Forward declarations
34class CLogger;
35class CBcm4343Device;
36class CWPASupplicant;
37
46class CTWlanLog : public CDevice, public CTask
47{
48public:
50 static CTWlanLog *Get();
51
53 CTWlanLog();
55 ~CTWlanLog() override;
56
58 bool Initialize(CBcm4343Device &wlan,
59 CNetSubSystem &net,
60 CWPASupplicant &supplicant,
61 CLogger &logger,
62 unsigned port,
63 CDevice *fallback);
64
66 void SetFallback(CDevice *fallback);
67
69 bool Start();
71 void Stop();
73 bool IsClientConnected() const;
75 bool IsHostModeActive() const;
76
78 void Send(const char *buffer, size_t length);
80 bool SendHostData(const char *buffer, size_t length);
82 void SendLine(const char *line);
84 void SendCommandPrompt();
85
87 int Write(const void *buffer, size_t count) override;
88
90 void Run() override;
91
92protected:
94 virtual void ProcessLine(const char *line);
95
96private:
97 enum ETelnetRxState
98 {
99 TelnetStateData,
100 TelnetStateIAC,
101 TelnetStateCommand,
102 TelnetStateSubnegotiation,
103 TelnetStateSubnegotiationIAC
104 };
105
107 bool EnsureListenSocket();
109 void AcceptClient();
111 void CloseClient(const char *reason, bool sendLocked = false);
113 void HandleIncomingData();
115 void HandleIncomingByte(u8 byte);
117 void HandleCommandChar(char ch);
119 bool HandleTelnetByte(u8 byte);
121 void SendTelnetCommand(u8 verb, u8 option);
123 void SendTelnetNegotiation();
125 void AnnounceConnection(const CIPAddress &remoteIP, u16 remotePort);
127 void ResetConnectionState();
128
129private:
130 static CTWlanLog *s_pInstance;
131
132 CBcm4343Device *m_pWlan;
133 CNetSubSystem *m_pNet;
134 CLogger *m_pLogger;
135 CWPASupplicant *m_pSupplicant;
136 CDevice *m_pFallback;
137 unsigned m_Port;
138
139 CSocket *m_pListenSocket;
140 CSocket *m_pClientSocket;
141
142 bool m_Initialized;
143 bool m_Activated;
144 bool m_StopRequested;
145 bool m_LoggerAttached;
146 bool m_RemoteLoggingActive;
147 bool m_HostModeActive;
148 bool m_CommandPromptVisible;
149 bool m_LogLastWasCR;
150 bool m_CloseRequested;
151 bool m_LastRxWasCR;
152 bool m_TelnetNegotiated;
153 ETelnetRxState m_TelnetRxState;
154 u8 m_TelnetCommand;
155
156 CString m_RxLineBuffer;
157 mutable CSpinLock m_ConnectionLock;
158 mutable CSpinLock m_SendLock;
159};
Network logging endpoint streaming log traffic to remote clients.
Definition TWlanLog.h:47
bool IsHostModeActive() const
Check whether active session is in TCP host bridge mode.
Definition TWlanLog.cpp:245
bool Initialize(CBcm4343Device &wlan, CNetSubSystem &net, CWPASupplicant &supplicant, CLogger &logger, unsigned port, CDevice *fallback)
Initialize sockets, WLAN hardware access and logger integration.
Definition TWlanLog.cpp:121
virtual void ProcessLine(const char *line)
Hook for processing complete log lines before transmit.
Definition TWlanLog.cpp:576
static CTWlanLog * Get()
Access the singleton WLAN log device.
Definition TWlanLog.cpp:68
~CTWlanLog() override
Ensure graceful shutdown of sockets.
Definition TWlanLog.cpp:108
CTWlanLog()
Construct the WLAN logging task.
Definition TWlanLog.cpp:77
bool SendHostData(const char *buffer, size_t length)
Send host-bound data when host bridge mode is active.
Definition TWlanLog.cpp:287
bool Start()
Start accepting clients and attach to the logger.
Definition TWlanLog.cpp:197
void Run() override
Scheduler entry point handling socket activity.
Definition TWlanLog.cpp:403
void Stop()
Stop serving remote clients and detach from logger.
Definition TWlanLog.cpp:224
void SendCommandPrompt()
Send the command-mode prompt to the active client.
Definition TWlanLog.cpp:316
void SendLine(const char *line)
Send a newline-terminated string to the client.
Definition TWlanLog.cpp:303
int Write(const void *buffer, size_t count) override
Write intercepted log output to the remote client and fallback.
Definition TWlanLog.cpp:323
bool IsClientConnected() const
Check whether a remote client is currently connected.
Definition TWlanLog.cpp:237
void SetFallback(CDevice *fallback)
Change the fallback logging device for pass-through output.
Definition TWlanLog.cpp:192
void Send(const char *buffer, size_t length)
Send raw data to the active client if present.
Definition TWlanLog.cpp:250