📄 mac_callback.c
字号:
//-----------------------------------------------------------------------------
//
// file: mac_callback.c
// description: demonstration program, MAC callbacks
// Version: 1.0
//
//-------------------------------------------------------------------------------
#pragma SFR
#pragma NOP
#pragma STOP
#pragma HALT
#pragma DI
#pragma EI
///////////////////////////////////////////////////////////////////////////////
// Include
#include "../include/config.h"
#include <mac_headers.h>
#include "../include/780547.h"
#include "../include/mac_def.h"
///////////////////////////////////////////////////////////////////////////////
// extern
extern volatile WORD g_myShortAddr;
extern BYTE pRxBuffer[PACKET_LENGTH];
extern BYTE g_Device_Num; // The number of the Device
extern WORD g_LED_brink_time; // LED brink time
extern BOOL g_RcvPacket;
extern BOOL g_AssocIndication; // for Coordinator
extern BOOL g_DataConfirm;
extern MAC_ENUM g_DataStatus;
//-------------------------------------------------------------------------------------------------------
// void mcpsDataIndication(MCPS_DATA_INDICATION *pMDI)
//
// DESCRIPTION:
// mcpsDataIndication is generated by the MAC layer when a data frame is successfully received.
// The higher layer is not required to return quickly from this callback. Note, however, that:
// - No more incoming packets will be processed until this function has returned, in fact all
// mechanisms except beacon handling and already scheduled transmissions will be halted.
// - One slot in the RX packet pool will be occupied.
//
// The coordinator will use the first MSDU byte as an index of which LED to turn on. Bit indexes 4
// to 7 will not be shown, since there are only 4 LEDs (with indexes 0-3).
//
// PARAMETERS:
// MCPS_DATA_INDICATION *pMDI
// A pointer to the structure containing the received packet
//-------------------------------------------------------------------------------------------------------
void mcpsDataIndication(MCPS_DATA_INDICATION *pMDI)
{
// Indicate of the receiving of the packet.
g_RcvPacket = TRUE;
// Get the Short Address of the Device, and decide the brink time.
g_LED_brink_time = pMDI->srcAddr.Short - DEV_SHORT + 1;
// Copy the receiving data.
memcpy(pRxBuffer,pMDI->pMsdu, PACKET_LENGTH);
} // mcpsDataIndication
//-------------------------------------------------------------------------------------------------------
// void mlmeAssociateIndication(ADDRESS deviceAddress, BYTE capabilityInformation, BOOL securityUse,...)
//
// DESCRIPTION:
// mlmeAssociateIndication is generated by the MAC layer upon reception of an associate request
// command frame. For this demo application, all devices are allowed to associate, however only one
// device at the time. The coordinator must be reset before a new device can associate.
//
// The short address is assigned from the associatedAddress variable, which should have been
// incremented if more devices could have joined.
//
// Function must be implemented by the higher layer
//
// PARAMETERS:
// ADDRESS deviceAddress
// The extended address of the device requesting association
// BYTE capabilityInformation
// The operational capabilities of the device requesting association
// CI_ALTERNATE_PAN_COORD_BM 0x01
// CI_DEVICE_TYPE_IS_FFD_BM 0x02
// CI_POWER_SOURCE_BM 0x04
// CI_RX_ON_WHEN_IDLE_BM 0x08
// CI_SECURITY_CAPABILITY_BM 0x40
// CI_ALLOCATE_ADDRESS_BM 0x80
// BOOL securityUse
// An indication of whether the received MAC command frame is using security. This value set to
// TRUE if the security enable subfield was set to 1 or FALSE if the security enabled subfield
// was set to 0
//
// UINT8 aclEntry
// The macSecurityMode parameter value from the ACL entry associated with the sender of the
// data frame. This value is set to 0x08 if the sender of the data frame was not found in the
// ACL.
//
//-------------------------------------------------------------------------------------------------------
void mlmeAssociateIndication(ADDRESS deviceAddress, BYTE capabilityInformation, BOOL securityUse, UINT8 aclEntry)
{
WORD dev_short_address;
char s[64];
dev_short_address = DEV_SHORT + g_Device_Num; // Decide the Short Address of the Device
g_Device_Num++; // Increment the number of the Device
mlmeAssociateResponse(&deviceAddress, dev_short_address, 0x00, FALSE); // Set the Short Address of the Device
g_AssocIndication = TRUE;
}
//-------------------------------------------------------------------------------------------------------
// void mlmeAssociateConfirm(WORD assocShortAddress, MAC_ENUM status)
//
// DESCRIPTION:
// mlmeAssociateConfirm is generated by the MAC layer when an association attempt has succeeded or
// failed (initiated by mlmeAssociateRequest(...)).
// Function must be implemented by the higher layer
//
// PARAMETERS:
// WORD assocShortAddress
// The short device address allocated by the coordinator on successful association. This
// parameter will be equal to 0xFFFF if the association attempt was unsuccessful.
// MAC_ENUM status
// The status of the association attempt (SUCCESS, CHANNEL_ACCESS_FAILURE, NO_DATA, etc.)
//-------------------------------------------------------------------------------------------------------
void mlmeAssociateConfirm(WORD assocShortAddress, MAC_ENUM status)
{
if (status == SUCCESS) {
g_myShortAddr = assocShortAddress; // Setting of my Address (when Device)
}
}
//-------------------------------------------------------------------------------------------------------
// 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.
// Function must be implemented by the higher layer
//
// PARAMETERS:
// MLME_BEACON_NOTIFY_INDICATION *pMBNI
// Pointer to the MLME_BEACON_NOTIFY_INDICATION beacon notification struct
//-------------------------------------------------------------------------------------------------------
void mlmeBeaconNotifyIndication(MLME_BEACON_NOTIFY_INDICATION *pMBNI) {}
//-------------------------------------------------------------------------------------------------------
// void mlmeCommStatusIndication(WORD panId, BYTE srcAddrMode, ADDRESS *pSrcAddr, BYTE dstAddrMode, ...
//
// DESCRIPTION:
// The mlmeCommStatusIndication callback is called by the MAC sublayer
// either following a transmission instigated through a .response primitive or on receipt of a
// frame that generates an error in its secure processing.
//
// Function must be implemented by the higher layer
//
// PARAMETERS:
// WORD panId
// The 16 bit PAN identifier of the device from which the frame was received or to
// which the frame was being sent.
// BYTE srcAddrMode
// Source address mode
// ADDRESS *pSrcAddr
// Source address pointer
// BYTE dstAddrMode
// Destination address mode
// ADDRESS *pDstAddr
// Destination address pointer
// MAC_ENUM status
// Status enumeration
// (SUCCESS | TRANSACTION_OVERFLOW | TRANSACTION_EXPIRED | CHANNEL_ACCESS_FAILURE | NO_ACK |
// UNAVAILABLE_KEY | FRAME_TOO_LONG | FAILED_SECURITY_CHECK | INVALID_PARAMETER)
//-------------------------------------------------------------------------------------------------------
void mlmeCommStatusIndication(WORD panId, BYTE srcAddrMode, ADDRESS *pSrcAddr, BYTE dstAddrMode, ADDRESS *pDstAddr, BYTE status) {}
//-------------------------------------------------------------------------------------------------------
// void mlmeDisassociateIndication(QWORD deviceAddress, BYTE disassociateReason, BOOL securityUse, ...
//
// DESCRIPTION:
// Callback generated by the MAC sublayer to the higher layer upon reception of a
// disassociation notification command frame
// Function must be implemented by the higher layer of a FFD device
//
// PARAMETERS:
// QWORD deviceAddress
// Extended address of the device requesting disassociation
// BYTE disassociateReason
// The disassociate reason (COORD_WISHES_DEVICE_TO_LEAVE | DEVICE_WISHES_TO_LEAVE)
// BOOL securityUse
// Security enabled for the incoming frame?
// UINT8 aclEntry
// The macSecurityMode parameter value from the ACL entry associated with the sender of
// the data frame. This value is set to 0x08 if the sender of the data frame was not
// found in the ACL.
//-------------------------------------------------------------------------------------------------------
void mlmeDisassociateIndication(QWORD deviceAddress, BYTE disassociateReason, BOOL securityUse, BOOL aclEntry) {}
//-------------------------------------------------------------------------------------------------------
// void mlmeDisassociateConfirm(MAC_ENUM status)
//
// DESCRIPTION:
// Callback generated by the MAC sublayer to the higher layer upon completion of a
// mlmeDisassociateRequest(...) call from the higher layer.
// Function must be implemented by the higher layer.
//
// PARAMETERS:
// MAC_ENUM status
// Status returned by the callback
// (SUCCESS | TRANSACTION_OVERFLOW | TRANSACTION_EXPIRED | NO_ACK |
// CHANNEL_ACCESS_FAILURE | UNAVAILABLE_KEY | FAILED_SECURITY_CHECK |
// INVALID_PARAMETER)
//-------------------------------------------------------------------------------------------------------
void mlmeDisassociateConfirm(MAC_ENUM status) {}
//-------------------------------------------------------------------------------------------------------
// void mlmeOrphanIndication(QWORD orphanAddress, BOOL securityUse, UINT8 aclEntry)
//
// DESCRIPTION:
// Callback generated by the MAC sublayer to the higher layer upon reception of a
// orphan notification command frame
// Function must be implemented by the higher layer of a FFD device
//
// PARAMETERS:
// QWORD orphanAddress
// Extended address of the device notifying its orphan state
// BOOL securityUse
// Security enabled for the incoming frame?
// UINT8 aclEntry
// The macSecurityMode parameter value from the ACL entry associated with the sender of
// the data frame. This value is set to 0x08 if the sender of the data frame was not
// found in the ACL.
//-------------------------------------------------------------------------------------------------------
void mlmeOrphanIndication(QWORD orphanAddress, BOOL securityUse, BOOL aclEntry) {}
//-------------------------------------------------------------------------------------------------------
// void mlmeDisassociateConfirm(MAC_ENUM status)
//
// DESCRIPTION:
// Callback generated by the MAC sublayer to the higher layer upon completion of a
// mlmePollRequest(...) call from the higher layer.
// Function must be implemented by the higher layer.
//
// PARAMETERS:
// MAC_ENUM status
// Status returned by the callback
// (SUCCESS | CHANNEL_ACCESS_FAILURE | NO_ACK | NO_DATA | UNAVAILABLE_KEY |
// FAILED_SECURITY_CHECK | INVALID_PARAMETER)
//-------------------------------------------------------------------------------------------------------
void mlmePollConfirm(MAC_ENUM status) {}
//-------------------------------------------------------------------------------------------------------
// void mlmeRxEnableConfirm(MAC_ENUM status)
//
// DESCRIPTION:
// Callback generated by the MAC sublayer to the higher layer upon completion of a
// mlmeRxEnableRequest(...) call from the higher layer.
// Function must be implemented by the higher layer.
//
// PARAMETERS:
// MAC_ENUM status
// Status returned by the callback
// (SUCCESS | TX_ACTIVE | OUT_OF_CAP | INVALID_PARAMETER)
//-------------------------------------------------------------------------------------------------------
void mlmeRxEnableConfirm(MAC_ENUM status) {}
//-------------------------------------------------------------------------------------------------------
// void mlmeSyncLossIndication(MAC_ENUM lossReason)
//
// DESCRIPTION:
// Callback generated by the MAC sublayer to the higher layer indicating the loss of
// synchronization with a coordinator, PAN Id conflicts or realignment.
//
// Function must be implemented by the higher layer.
//
// PARAMETERS:
// MAC_ENUM status
// Status generated by the callback
// (PAN_ID_CONFLICT | REALIGNMENT | BEACON_LOST)
//-------------------------------------------------------------------------------------------------------
void mlmeSyncLossIndication(MAC_ENUM lossReason) {}
//-------------------------------------------------------------------------------------------------------
// DESCRIPTION:
// The MAC layer is ready when the mpmSetConfirm callback is generated by the MAC sublayer
void mpmSetConfirm(BYTE status) {}
//-------------------------------------------------------------------------------------------------------
// void mcpsDataConfirm(MAC_ENUM status, BYTE msduHandle)
//
// DESCRIPTION:
// MAC callback to the higher layer upon complete processing of a mcpsDataRequest
// Function must be implemented by the higher layer
//
// PARAMETERS:
// MAC_ENUM status
// (SUCCESS | TRANSACTION_OVERFLOW | TRANSACTION_EXPIRED | CHANNEL_ACCESS_FAILURE
// INVALID_GTS | NO_ACK | UNAVAILABLE_KEY | FRAME_TOO_LONG | FAILED_SECURITY_CHECK)
// BYTE msduHandle,
// A handle to this packet from the mcpsDataRequest() function
//-------------------------------------------------------------------------------------------------------
void mcpsDataConfirm(MAC_ENUM status, BYTE msduHandle)
{
g_DataStatus = status;
g_DataConfirm = TRUE; // in this program, this function is used only for end-device.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -