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

📄 nnetdrv.c

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

        default:
            SNMP_ifInUnknownProtos_Inc(device->dev_index);
            pktlen = 0;
            break;
    } /* end switch */

#if (INCLUDE_SNMP == NU_TRUE)
    octets = pktlen;
#endif

    /* Now that we know how large the packet is, do the copy. */
    if((pktlen > 0) && (pktlen <= MTU))
    {
        /* Allocate a buffer into which the received packet can be copied. */
        buf_ptr = MEM_Buffer_Chain_Dequeue(&MEM_Buffer_Freelist, pktlen);

        if (buf_ptr != NU_NULL)
        {
            /* Put the head of the chain onto the incoming packet buffer list */
            MEM_Buffer_Enqueue (&MEM_Buffer_List, buf_ptr);

            /* Fill in the total packet length */
            buf_ptr->mem_total_data_len = pktlen;

            /* Compute the total number of bytes that must be copied. */
            bytes_left = pktlen;

            /* Preserve a pointer to the interface on which this packet was
               received. */
            buf_ptr->mem_buf_device = device;

            /* Clear the flags field. */
            buf_ptr->mem_flags = 0;

            /* Set the data pointer. */
            buf_ptr->data_ptr = buf_ptr->mem_parent_packet; 

            /* Will it all fit into one buffer? */
            if (bytes_left <= NET_PARENT_BUFFER_SIZE)
            {
                /* Store the number of data bytes held by this buffer */
                buf_ptr->data_len = bytes_left;

                /* Copy the data */
                memcpy  (buf_ptr->mem_parent_packet, pkt_ptr, bytes_left);
            }
            else
            {

                /* Fill the parent buffer in the chain. This one is slightly 
                   smaller than the rest in the chain. */
                memcpy (buf_ptr->mem_parent_packet, pkt_ptr, NET_PARENT_BUFFER_SIZE);

                /* Take off the bytes just copied from the total bytes left. */
                bytes_left -= NET_PARENT_BUFFER_SIZE;

                /* Store the number of data bytes in this buffer. */
                buf_ptr->data_len = (NET_PARENT_BUFFER_SIZE);

                /* Get a work pointer and bump it the number of bytes just copied. */
                work_ptr = (UINT8 *)((UINT8 *) pkt_ptr + NET_PARENT_BUFFER_SIZE);

                /* Get a work pointer to the buffer chain */
                work_buf = buf_ptr;

                /* Break the rest up into the multiple buffers in the chain. */
                do 
                {
                    /* Move to the next buffer in the chain */
                    work_buf = work_buf->next_buffer;

                    /* If the bytes left will fit into one buffer then copy them over */
                    if (bytes_left <= NET_MAX_BUFFER_SIZE)
                    {
                        /* Copy the rest of the data. */
                        memcpy (work_buf->mem_packet, work_ptr, bytes_left);

                        /* Store the number of bytes in this buffer and set the
                           data pointer. */
                        work_buf->data_len = bytes_left;
                        work_buf->data_ptr = work_buf->mem_packet;
                    }
                    else
                    {
                        /* Copy all that will fit into a single buffer */
                        memcpy (work_buf->mem_packet, work_ptr, 
                                 NET_MAX_BUFFER_SIZE);

                        /* Update the buffer pointer */
                        work_ptr += NET_MAX_BUFFER_SIZE;

                        /* Store the number of bytes in this buffer and set the
                           data pointer. */
                        work_buf->data_len = NET_MAX_BUFFER_SIZE;
                        work_buf->data_ptr = work_buf->mem_packet;
                   }

                    /* Update the data bytes left to copy. */
                    bytes_left -= NET_MAX_BUFFER_SIZE;

                } while (bytes_left > 0);

            } /* end if it will fit into one buffer */

            /* Update the total number of octets received. */
            SNMP_ifInOctets(device->dev_index, octets);
 
        } /* if the buffer pointer returned is not NULL */
        else
        {
            SNMP_ifInDiscards_Inc(device->dev_index);
        }

    } /* end if it is a valid packet size */

    /* Put this buffer back into the free ring so that it can be reused. */
    ringputInfo.MemPtr = NDISComMemStart;
    ringputInfo.RingPtr = ItoKval(MNT_Header_Ptr->MNT_hdr_pFreeRing,
                                  PMNT_RING,
                                  NDISComMemStart);

    ringputInfo.BuffNodeOffset = bufferOffset;

    if (!DeviceIoControl (hDriver,
                     (DWORD) IOCTL_RINGPUT,
                     &ringputInfo,
                     sizeof(ringputInfo),
                     &ringputStatus,
                     sizeof(ringputStatus),
                     &cbReturned,
                     0) )
    {
        NERRS_Log_Error (NERR_SEVERE, __FILE__, __LINE__);
    }

    if (ringputStatus == 0)
    {
        /* Note that this should never happen.  There should always be
           enough room in the free list for all buffers.
        */
        NERRS_Log_Error (NERR_FATAL, __FILE__, __LINE__);
    }


    TCD_Interrupt_Level = TCT_Control_Interrupts(NU_GET_INTERRUPTS);
    TCT_Interrupt_Context_Save();

    /* Activate the HISR timer function.  */
    NU_Activate_HISR(&Recv_HISR);

    TCT_Interrupt_Context_Restore();


    return NU_SUCCESS;

}  /* end VDRV_ISR */

/******************************************************************************
* FUNCTION                                                                   
*                                                                            
*    VDRV_Lookup_Host                                                        
*                                                                            
* DESCRIPTION                                                                
*                                                                            
*    This function searches the NT registry for the specified host name.  If 
*    a match is found the IP address associated with that host               
*    name is  retrieved from the registry.  If the host name is not found    
*    failure is returned.                                                    
*                                                                            
* AUTHOR
*
*   Glen Johnson
*
* INPUTS                                                                     
*                                                                            
*    CHAR *hostname:  A pointer to the host name.                            
*                                                                            
* OUTPUTS                                                                    
*                                                                            
*    sshort   : Returns NU_SUCCESS if ok, else -1                            
*                                                                            
*    When successful the IP address is filled in.                            
*                                                                            
******************************************************************************/
STATUS VDRV_Lookup_Host(CHAR *hostname, CHAR *ip_addr)
{
    DWORD                   valueDWORD, dataSize = 4;
    HKEY                    hKey, subKey;
    UINT                    stat;
    CHAR                    searchName[32];
    DWORD                   hostNameSize = sizeof (searchName);
    FILETIME                Dummy;
    DWORD                   i;

    /* Open a key to the VNETDRV entry in the system Registry.  Below each
       subkey of this key will be read and added to the "host file".
    */
    if ((stat = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                        "SYSTEM\\CURRENTCONTROLSET\\SERVICES\\VNETDRV",
                        0, KEY_ALL_ACCESS, &hKey)) != ERROR_SUCCESS)
        return (-1);

    /* Search each subkey until a match is found or there are no more subkeys. */
    for (i=0;;i++)
    {
        hostNameSize = sizeof (searchName);

        if ((stat = RegEnumKeyEx(hKey, i, searchName, &hostNameSize, 0, NULL,
                                 NULL, &Dummy)) != ERROR_SUCCESS)

            /* There are no more subkeys and no match was found. */
            return (-1);


        /* Break on a match. */
        if(NU_STRICMP(hostname, searchName) == 0)
            break;
    }


    /* Open the subkey so that the IP address can be sxtracted. */
    if ((stat = RegOpenKeyEx(hKey, searchName,
                    0, KEY_ALL_ACCESS, &subKey)) != ERROR_SUCCESS)
        return (-1);

    dataSize = IP_ADDR_LEN;

    /* Get the IP Address. */
    if ((stat = RegQueryValueEx(subKey, "IPADDR", NULL, &valueDWORD, ip_addr, 
                                &dataSize)) != ERROR_SUCCESS)
        return (-1);


    *(UINT32 *)ip_addr = LONGSWAP(*(UINT32 *)ip_addr);

    return NU_SUCCESS;

} /* end VDRV_Lookup_Host */

/******************************************************************************
* FUNCTION                                                                   
*                                                                            
*    VDRV_Lookup_ID                                                          
*                                                                            
* DESCRIPTION                                                                
*                                                                            
*    This function searches the NT registry for the specified host name.  If 
*    a match is found the D associated with that host name is retrieved from 
*    the registry.  If the host name is not found failure is returned.       
*                                                                            
* AUTHOR
*
*   Glen Johnson
*
* INPUTS                                                                     
*                                                                            
*    CHAR *hostname:  A pointer to the host name.                            
*                                                                            
* OUTPUTS                                                                    
*                                                                            
*    sshort   : Returns NU_SUCCESS if ok, else -1                            
*                                                                            
*    When successful the ID has been found and set.                          
*                                                                            
******************************************************************************/
STATUS VDRV_Lookup_ID(CHAR *hostname)
{
    DWORD                   valueDWORD, dataSize = 4;
    HKEY                    hKey, subKey;
    UINT                    stat;
    CHAR                    searchName[32];
    DWORD                   hostNameSize = sizeof (searchName);
    FILETIME                Dummy;
    DWORD                   i;

    /* Open a key to the VNETDRV entry in the system Registry.  Below each
       subkey of this key will be read and added to the "host file".
    */
    if ((stat = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                        "SYSTEM\\CURRENTCONTROLSET\\SERVICES\\VNETDRV",
                        0, KEY_ALL_ACCESS, &hKey)) != ERROR_SUCCESS)
        return (-1);

    /* Search each subkey until a match is found or there are no more subkeys. */
    for (i=0;;i++)
    {
        hostNameSize = sizeof (searchName);

        if ((stat = RegEnumKeyEx(hKey, i, searchName, &hostNameSize, 0, NULL,
                                 NULL, &Dummy)) != ERROR_SUCCESS)

            /* There are no more subkeys and no match was found. */
            return (-1);


        /* Break on a m

⌨️ 快捷键说明

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