Browse Source

cc3200: Improve usability and robustness of the servers.

pull/1166/head
danicampora 10 years ago
parent
commit
77791b5633
  1. 27
      cc3200/ftp/ftp.c
  2. 2
      cc3200/ftp/ftp.h
  3. 56
      cc3200/mods/modwlan.c
  4. 33
      cc3200/serverstask.c
  5. 1
      cc3200/serverstask.h
  6. 45
      cc3200/telnet/telnet.c
  7. 1
      cc3200/telnet/telnet.h

27
cc3200/ftp/ftp.c

@ -66,8 +66,8 @@
#define FTP_UNIX_TIME_20000101 946684800
#define FTP_UNIX_TIME_20150101 1420070400
#define FTP_UNIX_SECONDS_180_DAYS 15552000
#define FTP_DATA_TIMEOUT_MS 5000 // 5 seconds
#define FTP_CMD_TIMEOUT_MS 120000 // 2 minutes
#define FTP_DATA_TIMEOUT_MS 5000 // 5 seconds
#define FTP_CMD_TIMEOUT_MS 300000 // 5 minutes
#define FTP_SOCKETFIFO_ELEMENTS_MAX 4
#define FTP_CYCLE_TIME_MS (SERVERS_CYCLE_TIME_MS * 2)
@ -119,6 +119,7 @@ typedef enum {
typedef struct {
uint8_t *dBuffer;
uint32_t ctimeout;
union {
DIR dp;
FIL fp;
@ -126,7 +127,6 @@ typedef struct {
int16_t lc_sd;
int16_t ld_sd;
int16_t c_sd;
int16_t ctimeout;
int16_t d_sd;
int16_t dtimeout;
ftp_state_t state;
@ -212,7 +212,6 @@ static void ftp_process_cmd (void);
static void ftp_close_files (void);
static void ftp_close_filesystem_on_error (void);
static void ftp_close_cmd_data (void);
static void ftp_reset (void);
static ftp_cmd_index_t ftp_pop_command (char **str);
static void ftp_pop_param (char **str, char *param);
static int ftp_print_eplf_item (char *dest, uint32_t destsize, FILINFO *fno);
@ -406,6 +405,16 @@ void ftp_disable (void) {
ftp_data.state = E_FTP_STE_DISABLED;
}
void ftp_reset (void) {
// close all connections and start all over again
servers_close_socket(&ftp_data.lc_sd);
servers_close_socket(&ftp_data.ld_sd);
ftp_close_cmd_data();
ftp_data.state = E_FTP_STE_START;
ftp_data.substate.data = E_FTP_STE_SUB_DISCONNECTED;
SOCKETFIFO_Flush();
}
/******************************************************************************
DEFINE PRIVATE FUNCTIONS
******************************************************************************/
@ -848,16 +857,6 @@ static void ftp_close_cmd_data (void) {
ftp_close_filesystem_on_error ();
}
static void ftp_reset (void) {
// close all connections and start all over again
servers_close_socket(&ftp_data.lc_sd);
servers_close_socket(&ftp_data.ld_sd);
ftp_close_cmd_data();
ftp_data.state = E_FTP_STE_START;
ftp_data.substate.data = E_FTP_STE_SUB_DISCONNECTED;
SOCKETFIFO_Flush();
}
static ftp_cmd_index_t ftp_pop_command (char **str) {
char _cmd[FTP_CMD_SIZE_MAX];
ftp_pop_param (str, _cmd);

2
cc3200/ftp/ftp.h

@ -34,4 +34,6 @@ extern void ftp_init (void);
extern void ftp_run (void);
extern void ftp_enable (void);
extern void ftp_disable (void);
extern void ftp_reset (void);
#endif /* FTP_H_ */

56
cc3200/mods/modwlan.c

@ -78,21 +78,22 @@ typedef enum{
}e_StatusBits;
typedef struct _wlan_obj_t {
mp_obj_base_t base;
SlWlanMode_t mode;
uint32_t status;
mp_obj_base_t base;
SlWlanMode_t mode;
uint32_t status;
uint32_t ip;
uint32_t gateway;
uint32_t dns;
uint32_t ip;
uint32_t gateway;
uint32_t dns;
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
bool servers_enabled;
bool servers_enabled;
#endif
uint8_t security;
uint8_t mac[SL_MAC_ADDR_LEN];
uint8_t ssid[33];
uint8_t bssid[6];
uint8_t security;
uint8_t mac[SL_MAC_ADDR_LEN];
uint8_t ssid[33];
uint8_t bssid[6];
volatile uint8_t stasconnected;
} wlan_obj_t;
@ -162,6 +163,7 @@ STATIC wlan_obj_t wlan_obj = {
.ssid = {0},
.bssid = {0},
.mac = {0},
.stasconnected = 0,
};
STATIC const mp_cb_methods_t wlan_cb_methods;
@ -193,7 +195,7 @@ STATIC void wlan_lpds_callback_disable (mp_obj_t self_in);
//*****************************************************************************
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
{
if(!pWlanEvent) {
if (!pWlanEvent) {
return;
}
@ -202,44 +204,34 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
case SL_WLAN_CONNECT_EVENT:
{
SET_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION);
//
// Information about the connected AP (like name, MAC etc) will be
// available in 'slWlanConnectAsyncResponse_t'-Applications
// can use it if required
//
slWlanConnectAsyncResponse_t *pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
// Copy new connection SSID and BSSID to global parameters
// copy the new connection data
memcpy(wlan_obj.ssid, pEventData->ssid_name, pEventData->ssid_len);
memcpy(wlan_obj.bssid, pEventData->bssid, SL_BSSID_LENGTH);
}
break;
case SL_WLAN_DISCONNECT_EVENT:
{
slWlanConnectAsyncResponse_t* pEventData = NULL;
CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION);
CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED);
pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;
// If the user has initiated the 'Disconnect' request,
//'reason_code' is SL_USER_INITIATED_DISCONNECTION
if (SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code) {
// TODO ...
}
else {
// TODO: Maybe trow an exception?
}
memset(wlan_obj.ssid, 0, sizeof(wlan_obj.ssid));
memset(wlan_obj.bssid, 0, sizeof(wlan_obj.bssid));
}
break;
case SL_WLAN_STA_CONNECTED_EVENT:
// TODO
wlan_obj.stasconnected++;
break;
case SL_WLAN_STA_DISCONNECTED_EVENT:
// TODO
if (wlan_obj.stasconnected > 0) {
if (--wlan_obj.stasconnected == 0) {
#if (MICROPY_PORT_HAS_TELNET || MICROPY_PORT_HAS_FTP)
servers_reset();
#endif
}
}
break;
case SL_WLAN_P2P_DEV_FOUND_EVENT:
// TODO

33
cc3200/serverstask.c

@ -54,12 +54,13 @@ typedef struct {
volatile bool enabled;
volatile bool do_disable;
volatile bool do_enable;
volatile bool do_reset;
}servers_Data_t;
/******************************************************************************
DECLARE PRIVATE DATA
******************************************************************************/
static servers_Data_t servers_data = {.enabled = false, .do_disable = false, .do_enable = false};
static servers_Data_t servers_data = {.enabled = false, .do_disable = false, .do_enable = false, .do_reset = false};
/******************************************************************************
DECLARE PRIVATE FUNCTIONS
@ -74,7 +75,6 @@ char *servers_pass;
/******************************************************************************
DECLARE PUBLIC FUNCTIONS
******************************************************************************/
void TASK_Servers (void *pvParameters) {
bool cycle = false;
@ -91,14 +91,21 @@ void TASK_Servers (void *pvParameters) {
if (servers_data.enabled) {
if (servers_data.do_disable) {
servers_data.do_disable = false;
// disable all net processes
// disable network services
telnet_disable();
ftp_disable();
// now clear the flag
// now clear the flags
servers_data.do_disable = false;
servers_data.do_reset = false;
servers_data.enabled = false;
}
else if (servers_data.do_reset) {
// reset network services
telnet_reset();
ftp_reset();
// clear the flag
servers_data.do_reset = false;
}
else {
if (cycle) {
telnet_run();
@ -109,15 +116,15 @@ void TASK_Servers (void *pvParameters) {
}
}
else if (servers_data.do_enable) {
servers_data.do_enable = false;
// enable network services
telnet_enable();
ftp_enable();
// now set the flag
// now set/clear the flags
servers_data.enabled = true;
servers_data.do_enable = false;
}
// move to the next cycle
cycle = cycle ? false : true;
HAL_Delay(SERVERS_CYCLE_TIME_MS);
// set the alive flag for the wdt
@ -130,12 +137,18 @@ void servers_start (void) {
servers_data.do_enable = true;
}
void servers_reset (void) {
servers_data.do_reset = true;
}
void servers_stop (void) {
servers_data.do_enable = false;
servers_data.do_disable = true;
do {
HAL_Delay (SERVERS_CYCLE_TIME_MS);
} while (servers_are_enabled());
// clear the last command line
telnet_reset();
}
bool servers_are_enabled (void) {

1
cc3200/serverstask.h

@ -61,6 +61,7 @@ extern char *servers_pass;
******************************************************************************/
extern void TASK_Servers (void *pvParameters);
extern void servers_start (void);
extern void servers_reset (void);
extern void servers_stop (void);
extern bool servers_are_enabled (void);
extern void servers_close_socket (int16_t *sd);

45
cc3200/telnet/telnet.c

@ -48,7 +48,7 @@
#define TELNET_TX_RETRIES_MAX 25
#define TELNET_WAIT_TIME_MS 7
#define TELNET_LOGIN_RETRIES_MAX 3
#define TELNET_TIMEOUT_MS 300000 // 5 minutes
#define TELNET_TIMEOUT_MS 1800000 // 30 minutes
#define TELNET_CYCLE_TIME_MS (SERVERS_CYCLE_TIME_MS * 2)
/******************************************************************************
@ -87,11 +87,11 @@ typedef union {
typedef struct {
uint8_t *rxBuffer;
uint32_t timeout;
int16_t sd;
int16_t n_sd;
int16_t rxWindex;
int16_t rxRindex;
uint16_t timeout;
telnet_state_t state;
telnet_substate_t substate;
uint8_t txRetries;
@ -128,7 +128,7 @@ static telnet_result_t telnet_recv_text_non_blocking (void *buff, _i16 Maxlen, _
static void telnet_process (void);
static void telnet_parse_input (uint8_t *str, int16_t *len);
static bool telnet_send_with_retries (int16_t sd, const void *pBuf, int16_t len);
static void telnet_reset (void);
static void telnet_reset_buffer (void);
/******************************************************************************
DEFINE PUBLIC FUNCTIONS
@ -162,6 +162,8 @@ void telnet_run (void) {
telnet_send_and_proceed((void *)telnet_options_user, sizeof(telnet_options_user), E_TELNET_STE_SUB_REQ_USER);
break;
case E_TELNET_STE_SUB_REQ_USER:
// to catch any left over characters from the previous actions
telnet_recv_text_non_blocking(telnet_data.rxBuffer, TELNET_RX_BUFFER_SIZE, &rxLen);
telnet_send_and_proceed((void *)telnet_request_user, strlen(telnet_request_user), E_TELNET_STE_SUB_GET_USER);
break;
case E_TELNET_STE_SUB_GET_USER:
@ -170,20 +172,20 @@ void telnet_run (void) {
if (rxLen < 2 || memcmp(servers_user, (const char *)telnet_data.rxBuffer, MAX((rxLen - 2), strlen(servers_user)))) {
telnet_data.credentialsValid = false;
}
telnet_data.substate.connected = E_TELNET_STE_SUB_SND_PASSWORD_OPTIONS;
telnet_data.substate.connected = E_TELNET_STE_SUB_REQ_PASSWORD;
}
break;
case E_TELNET_STE_SUB_SND_PASSWORD_OPTIONS:
telnet_send_and_proceed((void *)telnet_options_pass, sizeof(telnet_options_pass), E_TELNET_STE_SUB_REQ_PASSWORD);
break;
case E_TELNET_STE_SUB_REQ_PASSWORD:
telnet_send_and_proceed((void *)telnet_request_password, strlen(telnet_request_password), E_TELNET_STE_SUB_GET_PASSWORD);
// to catch a possible "/r/n" that was left
telnet_send_and_proceed((void *)telnet_request_password, strlen(telnet_request_password), E_TELNET_STE_SUB_SND_PASSWORD_OPTIONS);
break;
case E_TELNET_STE_SUB_SND_PASSWORD_OPTIONS:
// to catch any left over characters from the previous actions
telnet_recv_text_non_blocking(telnet_data.rxBuffer, TELNET_RX_BUFFER_SIZE, &rxLen);
telnet_send_and_proceed((void *)telnet_options_pass, sizeof(telnet_options_pass), E_TELNET_STE_SUB_GET_PASSWORD);
break;
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)) {
// Skip /r/n
// skip /r/n
if (rxLen < 2 || memcmp(servers_pass, (const char *)telnet_data.rxBuffer, MAX((rxLen - 2), strlen(servers_pass)))) {
telnet_data.credentialsValid = false;
}
@ -211,7 +213,9 @@ void telnet_run (void) {
break;
case E_TELNET_STE_SUB_LOGGIN_SUCCESS:
if (E_TELNET_RESULT_OK == telnet_send_non_blocking((void *)telnet_loggin_success, strlen(telnet_loggin_success))) {
// fake "enter" key pressed to display the prompt
// clear the current line
telnet_reset_buffer();
// fake an "enter" key pressed to display the prompt
telnet_data.rxBuffer[telnet_data.rxWindex++] = '\r';
telnet_data.state= E_TELNET_STE_LOGGED_IN;
}
@ -282,6 +286,13 @@ void telnet_disable (void) {
telnet_data.state = E_TELNET_STE_DISABLED;
}
void telnet_reset (void) {
// close the connection and start all over again
servers_close_socket(&telnet_data.n_sd);
servers_close_socket(&telnet_data.sd);
telnet_data.state = E_TELNET_STE_START;
}
bool telnet_is_enabled (void) {
return telnet_data.enabled;
}
@ -389,7 +400,6 @@ static telnet_result_t telnet_send_non_blocking (void *data, _i16 Len) {
static telnet_result_t telnet_recv_text_non_blocking (void *buff, _i16 Maxlen, _i16 *rxLen) {
*rxLen = sl_Recv(telnet_data.n_sd, buff, Maxlen, 0);
// if there's data received, parse it
if (*rxLen > 0) {
telnet_data.timeout = 0;
@ -446,7 +456,6 @@ static void telnet_parse_input (uint8_t *str, int16_t *len) {
static bool telnet_send_with_retries (int16_t sd, const void *pBuf, int16_t len) {
int32_t retries = 0;
// abort sending if we happen to be within interrupt context
if ((HAL_NVIC_INT_CTRL_REG & HAL_VECTACTIVE_MASK) == 0) {
do {
@ -460,13 +469,11 @@ static bool telnet_send_with_retries (int16_t sd, const void *pBuf, int16_t len)
HAL_Delay (TELNET_WAIT_TIME_MS);
} while (++retries <= TELNET_TX_RETRIES_MAX);
}
return false;
}
static void telnet_reset (void) {
// close the connection and start all over again
servers_close_socket(&telnet_data.n_sd);
servers_close_socket(&telnet_data.sd);
telnet_data.state = E_TELNET_STE_START;
static void telnet_reset_buffer (void) {
memset (telnet_data.rxBuffer, '\b', TELNET_RX_BUFFER_SIZE / 2);
telnet_data.rxWindex = TELNET_RX_BUFFER_SIZE / 2;
}

1
cc3200/telnet/telnet.h

@ -38,6 +38,7 @@ extern bool telnet_rx_any (void);
extern int telnet_rx_char (void);
extern void telnet_enable (void);
extern void telnet_disable (void);
extern void telnet_reset (void);
extern bool telnet_is_enabled (void);
extern bool telnet_is_active (void);

Loading…
Cancel
Save