libs/winc1500/src/winc1500.c
/*
 * Called within winc1500 task context to report incoming events.
 */
Called within winc1500 task context to report incoming events.
Called within winc1500 task context to report incoming events .
static void
winc1500_callback(uint8_t msg_type, void *msg_data)
{
    struct winc1500 *w;
    struct wifi_if *wi;
    tstrM2mScanDone *scan_done;
    tstrM2mWifiscanResult *scan;
    tstrM2mWifiStateChanged *state;
    tstrM2MIPConfig *dhcp;
    tstrSystemTime *time;
    struct wifi_ap ap;
    int rc;
    w = &winc1500;
    wi = &w->w_if;
    switch (msg_type) {
    case M2M_WIFI_RESP_SCAN_DONE:
        if (wi->wi_state != SCANNING) {
            break;
        }
        scan_done = (tstrM2mScanDone *)msg_data;
        w->w_scan_cnt = scan_done->u8NumofCh;
        if (w->w_scan_cnt > 0) {
            w->w_scan_idx = 0;
            rc = m2m_wifi_req_scan_result(0);
            if (rc) {
                wifi_scan_done(wi, -1);
            }
        }
        break;
    case M2M_WIFI_RESP_SCAN_RESULT:
        if (wi->wi_state != SCANNING) {
            break;
        }
        scan = (tstrM2mWifiscanResult *)msg_data;
        memcpy(ap.wa_ssid, scan->au8SSID, sizeof(ap.wa_ssid));
        memcpy(ap.wa_bssid, scan->au8BSSID, sizeof(ap.wa_bssid));
        ap.wa_rssi = scan->s8rssi;
        ap.wa_key_type = scan->u8AuthType;
        ap.wa_channel = scan->u8ch;
        wifi_scan_result(wi, &ap);
        ++w->w_scan_idx;
        if (w->w_scan_idx < w->w_scan_cnt) {
            rc = m2m_wifi_req_scan_result(w->w_scan_idx);
            if (rc) {
                wifi_scan_done(wi, -1);
            }
        } else {
            wifi_scan_done(wi, 0);
        }
        break;
    case M2M_WIFI_RESP_CON_STATE_CHANGED:
        state = (tstrM2mWifiStateChanged *)msg_data;
        if (state->u8CurrState == M2M_WIFI_CONNECTED) {
            if (wi->wi_state != CONNECTING) {
                break;
            }
            wifi_connect_done(wi, 0);
        } else if (state->u8CurrState == M2M_WIFI_DISCONNECTED) {
            w->w_up = 0;
            if (wi->wi_state == CONNECTING) {
                wifi_connect_done(wi, state->u8ErrCode);
            } else {
                wifi_disconnected(wi, state->u8ErrCode);
            }
        }
        break;
    case M2M_WIFI_REQ_DHCP_CONF:
        dhcp = (tstrM2MIPConfig *)msg_data;
        w->w_up = 1;
        w->w_addr = dhcp->u32StaticIP;
        if (dhcp->u32SubnetMask) {
            w->w_plen = 33 - ffs(ntohl(dhcp->u32SubnetMask));
        } else {
            w->w_plen = 0;
        }
        wifi_dhcp_done(&w->w_if, (uint8_t *)&dhcp->u32StaticIP);
        break;
    case M2M_WIFI_RESP_GET_SYS_TIME:
        time = (tstrSystemTime *)msg_data;
        console_printf("get sys time response %d.%d.%d-%d.%d.%d\n",
          time->u16Year, time->u8Month, time->u8Day,
          time->u8Hour, time->u8Minute, time->u8Second);
        break;
    default:
        console_printf("wifi_callback(%d, %x)\n", msg_type, (unsigned)msg_data);
        break;
    }
}
static void winc1500_callback ( uint8_t msg_type , void * msg_data ) { struct winc1500 * w ; struct wifi_if * wi ; tstrM2mScanDone * scan_done ; tstrM2mWifiscanResult * scan ; tstrM2mWifiStateChanged * state ; tstrM2MIPConfig * dhcp ; tstrSystemTime * time ; struct wifi_ap ap ; int rc ; w = & winc1500 ; wi = & w -> w_if ; switch ( msg_type ) { case M2M_WIFI_RESP_SCAN_DONE : if ( wi -> wi_state != SCANNING ) { break ; } scan_done = ( tstrM2mScanDone * ) msg_data ; w -> w_scan_cnt = scan_done -> u8NumofCh ; if ( w -> w_scan_cnt > 0 ) { w -> w_scan_idx = 0 ; rc = m2m_wifi_req_scan_result ( 0 ) ; if ( rc ) { wifi_scan_done ( wi , -1 ) ; } } break ; case M2M_WIFI_RESP_SCAN_RESULT : if ( wi -> wi_state != SCANNING ) { break ; } scan = ( tstrM2mWifiscanResult * ) msg_data ; memcpy ( ap . wa_ssid , scan -> au8SSID , sizeof ( ap . wa_ssid ) ) ; memcpy ( ap . wa_bssid , scan -> au8BSSID , sizeof ( ap . wa_bssid ) ) ; ap . wa_rssi = scan -> s8rssi ; ap . wa_key_type = scan -> u8AuthType ; ap . wa_channel = scan -> u8ch ; wifi_scan_result ( wi , & ap ) ; ++ w -> w_scan_idx ; if ( w -> w_scan_idx < w -> w_scan_cnt ) { rc = m2m_wifi_req_scan_result ( w -> w_scan_idx ) ; if ( rc ) { wifi_scan_done ( wi , -1 ) ; } } else { wifi_scan_done ( wi , 0 ) ; } break ; case M2M_WIFI_RESP_CON_STATE_CHANGED : state = ( tstrM2mWifiStateChanged * ) msg_data ; if ( state -> u8CurrState == M2M_WIFI_CONNECTED ) { if ( wi -> wi_state != CONNECTING ) { break ; } wifi_connect_done ( wi , 0 ) ; } else if ( state -> u8CurrState == M2M_WIFI_DISCONNECTED ) { w -> w_up = 0 ; if ( wi -> wi_state == CONNECTING ) { wifi_connect_done ( wi , state -> u8ErrCode ) ; } else { wifi_disconnected ( wi , state -> u8ErrCode ) ; } } break ; case M2M_WIFI_REQ_DHCP_CONF : dhcp = ( tstrM2MIPConfig * ) msg_data ; w -> w_up = 1 ; w -> w_addr = dhcp -> u32StaticIP ; if ( dhcp -> u32SubnetMask ) { w -> w_plen = 33 - ffs ( ntohl ( dhcp -> u32SubnetMask ) ) ; } else { w -> w_plen = 0 ; } wifi_dhcp_done ( & w -> w_if , ( uint8_t * ) & dhcp -> u32StaticIP ) ; break ; case M2M_WIFI_RESP_GET_SYS_TIME : time = ( tstrSystemTime * ) msg_data ; console_printf ( " \n " , time -> u16Year , time -> u8Month , time -> u8Day , time -> u8Hour , time -> u8Minute , time -> u8Second ) ; break ; default : console_printf ( " \n " , msg_type , ( unsigned ) msg_data ) ; break ; } }
Called within winc1500 task context to report incoming events.
Called within winc1500 task context to report incoming events .
/* connected */ /* disconnected */