⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mac_802_15_4.cpp

📁 csma协议
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        {            MESSAGE_Free(node, mac->txBcnCmd2);            mac->txBcnCmd2 = NULL;        }    }    else if (task == 'd')   //data    {        Message* p = mac->txData;        int rt;        //if it is a pending packet, delete it from the pending list        rt = Mac802_15_4UpdateTransacLinkByPktOrHandle(                node,                1,  //del                &mac->transacLink1,                &mac->transacLink2,                p,                0);        if(rt != 0)        {            MESSAGE_Free(node, mac->txData);        }        mac->txData = NULL;        Mac802_15_4CheckForOutgoingPacket(node, interfaceIndex);    }    else    {        ERROR_Assert(0, "");    }    if (csmacaRes == TRUE)    {        Mac802_15_4CsmacaResume(node, interfaceIndex);    }}// /**// FUNCTION   :: Mac802_15_4Reset_TRX// LAYER      :: Mac// PURPOSE    :: Reset Transceiver// PARAMETERS ::// + node           : Node*     : Node receiving call// + interfaceIndex : int       : Interface index// RETURN  :: None// **/staticvoid Mac802_15_4Reset_TRX(Node* node, int interfaceIndex){    MacData802_15_4* mac;    clocktype t_CAP;    PLMEsetTrxState t_state;    mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar;    if ((mac->mpib.macBeaconOrder != 15) ||         (mac->macBeaconOrder2 != 15))    //beacon enabled    {        t_CAP = Mac802_15_4GetCAP(node, interfaceIndex, FALSE);        if (getSimTime(node) < t_CAP)        {            if(mac->mpib.macRxOnWhenIdle || mac->isPANCoor)            {                t_state = RX_ON;            }            else            {                t_state = TRX_OFF;            }        }        else        {            t_state = RX_ON;        }    }    else    {        if(mac->mpib.macRxOnWhenIdle || mac->isPANCoor)        {            t_state = RX_ON;        }        else        {            t_state = TRX_OFF;        }    }    mac->trx_state_req = t_state;    Phy802_15_4PlmeSetTRX_StateRequest(            node,            interfaceIndex,            t_state);}// /**// FUNCTION   :: Mac802_15_4Dispatch// LAYER      :: Mac// PURPOSE    :: Dispatches an incoming event// PARAMETERS ::// + node           : Node*     : Node receiving call// + interfaceIndex : int       : Interface index// + status         : PhyStatusType   : Phy status// + frFunc         : char*     : Function name from which dispatch() has//                                been called// + req_state      : PLMEsetTrxState   :// + mStatus        : M802_15_4_enum : MAC layer status// RETURN  :: None// **/staticvoid Mac802_15_4Dispatch(        Node* node,        int interfaceIndex,        PhyStatusType status,        const char* frFunc,        PLMEsetTrxState req_state,        M802_15_4_enum mStatus){    MacData802_15_4* mac;    M802_15_4FrameCtrl frmCtrl;    M802_15_4Header* wph;    UInt8 ifs;    mac = (MacData802_15_4*) node->macData[interfaceIndex]->macVar;    if (strcmp(frFunc,"csmacaCallBack") == 0)    {        if (mac->txCsmaca == mac->txBcnCmd2)        {            if (mac->taskP.mlme_scan_request_STEP &&                (strcmp(mac->taskP.mlme_scan_request_frFunc,frFunc) == 0))            {                if ((mac->taskP.mlme_scan_request_ScanType == 0x01) ||                     (mac->taskP.mlme_scan_request_ScanType == 0x03))                {                    Mac802_15_4mlme_scan_request(                            node,                            interfaceIndex,                            mac->taskP.mlme_scan_request_ScanType,                            mac->taskP.mlme_scan_request_ScanChannels,                            mac->taskP.mlme_scan_request_ScanDuration,                            FALSE,                            status);                }            }            else if (mac->taskP.mlme_start_request_STEP &&                     (strcmp(mac->taskP.mlme_start_request_frFunc,frFunc) ==                     0))            {                Mac802_15_4mlme_start_request(                        node,                        interfaceIndex,                        mac->taskP.mlme_start_request_PANId,                        mac->taskP.mlme_start_request_LogicalChannel,                        mac->taskP.mlme_start_request_BeaconOrder,                        mac->taskP.mlme_start_request_SuperframeOrder,                        mac->taskP.mlme_start_request_PANCoordinator,                        mac->taskP.mlme_start_request_BatteryLifeExtension,                        0,                        mac->taskP.mlme_start_request_SecurityEnable,                        FALSE,                        status);            }            else if (mac->taskP.mlme_associate_request_STEP &&                    (strcmp(mac->taskP.mlme_associate_request_frFunc,                                frFunc) == 0))            {                Mac802_15_4mlme_associate_request(                        node,                        interfaceIndex,                        0,                        0,                        0,                        0,                        0,                        mac->taskP.mlme_associate_request_SecurityEnable,                        FALSE,                        status,                        M802_15_4_SUCCESS);            }            else if (mac->taskP.mlme_disassociate_request_STEP &&                     (strcmp(mac->taskP.mlme_disassociate_request_frFunc,                      frFunc) == 0))            {                Mac802_15_4mlme_disassociate_request(                        node,                        interfaceIndex,                        0,                        0,                        FALSE,                        FALSE,                        status);            }            else if (mac->taskP.mlme_poll_request_STEP &&                     (strcmp(mac->taskP.mlme_poll_request_frFunc, frFunc)                        == 0))            {                Mac802_15_4mlme_poll_request(                        node,                        interfaceIndex,                        mac->taskP.mlme_poll_request_CoordAddrMode,                        mac->taskP.mlme_poll_request_CoordPANId,                        mac->taskP.mlme_poll_request_CoordAddress,                        mac->taskP.mlme_poll_request_SecurityEnable,                        mac->taskP.mlme_poll_request_autoRequest,                        FALSE,                        status);            }            else    //default handling for txBcnCmd2            {                if (status == PHY_IDLE)                {                    mac->trx_state_req = TX_ON;                    Phy802_15_4PlmeSetTRX_StateRequest(                            node,                            interfaceIndex,                            TX_ON);                    Mac802_15_4PLME_SET_TRX_STATE_confirm(                            node,                            interfaceIndex,                            PHY_BUSY_TX);                }                else                {                    if(mac->txBcnCmd2)                    {                        MESSAGE_Free(node, mac->txBcnCmd2);                        mac->txBcnCmd2 = NULL;                    }                    Mac802_15_4CsmacaResume(node, interfaceIndex);                }            }        }        else if (mac->txCsmaca == mac->txData)        {            ERROR_Assert(mac->taskP.mcps_data_request_STEP &&                    (strcmp(mac->taskP.mcps_data_request_frFunc,frFunc)                    == 0), "");            if (mac->taskP.mcps_data_request_TxOptions & TxOp_GTS)            //GTS transmission            {                ;   //TBD            }            //indirect transmission            else if ((mac->taskP.mcps_data_request_TxOptions & TxOp_Indirect)                      && (mac->capability.FFD &&                      (Mac802_15_4NumberDeviceLink(&mac->deviceLink1) > 0)))            {                if (status != PHY_IDLE)                {                    Mac802_15_4mcps_data_request(                            node,                            interfaceIndex,                            0, 0, 0, 0, 0, 0, 0, 0, 0,                            mac->taskP.mcps_data_request_TxOptions,                            FALSE,                            PHY_BUSY_TX,                            M802_15_4_CHANNEL_ACCESS_FAILURE);                }                else                {                    strcpy(mac->taskP.mcps_data_request_frFunc,                           "PD_DATA_confirm");                    mac->trx_state_req = TX_ON;                    Phy802_15_4PlmeSetTRX_StateRequest(                            node,                            interfaceIndex,                            TX_ON);                    //assumed that above always returns true                    Mac802_15_4PLME_SET_TRX_STATE_confirm(                            node,                            interfaceIndex,                            PHY_BUSY_TX);                }            }            else        //direct transmission: in this case, let                //mcps_data_request() take care of everything            {                Mac802_15_4mcps_data_request(                        node,                        interfaceIndex,                        0, 0, 0, 0, 0, 0, 0, 0, 0,                        mac->taskP.mcps_data_request_TxOptions,                        FALSE,                        status, M802_15_4_SUCCESS);            }        }        else if (mac->txCsmaca == mac->txBcnCmd)  //def handling for txBcnCmd        {            wph = (M802_15_4Header*) (mac->txBcnCmd->packet);            frmCtrl.FrmCtrl = wph->MHR_FrmCtrl;            Mac802_15_4FrameCtrlParse(&frmCtrl);            if (status == PHY_IDLE)            {                if ((frmCtrl.frmType == M802_15_4DEFFRMCTRL_TYPE_MACCMD)                     && (wph->MSDU_CmdType == 0x02)) //association resp pkt                {                    strcpy(mac->taskP.mlme_associate_request_frFunc,                           "PD_DATA_confirm");                }                else if ((frmCtrl.frmType ==                          M802_15_4DEFFRMCTRL_TYPE_MACCMD)  //cmd pkt                          && (wph->MSDU_CmdType == 0x08))                //coordinator realignment response packet                {                    strcpy(mac->taskP.mlme_orphan_response_frFunc,                           "PD_DATA_confirm");                }                mac->trx_state_req = TX_ON;                Phy802_15_4PlmeSetTRX_StateRequest(                        node,                        interfaceIndex,                        TX_ON);                //assumed that above always returns true                Mac802_15_4PLME_SET_TRX_STATE_confirm(                        node,                        interfaceIndex,                        PHY_BUSY_TX);            }            else            {                if ((frmCtrl.frmType == M802_15_4DEFFRMCTRL_TYPE_MACCMD)                     && (wph->MSDU_CmdType == 0x02)) //ass resp pkt                {                    Mac802_15_4mlme_associate_response(                            node,                            interfaceIndex,                            mac->taskP.mlme_associate_response_DeviceAddress,                            0,                            M802_15_4_CHANNEL_ACCESS_FAILURE,                            0,                            FALSE,                            PHY_BUSY_TX);                }                else if ((frmCtrl.frmType == M802_15_4DEFFRMCTRL_TYPE_MACCMD)                          && (wph->MSDU_CmdType == 0x08))                            //coordinator realignment response packet                {                    Mac802_15_4mlme_orphan_response(                            node,                            interfaceIndex,                            mac->taskP.mlme_orphan_response_OrphanAddress,                            0,                            TRUE,                            FALSE,                            FALSE,                            PHY_BUSY_TX);                }                else                {                    if(mac->txBcnCmd)                    {                        MESSAGE_Free(node, mac->txBcnCmd);                        mac->txBcnCmd = NULL;                    }                    Mac802_15_4CsmacaResume(node, interfaceIndex);                }            }        }    }    else if (strcmp(frFunc, "PD_DATA_confirm") == 0)    {        if (mac->txPkt == mac->txBeacon)        {            if (mac->taskP.mlme_start_request_STEP &&                (strcmp(mac->taskP.mlme_start_request_frFunc,frFunc) == 0))            {                Mac802_15_4mlme_start_request(                        node,                        interfaceIndex,                        mac->taskP.mlme_start_request_PANId,                        mac->taskP.mlme_start_request_LogicalChannel,                        mac->taskP.mlme_start_request_BeaconOrder,                        mac->taskP.mlme_start_request_SuperframeOrder,                        mac->taskP.mlme_start_request_PANCoordinator,                        mac->taskP.mlme_start_request_BatteryLifeExtension,                        0,                        mac->taskP.mlme_start_request_SecurityEnable,                        FALSE,                        status);            }            else    //default handling            {                Mac802_15_4Reset_TRX(node, interfaceIndex);                Mac802_15_4TaskSuccess(node, interfaceIndex, 'b', TRUE);            }        }        else if (mac->txPkt == mac->txAck)        {            if (mac->rxCmd)            {                if (MESSAGE_ReturnPacketSize(mac->rxCmd) <=                        aMaxSIFSFrameSize)                {                    ifs = aMinSIFSPeriod;                }                else                {                    ifs = aMinLIFSPeriod;                }                mac->IFST =                        Mac802_15_4SetTimer(                        node,                        mac,                        M802_15_4IFSTIMER,                        ifs * SECOND /                            PHY_GetRxDataRate(node, interfaceIndex),                        NULL);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -