MCPcopy Create free account
hub / github.com/BruceDevices/firmware / sshWorkerTask

Function sshWorkerTask

src/modules/wifi/clients.cpp:761–983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

759}
760
761void sshWorkerTask(void *pvParameters) {
762 std::unique_ptr<char[]> buffer(new char[CLIENT_IO_BUFFER_SIZE]);
763 int strictHostKeyChecking = 0;
764 ssh_session sshSession = nullptr;
765 ssh_channel sshChannel = nullptr;
766 bool stdoutPollingEnabled = true;
767 bool stderrPollingEnabled = true;
768 if (!buffer) {
769 markSessionClosed("SSH buffer allocation failed.", true);
770 goto SSH_EXIT;
771 }
772
773 markSessionConnecting();
774
775 sshSession = ssh_new();
776 if (sshSession == nullptr) {
777 markSessionClosed("SSH session creation failed.", true);
778 goto SSH_EXIT;
779 }
780
781 ssh_options_set(sshSession, SSH_OPTIONS_HOST, sessionHost.c_str());
782 ssh_options_set(sshSession, SSH_OPTIONS_PORT, &sessionPort);
783 ssh_options_set(sshSession, SSH_OPTIONS_USER, sessionUser.c_str());
784 ssh_options_set(sshSession, SSH_OPTIONS_KNOWNHOSTS, SSH_USER_KNOWN_HOSTS_PATH);
785 ssh_options_set(sshSession, SSH_OPTIONS_GLOBAL_KNOWNHOSTS, SSH_GLOBAL_KNOWN_HOSTS_PATH);
786 ssh_options_set(sshSession, SSH_OPTIONS_STRICTHOSTKEYCHECK, &strictHostKeyChecking);
787
788 if (WiFi.status() != WL_CONNECTED) {
789 markSessionClosed("WiFi disconnected before SSH connect.", true);
790 goto SSH_EXIT;
791 }
792
793 Serial.printf(
794 "[SSHDBG] connect start host=%s port=%u user=%s\n",
795 sessionHost.c_str(),
796 sessionPort,
797 sessionUser.c_str()
798 );
799 if (ssh_connect(sshSession) != SSH_OK) {
800 markSessionClosed("SSH connect error.", true);
801 goto SSH_EXIT;
802 }
803 Serial.printf("[SSHDBG] connect ok\n");
804
805 if (ssh_userauth_password(sshSession, nullptr, ssh_password.c_str()) != SSH_AUTH_SUCCESS) {
806 markSessionClosed("SSH authentication error.", true);
807 goto SSH_EXIT;
808 }
809 Serial.printf("[SSHDBG] auth ok\n");
810
811 sshChannel = ssh_channel_new(sshSession);
812 if (sshChannel == nullptr || ssh_channel_open_session(sshChannel) != SSH_OK) {
813 markSessionClosed("SSH channel open error.", true);
814 goto SSH_EXIT;
815 }
816 Serial.printf("[SSHDBG] channel open ok\n");
817
818 if (ssh_channel_request_pty_size(sshChannel, "vt100", getTerminalCols(), getTerminalRows()) != SSH_OK) {

Callers 1

ssh_loopFunction · 0.85

Calls 12

markSessionClosedFunction · 0.85
markSessionConnectingFunction · 0.85
getTerminalColsFunction · 0.85
getTerminalRowsFunction · 0.85
markSessionReadyFunction · 0.85
isStopRequestedFunction · 0.85
takeQueuedCommandFunction · 0.85
isQueuedOutputBackedUpFunction · 0.85
getQueuedOutputLengthFunction · 0.85
appendSessionOutputFunction · 0.85
setClientTaskHandleFunction · 0.85
printfMethod · 0.45

Tested by

no test coverage detected