📄 libif.c
字号:
/*
*
* libif.c
*
* Part of the Myson Century CS620X Ping demo program.
*
* Authors: LY Lin, WM Wang, IJ Chen, WH Lee
*
* libif.c contains ethernet and protocol stack interface routines.
*
* This program was developed using the Keil 8051 C uVision 2 system.
* The Keil compiler MUST be used if working with Myson Century supplied
* firmware.
*
* This program must be linked with the 620xlib.LIB library
* supplied by Myson Century in object module form.
*
*
* Note: Do not remove or rename any function or variable in this file.
*/
#define LIBIF_C
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "hpserver.h"
#include "620xenet.h"
#include "timer.h"
#include "ether.h"
#include "netutil.h"
#include "net.h"
#include "ip.h"
#include "tcp.h"
#include "config.h"
/* Frame for network Tx/Rx */
GENFRAME genframe;
/* My Ethernet and IP addresses */
NODE locnode;
unsigned char gfp_buff_flag=0;
/************************************************************************
/* Function Name : locnode_n *
/* *
/* Arguments : *
/* int n :locnode index to get. *
/* *
/* Return : *
/* Return ptr to local node 'n' (n=0 for first) or *
/* return 0 if doesn't exist *
/* *
/* Comment : *
/* This function Used by IP functions to get netmask & *
/* gateway addresses. *
/* *
/************************************************************************/
NODE *locnode_n(int n)
{
return(n==0 ? &locnode : 0);
}
/************************************************************************
/* Function Name : server_action *
/* *
/* Arguments : *
/* TSOCK *ts :Point to current socket. *
/* CONN_STATE conn : connect state of current socket. *
/* *
/* Return : *
/* Return 0 to prevent connection opening, or close *
/* if connected. *
/* *
/* Comment : *
/* This function upcall from TCP stack to server when opening, *
/* connecting,receiving data or closing a port. *
/* *
/************************************************************************/
int server_action(TSOCK *ts, CONN_STATE conn)
{
WORD port;
/* Uncomment this line to set the Urgent and Push Flag in the TCP/IP packet. */
ts->connflags = ts->connflags|TURGE|TPUSH;
port = ts->loc.port;
return 0;
}
/************************************************************************
/* Function Name : client_action *
/* *
/* Arguments : *
/* TSOCK *ts :Point to current socket. *
/* CONN_STATE conn : connect state of current socket. *
/* *
/* Return : *
/* Return 0 to prevent connection opening, or close *
/* if connected. *
/* *
/* Comment : *
/* This function upcall from TCP stack to client when opening, *
/* connecting,receiving data or closing a port. *
/* *
/************************************************************************/
int client_action(TSOCK *ts, CONN_STATE conn)
{
/* Uncomment this line to set the Urgent and Push Flag in the TCP/IP packet. */
ts->connflags = ts->connflags|TURGE|TPUSH;
if (ts->upcall)
return (ts->upcall(ts,conn));
/*client socket doesn't have upcall function.*/
return 0;
}
/************************************************************************
/* Function Name : get_frame *
/* *
/* Arguments : *
/* GENFRAME xdata *gfp:Point to GENFRAME to return frame. *
/* *
/* Return : *
/* The size in byte receive from network. *
/* *
/* Comment : *
/* This function gets an ethernet frame from the network. *
/* Return the frame length excluding the. hardware header. *
/* *
/************************************************************************/
int get_frame (GENFRAME xdata *gfp)
{
/* check if anything is received on the Ethernet Interface*/
if (gfp->g.dtype == DTYPE_ETHER)
if ((gfp->g.len = Ethernet_Receive (gfp->buff))>0)
{
return (gfp->g.len - sizeof (ETHERHDR));
}
return (0);
}
/************************************************************************
/* Function Name : put_frame *
/* *
/* Arguments : *
/* GENFRAME xdata *gfp:Point to GENFRAME to be transmitted. *
/* int len : The data length of gfp *
/* *
/* Return : *
/* The size size in byte transmit to network. *
/* *
/* Comment : *
/* This function aend an ethernet frame out onto the network. *
/* *
/************************************************************************/
int put_frame (GENFRAME xdata *gfp, int len)
{
extern xdata unsigned char nic_xmit_buf [];
int ret=0;
if (len > 0)
{
/* wait until the last transmission is done*/
while (!Ethernet_Transmit_Ready ());
/* copy to a page-aligned buffer*/
/* Edit by lin_jy 021219
memcpy (nic_xmit_buf, gfp->buff, (WORD)len);
ret = Ethernet_Transmit (nic_xmit_buf, (WORD)len);*/
ret = Ethernet_Transmit (gfp->buff, (WORD)len);
if (gfp_buff_flag)
{
gfp_buff_flag=0;
gfp->buff=&nic_xmit_buf[0];
}
else
{
gfp_buff_flag=1;
gfp->buff=&nic_xmit_buf[1536];
}
}
return(ret);
}
/************************************************************************
/* Function Name : udp_receive *
/* *
/* Arguments : *
/* GENFRAME *gfp:Point to GENFRAME that contain UDP packet. *
/* int len : UDP data size. *
/* *
/* Return : *
/* None. *
/* *
/* Comment : *
/* This function upcall from TCP stack to client when opening, *
/* connecting,receiving data or closing a port. *
/* *
/************************************************************************/
void udp_receive(GENFRAME *gfp, int len)
{
/*Below is a sample code for udp application*/
/*
UDPKT *udp;
NODE loc, rem;
udp = getframe_datap(gfp);
getudp_srce(gfp, &rem);
getudp_locdest(gfp, &loc);
*/
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -