📄 macfunctionemulationdefinition.c
字号:
// (optional).
//
// PARAMETERS:
// UINT8 logicalChannel
// The channel to switch to.
// ZBOOL trackBeacon
// Track beacons if >0.
//-------------------------------------------------------------------------------------------------------
void mlmeSyncRequest(UINT8 logicalChannel, ZBOOL trackBeacon)
{
printf("I am the MAC layer of the stack,I will execute the mlmeSyncRequest function\n");
}
//-------------------------------------------------------------------------------------------------------
// MAC_ENUM mlmeGetRequest(MAC_PIB_ATTR pibAttribute, void *pPibAttributeValue)
//
// DESCRIPTION:
// Get MAC PIB 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:
// MAC_PIB_ATTR pibAttribute
// The attribute to be changed
// void *pPibAttributeValue
// A pointer to the PIB attribute. Note that this data is _copied_ into the PIB.
//
// RETURN VALUE:
// MAC_ENUM
// SUCCESS or UNSUPPORTED_ATTRIBUTE
//-------------------------------------------------------------------------------------------------------
/*
MAC_ENUM mlmeGetRequest(MAC_PIB_ATTR pibAttribute, void *pPibAttributeValue)
{
//在这个函数中主要完成对‘值-结果’参数pPibAttributeValue的赋值操作]
return MAC_SUCCESS;
}*/
MAC_ENUM mlmeGetRequest(MAC_PIB_ATTR pibAttribute, void *pPibAttributeValue) {
switch (pibAttribute) {
#if MAC_OPT_TRANSMIT_POWER
case PHY_TRANSMIT_POWER: *((BYTE*) pPibAttributeValue) = ppib.phyTransmitPower; break;
#endif
// Category 1 attributes (read-only)
case MAC_ACK_WAIT_DURATION: *((BYTE*) pPibAttributeValue) = mpib.macAckWaitDuration; break;
case MAC_GTS_PERMIT: *((BOOL*) pPibAttributeValue) = mpib.macGTSPermit; break;
case MAC_PROMISCUOUS_MODE: *((BOOL*) pPibAttributeValue) = mpib.macPromiscuousMode; break;
// Category 2 attributes (direct write)
case MAC_ASSOCIATION_PERMIT: *((BOOL*) pPibAttributeValue) = mpib.macAssociationPermit; break;
case MAC_AUTO_REQUEST: *((BOOL*) pPibAttributeValue) = mpib.macAutoRequest; break;
case MAC_BEACON_PAYLOAD_LENGTH: *((BYTE*) pPibAttributeValue) = mpib.macBeaconPayloadLength; break;
case MAC_BSN: *((BYTE*) pPibAttributeValue) = mpib.macBSN; break;
//case MAC_DSN: *((BYTE*) pPibAttributeValue) = mpib.macDSN; break;
case MAC_MAX_CSMA_BACKOFFS: *((BYTE*) pPibAttributeValue) = mpib.macMaxCsmaBackoffs; break;
case MAC_MIN_BE: *((BYTE*) pPibAttributeValue) = mpib.macMinBE; break;
case MAC_ASSOCIATED_PAN_CORDINATOR: *((BOOL*) pPibAttributeValue) = mpib.macAssocatedPanCordinator; break;
// Category 3 attributes (disable interrupts)
case MAC_BEACON_PAYLOAD:
*((BYTE**) pPibAttributeValue) = mpib.pMacBeaconPayload;
break;
case MAC_BEACON_TX_TIME:
// DISABLE_GLOBAL_INT();
memcpy(pPibAttributeValue, &mpib.macBeaconTxTime, sizeof(UINT32));
// ENABLE_GLOBAL_INT();
break;
case MAC_COORD_EXTENDED_ADDRESS:
// DISABLE_GLOBAL_INT();
memcpy(pPibAttributeValue, &mpib.macCoordExtendedAddress, sizeof(QWORD));
// ENABLE_GLOBAL_INT();
break;
case MAC_COORD_SHORT_ADDRESS:
// DISABLE_GLOBAL_INT();
// *((WORD*) pPibAttributeValue) = mpib.macCoordShortAddress;
*((WORD*) pPibAttributeValue) =2000;
// ENABLE_GLOBAL_INT();
break;
case MAC_PAN_ID:
// DISABLE_GLOBAL_INT();
*((WORD*) pPibAttributeValue) = mpib.macPANId;
// ENABLE_GLOBAL_INT();
break;
case MAC_SHORT_ADDRESS:
// DISABLE_GLOBAL_INT();
*((WORD*) pPibAttributeValue) = mpib.macShortAddress;
// ENABLE_GLOBAL_INT();
break;
/*
case MAC_TRANSACTION_PERSISTENCE_TIME:
// DISABLE_GLOBAL_INT();
*((WORD*) pPibAttributeValue) = mpib.macTransactionPersistenceTime;
// ENABLE_GLOBAL_INT();
break;
// Category 4 attributes (buffered until beacon transmission / handled carefully)
case MAC_BATT_LIFE_EXT:
// DISABLE_GLOBAL_INT();
if (macInfo.pibTempBuffer.updateMask & MPIB_UPD_BATT_LIFE_EXT_BM) {
*((BOOL*) pPibAttributeValue) = macInfo.pibTempBuffer.macBattLifeExt;
} else {
*((BOOL*) pPibAttributeValue) = mpib.macBattLifeExt;
}
// ENABLE_GLOBAL_INT();
break;*/
/*
case MAC_BEACON_ORDER:
// DISABLE_GLOBAL_INT();
if (macInfo.pibTempBuffer.updateMask & MPIB_UPD_BEACON_ORDER_BM) {
*((BOOL*) pPibAttributeValue) = macInfo.pibTempBuffer.macBeaconOrder;
} else {
*((BOOL*) pPibAttributeValue) = mpib.macBeaconOrder;
}
// ENABLE_GLOBAL_INT();
break;
case MAC_RX_ON_WHEN_IDLE:
// DISABLE_GLOBAL_INT();
if (macInfo.pibTempBuffer.updateMask & MPIB_UPD_RX_ON_WHEN_IDLE_BM) {
*((BOOL*) pPibAttributeValue) = macInfo.pibTempBuffer.macRxOnWhenIdle;
} else {
*((BOOL*) pPibAttributeValue) = mpib.macRxOnWhenIdle;
}
// ENABLE_GLOBAL_INT();
break;
case MAC_SUPERFRAME_ORDER:
// DISABLE_GLOBAL_INT();
if (macInfo.pibTempBuffer.updateMask & MPIB_UPD_SUPERFRAME_ORDER_BM) {
*((BOOL*) pPibAttributeValue) = macInfo.pibTempBuffer.macSuperframeOrder;
} else {
*((BOOL*) pPibAttributeValue) = mpib.macSuperframeOrder;
}
// ENABLE_GLOBAL_INT();
break;
// TBD:
#if MAC_OPT_ACL_SIZE>0
case MAC_ACL_ENTRY_DESCRIPTOR_SET: *((ACL_ENTRY_SET**) pPibAttributeValue) = mpib.ppMacACLEntryDescriptorSet; break;
case MAC_ACL_ENTRY_DESCRIPTOR_SETSIZE: *((BYTE*) pPibAttributeValue) = mpib.macACLEntryDescriptorSetSize; break;
#endif
#if MAC_OPT_SECURITY
case MAC_DEFAULT_SECURITY: *((BOOL*) pPibAttributeValue) = mpib.macDefaultSecurity; break;
case MAC_DEFAULT_SECURITY_MATERIAL_LENGTH: *((BYTE*) pPibAttributeValue) = mpib.macDefaultSecurityMaterialLength; break;
case MAC_DEFAULT_SECURITY_MATERIAL: *((SECURITY_MATERIAL**) pPibAttributeValue) = mpib.pMacDefaultSecurityMaterial; break;
case MAC_DEFAULT_SECURITY_SUITE: *((BYTE*) pPibAttributeValue) = mpib.macDefaultSecuritySuite; break;
#endif
#if ((MAC_OPT_SECURITY) || (MAC_OPT_ACL_SIZE>0))
case MAC_SECURITY_MODE: *((BYTE*) pPibAttributeValue) = mpib.macSecurityMode; break;
#endif*/
default: return MAC_UNSUPPORTED_ATTRIBUTE;
}
return SUCCESS;
} // mlmeGetRequest
//-------------------------------------------------------------------------------------------------------
// void mlmePollRequest(BYTE coordAddrMode, WORD coordPANId, ADDRESS *pCoordAddress, ZBOOL ...)
//
// DESCRIPTION:
// Poll indirect data from the coordinator
//
// PARAMETERS:
// BYTE coordAddrMode
// The coordinator address mode (AM_SHORT_16 or AM_EXTENDED_64)
// WORD coordPANId
// The PAN identifier of the coordinator
// ADDRESS *pCoordAddress
// A pointer to the coordinator address (short or extended)
// ZBOOL securityEnable
// Enable security for data-request command frame?
//-------------------------------------------------------------------------------------------------------
void mlmePollRequest(BYTE coordAddrMode, WORD coordPANId, ADDRESS *coordAddress, ZBOOL securityEnable)
{
//do some operation
}
//-------------------------------------------------------------------------------------------------------
// MAC_ENUM mlmeStartRequest(WORD panId, UINT8 logicalChannel, UINT8 beaconOrder, UINT8 ...)
//
// DESCRIPTION:
// As a coordinator: Start or stop transmitting beacons.
//
// PARAMETERS:
// WORD panId
// The new PAN identifier
// UINT8 logicalChannel
// The channel to operate on (11-26)
// UINT8 beaconOrder
// The beacon order, which defines the beacon interval (0-14 for beacon PAN, 15 for non-beacon PAN)
// UINT8 superframeOrder
// The superframe order, which defines the superframe duration (that is the active period of the
// beacon interval). superframeOrder must be <= beaconOrder
// ZBOOL panCoordinator
// TRUE if this node should be the PAN coordinator
// ZBOOL batteryLifeExtension
// Enable battery life extension
// ZBOOL coordRealignment
// Transmit a coordinator realignment frame before making the changes
// ZBOOL securityEnable
// Security is enabled?
//
// RETURN VALUE:
// MAC_ENUM
// SUCCESS, NO_SHORT_ADDRESS or INVALID_PARAMETER
//-------------------------------------------------------------------------------------------------------
MAC_ENUM mlmeStartRequest(WORD panId, UINT8 logicalChannel, UINT8 beaconOrder, UINT8 superframeOrder, ZBOOL panCoordinator, ZBOOL batteryLifeExtension, ZBOOL coordRealignment, ZBOOL securityEnable)
{
//do some operation
printf("\n我需要构造一个信标帧!\n");
return MAC_SUCCESS;
}
//-------------------------------------------------------------------------------------------------------
// void mlmeDisassociateRequest(BYTE *pDeviceAddress, BYTE disassociateReason, ZBOOL securityEnable)
//
// DESCRIPTION:
// Used by an associated device to notify the coordinator of its intent to leave the PAN or
// used by the coordinator to instruct an associated device to leave the PAN. pDeviceAddress is a
// pointer to the extended address of the device to which to send the disassociation notification
// command.
//
// PARAMETERS:
// QWORD *pDeviceAddress
// For coordinators: A pointer to the extended address of the device to disassociate
// For devices: A pointer to the extended address of coordinator
// BYTE disassociateReason
// The disassociate reason (COORD_WISHES_DEVICE_TO_LEAVE | DEVICE_WISHES_TO_LEAVE)
// ZBOOL securityEnable
// Security is enabled?
//-------------------------------------------------------------------------------------------------------
void mlmeDisassociateRequest(BYTE*pDeviceAddress, BYTE disassociateReason, ZBOOL securityEnable)
{
printf("I am the MAC layer of the stack,I am executing the mlmeDisassociateRequest() function\n");
}
//-------------------------------------------------------------------------------------------------------
// MAC_ENUM mlmeSetRequest(MAC_PIB_ATTR pibAttribute, void *pPibAttributeValue)
//
// DESCRIPTION:
// Set MAC PIB attribute.
//
// PARAMETERS:
// MAC_PIB_ATTR pibAttribute
// The attribute to be changed
// void *pPibAttributeValue
// A pointer to the PIB attribute. Note that this data is _copied_ into the PIB.
//
// RETURN VALUE:
// MAC_ENUM
// INVALID_PARAMETER, SUCCESS or UNSUPPORTED_ATTRIBUTE
//-------------------------------------------------------------------------------------------------------
MAC_ENUM mlmeSetRequest(MAC_PIB_ATTR pibAttribute, void *pPibAttributeValue)
{
//do some operation
BOOL isBeaconEnabledPan = (mpib.macBeaconOrder < 15);
WORD pibAttributeValue;
// Store the word, not always used but saves memory space
pibAttributeValue = *((WORD*) pPibAttributeValue);
switch (pibAttribute) {
#if MAC_OPT_TRANSMIT_POWER
case PHY_TRANSMIT_POWER:
ppib.phyTransmitPower = *((UINT8*)pPibAttributeValue);
break;
#endif
// Category 1 attributes (read-only)
case MAC_ACK_WAIT_DURATION:
if ((UINT8) pibAttributeValue == 54) break;
return MAC_INVALID_PARAMETER;
case MAC_BATT_LIFE_EXT_PERIODS:
if ((UINT8) pibAttributeValue == 6) break;
return MAC_INVALID_PARAMETER;
case MAC_GTS_PERMIT:
case MAC_PROMISCUOUS_MODE:
if ((BOOL) pibAttributeValue == FALSE) break;
return MAC_INVALID_PARAMETER;
// Category 2 attributes (direct write)
case MAC_ASSOCIATION_PERMIT:
mpib.macAssociationPermit = (BOOL) pibAttributeValue;
break;
case MAC_AUTO_REQUEST:
mpib.macAutoRequest = (BOOL) pibAttributeValue;
break;
case MAC_BEACON_PAYLOAD_LENGTH:
if (((UINT8) pibAttributeValue) > aMaxBeaconPayloadLength) {
return MAC_INVALID_PARAMETER;
} else {
mpib.macBeaconPayloadLength = (UINT8) pibAttributeValue;
}
break;
case MAC_BSN:
mpib.macBSN = (UINT8) pibAttributeValue;
break;
case MAC_DSN:
mpib.macDSN = (UINT8) pibAttributeValue;
break;
case MAC_MAX_CSMA_BACKOFFS:
if (((UINT8) pibAttributeValue) > 5) {
return MAC_INVALID_PARAMETER;
} else {
mpib.macMaxCsmaBackoffs = (UINT8) pibAttributeValue;
}
break;
case MAC_MIN_BE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -