📄 net.c
字号:
/*************************************************************************
*
* CopyrIght (c) 1993 - 2001 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.
*
*************************************************************************/
/* Portions of this program were written by: */
/*************************************************************************
*
* part of:
* TCP/UDP/ICMP/IP Network kernel for NCSA Telnet
* by Tim Krauskopf
*
* National Center for Supercomputing Applications
* 152 Computing Applications Building
* 605 E. Springfield Ave.
* Champaign, IL 61820
*
*************************************************************************/
/*************************************************************************
*
* FILENAME VERSION
*
* NET.C 4.4
*
* DESCRIPTION
*
* This file will hold all the routines which are used to interface
* with the hardware. They will handle the basic functions of of
* setup, xmit, receive, etc. This file will change depending on the
* type of chip(s) you are using to handle the TCP/IP interface.
* These file are generic and will need to be changed for your
* specified interface. This file will use structure overlays for
* the chip(s) with the offset defines from the file chipint.h.
*
* DATA STRUCTURES
*
* NET_Ether_Broadaddr[DADDLEN]
*
* FUNCTIONS
*
* NET_Ether_Input
* NET_Ether_Send
* NET_Add_Multi
* NET_Del_Multi
*
* DEPENDENCIES
*
* nucleus.h
* target.h
* externs.h
* ip.h
* nerrs.h
* net.h
* arp.h
* mem_defs.h
*
*************************************************************************/
#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/net.h"
#include "net/inc/arp.h"
#include "net/inc/mem_defs.h"
#if (INCLUDE_SNMP == NU_TRUE)
#include SNMP_GLUE
#endif
/* The ethernet hardware broadcast address */
const UINT8 NET_Ether_Broadaddr[DADDLEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
/* Declare the global function pointer for SPAN. When SPAN is initialized
it will set this to point to the correct function. Otherwise this
will point to zero and will not be used. */
UINT32 (*span_process_packet) (UINT8 *, UINT32, UINT32);
#define SPAN_CONFIG 0x0026
#define SPAN_TOP_CHG 0x0007
/* Declare the global function pointer for PPPoE. */
VOID (*ppe_process_packet)(UINT16);
/*************************************************************************
*
* FUNCTION
*
* NET_Ether_Input
*
* DESCRIPTION
*
* Examines input ethernet packet and determines what type of
* packet it is. It then calls the proper interpret routine.
*
* INPUTS
*
* None
*
* OUTPUTS
*
* NU_SUCCESS
*
*************************************************************************/
STATUS NET_Ether_Input (VOID)
{
UINT16 getcode;
UINT8 *ether_pkt;
DV_DEVICE_ENTRY *device;
/* Point to the packet. */
ether_pkt = (UINT8 *)(MEM_Buffer_List.head->data_ptr);
/* Get a pointer to the device. */
device = MEM_Buffer_List.head->mem_buf_device;
/* If this packet was addressed to either a broadcast or multicast address
set the appropriate flag. */
if(EQ_STRING(ether_pkt, ETHER_DEST_OFFSET, NET_Ether_Broadaddr, DADDLEN))
{
MEM_Buffer_List.head->mem_flags |= NET_BCAST;
SNMP_ifInNUcastPkts_Inc(device->dev_index);
#if (INCLUDE_SNMP == NU_TRUE)
#if (INCLUDE_MIB_RMON1 == NU_TRUE)
RMON_BroadcastPkts_Inc(device->dev_index);
#endif
#endif
}
else if (GET8(ether_pkt, ETHER_DEST_OFFSET) & 1)
{
MEM_Buffer_List.head->mem_flags |= NET_MCAST;
SNMP_ifInNUcastPkts_Inc(device->dev_index);
#if (INCLUDE_SNMP == NU_TRUE)
#if (INCLUDE_MIB_RMON1 == NU_TRUE)
RMON_MulticastPkts_Inc(device->dev_index);
#endif
#endif
}
else
{
SNMP_ifInUcastPkts_Inc(device->dev_index);
}
/* What type of packet is this? */
getcode = GET16(ether_pkt, ETHER_TYPE_OFFSET);
/* Strip the ethernet header and size off of the packet */
MEM_Buffer_List.head->data_ptr += device->dev_hdrlen;
MEM_Buffer_List.head->data_len -= device->dev_hdrlen;
MEM_Buffer_List.head->mem_total_data_len -= device->dev_hdrlen;
switch (getcode)
{ /* what to do with it? */
case EARP:
case ERARP:
/* This is an ARP packet */
ARP_Interpret ((ARP_LAYER *)MEM_Buffer_List.head->data_ptr, device);
/* We are finished with the ARP packet. */
/* Drop the packet by placing it back on the buffer_freelist. */
MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
break;
case PPPOED:
case PPPOES:
/* If PPPoE has been initialized, then ppe_process_packet will have
been set to the handler function. */
if (ppe_process_packet != NU_NULL)
{
ppe_process_packet(getcode);
}
else
{
/* Log the unknown protocol. */
SNMP_ifInUnknownProtos_Inc(device->dev_index);
/* Drop the packet by placing it back on the buffer_freelist. */
MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
}
break;
case EIP:
/* This is an IP packet. */
IP_Interpret ((IPLAYER *)MEM_Buffer_List.head->data_ptr, device, MEM_Buffer_List.head);
break;
default:
/* If SPAN has been initialized this function pointer will
be setup. Therefore we need to check to see if this
packet is a SPAN type packet. */
if (span_process_packet != NU_NULL)
{
if( (getcode == SPAN_CONFIG) || (getcode == SPAN_TOP_CHG) )
{
/* Point to the packet. */
MEM_Buffer_List.head->data_ptr -= device->dev_hdrlen;
MEM_Buffer_List.head->data_len += device->dev_hdrlen;
MEM_Buffer_List.head->mem_total_data_len +=
device->dev_hdrlen;
span_process_packet((UINT8 *)MEM_Buffer_List.head->data_ptr,
device->dev_index,
(UINT32)getcode);
}
}
else
{
/* Log the unknown protocol. */
SNMP_ifInUnknownProtos_Inc(device->dev_index);
}
/* Drop the packet by placing it back on the buffer_freelist. */
MEM_Buffer_Chain_Free (&MEM_Buffer_List, &MEM_Buffer_Freelist);
break;
} /* end switch */
return (NU_SUCCESS);
} /* NET_Ether_Input */
/*************************************************************************
*
* FUNCTION
*
* NET_Ether_Send
*
* DESCRIPTION
*
* This function is the hardware layer transmission function for
* Ethernet. Other physical mediums (serial, token ring, etc.)
* will have their own transmit functions. Given a packet to
* transmit this function first resolves the hardware layer address
* and then queues the packet for transmission.
*
* INPUTS
*
* *buf_ptr
* *device
* *dest
* *ro
*
* OUTPUTS
*
* NU_HOST_UNREACHABLE
* NU_SUCCESS
* -1
*
*************************************************************************/
STATUS NET_Ether_Send(NET_BUFFER *buf_ptr, DV_DEVICE_ENTRY *device,
SCK_SOCKADDR_IP *dest, RTAB_ROUTE *ro)
{
#ifndef PACKET
INT old_int;
#endif
ROUTE_NODE *rt = NU_NULL;
UINT8 mac_dest[DADDLEN];
ARP_MAC_HEADER *eh; /* Ethernet header pointer */
INT16 type;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -