示例#1
0
/************************************************************************
* NAME: fnet_arp_init
*
* DESCRIPTION: ARP module initialization.
*************************************************************************/
fnet_return_t fnet_arp_init(fnet_netif_t *netif, fnet_arp_if_t *arpif)
{
    fnet_index_t    i;
    fnet_return_t   result = FNET_ERR;

    if(netif && arpif)
    {
        netif->arp_if_ptr = arpif;

        for (i = 0U; i < FNET_CFG_ARP_TABLE_SIZE; i++)
        {
            fnet_memset_zero(&(arpif->arp_table[i]), sizeof(fnet_arp_entry_t));
        }

#if FNET_CFG_ARP_EXPIRE_TIMEOUT
        arpif->arp_tmr = fnet_timer_new((FNET_ARP_TIMER_PERIOD / FNET_TIMER_PERIOD_MS), fnet_arp_timer, (fnet_uint32_t)arpif);
#endif

        if (arpif->arp_tmr)
        {
            /* Install event Handler. */
            arpif->arp_event = fnet_event_init(fnet_arp_ip4_addr_conflict, (fnet_uint32_t)netif);
            if (arpif->arp_event != FNET_ERR)
            {
                result = FNET_OK;
            }
        }
    }

    return result;
}
/************************************************************************
* NAME: fnet_netif_pmtu_init
* RETURS: None.
* DESCRIPTION: Initialize PMTU Discovery for the interface.
*************************************************************************/
void fnet_netif_pmtu_init(fnet_netif_t *netif)
{
    /* Path MTU for the link. */
    fnet_netif_set_pmtu(netif, netif->mtu);  
    
    /* Register timer, to detect increase of PMTU.*/       
    netif->pmtu_timer = fnet_timer_new((FNET_NETIF_PMTU_PERIOD/FNET_TIMER_PERIOD_MS), fnet_netif_pmtu_timer, netif);
}
/************************************************************************
* NAME: fnet_isr_init
*
* DESCRIPTION: This function inits ISR module
*
*************************************************************************/
void fnet_isr_init()
{
    fnet_locked = 0;
    fnet_isr_table = 0;
#if 0
    fnet_timer_new(20,&debug_pending_interrupts,0);
#endif
}
/************************************************************************
* NAME: fnet_arp_init
*
* DESCRIPTION: ARP module initialization.
*************************************************************************/
int fnet_arp_init( fnet_netif_t *netif )
{
    fnet_arp_if_t  *arpif = &(((fnet_eth_if_t *)(netif->if_ptr))->arp_if); 
    int            i;
    int            result= FNET_ERR;

    for (i = 0; i < FNET_ARP_TABLE_SIZE; i++)
      fnet_memset_zero(&(arpif->arp_table[i]), sizeof(fnet_arp_entry_t));

    arpif->arp_tmr = fnet_timer_new((FNET_ARP_TIMER_PERIOD / FNET_TIMER_PERIOD_MS), 
                        fnet_arp_timer, arpif);

    if(arpif->arp_tmr)
    {
        /* Install event Handler. */
    	arpif->arp_event = fnet_event_init(fnet_arp_ip_duplicated, netif);
    	if(arpif->arp_event != FNET_ERR)
    	    result = FNET_OK;
    }
        
    return result;
}
示例#5
0
/************************************************************************
* NAME: fnet_eth_init
*
* DESCRIPTION: Do initialization for an Ethernet-type interface.
*************************************************************************/
fnet_return_t fnet_eth_init( fnet_netif_t *netif)
{
    fnet_return_t result  = FNET_ERR;
    fnet_eth_if_t *eth_if = (fnet_eth_if_t *)(netif->if_ptr);

    if(eth_if)
    {
#if !FNET_CFG_CPU_ETH_MIB
        /* Clear Ethernet statistics. */
        fnet_memset_zero(&eth_if->statistics, sizeof(struct fnet_netif_statistics));
#endif

#if FNET_CFG_IP4
        result = fnet_arp_init(netif, &eth_if->arp_if); /* Init ARP for this interface.*/
#else
        result = FNET_OK;
#endif /* FNET_CFG_IP4 */

        if(result == FNET_OK)
        {

#if FNET_CFG_IP6
#if FNET_CFG_IP6_PMTU_DISCOVERY
            fnet_netif_pmtu_init(netif);
#endif

            /* Init Neighbor Discovery.*/
            if( ( result = fnet_nd6_init (netif, &eth_if->nd6_if) ) == FNET_OK)
            {
                /* RFC4861 6.3.3: The host joins the all-nodes multicast address on all
                 * multicastcapable interfaces.
                 */
                fnet_ip6_multicast_join(netif, &fnet_ip6_addr_linklocal_allnodes);

                /* To speed the autoconfiguration process, a host may generate its linklocal
                 * address (and verify its uniqueness) in parallel with waiting
                 * for a Router Advertisement. Because a router may delay responding to
                 * a Router Solicitation for a few seconds, the total time needed to
                 * complete autoconfiguration can be significantly longer if the two
                 * steps are done serially.
                 */


                /* Link-Local Address Generation/Auto configuration.
                 * It comprises of '1111111010' as the first ten bits followed by 54 zeroes
                 * and a 64 bit interface identifier.
                 * For all autoconfiguration types, a link-local address is always configured.
                 */
                fnet_netif_bind_ip6_addr_prv( netif, &fnet_ip6_addr_any, FNET_NETIF_IP_ADDR_TYPE_AUTOCONFIGURABLE,
                                              FNET_NETIF_IP6_ADDR_LIFETIME_INFINITE /*in seconds*/, FNET_ND6_PREFIX_LENGTH_DEFAULT /* bits */ );

                /* RFC4862: The next phase of autoconfiguration involves obtaining a Router
                 * Advertisement or determining that no routers are present.  If routers
                 * are present, they will send Router Advertisements that specify what
                 * sort of autoconfiguration a host can do.
                 * To obtain an advertisement quickly, a host sends one or more Router
                 * Solicitations to the all-routers multicast group.
                 */
                fnet_nd6_rd_start(netif);
            }
#endif /* FNET_CFG_IP6 */

            /* Set connection flag. */
            eth_if->connection_flag = fnet_netif_is_connected(netif);

            eth_if->eth_timer = fnet_timer_new((FNET_ETH_TIMER_PERIOD / FNET_TIMER_PERIOD_MS), fnet_eth_timer, (fnet_uint32_t)netif);

            fnet_eth_number++;
        }
    }

    return result;
}