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

📄 swszigbeenwk.c

📁 ucos在NEC平台下的移植
💻 C
📖 第 1 页 / 共 3 页
字号:
#pragma  section @@DATA swsZigbeeNWK at 0xF300

#include "includes.h"     


NWK_NIB nnib;
extern MAC_PIB mpib;
DEVICE_INFO deviceInfo;
MLME_START_REQUEST_INFO  mlmeStartRequestInfo;
MLME_BEACON_NOTIFY_INDICATION mlmeBeaconNotifyInfo;
NWK_DISCOVERY_INFO              nwkDiscoveryInfo;
NWK_PERMIT_JOIN_INFO  nwkPermitJoinInfo;
NWK_JOIN_INFO               nwkJoinInfo;
extern NWK_NETWORK_DISCOVERY_INFO nwkNetworkDiscoveryInfo;
NWK_DIRECT_JOIN_INFO   nwkDirectJoinInfo;
NWK_FORMATION_INFO nwkFormInfo;
MAC_ASSOCIATE_RESPONSE_INFO macAssociateResponseInfo;
MAC_ASSOCIATE_INDICATION_INFO macAssociateIndicationInfo;
MAC_ASSOCIATE_CONFIRM_INFO      macAssociateConfirmInfo;
NWK_LEAVE_INFO   nwkLeaveInfo;
NWK_START_ROUTER_INFO nwkStartRouterInfo;
MAC_POLL_INFO      macPollInfo;
NLDE_DATA_REQUEST_INFO nldeDataRequestInfo;
MCPS_DATA_INDICATION  mcpsDataIndicationInfo;
//BYTE                                 nwkTxFrame[NWK_HEADER_LENGTH+nwkcMaxPayloadSize];
BYTE                                *recivedInformation;// this pointer points to the recived frame,and this pointer is useful in the constructing of the outgoing frame. 
MCPS_DATA_INFO   mcpsDataRequestInfo;
//these two global variable will be initialized in mcpsDataIndication function.
volatile UINT16  nwkSrcAddrInHeaderOfRecivedPacket;
volatile UINT16  nwkDstAddrInHeaderOfRecivedPacket;
volatile UINT16  deviceCoordShortAddress;
UINT16  nwkBroadcastAddress;
NLDE_DATA_INDICATION * pNDI;
BYTE  nwkRxFrameFromAPS[aMaxNWKFrameSize-NWK_HEADER_LENGTH];

extern NEIGHBOR_TABLE_INFO     currentNeighborTableInfo;               // Info about the neighbor table and the node's children.
extern NEIGHBOR_RECORD        *pCurrentNeighborRecord;
extern NEIGHBOR_RECORD         currentNeighborRecord;                      // Node information.

extern NEIGHBOR_RECORD neighborTable[NEIGHBOR_TABLE_ENTRIES];
 UINT16 deviceShortAddress;
extern       BTR   *BTT[NWK_NUM_BUFFERED_BROADCAST_MESSAGES];  // Broadcast Transaction Table

extern NWK_FRAMES              nwkConfirmationHandles[MAX_NWK_FRAMES];


//WORD random;
/*
*********************************************************************************************************
*                                                VARIABLES
*********************************************************************************************************
*/
extern OS_STK        nwkFormNetworkProcedureStk[TASK_STK_SIZE];
BYTE             networkFormState=0;
extern OS_STK        nwkDiscoveryProcedureStk[TASK_STK_SIZE];
BYTE            networkDiscoverState=0;
OS_STK        nwkJoinProcedureStk[TASK_STK_SIZE];
BYTE            networkJoinState=0;
OS_STK        nwkRejoinProcedureStk[TASK_STK_SIZE];
BYTE            networkRejoinState=0;


void ByteArrayContentCopy(BYTE *dest,BYTE *src, BYTE copyLength);

//------------------------------------------------------------------------------------------------------
//     void nwkGlobalVariableStructInitialize();
//
//     DESCRIPTION:
//          Initialize the global struct variables of the NWK layer.
//     PARAMETERS:
//          NO
//     RETURN VALUE:
//          NO
//------------------------------------------------------------------------------------------------------
 void nwkGlobalStructVariableInitialize()
{
 //nnib=malloc(sizeof(NWK_NIB));
 //deviceInfo=malloc(sizeof(DEVICE_INFO));
 
}

//-------------------------------------------------------------------------------------------------------
//  NWK_ENUM nlmeSetRequest(NWK_PIB_ATTR nibAttribute, void *pNibAttributeValue)
//
//  DESCRIPTION:
//      Set NWK PIB attribute.
//
//  PARAMETERS:
//      NWK_PIB_ATTR nibAttribute
//          The attribute to be changed
//      void *pNibAttributeValue
//          A pointer to the NIB attribute. Note that this data is _copied_ into the NIB.
//
//  RETURN VALUE:
//      NWK_ENUM
//          INVALID_PARAMETER, SUCCESS or UNSUPPORTED_ATTRIBUTE
//
//-------------------------------------------------------------------------------------------------------


NWK_ENUM nlmeSetRequest(NWK_NIB_ATTR nibAttribute, void *pNibAttributeValue)
{
  WORD nibAttributeValue;
    
    // Store the word, not always used but saves memory space
    nibAttributeValue = *((WORD*) pNibAttributeValue);
	switch(nibAttribute)
		{
	case NWK_SEQUENCE_NUMBER:
		if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0xff))
		   nnib.nwkSequcenceNumber=(UINT8)nibAttributeValue;
		   break;
    case NWK_PASSIVE_TIME_OUT:
	   	if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0x0a))
		   nnib.nwkPassiveTimeout=(UINT8)nibAttributeValue;
		   break;
	case NWK_MAX_BROADCAST_RETRIES:
		if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0x05))
		   nnib.nwkMaxBroadcastRetries=(UINT8)nibAttributeValue;
		   break;
	case NWK_MAX_CHILDREN:
		if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0xff))
		   nnib.nwkMaxChildren=(UINT8)nibAttributeValue;
		   break;
	case NWK_MAX_DEPTH:
		if((nibAttributeValue>=0x01)&&(nibAttributeValue<=NWKC_MAX_DEPTH))
		   nnib.nwkMaxDepth=(UINT8)nibAttributeValue;
		   break;
       case NWK_MAX_ROUTERS:
	   	if((nibAttributeValue>=0x01)&&(nibAttributeValue<=0xff))
		   nnib.nwkMaxRouters = (UINT8)nibAttributeValue;
		   break;
       case  NWK_NETWORK_BROADCAST_DELIVERY_TIME:
	   	if((nibAttributeValue>=((nnib.nwkPassiveTimeout)*(nnib.nwkMaxBroadcastRetries)))&&(nibAttributeValue<=0xff))
		   nnib.nwkNetworkBroadcastDeliveryTime=(UINT8)nibAttributeValue;
		   break;
	case NWK_REPORT_CONSTANT_COST:
		if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0x01))
		   nnib.nwkReportConstantCost=(UINT8)nibAttributeValue;
		   break;
	case NWK_ROUTE_DISCOVERY_RETRIES_PERMITTED:
		if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0x03))
		   nnib.nwkRouteDiscoveryRetriesPermitted=(UINT8)nibAttributeValue;
		   break;
	case NWK_SYM_LINK:
		if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0x01))
		   nnib.nwkSymlink=(ZBOOL)nibAttributeValue;
		   break;
	case NWK_CAPABILITY_INFORMATION:
		nnib.nwkCapabilityInformation=(BYTE)nibAttributeValue;
		  break;
	case NWK_USE_TREE_ADDR_ALLOC:
		 if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0x01))
		 nnib.nwkUseTreeAddrAlloc=(ZBOOL)nibAttributeValue;
		 break;
	case NWK_USE_TREE_ROUTING:
		 if((nibAttributeValue>=0x00)&&(nibAttributeValue<=0x01))
		 nnib.nwkUseTreeRouting=(ZBOOL)nibAttributeValue;
		 break;
	case NWK_NEXT_ADDRESS:
		 if((nibAttributeValue>=0x0000)&&(nibAttributeValue<=0xfffd))
		 nnib.nwkNextAddress=nibAttributeValue;
		 break;
	case NWK_AVAILABLE_ADDRESSES:
		 if((nibAttributeValue>=0x0000)&&(nibAttributeValue<=0xfffd))
		 nnib.nwkAvailableAddresses=nibAttributeValue;
		 break;
	case NWK_ADDRESS_INCREAMENT:
		 if((nibAttributeValue>=0x0000)&&(nibAttributeValue<=0xfffd))
		 nnib.nwkAddressIncreament=nibAttributeValue;
		 break;
	case NWK_TRANSACTION_PERSISTENCE_TIME:
		 if((nibAttributeValue>=0x0000)&&(nibAttributeValue<=0xffff))
		 nnib.nwkTransactionPersistenceTime=nibAttributeValue;
		 break;
	default:
        return NWK_UNSUPPORTED_ATTRIBUTE;
		break;
	 }
	return NWK_SUCCESS;
}


//-------------------------------------------------------------------------------------------------------
//  NWK_ENUM nlmeGetRequest(NWK_NIB_ATTR nibAttribute, void *pNibAttributeValue)
//
//  DESCRIPTION:
//      Get NWK NIB attributes. The value is copied to the location pointed to by the void*. Note that 
//      some values are returned as pointers:
//          - pMacBeaconPayload
//          - pMacACLEntryDescriptorSet
//          - pMacDefaultSecurityMaterial
//
//  PARAMETERS:
//      NWK_NIB_ATTR nibAttribute
//          The attribute to be changed
//      void *pNibAttributeValue
//          A pointer to the PIB attribute. Note that this data is _copied_ into the PIB.
//
//  RETURN VALUE:
//      NWK_ENUM
//          SUCCESS or UNSUPPORTED_ATTRIBUTE
//-------------------------------------------------------------------------------------------------------
NWK_ENUM nlmeGetRequest(NWK_NIB_ATTR nibAttribute, void *pNibAttributeValue)
{
   switch(nibAttribute)
   	{
    case NWK_SEQUENCE_NUMBER:
   	*((UINT8*)pNibAttributeValue)=nnib.nwkSequcenceNumber++;
	 break;
    case NWK_PASSIVE_TIME_OUT:
   	*((UINT8*)pNibAttributeValue)=nnib.nwkPassiveTimeout;
	break;
    case NWK_MAX_BROADCAST_RETRIES:
   	*((UINT8*)pNibAttributeValue)=nnib.nwkMaxBroadcastRetries;
	break;
    case  NWK_MAX_CHILDREN:
	*((UINT8*)pNibAttributeValue)=nnib.nwkMaxChildren;
	break;
    case NWK_MAX_DEPTH:
	*((UINT8*)pNibAttributeValue)=nnib.nwkMaxDepth;
	break;
    case NWK_MAX_ROUTERS:
	*((UINT8*)pNibAttributeValue)=nnib.nwkMaxRouters;
	break;
    case NWK_NETWORK_BROADCAST_DELIVERY_TIME:
	*((UINT8*)pNibAttributeValue)=nnib.nwkNetworkBroadcastDeliveryTime;
	break;
    case NWK_REPORT_CONSTANT_COST:
	*((UINT8*)pNibAttributeValue)=nnib.nwkReportConstantCost;
	break;
    case NWK_ROUTE_DISCOVERY_RETRIES_PERMITTED:
	*((UINT8*)pNibAttributeValue)=nnib.nwkRouteDiscoveryRetriesPermitted;
	break;
    case NWK_SYM_LINK:
	*((ZBOOL*)pNibAttributeValue)=nnib.nwkSymlink;
	break;
    case NWK_CAPABILITY_INFORMATION:
	*((BYTE*)pNibAttributeValue)=nnib.nwkCapabilityInformation;
	break;
    case NWK_USE_TREE_ADDR_ALLOC:
	*((ZBOOL*)pNibAttributeValue)=nnib.nwkUseTreeAddrAlloc;
	break;
    case  NWK_USE_TREE_ROUTING:
	*((ZBOOL*)pNibAttributeValue)=nnib.nwkUseTreeRouting;
	break;
    case NWK_NEXT_ADDRESS:
	*((WORD*)pNibAttributeValue)=nnib.nwkNextAddress;
	break;
    case NWK_AVAILABLE_ADDRESSES:
	*((WORD*)pNibAttributeValue)=nnib.nwkAvailableAddresses;
	break;
    case NWK_ADDRESS_INCREAMENT:
	*((WORD*)pNibAttributeValue)=nnib.nwkAddressIncreament;
	break;
    case NWK_TRANSACTION_PERSISTENCE_TIME:
	*((WORD*)pNibAttributeValue)=nnib.nwkTransactionPersistenceTime;
       break;
    default:
	 return NWK_UNSUPPORTED_ATTRIBUTE;
    	}
      return NWK_SUCCESS;
}
//-------------------------------------------------------------------------------------------------------
//  void mlmeBeaconNotifyIndication(MLME_BEACON_NOTIFY_INDICATION *pMBNI)
//
//  DESCRIPTION:
//      MAC callback to the higher layer upon reception of a beacon frame with beacon payload
//      or when MAC_AUTO_REQUEST is set to FALSE.
//      
//  we should check the addrlist ,if our address is in the addresslist,we should do data request.
//     //do operation for the  Extended addresses first
 //
