📄 bs_ue.c
字号:
/******************************************************************************\
Copyright (c) 2007, UTStarcom,Inc. (ShenZhen R&D Center)
All Rights Reserved.
Subsystem : WIMAX
Group : GW/AnchorDP/...
File : bs_ue.c
Version :
Build :
Author : RCT
Maintained by : RCT
Create Date : 2007-01-22
Last Modify :
Description : BS SIM UE Context
\******************************************************************************/
/*
-----------------------------------------------------------
Software Develop CodeName :
Module Reference :
-----------------------------------------------------------
Change History:
07-01.22 RCT create file.
*/
#include <vxWorks.h>
#include <stdio.h>
#include <string.h>
#include <tickLib.h>
#include "global.h"
#include "bs_ue.h"
#include "bs_common.h"
#include "bs_fsm.h"
St_BsUeCtxt gBsUeCtxt[BS_MAX_NUM_UE];
St_BsUeCtxt_List gBsUeFreeList;
St_BsUeCtxt_List gBsUeHashList[BS_UE_HASH_LEN];
unsigned hash_func
(
char *string, /* string to use for hashcode */
FAST unsigned len /* length of input string */
)
{
FAST unsigned sum;
FAST unsigned value = 0;
sum = 0;
for (; len > 0; len--)
{
value = (unsigned) (*string++ & 0xFF);
sum += value * value;
}
return (sum);
}
int BS_UeCtxtInit()
{
int i;
St_BsUeCtxt *pUeCtxt = NULL;
bzero((char *)gBsUeCtxt,sizeof(gBsUeCtxt));
TAILQ_INIT(&gBsUeFreeList);
for(i = 0;i < BS_MAX_NUM_UE; i++)
{
pUeCtxt = &gBsUeCtxt[i];
BS_UECTXT_MAGIC_SET(pUeCtxt);
TAILQ_INSERT_TAIL(&gBsUeFreeList,pUeCtxt,listNode);
}
for (i = 0; i < BS_UE_HASH_LEN; i ++) {
TAILQ_INIT(&gBsUeHashList[i]);
}
return SUCCESS;
}
void BS_UeCtxtCheck(unsigned char *caller,unsigned int line)
{
int i;
St_BsUeCtxt *pUeCtxt = NULL;
/*
printf("caller %s line %d, uectxt free num %d\n",caller,line,TAILQ_TOTAL(&gBsUeFreeList));
TAILQ_FOREACH(pUeCtxt, &gBsUeFreeList, listNode)
{
if(!BS_UECTXT_GOOD(pUeCtxt)) {
printf("BS Ue Context damaged\n");
taskSuspend(0);
break;
}
}
*/
return ;
}
St_BsUeCtxt* BS_UeAlloc(R64_MS_ID_S msId)
{
int hashKey;
St_BsUeCtxt *pUeCtxt = NULL;
St_BsUeCtxt_List *pUeListHdr = NULL;
BS_UeCtxtCheck(__FUNCTION__,__LINE__);
if (NULL != (pUeCtxt = TAILQ_FIRST(&gBsUeFreeList))){
TAILQ_REMOVE(&gBsUeFreeList, pUeCtxt, listNode);
} else {
TRACE3("BS No free Ue\n");
return NULL;
}
if(!BS_UECTXT_GOOD(pUeCtxt)) {
TRACE3("BS Ue Context damaged\n");
if(pUeCtxt) {
TRACE3("magic0 0x%x, magic1 0x%x\n",pUeCtxt->magic0,pUeCtxt->magic1);
} else {
TRACE3("null pUeCtxt\n");
}
return NULL;
}
pUeCtxt->flag = BS_UECTXT_EXIST;
pUeCtxt->state = BSFS_NULL;
pUeCtxt->xid = 1;
bcopy((char *)&msId,(char *)&pUeCtxt->msId,sizeof(R64_MS_ID_S));
pUeCtxt->ueId = BS_GET_UE_ID(pUeCtxt);
hashKey = hash_func((char *)&msId,6);
hashKey = BS_UECTXT_HASHKEY(hashKey);
pUeListHdr = &gBsUeHashList[hashKey];
TAILQ_INSERT_HEAD(pUeListHdr, pUeCtxt, listNode);
/* other process */
BS_UeCtxtCheck(__FUNCTION__,__LINE__);
return pUeCtxt;
}
St_BsUeCtxt* BS_Ue_Lookup_By_MSID(R64_MS_ID_S msId)
{
int hashKey;
St_BsUeCtxt *pUeCtxt = NULL;
St_BsUeCtxt_List *pUeListHdr = NULL;
hashKey = hash_func((char *)&msId,6);
hashKey = BS_UECTXT_HASHKEY(hashKey);
pUeListHdr = &gBsUeHashList[hashKey];
TAILQ_FOREACH(pUeCtxt, pUeListHdr, listNode) {
if (pUeCtxt ->flag && !bcmp((char *)&pUeCtxt->msId,(char *)&msId,6)) {
return pUeCtxt;
}
}
return NULL;
}
St_BsUeCtxt* BS_Ue_Lookup_By_UEID(unsigned short ueId)
{
if (ueId > 0 && ueId <= BS_MAX_NUM_UE && gBsUeCtxt[ueId-1].flag && gBsUeCtxt[ueId-1].ueId == ueId) {
return &gBsUeCtxt[ueId-1];
}
return NULL;
}
int BS_UeFree(St_BsUeCtxt *pUeCtxt)
{
int hashKey;
St_BsUeCtxt_List *pUeListHdr = NULL;
BS_UeCtxtCheck(__FUNCTION__,__LINE__);
if(!BS_UECTXT_GOOD(pUeCtxt)) {
TRACE3("BS Ue Ctxt damaged\n");
return FAILURE;
}
/* other process */
pUeCtxt->flag = 0;
pUeCtxt->state = BSFS_NULL;
/* remove from hash and return it to free list */
hashKey = hash_func((char *)&pUeCtxt->msId,6);
hashKey = BS_UECTXT_HASHKEY(hashKey);
pUeListHdr = &gBsUeHashList[hashKey];
TAILQ_REMOVE(pUeListHdr, pUeCtxt, listNode);
TAILQ_INSERT_TAIL(&gBsUeFreeList,pUeCtxt, listNode);
BS_UeCtxtCheck(__FUNCTION__,__LINE__);
return SUCCESS;
}
void BS_ShowMs ()
{
int i;
int count = 0;
R64_MS_ID_S msId[BS_MAX_MS_NUM];
unsigned short ueId[BS_MAX_NUM_UE];
St_BsUeCtxt *pUeCtxt = NULL;
St_BsUeCtxt_List *pUeListHdr = NULL;
for(i = 0;i < BS_UE_HASH_LEN;i++)
{
if(gBsUeHashList[i].tqh_first == NULL)
continue;
pUeListHdr = &gBsUeHashList[i];
TAILQ_FOREACH(pUeCtxt, pUeListHdr, listNode)
{
msId[count] = pUeCtxt->msId;
ueId[count] = pUeCtxt->ueId;
count++;
}
}
printf("total %d ms connected:\n",count);
for(i = 0;i < count;i++)
{
printf("ms %d, msId:0x%02x%02x%02x-%02x%02x%02x, ueId:%d\n",i,
msId[i].id[0],msId[i].id[1],msId[i].id[2],msId[i].id[3],msId[i].id[4],msId[i].id[5],
ueId[i]);
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -