⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhcp_support.c

📁 Mavell 无线模块原厂IC AP32源代码。DHCP客户端与服务端源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        {#if defined (AP_URPTR) || defined(WB_EXCEPTION)			{				extern unsigned char ethMac[6];    			wetUpdateHashEntry(ewbGetEthIp(), ethMac);			}#endif                        cyg_semaphore_wait( &dhcp_needs_attention );#if 1			eth0_up = true;            s = socket(AF_INET, SOCK_DGRAM, 0);            if(s >= 0){                 dhcp_del_old_ip_and_reset_interface( eth0_name,                                                     s,                                                     &ifr);                close(s);            }            memset(&eth0_bootp_data,0 , sizeof(eth0_bootp_data));            eth0_dhcpstate = 0;#endif            if (mib_dhcpenable)            {                dhcp_halt(); // tear everything down                init_static_network_interfaces(0);                if ( ! dhcp_bind() ) // a lease expired                {                    dhcp_halt(); // tear everything down                    init_static_network_interfaces(0);                }            }            else            {                ipaddr = 0; /* clear ipaddr otherwise init_static_network_interfaces will use old ipaddr */                init_static_network_interfaces(1);            }            init_static_network_interfaces(2);            if((SUBNETMASK & 0xff000000) != 0xff000000)            {                if( (IPADDR & 0xC0000000) == 0xC0000000)                    SUBNETMASK = 0xffffff00;                else if( (IPADDR & 0xC0000000) == 0x80000000)                    SUBNETMASK = 0xffff0000;                else                    SUBNETMASK = 0xff000000;                init_static_network_interfaces(0);            }            break; // If we need to re-bind        }#if 0        dhcp_halt(); // tear everything down        if ( !loop_on_failure )            return ; // exit the thread/return        init_static_network_interfaces(1); // re-initialize        for ( j = 0; j < CYGPKG_NET_NLOOP; j++ )            init_loopback_interface( j );#endif#ifdef CYGPKG_SNMPAGENT        SnmpdShutDown(0) // Cycle the snmpd state#endif    }}#ifdef CYGOPT_NET_DHCP_DHCP_THREAD // Then we provide such a thread...cyg_handle_t dhcp_mgt_thread_h = 0;cyg_thread dhcp_mgt_thread;/* Need this because this is a port of a later tcpip package */#define CYGOPT_NET_DHCP_DHCP_THREAD_PARAM 1#define CYGOPT_NET_DHCP_DHCP_THREAD_PARAM_1#define CYGPKG_NET_DHCP_THREAD_PRIORITY 8#define CYGPKG_NET_DHCP_THREAD_PRIORITY_8#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + sizeof(struct bootp))static cyg_uint8 dhcp_mgt_stack[ STACK_SIZE ];void dhcp_start_dhcp_mgt_thread( void ){    if ( ! dhcp_mgt_thread_h )    {        cyg_semaphore_init( &dhcp_needs_attention, 0 );        cyg_thread_create(            CYGPKG_NET_DHCP_THREAD_PRIORITY,  /* scheduling info (eg pri) */            dhcp_mgt_entry,              /* entry point function */            CYGOPT_NET_DHCP_DHCP_THREAD_PARAM,  /* entry data */            "DHCP lease mgt",            /* optional thread name */            dhcp_mgt_stack,              /* stack base, NULL = alloc */            STACK_SIZE,                  /* stack size, 0 = default */            &dhcp_mgt_thread_h,          /* returned thread handle */            &dhcp_mgt_thread           /* put thread here */        );        cyg_thread_resume(dhcp_mgt_thread_h);    }}static unsigned char *add_tag(unsigned char *vp,        unsigned char tag,        void *val,        int len){    int i;    unsigned char *xp = (unsigned char *)val;    *vp++ = tag;    *vp++ = len;    for (i = 0; i < len; i++)    {        *vp++ = *xp++;    }    return vp;}unsigned long inet_address(unsigned long addr){    return htonl(addr);}void init_static_network_interfaces(int flag){    int i;    in_addr_t addr;    unsigned char *vp;    unsigned char cookie[] = VM_RFC1048;    struct bootp *bp;    if (flag != 2)    {        if (IPADDR == 0xffffffff || IPADDR == 0)        {            init_all_network_interfaces(); //initialize network interface first            return ;        }#ifdef CYGHWR_NET_DRIVER_ETH0        eth0_up = true;        bp = &eth0_bootp_data;        bzero(bp, sizeof(struct bootp));        bp->bp_op = BOOTREPLY;        bp->bp_htype = HTYPE_ETHERNET;        bp->bp_hlen = 6;        for (i = 0; i < bp->bp_hlen; i++)        {            bp->bp_chaddr[i] = 0xFF;        }        if(ipaddr)        {            bp->bp_ciaddr.s_addr = inet_address(ipaddr);                                  bp->bp_yiaddr.s_addr = inet_address(ipaddr);                                  bp->bp_siaddr.s_addr = inet_address((ipaddr & 0xffffff00) + 0x64);            bp->bp_giaddr.s_addr = inet_address((ipaddr & 0xffffff00) + 0x64);        }else        {        bp->bp_ciaddr.s_addr = inet_address(IPADDR);        bp->bp_yiaddr.s_addr = inet_address(IPADDR);        bp->bp_siaddr.s_addr = inet_address((IPADDR & 0xffffff00) + 0x64);        bp->bp_giaddr.s_addr = inet_address((IPADDR & 0xffffff00) + 0x64);        }        vp = &bp->bp_vend[0];        bcopy(&cookie, vp, sizeof(cookie));        vp += sizeof(cookie);        addr = inet_address(SUBNETMASK);        vp = add_tag(vp, TAG_SUBNET_MASK, &addr, sizeof(in_addr_t));        addr = inet_address((IPADDR & SUBNETMASK) ^ (~SUBNETMASK));        vp = add_tag(vp, TAG_IP_BROADCAST, &addr, sizeof(in_addr_t));        *vp = TAG_END;#endif#if 0//def CYGHWR_NET_DRIVER_ETH1        eth1_up = true;        bp = &eth1_bootp_data;        bzero(bp, sizeof(struct bootp));        bp->bp_op = BOOTREPLY;        bp->bp_htype = HTYPE_ETHERNET;        bp->bp_hlen = 6;        for (i = 0; i < bp->bp_hlen; i++)        {            bp->bp_chaddr[i] = 0xFF;        }        bp->bp_ciaddr.s_addr = inet_address(IPADDR);        bp->bp_yiaddr.s_addr = inet_address(IPADDR);        bp->bp_siaddr.s_addr = inet_address(GWYADDR & 0xffffff64);        bp->bp_giaddr.s_addr = inet_address(GWYADDR & 0xffffff64);        vp = &bp->bp_vend[0];        bcopy(&cookie, vp, sizeof(cookie));        vp += sizeof(cookie);        addr = inet_address(SUBNETMASK);        vp = add_tag(vp, TAG_SUBNET_MASK, &addr, sizeof(in_addr_t));        addr = inet_address((IPADDR & SUBNETMASK) ^ (~SUBNETMASK));        vp = add_tag(vp, TAG_IP_BROADCAST, &addr, sizeof(in_addr_t));        *vp = TAG_END;#endif#ifdef CYGHWR_NET_DRIVER_ETH0#ifndef CYGHWR_NET_DRIVER_ETH0_MANUAL        if (eth0_up)        {            if (!init_net(eth0_name, &eth0_bootp_data))            {                //diag_printf("Network initialization failed for eth0\n");                eth0_up = false;            }        }#endif#endif#if 0//def CYGHWR_NET_DRIVER_ETH1#ifndef CYGHWR_NET_DRIVER_ETH1_MANUAL        if (eth1_up)        {            if (!init_net(eth1_name, &eth1_bootp_data))            {                //diag_printf("Network initialization failed for eth1\n");                eth1_up = false;            }        }#endif#endif    }    if (flag)    {        update_IP_Info();        cyg_semaphore_post(&ip_ready);        cyg_semaphore_post(&ip_ready);    }}void update_IP_Info(void){    struct bootp *bp;    unsigned char *op, *ap = 0;    struct in_addr addr[32];    unsigned char name[128];    int i, len;    unsigned long tmpaddr;    bp = &eth0_bootp_data;    IPADDR = inet_address(eth0_bootp_data.bp_yiaddr.s_addr);    if (bp->bp_vend[0])    {        op = &bp->bp_vend[4];        while (*op != TAG_END)        {            switch (*op)            {            case TAG_SUBNET_MASK:                ap = (unsigned char *) & tmpaddr;                len = *(op + 1);                for (i = 0; i < len; i++)                {                    *ap++ = *(op + i + 2);                }                while (len > 0)                {                    len -= sizeof(struct in_addr);                    ap += sizeof(struct in_addr);                }                SUBNETMASK = inet_address(tmpaddr);                break;            case TAG_GATEWAY:                ap = (unsigned char *) & tmpaddr;                len = *(op + 1);                for (i = 0; i < len; i++)                {                    *ap++ = *(op + i + 2);                }                while (len > 0)                {                    len -= sizeof(struct in_addr);                    ap += sizeof(struct in_addr);                }                GWYADDR = inet_address(tmpaddr);                break;            case TAG_IP_BROADCAST:            case TAG_DOMAIN_SERVER:                ap = (unsigned char *) & addr[0];                len = *(op + 1);                for (i = 0; i < len; i++)                {                    *ap++ = *(op + i + 2);                }                if (*op == TAG_SUBNET_MASK)                    ap = "  subnet mask";                if (*op == TAG_GATEWAY)                    ap = "      gateway";                if (*op == TAG_IP_BROADCAST)                    ap = " IP broadcast";                if (*op == TAG_DOMAIN_SERVER)                    ap = "domain server";                ap = (unsigned char *) & addr[0];                while (len > 0)                {                    len -= sizeof(struct in_addr);                    ap += sizeof(struct in_addr);                }                break;            case TAG_DOMAIN_NAME:            case TAG_HOST_NAME:                for (i = 0; i < *(op + 1); i++)                {                    name[i] = *(op + i + 2);                }                name[*(op + 1)] = '\0';                if (*op == TAG_DOMAIN_NAME)                    ap = " domain name";                if (*op == TAG_HOST_NAME)                    ap = "   host name";                break;            default:                break;            }            op += *(op + 1) + 2;        }    }}void initiate_dhcp(int force){    static int dhcp_init = 0;    if ( !dhcp_init || force)    {        dhcp_init++;        cyg_semaphore_post( &dhcp_needs_attention);    }}void wait_ipReady(void){    cyg_semaphore_wait (&ip_ready);    cyg_semaphore_post(&ip_ready);}#endif // CYGOPT_NET_DHCP_DHCP_THREAD#endif // CYGPKG_NET_DHCP// EOF dhcp_support.c

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -