📄 dev.c
字号:
/**************************************************************************
*
* Copyright (c) 1993 - 2001 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
*
* DEV.C 4.4
*
* DESCRIPTION
*
* This file is responsible for intializing all of the devices that will
* be used with a specific instatiation of Nucleus NET. This code may
* be changed into a dynamic module in the future.
*
* DATA STRUCTURES
*
* Check in file 'dev.h'
*
* FUNCTIONS
*
* DEV_Attach_IP_To_Device
* DEV_Detach_IP_From_Device
* DEV_Get_Dev_By_Addr
* DEV_Get_Dev_By_Name
* DEV_Get_Dev_For_Vector
* DEV_Get_Ether_Address
* DEV_Init_Devices
* DEV_Init_Route
* DEV_Recover_TX_Buffers
*
* DEPENDENCIES
*
* other file dependencies
*
****************************************************************************/
#include "plus/nucleus.h"
#include "net/target.h"
#include "net/inc/externs.h"
#include "net/inc/ip.h"
#include "net/inc/tcp.h"
#include "net/inc/dev.h"
#include "net/inc/tcpdefs.h"
#include "net/inc/net.h"
#include "net/inc/arp.h"
#include "net/inc/igmp.h"
#if (INCLUDE_SNMP == NU_TRUE)
#include SNMP_GLUE
#endif
/* List of devices. */
DV_DEVICE_LIST DEV_Table;
extern NU_TASK rip2_task_ptr;
/**************************************************************************
* FUNCTION
*
* DEV_Init_Devices
*
* DESCRIPTION
*
* This function will initialize all of the devices that will be used by
* Nucleus NET. It will be hard coded to set up the devices based on the
* developer's requirements.
*
*
* INPUTS
*
* devices Pointer to device to init.
* dev_count Number of such devices.
*
* OUTPUTS
*
* NU_SUCCESS Successful init.
* -1 Failure.
*
****************************************************************************/
STATUS DEV_Init_Devices (DEV_DEVICE *devices, INT dev_count)
{
STATUS status;
DV_DEVICE_ENTRY *dev_ptr;
INT i;
static INT next_index = 0;
INT length;
NU_SUPERV_USER_VARIABLES
/* Switch to supervisor mode. */
NU_SUPERVISOR_MODE();
for ( i = 0; i < dev_count; i++)
{
/* Allocate memory for this device entry. */
if ((status = NU_Allocate_Memory(&System_Memory, (VOID **)&dev_ptr,
(UNSIGNED)(sizeof(struct _DV_DEVICE_ENTRY)),
(UNSIGNED)NU_NO_SUSPEND)) != NU_SUCCESS)
{
NU_USER_MODE();
return (status);
}
/* Clear out the structure. */
UTL_Zero(dev_ptr, sizeof(struct _DV_DEVICE_ENTRY));
/* Add the new device entry to the list of devices. */
DLL_Enqueue(&DEV_Table, dev_ptr);
/* Set the routing metric for this device. By default the metric will
always be set to 1. Later if a user chooses to use RIP2 or OSPF
with this device, the metric can be changed. */
dev_ptr->dev_metric = DEV_DEFAULT_METRIC;
/* Now initialize the fields that we can. The rest will be initialized
by the driver. */
/* Set the unit number. This number will be unique for all devices.
The first will be numbered at 0 each succeeding device will be
numbered contiguously. */
dev_ptr->dev_index = next_index++;
/* Initialize the device's name. If the supplied name is too long only
copy that portion which will fit and still leave room for the null
terminator. */
if ((length = strlen(devices[i].dv_name)) > (DEV_NAME_LENGTH - 1))
{
length = DEV_NAME_LENGTH - 1;
}
memcpy(dev_ptr->dev_net_if_name, devices[i].dv_name, (unsigned int)length);
dev_ptr->dev_net_if_name[length] = 0;
/* Get the flags set by the application */
dev_ptr->dev_flags = devices[i].dv_flags;
/* Set the driver options. This may or may not be used
by the driver, it is driver specific. */
dev_ptr->dev_driver_options = devices[i].dv_driver_options;
/* Is this a serial link? */
if (devices[i].dv_flags & DV_POINTTOPOINT)
{
/* Store the options that pertain only to a serial link. All of
these may not be used. It depends on the UART. */
dev_ptr->dev_com_port = devices[i].dv_hw.uart.com_port;
dev_ptr->dev_baud_rate = devices[i].dv_hw.uart.baud_rate;
dev_ptr->dev_data_mode = devices[i].dv_hw.uart.data_mode;
dev_ptr->dev_parity = devices[i].dv_hw.uart.parity;
dev_ptr->dev_stop_bits = devices[i].dv_hw.uart.stop_bits;
dev_ptr->dev_data_bits = devices[i].dv_hw.uart.data_bits;
}
else
{
/* Store the options that pertain only to an ethernet link */
dev_ptr->dev_irq = devices[i].dv_hw.ether.dv_irq;
dev_ptr->dev_sm_addr = devices[i].dv_hw.ether.dv_shared_addr;
dev_ptr->dev_io_addr = devices[i].dv_hw.ether.dv_io_addr;
}
/* Add the new interface to the list that SNMP knows about. This
initialization must be done before the call to the dv_init function
below as that function will up date the interface information. */
#if (defined(SNMP_VER) == NU_TRUE)
SNMP_ifCreate(dev_ptr->dev_index, devices[i].dv_ip_addr, devices[i].dv_subnet_mask);
#else
SNMP_ifCreate(dev_ptr->dev_index);
#endif
/* Update the total number of interfaces that have been registered with SNMP.
The index is 0 based, so add 1. */
SNMP_ifTotalInterfaces(dev_ptr->dev_index + 1);
if( (status = (devices[i].dv_init)(dev_ptr)) != NU_SUCCESS)
{
NU_USER_MODE();
return status;
}
/* Indicate that the device is Running. */
dev_ptr->dev_flags |= DV_RUNNING;
/* If an IP address was specified and this is not a PPP device then
go ahead and attach the IP address and the subnet mask. Otherwise
it is assumed Bootp will be used to discover the IP address and
attach it at a later time. */
if (( *(UINT32 *)devices[i].dv_ip_addr != 0 ) &&
(!(devices[i].dv_flags & DV_POINTTOPOINT)))
{
if ((status = DEV_Attach_IP_To_Device(dev_ptr->dev_net_if_name,
(UINT8 *)devices[i].dv_ip_addr,
(UINT8 *)devices[i].dv_subnet_mask))
!= NU_SUCCESS)
{
NU_USER_MODE();
return (status);
}
}
else
/* Clear the devices IP address. */
dev_ptr->dev_addr.dev_ip_addr = 0;
}
NU_USER_MODE();
/* Everything is OK. */
return( NU_SUCCESS );
} /* DEV_Init_Devices. */
/**************************************************************************
* FUNCTION
*
* DEV_Get_Dev_For_Vector
*
* DESCRIPTION
*
* Given a vector number, this routine will find the device that resides
* there and return the device table address.
*
*
* INPUTS
*
* vector - the vector for which the requestor is finding a device
*
* OUTPUTS
*
* DV_DEVICE_ENTRY* Address of the device table entry for the
* device found or 0 if not found.
*
****************************************************************************/
DV_DEVICE_ENTRY *DEV_Get_Dev_For_Vector( INT vector )
{
DV_DEVICE_ENTRY *temp_dev_table;
/* Look at the first in the list. */
temp_dev_table = DEV_Table.dv_head;
/* Search for a match. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -