util: Add detection whether WiFi interface is ad hoc on macOS
This commit only introduces framework to detect WiFi interface type.
This function is not yet integrated in any other code.
Change-Id: I072d654f7fdbd89fe5fee00b0400133d5cea19cf
Refs: #4019
diff --git a/.waf-tools/osx-frameworks.py b/.waf-tools/osx-frameworks.py
index 5366b72..477a7f7 100644
--- a/.waf-tools/osx-frameworks.py
+++ b/.waf-tools/osx-frameworks.py
@@ -34,12 +34,16 @@
use='OSX_COREFOUNDATION', fragment=OSX_SYSTEMCONFIGURATION_CODE,
mandatory=True)
+ conf.check_cxx(framework_name='Foundation', uselib_store='OSX_FOUNDATION',
+ mandatory=True, compile_filename='test.mm')
+ conf.check_cxx(framework_name='CoreWLAN', uselib_store='OSX_COREWLAN',
+ use="OSX_FOUNDATION", mandatory=True, compile_filename='test.mm')
+
conf.define('HAVE_OSX_FRAMEWORKS', 1)
conf.env['HAVE_OSX_FRAMEWORKS'] = True
except:
- Logs.warn("Compiling on OSX, but CoreFoundation, CoreServices, Security, or SystemConfiguration " +
- "framework is not functional.")
- Logs.warn("The frameworks are known to work only with the Apple clang compiler")
+ Logs.warn("Compiling on macOS, but required framework(s) is(are) not functional.")
+ Logs.warn("Note that the frameworks are known to work only with the Apple clang compiler.")
@TaskGen.extension('.mm')
def m_hook(self, node):
diff --git a/src/util/detail/link-type-helper-osx.mm b/src/util/detail/link-type-helper-osx.mm
new file mode 100644
index 0000000..200adff
--- /dev/null
+++ b/src/util/detail/link-type-helper-osx.mm
@@ -0,0 +1,65 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "link-type-helper.hpp"
+
+#ifndef NDN_CXX_HAVE_OSX_FRAMEWORKS
+#error "This file should not be compiled ..."
+#endif
+
+#import <Foundation/Foundation.h>
+#import <CoreWLAN/CoreWLAN.h>
+#import <CoreWLAN/CWInterface.h>
+#import <CoreWLAN/CWWiFiClient.h>
+
+namespace ndn {
+namespace util {
+namespace detail {
+
+ndn::nfd::LinkType
+getLinkType(const std::string& ifName)
+{
+ @autoreleasepool {
+ NSString* interfaceName = [NSString stringWithCString:ifName.c_str()
+ encoding:[NSString defaultCStringEncoding]];
+
+ CWWiFiClient* wifiInterface = [CWWiFiClient sharedWiFiClient];
+ if (wifiInterface == nullptr) {
+ return nfd::LINK_TYPE_NONE;
+ }
+
+ CWInterface* airport = [wifiInterface interfaceWithName:interfaceName];
+ if (airport == nullptr) {
+ return nfd::LINK_TYPE_NONE;
+ }
+
+ if ([airport interfaceMode] == kCWInterfaceModeIBSS) {
+ return nfd::LINK_TYPE_AD_HOC;
+ }
+ else {
+ return nfd::LINK_TYPE_MULTI_ACCESS;
+ }
+ }
+}
+
+} // namespace detail
+} // namespace util
+} // namespace ndn
diff --git a/src/util/detail/link-type-helper.cpp b/src/util/detail/link-type-helper.cpp
new file mode 100644
index 0000000..a25fd27
--- /dev/null
+++ b/src/util/detail/link-type-helper.cpp
@@ -0,0 +1,43 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "link-type-helper.hpp"
+#include "ndn-cxx-config.hpp"
+
+#ifdef NDN_CXX_HAVE_OSX_FRAMEWORKS
+// implemented in link-type-helper-osx.mm
+#else
+
+namespace ndn {
+namespace util {
+namespace detail {
+
+ndn::nfd::LinkType
+getLinkType(const std::string& ifName)
+{
+ return nfd::LINK_TYPE_NONE;
+}
+
+} // namespace detail
+} // namespace util
+} // namespace ndn
+
+#endif // NDN_CXX_HAVE_OSX_FRAMEWORKS
diff --git a/src/util/detail/link-type-helper.hpp b/src/util/detail/link-type-helper.hpp
new file mode 100644
index 0000000..c6e402f
--- /dev/null
+++ b/src/util/detail/link-type-helper.hpp
@@ -0,0 +1,41 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2017 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NDN_UTIL_DETAIL_LINK_TYPE_HELPER_HPP
+#define NDN_UTIL_DETAIL_LINK_TYPE_HELPER_HPP
+
+#include "../../encoding/nfd-constants.hpp"
+
+namespace ndn {
+namespace util {
+namespace detail {
+
+/**
+ * @brief Obtain information about WiFi link type
+ */
+ndn::nfd::LinkType
+getLinkType(const std::string& ifName);
+
+} // namespace detail
+} // namespace util
+} // namespace ndn
+
+#endif // NDN_UTIL_DETAIL_LINK_TYPE_HELPER_HPP
diff --git a/tests/integrated/network-monitor.cpp b/tests/integrated/network-monitor.cpp
index ac74862..498b970 100644
--- a/tests/integrated/network-monitor.cpp
+++ b/tests/integrated/network-monitor.cpp
@@ -29,6 +29,8 @@
#include "util/network-interface.hpp"
#include "util/time.hpp"
+#include "util/detail/link-type-helper.hpp"
+
#include "boost-test.hpp"
#include <boost/asio/io_service.hpp>
@@ -70,10 +72,11 @@
monitor.onInterfaceAdded.connect([] (const shared_ptr<NetworkInterface>& ni) {
logEvent(ni) << "onInterfaceAdded\n" << *ni;
+ logEvent(ni) << "link-type: " << detail::getLinkType(ni->getName()) << "\n";
ni->onAddressAdded.connect([ni] (const NetworkAddress& address) {
logEvent(ni) << "onAddressAdded " << address << std::endl;
- });
+ });
ni->onAddressRemoved.connect([ni] (const NetworkAddress& address) {
logEvent(ni) << "onAddressRemoved " << address << std::endl;
@@ -81,6 +84,7 @@
ni->onStateChanged.connect([ni] (InterfaceState oldState, InterfaceState newState) {
logEvent(ni) << "onStateChanged " << oldState << " -> " << newState << std::endl;
+ logEvent(ni) << "link-type: " << detail::getLinkType(ni->getName()) << "\n";
});
ni->onMtuChanged.connect([ni] (uint32_t oldMtu, uint32_t newMtu) {
diff --git a/wscript b/wscript
index 0d5a9c4..305057a 100644
--- a/wscript
+++ b/wscript
@@ -166,7 +166,7 @@
target="ndn-cxx-mm",
name="ndn-cxx-mm",
source=bld.path.ant_glob(['src/**/*-osx.mm']),
- use='version BOOST CRYPTOPP OPENSSL SQLITE3 RT PTHREAD OSX_COREFOUNDATION OSX_CORESERVICES OSX_SECURITY OSX_SYSTEMCONFIGURATION',
+ use='version BOOST CRYPTOPP OPENSSL SQLITE3 RT PTHREAD OSX_COREFOUNDATION OSX_CORESERVICES OSX_SECURITY OSX_SYSTEMCONFIGURATION OSX_FOUNDATION OSX_COREWLAN',
includes=". src")
libndn_cxx = dict(
@@ -184,7 +184,7 @@
if bld.env['HAVE_OSX_FRAMEWORKS']:
libndn_cxx['source'] += bld.path.ant_glob('src/**/*-osx.cpp')
- libndn_cxx['use'] += " OSX_COREFOUNDATION OSX_CORESERVICES OSX_SECURITY OSX_SYSTEMCONFIGURATION"
+ libndn_cxx['use'] += " OSX_COREFOUNDATION OSX_CORESERVICES OSX_SECURITY OSX_SYSTEMCONFIGURATION OSX_FOUNDATION OSX_COREWLAN"
if bld.env['HAVE_RTNETLINK']:
libndn_cxx['source'] += bld.path.ant_glob('src/**/*-rtnl.cpp')
@@ -222,7 +222,7 @@
EXTRA_FRAMEWORKS = ""
if bld.env['HAVE_OSX_FRAMEWORKS']:
- EXTRA_FRAMEWORKS = "-framework CoreFoundation -framework CoreServices -framework Security -framework SystemConfiguration"
+ EXTRA_FRAMEWORKS = "-framework CoreFoundation -framework CoreServices -framework Security -framework SystemConfiguration -framework Foundation -framework CoreWLAN"
def uniq(alist):
seen = set()