void ESP8266WiFiClass::_scanDone(void* result, int status) { if (status != OK) { ESP8266WiFiClass::_scanCount = 0; ESP8266WiFiClass::_scanResult = 0; } else { int i = 0; bss_info_head_t* head = reinterpret_cast<bss_info_head_t*>(result); for (bss_info* it = STAILQ_FIRST(head); it; it = STAILQ_NEXT(it, next), ++i); ESP8266WiFiClass::_scanCount = i; if (i == 0) { ESP8266WiFiClass::_scanResult = 0; } else { bss_info* copied_info = new bss_info[i]; i = 0; for (bss_info* it = STAILQ_FIRST(head); it; it = STAILQ_NEXT(it, next), ++i) { memcpy(copied_info + i, it, sizeof(bss_info)); } ESP8266WiFiClass::_scanResult = copied_info; } } esp_schedule(); }
void init_done() { system_set_os_print(1); gdb_init(); do_global_ctors(); printf("\n%08x\n", core_version); esp_schedule(); }
/** * DNS callback * @param name * @param ipaddr * @param callback_arg */ void wifi_dns_found_callback(const char *name, ip_addr_t *ipaddr, void *callback_arg) { (void) name; if(ipaddr) { (*reinterpret_cast<IPAddress*>(callback_arg)) = ipaddr->addr; } esp_schedule(); // resume the hostByName function }
/** * WPS callback * @param status wps_cb_status */ void wifi_wps_status_cb(wps_cb_status status) { DEBUGV("wps cb status: %d\r\n", status); switch(status) { case WPS_CB_ST_SUCCESS: if(!wifi_wps_disable()) { DEBUGV("wps disable failed\n"); } wifi_station_connect(); break; case WPS_CB_ST_FAILED: DEBUGV("wps FAILED\n"); break; case WPS_CB_ST_TIMEOUT: DEBUGV("wps TIMEOUT\n"); break; case WPS_CB_ST_WEP: DEBUGV("wps WEP\n"); break; case WPS_CB_ST_UNK: DEBUGV("wps UNKNOWN\n"); if(!wifi_wps_disable()) { DEBUGV("wps disable failed\n"); } break; } // TODO user function to get status esp_schedule(); // resume the beginWPSConfig function }
int8_t WiFiClient::_connected(void* pcb, int8_t err) { tcp_pcb* tpcb = reinterpret_cast<tcp_pcb*>(pcb); _client = new ClientContext(tpcb, 0, 0); _client->ref(); esp_schedule(); return ERR_OK; }
extern "C" void __yield() { if (cont_can_yield(&g_cont)) { esp_schedule(); esp_yield(); } else { panic(); } }
void init_done() { printf("\nInit Done with Yield support!\n"); printf("=============================\n"); // disable os_printf at this time //system_set_os_print(0); esp_schedule(); }
static void loop_wrapper() { static bool setup_done = false; if(!setup_done) { setup(); setup_done = true; } preloop_update_frequency(); loop(); esp_schedule(); }
/** * DNS callback * @param name * @param ipaddr * @param callback_arg */ void wifi_dns_found_callback(const char *name, CONST ip_addr_t *ipaddr, void *callback_arg) { (void) name; if (!_dns_lookup_pending) { return; } if(ipaddr) { (*reinterpret_cast<IPAddress*>(callback_arg)) = IPAddress(ipaddr); } esp_schedule(); // resume the hostByName function }
static void loop_wrapper() { static bool setup_done = false; preloop_update_frequency(); if(!setup_done) { setup(); setup_done = true; } loop(); run_scheduled_functions(); esp_schedule(); }
//void __yield() void yield() { if (cont_can_yield(&g_cont)) { esp_schedule(); esp_yield(); } else { abort(); } }
static void loop_wrapper() { static bool setup_done = false; if(!setup_done) { setup(); setup_done = true; Particle.initialize(); } preloop_update_frequency(); loop(); Particle.process(); esp_schedule(); }
static void loop_wrapper() { static bool setup_done = false; preloop_update_frequency(); if (!setup_done) { _begin(); // Startup MySensors library setup_done = true; } _process(); // Process incoming data loop(); run_scheduled_functions(); esp_schedule(); }
void delay(unsigned long ms) { if(ms) { os_timer_setfn(&delay_timer, (os_timer_func_t*) &delay_end, 0); os_timer_arm(&delay_timer, ms, ONCE); } else { esp_schedule(); } esp_yield(); if(ms) { os_timer_disarm(&delay_timer); } }
static void loop_wrapper() { static bool setup_done = false; preloop_update_frequency(); if(!setup_done) { setup(); #ifdef DEBUG_ESP_PORT DEBUG_ESP_PORT.setDebugOutput(true); #endif setup_done = true; } loop(); esp_schedule(); }
void wifi_wps_status_cb(WPS_CB_STATUS_t status) { DEBUGV("wps cb status: %d\r\n", status); switch (status) { case WPS_CB_ST_SUCCESS: if(!wifi_wps_disable()) { DEBUGV("wps disable faild\n"); } wifi_station_connect(); break; case WPS_CB_ST_FAILED: DEBUGV("wps FAILD\n"); break; case WPS_CB_ST_TIMEOUT: DEBUGV("wps TIMEOUT\n"); break; } // todo user function to get status esp_schedule(); // resume the beginWPSConfig function }
void PingClass::_ping_recv_cb(void *opt, void *resp) { // Cast the parameters to get some usable info ping_resp* ping_resp = reinterpret_cast<struct ping_resp*>(resp); ping_option* ping_opt = reinterpret_cast<struct ping_option*>(opt); // Error or success? if (ping_resp->ping_err == -1) _errors++; else { _success++; _avg_time += ping_resp->resp_time; } // Some debug info DEBUG_PING( "DEBUG: ping reply\n" "\ttotal_count = %d \n" "\tresp_time = %d \n" "\tseqno = %d \n" "\ttimeout_count = %d \n" "\tbytes = %d \n" "\ttotal_bytes = %d \n" "\ttotal_time = %d \n" "\tping_err = %d \n", ping_resp->total_count, ping_resp->resp_time, ping_resp->seqno, ping_resp->timeout_count, ping_resp->bytes, ping_resp->total_bytes, ping_resp->total_time, ping_resp->ping_err ); // Is it time to end? // Don't using seqno because it does not increase on error if (_success + _errors == _expected_count) { _avg_time = _avg_time / _expected_count; DEBUG_PING("Avg resp time %d ms\n", _avg_time); // Done, return to main functiom esp_schedule(); } }
void loop_wrapper() { extern void loop(void); extern void web_task(); if(!setup_done) { setup(); setup_done = true; } // FIXME DEBUG REG_SET_BIT(0x3ff00014, BIT(0)); hspi_waitReady(); #ifdef WEBSERVER web_task(); #endif // USER TASK loop(); esp_schedule(); }
void init_done() { do_global_ctors(); esp_schedule(); }
void init_done() { system_set_os_print(1); gdb_init(); do_global_ctors(); esp_schedule(); }
void ICACHE_FLASH_ATTR WiFiClient::_err(int8_t err) { DEBUGV(":err %d\r\n", err); esp_schedule(); }
void WiFiClient::_err(int8_t err) { DEBUGV(":err %d\r\n", err); esp_schedule(); }
void delay_end(void* arg) { esp_schedule(); }
int esp4_input(struct mbuf **mp, int *offp, int proto) { int off; struct ip *ip; struct esp *esp; struct esptail esptail; struct mbuf *m; u_int32_t spi; struct secasvar *sav = NULL; size_t taillen; u_int16_t nxt; const struct esp_algorithm *algo; int ivlen; size_t hlen; size_t esplen; off = *offp; m = *mp; *mp = NULL; /* sanity check for alignment. */ if (off % 4 != 0 || m->m_pkthdr.len % 4 != 0) { ipseclog((LOG_ERR, "IPv4 ESP input: packet alignment problem " "(off=%d, pktlen=%d)\n", off, m->m_pkthdr.len)); ipsecstat.in_inval++; goto bad; } if (m->m_len < off + ESPMAXLEN) { m = m_pullup(m, off + ESPMAXLEN); if (!m) { ipseclog((LOG_DEBUG, "IPv4 ESP input: can't pullup in esp4_input\n")); ipsecstat.in_inval++; goto bad; } } ip = mtod(m, struct ip *); esp = (struct esp *)(((u_int8_t *)ip) + off); #ifdef _IP_VHL hlen = IP_VHL_HL(ip->ip_vhl) << 2; #else hlen = ip->ip_hl << 2; #endif /* find the sassoc. */ spi = esp->esp_spi; if ((sav = key_allocsa(AF_INET, (caddr_t)&ip->ip_src, (caddr_t)&ip->ip_dst, IPPROTO_ESP, spi)) == 0) { ipseclog((LOG_WARNING, "IPv4 ESP input: no key association found for spi %u\n", (u_int32_t)ntohl(spi))); ipsecstat.in_nosa++; goto bad; } KEYDEBUG(KEYDEBUG_IPSEC_STAMP, kprintf("DP esp4_input called to allocate SA:%p\n", sav)); if (sav->state != SADB_SASTATE_MATURE && sav->state != SADB_SASTATE_DYING) { ipseclog((LOG_DEBUG, "IPv4 ESP input: non-mature/dying SA found for spi %u\n", (u_int32_t)ntohl(spi))); ipsecstat.in_badspi++; goto bad; } algo = esp_algorithm_lookup(sav->alg_enc); if (!algo) { ipseclog((LOG_DEBUG, "IPv4 ESP input: " "unsupported encryption algorithm for spi %u\n", (u_int32_t)ntohl(spi))); ipsecstat.in_badspi++; goto bad; } /* check if we have proper ivlen information */ ivlen = sav->ivlen; if (ivlen < 0) { ipseclog((LOG_ERR, "improper ivlen in IPv4 ESP input: %s %s\n", ipsec4_logpacketstr(ip, spi), ipsec_logsastr(sav))); ipsecstat.in_inval++; goto bad; } if (!((sav->flags & SADB_X_EXT_OLD) == 0 && sav->replay && (sav->alg_auth && sav->key_auth))) goto noreplaycheck; if (sav->alg_auth == SADB_X_AALG_NULL || sav->alg_auth == SADB_AALG_NONE) goto noreplaycheck; /* * check for sequence number. */ if (ipsec_chkreplay(ntohl(((struct newesp *)esp)->esp_seq), sav)) ; /* okey */ else { ipsecstat.in_espreplay++; ipseclog((LOG_WARNING, "replay packet in IPv4 ESP input: %s %s\n", ipsec4_logpacketstr(ip, spi), ipsec_logsastr(sav))); goto bad; } /* check ICV */ { u_char sum0[AH_MAXSUMSIZE]; u_char sum[AH_MAXSUMSIZE]; const struct ah_algorithm *sumalgo; size_t siz; sumalgo = ah_algorithm_lookup(sav->alg_auth); if (!sumalgo) goto noreplaycheck; siz = (((*sumalgo->sumsiz)(sav) + 3) & ~(4 - 1)); if (m->m_pkthdr.len < off + ESPMAXLEN + siz) { ipsecstat.in_inval++; goto bad; } if (AH_MAXSUMSIZE < siz) { ipseclog((LOG_DEBUG, "internal error: AH_MAXSUMSIZE must be larger than %lu\n", (u_long)siz)); ipsecstat.in_inval++; goto bad; } m_copydata(m, m->m_pkthdr.len - siz, siz, &sum0[0]); if (esp_auth(m, off, m->m_pkthdr.len - off - siz, sav, sum)) { ipseclog((LOG_WARNING, "auth fail in IPv4 ESP input: %s %s\n", ipsec4_logpacketstr(ip, spi), ipsec_logsastr(sav))); ipsecstat.in_espauthfail++; goto bad; } if (bcmp(sum0, sum, siz) != 0) { ipseclog((LOG_WARNING, "auth fail in IPv4 ESP input: %s %s\n", ipsec4_logpacketstr(ip, spi), ipsec_logsastr(sav))); ipsecstat.in_espauthfail++; goto bad; } /* strip off the authentication data */ m_adj(m, -siz); ip = mtod(m, struct ip *); #ifdef IPLEN_FLIPPED ip->ip_len = ip->ip_len - siz; #else ip->ip_len = htons(ntohs(ip->ip_len) - siz); #endif m->m_flags |= M_AUTHIPDGM; ipsecstat.in_espauthsucc++; } /* * update sequence number. */ if ((sav->flags & SADB_X_EXT_OLD) == 0 && sav->replay) { if (ipsec_updatereplay(ntohl(((struct newesp *)esp)->esp_seq), sav)) { ipsecstat.in_espreplay++; goto bad; } } noreplaycheck: /* process main esp header. */ if (sav->flags & SADB_X_EXT_OLD) { /* RFC 1827 */ esplen = sizeof(struct esp); } else { /* RFC 2406 */ if (sav->flags & SADB_X_EXT_DERIV) esplen = sizeof(struct esp); else esplen = sizeof(struct newesp); } if (m->m_pkthdr.len < off + esplen + ivlen + sizeof(esptail)) { ipseclog((LOG_WARNING, "IPv4 ESP input: packet too short\n")); ipsecstat.in_inval++; goto bad; } if (m->m_len < off + esplen + ivlen) { m = m_pullup(m, off + esplen + ivlen); if (!m) { ipseclog((LOG_DEBUG, "IPv4 ESP input: can't pullup in esp4_input\n")); ipsecstat.in_inval++; goto bad; } } /* * pre-compute and cache intermediate key */ if (esp_schedule(algo, sav) != 0) { ipsecstat.in_inval++; goto bad; } /* * decrypt the packet. */ if (!algo->decrypt) panic("internal error: no decrypt function"); if ((*algo->decrypt)(m, off, sav, algo, ivlen)) { /* m is already freed */ m = NULL; ipseclog((LOG_ERR, "decrypt fail in IPv4 ESP input: %s\n", ipsec_logsastr(sav))); ipsecstat.in_inval++; goto bad; } ipsecstat.in_esphist[sav->alg_enc]++; m->m_flags |= M_DECRYPTED; /* * find the trailer of the ESP. */ m_copydata(m, m->m_pkthdr.len - sizeof(esptail), sizeof(esptail), (caddr_t)&esptail); nxt = esptail.esp_nxt; taillen = esptail.esp_padlen + sizeof(esptail); if (m->m_pkthdr.len < taillen || m->m_pkthdr.len - taillen < off + esplen + ivlen + sizeof(esptail)) { ipseclog((LOG_WARNING, "bad pad length in IPv4 ESP input: %s %s\n", ipsec4_logpacketstr(ip, spi), ipsec_logsastr(sav))); ipsecstat.in_inval++; goto bad; } /* strip off the trailing pad area. */ m_adj(m, -taillen); #ifdef IPLEN_FLIPPED ip->ip_len = ip->ip_len - taillen; #else ip->ip_len = htons(ntohs(ip->ip_len) - taillen); #endif /* was it transmitted over the IPsec tunnel SA? */ if (ipsec4_tunnel_validate(m, off + esplen + ivlen, nxt, sav)) { /* * strip off all the headers that precedes ESP header. * IP4 xx ESP IP4' payload -> IP4' payload * * XXX more sanity checks * XXX relationship with gif? */ u_int8_t tos; tos = ip->ip_tos; m_adj(m, off + esplen + ivlen); if (m->m_len < sizeof(*ip)) { m = m_pullup(m, sizeof(*ip)); if (!m) { ipsecstat.in_inval++; goto bad; } } ip = mtod(m, struct ip *); /* ECN consideration. */ ip_ecn_egress(ip4_ipsec_ecn, &tos, &ip->ip_tos); if (!key_checktunnelsanity(sav, AF_INET, (caddr_t)&ip->ip_src, (caddr_t)&ip->ip_dst)) { ipseclog((LOG_ERR, "ipsec tunnel address mismatch " "in IPv4 ESP input: %s %s\n", ipsec4_logpacketstr(ip, spi), ipsec_logsastr(sav))); ipsecstat.in_inval++; goto bad; } key_sa_recordxfer(sav, m); if (ipsec_addhist(m, IPPROTO_ESP, spi) != 0 || ipsec_addhist(m, IPPROTO_IPV4, 0) != 0) { ipsecstat.in_nomem++; goto bad; } if (netisr_queue(NETISR_IP, m)) { ipsecstat.in_inval++; m = NULL; goto bad; } nxt = IPPROTO_DONE; } else {