📄 sscs_802_15_4.cpp
字号:
printf("%lld : Node %d: 802.15.4SSCS : " "No Coordinator found for association\n", getSimTime(node), node->nodeId); } Sscs802_15_4SetTimer(node, interfaceIndex, S802_15_4ASSORETRY, S802_15_4ASSORETRY_INTERVAL); return; } else { //If the coordinator is in beacon-enabled mode, we may begin //to track beacons now. //But this is only possible if the network is a one-hop star; // otherwise we don't know //which coordinator to track, since there may be more than // one beaconing coordinators //in a device's neighborhood and MLME-SYNC.request() has no // parameter telling which //coordinator to track. As this is an optional step, we will // not track beacons here. t_mpib.macAssociationPermit = assoPermit; Mac802_15_4MLME_SET_request(node, interfaceIndex, macAssociationPermit, &t_mpib); if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : Sending " "association request to Coordinator %d on " "channel %d with PAN Id %d\n", getSimTime(node), node->nodeId, sscs802_15_4->T_PANDescriptorList[i].CoordPANId, ch, sscs802_15_4-> T_PANDescriptorList[i].CoordAddress_64); } sscs802_15_4->state = S802_15_4ASSOREQ; sscs802_15_4->startDevice_panDes = sscs802_15_4->T_PANDescriptorList[i]; Mac802_15_4MLME_ASSOCIATE_request( node, interfaceIndex, ch, sscs802_15_4->T_PANDescriptorList[i].CoordAddrMode, sscs802_15_4->T_PANDescriptorList[i].CoordPANId, sscs802_15_4->T_PANDescriptorList[i].CoordAddress_64, mac->capability.cap, FALSE); } break; } case S802_15_4ASSOREQ: { sfSpec.SuperSpec = sscs802_15_4->startDevice_panDes.SuperframeSpec; Mac802_15_4SuperFrameParse(&sfSpec); if (sfSpec.BO != 15) { strcpy(tmpstr, "beacon enabled"); } else { strcpy(tmpstr, "non-beacon enabled"); } if (status != M802_15_4_SUCCESS) { //reset association permission t_mpib.macAssociationPermit = FALSE; Mac802_15_4MLME_SET_request( node, interfaceIndex, macAssociationPermit, &t_mpib); sscs802_15_4->state = S802_15_4NULL; if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : Association " "failed on channel %d, PAN Id %d, Coordinator " "%d (%s) -> %s\n", getSimTime(node), node->nodeId, sscs802_15_4->startDevice_panDes.LogicalChannel, sscs802_15_4->startDevice_panDes.CoordPANId, sscs802_15_4->startDevice_panDes.CoordAddress_64, tmpstr, Sscs802_15_4StatusName(status)); } Sscs802_15_4SetTimer(node, interfaceIndex, S802_15_4ASSORETRY, S802_15_4ASSORETRY_INTERVAL); } else { sscs802_15_4->neverAsso = FALSE; if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : Association " "successful on channel %d, PAN Id %d, " "Coordinator %d\n", getSimTime(node), node->nodeId, sscs802_15_4->startDevice_panDes.LogicalChannel, sscs802_15_4->startDevice_panDes.CoordPANId, sscs802_15_4->startDevice_panDes.CoordAddress_64 ); } if (sscs802_15_4->t_BO != 15 && sscs802_15_4->pollInt && mac->macBeaconOrder2 == 15) { Sscs802_15_4SetTimer (node, interfaceIndex, S802_15_4POLLINT, sscs802_15_4->pollInt + (RANDOM_nrand(sscs802_15_4->seed) % (1 * SECOND))); } if (sfSpec.BO != 15) { if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : Begin to " "synchronize with the coordinator\n", getSimTime(node), node->nodeId); } Mac802_15_4MLME_SYNC_request( node, interfaceIndex, sscs802_15_4->startDevice_panDes.LogicalChannel, TRUE); } if (sscs802_15_4->t_isFFD && sscs802_15_4->ffdMode < 2 && sscs802_15_4->t_BO < 15) { mac->isCoor = TRUE; sscs802_15_4->state = S802_15_4STARTREQ; if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : Begin to " "transmit beacons\n", getSimTime(node), node->nodeId); } Mac802_15_4MLME_START_request( node, interfaceIndex, mac->mpib.macPANId, sscs802_15_4->startDevice_Channel, sscs802_15_4->t_BO, sscs802_15_4->t_SO, FALSE, FALSE, FALSE, FALSE); } else { sscs802_15_4->state = S802_15_4UP; } } break; } case S802_15_4STARTREQ: { if (status == M802_15_4_SUCCESS) { if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : Successfully " "transmitted beacons on " "channel %d with PAN Id %d\n", getSimTime(node), node->nodeId, sscs802_15_4->startDevice_Channel, mac->mpib.macPANId); } sscs802_15_4->state = S802_15_4UP; } else { if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : Failed to " "transmit beacons on channel %d with PAN Id %d " "-> %s\n", getSimTime(node), node->nodeId, sscs802_15_4->startDevice_Channel, mac->mpib.macPANId, Sscs802_15_4StatusName(status)); } sscs802_15_4->state = S802_15_4NULL; } break; } default: { break; } }}// /**// FUNCTION :: Sscs802_15_4StopDevice// LAYER :: SSCS// PURPOSE :: Stops a Device// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// + status : M802_15_4_enum: Status of request// RETURN :: None// **/staticvoid Sscs802_15_4StopDevice( Node* node, int interfaceIndex, M802_15_4_enum status){ MacData802_15_4* mac; SscsData802_15_4* sscs802_15_4; mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar; sscs802_15_4 = (SscsData802_15_4*)mac->sscs; if(sscs802_15_4->state != S802_15_4UP && sscs802_15_4->state != S802_15_4DISASSOREQ) { if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : " "Device not associated with a coordinator\n", getSimTime(node), node->nodeId); } return; } switch(sscs802_15_4->state) { case S802_15_4UP: { sscs802_15_4->state = S802_15_4DISASSOREQ; Mac802_15_4MLME_DISASSOCIATE_request( node, interfaceIndex, mac->mpib.macCoordExtendedAddress, 0x02, //device wishes to leave FALSE); //reset the device Mac802_15_4MLME_RESET_request( node, interfaceIndex, TRUE); break; } case S802_15_4DISASSOREQ: { sscs802_15_4->state = S802_15_4NULL; if(DEBUG) { printf("%lld : Node %d: 802.15.4SSCS : " "Device disassociated from PAN\n", getSimTime(node), node->nodeId); } break; } }}// /**// FUNCTION :: Ssc802_15_4PollRequest// LAYER :: SSCS// PURPOSE :: Perform polling// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// RETURN :: None// **/staticvoid Sscs802_15_4PollRequest(Node* node, int interfaceIndex){ MacData802_15_4* mac; SscsData802_15_4* sscs802_15_4; mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar; sscs802_15_4 = (SscsData802_15_4*)mac->sscs; if(Sscs802_15_4IsDeviceUp(node, interfaceIndex)) { Mac802_15_4MLME_POLL_request( node, interfaceIndex, M802_15_4DEFFRMCTRL_ADDRMODE64, mac->mpib.macPANId, mac->mpib.macCoordExtendedAddress, FALSE); } if ((sscs802_15_4->t_BO != 15 && sscs802_15_4->pollInt && mac->macBeaconOrder2 == 15) || (sscs802_15_4->t_BO == 15 && sscs802_15_4->pollInt)) { Sscs802_15_4SetTimer ( node, interfaceIndex, S802_15_4POLLINT, sscs802_15_4->pollInt); } else if(mac->taskP.mlme_poll_request_STEP) { mac->taskP.mlme_poll_request_STEP = 0; }}//--------------------------------------------------------------------------// API functions between SSCS and MAC//--------------------------------------------------------------------------// /**// FUNCTION :: Sscs802_15_4IsDeviceUp// LAYER :: SSCS// PURPOSE :: Primitive to find out whether the device is up or not.// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// RETURN :: BOOL// **/BOOL Sscs802_15_4IsDeviceUp( Node* node, int interfaceIndex){ MacData802_15_4* mac; SscsData802_15_4* sscs802_15_4; mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar; sscs802_15_4 = (SscsData802_15_4*)mac->sscs; if(sscs802_15_4->state == S802_15_4UP) { return TRUE; } else { return FALSE; }}// /**// FUNCTION :: Sscs802_15_4MCPS_DATA_confirm// LAYER :: Mac// PURPOSE :: Primitive to report results of a request to tx a data SPDU// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// + msduHandle : UInt8 : Handle associated with MSDU// + status : M802_15_4_enum: Status of data sent request// RETURN :: None// **/void Sscs802_15_4MCPS_DATA_confirm( Node* node, int interfaceIndex, UInt8 msduHandle, M802_15_4_enum status){}// /**// FUNCTION :: Sscs802_15_4MCPS_DATA_indication// LAYER :: Mac// PURPOSE :: Primitive to indicate the transfer of a data SPDU to SSCS// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// + SrcAddrMode : UInt8 : Source address mode// + SrcPANId : UInt16 : source PAN id// + SrcAddr : MACADDR : Source address// + DstAddrMode : UInt8 : Destination address mode// + DstPANId : UInt16 : Destination PAN id// + DstAddr : MACADDR : Destination Address// + msduLength : UInt8 : MSDU length// + msdu : Message* : MSDU// + mpduLinkQuality: UInt8 : LQI value measured during reception of// the MPDU// + SecurityUse : BOOL : whether security is used// + ACLEntry : UInt8 : ACL entry// RETURN :: None// **/void Sscs802_15_4MCPS_DATA_indication( Node* node, int interfaceIndex, UInt8 SrcAddrMode, UInt16 SrcPANId, MACADDR SrcAddr, UInt8 DstAddrMode, UInt16 DstPANId, MACADDR DstAddr, UInt8 msduLength, Message *msdu, UInt8 mpduLinkQuality, BOOL SecurityUse, UInt8 ACLEntry){ MESSAGE_Free(node, msdu);}// /**// FUNCTION :: Sscs802_15_4MCPS_PURGE_confirm// LAYER :: Mac// PURPOSE :: Primitive to report result of purge request// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// + msduHandle : UInt8 : Handle associated with MSDU// + status : M802_15_4_enum: Status of purge request// RETURN :: None// **/void Sscs802_15_4MCPS_PURGE_confirm( Node* node, int interfaceIndex, UInt8 msduHandle, M802_15_4_enum status){}// /**// FUNCTION :: Sscs802_15_4MLME_ASSOCIATE_indication// LAYER :: Mac// PURPOSE :: Primitive to indicate an incoming associate request// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// + DeviceAddress : MACADDR : Address of device requesting// association// + CapabilityInformation : UInt8 : capabilities of associating device// + SecurityUse : BOOL : Whether enable security or not// + ACLEntry : UInt8 : ACL entry// RETURN :: None// **/void Sscs802_15_4MLME_ASSOCIATE_indication( Node* node, int interfaceIndex, MACADDR DeviceAddress, UInt8 CapabilityInformation, BOOL SecurityUse, UInt8 ACLEntry){ MacData802_15_4* mac; SscsData802_15_4* sscs802_15_4; mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar; sscs802_15_4 = (SscsData802_15_4*)mac->sscs; Mac802_15_4ChkAddDeviceLink( &mac->deviceLink1, &mac->deviceLink2, DeviceAddress, CapabilityInformation); Mac802_15_4MLME_ASSOCIATE_response( node, interfaceIndex, DeviceAddress, (UInt16)DeviceAddress, M802_15_4_SUCCESS, FALSE); sscs802_15_4->stats.numAssociationAcptd++;}// /**// FUNCTION :: Sscs802_15_4MLME_ASSOCIATE_confirm// LAYER :: Mac// PURPOSE :: Primitive to report result of associate request// PARAMETERS ::// + node : Node* : Node receiving call// + interfaceIndex : int : Interface Index// + AssocShortAddress : UInt16 : Short address allocated by coord// + status : M802_15_4_enum: Status of association attempt// RETURN :: None// **/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -