void lwip_network_uptime_completion(void *arg) { NATIVE_PROFILE_PAL_NETWORK(); struct netif* pNetIf = (struct netif*)arg; BOOL status = enc28j60_get_link_status(&g_ENC28J60_LWIP_Config.DeviceConfigs[0].SPI_Config); if(status != LwipNetworkStatus) { if(status) { tcpip_callback((sys_timeout_handler)netif_set_link_up, (void*)pNetIf); tcpip_callback((sys_timeout_handler)netif_set_up, (void*)pNetIf); Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, NETWORK_EVENT_FLAGS_IS_AVAILABLE ); } else { tcpip_callback((sys_timeout_handler)netif_set_link_down, (void*)pNetIf); tcpip_callback((sys_timeout_handler)netif_set_down, (void*)pNetIf); Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, 0); } Events_Set(SYSTEM_EVENT_FLAG_SOCKET); Events_Set(SYSTEM_EVENT_FLAG_NETWORK); LwipNetworkStatus = status; } LwipUpTimeCompletion.EnqueueDelta64( 2000000 ); }
/** * Dedicated thread to read data from the serial port. */ static void gprs_thread(void *arg) { gprs_t * gprs = (gprs_t *)arg; LWIP_DEBUGF(GPRS_DEBUG,("gprs: Thread: Started on device %d size %u\n",gprs->device,GPRS_MODEM_BUFFER_SIZE)); for (;;) { gprs->recvLen = sio_read(gprs->fd,(u8_t *)gprs->recvBuffer,GPRS_MODEM_BUFFER_SIZE); if (gprs->recvLen > 0) { #if GPRS_SERIAL_STAT gprs->rcvdBtes += gprs->recvLen; #endif if (tcpip_callback(gprs_input_callback,(void *)gprs) != ERR_OK) { LWIP_DEBUGF(GPRS_DEBUG,("gprs: Thread tcpip_callback() failed\n")); } else { sys_sem_wait(&gprs->recvSem); } } } }
static void TimerThread(void* pvArg) { while (1) { tcpip_callback(Timer,NULL); DelayThread(TCP_TMR_INTERVAL*1000); } }
void lwip_network_uptime_completion(void *arg) { NATIVE_PROFILE_PAL_NETWORK(); BOOL status = dm9161_lwip_GetLinkStatus( ) != 0; if(!status) { status = dm9161_lwip_GetLinkStatus( ) != 0; } if(status != LWIP_STATUS_isset(LWIP_STATUS_LinkUp) ) { struct netif* pNetIf = (struct netif*)arg; if(status) { tcpip_timeout(1000, (sys_timeout_handler)netif_set_link_up, (void*)pNetIf); tcpip_timeout(1000, (sys_timeout_handler)netif_set_up, (void*)pNetIf); Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, NETWORK_EVENT_FLAGS_IS_AVAILABLE ); } else { tcpip_callback((sys_timeout_handler)netif_set_link_down, (void*)pNetIf); tcpip_callback((sys_timeout_handler)netif_set_down, (void*)pNetIf); Network_PostEvent( NETWORK_EVENT_TYPE__AVAILABILITY_CHANGED, 0); } Events_Set(SYSTEM_EVENT_FLAG_SOCKET); Events_Set(SYSTEM_EVENT_FLAG_NETWORK); LWIP_STATUS_setorclear( LWIP_STATUS_LinkUp, status ); } LwipUpTimeCompletion.EnqueueDelta64( 2000000 ); }
//***************************************************************************** // //! Change the configuration of the lwIP network interface. //! //! \param ulIPAddr is the new IP address to be used (static). //! \param ulNetMask is the new network mask to be used (static). //! \param ulGWAddr is the new Gateway address to be used (static). //! \param ulIPMode is the IP Address Mode. \b IPADDR_USE_STATIC 0 will force //! static IP addressing to be used, \b IPADDR_USE_DHCP will force DHCP with //! fallback to Link Local (Auto IP), while \b IPADDR_USE_AUTOIP will force //! Link Local only. //! //! This function will evaluate the new configuration data. If necessary, the //! interface will be brought down, reconfigured, and then brought back up //! with the new configuration. //! //! \return None. // //***************************************************************************** void lwIPNetworkConfigChange(unsigned long ulIPAddr, unsigned long ulNetMask, unsigned long ulGWAddr, unsigned long ulIPMode) { // // Check the parameters. // #if LWIP_DHCP && LWIP_AUTOIP ASSERT((ulIPMode == IPADDR_USE_STATIC) || (ulIPMode == IPADDR_USE_DHCP) || (ulIPMode == IPADDR_USE_AUTOIP)); #elif LWIP_DHCP ASSERT((ulIPMode == IPADDR_USE_STATIC) || (ulIPMode == IPADDR_USE_DHCP)); #elif LWIP_AUTOIP ASSERT((ulIPMode == IPADDR_USE_STATIC) || (ulIPMode == IPADDR_USE_AUTOIP)); #else ASSERT(ulIPMode == IPADDR_USE_STATIC); #endif // // Save the network configuration for later use by the private network // configuration change. // g_ulIPAddr = ulIPAddr; g_ulNetMask = ulNetMask; g_ulGWAddr = ulGWAddr; // // Complete the network configuration change. The remainder is done // immediately if not using a RTOS and it is deferred to the TCP/IP // thread's context if using a RTOS. // #if NO_SYS lwIPPrivateNetworkConfigChange((void *)ulIPMode); #else tcpip_callback(lwIPPrivateNetworkConfigChange, (void *)ulIPMode); #endif }
int netlink_send(void *sock, void *data, int size, unsigned int flags) { struct netlink *nl=sock; struct stack *stack = nl->stack; struct netlink_send_data nlss_data; err_t rv; nlss_data.nl = nl; nlss_data.data = data; nlss_data.size = size; #if LWIP_CAPABILITIES if (stack->stack_capfun) nlss_data.cap=stack->stack_capfun(); else nlss_data.cap= ~0; #endif /* one single answer pending, multiple requests return one long answer */ rv = tcpip_callback(stack, netlink_sync_send, &nlss_data, SYNC); return 0; }
/** * Send an IP packet to be received on the same netif (loopif-like). * The pbuf is simply copied and handed back to netif->input. * In multithreaded mode, this is done directly since netif->input must put * the packet on a queue. * In callback mode, the packet is put on an internal queue and is fed to * netif->input by netif_poll(). * * @param netif the lwip network interface structure * @param p the (IP) packet to 'send' * @param ipaddr the ip address to send the packet to (not used) * @return ERR_OK if the packet has been sent * ERR_MEM if the pbuf used to copy the packet couldn't be allocated */ err_t netif_loop_output(struct netif *netif, struct pbuf *p, ip_addr_t *ipaddr) { struct pbuf *r; err_t err; struct pbuf *last; #if LWIP_LOOPBACK_MAX_PBUFS u8_t clen = 0; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ /* If we have a loopif, SNMP counters are adjusted for it, * if not they are adjusted for 'netif'. */ #if LWIP_SNMP #if LWIP_HAVE_LOOPIF struct netif *stats_if = &loop_netif; #else /* LWIP_HAVE_LOOPIF */ struct netif *stats_if = netif; #endif /* LWIP_HAVE_LOOPIF */ #endif /* LWIP_SNMP */ SYS_ARCH_DECL_PROTECT(lev); LWIP_UNUSED_ARG(ipaddr); /* Allocate a new pbuf */ r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM); if (r == NULL) { LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); snmp_inc_ifoutdiscards(stats_if); return ERR_MEM; } #if LWIP_LOOPBACK_MAX_PBUFS clen = pbuf_clen(r); /* check for overflow or too many pbuf on queue */ if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) || ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) { pbuf_free(r); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); snmp_inc_ifoutdiscards(stats_if); return ERR_MEM; } netif->loop_cnt_current += clen; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ /* Copy the whole pbuf queue p into the single pbuf r */ if ((err = pbuf_copy(r, p)) != ERR_OK) { pbuf_free(r); LINK_STATS_INC(link.memerr); LINK_STATS_INC(link.drop); snmp_inc_ifoutdiscards(stats_if); return err; } /* Put the packet on a linked list which gets emptied through calling netif_poll(). */ /* let last point to the last pbuf in chain r */ for (last = r; last->next != NULL; last = last->next); SYS_ARCH_PROTECT(lev); if(netif->loop_first != NULL) { LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL); netif->loop_last->next = r; netif->loop_last = last; } else { netif->loop_first = r; netif->loop_last = last; } SYS_ARCH_UNPROTECT(lev); LINK_STATS_INC(link.xmit); snmp_add_ifoutoctets(stats_if, p->tot_len); snmp_inc_ifoutucastpkts(stats_if); #if LWIP_NETIF_LOOPBACK_MULTITHREADING /* For multithreading environment, schedule a call to netif_poll */ tcpip_callback((tcpip_callback_fn)netif_poll, netif); #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ return ERR_OK; }
/** * Send an IP packet to be received on the same netif (loopif-like). * The pbuf is simply copied and handed back to netif->input. * In multithreaded mode, this is done directly since netif->input must put * the packet on a queue. * In callback mode, the packet is put on an internal queue and is fed to * netif->input by netif_poll(). * * @param netif the lwip network interface structure * @param p the (IP) packet to 'send' * @param ipaddr the ip address to send the packet to (not used) * @return ERR_OK if the packet has been sent * ERR_MEM if the pbuf used to copy the packet couldn't be allocated */ err_t netif_loop_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) { struct pbuf *r; err_t err; struct pbuf *last; #if LWIP_LOOPBACK_MAX_PBUFS u8_t clen = 0; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ SYS_ARCH_DECL_PROTECT(lev); LWIP_UNUSED_ARG(ipaddr); /* Allocate a new pbuf */ r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM); if (r == NULL) { return ERR_MEM; } #if LWIP_LOOPBACK_MAX_PBUFS clen = pbuf_clen(r); /* check for overflow or too many pbuf on queue */ if(((netif->loop_cnt_current + clen) < netif->loop_cnt_current) || ((netif->loop_cnt_current + clen) > LWIP_LOOPBACK_MAX_PBUFS)) { pbuf_free(r); r = NULL; return ERR_MEM; } netif->loop_cnt_current += clen; #endif /* LWIP_LOOPBACK_MAX_PBUFS */ /* Copy the whole pbuf queue p into the single pbuf r */ if ((err = pbuf_copy(r, p)) != ERR_OK) { pbuf_free(r); r = NULL; return err; } /* Put the packet on a linked list which gets emptied through calling netif_poll(). */ /* let last point to the last pbuf in chain r */ for (last = r; last->next != NULL; last = last->next); SYS_ARCH_PROTECT(lev); if(netif->loop_first != NULL) { LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL); netif->loop_last->next = r; netif->loop_last = last; } else { netif->loop_first = r; netif->loop_last = last; } SYS_ARCH_UNPROTECT(lev); #if LWIP_NETIF_LOOPBACK_MULTITHREADING /* For multithreading environment, schedule a call to netif_poll */ tcpip_callback((void (*)(void *))(netif_poll), netif); #endif /* LWIP_NETIF_LOOPBACK_MULTITHREADING */ return ERR_OK; }
time_t mg_lwip_if_poll(struct mg_iface *iface, int timeout_ms) { struct mg_mgr *mgr = iface->mgr; int n = 0; double now = mg_time(); struct mg_connection *nc, *tmp; double min_timer = 0; int num_timers = 0; #if 0 DBG(("begin poll @%u", (unsigned int) (now * 1000))); #endif mg_ev_mgr_lwip_process_signals(mgr); for (nc = mgr->active_connections; nc != NULL; nc = tmp) { struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock; tmp = nc->next; n++; if ((nc->flags & MG_F_CLOSE_IMMEDIATELY) || ((nc->flags & MG_F_SEND_AND_CLOSE) && (nc->flags & MG_F_UDP) && (nc->send_mbuf.len == 0))) { mg_close_conn(nc); continue; } mg_if_poll(nc, now); mg_if_timer(nc, now); #if MG_ENABLE_SSL if ((nc->flags & MG_F_SSL) && cs != NULL && cs->pcb.tcp != NULL && cs->pcb.tcp->state == ESTABLISHED) { if (((nc->flags & MG_F_WANT_WRITE) || ((nc->send_mbuf.len > 0) && (nc->flags & MG_F_SSL_HANDSHAKE_DONE))) && cs->pcb.tcp->snd_buf > 0) { /* Can write more. */ if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) { if (!(nc->flags & MG_F_CONNECTING)) mg_lwip_ssl_send(nc); } else { mg_lwip_ssl_do_hs(nc); } } if (cs->rx_chain != NULL || (nc->flags & MG_F_WANT_READ)) { if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) { if (!(nc->flags & MG_F_CONNECTING)) mg_lwip_ssl_recv(nc); } else { mg_lwip_ssl_do_hs(nc); } } } else #endif /* MG_ENABLE_SSL */ { if (nc->send_mbuf.len > 0 && !(nc->flags & MG_F_CONNECTING)) { mg_lwip_send_more(nc); } } if (nc->sock != INVALID_SOCKET && !(nc->flags & (MG_F_UDP | MG_F_LISTENING)) && cs->pcb.tcp != NULL && cs->pcb.tcp->unsent != NULL) { tcpip_callback(tcp_output_tcpip, cs->pcb.tcp); } if (nc->ev_timer_time > 0) { if (num_timers == 0 || nc->ev_timer_time < min_timer) { min_timer = nc->ev_timer_time; } num_timers++; } if (nc->sock != INVALID_SOCKET) { /* Try to consume data from cs->rx_chain */ mg_lwip_consume_rx_chain_tcp(nc); /* * If the connection is about to close, and rx_chain is finally empty, * send the MG_SIG_CLOSE_CONN signal */ if (cs->draining_rx_chain && cs->rx_chain == NULL) { mg_lwip_post_signal(MG_SIG_CLOSE_CONN, nc); } } } #if 0 DBG(("end poll @%u, %d conns, %d timers (min %u), next in %d ms", (unsigned int) (now * 1000), n, num_timers, (unsigned int) (min_timer * 1000), timeout_ms)); #endif (void) timeout_ms; return now; }
static void LinkStateDown(void){ tcpip_callback((void*)&netif_set_link_down, &NIF); }
static void LinkStateUp(void){ tcpip_callback((void*)&netif_set_link_up, &NIF); }