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

📄 dev.c

📁 基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7的BSP,操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:
    while ((temp_dev_table != NU_NULL) && 
        (temp_dev_table -> dev_vect != vector))
        temp_dev_table = temp_dev_table->dev_next;


    return( temp_dev_table);
}


/**************************************************************************
* FUNCTION                                                                 
*                                                                          
*  DEV_Get_Ether_Address                                                   
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*  Given a device name, this routine will get the ethernet address of      
*  the device.                                                             
*                                                                          
*                                                                          
* INPUTS                                                                   
*                                                                          
*    name              pointer to an ASCII string representing the device  
*    ether_addr        the container for the ethernet address              
*                       to be returned.                                    
*                                                                          
* OUTPUTS                                                                  
*                                                                          
*    NU_SUCCESS        device was updated                                  
*    -1                device was NOT updated                              
*                                                                          
****************************************************************************/

INT DEV_Get_Ether_Address(CHAR *name, UINT8 *ether_addr)
{

    DV_DEVICE_ENTRY   *temp_dev_table;
    INT         status = NU_SUCCESS;
    INT         i;

    /*  Look at the first in the list. */
    temp_dev_table = DEV_Table.dv_head;

    /*  Search for a match.  */
    while ((temp_dev_table != NU_NULL) && 
        (strcmp(temp_dev_table -> dev_net_if_name, name) != 0))
        temp_dev_table = temp_dev_table -> dev_next;


    /*  If we found one, then set up the IP address.  */
    if (temp_dev_table != NU_NULL)
    {

        /*  Copy the IP Address into the interface table. */
        for (i = 0; i < 6; i++)
            ether_addr[i] = temp_dev_table -> dev_mac_addr[i];

    }
    else
        status = -1;

    return(status);

}
/**************************************************************************
* FUNCTION                                                                 
*                                                                          
*  DEV_Attach_IP_To_Device                                                 
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*  Given a device name, this routine will set the IP number into the       
*  network interface table for the device.                                 
*                                                                          
*                                                                          
* INPUTS                                                                   
*                                                                          
*    name          an ASCII string representing the device                 
*    ip_addr       the IP address to be associated with the device         
*    subnet        the subnet mask to be associated with the device        
*                                                                          
* OUTPUTS                                                                  
*                                                                          
*    NU_SUCCESS    device was updated                                      
*    -1            device was NOT updated                                  
*                                                                          
****************************************************************************/
INT DEV_Attach_IP_To_Device(CHAR *name, UINT8 *ip_addr, UINT8 *subnet)
{

    DV_DEVICE_ENTRY     *device;
    INT                 status = NU_SUCCESS;
    UINT8               dev_ip_addr[4];
    UINT8               dev_netmask[4];

    /*  Look at the first in the list. */
    device = DEV_Table.dv_head;

    /*  Search for a match.  */
    while ((device != NU_NULL) &&
        (strcmp(device -> dev_net_if_name, name) != 0))
        device = device -> dev_next;


    /*  If we found one, then set up the IP address.  */
    if (device != NU_NULL)
    {

        /*  Copy the IP Address into the interface table. */
        device->dev_addr.dev_ip_addr = IP_ADDR(ip_addr);

        /* If a network mask was not supplied, then chose one based on the
           class of the IP address. Else use the supplied mask. */
        if (IP_ADDR(subnet) == 0)
        {
            if (IP_CLASSC_ADDR(device->dev_addr.dev_ip_addr))
                device->dev_addr.dev_netmask = 0xffffff00UL;
            else if (IP_CLASSB_ADDR(device->dev_addr.dev_ip_addr))
                device->dev_addr.dev_netmask = 0xffff0000UL;
            else if (IP_CLASSA_ADDR(device->dev_addr.dev_ip_addr))
                device->dev_addr.dev_netmask = 0xff000000UL;
        }
        else
        {
            device->dev_addr.dev_netmask = IP_ADDR(subnet);
        }

        PUT32(dev_ip_addr, 0, device->dev_addr.dev_ip_addr);
        PUT32(dev_netmask, 0, device->dev_addr.dev_netmask);

        /* Fill in the network number. */
        device->dev_addr.dev_net = device->dev_addr.dev_ip_addr &
                                  device->dev_addr.dev_netmask;
        
        /* Set the network broadcast address. */
        device->dev_addr.dev_net_brdcast = device->dev_addr.dev_ip_addr 
                                      | (~device->dev_addr.dev_netmask);
 
        /* Update the SNMP IP Address Translation Table. */
        SNMP_ipNetToMediaTableUpdate(SNMP_ADD, device->dev_index,
                                    device->dev_mac_addr, dev_ip_addr, 4);

        /* Update the address translation group. */
        SNMP_atTableUpdate(SNMP_ADD, (INT)(device->dev_index), 
                            device->dev_mac_addr, dev_ip_addr);

        SNMP_ipAdEntUpdate(SNMP_ADD, (INT)(device->dev_index), 
                           dev_ip_addr, dev_netmask, 1, 0);

        if (!(device->dev_flags & DV_POINTTOPOINT))

            /* Init the route to the directly connected network. Not used
               for PPP links. */
            status = DEV_Init_Route(device);

        /* Indicate that the device is Running. */
        device->dev_flags |= DV_UP;

#if INCLUDE_IP_MULTICASTING

        /* If multicasting support is desired then join the all hosts group
           (224.0.0.1) on all devices that support IP multicasting. */
        if (device->dev_flags & DV_MULTICAST)
            IGMP_Initialize(device);

#endif /* INCLUDE_IP_MULTICASTING */

        /* Send a gratuitous ARP. */
        if (!((device->dev_flags & DV_NOARP) || (device->dev_flags & DV_POINTTOPOINT)))
            ARP_Request(device, &device->dev_addr.dev_ip_addr,
                             (UINT8 *)"\0\0\0\0\0\0", EARP, ARPREQ);

#if (INCLUDE_LOOPBACK_DEVICE == NU_TRUE)

        /* Only add a new route if this is not the loopback device. */
        if (device->dev_type != DVT_LOOP)
        {
            /* Add a host route to the loopback device for this devices IP
               address. NOTE: since the loopback device is added first
               during NET initialization it will always be the first 
               device in the list. */
            RTAB_Add_Route (DEV_Table.dv_head, IP_ADDR(ip_addr), 0xFFFFFFFFUL,
                            0x7F000001UL, (RT_UP | RT_STATIC | 
                                            RT_GATEWAY | RT_HOST));
       }

#endif
    }
    else
        status = -1;

    return(status);

} /* DEV_Attach_IP_To_Device */


/**************************************************************************
* FUNCTION                                                                 
*                                                                          
*  DEV_Detach_IP_From_Device                                               
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*  Given a device name, this routine will remove the IP number from the    
*  network interface table for the device.                                 
*                                                                          
*                                                                          
* INPUTS                                                                   
*                                                                          
*    name              an ASCII string representing the device.            
*                                                                          
* OUTPUTS                                                                  
*                                                                          
*    NU_SUCCESS        device was updated.                                 
*    -1                device was NOT updated.                             
*                                                                          
****************************************************************************/
INT DEV_Detach_IP_From_Device(CHAR *name)
{
    DV_DEVICE_ENTRY     *device;
    INT                 status = 0;
    UINT8               dest_ip_addr[IP_ADDR_LEN];
    UINT8               dev_ip_addr[4];
    UINT8               dev_netmask[4];

    /*  Look at the first in the list. */
    device = DEV_Table.dv_head;

    /*  Search for a match.  */
    while ((device != NU_NULL) &&
           (strcmp(device -> dev_net_if_name, name) != 0))
        device = device -> dev_next;


    /*  If we found one, then set up the IP address.  */
    if ((device != NU_NULL) && (device->dev_flags & DV_UP))
    {

#if (INCLUDE_LOOPBACK_DEVICE == NU_TRUE)
            
        /* Copy the IP address over to the local array so that we can 
           delete the loopback HOST route. */
        dest_ip_addr [0] = (UINT8) ( 0x000000FF & 
                                    (device->dev_addr.dev_ip_addr >> 24) );
        dest_ip_addr [1] = (UINT8) ( 0x000000FF & 
                                    (device->dev_addr.dev_ip_addr >> 16) );
        dest_ip_addr [2] = (UINT8) ( 0x000000FF & 
                                    (device->dev_addr.dev_ip_addr >> 8) );
        dest_ip_addr [3] = (UINT8) ( 0x000000FF & 
                                   device->dev_addr.dev_ip_addr);

⌨️ 快捷键说明

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