⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftps_interface.c

📁 CSR蓝牙芯片的ftp程序的服务器端代码 客户端已经上传
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004

FILE NAME
    ftps_interface.c
    
DESCRIPTION
	Interface source for the FTP Server library

*/

#include <message.h>
#include <panic.h>
#include <string.h>
#include <print.h>

#include <goep.h>

#include "ftps.h"
#include "ftps_private.h"

static void SendInternalSetPathResponse(FTPS *session, ftps_setpath_result result);


/*!
	@brief Initialise the FTPS Library.
	@param theAppTask The current application task.
	@param priority The profile instance low power mode priority. For a set of 
	profile instances with connections on a given ACL the instance with the highest 
	priority value wins and the low power mode on the ACL is set according to it's power table.
	
	FTPS_INIT_CFM message will be received by the application. 
*/
void FtpsInit(Task theAppTask, uint16 priority)
{
	Task ftpsTask;
	ftpsState *state;
	PRINT(("FTPS Init\n"));
	
	ftpsTask = ftpsGetTheTask(); /* Can't fail since ftpcGetTheTask will Panic on no memory */
	state = (ftpsState*)ftpsTask;
	
	state->theAppTask=theAppTask;
	
	GoepInit(&state->task, goep_Server, goep_FTP);
}


/*!
 @brief Respond to a connection request.  
 @param session FTPS Session Handle.
 @param accept TRUE to accept the connection, or FALSE to refuse it.
 @param pktSize Maximum packet size that can be accepted on this connection.
 @param type Server type - Is the server read only?
*/
void FtpsConnectResponse(FTPS *session, bool accept, uint16 pktSize, ftps_serv_type type)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_CONNECTION_RESP);
        
        message->accept = accept;
        message->pktSize = pktSize;
		message->type = type;
        
		MessageSend(ftps, FTPS_INT_CONNECTION_RESP, message);
	}
}

/*!
 @brief Send the first packet of a folder listing.  
 @param session FTPS Session Handle.
 @param size_packet Length of this packet
 @param packet The first packet
 @param totalLen Total length of the folder listing
 @param onlyPacket Is this the only packet to transfer.
*/
void FtpsGetFolderFirstPacket(FTPS *session,
						const uint16 size_packet,  const uint8 *packet, 
						const uint32 totalLen, const bool onlyPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_FIRST_PACKET);
        
		message->nameLen = 0;
		message->name = NULL;
		message->typeLen = sizeof(typeFolder);
		message->type = typeFolder;
		message->length = size_packet;
		message->packet = packet;
		message->totalLen = totalLen;
		message->onlyPacket = onlyPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_FIRST_PACKET, message);
	}
}

/*!
 @brief Send the next packet of a folder listing.  
 @param session FTPS Session Handle.
 @param size_packet Length of this packet
 @param packet The first packet
 @param lastPacket Is this the last packet to transfer.
*/
void FtpsGetFolderNextPacket(FTPS *session,
						const uint16 size_packet,  const uint8 *packet, const bool lastPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_NEXT_PACKET);
        
		message->length = size_packet;
		message->packet = packet;
		message->lastPacket = lastPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_NEXT_PACKET, message);
	}
}

/*!
 @brief Send the first packet of a folder listing.  
 @param session FTPS Session Handle.
 @param size_packet Length of this packet
 @param src The source containing the packet
 @param offset The offset into the source
 @param totalLen Total length of the folder listing
 @param onlyPacket Is this the only packet to transfer.
*/
void FtpsGetFolderFirstPacketSource(FTPS *session,
						const uint16 size_packet,  Source src, uint16 offset, 
						const uint32 totalLen, const bool onlyPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_FIRST_PACKET_SRC);
        
		message->nameLen = 0;
		message->name = NULL;
		message->typeLen = sizeof(typeFolder);
		message->type = typeFolder;
		message->length = size_packet;
		message->src = src;
		message->offset = offset;
		message->totalLen = totalLen;
		message->onlyPacket = onlyPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_FIRST_PACKET_SRC, message);
	}
}

/*!
 @brief Send the next packet of a folder listing.  
 @param session FTPS Session Handle.
 @param size_packet Length of this packet
 @param src The source containing the packet
 @param offset The offset into the source
 @param lastPacket Is this the last packet to transfer.
*/
void FtpsGetFolderNextPacketSource(FTPS *session,
						const uint16 size_packet,  Source src, uint16 offset, const bool lastPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_NEXT_PACKET_SRC);
        
		message->length = size_packet;
		message->src = src;
		message->offset = offset;
		message->lastPacket = lastPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_NEXT_PACKET_SRC, message);
	}
}

/*!
 @brief Send the first packet of a get object request.  
 @param session FTPS Session Handle.
 @param size_name Length of this name
 @param name The first packet
 @param size_type Length of this type
 @param type The first packet
 @param size_packet Length of this packet
 @param packet The first packet
 @param totalLen Total length of the folder listing
 @param onlyPacket Is this the only packet to transfer.
*/
void FtpsGetObjectFirstPacket(FTPS *session,
						const uint16 size_name,  const uint8 *name, 
						const uint16 size_type,  const uint8 *type, 
						const uint16 size_packet,  const uint8 *packet, 
						const uint32 totalLen, const bool onlyPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_FIRST_PACKET);
        
		message->nameLen = size_name;
		message->name = name;
		message->typeLen = size_type;
		message->type = type;
		message->length = size_packet;
		message->packet = packet;
		message->totalLen = totalLen;
		message->onlyPacket = onlyPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_FIRST_PACKET, message);
	}
}

