cc3200: Make telnet login procedure work with Tera Term.
This is actually a workaround Ter Term's issue of not obeying to the telnet options that the server is sending. Therefore, we must buffer chars until either a '\r' or the max length of the username/password is received.
This commit is contained in:
parent
abea1c38a9
commit
0458833072
@ -16,7 +16,7 @@ include ../py/mkenv.mk
|
|||||||
CROSS_COMPILE ?= arm-none-eabi-
|
CROSS_COMPILE ?= arm-none-eabi-
|
||||||
|
|
||||||
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -march=armv7e-m -mabi=aapcs -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion
|
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -march=armv7e-m -mabi=aapcs -mcpu=cortex-m4 -msoft-float -mfloat-abi=soft -fsingle-precision-constant -Wdouble-promotion
|
||||||
CFLAGS = -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib $(CFLAGS_CORTEX_M4)
|
CFLAGS = -Wall -Wpointer-arith -Werror -ansi -std=gnu99 -nostdlib -lgcc $(CFLAGS_CORTEX_M4)
|
||||||
CFLAGS += -g -ffunction-sections -fdata-sections -fno-common -fsigned-char -mno-unaligned-access
|
CFLAGS += -g -ffunction-sections -fdata-sections -fno-common -fsigned-char -mno-unaligned-access
|
||||||
CFLAGS += -Iboards/$(BOARD)
|
CFLAGS += -Iboards/$(BOARD)
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ static void ftp_process_cmd (void) {
|
|||||||
case E_FTP_CMD_USER:
|
case E_FTP_CMD_USER:
|
||||||
ftp_pop_param (&bufptr, ftp_scratch_buffer);
|
ftp_pop_param (&bufptr, ftp_scratch_buffer);
|
||||||
if (!memcmp(ftp_scratch_buffer, servers_user, MAX(strlen(ftp_scratch_buffer), strlen(servers_user)))) {
|
if (!memcmp(ftp_scratch_buffer, servers_user, MAX(strlen(ftp_scratch_buffer), strlen(servers_user)))) {
|
||||||
ftp_data.loggin.uservalid = true;
|
ftp_data.loggin.uservalid = true && (strlen(servers_user) == strlen(ftp_scratch_buffer));
|
||||||
}
|
}
|
||||||
ftp_send_reply(331, NULL);
|
ftp_send_reply(331, NULL);
|
||||||
break;
|
break;
|
||||||
@ -679,12 +679,13 @@ static void ftp_process_cmd (void) {
|
|||||||
ftp_pop_param (&bufptr, ftp_scratch_buffer);
|
ftp_pop_param (&bufptr, ftp_scratch_buffer);
|
||||||
if (!memcmp(ftp_scratch_buffer, servers_pass, MAX(strlen(ftp_scratch_buffer), strlen(servers_pass))) &&
|
if (!memcmp(ftp_scratch_buffer, servers_pass, MAX(strlen(ftp_scratch_buffer), strlen(servers_pass))) &&
|
||||||
ftp_data.loggin.uservalid) {
|
ftp_data.loggin.uservalid) {
|
||||||
ftp_data.loggin.passvalid = true;
|
ftp_data.loggin.passvalid = true && (strlen(servers_pass) == strlen(ftp_scratch_buffer));
|
||||||
ftp_send_reply(230, NULL);
|
if (ftp_data.loggin.passvalid) {
|
||||||
}
|
ftp_send_reply(230, NULL);
|
||||||
else {
|
break;
|
||||||
ftp_send_reply(530, NULL);
|
}
|
||||||
}
|
}
|
||||||
|
ftp_send_reply(530, NULL);
|
||||||
break;
|
break;
|
||||||
case E_FTP_CMD_PASV:
|
case E_FTP_CMD_PASV:
|
||||||
{
|
{
|
||||||
|
@ -25,15 +25,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "py/mpconfig.h"
|
#include "py/mpconfig.h"
|
||||||
#include MICROPY_HAL_H
|
#include MICROPY_HAL_H
|
||||||
#include "py/misc.h"
|
#include "py/misc.h"
|
||||||
#include "simplelink.h"
|
|
||||||
#include "serverstask.h"
|
#include "serverstask.h"
|
||||||
#include "modwlan.h"
|
#include "simplelink.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "mpexception.h"
|
|
||||||
#include "telnet.h"
|
#include "telnet.h"
|
||||||
#include "ftp.h"
|
#include "ftp.h"
|
||||||
#include "pybwdt.h"
|
#include "pybwdt.h"
|
||||||
@ -67,8 +66,8 @@ static servers_Data_t servers_data = {.enabled = false, .do_disable = false, .do
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
DECLARE PUBLIC DATA
|
DECLARE PUBLIC DATA
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
char *servers_user;
|
char servers_user[SERVERS_USER_PASS_LEN_MAX + 1];
|
||||||
char *servers_pass;
|
char servers_pass[SERVERS_USER_PASS_LEN_MAX + 1];
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
DECLARE PUBLIC FUNCTIONS
|
DECLARE PUBLIC FUNCTIONS
|
||||||
@ -77,8 +76,6 @@ void TASK_Servers (void *pvParameters) {
|
|||||||
|
|
||||||
bool cycle = false;
|
bool cycle = false;
|
||||||
|
|
||||||
ASSERT ((servers_user = mem_Malloc(SERVERS_USER_LEN_MAX + 1)) != NULL);
|
|
||||||
ASSERT ((servers_pass = mem_Malloc(SERVERS_PASS_LEN_MAX + 1)) != NULL);
|
|
||||||
strcpy (servers_user, SERVERS_DEF_USER);
|
strcpy (servers_user, SERVERS_DEF_USER);
|
||||||
strcpy (servers_pass, SERVERS_DEF_PASS);
|
strcpy (servers_pass, SERVERS_DEF_PASS);
|
||||||
|
|
||||||
@ -148,8 +145,8 @@ void servers_close_socket (int16_t *sd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void servers_set_login (char *user, char *pass) {
|
void servers_set_login (char *user, char *pass) {
|
||||||
memcpy(servers_user, user, SERVERS_USER_LEN_MAX);
|
memcpy(servers_user, user, SERVERS_USER_PASS_LEN_MAX);
|
||||||
memcpy(servers_pass, pass, SERVERS_PASS_LEN_MAX);
|
memcpy(servers_pass, pass, SERVERS_USER_PASS_LEN_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
@ -36,8 +36,7 @@
|
|||||||
#define SERVERS_SSID_LEN_MAX 16
|
#define SERVERS_SSID_LEN_MAX 16
|
||||||
#define SERVERS_KEY_LEN_MAX 16
|
#define SERVERS_KEY_LEN_MAX 16
|
||||||
|
|
||||||
#define SERVERS_USER_LEN_MAX 16
|
#define SERVERS_USER_PASS_LEN_MAX 16
|
||||||
#define SERVERS_PASS_LEN_MAX 16
|
|
||||||
|
|
||||||
#define SERVERS_CYCLE_TIME_MS 5
|
#define SERVERS_CYCLE_TIME_MS 5
|
||||||
|
|
||||||
@ -48,8 +47,8 @@
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
EXPORTED DATA
|
EXPORTED DATA
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
extern char *servers_user;
|
extern char servers_user[];
|
||||||
extern char *servers_pass;
|
extern char servers_pass[];
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
DECLARE PUBLIC FUNCTIONS
|
DECLARE PUBLIC FUNCTIONS
|
||||||
|
@ -142,6 +142,28 @@ void telnet_init (void) {
|
|||||||
telnet_data.state = E_TELNET_STE_DISABLED;
|
telnet_data.state = E_TELNET_STE_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int telnet_process_credential (char *credential, _i16 rxLen) {
|
||||||
|
telnet_data.rxWindex += rxLen;
|
||||||
|
if (telnet_data.rxWindex >= SERVERS_USER_PASS_LEN_MAX) {
|
||||||
|
telnet_data.rxWindex = SERVERS_USER_PASS_LEN_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t *p = telnet_data.rxBuffer + SERVERS_USER_PASS_LEN_MAX;
|
||||||
|
// if a '\r' is found, or the length exceeds the max username length
|
||||||
|
if ((p = memchr(telnet_data.rxBuffer, '\r', telnet_data.rxWindex)) || (telnet_data.rxWindex >= SERVERS_USER_PASS_LEN_MAX)) {
|
||||||
|
uint8_t len = p - telnet_data.rxBuffer;
|
||||||
|
|
||||||
|
telnet_data.rxWindex = 0;
|
||||||
|
if ((len > 0) && (memcmp(credential, telnet_data.rxBuffer, MAX(len, strlen(credential))) == 0)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void telnet_run (void) {
|
void telnet_run (void) {
|
||||||
_i16 rxLen;
|
_i16 rxLen;
|
||||||
switch (telnet_data.state) {
|
switch (telnet_data.state) {
|
||||||
@ -170,12 +192,14 @@ void telnet_run (void) {
|
|||||||
telnet_send_and_proceed((void *)telnet_request_user, strlen(telnet_request_user), E_TELNET_STE_SUB_GET_USER);
|
telnet_send_and_proceed((void *)telnet_request_user, strlen(telnet_request_user), E_TELNET_STE_SUB_GET_USER);
|
||||||
break;
|
break;
|
||||||
case E_TELNET_STE_SUB_GET_USER:
|
case E_TELNET_STE_SUB_GET_USER:
|
||||||
if (E_TELNET_RESULT_OK == telnet_recv_text_non_blocking(telnet_data.rxBuffer, TELNET_RX_BUFFER_SIZE, &rxLen)) {
|
if (E_TELNET_RESULT_OK == telnet_recv_text_non_blocking(telnet_data.rxBuffer + telnet_data.rxWindex,
|
||||||
// Skip /r/n
|
TELNET_RX_BUFFER_SIZE - telnet_data.rxWindex,
|
||||||
if (rxLen < 2 || memcmp(servers_user, (const char *)telnet_data.rxBuffer, MAX((rxLen - 2), strlen(servers_user)))) {
|
&rxLen)) {
|
||||||
telnet_data.credentialsValid = false;
|
int result;
|
||||||
|
if ((result = telnet_process_credential (servers_user, rxLen))) {
|
||||||
|
telnet_data.credentialsValid = result > 0 ? true : false;
|
||||||
|
telnet_data.substate.connected = E_TELNET_STE_SUB_REQ_PASSWORD;
|
||||||
}
|
}
|
||||||
telnet_data.substate.connected = E_TELNET_STE_SUB_REQ_PASSWORD;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case E_TELNET_STE_SUB_REQ_PASSWORD:
|
case E_TELNET_STE_SUB_REQ_PASSWORD:
|
||||||
@ -187,16 +211,17 @@ void telnet_run (void) {
|
|||||||
telnet_send_and_proceed((void *)telnet_options_pass, sizeof(telnet_options_pass), E_TELNET_STE_SUB_GET_PASSWORD);
|
telnet_send_and_proceed((void *)telnet_options_pass, sizeof(telnet_options_pass), E_TELNET_STE_SUB_GET_PASSWORD);
|
||||||
break;
|
break;
|
||||||
case E_TELNET_STE_SUB_GET_PASSWORD:
|
case E_TELNET_STE_SUB_GET_PASSWORD:
|
||||||
if (E_TELNET_RESULT_OK == telnet_recv_text_non_blocking(telnet_data.rxBuffer, TELNET_RX_BUFFER_SIZE, &rxLen)) {
|
if (E_TELNET_RESULT_OK == telnet_recv_text_non_blocking(telnet_data.rxBuffer + telnet_data.rxWindex,
|
||||||
// skip /r/n
|
TELNET_RX_BUFFER_SIZE - telnet_data.rxWindex,
|
||||||
if (rxLen < 2 || memcmp(servers_pass, (const char *)telnet_data.rxBuffer, MAX((rxLen - 2), strlen(servers_pass)))) {
|
&rxLen)) {
|
||||||
telnet_data.credentialsValid = false;
|
int result;
|
||||||
}
|
if ((result = telnet_process_credential (servers_pass, rxLen))) {
|
||||||
if (telnet_data.credentialsValid) {
|
if ((telnet_data.credentialsValid = telnet_data.credentialsValid && (result > 0 ? true : false))) {
|
||||||
telnet_data.substate.connected = E_TELNET_STE_SUB_SND_REPL_OPTIONS;
|
telnet_data.substate.connected = E_TELNET_STE_SUB_SND_REPL_OPTIONS;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
telnet_data.substate.connected = E_TELNET_STE_SUB_INVALID_LOGGIN;
|
telnet_data.substate.connected = E_TELNET_STE_SUB_INVALID_LOGGIN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user