//  PARAMETERS:
//      MLME_BEACON_NOTIFY_INDICATION *pMBNI
//          Pointer to the MLME_BEACON_NOTIFY_INDICATION beacon notification struct 
//-------------------------------------------------------------------------------------------------------
void mlmeBeaconNotifyIndication(MLME_BEACON_NOTIFY_INDICATION *pMBNI)
{
  
  ZBOOL pending;
   int i;
  UINT8 n;
  /*initialize the  mlmeBeaconNotifyInfo variable  based on the input parameter*/
  mlmeBeaconNotifyInfo.bsn=pMBNI->bsn;
  mlmeBeaconNotifyInfo.panDescriptor=pMBNI->panDescriptor;//this is the panDescriptor for the received beacon
  mlmeBeaconNotifyInfo.pendAddrSpec=pMBNI->pendAddrSpec;
  mlmeBeaconNotifyInfo.sduLength=pMBNI->sduLength;
  for(i=0;i<7;i++)
  	{
  mlmeBeaconNotifyInfo.pAddrList[i].Short=pMBNI->pAddrList[i].Short;
  ByteArrayContentCopy(mlmeBeaconNotifyInfo.pAddrList[i].Extended,pMBNI->pAddrList[i].Extended,8);
  	}
  ByteArrayContentCopy(mlmeBeaconNotifyInfo.pSdu,pMBNI->pSdu,mlmeBeaconNotifyInfo.sduLength);

  if(mlmeBeaconNotifyInfo.panDescriptor.coordAddrMode=AM_SHORT_16)
  	{
         if( NWKLookupNodeByShortAddr(mlmeBeaconNotifyInfo.panDescriptor.coordAddress.Short)!=INVALID_NEIGHBOR_INDEX)
         	{
                //recived beacon from the old coordinator,the device shuld change some information in its neighbor table
		 }
	  else
	  	{
               //recived beacon from new coordinator,maybe a new FFD has joined the network.
               if(CanAddNeighborNode()!=INVALID_NEIGHBOR_INDEX)
               	{
                        currentNeighborRecord.deviceInfo.bits.bInUse            = 1;
                        currentNeighborRecord.deviceInfo.bits.relationship      = NEIGHBOR_IS_NONE;
                        // We don't know the long address from the beacon, so set it to 0's.
                            for (i=0; i<8; i++)
                            {
                                currentNeighborRecord.longAddress[i] = 0x00;
                            }
                        // Update the neighbor table size.
                        currentNeighborTableInfo.neighborTableSize++;
                            WriteNeighborTableInfoIntoROM();
			ResetNeighborTableFields:
                            // Set/Update the fields that may need updating.
                            if (mlmeBeaconNotifyInfo.panDescriptor.superframeSpec&0x02)
                            {
                                currentNeighborRecord.deviceInfo.bits.deviceType        = DEVICE_CAPABILITY_INFO&CI_DEVICE_TYPE_IS_FFD_BM;
                            }
                            else
                            {
                                currentNeighborRecord.deviceInfo.bits.deviceType        = DEVICE_CAPABILITY_INFO&CI_DEVICE_TYPE_IS_FFD_BM;
                            }
                            currentNeighborRecord.deviceInfo.bits.rxOnWhenIdle      =(BYTE) 1;
                            currentNeighborRecord.deviceInfo.bits.depth             = (BYTE)((mlmeBeaconNotifyInfo.pSdu[2] & 0x78) >> 3);
                            currentNeighborRecord.deviceInfo.bits.stackProfile      = (BYTE)(mlmeBeaconNotifyInfo.pSdu[1] & 0x0F);
                            currentNeighborRecord.deviceInfo.bits.zigBeeVersion     = (BYTE)((mlmeBeaconNotifyInfo.pSdu[1] & 0xF0) >> 4);
                            currentNeighborRecord.deviceInfo.bits.lqi               =(BYTE) mlmeBeaconNotifyInfo.panDescriptor.linkQuality;
                            currentNeighborRecord.deviceInfo.bits.permitJoining     =(BYTE) mlmeBeaconNotifyInfo.pSdu[2]&0xC0;

                            #ifdef NWK_OPT_FFD
                                currentNeighborRecord.deviceInfo.bits.potentialParent   = (mlmeBeaconNotifyInfo.pSdu[2] & 0x04) == 0x04;
                            #else
                                currentNeighborRecord.deviceInfo.bits.potentialParent   = (mlmeBeaconNotifyInfo.pSdu[2] & 0x80) == 0x80;
                            #endif

                            currentNeighborRecord.panID             = mlmeBeaconNotifyInfo.panDescriptor.coordPanId;
                            currentNeighborRecord.shortAddress = mlmeBeaconNotifyInfo.panDescriptor.coordAddress.Short;
                            currentNeighborRecord.logicalChannel    = mlmeBeaconNotifyInfo.panDescriptor.logicalChannel;

                            WriteNeighborTableInfoIntoROM(pCurrentNeighborRecord, (BYTE*)&currentNeighborRecord);

			 }
	       }
        }

⌨️ 快捷键说明

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