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

📄 main.c

📁 test ftp server code for bluetooth
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release

FILE NAME
    main.c
    
DESCRIPTION
	Main source file for an FTP Server application.
	Performs initialisation
*/

#include "ftps.h"
#include <message.h>
#include <vm.h>
#include <stdlib.h>
#include <connection.h>

#include "ftp_server.h"


tFTPState FTPState;
tMainState MainState;

#define OBJECT_TRANS_COD ((uint32)1<<20)

static const uint8 serviceRecordFTP[] =
    {   
		/* Service class ID list */
		0x09,0x00,0x01,  /* AttrID , ServiceClassIDList */
		0x35,0x03,   /* 3 bytes in total DataElSeq */
		0x19,0x11,0x06,  /* 2 byte UUID, Service class = OBEX_FTP */

		/* protocol descriptor list */
		0x09,0x00,0x04,  /* AttrId ProtocolDescriptorList */
		0x35,0x11,   /* 17 bytes in total DataElSeq */
		0x35,0x03,   /* 3 bytes in DataElSeq */
		0x19,0x01,0x00,  /* 2 byte UUID, Protocol = L2CAP */

		0x35,0x05,   /* 5 bytes in DataElSeq */
		0x19,0x00,0x03,  /* 2 byte UUID Protocol = RFCOMM */
		0x08,0x00,   /* 1 byte UINT - server channel template value 0 - to be filled in by library */

		0x35,0x03,   /* 3 bytes in DataElSeq */
		0x19, 0x00, 0x08, /* 2 byte UUID, Protocol = OBEX */

		/* service name */
		0x09,0x01,0x00,  /* AttrId - Service Name */
		0x25,0x08,   /* 8 byte string - OBEX FTP */
		'O','B','E','X',' ','F','T','P',

		/* profile descriptor list */
		0x09,0x00,0x09,  /* AttrId, ProfileDescriptorList */
		0x35,0x08,   /* DataElSeq wrapper */
		0x35,0x06,   /* 6 bytes in total DataElSeq */
		0x19,0x11,0x06,  /* 2 byte UUID, Service class = OBEX_FTP */
		0x09,0x01,0x00,  /* 2 byte uint, version = 100 */
    };


static void connect_handler(Task task, MessageId id, Message message)
{
	/* Get task control block */
	tMainState *state = (tMainState*)task;

	state = state;

	switch(id)
	{
	case CL_INIT_CFM:
	{
		CL_INIT_CFM_T *msg = (CL_INIT_CFM_T*)message;
		CON_DEBUG(("CL_INIT_CFM :- "));
		if (msg->status == success)
		{
			GEN_DEBUG(("success\n"));
			ConnectionSmSetSdpSecurityIn(TRUE);

			/* Initialise the FTP Server */
			FtpsInit(&FTPState.FtpTask, 1);
			
			/* Get class of device so we can include Object Transfer */
			ConnectionReadClassOfDevice(&state->ConTask);
		}
		else
			GEN_DEBUG(("failure : %d\n", msg->status));

		break;
	}
	case CL_DM_CLASS_OF_DEVICE_CFM:
	{
		CL_DM_CLASS_OF_DEVICE_CFM_T *msg = (CL_DM_CLASS_OF_DEVICE_CFM_T*)message;
		uint32 cod = msg->dev_class;
		CON_DEBUG(("CL_DM_CLASS_OF_DEVICE_CFM\n"));
		CON_DEBUG(("    Before 0x%X%X\n",(uint16)(cod>>16), (uint16)(cod & 0xffff)));
		cod |= OBJECT_TRANS_COD;
		CON_DEBUG(("     After 0x%X%X\n",(uint16)(cod>>16), (uint16)(cod & 0xffff)));
		
		ConnectionWriteClassOfDevice(cod);
	}
	case CL_SM_PIN_CODE_IND:
	{
		CL_SM_PIN_CODE_IND_T *msg = (CL_SM_PIN_CODE_IND_T*)message;
		uint8 pin_code[4] = {'1','2','3','4'};

		CON_DEBUG(("CL_SM_PIN_REQUEST_IND\n"));
		ConnectionSmPinCodeResponse(&msg->bd_addr, 4, &pin_code[0]); 
		break;
	}
	case CL_SM_AUTHORISE_IND:
	{
		CL_SM_AUTHORISE_IND_T *msg = (CL_SM_AUTHORISE_IND_T*)message;

		ConnectionSmAuthoriseResponse(&msg->bd_addr, msg->protocol_id, msg->channel, msg->incoming, TRUE);
		CON_DEBUG(("CL_SM_AUTHORISE_IND\n"));
		break;
	}

	default:
		CON_DEBUG(("Unhandled Message : %d , 0x%0X\n",id,id)); 
		break;
	}
}

int main(void)
{
	/* Set up Connection Manager message handler */
	MainState.ConTask.handler = connect_handler;

	/* Set up FTP Server message handler */
	ftp_initTask(&FTPState);

	GEN_DEBUG(("FTP Server App. Started\n"));

	ConnectionInit(&MainState.ConTask);

	/* Start the message scheduler loop */
	MessageLoop();

	/* Never get here! */
	return 0;
}

⌨️ 快捷键说明

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