JN RM 2002 802.15.4 Stack API 1v7
JN RM 2002 802.15.4 Stack API 1v7
JN-RM-2002
Revision 1.7
10-Jan-2007
Jennic
Disclaimer
The contents of this document are subject to change without notice. Customers are advised to consult with JENNIC commercial representatives before
ordering.
The information and circuit diagrams in this document are presented as examples of semiconductor device applications, and are not intended for
incorporation in devices for actual use. In addition, JENNIC is unable to assume responsibility for infringement of any patent rights or other rights of
third parties arising from the use of this information or circuit diagrams.
No license is granted by its implication or otherwise under any patent or patent rights of JENNIC Ltd
“Typical” parameters, which are provided in this document, may vary in different applications and performance may vary over time. All operating
parameters must be validated for each customer application by the customer’s own technical experts.
CAUTION:
Customers considering the use of our products in special applications where failure or abnormal
operation may directly affect human lives or cause physical injury or property damage, or where
extremely high levels of reliability are demanded (such as aerospace systems, atomic energy
controls, vehicle operating controls, medical devices for life support, etc.) are requested to
consult with JENNIC representatives before such use. JENNIC customers using or selling
products incorporating JENNIC IP for use in such applications do so at their own risk and agree
to fully indemnify JENNIC for any damages resulting from such improper use or sale.
Organisation
This manual consists of four chapters and an appendix:
• Chapter 1 defines the scope of the manual.
• Chapter 2 describes the implementation of the API.
• Chapter 3 describes in detail the MAC-Network Layer Interface.
• Chapter 4 outlines the MAC/PHY features.
• Appendix A describes how to identify modules and devices.
Conventions
Code fragments, function prototypes or filenames are represented by Courier typeface. When
referring to constants or functions defined in the code they are emboldened like so.
MAC User
Response
Request
Confirm
Indication
MAC Layer
A Request transaction is initiated by the MAC User and may solicit a Confirm. An Indication
transaction is initiated by the MAC Layer and may solicit a Response.
As this is purely a reference model, a specific implementation needs to be built upon the
reference model. This section describes the implementation based on the reference model.
Request Indication
Confirm Response
Request Indication
Confirm Response
Call Callback
(return) (return)
Note that the two threads of execution do not necessarily have to be the same, but the key point
is that the call/callback is executed in the thread of execution of the caller of the function.
2.2 Implementation
Based on the above, an implementation can be formed which satisfies all cases of blocking and
non-blocking operations for the primitives based on a call/callback interface. This is illustrated
as follows:
Application MAC Library Application MAC Library
Request Request
Synchronous (return)
Confirm
Deferred Confirm Hardware Event
(return)
Request/Confirm processing
Indication/Response processing
This section describes the interface between the Network layer and the MAC layer. The figure
provides an overview of the functions making up this interface.
Network Layer
vAppApiMlmeRequest
vAppApiMcpsRequest
u32AppApiInit
McpsGetBuffer
MlmeGetBuffer
MlmeCallback
McpsCallback
eAppApiPlmeGet
eAppApiPlmeSet
MLME MCPS
MAC Layer
partial PLME
PHY Layer
The following sections first describe the functions allowing requests from the Network layer to
the MAC layer and then the (callback) functions allowing the MAC layer to request the Network
layer to allocate buffer space and to pass information back to the Network layer.
Outputs None
Description Routine used to pass MLME requests from the NWK layer or Application to the
MAC.
The psMlmeReqRsp parameter is a pointer to a structure holding the request to the
MLME. The structure is of type MAC_MlmeReqRsp_s, defined below
/**
* MLME Request/Response
*
* The object passed to vAppApiMlmeRequest containing
* the request
*/
typedef struct
{
uint8 u8Type;
uint8 u8ParamLength;
uint16 u16Pad;
MAC_MlmeReqRspParam_u uParam;
} MAC_MlmeReqRsp_s;
The structure consists of 4 fields. The first, u8Type defines the type of request or
response that the structure carries; values carried in this field are defined in the
enumeration MAC_MlmeReqType_e shown below:
/* Enumeration of MAC MLME Request/Response
* Must not exceed 256 entries
*/
typedef enum
{
MAC_MLME_REQ_ASSOCIATE = 0,
MAC_MLME_REQ_DISASSOCIATE,
MAC_MLME_REQ_GET,
MAC_MLME_REQ_GTS,
MAC_MLME_REQ_RESET,
MAC_MLME_REQ_RX_ENABLE,
MAC_MLME_REQ_SCAN,
MAC_MLME_REQ_SET,
MAC_MLME_REQ_START,
MAC_MLME_REQ_SYNC,
MAC_MLME_REQ_POLL,
MAC_MLME_RSP_ASSOCIATE,
MAC_MLME_RSP_ORPHAN,
The second field u8ParamLength carries the size in bytes of the parameter
associated with the request. The parameter has a maximum size of 255 bytes
The third field ensures proper alignment of the fourth field.
The fourth field uParam is of type MAC_MlmeReqRspParam_u, a union of all the
data structures associated with the requests listed in MAC_MlmeReqRspType_e
The union is defined as follows:
/* MLME Request/Response Parameter union
* Union of all the possible MLME Requests and Responses,
* also including the vendor-specific requests
*/
union
{
/* MLME Requests */
MAC_MlmeReqAssociate_s sReqAssociate;
MAC_MlmeReqDisassociate_s sReqDisassociate;
MAC_MlmeReqGet_s sReqGet;
MAC_MlmeReqGts_s sReqGts;
MAC_MlmeReqReset_s sReqReset;
MAC_MlmeReqRxEnable_s sReqRxEnable;
MAC_MlmeReqScan_s sReqScan;
MAC_MlmeReqSet_s sReqSet;
MAC_MlmeReqStart_s sReqStart;
MAC_MlmeReqSync_s sReqSync;
MAC_MlmeReqPoll_s sReqPoll;
/* MLME Responses */
MAC_MlmeRspAssociate_s sRspAssociate;
MAC_MlmeRspOrphan_s sRspOrphan;
} MAC_MlmeReqRspParam_u;
The individual data structures that make up the union will be dealt with in more
detail in the section on MAC and PHY features, which explains the operations that
the higher layer can request using this interface.
The psMlmeSyncCfm parameter is a pointer to a structure holding the results of the
MLME request (the confirm), generated if the request executes synchronously (ie
returns with the results immediately, rather than the results being posted as a
deferred confirm some time later). If the MLME request is one that generates a
deferred confirm, a synchronous confirm is still generated but with a status of
MAC_MLME_CFM_DEFERRED (see below).
The first field carries the status of the request which caused the confirm, and the
values it may take are defined by the enumeration MAC_MlmeSyncCfmStatus_e
/* Synchronous confirm status
*
* Indicates in the synchronous confirm whether:
* (1) The request was processed without error
* (2) The request was processed with errors
* (3) The confirm will be deferred and posted via the
* Deferred Confirm/Indication callback
* (4) It is a dummy confirm to a Response.
* Note: must not exceed 256 entries
*/
typedef enum
{
MAC_MLME_CFM_OK,
MAC_MLME_CFM_ERROR,
MAC_MLME_CFM_DEFERRED,
MAC_MLME_CFM_NOT_APPLICABLE,
NUM_MAC_MLME_CFM /* (endstop) */
} MAC_MlmeSyncCfmStatus_e;
The second field u8ParamLength carries the size in bytes of the parameter
associated with the confirm. The parameter has a maximum size of 255 bytes
The third field ensures proper alignment of the fourth field.
The fourth field uParam is of type MAC_MlmeSyncCfmParam_u, a union of all the
data structures associated with the confirms that can come back from requests to
the MLME, including vendor-specific requests
Examples of using the call and setting up the parameters and interpreting the
results will be given throughout the remainder of the document.
Outputs None
Description Routine used to pass MCPS requests from the NWK layer or Application to the
MAC.
The psMcpsReqRsp parameter is a pointer to a structure holding the request to the
MCPS. The structure is of type MAC_MlmeReqRsp_s, defined below
/* MCPS Request/Response object
*
* The object passed to vAppApiMcpsRequest containing the
* request/response
*/
typedef struct
{
uint8 u8Type;
uint8 u8ParamLength;
uint16 u16Pad;
MAC_McpsReqRspParam_u uParam;
} MAC_McpsReqRsp_s;
The structure consists of 4 fields. The first, u8Type defines the type of request or
response that the structure carries; values carried in this field are defined in the
enumeration MAC_McpsReqRspType_e shown below:
/* MAC MCPS Request/Response enumeration.
* Note must not exceed 256 entries
*/
typedef enum
{
MAC_MCPS_REQ_DATA = 0,
MAC_MCPS_REQ_PURGE,
NUM_MAC_MCPS_REQ /* (endstop) */
} MAC_McpsReqRspType_e;
The second field u8ParamLength carries the size in bytes of the parameter
associated with the request. The parameter has a maximum size of 255 bytes
The third field ensures proper alignment of the fourth field.
The fourth field uParam is of type MAC_McpsReqRspParam_u, a union of all the data
structures associated with the requests listed in MAC_McpsReqRspType_e
The union is defined as follows:
/* MCPS Request/Response Parameter union
The individual data structures, which make up the union, will be dealt with in more
detail in the section on MAC and PHY features, which explains the operations that
the NWK layer or Application can request using this interface.
The psMcpsSyncCfm parameter is a pointer to a structure holding the results of the
MCPS request (the confirm), generated if the request executes synchronously (i.e.
returns with the results immediately, rather than the results being posted as a
deferred confirm some time later).
The structure is of type MAC_McpsSyncCfm_s defined below
/**
* MCPS Synchronous Confirm
* The object returned by vAppApiMcpsRequest containing
* the synchronous confirm.
* The confirm type is implied as corresponding to the
* request
* All Confirms may also be sent asynchronously via the
* registered Deferred Confirm/Indication callback;
* this is notified by returning MAC_MCPS_CFM_DEFERRED.
*/
typedef struct
{
uint8 u8Status;
uint8 u8ParamLength;
uint16 u16Pad;
MAC_McpsSyncCfmParam_u uParam;
} MAC_McpsSyncCfm_s;
The first field carries the status of the request which caused the confirm, and the
values it may take are defined by the enumeration MAC_McpsSyncCfmStatus_e
The second field u8ParamLength carries the size in bytes of the parameter
associated with the confirm. The parameter has a maximum size of 255 bytes.
The third field ensures proper alignment of the fourth field.
The fourth field uParam is of type MAC_McpsSyncCfmParam_u, a union of all the
data structures associated with the confirms that can come back from requests to
the MCPS, including vendor-specific requests
The union is defined as follows:
/* MCPS Synchronous Confirm Parameter union
*
* Union of all the possible MCPS Synchronous Confirms
*/
typedef union
{
MAC_McpsCfmData_s sCfmData;
MAC_McpsCfmPurge_s sCfmPurge;
} MAC_McpsSyncCfmParam_u;
Examples of using the call and setting up the parameters and interpreting the
results will be given throughout the remainder of the document.
Outputs uint32 0 if initialisation failed, otherwise a 32-bit version number (most significant
16 bits are main revision, least significant 16 bits are minor revision)
Description This routine registers five functions provided by the network layer, which are used
by the MAC and the Integrated Peripherals API to communicate with the network
layer.
Parameter 1: prMlmeGetBuffer
This is a routine that must provide a pointer to a buffer of type
MAC_DcfmIndHdr_s, which can be used by the MAC to send the results of
deferred (asynchronous) confirms as the result of a previous MLME Requests.
The same routine will also be called by the MAC to provide space to send
information to the network layer in the form of MLME Indications triggered by
hardware events.
which implements some form of buffer management which can return a pointer to
a buffer of type MAC_DcfmIndHdr_s. At its simplest, this could be to return the
address of a variable of this type known by the network layer, e.g.
PRIVATE MAC_DcfmIndHdr_s sAppBuffer;
PRIVATE MAC_DcfmIndHdr_s *
psMlmeDcfmIndGetBuf(void *pvParam)
{
/* Return a handle to a MLME buffer */
return &sAppBuffer;
}
The routine expects always to successfully send the buffer it received from the
network layer, which is not unreasonable, since the network layer is in charge of
allocating the buffer in the first place. If the implementation is done in such a way
that this might not be the case, the Send routine will have no way of signalling that
it could not send the buffer up to the network layer. It is the responsibility of the
network layer to provide sufficient buffers to be allocated to avoid losing confirms
or indications
The pvParam parameter is provided as a pointer which can be used to carry
further information between the MAC and network layer or vice versa when
performing an MLME Get or Post, and contains pvMlmeParam, the third parameter
to u32AppApiInit. This can be used for any purpose by the network layer and
has no meaning to the MAC.
In the example, the interface between the MAC and network layer is a queue with
enough entries to contain all the buffer pointers from a buffer pool managed by the
network layer for the MLME confirm/indications. The Post routine places the
buffer pointer on the queue and then signals the network layer that there is
something there to process. This is all happening in the MAC thread of execution,
which for a simple system will be in the interrupt context. At some stage the MAC
thread will stop running and the network layer thread will continue; in this case it
regularly polls the input queue and processes any entries it finds, before returning
the buffer back to the buffer pool.
Parameter 3: pvMlmeParam
This is the value passed in calls to the above MLME routines.
Parameter 4: prMcpsGetBuffer
This routine has the same functionality as prMlmeGetBuffer, but is used to obtain
a buffer for use with MCPS, rather than MLME, deferred confirmations or
indications. The parameter passed with the call is pvMcpsParam.
Parameter 5: prMcpsCallback
This routine has the same functionality as prMlmeCallback, but is used to post a
buffer containing a MCPS, rather than MLME, deferred confirmation or indication.
The parameter passed with the call is pvMcpsParam.
Parameter 6: pvMcpsParam
This is the value passed in calls to the above MCPS routines.
Inputs None
Outputs None
Description This function is used to enable the MAC to save settings in RAM before entering
sleep mode with memory held up.
Inputs None
Outputs None
Description This function is used when the device wakes up - it restores the MAC to the state
that it was in before the device entered sleep mode.
Currently, this feature is only suitable for use in networks that do not use regular
beacons, as it does not include a facility to resynchronise.
/* At start of file */
#include "AppApi.h"
#include "mac_pib.h"
Once the handle is obtained, PIB attributes can be read directly, e.g.
bMyAssociationPermit = psPib->bAssociationPermit;
Most of the PIB attributes can also be written using the PIB handle:
psPib->bAssociationPermit = bMyAssociationPermit;
e.g.:
MAC_vPibSetShortAddr(pvMac, 0x1234);
psPib->u8BeaconOrder = 5;
The following is an example of reading the coordinator short address from the PIB.
uint16 u16CoordShortAddr;
u16CoordShortAddr = psPib->u16CoordShortAddr;
The following is an example of writing to one of the variables within an access control list entry.
Pre-defined values are available for these PHY PIB attributes, as specified in the following table:
Attribute Values
PHY_PIB_ATTR_CURRENT_CHANNEL PHY_PIB_CURRENT_CHANNEL_DEF (default - 11)
PHY_PIB_CURRENT_CHANNEL_MIN (minimum - 11)
PHY_PIB_CURRENT_CHANNEL_MAX (maximum - 26)
PHY_PIB_ATTR_CHANNELS_SUPPORTED PHY_PIB_CHANNELS_SUPPORTED_DEF (default - 0x07fff800)
PHY_PIB_ATTR_TX_POWER PHY_PIB_TX_POWER_DEF (default - 0x40)
PHY_PIB_TX_POWER_MIN (minimum - 0)
PHY_PIB_TX_POWER_MAX (maximum - 0xbf)
PHY_PIB_TX_POWER_MASK (0x3f)
{mask to be used with dB settings below}
PHY_PIB_TX_POWER_1DB_TOLERANCE (0x00)
PHY_PIB_TX_POWER_3DB_TOLERANCE (0x40)
PHY_PIB_TX_POWER_6DB_TOLERANCE (0x80)
PHY_PIB_ATTR_CCA_MODE PHY_PIB_CCA_MODE_DEF (default - 1)
PHY_PIB_CCA_MODE_MIN (minimum - 1)
PHY_PIB_CCA_MODE_MAX (maximum - 3)
Both the Get and Set operations return a PHY_Enum_e enumeration status value to indicate
success or failure of the operation. This enumeration is defined in Table 16 (section 6.3.6) of the
802.15.4 specification (d18). Refer to the specification for the definitions.
Name Value Description
PHY_ENUM_INVALID_PARAMETER 0x05 A SET/GET request was issued with a parameter in the
primitive that is outside the valid range.
PHY_ENUM_SUCCESS 0x07 A SET/GET operation was successful.
PHY_ENUM_UNSUPPORTED_ATTRIBUTE 0x0A A SET/GET request was issued with the identifier of an
attribute that is not supported.
Outputs PHY_Enum_e Enumeration status value that indicates success or failure of the
operation.
Description This routine can be used to retrieve the current value of one of the PHY PIB
attributes.
If the routine returns PHY_ENUM_SUCCESS, the value of the PIB PHY attribute
retrieved has been copied into the location pointed to by pu32PhyPibValue.
4.2.2.2.1 Example
The following example illustrates how to read the current channel:
uint32 u32sChannel;
if (eAppApiPlmeGet (PHY_PIB_ATTR_CURRENT_CHANNEL,&u32sChannel)
== PHY_ENUM_SUCCESS)
{
printf("Channel is %d\n", u32Channel);
}
Outputs PHY_Enum_e Enumeration status value that indicates success or failure of the
operation.
Description This routine can be used to change the value of one of the PHY PIB parameters.
If the routine returns PHY_ENUM_SUCCESS, the value of the PIB PHY
parameter has been changed to u32PhyPibValue.
4.2.2.3.1 Examples
The following example illustrates how to set the current channel:
if (eAppApiPlmeSet(PHY_PIB_ATTR_CURRENT_CHANNEL, u8Channel) !=
PHY_ENUM_SUCCESS)
{
// Handle error;
}
The following example illustrates how to set the transmit power to 0 dBm:
if (eAppApiPlmeSet(PHY_PIB_ATTR_TX_POWER, 0) != PHY_ENUM_SUCCESS)
{
// Handle error;
}
The field u8SetDefaultPib controls whether the PIB contents are to be reset to their default
values. When set to TRUE the PIB is reset.
The confirm is generated synchronously and contains the following structure giving the result of
the reset request
/* Structure for MLME-RESET.confirm
*
*/
typedef struct
{
uint8 u8Status;
} MAC_MlmeCfmReset_s;
The status field of the confirm may take the values MAC_ENUM_SUCCESS indicating that the reset
took place, or MAC_ENUM_DISABLE_TRX_FAILURE which shows that the transmitter or receiver of
the node could not be turned off.
/* Request Reset */
sMlmeReqRsp.u8Type = MAC_MLME_REQ_RESET;
sMlmeReqRsp.u8ParamLength = sizeof(MAC_MlmeReqReset_s);
sMlmeReqRsp.uParam.sReqReset.u8SetDefaultPib = TRUE; /* Reset PIB */
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
sCoord is a structure, which holds the MAC address of the coordinator, which transmitted the
beacon. It consists of the following fields:
u8AddrMode denotes the type of addressing used to specify the address of the coordinator and
may take the following values:
Addressing mode value Description
0 PAN identifier and address field are not present
1 Reserved
2 Address field contains 16-bit short address
3 Address field contains 64-bit extended address
If u8AddrMode is non-zero then the following fields contain the PAN identifier and either the
short or the extended address of the coordinator sending the beacon
u16PanId is a the PAN identifier
uAddr is a union, which may contain either the 16-bit short address or the 64-bit extended
address
typedef union
{
uint16 u16Short; /* Short address */
MAC_ExtAddr_s sExt; /* Extended address */
} MAC_Addr_u;
u8LogicalChan holds the channel number on which the beacon was transmitted. For the
2.45GHz PHY this field may take the values 11 to 26 corresponding to the allowed channel
numbers for the radio.
u8GtsPermit is set to 1 if the beacon is from a PAN coordinator, which accepts GTS
(Guaranteed Time Slot) requests.
u8LinkQuality carries a measure of the quality of the transmission which carried the beacon
ranging from 0 to 255, 0 representing low quality.
u8SecurityUse is set to 1 if the beacon is using security, 0 otherwise.
u8AclEntry contains the value of the security mode in use by the sender of the beacon, as
retrieved from the ACL entry corresponding to the beacon sender and may take the values 0 to
7 denoting the security suite in use. If the sender is not found in the ACL this value is set to 8.
u8SecurityFailure is set to 1 if there was an error during the security processing of the
beacon, 0 otherwise. Always 0 if u8SecurityUse is 0.
u16SuperframeSpec contains information about the superframe used in the PAN that this
beacon describes. It follows the same format as that specified in section 7.2.2.1.2 of ref [1].
u32TimeStamp indicates the time that the beacon was received, measured in symbol periods.
sDeviceAddr contains the full 64-bit extended address of the orphaned node.
u8SecurityUse indicates if security was being used when the orphan notification was sent (set
to 1 if this is true).
u8AclEntry is the security mode (values o to 7) being used by the node transmitting the orphan
notification as stored in the coordinators ACL for that address. If the orphan node cannot be
found in the ACL the value is set to 8.
sOrphanAddr carries the full 64-bit extended address of the orphan node, as carried in the
Orphan Indication.
u16OrphanShortAddr holds the 16-bit short address that the orphan node used within the PAN
if it was previously associated, and should continue to use. If the node was not previously
associated with the coordinator, the value 0xFFFF is returned. If the node is not to use a short
address, then the value 0xFFFE is returned in this field.
u8Associated if set to 1 indicates that the node was previously associated with this
coordinator.
u8SecurityEnable should be set to 1 if the orphan node is to use security processing on its
communication with the coordinator, or 0 otherwise.
On receiving this response, if the orphan was previously associated with the coordinator, the
MAC will send a coordinator realignment command to the orphan. The result of sending this
command will be to generate a MLME-COMM-STATUS.indication from the MAC to the
Application/NWK layer. See section 4.4.9 Comm Status Indication for the usage of this
primitive.
sSrcAddr and sDstAddr contain the addresses of the source and destination of the frame, their
formats being shown below
u8AddrMode denotes the type of addressing used to specify the address and may take the
following values:
Addressing mode value Description
0 No address – address field uAddr omitted
1 Reserved
2 Address field contains 16-bit short address
3 Address field contains 64-bit extended address
uAddr is a union which can contain either a 64-bit extended address or a 16-bit short address.
u16PanId is the PAN id of the network.
u8Status is the result of the transaction whose status is being reported, and takes on values
from the enumeration MAC_enum_e. In the case of an Orphan Response the possible results
are
Status Reason
MAC_ENUM_UNAVAILABLE_KEY couldn’t find a security key in the ACL for the
transmission
MAC_ENUM_FAILED_SECURITY_CHECK failure during security processing of the frame
MAC_ENUM_CHANNEL_ACCESS_FAILURE couldn’t get access to the radio channel to
perform the transmission
MAC_ENUM_NO_ACK didn’t get an acknowledgement from the
orphan node after sending the coordinator
realignment command
MAC_ENUM_INVALID_PARAMETER invalid parameter value or parameter not
supported in the Orphan Response
MAC_ENUM_SUCCESS coordinator realignment command sent
successfully
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
The following is an example of handling a deferred active scan confirmation (assumes data is
passed as a pointer to a deferred confirm indicator data type i.e. MAC_MlmeDcfmInd_s
*psMlmeInd.)
MAC_PanDescr_s *psPanDesc;
int i;
if (psMlmeInd->u8Type == MAC_MLME_DCFM_SCAN)
{
if ((psMlmeInd->uParam.sDcfmScan.u8Status == MAC_ENUM_SUCCESS)
&& (psMlmeInd->uParam.sDcfmScan.u8ScanType ==
MAC_MLME_SCAN_TYPE_ACTIVE))
{
/* Determine which, if any, network contains demo coordinator.
Algorithm for determining which network to connect to is
beyond the scope of 802.15.4, and we use a simple approach
of matching the required PAN ID and short address, both of
which we already know */
i = 0;
while (i < psMlmeInd->uParam.sDcfmScan.u8ResultListSize)
{
psPanDesc = &psMlmeInd->uParam.sDcfmScan.uList.asPanDescr[i];
sMlmeReqRsp.uParam.sReqScan.u8ScanType =
MAC_MLME_SCAN_TYPE_ENERGY_DETECT;
sMlmeReqRsp.uParam.sReqScan.u32ScanChannels = ALL_CHANNELS_BITMAP;
sMlmeReqRsp.uParam.sReqScan.u8ScanDuration = 6;
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
int i;
uint8 u8ClearestChan, u8MinEnergy;
uint8 *pu8EnergyDetectList;
if (psMlmeInd->u8Type == MAC_MLME_DCFM_SCAN)
{
/* Check that this response is the result of a
successful energy detect scan */
if ((psMlmeInd->uParam.sDcfmScan.u8Status == MAC_ENUM_SUCCESS)
&& (psMlmeInd->uParam.sDcfmScan.u8ScanType ==
MAC_MLME_SCAN_TYPE_ENERGY_DETECT))
{
u8MinEnergy = 0xff;
u8ClearestChan = 11;
pu8EnergyDetectList =
4.5 Start
The MAC supports the PAN start feature as defined in ref [1] section 7.1.14 and 7.5.2.
The Start feature is used by a FFD to begin acting as the coordinator of a new PAN or to begin
transmitting beacons when associated with a PAN. A PAN should only be started after an
Active Scan has been performed in order to find which PAN identifiers are currently in use. A
PAN is started using the MLME-START.request primitive.
u16PanId contains the 16-bit PAN identifier as selected by the Application/NWK layer.
u8Channel carries the logical channel number (11 to 26 for 2.45 GHz PHY) on which the
beacon will be transmitted.
Value Reason
MAC_ENUM_NO_SHORT_ADDRESS The PIB value for the short address is set to
0xFFFF
MAC_ENUM_UNAVAILABLE_KEY The u8SecurityEnable field of the request is
set o TRUE but the key and security
information for the broadcast address cannot
be obtained from the ACL in the PIB
MAC_ENUM_FRAME_TOO_LONG The security encoding process on a beacon
results in a beacon which is longer than the
maximum MAC frame size
MAC_ENUM_FAILED_SECURITY_CHECK For any other reason than the above that
security processing fails
MAC_ENUM_INVALID_PARAMETER For any parameter out of range or not
supported
MAC_ENUM_SUCCESS Start primitive was successful
4.5.3 Examples
The following is an example of a typical start request.
#define DEMO_PAN_ID 0x1234
/* Start beacons */
sMlmeReqRsp.u8Type = MAC_MLME_REQ_START;
sMlmeReqRsp.u8ParamLength = sizeof(MAC_MlmeReqStart_s);
sMlmeReqRsp.uParam.sReqStart.u16PanId = DEMO_PAN_ID;
sMlmeReqRsp.uParam.sReqStart.u8Channel = 11;
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
u8Channel contains the logical channel on which the MAC will use to try to find beacon
transmissions. For the 2.45 GHz PHY this field will take on values of 11 to 26
u8TrackBeacon is set to TRUE if the device is to continue tracking beacon transmissions
following reception of the first beacon. Set to FALSE otherwise.
u8Reason is the reason for the loss of synchronisation and takes a value from the MAC_enum_e
enumeration
Value Reason
MAC_ENUM_PAN_ID_CONFLICT Generated when a device detects a PAN id
conflict
MAC_ENUM_REALIGNMENT A coordinator realignment command was
received and the device is not performing an
Orphan Scan
MAC_ENUM_BEACON_LOST Failed to see MAC_MAX_LOST_BEACONS
consecutive beacons either when tracking
transmissions or searching for beacons after a
Sync request
sPANdescriptor holds the information about the PAN that the beacon carries. This structure
has already been described in PAN descriptor.
u8BSN contains the Beacon Sequence Number, which can take the value 0 to 255.
u8PendAddrSpec consists of a byte, which encodes the number of nodes, which have
messages pending at the coordinator, which generated the beacon. There are at most seven
nodes which can be shown as having messages stored at the coordinator although there may
be more messages actually stored. The Address Specification may contain a mixture of short
and extended addresses, up to the total of 7. It is encoded as follows:
u8SDUlength contains the length in bytes of the beacon payload field, up to a maximum of
MAC_MAX_BEACON_PAYLOAD_LEN
uAddrList contains an array of seven short or extended addresses corresponding to the
numbers in u8PendAddrSpec. The addresses are ordered so that all the short addresses are
listed first (ie starting from index 0) followed by the extended addresses. The specification for
the union, which holds a short or extended address, has already been described in
MAC_addr_u
u8SDU is an array of MAC_MAX_BEACON_PAYLOAD_LEN bytes, which contains the beacon
payload. The contents of the beacon payload are specified at the Application/NWK layer.
sCoord contains the address of the coordinator to poll for data. The data structure in use has
been described before in MAC_addr_s, and holds the PANid and either the 16-bit short address
of the coordinator or its 64-bit extended address.
u8SecurityEnable if set to TRUE causes security processing to be applied to the data request
frame which is sent to the coordinator. The coordinator address is used to look up the security
information from the ACL in the PIB.
u8Status takes on a value from the MAC_enum_e enumeration type to indicate the status of the
corresponding Poll request. The following values may be returned:
Value Reason
MAC_ENUM_UNAVAILABLE_KEY The security settings corresponding to the
coordinator address are not found in the PIB
ACL
MAC_ENUM_FAILED_SECURITY_CHECK Security processing of the data request
command fails for some other reason
MAC_ENUM_CHANNEL_ACCESS_FAILURE The data request command cannot be sent
due to the CSMA algorithm failing
MAC_ENUM_NO_ACK No acknowledge frame is received for the data
request command after the coordinator has
tried to send the acknowledgement
MAC_MAX_FRAME_RETRIES (3) times
MAC_ENUM_NO_DATA No data is pending at the coordinator, or a
data frame is not received within a timeout
period after an acknowledge to the data
request command is received, or a data frame
with zero length payload is received
MAC_ENUM_INVALID_PARAMETER A parameter in the Poll request is out of range
or not supported
MAC_ENUM_SUCCESS A data frame with non-zero payload length is
received after the acknowledge of the data
request command.
If the Poll confirm has status MAC_ENUM_SUCCESS to show that data is available, the data will be
indicated to the Application/NWK layer using a MCPS-DATA.indication primitive.
4.6.6 Examples
The following is an example of a beacon synchronisation request.
uint8 au8Payload[MAC_MAX_BEACON_PAYLOAD_LEN];
int i;
if (psMlmeInd->u8Type == MAC_MLME_IND_BEACON_NOTIFY)
{
for (i = 0; i < psMlmeInd->uParam.sIndBeacon.u8SDUlength; i++))
{
/* Store beacon payload */
au8Payload[i] = psMlmeInd->uParam.sIndBeacon.u8SDU[i];
}
}
The following is an example of using a poll request to check if the coordinator has any data
pending for the device. It is assumed that u16CoordShortAddr has been previously
initialised.
4.7 Association
The MAC supports the Association feature as defined in ref [1] section 7.1.3 and 7.5.3
This feature allows a device to join a PAN and have pending data queued at the PAN
coordinator. Before it can associate to a PAN however it must first find one. It should perform a
MLME-Reset.request before performing either an Active or a Passive Scan using MLME-
Scan.request, which will generate a list of PANs which have been found. The Application/NWK
layer can then choose with which PAN it wishes to associate. At this point a MLME-
Associate.request primitive is issued by the Application/NWK layer, which results in an
Association request command being sent from the device to the coordinator. This frame
command is acknowledged by the coordinator. After a time period has elapsed the device MAC
sends a data request command to the coordinator to extract the result of the association. The
coordinator acknowledges this command and is followed by an association response command
from the coordinator which carries the status of the association attempt. On receiving the
sCoord contains the address of the PAN coordinator to associate with. The data structure in
use has been described before in MAC_addr_s, and holds the PANid and either the 16-bit short
address of the coordinator or its 64-bit extended address.
u8LogicalChan contains the channel number (11 to 26 for the 2.45 GHz PHY) which the PAN
to be associated with occupies
u8Capability is a byte encoded with the following information:
Bit 0 1 2 3 4-5 6 7
Alternate Device Power Receiver Reserved Security Allocate
PAN Type Source on when capability address
coordinator idle
Alternate PAN coordinator – set to 1 if the device is capable of becoming a PAN coordinator.
Device Type – set to 1 if the device is an FFD, or 0 if an RFD.
Power Source – set to 1 if the device is mains powered, 0 otherwise.
Receiver on when idle – set to 1 if the device leaves its receiver on during idle periods and does
not save power.
Security capability – set to 1 if the device can send and received frames using security.
Allocate address – set to 1 if the device requires the coordinator to provide a short address
during the association procedure. If set to 0 the short address 0xFFFE is allocated in the
u8Status holds the status of the operation, and takes on values from MAC_Enum_e
Value Reason
MAC_ENUM_UNAVAILABLE_KEY The security settings corresponding to the
coordinator address were not found in the PIB
ACL
MAC_ENUM_FAILED_SECURITY_CHECK Security processing of the association request
command fails for some other reason
MAC_ENUM_CHANNEL_ACCESS_FAILURE The association request command cannot be
sent due to the CSMA algorithm failing
MAC_ENUM_NO_ACK No acknowledge frame is received for the
association request command after the
coordinator has tried to send the
acknowledgement
MAC_MAX_FRAME_RETRIES (3) times
MAC_ENUM_NO_DATA No association response command was
received within a timeout period after an
acknowledge to the association request
command is received
MAC_ENUM_INVALID_PARAMETER A parameter in the Association request is out
of range or not supported
0x01 PAN is full
0x02 Access to the PAN denied by the coordinator
MAC_ENUM_SUCCESS The association request was successful
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
The following is an example of a device handling an associate confirm event (it stores the short
address assigned to it by the coordinator in variable u16ShortAddr). Assumes data is passed
as a pointer to a deferred confirm indicator data type i.e. MAC_MlmeDcfmInd_s *psMlmeInd.
if (psMlmeInd->u8Type == MAC_MLME_DCFM_ASSOCIATE)
{
if (psMlmeInd->uParam.sDcfmAssociate.u8Status == MAC_ENUM_SUCCESS)
{
/* Store short address */
u16ShortAddr = psMlmeInd->
uParam.sDcfmAssociate.u16AssocShortAddr;
}
}
tsDemoData sDemoData;
uint16 u16ShortAddress;
uint32 u32AddrLo;
uint32 u32AddrHi;
uint8 u8Node;
uint8 u8AssocStatus;
if (psMlmeInd->u8Type == MAC_MLME_IND_ASSOCIATE)
{
/* Default short address */
u16ShortAddress = 0xffff;
u32AddrLo = psMlmeInd->
uParam.sIndAssociate.sDeviceAddr.u32L);
u32AddrHi = psMlmeInd->
uParam.sIndAssociate.sDeviceAddr.u32H);
if ((u32AddrHi == DEMO_EXT_ADDR_HI)
&& (u32AddrLo >= DEMO_ENDPOINT_EXT_ADDR_LO_BASE)
&& (u32AddrLo < (DEMO_ENDPOINT_EXT_ADDR_LO_BASE
+ DEMO_ENDPOINTS))
&& (psMlmeInd->uParam.sIndAssociate.u8Capability & 0x80))
{
/* Check if already associated (idiot proofing) */
u8Node = 0;
while (u8Node < sDemoData.sNode.u8AssociatedNodes)
{
if ((u32AddrHi ==
sDemoData.sNode.asAssocNodes[u8Node].u32ExtAddrHi)
&& (u32AddrLo ==
sDemoData.sNode.asAssocNodes[u8Node].u32ExtAddrLo))
{
/*Already in system: give it same short address*/
u16ShortAddress =
sDemoData.sNode.asAssocNodes[u8Node].u16ShortAddr;
}
u8Node++;
}
if (u16ShortAddress == 0xffff)
sDemoData.sNode.asAssocNodes
[sDemoData.sNode.u8AssociatedNodes].u32ExtAddrLo
= u32AddrLo;
sDemoData.sNode.asAssocNodes
[sDemoData.sNode.u8AssociatedNodes].u16ShortAddr
= u16ShortAddress;
sDemoData.sNode.u8AssociatedNodes++;
}
else
{
/* PAN access denied */
u8AssocStatus = 2;
}
}
}
else
{
/* PAN access denied */
u8AssocStatus = 2;
}
sAddr contains the address of the recipient of the disassociation request – device or coordinator
address (format described in 4.4.9 Comm Status Indication)
u8Reason holds the reason for the disassociation being requested:
Status Reason
MAC_ENUM_UNAVAILABLE_KEY Couldn’t find a security key in the ACL for the
transmission
MAC_ENUM_FAILED_SECURITY_CHECK Failure during security processing of the frame
MAC_ENUM_TRANSACTION_OVERFLOW No room available to store the disassociation
notification command on the coordinator -
when coordinator requests disassociation
MAC_ENUM_TRANSACTION_EXPIRED Disassociation notification command was not
retrieved by the intended device in the timeout
period and has been discarded (coordinator
requested disassociation)
MAC_ENUM_CHANNEL_ACCESS_FAILURE Couldn’t get access to the radio channel to
perform the transmission of the disassociate
notification command
MAC_ENUM_NO_ACK No acknowledgement from the associating
device after sending the disassociate
notification command
MAC_ENUM_INVALID_PARAMETER Invalid parameter value or parameter not
supported in the Disassociate Request
primitive
MAC_ENUM_SUCCESS Disassociate request completed successfully
sDeviceAddr contains the 64-bit extended address of the device, which generated the
disassociation request
u8Reason contains the reason for the disassociation as described in 4.8.1 Disassociate
Request
u8SecurityUse TRUE if security is being used during the transmission
u8AclEntry contains the security mode held in the ACL entry of the PIB for the device. If an
ACL entry for the device cannot be found this value is set to 0x08. The security mode values
are described in Scan confirm
4.8.4 Examples
The following is an example of a request to disassociate a device from a PAN
vAppApiMlmeRequest(&sMlmeReqRsp, &sMlmeSyncCfm);
u8Handle identifies the transmission allowing more than one transmission to be performed
before the corresponding confirm has been seen. It may take the values 0 to 0xFF; the handle
is generated by the Application/NWK layer.
sFrame contains the data frame to be sent by this request and has the following format:
typedef struct
{
MAC_Addr_s sSrcAddr; /* Source address */
MAC_Addr_s sDstAddr; /* Destination address */
uint8 u8TxOptions; /* Transmit options */
uint8 u8SduLength; /* Length of payload (MSDU) */
uint8 au8Sdu[MAC_MAX_DATA_PAYLOAD_LEN];
/* Payload (MSDU) */
} MAC_TxFrameData_s;
The above bits are set to 1 to invoke the option. A GTS Transmission overrides an Indirect
Transmission option. The indirect transmission option is only valid for a coordinator generated
data request; for a non-coordinator device the option is ignored. If the Security option is set the
ACL corresponding to the destination address is searched and the keys etc used to apply
security to the data frame to be sent.
u8Handle contains the handle of the MCPS-DATA.request whose status is being reported
u8Status carries the result of the MCPS-DATA.request. It may take the following values
Status Reason
MAC_ENUM_UNAVAILABLE_KEY Couldn’t find a security key in the ACL for the
transmission
MAC_ENUM_FAILED_SECURITY_CHECK Failure during security processing of the frame
MAC_ENUM_FRAME_TOO_LONG The size of the frame after security processing
is greater than the maximum size that can be
transmitted, or the transmission is too long to
fit in the CAP or GTS period
MAC_ENUM_INVALID_GTS No Guaranteed Time Slot allocated for this
destination
MAC_ENUM_TRANSACTION_OVERFLOW No room available to store the data when an
indirect transmission is specified in the Tx
Options when a coordinator requests the
transmission
MAC_ENUM_TRANSACTION_EXPIRED Disassociation notification command was not
retrieved by the intended device in the timeout
period and has been discarded (coordinator
requested disassociation)
MAC_ENUM_CHANNEL_ACCESS_FAILURE Couldn’t get access to the radio channel to
perform the transmission of the data frame
MAC_ENUM_NO_ACK No acknowledgement from the destination
device after sending the data frame with the
acknowledge option set
MAC_ENUM_INVALID_PARAMETER Invalid parameter value or parameter not
supported in the Data Request primitive
sSrcAddr holds the source address and sDstAddr holds the and destination addresses – both
of which may be short (16-bit) or extended (64-bit) format together with the PAN identifier of
each address. The details of this structure are described in 4.9.1 Data Request.
u8LinkQuality contains a value between 0 and 0xFF which gives the quality of the reception
of the received frame.
u8SecurityUse indicates if security was used in transmitting the data.
u8AclEntry indicates the security suite used during the transmission, as retrieved from the ACL
for the source address held in the PIB. The encoding of this field is given in Security_modes.
u8SduLength contains the length of the payload in bytes.
au8Sdu is the array of bytes containing the payload of the transmission.
u8Handle contains the handle of the Data Request to be removed from the transaction queue
u8Handle holds the handle of the transaction specified in the Purge Request
u8Status contains the result of the attempt to remove the data from the transaction queue. It
takes on values from the enumeration MAC_enum_e.
Status Reason
MAC_ENUM_INVALID_HANDLE Could not find a transaction with a handle
matching that of the purge request
MAC_ENUM_SUCCESS Purge request completed successfully
uint8 *pu8Payload;
/* Request transmit */
vAppApiMcpsRequest(&sMcpsReqRsp, &sMcpsSyncCfm);
The following is an example of handling the data indication event that is generated by the MAC
layer of a coordinator when data is received. The variable u16DeviceAddr contains the short
address of the device from which we want to receive data. Assumes data is passed as a
pointer to a deferred confirm indicator data type i.e. MAC_McpsDcfmInd_s *psMcpsInd.
MAC_RxFrameData_s *psFrame;
MAC_Addr_s *psAddr;
uint16 u16NodeAddr;
au8DeviceData[8];
if (psMcpsInd->u8Type == MAC_MCPS_IND_DATA)
{
psFrame = &psMcpsInd->uParam.sIndData.sFrame;
psAddr = &psFrame->sAddrPair.sSrc;
The following is an example of a request to purge a data frame from the transaction queue. The
variable u8PurgeItemHandle defines which item is to be purged and is set by a higher layer.
/* Request transmit */
vAppApiMcpsRequest(&sMcpsReqRsp, &sMcpsSyncCfm);
The following is an example of handling a purge confirm event. Assumes data is passed as a
pointer to a deferred confirm indicator data type i.e. MAC_McpsDcfmInd_s *psMcpsInd.
if (psMcpsInd->u8Type == MAC_MCPS_DCFM_PURGE)
{
if (psMcpsInd->uParam.sCfmPurge.u8Status != MAC_ENUM_SUCCESS)
{
/* Purge request failed */
}
}
4.10 Rx Enable
The MAC supports the Receiver Enable feature as defined in ref [1] section 7.1.10
This feature allows a device to control when its receiver will be enabled or disabled, and for how
long. On beacon-enabled PANs the timings are relative to superframe boundaries; on non-
beacon-enabled PANs the receiver is enabled immediately.
u32RxOnTime is a 32-bit quantity specifying the number of symbols after the start of the
superframe that the receiver should be enabled
u32RxOnDuration is a 32-bit quantity specifying the number of symbols that the receiver should
remain enabled. If equal to 0, the receiver is disabled.
u8DeferPermit set to TRUE if the enable period is to be allowed to start in the next full
superframe period if the requested on time has already passed in the current superframe.
A new Rx Enable Request must be generated for each attempt to enable the receiver
u8Status contains the result of the Rx Enable Request, taking on values from MAC_enum_e
Status Reason
MAC_ENUM_INVALID_PARAMETER The combination of start time and duration
requested will not fit inside the superframe
(only relevant for a beacon enabled PAN)
MAC_ENUM_OUT_OF_CAP The start time requested has passed and the
receive is not allowed to be deferred to the
next superframe period or the requested
duration will not fit in the current CAP (only
relevant for a beacon enabled PAN)
MAC_ENUM_TX_ACTIVE The receiver cannot be enabled because the
transmitter is active
MAC_ENUM_SUCCESS Rx Enable request completed successfully
4.10.3 Examples
The following is an example of an receiver enable request.
/* Handle response */
if (sMlmeSyncCfm.u8Status != MAC_ENUM_SUCCESS)
{
/* Receiver not enabled */
}
u8Status contains the result of the GTS request using the MAC_enum_e enumeration.
u8Characteristics carries the characteristics of the GTS that has been allocated as encoded
in 4.11.1 GTS Request. If a GTS has been deallocated the characteristics type field is set
to 0.
u16ShortAddr contains the 16-bit short address of the device to which the GTS has been
allocated or deallocated, with value between 0 and 0xFFFD
4.11.4 Examples
The following is an example of a device making a GTS request to a PAN co-ordinator:
uint8 u8Characteristics = 0;
sMlmeReqRsp.uParam.MAC_MlmeReqGts_s.u8Characteristics =
u8Characteristics;
if (psMlmeInd->u8Type == MAC_MLME_DCFM_GTS)
{
if (psMlmeInd->uParam.MAC_MlmeCfmGts_s.u8Status == MAC_ENUM_SUCCESS)
{
/* GTS allocated successfully, store characteristics */
u8Characteristics = psMlmeInd->
uParam.MAC_MlmeCfmGts_s.u8Characteristics;
u8GtsLength = (u8Characteristics & MAC_GTS_LENGTH_MASK);
u8GtsDirection = (u8Characteristics & MAC_GTS_DIRECTION_MASK) >>
MAC_GTS_DIRECTION_BIT;
u8GtsType = (u8Characteristics & MAC_GTS_TYPE_MASK) >>
MAC_GTS_TYPE_BIT;
}
}
The following example shows a coordinator handling a GTS indication event (generated by the
MAC layer whenever following reception of a GTS request command from a device). Assumes
data is passed as a pointer to a deferred confirm indicator data type i.e. MAC_MlmeDcfmInd_s
*psMlmeInd.
if (psMlmeInd->u8Type == MAC_MLME_IND_GTS)
{
/* determine whether allocation or de-allocation has occurred */
u8Characteristics = psMlmeInd->
uParam.MAC_MlmeIndGts_s.u8Characteristics;
u8GtsType = (u8Characteristics & MAC_GTS_TYPE_MASK) >>
MAC_GTS_TYPE_BIT;
if (u8GtsType == MAC_GTS_TYPE_DEALLOC)
{
/* handle de-allocation of GTS */
}
else
{
/* handle allocation of GTS */
}
}
Identifying modules
All modules mounted on Sensor and Controller boards found in Evaluation, Starter or Expansion
kits have a barcode label easily visible, stuck over the JN5121/JN513x or shielding can. The
labels on modules with a screening can have a 10-digit batch and serial number below the
barcode. The first 4 digits are the batch code. Labels on modules without a screening can have
a 4-digit batch code above the barcode.
The batch code shows the week of manufacture of the module. It ends in either 05 or 06 for the
year of manufacture; the first two digits represent the week number starting from January 1st
(week 01) in the year. So batch code 1006 would be week 10 2006. The batch code shows
which version of the JN5121 or JN513x is used on the module. For a module with a screening
can a typical batch and serial number would be 0906300180, showing it was built in week 9 of
2006
Modules with batch codes later than 1006 contain the MAC in ROM, those with earlier codes
require the MAC library to be built into the program and downloaded to the flash memory.
Devices supplied directly (i.e. NOT mounted on modules) can be identified by a 4-digit date
code. Chip labelling is in the following format:
The date code is in the form YYWW (year number followed by week number). Devices with date
codes of 0607 or later have the MAC in ROM. Those with earlier codes require the MAC library
to be built into the program and downloaded to the Flash memory.
Jennic is a fabless semiconductor company leading the wireless connectivity revolution into new
applications. Jennic combines expertise in systems and software with world class RF and digital chip
design to provide low cost, highly integrated silicon solutions for its customers and partners.
Headquartered in Sheffield, UK, Jennic is privately held and has a proven track record of successful
silicon chip development.
Jennic
TECHNOLOGY FOR A CHANGING WORLD
Jennic Ltd.
Furnival Street, Sheffield, S1 4QT, UK
Tel: +44 (0) 114 281 2655 Fax: +44 (0) 114 281 2951
Email: [email protected] Web: www.jennic.com