Ejemplo n.º 1
0
void Joiner::HandleDiscoverResult(otActiveScanResult *aResult)
{
    if (aResult != NULL)
    {
        JoinerRouter joinerRouter;

        otLogDebgMeshCoP("Received Discovery Response (%s)",
                         static_cast<Mac::ExtAddress &>(aResult->mExtAddress).ToString().AsCString());

        // Joining is disabled if the Steering Data is not included
        if (aResult->mSteeringData.mLength == 0)
        {
            otLogDebgMeshCoP("No steering data, joining disabled");
            ExitNow();
        }

        SteeringDataTlv steeringData;
        steeringData.SetLength(aResult->mSteeringData.mLength);
        memcpy(steeringData.GetValue(), aResult->mSteeringData.m8, steeringData.GetLength());

        if (!steeringData.GetBit(mCcitt % steeringData.GetNumBits()) ||
            !steeringData.GetBit(mAnsi % steeringData.GetNumBits()))
        {
            otLogDebgMeshCoP("Steering data does not include this device");
            ExitNow();
        }

        joinerRouter.mPriority = static_cast<uint16_t>(aResult->mRssi) + 0x80;

        if (!steeringData.DoesAllowAny())
        {
            joinerRouter.mPriority += kSpecificPriorityBonus;
        }

        joinerRouter.mJoinerUdpPort = aResult->mJoinerUdpPort;
        joinerRouter.mPanId         = aResult->mPanId;
        joinerRouter.mChannel       = aResult->mChannel;
        joinerRouter.mExtAddr       = static_cast<Mac::ExtAddress &>(aResult->mExtAddress);
        AddJoinerRouter(joinerRouter);
    }
    else
    {
        otError error = TryNextJoin();

        if (error != OT_ERROR_NONE)
        {
            Complete(error);
        }
    }

exit:
    return;
}
Ejemplo n.º 2
0
void Joiner::HandleDiscoverResult(otActiveScanResult *aResult)
{
    if (aResult != NULL)
    {
        otLogFuncEntryMsg("aResult = %llX", HostSwap64(*reinterpret_cast<uint64_t *>(&aResult->mExtAddress)));

        SteeringDataTlv steeringData;
        Mac::ExtAddress extAddress;
        Crc16 ccitt(Crc16::kCcitt);
        Crc16 ansi(Crc16::kAnsi);

        mNetif.GetMac().GetHashMacAddress(&extAddress);

        for (size_t i = 0; i < sizeof(extAddress); i++)
        {
            ccitt.Update(extAddress.m8[i]);
            ansi.Update(extAddress.m8[i]);
        }

        steeringData.SetLength(aResult->mSteeringData.mLength);
        memcpy(steeringData.GetValue(), aResult->mSteeringData.m8, steeringData.GetLength());

        if (steeringData.GetBit(ccitt.Get() % steeringData.GetNumBits()) &&
            steeringData.GetBit(ansi.Get() % steeringData.GetNumBits()))
        {
            mJoinerUdpPort = aResult->mJoinerUdpPort;
            mJoinerRouterPanId = aResult->mPanId;
            mJoinerRouterChannel = aResult->mChannel;
            memcpy(&mJoinerRouter, &aResult->mExtAddress, sizeof(mJoinerRouter));
        }
        else
        {
            otLogDebgMeshCoP("Steering data not set");
        }
    }
    else if (mJoinerRouterPanId != Mac::kPanIdBroadcast)
    {
        otLogFuncEntryMsg("aResult = NULL");

        // open UDP port
        Ip6::SockAddr sockaddr;
        sockaddr.mPort = mJoinerUdpPort;
        mSocket.Open(&Joiner::HandleUdpReceive, this);
        mSocket.Bind(sockaddr);

        mNetif.GetMac().SetPanId(mJoinerRouterPanId);
        mNetif.GetMac().SetChannel(mJoinerRouterChannel);
        mNetif.GetIp6Filter().AddUnsecurePort(sockaddr.mPort);

        mNetif.GetDtls().Start(true, HandleDtlsReceive, HandleDtlsSend, this);
    }

    otLogFuncExit();
}