Skip to content

Commit

Permalink
Merge pull request #500 from hello/wifi-reset-new
Browse files Browse the repository at this point in the history
handle bad passwords more gracefully coming out of factory reset
  • Loading branch information
plasticchris committed May 10, 2016
2 parents 8657487 + 59494c0 commit f9d73f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
11 changes: 8 additions & 3 deletions kitsune/ble_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ static void _reply_wifi_scan_result()
int force_data_push();
static bool _set_wifi(const char* ssid, const char* password, int security_type, int version, int app_version)
{
int i;
int i,idx;
idx = -1;

LOGI("Connecting to WIFI %s\n", ssid );
xSemaphoreTake(_wifi_smphr, portMAX_DELAY);
Expand All @@ -223,7 +224,7 @@ static bool _set_wifi(const char* ssid, const char* password, int security_type,
nwp_reset();
wifi_state_requested = true;

if(connect_wifi(ssid, password, security_type, version, false) < 0)
if(connect_wifi(ssid, password, security_type, version, &idx, false) < 0)
{
LOGI("failed to connect\n");
ble_reply_protobuf_error(ErrorType_WLAN_CONNECTION_ERROR);
Expand All @@ -246,6 +247,10 @@ static bool _set_wifi(const char* ssid, const char* password, int security_type,
}

if( ++to > 6 ) {
if( idx != -1 ) {
sl_WlanProfileDel(idx);
nwp_reset();
}
LOGI("wifi timeout\n");
wifi_state_requested = false;
ble_reply_protobuf_error(ErrorType_SERVER_CONNECTION_TIMEOUT);
Expand Down Expand Up @@ -284,7 +289,7 @@ static bool _set_wifi(const char* ssid, const char* password, int security_type,
} else {
bool connection_ret = false;
//play_led_progress_bar(0xFF, 128, 0, 128,portMAX_DELAY);
connect_wifi(ssid, password, security_type, version, false);
connect_wifi(ssid, password, security_type, version, &idx, false);
if(!connection_ret)
{
LOGI("Tried all wifi ep, all failed to connect\n");
Expand Down
11 changes: 7 additions & 4 deletions kitsune/wifi_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,11 +646,13 @@ int Cmd_disconnect(int argc, char *argv[]) {
return (0);
}
int Cmd_connect(int argc, char *argv[]) {
int idx;

if (argc != 4) {
LOGF(
"usage: connect <ssid> <key> <security: 0=open, 1=wep, 2=wpa>\n\r");
}
connect_wifi( argv[1], argv[2], atoi(argv[3]), 1, true );
connect_wifi( argv[1], argv[2], atoi(argv[3]), 1, &idx, true );
return (0);
}
int Cmd_setDns(int argc, char *argv[]) {
Expand Down Expand Up @@ -2535,16 +2537,17 @@ SlSecParams_t make_sec_params(const char* ssid, const char* password, int sec_ty
}
return secParam;
}
int connect_wifi(const char* ssid, const char* password, int sec_type, int version, bool save)
int connect_wifi(const char* ssid, const char* password, int sec_type, int version, int * idx, bool save)
{
static uint32_t priority = 0;
int16_t ret = 0;
SlSecParams_t secParam = make_sec_params(ssid, password, sec_type, version);

ret = sl_WlanConnect((_i8*) ssid, strlen(ssid), NULL, sec_type == SL_SEC_TYPE_OPEN ? NULL : &secParam, 0);

if( save ) {
sl_WlanProfileAdd((_i8*) ssid, strlen(ssid), NULL,
&secParam, NULL, 0, 0);
*idx = sl_WlanProfileAdd((_i8*) ssid, strlen(ssid), NULL,
&secParam, NULL, ++priority, 0);
}
if(ret == 0 || ret == -71)
{
Expand Down
2 changes: 1 addition & 1 deletion kitsune/wifi_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ int send_data_pb( char* host, const char* path, char ** recv_buf_ptr,

int get_wifi_scan_result(Sl_WlanNetworkEntry_t* entries, uint16_t entry_len, uint32_t scan_duration_ms, int antenna);
SlSecParams_t make_sec_params(const char* ssid, const char* password, int sec_type, int version);
int connect_wifi(const char* ssid, const char* password, int sec_type, int version, bool save);
int connect_wifi(const char* ssid, const char* password, int sec_type, int version, int * idx, bool save);
void wifi_get_connected_ssid(uint8_t* ssid_buffer, size_t len);

long nwp_reset();
Expand Down

0 comments on commit f9d73f5

Please sign in to comment.