示例#1
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_br_periodic(void)
{
#if !UIP_CONF_6LBR
  for(locbr = uip_ds6_br_list;
      locbr < uip_ds6_br_list + UIP_DS6_BR_NB;
      locbr++) {
    if(locbr->state == BR_ST_USED && stimer_expired(&locbr->timeout)) {
      /* remove all thing associate to border router */
      uip_ds6_br_rm(locbr);
    } else if(stimer_expired(&locbr->rs_timer) &&
              (locbr->state == BR_ST_MUST_SEND_RS || locbr->state == BR_ST_SENDING_RS)) {
      /* Send RS if needed well before all timer expired */
      uip_ds6_defrt_t *d;
      d = list_head(defaultrouterlist);
      uint8_t allnotdone = 0;
      while(d != NULL) {
        if(d->br == locbr) {
          if(d->state != DEFRT_ST_SENDING_RS && locbr->state == BR_ST_MUST_SEND_RS) {
            /* Init defrt to send unicast RS */
            d->state = DEFRT_ST_SENDING_RS;
          }
          if(d->state == DEFRT_ST_SENDING_RS) {
            if(locbr->rscount > UIP_ND6_MAX_RTR_SOLICITATIONS) {
              uip_ds6_defrt_rm(d);
            } else {
              /* Must send unicast RS */
              uip_nd6_rs_unicast_output(&d->ipaddr);
              allnotdone = 1;
            }
          }
        }
        d = list_item_next(d);
      }
      if(list_head(defaultrouterlist) == NULL) {
        uip_ds6_send_rs();
        locbr->state = BR_ST_USED;
        return;
      }
      if(locbr->state == BR_ST_MUST_SEND_RS) {
        locbr->state = BR_ST_SENDING_RS;
        locbr->rscount = 1;
      } else if(!allnotdone) {
        locbr->state = BR_ST_USED;
      } else {
        locbr->rscount++;
      }
      stimer_set(&locbr->rs_timer, UIP_ND6_MAX_RTR_SOLICITATION_DELAY);
    }
  }
#endif /* !UIP_CONF_6LBR */
}
示例#2
0
文件: sock.c 项目: AriZuu/picoos-net
void etimer_callback(struct etimer* et)
{
#if NETSTACK_CONF_WITH_IPV6
   
#if !UIP_CONF_ROUTER
    if (et == &uip_ds6_timer_rs) {

      uip_ds6_send_rs();
      tcpip_ipv6_output();
    }
#endif

    if (et == &uip_ds6_timer_periodic) {

      uip_ds6_periodic();
      tcpip_ipv6_output();
    }
#endif

}
示例#3
0
/*---------------------------------------------------------------------------*/
static void
eventhandler(process_event_t ev, process_data_t data)
{
#if UIP_TCP
    static unsigned char i;
    register struct listenport *l;
#endif /*UIP_TCP*/
    struct process *p;

    switch(ev) {
    case PROCESS_EVENT_EXITED:
        /* This is the event we get if a process has exited. We go through
           the TCP/IP tables to see if this process had any open
           connections or listening TCP ports. If so, we'll close those
           connections. */

        p = (struct process *)data;
#if UIP_TCP
        l = s.listenports;
        for(i = 0; i < UIP_LISTENPORTS; ++i) {
            if(l->p == p) {
                uip_unlisten(l->port);
                l->port = 0;
                l->p = PROCESS_NONE;
            }
            ++l;
        }

        {
            struct uip_conn *cptr;

            for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) {
                if(cptr->appstate.p == p) {
                    cptr->appstate.p = PROCESS_NONE;
                    cptr->tcpstateflags = UIP_CLOSED;
                }
            }
        }
#endif /* UIP_TCP */
#if UIP_UDP
        {
            struct uip_udp_conn *cptr;

            for(cptr = &uip_udp_conns[0];
                    cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) {
                if(cptr->appstate.p == p) {
                    cptr->lport = 0;
                }
            }
        }
#endif /* UIP_UDP */
        break;

    case PROCESS_EVENT_TIMER:
        /* We get this event if one of our timers have expired. */
    {
        /* Check the clock so see if we should call the periodic uIP
           processing. */
        if(data == &periodic &&
                etimer_expired(&periodic)) {
#if UIP_TCP
            for(i = 0; i < UIP_CONNS; ++i) {
                if(uip_conn_active(i)) {
                    /* Only restart the timer if there are active
                       connections. */
                    etimer_restart(&periodic);
                    uip_periodic(i);
#if UIP_CONF_IPV6
                    tcpip_ipv6_output();
#else
                    if(uip_len > 0) {
                        PRINTF("tcpip_output from periodic len %d\n", uip_len);
                        tcpip_output();
                        PRINTF("tcpip_output after periodic len %d\n", uip_len);
                    }
#endif /* UIP_CONF_IPV6 */
                }
            }
#endif /* UIP_TCP */
#if UIP_CONF_IP_FORWARD
            uip_fw_periodic();
#endif /* UIP_CONF_IP_FORWARD */
        }

#if UIP_CONF_IPV6
#if UIP_CONF_IPV6_REASSEMBLY
        /*
         * check the timer for reassembly
         */
        if(data == &uip_reass_timer &&
                etimer_expired(&uip_reass_timer)) {
            uip_reass_over();
            tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6_REASSEMBLY */
        /*
         * check the different timers for neighbor discovery and
         * stateless autoconfiguration
         */
        /*if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }*/
#if !UIP_CONF_ROUTER
        if(data == &uip_ds6_timer_rs &&
                etimer_expired(&uip_ds6_timer_rs)) {
            uip_ds6_send_rs();
            tcpip_ipv6_output();
        }
#endif /* !UIP_CONF_ROUTER */
        if(data == &uip_ds6_timer_periodic &&
                etimer_expired(&uip_ds6_timer_periodic)) {
            uip_ds6_periodic();
            tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6 */
    }
    break;

#if UIP_TCP
    case TCP_POLL:
        if(data != NULL) {
            uip_poll_conn(data);
#if UIP_CONF_IPV6
            tcpip_ipv6_output();
#else /* UIP_CONF_IPV6 */
            if(uip_len > 0) {
                PRINTF("tcpip_output from tcp poll len %d\n", uip_len);
                tcpip_output();
            }
#endif /* UIP_CONF_IPV6 */
            /* Start the periodic polling, if it isn't already active. */
            start_periodic_tcp_timer();
        }
        break;
#endif /* UIP_TCP */
#if UIP_UDP
    case UDP_POLL:
        if(data != NULL) {
            uip_udp_periodic_conn(data);
#if UIP_CONF_IPV6
            tcpip_ipv6_output();
#else
            if(uip_len > 0) {
                tcpip_output();
            }
#endif /* UIP_UDP */
        }
        break;
#endif /* UIP_UDP */

    case PACKET_INPUT:
        packet_input();
        break;
    };
}
示例#4
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_periodic(void)
{
	/* This flag signals whether we allow or not to send a packet in the current 
	 * invocation. */
  u8_t allow_output = 1;

  /* minimum lifetime */
  min_lifetime = 0xFFFFFFFF;
  /* router with minimum lifetime */
  min_defrt = NULL;
	
	/* Periodic processing on registrations */
	for(locreg = uip_ds6_reg_list;
      locreg < uip_ds6_reg_list + UIP_DS6_REG_LIST_SIZE; locreg++) {
  	if (locreg->isused) {
  		if (stimer_expired(&locreg->reg_lifetime)) {
  			uip_ds6_reg_rm(locreg);
  		} else if (allow_output) {
  			/* If no output is allowed, it is pointless to enter here in this invocation */
  			if (uip_ds6_if.registration_in_progress) {
  				/* There is a registration in progress */
  				if ((locreg == uip_ds6_if.registration_in_progress) && 
  						(timer_expired(&locreg->registration_timer))) {
	      		/* We already sent a NS message for this address but there has been no response */
	      		if(locreg->reg_count >= UIP_ND6_MAX_UNICAST_SOLICIT) {
			  			/* NUD failed. Signal the need for next-hop determination by deleting the 
			   			 * NCE (RFC 4861) */
			   			uip_ds6_reg_rm(locreg); 
			  			/* And then, delete neighbor and corresponding router (as hosts only keep
			  			 * NCEs for routers in 6lowpan-nd) */ 
			  			locnbr = uip_ds6_nbr_lookup(&locreg->defrt->ipaddr); 
			  			uip_ds6_nbr_rm(locnbr);
			  			uip_ds6_defrt_rm(locreg->defrt);
			  			/* Since we are deleting a default router, we must delete also all 
			  			 * registrations with that router.
			  			 * Be careful here, uip_ds6_reg_cleanup_defrt() modifies the value of locreg!*/
			  			uip_ds6_reg_cleanup_defrt(locreg->defrt);
		      		/* We will also need to start sending RS, as specified in I-D.ietf-6lowpan-nd 
		      		 * for NUD failure case */
		      		uip_ds6_send_rs(NULL);
		      		uip_ds6_if.registration_in_progress = NULL;
  					} else {
  						locreg->reg_count++;
		      		timer_restart(&locreg->registration_timer);
		   	 			uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, 
		          			            &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME);
 						}
  					allow_output = 0; /* Prevent this invocation from sending anything else */
  				}
  			} else {
  				/* There are no registrations in progress, let's see this entry needs (re)registration
  				 * or deletion */
  				if ((locreg->state == REG_GARBAGE_COLLECTIBLE) || 
  						(locreg->state == REG_TO_BE_UNREGISTERED) || 
  						((locreg->state == REG_REGISTERED) && 
	 						(stimer_remaining(&locreg->reg_lifetime) < stimer_elapsed(&locreg->reg_lifetime)))) {
 						/* Issue (re)registration */
				  	uip_ds6_if.registration_in_progress = locreg;
				  	locreg->reg_count++;
				  	timer_set(&locreg->registration_timer, (uip_ds6_if.retrans_timer / 1000) * (CLOCK_SECOND /* FIXME @@@jwg!!!!*/+250));
				  	if (locreg->state == REG_TO_BE_UNREGISTERED) {
					  	uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, 
				      	   			        &locreg->defrt->ipaddr, 1, 0);
				  	} else {
				  		uip_nd6_ns_output(&locreg->addr->ipaddr, &locreg->defrt->ipaddr, 
				      	   			        &locreg->defrt->ipaddr, 1, UIP_ND6_REGISTRATION_LIFETIME);
				  	}   	   			       
			      allow_output = 0; /* Prevent this invocation from sending anything else */
  				}
  			}
  		}
  	}
  }

  
  /* Periodic processing on unicast addresses */
  for(locaddr = uip_ds6_if.addr_list;
      locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
    if(locaddr->isused) {
      if((!locaddr->isinfinite) && (stimer_expired(&locaddr->vlifetime))) {
        uip_ds6_addr_rm(locaddr);
      } else if (allow_output) {
        if (stimer_remaining(&locaddr->vlifetime) < min_lifetime) {
          min_lifetime = stimer_remaining(&locaddr->vlifetime);
          min_defrt = locaddr->defrt;
        }
      }
    }
  }
  
  /* Periodic processing on default routers */
	if (uip_ds6_defrt_choose() == NULL) {
	  if (allow_output) {
	    /* If default router list is empty, start sending RS */
	    uip_ds6_send_rs(NULL);
	    allow_output = 0; /* Prevent this invocation from sending anything else */
	  }
	} else {
    for(locdefrt = uip_ds6_defrt_list;
        locdefrt < uip_ds6_defrt_list + UIP_DS6_DEFRT_NB; locdefrt++) {
      if((locdefrt->isused) && (!locdefrt->isinfinite)) {
        if (stimer_expired(&(locdefrt->lifetime))) {
          uip_ds6_defrt_rm(locdefrt);
          /* If default router list is empty, we will start sending RS in
           * the next invocation of ds6_periodic() */
        } else {
          if (allow_output) {
            if (stimer_remaining(&locdefrt->lifetime) < min_lifetime) {
              min_lifetime = stimer_remaining(&locdefrt->lifetime);
              min_defrt = locdefrt;
            }
          }
        }
      }
    }
	}
	
