static vsf_err_t usrapp_thread(struct vsfsm_pt_t *pt, vsfsm_evt_t evt)
{
struct usrapp_t *app = (struct usrapp_t *)pt->user_data;
struct vsfsm_pt_t *caller_pt = &app->caller_pt;
struct bcm_wifi_t *wifi = &app->net.wifi;
struct vsfip_netif_t *netif = &wifi->netif;
vsf_err_t err;
vsfsm_pt_begin(pt);
bcm_wifi_netif_init(wifi);
caller_pt->sm = pt->sm;
caller_pt->state = 0;
vsfsm_pt_entry(pt);
err = vsfip_netif_add(caller_pt, evt, netif);
if (err) return err;
vsfdbg_printf("wifi: f1sig = 0x%08X MAC(%d) = %02X:%02X:%02X:%02X:%02X:%02X"
VSFCFG_DEBUG_LINEEND, wifi->bus.f1sig, netif->macaddr.size,
netif->macaddr.addr.s_addr_buf[0], netif->macaddr.addr.s_addr_buf[1],
netif->macaddr.addr.s_addr_buf[2], netif->macaddr.addr.s_addr_buf[3],
netif->macaddr.addr.s_addr_buf[4], netif->macaddr.addr.s_addr_buf[5]);
bcm_sdpcm_get_iovar_buffer(&app->net.cmd_buffer, 256, BCMIOVAR_VER);
if (NULL == app->net.cmd_buffer) return VSFERR_FAIL;
caller_pt->user_data = wifi;
caller_pt->state = 0;
vsfsm_pt_entry(pt);
err = bcm_sdpcm_ioctrl(caller_pt, evt, BCM_INTERFACE_STA,
BCM_SDPCM_CMDTYPE_GET, BCMIOCTRL_GET_VAR, app->net.cmd_buffer,
&app->net.reply_buffer);
if (err > 0) return err;
else if (err < 0)
{
vsfdbg_prints("Fail to read version." VSFSHELL_LINEEND);
vsfip_buffer_release(app->net.cmd_buffer);
return err;
}
vsfip_buffer_release(app->net.cmd_buffer);
if (app->net.reply_buffer != NULL)
{
if (app->net.reply_buffer->buf.size > 0)
vsfdbg_printf("wifi: %s", app->net.reply_buffer->buf.buffer);
vsfip_buffer_release(app->net.reply_buffer);
}
#if 1
caller_pt->state = 0;
vsfsm_pt_entry(pt);
err = bcm_wifi_scan(caller_pt, evt, &app->net.reply_buffer, BCM_INTERFACE_STA);
if (err < 0) return err;
else if (app->net.reply_buffer != NULL)
{
struct bcm_wifi_escan_result_t *scan_result =
(struct bcm_wifi_escan_result_t *)app->net.reply_buffer->buf.buffer;
for (uint16_t i = 0; i < scan_result->bss_count; i++)
{
vsfdbg_printf("wifi_scan: %02X:%02X:%02X:%02X:%02X:%02X %s" VSFCFG_DEBUG_LINEEND,
scan_result->bss_info[i].bssid[0], scan_result->bss_info[i].bssid[1],
scan_result->bss_info[i].bssid[2], scan_result->bss_info[i].bssid[3],
scan_result->bss_info[i].bssid[4], scan_result->bss_info[i].bssid[5],
scan_result->bss_info[i].ssid);
}
vsfip_buffer_release(app->net.reply_buffer);
}
if (err != 0) return err;
#else
caller_pt->state = 0;
vsfsm_pt_entry(pt);
err = app->net.key != NULL ?
bcm_wifi_join(caller_pt, evt, NULL, app->net.ssid,
BCM_AUTHTYPE_WPA2_AES_PSK, (const uint8_t *)app->net.key, strlen(app->net.key)) :
bcm_wifi_join(caller_pt, evt, NULL, app->net.ssid, BCM_AUTHTYPE_OPEN, NULL, 0);
if (err) return err;
usrapp_net_on_connect(&app->net.wifi_net, bcm_wifi_get_netif(&app->net.wifi));
#endif
vsfsm_pt_end(pt);
return VSFERR_NONE;
}