cc3200: Reset the servers and close user sockets on WLAN disconection.

This is needed to avoid half-open connections.
This commit is contained in:
Daniel Campora 2015-05-23 19:56:22 +02:00
parent 0d31bbc7fa
commit 9f8c5456be
8 changed files with 41 additions and 26 deletions

View File

@ -224,7 +224,6 @@ static ftp_result_t ftp_list_dir (char *list, uint32_t maxlistsize, uint32_t *li
static void ftp_open_child (char *pwd, char *dir); static void ftp_open_child (char *pwd, char *dir);
static void ftp_close_child (char *pwd); static void ftp_close_child (char *pwd);
static void ftp_return_to_previous_path (char *pwd, char *dir); static void ftp_return_to_previous_path (char *pwd, char *dir);
static void ftp_reset (void);
/****************************************************************************** /******************************************************************************
DEFINE PUBLIC FUNCTIONS DEFINE PUBLIC FUNCTIONS
@ -408,6 +407,16 @@ void ftp_disable (void) {
ftp_data.state = E_FTP_STE_DISABLED; 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 DEFINE PRIVATE FUNCTIONS
******************************************************************************/ ******************************************************************************/
@ -1079,12 +1088,3 @@ static void ftp_return_to_previous_path (char *pwd, char *dir) {
} }
} }
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();
}

View File

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

View File

@ -94,7 +94,6 @@ void modusocket_enter_sleep (void) {
fd_set socketset; fd_set socketset;
int16_t maxfd = 0; int16_t maxfd = 0;
sl_LockObjLock (&modusocket_LockObj, SL_OS_WAIT_FOREVER);
for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) { for (int i = 0; i < MOD_NETWORK_MAX_SOCKETS; i++) {
int16_t sd; int16_t sd;
if ((sd = modusocket_sockets[i].sd) >= 0) { if ((sd = modusocket_sockets[i].sd) >= 0) {
@ -105,7 +104,6 @@ void modusocket_enter_sleep (void) {
// wait for any of the sockets to become ready... // wait for any of the sockets to become ready...
sl_Select(maxfd + 1, &socketset, NULL, NULL, NULL); sl_Select(maxfd + 1, &socketset, NULL, NULL, NULL);
sl_LockObjUnlock (&modusocket_LockObj);
} }
void modusocket_close_all_user_sockets (void) { void modusocket_close_all_user_sockets (void) {

View File

@ -230,7 +230,7 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
{ {
CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_CONNECTION);
CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED); CLR_STATUS_BIT(wlan_obj.status, STATUS_BIT_IP_ACQUIRED);
// TODO reset the servers servers_reset();
} }
break; break;
case SL_WLAN_STA_CONNECTED_EVENT: case SL_WLAN_STA_CONNECTED_EVENT:
@ -245,7 +245,7 @@ void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent) {
break; break;
case SL_WLAN_STA_DISCONNECTED_EVENT: case SL_WLAN_STA_DISCONNECTED_EVENT:
wlan_obj.staconnected = false; wlan_obj.staconnected = false;
// TODO reset the servers servers_reset();
break; break;
case SL_WLAN_P2P_DEV_FOUND_EVENT: case SL_WLAN_P2P_DEV_FOUND_EVENT:
// TODO // TODO

View File

@ -53,12 +53,13 @@ typedef struct {
volatile bool enabled; volatile bool enabled;
volatile bool do_disable; volatile bool do_disable;
volatile bool do_enable; volatile bool do_enable;
volatile bool do_reset;
}servers_Data_t; }servers_Data_t;
/****************************************************************************** /******************************************************************************
DECLARE PRIVATE DATA 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};
static volatile bool sleep_sockets = false; static volatile bool sleep_sockets = false;
/****************************************************************************** /******************************************************************************
@ -103,11 +104,21 @@ void TASK_Servers (void *pvParameters) {
servers_data.enabled = false; servers_data.enabled = false;
} }
if (cycle) { if (servers_data.do_reset) {
telnet_run(); telnet_reset();
ftp_reset();
servers_data.do_reset = false;
// resetting the servers is needed to preven half-open sockets
// and we should also close all user sockets
modusocket_close_all_user_sockets();
} }
else { else {
ftp_run(); if (cycle) {
telnet_run();
}
else {
ftp_run();
}
} }
// set the alive flag for the wdt // set the alive flag for the wdt
@ -137,6 +148,10 @@ void servers_stop (void) {
HAL_Delay (SERVERS_CYCLE_TIME_MS * 5); HAL_Delay (SERVERS_CYCLE_TIME_MS * 5);
} }
void servers_reset (void) {
servers_data.do_reset = true;
}
bool servers_are_enabled (void) { bool servers_are_enabled (void) {
return servers_data.enabled; return servers_data.enabled;
} }

View File

@ -56,6 +56,7 @@ extern char servers_pass[];
extern void TASK_Servers (void *pvParameters); extern void TASK_Servers (void *pvParameters);
extern void servers_start (void); extern void servers_start (void);
extern void servers_stop (void); extern void servers_stop (void);
extern void servers_reset (void);
extern bool servers_are_enabled (void); extern bool servers_are_enabled (void);
extern void servers_close_socket (int16_t *sd); extern void servers_close_socket (int16_t *sd);
extern void servers_set_login (char *user, char *pass); extern void servers_set_login (char *user, char *pass);

View File

@ -132,7 +132,6 @@ static void telnet_process (void);
static int telnet_process_credential (char *credential, _i16 rxLen); static int telnet_process_credential (char *credential, _i16 rxLen);
static void telnet_parse_input (uint8_t *str, int16_t *len); 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 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); static void telnet_reset_buffer (void);
/****************************************************************************** /******************************************************************************
@ -293,6 +292,13 @@ void telnet_disable (void) {
telnet_data.state = E_TELNET_STE_DISABLED; 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) { bool telnet_is_enabled (void) {
return telnet_data.enabled; return telnet_data.enabled;
} }
@ -499,13 +505,6 @@ static bool telnet_send_with_retries (int16_t sd, const void *pBuf, int16_t len)
return false; 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) { static void telnet_reset_buffer (void) {
// erase any characters present in the current line // erase any characters present in the current line
memset (telnet_data.rxBuffer, '\b', TELNET_RX_BUFFER_SIZE / 2); memset (telnet_data.rxBuffer, '\b', TELNET_RX_BUFFER_SIZE / 2);

View File

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