📄 net_tftpc.c
字号:
/************************************************************************
*
* NET_TFTPC.c
*
* The 'NET_TFTPC' module implements the TFTP client application,
* which provides services to read a file by use of the
* TFTP-protocol.
*
*
* ######################################################################
*
* Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved.
*
* Unpublished rights reserved under the Copyright Laws of the United States of
* America.
*
* This document contains information that is proprietary to MIPS Technologies,
* Inc. ("MIPS Technologies"). Any copying, modifying or use of this information
* (in whole or in part) which is not expressly permitted in writing by MIPS
* Technologies or a contractually-authorized third party is strictly
* prohibited. At a minimum, this information is protected under unfair
* competition laws and the expression of the information contained herein is
* protected under federal copyright laws. Violations thereof may result in
* criminal penalties and fines.
* MIPS Technologies or any contractually-authorized third party reserves the
* right to change the information contained in this document to improve
* function, design or otherwise. MIPS Technologies does not assume any
* liability arising out of the application or use of this information. Any
* license under patent rights or any other intellectual property rights owned
* by MIPS Technologies or third parties shall be conveyed by MIPS Technologies
* or any contractually-authorized third party in a separate license agreement
* between the parties.
* The information contained in this document constitutes one or more of the
* following: commercial computer software, commercial computer software
* documentation or other commercial items. If the user of this information, or
* any related documentation of any kind, including related technical data or
* manuals, is an agency, department, or other entity of the United States
* government ("Government"), the use, duplication, reproduction, release,
* modification, disclosure, or transfer of this information, or any related
* documentation of any kind, is restricted in accordance with Federal
* Acquisition Regulation 12.212 for civilian agencies and Defense Federal
* Acquisition Regulation Supplement 227.7202 for military agencies. The use of
* this information by the Government is further restricted in accordance with
* the terms of the license agreement(s) and/or applicable contract terms and
* conditions covering this information from MIPS Technologies or any
* contractually-authorized third party.
*
************************************************************************/
/************************************************************************
* Include files
************************************************************************/
//#define NET_DEBUG 1
#include <string.h>
#include <stdio.h>
#include <sysdefs.h>
#include <syserror.h>
#include <sysdev.h>
#include <syscon_api.h>
/* net stuff */
#include <net_api.h>
#include "net.h"
#include "net_mac.h"
#include "net_ip.h"
#include "net_udp.h"
#include "net_tftpc.h"
/************************************************************************
* Definitions
************************************************************************/
/************************************************************************
* Public variables
************************************************************************/
/************************************************************************
* Static variables
************************************************************************/
/* Global state of TFTPC */
static UINT32 NET_TFTPC_state = TFTPC_STATE_CLOSED ;
/* SAP */
static t_tftpc_sap_context sap_context ;
/************************************************************************
* Static function prototypes
************************************************************************/
static
UINT32 NET_TFTPC_dumpcontext( void ) ;
/************************************************************************
*
* NET_TFTPC_receive_ack
* Description :
* -------------
* This function is registered in the UDP-module and linked with a
* unique UDP-'port', idnetifying our SAP. This allows the UDP to call
* us back with an reference to the received frame,
* containing a TFTP-frame.
*
*
*
* Parameters :
* ------------
* 'src_ip_adr': senders IP-address in BE-format
* 'src_port': senders UDP-port in BE-format
* 'src_mac_adr': senders MAC-address
* 'udp_sp_hd': UDP defined handle, identifying our SAP (i.e. port)
* 'length': length of received ethernet frame
* 'data': pointer for received ethernet frame (in driver's space)
*
*
* Return values :
* ---------------
* 'OK'
*
************************************************************************/
static
UINT32 NET_TFTPC_receive_ack(
UINT32 src_ip_adr, /* IP BE-format */
UINT16 src_port, /* port BE-format */
t_mac_addr *src_mac_adr,/* MAC */
UINT32 udp_sp_hd, /* handle of open */
UINT32 length, /* total length */
UINT8 *data ); /* start of frame */
/************************************************************************
*
* NET_TFTPC_receive_data_block
* Description :
* -------------
* This function is registered in the UDP-module and linked with a
* unique UDP-'port', idnetifying our SAP. This allows the UDP to call
* us back with an reference to the received frame,
* containing a TFTP-frame.
*
*
*
* Parameters :
* ------------
* 'src_ip_adr': senders IP-address in BE-format
* 'src_port': senders UDP-port in BE-format
* 'src_mac_adr': senders MAC-address
* 'udp_sp_hd': UDP defined handle, identifying our SAP (i.e. port)
* 'length': length of received ethernet frame
* 'data': pointer for received ethernet frame (in driver's space)
*
*
* Return values :
* ---------------
* 'OK'
*
************************************************************************/
static
UINT32 NET_TFTPC_receive_data_block(
UINT32 src_ip_adr, /* IP BE-format */
UINT16 src_port, /* port BE-format */
t_mac_addr *src_mac_adr,/* MAC */
UINT32 udp_sp_hd, /* handle of open */
UINT32 length, /* total length */
UINT8 *data ); /* start of frame */
/************************************************************************
*
* NET_TFTPC_receive_data_byte
* Description :
* -------------
* This function is registered in the UDP-module and linked with a
* unique UDP-'port', idnetifying our SAP. This allows the UDP to call
* us back with an reference to the received frame,
* containing a TFTP-frame.
*
*
*
* Parameters :
* ------------
* 'src_ip_adr': senders IP-address in BE-format
* 'src_port': senders UDP-port in BE-format
* 'src_mac_adr': senders MAC-address
* 'udp_sp_hd': UDP defined handle, identifying our SAP (i.e. port)
* 'length': length of received ethernet frame
* 'data': pointer for received ethernet frame (in driver's space)
*
*
* Return values :
* ---------------
* 'OK'
*
************************************************************************/
static
UINT32 NET_TFTPC_receive_data_byte(
UINT32 src_ip_adr, /* IP BE-format */
UINT16 src_port, /* port BE-format */
t_mac_addr *src_mac_adr,/* MAC */
UINT32 udp_sp_hd, /* handle of open */
UINT32 length, /* total length */
UINT8 *data ); /* start of frame */
/************************************************************************
*
* NET_TFTPC_init_sap
* Description :
* -------------
* Initialize the TFTPC SAP context.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0), successfull initialization
*
************************************************************************/
static
UINT32 NET_TFTPC_init_sap( t_tftpc_sap_context *context ) ;
/************************************************************************
*
* NET_TFTPC_reset_sap
* Description :
* -------------
* Reset the TFTPC SAP context.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0), successfull initialization
I
************************************************************************/
static
UINT32 NET_TFTPC_reset_sap( t_tftpc_sap_context *context,
t_udp_usr_receive rec ) ;
/************************************************************************
*
* NET_TFTPC_sendDATA
* Description :
* -------------
* Send 'DATA' of this SAP context.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0),
*
************************************************************************/
static
UINT32 NET_TFTPC_sendDATA( t_tftpc_sap_context *context ) ;
/************************************************************************
*
* NET_TFTPC_sendRRQ
* Description :
* -------------
* Send 'RRQ' of this SAP context.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0),
*
************************************************************************/
static
UINT32 NET_TFTPC_sendRRQ( t_tftpc_sap_context *context ) ;
/************************************************************************
*
* NET_TFTPC_sendWRQ
* Description :
* -------------
* Send 'WRQ' of this SAP context.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0),
*
************************************************************************/
static
UINT32 NET_TFTPC_sendWRQ( t_tftpc_sap_context *context ) ;
/************************************************************************
*
* NET_TFTPC_sendACK
* Description :
* -------------
* Send 'ACK' of this SAP context.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0),
*
************************************************************************/
static
UINT32 NET_TFTPC_sendACK( t_tftpc_sap_context *context ) ;
/************************************************************************
*
* NET_TFTPC_sendERROR
* Description :
* -------------
* Send 'ERROR' of this SAP context.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0),
*
************************************************************************/
static
UINT32 NET_TFTPC_sendERROR( t_tftpc_sap_context *context, UINT16 error ) ;
/************************************************************************
* Implementation : Public functions
************************************************************************/
/************************************************************************
*
* NET_TFTPC_init
* Description :
* -------------
* Initialize the TFTPC module, which includes make a UDP-'open' to
* create a UDP-SAP.
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0), successfull initialization
*
************************************************************************/
UINT32 NET_TFTPC_init( void )
{
UINT32 i, rcode ;
t_sys_malloc mem ;
void *ptmp ;
/* allocate buffers */
mem.size = TFTP_HEADER_DATA_MAX_SIZE ;
mem.boundary = TFTPC_SAP_BUFFER_ALIGNMENT_SIZE ;
mem.memory = &(ptmp) ;
rcode = SYSCON_read( SYSCON_BOARD_MALLOC_ID,
&mem,
sizeof(t_sys_malloc) ) ;
if (rcode != OK)
{
return( rcode ) ;
}
sap_context.data = (UINT8*) KSEG0( (UINT32)ptmp ) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -