示例#1
0
otError Joiner::TryNextJoin()
{
    ThreadNetif & netif        = GetNetif();
    otError       error        = OT_ERROR_NOT_FOUND;
    JoinerRouter *joinerRouter = &mJoinerRouters[0];

    for (size_t i = 1; i < OPENTHREAD_CONFIG_MAX_JOINER_ROUTER_ENTRIES; i++)
    {
        if (mJoinerRouters[i].mPriority > joinerRouter->mPriority)
        {
            joinerRouter = &mJoinerRouters[i];
        }
    }

    if (joinerRouter->mPriority > 0)
    {
        Ip6::SockAddr sockaddr;

        joinerRouter->mPriority = 0;

        netif.GetMac().SetPanId(joinerRouter->mPanId);
        netif.GetMac().SetPanChannel(joinerRouter->mChannel);
        netif.GetIp6Filter().AddUnsecurePort(OPENTHREAD_CONFIG_JOINER_UDP_PORT);

        sockaddr.GetAddress().mFields.m16[0] = HostSwap16(0xfe80);
        sockaddr.GetAddress().SetIid(joinerRouter->mExtAddr);
        sockaddr.mPort    = joinerRouter->mJoinerUdpPort;
        sockaddr.mScopeId = OT_NETIF_INTERFACE_ID_THREAD;

        netif.GetCoapSecure().Connect(sockaddr, Joiner::HandleSecureCoapClientConnect, this);
        mState = OT_JOINER_STATE_CONNECT;
        error  = OT_ERROR_NONE;
    }
    else
    {
        otLogDebgMeshCoP("No joinable networks remaining to try");
    }

    return error;
}
示例#2
0
otError Dtls::Connect(const Ip6::SockAddr &aSockAddr)
{
    otError error;

    VerifyOrExit(mState == kStateOpen, error = OT_ERROR_INVALID_STATE);

    memcpy(&mPeerAddress.mPeerAddr, &aSockAddr.mAddress, sizeof(mPeerAddress.mPeerAddr));
    mPeerAddress.mPeerPort = aSockAddr.mPort;

    if (aSockAddr.GetAddress().IsLinkLocal() || aSockAddr.GetAddress().IsMulticast())
    {
        mPeerAddress.mInterfaceId = aSockAddr.mScopeId;
    }
    else
    {
        mPeerAddress.mInterfaceId = 0;
    }

    error = Setup(true);

exit:
    return error;
}