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

📄 nnetdrv.c

📁 基于nucleus操作系统的GPRS无线数据传输终端全套源文件。包括支持ARM7的BSP,操作系统
💻 C
📖 第 1 页 / 共 5 页
字号:
/****************************************************************************/
/*                                                                          */
/*      Copyright (c) 2002 by Accelerated Technology, Inc.                  */
/*                                                                          */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the subject */
/* matter of this material.  All manufacturing, reproduction, use and sales */
/* rights pertaining to this subject matter are governed by the license     */
/* agreement.  The recipient of this software implicity accepts the terms   */
/* of the license.                                                          */
/*                                                                          */
/****************************************************************************/
/****************************************************************************
*                                                                          
* FILENAME                                                 VERSION         
*                                                                          
*    NNETDRV.C                                              4.4.6            
*                                                                          
* DESCRIPTION                                                              
*                                                                          
*    This is a driver for a simulated network executing on an NT work      
*    station.  It provides all of the standard routines that Nucleus NET   
*    expects to find in an Ethernet driver for a real NIC.  It must be used
*    in conjunction with the the virtual NT network driver and the vitual  
*    NDIS driver.  It provides the interface to the virtual network.       
*    The virtual network is large common memory area that can be accessed  
*    through calls to an NT driver developed for this purpose.             
*                                                                          
* AUTHOR                                                                   
*                                                                          
*    Glen Johnson                                                          
*                                                                          
* DATA STRUCTURES                                                          
*                                                                          
*    Check in files MNT.H and MNTRING.H                                    
*                                                                          
* FUNCTIONS                                                                
*                                                                          
*     NU_Get_Address                                                       
*     VDRV_Open                                                            
*     NU_Recv_Packet                                                       
*     VDRV_Xmit_Packet                                                     
*     NU_Close_Driver                                                      
*     VDRV_ISR                                                             
*     VDRV_Lookup_Host                                                     
*     VDRV_Lookup_Default_Gateway                                          
*     VDRV_Lookup_Base_Ether                                               
*     VDRV_Init_MNT_DESC                                                   
*     VDRV_Recv_HISR                                                       
*     VDRV_Ioctl                                                           
*     VDRV_DNS_Init                                                        
*                                                                          
* DEPENDENCIES                                                             
*                                                                          
*  other file dependencies                                                 
*                                                                          
* HISTORY                                                                  
*                                                                          
*  NAME              DATE       REMARKS                                    
*                                                                          
*  Glen Johnson      xx/xx/xx   Created initial version                    
*  Uriah T. Pollock  10/24/97   Removed the config.h dependency. This file 
*                                 has been removed.                        
*                                                                          
****************************************************************************/
#ifndef _WINSOCKAPI_
#define _WINSOCKAPI_     /* _WINSOCKAPI_ must be defined to keep the      */
#endif                   /* winsock.h file from being included.  If it is */
                         /* included some of the typedefs will conflict   */
                         /* with those in Nucleus NET.                    */

#include "plus\nucleus.h"
#include "net\target.h"
#include "net\inc\externs.h"
#include "net\inc\ip.h"
#include "net\inc\nerrs.h"
#include "net\inc\arp.h"
#include "net\inc\net.h"
#include "net\inc\mem_defs.h"

#include <windows.h>
#include <process.h>
#include "mnt.h"
#include "mntring.h"
#include "hardware\hardware.h"

#if (INCLUDE_SNMP == NU_TRUE)
#include SNMP_GLUE
#endif

#ifndef PACKET
#error PACKET must be defined in TARGET.H for this driver to work.
#endif

/*
*  full IP packet, with data and ip header
*/

typedef struct ip
{
    DLAYER d;
    IPLAYER i;
    union
    {
        UINT8 data[536];       /* largest recommended, may include options */
        UINT8 options[40];
    } x;
} IPKT;

typedef enum _INTERFACE_TYPE
{
    Internal,
    Isa,
    Eisa,
    MicroChannel,
    TurboChannel,
    MaximumInterfaceType
} INTERFACE_TYPE, *PINTERFACE_TYPE;


#include "control.h"

/* Driver handle, this is necessary for all communication with the driver. */
HANDLE              hDriver;

/* Base address of the common memory area as mapped into this processes virtual
 * address space. */
PMNT_ANCHOR         CommonMemPtr;

/* Handle of the Recv thread. */
HANDLE              hRecvThread;

/* Base address of the common memory area as written to the system registry by
 * NDIS, i.e., this is mapped to NDIS driver's virtual address space. */
PMNT_ANCHOR         NDISComMemStart;

MNT_HEADER          *MNT_Header_Ptr;
UCHAR               VNET_ether_addr_base[6];
ULONG               VNET_Ncpu;
ULONG               MNT_ID = 0;
ULONG               VNET_BaseEtherAddr = 0;
CHAR                Ether_Addr[6];
                                           
NU_HISR             Recv_HISR;
VOID (*oldlisr)(INT);
INT                 VDRV_Driver_Closing = 0;

/* External global variable references */
extern struct config Scon;             /* current configuration */
extern struct machinfo defmachinfo[];
extern struct machinfo *Smachlist;
extern NU_TASK  timer_task_ptr;
extern thrd_t Recv_Thread_ID;
extern INT    interrupt_level;                /* set during interrupt */
extern UNSIGNED Recv_Thread_Suspended;
extern INT In_ISR;
extern INT (*VectorTable[VCTRTBLSIZE])();
extern VOID   (*INT_Vector_Table[VCTRTBLSIZE])(INT);
extern INT TCD_Interrupt_Level;
extern VOID TCT_Interrupt_Context_Restore();
extern VOID  TCT_Interrupt_Context_Save();


/*  Prototypes  */

/* Declarations for the interrupt service routines, tasks, and functions that
 * are required when interrupts are used. */
STATUS  VDRV_Open (UINT8 *ether_addr, DV_DEVICE_ENTRY *device);
STATUS  VDRV_Xmit_Packet (DV_DEVICE_ENTRY *, NET_BUFFER *);
VOID    demo_exit(INT exit_value);
INT     VDRV_Init_MNT_DESC(MNT_HEADER *header_ptr, ULONG id);
INT     VDRV_ISR(INT vector);
STATUS  VDRV_Lookup_Host(CHAR *hostname, CHAR *ip_addr);
STATUS  VDRV_Lookup_Default_Gateway(DV_DEVICE_ENTRY *device);
VOID    NU_Recv_Packet (LPDWORD unusedParam);
VOID    VDRV_Recv_HISR (VOID);
STATUS  VDRV_Lookup_Base_Ether(VOID);
STATUS  VDRV_Lookup_ID(CHAR *hostname);
STATUS  VDRV_Ioctl(DV_DEVICE_ENTRY *dev, INT option, DV_REQ *d_req);
STATUS  VDRV_DNS_Init(VOID);

/* These three pointers are used in the function VDRV_Xmit_Packet.  By making them
   global I was able to allocate memory for them once at initialization time.
   The alternative was to allocate and deallocate the memory each time
   VDRV_Xmit_Packet was called.
*/
IOCTL_OUT_MULTI_RINGPUT  *mRingputInfo;
IOCTL_OUT_MULTI_GENEVENT *mGeneventOut;
IOCTL_IN_MULTI_RINGGET   *mRinggetInput;

extern void     PRINTF(CHAR *fmt, ...);

extern DNS_HOST_LIST   DNS_Hosts;

/******************************************************************************
* FUNCTION                                                                   
*                                                                            
*  VDRV_Init                                                                 
*                                                                            
* DESCRIPTION                                                                
*                                                                            
*  Initialize the device structure for the virtual network device.           
*                                                                            
* AUTHOR                                                                   
*                                                                          
*    Glen Johnson                                                          
*                                                                            
* INPUTS                                                                     
*                                                                            
* DV_DEVICE_ENTRY * : A pointer to this device's device structure.           
*                                                                            
* OUTPUTS                                                                    
*                                                                            
*    NU_SUCCESS upon success a negative value otherwise.                     
*    returned.                                                               
*                                                                            
* HISTORY                                                                    
*                                                                            
*    NAME                DATE        REMARKS                                 
*                                                                            
*    Glen Johnson      05/06/98      Created Intial version.                 
*                                                                            
******************************************************************************/
STATUS VDRV_Init(DV_DEVICE_ENTRY *device)
{
    /*  Initialize the various function pointers. */
    device-> dev_open      = VDRV_Open;
    device-> dev_start     = VDRV_Xmit_Packet;
    device-> dev_output    = NET_Ether_Send;
    device-> dev_input     = NET_Ether_Input;
    device-> dev_ioctl     = VDRV_Ioctl;
    device-> dev_type      = DVT_ETHER;
    device-> dev_addrlen   = 6;
    device-> dev_hdrlen    = sizeof (DLAYER);
    device-> dev_mtu       = 1500; /* MTU excludes the size of the MAC layer header. */

    device->dev_flags |= (DV_BROADCAST | DV_SIMPLEX | DV_MULTICAST);

    /*  Initialize the device.  */
    return ( (*(device->dev_open)) (device->dev_mac_addr, device) );

} /* VDRV_Init */

/******************************************************************************
* FUNCTION                                                                   
*                                                                            
*  NU_Get_Address                                                            
*                                                                            
* DESCRIPTION                                                                
*                                                                            
*  This function will simply return the ethernet address of this MNT         
*  process.  The ethernet address is initialized during the execution of     
*  VDRV_Open.                                                                
*                                                                            
* AUTHOR                                                                   
*                                                                          
*    Glen Johnson                                                          
*
* INPUTS                                                                     
*                                                                            
*   UINT8 *  : pointer to the location to store the Ethernet address.           
*   UINT32   : not used in this driver.                                        
*   UINT32   : not used in this driver.                                        
*                                                                            
* OUTPUTS                                                                    
*                                                                            
*    ether_addr is filled in with the ethernet address ans NU_Success is     
*    returned.                                                               
*                                                                            
*****************************************************************************/
INT16 NU_Get_Address (UINT8 *ether_addr, UINT32 not_used, UINT32 io_base)    
{                                                                            
    INT         i;                                                           

    /* Simply copy the ethernet address into the caller's buffer. */
    for(i=0; i<6; i++)
        ether_addr[i] = Ether_Addr[i];

    return(NU_SUCCESS);

}        /* end NU_Get_Address routine */

/******************************************************************************
* FUNCTION                                                                   
*                                                                            
*    VDRV_Open                                                               
*                                                                            
* DESCRIPTION                                                                
*                                                                            
*    This function will handle the initilization of virtual network.  Its    
*    functions include the following:  Get a handle to the NT driver that    
*    simulates the hardware.  Verify that the NDIS is up and running.        
*    Initialize global data structures and variables required by the driver. 
*    Create the receive HISR.  Create the LISR to handle the simualted       
*    interrupt.                                                              
*
* AUTHOR                                                                   
*                                                                          
*    Glen Johnson                                                          
*                                                                            
* INPUTS                                                                     
*                                                                            
*    schar * : not used in this driver.                                      

⌨️ 快捷键说明

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