2025-12-10 14:06:45 +08:00
/*
* tftp_function . c
*
* Created on : Dec 6 , 2025
* Author : cc
*/
# include "tftp_function.h"
# include "net_function.h"
# include "sram_mem_addr.h"
# include "flash_mem_addr.h"
# include "spi_flash.h"
# include "spi_sram.h"
# include "mcu_flash.h"
# include "check_fun.h"
# include "log_api.h"
# include "watchdog.h"
# include "md5.h"
# include "debug.h"
IAPVarTypeStruct IAPVarTypeStruct_Ptr ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͨѶ<CDA8> <D1B6> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> <EFBFBD> <EFBFBD>
tftp_connection_args tftp_args ; //TFTP<54> <50> <EFBFBD> ص<EFBFBD> <D8B5> <EFBFBD> <EFBFBD> <EFBFBD>
__attribute__ ( ( section ( " .non_0_wait " ) ) ) uint8_t bytes_cmp ( uint8_t * src , uint8_t * dat , uint32_t len )
{
for ( uint32_t i = 0 ; i < len ; i + + )
{
if ( src [ i ] ! = dat [ i ] )
{
return 0x01 ;
}
}
return 0x00 ;
}
/*******************************************************************************
* Function Name : TFTP_Get_Decode_op
* Description : TFTP <EFBFBD> <EFBFBD> ȡ TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݱ <EFBFBD> <EFBFBD> е Ĺ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* Input <EFBFBD> <EFBFBD>
* buf - TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) uint8_t TFTP_Pack_Get_Opcode ( uint8_t * buf )
{
return buf [ 1 ] ;
}
/*******************************************************************************
* Function Name : TFTP_Pack_Get_Block
* Description : TFTP <EFBFBD> <EFBFBD> ȡ TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݱ <EFBFBD> <EFBFBD> е Ŀ <EFBFBD> <EFBFBD> <EFBFBD>
* Input <EFBFBD> <EFBFBD>
* buf - TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) uint16_t TFTP_Pack_Get_Block ( uint8_t * buf )
{
uint16_t temp = 0x00 ;
2025-12-25 20:25:57 +08:00
temp = buf [ 2 ] ;
2025-12-10 14:06:45 +08:00
temp < < = 8 ;
2025-12-25 20:25:57 +08:00
temp | = buf [ 3 ] ;
2025-12-10 14:06:45 +08:00
return temp ;
}
/*******************************************************************************
* Function Name : TFTP_Pack_Set_Opcode
* Description : TFTP <EFBFBD> <EFBFBD> ȡ TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݱ <EFBFBD> <EFBFBD> е Ĺ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* Input <EFBFBD> <EFBFBD>
* buf - TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) void TFTP_Pack_Set_Opcode ( uint8_t * buffer , uint8_t opcode )
{
buffer [ 0 ] = 0 ;
buffer [ 1 ] = opcode ;
}
/*******************************************************************************
* Function Name : TFTP_Pack_Set_Opcode
* Description : TFTP <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݱ <EFBFBD> <EFBFBD> е Ŀ <EFBFBD> <EFBFBD> <EFBFBD>
* Input <EFBFBD> <EFBFBD>
* buf - TFTP <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) void TFTP_Pack_Set_Block ( uint8_t * packet , uint16_t block )
{
packet [ 2 ] = ( block > > 8 ) & 0xFF ;
packet [ 3 ] = block & 0xFF ;
}
/*******************************************************************************
* Function Name : TFTP_send_ack_packet
* Description : <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> TFTP Ӧ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* Input : None
* Return : <EFBFBD> <EFBFBD> <EFBFBD> ط <EFBFBD> <EFBFBD> <EFBFBD> ״ ̬
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) uint8_t TFTP_send_ack_packet ( uint8_t s , uint8_t * to_ip , int to_port , int block )
{
uint8_t err = 0 ;
uint32_t sendlen = TFTP_ACK_PKT_LEN ;
2025-12-25 20:25:57 +08:00
uint8_t packet [ 24 ] ;
2025-12-10 14:06:45 +08:00
/* define the first two bytes of the packet */
if ( 1 = = IAPVarTypeStruct_Ptr . IapErrFlag ) TFTP_Pack_Set_Opcode ( packet , TFTP_ERROR ) ;
else TFTP_Pack_Set_Opcode ( packet , TFTP_ACK ) ;
TFTP_Pack_Set_Block ( packet , block ) ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " TFTP ACK packet -- SocketId:%d , port:%d ,block:%d len:%d , IP:%d.%d.%d.%d " , s , to_port , block , sendlen , to_ip [ 0 ] , to_ip [ 1 ] , to_ip [ 2 ] , to_ip [ 3 ] ) ;
Dbg_Print_Buff ( DBG_BIT_NET_STATUS_bit , " Send Data: " , packet , sendlen ) ;
err = WCHNET_SocketUdpSendTo ( s , packet , & sendlen , to_ip , to_port ) ;
2025-12-10 14:06:45 +08:00
return err ;
}
/*******************************************************************************
* Function Name : IAP_tftp_process_write
* Description : IAP TFTP д <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* Input :
s : <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ID <EFBFBD> <EFBFBD>
to_ip : <EFBFBD> <EFBFBD> <EFBFBD> յ <EFBFBD> IP
to_port <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> յ Ķ ˿ <EFBFBD>
* Return : None
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) uint8_t IAP_tftp_process_write ( uint8_t s , uint8_t * to_ip , int to_port )
{
tftp_args . op = TFTP_WRQ ;
memcpy ( & tftp_args . to_ip [ 0 ] , to_ip , 4 ) ;
tftp_args . to_port = to_port ;
tftp_args . block = 0 ;
tftp_args . tot_bytes = 0 ;
IAPVarTypeStruct_Ptr . TotalCount = 0 ;
IAPVarTypeStruct_Ptr . IapErrFlag = 0 ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " ip:%d.%d.%d.%d, port:%d " , to_ip [ 0 ] , to_ip [ 1 ] , to_ip [ 2 ] , to_ip [ 3 ] , to_port ) ;
2025-12-10 14:06:45 +08:00
/*BLV_C1 -- <20> <> <EFBFBD> <EFBFBD> Flash<73> <68> <EFBFBD> ݣ<EFBFBD> <DDA3> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֤<EFBFBD> <D6A4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ֮<EFBFBD> <D6AE> <EFBFBD> <EFBFBD> <EFBFBD> ٲ<EFBFBD> <D9B2> <EFBFBD> ͬʱ<CDAC> <CAB1> SRAM<41> е <EFBFBD> <D0B5> <EFBFBD> <EFBFBD> <EFBFBD> д<EFBFBD> <D0B4> flash<73> <68> */
if ( IAPVarTypeStruct_Ptr . IapFileType = = TFTP_IAP_DataType_APP )
{
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> д<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ַ" ) ;
IAPVarTypeStruct_Ptr . FlashWriteAddress = SRAM_IAP_APP_FILE_ADDRESS ; //<2F> <> <EFBFBD> <EFBFBD> д<EFBFBD> <D0B4> ַ - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ȱ<EFBFBD> <C8B1> <EFBFBD> <EFBFBD> <EFBFBD> SRAM<41> <4D>
}
else if ( IAPVarTypeStruct_Ptr . IapFileType = = TFTP_IAP_DataType_CONFIG )
{
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> д<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ַ" ) ;
IAPVarTypeStruct_Ptr . FlashWriteAddress = SRAM_IAP_LOGIC_DataStart_ADDRESS ; //<2F> <> <EFBFBD> <EFBFBD> д<EFBFBD> <D0B4> ַ - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ȱ<EFBFBD> <C8B1> <EFBFBD> <EFBFBD> <EFBFBD> SRAM<41> <4D>
}
else
{
return 0x01 ;
}
2025-12-25 20:25:57 +08:00
TFTP_send_ack_packet ( g_netinfo . SocketId [ SocketIdnex_TFTPDATA ] , to_ip , to_port , tftp_args . block ) ; //ʹ <> <CAB9> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <D7BD> <EFBFBD>
2025-12-10 14:06:45 +08:00
return 0x00 ;
}
/*******************************************************************************
* Function Name : TFTP_IAP_Data_Processing
* Description : TFTP IAP <EFBFBD> <EFBFBD> <EFBFBD> ݴ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <EFBFBD> <EFBFBD> Ҫ <EFBFBD> Ǵ <EFBFBD> <EFBFBD> <EFBFBD> IAP <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* Input <EFBFBD> <EFBFBD>
* s - <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ID
* pkt_buf - <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD>
* pkt_buf_len - <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* ip_addr - <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD> <EFBFBD> <EFBFBD> IP
* Port - <EFBFBD> <EFBFBD> <EFBFBD> ݰ <EFBFBD> <EFBFBD> Ķ ˿ ں <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) void TFTP_IAP_Data_Processing ( uint8_t s , uint8_t * pkt_buf , uint16_t pkt_buf_len , uint8_t * ip_addr , uint16_t Port )
{
uint8_t data_buffer [ TFTP_DATA_LEN_MAX ] ;
uint32_t temp_val = 0 , crcNumIndex = 0 ;
IAPVarTypeStruct_Ptr . IapPercent + + ;
IAPVarTypeStruct_Ptr . processing_tick = SysTick_1ms ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " %s block:%d - %d " , __func__ , IAPVarTypeStruct_Ptr . Write_Block , TFTP_Pack_Get_Block ( pkt_buf ) ) ;
if ( ( pkt_buf_len > TFTP_DATA_PKT_HDR_LEN ) & & ( TFTP_Pack_Get_Block ( pkt_buf ) = = ( IAPVarTypeStruct_Ptr . Write_Block + 1 ) ) )
2025-12-10 14:06:45 +08:00
{
pkt_buf_len = pkt_buf_len - TFTP_DATA_PKT_HDR_LEN ;
memset ( data_buffer , 0 , TFTP_DATA_LEN_MAX ) ;
for ( uint32_t i = 0 ; i < pkt_buf_len ; i + + )
{
data_buffer [ i ] = pkt_buf [ TFTP_DATA_PKT_HDR_LEN + i ] ;
}
IAPVarTypeStruct_Ptr . TotalCount + = pkt_buf_len ;
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " IapFileType:%d " , IAPVarTypeStruct_Ptr . IapFileType ) ;
switch ( IAPVarTypeStruct_Ptr . IapFileType )
{
case TFTP_IAP_DataType_APP :
if ( IAPVarTypeStruct_Ptr . Write_Block = = 0x00 )
{
temp_val = data_buffer [ 0 ] + ( data_buffer [ 1 ] < < 8 ) + ( data_buffer [ 2 ] < < 16 ) + ( data_buffer [ 3 ] < < 24 ) ;
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " temp_var : %08X ,block :%d " , temp_val , IAPVarTypeStruct_Ptr . Write_Block ) ;
if ( ( temp_val & 0x2FFE0000 ) ! = 0x20000000 )
{
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> ڴ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ĵ<EFBFBD> ַ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ч<EFBFBD> <EFBFBD> " ) ;
Dbg_Print_Buff ( DBG_BIT_NET_STATUS_bit , " pkt_buf: " , pkt_buf , pkt_buf_len ) ;
Dbg_Print_Buff ( DBG_BIT_NET_STATUS_bit , " data: " , data_buffer , pkt_buf_len - TFTP_DATA_PKT_HDR_LEN ) ;
}
// switch(IAPVarTypeStruct_Ptr.IapType)
// {
// case IAPTFTPWRITE: //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD>
// IAP_AckState(IAP_Error_File,(uint8_t *)ip,(uint16_t)port);
// break;
// case IAPTFTPREAD:
// CLOUD_IAP_AckState(CLOUD_IAP_Cmd, IAP_Error_File, (uint8_t *)ip, (uint16_t)port, DATATYPE_IAP);
// break;
// }
IAPVarTypeStruct_Ptr . IapErrFlag = 1 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ־<EFBFBD> <D6BE> һ
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʧ<EFBFBD> ܣ<EFBFBD> <EFBFBD> <EFBFBD> ַ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> data_buffer[0] & 0x2FFE0000 = %X; data_buffer[1]=%X\n " , ( data_buffer [ 0 ] & 0x2FFE0000 ) , data_buffer [ 1 ] ) ;
} else if ( IAPVarTypeStruct_Ptr . Write_Block > APP_BLOCK_MAX ) {
// switch(IAPVarTypeStruct_Ptr->IapType)
// {
// case IAPTFTPWRITE: //<2F> ظ<EFBFBD> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// IAP_AckState(IAP_Error_Block, (uint8_t *)ip, (uint16_t)port);
// break;
// case IAPTFTPREAD:
// CLOUD_IAP_AckState(CLOUD_IAP_Cmd, IAP_Error_Block, (uint8_t *)ip, (uint16_t)port, DATATYPE_IAP);
// break;
// }
IAPVarTypeStruct_Ptr . IapErrFlag = 1 ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ־<EFBFBD> <D6BE> һ
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʧ<EFBFBD> ܣ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> \n " ) ;
}
break ;
case TFTP_IAP_DataType_CONFIG :
if ( IAPVarTypeStruct_Ptr . Write_Block > = CONFIG_BLOCK_MAX )
{
// switch(IAPVarTypeStruct_Ptr->IapType)
// {
// case IAPTFTPWRITE: //<2F> ظ<EFBFBD> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// LOGIC_Config_AckState(IAP_Error_Block, (uint8_t *)ip, (uint16_t)port);
// break;
// case IAPTFTPREAD:
// CLOUD_IAP_AckState(CLOUD_IAP_Cmd, IAP_Error_Block, (uint8_t *)ip, (uint16_t)port, DATATYPE_CONFIG);
// break;
// }
IAPVarTypeStruct_Ptr . IapErrFlag = 1 ;
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʧ<EFBFBD> ܣ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> \n " ) ;
}
break ;
default :
IAPVarTypeStruct_Ptr . IapErrFlag = 1 ;
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ͳ<EFBFBD> <EFBFBD> <EFBFBD> " ) ;
break ;
}
if ( IAPVarTypeStruct_Ptr . IapErrFlag = = 0x00 )
{
IAPVarTypeStruct_Ptr . Write_Block + + ;
SRAM_DMA_Write_Buff ( data_buffer , pkt_buf_len , IAPVarTypeStruct_Ptr . FlashWriteAddress ) ; //д<> <D0B4> SRAM<41> <4D> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " д<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ַ<EFBFBD> <EFBFBD> %08X,д<> <D0B4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> : byte<74> <65> %d " , IAPVarTypeStruct_Ptr . FlashWriteAddress , pkt_buf_len ) ;
/*<2A> Գ<EFBFBD> <D4B3> Ƚ<EFBFBD> <C8BD> <EFBFBD> 4Byte<74> <65> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ڵ<EFBFBD> ַƫ<D6B7> <C6AB> ʹ <EFBFBD> <CAB9> <20> <> <EFBFBD> 費<EFBFBD> <E8B2BB> Ҫ<EFBFBD> ֽڶ<D6BD> <DAB6> 룬<EFBFBD> <EBA3AC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ̫<EFBFBD> <CCAB> Ҫ*/
// pkt_buf_len = (pkt_buf_len + 3) / 4;
// pkt_buf_len = pkt_buf_len * 4;
IAPVarTypeStruct_Ptr . FlashWriteAddress + = pkt_buf_len ;
}
} else if ( TFTP_Pack_Get_Block ( ( char * ) pkt_buf ) = = ( IAPVarTypeStruct_Ptr . Write_Block + 1 ) )
{
IAPVarTypeStruct_Ptr . Write_Block + + ;
}
TFTP_send_ack_packet ( s , ip_addr , Port , IAPVarTypeStruct_Ptr . Write_Block ) ; //<2F> <> ÿ<EFBFBD> δ<EFBFBD> <CEB4> <EFBFBD> <EFBFBD> ݰ<EFBFBD> <DDB0> Ļظ<C4BB> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <D7BD> <EFBFBD> <20> <> ַ <20> ˿ںͿ <DABA> <CDBF> <EFBFBD>
if ( IAPVarTypeStruct_Ptr . Write_Block = = IAPVarTypeStruct_Ptr . BlockSize )
{
uint8_t md5 [ 16 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ;
uint16_t crc_data_len = 0 ;
switch ( IAPVarTypeStruct_Ptr . IapFileType )
{
case TFTP_IAP_DataType_APP :
MD5Digest_SRAM ( SRAM_IAP_APP_FILE_ADDRESS , IAPVarTypeStruct_Ptr . TotalCount , ( char * ) & md5 [ 0 ] ) ;
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " falshд<EFBFBD> <EFBFBD> <EFBFBD> ܳ<EFBFBD> <EFBFBD> ȣ <EFBFBD> %dByte " , IAPVarTypeStruct_Ptr . TotalCount ) ;
if ( bytes_cmp ( md5 , IAPVarTypeStruct_Ptr . Md5 , 16 ) = = 0x00 )
{
//<2F> ļ<EFBFBD> MD5У <35> <D0A3> <EFBFBD> ɹ<EFBFBD>
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɹ<EFBFBD> <EFBFBD> <EFBFBD> Md5<EFBFBD> <EFBFBD> ȷ" ) ;
//Ϊɶ<CEAA> <C9B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ƶ˻ظ<CBBB> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ<EFBFBD> <D2AA> һ <EFBFBD> <D2BB>
// switch(IAPVarTypeStruct_Ptr->IapType)
// {
// case IAPTFTPWRITE: //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ״̬Ϊ<CCAC> <CEAA> <EFBFBD> <EFBFBD> ,<2C> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// Dbg_Println(DBG_BIT_NET_STATUS_bit,"<22> <> ¼<EFBFBD> <C2BC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɹ<EFBFBD> ״̬..");
// SRAM_Write_Byte(IAP_STATE_COMPLETE, SRAM_IAP_NET_UPGRADE_Flag_ADDRESS);
// LOG_LogicInfo_DebugRecord("<22> <> ¼<EFBFBD> <C2BC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɹ<EFBFBD> ״̬..");
// break;
// case IAPTFTPREAD: //<2F> ƶ<EFBFBD> <C6B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// Dbg_Println(DBG_BIT_NET_STATUS_bit,"<22> <> ¼<EFBFBD> ƶ<EFBFBD> <C6B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɹ<EFBFBD> ״̬..");
// LOG_LogicInfo_DebugRecord("<22> <> ¼<EFBFBD> ƶ<EFBFBD> <C6B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɹ<EFBFBD> ״̬..");
// SRAM_Write_Byte(CLOUD_IAP_TFTP_STATE_COMPLETE, SRAM_IAP_NET_UPGRADE_Flag_ADDRESS);
// break;
// }
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> APPд<EFBFBD> <EFBFBD> Flash<EFBFBD> <EFBFBD> .." ) ;
//Cloud_IAP_Plan_SendPack(args,IAPVarTypeStruct_Ptr,IAPPlan_State_CheckSucc); //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɣ <EFBFBD> У <EFBFBD> <D0A3> <EFBFBD> С <EFBFBD> <D0A1> <EFBFBD> <EFBFBD> <EFBFBD>
SPI_FLASH_APP_Data_Erase ( ) ;
for ( uint32_t i = 0 ; i < IAPVarTypeStruct_Ptr . BlockSize ; i + + )
{
WDT_Feed ( ) ;
SRAM_DMA_Read_Buff ( data_buffer , 512 , SRAM_IAP_APP_FILE_ADDRESS + i * 512 ) ;
Flash_Write ( data_buffer , 512 , SPIFLASH_APP_Data_Start_Addr + i * 512 ) ;
}
memset ( data_buffer , 0 , TFTP_DATA_LEN_MAX ) ;
/* <20> <> <EFBFBD> <EFBFBD> APP<50> <50> CRCУ <43> <D0A3> ֵ <20> <> <EFBFBD> <EFBFBD> APP<50> <50> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
g_app_feature . app_flag = App_Procedure_Ready ;
g_app_feature . app_crc_size = MCU_APP_Flash_PageSize ;
g_app_feature . app_start_addr = MCU_APP_Flash_Start_Addr ;
g_app_feature . app_end_addr = MCU_APP_Flash_Start_Addr + IAPVarTypeStruct_Ptr . TotalCount ;
if ( ( IAPVarTypeStruct_Ptr . TotalCount % g_app_feature . app_crc_size ) ! = 0x00 ) {
g_app_feature . app_crc_len = ( ( IAPVarTypeStruct_Ptr . TotalCount / g_app_feature . app_crc_size ) + 1 ) * 2 ;
} else {
g_app_feature . app_crc_len = ( IAPVarTypeStruct_Ptr . TotalCount / g_app_feature . app_crc_size ) * 2 ;
}
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " App CRC BLock:%d " , g_app_feature . app_crc_len ) ;
crcNumIndex = 0x00 ;
for ( uint32_t crc_addr = g_app_feature . app_start_addr ; crc_addr < g_app_feature . app_end_addr ; crc_addr + = g_app_feature . app_crc_size )
{
if ( g_app_feature . app_end_addr - crc_addr > = g_app_feature . app_crc_size ) {
crc_data_len = g_app_feature . app_crc_size ;
} else {
crc_data_len = g_app_feature . app_end_addr - crc_addr ;
}
memset ( Temp_Flash_Buff , 0 , sizeof ( Temp_Flash_Buff ) ) ;
if ( crc_data_len > 2048 )
{
Flash_Read ( Temp_Flash_Buff , 2048 , crc_addr ) ;
Flash_Read ( & Temp_Flash_Buff [ 2048 ] , ( crc_data_len - 2048 ) , crc_addr + 2048 ) ;
} else {
Flash_Read ( Temp_Flash_Buff , crc_data_len , crc_addr ) ;
}
temp_val = NetCRC16_2 ( Temp_Flash_Buff , crc_data_len ) ;
g_app_feature . app_crc [ crcNumIndex ] = temp_val & 0xFF ;
g_app_feature . app_crc [ crcNumIndex + 1 ] = ( temp_val > > 8 ) & 0xFF ;
crcNumIndex + = 2 ;
}
g_app_feature . crc_check = 0x00 ;
Write_APP_Feature_Info ( 0x02 , & g_app_feature ) ; //д<> <D0B4> APP<50> <50> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
WDT_Feed ( ) ; //<2F> <> ֹ<EFBFBD> <D6B9> <EFBFBD> Ź<EFBFBD> <C5B9> <EFBFBD> λ
Dbg_Println ( DBG_BIT_DEVICE_STATUS_bit , " <EFBFBD> ̼<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ!" ) ;
//ֱ<> ӿ<EFBFBD> <D3BF> Ź<EFBFBD> <C5B9> <EFBFBD> λ
} else {
//MD5У <35> <D0A3> ʧ<EFBFBD> <CAA7>
// switch(IAPVarTypeStruct_Ptr->IapType)
// {
// case IAPTFTPWRITE://IAP_AckState(IAP_Error_MD5, (uint8_t *)ip, (uint16_t)port); break; //<2F> ظ<EFBFBD> Md5<64> <35> <EFBFBD> <EFBFBD>
// IAP_AckState(IAP_Error_MD5, (uint8_t *)ip_addr, (uint16_t)sever_port); //<2F> ظ<EFBFBD> Md5<64> <35> <EFBFBD> <EFBFBD>
// break;
// case IAPTFTPREAD:
// CLOUD_IAP_AckState(CLOUD_IAP_Cmd, IAP_Error_MD5, (uint8_t *)ip, (uint16_t)port, DATATYPE_IAP);
// break;
// }
IAPVarTypeStruct_Ptr . IapErrFlag = 1 ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʧ<EFBFBD> ܣ<EFBFBD> Md5<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> :%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X" , \
2025-12-10 14:06:45 +08:00
md5 [ 0 ] , md5 [ 1 ] , md5 [ 2 ] , md5 [ 3 ] , md5 [ 4 ] , md5 [ 5 ] , md5 [ 6 ] , md5 [ 7 ] , md5 [ 8 ] , md5 [ 9 ] , md5 [ 10 ] , md5 [ 11 ] , md5 [ 12 ] , md5 [ 13 ] , md5 [ 14 ] , md5 [ 15 ] ) ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " UDP Md5:%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X " , \
2025-12-10 14:06:45 +08:00
IAPVarTypeStruct_Ptr . Md5 [ 0 ] , IAPVarTypeStruct_Ptr . Md5 [ 1 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 2 ] , IAPVarTypeStruct_Ptr . Md5 [ 3 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 4 ] , IAPVarTypeStruct_Ptr . Md5 [ 5 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 6 ] , IAPVarTypeStruct_Ptr . Md5 [ 7 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 8 ] , IAPVarTypeStruct_Ptr . Md5 [ 9 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 10 ] , IAPVarTypeStruct_Ptr . Md5 [ 11 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 12 ] , IAPVarTypeStruct_Ptr . Md5 [ 13 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 14 ] , IAPVarTypeStruct_Ptr . Md5 [ 15 ] ) ;
}
break ;
case TFTP_IAP_DataType_CONFIG :
MD5Digest_SRAM ( SRAM_IAP_LOGIC_DataStart_ADDRESS , IAPVarTypeStruct_Ptr . TotalCount , ( char * ) & md5 [ 0 ] ) ;
if ( bytes_cmp ( md5 , IAPVarTypeStruct_Ptr . Md5 , 16 ) = = 0x00 )
{
// switch(IAPVarTypeStruct_Ptr->IapType)
// {
// case IAPTFTPWRITE: //<2F> ظ<EFBFBD> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// Dbg_Println(DBG_BIT_NET_STATUS_bit,"<22> <> ¼<EFBFBD> <EFBFBD> <DFBC> ļ<EFBFBD> д<EFBFBD> <D0B4> <EFBFBD> ɹ<EFBFBD> ״̬..");
// LOGIC_Config_AckState(IAP_Finish, (uint8_t *)ip, (uint16_t)sever_port);
// break;
// case IAPTFTPREAD:
// Dbg_Println(DBG_BIT_NET_STATUS_bit,"<22> <> ¼<EFBFBD> <EFBFBD> <DFBC> ļ<EFBFBD> <C4BC> <EFBFBD> ȡ<EFBFBD> ɹ<EFBFBD> ״̬..");
// CLOUD_IAP_AckState(CLOUD_IAP_Cmd, IAP_Finish, (uint8_t *)ip, (uint16_t)sever_port, DATATYPE_CONFIG);
// break;
// }
//Cloud_IAP_Plan_SendPack(args,IAPVarTypeStruct_Ptr,IAPPlan_State_CheckSucc); //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ɣ <EFBFBD> У <EFBFBD> <D0A3> <EFBFBD> С <EFBFBD> <D0A1> <EFBFBD> <EFBFBD> <EFBFBD>
SPI_FLASH_Logic_File_Erase ( ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ȫ<EFBFBD> <C8AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
for ( uint32_t i = 0 ; i < IAPVarTypeStruct_Ptr . BlockSize ; i + + )
{
WDT_Feed ( ) ;
temp_val = SRAM_IAP_LOGIC_DataStart_ADDRESS + i * 512 ;
SRAM_DMA_Read_Buff ( data_buffer , 512 , SRAM_IAP_LOGIC_DataStart_ADDRESS + i * 512 ) ;
Flash_Write ( data_buffer , 512 , SPIFLASH_LOGIC_DataStart_ADDRESS + i * 512 ) ;
}
data_buffer [ 0 ] = 0x01 ;
data_buffer [ 1 ] = 0x00 ;
data_buffer [ 2 ] = 0x06 ;
data_buffer [ 3 ] = 0xCC ;
data_buffer [ 4 ] = IAPVarTypeStruct_Ptr . TotalCount & 0xFF ;
data_buffer [ 5 ] = ( IAPVarTypeStruct_Ptr . TotalCount > > 8 ) & 0xFF ;
data_buffer [ 6 ] = ( IAPVarTypeStruct_Ptr . TotalCount > > 16 ) & 0xFF ;
data_buffer [ 7 ] = ( IAPVarTypeStruct_Ptr . TotalCount > > 24 ) & 0xFF ;
memcpy ( & data_buffer [ 8 ] , IAPVarTypeStruct_Ptr . Md5 , 16 ) ;
Flash_Write ( data_buffer , 24 , SPIFLASH_LOGIC_DataFlag_ADDRESS ) ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_DEVICE_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) ;
LOG_LogicInfo_DebugRecord ( " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> λ" ) ;
2025-12-10 14:06:45 +08:00
} else {
// switch(IAPVarTypeStruct_Ptr->IapType)
// {
// case IAPTFTPWRITE: //<2F> ظ<EFBFBD> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// LOGIC_Config_AckState(IAP_Error_MD5, (uint8_t *)ip_addr, (uint16_t)sever_port);
// break;
// case IAPTFTPREAD:
// CLOUD_IAP_AckState(CLOUD_IAP_Cmd, IAP_Error_MD5, (uint8_t *)ip, (uint16_t)sever_port, DATATYPE_CONFIG);
// break;
// }
IAPVarTypeStruct_Ptr . IapErrFlag = 1 ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʧ<EFBFBD> ܣ<EFBFBD> Md5<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> :%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X" , \
2025-12-10 14:06:45 +08:00
md5 [ 0 ] , md5 [ 1 ] , md5 [ 2 ] , md5 [ 3 ] , md5 [ 4 ] , md5 [ 5 ] , md5 [ 6 ] , md5 [ 7 ] , md5 [ 8 ] , md5 [ 9 ] , md5 [ 10 ] , md5 [ 11 ] , md5 [ 12 ] , md5 [ 13 ] , md5 [ 14 ] , md5 [ 15 ] ) ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " UDP Md5:%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X,%X " , \
2025-12-10 14:06:45 +08:00
IAPVarTypeStruct_Ptr . Md5 [ 0 ] , IAPVarTypeStruct_Ptr . Md5 [ 1 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 2 ] , IAPVarTypeStruct_Ptr . Md5 [ 3 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 4 ] , IAPVarTypeStruct_Ptr . Md5 [ 5 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 6 ] , IAPVarTypeStruct_Ptr . Md5 [ 7 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 8 ] , IAPVarTypeStruct_Ptr . Md5 [ 9 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 10 ] , IAPVarTypeStruct_Ptr . Md5 [ 11 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 12 ] , IAPVarTypeStruct_Ptr . Md5 [ 13 ] , \
IAPVarTypeStruct_Ptr . Md5 [ 14 ] , IAPVarTypeStruct_Ptr . Md5 [ 15 ] ) ;
}
break ;
default :
IAPVarTypeStruct_Ptr . IapErrFlag = 1 ;
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ļ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ͳ<EFBFBD> <EFBFBD> <EFBFBD> " ) ;
break ;
}
}
}
/*******************************************************************************
* Function Name : UDPSocket_TFTP_CMD_AppCallBack
* Description : TFTP <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <EFBFBD> <EFBFBD> <EFBFBD> ݴ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ص <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2025-12-25 20:25:57 +08:00
void UDPSocket_TFTP_CMD_AppCallBack ( struct _SOCK_INF * SocketInf , uint32_t ipaddr , uint16_t port , uint8_t * buff , uint32_t len )
2025-12-10 14:06:45 +08:00
{
uint8_t ip_addr [ 4 ] ;
ip_addr [ 0 ] = ipaddr & 0xFF ;
ip_addr [ 1 ] = ( ipaddr > > 8 ) & 0xFF ;
ip_addr [ 2 ] = ( ipaddr > > 16 ) & 0xFF ;
ip_addr [ 3 ] = ( ipaddr > > 24 ) & 0xFF ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " %s len:%d " , __func__ , len ) ;
2025-12-10 14:06:45 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " ip:%d.%d.%d.%d, port:%d " , ip_addr [ 0 ] , ip_addr [ 1 ] , ip_addr [ 2 ] , ip_addr [ 3 ] , port ) ;
/*TFTP <20> <> <EFBFBD> <EFBFBD> <EEB4A6> */
if ( TFTP_Pack_Get_Opcode ( buff ) = = TFTP_WRQ )
{
if ( IAPVarTypeStruct_Ptr . FunType = = TFTP_FUNTYPE_LocalIAP )
{
/*<2A> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> TFTP<54> <50> <EFBFBD> <EFBFBD> ״̬<D7B4> £<EFBFBD> <C2A3> <EFBFBD> <EFBFBD> յ<EFBFBD> д<EFBFBD> <D0B4> <EFBFBD> <EFBFBD> */
Dbg_Print_Buff ( DBG_BIT_NET_STATUS_bit , " TFTPд<EFBFBD> ļ<EFBFBD> ָ<EFBFBD> <EFBFBD> : " , buff , len ) ;
IAP_tftp_process_write ( g_netinfo . SocketId [ SocketIdnex_TFTPCMD ] , ip_addr , port ) ; //<2F> ظ<EFBFBD> <D8B8> <EFBFBD> <EFBFBD> <EFBFBD> д<> ļ<EFBFBD> ָ<EFBFBD> <D6B8>
} else {
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " TFTP Type:%d " , IAPVarTypeStruct_Ptr . FunType ) ;
2025-12-10 14:06:45 +08:00
}
} else if ( TFTP_Pack_Get_Opcode ( buff ) = = TFTP_OPTION )
{
/*TFTP<54> <50> <EFBFBD> <EFBFBD> <EFBFBD> ϴ<EFBFBD> <CFB4> <EFBFBD> ־<EFBFBD> <D6BE> <EFBFBD> <EFBFBD> <EFBFBD> У <EFBFBD> <D0A3> Ż<EFBFBD> <C5BB> <EFBFBD> <EFBFBD> յ<EFBFBD> <D5B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
} else {
/*<2A> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> ݲ<EFBFBD> <DDB2> <EFBFBD> <EFBFBD> <EFBFBD> */
}
}
/*******************************************************************************
* Function Name : UDPSocket_TFTP_DATA_AppCallBack
* Description : TFTP <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <EFBFBD> <EFBFBD> <EFBFBD> ݴ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ص <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2025-12-25 20:25:57 +08:00
void UDPSocket_TFTP_DATA_AppCallBack ( struct _SOCK_INF * SocketInf , uint32_t ipaddr , uint16_t port , uint8_t * buff , uint32_t len )
2025-12-10 14:06:45 +08:00
{
uint8_t ip_addr [ 4 ] ;
ip_addr [ 0 ] = ipaddr & 0xFF ;
ip_addr [ 1 ] = ( ipaddr > > 8 ) & 0xFF ;
ip_addr [ 2 ] = ( ipaddr > > 16 ) & 0xFF ;
ip_addr [ 3 ] = ( ipaddr > > 24 ) & 0xFF ;
2025-12-25 20:25:57 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " %s len:%d " , __func__ , len ) ;
2025-12-10 14:06:45 +08:00
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " ip:%d.%d.%d.%d, port:%d " , ip_addr [ 0 ] , ip_addr [ 1 ] , ip_addr [ 2 ] , ip_addr [ 3 ] , port ) ;
if ( TFTP_Pack_Get_Opcode ( buff ) = = TFTP_DATA ) //TFTP IAP<41> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD>
{
TFTP_IAP_Data_Processing ( g_netinfo . SocketId [ SocketIdnex_TFTPDATA ] , buff , len , ip_addr , port ) ;
}
// else if( TFTP_Get_Decode_op(buff) == TFTP_ACK ) //TFTP<54> <50> ACK,<2C> ˴ <EFBFBD> <CBB4> <EFBFBD> д<EFBFBD> <D0B4> ־<EFBFBD> ij<EFBFBD> <C4B3> <EFBFBD> <EFBFBD> Ż<EFBFBD> <C5BB> <EFBFBD> <EFBFBD> <EFBFBD>
// {
// //TFTP<54> <50> <EFBFBD> ڴ˴ <DAB4> <CBB4> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ر<EFBFBD> ע<EFBFBD> ⣬TFTP<54> Ļص<C4BB> <D8B5> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> һ <EFBFBD> <D2BB>
// Dbg_Println(DBG_BIT_NET_STATUS_bit,"TFTP<54> <50> ACK,<2C> ˴ <EFBFBD> <CBB4> <EFBFBD> д<EFBFBD> <D0B4> ־");
// }
}
/*******************************************************************************
* Function Name : Internal_TFTP_Task
* Description : TFTP <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* - - <EFBFBD> <EFBFBD> Ҫ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> У <EFBFBD> 1 <EFBFBD> <EFBFBD> IAP <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 2 <EFBFBD> <EFBFBD> IAP <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <EFBFBD> ƶ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 2 <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ־ <EFBFBD> ļ <EFBFBD> <EFBFBD> ϴ <EFBFBD>
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
__attribute__ ( ( section ( " .non_0_wait " ) ) ) void Internal_TFTP_Task ( void )
{
//static uint8_t tftp_ack_num = 0;
if ( IAPVarTypeStruct_Ptr . enable = = 0x01 )
{
if ( ( IAPVarTypeStruct_Ptr . FunType = = TFTP_FUNTYPE_LocalIAP ) | | ( IAPVarTypeStruct_Ptr . FunType = = TFTP_FUNTYPE_CloudIAP ) )
{
if ( ( WCHNET_Get_PHY_Linked_Status ( ) = = 0x01 ) | | ( server_info . init_flag = = 0x00 ) ) {
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӶϿ<D3B6> <CFBF> <EFBFBD> ֱ<EFBFBD> <D6B1> <EFBFBD> ˳<EFBFBD> - ͬʱ<CDAC> ˳<EFBFBD> <CBB3> <EFBFBD> ǰ<EFBFBD> <C7B0> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ״̬
return ;
}
switch ( IAPVarTypeStruct_Ptr . status )
{
case STA_INIT :
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> ʼ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> TFTP<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ..." ) ;
WCHNET_CreateUdpSocket ( & g_netinfo . SocketId [ SocketIdnex_TFTPCMD ] , TFTP_Destination_Port , UDPSocket_TFTP_CMD_AppCallBack ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <D7BD> <EFBFBD> ,TFTP<54> <50> <EFBFBD> <EFBFBD>
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> ʼ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> TFTP<EFBFBD> ļ<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ..." ) ;
WCHNET_CreateUdpSocket ( & g_netinfo . SocketId [ SocketIdnex_TFTPDATA ] , TFTP_LOG_Local_Port , UDPSocket_TFTP_DATA_AppCallBack ) ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <D7BD> <EFBFBD> ,TFTP<54> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD>
IAPVarTypeStruct_Ptr . status = STA_INIT_WAIT ;
IAPVarTypeStruct_Ptr . processing_tick = SysTick_1ms ;
break ;
case STA_INIT_WAIT :
if ( SysTick_1ms - IAPVarTypeStruct_Ptr . processing_tick > 50 )
{
IAPVarTypeStruct_Ptr . processing_tick = SysTick_1ms ;
IAPVarTypeStruct_Ptr . status = STA_INIT_IDLE ;
}
break ;
case STA_INIT_IDLE :
//<2F> <> <EFBFBD> ƶ˷<C6B6> <CBB7> Ͷ<EFBFBD> ȡ<EFBFBD> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD>
2025-12-25 20:25:57 +08:00
if ( SysTick_1ms - IAPVarTypeStruct_Ptr . processing_tick > 30000 ) //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʱ<EFBFBD> <CAB1> <EFBFBD> ͷ<EFBFBD> <CDB7> <EFBFBD> <D7BD> <EFBFBD>
2025-12-10 14:06:45 +08:00
{
//Cloud_IAP_Plan_SendPack(tftp_args,IAPVarTypeStruct_Ptr,IAPPlan_State_IAPTimeout); //<2F> <> <EFBFBD> <EFBFBD> IAP<41> <50> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʱ
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " TFTP <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ʱ " ) ;
IAPVarTypeStruct_Ptr . status = STA_END ;
}
if ( IAPVarTypeStruct_Ptr . IapErrFlag = = 0x01 )
{
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " TFTP <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> " ) ;
IAPVarTypeStruct_Ptr . status = STA_END ;
}
break ;
case STA_END : //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - <20> ͷ<EFBFBD> <CDB7> <EFBFBD> <D7BD> <EFBFBD>
WCHNET_SocketClose ( g_netinfo . SocketId [ SocketIdnex_TFTPCMD ] , TCP_CLOSE_NORMAL ) ; //<2F> ͷ<EFBFBD> <CDB7> <EFBFBD> <D7BD> <EFBFBD>
WCHNET_SocketClose ( g_netinfo . SocketId [ SocketIdnex_TFTPDATA ] , TCP_CLOSE_NORMAL ) ; //<2F> ͷ<EFBFBD> <CDB7> <EFBFBD> <D7BD> <EFBFBD>
IAPVarTypeStruct_Ptr . status = STA_INIT ; //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ״̬<D7B4> <CCAC> Ϊ<EFBFBD> <CEAA> Ҫ<EFBFBD> <D2AA> ʼ <EFBFBD> <CABC>
IAPVarTypeStruct_Ptr . IapErrFlag = 0 ;
IAPVarTypeStruct_Ptr . enable = 0x00 ;
break ;
default :
2025-12-25 20:25:57 +08:00
IAPVarTypeStruct_Ptr . status = STA_INIT_WAIT ; //<2F> ͷ<EFBFBD> <CDB7> <EFBFBD> <D7BD> <EFBFBD>
2025-12-10 14:06:45 +08:00
break ;
}
} else if ( IAPVarTypeStruct_Ptr . FunType = = TFTP_FUNTYPE_LogUpload )
{
if ( ( WCHNET_Get_PHY_Linked_Status ( ) = = 0x01 ) | | ( server_info . init_flag = = 0x00 ) ) {
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ӶϿ<D3B6> <CFBF> <EFBFBD> ֱ<EFBFBD> <D6B1> <EFBFBD> ˳<EFBFBD> - ͬʱ<CDAC> ˳<EFBFBD> <CBB3> <EFBFBD> ǰTFTP <20> ϴ<EFBFBD> <CFB4> <EFBFBD> ־
return ;
}
/*- TFTP <20> <> ־<EFBFBD> ϴ<EFBFBD> <CFB4> <EFBFBD> ʽ <EFBFBD> <CABD> Ҫ<EFBFBD> <EFBFBD> һ <EFBFBD> £<EFBFBD>
* - <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ϴ <EFBFBD> <EFBFBD> <EFBFBD> ־ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ѹ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* - <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ϊ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ҫ <EFBFBD> <EFBFBD> ʱ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͨ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> · <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ݶ <EFBFBD> ȡ */
switch ( IAPVarTypeStruct_Ptr . status )
{
case STA_INIT :
/*TFTP<54> ļ<EFBFBD> <C4BC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> - һ <> <D2BB> <EFBFBD> <EFBFBD> <D7BD> ָ㶨*/
Dbg_Println ( DBG_BIT_NET_STATUS_bit , " <EFBFBD> <EFBFBD> ʼ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> TFTP<EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ..." ) ;
//WCHNET_CreateUdpSocket(&g_netinfo.SocketId[SocketIdnex_TFTPCMD], TFTP_LOG_Local_Port, TFTP_LOG_CallBack); //<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <D7BD> <EFBFBD> ,TFTP<54> <50> <EFBFBD> <EFBFBD>
//tftp_ack_num = 0x00;
IAPVarTypeStruct_Ptr . status = STA_INIT_WAIT ;
IAPVarTypeStruct_Ptr . processing_tick = SysTick_1ms ;
break ;
case STA_INIT_WAIT :
if ( SysTick_1ms - IAPVarTypeStruct_Ptr . processing_tick > 50 )
{
IAPVarTypeStruct_Ptr . processing_tick = SysTick_1ms ;
IAPVarTypeStruct_Ptr . status = STA_INIT_CONNECT ;
}
break ;
case STA_INIT_CONNECT : //
break ;
}
}
}
}