コード例 #1
0
ファイル: lwiplib.c プロジェクト: OS-Project/Divers
static void lwIPDHCPComplete(unsigned int ifNum)
{
    unsigned int dhcpTries = NUM_DHCP_TRIES;
    int cnt;
    volatile unsigned char *state;

    while(dhcpTries--)
    {
        LWIP_PRINTF("\n\rDHCP Trial %d...", (NUM_DHCP_TRIES - dhcpTries));
        dhcp_start(&cpswNetIF[ifNum]);

        cnt = LWIP_DHCP_TIMEOUT;

        /* Check for DHCP completion for 'cnt' number of times, each 10ms */
        while(cnt--)
        {
            delay(10);
            state = &(cpswNetIF[ifNum].dhcp->state);
            if(DHCP_BOUND == *state)
            {
                return;
            }
        }
    }

    LWIP_PRINTF("\n\rUnable to complete DHCP! \n\r");
}
コード例 #2
0
ファイル: lwiplib.c プロジェクト: ragunath3252/lwip-drv
/**
 *
 * @brief Initializes the lwIP TCP/IP stack.
 *
 * @param lwipIf  The interface structure for lwIP
 *
 * @return true if everything ok, false otherwise.
*/
static bool lwIPInit(LWIP_IF *const lwipIf, const unsigned int ifNum)
{
    static unsigned int lwipInitFlag = LWIP_NOT_INITIALIZED;
    bool ret = true;

    /* do lwip library init only once */
    if(LWIP_NOT_INITIALIZED == lwipInitFlag)
    {
        tcpip_init(NULL, NULL);
    }
    setPortIf(lwipIf, ifNum);

    if(netif_add(&cpswNetIF[ifNum], &lwipIf->ipAddr, &lwipIf->netMask, 
            &lwipIf->gwAddr,&cpswPortIf[ifNum], cpswif_init, tcpip_input) != NULL)
    {
        if(LWIP_NOT_INITIALIZED == lwipInitFlag)
        {
            netif_set_default(&cpswNetIF[ifNum]);
            lwipInitFlag = LWIP_INITIALIZED;
        }
	lwipIf->ipMode = IPADDR_USE_DHCP;
        ret = netifStart(lwipIf, ifNum);
    }
    else
    {
        LWIP_PRINTF("\n\rUnable to add interface for interface %d", ifNum);
        ret = false;
    }
    return ret;
}
コード例 #3
0
ファイル: lwiplib.c プロジェクト: ragunath3252/lwip-drv
/**
 * @brief   This function waits for DHCP completion with a timeout
 *
 * @param   ifNum  The netif number for the interface
 *
 * @return  True if IP acquired succesfully, false otherwise.
*/
static bool lwIPDHCPComplete(const unsigned int ifNum)
{
    bool ret = true;
    unsigned int dhcpTries = 0;
    volatile unsigned char * state;
    struct netif* const netif = &cpswNetIF[ifNum];

    do
    {
        ++dhcpTries;
        dhcp_start(netif);
        state = &(netif->dhcp->state);
        LWIP_PRINTF("\n\rDHCP Trial %d ", (dhcpTries));
        dhcpCheck(state);
    }while((dhcpTries < NUM_DHCP_TRIES) && (*state != DHCP_BOUND));

    if (*state != DHCP_BOUND)
    {
        LWIP_PRINTF("\n\rUnable to complete DHCP! \n\r");
        ret = false;
    }
    return ret;
}
コード例 #4
0
ファイル: lwiplib.c プロジェクト: OS-Project/Divers
/**
 *
 * \brief Initializes the lwIP TCP/IP stack.
 *
 * \param lwipIf  The interface structure for lwIP
 *
 * \return IP Address.
*/
unsigned int lwIPInit(LWIP_IF *lwipIf,char *hwOK)
{
    struct ip_addr ip_addr;
    struct ip_addr net_mask;
    struct ip_addr gw_addr;
    unsigned int *ipAddrPtr;
    static unsigned int lwipInitFlag = 0;
    unsigned int ifNum;
    unsigned int temp;
    
    /* do lwip library init only once */
    if(0 == lwipInitFlag)
    {
        lwip_init();
    }

    /* Setup the network address values. */
    if(lwipIf->ipMode == IPADDR_USE_STATIC)
    {
        ip_addr.addr = htonl(lwipIf->ipAddr);
        net_mask.addr = htonl(lwipIf->netMask);
        gw_addr.addr = htonl(lwipIf->gwAddr);
    }
    else
    {
        ip_addr.addr = 0;
        net_mask.addr = 0;
        gw_addr.addr = 0;
    }

#ifdef CPSW_DUAL_MAC_MODE
    ifNum = (lwipIf->instNum * MAX_SLAVEPORT_PER_INST) + lwipIf->slvPortNum - 1;
#else
    ifNum = lwipIf->instNum;
#endif

    cpswPortIf[ifNum].inst_num = lwipIf->instNum;
    cpswPortIf[ifNum].port_num = lwipIf->slvPortNum;

    /* set MAC hardware address */
    for(temp = 0; temp < LEN_MAC_ADDRESS; temp++) 
    {
        cpswPortIf[ifNum].eth_addr[temp] =
                         lwipIf->macArray[(LEN_MAC_ADDRESS - 1) - temp];
    }
    
    /*
    ** Create, configure and add the Ethernet controller interface with
    ** default settings.  ip_input should be used to send packets directly to
    ** the stack. The lwIP will internaly call the cpswif_init function. 
    */
    if(NULL ==
       netif_add(&cpswNetIF[ifNum], &ip_addr, &net_mask, &gw_addr, 
                 &cpswPortIf[ifNum], cpswif_init, ip_input,hwOK))
    {
        LWIP_PRINTF("\n\rUnable to add interface for interface %d", ifNum);
        return 0;
    }

    if(0 == lwipInitFlag)
    {
        netif_set_default(&cpswNetIF[ifNum]);
        lwipInitFlag = 1;
    }

    /* Start DHCP, if enabled. */
#if LWIP_DHCP
    if(lwipIf->ipMode == IPADDR_USE_DHCP)
    {
        lwIPDHCPComplete(ifNum);
    }
#endif

    /* Start AutoIP, if enabled and DHCP is not. */
#if LWIP_AUTOIP
    if(lwipIf->ipMode == IPADDR_USE_AUTOIP)
    {
        autoip_start(&cpswNetIF[ifNum]);
    }
#endif

    if((lwipIf->ipMode == IPADDR_USE_STATIC)
       ||(lwipIf->ipMode == IPADDR_USE_AUTOIP))
    {
       /* Bring the interface up */
       netif_set_up(&cpswNetIF[ifNum]);
    }
  
    ipAddrPtr = (unsigned int*)&(cpswNetIF[ifNum].ip_addr);

    return (*ipAddrPtr);
}