📄 macfunctionemulationdefinition.c
字号:
if (((UINT8) pibAttributeValue) > 3) {
return MAC_INVALID_PARAMETER;
} else {
mpib.macMinBE = (UINT8) pibAttributeValue;
}
break;
case MAC_ASSOCIATED_PAN_CORDINATOR:
mpib.macAssocatedPanCordinator = (BOOL) pibAttributeValue;
break;
// Category 3 attributes (disable interrupts)
case MAC_BEACON_PAYLOAD:
// DISABLE_GLOBAL_INT();
mpib.pMacBeaconPayload = (BYTE*) pPibAttributeValue;
// ENABLE_GLOBAL_INT();
break;
case MAC_BEACON_TX_TIME:
// DISABLE_GLOBAL_INT();
memcpy(&mpib.macBeaconTxTime, (UINT32*) pPibAttributeValue, sizeof(UINT32));
// ENABLE_GLOBAL_INT();
break;
case MAC_COORD_EXTENDED_ADDRESS:
// DISABLE_GLOBAL_INT();
memcpy(&mpib.macCoordExtendedAddress, (QWORD*) pPibAttributeValue, sizeof(QWORD));
// ENABLE_GLOBAL_INT();
break;
case MAC_COORD_SHORT_ADDRESS:
// DISABLE_GLOBAL_INT();
mpib.macCoordShortAddress = pibAttributeValue;
// ENABLE_GLOBAL_INT();
break;
case MAC_PAN_ID:
// DISABLE_GLOBAL_INT();
mpib.macPANId = pibAttributeValue;
// msupWriteRam((BYTE*) &mpib.macPANId, CC2420RAM_PANID, 2, FALSE);
// ENABLE_GLOBAL_INT();
break;
case MAC_SHORT_ADDRESS:
// DISABLE_GLOBAL_INT();
mpib.macShortAddress = pibAttributeValue;
// msupWriteRam((BYTE*) &mpib.macShortAddress, CC2420RAM_SHORTADDR, 2, FALSE);
// ENABLE_GLOBAL_INT();
break;
case MAC_TRANSACTION_PERSISTENCE_TIME:
// DISABLE_GLOBAL_INT();
mpib.macTransactionPersistenceTime = pibAttributeValue;
// ENABLE_GLOBAL_INT();
break;
// Category 4 attributes (buffered until beacon transmission / handled carefully)
/*
case MAC_BATT_LIFE_EXT:
// DISABLE_GLOBAL_INT();
// if (isBeaconEnabledPan && (GET_MF(MF_TRANSMIT_BEACON) || mbcnInfo.trackBeacon)) {
macInfo.pibTempBuffer.macBattLifeExt = (BOOL) pibAttributeValue;
macInfo.pibTempBuffer.updateMask |= MPIB_UPD_BATT_LIFE_EXT_BM;
} else {
mpib.macBattLifeExt = (BOOL) pibAttributeValue;
}
// ENABLE_GLOBAL_INT();
break;*/
/*
case MAC_BEACON_ORDER:
// DISABLE_GLOBAL_INT();
if (((UINT8) pibAttributeValue) > 15) {
return MAC_INVALID_PARAMETER;
} else if (isBeaconEnabledPan && (GET_MF(MF_TRANSMIT_BEACON) || mbcnInfo.trackBeacon)) {
#if MAC_OPT_FFD
// Handle beacon -> non-beacon network change
if ((UINT8) pibAttributeValue == 15) {
if (mtimCancelCallback(mbcnTxPeriodicalBeacon)) mbcnUpdateBufferedPibAttributes();
}
#endif
macInfo.pibTempBuffer.macBeaconOrder = (UINT8) pibAttributeValue;
macInfo.pibTempBuffer.updateMask |= MPIB_UPD_BEACON_ORDER_BM;
} else {
mpib.macBeaconOrder = (UINT8) pibAttributeValue;
}
// Handle non-beacon <-> beacon network change
mbcnHandleBeaconModeChange(!isBeaconEnabledPan);
/ * ENABLE_GLOBAL_INT();* /
break;*/
/*
case MAC_RX_ON_WHEN_IDLE:
// DISABLE_GLOBAL_INT();
if (isBeaconEnabledPan && (GET_MF(MF_TRANSMIT_BEACON) || mbcnInfo.trackBeacon)) {
macInfo.pibTempBuffer.macRxOnWhenIdle = (BOOL) pibAttributeValue;
macInfo.pibTempBuffer.updateMask |= MPIB_UPD_RX_ON_WHEN_IDLE_BM;
} else {
if (!mpib.macRxOnWhenIdle && (BOOL) pibAttributeValue) {
mrxIncrOnCounter();
} else if (mpib.macRxOnWhenIdle && !((BOOL) pibAttributeValue)) {
mrxDecrOnCounter();
}
mpib.macRxOnWhenIdle = (BOOL) pibAttributeValue;
}
// ENABLE_GLOBAL_INT();
break;*/
/*
case MAC_SUPERFRAME_ORDER:
// DISABLE_GLOBAL_INT();
if (((UINT8) pibAttributeValue) > 15) {
return MAC_INVALID_PARAMETER;
} else if (isBeaconEnabledPan && (GET_MF(MF_TRANSMIT_BEACON) || mbcnInfo.trackBeacon)) {
macInfo.pibTempBuffer.macSuperframeOrder = (UINT8) pibAttributeValue;
macInfo.pibTempBuffer.updateMask |= MPIB_UPD_SUPERFRAME_ORDER_BM;
} else {
mpib.macSuperframeOrder = (UINT8) pibAttributeValue;
}
// ENABLE_GLOBAL_INT();
break;*/
#if MAC_OPT_ACL_SIZE > 0
case MAC_ACL_ENTRY_DESCRIPTOR_SET:
mpib.ppMacACLEntryDescriptorSet = (ACL_ENTRY_SET*) pPibAttributeValue;
break;
case MAC_ACL_ENTRY_DESCRIPTOR_SETSIZE:
mpib.macACLEntryDescriptorSetSize = (BYTE) pibAttributeValue;
break;
#endif
#if MAC_OPT_SECURITY
case MAC_DEFAULT_SECURITY:
mpib.macDefaultSecurity = (BYTE) pibAttributeValue;
break;
case MAC_DEFAULT_SECURITY_MATERIAL_LENGTH:
mpib.macDefaultSecurityMaterialLength = (BYTE) pibAttributeValue;
break;
case MAC_DEFAULT_SECURITY_MATERIAL:
mpib.pMacDefaultSecurityMaterial = (SECURITY_MATERIAL*) pPibAttributeValue;
break;
case MAC_DEFAULT_SECURITY_SUITE:
mpib.macDefaultSecuritySuite = (BYTE) pibAttributeValue;
break;
#endif
#if ((MAC_OPT_SECURITY) || (MAC_OPT_ACL_SIZE>0))
case MAC_SECURITY_MODE:
mpib.macSecurityMode = (BYTE) pibAttributeValue;
break;
#endif
default:
return NWK_UNSUPPORTED_ATTRIBUTE;
}
return MAC_SUCCESS;
}
//-------------------------------------------------------------------------------------------------------
// void mlmeAssociateResponse(ADDRESS *pDeviceAddress, WORD assocShortAddress, MAC_ENUM status, ...
//
// DESCRIPTION:
// Used by a ccordinator to respond to an association indication. The response is placed in the
// indirect transmission queue.
// Generates a mlmeCommStatusIndication callback upon completion
//
// PARAMETERS:
// ADDRESS *pDeviceAddress
// Pointer to the extended address of the associated device
// WORD assocShortAddress
// The assigned short address
// MAC_ENUM status
// The association status
// ZBOOL securityEnable
// Security is enabled?
//-------------------------------------------------------------------------------------------------------
void mlmeAssociateResponse(ADDRESS *deviceAddress, WORD assocShortAddress, MAC_ENUM status, ZBOOL securityEnable)
{
printf("I am running the mlmeAssociateResponse() function!\n");
}
//-------------------------------------------------------------------------------------------------------
// void mlmeOrphanResponse(QWORD orphanAddress, WORD shortAddress, ZBOOL associatedMember, ZBOOL ...)
//
// DESCRIPTION:
// Respond to an orphan notification by transmitting a coordinator realignment frame.
//
// PARAMETERS:
// QWORD orphanAddress
// Extended address of the orphaned device
// WORD shortAddress
// The short address of the coordinator
// ZBOOL associatedMember
// This node is associated on this PAN
// Note: mlmeOrphanResponse is ignored if set to FALSE
// ZBOOL securityEnable
// Security is enabled for the coordinator realignment command frame?
//-------------------------------------------------------------------------------------------------------
void mlmeOrphanResponse(QWORD orphanAddress, WORD shortAddress, ZBOOL associatedMember, ZBOOL securityEnable)
{
printf("I am running the mlmeOrphanResponse() function!\n");
}
//-------------------------------------------------------------------------------------------------------
// void mlmeAssociateRequest(UINT8 logicalChannel, BYTE coordAddrMode, WORD coordPANId, ...)
//
// DESCRIPTION:
// Generates an association request command frame, transmitted to the coordinator using direct
// transmission. The response is polled automatically from the coordinator.
// NOTE: Please note that the PAN ID and the coordinator address (short or extended) are set by the
// the MAC layer, according to the IEEE 802.15.4 spec.
//
// PARAMETERS:
// UINT8 logicalChannel
// Channel number (0x0B - 0x1A)
// BYTE coordAddrMode
// AM_SHORT_16 or AM_EXTENDED_64
// WORD coordPANId
// The coordinator PAN identifier
// ADDRESS *pCoordAddress
// Pointer to the short or extended address of the coordinator
// BYTE capabilityInformation
// (CI_ALTERNATE_PAN_COORD_BM | CI_DEVICE_TYPE_IS_FFD_BM | CI_POWER_SOURCE_BM |
// CI_RX_ON_WHEN_IDLE_BM | CI_SECURITY_CAPABILITY_BM | CI_ALLOCATE_ADDRESS_BM)
// ZBOOL securityEnable
// Security is enabled?
//-------------------------------------------------------------------------------------------------------
void mlmeAssociateRequest(UINT8 logicalChannel, BYTE coordAddrMode, WORD coordPANId, ADDRESS *pCoordAddress, BYTE capabilityInformation, ZBOOL securityEnable)
{
//定义这个数组用来存放‘关联请求命令帧’的信息
BYTE associateRequestCommand[15];
WORD wVersionRequested;
WSADATA wsaData;
int err;
SOCKET sock;
struct sockaddr_in server;
struct hostent *hp ;
int i;
char *trueSendNwkData=NULL;
//要通过socket通讯将这一‘关联请求命令帧’发送出去
//下边的这部分代码最先执行
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 )
{
printf("\ncould not find a usable WinSock DLL!\n");
exit(1);
}
printf("I am running the mlmeAssociateRequest() function!\n");
sock = socket(AF_INET, SOCK_STREAM, 0);
printf("The socket number is :%ld\n ",sock);
if (sock ==INVALID_SOCKET)
{
perror("opening stream socket");
exit(1);
}
//定义下边这个‘关联请求命令帧’主要是为了更好地测试网络层的mlmeAssociateIndication函数
associateRequestCommand[0]=(FT_MAC_COMMAND<<5)|(ACK_REQ_BM>>3); //帧控制域的信息
associateRequestCommand[1]=(AM_SHORT_16<<4)|AM_SHORT_16; //帧控制域中目的地址和源地址的编址方式
associateRequestCommand[2]=123; //序列号
associateRequestCommand[3]=(BYTE)(coordPANId>>8);
associateRequestCommand[4]=(BYTE)(coordPANId&0xFF);
associateRequestCommand[5]=(BYTE)(pCoordAddress->Short>>8);
associateRequestCommand[6]=(BYTE)(pCoordAddress->Short&0xFF);
associateRequestCommand[7]=FF; //源PAN标识符
associateRequestCommand[8]=FF;
//设备请求与网络发生关联时,应该使用设备固有的长地址
associateRequestCommand[9]=0x12;
associateRequestCommand[10]=0x35;
associateRequestCommand[11]=0x11;
associateRequestCommand[12]=0x23;
associateRequestCommand[13]=0x12;
associateRequestCommand[14]=0x24;
associateRequestCommand[15]=0x13;
associateRequestCommand[16]=0x25;
associateRequestCommand[17]=0x01; //表示这一命令是连接请求命令
associateRequestCommand[18]=capabilityInformation;//请求与网络关联的设备的性能信息
associateRequestCommand[19]=0; //MAC层帧的尾部信息
associateRequestCommand[20]=0;
//初始化通过socket要传送出去的来自网络层的数据
printf("将要传出去的关联请求命令帧为:!\n");
for(i=0;i<21;i++)
{
printf("%d ",associateRequestCommand[i]);
}
server.sin_family = AF_INET;
hp = gethostbyname("127.0.0.1");
if (hp == 0) {
fprintf(stderr, "%s: unknown host \n", "127.0.0.1");
exit(2);
}
memcpy((char*)&server.sin_addr, (char*)hp->h_addr, hp->h_length);
server.sin_port = htons(pCoordAddress->Short);
if (connect(sock, (struct sockaddr*)&server, sizeof(server)) < 0)
{
perror("connecting stream socket");
exit(3);
}
printf("are you here?\n");
/*此处主要对要被传送出去的数据进行操作*/
// memcpy(sendNwkData,(char*)pMsdu,msduLength);
// trueSendNwkData=(char*)malloc((msduLength+1)*sizeof(char));
// memset(trueSendNwkData,-1,msduLength+1);
if (send(sock, (const char*)associateRequestCommand, 21,0) < 0)
perror("sending on stream socket");
closesocket(sock);
printf("I have send out some command\n");
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -