FelipeMdeO commented on code in PR #3532:
URL: https://github.com/apache/nuttx-apps/pull/3532#discussion_r3409816275


##########
nshlib/nsh_dropbear.c:
##########
@@ -26,45 +26,51 @@
 
 #include <nuttx/config.h>
 
-#include <nuttx/compiler.h>
+#include <assert.h>
+#include <debug.h>
 
-#include <stdint.h>
+#include "nsh.h"
+#include "nsh_console.h"
 
-#include "nxmb_internal.h"
+#ifdef CONFIG_NSH_DROPBEAR
 
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: nxmb_lrc
+ * Name: nsh_dropbearstart
  *
  * Description:
- *   Calculate Modbus ASCII LRC checksum.
+ *   nsh_dropbearstart() starts the Dropbear SSH server.  This function
+ *   returns immediately after the daemon has been started.
  *
- * Input Parameters:
- *   buf - Pointer to data buffer
- *   len - Length of data in bytes
- *
- * Returned Value:
- *   LRC value (8-bit)
+ * Returned Values:
+ *   Zero is returned if Dropbear was started.  A negated errno value will be
+ *   returned on failure.
  *
  ****************************************************************************/
 
-uint8_t nxmb_lrc(FAR const uint8_t *buf, uint16_t len)
+#ifndef CONFIG_NSH_DISABLE_DROPBEARSTART
+int nsh_dropbearstart(void)
 {
-  uint8_t  lrc = 0;
-  uint16_t i;
+  FAR struct console_stdio_s *pstate = nsh_newconsole(false);
+  char cmdline[] = CONFIG_NETUTILS_DROPBEAR_PROGNAME " &";
+  int ret;
 
-  if (buf == NULL || len == 0)
-    {
-      return lrc;
-    }
+  DEBUGASSERT(pstate != NULL);
 
-  for (i = 0; i < len; i++)
+  ninfo("Starting the Dropbear SSH server\n");
+
+  ret = nsh_parse(&pstate->cn_vtbl, cmdline);

Review Comment:
   Hello Alan, nsh_dropbearstart() mirrors nsh_telnetstart() (nsh_telnetd.c), 
not nsh_telnetmain(). This is a bit tricky, but let me try to explain.
   
   SSH can't reuse the nsh_session() path: unlike Telnet's line protocol, each 
SSH connection multiplexes channels and the shell must run on a PTY (for 
SIGINT/Ctrl-C, window size, raw mode). So the per-session NSH is spawned inside 
the Dropbear app (dropbear_nshsession.c) over a PTY pair, with no equivalent 
nsh_session() call at the nshlib layer.
   
   We have this diff "approach" because telnet can hand the socket straight to 
nsh_session() because it's a plain-text line protocol while SSH transfer data 
uses encrypted data.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to