コード例 #1
0
static void
autoip_start_probing(struct netif *netif)
{
  struct autoip *autoip = netif->autoip;

  autoip->state = AUTOIP_STATE_PROBING;
  autoip->sent_num = 0;
  LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
     ("autoip_start_probing(): changing state to PROBING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
      ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr),
      ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr)));

  /* time to wait to first probe, this is randomly
   * choosen out of 0 to PROBE_WAIT seconds.
   * compliant to RFC 3927 Section 2.2.1
   */
  autoip->ttw = (u16_t)(LWIP_AUTOIP_RAND(netif) % (PROBE_WAIT * AUTOIP_TICKS_PER_SECOND));

  /*
   * if we tried more then MAX_CONFLICTS we must limit our rate for
   * accquiring and probing address
   * compliant to RFC 3927 Section 2.2.1
   */
  if(autoip->tried_llipaddr > MAX_CONFLICTS) {
    autoip->ttw = RATE_LIMIT_INTERVAL * AUTOIP_TICKS_PER_SECOND;
  }
}
コード例 #2
0
/**
 * Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds
 */
void
autoip_tmr()
{
    struct netif *netif = netif_list;
    /* loop through netif's */
    while (netif != NULL) {
        /* only act on AutoIP configured interfaces */
        if (netif->autoip != NULL) {
            if(netif->autoip->lastconflict > 0) {
                netif->autoip->lastconflict--;
            }

            LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
                        ("autoip_tmr() AutoIP-State: %"U16_F", ttw=%"U16_F"\n",
                         (u16_t)(netif->autoip->state), netif->autoip->ttw));

            switch(netif->autoip->state) {
            case AUTOIP_STATE_PROBING:
                if(netif->autoip->ttw > 0) {
                    netif->autoip->ttw--;
                } else {
                    if(netif->autoip->sent_num >= PROBE_NUM) {
                        netif->autoip->state = AUTOIP_STATE_ANNOUNCING;
                        netif->autoip->sent_num = 0;
                        netif->autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND;
                    } else {
                        autoip_arp_probe(netif);
                        LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
                                    ("autoip_tmr() PROBING Sent Probe\n"));
                        netif->autoip->sent_num++;
                        /* calculate time to wait to next probe */
                        netif->autoip->ttw = (u16_t)((LWIP_AUTOIP_RAND(netif) %
                                                      ((PROBE_MAX - PROBE_MIN) * AUTOIP_TICKS_PER_SECOND) ) +
                                                     PROBE_MIN * AUTOIP_TICKS_PER_SECOND);
                    }
                }
                break;

            case AUTOIP_STATE_ANNOUNCING:
                if(netif->autoip->ttw > 0) {
                    netif->autoip->ttw--;
                } else {
                    if(netif->autoip->sent_num == 0) {
                        /* We are here the first time, so we waited ANNOUNCE_WAIT seconds
                         * Now we can bind to an IP address and use it.
                         *
                         * autoip_bind calls netif_set_up. This triggers a gratuitous ARP
                         * which counts as an announcement.
                         */
                        autoip_bind(netif);
                    } else {
                        autoip_arp_announce(netif);
                        LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
                                    ("autoip_tmr() ANNOUNCING Sent Announce\n"));
                    }
                    netif->autoip->ttw = ANNOUNCE_INTERVAL * AUTOIP_TICKS_PER_SECOND;
                    netif->autoip->sent_num++;

                    if(netif->autoip->sent_num >= ANNOUNCE_NUM) {
                        netif->autoip->state = AUTOIP_STATE_BOUND;
                        netif->autoip->sent_num = 0;
                        netif->autoip->ttw = 0;
                    }
                }
                break;
            }
        }
        /* proceed to next network interface */
        netif = netif->next;
    }
}
コード例 #3
0
ファイル: autoip.c プロジェクト: Altizon/Aliot-SDK-Examples
/**
 * Has to be called in loop every AUTOIP_TMR_INTERVAL milliseconds
 */
void
autoip_tmr()
{
  struct netif *netif = netif_list;
  /* loop through netif's */
  while (netif != NULL) {
    /* only act on AutoIP configured interfaces */
    if (netif->autoip != NULL) {
      if (netif->autoip->lastconflict > 0) {
        netif->autoip->lastconflict--;
      }

      LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
        ("autoip_tmr() AutoIP-State: %"U16_F", ttw=%"U16_F"\n",
        (u16_t)(netif->autoip->state), netif->autoip->ttw));

      switch(netif->autoip->state) {
        case AUTOIP_STATE_PROBING:
          if (netif->autoip->ttw > 0) {
            netif->autoip->ttw--;
          } else {
            if (netif->autoip->sent_num >= PROBE_NUM) {
              netif->autoip->state = AUTOIP_STATE_ANNOUNCING;
              netif->autoip->sent_num = 0;
              netif->autoip->ttw = ANNOUNCE_WAIT * AUTOIP_TICKS_PER_SECOND;
              LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
                 ("autoip_tmr(): changing state to ANNOUNCING: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
                  ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr),
                  ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr)));
            } else {
              autoip_arp_probe(netif);
              LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
                ("autoip_tmr() PROBING Sent Probe\n"));
              netif->autoip->sent_num++;
              /* calculate time to wait to next probe */
              netif->autoip->ttw = (u16_t)((LWIP_AUTOIP_RAND(netif) %
                ((PROBE_MAX - PROBE_MIN) * AUTOIP_TICKS_PER_SECOND) ) +
                PROBE_MIN * AUTOIP_TICKS_PER_SECOND);
            }
          }
          break;

        case AUTOIP_STATE_ANNOUNCING:
          if (netif->autoip->ttw > 0) {
            netif->autoip->ttw--;
          } else {
            if (netif->autoip->sent_num == 0) {
             /* We are here the first time, so we waited ANNOUNCE_WAIT seconds
              * Now we can bind to an IP address and use it.
              *
              * autoip_bind calls netif_set_up. This triggers a gratuitous ARP
              * which counts as an announcement.
              */
              autoip_bind(netif);
            } else {
              autoip_arp_announce(netif);
	      /* Store announced IP address in a global variable, so that
	       * it can be retrieved in case of link-loss */
	      memcpy(&prev_llipaddr, &(netif->autoip->llipaddr),
			      sizeof(ip_addr_t));
              LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE,
                ("autoip_tmr() ANNOUNCING Sent Announce\n"));
            }
            netif->autoip->ttw = ANNOUNCE_INTERVAL * AUTOIP_TICKS_PER_SECOND;
            netif->autoip->sent_num++;

            if (netif->autoip->sent_num >= ANNOUNCE_NUM) {
                netif->autoip->state = AUTOIP_STATE_BOUND;
                netif->autoip->sent_num = 0;
                netif->autoip->ttw = 0;
				netif->autoip->tried_llipaddr = 0;
                netif_send_status(netif);
                 LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
                    ("autoip_tmr(): changing state to BOUND: %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
                     ip4_addr1_16(&netif->autoip->llipaddr), ip4_addr2_16(&netif->autoip->llipaddr),
                     ip4_addr3_16(&netif->autoip->llipaddr), ip4_addr4_16(&netif->autoip->llipaddr)));
            }
          }
          break;
      }
    }
    /* proceed to next network interface */
    netif = netif->next;
  }
}
コード例 #4
0
ファイル: autoip.c プロジェクト: ChrisRieger/openbeacon
/**
 * Start AutoIP client
 *
 * @param netif network interface on which start the AutoIP client
 */
err_t
autoip_start (struct netif * netif)
{
  struct autoip *autoip = netif->autoip;
  err_t result = ERR_OK;

  if (netif_is_up (netif))
    {
      netif_set_down (netif);
    }

  /* Set IP-Address, Netmask and Gateway to 0 to make sure that
   * ARP Packets are formed correctly
   */
  netif->ip_addr.addr = 0;
  netif->netmask.addr = 0;
  netif->gw.addr = 0;

  LWIP_DEBUGF (AUTOIP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
	       ("autoip_start(netif=%p) %c%c%" U16_F "\n", (void *) netif,
		netif->name[0], netif->name[1], (u16_t) netif->num));
  if (autoip == NULL)
    {
      /* no AutoIP client attached yet? */
      LWIP_DEBUGF (AUTOIP_DEBUG | LWIP_DBG_TRACE,
		   ("autoip_start(): starting new AUTOIP client\n"));
      autoip = mem_malloc (sizeof (struct autoip));
      if (autoip == NULL)
	{
	  LWIP_DEBUGF (AUTOIP_DEBUG | LWIP_DBG_TRACE,
		       ("autoip_start(): could not allocate autoip\n"));
	  return ERR_MEM;
	}
      memset (autoip, 0, sizeof (struct autoip));
      /* store this AutoIP client in the netif */
      netif->autoip = autoip;
      LWIP_DEBUGF (AUTOIP_DEBUG | LWIP_DBG_TRACE,
		   ("autoip_start(): allocated autoip"));
    }
  else
    {
      autoip->state = AUTOIP_STATE_OFF;
      autoip->ttw = 0;
      autoip->sent_num = 0;
      memset (&autoip->llipaddr, 0, sizeof (struct ip_addr));
      autoip->lastconflict = 0;
    }

  autoip_create_rand_addr (netif, &(autoip->llipaddr));
  autoip->tried_llipaddr++;
  autoip->state = AUTOIP_STATE_PROBING;
  autoip->sent_num = 0;

  /* time to wait to first probe, this is randomly
   * choosen out of 0 to PROBE_WAIT seconds.
   * compliant to RFC 3927 Section 2.2.1
   */
  autoip->ttw =
    (u16_t) (LWIP_AUTOIP_RAND (netif) %
	     (PROBE_WAIT * AUTOIP_TICKS_PER_SECOND));

  /*
   * if we tried more then MAX_CONFLICTS we must limit our rate for
   * accquiring and probing address
   * compliant to RFC 3927 Section 2.2.1
   */

  if (autoip->tried_llipaddr > MAX_CONFLICTS)
    {
      autoip->ttw = RATE_LIMIT_INTERVAL * AUTOIP_TICKS_PER_SECOND;
    }

  return result;
}