📄 zep.c
字号:
/*
* "Copyright (c) 2006 Robert B. Reese ("AUTHOR")"
* All rights reserved.
* (R. Reese, reese@ece.msstate.edu, Mississippi State University)
* IN NO EVENT SHALL THE "AUTHOR" BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHOR"
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE "AUTHOR" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE "AUTHOR" HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*
* This file makes use of Zigbee Alliance intellectual property in the
* form of frame formats as specified in the Zigbee 1.0 standard.
* The author consulted the
* Zigbee standard when writing this file, and agreed to the terms
* of conditions by the Zibee Alliance when downloading the standard.
* As such, use of this file is governed by the Zigbee Trademarks,
* Designations, and Logos policy. A paraphrase of this policy is
* that free usage is granted for research, educational or personal
* use. Commercial usage is restricted, see the policy for details.
*
* Please maintain this header in its entirety when copying/modifying
* these files.
*
* Files in this software distribution may have different usage
* permissions, see the header in each file. Some files have NO permission
* headers since parts of the original sources in these files
* came from vendor sources with no usage restrictions.
*
*/
/*
V0.1 Initial Release 10/July/2006 RBR
*/
/*
Handles messages for the Zero Endpoint
*/
#include "compiler.h" //compiler specific
#include "lrwpan_common_types.h"
#include "lrwpan_config.h"
#include "ieee_lrwpan_defs.h"
#include "hal.h"
#include "console.h"
#include "debug.h"
#include "phy.h"
#include "mac.h"
#include "nwk.h"
#include "aps.h"
#include "zep.h"
#include "neighbor.h"
ZEP_STATE_ENUM zepState;
//locals
#ifdef LRWPAN_COORDINATOR
static void zepHandleEndDeviceAnnounce(void);
#endif
void zepInit(void){
zepState = ZEP_STATE_IDLE;
}
void zepFSM(void) {
switch (zepState) {
case ZEP_STATE_IDLE:
break;
//in this state, we have received an RX for the ZEP. Handle it
case ZEP_STATE_RX_START:
switch (a_aps_rx_data.cluster) {
//only the true coordinator handles this
#ifdef LRWPAN_COORDINATOR
case ZEP_END_DEVICE_ANNOUNCE:
zepHandleEndDeviceAnnounce();
usrZepRxCallback();
zepState = ZEP_STATE_IDLE;
break;
#endif
default:
DEBUG_STRING(DBG_INFO,"Unhandled Zero Endpoint Command, discarding.\n");
zepState = ZEP_STATE_IDLE;
}
break;
}
}
//sends an empty payload, only want to get the APS ACK back
//as verification that this was delivered
void zepFmtPing(void) {
a_aps_tx_data.usrPlen = 0;
a_aps_tx_data.usrPload = (BYTE *) NULL;
//now, the rest
a_aps_tx_data.srcEP = 0; //from endpoint 0
a_aps_tx_data.tsn = apsGenTSN();
a_aps_tx_data.cluster = ZEP_PING;
a_aps_tx_data.dstMode = APS_DSTMODE_SHORT;
a_aps_tx_data.dstSADDR = mac_pib.macCoordShortAddress; //send to our parent
a_aps_tx_data.dstEP = 0; //to endpoint 0
a_aps_tx_data.srcSADDR = macGetShortAddr();
a_aps_tx_data.af_fcf = (1 | AF_FRM_TYPE_MSG);
//use an ACK so that we know if this succeeds
a_aps_tx_data.aps_fcf = APS_FRM_TYPE_DATA | APS_FRM_DLVRMODE_NORMAL | APS_FRM_ACKREQ_MASK;
}
#ifdef LRWPAN_COORDINATOR
//an End Device has sent us its short address, long address information.
//put this in the address map.
static void zepHandleEndDeviceAnnounce(void){
BYTE *ptr;
SADDR saddr;
if (aplGetRxMsgLen() != 10) return; // wrong message length.
ptr = aplGetRxMsgData(); //get pointer to data
//parse the message.
saddr = *ptr;
ptr++;
saddr += (((UINT16)*ptr) << 8);
ptr++;
//enter this into the map
ntNewAddressMapEntry(ptr, saddr);
}
#endif
//put our long address, short address into the tmpTxBuffer
//so that it can be sent to the coordinator.
void zepFmtEndDeviceAnnounce(void){
BYTE *ptr;
//first, do the payload
ptr = &tmpTxBuff[LRWPAN_MAX_FRAME_SIZE] - 8;
//copy in the long address
halGetProcessorIEEEAddress(ptr);
//now put our short address
--ptr;
*ptr = (BYTE) (macGetShortAddr()>>8);
--ptr;
*ptr = (BYTE) (macGetShortAddr());
a_aps_tx_data.usrPlen = 10;
//now, the rest
a_aps_tx_data.srcEP = 0; //from endpoint 0
a_aps_tx_data.tsn = apsGenTSN();
a_aps_tx_data.cluster = ZEP_END_DEVICE_ANNOUNCE;
a_aps_tx_data.dstMode = APS_DSTMODE_SHORT;
a_aps_tx_data.dstSADDR = 0; //send to coordinator
a_aps_tx_data.dstEP = 0; //to endpoint 0
a_aps_tx_data.srcSADDR = macGetShortAddr();
a_aps_tx_data.af_fcf = (1 | AF_FRM_TYPE_MSG);
//use an ACK so that we know if this succeeds
a_aps_tx_data.aps_fcf = APS_FRM_TYPE_DATA | APS_FRM_DLVRMODE_NORMAL | APS_FRM_ACKREQ_MASK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -