Skip to content

Commit 85c0547

Browse files
committed
Fix ScanNetworks list
1 parent 4ed671b commit 85c0547

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

wifiHD/Release/wifiHD.elf

331 Bytes
Binary file not shown.

wifiHD/src/ard_spi.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676

7777
extern void tcp_debug_print_pcbs(void);
7878
extern bool ifStatus;
79+
extern bool scanNetCompleted;
7980

8081
static char buf[CMD_MAX_LEN];
8182
static char reply[REPLY_MAX_LEN];
@@ -1004,22 +1005,45 @@ static void copy_network_list(struct wl_network_list_t *dst,
10041005
}
10051006
}
10061007

1008+
int start_scan_net_cmd_cb(int numParam, char* buf, void* ctx) {
1009+
wl_err_t err = WL_FAILURE;
1010+
1011+
INFO_SPI("Start Network Scan %d\n", numParam);
1012+
if (scanNetCompleted){
1013+
scanNetCompleted = false;
1014+
err = wl_scan();
1015+
if (err != WL_SUCCESS)
1016+
{
1017+
// May be busy scanning already, no fatal error
1018+
WARN("err=%d\n", err);
1019+
err = WL_SUCCESS;
1020+
}
1021+
}
1022+
return err;
1023+
}
10071024

10081025
cmd_spi_state_t get_reply_scan_networks_cb(char* recv, char* reply, void* ctx, uint16_t* count) {
10091026

1010-
INFO_SPI("netif:0x%x\n", ard_netif);
1011-
CHECK_ARD_NETIF(recv, reply, count);
1027+
const int8_t SCAN_NOT_YET_COMPLETED = 0;
10121028

1013-
int network_cnt = 0;
1029+
if (!scanNetCompleted)
1030+
{
1031+
//return empty list with an error to retry
1032+
CREATE_HEADER_REPLY(reply, recv, SCAN_NOT_YET_COMPLETED);
1033+
END_HEADER_REPLY(reply, 3, *count);
1034+
INFO_SPI("Scan not completed!\n");
1035+
return SPI_CMD_DONE;
1036+
}
10141037

1038+
int network_cnt = 0;
10151039
struct wl_network_list_t* wl_network_list;
10161040

1017-
wl_scan();
10181041
wl_get_network_list(&wl_network_list);
10191042
if (wl_network_list->cnt == 0)
10201043
{
10211044
CREATE_HEADER_REPLY(reply, recv, 0);
10221045
END_HEADER_REPLY(reply, 3, *count);
1046+
INFO_SPI("Networks not found!\n");
10231047
return SPI_CMD_DONE;
10241048
}
10251049

@@ -1354,6 +1378,7 @@ void init_spi_cmds() {
13541378
spi_add_cmd(GET_CURR_BSSID_CMD, ack_cmd_cb, get_reply_curr_net_cb, (void*)GET_CURR_BSSID_CMD, CMD_GET_FLAG);
13551379
spi_add_cmd(GET_CURR_RSSI_CMD, ack_cmd_cb, get_reply_curr_net_cb, (void*)GET_CURR_RSSI_CMD, CMD_GET_FLAG);
13561380
spi_add_cmd(GET_CURR_ENCT_CMD, ack_cmd_cb, get_reply_curr_net_cb, (void*)GET_CURR_ENCT_CMD, CMD_GET_FLAG);
1381+
spi_add_cmd(START_SCAN_NETWORKS, start_scan_net_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
13571382
spi_add_cmd(SCAN_NETWORKS, ack_cmd_cb, get_reply_scan_networks_cb, NULL, CMD_GET_FLAG);
13581383
spi_add_cmd(DISCONNECT_CMD, disconnect_cmd_cb, ack_reply_cb, NULL, CMD_SET_FLAG);
13591384
spi_add_cmd(GET_IDX_ENCT_CMD, ack_cmd_cb, get_reply_idx_net_cb, (void*)GET_IDX_ENCT_CMD, CMD_GET_FLAG);

wifiHD/src/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ struct ctx_server {
8484
};
8585

8686
bool ifStatus = false;
87+
bool scanNetCompleted = false;
8788

8889
// to maintain the word alignment
8990
//#define PAD_CTX_SIZE 0x18
@@ -105,6 +106,7 @@ wl_cm_scan_cb(void* ctx)
105106
{
106107
INFO_INIT("Scan Completed!\n");
107108
set_result(WL_SCAN_COMPLETED);
109+
scanNetCompleted=true;
108110
}
109111

110112
/**
@@ -336,7 +338,7 @@ wl_init_complete_cb(void* ctx)
336338

337339
INFO_INIT("Starting CM...\n");
338340
/* start connection manager */
339-
wl_status = wl_cm_init(NULL, wl_cm_conn_cb, wl_cm_disconn_cb, hs);
341+
wl_status = wl_cm_init(wl_cm_scan_cb, wl_cm_conn_cb, wl_cm_disconn_cb, hs);
340342
ASSERT(wl_status == WL_SUCCESS, "failed to init wl conn mgr");
341343
wl_cm_start();
342344

wifiHD/src/wifi_spi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ enum {
5353
GET_IDX_ENCT_CMD = 0x33,
5454
REQ_HOST_BY_NAME_CMD= 0x34,
5555
GET_HOST_BY_NAME_CMD= 0x35,
56+
START_SCAN_NETWORKS = 0x36,
57+
5658
// All command with DATA_FLAG 0x40 send a 16bit Len
5759

5860
SEND_DATA_TCP_CMD = 0x44,

0 commit comments

Comments
 (0)