예제 #1
0
void Instance::AfterInit(void)
{
    mIsInitialized = true;
#if OPENTHREAD_MTD || OPENTHREAD_FTD

    // Restore datasets and network information

    GetSettings().Init();
    mThreadNetif.GetMle().Restore();

#if OPENTHREAD_CONFIG_ENABLE_AUTO_START_SUPPORT

    if (otThreadGetAutoStart(this))
    {
        if (otIp6SetEnabled(this, true) == OT_ERROR_NONE)
        {
            // Only try to start Thread if we could bring up the interface
            if (otThreadSetEnabled(this, true) != OT_ERROR_NONE)
            {
                // Bring the interface down if Thread failed to start
                otIp6SetEnabled(this, false);
            }
        }
    }

#endif
#endif // OPENTHREAD_MTD || OPENTHREAD_FTD
}
예제 #2
0
void Instance::Finalize(void)
{
    VerifyOrExit(mIsInitialized == true);

    mIsInitialized = false;

    IgnoreReturnValue(otThreadSetEnabled(this, false));
    IgnoreReturnValue(otIp6SetEnabled(this, false));
    IgnoreReturnValue(otLinkSetEnabled(this, false));

exit:
    return;
}
예제 #3
0
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
    const otPanId panId = 0xdead;

    otInstance *      instance = NULL;
    otMessage *       message  = NULL;
    otError           error    = OT_ERROR_NONE;
    otMessageSettings settings;

    VerifyOrExit(size > 0);

    FuzzerPlatformInit();

    instance = otInstanceInitSingle();
    otLinkSetPanId(instance, panId);
    otIp6SetEnabled(instance, true);
    otThreadSetEnabled(instance, true);
    otThreadBecomeLeader(instance);

    settings.mLinkSecurityEnabled = (data[0] & 0x1) != 0;
    settings.mPriority            = OT_MESSAGE_PRIORITY_NORMAL;

    message = otIp6NewMessage(instance, &settings);
    VerifyOrExit(message != NULL, error = OT_ERROR_NO_BUFS);

    error = otMessageAppend(message, data + 1, static_cast<uint16_t>(size - 1));
    SuccessOrExit(error);

    error = otIp6Send(instance, message);

    message = NULL;

exit:

    if (message != NULL)
    {
        otMessageFree(message);
    }

    if (instance != NULL)
    {
        otInstanceFinalize(instance);
    }

    return 0;
}