// Copyright (c) 2001-2008, Scalable Network Technologies, Inc. All Rights Reserved.
// 6701 Center Drive West
// Suite 520
// Los Angeles, CA 90045
// sales@scalable-networks.com
//
// This source code is licensed, not sold, and is subject to a written
// license agreement. Among other things, no portion of this source
// code may be copied, transmitted, disclosed, displayed, distributed,
// translated, used as the basis for a derivative work, or used, in
// whole or in part, for any program or purpose other than its intended
// use in compliance with the license agreement as part of the QualNet
// software. This source code and certain of the algorithms contained
// within it are confidential trade secrets of Scalable Network
// Technologies, Inc. and may not be used as the basis for any other
// software, hardware, product or service.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "api.h"
#include "partition.h"
#include "network_ip.h"
#include "list.h"
#include "mac.h"
#include "mac_802_15_4.h"
#define DEBUG 0
#define DEBUG_TIMER 0
//Forward declarations
static
void Mac802_15_4mlme_scan_request(
Node* node,
int interfaceIndex,
UInt8 ScanType,
UInt32 ScanChannels,
UInt8 ScanDuration,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mlme_start_request(
Node* node,
int interfaceIndex,
UInt16 PANId,
UInt8 LogicalChannel,
UInt8 BeaconOrder,
UInt8 SuperframeOrder,
BOOL PANCoordinator,
BOOL BatteryLifeExtension,
BOOL CoordRealignment,
BOOL SecurityEnable,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mlme_associate_request(
Node* node,
int interfaceIndex,
UInt8 LogicalChannel,
UInt8 CoordAddrMode,
UInt16 CoordPANId,
MACADDR CoordAddress,
UInt8 CapabilityInformation,
BOOL SecurityEnable,
BOOL frUpper,
PhyStatusType status,
M802_15_4_enum mStatus);
static
void Mac802_15_4mlme_associate_response(
Node* node,
int interfaceIndex,
MACADDR DeviceAddress,
UInt16 AssocShortAddress,
M802_15_4_enum Status,
BOOL SecurityEnable,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mlme_orphan_response(
Node* node,
int interfaceIndex,
MACADDR OrphanAddress,
UInt16 ShortAddress,
BOOL AssociatedMember,
BOOL SecurityEnable,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mlme_disassociate_request(
Node* node,
int interfaceIndex,
MACADDR DeviceAddress,
UInt8 DisassociateReason,
BOOL SecurityEnable,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mlme_sync_request(
Node* node,
int interfaceIndex,
UInt8 LogicalChannel,
BOOL TrackBeacon,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mlme_poll_request(
Node* node,
int interfaceIndex,
UInt8 CoordAddrMode,
UInt16 CoordPANId,
MACADDR CoordAddress,
BOOL SecurityEnable,
BOOL autoRequest,
BOOL firstTime,
PhyStatusType status);
static
void Mac802_15_4mlme_reset_request(
Node* node,
int interfaceIndex,
BOOL SetDefaultPIB,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mlme_rx_enable_request(
Node* node,
int interfaceIndex,
BOOL DeferPermit,
UInt32 RxOnTime,
UInt32 RxOnDuration,
BOOL frUpper,
PhyStatusType status);
static
void Mac802_15_4mcps_data_request(
Node* node,
int interfaceIndex,
UInt8 SrcAddrMode,
UInt16 SrcPANId,
MACADDR SrcAddr,
UInt8 DstAddrMode,
UInt16 DstPANId,
MACADDR DstAddr,
UInt8 msduLength,
Message* msdu,
UInt8 msduHandle,
UInt8 TxOptions,
BOOL frUpper,
PhyStatusType status,
M802_15_4_enum mStatus);
static
void Mac802_15_4CsmacaResume(Node* node, int interfaceIndex);
static
void Mac802_15_4TxBcnCmdDataHandler(Node* node, int interfaceIndex);
// /**
// FUNCTION :: MAC_VariableHWAddressToTwoByteMacAddress
// LAYER :: MAC
// PURPOSE :: Retrieve IP address from.MacHWAddress of type
// HW_NODE_ID
// PARAMETERS ::
// + node : Node* : Pointer to Node structure
// + macAddr : MacHWAddress* : Pointer to hardware address structure
// RETURN :: NodeAddress : Ipv4 Address
// **/
static
MACADDR MAC_VariableHWAddressToTwoByteMacAddress (
Node* node,
MacHWAddress* macAddr)
{
if(macAddr->hwLength != MAC_NODEID_LINKADDRESS_LENGTH ||
macAddr->hwType == HW_TYPE_UNKNOWN)
{
return 0;
}
if (MAC_IsBroadcastHWAddress(macAddr))
{
return (MACADDR)ANY_DEST;
}
else
{
MACADDR nodeAddress;
memcpy(&nodeAddress, macAddr->byte, MAC_NODEID_LINKADDRESS_LENGTH);
return nodeAddress;
}
}
// /**
// FUNCTION :: ConvertVariableHWAddressToMacAddr
// LAYER :: MAC
// PURPOSE :: Convert Variable Hardware address to ZigBee MACADDR
// PARAMETERS ::
// + node : Node* : Pointer to Node structure
// + macHWAddr : MacHWAddress* : Pointer to hardware address structure
// + macAddr : MACADDR* : Pointer to ZigBee MAC address structure
// RETURN :: Bool :
// **/
static
BOOL ConvertVariableHWAddressToMacAddr(
Node *node,
MacHWAddress* macHWAddr,
MACADDR* macAddr)
{
if(macHWAddr->hwLength == MAC_NODEID_LINKADDRESS_LENGTH){
memcpy(macAddr, macHWAddr->byte, macHWAddr->hwLength);
return TRUE;
}
else
return FALSE;
}
// /**
// FUNCTION :: ConvertMacAddrToVariableHWAddress
// LAYER :: MAC
// PURPOSE :: Convert ZigBee Mac addtess to Variable Hardware address
// PARAMETERS ::
// + node : Node* : Pointer to Node structure
// + macHWAddr : MacHWAddress* : Pointer to hardware address structure
// + macAddr : MACADDR* : Pointer to mac 802 address structure
// RETURN :: Bool :
// **/
static
void ConvertMacAddrToVariableHWAddress (
Node *node,
MacHWAddress* macHWAddr,
MACADDR* macAddr)
{
macHWAddr->hwLength = MAC_NODEID_LINKADDRESS_LENGTH;
macHWAddr->hwType = HW_NODE_ID;
(*macHWAddr).byte = (unsigned char*) MEM_malloc(
sizeof(unsigned char)*MAC_NODEID_LINKADDRESS_LENGTH);
memcpy(macHWAddr->byte, macAddr, MAC_NODEID_LINKADDRESS_LENGTH);
}
// /**
// FUNCTION :: MAC802_15_4IPv4AddressToHWAddress
// LAYER :: MAC
// PURPOSE :: Convert IPv4 addtess to Hardware address
// PARAMETERS ::
// + node : Node* : Pointer to Node structure
// + ipv4Address : NodeAddress : IPv4 address
// + macAddr : MacHWAddress* : Pointer to Hardware address structure
// RETURN :: void :
// **/
void MAC802_15_4IPv4AddressToHWAddress(
Node *node,
NodeAddress ipv4Address,
MacHWAddress* macAddr)
{
MACADDR nodeId = (MACADDR)
MAPPING_GetNodeIdFromInterfaceAddress(
node,
ipv4Address);
ConvertMacAddrToVariableHWAddress(node, macAddr, &nodeId);
}
// /**
// FUNCTION :: Phy802_15_4PLME_CCA_request
// LAYER :: MAC
// PURPOSE :: To initiate Channel clear access request
// PARAMETERS ::
// + node : Node* : Pointer to node
// + interfaceIndex : int : Interface index
// RETURN :: None
// **/
void Phy802_15_4PLME_CCA_request(Node* node, int interfaceIndex)
{
BOOL isChannelFree;
PhyStatusType sta
qualnet之zigbee模型
5星 · 超过95%的资源 需积分: 9 146 浏览量
2009-01-07
15:55:23
上传
评论 1
收藏 84KB RAR 举报
taiyuancity
- 粉丝: 0
- 资源: 1