コード例 #1
0
ファイル: main.c プロジェクト: edwin-oetelaar/W7500P
/*******************************************
 * @ brief Call back for DNS Client
 *******************************************/
int32_t dns_do(uint8_t sn, uint8_t* buf)
{
    int32_t ret;
#ifdef _DNS_DEBUG_
    printf("\r\n===== DNS Servers =====\r\n");
    printf("> DNS  : %d.%d.%d.%d\r\n", dns_server[0], dns_server[1], dns_server[2], dns_server[3]);
    printf("=======================================\r\n");
    printf("> [Example] Target Domain Name : %s\r\n", Domain_name);
#endif

    /* DNS client Initialization */
    DNS_init(sn, buf);
    if (((ret = DNS_run(dns_server, Domain_name, Domain_IP))>0))     // retry to 2nd DNS
    {

     	printf("> Translated %s to %d.%d.%d.%d\r\n",Domain_name,Domain_IP[0],Domain_IP[1],Domain_IP[2],Domain_IP[3]);

    }
    else
    {
#ifdef _DNS_DEBUG_
        printf("> DNS Failed\r\n");
#endif
        if(ret == -1)
        {
#ifdef _DNS_DEBUG_
            printf("> MAX_DOMAIN_NAME3 is too small. Should be redefined it.\r\n");
#endif
            ;
        }
        ;
    }
	delay(1000);
#ifdef _DNS_DEBUG_
    if(ret>0)
    {
        printf("> Domain_IP : %d.%d.%d.%d\r\n", Domain_IP[0], Domain_IP[1], Domain_IP[2], Domain_IP[3]);
    }        
#endif
    return ret;
}
コード例 #2
0
ファイル: wizSystem.c プロジェクト: sobhamo/hello-world
int8_t DNSTimeOut(uint8_t * name, uint8_t * ip_from_dns, uint32_t timeout)
{
	int8_t ret;

    str_to_ip(name, ip_from_dns);
    char buf[17];
    snprintf(buf, sizeof(buf), "%d.%d.%d.%d", ip_from_dns[0], ip_from_dns[1], ip_from_dns[2], ip_from_dns[3]);
    if (strcmp(buf, name) == 0) {
        return 0;
    }

	sockPool *sockP = sockPoolAlloc();
	DNS_init(sockP->sockNo,sockP->netBuf);
	ret = DNS_run(NetInfo.dns,name,ip_from_dns);

	if(ret < 0)
	{
		printf("DNS timeout.\r\n");
	}
	sockPoolFree(sockP);
	return ret;
}
コード例 #3
0
void DNS_update(void)
{
	int val=0;

	CFG_get(CFG_DNS_EN, &val);
	if(val)
	{
		if(dns_running)
			dns_cmd = DNS_SIGHUP;
		else
		{
			DNS_init();
			return;
		}
	}
	else
	{
		if(dns_running)
			dns_cmd = DNS_SHUTDOWN;
		else
			return;
	}
	cyg_mbox_tryput(dns_mbox_id, (void*)dns_cmd);
}
コード例 #4
0
ファイル: main.c プロジェクト: hecko/W7500P
/**
 * @brief   Main program
 * @param  None
 * @retval None
 */
int main()
{
    //uint8_t tx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    //uint8_t rx_size[8] = { 2, 2, 2, 2, 2, 2, 2, 2 };
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x71, 0x72, 0x77}; 
    uint8_t src_addr[4] = {192, 168,  77,  9};
    uint8_t gw_addr[4]  = {192, 168,  77,  1};
    uint8_t sub_addr[4] = {255, 255, 255,  0};	
		uint8_t Domain_name[] = "www.google.com";    // for example domain name
    uint8_t dns_server[4] = {8, 8, 8, 8};           // for Example domain name server
		uint8_t Domain_IP[4] = {0, 0, 0, 0};           // for Example domain name server
    uint8_t tmp[8];
    uint32_t toggle = 1;

    /* External Clock */
    //CRG_PLL_InputFrequencySelect(CRG_OCLK);

    /* Set Systme init */
    SystemInit();

    /* UART Init */
    //UART_StructInit(&UART_InitStructure);
    //UART_Init(UART1,&UART_InitStructure);
		S_UART_Init(115200);
		
    /* SysTick_Config */
    SysTick_Config((GetSystemClock()/1000));

    /* Set WZ_100US Register */
    setTIC100US((GetSystemClock()/10000));
    //getTIC100US();	
    //printf(" GetSystemClock: %X, getTIC100US: %X, (%X) \r\n", 
    //      GetSystemClock, getTIC100US(), *(uint32_t *)TIC100US);        


#ifdef __DEF_USED_IC101AG__ //For using IC+101AG
    *(volatile uint32_t *)(0x41003068) = 0x64; //TXD0 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x4100306C) = 0x64; //TXD1 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003070) = 0x64; //TXD2 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003074) = 0x64; //TXD3 - set PAD strengh and pull-up
    *(volatile uint32_t *)(0x41003050) = 0x64; //TXE  - set PAD strengh and pull-up
#endif	

#ifdef __W7500P__
	*(volatile uint32_t *)(0x41003070) = 0x61;
	*(volatile uint32_t *)(0x41003054) = 0x61;
#endif


#ifdef __DEF_USED_MDIO__ 
    /* mdio Init */
    mdio_init(GPIOB, MDC, MDIO );
    /* PHY Link Check via gpio mdio */
    while( link() == 0x0 )
    {
        printf(".");  
        delay(500);
    }
    printf("PHY is linked. \r\n");  
#else
    delay(1000);
#endif

    /* Network Configuration (Default setting) */
    setSHAR(mac_addr);
    setSIPR(src_addr);
    setGAR(gw_addr);
    setSUBR(sub_addr);

    getSHAR(tmp);	printf("MAC ADDRESS : %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\r\n",tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]); 
    getSIPR(tmp); printf("IP ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getGAR(tmp);  printf("GW ADDRESS : %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 
    getSUBR(tmp); printf("SN MASK: %.3d.%.3d.%.3d.%.3d\r\n",tmp[0],tmp[1],tmp[2],tmp[3]); 

    /* Set Network Configuration */
    //wizchip_init(tx_size, rx_size);
			
    /* DHCP client Initialization */
    DHCP_init(SOCK_DHCP, test_buf);
    /* DHCP IP allocation and check the DHCP lease time (for IP renewal) */
    while(1)
    {
        switch(DHCP_run())
        {
            case DHCP_IP_ASSIGN:
            case DHCP_IP_CHANGED:
                /* If this block empty, act with default_ip_assign & default_ip_update  */
                //
                // This example calls the registered 'my_ip_assign' in the two case.
                //
                // Add to ...
                //
                //
                break;
            case DHCP_IP_LEASED:
                //
                if(toggle)
                {
                    getGAR(tmp);  printf("> DHCP GW : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]);
                    getSUBR(tmp); printf("> DHCP SN : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]);
                    getSIPR(tmp); printf("> DHCP IP : %d.%d.%d.%d\r\n", tmp[0], tmp[1], tmp[2], tmp[3]);
                    toggle = 0;
                }  
                // TO DO YOUR NETWORK APPs.
								// 
								/* DNS client initialization */
								DNS_init(SOCK_DNS, test_buf);
								if(DNS_run(dns_server, Domain_name, Domain_IP))
								{
									printf("> Translated %s to %d.%d.%d.%d\r\n",Domain_name,Domain_IP[0],Domain_IP[1],Domain_IP[2],Domain_IP[3]);
								}
								else
								{
									printf("> DNS Failed\r\n");
								}
								delay(1000);
								
                break;

            case DHCP_FAILED:
                /* ===== Example pseudo code =====  */
                // The below code can be replaced your code or omitted.
                // if omitted, retry to process DHCP
                my_dhcp_retry++;
                if(my_dhcp_retry > MY_MAX_DHCP_RETRY)
                {
#if DEBUG_MODE != DEBUG_NO
                    printf(">> DHCP %d Failed\r\n",my_dhcp_retry);
#endif
                    my_dhcp_retry = 0;
                    DHCP_stop();      // if restart, recall DHCP_init()
                }
                break;
            default:
                break;
        }	


    }

}