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

📄 bs_cp.c

📁 wimax bs模拟器
💻 C
字号:
/******************************************************************************
**
**    Copyright (c) 2007, UTStarcom, Inc.
**            All Rights Reserved.
**
**    Subsystem : Wimax BS
**    File      : bs_cp.c
**    Created By: RCT
**    Created On: 1/15/2007
**
**    Purpose:
**        This file define R64 message structure.
**    History:
**    Programmer  Date       Rev     Description
**    RCT		  1/15/2007   0.0     Creating file
******************************************************************************/

#include "global.h"
#include "bs_cp.h"
#include "bs_fsm.h"

MSG_Q_ID 	g_msgq_bscp;
int 			gi_tid_bs=0;
u_long 		bs_cp_trace_id=0;

/*******************************************************************************
** Function Name: bs_cp_init
** Input parameters description:
a - None
** Output results description:
a - ERROR, create UDP task failure.
b - OK, create UDP task success.
** function description:
Create UdpTask
*******************************************************************************/


STATUS bs_cp_init()
{
	int i;

	extern R64_MS_ID_S gMsId;
	extern int BS_UeCtxtInit();
	extern int bs_fsm_init();

     XTRACEOPEN("BS-CP",0,&bs_cp_trace_id);
     XTRACE0(bs_cp_trace_id,2,"bs trace cp opened");


	/* Initial module variables */
	if (ERROR == bs_cp_init_data())
	{
		bs_log_err("bs_cp_init, bs_cp_init_data error.");
		return ERROR;
	}

	/* Initial ue context*/
	for(i = 0;i < R64_MSID_LENGTH;i++)
		gMsId.id[i] = 0;
	if(ERROR == BS_UeCtxtInit())
	{
		bs_log_err("bs_cp_init, BS_UeCtxtInit error.");
	       return ERROR;
	}

	/* Initial fsm*/
	if(ERROR == bs_fsm_init())
	{
		bs_log_err("bs_cp_init, bs_init_call_fsm_init error.");
	       return ERROR;
	}

	/* Create message queue */
	g_msgq_bscp = msgQCreate(BS_CP_MAX_MSG_NUM,BS_CP_MAX_MSG_LEN, MSG_Q_FIFO);
	if (NULL==g_msgq_bscp)
	{
		bs_log_err("bs_cp_init, message queue create error %d.\n", errno);
		return ERROR;
	}

	/* Create task */
	if (ERROR == (gi_tid_bs=xTaskCreate("tBsCp",
	                   (XTHREADFUNC)bs_cp_task_entry,
	                   BS_STACK_SIZE,
	                   0,
	                   BS_TASK_PRI)))
	{
		bs_log_err("bs_cp_init, task spawn error %d.\n", errno);
		return ERROR;
	}

	bs_log_debug("bs_cp_init, bs Startup OK\n");
	return OK;
}

/*******************************************************************************
** Function Name: bs_cp_init
** Input parameters description:
a - None
** Output results description:
a - ERROR, create UDP task failure.
b - OK, create UDP task success.
** function description:
Create UdpTask
*******************************************************************************/

STATUS bs_cp_init_data()
{
	return OK;
}

/*******************************************************************************
** Function Name: gw_cp_task_entry
** Input parameters description:
a - None
** Output results description:
a - ERROR, create UDP task failure.
b - OK, create UDP task success.
** function description:
Create UdpTask
*******************************************************************************/


void bs_cp_task_entry()
{
	unsigned char ab_msg_buf[BS_CP_MAX_MSG_LEN];
	ENVELOP * p_env;
	UDP_MSG_S * p_udp_msg;
	St_BsTmrMsg * p_timer_msg;
	BS_ACTION_MSG_S * p_action_msg;
	int i_msg_len;

	while (1)
	{
		i_msg_len = msgQReceive(g_msgq_bscp, (char *)ab_msg_buf, BS_CP_MAX_MSG_LEN, WAIT_FOREVER);
		if (ERROR == i_msg_len)
		{
			bs_log_err("bs_cp_task_entry, message queue read failed %d.\n", errno);
			break;
		}

		/* Check length */
		if ((unsigned int)i_msg_len < sizeof(ENVELOP))
		{
			bs_log_err("bs_cp_task_entry, receive a too short message %d.\n", i_msg_len);
			continue;
		}

		p_env = (ENVELOP *)ab_msg_buf;

		switch (p_env->protocolSap)
		{
		case BS_UDP_SAP:
			XTRACE0(bs_cp_trace_id,2,"UDP message is received");
			p_udp_msg = (UDP_MSG_S *)ab_msg_buf;
			bs_cp_udp_msg_entry(p_udp_msg);
		    	break;
		case BS_TIMER_SAP:
			XTRACE0(bs_cp_trace_id,2,"Time out message is received");
			p_timer_msg = (St_BsTmrMsg *)ab_msg_buf;
			bs_cp_timer_msg_entry(p_timer_msg);
			break;
		case BS_ACTION_SAP:
			XTRACE0(bs_cp_trace_id,2,"Action message is received");
			p_action_msg = (BS_ACTION_MSG_S *)ab_msg_buf;
			bs_cp_action_msg_entry(p_action_msg);
			break;
		default:
			bs_log_err("bs_cp_task_entry, unknown sap %d.\n", p_env->protocolSap);
			break;
		}
	}
	bs_log_err("the BSCP task terminated");
	return ;
}

/*******************************************************************************
** Function Name: bs_action_msg_entry
** Input parameters description:
a - None
** Output results description:
a - ERROR, create UDP task failure.
b - OK, create UDP task success.
** function description:
Create UdpTask
*******************************************************************************/
STATUS bs_cp_action_msg_entry(BS_ACTION_MSG_S * p_action_msg)
{
	BYTE purpose;
	BS_ACTION_S* pBsAction;

	extern DWORD gHostIp;
	extern DWORD gSourceIp;
	extern DWORD gDestinationIp;
	extern int BS_CallInit(unsigned int msNum);
	extern int BS_UeDreg(unsigned short ueId);

	pBsAction = (BS_ACTION_S*)p_action_msg->data;
	purpose = pBsAction->purpose;

	if(purpose == BS_SIM_CONFIG)
	{
		gHostIp = pBsAction->u.initConfig.gHostIp;
		gSourceIp = pBsAction->u.initConfig.gSourceIp;
		gDestinationIp = pBsAction->u.initConfig.gDestinationIp;
		return SUCCESS;
	}
	else if(purpose == BS_CALL_INIT)
	{
		return BS_CallInit(pBsAction->u.msNum);
	}
	else if(purpose == BS_MS_DEREG)
	{
		return BS_UeDreg(pBsAction->u.ueId);
	}
	else 
	{
		TRACE3("Action message purpose error!\n");
		return FAILURE;
	}
}


/*******************************************************************************
** Function Name: bs_cp_timer_msg_entry
** Input parameters description:
a - None
** Output results description:
a - ERROR, create UDP task failure.
b - OK, create UDP task success.
** function description:
Create UdpTask
*******************************************************************************/
STATUS bs_cp_timer_msg_entry(St_BsTmrMsg * p_timer_msg)
{
	unsigned int event;
	St_BsUeCtxt * pUeCtxt;
		
	extern int BS_FsmGetEventTimer(St_BsTmrMsg * pTmrMsg);

	event = BS_FsmGetEventTimer(p_timer_msg);
	pUeCtxt = (St_BsUeCtxt *)p_timer_msg->dw_data;

	/* enter fsm*/
	if(pUeCtxt->state > BS_FSM_NUM_STATES || event > BS_FSM_NUM_EVENTS) 
	{
		TRACE3("fsm state %d(%d) or event %d(%d) exceeded\n",pUeCtxt->state,event,BS_FSM_NUM_STATES,BS_FSM_NUM_EVENTS);
		return FAILURE;
	}

	if(FAILURE== bs_fsm_entry(pUeCtxt, NULL, pUeCtxt->state,event)) 
	{
		TRACE3("fsm process failed,msId 0x%02x%02x%02x-%02x%02x%02x state %d event %d\n",
				pUeCtxt->msId.id[0],pUeCtxt->msId.id[1],pUeCtxt->msId.id[2],
				pUeCtxt->msId.id[3],pUeCtxt->msId.id[4],pUeCtxt->msId.id[5],
				pUeCtxt->state,event);
		return FAILURE;
	}
	
	return SUCCESS;
}

/*******************************************************************************
** Function Name: bs_cp_udp_msg_entry
** Input parameters description:
a - None
** Output results description:
a - ERROR, create UDP task failure.
b - OK, create UDP task success.
** function description:
Create UdpTask
*******************************************************************************/


STATUS bs_cp_udp_msg_entry(UDP_MSG_S * p_udp_msg)
{
	int i_send_len;
	R64_MSG_S st_r64_msg;

	extern int g_host_sock_fd;
	extern DWORD gHostIp;
	extern void BS_ProtoHandler(R64_MSG_S * pR64Msg);
	
	if(ERROR==bs_udp_send_packet(g_host_sock_fd, gHostIp, HOST_GW_UDP_PORT, p_udp_msg->data,p_udp_msg->dataLen))
	{
		bs_log_err("send gw message to host returned error");
		return ERROR;
	
	}

	/* R6 message handle */
	st_r64_msg.msgHead.ifType = IF_TYPE_R6;
	st_r64_msg.msgHead.destinationIp = p_udp_msg->destIp;
	st_r64_msg.msgHead.destinationUdpPort = p_udp_msg->destUdpPort;
	st_r64_msg.msgHead.sourceIp = p_udp_msg->srcIp;
	st_r64_msg.msgHead.sourceUdpPort = p_udp_msg->srcUdpPort;

	XTRACE4(bs_cp_trace_id,2,"bs_cp_udp_msg_entry, from ip 0x%lx port %d, to us ip 0x%lx port %d",
		st_r64_msg.msgHead.sourceIp,st_r64_msg.msgHead.sourceUdpPort,
		st_r64_msg.msgHead.destinationIp,st_r64_msg.msgHead.destinationUdpPort);
	
	XDUMP(bs_cp_trace_id,1,(char *)&st_r64_msg.msgHead,sizeof(R64_MESSAGE_HEAD_S));
				
	if (SUCCESS == r64_decode_msg(p_udp_msg, &st_r64_msg))
	{
		BS_ProtoHandler(&st_r64_msg);
	}
	else
	{
		bs_log_err("bs_cp_udp_msg_entry, r64_decode_msg error.\n");
		r64_print_msg(&st_r64_msg);
	}
	return SUCCESS;
}

⌨️ 快捷键说明

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