#if !UIP_CONF_ROUTER
  /* Periodic processing on prefixes */
  for (locprefix = uip_ds6_prefix_list;
      locprefix < uip_ds6_prefix_list + UIP_DS6_PREFIX_NB; locprefix++) {
    if((locprefix->isused) && (!locprefix->isinfinite)) {
    	if (stimer_expired(&locprefix->vlifetime)) {
      	uip_ds6_prefix_rm(locprefix);
    	} else if (allow_output) {
    		if (stimer_remaining(&locprefix->vlifetime) < min_lifetime) {
    			min_lifetime = stimer_remaining(&locprefix->vlifetime);
    			min_defrt = locprefix->defrt;
    		}
    	}
    }
  }
#endif /* !UIP_CONF_ROUTER */

#if CONF_6LOWPAN_ND_6CO
	/* Periodic processing on contexts */
  for(loccontext = uip_ds6_addr_context_table;
      loccontext < uip_ds6_addr_context_table + SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS; loccontext++) {
    if(loccontext->state != NOT_IN_USE) {
    	if (stimer_expired(&loccontext->vlifetime)) {
    		if (loccontext->state != EXPIRED) {
    			loccontext->state = IN_USE_UNCOMPRESS_ONLY;
    			stimer_set(&loccontext->vlifetime, 2 * loccontext->defrt_lifetime);
    		} else {
      		uip_ds6_context_rm(loccontext);
    		}
    	} else if (allow_output) {
    		if (stimer_remaining(&loccontext->vlifetime) < min_lifetime) {
    			min_lifetime = stimer_remaining(&loccontext->vlifetime);
    			min_defrt = loccontext->defrt;
    		}
    	}
    }
  }
#endif /* CONF_6LOWPAN_ND_6CO */

	/* Start sending RS well before the minimum of the lifetimes (def. router, 
	 * context, or prefix) expires */
	if ((allow_output) && (min_lifetime < UIP_DS6_LIFETIME_THRESHOLD)) {
	  /* Start sending RSs to the router with minimum lifetime (if possible) */
		uip_ds6_send_rs(min_defrt);
		allow_output = 0;
	}

  /* Periodic processing on neighbors */
  for(locnbr = uip_ds6_nbr_cache; locnbr < uip_ds6_nbr_cache + UIP_DS6_NBR_NB;
      locnbr++) {
    if(locnbr->isused) {
      switch (locnbr->state) {
#if UIP_CONF_ROUTER
/* There can not be INCOMPLETE NCEs in a host in 6lowpan-nd */
      case NBR_INCOMPLETE:
    		if (allow_output) {  
	        if(locnbr->nscount >= UIP_ND6_MAX_MULTICAST_SOLICIT) {
	          uip_ds6_nbr_rm(locnbr);
	        } else if(stimer_expired(&(locnbr->sendns))) {
	          locnbr->nscount++;
	          PRINTF("NBR_INCOMPLETE: NS %u\n", locnbr->nscount);
	          uip_nd6_ns_output(NULL, NULL, &locnbr->ipaddr);
	          stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
						allow_output = 0;
	        }
    		}  
        break;
#endif /* UIP_CONF_ROUTER */
      case NBR_REACHABLE:
        if(stimer_expired(&(locnbr->reachable))) {
          PRINTF("REACHABLE: moving to STALE (");
          PRINT6ADDR(&locnbr->ipaddr);
          PRINTF(")\n");
          locnbr->state = NBR_STALE;
          NEIGHBOR_STATE_CHANGED(locnbr);
        }
        break;
      case NBR_DELAY:
    		if (allow_output) {  
	        if(stimer_expired(&(locnbr->reachable))) {
	          locnbr->state = NBR_PROBE;
	          locnbr->nscount = 1;
	          NEIGHBOR_STATE_CHANGED(locnbr);
	          PRINTF("DELAY: moving to PROBE + NS %u\n", locnbr->nscount);
	          uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0);
	          stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
	          allow_output = 0;
	        }
    		}  
        break;
      case NBR_PROBE:
    		if (allow_output) {  
	        if(locnbr->nscount >= UIP_ND6_MAX_UNICAST_SOLICIT) {
	          PRINTF("PROBE END \n");
	          if((locdefrt = uip_ds6_defrt_lookup(&locnbr->ipaddr)) != NULL) {
	            uip_ds6_defrt_rm(locdefrt);
	          }
	          uip_ds6_nbr_rm(locnbr);
	        } else if(stimer_expired(&(locnbr->sendns))) {
	          locnbr->nscount++;
	          PRINTF("PROBE: NS %u\n", locnbr->nscount);
	          uip_nd6_ns_output(NULL, &locnbr->ipaddr, &locnbr->ipaddr, 0, 0);
	          stimer_set(&(locnbr->sendns), uip_ds6_if.retrans_timer / 1000);
	          allow_output = 0;
	        }
    		}  
        break;
      default:
        break;
      }
    }
  }

#if UIP_CONF_ROUTER & UIP_ND6_SEND_RA 
  /* Periodic RA sending */
  if(stimer_expired(&uip_ds6_timer_ra)) {
    uip_ds6_send_ra_periodic();
  }
#endif /* UIP_CONF_ROUTER & UIP_ND6_SEND_RA */
  etimer_reset(&uip_ds6_timer_periodic);
  return;
}
示例#5
0
/* -----------------------------------------------------------------------------
 * Process periodical stuff.
 *
 * In contiki, this is handlet by the eventhandler of the tcpip.c file
 * with the process event "PROCESS_EVENT_TIMER".
 * -------------------------------------------------------------------------- */
void xtcp_process_timer(chanend mac_tx, xtcp_tmr_event_type_t event)
{
#if UIP_IGMP
  igmp_periodic();
  if(uip_len > 0) {
    xtcp_tx_buffer(mac_tx);
  }
#endif

  if(event == XTCP_TMR_PERIODIC) {
#if UIP_TCP
    for(int i = 0; i < UIP_CONNS; ++i) {
      if(uip_conn_active(i)) {
        uip_periodic(i);
#if UIP_CONF_IPV6
        xtcpip_ipv6_output(mac_tx);
#else
        if(uip_len > 0) {
          PRINTF("tcpip_output from periodic len %d\n", uip_len);
          tcpip_output();
          PRINTF("tcpip_output after periodic len %d\n", uip_len);
        }
#endif /* UIP_CONF_IPV6 */
      }
    }
#endif /* UIP_TCP */
#if UIP_CONF_IP_FORWARD
    uip_fw_periodic();
#endif /* UIP_CONF_IP_FORWARD */
  }
  /*XXX CHSC HACK*/
#if UIP_CONF_IPV6
#if UIP_CONF_IPV6_REASSEMBLY
        /*
         * check the timer for reassembly
         */
        if(etimer_expired(&uip_reass_timer)) {
          uip_reass_over();
          tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6_REASSEMBLY */
        /*
         * check the different timers for neighbor discovery and
         * stateless autoconfiguration
         */
        /*if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }*/
#if !UIP_CONF_ROUTER
        if(etimer_expired(&uip_ds6_timer_rs)) {
          uip_ds6_send_rs();
          xtcpip_ipv6_output(mac_tx);
        }
#endif /* !UIP_CONF_ROUTER */
        if(etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          xtcpip_ipv6_output(mac_tx);
        }
#endif /* UIP_CONF_IPV6 */

}
示例#6
0
文件: tcpip.c 项目: kamejoko80/emb6
/*---------------------------------------------------------------------------*/
static void
eventhandler(c_event_t ev, p_data_t data)
{
#if UIP_TCP
  static unsigned char i;
//  register struct listenport *l;
#endif /*UIP_TCP*/

  switch(ev) {
    case EVENT_TYPE_TIMER_EXP:
      /* We get this event if one of our timers have expired. */
      {
        /* Check the clock so see if we should call the periodic uIP
           processing. */
        if(data == &periodic &&
           etimer_expired(&periodic)) {
#if UIP_TCP
          for(i = 0; i < UIP_CONNS; ++i) {
            if(uip_conn_active(i)) {
              /* Only restart the timer if there are active
                 connections. */
              etimer_restart(&periodic);
              uip_periodic(i);
#if NETSTACK_CONF_WITH_IPV6
              tcpip_ipv6_output();
#else
              if(uip_len > 0) {
		PRINTF("tcpip_output from periodic len %d\n\r", uip_len);
                tcpip_output();
		PRINTF("tcpip_output after periodic len %d\n\r", uip_len);
              }
#endif /* NETSTACK_CONF_WITH_IPV6 */
            }
          }
#endif /* UIP_TCP */
#if UIP_CONF_IP_FORWARD
          uip_fw_periodic();
#endif /* UIP_CONF_IP_FORWARD */
        }
        
#if NETSTACK_CONF_WITH_IPV6
#if UIP_CONF_IPV6_REASSEMBLY
        /*
         * check the timer for reassembly
         */
        if(data == &uip_reass_timer &&
           etimer_expired(&uip_reass_timer)) {
          uip_reass_over();
          tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6_REASSEMBLY */
        /*
         * check the different timers for neighbor discovery and
         * stateless autoconfiguration
         */
        /*if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }*/
#if !UIP_CONF_ROUTER
        if(data == &uip_ds6_timer_rs &&
           etimer_expired(&uip_ds6_timer_rs)) {
          uip_ds6_send_rs();
          tcpip_ipv6_output();
        }
#endif /* !UIP_CONF_ROUTER */
        if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }
#endif /* NETSTACK_CONF_WITH_IPV6 */
      }
      break;
	 
#if UIP_TCP
    case EVENT_TYPE_TCP_POLL:
      if(data != NULL) {
        uip_poll_conn(data);
#if NETSTACK_CONF_WITH_IPV6
        tcpip_ipv6_output();
#else /* NETSTACK_CONF_WITH_IPV6 */
        if(uip_len > 0) {
        	PRINTF("tcpip_output from tcp poll len %d\n\r", uip_len);
        	tcpip_output();
        }
#endif /* NETSTACK_CONF_WITH_IPV6 */
        /* Start the periodic polling, if it isn't already active. */
        start_periodic_tcp_timer();
      }
      break;
#endif /* UIP_TCP */
#if UIP_UDP
    case EVENT_TYPE_UDP_POLL:
      if(data != NULL) {
        uip_udp_periodic_conn(data);
#if NETSTACK_CONF_WITH_IPV6
        tcpip_ipv6_output();
#else
        if(uip_len > 0) {
          tcpip_output();
        }
#endif /* UIP_UDP */
      }
      break;
#endif /* UIP_UDP */

    case EVENT_TYPE_PCK_INPUT:
      packet_input();
      break;
  };
}