/** * @brief Command line processing callback function * @param[in] session Handle referencing an SCP session * @param[in] user NULL-terminated string that contains the user name * @param[in] path Canonical path of the file * @return Permissions for the specified file **/ error_t shellServerCommandLineCallback(ShellServerSession *session, char_t *commandLine) { error_t error; // Debug message TRACE_INFO("Shell server: Command line received\r\n"); TRACE_INFO(" %s\r\n", commandLine); // Flag to control the continuous UART communication loop bool exitLoop = false; // Check command name if (!strcasecmp(commandLine, "hello")) { // Send response to the client error = shellServerWriteStream(session, "Hello World!\r\n", 14, NULL, 0); // UART output: Sending a hello message UARTCharPut(UART0_BASE, 'S'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, 'n'); UARTCharPut(UART0_BASE, 'd'); UARTCharPut(UART0_BASE, 'i'); UARTCharPut(UART0_BASE, 'n'); UARTCharPut(UART0_BASE, 'g'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, 'H'); UARTCharPut(UART0_BASE, 'e'); UARTCharPut(UART0_BASE, 'l'); UARTCharPut(UART0_BASE, 'l'); UARTCharPut(UART0_BASE, 'o'); UARTCharPut(UART0_BASE, ' '); UARTCharPut(UART0_BASE, 'W'); UARTCharPut(UART0_BASE, 'o'); UARTCharPut(UART0_BASE, 'r'); UARTCharPut(UART0_BASE, 'l'); UARTCharPut(UART0_BASE, 'd'); UARTCharPut(UART0_BASE, '!'); UARTCharPut(UART0_BASE, '\r'); UARTCharPut(UART0_BASE, '\n'); // Continuous UART communication loop while (!exitLoop) { if (UARTCharsAvail(UART0_BASE)) { char receivedChar = UARTCharGet(UART0_BASE); // Check for exit command if (receivedChar == 'e' || receivedChar == 'E') { // Check if the next characters match "exit" or "quit" char nextChar1 = UARTCharGet(UART0_BASE); char nextChar2 = UARTCharGet(UART0_BASE); if ((nextChar1 == 'x' || nextChar1 == 'X') && (nextChar2 == 'i' || nextChar2 == 'I') && (UARTCharGet(UART0_BASE) == 't' || UARTCharGet(UART0_BASE) == 'T')) { // Exit the loop exitLoop = true; break; // Exit the loop immediately } } // Echo the received character back to UART UARTCharPut(UART0_BASE, receivedChar); // Relay UART input to SSH server shellServerWriteStream(session, &receivedChar;, 1, NULL, 0); } } } else if (!strcasecmp(commandLine, "exit") || !strcasecmp(commandLine, "quit")) { // Close shell session error = ERROR_END_OF_STREAM; } else { // Unknown command received error = shellServerWriteStream(session, "Unknown command!\r\n", 18, NULL, 0); } // Return status code return error; }