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

📄 dev.c

📁 基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7的BSP,操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:

        /* Remove the loopback route for this device. */
        RTAB_Delete_Route (dest_ip_addr);

#endif            

        /* We only need to remove the route if this is not a point to point
           device. */
        if (!(device->dev_flags & DV_POINTTOPOINT))
        {
            /* Remove the main route for this device. Use the net
               field of the deice structure for the address, this
               includes the mask. */
            dest_ip_addr [0] = (UINT8) ( 0x000000FF & 
                                        (device->dev_addr.dev_net >> 24) );
            dest_ip_addr [1] = (UINT8) ( 0x000000FF & 
                                        (device->dev_addr.dev_net >> 16) );
            dest_ip_addr [2] = (UINT8) ( 0x000000FF & 
                                        (device->dev_addr.dev_net >> 8) );
            dest_ip_addr [3] = (UINT8) ( 0x000000FF & 
                                       device->dev_addr.dev_net);

            /* Now delete the main route for this device. */
            RTAB_Delete_Route (dest_ip_addr);

        }

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

        /*  Copy the IP Address into the interface table. This will be zero for 
            removing the device. */
        device->dev_addr.dev_ip_addr = NU_NULL;

        /* Update the SNMP IP Address Translation Table. */
        SNMP_ipNetToMediaTableUpdate(SNMP_DELETE, device->dev_index,
                                    device->dev_mac_addr, dev_ip_addr, 4);

        SNMP_atTableUpdate(SNMP_DELETE, (INT)(device->dev_index), 
                            device->dev_mac_addr, dev_ip_addr);

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

        /*  Copy the subnet mask the device table. */
        device->dev_addr.dev_netmask = NU_NULL;

        /* Fill in the network number. */
        device->dev_addr.dev_net = NU_NULL;
        
        /* Set the network broadcast address. */
        device->dev_addr.dev_net_brdcast = NU_NULL;

        /* Indicate that the device is not up and running. */
        device->dev_flags &= ~DV_UP;

    }
    else
        status = -1;

    return(status);

} /* end DEV_Detach_IP_From_Device */


/**************************************************************************
* FUNCTION                                                                 
*                                                                          
*  DEV_Init_Route                                                          
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*  Given a device structure, this routine will initialize the route for    
*  the device.                                                             
*                                                                          
*                                                                          
* INPUTS                                                                   
*                                                                          
*    device                Device to initialize                            
*                                                                          
* OUTPUTS                                                                  
*                                                                          
*    NU_SUCCESS            If successful.                                  
*    -1                    If failure.                                     
*                                                                          
****************************************************************************/

STATUS  DEV_Init_Route(DV_DEVICE_ENTRY *device)
{
    UINT32          dest;
    DEV_IF_ADDRESS  *dv_addr;

    dv_addr = &device->dev_addr;

    dest = dv_addr->dev_ip_addr & dv_addr->dev_netmask;

    /* The bitwise anding and checking of the destination address with
       the loopback address is done so that loopback routes will be 
       marked as RT_SLIENT routes and thus will not be part of 
       routing advertisement messages. */
    return ( RTAB_Add_Route(device, dest, dv_addr->dev_netmask, 
             dv_addr->dev_ip_addr, (INT16)(RT_UP | RT_STATIC | 
             ( ( (dest & 0x7F000000UL) == 0x7F000000UL) ? RT_SILENT : 0) )) );

} /* DEV_Init_Route */


/**************************************************************************
* FUNCTION                                                                 
*                                                                          
*  DEV_Get_Device_By_Name                                                  
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*  Given a device name, this routine will return a pointer to the device   
*  structure of the device that wasd named.                                
*                                                                          
*                                                                          
* INPUTS                                                                   
*                                                                          
*    name                  an ASCII string representing the device         
*                                                                          
* OUTPUTS                                                                  
*                                                                          
*    DV_DEVICE_ENTRY*      pointer to the device structure of that name.   
*                                                                          
****************************************************************************/

DV_DEVICE_ENTRY *DEV_Get_Dev_By_Name( CHAR *name )
{

    DV_DEVICE_ENTRY   *dev;

    if (name == NU_NULL)
        return (NU_NULL);

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

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


    return(dev);

} /* DEV_Get_Dev_By_Name */

/**************************************************************************
* FUNCTION                                                                 
*                                                                          
*  DEV_Get_Dev_By_Addr                                                     
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*    Find the device by IP address                                         
*                                                                          
*                                                                          
* INPUTS                                                                   
*                                                                          
*    addr                  IP address to be assocated with the device.     
*                                                                          
* OUTPUTS                                                                  
*                                                                          
*    DV_DEVICE_ENTRY*      Pointer to the device structure.                
*                                                                          
****************************************************************************/

DV_DEVICE_ENTRY *DEV_Get_Dev_By_Addr( UINT8 *addr )
{
    DV_DEVICE_ENTRY   *dev;

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

    /*  Search for a match.  */
    while ( (dev != NU_NULL) &&
            (dev->dev_addr.dev_ip_addr != IP_ADDR(addr)) )
        dev = dev->dev_next;


    return(dev);

} /* DEV_Get_Dev_By_Addr */

/*****************************************************************************
*                                                                      
*  FUNCTION                                                            
*                                                                      
*      DEV_Recover_TX_Buffers                                                        
*                                                                      
*  DESCRIPTION                                                         
*                                                                      
*      This function "frees" the buffers for the first packet on a devices
*  transmit queue, depending on the packet the buffers will be placed on
*  the free buffer list or on the TCP ports retransmit list. This is done 
*  after a driver has completed transmitting a packet and needs to 
*  return the buffers to the stack.
*                                                                      
*  INPUTS                                                              
*                                                                      
*      DV_DEVICE_ENRY  *device     Pointer to the device that has completed
*                                   transmission of a packet.
*                                                                      
*  OUTPUTS                                                             
*                                                                      
*      NONE
*                                                                      
*****************************************************************************/
VOID DEV_Recover_TX_Buffers (DV_DEVICE_ENTRY *device)
{
    NET_BUFFER    *buf_ptr;

    /* If there is an item on the transmit list (there should be everytime we
     * get here) then remove it because it has just been successfully
     * transmitted. */
    if ((device) && (device -> dev_transq.head))
    {
        /* Pull the transmited packet from the transmit queue. */
        buf_ptr = MEM_Buffer_Dequeue(&device -> dev_transq);

#if (INCLUDE_TCP == NU_TRUE)

        /* If this buffer is to be deallocated to a port (it has TCP data) 
           check to see if the port has been closed in the meantime. If it
           has then set the deallocation list to be the free list. */
        if ( (buf_ptr ->mem_port_index != -1) && 
            ( (TCP_Ports[(UINT16)buf_ptr -> mem_port_index] -> state == SCLOSED) ||
              (TCP_Ports[(UINT16)buf_ptr -> mem_port_index] -> state == STWAIT)) )
        {
            buf_ptr -> mem_dlist = &MEM_Buffer_Freelist;
        }

#endif

        /* Free the buffer chain. */
        MEM_One_Buffer_Chain_Free (buf_ptr, buf_ptr -> mem_dlist);

        /* Decrement the Q length for the device transmit Q.*/
        --(device -> dev_transq_length);

        /* Decrement the SNMP out Q len since we just removed one packet. */
        SNMP_ifOutQLen_Dec (device -> dev_index);
    }

} /* end DEV_Recover_TX_Buffers */

⌨️ 快捷键说明

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