diff --git a/examples/drivers/windows/otApi/otApi.cpp b/examples/drivers/windows/otApi/otApi.cpp index 942d2fc90..c47178e00 100644 --- a/examples/drivers/windows/otApi/otApi.cpp +++ b/examples/drivers/windows/otApi/otApi.cpp @@ -230,13 +230,13 @@ otApiInit( DWORD dwError = ERROR_SUCCESS; otApiInstance *aApitInstance = nullptr; - otLogFuncEntry(); + LogFuncEntry(API_DEFAULT); aApitInstance = new(std::nothrow)otApiInstance(); if (aApitInstance == nullptr) { dwError = GetLastError(); - otLogWarnApi("Failed to allocate otApiInstance"); + LogWarning(API_DEFAULT, "Failed to allocate otApiInstance"); goto error; } @@ -254,7 +254,7 @@ otApiInit( if (aApitInstance->DeviceHandle == INVALID_HANDLE_VALUE) { dwError = GetLastError(); - otLogCritApi("CreateFile failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "CreateFile failed, %!WINERROR!", dwError); goto error; } @@ -263,7 +263,7 @@ otApiInit( if (aApitInstance->Overlapped.hEvent == nullptr) { dwError = GetLastError(); - otLogCritApi("CreateEvent (Overlapped.hEvent) failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "CreateEvent (Overlapped.hEvent) failed, %!WINERROR!", dwError); goto error; } @@ -277,7 +277,7 @@ otApiInit( if (aApitInstance->ThreadpoolWait == nullptr) { dwError = GetLastError(); - otLogCritApi("CreateThreadpoolWait failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "CreateThreadpoolWait failed, %!WINERROR!", dwError); goto error; } @@ -285,7 +285,7 @@ otApiInit( SetThreadpoolWait(aApitInstance->ThreadpoolWait, aApitInstance->Overlapped.hEvent, nullptr); #ifdef DEBUG_ASYNC_IO - otLogDebgApi("Querying for 1st notification"); + LogVerbose(API_DEFAULT, "Querying for 1st notification"); #endif // Request first notification asynchronously @@ -300,7 +300,7 @@ otApiInit( dwError = GetLastError(); if (dwError != ERROR_IO_PENDING) { - otLogCritApi("DeviceIoControl for first notification failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "DeviceIoControl for first notification failed, %!WINERROR!", dwError); goto error; } dwError = ERROR_SUCCESS; @@ -314,7 +314,7 @@ error: aApitInstance = nullptr; } - otLogFuncExit(); + LogFuncExit(API_DEFAULT); return aApitInstance; } @@ -328,7 +328,7 @@ otApiFinalize( { if (aApitInstance == nullptr) return; - otLogFuncEntry(); + LogFuncEntry(API_DEFAULT); // If we never got the handle, nothing left to clean up if (aApitInstance->DeviceHandle != INVALID_HANDLE_VALUE) @@ -364,7 +364,7 @@ otApiFinalize( aApitInstance->JoinerCallbacks.clear(); #ifdef DEBUG_ASYNC_IO - otLogDebgApi("Clearing Threadpool Wait"); + LogVerbose(API_DEFAULT, "Clearing Threadpool Wait"); #endif // Clear the threadpool wait to prevent further waits from being scheduled @@ -419,14 +419,14 @@ otApiFinalize( if (tpWait) { #ifdef DEBUG_ASYNC_IO - otLogDebgApi("Waiting for outstanding threadpool callbacks to compelte"); + LogVerbose(API_DEFAULT, "Waiting for outstanding threadpool callbacks to compelte"); #endif // Cancel any queued waits and wait for any outstanding calls to compelte WaitForThreadpoolWaitCallbacks(tpWait, TRUE); #ifdef DEBUG_ASYNC_IO - otLogDebgApi("Cancelling any pending IO"); + LogVerbose(API_DEFAULT, "Cancelling any pending IO"); #endif // Cancel any async IO @@ -448,7 +448,7 @@ otApiFinalize( delete aApitInstance; - otLogFuncExit(); + LogFuncExit(API_DEFAULT); } OTAPI @@ -713,7 +713,7 @@ otIoComplete( ) { #ifdef DEBUG_ASYNC_IO - otLogFuncEntry(); + LogFuncEntry(API_DEFAULT); #endif otApiInstance *aApitInstance = (otApiInstance*)Context; @@ -728,11 +728,11 @@ otIoComplete( FALSE)) { DWORD dwError = GetLastError(); - otLogCritApi("GetOverlappedResult for notification failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "GetOverlappedResult for notification failed, %!WINERROR!", dwError); } else { - otLogDebgApi("Received successful callback for notification, type=%d", + LogVerbose(API_DEFAULT, "Received successful callback for notification, type=%d", aApitInstance->NotificationBuffer.NotifType); // Invoke the callback if set @@ -749,7 +749,7 @@ otIoComplete( SetThreadpoolWait(tpWait, aApitInstance->Overlapped.hEvent, nullptr); #ifdef DEBUG_ASYNC_IO - otLogDebgApi("Querying for next notification"); + LogVerbose(API_DEFAULT, "Querying for next notification"); #endif // Request next notification @@ -764,14 +764,14 @@ otIoComplete( DWORD dwError = GetLastError(); if (dwError != ERROR_IO_PENDING) { - otLogCritApi("DeviceIoControl for new notification failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "DeviceIoControl for new notification failed, %!WINERROR!", dwError); } } } } #ifdef DEBUG_ASYNC_IO - otLogFuncExit(); + LogFuncExit(API_DEFAULT); #endif } @@ -793,7 +793,7 @@ SendIOCTL( if (Overlapped.hEvent == nullptr) { dwError = GetLastError(); - otLogCritApi("CreateEvent (Overlapped.hEvent) failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "CreateEvent (Overlapped.hEvent) failed, %!WINERROR!", dwError); goto error; } @@ -809,7 +809,7 @@ SendIOCTL( dwError = GetLastError(); if (dwError != ERROR_IO_PENDING) { - otLogCritApi("DeviceIoControl(0x%x) failed, %!WINERROR!", dwIoControlCode, dwError); + LogError(API_DEFAULT, "DeviceIoControl(0x%x) failed, %!WINERROR!", dwIoControlCode, dwError); goto error; } dwError = ERROR_SUCCESS; @@ -830,14 +830,14 @@ SendIOCTL( dwError = ERROR_TIMEOUT; CancelIoEx(aApitInstance->DeviceHandle, &Overlapped); } - otLogCritApi("GetOverlappedResult failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "GetOverlappedResult failed, %!WINERROR!", dwError); goto error; } if (dwBytesReturned != nOutBufferSize) { dwError = ERROR_INVALID_DATA; - otLogCritApi("GetOverlappedResult returned invalid output size, expected=%u actual=%u", + LogError(API_DEFAULT, "GetOverlappedResult returned invalid output size, expected=%u actual=%u", nOutBufferSize, dwBytesReturned); goto error; } @@ -1004,20 +1004,20 @@ otEnumerateDevices( otDeviceList* pDeviceList = nullptr; DWORD cbDeviceList = sizeof(otDeviceList); - otLogFuncEntry(); + LogFuncEntry(API_DEFAULT); Overlapped.hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr); if (Overlapped.hEvent == nullptr) { dwError = GetLastError(); - otLogCritApi("CreateEvent (Overlapped.hEvent) failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "CreateEvent (Overlapped.hEvent) failed, %!WINERROR!", dwError); goto error; } pDeviceList = (otDeviceList*)malloc(cbDeviceList); if (pDeviceList == nullptr) { - otLogWarnApi("Failed to allocate otDeviceList of %u bytes.", cbDeviceList); + LogWarning(API_DEFAULT, "Failed to allocate otDeviceList of %u bytes.", cbDeviceList); dwError = ERROR_NOT_ENOUGH_MEMORY; goto error; } @@ -1038,7 +1038,7 @@ otEnumerateDevices( dwError = GetLastError(); if (dwError != ERROR_IO_PENDING) { - otLogCritApi("DeviceIoControl(IOCTL_OTLWF_ENUMERATE_DEVICES) failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "DeviceIoControl(IOCTL_OTLWF_ENUMERATE_DEVICES) failed, %!WINERROR!", dwError); goto error; } dwError = ERROR_SUCCESS; @@ -1058,7 +1058,7 @@ otEnumerateDevices( dwError = ERROR_TIMEOUT; CancelIoEx(aApitInstance->DeviceHandle, &Overlapped); } - otLogCritApi("GetOverlappedResult for notification failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "GetOverlappedResult for notification failed, %!WINERROR!", dwError); goto error; } @@ -1076,7 +1076,7 @@ otEnumerateDevices( pDeviceList = (otDeviceList*)malloc(cbDeviceList); if (pDeviceList == nullptr) { - otLogCritApi("Failed to allocate otDeviceList of %u bytes.", cbDeviceList); + LogError(API_DEFAULT, "Failed to allocate otDeviceList of %u bytes.", cbDeviceList); dwError = ERROR_NOT_ENOUGH_MEMORY; goto error; } @@ -1096,7 +1096,7 @@ error: CloseHandle(Overlapped.hEvent); } - otLogFuncExitMsg("%d devices", pDeviceList == nullptr ? -1 : (int)pDeviceList->aDevicesLength); + LogFuncExitMsg(API_DEFAULT, "%d devices", pDeviceList == nullptr ? -1 : (int)pDeviceList->aDevicesLength); return pDeviceList; } @@ -1132,7 +1132,7 @@ otInstanceInit( if (ConvertInterfaceGuidToLuid(aDeviceGuid, &aInstance->InterfaceLuid) != ERROR_SUCCESS || ConvertInterfaceLuidToIndex(&aInstance->InterfaceLuid, &aInstance->InterfaceIndex) != ERROR_SUCCESS) { - otLogCritApi("Failed to convert interface guid to index!"); + LogError(API_DEFAULT, "Failed to convert interface guid to index!"); free(aInstance); aInstance = nullptr; } @@ -1920,10 +1920,10 @@ otIp6GetUnicastAddresses( _In_ otInstance *aInstance ) { - otLogFuncEntry(); + LogFuncEntry(API_DEFAULT); if (aInstance == nullptr) { - otLogFuncExit(); + LogFuncExit(API_DEFAULT); return nullptr; } @@ -1935,7 +1935,7 @@ otIp6GetUnicastAddresses( DWORD dwError = ERROR_SUCCESS; if ((dwError = SetCurrentThreadCompartmentId(aInstance->CompartmentID)) != ERROR_SUCCESS) { - otLogCritApi("SetCurrentThreadCompartmentId failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "SetCurrentThreadCompartmentId failed, %!WINERROR!", dwError); return nullptr; } RevertCompartmentOnExit = true; @@ -1972,7 +1972,7 @@ otIp6GetUnicastAddresses( addrs = (otNetifAddress*)malloc(AddrCount * sizeof(otNetifAddress)); if (addrs == nullptr) { - otLogWarnApi("Not enough memory to alloc otNetifAddress array"); + LogWarning(API_DEFAULT, "Not enough memory to alloc otNetifAddress array"); goto error; } ZeroMemory(addrs, AddrCount * sizeof(otNetifAddress)); @@ -2015,7 +2015,7 @@ otIp6GetUnicastAddresses( } else { - otLogCritApi("GetAdapterAddresses failed!"); + LogError(API_DEFAULT, "GetAdapterAddresses failed!"); } // Revert the comparment if necessary @@ -2024,7 +2024,7 @@ otIp6GetUnicastAddresses( (VOID)SetCurrentThreadCompartmentId(OriginalCompartmentID); } - otLogFuncExitMsg("%d addrs", AddrCount); + LogFuncExitMsg(API_DEFAULT, "%d addrs", AddrCount); return addrs; } @@ -2046,7 +2046,7 @@ otIp6AddUnicastAddress( DWORD dwError = ERROR_SUCCESS; if ((dwError = SetCurrentThreadCompartmentId(aInstance->CompartmentID)) != ERROR_SUCCESS) { - otLogCritApi("SetCurrentThreadCompartmentId failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "SetCurrentThreadCompartmentId failed, %!WINERROR!", dwError); return kThreadError_Failed; } RevertCompartmentOnExit = true; @@ -2088,7 +2088,7 @@ otIp6AddUnicastAddress( if (dwError != ERROR_SUCCESS) { - otLogCritApi("CreateUnicastIpAddressEntry failed %!WINERROR!", dwError); + LogError(API_DEFAULT, "CreateUnicastIpAddressEntry failed %!WINERROR!", dwError); return kThreadError_Failed; } @@ -2113,7 +2113,7 @@ otIp6RemoveUnicastAddress( DWORD dwError = ERROR_SUCCESS; if ((dwError = SetCurrentThreadCompartmentId(aInstance->CompartmentID)) != ERROR_SUCCESS) { - otLogCritApi("SetCurrentThreadCompartmentId failed, %!WINERROR!", dwError); + LogError(API_DEFAULT, "SetCurrentThreadCompartmentId failed, %!WINERROR!", dwError); return kThreadError_Failed; } RevertCompartmentOnExit = true; @@ -2138,7 +2138,7 @@ otIp6RemoveUnicastAddress( if (dwError != ERROR_SUCCESS) { - otLogCritApi("DeleteUnicastIpAddressEntry failed %!WINERROR!", dwError); + LogError(API_DEFAULT, "DeleteUnicastIpAddressEntry failed %!WINERROR!", dwError); return kThreadError_Failed; } diff --git a/include/openthread/platform/logging-windows.h b/include/openthread/platform/logging-windows.h index e155a4b11..263d390fb 100644 --- a/include/openthread/platform/logging-windows.h +++ b/include/openthread/platform/logging-windows.h @@ -62,26 +62,19 @@ WPP_DEFINE_BIT(OT_MBEDTLS) /* 0x00008000 */ \ WPP_DEFINE_BIT(OT_DUMP) /* 0x00010000 */ \ WPP_DEFINE_BIT(OT_NDIAG) /* 0x00020000 */ \ + WPP_DEFINE_BIT(API_DEFAULT) /* 0x00040000 */ \ ) -#define WPP_LEVEL_FLAGS_LOGGER(lvl,flag) \ - WPP_FLAG_LOGGER(flag) +#define WPP_LEVEL_FLAGS_LOGGER(lvl,flag) WPP_FLAG_LOGGER(flag) +#define WPP_LEVEL_FLAGS_EXP_ENABLED(LEVEL,FLAGS,EXP) WPP_LEVEL_FLAGS_ENABLED (LEVEL,FLAGS) +#define WPP_LEVEL_FLAGS_CTX_ENABLED(LEVEL,FLAGS,CTX) WPP_LEVEL_FLAGS_ENABLED (LEVEL,FLAGS) +#define WPP_LEVEL_FLAGS_CTX_EXP_ENABLED(LEVEL,FLAGS,CTX,EXP) WPP_LEVEL_FLAGS_ENABLED (LEVEL,FLAGS) #define WPP_LEVEL_FLAGS_ENABLED(lvl, flag) \ (WPP_FLAG_ENABLED(flag) && WPP_CONTROL(WPP_BIT_ ## flag).Level >= lvl) - -// Suppress warnings about constants in logical expressions because the -// level is often a constant -#define WPP_LEVEL_FLAGS_PRE(LEVEL,FLAGS) __pragma(warning(suppress:25039 25040 25078 25080)) - -// Map no-argument macros (dummy) back to regular macros -#define WPP_LEVEL_FLAGS__PRE(lvl, flags, dummy) WPP_LEVEL_FLAGS_PRE(lvl, flags) -#define WPP_LEVEL_FLAGS__POST(lvl, flags, dummy) WPP_LEVEL_FLAGS_POST(lvl, flags) - -#define WPP_LEVEL_FLAGS_EXP_ENABLED(LEVEL,FLAGS,EXP) \ - WPP_LEVEL_FLAGS_ENABLED (LEVEL,FLAGS) -#define WPP_LEVEL_FLAGS_EXP_LOGGER(LEVEL,FLAGS,EXP) \ - WPP_LEVEL_FLAGS_LOGGER (LEVEL,FLAGS) +#define WPP_LEVEL_FLAGS_EXP_LOGGER(LEVEL,FLAGS,EXP) WPP_LEVEL_FLAGS_LOGGER (LEVEL,FLAGS) +#define WPP_LEVEL_FLAGS_CTX_LOGGER(LEVEL,FLAGS,CTX) WPP_LEVEL_FLAGS_LOGGER (LEVEL,FLAGS) +#define WPP_LEVEL_FLAGS_CTX_EXP_LOGGER(LEVEL,FLAGS,CTX,EXP) WPP_LEVEL_FLAGS_LOGGER (LEVEL,FLAGS) #define WPP_LOGIPV6(x) WPP_LOGPAIR(16, (x)) @@ -89,10 +82,6 @@ // DEFINE_CPLX_TYPE(IPV6ADDR, WPP_LOGIPV6, IN6_ADDR *, ItemIPV6Addr, "s", _IPV6_, 0); // end_wpp -// begin_wpp config -// FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); -// end_wpp - // begin_wpp config // USEPREFIX(LogFuncEntry, "---> %!FUNC!"); // FUNC LogFuncEntry{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS); @@ -132,18 +121,22 @@ // end_wpp // begin_wpp config +// USEPREFIX (LogError, " "); // LogError{LEVEL=TRACE_LEVEL_ERROR}(FLAGS, MSG, ...); // end_wpp // begin_wpp config +// USEPREFIX (LogWarning, " "); // LogWarning{LEVEL=TRACE_LEVEL_WARNING}(FLAGS, MSG, ...); // end_wpp // begin_wpp config +// USEPREFIX (LogInfo, " "); // LogInfo{LEVEL=TRACE_LEVEL_INFORMATION}(FLAGS, MSG, ...); // end_wpp // begin_wpp config +// USEPREFIX (LogVerbose, " "); // LogVerbose{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS, MSG, ...); // end_wpp @@ -163,237 +156,237 @@ // ==API== // begin_wpp config -// USEPREFIX (otLogCritApi, "API%!SPACE!"); -// otLogCritApi{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_API}(MSG, ...); +// USEPREFIX (otLogCritApi, "[%p]API%!SPACE!", CTX); +// otLogCritApi{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_API}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnApi, "API%!SPACE!"); -// otLogWarnApi{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_API}(MSG, ...); +// USEPREFIX (otLogWarnApi, "[%p]API%!SPACE!", CTX); +// otLogWarnApi{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_API}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoApi, "API%!SPACE!"); -// otLogInfoApi{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_API}(MSG, ...); +// USEPREFIX (otLogInfoApi, "[%p]API%!SPACE!", CTX); +// otLogInfoApi{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_API}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgApi, "API%!SPACE!"); -// otLogDebgApi{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_API}(MSG, ...); +// USEPREFIX (otLogDebgApi, "[%p]API%!SPACE!", CTX); +// otLogDebgApi{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_API}(CTX, MSG, ...); // end_wpp // ==NCP== // begin_wpp config -// USEPREFIX (otLogCritNcp, "NCP%!SPACE!"); -// otLogCritNcp{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_NCP}(MSG, ...); +// USEPREFIX (otLogCritNcp, "[%p]NCP%!SPACE!", CTX); +// otLogCritNcp{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_NCP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnNcp, "NCP%!SPACE!"); -// otLogWarnNcp{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_NCP}(MSG, ...); +// USEPREFIX (otLogWarnNcp, "[%p]NCP%!SPACE!", CTX); +// otLogWarnNcp{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_NCP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoNcp, "NCP%!SPACE!"); -// otLogInfoNcp{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_NCP}(MSG, ...); +// USEPREFIX (otLogInfoNcp, "[%p]NCP%!SPACE!", CTX); +// otLogInfoNcp{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_NCP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgNcp, "NCP%!SPACE!"); -// otLogDebgNcp{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_NCP}(MSG, ...); +// USEPREFIX (otLogDebgNcp, "[%p]NCP%!SPACE!", CTX); +// otLogDebgNcp{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_NCP}(CTX, MSG, ...); // end_wpp // ==COAP== // begin_wpp config -// USEPREFIX (otLogCritMeshCoP, "COAP%!SPACE!"); -// otLogCritMeshCoP{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_COAP}(MSG, ...); +// USEPREFIX (otLogCritMeshCoP, "[%p]COAP%!SPACE!", CTX); +// otLogCritMeshCoP{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_COAP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnMeshCoP, "COAP%!SPACE!"); -// otLogWarnMeshCoP{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_COAP}(MSG, ...); +// USEPREFIX (otLogWarnMeshCoP, "[%p]COAP%!SPACE!", CTX); +// otLogWarnMeshCoP{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_COAP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoMeshCoP, "COAP%!SPACE!"); -// otLogInfoMeshCoP{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_COAP}(MSG, ...); +// USEPREFIX (otLogInfoMeshCoP, "[%p]COAP%!SPACE!", CTX); +// otLogInfoMeshCoP{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_COAP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgMeshCoP, "COAP%!SPACE!"); -// otLogDebgMeshCoP{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_COAP}(MSG, ...); +// USEPREFIX (otLogDebgMeshCoP, "[%p]COAP%!SPACE!", CTX); +// otLogDebgMeshCoP{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_COAP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogCertMeshCoP, "COAP%!SPACE!"); -// otLogCertMeshCoP{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_COAP}(MSG, ...); +// USEPREFIX (otLogCertMeshCoP, "[%p]COAP%!SPACE!", CTX); +// otLogCertMeshCoP{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_COAP}(CTX, MSG, ...); // end_wpp // ==MBEDTLS== // begin_wpp config -// USEPREFIX (otLogCritMbedTls, "MBED%!SPACE!"); -// otLogCritMbedTls{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_MBEDTLS}(MSG, ...); +// USEPREFIX (otLogCritMbedTls, "[%p]MBED%!SPACE!", CTX); +// otLogCritMbedTls{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_MBEDTLS}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnMbedTls, "MBED%!SPACE!"); -// otLogWarnMbedTls{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MBEDTLS}(MSG, ...); +// USEPREFIX (otLogWarnMbedTls, "[%p]MBED%!SPACE!", CTX); +// otLogWarnMbedTls{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MBEDTLS}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoMbedTls, "MBED%!SPACE!"); -// otLogInfoMbedTls{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_MBEDTLS}(MSG, ...); +// USEPREFIX (otLogInfoMbedTls, "[%p]MBED%!SPACE!", CTX); +// otLogInfoMbedTls{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_MBEDTLS}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgMbedTls, "MBED%!SPACE!"); -// otLogDebgMbedTls{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MBEDTLS}(MSG, ...); +// USEPREFIX (otLogDebgMbedTls, "[%p]MBED%!SPACE!", CTX); +// otLogDebgMbedTls{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MBEDTLS}(CTX, MSG, ...); // end_wpp // ==MLE== // begin_wpp config -// USEPREFIX (otLogCritMle, "MLE%!SPACE!"); -// otLogCritMle{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_MLE}(MSG, ...); +// USEPREFIX (otLogCritMle, "[%p]MLE%!SPACE!", CTX); +// otLogCritMle{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_MLE}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnMle, "MLE%!SPACE!"); -// otLogWarnMle{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MLE}(MSG, ...); +// USEPREFIX (otLogWarnMle, "[%p]MLE%!SPACE!", CTX); +// otLogWarnMle{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MLE}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnMleErr, "MLE%!SPACE!"); -// otLogWarnMleErr{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MLE}(EXP, MSG, ...); +// USEPREFIX (otLogWarnMleErr, "[%p]MLE%!SPACE!", CTX); +// otLogWarnMleErr{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MLE}(CTX, EXP, MSG, ...); // USESUFFIX(otLogWarnMleErr, ", %!otError!", EXP); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoMle, "MLE%!SPACE!"); -// otLogInfoMle{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_MLE}(MSG, ...); +// USEPREFIX (otLogInfoMle, "[%p]MLE%!SPACE!", CTX); +// otLogInfoMle{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_MLE}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgMle, "MLE%!SPACE!"); -// otLogDebgMle{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MLE}(MSG, ...); +// USEPREFIX (otLogDebgMle, "[%p]MLE%!SPACE!", CTX); +// otLogDebgMle{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MLE}(CTX, MSG, ...); // end_wpp // ==ARP== // begin_wpp config -// USEPREFIX (otLogCritArp, "ARP%!SPACE!"); -// otLogCritArp{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_ARP}(MSG, ...); +// USEPREFIX (otLogCritArp, "[%p]ARP%!SPACE!", CTX); +// otLogCritArp{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_ARP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnArp, "ARP%!SPACE!"); -// otLogWarnArp{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_ARP}(MSG, ...); +// USEPREFIX (otLogWarnArp, "[%p]ARP%!SPACE!", CTX); +// otLogWarnArp{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_ARP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoArp, "ARP%!SPACE!"); -// otLogInfoArp{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_ARP}(MSG, ...); +// USEPREFIX (otLogInfoArp, "[%p]ARP%!SPACE!", CTX); +// otLogInfoArp{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_ARP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgArp, "ARP%!SPACE!"); -// otLogDebgArp{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_ARP}(MSG, ...); +// USEPREFIX (otLogDebgArp, "[%p]ARP%!SPACE!", CTX); +// otLogDebgArp{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_ARP}(CTX, MSG, ...); // end_wpp // ==NETD== // begin_wpp config -// USEPREFIX (otLogCritNetData, "NETD%!SPACE!"); -// otLogCritNetData{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_NETD}(MSG, ...); +// USEPREFIX (otLogCritNetData, "[%p]NETD%!SPACE!", CTX); +// otLogCritNetData{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_NETD}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnNetData, "NETD%!SPACE!"); -// otLogWarnNetData{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_NETD}(MSG, ...); +// USEPREFIX (otLogWarnNetData, "[%p]NETD%!SPACE!", CTX); +// otLogWarnNetData{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_NETD}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoNetData, "NETD%!SPACE!"); -// otLogInfoNetData{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_NETD}(MSG, ...); +// USEPREFIX (otLogInfoNetData, "[%p]NETD%!SPACE!", CTX); +// otLogInfoNetData{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_NETD}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgNetData, "NETD%!SPACE!"); -// otLogDebgNetData{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_NETD}(MSG, ...); +// USEPREFIX (otLogDebgNetData, "[%p]NETD%!SPACE!", CTX); +// otLogDebgNetData{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_NETD}(CTX, MSG, ...); // end_wpp // ==ICMP== // begin_wpp config -// USEPREFIX (otLogCritIcmp, "ICMP%!SPACE!"); -// otLogCritIcmp{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_ICMP}(MSG, ...); +// USEPREFIX (otLogCritIcmp, "[%p]ICMP%!SPACE!", CTX); +// otLogCritIcmp{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_ICMP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnIcmp, "ICMP%!SPACE!"); -// otLogWarnIcmp{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_ICMP}(MSG, ...); +// USEPREFIX (otLogWarnIcmp, "[%p]ICMP%!SPACE!", CTX); +// otLogWarnIcmp{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_ICMP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoIcmp, "ICMP%!SPACE!"); -// otLogInfoIcmp{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_ICMP}(MSG, ...); +// USEPREFIX (otLogInfoIcmp, "[%p]ICMP%!SPACE!", CTX); +// otLogInfoIcmp{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_ICMP}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgIcmp, "ICMP%!SPACE!"); -// otLogDebgIcmp{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_ICMP}(MSG, ...); +// USEPREFIX (otLogDebgIcmp, "[%p]ICMP%!SPACE!", CTX); +// otLogDebgIcmp{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_ICMP}(CTX, MSG, ...); // end_wpp // ==IPV6== // begin_wpp config -// USEPREFIX (otLogCritIp6, "IPV6%!SPACE!"); -// otLogCritIp6{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_IPV6}(MSG, ...); +// USEPREFIX (otLogCritIp6, "[%p]IP6%!SPACE!", CTX); +// otLogCritIp6{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_IPV6}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnIp6, "IPV6%!SPACE!"); -// otLogWarnIp6{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_IPV6}(MSG, ...); +// USEPREFIX (otLogWarnIp6, "[%p]IP6%!SPACE!", CTX); +// otLogWarnIp6{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_IPV6}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoIp6, "IPV6%!SPACE!"); -// otLogInfoIp6{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_IPV6}(MSG, ...); +// USEPREFIX (otLogInfoIp6, "[%p]IP6%!SPACE!", CTX); +// otLogInfoIp6{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_IPV6}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgIp6, "IPV6%!SPACE!"); -// otLogDebgIp6{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_IPV6}(MSG, ...); +// USEPREFIX (otLogDebgIp6, "[%p]IP6%!SPACE!", CTX); +// otLogDebgIp6{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_IPV6}(CTX, MSG, ...); // end_wpp // ==MAC== // begin_wpp config -// USEPREFIX (otLogCritMac, "MAC%!SPACE!"); -// otLogCritMac{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_MAC}(MSG, ...); +// USEPREFIX (otLogCritMac, "[%p]MAC%!SPACE!", CTX); +// otLogCritMac{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_MAC}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnMac, "MAC%!SPACE!"); -// otLogWarnMac{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MAC}(MSG, ...); +// USEPREFIX (otLogWarnMac, "[%p]MAC%!SPACE!", CTX); +// otLogWarnMac{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_MAC}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoMac, "MAC%!SPACE!"); -// otLogInfoMac{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_MAC}(MSG, ...); +// USEPREFIX (otLogInfoMac, "[%p]MAC%!SPACE!", CTX); +// otLogInfoMac{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_MAC}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgMac, "MAC%!SPACE!"); -// otLogDebgMac{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MAC}(MSG, ...); +// USEPREFIX (otLogDebgMac, "[%p]MAC%!SPACE!", CTX); +// otLogDebgMac{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MAC}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgMacErr, "MAC%!SPACE!"); -// otLogDebgMacErr{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MAC}(EXP, MSG, ...); +// USEPREFIX (otLogDebgMacErr, "[%p]MAC%!SPACE!", CTX); +// otLogDebgMacErr{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_MAC}(CTX, EXP, MSG, ...); // USESUFFIX(otLogDebgMacErr, ", %!otError!", EXP); // end_wpp @@ -428,23 +421,23 @@ // ==MEM== // begin_wpp config -// USEPREFIX (otLogCritNetDiag, "NETDIAG%!SPACE!"); -// otLogCritNetDiag{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_NDIAG}(MSG, ...); +// USEPREFIX (otLogCritNetDiag, "[%p]NETD%!SPACE!", CTX); +// otLogCritNetDiag{LEVEL=TRACE_LEVEL_ERROR,FLAGS=OT_NDIAG}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogWarnNetDiag, "NETDIAG%!SPACE!"); -// otLogWarnNetDiag{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_NDIAG}(MSG, ...); +// USEPREFIX (otLogWarnNetDiag, "[%p]NETD%!SPACE!", CTX); +// otLogWarnNetDiag{LEVEL=TRACE_LEVEL_WARNING,FLAGS=OT_NDIAG}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogInfoNetDiag, "NETDIAG%!SPACE!"); -// otLogInfoNetDiag{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_NDIAG}(MSG, ...); +// USEPREFIX (otLogInfoNetDiag, "[%p]NETD%!SPACE!", CTX); +// otLogInfoNetDiag{LEVEL=TRACE_LEVEL_INFORMATION,FLAGS=OT_NDIAG}(CTX, MSG, ...); // end_wpp // begin_wpp config -// USEPREFIX (otLogDebgNetDiag, "NETDIAG%!SPACE!"); -// otLogDebgNetDiag{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_NDIAG}(MSG, ...); +// USEPREFIX (otLogDebgNetDiag, "[%p]NETD%!SPACE!", CTX); +// otLogDebgNetDiag{LEVEL=TRACE_LEVEL_VERBOSE,FLAGS=OT_NDIAG}(CTX, MSG, ...); // end_wpp // ==FUNC== diff --git a/src/core/api/instance_api.cpp b/src/core/api/instance_api.cpp index 808885356..5da57fc0b 100644 --- a/src/core/api/instance_api.cpp +++ b/src/core/api/instance_api.cpp @@ -102,7 +102,6 @@ otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize) otInstance *aInstance = NULL; otLogFuncEntry(); - otLogInfoApi("otInstanceInit"); VerifyOrExit(aInstanceBufferSize != NULL, ;); @@ -117,6 +116,8 @@ otInstance *otInstanceInit(void *aInstanceBuffer, size_t *aInstanceBufferSize) // Execute post constructor operations otInstancePostConstructor(aInstance); + otLogInfoApi(aInstance, "otInstance Initialized"); + exit: otLogFuncExit(); @@ -129,8 +130,6 @@ otInstance *otInstanceInit() { otLogFuncEntry(); - otLogInfoApi("otInstanceInit"); - VerifyOrExit(sInstance == NULL, ;); // Construct the context @@ -139,6 +138,8 @@ otInstance *otInstanceInit() // Execute post constructor operations otInstancePostConstructor(sInstance); + otLogInfoApi(sInstance, "otInstance Initialized"); + exit: otLogFuncExit(); diff --git a/src/core/common/logging.hpp b/src/core/common/logging.hpp index c6da9b51b..287101225 100644 --- a/src/core/common/logging.hpp +++ b/src/core/common/logging.hpp @@ -169,15 +169,15 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_API == 1 -#define otLogCritApi(aFormat, ...) otLogCrit(kLogRegionApi, aFormat, ## __VA_ARGS__) -#define otLogWarnApi(aFormat, ...) otLogWarn(kLogRegionApi, aFormat, ## __VA_ARGS__) -#define otLogInfoApi(aFormat, ...) otLogInfo(kLogRegionApi, aFormat, ## __VA_ARGS__) -#define otLogDebgApi(aFormat, ...) otLogDebg(kLogRegionApi, aFormat, ## __VA_ARGS__) +#define otLogCritApi(aInstance, aFormat, ...) otLogCrit(kLogRegionApi, aFormat, ## __VA_ARGS__) +#define otLogWarnApi(aInstance, aFormat, ...) otLogWarn(kLogRegionApi, aFormat, ## __VA_ARGS__) +#define otLogInfoApi(aInstance, aFormat, ...) otLogInfo(kLogRegionApi, aFormat, ## __VA_ARGS__) +#define otLogDebgApi(aInstance, aFormat, ...) otLogDebg(kLogRegionApi, aFormat, ## __VA_ARGS__) #else -#define otLogCritApi(aFormat, ...) -#define otLogWarnApi(aFormat, ...) -#define otLogInfoApi(aFormat, ...) -#define otLogDebgApi(aFormat, ...) +#define otLogCritApi(aInstance, aFormat, ...) +#define otLogWarnApi(aInstance, aFormat, ...) +#define otLogInfoApi(aInstance, aFormat, ...) +#define otLogDebgApi(aInstance, aFormat, ...) #endif /** @@ -220,21 +220,21 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_MLE == 1 -#define otLogCritMeshCoP(aFormat, ...) otLogCrit(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) -#define otLogWarnMeshCoP(aFormat, ...) otLogWarn(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) -#define otLogInfoMeshCoP(aFormat, ...) otLogInfo(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) -#define otLogDebgMeshCoP(aFormat, ...) otLogDebg(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) +#define otLogCritMeshCoP(aInstance, aFormat, ...) otLogCrit(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) +#define otLogWarnMeshCoP(aInstance, aFormat, ...) otLogWarn(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) +#define otLogInfoMeshCoP(aInstance, aFormat, ...) otLogInfo(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) +#define otLogDebgMeshCoP(aInstance, aFormat, ...) otLogDebg(kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) #else -#define otLogCritMeshCoP(aFormat, ...) -#define otLogWarnMeshCoP(aFormat, ...) -#define otLogInfoMeshCoP(aFormat, ...) -#define otLogDebgMeshCoP(aFormat, ...) +#define otLogCritMeshCoP(aInstance, aFormat, ...) +#define otLogWarnMeshCoP(aInstance, aFormat, ...) +#define otLogInfoMeshCoP(aInstance, aFormat, ...) +#define otLogDebgMeshCoP(aInstance, aFormat, ...) #endif -#define otLogCritMbedTls(aFormat, ...) otLogCritMeshCoP(aFormat, ## __VA_ARGS__) -#define otLogWarnMbedTls(aFormat, ...) otLogWarnMeshCoP(aFormat, ## __VA_ARGS__) -#define otLogInfoMbedTls(aFormat, ...) otLogInfoMeshCoP(aFormat, ## __VA_ARGS__) -#define otLogDebgMbedTls(aFormat, ...) otLogDebgMeshCoP(aFormat, ## __VA_ARGS__) +#define otLogCritMbedTls(aInstance, aFormat, ...) otLogCritMeshCoP(aInstance, aFormat, ## __VA_ARGS__) +#define otLogWarnMbedTls(aInstance, aFormat, ...) otLogWarnMeshCoP(aInstance, aFormat, ## __VA_ARGS__) +#define otLogInfoMbedTls(aInstance, aFormat, ...) otLogInfoMeshCoP(aInstance, aFormat, ## __VA_ARGS__) +#define otLogDebgMbedTls(aInstance, aFormat, ...) otLogDebgMeshCoP(aInstance, aFormat, ## __VA_ARGS__) /** * @def otLogCritMle @@ -276,17 +276,17 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_MLE == 1 -#define otLogCritMle(aFormat, ...) otLogCrit(kLogRegionMle, aFormat, ## __VA_ARGS__) -#define otLogWarnMle(aFormat, ...) otLogWarn(kLogRegionMle, aFormat, ## __VA_ARGS__) +#define otLogCritMle(aInstance, aFormat, ...) otLogCrit(kLogRegionMle, aFormat, ## __VA_ARGS__) +#define otLogWarnMle(aInstance, aFormat, ...) otLogWarn(kLogRegionMle, aFormat, ## __VA_ARGS__) #define otLogWarnMleErr(aError, aFormat, ...) otLogWarn(kLogRegionMac, "Error %s: " aFormat, otThreadErrorToString(aError), ## __VA_ARGS__) -#define otLogInfoMle(aFormat, ...) otLogInfo(kLogRegionMle, aFormat, ## __VA_ARGS__) -#define otLogDebgMle(aFormat, ...) otLogDebg(kLogRegionMle, aFormat, ## __VA_ARGS__) +#define otLogInfoMle(aInstance, aFormat, ...) otLogInfo(kLogRegionMle, aFormat, ## __VA_ARGS__) +#define otLogDebgMle(aInstance, aFormat, ...) otLogDebg(kLogRegionMle, aFormat, ## __VA_ARGS__) #else -#define otLogCritMle(aFormat, ...) -#define otLogWarnMle(aFormat, ...) +#define otLogCritMle(aInstance, aFormat, ...) +#define otLogWarnMle(aInstance, aFormat, ...) #define otLogWarnMleErr(aError, aFormat, ...) -#define otLogInfoMle(aFormat, ...) -#define otLogDebgMle(aFormat, ...) +#define otLogInfoMle(aInstance, aFormat, ...) +#define otLogDebgMle(aInstance, aFormat, ...) #endif /** @@ -329,15 +329,15 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_ARP == 1 -#define otLogCritArp(aFormat, ...) otLogCrit(kLogRegionArp, aFormat, ## __VA_ARGS__) -#define otLogWarnArp(aFormat, ...) otLogWarn(kLogRegionArp, aFormat, ## __VA_ARGS__) -#define otLogInfoArp(aFormat, ...) otLogInfo(kLogRegionArp, aFormat, ## __VA_ARGS__) -#define otLogDebgArp(aFormat, ...) otLogDebg(kLogRegionArp, aFormat, ## __VA_ARGS__) +#define otLogCritArp(aInstance, aFormat, ...) otLogCrit(kLogRegionArp, aFormat, ## __VA_ARGS__) +#define otLogWarnArp(aInstance, aFormat, ...) otLogWarn(kLogRegionArp, aFormat, ## __VA_ARGS__) +#define otLogInfoArp(aInstance, aFormat, ...) otLogInfo(kLogRegionArp, aFormat, ## __VA_ARGS__) +#define otLogDebgArp(aInstance, aFormat, ...) otLogDebg(kLogRegionArp, aFormat, ## __VA_ARGS__) #else -#define otLogCritArp(aFormat, ...) -#define otLogWarnArp(aFormat, ...) -#define otLogInfoArp(aFormat, ...) -#define otLogDebgArp(aFormat, ...) +#define otLogCritArp(aInstance, aFormat, ...) +#define otLogWarnArp(aInstance, aFormat, ...) +#define otLogInfoArp(aInstance, aFormat, ...) +#define otLogDebgArp(aInstance, aFormat, ...) #endif /** @@ -380,15 +380,15 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_NETDATA == 1 -#define otLogCritNetData(aFormat, ...) otLogCrit(kLogRegionNetData, aFormat, ## __VA_ARGS__) -#define otLogWarnNetData(aFormat, ...) otLogWarn(kLogRegionNetData, aFormat, ## __VA_ARGS__) -#define otLogInfoNetData(aFormat, ...) otLogInfo(kLogRegionNetData, aFormat, ## __VA_ARGS__) -#define otLogDebgNetData(aFormat, ...) otLogDebg(kLogRegionNetData, aFormat, ## __VA_ARGS__) +#define otLogCritNetData(aInstance, aFormat, ...) otLogCrit(kLogRegionNetData, aFormat, ## __VA_ARGS__) +#define otLogWarnNetData(aInstance, aFormat, ...) otLogWarn(kLogRegionNetData, aFormat, ## __VA_ARGS__) +#define otLogInfoNetData(aInstance, aFormat, ...) otLogInfo(kLogRegionNetData, aFormat, ## __VA_ARGS__) +#define otLogDebgNetData(aInstance, aFormat, ...) otLogDebg(kLogRegionNetData, aFormat, ## __VA_ARGS__) #else -#define otLogCritNetData(aFormat, ...) -#define otLogWarnNetData(aFormat, ...) -#define otLogInfoNetData(aFormat, ...) -#define otLogDebgNetData(aFormat, ...) +#define otLogCritNetData(aInstance, aFormat, ...) +#define otLogWarnNetData(aInstance, aFormat, ...) +#define otLogInfoNetData(aInstance, aFormat, ...) +#define otLogDebgNetData(aInstance, aFormat, ...) #endif /** @@ -431,15 +431,15 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_ICMP == 1 -#define otLogCritIcmp(aFormat, ...) otLogCrit(kLogRegionIcmp, aFormat, ## __VA_ARGS__) -#define otLogWarnIcmp(aFormat, ...) otLogWarn(kLogRegionIcmp, aFormat, ## __VA_ARGS__) -#define otLogInfoIcmp(aFormat, ...) otLogInfo(kLogRegionIcmp, aFormat, ## __VA_ARGS__) -#define otLogDebgIcmp(aFormat, ...) otLogDebg(kLogRegionIcmp, aFormat, ## __VA_ARGS__) +#define otLogCritIcmp(aInstance, aFormat, ...) otLogCrit(kLogRegionIcmp, aFormat, ## __VA_ARGS__) +#define otLogWarnIcmp(aInstance, aFormat, ...) otLogWarn(kLogRegionIcmp, aFormat, ## __VA_ARGS__) +#define otLogInfoIcmp(aInstance, aFormat, ...) otLogInfo(kLogRegionIcmp, aFormat, ## __VA_ARGS__) +#define otLogDebgIcmp(aInstance, aFormat, ...) otLogDebg(kLogRegionIcmp, aFormat, ## __VA_ARGS__) #else -#define otLogCritIcmp(aFormat, ...) -#define otLogWarnIcmp(aFormat, ...) -#define otLogInfoIcmp(aFormat, ...) -#define otLogDebgIcmp(aFormat, ...) +#define otLogCritIcmp(aInstance, aFormat, ...) +#define otLogWarnIcmp(aInstance, aFormat, ...) +#define otLogInfoIcmp(aInstance, aFormat, ...) +#define otLogDebgIcmp(aInstance, aFormat, ...) #endif /** @@ -482,15 +482,15 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_IP6 == 1 -#define otLogCritIp6(aFormat, ...) otLogCrit(kLogRegionIp6, aFormat, ## __VA_ARGS__) -#define otLogWarnIp6(aFormat, ...) otLogWarn(kLogRegionIp6, aFormat, ## __VA_ARGS__) -#define otLogInfoIp6(aFormat, ...) otLogInfo(kLogRegionIp6, aFormat, ## __VA_ARGS__) -#define otLogDebgIp6(aFormat, ...) otLogDebg(kLogRegionIp6, aFormat, ## __VA_ARGS__) +#define otLogCritIp6(aInstance, aFormat, ...) otLogCrit(kLogRegionIp6, aFormat, ## __VA_ARGS__) +#define otLogWarnIp6(aInstance, aFormat, ...) otLogWarn(kLogRegionIp6, aFormat, ## __VA_ARGS__) +#define otLogInfoIp6(aInstance, aFormat, ...) otLogInfo(kLogRegionIp6, aFormat, ## __VA_ARGS__) +#define otLogDebgIp6(aInstance, aFormat, ...) otLogDebg(kLogRegionIp6, aFormat, ## __VA_ARGS__) #else -#define otLogCritIp6(aFormat, ...) -#define otLogWarnIp6(aFormat, ...) -#define otLogInfoIp6(aFormat, ...) -#define otLogDebgIp6(aFormat, ...) +#define otLogCritIp6(aInstance, aFormat, ...) +#define otLogWarnIp6(aInstance, aFormat, ...) +#define otLogInfoIp6(aInstance, aFormat, ...) +#define otLogDebgIp6(aInstance, aFormat, ...) #endif /** @@ -533,16 +533,16 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_MAC == 1 -#define otLogCritMac(aFormat, ...) otLogCrit(kLogRegionMac, aFormat, ## __VA_ARGS__) -#define otLogWarnMac(aFormat, ...) otLogWarn(kLogRegionMac, aFormat, ## __VA_ARGS__) -#define otLogInfoMac(aFormat, ...) otLogInfo(kLogRegionMac, aFormat, ## __VA_ARGS__) -#define otLogDebgMac(aFormat, ...) otLogDebg(kLogRegionMac, aFormat, ## __VA_ARGS__) +#define otLogCritMac(aInstance, aFormat, ...) otLogCrit(kLogRegionMac, aFormat, ## __VA_ARGS__) +#define otLogWarnMac(aInstance, aFormat, ...) otLogWarn(kLogRegionMac, aFormat, ## __VA_ARGS__) +#define otLogInfoMac(aInstance, aFormat, ...) otLogInfo(kLogRegionMac, aFormat, ## __VA_ARGS__) +#define otLogDebgMac(aInstance, aFormat, ...) otLogDebg(kLogRegionMac, aFormat, ## __VA_ARGS__) #define otLogDebgMacErr(aError, aFormat, ...) otLogWarn(kLogRegionMac, "Error %s: " aFormat, otThreadErrorToString(aError), ## __VA_ARGS__) #else -#define otLogCritMac(aFormat, ...) -#define otLogWarnMac(aFormat, ...) -#define otLogInfoMac(aFormat, ...) -#define otLogDebgMac(aFormat, ...) +#define otLogCritMac(aInstance, aFormat, ...) +#define otLogWarnMac(aInstance, aFormat, ...) +#define otLogInfoMac(aInstance, aFormat, ...) +#define otLogDebgMac(aInstance, aFormat, ...) #define otLogDebgMacErr(aError, aFormat, ...) #endif @@ -637,15 +637,15 @@ extern "C" { * */ #if OPENTHREAD_CONFIG_LOG_NETDIAG == 1 -#define otLogCritNetDiag(aFormat, ...) otLogCrit(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) -#define otLogWarnNetDiag(aFormat, ...) otLogWarn(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) -#define otLogInfoNetDiag(aFormat, ...) otLogInfo(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) -#define otLogDebgNetDiag(aFormat, ...) otLogDebg(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) +#define otLogCritNetDiag(aInstance, aFormat, ...) otLogCrit(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) +#define otLogWarnNetDiag(aInstance, aFormat, ...) otLogWarn(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) +#define otLogInfoNetDiag(aInstance, aFormat, ...) otLogInfo(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) +#define otLogDebgNetDiag(aInstance, aFormat, ...) otLogDebg(kLogRegionNetDiag, aFormat, ## __VA_ARGS__) #else -#define otLogCritNetDiag(aFormat, ...) -#define otLogWarnNetDiag(aFormat, ...) -#define otLogInfoNetDiag(aFormat, ...) -#define otLogDebgNetDiag(aFormat, ...) +#define otLogCritNetDiag(aInstance, aFormat, ...) +#define otLogWarnNetDiag(aInstance, aFormat, ...) +#define otLogInfoNetDiag(aInstance, aFormat, ...) +#define otLogDebgNetDiag(aInstance, aFormat, ...) #endif /** @@ -658,9 +658,9 @@ extern "C" { * */ #if OPENTHREAD_ENABLE_CERT_LOG -#define otLogCertMeshCoP(aFormat, ...) _otLogFormatter(kLogLevelNone, kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) +#define otLogCertMeshCoP(aInstance, aFormat, ...) _otLogFormatter(kLogLevelNone, kLogRegionMeshCoP, aFormat, ## __VA_ARGS__) #else -#define otLogCertMeshCoP(aFormat, ...) +#define otLogCertMeshCoP(aInstance, aFormat, ...) #endif /** diff --git a/src/core/common/message.cpp b/src/core/common/message.cpp index 5e562952c..5e6391332 100644 --- a/src/core/common/message.cpp +++ b/src/core/common/message.cpp @@ -105,29 +105,26 @@ Buffer *MessagePool::NewBuffer(void) Buffer *buffer = NULL; #if OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT - buffer = static_cast(otPlatMessagePoolNew(mInstance)); - if (buffer == NULL) - { - otLogInfoMac("No available message buffer"); - } + buffer = static_cast(otPlatMessagePoolNew(mInstance)); #else - if (mFreeBuffers == NULL) + if (mFreeBuffers != NULL) { - otLogInfoMac("No available message buffer"); - ExitNow(); + buffer = mFreeBuffers; + mFreeBuffers = mFreeBuffers->GetNextBuffer(); + buffer->SetNextBuffer(NULL); + mNumFreeBuffers--; } - buffer = mFreeBuffers; - mFreeBuffers = mFreeBuffers->GetNextBuffer(); - buffer->SetNextBuffer(NULL); - mNumFreeBuffers--; - -exit: #endif + if (buffer == NULL) + { + otLogInfoMem("No available message buffer"); + } + return buffer; } diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index fd8978695..ef12124b6 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -108,7 +108,7 @@ void Mac::StartCsmaBackoff(void) delay.mMs = backoff / 1000UL; delay.mUs = backoff - (delay.mMs * 1000UL); - otPlatUsecAlarmStartAt(mNetif.GetInstance(), &now, &delay, &Mac::HandleBeginTransmit, this); + otPlatUsecAlarmStartAt(GetInstance(), &now, &delay, &Mac::HandleBeginTransmit, this); #else // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER mBackoffTimer.Start(backoff / 1000UL); #endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_BACKOFF_TIMER @@ -173,12 +173,17 @@ Mac::Mac(ThreadNetif &aThreadNetif): mPcapCallback = NULL; mPcapCallbackContext = NULL; - otPlatRadioEnable(mNetif.GetInstance()); - mTxFrame = static_cast(otPlatRadioGetTransmitBuffer(mNetif.GetInstance())); + otPlatRadioEnable(GetInstance()); + mTxFrame = static_cast(otPlatRadioGetTransmitBuffer(GetInstance())); mKeyIdMode2FrameCounter = 0; } +otInstance *Mac::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError Mac::ActiveScan(uint32_t aScanChannels, uint16_t aScanDuration, ActiveScanHandler aHandler, void *aContext) { ThreadError error; @@ -256,7 +261,7 @@ void Mac::StartEnergyScan(void) { mState = kStateEnergyScan; - if (!(otPlatRadioGetCaps(mNetif.GetInstance()) & kRadioCapsEnergyScan)) + if (!(otPlatRadioGetCaps(GetInstance()) & kRadioCapsEnergyScan)) { mEnergyScanCurrentMaxRssi = kInvalidRssiValue; mMacTimer.Start(mScanDuration); @@ -265,7 +270,7 @@ void Mac::StartEnergyScan(void) } else { - ThreadError error = otPlatRadioEnergyScan(mNetif.GetInstance(), mScanChannel, mScanDuration); + ThreadError error = otPlatRadioEnergyScan(GetInstance(), mScanChannel, mScanDuration); if (error != kThreadError_None) { @@ -313,7 +318,7 @@ void Mac::EnergyScanDone(int8_t aEnergyScanMaxRssi) // and start the next transmission task if (mScanChannels == 0 || mScanChannel > kPhyMaxChannel) { - otPlatRadioReceive(mNetif.GetInstance(), mChannel); + otPlatRadioReceive(GetInstance(), mChannel); mEnergyScanHandler(mScanContext, NULL); ScheduleNextTransmission(); ExitNow(); @@ -339,7 +344,7 @@ void Mac::HandleEnergyScanSampleRssi(void) VerifyOrExit(mState == kStateEnergyScan, ;); - rssi = otPlatRadioGetRssi(mNetif.GetInstance()); + rssi = otPlatRadioGetRssi(GetInstance()); if (rssi != kInvalidRssiValue) { @@ -404,7 +409,7 @@ void Mac::SetExtAddress(const ExtAddress &aExtAddress) buf[i] = aExtAddress.m8[7 - i]; } - otPlatRadioSetExtendedAddress(mNetif.GetInstance(), buf); + otPlatRadioSetExtendedAddress(GetInstance(), buf); mExtAddress = aExtAddress; otLogFuncExit(); @@ -417,7 +422,7 @@ void Mac::GetHashMacAddress(ExtAddress *aHashMacAddress) otLogFuncEntry(); - otPlatRadioGetIeeeEui64(mNetif.GetInstance(), buf); + otPlatRadioGetIeeeEui64(GetInstance(), buf); sha256.Start(); sha256.Update(buf, OT_EXT_ADDRESS_SIZE); sha256.Finish(buf); @@ -437,7 +442,7 @@ ThreadError Mac::SetShortAddress(ShortAddress aShortAddress) { otLogFuncEntryMsg("%d", aShortAddress); mShortAddress = aShortAddress; - otPlatRadioSetShortAddress(mNetif.GetInstance(), aShortAddress); + otPlatRadioSetShortAddress(GetInstance(), aShortAddress); otLogFuncExit(); return kThreadError_None; } @@ -500,7 +505,7 @@ ThreadError Mac::SetPanId(PanId aPanId) { otLogFuncEntryMsg("%d", aPanId); mPanId = aPanId; - otPlatRadioSetPanId(mNetif.GetInstance(), mPanId); + otPlatRadioSetPanId(GetInstance(), mPanId); otLogFuncExit(); return kThreadError_None; } @@ -549,17 +554,17 @@ void Mac::NextOperation(void) { case kStateActiveScan: case kStateEnergyScan: - otPlatRadioReceive(mNetif.GetInstance(), mScanChannel); + otPlatRadioReceive(GetInstance(), mScanChannel); break; default: - if (mRxOnWhenIdle || mReceiveTimer.IsRunning() || otPlatRadioGetPromiscuous(mNetif.GetInstance())) + if (mRxOnWhenIdle || mReceiveTimer.IsRunning() || otPlatRadioGetPromiscuous(GetInstance())) { - otPlatRadioReceive(mNetif.GetInstance(), mChannel); + otPlatRadioReceive(GetInstance(), mChannel); } else { - otPlatRadioSleep(mNetif.GetInstance()); + otPlatRadioSleep(GetInstance()); } break; @@ -628,7 +633,7 @@ void Mac::SendBeaconRequest(Frame &aFrame) aFrame.SetDstAddr(kShortAddrBroadcast); aFrame.SetCommandId(Frame::kMacCmdBeaconRequest); - otLogDebgMac("Sent Beacon Request"); + otLogDebgMac(GetInstance(), "Sent Beacon Request"); } void Mac::SendBeacon(Frame &aFrame) @@ -664,7 +669,7 @@ void Mac::SendBeacon(Frame &aFrame) aFrame.SetPayloadLength(sizeof(*beacon)); - otLogDebgMac("Sent Beacon"); + otLogDebgMac(GetInstance(), "Sent Beacon"); } void Mac::HandleBeginTransmit(void *aContext) @@ -770,7 +775,7 @@ void Mac::HandleBeginTransmit(void) switch (mState) { case kStateActiveScan: - otPlatRadioSetPanId(mNetif.GetInstance(), kPanIdBroadcast); + otPlatRadioSetPanId(GetInstance(), kPanIdBroadcast); sendFrame.SetChannel(mScanChannel); SendBeaconRequest(sendFrame); sendFrame.SetSequence(0); @@ -808,15 +813,15 @@ void Mac::HandleBeginTransmit(void) } } - error = otPlatRadioReceive(mNetif.GetInstance(), sendFrame.GetChannel()); + error = otPlatRadioReceive(GetInstance(), sendFrame.GetChannel()); assert(error == kThreadError_None); - error = otPlatRadioTransmit(mNetif.GetInstance(), static_cast(&sendFrame)); + error = otPlatRadioTransmit(GetInstance(), static_cast(&sendFrame)); assert(error == kThreadError_None); - if (sendFrame.GetAckRequest() && !(otPlatRadioGetCaps(mNetif.GetInstance()) & kRadioCapsAckTimeout)) + if (sendFrame.GetAckRequest() && !(otPlatRadioGetCaps(GetInstance()) & kRadioCapsAckTimeout)) { mMacTimer.Start(kAckTimeout); - otLogDebgMac("ack timer start"); + otLogDebgMac(GetInstance(), "ack timer start"); } if (mPcapCallback) @@ -936,8 +941,8 @@ void Mac::HandleMacTimer(void) if (mScanChannels == 0 || mScanChannel > kPhyMaxChannel) { - otPlatRadioReceive(mNetif.GetInstance(), mChannel); - otPlatRadioSetPanId(mNetif.GetInstance(), mPanId); + otPlatRadioReceive(GetInstance(), mChannel); + otPlatRadioSetPanId(GetInstance(), mPanId); mActiveScanHandler(mScanContext, NULL); ScheduleNextTransmission(); ExitNow(); @@ -953,8 +958,8 @@ void Mac::HandleMacTimer(void) break; case kStateTransmitData: - otLogDebgMac("ack timer fired"); - otPlatRadioReceive(mNetif.GetInstance(), mChannel); + otLogDebgMac(GetInstance(), "ack timer fired"); + otPlatRadioReceive(GetInstance(), mChannel); mCounters.mTxTotal++; mTxFrame->GetDstAddr(addr); @@ -989,7 +994,7 @@ void Mac::HandleReceiveTimer(void *aContext) void Mac::HandleReceiveTimer(void) { - otLogDebgMac("data poll timeout!"); + otLogDebgMac(GetInstance(), "data poll timeout!"); if (mState == kStateIdle) { @@ -1123,7 +1128,7 @@ ThreadError Mac::ProcessReceiveSecurity(Frame &aFrame, const Address &aSrcAddr, aFrame.GetSecurityLevel(securityLevel); aFrame.GetFrameCounter(frameCounter); - otLogDebgMac("Frame counter %u", frameCounter); + otLogDebgMac(GetInstance(), "Frame counter %u", frameCounter); aFrame.GetKeyIdMode(keyIdMode); @@ -1293,11 +1298,11 @@ void Mac::ReceiveDoneTask(Frame *aFrame, ThreadError aError) break; case sizeof(ShortAddress): - otLogDebgMac("Received from short address %x", srcaddr.mShortAddress); + otLogDebgMac(GetInstance(), "Received from short address %x", srcaddr.mShortAddress); if (neighbor == NULL) { - otLogDebgMac("drop not neighbor"); + otLogDebgMac(GetInstance(), "drop not neighbor"); ExitNow(error = kThreadError_UnknownNeighbor); } @@ -1315,7 +1320,7 @@ void Mac::ReceiveDoneTask(Frame *aFrame, ThreadError aError) // Duplicate Address Protection if (memcmp(&srcaddr.mExtAddress, &mExtAddress, sizeof(srcaddr.mExtAddress)) == 0) { - otLogDebgMac("duplicate address received"); + otLogDebgMac(GetInstance(), "duplicate address received"); ExitNow(error = kThreadError_InvalidSourceAddress); } @@ -1420,7 +1425,7 @@ void Mac::ReceiveDoneTask(Frame *aFrame, ThreadError aError) if (!mRxOnWhenIdle && dstaddr.mLength != 0) { mReceiveTimer.Stop(); - otPlatRadioSleep(mNetif.GetInstance()); + otPlatRadioSleep(GetInstance()); } switch (aFrame->GetType()) @@ -1466,7 +1471,7 @@ exit: if (error != kThreadError_None) { - otLogDebgMacErr(error, "Dropping received frame"); + otLogDebgMacErr(GetInstance(), error, "Dropping received frame"); switch (error) { @@ -1520,7 +1525,7 @@ ThreadError Mac::HandleMacCommand(Frame &aFrame) { case Frame::kMacCmdBeaconRequest: mCounters.mRxBeaconRequest++; - otLogDebgMac("Received Beacon Request"); + otLogDebgMac(GetInstance(), "Received Beacon Request"); mTransmitBeacon = true; @@ -1554,12 +1559,12 @@ void Mac::SetPcapCallback(otLinkPcapCallback aPcapCallback, void *aCallbackConte bool Mac::IsPromiscuous(void) { - return otPlatRadioGetPromiscuous(mNetif.GetInstance()); + return otPlatRadioGetPromiscuous(GetInstance()); } void Mac::SetPromiscuous(bool aPromiscuous) { - otPlatRadioSetPromiscuous(mNetif.GetInstance(), aPromiscuous); + otPlatRadioSetPromiscuous(GetInstance(), aPromiscuous); if (mState == kStateIdle) { @@ -1573,12 +1578,12 @@ bool Mac::RadioSupportsCsmaBackoff(void) * 1) Radio provides the CSMA backoff capability (i.e., `kRadioCapsCsmaBackOff` bit is set) or; * 2) It provides `kRadioCapsTransmitRetries` which indicates support for MAC retries along with CSMA backoff. */ - return (otPlatRadioGetCaps(mNetif.GetInstance()) & (kRadioCapsTransmitRetries | kRadioCapsCsmaBackOff)) != 0; + return (otPlatRadioGetCaps(GetInstance()) & (kRadioCapsTransmitRetries | kRadioCapsCsmaBackOff)) != 0; } bool Mac::RadioSupportsRetries(void) { - return (otPlatRadioGetCaps(mNetif.GetInstance()) & kRadioCapsTransmitRetries) != 0; + return (otPlatRadioGetCaps(GetInstance()) & kRadioCapsTransmitRetries) != 0; } Whitelist &Mac::GetWhitelist(void) @@ -1617,8 +1622,8 @@ otMacCounters &Mac::GetCounters(void) void Mac::EnableSrcMatch(bool aEnable) { - otPlatRadioEnableSrcMatch(mNetif.GetInstance(), aEnable); - otLogDebgMac("Enable SrcMatch -- %d(0:Dis, 1:En)", aEnable); + otPlatRadioEnableSrcMatch(GetInstance(), aEnable); + otLogDebgMac(GetInstance(), "Enable SrcMatch -- %d(0:Dis, 1:En)", aEnable); } ThreadError Mac::AddSrcMatchEntry(Address &aAddr) @@ -1627,8 +1632,8 @@ ThreadError Mac::AddSrcMatchEntry(Address &aAddr) if (aAddr.mLength == 2) { - error = otPlatRadioAddSrcMatchShortEntry(mNetif.GetInstance(), aAddr.mShortAddress); - otLogDebgMac("Adding short address: 0x%x -- %d (0:Ok, 3:NoBufs)", aAddr.mShortAddress, error); + error = otPlatRadioAddSrcMatchShortEntry(GetInstance(), aAddr.mShortAddress); + otLogDebgMac(GetInstance(), "Adding short address: 0x%x -- %d (0:Ok, 3:NoBufs)", aAddr.mShortAddress, error); } else { @@ -1639,8 +1644,8 @@ ThreadError Mac::AddSrcMatchEntry(Address &aAddr) buf[i] = aAddr.mExtAddress.m8[7 - i]; } - error = otPlatRadioAddSrcMatchExtEntry(mNetif.GetInstance(), buf); - otLogDebgMac("Adding extended address: 0x%02x%02x%02x%02x%02x%02x%02x%02x -- %d (0:OK, 3:NoBufs)", + error = otPlatRadioAddSrcMatchExtEntry(GetInstance(), buf); + otLogDebgMac(GetInstance(), "Adding extended address: 0x%02x%02x%02x%02x%02x%02x%02x%02x -- %d (0:OK, 3:NoBufs)", buf[7], buf[6], buf[5], buf[4], buf[3], buf[2], buf[1], buf[0], error); } @@ -1653,8 +1658,8 @@ ThreadError Mac::ClearSrcMatchEntry(Address &aAddr) if (aAddr.mLength == 2) { - error = otPlatRadioClearSrcMatchShortEntry(mNetif.GetInstance(), aAddr.mShortAddress); - otLogDebgMac("Clearing short address: 0x%x -- %d (0:OK, 10:NoAddress)", aAddr.mShortAddress, error); + error = otPlatRadioClearSrcMatchShortEntry(GetInstance(), aAddr.mShortAddress); + otLogDebgMac(GetInstance(), "Clearing short address: 0x%x -- %d (0:OK, 10:NoAddress)", aAddr.mShortAddress, error); } else { @@ -1665,8 +1670,8 @@ ThreadError Mac::ClearSrcMatchEntry(Address &aAddr) buf[i] = aAddr.mExtAddress.m8[7 - i]; } - error = otPlatRadioClearSrcMatchExtEntry(mNetif.GetInstance(), buf); - otLogDebgMac("Clearing extended address: 0x%02x%02x%02x%02x%02x%02x%02x%02x -- %d (0:OK, 10:NoAddress)", + error = otPlatRadioClearSrcMatchExtEntry(GetInstance(), buf); + otLogDebgMac(GetInstance(), "Clearing extended address: 0x%02x%02x%02x%02x%02x%02x%02x%02x -- %d (0:OK, 10:NoAddress)", buf[7], buf[6], buf[5], buf[4], buf[3], buf[2], buf[1], buf[0], error); } @@ -1675,9 +1680,9 @@ ThreadError Mac::ClearSrcMatchEntry(Address &aAddr) void Mac::ClearSrcMatchEntries() { - otPlatRadioClearSrcMatchShortEntries(mNetif.GetInstance()); - otPlatRadioClearSrcMatchExtEntries(mNetif.GetInstance()); - otLogDebgMac("Clearing source match table"); + otPlatRadioClearSrcMatchShortEntries(GetInstance()); + otPlatRadioClearSrcMatchExtEntries(GetInstance()); + otLogDebgMac(GetInstance(), "Clearing source match table"); } diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index ce77fec7c..e52277a09 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -191,6 +191,14 @@ public: */ explicit Mac(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This function pointer is called on receiving an IEEE 802.15.4 Beacon during an Active Scan. * diff --git a/src/core/meshcop/announce_begin_client.cpp b/src/core/meshcop/announce_begin_client.cpp index 16a885eff..c79bf21a7 100644 --- a/src/core/meshcop/announce_begin_client.cpp +++ b/src/core/meshcop/announce_begin_client.cpp @@ -57,6 +57,11 @@ AnnounceBeginClient::AnnounceBeginClient(ThreadNetif &aThreadNetif) : { } +otInstance *AnnounceBeginClient::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod, const Ip6::Address &aAddress) { @@ -100,7 +105,7 @@ ThreadError AnnounceBeginClient::SendRequest(uint32_t aChannelMask, uint8_t aCou SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent announce begin query"); + otLogInfoMeshCoP(GetInstance(), "sent announce begin query"); exit: diff --git a/src/core/meshcop/announce_begin_client.hpp b/src/core/meshcop/announce_begin_client.hpp index 0ad0c33e9..4630b8b39 100644 --- a/src/core/meshcop/announce_begin_client.hpp +++ b/src/core/meshcop/announce_begin_client.hpp @@ -59,6 +59,14 @@ public: */ AnnounceBeginClient(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method sends a Announce Begin message. * diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 2a53b28cd..fa1930094 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -84,6 +84,11 @@ Commissioner::Commissioner(ThreadNetif &aThreadNetif): mNetif.GetSecureCoapServer().AddResource(mJoinerFinalize); } +otInstance *Commissioner::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError Commissioner::Start(void) { ThreadError error = kThreadError_None; @@ -336,7 +341,7 @@ void Commissioner::HandleJoinerExpirationTimer(void) if (static_cast(now - mJoiners[i].mExpirationTime) >= 0) { - otLogDebgMeshCoP("removing joiner due to timeout"); + otLogDebgMeshCoP(GetInstance(), "removing joiner due to timeout"); RemoveJoiner(&mJoiners[i].mExtAddress); } } @@ -412,7 +417,7 @@ ThreadError Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, Commissioner::HandleMgmtCommissionerGetResponse, this)); - otLogInfoMeshCoP("sent MGMT_COMMISSIONER_GET.req to leader"); + otLogInfoMeshCoP(GetInstance(), "sent MGMT_COMMISSIONER_GET.req to leader"); exit: @@ -442,7 +447,7 @@ void Commissioner::HandleMgmtCommissisonerGetResponse(Coap::Header *aHeader, Mes otLogFuncEntry(); VerifyOrExit(aResult == kThreadError_None && aHeader->GetCode() == kCoapResponseChanged, ;); - otLogInfoMeshCoP("received MGMT_COMMISSIONER_GET response"); + otLogInfoMeshCoP(GetInstance(), "received MGMT_COMMISSIONER_GET response"); exit: otLogFuncExit(); @@ -514,7 +519,7 @@ ThreadError Commissioner::SendMgmtCommissionerSetRequest(const otCommissioningDa SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, Commissioner::HandleMgmtCommissionerSetResponse, this)); - otLogInfoMeshCoP("sent MGMT_COMMISSIONER_SET.req to leader"); + otLogInfoMeshCoP(GetInstance(), "sent MGMT_COMMISSIONER_SET.req to leader"); exit: @@ -544,7 +549,7 @@ void Commissioner::HandleMgmtCommissisonerSetResponse(Coap::Header *aHeader, Mes otLogFuncEntry(); VerifyOrExit(aResult == kThreadError_None && aHeader->GetCode() == kCoapResponseChanged, ;); - otLogInfoMeshCoP("received MGMT_COMMISSIONER_SET response"); + otLogInfoMeshCoP(GetInstance(), "received MGMT_COMMISSIONER_SET response"); exit: otLogFuncExit(); @@ -579,7 +584,7 @@ ThreadError Commissioner::SendPetition(void) SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, Commissioner::HandleLeaderPetitionResponse, this)); - otLogInfoMeshCoP("sent petition"); + otLogInfoMeshCoP(GetInstance(), "sent petition"); exit: @@ -616,7 +621,7 @@ void Commissioner::HandleLeaderPetitionResponse(Coap::Header *aHeader, Message * VerifyOrExit(aResult == kThreadError_None && aHeader->GetCode() == kCoapResponseChanged, retransmit = true); - otLogInfoMeshCoP("received Leader Petition response"); + otLogInfoMeshCoP(GetInstance(), "received Leader Petition response"); SuccessOrExit(Tlv::GetTlv(*aMessage, Tlv::kState, sizeof(state), state)); VerifyOrExit(state.IsValid(), ;); @@ -679,7 +684,7 @@ ThreadError Commissioner::SendKeepAlive(void) SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, Commissioner::HandleLeaderKeepAliveResponse, this)); - otLogInfoMeshCoP("sent keep alive"); + otLogInfoMeshCoP(GetInstance(), "sent keep alive"); exit: @@ -713,7 +718,7 @@ void Commissioner::HandleLeaderKeepAliveResponse(Coap::Header *aHeader, Message VerifyOrExit(aResult == kThreadError_None && aHeader->GetCode() == kCoapResponseChanged, mState = kStateDisabled); - otLogInfoMeshCoP("received Leader Petition response"); + otLogInfoMeshCoP(GetInstance(), "received Leader Petition response"); SuccessOrExit(Tlv::GetTlv(*aMessage, Tlv::kState, sizeof(state), state)); VerifyOrExit(state.IsValid(), ;); @@ -780,7 +785,7 @@ void Commissioner::HandleRelayReceive(Coap::Header &aHeader, Message &aMessage, error = mNetif.GetSecureCoapServer().SetPsk(reinterpret_cast(mJoiners[i].mPsk), static_cast(strlen(mJoiners[i].mPsk))); SuccessOrExit(error); - otLogInfoMeshCoP("found joiner, starting new session"); + otLogInfoMeshCoP(GetInstance(), "found joiner, starting new session"); enableJoiner = true; break; } @@ -798,7 +803,7 @@ void Commissioner::HandleRelayReceive(Coap::Header &aHeader, Message &aMessage, mJoinerPort = joinerPort.GetUdpPort(); mJoinerRloc = joinerRloc.GetJoinerRouterLocator(); - otLogInfoMeshCoP("Received relay receive for %llX, rloc:%x", HostSwap64(mJoinerIid64), mJoinerRloc); + otLogInfoMeshCoP(GetInstance(), "Received relay receive for %llX, rloc:%x", HostSwap64(mJoinerIid64), mJoinerRloc); aMessage.SetOffset(offset); SuccessOrExit(error = aMessage.SetLength(offset + length)); @@ -828,12 +833,12 @@ void Commissioner::HandleDatasetChanged(Coap::Header &aHeader, Message &aMessage VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); - otLogInfoMeshCoP("received dataset changed"); + otLogInfoMeshCoP(GetInstance(), "received dataset changed"); (void)aMessage; SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo)); - otLogInfoMeshCoP("sent dataset changed acknowledgment"); + otLogInfoMeshCoP(GetInstance(), "sent dataset changed acknowledgment"); exit: otLogFuncExit(); @@ -854,7 +859,7 @@ void Commissioner::HandleJoinerFinalize(Coap::Header &aHeader, Message &aMessage ProvisioningUrlTlv provisioningUrl; otLogFuncEntry(); - otLogInfoMeshCoP("received joiner finalize"); + otLogInfoMeshCoP(GetInstance(), "received joiner finalize"); if (Tlv::GetTlv(aMessage, Tlv::kProvisioningUrl, sizeof(provisioningUrl), provisioningUrl) == kThreadError_None) { @@ -913,8 +918,8 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Header &aRequestHeader, extAddr.SetLocal(!extAddr.IsLocal()); RemoveJoiner(&extAddr); - otLogInfoMeshCoP("sent joiner finalize response"); - otLogCertMeshCoP("[THCI] direction=send | type=JOIN_FIN.rsp"); + otLogInfoMeshCoP(GetInstance(), "sent joiner finalize response"); + otLogCertMeshCoP(GetInstance(), "[THCI] direction=send | type=JOIN_FIN.rsp"); exit: if (error != kThreadError_None && message != NULL) diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index 005175c6e..9c7f51913 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -66,6 +66,14 @@ public: */ Commissioner(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method starts the Commissioner service. * diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 3b61f2808..2ba99299e 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -68,6 +68,11 @@ DatasetManager::DatasetManager(ThreadNetif &aThreadNetif, const Tlv::Type aType, { } +otInstance *DatasetManager::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError DatasetManager::ApplyConfiguration(void) { ThreadError error = kThreadError_None; @@ -298,7 +303,7 @@ ThreadError DatasetManager::Register(void) messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent dataset to leader"); + otLogInfoMeshCoP(GetInstance(), "sent dataset to leader"); exit: @@ -709,7 +714,7 @@ ThreadError DatasetManager::SendSetRequest(const otOperationalDataset &aDataset, messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent dataset set request to leader"); + otLogInfoMeshCoP(GetInstance(), "sent dataset set request to leader"); exit: @@ -761,7 +766,7 @@ ThreadError DatasetManager::SendGetRequest(const uint8_t *aTlvTypes, const uint8 messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent dataset get request"); + otLogInfoMeshCoP(GetInstance(), "sent dataset get request"); exit: @@ -794,7 +799,7 @@ void DatasetManager::SendSetResponse(const Coap::Header &aRequestHeader, const I SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, aMessageInfo)); - otLogInfoMeshCoP("sent dataset set response"); + otLogInfoMeshCoP(GetInstance(), "sent dataset set response"); exit: @@ -861,7 +866,7 @@ void DatasetManager::SendGetResponse(const Coap::Header &aRequestHeader, const I SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, aMessageInfo)); - otLogInfoMeshCoP("sent dataset get response"); + otLogInfoMeshCoP(GetInstance(), "sent dataset get response"); exit: @@ -1048,7 +1053,7 @@ void PendingDatasetBase::ResetDelayTimer(uint8_t aFlags) else { mTimer.Start(delayTimer->GetDelayTimer()); - otLogInfoMeshCoP("delay timer started"); + otLogInfoMeshCoP(GetInstance(), "delay timer started"); } } } @@ -1099,7 +1104,7 @@ void PendingDatasetBase::HandleTimer(void) { DelayTimerTlv *delayTimer; - otLogInfoMeshCoP("pending delay timer expired"); + otLogInfoMeshCoP(GetInstance(), "pending delay timer expired"); UpdateDelayTimer(); delayTimer = static_cast(mNetwork.Get(Tlv::kDelayTimer)); diff --git a/src/core/meshcop/dataset_manager.hpp b/src/core/meshcop/dataset_manager.hpp index ebd6d2a19..54f456eec 100644 --- a/src/core/meshcop/dataset_manager.hpp +++ b/src/core/meshcop/dataset_manager.hpp @@ -53,6 +53,15 @@ namespace MeshCoP { class DatasetManager { public: + + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + Dataset &GetLocal(void) { return mLocal; } Dataset &GetNetwork(void) { return mNetwork; } diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index ab706a2ff..7b4fce28d 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -72,6 +72,11 @@ Dtls::Dtls(ThreadNetif &aNetif): mProvisioningUrl.Init(); } +otInstance *Dtls::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError Dtls::Start(bool aClient, ConnectedHandler aConnectedHandler, ReceiveHandler aReceiveHandler, SendHandler aSendHandler, void *aContext) { @@ -106,7 +111,7 @@ ThreadError Dtls::Start(bool aClient, ConnectedHandler aConnectedHandler, Receiv mbedtls_ssl_conf_ciphersuites(&mConf, ciphersuites); mbedtls_ssl_conf_export_keys_cb(&mConf, HandleMbedtlsExportKeys, this); mbedtls_ssl_conf_handshake_timeout(&mConf, 8000, 60000); - mbedtls_ssl_conf_dbg(&mConf, HandleMbedtlsDebug, NULL); + mbedtls_ssl_conf_dbg(&mConf, HandleMbedtlsDebug, this); if (!mClient) { @@ -130,7 +135,7 @@ ThreadError Dtls::Start(bool aClient, ConnectedHandler aConnectedHandler, Receiv mStarted = true; Process(); - otLogInfoMeshCoP("DTLS started"); + otLogInfoMeshCoP(GetInstance(), "DTLS started"); exit: return MapError(rval); @@ -230,7 +235,7 @@ int Dtls::HandleMbedtlsTransmit(const unsigned char *aBuf, size_t aLength) ThreadError error; int rval = 0; - otLogInfoMeshCoP("Dtls::HandleMbedtlsTransmit"); + otLogInfoMeshCoP(GetInstance(), "Dtls::HandleMbedtlsTransmit"); error = mSendHandler(mContext, aBuf, (uint16_t)aLength); @@ -261,7 +266,7 @@ int Dtls::HandleMbedtlsReceive(unsigned char *aBuf, size_t aLength) { int rval; - otLogInfoMeshCoP("Dtls::HandleMbedtlsReceive"); + otLogInfoMeshCoP(GetInstance(), "Dtls::HandleMbedtlsReceive"); VerifyOrExit(mReceiveMessage != NULL && mReceiveLength != 0, rval = MBEDTLS_ERR_SSL_WANT_READ); @@ -287,7 +292,7 @@ int Dtls::HandleMbedtlsGetTimer(void) { int rval; - otLogInfoMeshCoP("Dtls::HandleMbedtlsGetTimer"); + otLogInfoMeshCoP(GetInstance(), "Dtls::HandleMbedtlsGetTimer"); if (!mTimerSet) { @@ -316,7 +321,7 @@ void Dtls::HandleMbedtlsSetTimer(void *aContext, uint32_t aIntermediate, uint32_ void Dtls::HandleMbedtlsSetTimer(uint32_t aIntermediate, uint32_t aFinish) { - otLogInfoMeshCoP("Dtls::SetTimer"); + otLogInfoMeshCoP(GetInstance(), "Dtls::SetTimer"); if (aFinish == 0) { @@ -350,7 +355,7 @@ int Dtls::HandleMbedtlsExportKeys(const unsigned char *aMasterSecret, const unsi mNetif.GetKeyManager().SetKek(kek); - otLogInfoMeshCoP("Generated KEK"); + otLogInfoMeshCoP(GetInstance(), "Generated KEK"); (void)aMasterSecret; return 0; @@ -470,25 +475,28 @@ ThreadError Dtls::MapError(int rval) return error; } -void Dtls::HandleMbedtlsDebug(void *, int level, const char *, int , const char *str) +void Dtls::HandleMbedtlsDebug(void *ctx, int level, const char *, int , const char *str) { + Dtls *pThis = static_cast(ctx); + (void)pThis; + switch (level) { case 1: - otLogCritMbedTls("%s", str); + otLogCritMbedTls(pThis->GetInstance(), "%s", str); break; case 2: - otLogWarnMbedTls("%s", str); + otLogWarnMbedTls(pThis->GetInstance(), "%s", str); break; case 3: - otLogInfoMbedTls("%s", str); + otLogInfoMbedTls(pThis->GetInstance(), "%s", str); break; case 4: default: - otLogDebgMbedTls("%s", str); + otLogDebgMbedTls(pThis->GetInstance(), "%s", str); break; } } diff --git a/src/core/meshcop/dtls.hpp b/src/core/meshcop/dtls.hpp index 4973dad80..cedcd77ea 100644 --- a/src/core/meshcop/dtls.hpp +++ b/src/core/meshcop/dtls.hpp @@ -71,6 +71,14 @@ public: */ Dtls(ThreadNetif &aNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This function pointer is called when a connection is established or torn down. * diff --git a/src/core/meshcop/energy_scan_client.cpp b/src/core/meshcop/energy_scan_client.cpp index 419d72dd7..1006889d1 100644 --- a/src/core/meshcop/energy_scan_client.cpp +++ b/src/core/meshcop/energy_scan_client.cpp @@ -59,6 +59,11 @@ EnergyScanClient::EnergyScanClient(ThreadNetif &aThreadNetif) : mNetif.GetCoapServer().AddResource(mEnergyScan); } +otInstance *EnergyScanClient::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, uint16_t aPeriod, uint16_t aScanDuration, const Ip6::Address &aAddress, otCommissionerEnergyReportCallback aCallback, void *aContext) @@ -106,7 +111,7 @@ ThreadError EnergyScanClient::SendQuery(uint32_t aChannelMask, uint8_t aCount, u messageInfo.SetInterfaceId(mNetif.GetInterfaceId()); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent energy scan query"); + otLogInfoMeshCoP(GetInstance(), "sent energy scan query"); mCallback = aCallback; mContext = aContext; @@ -144,7 +149,7 @@ void EnergyScanClient::HandleReport(Coap::Header &aHeader, Message &aMessage, co VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); - otLogInfoMeshCoP("received energy scan report"); + otLogInfoMeshCoP(GetInstance(), "received energy scan report"); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask)); VerifyOrExit(channelMask.IsValid(),); @@ -160,7 +165,7 @@ void EnergyScanClient::HandleReport(Coap::Header &aHeader, Message &aMessage, co memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr)); SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, responseInfo)); - otLogInfoMeshCoP("sent energy scan report response"); + otLogInfoMeshCoP(GetInstance(), "sent energy scan report response"); exit: return; diff --git a/src/core/meshcop/energy_scan_client.hpp b/src/core/meshcop/energy_scan_client.hpp index 2b0232faa..12b9a737f 100644 --- a/src/core/meshcop/energy_scan_client.hpp +++ b/src/core/meshcop/energy_scan_client.hpp @@ -60,6 +60,14 @@ public: */ EnergyScanClient(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method sends an Energy Scan Query message. * diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index f66b0de08..f426f145a 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -80,6 +80,11 @@ Joiner::Joiner(ThreadNetif &aNetif): mNetif.GetCoapServer().AddResource(mJoinerEntrust); } +otInstance *Joiner::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError Joiner::Start(const char *aPSKd, const char *aProvisioningUrl, const char *aVendorName, const char *aVendorModel, const char *aVendorSwVersion, const char *aVendorData, otJoinerCallback aCallback, void *aContext) @@ -174,7 +179,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) // Joining is disabled if the Steering Data is not included if (aResult->mSteeringData.mLength == 0) { - otLogDebgMeshCoP("No steering data, joining disabled"); + otLogDebgMeshCoP(GetInstance(), "No steering data, joining disabled"); ExitNow(); } @@ -193,7 +198,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) } else { - otLogDebgMeshCoP("Steering data does not include this device"); + otLogDebgMeshCoP(GetInstance(), "Steering data does not include this device"); } } else if (mJoinerRouterPanId != Mac::kPanIdBroadcast) @@ -214,7 +219,7 @@ void Joiner::HandleDiscoverResult(otActiveScanResult *aResult) } else { - otLogDebgMeshCoP("No joinable network found"); + otLogDebgMeshCoP(GetInstance(), "No joinable network found"); Complete(kThreadError_NotFound); } @@ -316,7 +321,7 @@ void Joiner::SendJoinerFinalize(void) mNetif.GetSecureCoapClient().SendMessage(*message, Joiner::HandleJoinerFinalizeResponse, this); - otLogInfoMeshCoP("Sent joiner finalize"); + otLogInfoMeshCoP(GetInstance(), "Sent joiner finalize"); exit: @@ -355,8 +360,8 @@ void Joiner::HandleJoinerFinalizeResponse(Coap::Header *aHeader, Message *aMessa mState = kStateEntrust; mTimer.Start(kTimeout); - otLogInfoMeshCoP("received joiner finalize response %d", static_cast(state.GetState())); - otLogCertMeshCoP("[THCI] direction=recv | type=JOIN_FIN.rsp"); + otLogInfoMeshCoP(GetInstance(), "received joiner finalize response %d", static_cast(state.GetState())); + otLogCertMeshCoP(GetInstance(), "[THCI] direction=recv | type=JOIN_FIN.rsp"); exit: Close(); @@ -388,8 +393,8 @@ void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, error = kThreadError_Drop); - otLogInfoMeshCoP("Received joiner entrust"); - otLogCertMeshCoP("[THCI] direction=recv | type=JOIN_ENT.ntf"); + otLogInfoMeshCoP(GetInstance(), "Received joiner entrust"); + otLogCertMeshCoP(GetInstance(), "[THCI] direction=recv | type=JOIN_ENT.ntf"); SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kNetworkMasterKey, sizeof(masterKey), masterKey)); VerifyOrExit(masterKey.IsValid(), error = kThreadError_Parse); @@ -415,7 +420,7 @@ void Joiner::HandleJoinerEntrust(Coap::Header &aHeader, Message &aMessage, const mNetif.GetMac().SetExtendedPanId(extendedPanId.GetExtendedPanId()); mNetif.GetMac().SetNetworkName(networkName.GetNetworkName()); - otLogInfoMeshCoP("join success!"); + otLogInfoMeshCoP(GetInstance(), "join success!"); // Send dummy response. SendJoinerEntrustResponse(aHeader, aMessageInfo); @@ -449,10 +454,10 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Header &aRequestHeader, mState = kStateJoined; - otLogInfoArp("Sent Joiner Entrust response"); + otLogInfoArp(GetInstance(), "Sent Joiner Entrust response"); - otLogInfoMeshCoP("Sent joiner entrust response length = %d", message->GetLength()); - otLogCertMeshCoP("[THCI] direction=send | type=JOIN_ENT.rsp"); + otLogInfoMeshCoP(GetInstance(), "Sent joiner entrust response length = %d", message->GetLength()); + otLogCertMeshCoP(GetInstance(), "[THCI] direction=send | type=JOIN_ENT.rsp"); exit: diff --git a/src/core/meshcop/joiner.hpp b/src/core/meshcop/joiner.hpp index ba41c11bb..90bc1212a 100644 --- a/src/core/meshcop/joiner.hpp +++ b/src/core/meshcop/joiner.hpp @@ -62,6 +62,14 @@ public: */ Joiner(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method starts the Joiner service. * diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index 7e766bc3d..2a3faf27a 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -71,6 +71,11 @@ JoinerRouter::JoinerRouter(ThreadNetif &aNetif): mNetif.RegisterCallback(mNetifCallback); } +otInstance *JoinerRouter::GetInstance() +{ + return mNetif.GetInstance(); +} + void JoinerRouter::HandleNetifStateChanged(uint32_t aFlags, void *aContext) { static_cast(aContext)->HandleNetifStateChanged(aFlags); @@ -92,7 +97,7 @@ void JoinerRouter::HandleNetifStateChanged(uint32_t aFlags) mSocket.Open(&JoinerRouter::HandleUdpReceive, this); mSocket.Bind(sockaddr); mNetif.GetIp6Filter().AddUnsecurePort(sockaddr.mPort); - otLogInfoMeshCoP("Joiner Router: start"); + otLogInfoMeshCoP(GetInstance(), "Joiner Router: start"); } else { @@ -165,7 +170,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a otLogFuncEntryMsg("from peer: %llX", HostSwap64(*reinterpret_cast(aMessageInfo.GetPeerAddr().mFields.m8 + 8))); - otLogInfoMeshCoP("JoinerRouter::HandleUdpReceive"); + otLogInfoMeshCoP(GetInstance(), "JoinerRouter::HandleUdpReceive"); SuccessOrExit(error = GetBorderAgentRloc(borderAgentRloc)); @@ -214,7 +219,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("Sent relay rx"); + otLogInfoMeshCoP(GetInstance(), "Sent relay rx"); exit: @@ -249,7 +254,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage, VerifyOrExit(aHeader.GetType() == kCoapTypeNonConfirmable && aHeader.GetCode() == kCoapRequestPost, error = kThreadError_Drop); - otLogInfoMeshCoP("Received relay transmit"); + otLogInfoMeshCoP(GetInstance(), "Received relay transmit"); SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kJoinerUdpPort, sizeof(joinerPort), joinerPort)); VerifyOrExit(joinerPort.IsValid(), error = kThreadError_Parse); @@ -291,7 +296,7 @@ void JoinerRouter::HandleRelayTransmit(Coap::Header &aHeader, Message &aMessage, if (Tlv::GetTlv(aMessage, Tlv::kJoinerRouterKek, sizeof(kek), kek) == kThreadError_None) { - otLogInfoMeshCoP("Received kek"); + otLogInfoMeshCoP(GetInstance(), "Received kek"); DelaySendingJoinerEntrust(messageInfo, kek); } @@ -482,12 +487,12 @@ ThreadError JoinerRouter::SendJoinerEntrust(Message &aMessage, const Ip6::Messag mNetif.GetCoapClient().AbortTransaction(&JoinerRouter::HandleJoinerEntrustResponse, this); - otLogInfoMeshCoP("Sending JOIN_ENT.ntf"); + otLogInfoMeshCoP(GetInstance(), "Sending JOIN_ENT.ntf"); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(aMessage, aMessageInfo, &JoinerRouter::HandleJoinerEntrustResponse, this)); - otLogInfoMeshCoP("Sent joiner entrust length = %d", aMessage.GetLength()); - otLogCertMeshCoP("[THCI] direction=send | type=JOIN_ENT.ntf"); + otLogInfoMeshCoP(GetInstance(), "Sent joiner entrust length = %d", aMessage.GetLength()); + otLogCertMeshCoP(GetInstance(), "[THCI] direction=send | type=JOIN_ENT.ntf"); mExpectJoinEntRsp = true; @@ -516,8 +521,8 @@ void JoinerRouter::HandleJoinerEntrustResponse(Coap::Header *aHeader, Message *a VerifyOrExit(aHeader->GetCode() == kCoapResponseChanged, ;); - otLogInfoMeshCoP("Receive joiner entrust response"); - otLogCertMeshCoP("[THCI] direction=recv | type=JOIN_ENT.rsp"); + otLogInfoMeshCoP(GetInstance(), "Receive joiner entrust response"); + otLogCertMeshCoP(GetInstance(), "[THCI] direction=recv | type=JOIN_ENT.rsp"); exit: return ; diff --git a/src/core/meshcop/joiner_router_ftd.hpp b/src/core/meshcop/joiner_router_ftd.hpp index d14ac5154..c003a6591 100644 --- a/src/core/meshcop/joiner_router_ftd.hpp +++ b/src/core/meshcop/joiner_router_ftd.hpp @@ -64,6 +64,14 @@ public: */ JoinerRouter(ThreadNetif &aNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method returns the Joiner UDP Port. * diff --git a/src/core/meshcop/leader.cpp b/src/core/meshcop/leader.cpp index 77f8799d0..a74789f19 100644 --- a/src/core/meshcop/leader.cpp +++ b/src/core/meshcop/leader.cpp @@ -61,6 +61,11 @@ Leader::Leader(ThreadNetif &aThreadNetif): mNetif.GetCoapServer().AddResource(mKeepAlive); } +otInstance *Leader::GetInstance() +{ + return mNetif.GetInstance(); +} + void Leader::HandlePetition(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, const otMessageInfo *aMessageInfo) { @@ -75,7 +80,7 @@ void Leader::HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6: CommissionerIdTlv commissionerId; StateTlv::State state = StateTlv::kReject; - otLogInfoMeshCoP("received petition"); + otLogInfoMeshCoP(GetInstance(), "received petition"); SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kCommissionerId, sizeof(commissionerId), commissionerId)); VerifyOrExit(commissionerId.IsValid(), ;); @@ -139,7 +144,7 @@ ThreadError Leader::SendPetitionResponse(const Coap::Header &aRequestHeader, con SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, aMessageInfo)); - otLogInfoMeshCoP("sent petition response"); + otLogInfoMeshCoP(GetInstance(), "sent petition response"); exit: @@ -165,7 +170,7 @@ void Leader::HandleKeepAlive(Coap::Header &aHeader, Message &aMessage, const Ip6 CommissionerSessionIdTlv sessionId; StateTlv::State responseState; - otLogInfoMeshCoP("received keep alive"); + otLogInfoMeshCoP(GetInstance(), "received keep alive"); SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kState, sizeof(state), state)); VerifyOrExit(state.IsValid(),); @@ -216,7 +221,7 @@ ThreadError Leader::SendKeepAliveResponse(const Coap::Header &aRequestHeader, co SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, aMessageInfo)); - otLogInfoMeshCoP("sent keep alive response"); + otLogInfoMeshCoP(GetInstance(), "sent keep alive response"); exit: @@ -245,7 +250,7 @@ ThreadError Leader::SendDatasetChanged(const Ip6::Address &aAddress) messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent dataset changed"); + otLogInfoMeshCoP(GetInstance(), "sent dataset changed"); exit: @@ -298,7 +303,7 @@ void Leader::ResignCommissioner(void) mNetif.GetNetworkDataLeader().SetCommissioningData(reinterpret_cast(&mCommissionerSessionId), sizeof(Tlv) + mCommissionerSessionId.GetLength()); - otLogInfoMeshCoP("commissioner inactive"); + otLogInfoMeshCoP(GetInstance(), "commissioner inactive"); } } // namespace MeshCoP diff --git a/src/core/meshcop/leader_ftd.hpp b/src/core/meshcop/leader_ftd.hpp index e68bf7ea5..b2daba595 100644 --- a/src/core/meshcop/leader_ftd.hpp +++ b/src/core/meshcop/leader_ftd.hpp @@ -70,6 +70,14 @@ public: */ Leader(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method sends a MGMT_DATASET_CHANGED message to commissioner. * diff --git a/src/core/meshcop/panid_query_client.cpp b/src/core/meshcop/panid_query_client.cpp index 052f49d0a..a306e9302 100644 --- a/src/core/meshcop/panid_query_client.cpp +++ b/src/core/meshcop/panid_query_client.cpp @@ -55,6 +55,11 @@ PanIdQueryClient::PanIdQueryClient(ThreadNetif &aThreadNetif) : mNetif.GetCoapServer().AddResource(mPanIdQuery); } +otInstance *PanIdQueryClient::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, const Ip6::Address &aAddress, otCommissionerPanIdConflictCallback aCallback, void *aContext) { @@ -91,7 +96,7 @@ ThreadError PanIdQueryClient::SendQuery(uint16_t aPanId, uint32_t aChannelMask, messageInfo.SetInterfaceId(mNetif.GetInterfaceId()); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent panid query"); + otLogInfoMeshCoP(GetInstance(), "sent panid query"); mCallback = aCallback; mContext = aContext; @@ -123,7 +128,7 @@ void PanIdQueryClient::HandleConflict(Coap::Header &aHeader, Message &aMessage, VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); - otLogInfoMeshCoP("received panid conflict"); + otLogInfoMeshCoP(GetInstance(), "received panid conflict"); SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kPanId, sizeof(panId), panId)); VerifyOrExit(panId.IsValid(), ;); @@ -139,7 +144,7 @@ void PanIdQueryClient::HandleConflict(Coap::Header &aHeader, Message &aMessage, memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr)); SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, responseInfo)); - otLogInfoMeshCoP("sent panid query conflict response"); + otLogInfoMeshCoP(GetInstance(), "sent panid query conflict response"); exit: return; diff --git a/src/core/meshcop/panid_query_client.hpp b/src/core/meshcop/panid_query_client.hpp index c50777e25..d6850443a 100644 --- a/src/core/meshcop/panid_query_client.hpp +++ b/src/core/meshcop/panid_query_client.hpp @@ -60,6 +60,14 @@ public: */ PanIdQueryClient(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method sends a PAN ID Query message. * diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index ec7a27931..b6efc032e 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -70,6 +70,11 @@ Dhcp6Client::Dhcp6Client(ThreadNetif &aThreadNetif) : mIdentityAssociationAvail = &mIdentityAssociations[0]; } +otInstance *Dhcp6Client::GetInstance() +{ + return mNetif.GetInstance(); +} + void Dhcp6Client::UpdateAddresses(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext) { @@ -394,7 +399,7 @@ ThreadError Dhcp6Client::Solicit(uint16_t aRloc16) messageInfo.mInterfaceId = mNetif.GetInterfaceId(); SuccessOrExit(error = mSocket.SendTo(*message, messageInfo)); - otLogInfoIp6("solicit\n"); + otLogInfoIp6(GetInstance(), "solicit"); exit: diff --git a/src/core/net/dhcp6_client.hpp b/src/core/net/dhcp6_client.hpp index f8cd044f3..2ce0a5022 100644 --- a/src/core/net/dhcp6_client.hpp +++ b/src/core/net/dhcp6_client.hpp @@ -178,6 +178,14 @@ public: */ explicit Dhcp6Client(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method update addresses that shall be automatically created using DHCP. * diff --git a/src/core/net/icmp6.cpp b/src/core/net/icmp6.cpp index 9ad8fb42f..4820c04cf 100644 --- a/src/core/net/icmp6.cpp +++ b/src/core/net/icmp6.cpp @@ -55,6 +55,11 @@ Icmp::Icmp(Ip6 &aIp6): { } +otInstance *Icmp::GetInstance() +{ + return mIp6.GetInstance(); +} + Message *Icmp::NewMessage(uint16_t aReserved) { return mIp6.NewMessage(sizeof(IcmpHeader) + aReserved); @@ -97,7 +102,7 @@ ThreadError Icmp::SendEchoRequest(Message &aMessage, const MessageInfo &aMessage aMessage.SetOffset(0); SuccessOrExit(error = mIp6.SendDatagram(aMessage, messageInfoLocal, kProtoIcmp6)); - otLogInfoIcmp("Sent echo request: (seq = %d)", icmpHeader.GetSequence()); + otLogInfoIcmp(GetInstance(), "Sent echo request: (seq = %d)", icmpHeader.GetSequence()); exit: return error; @@ -125,7 +130,7 @@ ThreadError Icmp::SendError(IcmpHeader::Type aType, IcmpHeader::Code aCode, cons SuccessOrExit(error = mIp6.SendDatagram(*message, messageInfoLocal, kProtoIcmp6)); - otLogInfoIcmp("Sent ICMPv6 Error"); + otLogInfoIcmp(GetInstance(), "Sent ICMPv6 Error"); exit: @@ -177,14 +182,14 @@ ThreadError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo MessageInfo replyMessageInfo; uint16_t payloadLength; - otLogInfoIcmp("Received Echo Request"); + otLogInfoIcmp(GetInstance(), "Received Echo Request"); icmp6Header.Init(); icmp6Header.SetType(kIcmp6TypeEchoReply); if ((replyMessage = mIp6.NewMessage(0)) == NULL) { - otLogDebgIcmp("Failed to allocate a new message"); + otLogDebgIcmp(GetInstance(), "Failed to allocate a new message"); ExitNow(); } @@ -207,7 +212,7 @@ ThreadError Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo SuccessOrExit(error = mIp6.SendDatagram(*replyMessage, replyMessageInfo, kProtoIcmp6)); replyMessage->Read(replyMessage->GetOffset(), sizeof(icmp6Header), &icmp6Header); - otLogInfoIcmp("Sent Echo Reply (seq = %d)", icmp6Header.GetSequence()); + otLogInfoIcmp(GetInstance(), "Sent Echo Reply (seq = %d)", icmp6Header.GetSequence()); exit: diff --git a/src/core/net/icmp6.hpp b/src/core/net/icmp6.hpp index 59c1caea8..f069486d8 100644 --- a/src/core/net/icmp6.hpp +++ b/src/core/net/icmp6.hpp @@ -221,6 +221,14 @@ public: */ Icmp(Ip6 &aIp6); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method returns a new ICMP message with sufficient header space reserved. * diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index 5fa80a0bf..1f87a848a 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -69,6 +69,11 @@ AddressResolver::AddressResolver(ThreadNetif &aThreadNetif) : mNetif.GetIp6().mIcmp.RegisterHandler(mIcmpHandler); } +otInstance *AddressResolver::GetInstance() +{ + return mNetif.GetInstance(); +} + void AddressResolver::Clear() { memset(&mCache, 0, sizeof(mCache)); @@ -153,7 +158,7 @@ void AddressResolver::InvalidateCacheEntry(Cache &aEntry) aEntry.mAge = kCacheEntries - 1; aEntry.mState = Cache::kStateInvalid; - otLogInfoArp("cache entry removed!"); + otLogInfoArp(GetInstance(), "cache entry removed!"); } ThreadError AddressResolver::Resolve(const Ip6::Address &aEid, uint16_t &aRloc16) @@ -247,7 +252,7 @@ ThreadError AddressResolver::SendAddressQuery(const Ip6::Address &aEid) SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoArp("Sent address query"); + otLogInfoArp(GetInstance(), "Sent address query"); exit: @@ -284,7 +289,8 @@ void AddressResolver::HandleAddressNotification(Coap::Header &aHeader, Message & VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); - otLogInfoArp("Received address notification from %04x", HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7])); + otLogInfoArp(GetInstance(), "Received address notification from %04x", + HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7])); SuccessOrExit(ThreadTlv::GetTlv(aMessage, ThreadTlv::kTarget, sizeof(targetTlv), targetTlv)); VerifyOrExit(targetTlv.IsValid(), ;); @@ -342,7 +348,7 @@ void AddressResolver::HandleAddressNotification(Coap::Header &aHeader, Message & if (mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo) == kThreadError_None) { - otLogInfoArp("Sent address notification acknowledgment"); + otLogInfoArp(GetInstance(), "Sent address notification acknowledgment"); } mNetif.GetMeshForwarder().HandleResolved(*targetTlv.GetTarget(), kThreadError_None); @@ -388,7 +394,7 @@ ThreadError AddressResolver::SendAddressError(const ThreadTargetTlv &aTarget, co SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoArp("Sent address error"); + otLogInfoArp(GetInstance(), "Sent address error"); exit: @@ -422,13 +428,13 @@ void AddressResolver::HandleAddressError(Coap::Header &aHeader, Message &aMessag VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, error = kThreadError_Drop); - otLogInfoArp("Received address error notification"); + otLogInfoArp(GetInstance(), "Received address error notification"); if (!aMessageInfo.GetSockAddr().IsMulticast()) { if (mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo) == kThreadError_None) { - otLogInfoArp("Sent address error notification acknowledgment"); + otLogInfoArp(GetInstance(), "Sent address error notification acknowledgment"); } } @@ -503,7 +509,7 @@ void AddressResolver::HandleAddressQuery(Coap::Header &aHeader, Message &aMessag VerifyOrExit(aHeader.GetType() == kCoapTypeNonConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); - otLogInfoArp("Received address query from %04x", HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7])); + otLogInfoArp(GetInstance(), "Received address query from %04x", HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7])); SuccessOrExit(ThreadTlv::GetTlv(aMessage, ThreadTlv::kTarget, sizeof(targetTlv), targetTlv)); VerifyOrExit(targetTlv.IsValid(), ;); @@ -585,7 +591,7 @@ void AddressResolver::SendAddressQueryResponse(const ThreadTargetTlv &aTargetTlv SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoArp("Sent address notification"); + otLogInfoArp(GetInstance(), "Sent address notification"); exit: diff --git a/src/core/thread/address_resolver_ftd.hpp b/src/core/thread/address_resolver_ftd.hpp index c252081b3..8aed35f97 100644 --- a/src/core/thread/address_resolver_ftd.hpp +++ b/src/core/thread/address_resolver_ftd.hpp @@ -75,6 +75,14 @@ public: */ explicit AddressResolver(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method clears the EID-to-RLOC cache. * diff --git a/src/core/thread/announce_begin_server.cpp b/src/core/thread/announce_begin_server.cpp index b130ae31b..408b17c38 100644 --- a/src/core/thread/announce_begin_server.cpp +++ b/src/core/thread/announce_begin_server.cpp @@ -66,6 +66,11 @@ AnnounceBeginServer::AnnounceBeginServer(ThreadNetif &aThreadNetif) : mNetif.GetCoapServer().AddResource(mAnnounceBegin); } +otInstance *AnnounceBeginServer::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError AnnounceBeginServer::SendAnnounce(uint32_t aChannelMask) { return SendAnnounce(aChannelMask, kDefaultCount, kDefaultPeriod); @@ -122,7 +127,7 @@ void AnnounceBeginServer::HandleRequest(Coap::Header &aHeader, Message &aMessage memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr)); SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, responseInfo)); - otLogInfoMeshCoP("sent announce begin response"); + otLogInfoMeshCoP(GetInstance(), "sent announce begin response"); exit: return; diff --git a/src/core/thread/announce_begin_server.hpp b/src/core/thread/announce_begin_server.hpp index c48529411..78c314950 100644 --- a/src/core/thread/announce_begin_server.hpp +++ b/src/core/thread/announce_begin_server.hpp @@ -60,6 +60,14 @@ public: */ AnnounceBeginServer(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method begins the MLE Announce transmission process using Count=3 and Period=1s. * diff --git a/src/core/thread/energy_scan_server.cpp b/src/core/thread/energy_scan_server.cpp index 95bc9c220..cce2089db 100644 --- a/src/core/thread/energy_scan_server.cpp +++ b/src/core/thread/energy_scan_server.cpp @@ -64,6 +64,11 @@ EnergyScanServer::EnergyScanServer(ThreadNetif &aThreadNetif) : mNetif.GetCoapServer().AddResource(mEnergyScan); } +otInstance *EnergyScanServer::GetInstance() +{ + return mNetif.GetInstance(); +} + void EnergyScanServer::HandleRequest(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, const otMessageInfo *aMessageInfo) { @@ -108,7 +113,7 @@ void EnergyScanServer::HandleRequest(Coap::Header &aHeader, Message &aMessage, c memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr)); SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, responseInfo)); - otLogInfoMeshCoP("sent energy scan query response"); + otLogInfoMeshCoP(GetInstance(), "sent energy scan query response"); exit: return; @@ -205,7 +210,7 @@ ThreadError EnergyScanServer::SendReport(void) messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent scan results"); + otLogInfoMeshCoP(GetInstance(), "sent scan results"); exit: diff --git a/src/core/thread/energy_scan_server.hpp b/src/core/thread/energy_scan_server.hpp index a474edcac..3b99ee378 100644 --- a/src/core/thread/energy_scan_server.hpp +++ b/src/core/thread/energy_scan_server.hpp @@ -65,6 +65,14 @@ public: */ EnergyScanServer(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + private: enum { diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 55903d48e..da86b057f 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -85,6 +85,11 @@ MeshForwarder::MeshForwarder(ThreadNetif &aThreadNetif): mMacDest.mLength = 0; } +otInstance *MeshForwarder::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError MeshForwarder::Start(void) { ThreadError error = kThreadError_None; @@ -341,8 +346,8 @@ ThreadError MeshForwarder::AddSrcMatchEntry(Child &aChild) ThreadError error = kThreadError_NoBufs; Mac::Address macAddr; - otLogDebgMac("Queuing for child (0x%x)", aChild.mValid.mRloc16); - otLogDebgMac("SrcMatch %d (0:Dis, 1:En))", mSrcMatchEnabled); + otLogDebgMac(GetInstance(), "Queuing for child (0x%x)", aChild.mValid.mRloc16); + otLogDebgMac(GetInstance(), "SrcMatch %d (0:Dis, 1:En))", mSrcMatchEnabled); // first queued message, to be added into source match table if (aChild.mQueuedIndirectMessageCnt == 1) @@ -390,7 +395,7 @@ exit: void MeshForwarder::ClearSrcMatchEntry(Child &aChild) { Mac::Address macAddr; - otLogDebgMac("SrcMatch %d (0:Dis, 1:En))", mSrcMatchEnabled); + otLogDebgMac(GetInstance(), "SrcMatch %d (0:Dis, 1:En))", mSrcMatchEnabled); if (aChild.mAddSrcMatchEntryShort) { @@ -937,7 +942,7 @@ void MeshForwarder::ScheduleNextPoll(uint32_t aDelay) } else { - otLogWarnMac("Cannot start poll timer with uninitialized value of poll period."); + otLogWarnMac(GetInstance(), "Cannot start poll timer with uninitialized value of poll period."); } } @@ -960,7 +965,7 @@ void MeshForwarder::HandlePollTimer() case kThreadError_InvalidState: // The poll timer should have been stopped. Hitting // this might indicate a logic error. - otLogWarnMac("Poll timer fired while RxOnWhenIdle set!"); + otLogWarnMac(GetInstance(), "Poll timer fired while RxOnWhenIdle set!"); break; case kThreadError_NoBufs: @@ -974,7 +979,7 @@ void MeshForwarder::HandlePollTimer() // bad behavior, as it suggests that mPollPeriod was not long // enough for the previously scheduled DataRequest to get out of // the sendQueue. - otLogDebgMac("Poll timer fired with DataRequest in SendQueue."); + otLogDebgMac(GetInstance(), "Poll timer fired with DataRequest in SendQueue."); // Intentional fall-thru default: @@ -1006,7 +1011,7 @@ ThreadError MeshForwarder::SendMacDataRequest(void) if (error == kThreadError_None) { - otLogDebgMac("Sent poll"); + otLogDebgMac(GetInstance(), "Sent poll"); // restart the polling timer ScheduleNextPoll(mPollPeriod); @@ -1695,7 +1700,7 @@ void MeshForwarder::HandleSentFrame(Mac::Frame &aFrame, ThreadError aError) if ((child->mMode & Mle::ModeTlv::kModeRxOnWhenIdle) == 0) { child->mQueuedIndirectMessageCnt--; - otLogDebgMac("Sent to child (0x%x), still queued message (%d)", + otLogDebgMac(GetInstance(), "Sent to child (0x%x), still queued message (%d)", child->mValid.mRloc16, child->mQueuedIndirectMessageCnt); if (child->mQueuedIndirectMessageCnt == 0) @@ -1878,7 +1883,7 @@ exit: if (error != kThreadError_None) { - otLogDebgMacErr(error, "Dropping received frame"); + otLogDebgMacErr(GetInstance(), error, "Dropping received frame"); } } @@ -1943,7 +1948,7 @@ exit: if (error != kThreadError_None) { - otLogDebgMacErr(error, "Dropping received mesh frame"); + otLogDebgMacErr(GetInstance(), error, "Dropping received mesh frame"); if (message != NULL) { @@ -2072,7 +2077,7 @@ exit: } else { - otLogDebgMacErr(error, "Dropping received fragment"); + otLogDebgMacErr(GetInstance(), error, "Dropping received fragment"); if (message != NULL) { @@ -2146,7 +2151,7 @@ exit: } else { - otLogDebgMacErr(error, "Dropping received lowpan HC"); + otLogDebgMacErr(GetInstance(), error, "Dropping received lowpan HC"); if (message != NULL) { diff --git a/src/core/thread/mesh_forwarder.hpp b/src/core/thread/mesh_forwarder.hpp index 2c9d06fbe..6a796f5e0 100644 --- a/src/core/thread/mesh_forwarder.hpp +++ b/src/core/thread/mesh_forwarder.hpp @@ -80,6 +80,14 @@ public: */ explicit MeshForwarder(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method enables mesh forwarding and the IEEE 802.15.4 MAC layer. * diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 3540c406b..a12ea8e6f 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -172,6 +172,11 @@ Mle::Mle(ThreadNetif &aThreadNetif) : memset(&mAddr64, 0, sizeof(mAddr64)); } +otInstance *Mle::GetInstance() +{ + return mNetif.GetInstance(); +} + ThreadError Mle::Enable(void) { ThreadError error = kThreadError_None; @@ -348,7 +353,7 @@ ThreadError Mle::Store(void) mNetif.GetKeyManager().SetStoredMleFrameCounter(networkInfo.mMleFrameCounter); mNetif.GetKeyManager().SetStoredMacFrameCounter(networkInfo.mMacFrameCounter); - otLogDebgMle("Store Network Information"); + otLogDebgMle(GetInstance(), "Store Network Information"); exit: return error; @@ -397,7 +402,7 @@ ThreadError Mle::Discover(uint32_t aScanChannels, uint16_t aScanDuration, uint16 mIsDiscoverInProgress = true; - otLogInfoMle("Sent discovery request"); + otLogInfoMle(GetInstance(), "Sent discovery request"); exit: @@ -522,7 +527,7 @@ ThreadError Mle::SetStateDetached(void) mNetif.GetIp6().SetForwardingEnabled(false); mNetif.GetIp6().mMpl.SetTimerExpirations(0); - otLogInfoMle("Mode -> Detached"); + otLogInfoMle(GetInstance(), "Mode -> Detached"); return kThreadError_None; } @@ -563,7 +568,7 @@ ThreadError Mle::SetStateChild(uint16_t aRloc16) mNetif.GetAnnounceBeginServer().SendAnnounce(1 << mPreviousChannel); } - otLogInfoMle("Mode -> Child"); + otLogInfoMle(GetInstance(), "Mode -> Child"); return kThreadError_None; } @@ -1452,7 +1457,7 @@ void Mle::HandleDelayedResponseTimer(void) // Send the message. if (SendMessage(*message, delayedResponse.GetDestination()) == kThreadError_None) { - otLogInfoMle("Sent delayed response"); + otLogInfoMle(GetInstance(), "Sent delayed response"); } else { @@ -1517,11 +1522,11 @@ ThreadError Mle::SendParentRequest(void) if ((scanMask & ScanMaskTlv::kEndDeviceFlag) == 0) { - otLogInfoMle("Sent parent request to routers"); + otLogInfoMle(GetInstance(), "Sent parent request to routers"); } else { - otLogInfoMle("Sent parent request to all devices"); + otLogInfoMle(GetInstance(), "Sent parent request to all devices"); } exit: @@ -1572,7 +1577,7 @@ ThreadError Mle::SendChildIdRequest(void) destination.mFields.m16[0] = HostSwap16(0xfe80); destination.SetIid(mParentCandidate.mMacAddr); SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("Sent Child ID Request"); + otLogInfoMle(GetInstance(), "Sent Child ID Request"); if ((mDeviceMode & ModeTlv::kModeRxOnWhenIdle) == 0) { @@ -1611,7 +1616,7 @@ ThreadError Mle::SendDataRequest(const Ip6::Address &aDestination, const uint8_t SuccessOrExit(error = SendMessage(*message, aDestination)); } - otLogInfoMle("Sent Data Request"); + otLogInfoMle(GetInstance(), "Sent Data Request"); exit: @@ -1687,7 +1692,7 @@ ThreadError Mle::SendChildUpdateRequest(void) destination.SetIid(mParent.mMacAddr); SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("Sent Child Update Request to parent"); + otLogInfoMle(GetInstance(), "Sent Child Update Request to parent"); if ((mDeviceMode & ModeTlv::kModeRxOnWhenIdle) == 0) { @@ -1755,7 +1760,7 @@ ThreadError Mle::SendChildUpdateResponse(const uint8_t *aTlvs, uint8_t aNumTlvs, destination.SetIid(mParent.mMacAddr); SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("Sent Child Update Response to parent"); + otLogInfoMle(GetInstance(), "Sent Child Update Response to parent"); exit: @@ -1810,7 +1815,7 @@ ThreadError Mle::SendAnnounce(uint8_t aChannel, bool aOrphanAnnounce) destination.mFields.m16[7] = HostSwap16(0x0001); SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("sent announce on channel %d", aChannel); + otLogInfoMle(GetInstance(), "sent announce on channel %d", aChannel); exit: @@ -2096,7 +2101,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn { if (frameCounter < neighbor->mValid.mMleFrameCounter) { - otLogDebgMle("mle frame reject 1"); + otLogDebgMle(GetInstance(), "mle frame reject 1"); ExitNow(); } } @@ -2104,7 +2109,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn { if (keySequence <= neighbor->mKeySequence) { - otLogDebgMle("mle frame reject 2"); + otLogDebgMle(GetInstance(), "mle frame reject 2"); ExitNow(); } @@ -2127,7 +2132,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn command == Header::kCommandChildUpdateResponse || command == Header::kCommandAnnounce)) { - otLogDebgMle("mle sequence unknown! %d", command); + otLogDebgMle(GetInstance(), "mle sequence unknown! %d", command); ExitNow(); } } @@ -2227,7 +2232,7 @@ ThreadError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::Message SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kLeaderData, sizeof(leaderData), leaderData)); VerifyOrExit(leaderData.IsValid(), error = kThreadError_Parse); - otLogInfoMle("Received advertisement from %04x", sourceAddress.GetRloc16()); + otLogInfoMle(GetInstance(), "Received advertisement from %04x", sourceAddress.GetRloc16()); if (mDeviceState != kDeviceStateDetached) { @@ -2296,7 +2301,7 @@ exit: if (error != kThreadError_None) { - otLogWarnMleErr(error, "Failed to process Advertisement"); + otLogWarnMleErr(GetInstance(), error, "Failed to process Advertisement"); } return error; @@ -2306,13 +2311,13 @@ ThreadError Mle::HandleDataResponse(const Message &aMessage, const Ip6::MessageI { ThreadError error; - otLogInfoMle("Received Data Response"); + otLogInfoMle(GetInstance(), "Received Data Response"); error = HandleLeaderData(aMessage, aMessageInfo); if (error != kThreadError_None) { - otLogWarnMleErr(error, "Failed to process Data Response"); + otLogWarnMleErr(GetInstance(), error, "Failed to process Data Response"); } return error; @@ -2532,7 +2537,7 @@ ThreadError Mle::HandleParentResponse(const Message &aMessage, const Ip6::Messag ChallengeTlv challenge; int8_t diff; - otLogInfoMle("Received Parent Response"); + otLogInfoMle(GetInstance(), "Received Parent Response"); // Response SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kResponse, sizeof(response), response)); @@ -2653,7 +2658,7 @@ exit: if (error != kThreadError_None) { - otLogWarnMleErr(error, "Failed to process Parent Response"); + otLogWarnMleErr(GetInstance(), error, "Failed to process Parent Response"); } return error; @@ -2673,7 +2678,7 @@ ThreadError Mle::HandleChildIdResponse(const Message &aMessage, const Ip6::Messa uint16_t offset; uint8_t numRouters = 0; - otLogInfoMle("Received Child ID Response"); + otLogInfoMle(GetInstance(), "Received Child ID Response"); VerifyOrExit(mParentRequestState == kChildIdRequest, ;); @@ -2786,7 +2791,7 @@ exit: if (error != kThreadError_None) { - otLogWarnMleErr(error, "Failed to process Child ID Response"); + otLogWarnMleErr(GetInstance(), error, "Failed to process Child ID Response"); } (void)aMessageInfo; @@ -2807,7 +2812,7 @@ ThreadError Mle::HandleChildUpdateRequest(const Message &aMessage, const Ip6::Me uint8_t tlvs[kMaxResponseTlvs] = {}; uint8_t numTlvs = 0; - otLogInfoMle("Received Child Update Request from parent"); + otLogInfoMle(GetInstance(), "Received Child Update Request from parent"); // Source Address SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kSourceAddress, sizeof(sourceAddress), sourceAddress)); @@ -2880,7 +2885,7 @@ ThreadError Mle::HandleChildUpdateResponse(const Message &aMessage, const Ip6::M SourceAddressTlv sourceAddress; TimeoutTlv timeout; - otLogInfoMle("Received Child Update Response from parent"); + otLogInfoMle(GetInstance(), "Received Child Update Response from parent"); // Status if (Tlv::GetTlv(aMessage, Tlv::kStatus, sizeof(status), status) == kThreadError_None) @@ -2968,7 +2973,7 @@ exit: if (error != kThreadError_None) { - otLogWarnMleErr(error, "Failed to process Child Update Response"); + otLogWarnMleErr(GetInstance(), error, "Failed to process Child Update Response"); } return error; @@ -2982,7 +2987,7 @@ ThreadError Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo const MeshCoP::Timestamp *localTimestamp; PanIdTlv panid; - otLogInfoMle("Received announce"); + otLogInfoMle(GetInstance(), "Received announce"); SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kChannel, sizeof(channel), channel)); VerifyOrExit(channel.IsValid(),); @@ -3029,7 +3034,7 @@ ThreadError Mle::HandleDiscoveryResponse(const Message &aMessage, const Ip6::Mes uint16_t offset; uint16_t end; - otLogInfoMle("Handle discovery response"); + otLogInfoMle(GetInstance(), "Handle discovery response"); VerifyOrExit(mIsDiscoverInProgress, error = kThreadError_Drop); @@ -3114,7 +3119,7 @@ exit: if (error != kThreadError_None) { - otLogWarnMleErr(error, "Failed to process Discovery Response"); + otLogWarnMleErr(GetInstance(), error, "Failed to process Discovery Response"); } return error; diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 65310d5a8..c2d425c1b 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -460,6 +460,14 @@ public: */ explicit Mle(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method enables MLE. * diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index beb5226bc..147372dcb 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -163,7 +163,7 @@ uint8_t MleRouter::AllocateRouterId(uint8_t aRouterId) mRouterIdSequenceLastUpdated = Timer::GetNow(); rval = aRouterId; - otLogInfoMle("add router id %d", aRouterId); + otLogInfoMle(GetInstance(), "add router id %d", aRouterId); exit: return rval; @@ -177,7 +177,7 @@ ThreadError MleRouter::ReleaseRouterId(uint8_t aRouterId) VerifyOrExit(router != NULL, error = kThreadError_InvalidArgs); VerifyOrExit(mDeviceState == kDeviceStateLeader, error = kThreadError_InvalidState); - otLogInfoMle("delete router id %d", aRouterId); + otLogInfoMle(GetInstance(), "delete router id %d", aRouterId); router->mAllocated = false; router->mReclaimDelay = true; router->mState = Neighbor::kStateInvalid; @@ -411,7 +411,7 @@ ThreadError MleRouter::SetStateRouter(uint16_t aRloc16) } } - otLogInfoMle("Mode -> Router"); + otLogInfoMle(GetInstance(), "Mode -> Router"); return kThreadError_None; } @@ -452,7 +452,7 @@ ThreadError MleRouter::SetStateLeader(uint16_t aRloc16) } } - otLogInfoMle("Mode -> Leader %d", mLeaderData.GetPartitionId()); + otLogInfoMle(GetInstance(), "Mode -> Leader %d", mLeaderData.GetPartitionId()); return kThreadError_None; } @@ -554,7 +554,7 @@ ThreadError MleRouter::SendAdvertisement(void) destination.mFields.m16[7] = HostSwap16(0x0001); SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("Sent advertisement"); + otLogInfoMle(GetInstance(), "Sent advertisement"); exit: @@ -632,7 +632,7 @@ ThreadError MleRouter::SendLinkRequest(Neighbor *aNeighbor) SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("Sent link request"); + otLogInfoMle(GetInstance(), "Sent link request"); exit: @@ -656,7 +656,7 @@ ThreadError MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::Mes TlvRequestTlv tlvRequest; uint16_t rloc16; - otLogInfoMle("Received link request"); + otLogInfoMle(GetInstance(), "Received link request"); VerifyOrExit(GetDeviceState() == kDeviceStateRouter || GetDeviceState() == kDeviceStateLeader, ;); @@ -824,13 +824,13 @@ ThreadError MleRouter::SendLinkAccept(const Ip6::MessageInfo &aMessageInfo, Neig SuccessOrExit(error = AddDelayedResponse(*message, aMessageInfo.GetPeerAddr(), (otPlatRandomGet() % kMaxResponseDelay) + 1)); - otLogInfoMle("Delayed link accept"); + otLogInfoMle(GetInstance(), "Delayed link accept"); } else { SuccessOrExit(error = SendMessage(*message, aMessageInfo.GetPeerAddr())); - otLogInfoMle("Sent link accept"); + otLogInfoMle(GetInstance(), "Sent link accept"); } exit: @@ -846,14 +846,14 @@ exit: ThreadError MleRouter::HandleLinkAccept(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence) { - otLogInfoMle("Received link accept"); + otLogInfoMle(GetInstance(), "Received link accept"); return HandleLinkAccept(aMessage, aMessageInfo, aKeySequence, false); } ThreadError MleRouter::HandleLinkAcceptAndRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence) { - otLogInfoMle("Received link accept and request"); + otLogInfoMle(GetInstance(), "Received link accept and request"); return HandleLinkAccept(aMessage, aMessageInfo, aKeySequence, true); } @@ -1285,7 +1285,7 @@ ThreadError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::M if (partitionId != mLeaderData.GetPartitionId()) { - otLogDebgMle("different partition! %d %d %d %d", + otLogDebgMle(GetInstance(), "different partition! %d %d %d %d", leaderData.GetWeighting(), partitionId, mLeaderData.GetWeighting(), mLeaderData.GetPartitionId()); @@ -1313,7 +1313,7 @@ ThreadError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::M if (ComparePartitions(routerCount <= 1, leaderData, IsSingleton(), mLeaderData) > 0) { - otLogDebgMle("trying to migrate"); + otLogDebgMle(GetInstance(), "trying to migrate"); BecomeChild(kMleAttachBetterPartition); } @@ -1607,7 +1607,8 @@ void MleRouter::UpdateRoutes(const RouteTlv &aRoute, uint8_t aRouterId) continue; } - otLogDebgMle("%x: %x %d %d %d %d", + otLogDebgMle(GetInstance(), + "%x: %x %d %d %d %d", GetRloc16(i), GetRloc16(mRouters[i].mNextHop), mRouters[i].mCost, @@ -1628,7 +1629,7 @@ ThreadError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::M ChallengeTlv challenge; Child *child; - otLogInfoMle("Received parent request"); + otLogInfoMle(GetInstance(), "Received parent request"); // A Router MUST NOT send an MLE Parent Response if: @@ -1770,7 +1771,7 @@ void MleRouter::HandleStateUpdateTimer(void) case kDeviceStateRouter: // verify path to leader - otLogDebgMle("network id timeout = %d", GetLeaderAge()); + otLogDebgMle(GetInstance(), "network id timeout = %d", GetLeaderAge()); if (GetLeaderAge() >= mNetworkIdTimeout) { @@ -1947,7 +1948,7 @@ ThreadError MleRouter::SendParentResponse(Child *aChild, const ChallengeTlv &cha SuccessOrExit(error = AddDelayedResponse(*message, destination, delay)); - otLogInfoMle("Delayed Parent Response"); + otLogInfoMle(GetInstance(), "Delayed Parent Response"); exit: @@ -2007,7 +2008,7 @@ ThreadError MleRouter::HandleChildIdRequest(const Message &aMessage, const Ip6:: Child *child; uint8_t numTlvs; - otLogInfoMle("Received Child ID Request"); + otLogInfoMle(GetInstance(), "Received Child ID Request"); // only process message when operating as a child, router, or leader VerifyOrExit(mDeviceState >= kDeviceStateChild, error = kThreadError_InvalidState); @@ -2176,7 +2177,7 @@ ThreadError MleRouter::HandleChildUpdateRequest(const Message &aMessage, const I uint8_t tlvs[kMaxResponseTlvs]; uint8_t tlvslength = 0; - otLogInfoMle("Received Child Update Request from child"); + otLogInfoMle(GetInstance(), "Received Child Update Request from child"); // Mode SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kMode, sizeof(mode), mode)); @@ -2286,7 +2287,7 @@ ThreadError MleRouter::HandleChildUpdateResponse(const Message &aMessage, const LeaderDataTlv leaderData; Child *child; - otLogInfoMle("Received Child Update Response from child"); + otLogInfoMle(GetInstance(), "Received Child Update Response from child"); // Find Child macAddr.Set(aMessageInfo.GetPeerAddr()); @@ -2369,7 +2370,7 @@ ThreadError MleRouter::HandleDataRequest(const Message &aMessage, const Ip6::Mes uint8_t tlvs[4]; uint8_t numTlvs; - otLogInfoMle("Received Data Request"); + otLogInfoMle(GetInstance(), "Received Data Request"); // TLV Request SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kTlvRequest, sizeof(tlvRequest), tlvRequest)); @@ -2475,7 +2476,7 @@ ThreadError MleRouter::HandleDiscoveryRequest(const Message &aMessage, const Ip6 uint16_t offset; uint16_t end; - otLogInfoMle("Received discovery request"); + otLogInfoMle(GetInstance(), "Received discovery request"); // only Routers and REEDs respond VerifyOrExit((mDeviceMode & ModeTlv::kModeFFD) != 0, ;); @@ -2532,7 +2533,7 @@ exit: if (error != kThreadError_None) { - otLogWarnMleErr(error, "Failed to process Discovery Request"); + otLogWarnMleErr(GetInstance(), error, "Failed to process Discovery Request"); } return error; @@ -2607,7 +2608,7 @@ ThreadError MleRouter::SendDiscoveryResponse(const Ip6::Address &aDestination, u SuccessOrExit(error = AddDelayedResponse(*message, aDestination, delay)); - otLogInfoMle("Sent discovery response"); + otLogInfoMle(GetInstance(), "Sent discovery response"); exit: @@ -2689,7 +2690,7 @@ ThreadError MleRouter::SendChildIdResponse(Child *aChild) destination.SetIid(aChild->mMacAddr); SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("Sent Child ID Response"); + otLogInfoMle(GetInstance(), "Sent Child ID Response"); exit: @@ -2730,7 +2731,7 @@ ThreadError MleRouter::SendChildUpdateRequest(Child *aChild) destination.SetIid(aChild->mMacAddr); SuccessOrExit(error = SendMessage(*message, destination)); - otLogInfoMle("Sent Child Update Request to child"); + otLogInfoMle(GetInstance(), "Sent Child Update Request to child"); exit: @@ -2802,7 +2803,7 @@ ThreadError MleRouter::SendChildUpdateResponse(Child *aChild, const Ip6::Message SuccessOrExit(error = SendMessage(*message, aMessageInfo.GetPeerAddr())); - otLogInfoMle("Sent Child Update Response to child"); + otLogInfoMle(GetInstance(), "Sent Child Update Response to child"); exit: @@ -2858,7 +2859,7 @@ ThreadError MleRouter::SendDataResponse(const Ip6::Address &aDestination, const SuccessOrExit(error = SendMessage(*message, aDestination)); } - otLogInfoMle("Sent Data Response"); + otLogInfoMle(GetInstance(), "Sent Data Response"); exit: @@ -3681,7 +3682,7 @@ ThreadError MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus) SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, &MleRouter::HandleAddressSolicitResponse, this)); - otLogInfoMle("Sent address solicit to %04x", HostSwap16(messageInfo.GetPeerAddr().mFields.m16[7])); + otLogInfoMle(GetInstance(), "Sent address solicit to %04x", HostSwap16(messageInfo.GetPeerAddr().mFields.m16[7])); exit: @@ -3721,7 +3722,7 @@ ThreadError MleRouter::SendAddressRelease(void) messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMle("Sent address release"); + otLogInfoMle(GetInstance(), "Sent address release"); exit: @@ -3759,7 +3760,7 @@ void MleRouter::HandleAddressSolicitResponse(Coap::Header *aHeader, Message *aMe VerifyOrExit(aHeader->GetCode() == kCoapResponseChanged, ;); - otLogInfoMle("Received address reply"); + otLogInfoMle(GetInstance(), "Received address reply"); SuccessOrExit(ThreadTlv::GetTlv(*aMessage, ThreadTlv::kStatus, sizeof(statusTlv), statusTlv)); VerifyOrExit(statusTlv.IsValid(), ;); @@ -3869,7 +3870,7 @@ void MleRouter::HandleAddressSolicit(Coap::Header &aHeader, Message &aMessage, c VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, error = kThreadError_Parse); - otLogInfoMle("Received address solicit"); + otLogInfoMle(GetInstance(), "Received address solicit"); SuccessOrExit(error = ThreadTlv::GetTlv(aMessage, ThreadTlv::kExtMacAddress, sizeof(macAddr64Tlv), macAddr64Tlv)); VerifyOrExit(macAddr64Tlv.IsValid(), error = kThreadError_Parse); @@ -3936,7 +3937,7 @@ void MleRouter::HandleAddressSolicit(Coap::Header &aHeader, Message &aMessage, c } else { - otLogInfoMle("router id requested and provided!"); + otLogInfoMle(GetInstance(), "router id requested and provided!"); } router = GetRouter(routerId); @@ -3947,7 +3948,7 @@ void MleRouter::HandleAddressSolicit(Coap::Header &aHeader, Message &aMessage, c } else { - otLogInfoMle("router address unavailable!"); + otLogInfoMle(GetInstance(), "router address unavailable!"); } exit: @@ -4002,7 +4003,7 @@ void MleRouter::SendAddressSolicitResponse(const Coap::Header &aRequestHeader, u SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, aMessageInfo)); - otLogInfoMle("Sent address reply"); + otLogInfoMle(GetInstance(), "Sent address reply"); exit: @@ -4031,7 +4032,7 @@ void MleRouter::HandleAddressRelease(Coap::Header &aHeader, Message &aMessage, VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); - otLogInfoMle("Received address release"); + otLogInfoMle(GetInstance(), "Received address release"); SuccessOrExit(ThreadTlv::GetTlv(aMessage, ThreadTlv::kRloc16, sizeof(rlocTlv), rlocTlv)); VerifyOrExit(rlocTlv.IsValid(),); @@ -4049,7 +4050,7 @@ void MleRouter::HandleAddressRelease(Coap::Header &aHeader, Message &aMessage, SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo)); - otLogInfoMle("Sent address release response"); + otLogInfoMle(GetInstance(), "Sent address release response"); exit: {} diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index fd6ac3883..bc8cc331a 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -57,6 +57,11 @@ NetworkData::NetworkData(ThreadNetif &aThreadNetif, bool aLocal): mLength = 0; } +otInstance *NetworkData::GetInstance() +{ + return mNetif.GetInstance(); +} + void NetworkData::Clear(void) { mLength = 0; @@ -640,7 +645,7 @@ ThreadError NetworkData::SendServerDataNotification(uint16_t aRloc16) mLastAttemptWait = true; } - otLogInfoNetData("Sent server data notification"); + otLogInfoNetData(GetInstance(), "Sent server data notification"); exit: diff --git a/src/core/thread/network_data.hpp b/src/core/thread/network_data.hpp index 5a7f25523..25ba032f9 100644 --- a/src/core/thread/network_data.hpp +++ b/src/core/thread/network_data.hpp @@ -100,6 +100,14 @@ public: */ NetworkData(ThreadNetif &aThreadNetif, bool aLocal); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method clears the network data. * diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index a042c9403..35a582eb0 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -152,7 +152,7 @@ void Leader::HandleServerData(Coap::Header &aHeader, Message &aMessage, ThreadNetworkDataTlv networkData; ThreadRloc16Tlv rloc16; - otLogInfoNetData("Received network data registration"); + otLogInfoNetData(GetInstance(), "Received network data registration"); if (ThreadTlv::GetTlv(aMessage, ThreadTlv::kRloc16, sizeof(rloc16), rloc16) == kThreadError_None) { @@ -169,7 +169,7 @@ void Leader::HandleServerData(Coap::Header &aHeader, Message &aMessage, SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo)); - otLogInfoNetData("Sent network data registration acknowledgment"); + otLogInfoNetData(GetInstance(), "Sent network data registration acknowledgment"); exit: return; @@ -361,7 +361,7 @@ void Leader::SendCommissioningGetResponse(const Coap::Header &aRequestHeader, co SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, aMessageInfo)); - otLogInfoMeshCoP("sent commissioning dataset get response"); + otLogInfoMeshCoP(GetInstance(), "sent commissioning dataset get response"); exit: @@ -392,7 +392,7 @@ void Leader::SendCommissioningSetResponse(const Coap::Header &aRequestHeader, co SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, aMessageInfo)); - otLogInfoMeshCoP("sent commissioning dataset set response"); + otLogInfoMeshCoP(GetInstance(), "sent commissioning dataset set response"); exit: @@ -750,7 +750,7 @@ int Leader::AllocateContext(void) { mContextUsed |= 1 << i; rval = i; - otLogInfoNetData("Allocated Context ID = %d", rval); + otLogInfoNetData(GetInstance(), "Allocated Context ID = %d", rval); ExitNow(); } } @@ -761,7 +761,7 @@ exit: ThreadError Leader::FreeContext(uint8_t aContextId) { - otLogInfoNetData("Free Context Id = %d", aContextId); + otLogInfoNetData(GetInstance(), "Free Context Id = %d", aContextId); RemoveContext(aContextId); mContextUsed &= ~(1 << aContextId); mVersion++; diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 4bd4f437a..0de38cb59 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -71,6 +71,11 @@ NetworkDiagnostic::NetworkDiagnostic(ThreadNetif &aThreadNetif) : mNetif.GetCoapServer().AddResource(mDiagnosticReset); } +otInstance *NetworkDiagnostic::GetInstance() +{ + return mNetif.GetInstance(); +} + void NetworkDiagnostic::SetReceiveDiagnosticGetCallback(otReceiveDiagnosticGetCallback aCallback, void *aCallbackContext) { @@ -117,7 +122,7 @@ ThreadError NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address &aDestinatio SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, handler, this)); - otLogInfoNetDiag("Sent diagnostic get"); + otLogInfoNetDiag(GetInstance(), "Sent diagnostic get"); exit: @@ -145,7 +150,7 @@ void NetworkDiagnostic::HandleDiagnosticGetResponse(Coap::Header &aHeader, Messa VerifyOrExit(aResult == kThreadError_None, ;); VerifyOrExit(aHeader.GetCode() == kCoapResponseChanged, ;); - otLogInfoNetDiag("Received diagnostic get response"); + otLogInfoNetDiag(GetInstance(), "Received diagnostic get response"); if (mReceiveDiagnosticGetCallback) { @@ -170,7 +175,7 @@ void NetworkDiagnostic::HandleDiagnosticGetAnswer(Coap::Header &aHeader, Message VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); - otLogInfoNetDiag("Diagnostic get answer received"); + otLogInfoNetDiag(GetInstance(), "Diagnostic get answer received"); if (mReceiveDiagnosticGetCallback) { @@ -179,7 +184,7 @@ void NetworkDiagnostic::HandleDiagnosticGetAnswer(Coap::Header &aHeader, Message SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo)); - otLogInfoNetDiag("Sent diagnostic answer acknowledgment"); + otLogInfoNetDiag(GetInstance(), "Sent diagnostic answer acknowledgment"); exit: return; @@ -270,7 +275,7 @@ ThreadError NetworkDiagnostic::FillRequestedTlvs(Message &aRequest, Message &aRe { VerifyOrExit(aRequest.Read(offset, sizeof(type), &type) == sizeof(type), error = kThreadError_Drop); - otLogInfoNetDiag("Received diagnostic get type %d", type); + otLogInfoNetDiag(GetInstance(), "Received diagnostic get type %d", type); switch (type) { @@ -432,7 +437,7 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Header &aHeader, Message VerifyOrExit(aHeader.GetCode() == kCoapRequestPost, error = kThreadError_Drop); - otLogInfoNetDiag("Received diagnostic get query"); + otLogInfoNetDiag(GetInstance(), "Received diagnostic get query"); VerifyOrExit((aMessage.Read(aMessage.GetOffset(), sizeof(NetworkDiagnosticTlv), &networkDiagnosticTlv) == sizeof(NetworkDiagnosticTlv)), error = kThreadError_Drop); @@ -446,7 +451,7 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Header &aHeader, Message { if (mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo) == kThreadError_None) { - otLogInfoNetDiag("Sent diagnostic get query acknowledgment"); + otLogInfoNetDiag(GetInstance(), "Sent diagnostic get query acknowledgment"); } } @@ -470,7 +475,7 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Header &aHeader, Message SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo, NULL, this)); - otLogInfoNetDiag("Sent diagnostic get answer"); + otLogInfoNetDiag(GetInstance(), "Sent diagnostic get answer"); exit: @@ -500,7 +505,7 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Header &aHeader, Messag VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, error = kThreadError_Drop); - otLogInfoNetDiag("Received diagnostic get request"); + otLogInfoNetDiag(GetInstance(), "Received diagnostic get request"); VerifyOrExit((aMessage.Read(aMessage.GetOffset(), sizeof(NetworkDiagnosticTlv), &networkDiagnosticTlv) == sizeof(NetworkDiagnosticTlv)), error = kThreadError_Drop); @@ -526,7 +531,7 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Header &aHeader, Messag SuccessOrExit(error = mNetif.GetCoapServer().SendMessage(*message, messageInfo)); - otLogInfoNetDiag("Sent diagnostic get response"); + otLogInfoNetDiag(GetInstance(), "Sent diagnostic get response"); exit: @@ -564,7 +569,7 @@ ThreadError NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestinat SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoNetDiag("Sent network diagnostic reset"); + otLogInfoNetDiag(GetInstance(), "Sent network diagnostic reset"); exit: @@ -591,7 +596,7 @@ void NetworkDiagnostic::HandleDiagnosticReset(Coap::Header &aHeader, Message &aM uint8_t type; NetworkDiagnosticTlv networkDiagnosticTlv; - otLogInfoNetDiag("Received diagnostic reset request"); + otLogInfoNetDiag(GetInstance(), "Received diagnostic reset request"); VerifyOrExit(aHeader.GetType() == kCoapTypeConfirmable && aHeader.GetCode() == kCoapRequestPost, ;); @@ -613,18 +618,18 @@ void NetworkDiagnostic::HandleDiagnosticReset(Coap::Header &aHeader, Message &aM { case NetworkDiagnosticTlv::kMacCounters: mNetif.GetMac().ResetCounters(); - otLogInfoNetDiag("Received diagnostic reset type kMacCounters(9)"); + otLogInfoNetDiag(GetInstance(), "Received diagnostic reset type kMacCounters(9)"); break; default: - otLogInfoNetDiag("Received diagnostic reset other type %d not resetable", type); + otLogInfoNetDiag(GetInstance(), "Received diagnostic reset other type %d not resetable", type); break; } } SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, aMessageInfo)); - otLogInfoNetDiag("Sent diagnostic reset acknowledgment"); + otLogInfoNetDiag(GetInstance(), "Sent diagnostic reset acknowledgment"); exit: return; diff --git a/src/core/thread/network_diagnostic.hpp b/src/core/thread/network_diagnostic.hpp index 1cfb215b1..2d0a9b5e3 100644 --- a/src/core/thread/network_diagnostic.hpp +++ b/src/core/thread/network_diagnostic.hpp @@ -75,6 +75,14 @@ public: */ explicit NetworkDiagnostic(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + /** * This method registers a callback to provide received raw DIAG_GET.rsp or an DIAG_GET.ans payload. * diff --git a/src/core/thread/panid_query_server.cpp b/src/core/thread/panid_query_server.cpp index 3c32efcaf..e4adf73a9 100644 --- a/src/core/thread/panid_query_server.cpp +++ b/src/core/thread/panid_query_server.cpp @@ -56,6 +56,11 @@ PanIdQueryServer::PanIdQueryServer(ThreadNetif &aThreadNetif) : mNetif.GetCoapServer().AddResource(mPanIdQuery); } +otInstance *PanIdQueryServer::GetInstance() +{ + return mNetif.GetInstance(); +} + void PanIdQueryServer::HandleQuery(void *aContext, otCoapHeader *aHeader, otMessage *aMessage, const otMessageInfo *aMessageInfo) { @@ -86,7 +91,7 @@ void PanIdQueryServer::HandleQuery(Coap::Header &aHeader, Message &aMessage, con memset(&responseInfo.mSockAddr, 0, sizeof(responseInfo.mSockAddr)); SuccessOrExit(mNetif.GetCoapServer().SendEmptyAck(aHeader, responseInfo)); - otLogInfoMeshCoP("sent panid query response"); + otLogInfoMeshCoP(GetInstance(), "sent panid query response"); exit: return; @@ -144,7 +149,7 @@ ThreadError PanIdQueryServer::SendConflict(void) messageInfo.SetPeerPort(kCoapUdpPort); SuccessOrExit(error = mNetif.GetCoapClient().SendMessage(*message, messageInfo)); - otLogInfoMeshCoP("sent panid conflict"); + otLogInfoMeshCoP(GetInstance(), "sent panid conflict"); exit: diff --git a/src/core/thread/panid_query_server.hpp b/src/core/thread/panid_query_server.hpp index 77c75044e..ae4057b24 100644 --- a/src/core/thread/panid_query_server.hpp +++ b/src/core/thread/panid_query_server.hpp @@ -65,6 +65,14 @@ public: */ PanIdQueryServer(ThreadNetif &aThreadNetif); + /** + * This method returns the pointer to the parent otInstance structure. + * + * @returns The pointer to the parent otInstance structure. + * + */ + otInstance *GetInstance(); + private: enum {