From 669c79211802ee26c4a7678092103254a52b2480 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Wed, 11 Jan 2017 21:40:48 -0800 Subject: [PATCH] DHCPv6 Client and Server API cleanup. --- configure.ac | 1 - etc/visual-studio/libopenthread.vcxproj | 1 + .../libopenthread.vcxproj.filters | 3 + etc/visual-studio/libopenthread_k.vcxproj | 1 + .../libopenthread_k.vcxproj.filters | 3 + examples/drivers/windows/otLwf/precomp.h | 4 +- include/Makefile.am | 3 - include/dhcp6/Makefile.am | 41 ------------- include/openthread/Makefile.am | 2 + include/{dhcp6 => openthread}/dhcp6_client.h | 0 include/{dhcp6 => openthread}/dhcp6_server.h | 0 src/cli/cli.cpp | 4 +- src/cli/cli.hpp | 2 +- src/core/Makefile.am | 2 + src/core/api/dhcp6_api.cpp | 61 +++++++++++++++++++ src/core/net/dhcp6_client.hpp | 2 +- src/core/openthread.cpp | 14 ----- 17 files changed, 79 insertions(+), 65 deletions(-) delete mode 100644 include/dhcp6/Makefile.am rename include/{dhcp6 => openthread}/dhcp6_client.h (100%) rename include/{dhcp6 => openthread}/dhcp6_server.h (100%) create mode 100644 src/core/api/dhcp6_api.cpp diff --git a/configure.ac b/configure.ac index 208aa6915..1cdc58935 100644 --- a/configure.ac +++ b/configure.ac @@ -1080,7 +1080,6 @@ AC_CONFIG_FILES([ Makefile include/Makefile include/cli/Makefile -include/dhcp6/Makefile include/ncp/Makefile include/openthread/Makefile include/platform/Makefile diff --git a/etc/visual-studio/libopenthread.vcxproj b/etc/visual-studio/libopenthread.vcxproj index e862e6af5..4acbeba23 100644 --- a/etc/visual-studio/libopenthread.vcxproj +++ b/etc/visual-studio/libopenthread.vcxproj @@ -56,6 +56,7 @@ + diff --git a/etc/visual-studio/libopenthread.vcxproj.filters b/etc/visual-studio/libopenthread.vcxproj.filters index f6957246c..017955497 100644 --- a/etc/visual-studio/libopenthread.vcxproj.filters +++ b/etc/visual-studio/libopenthread.vcxproj.filters @@ -63,6 +63,9 @@ Source Files\api + + Source Files\api + Source Files\api diff --git a/etc/visual-studio/libopenthread_k.vcxproj b/etc/visual-studio/libopenthread_k.vcxproj index c72143d64..9881ca7ae 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj +++ b/etc/visual-studio/libopenthread_k.vcxproj @@ -65,6 +65,7 @@ + diff --git a/etc/visual-studio/libopenthread_k.vcxproj.filters b/etc/visual-studio/libopenthread_k.vcxproj.filters index a64446d87..1d9e9b347 100644 --- a/etc/visual-studio/libopenthread_k.vcxproj.filters +++ b/etc/visual-studio/libopenthread_k.vcxproj.filters @@ -63,6 +63,9 @@ Source Files\api + + Source Files\api + Source Files\api diff --git a/examples/drivers/windows/otLwf/precomp.h b/examples/drivers/windows/otLwf/precomp.h index 08fdfcc11..fee305bfe 100644 --- a/examples/drivers/windows/otLwf/precomp.h +++ b/examples/drivers/windows/otLwf/precomp.h @@ -67,8 +67,8 @@ RtlCopyBufferToMdl( #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/include/Makefile.am b/include/Makefile.am index 3a89b3428..6e3e1e9b0 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -32,7 +32,6 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am DIST_SUBDIRS = \ cli \ - dhcp6 \ ncp \ openthread \ platform \ @@ -42,7 +41,6 @@ DIST_SUBDIRS = \ SUBDIRS = \ cli \ - dhcp6 \ ncp \ openthread \ platform \ @@ -52,7 +50,6 @@ SUBDIRS = \ PRETTY_SUBDIRS = \ cli \ - dhcp6 \ ncp \ openthread \ platform \ diff --git a/include/dhcp6/Makefile.am b/include/dhcp6/Makefile.am deleted file mode 100644 index f921db93d..000000000 --- a/include/dhcp6/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright (c) 2016, The OpenThread Authors. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the copyright holder nor the -# names of its contributors may be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. -# - -include $(abs_top_nlbuild_autotools_dir)/automake/pre.am - -ot_dhcp6_headers = \ - dhcp6_client.h \ - dhcp6_server.h \ - $(NULL) - -ot_dhcp6dir = $(includedir)/dhcp6 -dist_ot_dhcp6_HEADERS = $(ot_dhcp6_headers) - -install-headers: install-includeHEADERS - -include $(abs_top_nlbuild_autotools_dir)/automake/post.am diff --git a/include/openthread/Makefile.am b/include/openthread/Makefile.am index 26fb07680..d567bc5a0 100644 --- a/include/openthread/Makefile.am +++ b/include/openthread/Makefile.am @@ -32,6 +32,8 @@ openthread_headers = \ coap.h \ commissioner.h \ crypto.h \ + dhcp6_client.h \ + dhcp6_server.h \ jam_detection.h \ joiner.h \ message.h \ diff --git a/include/dhcp6/dhcp6_client.h b/include/openthread/dhcp6_client.h similarity index 100% rename from include/dhcp6/dhcp6_client.h rename to include/openthread/dhcp6_client.h diff --git a/include/dhcp6/dhcp6_server.h b/include/openthread/dhcp6_server.h similarity index 100% rename from include/dhcp6/dhcp6_server.h rename to include/openthread/dhcp6_server.h diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 75cb1aad8..6622672e2 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -56,8 +56,8 @@ #include #include -#include -#include +#include "openthread/dhcp6_client.h" +#include "openthread/dhcp6_server.h" #include #endif diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 898fe009c..af97404d6 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -51,7 +51,7 @@ #ifndef OTDLL #include #include -#include +#include "openthread/dhcp6_client.h" #endif #ifdef OTDLL diff --git a/src/core/Makefile.am b/src/core/Makefile.am index a10167909..a7c7fe5d4 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -129,12 +129,14 @@ endif # OPENTHREAD_ENABLE_DTLS if OPENTHREAD_ENABLE_DHCP6_CLIENT SOURCES_COMMON += \ + api/dhcp6_api.cpp \ net/dhcp6_client.cpp \ $(NULL) endif # OPENTHREAD_ENABLE_DHCP6_CLIENT if OPENTHREAD_ENABLE_DHCP6_SERVER SOURCES_COMMON += \ + api/dhcp6_api.cpp \ net/dhcp6_server.cpp \ $(NULL) endif # OPENTHREAD_ENABLE_DHCP6_SERVER diff --git a/src/core/api/dhcp6_api.cpp b/src/core/api/dhcp6_api.cpp new file mode 100644 index 000000000..5af1f4538 --- /dev/null +++ b/src/core/api/dhcp6_api.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file implements the OpenThread UDP API. + */ + +#include "openthread/dhcp6_client.h" +#include "openthread/dhcp6_server.h" + +#include "openthread-instance.h" + +using namespace Thread; + +#ifdef __cplusplus +extern "C" { +#endif + +#if OPENTHREAD_ENABLE_DHCP6_CLIENT +void otDhcp6ClientUpdate(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext) +{ + aInstance->mThreadNetif.GetDhcp6Client().UpdateAddresses(aInstance, aAddresses, aNumAddresses, aContext); +} +#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT + +#if OPENTHREAD_ENABLE_DHCP6_SERVER +void otDhcp6ServerUpdate(otInstance *aInstance) +{ + aInstance->mThreadNetif.GetDhcp6Server().UpdateService(); +} +#endif // OPENTHREAD_ENABLE_DHCP6_SERVER + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/src/core/net/dhcp6_client.hpp b/src/core/net/dhcp6_client.hpp index 02ca43e94..28f508c5a 100644 --- a/src/core/net/dhcp6_client.hpp +++ b/src/core/net/dhcp6_client.hpp @@ -34,7 +34,7 @@ #ifndef DHCP6_CLIENT_HPP_ #define DHCP6_CLIENT_HPP_ -#include +#include "openthread/dhcp6_client.h" #include #include diff --git a/src/core/openthread.cpp b/src/core/openthread.cpp index 00ee8eeaa..ea52bb3a1 100644 --- a/src/core/openthread.cpp +++ b/src/core/openthread.cpp @@ -976,20 +976,6 @@ ThreadError otRemoveUnicastAddress(otInstance *aInstance, const otIp6Address *ad return aInstance->mThreadNetif.RemoveExternalUnicastAddress(*static_cast(address)); } -#if OPENTHREAD_ENABLE_DHCP6_SERVER -void otDhcp6ServerUpdate(otInstance *aInstance) -{ - aInstance->mThreadNetif.GetDhcp6Server().UpdateService(); -} -#endif // OPENTHREAD_ENABLE_DHCP6_SERVER - -#if OPENTHREAD_ENABLE_DHCP6_CLIENT -void otDhcp6ClientUpdate(otInstance *aInstance, otDhcpAddress *aAddresses, uint32_t aNumAddresses, void *aContext) -{ - aInstance->mThreadNetif.GetDhcp6Client().UpdateAddresses(aInstance, aAddresses, aNumAddresses, aContext); -} -#endif // OPENTHREAD_ENABLE_DHCP6_CLIENT - const otNetifMulticastAddress *otGetMulticastAddresses(otInstance *aInstance) { return aInstance->mThreadNetif.GetMulticastAddresses();