/*!
 @brief Send the next packet of a get object request.  
 @param session FTPS Session Handle.
 @param size_packet Length of this packet
 @param packet The first packet
 @param lastPacket Is this the last packet to transfer.
*/
void FtpsGetObjectNextPacket(FTPS *session,
						const uint16 size_packet,  const uint8 *packet, const bool lastPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_NEXT_PACKET);
        
		message->length = size_packet;
		message->packet = packet;
		message->lastPacket = lastPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_NEXT_PACKET, message);
	}
}

/*!
 @brief Send the first packet of a get object request.  
 @param session FTPS Session Handle.
 @param size_name Length of this name
 @param name The first packet
 @param size_type Length of this type
 @param type The first packet
 @param size_packet Length of this packet
 @param src The source containing the packet
 @param offset The offset into the source
 @param totalLen Total length of the folder listing
 @param onlyPacket Is this the only packet to transfer.
*/
void FtpsGetObjectFirstPacketSource(FTPS *session,
						const uint16 size_name,  const uint8 *name, 
						const uint16 size_type,  const uint8 *type, 
						const uint16 size_packet,  Source src, uint16 offset, 
						const uint32 totalLen, const bool onlyPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_FIRST_PACKET_SRC);
        
		message->nameLen = size_name;
		message->name = name;
		message->typeLen = size_type;
		message->type = type;
		message->length = size_packet;
		message->src = src;
		message->offset = offset;
		message->totalLen = totalLen;
		message->onlyPacket = onlyPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_FIRST_PACKET_SRC, message);
	}
}

/*!
 @brief Send the next packet of a get object request.  
 @param session FTPS Session Handle.
 @param size_packet Length of this packet
 @param src The source containing the packet
 @param offset The offset into the source
 @param lastPacket Is this the last packet to transfer.
*/
void FtpsGetObjectNextPacketSource(FTPS *session,
						const uint16 size_packet,  Source src, uint16 offset, const bool lastPacket)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_NEXT_PACKET_SRC);
        
		message->length = size_packet;
		message->src = src;
		message->offset = offset;
		message->lastPacket = lastPacket;
        
		MessageSend(ftps, FTPS_INT_SEND_NEXT_PACKET_SRC, message);
	}
}

/****************************************************************************
NAME	
	FtpsSendNextObjectPacket

DESCRIPTION
	Send the next packet of a folder listing.  
	
RETURNS
    void
*/
void FtpsGetObjectReject(FTPS *session, ftps_transfer_reason reason)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_GET_REJECT);
        
		message->reason = reason;
        
		MessageSend(ftps, FTPS_INT_SEND_GET_REJECT, message);
	}
}

/****************************************************************************
NAME	
	FtpsPutObjectGetNextPacket

DESCRIPTION
	Request the next packet during a Remote PUT operation.  
	
RETURNS
    void
*/
void FtpsPutObjectGetNextPacket(FTPS *session, bool moreData)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_GET_NEXT_PACKET);
        
        message->moreData = moreData;
        
		MessageSend(ftps, FTPS_INT_GET_NEXT_PACKET, message);
	}
}

/*!
 @brief Send a reject response to a put object request.  
 @param session FTPS Session Handle.
 @param reason Reason to reject the request.
*/
void FtpsPutObjectReject(FTPS *session, ftps_transfer_reason reason)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_PUT_REJECT);
        
		message->reason = reason;
        
		MessageSend(ftps, FTPS_INT_SEND_PUT_REJECT, message);
	}
}

/****************************************************************************
NAME	
	FtpsSendDeleteReply

DESCRIPTION
	Send the result of a DELETE request.
RETURNS
    void
*/
void FtpsDeleteResponse(FTPS *session, bool success)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SEND_DELETE_REPLY);
        
        message->success = success;
        
		MessageSend(ftps, FTPS_INT_SEND_DELETE_REPLY, message);
	}
}

/*!
	@brief Send the result of a SETPATH request.
	@param session FTPS Session Handle.
	@param result Result of a SETPATH request.
*/
void FtpsSetPathRootResponse(FTPS *session, ftps_setpath_result result)
{
	SendInternalSetPathResponse(session, result);
}

/*!
	@brief Send the result of a SETPATH request.
	@param session FTPS Session Handle.
	@param result Result of a SETPATH request.
*/
void FtpsSetPathParentResponse(FTPS *session, ftps_setpath_result result)
{
	SendInternalSetPathResponse(session, result);
}

/*!
	@brief Send the result of a SETPATH request.
	@param session FTPS Session Handle.
	@param result Result of a SETPATH request.
*/
void FtpsSetPathSubFolderResponse(FTPS *session, ftps_setpath_result result)
{
	SendInternalSetPathResponse(session, result);
}

static void SendInternalSetPathResponse(FTPS *session, ftps_setpath_result result)
{
    Task ftps;
    
    ftps = (Task)(&session->task);
	
	/* Send an internal message */
	{
		MAKE_FTPS_MESSAGE(FTPS_INT_SETPATH_RESULT);
        
        message->result = result;
        
		MessageSend(ftps, FTPS_INT_SETPATH_RESULT, message);
	}
}

/*!
	@brief The packet received has been processed and is no longer needed.
	@param session FTPS Session Handle (as returned in FTPS_INIT_CFM).
	
	Every packet send to the client that contains a source must be declared complete before the next
	function is called.
	e.g. When a FTPS_PUTOBJECT_START_IND has been received, FtpsPacketComplete must be called before calling
	FtpsPutObjectGetNextPacket.
*/
void FtpsPacketComplete(FTPS *session)
{
	GoepPacketComplete(session->handle);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -