Merge "New NativeDaemonConnector protocol adds a seqnum."
diff --git a/include/arch/linux-arm/AndroidConfig.h b/include/arch/linux-arm/AndroidConfig.h
index e1ce0e0..b8e8713 100644
--- a/include/arch/linux-arm/AndroidConfig.h
+++ b/include/arch/linux-arm/AndroidConfig.h
@@ -96,7 +96,7 @@
/*
* Define this if you have <termio.h>
*/
-#define HAVE_TERMIO_H
+#define HAVE_TERMIO_H 1
/*
* Define this if you have <sys/sendfile.h>
@@ -111,7 +111,7 @@
/*
* Define this if you have sys/uio.h
*/
-#define HAVE_SYS_UIO_H
+#define HAVE_SYS_UIO_H 1
/*
* Define this if your platforms implements symbolic links
diff --git a/include/arch/linux-ppc/AndroidConfig.h b/include/arch/linux-ppc/AndroidConfig.h
index b9719e6..774c458 100644
--- a/include/arch/linux-ppc/AndroidConfig.h
+++ b/include/arch/linux-ppc/AndroidConfig.h
@@ -83,7 +83,7 @@
/*
* Define this if you have <termio.h>
*/
-#define HAVE_TERMIO_H
+#define HAVE_TERMIO_H 1
/*
* Define this if you have <sys/sendfile.h>
@@ -98,7 +98,7 @@
/*
* Define this if you have sys/uio.h
*/
-#define HAVE_SYS_UIO_H
+#define HAVE_SYS_UIO_H 1
/*
* Define this if your platforms implements symbolic links
diff --git a/include/arch/linux-sh/AndroidConfig.h b/include/arch/linux-sh/AndroidConfig.h
index a040b98..cdfa2ac 100644
--- a/include/arch/linux-sh/AndroidConfig.h
+++ b/include/arch/linux-sh/AndroidConfig.h
@@ -96,7 +96,7 @@
/*
* Define this if you have <termio.h>
*/
-#define HAVE_TERMIO_H
+#define HAVE_TERMIO_H 1
/*
* Define this if you have <sys/sendfile.h>
@@ -111,7 +111,7 @@
/*
* Define this if you have sys/uio.h
*/
-#define HAVE_SYS_UIO_H
+#define HAVE_SYS_UIO_H 1
/*
* Define this if your platforms implements symbolic links
diff --git a/include/arch/linux-x86/AndroidConfig.h b/include/arch/linux-x86/AndroidConfig.h
index 82e538c..6521699 100644
--- a/include/arch/linux-x86/AndroidConfig.h
+++ b/include/arch/linux-x86/AndroidConfig.h
@@ -83,7 +83,7 @@
/*
* Define this if you have <termio.h>
*/
-#define HAVE_TERMIO_H
+#define HAVE_TERMIO_H 1
/*
* Define this if you have <sys/sendfile.h>
@@ -98,7 +98,7 @@
/*
* Define this if you have sys/uio.h
*/
-#define HAVE_SYS_UIO_H
+#define HAVE_SYS_UIO_H 1
/*
* Define this if your platforms implements symbolic links
diff --git a/include/cutils/logprint.h b/include/cutils/logprint.h
index 769c8a7..2b1e1c5 100644
--- a/include/cutils/logprint.h
+++ b/include/cutils/logprint.h
@@ -44,8 +44,8 @@
time_t tv_sec;
long tv_nsec;
android_LogPriority priority;
- pid_t pid;
- pthread_t tid;
+ int32_t pid;
+ int32_t tid;
const char * tag;
size_t messageLen;
const char * message;
diff --git a/include/system/audio.h b/include/system/audio.h
index 0f19101..0980319 100644
--- a/include/system/audio.h
+++ b/include/system/audio.h
@@ -250,7 +250,9 @@
AUDIO_CHANNEL_IN_Z_AXIS |
AUDIO_CHANNEL_IN_VOICE_UPLINK |
AUDIO_CHANNEL_IN_VOICE_DNLINK),
-} audio_channels_t;
+};
+
+typedef uint32_t audio_channel_mask_t;
typedef enum {
AUDIO_MODE_INVALID = -2,
@@ -382,6 +384,38 @@
return false;
}
+/* Derive a channel mask from a channel count.
+ * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel
+ * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad,
+ * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC
+ * for continuity with stereo.
+ * Returns the matching channel mask, or 0 if the number of channels exceeds that of the
+ * configurations for which a default channel mask is defined.
+ */
+static inline audio_channel_mask_t audio_channel_mask_from_count(uint32_t channel_count)
+{
+ switch(channel_count) {
+ case 1:
+ return AUDIO_CHANNEL_OUT_MONO;
+ case 2:
+ return AUDIO_CHANNEL_OUT_STEREO;
+ case 3:
+ return (AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER);
+ case 4: // 4.0
+ return AUDIO_CHANNEL_OUT_QUAD;
+ case 5: // 5.0
+ return (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER);
+ case 6: // 5.1
+ return AUDIO_CHANNEL_OUT_5POINT1;
+ case 7: // 6.1
+ return (AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER);
+ case 8:
+ return AUDIO_CHANNEL_OUT_7POINT1;
+ default:
+ return 0;
+ }
+}
+
static inline bool audio_is_valid_format(audio_format_t format)
{
switch (format & AUDIO_FORMAT_MAIN_MASK) {
diff --git a/include/system/audio_policy.h b/include/system/audio_policy.h
index 1e0af7d..d45758a 100644
--- a/include/system/audio_policy.h
+++ b/include/system/audio_policy.h
@@ -34,7 +34,7 @@
* sharing an output with other AudioTracks)
*/
typedef enum {
- AUDIO_POLICY_OUTPUT_FLAG_INDIRECT = 0x0,
+ AUDIO_POLICY_OUTPUT_FLAG_NONE = 0x0,
AUDIO_POLICY_OUTPUT_FLAG_DIRECT = 0x1
} audio_policy_output_flags_t;
diff --git a/include/sysutils/FrameworkClient.h b/include/sysutils/FrameworkClient.h
index 0ef0753..4a3f0de 100644
--- a/include/sysutils/FrameworkClient.h
+++ b/include/sysutils/FrameworkClient.h
@@ -1,7 +1,7 @@
#ifndef _FRAMEWORK_CLIENT_H
#define _FRAMEWORK_CLIENT_H
-#include "../../../frameworks/base/include/utils/List.h"
+#include "List.h"
#include <pthread.h>
@@ -17,5 +17,5 @@
int sendMsg(const char *msg, const char *data);
};
-typedef android::List<FrameworkClient *> FrameworkClientCollection;
+typedef android::sysutils::List<FrameworkClient *> FrameworkClientCollection;
#endif
diff --git a/include/sysutils/FrameworkCommand.h b/include/sysutils/FrameworkCommand.h
index 6c1fca6..3e6264b 100644
--- a/include/sysutils/FrameworkCommand.h
+++ b/include/sysutils/FrameworkCommand.h
@@ -16,7 +16,7 @@
#ifndef __FRAMEWORK_CMD_HANDLER_H
#define __FRAMEWORK_CMD_HANDLER_H
-#include "../../../frameworks/base/include/utils/List.h"
+#include "List.h"
class SocketClient;
@@ -34,5 +34,5 @@
const char *getCommand() { return mCommand; }
};
-typedef android::List<FrameworkCommand *> FrameworkCommandCollection;
+typedef android::sysutils::List<FrameworkCommand *> FrameworkCommandCollection;
#endif
diff --git a/include/sysutils/List.h b/include/sysutils/List.h
new file mode 100644
index 0000000..31f7b37
--- /dev/null
+++ b/include/sysutils/List.h
@@ -0,0 +1,334 @@
+/*
+ * Copyright (C) 2005 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// Templated list class. Normally we'd use STL, but we don't have that.
+// This class mimics STL's interfaces.
+//
+// Objects are copied into the list with the '=' operator or with copy-
+// construction, so if the compiler's auto-generated versions won't work for
+// you, define your own.
+//
+// The only class you want to use from here is "List".
+//
+#ifndef _SYSUTILS_LIST_H
+#define _SYSUTILS_LIST_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+namespace android {
+namespace sysutils {
+
+/*
+ * Doubly-linked list. Instantiate with "List<MyClass> myList".
+ *
+ * Objects added to the list are copied using the assignment operator,
+ * so this must be defined.
+ */
+template<typename T>
+class List
+{
+protected:
+ /*
+ * One element in the list.
+ */
+ class _Node {
+ public:
+ explicit _Node(const T& val) : mVal(val) {}
+ ~_Node() {}
+ inline T& getRef() { return mVal; }
+ inline const T& getRef() const { return mVal; }
+ inline _Node* getPrev() const { return mpPrev; }
+ inline _Node* getNext() const { return mpNext; }
+ inline void setVal(const T& val) { mVal = val; }
+ inline void setPrev(_Node* ptr) { mpPrev = ptr; }
+ inline void setNext(_Node* ptr) { mpNext = ptr; }
+ private:
+ friend class List;
+ friend class _ListIterator;
+ T mVal;
+ _Node* mpPrev;
+ _Node* mpNext;
+ };
+
+ /*
+ * Iterator for walking through the list.
+ */
+
+ template <typename TYPE>
+ struct CONST_ITERATOR {
+ typedef _Node const * NodePtr;
+ typedef const TYPE Type;
+ };
+
+ template <typename TYPE>
+ struct NON_CONST_ITERATOR {
+ typedef _Node* NodePtr;
+ typedef TYPE Type;
+ };
+
+ template<
+ typename U,
+ template <class> class Constness
+ >
+ class _ListIterator {
+ typedef _ListIterator<U, Constness> _Iter;
+ typedef typename Constness<U>::NodePtr _NodePtr;
+ typedef typename Constness<U>::Type _Type;
+
+ explicit _ListIterator(_NodePtr ptr) : mpNode(ptr) {}
+
+ public:
+ _ListIterator() {}
+ _ListIterator(const _Iter& rhs) : mpNode(rhs.mpNode) {}
+ ~_ListIterator() {}
+
+ // this will handle conversions from iterator to const_iterator
+ // (and also all convertible iterators)
+ // Here, in this implementation, the iterators can be converted
+ // if the nodes can be converted
+ template<typename V> explicit
+ _ListIterator(const V& rhs) : mpNode(rhs.mpNode) {}
+
+
+ /*
+ * Dereference operator. Used to get at the juicy insides.
+ */
+ _Type& operator*() const { return mpNode->getRef(); }
+ _Type* operator->() const { return &(mpNode->getRef()); }
+
+ /*
+ * Iterator comparison.
+ */
+ inline bool operator==(const _Iter& right) const {
+ return mpNode == right.mpNode; }
+
+ inline bool operator!=(const _Iter& right) const {
+ return mpNode != right.mpNode; }
+
+ /*
+ * handle comparisons between iterator and const_iterator
+ */
+ template<typename OTHER>
+ inline bool operator==(const OTHER& right) const {
+ return mpNode == right.mpNode; }
+
+ template<typename OTHER>
+ inline bool operator!=(const OTHER& right) const {
+ return mpNode != right.mpNode; }
+
+ /*
+ * Incr/decr, used to move through the list.
+ */
+ inline _Iter& operator++() { // pre-increment
+ mpNode = mpNode->getNext();
+ return *this;
+ }
+ const _Iter operator++(int) { // post-increment
+ _Iter tmp(*this);
+ mpNode = mpNode->getNext();
+ return tmp;
+ }
+ inline _Iter& operator--() { // pre-increment
+ mpNode = mpNode->getPrev();
+ return *this;
+ }
+ const _Iter operator--(int) { // post-increment
+ _Iter tmp(*this);
+ mpNode = mpNode->getPrev();
+ return tmp;
+ }
+
+ inline _NodePtr getNode() const { return mpNode; }
+
+ _NodePtr mpNode; /* should be private, but older gcc fails */
+ private:
+ friend class List;
+ };
+
+public:
+ List() {
+ prep();
+ }
+ List(const List<T>& src) { // copy-constructor
+ prep();
+ insert(begin(), src.begin(), src.end());
+ }
+ virtual ~List() {
+ clear();
+ delete[] (unsigned char*) mpMiddle;
+ }
+
+ typedef _ListIterator<T, NON_CONST_ITERATOR> iterator;
+ typedef _ListIterator<T, CONST_ITERATOR> const_iterator;
+
+ List<T>& operator=(const List<T>& right);
+
+ /* returns true if the list is empty */
+ inline bool empty() const { return mpMiddle->getNext() == mpMiddle; }
+
+ /* return #of elements in list */
+ size_t size() const {
+ return size_t(distance(begin(), end()));
+ }
+
+ /*
+ * Return the first element or one past the last element. The
+ * _Node* we're returning is converted to an "iterator" by a
+ * constructor in _ListIterator.
+ */
+ inline iterator begin() {
+ return iterator(mpMiddle->getNext());
+ }
+ inline const_iterator begin() const {
+ return const_iterator(const_cast<_Node const*>(mpMiddle->getNext()));
+ }
+ inline iterator end() {
+ return iterator(mpMiddle);
+ }
+ inline const_iterator end() const {
+ return const_iterator(const_cast<_Node const*>(mpMiddle));
+ }
+
+ /* add the object to the head or tail of the list */
+ void push_front(const T& val) { insert(begin(), val); }
+ void push_back(const T& val) { insert(end(), val); }
+
+ /* insert before the current node; returns iterator at new node */
+ iterator insert(iterator posn, const T& val)
+ {
+ _Node* newNode = new _Node(val); // alloc & copy-construct
+ newNode->setNext(posn.getNode());
+ newNode->setPrev(posn.getNode()->getPrev());
+ posn.getNode()->getPrev()->setNext(newNode);
+ posn.getNode()->setPrev(newNode);
+ return iterator(newNode);
+ }
+
+ /* insert a range of elements before the current node */
+ void insert(iterator posn, const_iterator first, const_iterator last) {
+ for ( ; first != last; ++first)
+ insert(posn, *first);
+ }
+
+ /* remove one entry; returns iterator at next node */
+ iterator erase(iterator posn) {
+ _Node* pNext = posn.getNode()->getNext();
+ _Node* pPrev = posn.getNode()->getPrev();
+ pPrev->setNext(pNext);
+ pNext->setPrev(pPrev);
+ delete posn.getNode();
+ return iterator(pNext);
+ }
+
+ /* remove a range of elements */
+ iterator erase(iterator first, iterator last) {
+ while (first != last)
+ erase(first++); // don't erase than incr later!
+ return iterator(last);
+ }
+
+ /* remove all contents of the list */
+ void clear() {
+ _Node* pCurrent = mpMiddle->getNext();
+ _Node* pNext;
+
+ while (pCurrent != mpMiddle) {
+ pNext = pCurrent->getNext();
+ delete pCurrent;
+ pCurrent = pNext;
+ }
+ mpMiddle->setPrev(mpMiddle);
+ mpMiddle->setNext(mpMiddle);
+ }
+
+ /*
+ * Measure the distance between two iterators. On exist, "first"
+ * will be equal to "last". The iterators must refer to the same
+ * list.
+ *
+ * FIXME: This is actually a generic iterator function. It should be a
+ * template function at the top-level with specializations for things like
+ * vector<>, which can just do pointer math). Here we limit it to
+ * _ListIterator of the same type but different constness.
+ */
+ template<
+ typename U,
+ template <class> class CL,
+ template <class> class CR
+ >
+ ptrdiff_t distance(
+ _ListIterator<U, CL> first, _ListIterator<U, CR> last) const
+ {
+ ptrdiff_t count = 0;
+ while (first != last) {
+ ++first;
+ ++count;
+ }
+ return count;
+ }
+
+private:
+ /*
+ * I want a _Node but don't need it to hold valid data. More
+ * to the point, I don't want T's constructor to fire, since it
+ * might have side-effects or require arguments. So, we do this
+ * slightly uncouth storage alloc.
+ */
+ void prep() {
+ mpMiddle = (_Node*) new unsigned char[sizeof(_Node)];
+ mpMiddle->setPrev(mpMiddle);
+ mpMiddle->setNext(mpMiddle);
+ }
+
+ /*
+ * This node plays the role of "pointer to head" and "pointer to tail".
+ * It sits in the middle of a circular list of nodes. The iterator
+ * runs around the circle until it encounters this one.
+ */
+ _Node* mpMiddle;
+};
+
+/*
+ * Assignment operator.
+ *
+ * The simplest way to do this would be to clear out the target list and
+ * fill it with the source. However, we can speed things along by
+ * re-using existing elements.
+ */
+template<class T>
+List<T>& List<T>::operator=(const List<T>& right)
+{
+ if (this == &right)
+ return *this; // self-assignment
+ iterator firstDst = begin();
+ iterator lastDst = end();
+ const_iterator firstSrc = right.begin();
+ const_iterator lastSrc = right.end();
+ while (firstSrc != lastSrc && firstDst != lastDst)
+ *firstDst++ = *firstSrc++;
+ if (firstSrc == lastSrc) // ran out of elements in source?
+ erase(firstDst, lastDst); // yes, erase any extras
+ else
+ insert(lastDst, firstSrc, lastSrc); // copy remaining over
+ return *this;
+}
+
+}; // namespace sysutils
+}; // namespace android
+
+#endif // _SYSUTILS_LIST_H
diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h
index 6473b3a..65a5b1b 100644
--- a/include/sysutils/SocketClient.h
+++ b/include/sysutils/SocketClient.h
@@ -1,7 +1,7 @@
#ifndef _SOCKET_CLIENT_H
#define _SOCKET_CLIENT_H
-#include "../../../frameworks/base/include/utils/List.h"
+#include "List.h"
#include <pthread.h>
#include <cutils/atomic.h>
@@ -61,5 +61,5 @@
void init(int socket, bool owned, bool useCmdNum);
};
-typedef android::List<SocketClient *> SocketClientCollection;
+typedef android::sysutils::List<SocketClient *> SocketClientCollection;
#endif
diff --git a/init/init.c b/init/init.c
index 71c28b5..1ee88a7 100755
--- a/init/init.c
+++ b/init/init.c
@@ -940,7 +940,7 @@
}
/* run all property triggers based on current state of the properties */
- queue_builtin_action(queue_property_triggers_action, "queue_propety_triggers");
+ queue_builtin_action(queue_property_triggers_action, "queue_property_triggers");
#if BOOTCHART
diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c
index f8b7254..df43299 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -398,7 +398,7 @@
break;
case FORMAT_THREAD:
prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
- "%c(%5d:%p) ", priChar, pid, (void*)tid);
+ "%c(%5d:%5d) ", priChar, pid, tid);
strcpy(suffixBuf, "\n"); suffixLen = 1;
break;
case FORMAT_RAW:
@@ -417,8 +417,8 @@
break;
case FORMAT_LONG:
prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
- "[ %s %5d:%p %c/%-8s ]\n",
- timeBuf, pid, (void*)tid, priChar, tag);
+ "[ %s %5d:%5d %c/%-8s ]\n",
+ timeBuf, pid, tid, priChar, tag);
strcpy(suffixBuf, "\n\n"); suffixLen = 2;
break;
default:
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 8366c94..6fac84b 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -673,7 +673,7 @@
if (inCount != 0) {
fprintf(stderr,
- "Warning: leftover binary log data (%d bytes)\n", inCount);
+ "Warning: leftover binary log data (%zu bytes)\n", inCount);
}
/*
@@ -753,7 +753,7 @@
break;
case FORMAT_THREAD:
prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
- "%c(%5d:%p) ", priChar, entry->pid, (void*)entry->tid);
+ "%c(%5d:%5d) ", priChar, entry->pid, entry->tid);
strcpy(suffixBuf, "\n");
suffixLen = 1;
break;
@@ -773,15 +773,15 @@
case FORMAT_THREADTIME:
prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
"%s.%03ld %5d %5d %c %-8s: ", timeBuf, entry->tv_nsec / 1000000,
- (int)entry->pid, (int)entry->tid, priChar, entry->tag);
+ entry->pid, entry->tid, priChar, entry->tag);
strcpy(suffixBuf, "\n");
suffixLen = 1;
break;
case FORMAT_LONG:
prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
- "[ %s.%03ld %5d:%p %c/%-8s ]\n",
+ "[ %s.%03ld %5d:%5d %c/%-8s ]\n",
timeBuf, entry->tv_nsec / 1000000, entry->pid,
- (void*)entry->tid, priChar, entry->tag);
+ entry->tid, priChar, entry->tag);
strcpy(suffixBuf, "\n\n");
suffixLen = 2;
prefixSuffixIsHeaderFooter = 1;
diff --git a/nexus/Android.mk b/nexus/Android.mk
deleted file mode 100644
index f9f7110..0000000
--- a/nexus/Android.mk
+++ /dev/null
@@ -1,66 +0,0 @@
-BUILD_NEXUS := false
-ifeq ($(BUILD_NEXUS),true)
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- main.cpp \
- NexusCommand.cpp \
- CommandListener.cpp \
- Property.cpp \
- PropertyManager.cpp \
- InterfaceConfig.cpp \
- NetworkManager.cpp \
- Controller.cpp \
- WifiController.cpp \
- TiwlanWifiController.cpp \
- TiwlanEventListener.cpp \
- WifiNetwork.cpp \
- WifiStatusPoller.cpp \
- ScanResult.cpp \
- Supplicant.cpp \
- SupplicantEvent.cpp \
- SupplicantListener.cpp \
- SupplicantState.cpp \
- SupplicantEventFactory.cpp \
- SupplicantConnectedEvent.cpp \
- SupplicantAssociatingEvent.cpp \
- SupplicantAssociatedEvent.cpp \
- SupplicantStateChangeEvent.cpp \
- SupplicantScanResultsEvent.cpp \
- SupplicantConnectionTimeoutEvent.cpp \
- SupplicantDisconnectedEvent.cpp \
- SupplicantStatus.cpp \
- OpenVpnController.cpp \
- VpnController.cpp \
- LoopController.cpp \
- DhcpClient.cpp DhcpListener.cpp \
- DhcpState.cpp DhcpEvent.cpp \
-
-LOCAL_MODULE:= nexus
-
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS) -I../../../frameworks/base/include/
-
-LOCAL_CFLAGS :=
-
-LOCAL_SHARED_LIBRARIES := libsysutils libwpa_client
-
-include $(BUILD_EXECUTABLE)
-
-include $(CLEAR_VARS)
-LOCAL_SRC_FILES:= \
- nexctl.c \
-
-LOCAL_MODULE:= nexctl
-
-LOCAL_C_INCLUDES := $(KERNEL_HEADERS)
-
-LOCAL_CFLAGS :=
-
-LOCAL_SHARED_LIBRARIES := libcutils
-
-include $(BUILD_EXECUTABLE)
-
-endif # ifeq ($(BUILD_NEXUS),true)
diff --git a/nexus/CommandListener.cpp b/nexus/CommandListener.cpp
deleted file mode 100644
index 7c934a7..0000000
--- a/nexus/CommandListener.cpp
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <errno.h>
-
-#define LOG_TAG "CommandListener"
-#include <cutils/log.h>
-
-#include <sysutils/SocketClient.h>
-
-#include "CommandListener.h"
-#include "Controller.h"
-#include "Property.h"
-#include "NetworkManager.h"
-#include "WifiController.h"
-#include "VpnController.h"
-#include "ResponseCode.h"
-
-CommandListener::CommandListener() :
- FrameworkListener("nexus") {
- registerCmd(new WifiScanResultsCmd());
- registerCmd(new WifiListNetworksCmd());
- registerCmd(new WifiCreateNetworkCmd());
- registerCmd(new WifiRemoveNetworkCmd());
-
- registerCmd(new GetCmd());
- registerCmd(new SetCmd());
- registerCmd(new ListCmd());
-}
-
-/* -------------
- * Wifi Commands
- * ------------ */
-
-CommandListener::WifiCreateNetworkCmd::WifiCreateNetworkCmd() :
- NexusCommand("wifi_create_network") {
-}
-
-int CommandListener::WifiCreateNetworkCmd::runCommand(SocketClient *cli,
- int argc, char **argv) {
- NetworkManager *nm = NetworkManager::Instance();
- WifiController *wc = (WifiController *) nm->findController("WIFI");
- WifiNetwork *wn;
-
- if (!(wn = wc->createNetwork()))
- cli->sendMsg(ResponseCode::OperationFailed, "Failed to create network", true);
- else {
- char tmp[128];
- sprintf(tmp, "Created network id %d.", wn->getNetworkId());
- cli->sendMsg(ResponseCode::CommandOkay, tmp, false);
- }
- return 0;
-}
-
-CommandListener::WifiRemoveNetworkCmd::WifiRemoveNetworkCmd() :
- NexusCommand("wifi_remove_network") {
-}
-
-int CommandListener::WifiRemoveNetworkCmd::runCommand(SocketClient *cli,
- int argc, char **argv) {
- NetworkManager *nm = NetworkManager::Instance();
- WifiController *wc = (WifiController *) nm->findController("WIFI");
-
- if (wc->removeNetwork(atoi(argv[1])))
- cli->sendMsg(ResponseCode::OperationFailed, "Failed to remove network", true);
- else {
- cli->sendMsg(ResponseCode::CommandOkay, "Network removed.", false);
- }
- return 0;
-}
-
-CommandListener::WifiScanResultsCmd::WifiScanResultsCmd() :
- NexusCommand("wifi_scan_results") {
-}
-
-int CommandListener::WifiScanResultsCmd::runCommand(SocketClient *cli,
- int argc, char **argv) {
- NetworkManager *nm = NetworkManager::Instance();
- WifiController *wc = (WifiController *) nm->findController("WIFI");
-
- ScanResultCollection *src = wc->createScanResults();
- ScanResultCollection::iterator it;
- char buffer[256];
-
- for(it = src->begin(); it != src->end(); ++it) {
- sprintf(buffer, "%s %u %d %s %s",
- (*it)->getBssid(), (*it)->getFreq(), (*it)->getLevel(),
- (*it)->getFlags(), (*it)->getSsid());
- cli->sendMsg(ResponseCode::WifiScanResult, buffer, false);
- delete (*it);
- it = src->erase(it);
- }
-
- delete src;
- cli->sendMsg(ResponseCode::CommandOkay, "Scan results complete.", false);
- return 0;
-}
-
-CommandListener::WifiListNetworksCmd::WifiListNetworksCmd() :
- NexusCommand("wifi_list_networks") {
-}
-
-int CommandListener::WifiListNetworksCmd::runCommand(SocketClient *cli,
- int argc, char **argv) {
- NetworkManager *nm = NetworkManager::Instance();
- WifiController *wc = (WifiController *) nm->findController("WIFI");
-
- WifiNetworkCollection *src = wc->createNetworkList();
- WifiNetworkCollection::iterator it;
- char buffer[256];
-
- for(it = src->begin(); it != src->end(); ++it) {
- sprintf(buffer, "%d:%s", (*it)->getNetworkId(), (*it)->getSsid());
- cli->sendMsg(ResponseCode::WifiNetworkList, buffer, false);
- delete (*it);
- }
-
- delete src;
- cli->sendMsg(ResponseCode::CommandOkay, "Network listing complete.", false);
- return 0;
-}
-
-/* ------------
- * Vpn Commands
- * ------------ */
-
-/* ----------------
- * Generic Commands
- * ---------------- */
-CommandListener::GetCmd::GetCmd() :
- NexusCommand("get") {
-}
-
-int CommandListener::GetCmd::runCommand(SocketClient *cli, int argc, char **argv) {
- char val[Property::ValueMaxSize];
-
- if (!NetworkManager::Instance()->getPropMngr()->get(argv[1],
- val,
- sizeof(val))) {
- goto out_inval;
- }
-
- char *tmp;
- asprintf(&tmp, "%s %s", argv[1], val);
- cli->sendMsg(ResponseCode::PropertyRead, tmp, false);
- free(tmp);
-
- cli->sendMsg(ResponseCode::CommandOkay, "Property read.", false);
- return 0;
-out_inval:
- errno = EINVAL;
- cli->sendMsg(ResponseCode::CommandParameterError, "Failed to read property.", true);
- return 0;
-}
-
-CommandListener::SetCmd::SetCmd() :
- NexusCommand("set") {
-}
-
-int CommandListener::SetCmd::runCommand(SocketClient *cli, int argc,
- char **argv) {
- if (NetworkManager::Instance()->getPropMngr()->set(argv[1], argv[2]))
- goto out_inval;
-
- cli->sendMsg(ResponseCode::CommandOkay, "Property set.", false);
- return 0;
-
-out_inval:
- errno = EINVAL;
- cli->sendMsg(ResponseCode::CommandParameterError, "Failed to set property.", true);
- return 0;
-}
-
-CommandListener::ListCmd::ListCmd() :
- NexusCommand("list") {
-}
-
-int CommandListener::ListCmd::runCommand(SocketClient *cli, int argc, char **argv) {
- android::List<char *> *pc;
- char *prefix = NULL;
-
- if (argc > 1)
- prefix = argv[1];
-
- if (!(pc = NetworkManager::Instance()->getPropMngr()->createPropertyList(prefix))) {
- errno = ENODATA;
- cli->sendMsg(ResponseCode::CommandParameterError, "Failed to list properties.", true);
- return 0;
- }
-
- android::List<char *>::iterator it;
-
- for (it = pc->begin(); it != pc->end(); ++it) {
- char p_v[Property::ValueMaxSize];
-
- if (!NetworkManager::Instance()->getPropMngr()->get((*it),
- p_v,
- sizeof(p_v))) {
- ALOGW("Failed to get %s (%s)", (*it), strerror(errno));
- }
-
- char *buf;
- if (asprintf(&buf, "%s %s", (*it), p_v) < 0) {
- ALOGE("Failed to allocate memory");
- free((*it));
- continue;
- }
- cli->sendMsg(ResponseCode::PropertyList, buf, false);
- free(buf);
-
- free((*it));
- }
-
- delete pc;
-
- cli->sendMsg(ResponseCode::CommandOkay, "Properties list complete.", false);
- return 0;
-}
diff --git a/nexus/CommandListener.h b/nexus/CommandListener.h
deleted file mode 100644
index 30c6dc0..0000000
--- a/nexus/CommandListener.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _COMMANDLISTENER_H__
-#define _COMMANDLISTENER_H__
-
-#include <sysutils/FrameworkListener.h>
-#include "NexusCommand.h"
-
-class CommandListener : public FrameworkListener {
-public:
- CommandListener();
- virtual ~CommandListener() {}
-
-private:
-
- class WifiScanCmd : public NexusCommand {
- public:
- WifiScanCmd();
- virtual ~WifiScanCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-
- class WifiScanResultsCmd : public NexusCommand {
- public:
- WifiScanResultsCmd();
- virtual ~WifiScanResultsCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-
- class WifiCreateNetworkCmd : public NexusCommand {
- public:
- WifiCreateNetworkCmd();
- virtual ~WifiCreateNetworkCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-
- class WifiRemoveNetworkCmd : public NexusCommand {
- public:
- WifiRemoveNetworkCmd();
- virtual ~WifiRemoveNetworkCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-
- class WifiListNetworksCmd : public NexusCommand {
- public:
- WifiListNetworksCmd();
- virtual ~WifiListNetworksCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-
- class SetCmd : public NexusCommand {
- public:
- SetCmd();
- virtual ~SetCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-
- class GetCmd : public NexusCommand {
- public:
- GetCmd();
- virtual ~GetCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-
- class ListCmd : public NexusCommand {
- public:
- ListCmd();
- virtual ~ListCmd() {}
- int runCommand(SocketClient *c, int argc, char ** argv);
- };
-};
-
-#endif
diff --git a/nexus/Controller.cpp b/nexus/Controller.cpp
deleted file mode 100644
index dae8783..0000000
--- a/nexus/Controller.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#define LOG_TAG "Controller"
-
-#include <cutils/log.h>
-
-#include "Controller.h"
-#include "InterfaceConfig.h"
-
-extern "C" int init_module(void *, unsigned int, const char *);
-extern "C" int delete_module(const char *, unsigned int);
-
-Controller::Controller(const char *name, PropertyManager *propMngr,
- IControllerHandler *handlers) {
- mPropMngr = propMngr;
- mName = strdup(name);
- mHandlers = handlers;
- mBoundInterface = NULL;
-}
-
-Controller::~Controller() {
- if (mBoundInterface)
- free(mBoundInterface);
- if (mName)
- free(mName);
-}
-
-int Controller::start() {
- return 0;
-}
-
-int Controller::stop() {
- return 0;
-}
-
-int Controller::loadKernelModule(char *modpath, const char *args) {
- void *module;
- unsigned int size;
-
- module = loadFile(modpath, &size);
- if (!module) {
- errno = -EIO;
- return -1;
- }
-
- int rc = init_module(module, size, args);
- free (module);
- return rc;
-}
-
-int Controller::unloadKernelModule(const char *modtag) {
- int rc = -1;
- int retries = 10;
-
- while (retries--) {
- rc = delete_module(modtag, O_NONBLOCK | O_EXCL);
- if (rc < 0 && errno == EAGAIN)
- usleep(1000*500);
- else
- break;
- }
-
- if (rc != 0) {
- ALOGW("Unable to unload kernel driver '%s' (%s)", modtag,
- strerror(errno));
- }
- return rc;
-}
-
-bool Controller::isKernelModuleLoaded(const char *modtag) {
- FILE *fp = fopen("/proc/modules", "r");
-
- if (!fp) {
- ALOGE("Unable to open /proc/modules (%s)", strerror(errno));
- return false;
- }
-
- char line[255];
- while(fgets(line, sizeof(line), fp)) {
- char *endTag = strchr(line, ' ');
-
- if (!endTag) {
- ALOGW("Unable to find tag for line '%s'", line);
- continue;
- }
- if (!strncmp(line, modtag, (endTag - line))) {
- fclose(fp);
- return true;
- }
- }
-
- fclose(fp);
- return false;
-}
-
-void *Controller::loadFile(char *filename, unsigned int *_size)
-{
- int ret, fd;
- struct stat sb;
- ssize_t size;
- void *buffer = NULL;
-
- /* open the file */
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return NULL;
-
- /* find out how big it is */
- if (fstat(fd, &sb) < 0)
- goto bail;
- size = sb.st_size;
-
- /* allocate memory for it to be read into */
- buffer = malloc(size);
- if (!buffer)
- goto bail;
-
- /* slurp it into our buffer */
- ret = read(fd, buffer, size);
- if (ret != size)
- goto bail;
-
- /* let the caller know how big it is */
- *_size = size;
-
-bail:
- close(fd);
- return buffer;
-}
-
-int Controller::bindInterface(const char *ifname) {
- mBoundInterface = strdup(ifname);
- return 0;
-}
-
-int Controller::unbindInterface(const char *ifname) {
- free(mBoundInterface);
- mBoundInterface = NULL;
- return 0;
-}
diff --git a/nexus/Controller.h b/nexus/Controller.h
deleted file mode 100644
index e7e17c5..0000000
--- a/nexus/Controller.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _CONTROLLER_H
-#define _CONTROLLER_H
-
-#include <unistd.h>
-#include <sys/types.h>
-
-#include <utils/List.h>
-
-class PropertyManager;
-class IControllerHandler;
-
-#include "PropertyManager.h"
-
-class Controller {
- /*
- * Name of this controller - WIFI/VPN/USBNET/BTNET/BTDUN/LOOP/etc
- */
- char *mName;
-
- /*
- * Name of the system ethernet interface which this controller is
- * bound to.
- */
- char *mBoundInterface;
-
-protected:
- PropertyManager *mPropMngr;
- IControllerHandler *mHandlers;
-
-public:
- Controller(const char *name, PropertyManager *propMngr,
- IControllerHandler *handlers);
- virtual ~Controller();
-
- virtual int start();
- virtual int stop();
-
- const char *getName() { return mName; }
- const char *getBoundInterface() { return mBoundInterface; }
-
-protected:
- int loadKernelModule(char *modpath, const char *args);
- bool isKernelModuleLoaded(const char *modtag);
- int unloadKernelModule(const char *modtag);
- int bindInterface(const char *ifname);
- int unbindInterface(const char *ifname);
-
-private:
- void *loadFile(char *filename, unsigned int *_size);
-};
-
-typedef android::List<Controller *> ControllerCollection;
-#endif
diff --git a/nexus/DhcpClient.cpp b/nexus/DhcpClient.cpp
deleted file mode 100644
index 81fdf47..0000000
--- a/nexus/DhcpClient.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <pthread.h>
-
-#define LOG_TAG "DhcpClient"
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include <sysutils/ServiceManager.h>
-
-#include <netutils/ifc.h>
-#include <netutils/dhcp.h>
-
-#include "DhcpClient.h"
-#include "DhcpState.h"
-#include "DhcpListener.h"
-#include "IDhcpEventHandlers.h"
-#include "Controller.h"
-
-DhcpClient::DhcpClient(IDhcpEventHandlers *handlers) :
- mState(DhcpState::INIT), mHandlers(handlers) {
- mServiceManager = new ServiceManager();
- mListener = NULL;
- mListenerSocket = NULL;
- mController = NULL;
- mDoArpProbe = false;
- pthread_mutex_init(&mLock, NULL);
-}
-
-DhcpClient::~DhcpClient() {
- delete mServiceManager;
- if (mListener)
- delete mListener;
-}
-
-int DhcpClient::start(Controller *c) {
- ALOGD("Starting DHCP service (arp probe = %d)", mDoArpProbe);
- char svc[PROPERTY_VALUE_MAX];
- snprintf(svc,
- sizeof(svc),
- "dhcpcd:%s%s",
- (!mDoArpProbe ? "-A " : ""),
- c->getBoundInterface());
-
- pthread_mutex_lock(&mLock);
-
- if (mController) {
- pthread_mutex_unlock(&mLock);
- errno = EBUSY;
- return -1;
- }
- mController = c;
-
- sockaddr_in addr;
- if ((mListenerSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- ALOGE("Failed to create DHCP listener socket");
- pthread_mutex_unlock(&mLock);
- return -1;
- }
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- addr.sin_port = htons(DhcpClient::STATUS_MONITOR_PORT);
-
- if (bind(mListenerSocket, (struct sockaddr *) &addr, sizeof(addr))) {
- ALOGE("Failed to bind DHCP listener socket");
- close(mListenerSocket);
- mListenerSocket = -1;
- pthread_mutex_unlock(&mLock);
- return -1;
- }
-
- if (mServiceManager->start(svc)) {
- ALOGE("Failed to start dhcp service");
- pthread_mutex_unlock(&mLock);
- return -1;
- }
-
- mListener = new DhcpListener(mController, mListenerSocket, mHandlers);
- if (mListener->startListener()) {
- ALOGE("Failed to start listener");
-#if 0
- mServiceManager->stop("dhcpcd");
- return -1;
-#endif
- delete mListener;
- mListener = NULL;
- pthread_mutex_unlock(&mLock);
- }
-
- pthread_mutex_unlock(&mLock);
- return 0;
-}
-
-int DhcpClient::stop() {
- pthread_mutex_lock(&mLock);
- if (!mController) {
- pthread_mutex_unlock(&mLock);
- return 0;
- }
-
- if (mListener) {
- mListener->stopListener();
- delete mListener;
- mListener = NULL;
- }
- close(mListenerSocket);
-
- if (mServiceManager->stop("dhcpcd")) {
- ALOGW("Failed to stop DHCP service (%s)", strerror(errno));
- // XXX: Kill it the hard way.. but its gotta go!
- }
-
- mController = NULL;
- pthread_mutex_unlock(&mLock);
- return 0;
-}
-
-void DhcpClient::setDoArpProbe(bool probe) {
- mDoArpProbe = probe;
-}
diff --git a/nexus/DhcpClient.h b/nexus/DhcpClient.h
deleted file mode 100644
index 42bfda0..0000000
--- a/nexus/DhcpClient.h
+++ /dev/null
@@ -1,54 +0,0 @@
-
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _DhcpClient_H
-#define _DhcpClient_H
-
-#include <pthread.h>
-
-class IDhcpEventHandlers;
-class ServiceManager;
-class DhcpListener;
-class Controller;
-
-class DhcpClient {
-public:
- static const int STATUS_MONITOR_PORT = 6666;
-
-private:
- int mState;
- IDhcpEventHandlers *mHandlers;
- ServiceManager *mServiceManager;
- DhcpListener *mListener;
- int mListenerSocket;
- pthread_mutex_t mLock;
- Controller *mController;
- bool mDoArpProbe;
-
-public:
- DhcpClient(IDhcpEventHandlers *handlers);
- virtual ~DhcpClient();
-
- int getState() { return mState; }
- bool getDoArpProbe() { return mDoArpProbe; }
- void setDoArpProbe(bool probe);
-
- int start(Controller *c);
- int stop();
-};
-
-#endif
diff --git a/nexus/DhcpEvent.cpp b/nexus/DhcpEvent.cpp
deleted file mode 100644
index 2f1ce6f..0000000
--- a/nexus/DhcpEvent.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-
-#define LOG_TAG "DhcpEvent"
-#include <cutils/log.h>
-
-#include "DhcpEvent.h"
-
-char *DhcpEvent::toString(int val, char *buffer, int max) {
- if (val == DhcpEvent::UNKNOWN)
- strncpy(buffer, "UNKNOWN", max);
- else if (val == DhcpEvent::STOP)
- strncpy(buffer, "STOP", max);
- else if (val == DhcpEvent::RENEW)
- strncpy(buffer, "RENEW", max);
- else if (val == DhcpEvent::RELEASE)
- strncpy(buffer, "RELEASE", max);
- else if (val == DhcpEvent::TIMEOUT)
- strncpy(buffer, "TIMEOUT", max);
- else
- strncpy(buffer, "(internal error)", max);
-
- return buffer;
-}
-
-int DhcpEvent::parseString(const char *buffer) {
- if (!strcasecmp(buffer, "UNKNOWN"))
- return DhcpEvent::UNKNOWN;
- else if (!strcasecmp(buffer, "STOP"))
- return DhcpEvent::STOP;
- else if (!strcasecmp(buffer, "RENEW"))
- return DhcpEvent::RENEW;
- else if (!strcasecmp(buffer, "RELEASE"))
- return DhcpEvent::RELEASE;
- else if (!strcasecmp(buffer, "TIMEOUT"))
- return DhcpEvent::TIMEOUT;
- else {
- ALOGW("Bad event '%s'", buffer);
- return -1;
- }
-}
diff --git a/nexus/DhcpEvent.h b/nexus/DhcpEvent.h
deleted file mode 100644
index f77834d..0000000
--- a/nexus/DhcpEvent.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _DHCP_EVENT_H
-#define _DHCP_EVENT_H
-
-class DhcpEvent {
-public:
- static const int UNKNOWN = 0;
- static const int STOP = 1;
- static const int RENEW = 2;
- static const int RELEASE = 3;
- static const int TIMEOUT = 4;
-
- static char *toString(int val, char *buffer, int max);
-
- static int parseString(const char *buffer);
-};
-
-#endif
diff --git a/nexus/DhcpListener.cpp b/nexus/DhcpListener.cpp
deleted file mode 100644
index 16c369b..0000000
--- a/nexus/DhcpListener.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <errno.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#define LOG_TAG "DhcpListener"
-#include <cutils/log.h>
-
-#include <DhcpListener.h>
-#include "IDhcpEventHandlers.h"
-#include "DhcpState.h"
-#include "DhcpEvent.h"
-#include "Controller.h"
-
-DhcpListener::DhcpListener(Controller *c, int socket, IDhcpEventHandlers *handlers) :
- SocketListener(socket, false) {
- mHandlers = handlers;
- mController = c;
-}
-
-DhcpListener::~DhcpListener() {
-}
-
-bool DhcpListener::onDataAvailable(SocketClient *cli) {
- char buffer[255];
- int rc;
-
- if ((rc = read(cli->getSocket(), buffer, sizeof(buffer))) < 0) {
- ALOGW("Error reading dhcp status msg (%s)", strerror(errno));
- return true;
- }
-
- if (!strncmp(buffer, "STATE:", 6)) {
- char *next = buffer;
- char *tmp;
- int i;
-
- for (i = 0; i < 2; i++) {
- if (!(tmp = strsep(&next, ":"))) {
- ALOGW("Error parsing state '%s'", buffer);
- return true;
- }
- }
-
- int st = DhcpState::parseString(tmp);
- mHandlers->onDhcpStateChanged(mController, st);
- } else if (!strncmp(buffer, "ADDRINFO:", 9)) {
- char *next = buffer + 9;
- struct in_addr ipaddr, netmask, gateway, broadcast, dns1, dns2;
-
- if (!inet_aton(strsep(&next, ":"), &ipaddr)) {
- ALOGW("Malformatted IP specified");
- }
- if (!inet_aton(strsep(&next, ":"), &netmask)) {
- ALOGW("Malformatted netmask specified");
- }
- if (!inet_aton(strsep(&next, ":"), &broadcast)) {
- ALOGW("Malformatted broadcast specified");
- }
- if (!inet_aton(strsep(&next, ":"), &gateway)) {
- ALOGW("Malformatted gateway specified");
- }
- if (!inet_aton(strsep(&next, ":"), &dns1)) {
- ALOGW("Malformatted dns1 specified");
- }
- if (!inet_aton(strsep(&next, ":"), &dns2)) {
- ALOGW("Malformatted dns2 specified");
- }
- mHandlers->onDhcpLeaseUpdated(mController, &ipaddr, &netmask,
- &broadcast, &gateway, &dns1, &dns2);
-
- } else if (!strncmp(buffer, "EVENT:", 6)) {
- char *next = buffer;
- char *tmp;
- int i;
-
- for (i = 0; i < 2; i++) {
- if (!(tmp = strsep(&next, ":"))) {
- ALOGW("Error parsing event '%s'", buffer);
- return true;
- }
- }
-
- int ev = DhcpEvent::parseString(tmp);
- mHandlers->onDhcpEvent(mController, ev);
-
- } else {
- ALOGW("Unknown DHCP monitor msg '%s'", buffer);
- }
-
- return true;
-}
diff --git a/nexus/DhcpListener.h b/nexus/DhcpListener.h
deleted file mode 100644
index ca6fe37..0000000
--- a/nexus/DhcpListener.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _DhcpListener_H
-#define _DhcpListener_H
-
-#include <sysutils/SocketListener.h>
-
-class IDhcpEventHandlers;
-class Controller;
-
-class DhcpListener : public SocketListener {
- IDhcpEventHandlers *mHandlers;
- Controller *mController;
-
-public:
-
- DhcpListener(Controller *c, int socket, IDhcpEventHandlers *handlers);
- virtual ~DhcpListener();
-
-private:
- bool onDataAvailable(SocketClient *cli);
-};
-
-#endif
diff --git a/nexus/DhcpState.cpp b/nexus/DhcpState.cpp
deleted file mode 100644
index b86c186..0000000
--- a/nexus/DhcpState.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-
-#define LOG_TAG "DhcpState"
-#include <cutils/log.h>
-
-#include "DhcpState.h"
-
-char *DhcpState::toString(int val, char *buffer, int max) {
- if (val == DhcpState::INIT)
- strncpy(buffer, "INIT", max);
- else if (val == DhcpState::DISCOVERING)
- strncpy(buffer, "DISCOVERING", max);
- else if (val == DhcpState::REQUESTING)
- strncpy(buffer, "REQUESTING", max);
- else if (val == DhcpState::BOUND)
- strncpy(buffer, "BOUND", max);
- else if (val == DhcpState::RENEWING)
- strncpy(buffer, "RENEWING", max);
- else if (val == DhcpState::REBINDING)
- strncpy(buffer, "REBINDING", max);
- else if (val == DhcpState::REBOOT)
- strncpy(buffer, "REBOOT", max);
- else if (val == DhcpState::RENEW_REQUESTED)
- strncpy(buffer, "RENEW_REQUESTED", max);
- else if (val == DhcpState::INIT_IPV4LL)
- strncpy(buffer, "INIT_IPV4LL", max);
- else if (val == DhcpState::PROBING)
- strncpy(buffer, "PROBING", max);
- else if (val == DhcpState::ANNOUNCING)
- strncpy(buffer, "ANNOUNCING", max);
- else
- strncpy(buffer, "(internal error)", max);
-
- return buffer;
-}
-
-int DhcpState::parseString(const char *buffer) {
- if (!strcasecmp(buffer, "INIT"))
- return DhcpState::INIT;
- else if (!strcasecmp(buffer, "DISCOVERING"))
- return DhcpState::DISCOVERING;
- else if (!strcasecmp(buffer, "REQUESTING"))
- return DhcpState::REQUESTING;
- else if (!strcasecmp(buffer, "BOUND"))
- return DhcpState::BOUND;
- else if (!strcasecmp(buffer, "RENEWING"))
- return DhcpState::RENEWING;
- else if (!strcasecmp(buffer, "REBINDING"))
- return DhcpState::REBINDING;
- else if (!strcasecmp(buffer, "REBOOT"))
- return DhcpState::REBOOT;
- else if (!strcasecmp(buffer, "RENEW_REQUESTED"))
- return DhcpState::INIT_IPV4LL;
- else if (!strcasecmp(buffer, "INIT_IPV4LL"))
- return DhcpState::INIT_IPV4LL;
- else if (!strcasecmp(buffer, "PROBING"))
- return DhcpState::PROBING;
- else if (!strcasecmp(buffer, "ANNOUNCING"))
- return DhcpState::ANNOUNCING;
- else {
- ALOGW("Bad state '%s'", buffer);
- return -1;
- }
-}
diff --git a/nexus/DhcpState.h b/nexus/DhcpState.h
deleted file mode 100644
index 041c5d2..0000000
--- a/nexus/DhcpState.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _DHCP_STATE_H
-#define _DHCP_STATE_H
-
-class DhcpState {
-public:
- static const int INIT = 0;
- static const int DISCOVERING = 1;
- static const int REQUESTING = 2;
- static const int BOUND = 3;
- static const int RENEWING = 4;
- static const int REBINDING = 5;
- static const int REBOOT = 6;
- static const int RENEW_REQUESTED = 7;
- static const int INIT_IPV4LL = 8;
- static const int PROBING = 9;
- static const int ANNOUNCING = 10;
-
- static char *toString(int val, char *buffer, int max);
-
- static int parseString(const char *buffer);
-};
-
-#endif
diff --git a/nexus/IControllerHandler.h b/nexus/IControllerHandler.h
deleted file mode 100644
index 3151587..0000000
--- a/nexus/IControllerHandler.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _ICONTROLLER_HANDLER_H
-#define _ICONTROLLER_HANDLER_H
-
-class Controller;
-class InterfaceConfig;
-
-class IControllerHandler {
-public:
- virtual ~IControllerHandler() {}
- virtual void onInterfaceConnected(Controller *c) = 0;
- virtual void onInterfaceDisconnected(Controller *c) = 0;
- virtual void onControllerSuspending(Controller *c) = 0;
- virtual void onControllerResumed(Controller *c) = 0;
-};
-
-#endif
-
diff --git a/nexus/IDhcpEventHandlers.h b/nexus/IDhcpEventHandlers.h
deleted file mode 100644
index 2568f09..0000000
--- a/nexus/IDhcpEventHandlers.h
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IDhcpEventHandlers_H
-#define _IDhcpEventHandlers_H
-
-class IDhcpEventHandlers {
-public:
- virtual ~IDhcpEventHandlers() {}
- virtual void onDhcpStateChanged(Controller *c, int state) = 0;
- virtual void onDhcpEvent(Controller *c, int event) = 0;
- virtual void onDhcpLeaseUpdated(Controller *c,
- struct in_addr *addr, struct in_addr *net,
- struct in_addr *brd,
- struct in_addr *gw, struct in_addr *dns1,
- struct in_addr *dns2) = 0;
-};
-
-#endif
diff --git a/nexus/ISupplicantEventHandler.h b/nexus/ISupplicantEventHandler.h
deleted file mode 100644
index 1a3aa07..0000000
--- a/nexus/ISupplicantEventHandler.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _ISUPPLICANT_EVENT_HANDLER_H
-#define _ISUPPLICANT_EVENT_HANDLER_H
-
-class SupplicantAssociatingEvent;
-class SupplicantAssociatedEvent;
-class SupplicantConnectedEvent;
-class SupplicantScanResultsEvent;
-class SupplicantStateChangeEvent;
-class SupplicantConnectionTimeoutEvent;
-class SupplicantDisconnectedEvent;
-
-class ISupplicantEventHandler {
-public:
- virtual ~ISupplicantEventHandler(){}
- virtual void onAssociatingEvent(SupplicantAssociatingEvent *evt) = 0;
- virtual void onAssociatedEvent(SupplicantAssociatedEvent *evt) = 0;
- virtual void onConnectedEvent(SupplicantConnectedEvent *evt) = 0;
- virtual void onScanResultsEvent(SupplicantScanResultsEvent *evt) = 0;
- virtual void onStateChangeEvent(SupplicantStateChangeEvent *evt) = 0;
- virtual void onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt) = 0;
- virtual void onDisconnectedEvent(SupplicantDisconnectedEvent *evt) = 0;
-#if 0
- virtual void onTerminatingEvent(SupplicantEvent *evt) = 0;
- virtual void onPasswordChangedEvent(SupplicantEvent *evt) = 0;
- virtual void onEapNotificationEvent(SupplicantEvent *evt) = 0;
- virtual void onEapStartedEvent(SupplicantEvent *evt) = 0;
- virtual void onEapMethodEvent(SupplicantEvent *evt) = 0;
- virtual void onEapSuccessEvent(SupplicantEvent *evt) = 0;
- virtual void onEapFailureEvent(SupplicantEvent *evt) = 0;
- virtual void onLinkSpeedEvent(SupplicantEvent *evt) = 0;
- virtual void onDriverStateEvent(SupplicantEvent *evt) = 0;
-#endif
-};
-
-#endif
-
diff --git a/nexus/IWifiStatusPollerHandler.h b/nexus/IWifiStatusPollerHandler.h
deleted file mode 100644
index 9b94945..0000000
--- a/nexus/IWifiStatusPollerHandler.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _IWIFISTATUSPOLLER_HANDLER_H
-#define _IWIFISTATUSPOLLER_HANDLER_H
-
-class IWifiStatusPollerHandler {
-public:
- virtual ~IWifiStatusPollerHandler() {}
- virtual void onStatusPollInterval() = 0;
-};
-
-#endif
diff --git a/nexus/InterfaceConfig.cpp b/nexus/InterfaceConfig.cpp
deleted file mode 100644
index 832cbca..0000000
--- a/nexus/InterfaceConfig.cpp
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#define LOG_TAG "InterfaceConfig"
-#include <cutils/log.h>
-
-#include "InterfaceConfig.h"
-#include "NetworkManager.h"
-
-InterfaceConfig::InterfaceConfig(bool propertiesReadOnly) {
- mStaticProperties.propIp = new IPV4AddressPropertyHelper("Addr", propertiesReadOnly, &mIp);
- mStaticProperties.propNetmask = new IPV4AddressPropertyHelper("Netmask", propertiesReadOnly, &mNetmask);
- mStaticProperties.propGateway = new IPV4AddressPropertyHelper("Gateway", propertiesReadOnly, &mGateway);
- mStaticProperties.propBroadcast = new IPV4AddressPropertyHelper("Broadcast", propertiesReadOnly, &mBroadcast);
- mStaticProperties.propDns = new InterfaceDnsProperty(this, propertiesReadOnly);
-}
-
-InterfaceConfig::~InterfaceConfig() {
- delete mStaticProperties.propIp;
- delete mStaticProperties.propNetmask;
- delete mStaticProperties.propGateway;
- delete mStaticProperties.propBroadcast;
- delete mStaticProperties.propDns;
-}
-
-void InterfaceConfig::setIp(struct in_addr *addr) {
- memcpy(&mIp, addr, sizeof(struct in_addr));
-}
-
-void InterfaceConfig::setNetmask(struct in_addr *addr) {
- memcpy(&mNetmask, addr, sizeof(struct in_addr));
-}
-
-void InterfaceConfig::setGateway(struct in_addr *addr) {
- memcpy(&mGateway, addr, sizeof(struct in_addr));
-}
-
-void InterfaceConfig::setBroadcast(struct in_addr *addr) {
- memcpy(&mBroadcast, addr, sizeof(struct in_addr));
-}
-
-void InterfaceConfig::setDns(int idx, struct in_addr *addr) {
- memcpy(&mDns[idx], addr, sizeof(struct in_addr));
-}
-
-int InterfaceConfig::attachProperties(PropertyManager *pm, const char *nsName) {
- pm->attachProperty(nsName, mStaticProperties.propIp);
- pm->attachProperty(nsName, mStaticProperties.propNetmask);
- pm->attachProperty(nsName, mStaticProperties.propGateway);
- pm->attachProperty(nsName, mStaticProperties.propBroadcast);
- pm->attachProperty(nsName, mStaticProperties.propDns);
- return 0;
-}
-
-int InterfaceConfig::detachProperties(PropertyManager *pm, const char *nsName) {
- pm->detachProperty(nsName, mStaticProperties.propIp);
- pm->detachProperty(nsName, mStaticProperties.propNetmask);
- pm->detachProperty(nsName, mStaticProperties.propGateway);
- pm->detachProperty(nsName, mStaticProperties.propBroadcast);
- pm->detachProperty(nsName, mStaticProperties.propDns);
- return 0;
-}
-
-InterfaceConfig::InterfaceDnsProperty::InterfaceDnsProperty(InterfaceConfig *c,
- bool ro) :
- IPV4AddressProperty("Dns", ro, 2) {
- mCfg = c;
-}
-
-int InterfaceConfig::InterfaceDnsProperty::set(int idx, struct in_addr *value) {
- memcpy(&mCfg->mDns[idx], value, sizeof(struct in_addr));
- return 0;
-}
-int InterfaceConfig::InterfaceDnsProperty::get(int idx, struct in_addr *buf) {
- memcpy(buf, &mCfg->mDns[idx], sizeof(struct in_addr));
- return 0;
-}
-
diff --git a/nexus/InterfaceConfig.h b/nexus/InterfaceConfig.h
deleted file mode 100644
index 3fc7390..0000000
--- a/nexus/InterfaceConfig.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _INTERFACE_CONFIG_H
-#define _INTERFACE_CONFIG_H
-
-#include <unistd.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "Property.h"
-class PropertyManager;
-
-class InterfaceConfig {
- class InterfaceDnsProperty;
- friend class InterfaceConfig::InterfaceDnsProperty;
-
- struct {
- IPV4AddressPropertyHelper *propIp;
- IPV4AddressPropertyHelper *propNetmask;
- IPV4AddressPropertyHelper *propGateway;
- IPV4AddressPropertyHelper *propBroadcast;
- InterfaceDnsProperty *propDns;
- } mStaticProperties;
-
- struct in_addr mIp;
- struct in_addr mNetmask;
- struct in_addr mGateway;
- struct in_addr mBroadcast;
- struct in_addr mDns[2];
-
-public:
- InterfaceConfig(bool propertiesReadOnly);
- virtual ~InterfaceConfig();
-
- int set(const char *name, const char *value);
- const char *get(const char *name, char *buffer, size_t maxsize);
-
- const struct in_addr &getIp() const { return mIp; }
- const struct in_addr &getNetmask() const { return mNetmask; }
- const struct in_addr &getGateway() const { return mGateway; }
- const struct in_addr &getBroadcast() const { return mBroadcast; }
- const struct in_addr &getDns(int idx) const { return mDns[idx]; }
-
- void setIp(struct in_addr *addr);
- void setNetmask(struct in_addr *addr);
- void setGateway(struct in_addr *addr);
- void setBroadcast(struct in_addr *addr);
- void setDns(int idx, struct in_addr *addr);
-
- int attachProperties(PropertyManager *pm, const char *nsName);
- int detachProperties(PropertyManager *pm, const char *nsName);
-
-private:
-
- class InterfaceDnsProperty : public IPV4AddressProperty {
- InterfaceConfig *mCfg;
- public:
- InterfaceDnsProperty(InterfaceConfig *cfg, bool ro);
- int set(int idx, struct in_addr *value);
- int get(int idx, struct in_addr *buffer);
- };
-};
-
-
-#endif
diff --git a/nexus/LoopController.cpp b/nexus/LoopController.cpp
deleted file mode 100644
index f8e01d7..0000000
--- a/nexus/LoopController.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <errno.h>
-
-#include "LoopController.h"
-#include "PropertyManager.h"
-
-LoopController::LoopController(PropertyManager *propmngr,
- IControllerHandler *handlers) :
- Controller("loop", propmngr, handlers) {
-}
diff --git a/nexus/LoopController.h b/nexus/LoopController.h
deleted file mode 100644
index 53d16f1..0000000
--- a/nexus/LoopController.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _LOOP_CONTROLLER_H
-#define _LOOP_CONTROLLER_H
-
-#include "Controller.h"
-
-class ControllerHandler;
-
-class LoopController : public Controller {
-public:
- LoopController(PropertyManager *propmngr, IControllerHandler *h);
- virtual ~LoopController() {}
-
- int set(const char *name, const char *value);
- const char *get(const char *name, char *buffer, size_t maxsize);
-};
-
-#endif
diff --git a/nexus/NetworkManager.cpp b/nexus/NetworkManager.cpp
deleted file mode 100644
index d4285bf..0000000
--- a/nexus/NetworkManager.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <errno.h>
-
-#define LOG_TAG "Nexus"
-
-#include <cutils/log.h>
-
-#include "NetworkManager.h"
-#include "InterfaceConfig.h"
-#include "DhcpClient.h"
-#include "DhcpState.h"
-#include "DhcpEvent.h"
-#include "ResponseCode.h"
-
-NetworkManager *NetworkManager::sInstance = NULL;
-
-NetworkManager *NetworkManager::Instance() {
- if (!sInstance)
- sInstance = new NetworkManager(new PropertyManager());
- return sInstance;
-}
-
-NetworkManager::NetworkManager(PropertyManager *propMngr) {
- mBroadcaster = NULL;
- mControllerBindings = new ControllerBindingCollection();
- mPropMngr = propMngr;
- mLastDhcpState = DhcpState::INIT;
- mDhcp = new DhcpClient(this);
-}
-
-NetworkManager::~NetworkManager() {
-}
-
-int NetworkManager::run() {
- if (startControllers()) {
- ALOGW("Unable to start all controllers (%s)", strerror(errno));
- }
- return 0;
-}
-
-int NetworkManager::attachController(Controller *c) {
- ControllerBinding *cb = new ControllerBinding(c);
- mControllerBindings->push_back(cb);
- return 0;
-}
-
-int NetworkManager::startControllers() {
- int rc = 0;
- ControllerBindingCollection::iterator it;
-
- for (it = mControllerBindings->begin(); it != mControllerBindings->end(); ++it) {
- int irc = (*it)->getController()->start();
- if (irc && !rc)
- rc = irc;
- }
- return rc;
-}
-
-int NetworkManager::stopControllers() {
- int rc = 0;
- ControllerBindingCollection::iterator it;
-
- for (it = mControllerBindings->begin(); it != mControllerBindings->end(); ++it) {
- int irc = (*it)->getController()->stop();
- if (irc && !rc)
- rc = irc;
- }
- return rc;
-}
-
-NetworkManager::ControllerBinding *NetworkManager::lookupBinding(Controller *c) {
- ControllerBindingCollection::iterator it;
-
- for (it = mControllerBindings->begin(); it != mControllerBindings->end(); ++it) {
- if ((*it)->getController() == c)
- return (*it);
- }
- errno = ENOENT;
- return NULL;
-}
-
-Controller *NetworkManager::findController(const char *name) {
- ControllerBindingCollection::iterator it;
-
- for (it = mControllerBindings->begin(); it != mControllerBindings->end(); ++it) {
- if (!strcasecmp((*it)->getController()->getName(), name))
- return (*it)->getController();
- }
- errno = ENOENT;
- return NULL;
-}
-
-void NetworkManager::onInterfaceConnected(Controller *c) {
- ALOGD("Controller %s interface %s connected", c->getName(), c->getBoundInterface());
-
- if (mDhcp->start(c)) {
- ALOGE("Failed to start DHCP (%s)", strerror(errno));
- return;
- }
-}
-
-void NetworkManager::onInterfaceDisconnected(Controller *c) {
- ALOGD("Controller %s interface %s disconnected", c->getName(),
- c->getBoundInterface());
-
- mDhcp->stop();
-}
-
-void NetworkManager::onControllerSuspending(Controller *c) {
- ALOGD("Controller %s interface %s suspending", c->getName(),
- c->getBoundInterface());
- mDhcp->stop();
-}
-
-void NetworkManager::onControllerResumed(Controller *c) {
- ALOGD("Controller %s interface %s resumed", c->getName(),
- c->getBoundInterface());
-}
-
-void NetworkManager::onDhcpStateChanged(Controller *c, int state) {
- char tmp[255];
- char tmp2[255];
-
- ALOGD("onDhcpStateChanged(%s -> %s)",
- DhcpState::toString(mLastDhcpState, tmp, sizeof(tmp)),
- DhcpState::toString(state, tmp2, sizeof(tmp2)));
-
- switch(state) {
- case DhcpState::BOUND:
- // Refresh the 'net.xxx' for the controller
- break;
- case DhcpState::RENEWING:
- break;
- default:
- break;
- }
-
- char *tmp3;
- asprintf(&tmp3,
- "DHCP state changed from %d (%s) -> %d (%s)",
- mLastDhcpState,
- DhcpState::toString(mLastDhcpState, tmp, sizeof(tmp)),
- state,
- DhcpState::toString(state, tmp2, sizeof(tmp2)));
-
- getBroadcaster()->sendBroadcast(ResponseCode::DhcpStateChange,
- tmp3,
- false);
- free(tmp3);
-
- mLastDhcpState = state;
-}
-
-void NetworkManager::onDhcpEvent(Controller *c, int evt) {
- char tmp[64];
- ALOGD("onDhcpEvent(%s)", DhcpEvent::toString(evt, tmp, sizeof(tmp)));
-}
-
-void NetworkManager::onDhcpLeaseUpdated(Controller *c, struct in_addr *addr,
- struct in_addr *net,
- struct in_addr *brd,
- struct in_addr *gw,
- struct in_addr *dns1,
- struct in_addr *dns2) {
- ControllerBinding *bind = lookupBinding(c);
-
- if (!bind->getCurrentCfg())
- bind->setCurrentCfg(new InterfaceConfig(true));
-
- bind->getCurrentCfg()->setIp(addr);
- bind->getCurrentCfg()->setNetmask(net);
- bind->getCurrentCfg()->setGateway(gw);
- bind->getCurrentCfg()->setBroadcast(brd);
- bind->getCurrentCfg()->setDns(0, dns1);
- bind->getCurrentCfg()->setDns(1, dns2);
-}
-
-NetworkManager::ControllerBinding::ControllerBinding(Controller *c) :
- mController(c) {
-}
-
-void NetworkManager::ControllerBinding::setCurrentCfg(InterfaceConfig *c) {
- mCurrentCfg = c;
-}
-
-void NetworkManager::ControllerBinding::setBoundCfg(InterfaceConfig *c) {
- mBoundCfg = c;
-}
-
diff --git a/nexus/NetworkManager.h b/nexus/NetworkManager.h
deleted file mode 100644
index 93702ce..0000000
--- a/nexus/NetworkManager.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _NETWORKMANAGER_H
-#define _NETWORKMANAGER_H
-
-#include <utils/List.h>
-#include <sysutils/SocketListener.h>
-
-#include "Controller.h"
-#include "PropertyManager.h"
-#include "IControllerHandler.h"
-#include "IDhcpEventHandlers.h"
-
-class InterfaceConfig;
-class DhcpClient;
-
-class NetworkManager : public IControllerHandler, public IDhcpEventHandlers {
- static NetworkManager *sInstance;
-
- class ControllerBinding {
- Controller *mController;
- InterfaceConfig *mCurrentCfg;
- InterfaceConfig *mBoundCfg;
-
- public:
- ControllerBinding(Controller *c);
- virtual ~ControllerBinding() {}
-
- InterfaceConfig *getCurrentCfg() { return mCurrentCfg; }
- InterfaceConfig *getBoundCfg() { return mCurrentCfg; }
- Controller *getController() { return mController; }
-
- void setCurrentCfg(InterfaceConfig *cfg);
- void setBoundCfg(InterfaceConfig *cfg);
- };
-
- typedef android::List<ControllerBinding *> ControllerBindingCollection;
-
-private:
- ControllerBindingCollection *mControllerBindings;
- SocketListener *mBroadcaster;
- PropertyManager *mPropMngr;
- DhcpClient *mDhcp;
- int mLastDhcpState;
-
-public:
- virtual ~NetworkManager();
-
- int run();
-
- int attachController(Controller *controller);
-
- Controller *findController(const char *name);
-
- void setBroadcaster(SocketListener *sl) { mBroadcaster = sl; }
- SocketListener *getBroadcaster() { return mBroadcaster; }
- PropertyManager *getPropMngr() { return mPropMngr; }
-
- static NetworkManager *Instance();
-
-private:
- int startControllers();
- int stopControllers();
-
- NetworkManager(PropertyManager *propMngr);
- ControllerBinding *lookupBinding(Controller *c);
-
- void onInterfaceConnected(Controller *c);
- void onInterfaceDisconnected(Controller *c);
- void onControllerSuspending(Controller *c);
- void onControllerResumed(Controller *c);
-
- void onDhcpStateChanged(Controller *c, int state);
- void onDhcpEvent(Controller *c, int event);
- void onDhcpLeaseUpdated(Controller *c,
- struct in_addr *addr, struct in_addr *net,
- struct in_addr *brd,
- struct in_addr *gw, struct in_addr *dns1,
- struct in_addr *dns2);
-};
-#endif
diff --git a/nexus/NexusCommand.cpp b/nexus/NexusCommand.cpp
deleted file mode 100644
index 541eeeb..0000000
--- a/nexus/NexusCommand.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "NexusCommand.h"
-
-NexusCommand::NexusCommand(const char *cmd) :
- FrameworkCommand(cmd) {
-}
diff --git a/nexus/NexusCommand.h b/nexus/NexusCommand.h
deleted file mode 100644
index a7f944a..0000000
--- a/nexus/NexusCommand.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _NEXUS_COMMAND_H
-#define _NEXUS_COMMAND_H
-
-#include <sysutils/FrameworkCommand.h>
-
-class NexusCommand : public FrameworkCommand {
-public:
- NexusCommand(const char *cmd);
- virtual ~NexusCommand() {}
-};
-
-#endif
diff --git a/nexus/OpenVpnController.cpp b/nexus/OpenVpnController.cpp
deleted file mode 100644
index 6b6d892..0000000
--- a/nexus/OpenVpnController.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <errno.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#define LOG_TAG "OpenVpnController"
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include <sysutils/ServiceManager.h>
-
-#include "OpenVpnController.h"
-#include "PropertyManager.h"
-
-#define DAEMON_PROP_NAME "vpn.openvpn.status"
-#define DAEMON_CONFIG_FILE "/data/misc/openvpn/openvpn.conf"
-
-OpenVpnController::OpenVpnController(PropertyManager *propmngr,
- IControllerHandler *handlers) :
- VpnController(propmngr, handlers) {
- mServiceManager = new ServiceManager();
-}
-
-OpenVpnController::~OpenVpnController() {
- delete mServiceManager;
-}
-
-int OpenVpnController::start() {
- return VpnController::start();
-}
-
-int OpenVpnController::stop() {
- return VpnController::stop();
-}
-
-int OpenVpnController::enable() {
- char svc[PROPERTY_VALUE_MAX];
- char tmp[64];
-
- if (!mPropMngr->get("vpn.gateway", tmp, sizeof(tmp))) {
- ALOGE("Error reading property 'vpn.gateway' (%s)", strerror(errno));
- return -1;
- }
- snprintf(svc, sizeof(svc), "openvpn:--remote %s 1194", tmp);
-
- if (mServiceManager->start(svc))
- return -1;
-
- return 0;
-}
-
-int OpenVpnController::disable() {
- if (mServiceManager->stop("openvpn"))
- return -1;
- return 0;
-}
diff --git a/nexus/OpenVpnController.h b/nexus/OpenVpnController.h
deleted file mode 100644
index 529aab5..0000000
--- a/nexus/OpenVpnController.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _OPEN_VPN_CONTROLLER_H
-#define _OPEN_VPN_CONTROLLER_H
-
-#include "PropertyManager.h"
-#include "VpnController.h"
-
-class ServiceManager;
-class IControllerHandler;
-
-class OpenVpnController : public VpnController {
-private:
- ServiceManager *mServiceManager;
-
-public:
- OpenVpnController(PropertyManager *propmngr, IControllerHandler *handlers);
- virtual ~OpenVpnController();
-
- int start();
- int stop();
-
-private:
- int enable();
- int disable();
-};
-
-#endif
diff --git a/nexus/Property.cpp b/nexus/Property.cpp
deleted file mode 100644
index 6cfa955..0000000
--- a/nexus/Property.cpp
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <strings.h>
-#include <netinet/in.h>
-
-#define LOG_TAG "Property"
-
-#include <cutils/log.h>
-
-#include "Property.h"
-
-Property::Property(const char *name, bool readOnly,
- int type, int numElements) :
- mName(name), mReadOnly(readOnly), mType(type),
- mNumElements(numElements) {
- if (index(name, '.')) {
- ALOGW("Property name %s violates namespace rules", name);
- }
-}
-
-StringProperty::StringProperty(const char *name, bool ro, int elements) :
- Property(name, ro, Property::Type_STRING, elements) {
-}
-int StringProperty::set(int idx, int value) {
- ALOGE("Integer 'set' called on string property!");
- errno = EINVAL;
- return -1;
-}
-int StringProperty::set(int idx, struct in_addr *value) {
- ALOGE("IpAddr 'set' called on string property!");
- errno = EINVAL;
- return -1;
-}
-int StringProperty::get(int idx, int *buffer) {
- ALOGE("Integer 'get' called on string property!");
- errno = EINVAL;
- return -1;
-}
-int StringProperty::get(int idx, struct in_addr *buffer) {
- ALOGE("IpAddr 'get' called on string property!");
- errno = EINVAL;
- return -1;
-}
-
-StringPropertyHelper::StringPropertyHelper(const char *name, bool ro,
- char *buffer, size_t max) :
- StringProperty(name, ro, 1) {
- mBuffer = buffer;
- mMax = max;
-}
-
-int StringPropertyHelper::set(int idx, const char *value) {
- if (idx != 0) {
- ALOGW("Attempt to use array index on StringPropertyHelper::set");
- errno = EINVAL;
- return -1;
- }
- strncpy(mBuffer, value, mMax);
- return 0;
-}
-
-int StringPropertyHelper::get(int idx, char *buffer, size_t max) {
- if (idx != 0) {
- ALOGW("Attempt to use array index on StringPropertyHelper::get");
- errno = EINVAL;
- return -1;
- }
- strncpy(buffer, mBuffer, max);
- return 0;
-}
-
-IntegerProperty::IntegerProperty(const char *name, bool ro, int elements) :
- Property(name, ro, Property::Type_INTEGER, elements) {
-}
-
-int IntegerProperty::set(int idx, const char *value) {
- ALOGE("String 'set' called on integer property!");
- errno = EINVAL;
- return -1;
-}
-int IntegerProperty::set(int idx, struct in_addr *value) {
- ALOGE("IpAddr 'set' called on integer property!");
- errno = EINVAL;
- return -1;
-}
-int IntegerProperty::get(int idx, char *buffer, size_t max) {
- ALOGE("String 'get' called on integer property!");
- errno = EINVAL;
- return -1;
-}
-int IntegerProperty::get(int idx, struct in_addr *buffer) {
- ALOGE("IpAddr 'get' called on integer property!");
- errno = EINVAL;
- return -1;
-}
-
-IntegerPropertyHelper::IntegerPropertyHelper(const char *name, bool ro,
- int *buffer) :
- IntegerProperty(name, ro, 1) {
- mBuffer = buffer;
-}
-
-int IntegerPropertyHelper::set(int idx, int value) {
- if (idx != 0) {
- ALOGW("Attempt to use array index on IntegerPropertyHelper::set");
- errno = EINVAL;
- return -1;
- }
- *mBuffer = value;
- return 0;
-}
-
-int IntegerPropertyHelper::get(int idx, int *buffer) {
- if (idx != 0) {
- ALOGW("Attempt to use array index on IntegerPropertyHelper::get");
- errno = EINVAL;
- return -1;
- }
- *buffer = *mBuffer;
- return 0;
-}
-
-IPV4AddressProperty::IPV4AddressProperty(const char *name, bool ro, int elements) :
- Property(name, ro, Property::Type_IPV4, elements) {
-}
-
-int IPV4AddressProperty::set(int idx, const char *value) {
- ALOGE("String 'set' called on ipv4 property!");
- errno = EINVAL;
- return -1;
-}
-int IPV4AddressProperty::set(int idx, int value) {
- ALOGE("Integer 'set' called on ipv4 property!");
- errno = EINVAL;
- return -1;
-}
-int IPV4AddressProperty::get(int idx, char *buffer, size_t max) {
- ALOGE("String 'get' called on ipv4 property!");
- errno = EINVAL;
- return -1;
-}
-int IPV4AddressProperty::get(int idx, int *buffer) {
- ALOGE("Integer 'get' called on ipv4 property!");
- errno = EINVAL;
- return -1;
-}
-
-IPV4AddressPropertyHelper::IPV4AddressPropertyHelper(const char *name, bool ro,
- struct in_addr *buffer) :
- IPV4AddressProperty(name, ro, 1) {
- mBuffer = buffer;
-}
-
-int IPV4AddressPropertyHelper::set(int idx, struct in_addr *value) {
- if (idx != 0) {
- ALOGW("Attempt to use array index on IPV4AddressPropertyHelper::set");
- errno = EINVAL;
- return -1;
- }
- memcpy(mBuffer, value, sizeof(struct in_addr));
- return 0;
-}
-
-int IPV4AddressPropertyHelper::get(int idx, struct in_addr *buffer) {
- if (idx != 0) {
- ALOGW("Attempt to use array index on IPV4AddressPropertyHelper::get");
- errno = EINVAL;
- return -1;
- }
- memcpy(buffer, mBuffer, sizeof(struct in_addr));
- return 0;
-}
-
-PropertyNamespace::PropertyNamespace(const char *name) {
- mName = strdup(name);
- mProperties = new PropertyCollection();
-}
-
-PropertyNamespace::~PropertyNamespace() {
- PropertyCollection::iterator it;
- for (it = mProperties->begin(); it != mProperties->end();) {
- delete (*it);
- it = mProperties->erase(it);
- }
- delete mProperties;
- free(mName);
-}
diff --git a/nexus/Property.h b/nexus/Property.h
deleted file mode 100644
index ceea2d3..0000000
--- a/nexus/Property.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _PROPERTY_H
-#define _PROPERTY_H
-
-#include <netinet/in.h>
-#include <utils/List.h>
-
-class Property {
- const char *mName;
- bool mReadOnly;
- int mType;
- int mNumElements;
-
-public:
- static const int NameMaxSize = 128;
- static const int ValueMaxSize = 255;
-
- static const int Type_STRING = 1;
- static const int Type_INTEGER = 2;
- static const int Type_IPV4 = 3;
-
- Property(const char *name, bool ro, int type, int elements);
- virtual ~Property() {}
-
- virtual int set(int idx, const char *value) = 0;
- virtual int set(int idx, int value) = 0;
- virtual int set(int idx, struct in_addr *value) = 0;
-
- virtual int get(int idx, char *buffer, size_t max) = 0;
- virtual int get(int idx, int *buffer) = 0;
- virtual int get(int idx, struct in_addr *buffer) = 0;
-
- int getType() { return mType; }
- bool getReadOnly() { return mReadOnly; }
- int getNumElements() { return mNumElements; }
- const char *getName() { return mName; }
-};
-
-class StringProperty : public Property {
-public:
- StringProperty(const char *name, bool ro, int elements);
- virtual ~StringProperty() {}
-
- virtual int set(int idx, const char *value) = 0;
- int set(int idx, int value);
- int set(int idx, struct in_addr *value);
-
- virtual int get(int idx, char *buffer, size_t max) = 0;
- int get(int idx, int *buffer);
- int get(int idx, struct in_addr *buffer);
-};
-
-class StringPropertyHelper : public StringProperty {
- char *mBuffer;
- size_t mMax;
-public:
- StringPropertyHelper(const char *name, bool ro,
- char *buffer, size_t max);
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
-};
-
-class IntegerProperty : public Property {
-public:
- IntegerProperty(const char *name, bool ro, int elements);
- virtual ~IntegerProperty() {}
-
- int set(int idx, const char *value);
- virtual int set(int idx, int value) = 0;
- int set(int idx, struct in_addr *value);
-
- int get(int idx, char *buffer, size_t max);
- virtual int get(int idx, int *buffer) = 0;
- int get(int idx, struct in_addr *buffer);
-};
-
-class IntegerPropertyHelper : public IntegerProperty {
- int *mBuffer;
-public:
- IntegerPropertyHelper(const char *name, bool ro, int *buffer);
- int set(int idx, int value);
- int get(int idx, int *buffer);
-};
-
-class IPV4AddressProperty : public Property {
-public:
- IPV4AddressProperty(const char *name, bool ro, int elements);
- virtual ~IPV4AddressProperty() {}
-
- int set(int idx, const char *value);
- int set(int idx, int value);
- virtual int set(int idx, struct in_addr *value) = 0;
-
- int get(int idx, char *buffer, size_t max);
- int get(int idx, int *buffer);
- virtual int get(int idx, struct in_addr *buffer) = 0;
-};
-
-class IPV4AddressPropertyHelper : public IPV4AddressProperty {
- struct in_addr *mBuffer;
-public:
- IPV4AddressPropertyHelper(const char *name, bool ro, struct in_addr *buf);
- int set(int idx, struct in_addr *value);
- int get(int idx, struct in_addr *buffer);
-};
-
-typedef android::List<Property *> PropertyCollection;
-
-class PropertyNamespace {
- char *mName;
- PropertyCollection *mProperties;
-
-public:
- PropertyNamespace(const char *name);
- virtual ~PropertyNamespace();
-
- const char *getName() { return mName; }
- PropertyCollection *getProperties() { return mProperties; }
-};
-
-typedef android::List<PropertyNamespace *> PropertyNamespaceCollection;
-#endif
diff --git a/nexus/PropertyManager.cpp b/nexus/PropertyManager.cpp
deleted file mode 100644
index 41cdb41..0000000
--- a/nexus/PropertyManager.cpp
+++ /dev/null
@@ -1,280 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#define LOG_TAG "PropertyManager"
-
-#include <cutils/log.h>
-
-#include "PropertyManager.h"
-
-PropertyManager::PropertyManager() {
- mNamespaces = new PropertyNamespaceCollection();
- pthread_mutex_init(&mLock, NULL);
-}
-
-PropertyManager::~PropertyManager() {
- PropertyNamespaceCollection::iterator it;
-
- for (it = mNamespaces->begin(); it != mNamespaces->end();) {
- delete (*it);
- it = mNamespaces->erase(it);
- }
- delete mNamespaces;
-}
-
-PropertyNamespace *PropertyManager::lookupNamespace_UNLOCKED(const char *ns) {
- PropertyNamespaceCollection::iterator ns_it;
-
- for (ns_it = mNamespaces->begin(); ns_it != mNamespaces->end(); ++ns_it) {
- if (!strcasecmp(ns, (*ns_it)->getName()))
- return (*ns_it);
- }
- errno = ENOENT;
- return NULL;
-}
-
-Property *PropertyManager::lookupProperty_UNLOCKED(PropertyNamespace *ns, const char *name) {
- PropertyCollection::iterator it;
-
- for (it = ns->getProperties()->begin();
- it != ns->getProperties()->end(); ++it) {
- if (!strcasecmp(name, (*it)->getName()))
- return (*it);
- }
- errno = ENOENT;
- return NULL;
-}
-
-int PropertyManager::attachProperty(const char *ns_name, Property *p) {
- PropertyNamespace *ns;
-
- ALOGD("Attaching property %s to namespace %s", p->getName(), ns_name);
- pthread_mutex_lock(&mLock);
- if (!(ns = lookupNamespace_UNLOCKED(ns_name))) {
- ALOGD("Creating namespace %s", ns_name);
- ns = new PropertyNamespace(ns_name);
- mNamespaces->push_back(ns);
- }
-
- if (lookupProperty_UNLOCKED(ns, p->getName())) {
- errno = EADDRINUSE;
- pthread_mutex_unlock(&mLock);
- ALOGE("Failed to register property %s.%s (%s)",
- ns_name, p->getName(), strerror(errno));
- return -1;
- }
-
- ns->getProperties()->push_back(p);
- pthread_mutex_unlock(&mLock);
- return 0;
-}
-
-int PropertyManager::detachProperty(const char *ns_name, Property *p) {
- PropertyNamespace *ns;
-
- ALOGD("Detaching property %s from namespace %s", p->getName(), ns_name);
- pthread_mutex_lock(&mLock);
- if (!(ns = lookupNamespace_UNLOCKED(ns_name))) {
- pthread_mutex_unlock(&mLock);
- ALOGE("Namespace '%s' not found", ns_name);
- return -1;
- }
-
- PropertyCollection::iterator it;
-
- for (it = ns->getProperties()->begin();
- it != ns->getProperties()->end(); ++it) {
- if (!strcasecmp(p->getName(), (*it)->getName())) {
- delete ((*it));
- ns->getProperties()->erase(it);
- pthread_mutex_unlock(&mLock);
- return 0;
- }
- }
-
- ALOGE("Property %s.%s not found", ns_name, p->getName());
- pthread_mutex_unlock(&mLock);
- errno = ENOENT;
- return -1;
-}
-
-int PropertyManager::doSet(Property *p, int idx, const char *value) {
-
- if (p->getReadOnly()) {
- errno = EROFS;
- return -1;
- }
-
- if (p->getType() == Property::Type_STRING) {
- return p->set(idx, value);
- } else if (p->getType() == Property::Type_INTEGER) {
- int tmp;
- errno = 0;
- tmp = strtol(value, (char **) NULL, 10);
- if (errno) {
- ALOGE("Failed to convert '%s' to int", value);
- errno = EINVAL;
- return -1;
- }
- return p->set(idx, tmp);
- } else if (p->getType() == Property::Type_IPV4) {
- struct in_addr tmp;
- if (!inet_aton(value, &tmp)) {
- ALOGE("Failed to convert '%s' to ipv4", value);
- errno = EINVAL;
- return -1;
- }
- return p->set(idx, &tmp);
- } else {
- ALOGE("Property '%s' has an unknown type (%d)", p->getName(),
- p->getType());
- errno = EINVAL;
- return -1;
- }
- errno = ENOENT;
- return -1;
-}
-
-int PropertyManager::doGet(Property *p, int idx, char *buffer, size_t max) {
-
- if (p->getType() == Property::Type_STRING) {
- if (p->get(idx, buffer, max)) {
- ALOGW("String property %s get failed (%s)", p->getName(),
- strerror(errno));
- return -1;
- }
- }
- else if (p->getType() == Property::Type_INTEGER) {
- int tmp;
- if (p->get(idx, &tmp)) {
- ALOGW("Integer property %s get failed (%s)", p->getName(),
- strerror(errno));
- return -1;
- }
- snprintf(buffer, max, "%d", tmp);
- } else if (p->getType() == Property::Type_IPV4) {
- struct in_addr tmp;
- if (p->get(idx, &tmp)) {
- ALOGW("IPV4 property %s get failed (%s)", p->getName(),
- strerror(errno));
- return -1;
- }
- strncpy(buffer, inet_ntoa(tmp), max);
- } else {
- ALOGE("Property '%s' has an unknown type (%d)", p->getName(),
- p->getType());
- errno = EINVAL;
- return -1;
- }
- return 0;
-}
-
-/*
- * IPropertyManager methods
- */
-
-int PropertyManager::set(const char *name, const char *value) {
-
- ALOGD("set %s = '%s'", name, value);
- pthread_mutex_lock(&mLock);
- PropertyNamespaceCollection::iterator ns_it;
- for (ns_it = mNamespaces->begin(); ns_it != mNamespaces->end(); ++ns_it) {
- PropertyCollection::iterator p_it;
- for (p_it = (*ns_it)->getProperties()->begin();
- p_it != (*ns_it)->getProperties()->end(); ++p_it) {
- for (int i = 0; i < (*p_it)->getNumElements(); i++) {
- char fqn[255];
- char tmp[8];
- sprintf(tmp, "_%d", i);
- snprintf(fqn, sizeof(fqn), "%s.%s%s",
- (*ns_it)->getName(), (*p_it)->getName(),
- ((*p_it)->getNumElements() > 1 ? tmp : ""));
- if (!strcasecmp(name, fqn)) {
- pthread_mutex_unlock(&mLock);
- return doSet((*p_it), i, value);
- }
- }
- }
- }
-
- ALOGE("Property %s not found", name);
- pthread_mutex_unlock(&mLock);
- errno = ENOENT;
- return -1;
-}
-
-const char *PropertyManager::get(const char *name, char *buffer, size_t max) {
- pthread_mutex_lock(&mLock);
- PropertyNamespaceCollection::iterator ns_it;
- for (ns_it = mNamespaces->begin(); ns_it != mNamespaces->end(); ++ns_it) {
- PropertyCollection::iterator p_it;
- for (p_it = (*ns_it)->getProperties()->begin();
- p_it != (*ns_it)->getProperties()->end(); ++p_it) {
-
- for (int i = 0; i < (*p_it)->getNumElements(); i++) {
- char fqn[255];
- char tmp[8];
- sprintf(tmp, "_%d", i);
- snprintf(fqn, sizeof(fqn), "%s.%s%s",
- (*ns_it)->getName(), (*p_it)->getName(),
- ((*p_it)->getNumElements() > 1 ? tmp : ""));
- if (!strcasecmp(name, fqn)) {
- pthread_mutex_unlock(&mLock);
- if (doGet((*p_it), i, buffer, max))
- return NULL;
- return buffer;
- }
- }
- }
- }
-
- ALOGE("Property %s not found", name);
- pthread_mutex_unlock(&mLock);
- errno = ENOENT;
- return NULL;
-}
-
-android::List<char *> *PropertyManager::createPropertyList(const char *prefix) {
- android::List<char *> *c = new android::List<char *>();
-
- pthread_mutex_lock(&mLock);
- PropertyNamespaceCollection::iterator ns_it;
- for (ns_it = mNamespaces->begin(); ns_it != mNamespaces->end(); ++ns_it) {
- PropertyCollection::iterator p_it;
- for (p_it = (*ns_it)->getProperties()->begin();
- p_it != (*ns_it)->getProperties()->end(); ++p_it) {
- for (int i = 0; i < (*p_it)->getNumElements(); i++) {
- char fqn[255];
- char tmp[8];
- sprintf(tmp, "_%d", i);
- snprintf(fqn, sizeof(fqn), "%s.%s%s",
- (*ns_it)->getName(), (*p_it)->getName(),
- ((*p_it)->getNumElements() > 1 ? tmp : ""));
- if (!prefix ||
- (prefix && !strncasecmp(fqn, prefix, strlen(prefix)))) {
- c->push_back(strdup(fqn));
- }
- }
- }
- }
- pthread_mutex_unlock(&mLock);
- return c;
-}
diff --git a/nexus/PropertyManager.h b/nexus/PropertyManager.h
deleted file mode 100644
index af56a9c..0000000
--- a/nexus/PropertyManager.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _PROPERTY_MANAGER_H
-#define _PROPERTY_MANAGER_H
-
-#include <errno.h>
-#include <pthread.h>
-
-#include <utils/List.h>
-
-#include "Property.h"
-
-class PropertyManager {
- PropertyNamespaceCollection *mNamespaces;
- pthread_mutex_t mLock;
-
-public:
- PropertyManager();
- virtual ~PropertyManager();
- int attachProperty(const char *ns, Property *p);
- int detachProperty(const char *ns, Property *p);
-
- android::List<char *> *createPropertyList(const char *prefix);
-
- int set(const char *name, const char *value);
- const char *get(const char *name, char *buffer, size_t max);
-
-private:
- PropertyNamespace *lookupNamespace_UNLOCKED(const char *ns);
- Property *lookupProperty_UNLOCKED(PropertyNamespace *ns, const char *name);
- int doSet(Property *p, int idx, const char *value);
- int doGet(Property *p, int idx, char *buffer, size_t max);
-};
-
-#endif
diff --git a/nexus/ResponseCode.h b/nexus/ResponseCode.h
deleted file mode 100644
index 4b6cac8..0000000
--- a/nexus/ResponseCode.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _RESPONSECODE_H
-#define _RESPONSECODE_H
-
-class ResponseCode {
-public:
- // 100 series - Requestion action was initiated; expect another reply
- // before proceeding with a new command.
- static const int ActionInitiated = 100;
-
- static const int WifiScanResult = 125;
- static const int WifiNetworkList = 126;
-
- static const int PropertyRead = 127;
- static const int PropertySet = 128;
- static const int PropertyList = 129;
-
- // 200 series - Requested action has been successfully completed
- static const int CommandOkay = 200;
-
- // 400 series - The command was accepted but the requested action
- // did not take place.
- static const int OperationFailed = 400;
-
- // 500 series - The command was not accepted and the requested
- // action did not take place.
- static const int CommandSyntaxError = 500;
- static const int CommandParameterError = 501;
-
- // 600 series - Unsolicited broadcasts
- static const int UnsolicitedInformational = 600;
- static const int DhcpStateChange = 605;
- static const int SupplicantStateChange = 610;
- static const int ScanResultsReady = 615;
- static const int LinkSpeedChange = 620;
- static const int RssiChange = 625;
-};
-#endif
diff --git a/nexus/ScanResult.cpp b/nexus/ScanResult.cpp
deleted file mode 100644
index 72cb164..0000000
--- a/nexus/ScanResult.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <ctype.h>
-
-#define LOG_TAG "ScanResult"
-#include <cutils/log.h>
-
-#include "ScanResult.h"
-
-ScanResult::ScanResult() {
-}
-
-ScanResult::ScanResult(char *rawResult) {
- char *p = rawResult, *q = rawResult;
- char tmp[255];
-
- // BSSID
- for (q = p; *q != '\t'; ++q);
- strncpy(tmp, p, (q - p));
- tmp[q-p] = '\0';
- mBssid = strdup(tmp);
- ++q;
-
- // FREQ
- for (p = q; *q != '\t'; ++q);
- strncpy(tmp, p, (q - p));
- tmp[q-p] = '\0';
- mFreq = atoi(tmp);
- ++q;
-
- // LEVEL
- for (p = q; *q != '\t'; ++q);
- strncpy(tmp, p, (q - p));
- tmp[q-p] = '\0';
- mLevel = atoi(tmp);
- ++q;
-
- // FLAGS
- for (p = q; *q != '\t'; ++q);
- strncpy(tmp, p, (q - p));
- tmp[q-p] = '\0';
- mFlags = strdup(tmp);
- ++q;
-
- // XXX: For some reason Supplicant sometimes sends a double-tab here.
- // haven't had time to dig into it ...
- if (*q == '\t')
- q++;
-
- for (p = q; *q != '\t'; ++q) {
- if (*q == '\0')
- break;
- }
-
- strncpy(tmp, p, (q - p));
- tmp[q-p] = '\0';
- mSsid = strdup(tmp);
- ++q;
-
- return;
- out_bad:
- ALOGW("Malformatted scan result (%s)", rawResult);
-}
-
-ScanResult::~ScanResult() {
- if (mBssid)
- free(mBssid);
- if (mFlags)
- free(mFlags);
- if (mSsid)
- free(mSsid);
-}
-
-ScanResult *ScanResult::clone() {
- ScanResult *r = new ScanResult();
-
- r->mBssid = strdup(mBssid);
- r->mFreq = mFreq;
- r->mLevel = mLevel;
- r->mFlags = strdup(mFlags);
- r->mSsid = strdup(mSsid);
-
- return r;
-}
diff --git a/nexus/ScanResult.h b/nexus/ScanResult.h
deleted file mode 100644
index 68ad0f0..0000000
--- a/nexus/ScanResult.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SCAN_RESULT_H
-#define _SCAN_RESULT_H
-
-#include <sys/types.h>
-
-#include <utils/List.h>
-
-class ScanResult {
- char *mBssid;
- uint32_t mFreq;
- int mLevel;
- char *mFlags;
- char *mSsid;
-
-private:
- ScanResult();
-
-public:
- ScanResult(char *rawResult);
- virtual ~ScanResult();
-
- ScanResult *clone();
-
- const char *getBssid() { return mBssid; }
- uint32_t getFreq() { return mFreq; }
- int getLevel() { return mLevel; }
- const char *getFlags() { return mFlags; }
- const char *getSsid() { return mSsid; }
-};
-
-typedef android::List<ScanResult *> ScanResultCollection;
-
-#endif
diff --git a/nexus/Supplicant.cpp b/nexus/Supplicant.cpp
deleted file mode 100644
index b604698..0000000
--- a/nexus/Supplicant.cpp
+++ /dev/null
@@ -1,677 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#define LOG_TAG "Supplicant"
-#include <cutils/log.h>
-#include <cutils/properties.h>
-
-#include "private/android_filesystem_config.h"
-
-#include <sysutils/ServiceManager.h>
-
-#include "Supplicant.h"
-#include "SupplicantListener.h"
-#include "NetworkManager.h"
-#include "WifiController.h"
-#include "SupplicantStatus.h"
-
-#include "libwpa_client/wpa_ctrl.h"
-
-#define IFACE_DIR "/data/system/wpa_supplicant"
-#define DRIVER_PROP_NAME "wlan.driver.status"
-#define SUPPLICANT_SERVICE_NAME "wpa_supplicant"
-#define SUPP_CONFIG_TEMPLATE "/system/etc/wifi/wpa_supplicant.conf"
-#define SUPP_CONFIG_FILE "/data/misc/wifi/wpa_supplicant.conf"
-
-Supplicant::Supplicant(WifiController *wc, ISupplicantEventHandler *handlers) {
- mHandlers = handlers;
- mController = wc;
- mInterfaceName = NULL;
- mCtrl = NULL;
- mMonitor = NULL;
- mListener = NULL;
-
- mServiceManager = new ServiceManager();
-
- mNetworks = new WifiNetworkCollection();
- pthread_mutex_init(&mNetworksLock, NULL);
-}
-
-Supplicant::~Supplicant() {
- delete mServiceManager;
- if (mInterfaceName)
- free(mInterfaceName);
-}
-
-int Supplicant::start() {
-
- if (setupConfig()) {
- ALOGW("Unable to setup supplicant.conf");
- }
-
- if (mServiceManager->start(SUPPLICANT_SERVICE_NAME)) {
- ALOGE("Error starting supplicant (%s)", strerror(errno));
- return -1;
- }
-
- wpa_ctrl_cleanup();
- if (connectToSupplicant()) {
- ALOGE("Error connecting to supplicant (%s)\n", strerror(errno));
- return -1;
- }
-
- if (retrieveInterfaceName()) {
- ALOGE("Error retrieving interface name (%s)\n", strerror(errno));
- return -1;
- }
-
- return 0;
-}
-
-int Supplicant::stop() {
-
- if (mListener->stopListener()) {
- ALOGW("Unable to stop supplicant listener (%s)", strerror(errno));
- return -1;
- }
-
- if (mServiceManager->stop(SUPPLICANT_SERVICE_NAME)) {
- ALOGW("Error stopping supplicant (%s)", strerror(errno));
- }
-
- if (mCtrl) {
- wpa_ctrl_close(mCtrl);
- mCtrl = NULL;
- }
- if (mMonitor) {
- wpa_ctrl_close(mMonitor);
- mMonitor = NULL;
- }
-
- return 0;
-}
-
-bool Supplicant::isStarted() {
- return mServiceManager->isRunning(SUPPLICANT_SERVICE_NAME);
-}
-
-int Supplicant::sendCommand(const char *cmd, char *reply, size_t *reply_len) {
-
- if (!mCtrl) {
- errno = ENOTCONN;
- return -1;
- }
-
-// ALOGD("sendCommand(): -> '%s'", cmd);
-
- int rc;
- memset(reply, 0, *reply_len);
- if ((rc = wpa_ctrl_request(mCtrl, cmd, strlen(cmd), reply, reply_len, NULL)) == -2) {
- errno = ETIMEDOUT;
- return -1;
- } else if (rc < 0 || !strncmp(reply, "FAIL", 4)) {
- strcpy(reply, "FAIL");
- errno = EIO;
- return -1;
- }
-
- // ALOGD("sendCommand(): <- '%s'", reply);
- return 0;
-}
-SupplicantStatus *Supplicant::getStatus() {
- char *reply;
- size_t len = 4096;
-
- if (!(reply = (char *) malloc(len))) {
- errno = ENOMEM;
- return NULL;
- }
-
- if (sendCommand("STATUS", reply, &len)) {
- free(reply);
- return NULL;
- }
-
- SupplicantStatus *ss = SupplicantStatus::createStatus(reply, len);
-
- free (reply);
- return ss;
-}
-
-/*
- * Retrieves the list of networks from Supplicant
- * and merge them into our current list
- */
-int Supplicant::refreshNetworkList() {
- char *reply;
- size_t len = 4096;
-
- if (!(reply = (char *) malloc(len))) {
- errno = ENOMEM;
- return -1;
- }
-
- if (sendCommand("LIST_NETWORKS", reply, &len)) {
- free(reply);
- return -1;
- }
-
- char *linep;
- char *linep_next = NULL;
-
- if (!strtok_r(reply, "\n", &linep_next)) {
- ALOGW("Malformatted network list\n");
- free(reply);
- errno = EIO;
- return -1;
- }
-
- PropertyManager *pm = NetworkManager::Instance()->getPropMngr();
- pthread_mutex_lock(&mNetworksLock);
-
- int num_added = 0;
- int num_refreshed = 0;
- int num_removed = 0;
- while((linep = strtok_r(NULL, "\n", &linep_next))) {
- // TODO: Move the decode into a static method so we
- // don't create new_wn when we don't have to.
- WifiNetwork *new_wn = new WifiNetwork(mController, this, linep);
- WifiNetwork *merge_wn;
-
- if ((merge_wn = this->lookupNetwork_UNLOCKED(new_wn->getNetworkId()))) {
- num_refreshed++;
- if (merge_wn->refresh()) {
- ALOGW("Error refreshing network %d (%s)",
- merge_wn->getNetworkId(), strerror(errno));
- }
- delete new_wn;
- } else {
- num_added++;
- char new_ns[20];
- snprintf(new_ns, sizeof(new_ns), "wifi.net.%d", new_wn->getNetworkId());
- new_wn->attachProperties(pm, new_ns);
- mNetworks->push_back(new_wn);
- if (new_wn->refresh()) {
- ALOGW("Unable to refresh network id %d (%s)",
- new_wn->getNetworkId(), strerror(errno));
- }
- }
- }
-
- if (!mNetworks->empty()) {
- // TODO: Add support for detecting removed networks
- WifiNetworkCollection::iterator i;
-
- for (i = mNetworks->begin(); i != mNetworks->end(); ++i) {
- if (0) {
- num_removed++;
- char del_ns[20];
- snprintf(del_ns, sizeof(del_ns), "wifi.net.%d", (*i)->getNetworkId());
- (*i)->detachProperties(pm, del_ns);
- delete (*i);
- i = mNetworks->erase(i);
- }
- }
- }
-
-
- ALOGD("Networks added %d, refreshed %d, removed %d\n",
- num_added, num_refreshed, num_removed);
- pthread_mutex_unlock(&mNetworksLock);
-
- free(reply);
- return 0;
-}
-
-int Supplicant::connectToSupplicant() {
- if (!isStarted())
- ALOGW("Supplicant service not running");
-
- mCtrl = wpa_ctrl_open("tiwlan0"); // XXX:
- if (mCtrl == NULL) {
- ALOGE("Unable to open connection to supplicant on \"%s\": %s",
- "tiwlan0", strerror(errno));
- return -1;
- }
- mMonitor = wpa_ctrl_open("tiwlan0");
- if (mMonitor == NULL) {
- wpa_ctrl_close(mCtrl);
- mCtrl = NULL;
- return -1;
- }
- if (wpa_ctrl_attach(mMonitor) != 0) {
- wpa_ctrl_close(mMonitor);
- wpa_ctrl_close(mCtrl);
- mCtrl = mMonitor = NULL;
- return -1;
- }
-
- mListener = new SupplicantListener(mHandlers, mMonitor);
-
- if (mListener->startListener()) {
- ALOGE("Error - unable to start supplicant listener");
- stop();
- return -1;
- }
- return 0;
-}
-
-int Supplicant::setScanMode(bool active) {
- char reply[255];
- size_t len = sizeof(reply);
-
- if (sendCommand((active ? "DRIVER SCAN-ACTIVE" : "DRIVER SCAN-PASSIVE"),
- reply, &len)) {
- ALOGW("triggerScan(%d): Error setting scan mode (%s)", active,
- strerror(errno));
- return -1;
- }
- return 0;
-}
-
-int Supplicant::triggerScan() {
- char reply[255];
- size_t len = sizeof(reply);
-
- if (sendCommand("SCAN", reply, &len)) {
- ALOGW("triggerScan(): Error initiating scan");
- return -1;
- }
- return 0;
-}
-
-int Supplicant::getRssi(int *buffer) {
- char reply[64];
- size_t len = sizeof(reply);
-
- if (sendCommand("DRIVER RSSI", reply, &len)) {
- ALOGW("Failed to get RSSI (%s)", strerror(errno));
- return -1;
- }
-
- char *next = reply;
- char *s;
- for (int i = 0; i < 3; i++) {
- if (!(s = strsep(&next, " "))) {
- ALOGE("Error parsing RSSI");
- errno = EIO;
- return -1;
- }
- }
- *buffer = atoi(s);
- return 0;
-}
-
-int Supplicant::getLinkSpeed() {
- char reply[64];
- size_t len = sizeof(reply);
-
- if (sendCommand("DRIVER LINKSPEED", reply, &len)) {
- ALOGW("Failed to get LINKSPEED (%s)", strerror(errno));
- return -1;
- }
-
- char *next = reply;
- char *s;
-
- if (!(s = strsep(&next, " "))) {
- ALOGE("Error parsing LINKSPEED");
- errno = EIO;
- return -1;
- }
-
- if (!(s = strsep(&next, " "))) {
- ALOGE("Error parsing LINKSPEED");
- errno = EIO;
- return -1;
- }
- return atoi(s);
-}
-
-int Supplicant::stopDriver() {
- char reply[64];
- size_t len = sizeof(reply);
-
- ALOGD("stopDriver()");
-
- if (sendCommand("DRIVER STOP", reply, &len)) {
- ALOGW("Failed to stop driver (%s)", strerror(errno));
- return -1;
- }
- return 0;
-}
-
-int Supplicant::startDriver() {
- char reply[64];
- size_t len = sizeof(reply);
-
- ALOGD("startDriver()");
- if (sendCommand("DRIVER START", reply, &len)) {
- ALOGW("Failed to start driver (%s)", strerror(errno));
- return -1;
- }
- return 0;
-}
-
-WifiNetwork *Supplicant::createNetwork() {
- char reply[255];
- size_t len = sizeof(reply) -1;
-
- if (sendCommand("ADD_NETWORK", reply, &len))
- return NULL;
-
- if (reply[strlen(reply) -1] == '\n')
- reply[strlen(reply) -1] = '\0';
-
- WifiNetwork *wn = new WifiNetwork(mController, this, atoi(reply));
- PropertyManager *pm = NetworkManager::Instance()->getPropMngr();
- pthread_mutex_lock(&mNetworksLock);
- char new_ns[20];
- snprintf(new_ns, sizeof(new_ns), "wifi.net.%d", wn->getNetworkId());
- wn->attachProperties(pm, new_ns);
- mNetworks->push_back(wn);
- pthread_mutex_unlock(&mNetworksLock);
- return wn;
-}
-
-int Supplicant::removeNetwork(WifiNetwork *wn) {
- char req[64];
-
- sprintf(req, "REMOVE_NETWORK %d", wn->getNetworkId());
- char reply[32];
- size_t len = sizeof(reply) -1;
-
- if (sendCommand(req, reply, &len))
- return -1;
-
- pthread_mutex_lock(&mNetworksLock);
- WifiNetworkCollection::iterator it;
- for (it = mNetworks->begin(); it != mNetworks->end(); ++it) {
- if ((*it) == wn) {
- mNetworks->erase(it);
- break;
- }
- }
- pthread_mutex_unlock(&mNetworksLock);
- return 0;
-}
-
-WifiNetwork *Supplicant::lookupNetwork(int networkId) {
- pthread_mutex_lock(&mNetworksLock);
- WifiNetwork *wn = lookupNetwork_UNLOCKED(networkId);
- pthread_mutex_unlock(&mNetworksLock);
- return wn;
-}
-
-WifiNetwork *Supplicant::lookupNetwork_UNLOCKED(int networkId) {
- WifiNetworkCollection::iterator it;
- for (it = mNetworks->begin(); it != mNetworks->end(); ++it) {
- if ((*it)->getNetworkId() == networkId) {
- return *it;
- }
- }
- errno = ENOENT;
- return NULL;
-}
-
-WifiNetworkCollection *Supplicant::createNetworkList() {
- WifiNetworkCollection *d = new WifiNetworkCollection();
- WifiNetworkCollection::iterator i;
-
- pthread_mutex_lock(&mNetworksLock);
- for (i = mNetworks->begin(); i != mNetworks->end(); ++i)
- d->push_back((*i)->clone());
-
- pthread_mutex_unlock(&mNetworksLock);
- return d;
-}
-
-int Supplicant::setupConfig() {
- char buf[2048];
- int srcfd, destfd;
- int nread;
-
- if (access(SUPP_CONFIG_FILE, R_OK|W_OK) == 0) {
- return 0;
- } else if (errno != ENOENT) {
- ALOGE("Cannot access \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno));
- return -1;
- }
-
- srcfd = open(SUPP_CONFIG_TEMPLATE, O_RDONLY);
- if (srcfd < 0) {
- ALOGE("Cannot open \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
- return -1;
- }
-
- destfd = open(SUPP_CONFIG_FILE, O_CREAT|O_WRONLY, 0660);
- if (destfd < 0) {
- close(srcfd);
- ALOGE("Cannot create \"%s\": %s", SUPP_CONFIG_FILE, strerror(errno));
- return -1;
- }
-
- while ((nread = read(srcfd, buf, sizeof(buf))) != 0) {
- if (nread < 0) {
- ALOGE("Error reading \"%s\": %s", SUPP_CONFIG_TEMPLATE, strerror(errno));
- close(srcfd);
- close(destfd);
- unlink(SUPP_CONFIG_FILE);
- return -1;
- }
- write(destfd, buf, nread);
- }
-
- close(destfd);
- close(srcfd);
-
- if (chown(SUPP_CONFIG_FILE, AID_SYSTEM, AID_WIFI) < 0) {
- ALOGE("Error changing group ownership of %s to %d: %s",
- SUPP_CONFIG_FILE, AID_WIFI, strerror(errno));
- unlink(SUPP_CONFIG_FILE);
- return -1;
- }
- return 0;
-}
-
-int Supplicant::setNetworkVar(int networkId, const char *var, const char *val) {
- char reply[255];
- size_t len = sizeof(reply) -1;
-
- ALOGD("netid %d, var '%s' = '%s'", networkId, var, val);
- char *tmp;
- asprintf(&tmp, "SET_NETWORK %d %s %s", networkId, var, val);
- if (sendCommand(tmp, reply, &len)) {
- free(tmp);
- return -1;
- }
- free(tmp);
-
- len = sizeof(reply) -1;
- if (sendCommand("SAVE_CONFIG", reply, &len)) {
- ALOGE("Error saving config after %s = %s", var, val);
- return -1;
- }
- return 0;
-}
-
-const char *Supplicant::getNetworkVar(int networkId, const char *var,
- char *buffer, size_t max) {
- size_t len = max - 1;
- char *tmp;
-
- asprintf(&tmp, "GET_NETWORK %d %s", networkId, var);
- if (sendCommand(tmp, buffer, &len)) {
- free(tmp);
- return NULL;
- }
- free(tmp);
- return buffer;
-}
-
-int Supplicant::enableNetwork(int networkId, bool enabled) {
- char req[64];
-
- if (enabled)
- sprintf(req, "ENABLE_NETWORK %d", networkId);
- else
- sprintf(req, "DISABLE_NETWORK %d", networkId);
-
- char reply[16];
- size_t len = sizeof(reply) -1;
-
- if (sendCommand(req, reply, &len))
- return -1;
- return 0;
-}
-
-int Supplicant::enablePacketFilter() {
- char req[128];
- char reply[16];
- size_t len;
- int i;
-
- for (i = 0; i <=3; i++) {
- snprintf(req, sizeof(req), "DRIVER RXFILTER-ADD %d", i);
- len = sizeof(reply);
- if (sendCommand(req, reply, &len))
- return -1;
- }
-
- len = sizeof(reply);
- if (sendCommand("DRIVER RXFILTER-START", reply, &len))
- return -1;
- return 0;
-}
-
-int Supplicant::disablePacketFilter() {
- char req[128];
- char reply[16];
- size_t len;
- int i;
-
- len = sizeof(reply);
- if (sendCommand("DRIVER RXFILTER-STOP", reply, &len))
- return -1;
-
- for (i = 3; i >=0; i--) {
- snprintf(req, sizeof(req), "DRIVER RXFILTER-REMOVE %d", i);
- len = sizeof(reply);
- if (sendCommand(req, reply, &len))
- return -1;
- }
- return 0;
-}
-
-int Supplicant::enableBluetoothCoexistenceScan() {
- char req[128];
- char reply[16];
- size_t len;
- int i;
-
- len = sizeof(reply);
- if (sendCommand("DRIVER BTCOEXSCAN-START", reply, &len))
- return -1;
- return 0;
-}
-
-int Supplicant::disableBluetoothCoexistenceScan() {
- char req[128];
- char reply[16];
- size_t len;
- int i;
-
- len = sizeof(reply);
- if (sendCommand("DRIVER BTCOEXSCAN-STOP", reply, &len))
- return -1;
- return 0;
-}
-
-int Supplicant::setBluetoothCoexistenceMode(int mode) {
- char req[64];
-
- sprintf(req, "DRIVER BTCOEXMODE %d", mode);
-
- char reply[16];
- size_t len = sizeof(reply) -1;
-
- if (sendCommand(req, reply, &len))
- return -1;
- return 0;
-}
-
-int Supplicant::setApScanMode(int mode) {
- char req[64];
-
-// ALOGD("setApScanMode(%d)", mode);
- sprintf(req, "AP_SCAN %d", mode);
-
- char reply[16];
- size_t len = sizeof(reply) -1;
-
- if (sendCommand(req, reply, &len))
- return -1;
- return 0;
-}
-
-
-int Supplicant::retrieveInterfaceName() {
- char reply[255];
- size_t len = sizeof(reply) -1;
-
- if (sendCommand("INTERFACES", reply, &len))
- return -1;
-
- reply[strlen(reply)-1] = '\0';
- mInterfaceName = strdup(reply);
- return 0;
-}
-
-int Supplicant::reconnect() {
- char req[128];
- char reply[16];
- size_t len;
- int i;
-
- len = sizeof(reply);
- if (sendCommand("RECONNECT", reply, &len))
- return -1;
- return 0;
-}
-
-int Supplicant::disconnect() {
- char req[128];
- char reply[16];
- size_t len;
- int i;
-
- len = sizeof(reply);
- if (sendCommand("DISCONNECT", reply, &len))
- return -1;
- return 0;
-}
-
-int Supplicant::getNetworkCount() {
- pthread_mutex_lock(&mNetworksLock);
- int cnt = mNetworks->size();
- pthread_mutex_unlock(&mNetworksLock);
- return cnt;
-}
diff --git a/nexus/Supplicant.h b/nexus/Supplicant.h
deleted file mode 100644
index 3900f4f..0000000
--- a/nexus/Supplicant.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SUPPLICANT_H
-#define _SUPPLICANT_H
-
-struct wpa_ctrl;
-class SupplicantListener;
-class ServiceManager;
-class Controller;
-class WifiController;
-class SupplicantStatus;
-
-#include <pthread.h>
-
-#include "WifiNetwork.h"
-#include "ISupplicantEventHandler.h"
-
-class Supplicant {
- struct wpa_ctrl *mCtrl;
- struct wpa_ctrl *mMonitor;
- SupplicantListener *mListener;
- ServiceManager *mServiceManager;
- WifiController *mController;
- char *mInterfaceName;
-
- WifiNetworkCollection *mNetworks;
- pthread_mutex_t mNetworksLock;
- ISupplicantEventHandler *mHandlers;
-
-public:
- Supplicant(WifiController *wc, ISupplicantEventHandler *handlers);
- virtual ~Supplicant();
-
- int start();
- int stop();
- bool isStarted();
-
- int setScanMode(bool active);
- int triggerScan();
-
- WifiNetwork *createNetwork();
- WifiNetwork *lookupNetwork(int networkId);
- int removeNetwork(WifiNetwork *net);
- WifiNetworkCollection *createNetworkList();
- int refreshNetworkList();
-
- int setNetworkVar(int networkId, const char *var, const char *value);
- const char *getNetworkVar(int networkid, const char *var, char *buffer,
- size_t max);
- int enableNetwork(int networkId, bool enabled);
-
- int disconnect();
- int reconnect();
- int reassociate();
- int setApScanMode(int mode);
- int enablePacketFilter();
- int disablePacketFilter();
- int setBluetoothCoexistenceMode(int mode);
- int enableBluetoothCoexistenceScan();
- int disableBluetoothCoexistenceScan();
- int stopDriver();
- int startDriver();
- int getRssi(int *buffer);
- int getLinkSpeed();
- int getNetworkCount();
-
- SupplicantStatus *getStatus();
-
- Controller *getController() { return (Controller *) mController; }
- const char *getInterfaceName() { return mInterfaceName; }
-
- int sendCommand(const char *cmd, char *reply, size_t *reply_len);
-
-private:
- int connectToSupplicant();
- int setupConfig();
- int retrieveInterfaceName();
- WifiNetwork *lookupNetwork_UNLOCKED(int networkId);
-};
-
-#endif
diff --git a/nexus/SupplicantAssociatedEvent.cpp b/nexus/SupplicantAssociatedEvent.cpp
deleted file mode 100644
index e40411e..0000000
--- a/nexus/SupplicantAssociatedEvent.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-
-#define LOG_TAG "SupplicantAssociatedEvent"
-#include <cutils/log.h>
-
-#include "SupplicantAssociatedEvent.h"
-
-SupplicantAssociatedEvent::SupplicantAssociatedEvent(int level, char *event,
- size_t len) :
- SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATED,
- level) {
- char *p = event;
-
- // "00:13:46:40:40:aa"
- mBssid = (char *) malloc(18);
- strncpy(mBssid, p, 17);
- mBssid[17] = '\0';
-}
-
-SupplicantAssociatedEvent::~SupplicantAssociatedEvent() {
- if (mBssid)
- free(mBssid);
-}
-
diff --git a/nexus/SupplicantAssociatedEvent.h b/nexus/SupplicantAssociatedEvent.h
deleted file mode 100644
index aa33c59..0000000
--- a/nexus/SupplicantAssociatedEvent.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantAssociatedEvent_H
-#define _SupplicantAssociatedEvent_H
-
-#include "SupplicantEvent.h"
-
-class SupplicantAssociatedEvent : public SupplicantEvent {
- char *mBssid;
- char *mSsid;
- int mFreq;
-
-public:
- SupplicantAssociatedEvent(int level, char *event, size_t len);
- virtual ~SupplicantAssociatedEvent();
-
- const char *getBssid() { return mBssid; }
-};
-
-#endif
diff --git a/nexus/SupplicantAssociatingEvent.cpp b/nexus/SupplicantAssociatingEvent.cpp
deleted file mode 100644
index 8fe502e..0000000
--- a/nexus/SupplicantAssociatingEvent.cpp
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-
-#define LOG_TAG "SupplicantAssociatingEvent"
-#include <cutils/log.h>
-
-#include "SupplicantAssociatingEvent.h"
-
-SupplicantAssociatingEvent::SupplicantAssociatingEvent(int level, char *event,
- size_t len) :
- SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATING,
- level) {
- char *p = event;
-
- mBssid = NULL;
- mSsid = NULL;
- mFreq = -1;
-
- // SSID 'default'
- // OR
- // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)"
-
- if (strncmp(event, "SSID", 4)) {
- mBssid = (char *) malloc(18);
- strncpy(mBssid, p, 17);
- mBssid[17] = '\0';
- p += 25;
-
- // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)"
- // ^
- // p
- char *q = index(p, '\'');
- if (!q) {
- ALOGE("Unable to decode SSID (p = {%s})\n", p);
- return;
- }
- mSsid = (char *) malloc((q - p) +1);
- strncpy(mSsid, p, q-p);
- mSsid[q-p] = '\0';
-
- p = q + 7;
-
- // "00:13:46:40:40:aa (SSID='default' freq=2437 MHz)"
- // ^
- // p
- if (!(q = index(p, ' '))) {
- ALOGE("Unable to decode frequency\n");
- return;
- }
- *q = '\0';
- mFreq = atoi(p);
- } else {
- p+= 6;
-
- // SSID 'default'
- // ^
- // p
-
- char *q = index(p, '\'');
- if (!q) {
- ALOGE("Unable to decode SSID (p = {%s})\n", p);
- return;
- }
- mSsid = (char *) malloc((q - p) +1);
- strncpy(mSsid, p, q-p);
- mSsid[q-p] = '\0';
- }
-}
-
-SupplicantAssociatingEvent::SupplicantAssociatingEvent(const char *bssid,
- const char *ssid,
- int freq) :
- SupplicantEvent(SupplicantEvent::EVENT_ASSOCIATING, -1) {
- mBssid = strdup(bssid);
- mSsid= strdup(ssid);
- mFreq = freq;
-}
-
-SupplicantAssociatingEvent::~SupplicantAssociatingEvent() {
- if (mBssid)
- free(mBssid);
- if (mSsid)
- free(mSsid);
-}
-
diff --git a/nexus/SupplicantAssociatingEvent.h b/nexus/SupplicantAssociatingEvent.h
deleted file mode 100644
index d3a4d5c..0000000
--- a/nexus/SupplicantAssociatingEvent.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantAssociatingEvent_H
-#define _SupplicantAssociatingEvent_H
-
-#include "SupplicantEvent.h"
-
-class SupplicantAssociatingEvent : public SupplicantEvent {
- char *mBssid;
- char *mSsid;
- int mFreq;
-
-public:
- SupplicantAssociatingEvent(int level, char *event, size_t len);
- SupplicantAssociatingEvent(const char *bssid, const char *ssid, int freq);
- virtual ~SupplicantAssociatingEvent();
-
- const char *getBssid() { return mBssid; }
- const char *getSsid() { return mSsid; }
- int getFreq() { return mFreq;}
-};
-
-#endif
diff --git a/nexus/SupplicantConnectedEvent.cpp b/nexus/SupplicantConnectedEvent.cpp
deleted file mode 100644
index 107c766..0000000
--- a/nexus/SupplicantConnectedEvent.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "SupplicantConnectedEvent"
-#include <cutils/log.h>
-
-#include "SupplicantConnectedEvent.h"
-
-SupplicantConnectedEvent::SupplicantConnectedEvent(int level, char *event,
- size_t len) :
- SupplicantEvent(SupplicantEvent::EVENT_CONNECTED,
- level) {
- char *p;
-
- // "- Connection to 00:13:46:40:40:aa completed (auth) [id=1 id_str=], 89"
-
- if ((p = index(event + 2, ' ')) && (++p = index(p, ' '))) {
- mBssid = (char *) malloc(18);
- strncpy(mBssid, ++p, 17);
- mBssid[17] = '\0';
-
- // "- Connection to 00:13:46:40:40:aa completed (auth) [id=1 id_str=], 89"
- // ^
- // p
-
- if ((p = index(p, ' ')) && ((++p = index(p, ' ')))) {
- if (!strncmp(++p, "(auth)", 6))
- mReassociated = false;
- else
- mReassociated = true;
- } else
- ALOGE("Unable to decode re-assocation");
- } else
- ALOGE("Unable to decode event");
-}
-
-SupplicantConnectedEvent::SupplicantConnectedEvent(const char *bssid,
- bool reassocated) :
- SupplicantEvent(SupplicantEvent::EVENT_CONNECTED, -1) {
- mBssid = strdup(bssid);
- mReassociated = reassocated;
-}
-
-SupplicantConnectedEvent::~SupplicantConnectedEvent() {
- if (mBssid)
- free(mBssid);
-}
-
diff --git a/nexus/SupplicantConnectedEvent.h b/nexus/SupplicantConnectedEvent.h
deleted file mode 100644
index 03e9842..0000000
--- a/nexus/SupplicantConnectedEvent.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantConnectedEvent_H
-#define _SupplicantConnectedEvent_H
-
-#include "SupplicantEvent.h"
-
-class SupplicantConnectedEvent : public SupplicantEvent {
-private:
- char *mBssid;
- bool mReassociated;
-
-public:
- SupplicantConnectedEvent(int level, char *event, size_t len);
- SupplicantConnectedEvent(const char *bssid, bool reassicated);
- virtual ~SupplicantConnectedEvent();
-
- const char *getBssid() { return mBssid; }
- bool getReassociated() { return mReassociated; }
-};
-
-#endif
diff --git a/nexus/SupplicantConnectionTimeoutEvent.cpp b/nexus/SupplicantConnectionTimeoutEvent.cpp
deleted file mode 100644
index 8b8a7d7..0000000
--- a/nexus/SupplicantConnectionTimeoutEvent.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "SupplicantConnectionTimeoutEvent"
-#include <cutils/log.h>
-
-#include "SupplicantConnectionTimeoutEvent.h"
-
-SupplicantConnectionTimeoutEvent::SupplicantConnectionTimeoutEvent(int level, char *event,
- size_t len) :
- SupplicantEvent(SupplicantEvent::EVENT_CONNECTIONTIMEOUT,
- level) {
- // 00:13:46:40:40:aa timed out.'
- mBssid = (char *) malloc(18);
- strncpy(mBssid, event, 17);
- mBssid[17] = '\0';
-}
-
-SupplicantConnectionTimeoutEvent::~SupplicantConnectionTimeoutEvent() {
- if (mBssid)
- free(mBssid);
-}
-
diff --git a/nexus/SupplicantConnectionTimeoutEvent.h b/nexus/SupplicantConnectionTimeoutEvent.h
deleted file mode 100644
index 0d2606d..0000000
--- a/nexus/SupplicantConnectionTimeoutEvent.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantConnectionTimeoutEvent_H
-#define _SupplicantConnectionTimeoutEvent_H
-
-#include "SupplicantEvent.h"
-
-class SupplicantConnectionTimeoutEvent : public SupplicantEvent {
-private:
- char *mBssid;
- bool mReassociated;
-
-public:
- SupplicantConnectionTimeoutEvent(int level, char *event, size_t len);
- virtual ~SupplicantConnectionTimeoutEvent();
-
- const char *getBssid() { return mBssid; }
-};
-
-#endif
diff --git a/nexus/SupplicantDisconnectedEvent.cpp b/nexus/SupplicantDisconnectedEvent.cpp
deleted file mode 100644
index 11e499d..0000000
--- a/nexus/SupplicantDisconnectedEvent.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "SupplicantDisconnectedEvent"
-#include <cutils/log.h>
-
-#include "SupplicantDisconnectedEvent.h"
-
-SupplicantDisconnectedEvent::SupplicantDisconnectedEvent(int level, char *event,
- size_t len) :
- SupplicantEvent(SupplicantEvent::EVENT_DISCONNECTED,
- level) {
-}
-
-SupplicantDisconnectedEvent::SupplicantDisconnectedEvent() :
- SupplicantEvent(SupplicantEvent::EVENT_DISCONNECTED, -1) {
-}
-
-SupplicantDisconnectedEvent::~SupplicantDisconnectedEvent() {
-}
diff --git a/nexus/SupplicantDisconnectedEvent.h b/nexus/SupplicantDisconnectedEvent.h
deleted file mode 100644
index c09ec62..0000000
--- a/nexus/SupplicantDisconnectedEvent.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantDisconnectedEvent_H
-#define _SupplicantDisconnectedEvent_H
-
-#include "SupplicantEvent.h"
-
-class SupplicantDisconnectedEvent : public SupplicantEvent {
-
-public:
- SupplicantDisconnectedEvent(int level, char *event, size_t len);
- SupplicantDisconnectedEvent();
- virtual ~SupplicantDisconnectedEvent();
-};
-
-#endif
diff --git a/nexus/SupplicantEvent.cpp b/nexus/SupplicantEvent.cpp
deleted file mode 100644
index faf7b45..0000000
--- a/nexus/SupplicantEvent.cpp
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-
-#define LOG_TAG "SupplicantEvent"
-#include <cutils/log.h>
-
-#include "SupplicantEvent.h"
-
-#include "libwpa_client/wpa_ctrl.h"
-
-SupplicantEvent::SupplicantEvent(int type, int level) {
- mType = type;
- mLevel = level;
-}
diff --git a/nexus/SupplicantEvent.h b/nexus/SupplicantEvent.h
deleted file mode 100644
index 9d7cbd9..0000000
--- a/nexus/SupplicantEvent.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SUPPLICANT_EVENT_H
-#define _SUPPLICANT_EVENT_H
-
-#include <sys/types.h>
-
-class SupplicantEvent {
-private:
- int mType;
- int mLevel;
-
-public:
- static const int EVENT_UNKNOWN = 0;
- static const int EVENT_CONNECTED = 1;
- static const int EVENT_DISCONNECTED = 2;
- static const int EVENT_TERMINATING = 3;
- static const int EVENT_PASSWORD_CHANGED = 4;
- static const int EVENT_EAP_NOTIFICATION = 5;
- static const int EVENT_EAP_STARTED = 6;
- static const int EVENT_EAP_METHOD = 7;
- static const int EVENT_EAP_SUCCESS = 8;
- static const int EVENT_EAP_FAILURE = 9;
- static const int EVENT_SCAN_RESULTS = 10;
- static const int EVENT_STATE_CHANGE = 11;
- static const int EVENT_LINK_SPEED = 12;
- static const int EVENT_DRIVER_STATE = 13;
- static const int EVENT_ASSOCIATING = 14;
- static const int EVENT_ASSOCIATED = 15;
- static const int EVENT_CONNECTIONTIMEOUT = 16;
-
-public:
- SupplicantEvent(int type, int level);
- virtual ~SupplicantEvent() {}
-
- int getType() { return mType; }
- int getLevel() { return mLevel; }
-};
-
-#endif
diff --git a/nexus/SupplicantEventFactory.cpp b/nexus/SupplicantEventFactory.cpp
deleted file mode 100644
index f91db15..0000000
--- a/nexus/SupplicantEventFactory.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-
-#define LOG_TAG "SupplicantEventFactory"
-#include <cutils/log.h>
-
-#include "SupplicantEvent.h"
-#include "SupplicantEventFactory.h"
-#include "SupplicantAssociatingEvent.h"
-#include "SupplicantAssociatedEvent.h"
-#include "SupplicantConnectedEvent.h"
-#include "SupplicantStateChangeEvent.h"
-#include "SupplicantScanResultsEvent.h"
-#include "SupplicantConnectionTimeoutEvent.h"
-#include "SupplicantDisconnectedEvent.h"
-#if 0
-#include "SupplicantTerminatingEvent.h"
-#include "SupplicantPasswordChangedEvent.h"
-#include "SupplicantEapNotificationEvent.h"
-#include "SupplicantEapStartedEvent.h"
-#include "SupplicantEapMethodEvent.h"
-#include "SupplicantEapSuccessEvent.h"
-#include "SupplicantEapFailureEvent.h"
-#include "SupplicantLinkSpeedEvent.h"
-#include "SupplicantDriverStateEvent.h"
-#endif
-
-#include "libwpa_client/wpa_ctrl.h"
-
-SupplicantEventFactory::SupplicantEventFactory() {
-}
-
-SupplicantEvent *SupplicantEventFactory::createEvent(char *event, size_t len) {
- int level = 0;
-
- if (event[0] == '<') {
- char *match = strchr(event, '>');
- if (match) {
- char tmp[16];
-
- strncpy(tmp, &event[1], (match - event));
- level = atoi(tmp);
- event += (match - event) + 1;
- } else
- ALOGW("Unclosed level brace in event");
- } else
- ALOGW("No level specified in event");
-
- /*
- * <N>CTRL-EVENT-XXX
- * ^
- * +---- event
- */
-
- if (!strncmp(event, "Authentication with ", 20)) {
- if (!strcmp(event + strlen(event) - strlen(" timed out."),
- " timed out.")) {
- return new SupplicantConnectionTimeoutEvent(level,
- event + 20,
- len);
- } else
- return NULL;
-
- } else if (!strncmp(event, "Associated with ", 16))
- return new SupplicantAssociatedEvent(level, event + 16, len);
- else if (!strncmp(event, "Trying to associate with ", 25))
- return new SupplicantAssociatingEvent(level, event + 25, len);
- else if (!strncmp(event, WPA_EVENT_CONNECTED, strlen(WPA_EVENT_CONNECTED))) {
- return new SupplicantConnectedEvent(level,
- event + strlen(WPA_EVENT_CONNECTED),
- len);
- } else if (!strncmp(event, WPA_EVENT_SCAN_RESULTS, strlen(WPA_EVENT_SCAN_RESULTS))) {
- return new SupplicantScanResultsEvent(level,
- event + strlen(WPA_EVENT_SCAN_RESULTS),
- len);
- } else if (!strncmp(event, WPA_EVENT_STATE_CHANGE, strlen(WPA_EVENT_STATE_CHANGE))) {
- return new SupplicantStateChangeEvent(level,
- event + strlen(WPA_EVENT_STATE_CHANGE),
- len);
- }
- else if (!strncmp(event, WPA_EVENT_DISCONNECTED, strlen(WPA_EVENT_DISCONNECTED)))
- return new SupplicantDisconnectedEvent(level, event, len);
-#if 0
- else if (!strncmp(event, WPA_EVENT_TERMINATING, strlen(WPA_EVENT_TERMINATING)))
- return new SupplicantTerminatingEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_PASSWORD_CHANGED, strlen(WPA_EVENT_PASSWORD_CHANGED)))
- return new SupplicantPasswordChangedEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_EAP_NOTIFICATION, strlen(WPA_EVENT_EAP_NOTIFICATION)))
- return new SupplicantEapNotificationEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_EAP_STARTED, strlen(WPA_EVENT_EAP_STARTED)))
- return new SupplicantEapStartedEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_EAP_METHOD, strlen(WPA_EVENT_EAP_METHOD)))
- return new SupplicantEapMethodEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_EAP_SUCCESS, strlen(WPA_EVENT_EAP_SUCCESS)))
- return new SupplicantEapSuccessEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_EAP_FAILURE, strlen(WPA_EVENT_EAP_FAILURE)))
- return new SupplicantEapFailureEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_LINK_SPEED, strlen(WPA_EVENT_LINK_SPEED)))
- return new SupplicantLinkSpeedEvent(event, len);
- else if (!strncmp(event, WPA_EVENT_DRIVER_STATE, strlen(WPA_EVENT_DRIVER_STATE)))
- return new SupplicantDriverStateEvent(event, len);
-#endif
- return NULL;
-}
diff --git a/nexus/SupplicantEventFactory.h b/nexus/SupplicantEventFactory.h
deleted file mode 100644
index 22e5707..0000000
--- a/nexus/SupplicantEventFactory.h
+++ /dev/null
@@ -1,31 +0,0 @@
-
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantEventFactory_H
-#define _SupplicantEventFactory_H
-
-class SupplicantEvent;
-
-class SupplicantEventFactory {
-public:
- SupplicantEventFactory();
- virtual ~SupplicantEventFactory() {}
-
- SupplicantEvent *createEvent(char *event, size_t len);
-};
-
-#endif
diff --git a/nexus/SupplicantListener.cpp b/nexus/SupplicantListener.cpp
deleted file mode 100644
index 421d84d..0000000
--- a/nexus/SupplicantListener.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <errno.h>
-#include <sys/types.h>
-#include <pthread.h>
-
-#define LOG_TAG "SupplicantListener"
-#include <cutils/log.h>
-
-#include "libwpa_client/wpa_ctrl.h"
-
-#include "SupplicantListener.h"
-#include "ISupplicantEventHandler.h"
-#include "SupplicantEventFactory.h"
-#include "SupplicantEvent.h"
-#include "SupplicantAssociatingEvent.h"
-#include "SupplicantAssociatedEvent.h"
-#include "SupplicantConnectedEvent.h"
-#include "SupplicantScanResultsEvent.h"
-#include "SupplicantStateChangeEvent.h"
-
-SupplicantListener::SupplicantListener(ISupplicantEventHandler *handlers,
- struct wpa_ctrl *monitor) :
- SocketListener(wpa_ctrl_get_fd(monitor), false) {
- mHandlers = handlers;
- mMonitor = monitor;
- mFactory = new SupplicantEventFactory();
-}
-
-bool SupplicantListener::onDataAvailable(SocketClient *cli) {
- char buf[255];
- size_t buflen = sizeof(buf);
- int rc;
- size_t nread = buflen - 1;
-
- if ((rc = wpa_ctrl_recv(mMonitor, buf, &nread))) {
- ALOGE("wpa_ctrl_recv failed (%s)", strerror(errno));
- return false;
- }
-
- buf[nread] = '\0';
- if (!rc && !nread) {
- ALOGD("Received EOF on supplicant socket\n");
- strncpy(buf, WPA_EVENT_TERMINATING " - signal 0 received", buflen-1);
- buf[buflen-1] = '\0';
- return false;
- }
-
- SupplicantEvent *evt = mFactory->createEvent(buf, nread);
-
- if (!evt) {
- ALOGW("Dropping unknown supplicant event '%s'", buf);
- return true;
- }
-
- // Call the appropriate handler
- if (evt->getType() == SupplicantEvent::EVENT_ASSOCIATING)
- mHandlers->onAssociatingEvent((SupplicantAssociatingEvent *) evt);
- else if (evt->getType() == SupplicantEvent::EVENT_ASSOCIATED)
- mHandlers->onAssociatedEvent((SupplicantAssociatedEvent *) evt);
- else if (evt->getType() == SupplicantEvent::EVENT_CONNECTED)
- mHandlers->onConnectedEvent((SupplicantConnectedEvent *) evt);
- else if (evt->getType() == SupplicantEvent::EVENT_SCAN_RESULTS)
- mHandlers->onScanResultsEvent((SupplicantScanResultsEvent *) evt);
- else if (evt->getType() == SupplicantEvent::EVENT_STATE_CHANGE)
- mHandlers->onStateChangeEvent((SupplicantStateChangeEvent *) evt);
- else if (evt->getType() == SupplicantEvent::EVENT_CONNECTIONTIMEOUT)
- mHandlers->onConnectionTimeoutEvent((SupplicantConnectionTimeoutEvent *) evt);
- else if (evt->getType() == SupplicantEvent::EVENT_DISCONNECTED)
- mHandlers->onDisconnectedEvent((SupplicantDisconnectedEvent *) evt);
- else
- ALOGW("Whoops - no handler available for event '%s'\n", buf);
-#if 0
- else if (evt->getType() == SupplicantEvent::EVENT_TERMINATING)
- mHandlers->onTerminatingEvent(evt);
- else if (evt->getType() == SupplicantEvent::EVENT_PASSWORD_CHANGED)
- mHandlers->onPasswordChangedEvent(evt);
- else if (evt->getType() == SupplicantEvent::EVENT_EAP_NOTIFICATION)
- mHandlers->onEapNotificationEvent(evt);
- else if (evt->getType() == SupplicantEvent::EVENT_EAP_STARTED)
- mHandlers->onEapStartedEvent(evt);
- else if (evt->getType() == SupplicantEvent::EVENT_EAP_SUCCESS)
- mHandlers->onEapSuccessEvent(evt);
- else if (evt->getType() == SupplicantEvent::EVENT_EAP_FAILURE)
- mHandlers->onEapFailureEvent(evt);
- else if (evt->getType() == SupplicantEvent::EVENT_LINK_SPEED)
- mHandlers->onLinkSpeedEvent(evt);
- else if (evt->getType() == SupplicantEvent::EVENT_DRIVER_STATE)
- mHandlers->onDriverStateEvent(evt);
-#endif
-
- delete evt;
-
- return true;
-}
diff --git a/nexus/SupplicantListener.h b/nexus/SupplicantListener.h
deleted file mode 100644
index a1da773..0000000
--- a/nexus/SupplicantListener.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SUPPLICANTLISTENER_H__
-#define _SUPPLICANTLISTENER_H__
-
-#include <sysutils/SocketListener.h>
-
-struct wpa_ctrl;
-class Supplicant;
-class SocketClient;
-class ISupplicantEventHandler;
-class SupplicantEventFactory;
-
-class SupplicantListener: public SocketListener {
- struct wpa_ctrl *mMonitor;
- ISupplicantEventHandler *mHandlers;
- SupplicantEventFactory *mFactory;
-
-public:
- SupplicantListener(ISupplicantEventHandler *handlers,
- struct wpa_ctrl *monitor);
- virtual ~SupplicantListener() {}
-
- struct wpa_ctrl *getMonitor() { return mMonitor; }
-
-protected:
- virtual bool onDataAvailable(SocketClient *c);
-};
-
-#endif
diff --git a/nexus/SupplicantScanResultsEvent.cpp b/nexus/SupplicantScanResultsEvent.cpp
deleted file mode 100644
index c53adad..0000000
--- a/nexus/SupplicantScanResultsEvent.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "SupplicantScanResultsEvent"
-#include <cutils/log.h>
-
-#include "SupplicantScanResultsEvent.h"
-
-SupplicantScanResultsEvent::SupplicantScanResultsEvent(int level, char *event,
- size_t len) :
- SupplicantEvent(SupplicantEvent::EVENT_SCAN_RESULTS,
- level) {
-}
-
-SupplicantScanResultsEvent::SupplicantScanResultsEvent() :
- SupplicantEvent(SupplicantEvent::EVENT_SCAN_RESULTS, -1) {
-}
-
-SupplicantScanResultsEvent::~SupplicantScanResultsEvent() {
-}
-
diff --git a/nexus/SupplicantScanResultsEvent.h b/nexus/SupplicantScanResultsEvent.h
deleted file mode 100644
index 5f82041..0000000
--- a/nexus/SupplicantScanResultsEvent.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantScanResultsEvent_H
-#define _SupplicantScanResultsEvent_H
-
-#include "SupplicantEvent.h"
-
-class SupplicantScanResultsEvent : public SupplicantEvent {
-
-public:
- SupplicantScanResultsEvent(int level, char *event, size_t len);
- SupplicantScanResultsEvent();
- virtual ~SupplicantScanResultsEvent();
-};
-
-#endif
diff --git a/nexus/SupplicantState.cpp b/nexus/SupplicantState.cpp
deleted file mode 100644
index 2815430..0000000
--- a/nexus/SupplicantState.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-
-#define LOG_TAG "SupplicantState"
-#include <cutils/log.h>
-
-#include "SupplicantState.h"
-
-char *SupplicantState::toString(int val, char *buffer, int max) {
- if (val == SupplicantState::UNKNOWN)
- strncpy(buffer, "UNKNOWN", max);
- else if (val == SupplicantState::DISCONNECTED)
- strncpy(buffer, "DISCONNECTED", max);
- else if (val == SupplicantState::INACTIVE)
- strncpy(buffer, "INACTIVE", max);
- else if (val == SupplicantState::SCANNING)
- strncpy(buffer, "SCANNING", max);
- else if (val == SupplicantState::ASSOCIATING)
- strncpy(buffer, "ASSOCIATING", max);
- else if (val == SupplicantState::ASSOCIATED)
- strncpy(buffer, "ASSOCIATED", max);
- else if (val == SupplicantState::FOURWAY_HANDSHAKE)
- strncpy(buffer, "FOURWAY_HANDSHAKE", max);
- else if (val == SupplicantState::GROUP_HANDSHAKE)
- strncpy(buffer, "GROUP_HANDSHAKE", max);
- else if (val == SupplicantState::COMPLETED)
- strncpy(buffer, "COMPLETED", max);
- else if (val == SupplicantState::IDLE)
- strncpy(buffer, "IDLE", max);
- else
- strncpy(buffer, "(internal error)", max);
-
- return buffer;
-}
diff --git a/nexus/SupplicantState.h b/nexus/SupplicantState.h
deleted file mode 100644
index 6882f0c..0000000
--- a/nexus/SupplicantState.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SUPPLICANT_STATE_H
-#define _SUPPLICANT_STATE_H
-
-class SupplicantState {
-public:
- static const int UNKNOWN = -1;
- static const int DISCONNECTED = 0;
- static const int INACTIVE = 1;
- static const int SCANNING = 2;
- static const int ASSOCIATING = 3;
- static const int ASSOCIATED = 4;
- static const int FOURWAY_HANDSHAKE = 5;
- static const int GROUP_HANDSHAKE = 6;
- static const int COMPLETED = 7;
- static const int IDLE = 8;
-
- static char *toString(int val, char *buffer, int max);
-};
-
-#endif
diff --git a/nexus/SupplicantStateChangeEvent.cpp b/nexus/SupplicantStateChangeEvent.cpp
deleted file mode 100644
index fd9233a..0000000
--- a/nexus/SupplicantStateChangeEvent.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-
-#define LOG_TAG "SupplicantStateChangeEvent"
-#include <cutils/log.h>
-
-#include "SupplicantStateChangeEvent.h"
-
-SupplicantStateChangeEvent::SupplicantStateChangeEvent(int level, char *event,
- size_t len) :
- SupplicantEvent(SupplicantEvent::EVENT_STATE_CHANGE,
- level) {
- // XXX: move this stuff into a static creation method
- char *p = index(event, ' ');
- if (!p) {
- ALOGW("Bad event '%s'\n", event);
- return;
- }
-
- mState = atoi(p + strlen("state=") + 1);
-}
-
-SupplicantStateChangeEvent::SupplicantStateChangeEvent(int state) :
- SupplicantEvent(SupplicantEvent::EVENT_STATE_CHANGE, -1) {
- mState = state;
-}
-
-SupplicantStateChangeEvent::~SupplicantStateChangeEvent() {
-}
-
diff --git a/nexus/SupplicantStateChangeEvent.h b/nexus/SupplicantStateChangeEvent.h
deleted file mode 100644
index 77bff65..0000000
--- a/nexus/SupplicantStateChangeEvent.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantStateChangeEvent_H
-#define _SupplicantStateChangeEvent_H
-
-#include "SupplicantEvent.h"
-
-class SupplicantStateChangeEvent : public SupplicantEvent {
-private:
- int mState;
-
-public:
- SupplicantStateChangeEvent(int level, char *event, size_t len);
- SupplicantStateChangeEvent(int state);
- virtual ~SupplicantStateChangeEvent();
-
- int getState() { return mState; }
-};
-
-#endif
diff --git a/nexus/SupplicantStatus.cpp b/nexus/SupplicantStatus.cpp
deleted file mode 100644
index 8f28abe..0000000
--- a/nexus/SupplicantStatus.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-
-#define LOG_TAG "SupplicantStatus"
-#include <cutils/log.h>
-
-#include "SupplicantStatus.h"
-#include "SupplicantState.h"
-
-SupplicantStatus::SupplicantStatus() {
- mWpaState = SupplicantState::UNKNOWN;
- mId = -1;
- mBssid = NULL;
- mSsid = NULL;
-}
-
-SupplicantStatus::SupplicantStatus(int state, int id, char *bssid, char *ssid) :
- mWpaState(state), mId(id), mBssid(bssid), mSsid(ssid) {
-
-LOGD("state %d, id %d, bssid %p, ssid %p\n", mWpaState, mId, mBssid, mSsid);
-}
-
-SupplicantStatus::~SupplicantStatus() {
- if (mBssid)
- free(mBssid);
- if (mSsid)
- free(mSsid);
-}
-
-SupplicantStatus *SupplicantStatus::createStatus(char *data, int len) {
- char *bssid = NULL;
- char *ssid = NULL;
- int id = -1;
- int state = SupplicantState::UNKNOWN;
-
- char *next = data;
- char *line;
- while((line = strsep(&next, "\n"))) {
- char *line_next = line;
- char *token = strsep(&line_next, "=");
- char *value = strsep(&line_next, "=");
- if (!strcmp(token, "bssid"))
- bssid = strdup(value);
- else if (!strcmp(token, "ssid"))
- ssid = strdup(value);
- else if (!strcmp(token, "id"))
- id = atoi(value);
- else if (!strcmp(token, "wpa_state")) {
- if (!strcmp(value, "DISCONNECTED"))
- state = SupplicantState::DISCONNECTED;
- else if (!strcmp(value, "INACTIVE"))
- state = SupplicantState::INACTIVE;
- else if (!strcmp(value, "SCANNING"))
- state = SupplicantState::SCANNING;
- else if (!strcmp(value, "ASSOCIATING"))
- state = SupplicantState::ASSOCIATING;
- else if (!strcmp(value, "ASSOCIATED"))
- state = SupplicantState::ASSOCIATED;
- else if (!strcmp(value, "FOURWAY_HANDSHAKE"))
- state = SupplicantState::FOURWAY_HANDSHAKE;
- else if (!strcmp(value, "GROUP_HANDSHAKE"))
- state = SupplicantState::GROUP_HANDSHAKE;
- else if (!strcmp(value, "COMPLETED"))
- state = SupplicantState::COMPLETED;
- else if (!strcmp(value, "IDLE"))
- state = SupplicantState::IDLE;
- else
- ALOGE("Unknown supplicant state '%s'", value);
- } else
- ALOGD("Ignoring unsupported status token '%s'", token);
- }
-
- return new SupplicantStatus(state, id, bssid, ssid);
-
-}
diff --git a/nexus/SupplicantStatus.h b/nexus/SupplicantStatus.h
deleted file mode 100644
index ef01841..0000000
--- a/nexus/SupplicantStatus.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _SupplicantStatus_H
-#define _SupplicantStatus_H
-
-class SupplicantStatus {
-private:
- int mWpaState;
- int mId;
- char *mBssid;
- char *mSsid;
-
-private:
- SupplicantStatus();
- SupplicantStatus(int state, int id, char *bssid, char *ssid);
-
-public:
- virtual ~SupplicantStatus();
- static SupplicantStatus *createStatus(char *data, int len);
-
- int getWpaState() { return mWpaState; }
- int getId() { return mId; }
- const char *getBssid() { return mBssid; }
- const char *getSsid() { return mSsid; }
-
-};
-
-#endif
diff --git a/nexus/TiwlanEventListener.cpp b/nexus/TiwlanEventListener.cpp
deleted file mode 100644
index fde3a44..0000000
--- a/nexus/TiwlanEventListener.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <errno.h>
-#include <pthread.h>
-#include <sys/types.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#define LOG_TAG "TiwlanEventListener"
-#include <cutils/log.h>
-
-#include "TiwlanEventListener.h"
-
-TiwlanEventListener::TiwlanEventListener(int socket) :
- SocketListener(socket, false) {
-}
-
-bool TiwlanEventListener::onDataAvailable(SocketClient *cli) {
- struct ipc_ev_data *data;
-
- if (!(data = (struct ipc_ev_data *) malloc(sizeof(struct ipc_ev_data)))) {
- ALOGE("Failed to allocate packet (out of memory)");
- return true;
- }
-
- if (recv(cli->getSocket(), data, sizeof(struct ipc_ev_data), 0) < 0) {
- ALOGE("recv failed (%s)", strerror(errno));
- goto out;
- }
-
- if (data->event_type == IPC_EVENT_LINK_SPEED) {
- uint32_t *spd = (uint32_t *) data->buffer;
- *spd /= 2;
-// ALOGD("Link speed = %u MB/s", *spd);
- } else if (data->event_type == IPC_EVENT_LOW_SNR) {
- ALOGW("Low signal/noise ratio");
- } else if (data->event_type == IPC_EVENT_LOW_RSSI) {
- ALOGW("Low RSSI");
- } else {
-// ALOGD("Dropping unhandled driver event %d", data->event_type);
- }
-
- // TODO: Tell WifiController about the event
-out:
- free(data);
- return true;
-}
diff --git a/nexus/TiwlanEventListener.h b/nexus/TiwlanEventListener.h
deleted file mode 100644
index 052d6b1..0000000
--- a/nexus/TiwlanEventListener.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _TIWLAN_EVENT_LISTENER_H__
-#define _TIWLAN_EVENT_LISTENER_H__
-
-#include <sysutils/SocketListener.h>
-
-struct wpa_ctrl;
-class SocketClient;
-class ITiwlanEventHandler;
-class TiwlanEventFactory;
-
-class TiwlanEventListener: public SocketListener {
-
-public:
- TiwlanEventListener(int sock);
- virtual ~TiwlanEventListener() {}
-
-protected:
- virtual bool onDataAvailable(SocketClient *c);
-};
-
-// TODO: Move all this crap into a factory
-#define TI_DRIVER_MSG_PORT 9001
-
-#define IPC_EVENT_LINK_SPEED 2
-#define IPC_EVENT_LOW_SNR 13
-#define IPC_EVENT_LOW_RSSI 14
-
-struct ipc_ev_data {
- uint32_t event_type;
- void *event_id;
- uint32_t process_id;
- uint32_t delivery_type;
- uint32_t user_param;
- void *event_callback;
- uint32_t bufferSize;
- uint8_t buffer[2048];
-};
-
-#endif
diff --git a/nexus/TiwlanWifiController.cpp b/nexus/TiwlanWifiController.cpp
deleted file mode 100644
index 76b6a2e..0000000
--- a/nexus/TiwlanWifiController.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-
-#include <cutils/properties.h>
-#define LOG_TAG "TiwlanWifiController"
-#include <cutils/log.h>
-
-#include "PropertyManager.h"
-#include "TiwlanWifiController.h"
-#include "TiwlanEventListener.h"
-
-#define DRIVER_PROP_NAME "wlan.driver.status"
-
-extern "C" int sched_yield(void);
-
-TiwlanWifiController::TiwlanWifiController(PropertyManager *propmngr,
- IControllerHandler *handlers,
- char *modpath, char *modname,
- char *modargs) :
- WifiController(propmngr, handlers, modpath, modname,
- modargs) {
- mEventListener = NULL;
- mListenerSock = -1;
-}
-
-int TiwlanWifiController::powerUp() {
- return 0; // Powerup is currently done when the driver is loaded
-}
-
-int TiwlanWifiController::powerDown() {
- if (mEventListener) {
- delete mEventListener;
- shutdown(mListenerSock, SHUT_RDWR);
- close(mListenerSock);
- mListenerSock = -1;
- mEventListener = NULL;
- }
-
- return 0; // Powerdown is currently done when the driver is unloaded
-}
-
-bool TiwlanWifiController::isPoweredUp() {
- return isKernelModuleLoaded(getModuleName());
-}
-
-int TiwlanWifiController::loadFirmware() {
- char driver_status[PROPERTY_VALUE_MAX];
- int count = 100;
-
- property_set("ctl.start", "wlan_loader");
- sched_yield();
-
- // Wait for driver to be ready
- while (count-- > 0) {
- if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
- if (!strcmp(driver_status, "ok")) {
- ALOGD("Firmware loaded OK");
-
- if (startDriverEventListener()) {
- ALOGW("Failed to start driver event listener (%s)",
- strerror(errno));
- }
-
- return 0;
- } else if (!strcmp(DRIVER_PROP_NAME, "failed")) {
- ALOGE("Firmware load failed");
- return -1;
- }
- }
- usleep(200000);
- }
- property_set(DRIVER_PROP_NAME, "timeout");
- ALOGE("Firmware load timed out");
- return -1;
-}
-
-int TiwlanWifiController::startDriverEventListener() {
- struct sockaddr_in addr;
-
- if (mListenerSock != -1) {
- ALOGE("Listener already started!");
- errno = EBUSY;
- return -1;
- }
-
- if ((mListenerSock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- ALOGE("socket failed (%s)", strerror(errno));
- return -1;
- }
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- addr.sin_port = htons(TI_DRIVER_MSG_PORT);
-
- if (bind(mListenerSock,
- (struct sockaddr *) &addr,
- sizeof(addr)) < 0) {
- ALOGE("bind failed (%s)", strerror(errno));
- goto out_err;
- }
-
- mEventListener = new TiwlanEventListener(mListenerSock);
-
- if (mEventListener->startListener()) {
- ALOGE("Error starting driver listener (%s)", strerror(errno));
- goto out_err;
- }
- return 0;
-out_err:
- if (mEventListener) {
- delete mEventListener;
- mEventListener = NULL;
- }
- if (mListenerSock != -1) {
- shutdown(mListenerSock, SHUT_RDWR);
- close(mListenerSock);
- mListenerSock = -1;
- }
- return -1;
-}
-
-bool TiwlanWifiController::isFirmwareLoaded() {
- // Always load the firmware
- return false;
-}
diff --git a/nexus/TiwlanWifiController.h b/nexus/TiwlanWifiController.h
deleted file mode 100644
index 583be71..0000000
--- a/nexus/TiwlanWifiController.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _TIWLAN_WIFI_CONTROLLER_H
-#define _TIWLAN_WIFI_CONTROLLER_H
-
-#include "PropertyManager.h"
-#include "WifiController.h"
-
-class IControllerHandler;
-class TiwlanEventListener;
-
-class TiwlanWifiController : public WifiController {
- int mListenerSock;
- TiwlanEventListener *mEventListener;
-
-public:
- TiwlanWifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs);
- virtual ~TiwlanWifiController() {}
-
- virtual int powerUp();
- virtual int powerDown();
- virtual bool isPoweredUp();
- virtual int loadFirmware();
- virtual bool isFirmwareLoaded();
-
-private:
- int startDriverEventListener();
-};
-#endif
diff --git a/nexus/VpnController.cpp b/nexus/VpnController.cpp
deleted file mode 100644
index 015710f..0000000
--- a/nexus/VpnController.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "PropertyManager.h"
-#include "VpnController.h"
-
-VpnController::VpnController(PropertyManager *propmngr,
- IControllerHandler *handlers) :
- Controller("vpn", propmngr, handlers) {
- mEnabled = false;
-
- mStaticProperties.propEnabled = new VpnEnabledProperty(this);
- mDynamicProperties.propGateway = new IPV4AddressPropertyHelper("Gateway",
- false,
- &mGateway);
-}
-
-int VpnController::start() {
- mPropMngr->attachProperty("vpn", mStaticProperties.propEnabled);
- return 0;
-}
-
-int VpnController::stop() {
- mPropMngr->detachProperty("vpn", mStaticProperties.propEnabled);
- return 0;
-}
-
-VpnController::VpnIntegerProperty::VpnIntegerProperty(VpnController *c,
- const char *name,
- bool ro,
- int elements) :
- IntegerProperty(name, ro, elements) {
- mVc = c;
-}
-
-VpnController::VpnStringProperty::VpnStringProperty(VpnController *c,
- const char *name,
- bool ro, int elements) :
- StringProperty(name, ro, elements) {
- mVc = c;
-}
-
-VpnController::VpnIPV4AddressProperty::VpnIPV4AddressProperty(VpnController *c,
- const char *name,
- bool ro, int elements) :
- IPV4AddressProperty(name, ro, elements) {
- mVc = c;
-}
-
-VpnController::VpnEnabledProperty::VpnEnabledProperty(VpnController *c) :
- VpnIntegerProperty(c, "Enabled", false, 1) {
-}
-int VpnController::VpnEnabledProperty::get(int idx, int *buffer) {
- *buffer = mVc->mEnabled;
- return 0;
-}
-int VpnController::VpnEnabledProperty::set(int idx, int value) {
- int rc;
- if (!value) {
- mVc->mPropMngr->detachProperty("vpn", mVc->mDynamicProperties.propGateway);
- rc = mVc->disable();
- } else {
- rc = mVc->enable();
- if (!rc) {
- mVc->mPropMngr->attachProperty("vpn", mVc->mDynamicProperties.propGateway);
- }
- }
- if (!rc)
- mVc->mEnabled = value;
- return rc;
-}
diff --git a/nexus/VpnController.h b/nexus/VpnController.h
deleted file mode 100644
index 4bd86b5..0000000
--- a/nexus/VpnController.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _VPN_CONTROLLER_H
-#define _VPN_CONTROLLER_H
-
-#include <netinet/in.h>
-
-#include "Controller.h"
-
-class IControllerHandler;
-
-class VpnController : public Controller {
- class VpnIntegerProperty : public IntegerProperty {
- protected:
- VpnController *mVc;
- public:
- VpnIntegerProperty(VpnController *c, const char *name, bool ro,
- int elements);
- virtual ~VpnIntegerProperty() {}
- virtual int set(int idx, int value) = 0;
- virtual int get(int idx, int *buffer) = 0;
- };
- friend class VpnController::VpnIntegerProperty;
-
- class VpnStringProperty : public StringProperty {
- protected:
- VpnController *mVc;
- public:
- VpnStringProperty(VpnController *c, const char *name, bool ro,
- int elements);
- virtual ~VpnStringProperty() {}
- virtual int set(int idx, const char *value) = 0;
- virtual int get(int idx, char *buffer, size_t max) = 0;
- };
- friend class VpnController::VpnStringProperty;
-
- class VpnIPV4AddressProperty : public IPV4AddressProperty {
- protected:
- VpnController *mVc;
- public:
- VpnIPV4AddressProperty(VpnController *c, const char *name, bool ro,
- int elements);
- virtual ~VpnIPV4AddressProperty() {}
- virtual int set(int idx, struct in_addr *value) = 0;
- virtual int get(int idx, struct in_addr *buffer) = 0;
- };
- friend class VpnController::VpnIPV4AddressProperty;
-
- class VpnEnabledProperty : public VpnIntegerProperty {
- public:
- VpnEnabledProperty(VpnController *c);
- virtual ~VpnEnabledProperty() {};
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- bool mEnabled;
- /*
- * Gateway of the VPN server to connect to
- */
- struct in_addr mGateway;
-
- struct {
- VpnEnabledProperty *propEnabled;
- } mStaticProperties;
-
- struct {
- IPV4AddressPropertyHelper *propGateway;
- } mDynamicProperties;
-
-public:
- VpnController(PropertyManager *propmngr, IControllerHandler *handlers);
- virtual ~VpnController() {}
-
- virtual int start();
- virtual int stop();
-
-protected:
- virtual int enable() = 0;
- virtual int disable() = 0;
-};
-
-#endif
diff --git a/nexus/WifiController.cpp b/nexus/WifiController.cpp
deleted file mode 100644
index cedd013..0000000
--- a/nexus/WifiController.cpp
+++ /dev/null
@@ -1,819 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-
-#define LOG_TAG "WifiController"
-#include <cutils/log.h>
-
-#include "Supplicant.h"
-#include "WifiController.h"
-#include "NetworkManager.h"
-#include "ResponseCode.h"
-#include "WifiNetwork.h"
-#include "ISupplicantEventHandler.h"
-#include "SupplicantState.h"
-#include "SupplicantStatus.h"
-#include "SupplicantAssociatingEvent.h"
-#include "SupplicantAssociatedEvent.h"
-#include "SupplicantConnectedEvent.h"
-#include "SupplicantScanResultsEvent.h"
-#include "SupplicantStateChangeEvent.h"
-#include "SupplicantConnectionTimeoutEvent.h"
-#include "SupplicantDisconnectedEvent.h"
-#include "WifiStatusPoller.h"
-
-WifiController::WifiController(PropertyManager *mPropMngr,
- IControllerHandler *handlers,
- char *modpath, char *modname, char *modargs) :
- Controller("wifi", mPropMngr, handlers) {
- strncpy(mModulePath, modpath, sizeof(mModulePath));
- strncpy(mModuleName, modname, sizeof(mModuleName));
- strncpy(mModuleArgs, modargs, sizeof(mModuleArgs));
-
- mLatestScanResults = new ScanResultCollection();
- pthread_mutex_init(&mLatestScanResultsLock, NULL);
-
- pthread_mutex_init(&mLock, NULL);
-
- mSupplicant = new Supplicant(this, this);
- mActiveScan = false;
- mEnabled = false;
- mScanOnly = false;
- mPacketFilter = false;
- mBluetoothCoexScan = false;
- mBluetoothCoexMode = 0;
- mCurrentlyConnectedNetworkId = -1;
- mStatusPoller = new WifiStatusPoller(this);
- mRssiEventThreshold = 5;
- mLastLinkSpeed = 0;
-
- mSupplicantState = SupplicantState::UNKNOWN;
-
- mStaticProperties.propEnabled = new WifiEnabledProperty(this);
- mStaticProperties.propScanOnly = new WifiScanOnlyProperty(this);
- mStaticProperties.propAllowedChannels = new WifiAllowedChannelsProperty(this);
-
- mStaticProperties.propRssiEventThreshold =
- new IntegerPropertyHelper("RssiEventThreshold", false, &mRssiEventThreshold);
-
- mDynamicProperties.propSupplicantState = new WifiSupplicantStateProperty(this);
- mDynamicProperties.propActiveScan = new WifiActiveScanProperty(this);
- mDynamicProperties.propInterface = new WifiInterfaceProperty(this);
- mDynamicProperties.propSearching = new WifiSearchingProperty(this);
- mDynamicProperties.propPacketFilter = new WifiPacketFilterProperty(this);
- mDynamicProperties.propBluetoothCoexScan = new WifiBluetoothCoexScanProperty(this);
- mDynamicProperties.propBluetoothCoexMode = new WifiBluetoothCoexModeProperty(this);
- mDynamicProperties.propCurrentNetwork = new WifiCurrentNetworkProperty(this);
-
- mDynamicProperties.propRssi = new IntegerPropertyHelper("Rssi", true, &mLastRssi);
- mDynamicProperties.propLinkSpeed = new IntegerPropertyHelper("LinkSpeed", true, &mLastLinkSpeed);
-
- mDynamicProperties.propSuspended = new WifiSuspendedProperty(this);
- mDynamicProperties.propNetCount = new WifiNetCountProperty(this);
- mDynamicProperties.propTriggerScan = new WifiTriggerScanProperty(this);
-}
-
-int WifiController::start() {
- mPropMngr->attachProperty("wifi", mStaticProperties.propEnabled);
- mPropMngr->attachProperty("wifi", mStaticProperties.propScanOnly);
- mPropMngr->attachProperty("wifi", mStaticProperties.propAllowedChannels);
- mPropMngr->attachProperty("wifi", mStaticProperties.propRssiEventThreshold);
- return 0;
-}
-
-int WifiController::stop() {
- mPropMngr->detachProperty("wifi", mStaticProperties.propEnabled);
- mPropMngr->detachProperty("wifi", mStaticProperties.propScanOnly);
- mPropMngr->detachProperty("wifi", mStaticProperties.propAllowedChannels);
- mPropMngr->detachProperty("wifi", mStaticProperties.propRssiEventThreshold);
- return 0;
-}
-
-int WifiController::enable() {
-
- if (!isPoweredUp()) {
- ALOGI("Powering up");
- sendStatusBroadcast("Powering up WiFi hardware");
- if (powerUp()) {
- ALOGE("Powerup failed (%s)", strerror(errno));
- return -1;
- }
- }
-
- if (mModuleName[0] != '\0' && !isKernelModuleLoaded(mModuleName)) {
- ALOGI("Loading driver");
- sendStatusBroadcast("Loading WiFi driver");
- if (loadKernelModule(mModulePath, mModuleArgs)) {
- ALOGE("Kernel module load failed (%s)", strerror(errno));
- goto out_powerdown;
- }
- }
-
- if (!isFirmwareLoaded()) {
- ALOGI("Loading firmware");
- sendStatusBroadcast("Loading WiFI firmware");
- if (loadFirmware()) {
- ALOGE("Firmware load failed (%s)", strerror(errno));
- goto out_powerdown;
- }
- }
-
- if (!mSupplicant->isStarted()) {
- ALOGI("Starting WPA Supplicant");
- sendStatusBroadcast("Starting WPA Supplicant");
- if (mSupplicant->start()) {
- ALOGE("Supplicant start failed (%s)", strerror(errno));
- goto out_unloadmodule;
- }
- }
-
- if (Controller::bindInterface(mSupplicant->getInterfaceName())) {
- ALOGE("Error binding interface (%s)", strerror(errno));
- goto out_unloadmodule;
- }
-
- if (mSupplicant->refreshNetworkList())
- ALOGW("Error getting list of networks (%s)", strerror(errno));
-
- ALOGW("TODO: Set # of allowed regulatory channels!");
-
- mPropMngr->attachProperty("wifi", mDynamicProperties.propSupplicantState);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propActiveScan);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propInterface);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propSearching);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propPacketFilter);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propBluetoothCoexScan);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propBluetoothCoexMode);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propCurrentNetwork);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propRssi);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propLinkSpeed);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propSuspended);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propNetCount);
- mPropMngr->attachProperty("wifi", mDynamicProperties.propTriggerScan);
-
- ALOGI("Enabled successfully");
- return 0;
-
-out_unloadmodule:
- if (mModuleName[0] != '\0' && !isKernelModuleLoaded(mModuleName)) {
- if (unloadKernelModule(mModuleName)) {
- ALOGE("Unable to unload module after failure!");
- }
- }
-
-out_powerdown:
- if (powerDown()) {
- ALOGE("Unable to powerdown after failure!");
- }
- return -1;
-}
-
-bool WifiController::getSuspended() {
- pthread_mutex_lock(&mLock);
- bool r = mSuspended;
- pthread_mutex_unlock(&mLock);
- return r;
-}
-
-int WifiController::setSuspend(bool suspend) {
-
- pthread_mutex_lock(&mLock);
- if (suspend == mSuspended) {
- ALOGW("Suspended state already = %d", suspend);
- pthread_mutex_unlock(&mLock);
- return 0;
- }
-
- if (suspend) {
- mHandlers->onControllerSuspending(this);
-
- char tmp[80];
- ALOGD("Suspending from supplicant state %s",
- SupplicantState::toString(mSupplicantState,
- tmp,
- sizeof(tmp)));
-
- if (mSupplicantState != SupplicantState::IDLE) {
- ALOGD("Forcing Supplicant disconnect");
- if (mSupplicant->disconnect()) {
- ALOGW("Error disconnecting (%s)", strerror(errno));
- }
- }
-
- ALOGD("Stopping Supplicant driver");
- if (mSupplicant->stopDriver()) {
- ALOGE("Error stopping driver (%s)", strerror(errno));
- pthread_mutex_unlock(&mLock);
- return -1;
- }
- } else {
- ALOGD("Resuming");
-
- if (mSupplicant->startDriver()) {
- ALOGE("Error resuming driver (%s)", strerror(errno));
- pthread_mutex_unlock(&mLock);
- return -1;
- }
- // XXX: set regulatory max channels
- if (mScanOnly)
- mSupplicant->triggerScan();
- else
- mSupplicant->reconnect();
-
- mHandlers->onControllerResumed(this);
- }
-
- mSuspended = suspend;
- pthread_mutex_unlock(&mLock);
- ALOGD("Suspend / Resume completed");
- return 0;
-}
-
-void WifiController::sendStatusBroadcast(const char *msg) {
- NetworkManager::Instance()->
- getBroadcaster()->
- sendBroadcast(ResponseCode::UnsolicitedInformational, msg, false);
-}
-
-int WifiController::disable() {
-
- mPropMngr->detachProperty("wifi", mDynamicProperties.propSupplicantState);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propActiveScan);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propInterface);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propSearching);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propPacketFilter);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propBluetoothCoexScan);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propBluetoothCoexMode);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propCurrentNetwork);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propRssi);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propLinkSpeed);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propSuspended);
- mPropMngr->detachProperty("wifi", mDynamicProperties.propNetCount);
-
- if (mSupplicant->isStarted()) {
- sendStatusBroadcast("Stopping WPA Supplicant");
- if (mSupplicant->stop()) {
- ALOGE("Supplicant stop failed (%s)", strerror(errno));
- return -1;
- }
- } else
- ALOGW("disable(): Supplicant not running?");
-
- if (mModuleName[0] != '\0' && isKernelModuleLoaded(mModuleName)) {
- sendStatusBroadcast("Unloading WiFi driver");
- if (unloadKernelModule(mModuleName)) {
- ALOGE("Unable to unload module (%s)", strerror(errno));
- return -1;
- }
- }
-
- if (isPoweredUp()) {
- sendStatusBroadcast("Powering down WiFi hardware");
- if (powerDown()) {
- ALOGE("Powerdown failed (%s)", strerror(errno));
- return -1;
- }
- }
- return 0;
-}
-
-int WifiController::loadFirmware() {
- return 0;
-}
-
-int WifiController::triggerScan() {
- pthread_mutex_lock(&mLock);
- if (verifyNotSuspended()) {
- pthread_mutex_unlock(&mLock);
- return -1;
- }
-
- switch (mSupplicantState) {
- case SupplicantState::DISCONNECTED:
- case SupplicantState::INACTIVE:
- case SupplicantState::SCANNING:
- case SupplicantState::IDLE:
- break;
- default:
- // Switch to scan only mode
- mSupplicant->setApScanMode(2);
- break;
- }
-
- int rc = mSupplicant->triggerScan();
- pthread_mutex_unlock(&mLock);
- return rc;
-}
-
-int WifiController::setActiveScan(bool active) {
- pthread_mutex_lock(&mLock);
- if (mActiveScan == active) {
- pthread_mutex_unlock(&mLock);
- return 0;
- }
- mActiveScan = active;
-
- int rc = mSupplicant->setScanMode(active);
- pthread_mutex_unlock(&mLock);
- return rc;
-}
-
-WifiNetwork *WifiController::createNetwork() {
- pthread_mutex_lock(&mLock);
- WifiNetwork *wn = mSupplicant->createNetwork();
- pthread_mutex_unlock(&mLock);
- return wn;
-}
-
-int WifiController::removeNetwork(int networkId) {
- pthread_mutex_lock(&mLock);
- WifiNetwork *wn = mSupplicant->lookupNetwork(networkId);
-
- if (!wn) {
- pthread_mutex_unlock(&mLock);
- return -1;
- }
- int rc = mSupplicant->removeNetwork(wn);
- pthread_mutex_unlock(&mLock);
- return rc;
-}
-
-ScanResultCollection *WifiController::createScanResults() {
- ScanResultCollection *d = new ScanResultCollection();
- ScanResultCollection::iterator i;
-
- pthread_mutex_lock(&mLatestScanResultsLock);
- for (i = mLatestScanResults->begin(); i != mLatestScanResults->end(); ++i)
- d->push_back((*i)->clone());
-
- pthread_mutex_unlock(&mLatestScanResultsLock);
- return d;
-}
-
-WifiNetworkCollection *WifiController::createNetworkList() {
- return mSupplicant->createNetworkList();
-}
-
-int WifiController::setPacketFilter(bool enable) {
- int rc;
-
- pthread_mutex_lock(&mLock);
- if (enable)
- rc = mSupplicant->enablePacketFilter();
- else
- rc = mSupplicant->disablePacketFilter();
-
- if (!rc)
- mPacketFilter = enable;
- pthread_mutex_unlock(&mLock);
- return rc;
-}
-
-int WifiController::setBluetoothCoexistenceScan(bool enable) {
- int rc;
-
- pthread_mutex_lock(&mLock);
-
- if (enable)
- rc = mSupplicant->enableBluetoothCoexistenceScan();
- else
- rc = mSupplicant->disableBluetoothCoexistenceScan();
-
- if (!rc)
- mBluetoothCoexScan = enable;
- pthread_mutex_unlock(&mLock);
- return rc;
-}
-
-int WifiController::setScanOnly(bool scanOnly) {
- pthread_mutex_lock(&mLock);
- int rc = mSupplicant->setApScanMode((scanOnly ? 2 : 1));
- if (!rc)
- mScanOnly = scanOnly;
- if (!mSuspended) {
- if (scanOnly)
- mSupplicant->disconnect();
- else
- mSupplicant->reconnect();
- }
- pthread_mutex_unlock(&mLock);
- return rc;
-}
-
-int WifiController::setBluetoothCoexistenceMode(int mode) {
- pthread_mutex_lock(&mLock);
- int rc = mSupplicant->setBluetoothCoexistenceMode(mode);
- if (!rc)
- mBluetoothCoexMode = mode;
- pthread_mutex_unlock(&mLock);
- return rc;
-}
-
-void WifiController::onAssociatingEvent(SupplicantAssociatingEvent *evt) {
- ALOGD("onAssociatingEvent(%s, %s, %d)",
- (evt->getBssid() ? evt->getBssid() : "n/a"),
- (evt->getSsid() ? evt->getSsid() : "n/a"),
- evt->getFreq());
-}
-
-void WifiController::onAssociatedEvent(SupplicantAssociatedEvent *evt) {
- ALOGD("onAssociatedEvent(%s)", evt->getBssid());
-}
-
-void WifiController::onConnectedEvent(SupplicantConnectedEvent *evt) {
- ALOGD("onConnectedEvent(%s, %d)", evt->getBssid(), evt->getReassociated());
- SupplicantStatus *ss = mSupplicant->getStatus();
- WifiNetwork *wn;
-
- if (ss->getWpaState() != SupplicantState::COMPLETED) {
- char tmp[32];
-
- ALOGW("onConnected() with SupplicantState = %s!",
- SupplicantState::toString(ss->getWpaState(), tmp,
- sizeof(tmp)));
- return;
- }
-
- if (ss->getId() == -1) {
- ALOGW("onConnected() with id = -1!");
- return;
- }
-
- mCurrentlyConnectedNetworkId = ss->getId();
- if (!(wn = mSupplicant->lookupNetwork(ss->getId()))) {
- ALOGW("Error looking up connected network id %d (%s)",
- ss->getId(), strerror(errno));
- return;
- }
-
- delete ss;
- mHandlers->onInterfaceConnected(this);
-}
-
-void WifiController::onScanResultsEvent(SupplicantScanResultsEvent *evt) {
- char *reply;
-
- if (!(reply = (char *) malloc(4096))) {
- ALOGE("Out of memory");
- return;
- }
-
- mNumScanResultsSinceLastStateChange++;
- if (mNumScanResultsSinceLastStateChange >= 3)
- mIsSupplicantSearching = false;
-
- size_t len = 4096;
-
- if (mSupplicant->sendCommand("SCAN_RESULTS", reply, &len)) {
- ALOGW("onScanResultsEvent: Error getting scan results (%s)",
- strerror(errno));
- free(reply);
- return;
- }
-
- pthread_mutex_lock(&mLatestScanResultsLock);
- if (!mLatestScanResults->empty()) {
- ScanResultCollection::iterator i;
-
- for (i = mLatestScanResults->begin();
- i !=mLatestScanResults->end(); ++i) {
- delete *i;
- }
- mLatestScanResults->clear();
- }
-
- char *linep;
- char *linep_next = NULL;
-
- if (!strtok_r(reply, "\n", &linep_next)) {
- free(reply);
- pthread_mutex_unlock(&mLatestScanResultsLock);
- return;
- }
-
- while((linep = strtok_r(NULL, "\n", &linep_next)))
- mLatestScanResults->push_back(new ScanResult(linep));
-
- // Switch handling of scan results back to normal mode
- mSupplicant->setApScanMode(1);
-
- char *tmp;
- asprintf(&tmp, "Scan results ready (%d)", mLatestScanResults->size());
- NetworkManager::Instance()->getBroadcaster()->
- sendBroadcast(ResponseCode::ScanResultsReady,
- tmp, false);
- free(tmp);
- pthread_mutex_unlock(&mLatestScanResultsLock);
- free(reply);
-}
-
-void WifiController::onStateChangeEvent(SupplicantStateChangeEvent *evt) {
- char tmp[32];
- char tmp2[32];
-
- if (evt->getState() == mSupplicantState)
- return;
-
- ALOGD("onStateChangeEvent(%s -> %s)",
- SupplicantState::toString(mSupplicantState, tmp, sizeof(tmp)),
- SupplicantState::toString(evt->getState(), tmp2, sizeof(tmp2)));
-
- if (evt->getState() != SupplicantState::SCANNING) {
- mIsSupplicantSearching = true;
- mNumScanResultsSinceLastStateChange = 0;
- }
-
- char *tmp3;
- asprintf(&tmp3,
- "Supplicant state changed from %d (%s) -> %d (%s)",
- mSupplicantState, tmp, evt->getState(), tmp2);
-
- mSupplicantState = evt->getState();
-
- if (mSupplicantState == SupplicantState::COMPLETED) {
- mStatusPoller->start();
- } else if (mStatusPoller->isStarted()) {
- mStatusPoller->stop();
- }
-
- NetworkManager::Instance()->getBroadcaster()->
- sendBroadcast(ResponseCode::SupplicantStateChange,
- tmp3, false);
- free(tmp3);
-}
-
-void WifiController::onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt) {
- ALOGD("onConnectionTimeoutEvent(%s)", evt->getBssid());
-}
-
-void WifiController::onDisconnectedEvent(SupplicantDisconnectedEvent *evt) {
- mCurrentlyConnectedNetworkId = -1;
- mHandlers->onInterfaceDisconnected(this);
-}
-
-#if 0
-void WifiController::onTerminatingEvent(SupplicantEvent *evt) {
- ALOGD("onTerminatingEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onPasswordChangedEvent(SupplicantEvent *evt) {
- ALOGD("onPasswordChangedEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onEapNotificationEvent(SupplicantEvent *evt) {
- ALOGD("onEapNotificationEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onEapStartedEvent(SupplicantEvent *evt) {
- ALOGD("onEapStartedEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onEapMethodEvent(SupplicantEvent *evt) {
- ALOGD("onEapMethodEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onEapSuccessEvent(SupplicantEvent *evt) {
- ALOGD("onEapSuccessEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onEapFailureEvent(SupplicantEvent *evt) {
- ALOGD("onEapFailureEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onLinkSpeedEvent(SupplicantEvent *evt) {
- ALOGD("onLinkSpeedEvent(%s)", evt->getEvent());
-}
-
-void WifiController::onDriverStateEvent(SupplicantEvent *evt) {
- ALOGD("onDriverStateEvent(%s)", evt->getEvent());
-}
-#endif
-
-void WifiController::onStatusPollInterval() {
- pthread_mutex_lock(&mLock);
- int rssi;
- if (mSupplicant->getRssi(&rssi)) {
- ALOGE("Failed to get rssi (%s)", strerror(errno));
- pthread_mutex_unlock(&mLock);
- return;
- }
-
- if (abs(mLastRssi - rssi) > mRssiEventThreshold) {
- char *tmp3;
- asprintf(&tmp3, "RSSI changed from %d -> %d",
- mLastRssi, rssi);
- mLastRssi = rssi;
- NetworkManager::Instance()->getBroadcaster()->
- sendBroadcast(ResponseCode::RssiChange,
- tmp3, false);
- free(tmp3);
- }
-
- int linkspeed = mSupplicant->getLinkSpeed();
- if (linkspeed != mLastLinkSpeed) {
- char *tmp3;
- asprintf(&tmp3, "Link speed changed from %d -> %d",
- mLastLinkSpeed, linkspeed);
- mLastLinkSpeed = linkspeed;
- NetworkManager::Instance()->getBroadcaster()->
- sendBroadcast(ResponseCode::LinkSpeedChange,
- tmp3, false);
- free(tmp3);
-
- }
- pthread_mutex_unlock(&mLock);
-}
-
-int WifiController::verifyNotSuspended() {
- if (mSuspended) {
- errno = ESHUTDOWN;
- return -1;
- }
- return 0;
-}
-
-/*
- * Property inner classes
- */
-
-WifiController::WifiIntegerProperty::WifiIntegerProperty(WifiController *c,
- const char *name,
- bool ro,
- int elements) :
- IntegerProperty(name, ro, elements) {
- mWc = c;
-}
-
-WifiController::WifiStringProperty::WifiStringProperty(WifiController *c,
- const char *name,
- bool ro, int elements) :
- StringProperty(name, ro, elements) {
- mWc = c;
-}
-
-WifiController::WifiEnabledProperty::WifiEnabledProperty(WifiController *c) :
- WifiIntegerProperty(c, "Enabled", false, 1) {
-}
-
-int WifiController::WifiEnabledProperty::get(int idx, int *buffer) {
- *buffer = mWc->mEnabled;
- return 0;
-}
-int WifiController::WifiEnabledProperty::set(int idx, int value) {
- int rc = (value ? mWc->enable() : mWc->disable());
- if (!rc)
- mWc->mEnabled = value;
- return rc;
-}
-
-WifiController::WifiScanOnlyProperty::WifiScanOnlyProperty(WifiController *c) :
- WifiIntegerProperty(c, "ScanOnly", false, 1) {
-}
-int WifiController::WifiScanOnlyProperty::get(int idx, int *buffer) {
- *buffer = mWc->mScanOnly;
- return 0;
-}
-int WifiController::WifiScanOnlyProperty::set(int idx, int value) {
- return mWc->setScanOnly(value == 1);
-}
-
-WifiController::WifiAllowedChannelsProperty::WifiAllowedChannelsProperty(WifiController *c) :
- WifiIntegerProperty(c, "AllowedChannels", false, 1) {
-}
-int WifiController::WifiAllowedChannelsProperty::get(int idx, int *buffer) {
- *buffer = mWc->mNumAllowedChannels;
- return 0;
-}
-int WifiController::WifiAllowedChannelsProperty::set(int idx, int value) {
- // XXX: IMPL
- errno = ENOSYS;
- return -1;
-}
-
-WifiController::WifiSupplicantStateProperty::WifiSupplicantStateProperty(WifiController *c) :
- WifiStringProperty(c, "SupplicantState", true, 1) {
-}
-int WifiController::WifiSupplicantStateProperty::get(int idx, char *buffer, size_t max) {
- if (!SupplicantState::toString(mWc->mSupplicantState, buffer, max))
- return -1;
- return 0;
-}
-
-WifiController::WifiActiveScanProperty::WifiActiveScanProperty(WifiController *c) :
- WifiIntegerProperty(c, "ActiveScan", false, 1) {
-}
-int WifiController::WifiActiveScanProperty::get(int idx, int *buffer) {
- *buffer = mWc->mActiveScan;
- return 0;
-}
-int WifiController::WifiActiveScanProperty::set(int idx, int value) {
- return mWc->setActiveScan(value);
-}
-
-WifiController::WifiInterfaceProperty::WifiInterfaceProperty(WifiController *c) :
- WifiStringProperty(c, "Interface", true, 1) {
-}
-int WifiController::WifiInterfaceProperty::get(int idx, char *buffer, size_t max) {
- strncpy(buffer, (mWc->getBoundInterface() ? mWc->getBoundInterface() : "none"), max);
- return 0;
-}
-
-WifiController::WifiSearchingProperty::WifiSearchingProperty(WifiController *c) :
- WifiIntegerProperty(c, "Searching", true, 1) {
-}
-int WifiController::WifiSearchingProperty::get(int idx, int *buffer) {
- *buffer = mWc->mIsSupplicantSearching;
- return 0;
-}
-
-WifiController::WifiPacketFilterProperty::WifiPacketFilterProperty(WifiController *c) :
- WifiIntegerProperty(c, "PacketFilter", false, 1) {
-}
-int WifiController::WifiPacketFilterProperty::get(int idx, int *buffer) {
- *buffer = mWc->mPacketFilter;
- return 0;
-}
-int WifiController::WifiPacketFilterProperty::set(int idx, int value) {
- return mWc->setPacketFilter(value);
-}
-
-WifiController::WifiBluetoothCoexScanProperty::WifiBluetoothCoexScanProperty(WifiController *c) :
- WifiIntegerProperty(c, "BluetoothCoexScan", false, 1) {
-}
-int WifiController::WifiBluetoothCoexScanProperty::get(int idx, int *buffer) {
- *buffer = mWc->mBluetoothCoexScan;
- return 0;
-}
-int WifiController::WifiBluetoothCoexScanProperty::set(int idx, int value) {
- return mWc->setBluetoothCoexistenceScan(value == 1);
-}
-
-WifiController::WifiBluetoothCoexModeProperty::WifiBluetoothCoexModeProperty(WifiController *c) :
- WifiIntegerProperty(c, "BluetoothCoexMode", false, 1) {
-}
-int WifiController::WifiBluetoothCoexModeProperty::get(int idx, int *buffer) {
- *buffer = mWc->mBluetoothCoexMode;
- return 0;
-}
-int WifiController::WifiBluetoothCoexModeProperty::set(int idx, int value) {
- return mWc->setBluetoothCoexistenceMode(value);
-}
-
-WifiController::WifiCurrentNetworkProperty::WifiCurrentNetworkProperty(WifiController *c) :
- WifiIntegerProperty(c, "CurrentlyConnectedNetworkId", true, 1) {
-}
-int WifiController::WifiCurrentNetworkProperty::get(int idx, int *buffer) {
- *buffer = mWc->mCurrentlyConnectedNetworkId;
- return 0;
-}
-
-WifiController::WifiSuspendedProperty::WifiSuspendedProperty(WifiController *c) :
- WifiIntegerProperty(c, "Suspended", false, 1) {
-}
-int WifiController::WifiSuspendedProperty::get(int idx, int *buffer) {
- *buffer = mWc->getSuspended();
- return 0;
-}
-int WifiController::WifiSuspendedProperty::set(int idx, int value) {
- return mWc->setSuspend(value == 1);
-}
-
-WifiController::WifiNetCountProperty::WifiNetCountProperty(WifiController *c) :
- WifiIntegerProperty(c, "NetCount", true, 1) {
-}
-int WifiController::WifiNetCountProperty::get(int idx, int *buffer) {
- pthread_mutex_lock(&mWc->mLock);
- *buffer = mWc->mSupplicant->getNetworkCount();
- pthread_mutex_unlock(&mWc->mLock);
- return 0;
-}
-
-WifiController::WifiTriggerScanProperty::WifiTriggerScanProperty(WifiController *c) :
- WifiIntegerProperty(c, "TriggerScan", false, 1) {
-}
-int WifiController::WifiTriggerScanProperty::get(int idx, int *buffer) {
- // XXX: Need action type
- *buffer = 0;
- return 0;
-}
-
-int WifiController::WifiTriggerScanProperty::set(int idx, int value) {
- return mWc->triggerScan();
-}
-
diff --git a/nexus/WifiController.h b/nexus/WifiController.h
deleted file mode 100644
index b1524f6..0000000
--- a/nexus/WifiController.h
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _WIFI_CONTROLLER_H
-#define _WIFI_CONTROLLER_H
-
-#include <sys/types.h>
-
-#include "Controller.h"
-#include "ScanResult.h"
-#include "WifiNetwork.h"
-#include "ISupplicantEventHandler.h"
-#include "IWifiStatusPollerHandler.h"
-
-class NetInterface;
-class Supplicant;
-class SupplicantAssociatingEvent;
-class SupplicantAssociatedEvent;
-class SupplicantConnectedEvent;
-class SupplicantScanResultsEvent;
-class SupplicantStateChangeEvent;
-class SupplicantDisconnectedEvent;
-class WifiStatusPoller;
-
-class WifiController : public Controller,
- public ISupplicantEventHandler,
- public IWifiStatusPollerHandler {
-
- class WifiIntegerProperty : public IntegerProperty {
- protected:
- WifiController *mWc;
- public:
- WifiIntegerProperty(WifiController *c, const char *name, bool ro,
- int elements);
- virtual ~WifiIntegerProperty() {}
- virtual int set(int idx, int value) = 0;
- virtual int get(int idx, int *buffer) = 0;
- };
- friend class WifiController::WifiIntegerProperty;
-
- class WifiStringProperty : public StringProperty {
- protected:
- WifiController *mWc;
- public:
- WifiStringProperty(WifiController *c, const char *name, bool ro,
- int elements);
- virtual ~WifiStringProperty() {}
- virtual int set(int idx, const char *value) = 0;
- virtual int get(int idx, char *buffer, size_t max) = 0;
- };
- friend class WifiController::WifiStringProperty;
-
- class WifiEnabledProperty : public WifiIntegerProperty {
- public:
- WifiEnabledProperty(WifiController *c);
- virtual ~WifiEnabledProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiScanOnlyProperty : public WifiIntegerProperty {
- public:
- WifiScanOnlyProperty(WifiController *c);
- virtual ~WifiScanOnlyProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiAllowedChannelsProperty : public WifiIntegerProperty {
- public:
- WifiAllowedChannelsProperty(WifiController *c);
- virtual ~WifiAllowedChannelsProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiActiveScanProperty : public WifiIntegerProperty {
- public:
- WifiActiveScanProperty(WifiController *c);
- virtual ~WifiActiveScanProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiSearchingProperty : public WifiIntegerProperty {
- public:
- WifiSearchingProperty(WifiController *c);
- virtual ~WifiSearchingProperty() {}
- int set(int idx, int value) { return -1; }
- int get(int idx, int *buffer);
- };
-
- class WifiPacketFilterProperty : public WifiIntegerProperty {
- public:
- WifiPacketFilterProperty(WifiController *c);
- virtual ~WifiPacketFilterProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiBluetoothCoexScanProperty : public WifiIntegerProperty {
- public:
- WifiBluetoothCoexScanProperty(WifiController *c);
- virtual ~WifiBluetoothCoexScanProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiBluetoothCoexModeProperty : public WifiIntegerProperty {
- public:
- WifiBluetoothCoexModeProperty(WifiController *c);
- virtual ~WifiBluetoothCoexModeProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiCurrentNetworkProperty : public WifiIntegerProperty {
- public:
- WifiCurrentNetworkProperty(WifiController *c);
- virtual ~WifiCurrentNetworkProperty() {}
- int set(int idx, int value) { return -1; }
- int get(int idx, int *buffer);
- };
-
- class WifiSuspendedProperty : public WifiIntegerProperty {
- public:
- WifiSuspendedProperty(WifiController *c);
- virtual ~WifiSuspendedProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiNetCountProperty : public WifiIntegerProperty {
- public:
- WifiNetCountProperty(WifiController *c);
- virtual ~WifiNetCountProperty() {}
- int set(int idx, int value) { return -1; }
- int get(int idx, int *buffer);
- };
-
- class WifiTriggerScanProperty : public WifiIntegerProperty {
- public:
- WifiTriggerScanProperty(WifiController *c);
- virtual ~WifiTriggerScanProperty() {}
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiSupplicantStateProperty : public WifiStringProperty {
- public:
- WifiSupplicantStateProperty(WifiController *c);
- virtual ~WifiSupplicantStateProperty() {}
- int set(int idx, const char *value) { return -1; }
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiInterfaceProperty : public WifiStringProperty {
- public:
- WifiInterfaceProperty(WifiController *c);
- virtual ~WifiInterfaceProperty() {}
- int set(int idx, const char *value) { return -1; }
- int get(int idx, char *buffer, size_t max);
- };
-
- Supplicant *mSupplicant;
- char mModulePath[255];
- char mModuleName[64];
- char mModuleArgs[255];
-
- int mSupplicantState;
- bool mActiveScan;
- bool mScanOnly;
- bool mPacketFilter;
- bool mBluetoothCoexScan;
- int mBluetoothCoexMode;
- int mCurrentlyConnectedNetworkId;
- bool mSuspended;
- int mLastRssi;
- int mRssiEventThreshold;
- int mLastLinkSpeed;
- int mNumAllowedChannels;
-
- ScanResultCollection *mLatestScanResults;
- pthread_mutex_t mLatestScanResultsLock;
- pthread_mutex_t mLock;
- WifiStatusPoller *mStatusPoller;
-
- struct {
- WifiEnabledProperty *propEnabled;
- WifiScanOnlyProperty *propScanOnly;
- WifiAllowedChannelsProperty *propAllowedChannels;
- IntegerPropertyHelper *propRssiEventThreshold;
- } mStaticProperties;
-
- struct {
- WifiActiveScanProperty *propActiveScan;
- WifiSearchingProperty *propSearching;
- WifiPacketFilterProperty *propPacketFilter;
- WifiBluetoothCoexScanProperty *propBluetoothCoexScan;
- WifiBluetoothCoexModeProperty *propBluetoothCoexMode;
- WifiCurrentNetworkProperty *propCurrentNetwork;
- IntegerPropertyHelper *propRssi;
- IntegerPropertyHelper *propLinkSpeed;
- WifiSuspendedProperty *propSuspended;
- WifiNetCountProperty *propNetCount;
- WifiSupplicantStateProperty *propSupplicantState;
- WifiInterfaceProperty *propInterface;
- WifiTriggerScanProperty *propTriggerScan;
- } mDynamicProperties;
-
- // True if supplicant is currently searching for a network
- bool mIsSupplicantSearching;
- int mNumScanResultsSinceLastStateChange;
-
- bool mEnabled;
-
-public:
- WifiController(PropertyManager *propmngr, IControllerHandler *handlers, char *modpath, char *modname, char *modargs);
- virtual ~WifiController() {}
-
- int start();
- int stop();
-
- WifiNetwork *createNetwork();
- int removeNetwork(int networkId);
- WifiNetworkCollection *createNetworkList();
-
- ScanResultCollection *createScanResults();
-
- char *getModulePath() { return mModulePath; }
- char *getModuleName() { return mModuleName; }
- char *getModuleArgs() { return mModuleArgs; }
-
- Supplicant *getSupplicant() { return mSupplicant; }
-
-protected:
- // Move this crap into a 'driver'
- virtual int powerUp() = 0;
- virtual int powerDown() = 0;
- virtual int loadFirmware();
-
- virtual bool isFirmwareLoaded() = 0;
- virtual bool isPoweredUp() = 0;
-
-private:
- void sendStatusBroadcast(const char *msg);
- int setActiveScan(bool active);
- int triggerScan();
- int enable();
- int disable();
- int setSuspend(bool suspend);
- bool getSuspended();
- int setBluetoothCoexistenceScan(bool enable);
- int setBluetoothCoexistenceMode(int mode);
- int setPacketFilter(bool enable);
- int setScanOnly(bool scanOnly);
-
- // ISupplicantEventHandler methods
- void onAssociatingEvent(SupplicantAssociatingEvent *evt);
- void onAssociatedEvent(SupplicantAssociatedEvent *evt);
- void onConnectedEvent(SupplicantConnectedEvent *evt);
- void onScanResultsEvent(SupplicantScanResultsEvent *evt);
- void onStateChangeEvent(SupplicantStateChangeEvent *evt);
- void onConnectionTimeoutEvent(SupplicantConnectionTimeoutEvent *evt);
- void onDisconnectedEvent(SupplicantDisconnectedEvent *evt);
-#if 0
- virtual void onTerminatingEvent(SupplicantEvent *evt);
- virtual void onPasswordChangedEvent(SupplicantEvent *evt);
- virtual void onEapNotificationEvent(SupplicantEvent *evt);
- virtual void onEapStartedEvent(SupplicantEvent *evt);
- virtual void onEapMethodEvent(SupplicantEvent *evt);
- virtual void onEapSuccessEvent(SupplicantEvent *evt);
- virtual void onEapFailureEvent(SupplicantEvent *evt);
- virtual void onLinkSpeedEvent(SupplicantEvent *evt);
- virtual void onDriverStateEvent(SupplicantEvent *evt);
-#endif
-
- void onStatusPollInterval();
-
- int verifyNotSuspended();
-};
-
-#endif
diff --git a/nexus/WifiNetwork.cpp b/nexus/WifiNetwork.cpp
deleted file mode 100644
index 0197b64..0000000
--- a/nexus/WifiNetwork.cpp
+++ /dev/null
@@ -1,970 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-
-#define LOG_TAG "WifiNetwork"
-#include <cutils/log.h>
-
-#include "NetworkManager.h"
-#include "WifiNetwork.h"
-#include "Supplicant.h"
-#include "WifiController.h"
-
-WifiNetwork::WifiNetwork() {
- // This is private to restrict copy constructors
-}
-
-WifiNetwork::WifiNetwork(WifiController *c, Supplicant *suppl, const char *data) {
- mController = c;
- mSuppl = suppl;
-
- char *tmp = strdup(data);
- char *next = tmp;
- char *id;
- char *ssid;
- char *bssid;
- char *flags;
-
- if (!(id = strsep(&next, "\t")))
- ALOGE("Failed to extract network id");
- if (!(ssid = strsep(&next, "\t")))
- ALOGE("Failed to extract ssid");
- if (!(bssid = strsep(&next, "\t")))
- ALOGE("Failed to extract bssid");
- if (!(flags = strsep(&next, "\t")))
- ALOGE("Failed to extract flags");
-
- // ALOGD("id '%s', ssid '%s', bssid '%s', flags '%s'", id, ssid, bssid,
- // flags ? flags :"null");
-
- if (id)
- mNetid = atoi(id);
- if (ssid)
- mSsid = strdup(ssid);
- if (bssid)
- mBssid = strdup(bssid);
-
- mPsk = NULL;
- memset(mWepKeys, 0, sizeof(mWepKeys));
- mDefaultKeyIndex = -1;
- mPriority = -1;
- mHiddenSsid = NULL;
- mKeyManagement = KeyManagementMask::UNKNOWN;
- mProtocols = 0;
- mAuthAlgorithms = 0;
- mPairwiseCiphers = 0;
- mGroupCiphers = 0;
- mEnabled = true;
-
- if (flags && flags[0] != '\0') {
- if (!strcmp(flags, "[DISABLED]"))
- mEnabled = false;
- else
- ALOGW("Unsupported flags '%s'", flags);
- }
-
- free(tmp);
- createProperties();
-}
-
-WifiNetwork::WifiNetwork(WifiController *c, Supplicant *suppl, int networkId) {
- mController = c;
- mSuppl = suppl;
- mNetid = networkId;
- mSsid = NULL;
- mBssid = NULL;
- mPsk = NULL;
- memset(mWepKeys, 0, sizeof(mWepKeys));
- mDefaultKeyIndex = -1;
- mPriority = -1;
- mHiddenSsid = NULL;
- mKeyManagement = 0;
- mProtocols = 0;
- mAuthAlgorithms = 0;
- mPairwiseCiphers = 0;
- mGroupCiphers = 0;
- mEnabled = false;
- createProperties();
-}
-
-WifiNetwork *WifiNetwork::clone() {
- WifiNetwork *r = new WifiNetwork();
-
- r->mSuppl = mSuppl;
- r->mNetid = mNetid;
-
- if (mSsid)
- r->mSsid = strdup(mSsid);
- if (mBssid)
- r->mBssid = strdup(mBssid);
- if (mPsk)
- r->mPsk = strdup(mPsk);
-
- r->mController = mController;
- memcpy(r->mWepKeys, mWepKeys, sizeof(mWepKeys));
- r->mDefaultKeyIndex = mDefaultKeyIndex;
- r->mPriority = mPriority;
- if (mHiddenSsid)
- r->mHiddenSsid = strdup(mHiddenSsid);
- r->mKeyManagement = mKeyManagement;
- r->mProtocols = mProtocols;
- r->mAuthAlgorithms = mAuthAlgorithms;
- r->mPairwiseCiphers = mPairwiseCiphers;
- r->mGroupCiphers = mGroupCiphers;
- return r;
-}
-
-void WifiNetwork::createProperties() {
- asprintf(&mPropNamespace, "wifi.net.%d", mNetid);
-
- mStaticProperties.propEnabled = new WifiNetworkEnabledProperty(this);
- mStaticProperties.propSsid = new WifiNetworkSsidProperty(this);
- mStaticProperties.propBssid = new WifiNetworkBssidProperty(this);
- mStaticProperties.propPsk = new WifiNetworkPskProperty(this);
- mStaticProperties.propWepKey = new WifiNetworkWepKeyProperty(this);
- mStaticProperties.propDefKeyIdx = new WifiNetworkDefaultKeyIndexProperty(this);
- mStaticProperties.propPriority = new WifiNetworkPriorityProperty(this);
- mStaticProperties.propKeyManagement = new WifiNetworkKeyManagementProperty(this);
- mStaticProperties.propProtocols = new WifiNetworkProtocolsProperty(this);
- mStaticProperties.propAuthAlgorithms = new WifiNetworkAuthAlgorithmsProperty(this);
- mStaticProperties.propPairwiseCiphers = new WifiNetworkPairwiseCiphersProperty(this);
- mStaticProperties.propGroupCiphers = new WifiNetworkGroupCiphersProperty(this);
- mStaticProperties.propHiddenSsid = new WifiNetworkHiddenSsidProperty(this);
-}
-
-WifiNetwork::~WifiNetwork() {
- if (mPropNamespace)
- free(mPropNamespace);
- if (mSsid)
- free(mSsid);
- if (mBssid)
- free(mBssid);
- if (mPsk)
- free(mPsk);
- for (int i = 0; i < 4; i++) {
- if (mWepKeys[i])
- free(mWepKeys[i]);
- }
-
- if (mHiddenSsid)
- free(mHiddenSsid);
-
- delete mStaticProperties.propEnabled;
- delete mStaticProperties.propSsid;
- delete mStaticProperties.propBssid;
- delete mStaticProperties.propPsk;
- delete mStaticProperties.propWepKey;
- delete mStaticProperties.propDefKeyIdx;
- delete mStaticProperties.propPriority;
- delete mStaticProperties.propKeyManagement;
- delete mStaticProperties.propProtocols;
- delete mStaticProperties.propAuthAlgorithms;
- delete mStaticProperties.propPairwiseCiphers;
- delete mStaticProperties.propGroupCiphers;
- delete mStaticProperties.propHiddenSsid;
-}
-
-int WifiNetwork::refresh() {
- char buffer[255];
- size_t len;
- uint32_t mask;
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "psk", buffer, len))
- mPsk = strdup(buffer);
-
- for (int i = 0; i < 4; i++) {
- char *name;
-
- asprintf(&name, "wep_key%d", i);
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, name, buffer, len))
- mWepKeys[i] = strdup(buffer);
- free(name);
- }
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "wep_tx_keyidx", buffer, len))
- mDefaultKeyIndex = atoi(buffer);
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "priority", buffer, len))
- mPriority = atoi(buffer);
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "scan_ssid", buffer, len))
- mHiddenSsid = strdup(buffer);
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "key_mgmt", buffer, len)) {
- if (WifiNetwork::parseKeyManagementMask(buffer, &mask)) {
- ALOGE("Error parsing key_mgmt (%s)", strerror(errno));
- } else {
- mKeyManagement = mask;
- }
- }
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "proto", buffer, len)) {
- if (WifiNetwork::parseProtocolsMask(buffer, &mask)) {
- ALOGE("Error parsing proto (%s)", strerror(errno));
- } else {
- mProtocols = mask;
- }
- }
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "auth_alg", buffer, len)) {
- if (WifiNetwork::parseAuthAlgorithmsMask(buffer, &mask)) {
- ALOGE("Error parsing auth_alg (%s)", strerror(errno));
- } else {
- mAuthAlgorithms = mask;
- }
- }
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "pairwise", buffer, len)) {
- if (WifiNetwork::parsePairwiseCiphersMask(buffer, &mask)) {
- ALOGE("Error parsing pairwise (%s)", strerror(errno));
- } else {
- mPairwiseCiphers = mask;
- }
- }
-
- len = sizeof(buffer);
- if (mSuppl->getNetworkVar(mNetid, "group", buffer, len)) {
- if (WifiNetwork::parseGroupCiphersMask(buffer, &mask)) {
- ALOGE("Error parsing group (%s)", strerror(errno));
- } else {
- mGroupCiphers = mask;
- }
- }
-
- return 0;
-out_err:
- ALOGE("Refresh failed (%s)",strerror(errno));
- return -1;
-}
-
-int WifiNetwork::setSsid(const char *ssid) {
- char tmp[255];
- snprintf(tmp, sizeof(tmp), "\"%s\"", ssid);
- if (mSuppl->setNetworkVar(mNetid, "ssid", tmp))
- return -1;
- if (mSsid)
- free(mSsid);
- mSsid = strdup(ssid);
- return 0;
-}
-
-int WifiNetwork::setBssid(const char *bssid) {
- if (mSuppl->setNetworkVar(mNetid, "bssid", bssid))
- return -1;
- if (mBssid)
- free(mBssid);
- mBssid = strdup(bssid);
- return 0;
-}
-
-int WifiNetwork::setPsk(const char *psk) {
- char tmp[255];
- snprintf(tmp, sizeof(tmp), "\"%s\"", psk);
- if (mSuppl->setNetworkVar(mNetid, "psk", tmp))
- return -1;
-
- if (mPsk)
- free(mPsk);
- mPsk = strdup(psk);
- return 0;
-}
-
-int WifiNetwork::setWepKey(int idx, const char *key) {
- char *name;
-
- asprintf(&name, "wep_key%d", idx);
- int rc = mSuppl->setNetworkVar(mNetid, name, key);
- free(name);
-
- if (rc)
- return -1;
-
- if (mWepKeys[idx])
- free(mWepKeys[idx]);
- mWepKeys[idx] = strdup(key);
- return 0;
-}
-
-int WifiNetwork::setDefaultKeyIndex(int idx) {
- char val[16];
- sprintf(val, "%d", idx);
- if (mSuppl->setNetworkVar(mNetid, "wep_tx_keyidx", val))
- return -1;
-
- mDefaultKeyIndex = idx;
- return 0;
-}
-
-int WifiNetwork::setPriority(int priority) {
- char val[16];
- sprintf(val, "%d", priority);
- if (mSuppl->setNetworkVar(mNetid, "priority", val))
- return -1;
-
- mPriority = priority;
- return 0;
-}
-
-int WifiNetwork::setHiddenSsid(const char *ssid) {
- if (mSuppl->setNetworkVar(mNetid, "scan_ssid", ssid))
- return -1;
-
- if (mHiddenSsid)
- free(mHiddenSsid);
- mHiddenSsid = strdup(ssid);
- return 0;
-}
-
-int WifiNetwork::setKeyManagement(uint32_t mask) {
- char accum[64] = {'\0'};
-
- if (mask == KeyManagementMask::NONE)
- strcpy(accum, "NONE");
- else {
- if (mask & KeyManagementMask::WPA_PSK)
- strcat(accum, "WPA-PSK");
- if (mask & KeyManagementMask::WPA_EAP) {
- if (accum[0] != '\0')
- strcat(accum, " ");
- strcat(accum, "WPA-EAP");
- }
- if (mask & KeyManagementMask::IEEE8021X) {
- if (accum[0] != '\0')
- strcat(accum, " ");
- strcat(accum, "IEEE8021X");
- }
- }
-
- if (mSuppl->setNetworkVar(mNetid, "key_mgmt", accum))
- return -1;
- mKeyManagement = mask;
- return 0;
-}
-
-int WifiNetwork::setProtocols(uint32_t mask) {
- char accum[64];
-
- accum[0] = '\0';
-
- if (mask & SecurityProtocolMask::WPA)
- strcpy(accum, "WPA ");
-
- if (mask & SecurityProtocolMask::RSN)
- strcat(accum, "RSN");
-
- if (mSuppl->setNetworkVar(mNetid, "proto", accum))
- return -1;
- mProtocols = mask;
- return 0;
-}
-
-int WifiNetwork::setAuthAlgorithms(uint32_t mask) {
- char accum[64];
-
- accum[0] = '\0';
-
- if (mask == 0)
- strcpy(accum, "");
-
- if (mask & AuthenticationAlgorithmMask::OPEN)
- strcpy(accum, "OPEN ");
-
- if (mask & AuthenticationAlgorithmMask::SHARED)
- strcat(accum, "SHARED ");
-
- if (mask & AuthenticationAlgorithmMask::LEAP)
- strcat(accum, "LEAP ");
-
- if (mSuppl->setNetworkVar(mNetid, "auth_alg", accum))
- return -1;
-
- mAuthAlgorithms = mask;
- return 0;
-}
-
-int WifiNetwork::setPairwiseCiphers(uint32_t mask) {
- char accum[64];
-
- accum[0] = '\0';
-
- if (mask == PairwiseCiphersMask::NONE)
- strcpy(accum, "NONE");
- else {
- if (mask & PairwiseCiphersMask::TKIP)
- strcat(accum, "TKIP ");
- if (mask & PairwiseCiphersMask::CCMP)
- strcat(accum, "CCMP ");
- }
-
- if (mSuppl->setNetworkVar(mNetid, "pairwise", accum))
- return -1;
-
- mPairwiseCiphers = mask;
- return 0;
-}
-
-int WifiNetwork::setGroupCiphers(uint32_t mask) {
- char accum[64];
-
- accum[0] = '\0';
-
- if (mask & GroupCiphersMask::WEP40)
- strcat(accum, "WEP40 ");
- if (mask & GroupCiphersMask::WEP104)
- strcat(accum, "WEP104 ");
- if (mask & GroupCiphersMask::TKIP)
- strcat(accum, "TKIP ");
- if (mask & GroupCiphersMask::CCMP)
- strcat(accum, "CCMP ");
-
- if (mSuppl->setNetworkVar(mNetid, "group", accum))
- return -1;
- mGroupCiphers = mask;
- return 0;
-}
-
-int WifiNetwork::setEnabled(bool enabled) {
-
- if (enabled) {
- if (getPriority() == -1) {
- ALOGE("Cannot enable network when priority is not set");
- errno = EAGAIN;
- return -1;
- }
- if (getKeyManagement() == KeyManagementMask::UNKNOWN) {
- ALOGE("Cannot enable network when KeyManagement is not set");
- errno = EAGAIN;
- return -1;
- }
- }
-
- if (mSuppl->enableNetwork(mNetid, enabled))
- return -1;
-
- mEnabled = enabled;
- return 0;
-}
-
-int WifiNetwork::attachProperties(PropertyManager *pm, const char *nsName) {
- pm->attachProperty(nsName, mStaticProperties.propSsid);
- pm->attachProperty(nsName, mStaticProperties.propBssid);
- pm->attachProperty(nsName, mStaticProperties.propPsk);
- pm->attachProperty(nsName, mStaticProperties.propWepKey);
- pm->attachProperty(nsName, mStaticProperties.propDefKeyIdx);
- pm->attachProperty(nsName, mStaticProperties.propPriority);
- pm->attachProperty(nsName, mStaticProperties.propKeyManagement);
- pm->attachProperty(nsName, mStaticProperties.propProtocols);
- pm->attachProperty(nsName, mStaticProperties.propAuthAlgorithms);
- pm->attachProperty(nsName, mStaticProperties.propPairwiseCiphers);
- pm->attachProperty(nsName, mStaticProperties.propGroupCiphers);
- pm->attachProperty(nsName, mStaticProperties.propHiddenSsid);
- pm->attachProperty(nsName, mStaticProperties.propEnabled);
- return 0;
-}
-
-int WifiNetwork::detachProperties(PropertyManager *pm, const char *nsName) {
- pm->detachProperty(nsName, mStaticProperties.propEnabled);
- pm->detachProperty(nsName, mStaticProperties.propSsid);
- pm->detachProperty(nsName, mStaticProperties.propBssid);
- pm->detachProperty(nsName, mStaticProperties.propPsk);
- pm->detachProperty(nsName, mStaticProperties.propWepKey);
- pm->detachProperty(nsName, mStaticProperties.propDefKeyIdx);
- pm->detachProperty(nsName, mStaticProperties.propPriority);
- pm->detachProperty(nsName, mStaticProperties.propKeyManagement);
- pm->detachProperty(nsName, mStaticProperties.propProtocols);
- pm->detachProperty(nsName, mStaticProperties.propAuthAlgorithms);
- pm->detachProperty(nsName, mStaticProperties.propPairwiseCiphers);
- pm->detachProperty(nsName, mStaticProperties.propGroupCiphers);
- pm->detachProperty(nsName, mStaticProperties.propHiddenSsid);
- return 0;
-}
-
-int WifiNetwork::parseKeyManagementMask(const char *buffer, uint32_t *mask) {
- bool none = false;
- char *v_tmp = strdup(buffer);
- char *v_next = v_tmp;
- char *v_token;
-
-// ALOGD("parseKeyManagementMask(%s)", buffer);
- *mask = 0;
-
- while((v_token = strsep(&v_next, " "))) {
- if (!strcasecmp(v_token, "NONE")) {
- *mask = KeyManagementMask::NONE;
- none = true;
- } else if (!none) {
- if (!strcasecmp(v_token, "WPA-PSK"))
- *mask |= KeyManagementMask::WPA_PSK;
- else if (!strcasecmp(v_token, "WPA-EAP"))
- *mask |= KeyManagementMask::WPA_EAP;
- else if (!strcasecmp(v_token, "IEEE8021X"))
- *mask |= KeyManagementMask::IEEE8021X;
- else {
- ALOGW("Invalid KeyManagementMask value '%s'", v_token);
- errno = EINVAL;
- free(v_tmp);
- return -1;
- }
- } else {
- ALOGW("KeyManagementMask value '%s' when NONE", v_token);
- errno = EINVAL;
- free(v_tmp);
- return -1;
- }
- }
- free(v_tmp);
- return 0;
-}
-
-int WifiNetwork::parseProtocolsMask(const char *buffer, uint32_t *mask) {
- bool none = false;
- char *v_tmp = strdup(buffer);
- char *v_next = v_tmp;
- char *v_token;
-
-// ALOGD("parseProtocolsMask(%s)", buffer);
- *mask = 0;
- while((v_token = strsep(&v_next, " "))) {
- if (!strcasecmp(v_token, "WPA"))
- *mask |= SecurityProtocolMask::WPA;
- else if (!strcasecmp(v_token, "RSN"))
- *mask |= SecurityProtocolMask::RSN;
- else {
- ALOGW("Invalid ProtocolsMask value '%s'", v_token);
- errno = EINVAL;
- free(v_tmp);
- return -1;
- }
- }
-
- free(v_tmp);
- return 0;
-}
-
-int WifiNetwork::parseAuthAlgorithmsMask(const char *buffer, uint32_t *mask) {
- bool none = false;
- char *v_tmp = strdup(buffer);
- char *v_next = v_tmp;
- char *v_token;
-
-// ALOGD("parseAuthAlgorithmsMask(%s)", buffer);
-
- *mask = 0;
- if (buffer[0] == '\0')
- return 0;
-
- while((v_token = strsep(&v_next, " "))) {
- if (!strcasecmp(v_token, "OPEN"))
- *mask |= AuthenticationAlgorithmMask::OPEN;
- else if (!strcasecmp(v_token, "SHARED"))
- *mask |= AuthenticationAlgorithmMask::SHARED;
- else if (!strcasecmp(v_token, "LEAP"))
- *mask |= AuthenticationAlgorithmMask::LEAP;
- else {
- ALOGW("Invalid AuthAlgorithmsMask value '%s'", v_token);
- errno = EINVAL;
- free(v_tmp);
- return -1;
- }
- }
- free(v_tmp);
- return 0;
-}
-
-int WifiNetwork::parsePairwiseCiphersMask(const char *buffer, uint32_t *mask) {
- bool none = false;
- char *v_tmp = strdup(buffer);
- char *v_next = v_tmp;
- char *v_token;
-
-// ALOGD("parsePairwiseCiphersMask(%s)", buffer);
-
- *mask = 0;
- while((v_token = strsep(&v_next, " "))) {
- if (!strcasecmp(v_token, "NONE")) {
- *mask = PairwiseCiphersMask::NONE;
- none = true;
- } else if (!none) {
- if (!strcasecmp(v_token, "TKIP"))
- *mask |= PairwiseCiphersMask::TKIP;
- else if (!strcasecmp(v_token, "CCMP"))
- *mask |= PairwiseCiphersMask::CCMP;
- else {
- ALOGW("PairwiseCiphersMask value '%s' when NONE", v_token);
- errno = EINVAL;
- free(v_tmp);
- return -1;
- }
- } else {
- ALOGW("Invalid PairwiseCiphersMask value '%s'", v_token);
- errno = EINVAL;
- free(v_tmp);
- return -1;
- }
- }
- free(v_tmp);
- return 0;
-}
-
-int WifiNetwork::parseGroupCiphersMask(const char *buffer, uint32_t *mask) {
- bool none = false;
- char *v_tmp = strdup(buffer);
- char *v_next = v_tmp;
- char *v_token;
-
-// ALOGD("parseGroupCiphersMask(%s)", buffer);
-
- *mask = 0;
- while((v_token = strsep(&v_next, " "))) {
- if (!strcasecmp(v_token, "WEP40"))
- *mask |= GroupCiphersMask::WEP40;
- else if (!strcasecmp(v_token, "WEP104"))
- *mask |= GroupCiphersMask::WEP104;
- else if (!strcasecmp(v_token, "TKIP"))
- *mask |= GroupCiphersMask::TKIP;
- else if (!strcasecmp(v_token, "CCMP"))
- *mask |= GroupCiphersMask::CCMP;
- else {
- ALOGW("Invalid GroupCiphersMask value '%s'", v_token);
- errno = EINVAL;
- free(v_tmp);
- return -1;
- }
- }
- free(v_tmp);
- return 0;
-}
-
-WifiNetwork::WifiNetworkIntegerProperty::WifiNetworkIntegerProperty(WifiNetwork *wn,
- const char *name,
- bool ro,
- int elements) :
- IntegerProperty(name, ro, elements) {
- mWn = wn;
-}
-
-WifiNetwork::WifiNetworkStringProperty::WifiNetworkStringProperty(WifiNetwork *wn,
- const char *name,
- bool ro, int elements) :
- StringProperty(name, ro, elements) {
- mWn = wn;
-}
-
-WifiNetwork::WifiNetworkEnabledProperty::WifiNetworkEnabledProperty(WifiNetwork *wn) :
- WifiNetworkIntegerProperty(wn, "Enabled", false, 1) {
-}
-
-int WifiNetwork::WifiNetworkEnabledProperty::get(int idx, int *buffer) {
- *buffer = mWn->mEnabled;
- return 0;
-}
-int WifiNetwork::WifiNetworkEnabledProperty::set(int idx, int value) {
- return mWn->setEnabled(value == 1);
-}
-
-WifiNetwork::WifiNetworkSsidProperty::WifiNetworkSsidProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "Ssid", false, 1) {
-}
-
-int WifiNetwork::WifiNetworkSsidProperty::get(int idx, char *buffer, size_t max) {
- strncpy(buffer,
- mWn->getSsid() ? mWn->getSsid() : "none",
- max);
- return 0;
-}
-int WifiNetwork::WifiNetworkSsidProperty::set(int idx, const char *value) {
- return mWn->setSsid(value);
-}
-
-WifiNetwork::WifiNetworkBssidProperty::WifiNetworkBssidProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "Bssid", false, 1) {
-}
-int WifiNetwork::WifiNetworkBssidProperty::get(int idx, char *buffer, size_t max) {
- strncpy(buffer,
- mWn->getBssid() ? mWn->getBssid() : "none",
- max);
- return 0;
-}
-int WifiNetwork::WifiNetworkBssidProperty::set(int idx, const char *value) {
- return mWn->setBssid(value);
-}
-
-WifiNetwork::WifiNetworkPskProperty::WifiNetworkPskProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "Psk", false, 1) {
-}
-int WifiNetwork::WifiNetworkPskProperty::get(int idx, char *buffer, size_t max) {
- strncpy(buffer,
- mWn->getPsk() ? mWn->getPsk() : "none",
- max);
- return 0;
-}
-int WifiNetwork::WifiNetworkPskProperty::set(int idx, const char *value) {
- return mWn->setPsk(value);
-}
-
-WifiNetwork::WifiNetworkWepKeyProperty::WifiNetworkWepKeyProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "WepKey", false, 4) {
-}
-
-int WifiNetwork::WifiNetworkWepKeyProperty::get(int idx, char *buffer, size_t max) {
- const char *key = mWn->getWepKey(idx);
-
- strncpy(buffer, (key ? key : "none"), max);
- return 0;
-}
-int WifiNetwork::WifiNetworkWepKeyProperty::set(int idx, const char *value) {
- return mWn->setWepKey(idx, value);
-}
-
-WifiNetwork::WifiNetworkDefaultKeyIndexProperty::WifiNetworkDefaultKeyIndexProperty(WifiNetwork *wn) :
- WifiNetworkIntegerProperty(wn, "DefaultKeyIndex", false, 1) {
-}
-int WifiNetwork::WifiNetworkDefaultKeyIndexProperty::get(int idx, int *buffer) {
- *buffer = mWn->getDefaultKeyIndex();
- return 0;
-}
-int WifiNetwork::WifiNetworkDefaultKeyIndexProperty::set(int idx, int value) {
- return mWn->setDefaultKeyIndex(value);
-}
-
-WifiNetwork::WifiNetworkPriorityProperty::WifiNetworkPriorityProperty(WifiNetwork *wn) :
- WifiNetworkIntegerProperty(wn, "Priority", false, 1) {
-}
-int WifiNetwork::WifiNetworkPriorityProperty::get(int idx, int *buffer) {
- *buffer = mWn->getPriority();
- return 0;
-}
-int WifiNetwork::WifiNetworkPriorityProperty::set(int idx, int value) {
- return mWn->setPriority(value);
-}
-
-WifiNetwork::WifiNetworkKeyManagementProperty::WifiNetworkKeyManagementProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "KeyManagement", false, 1) {
-}
-int WifiNetwork::WifiNetworkKeyManagementProperty::get(int idx, char *buffer, size_t max) {
-
- if (mWn->getKeyManagement() == KeyManagementMask::NONE)
- strncpy(buffer, "NONE", max);
- else {
- char tmp[80] = { '\0' };
-
- if (mWn->getKeyManagement() & KeyManagementMask::WPA_PSK)
- strcat(tmp, "WPA-PSK");
- if (mWn->getKeyManagement() & KeyManagementMask::WPA_EAP) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "WPA-EAP");
- }
- if (mWn->getKeyManagement() & KeyManagementMask::IEEE8021X) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "IEEE8021X");
- }
- if (tmp[0] == '\0') {
- strncpy(buffer, "(internal error)", max);
- errno = ENOENT;
- return -1;
- }
- if (tmp[strlen(tmp)] == ' ')
- tmp[strlen(tmp)] = '\0';
-
- strncpy(buffer, tmp, max);
- }
- return 0;
-}
-int WifiNetwork::WifiNetworkKeyManagementProperty::set(int idx, const char *value) {
- uint32_t mask;
- if (mWn->parseKeyManagementMask(value, &mask))
- return -1;
- return mWn->setKeyManagement(mask);
-}
-
-WifiNetwork::WifiNetworkProtocolsProperty::WifiNetworkProtocolsProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "Protocols", false, 1) {
-}
-int WifiNetwork::WifiNetworkProtocolsProperty::get(int idx, char *buffer, size_t max) {
- char tmp[80] = { '\0' };
-
- if (mWn->getProtocols() & SecurityProtocolMask::WPA)
- strcat(tmp, "WPA");
- if (mWn->getProtocols() & SecurityProtocolMask::RSN) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "RSN");
- }
-
- if (tmp[0] == '\0') {
- strncpy(buffer, "(internal error)", max);
- errno = ENOENT;
- return NULL;
- }
- if (tmp[strlen(tmp)] == ' ')
- tmp[strlen(tmp)] = '\0';
-
- strncpy(buffer, tmp, max);
- return 0;
-}
-int WifiNetwork::WifiNetworkProtocolsProperty::set(int idx, const char *value) {
- uint32_t mask;
- if (mWn->parseProtocolsMask(value, &mask))
- return -1;
- return mWn->setProtocols(mask);
-}
-
-WifiNetwork::WifiNetworkAuthAlgorithmsProperty::WifiNetworkAuthAlgorithmsProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "AuthAlgorithms", false, 1) {
-}
-int WifiNetwork::WifiNetworkAuthAlgorithmsProperty::get(int idx, char *buffer, size_t max) {
- char tmp[80] = { '\0' };
-
- if (mWn->getAuthAlgorithms() == 0) {
- strncpy(buffer, "NONE", max);
- return 0;
- }
-
- if (mWn->getAuthAlgorithms() & AuthenticationAlgorithmMask::OPEN)
- strcat(tmp, "OPEN");
- if (mWn->getAuthAlgorithms() & AuthenticationAlgorithmMask::SHARED) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "SHARED");
- }
- if (mWn->getAuthAlgorithms() & AuthenticationAlgorithmMask::LEAP) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "LEAP");
- }
-
- if (tmp[0] == '\0') {
- strncpy(buffer, "(internal error)", max);
- errno = ENOENT;
- return NULL;
- }
- if (tmp[strlen(tmp)] == ' ')
- tmp[strlen(tmp)] = '\0';
-
- strncpy(buffer, tmp, max);
- return 0;
-}
-int WifiNetwork::WifiNetworkAuthAlgorithmsProperty::set(int idx, const char *value) {
- uint32_t mask;
- if (mWn->parseAuthAlgorithmsMask(value, &mask))
- return -1;
- return mWn->setAuthAlgorithms(mask);
-}
-
-WifiNetwork::WifiNetworkPairwiseCiphersProperty::WifiNetworkPairwiseCiphersProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "PairwiseCiphers", false, 1) {
-}
-int WifiNetwork::WifiNetworkPairwiseCiphersProperty::get(int idx, char *buffer, size_t max) {
- if (mWn->getPairwiseCiphers() == PairwiseCiphersMask::NONE)
- strncpy(buffer, "NONE", max);
- else {
- char tmp[80] = { '\0' };
-
- if (mWn->getPairwiseCiphers() & PairwiseCiphersMask::TKIP)
- strcat(tmp, "TKIP");
- if (mWn->getPairwiseCiphers() & PairwiseCiphersMask::CCMP) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "CCMP");
- }
- if (tmp[0] == '\0') {
- strncpy(buffer, "(internal error)", max);
- errno = ENOENT;
- return NULL;
- }
- if (tmp[strlen(tmp)] == ' ')
- tmp[strlen(tmp)] = '\0';
-
- strncpy(buffer, tmp, max);
- }
- return 0;
-}
-int WifiNetwork::WifiNetworkPairwiseCiphersProperty::set(int idx, const char *value) {
- uint32_t mask;
- if (mWn->parsePairwiseCiphersMask(value, &mask))
- return -1;
- return mWn->setPairwiseCiphers(mask);
-}
-
-WifiNetwork::WifiNetworkGroupCiphersProperty::WifiNetworkGroupCiphersProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "GroupCiphers", false, 1) {
-}
-int WifiNetwork::WifiNetworkGroupCiphersProperty::get(int idx, char *buffer, size_t max) {
- char tmp[80] = { '\0' };
-
- if (mWn->getGroupCiphers() & GroupCiphersMask::WEP40)
- strcat(tmp, "WEP40");
- if (mWn->getGroupCiphers() & GroupCiphersMask::WEP104) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "WEP104");
- }
- if (mWn->getGroupCiphers() & GroupCiphersMask::TKIP) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "TKIP");
- }
- if (mWn->getGroupCiphers() & GroupCiphersMask::CCMP) {
- if (tmp[0] != '\0')
- strcat(tmp, " ");
- strcat(tmp, "CCMP");
- }
-
- if (tmp[0] == '\0') {
- strncpy(buffer, "(internal error)", max);
- errno = ENOENT;
- return -1;
- }
- if (tmp[strlen(tmp)] == ' ')
- tmp[strlen(tmp)] = '\0';
-
- strncpy(buffer, tmp, max);
- return 0;
-}
-int WifiNetwork::WifiNetworkGroupCiphersProperty::set(int idx, const char *value) {
- uint32_t mask;
- if (mWn->parseGroupCiphersMask(value, &mask))
- return -1;
- return mWn->setGroupCiphers(mask);
-}
-
-WifiNetwork::WifiNetworkHiddenSsidProperty::WifiNetworkHiddenSsidProperty(WifiNetwork *wn) :
- WifiNetworkStringProperty(wn, "HiddenSsid", false, 1) {
-}
-int WifiNetwork::WifiNetworkHiddenSsidProperty::get(int idx, char *buffer, size_t max) {
- const char *scan_ssid = mWn->getHiddenSsid();
-
- strncpy(buffer, (scan_ssid ? scan_ssid : "none"), max);
- return 0;
-}
-int WifiNetwork::WifiNetworkHiddenSsidProperty::set(int idx, const char *value) {
- return mWn->setHiddenSsid(value);
-}
diff --git a/nexus/WifiNetwork.h b/nexus/WifiNetwork.h
deleted file mode 100644
index 15ec647..0000000
--- a/nexus/WifiNetwork.h
+++ /dev/null
@@ -1,356 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _WIFI_NETWORK_H
-#define _WIFI_NETWORK_H
-
-#include <sys/types.h>
-
-#include <utils/List.h>
-
-#include "Property.h"
-
-class PropertyManager;
-
-class KeyManagementMask {
-public:
- static const uint32_t UNKNOWN = 0;
- static const uint32_t NONE = 0x01;
- static const uint32_t WPA_PSK = 0x02;
- static const uint32_t WPA_EAP = 0x04;
- static const uint32_t IEEE8021X = 0x08;
- static const uint32_t ALL = WPA_PSK | WPA_EAP | IEEE8021X;
-};
-
-class SecurityProtocolMask {
-public:
- static const uint32_t WPA = 0x01;
- static const uint32_t RSN = 0x02;
-};
-
-class AuthenticationAlgorithmMask {
-public:
- static const uint32_t OPEN = 0x01;
- static const uint32_t SHARED = 0x02;
- static const uint32_t LEAP = 0x04;
-};
-
-class PairwiseCiphersMask {
-public:
- static const uint32_t NONE = 0x00;
- static const uint32_t TKIP = 0x01;
- static const uint32_t CCMP = 0x02;
-};
-
-class GroupCiphersMask {
-public:
- static const uint32_t WEP40 = 0x01;
- static const uint32_t WEP104 = 0x02;
- static const uint32_t TKIP = 0x04;
- static const uint32_t CCMP = 0x08;
-};
-
-class Supplicant;
-class Controller;
-class WifiController;
-
-class WifiNetwork {
- class WifiNetworkIntegerProperty : public IntegerProperty {
- protected:
- WifiNetwork *mWn;
- public:
- WifiNetworkIntegerProperty(WifiNetwork *wn, const char *name, bool ro,
- int elements);
- virtual ~WifiNetworkIntegerProperty() {}
- virtual int set(int idx, int value) = 0;
- virtual int get(int idx, int *buffer) = 0;
- };
- friend class WifiNetwork::WifiNetworkIntegerProperty;
-
- class WifiNetworkStringProperty : public StringProperty {
- protected:
- WifiNetwork *mWn;
- public:
- WifiNetworkStringProperty(WifiNetwork *wn, const char *name, bool ro,
- int elements);
- virtual ~WifiNetworkStringProperty() {}
- virtual int set(int idx, const char *value) = 0;
- virtual int get(int idx, char *buffer, size_t max) = 0;
- };
- friend class WifiNetwork::WifiNetworkStringProperty;
-
- class WifiNetworkEnabledProperty : public WifiNetworkIntegerProperty {
- public:
- WifiNetworkEnabledProperty(WifiNetwork *wn);
- virtual ~WifiNetworkEnabledProperty() {};
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiNetworkPriorityProperty : public WifiNetworkIntegerProperty {
- public:
- WifiNetworkPriorityProperty(WifiNetwork *wn);
- virtual ~WifiNetworkPriorityProperty() {};
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiNetworkDefaultKeyIndexProperty : public WifiNetworkIntegerProperty {
- public:
- WifiNetworkDefaultKeyIndexProperty(WifiNetwork *wn);
- virtual ~WifiNetworkDefaultKeyIndexProperty() {};
- int set(int idx, int value);
- int get(int idx, int *buffer);
- };
-
- class WifiNetworkSsidProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkSsidProperty(WifiNetwork *wn);
- virtual ~WifiNetworkSsidProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkBssidProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkBssidProperty(WifiNetwork *wn);
- virtual ~WifiNetworkBssidProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkPskProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkPskProperty(WifiNetwork *wn);
- virtual ~WifiNetworkPskProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkKeyManagementProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkKeyManagementProperty(WifiNetwork *wn);
- virtual ~WifiNetworkKeyManagementProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkAuthAlgorithmsProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkAuthAlgorithmsProperty(WifiNetwork *wn);
- virtual ~WifiNetworkAuthAlgorithmsProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkProtocolsProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkProtocolsProperty(WifiNetwork *wn);
- virtual ~WifiNetworkProtocolsProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkWepKeyProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkWepKeyProperty(WifiNetwork *wn);
- virtual ~WifiNetworkWepKeyProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkPairwiseCiphersProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkPairwiseCiphersProperty(WifiNetwork *wn);
- virtual ~WifiNetworkPairwiseCiphersProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkGroupCiphersProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkGroupCiphersProperty(WifiNetwork *wn);
- virtual ~WifiNetworkGroupCiphersProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
- class WifiNetworkHiddenSsidProperty : public WifiNetworkStringProperty {
- public:
- WifiNetworkHiddenSsidProperty(WifiNetwork *wn);
- virtual ~WifiNetworkHiddenSsidProperty() {};
- int set(int idx, const char *value);
- int get(int idx, char *buffer, size_t max);
- };
-
-private:
- Supplicant *mSuppl;
- WifiController *mController;
-
- /*
- * Unique network id - normally provided by supplicant
- */
- int mNetid;
-
- /*
- * The networks' SSID. Can either be an ASCII string,
- * which must be enclosed in double quotation marks
- * (ie: "MyNetwork"), or a string of hex digits which
- * are not enclosed in quotes (ie: 01ab7893)
- */
- char *mSsid;
-
- /*
- * When set, this entry should only be used
- * when associating with the AP having the specified
- * BSSID. The value is a string in the format of an
- * Ethernet MAC address
- */
- char *mBssid;
-
- /*
- * Pre-shared key for use with WPA-PSK
- */
- char *mPsk;
-
- /*
- * Up to four WEP keys. Either in ASCII string enclosed in
- * double quotes, or a string of hex digits
- */
- char *mWepKeys[4];
-
- /*
- * Default WEP key index, ranging from 0 -> NUM_WEP_KEYS -1
- */
- int mDefaultKeyIndex;
-
- /*
- * Priority determines the preference given to a network by
- * supplicant when choosing an access point with which
- * to associate
- */
- int mPriority;
-
- /*
- * This is a network that does not broadcast it's SSID, so an
- * SSID-specific probe request must be used for scans.
- */
- char *mHiddenSsid;
-
- /*
- * The set of key management protocols supported by this configuration.
- */
- uint32_t mKeyManagement;
-
- /*
- * The set of security protocols supported by this configuration.
- */
- uint32_t mProtocols;
-
- /*
- * The set of authentication protocols supported by this configuration.
- */
- uint32_t mAuthAlgorithms;
-
- /*
- * The set of pairwise ciphers for WPA supported by this configuration.
- */
- uint32_t mPairwiseCiphers;
-
- /*
- * The set of group ciphers for WPA supported by this configuration.
- */
- uint32_t mGroupCiphers;
-
- /*
- * Set if this Network is enabled
- */
- bool mEnabled;
-
- char *mPropNamespace;
- struct {
- WifiNetworkEnabledProperty *propEnabled;
- WifiNetworkSsidProperty *propSsid;
- WifiNetworkBssidProperty *propBssid;
- WifiNetworkPskProperty *propPsk;
- WifiNetworkWepKeyProperty *propWepKey;
- WifiNetworkDefaultKeyIndexProperty *propDefKeyIdx;
- WifiNetworkPriorityProperty *propPriority;
- WifiNetworkKeyManagementProperty *propKeyManagement;
- WifiNetworkProtocolsProperty *propProtocols;
- WifiNetworkAuthAlgorithmsProperty *propAuthAlgorithms;
- WifiNetworkPairwiseCiphersProperty *propPairwiseCiphers;
- WifiNetworkGroupCiphersProperty *propGroupCiphers;
- WifiNetworkHiddenSsidProperty *propHiddenSsid;
- } mStaticProperties;
-private:
- WifiNetwork();
-
-public:
- WifiNetwork(WifiController *c, Supplicant *suppl, int networkId);
- WifiNetwork(WifiController *c, Supplicant *suppl, const char *data);
-
- virtual ~WifiNetwork();
-
- WifiNetwork *clone();
- int attachProperties(PropertyManager *pm, const char *nsName);
- int detachProperties(PropertyManager *pm, const char *nsName);
-
- int getNetworkId() { return mNetid; }
- const char *getSsid() { return mSsid; }
- const char *getBssid() { return mBssid; }
- const char *getPsk() { return mPsk; }
- const char *getWepKey(int idx) { return mWepKeys[idx]; }
- int getDefaultKeyIndex() { return mDefaultKeyIndex; }
- int getPriority() { return mPriority; }
- const char *getHiddenSsid() { return mHiddenSsid; }
- uint32_t getKeyManagement() { return mKeyManagement; }
- uint32_t getProtocols() { return mProtocols; }
- uint32_t getAuthAlgorithms() { return mAuthAlgorithms; }
- uint32_t getPairwiseCiphers() { return mPairwiseCiphers; }
- uint32_t getGroupCiphers() { return mGroupCiphers; }
- bool getEnabled() { return mEnabled; }
- Controller *getController() { return (Controller *) mController; }
-
- int setEnabled(bool enabled);
- int setSsid(const char *ssid);
- int setBssid(const char *bssid);
- int setPsk(const char *psk);
- int setWepKey(int idx, const char *key);
- int setDefaultKeyIndex(int idx);
- int setPriority(int pri);
- int setHiddenSsid(const char *ssid);
- int setKeyManagement(uint32_t mask);
- int setProtocols(uint32_t mask);
- int setAuthAlgorithms(uint32_t mask);
- int setPairwiseCiphers(uint32_t mask);
- int setGroupCiphers(uint32_t mask);
-
- // XXX:Should this really be exposed?.. meh
- int refresh();
-
-private:
- int parseKeyManagementMask(const char *buffer, uint32_t *mask);
- int parseProtocolsMask(const char *buffer, uint32_t *mask);
- int parseAuthAlgorithmsMask(const char *buffer, uint32_t *mask);
- int parsePairwiseCiphersMask(const char *buffer, uint32_t *mask);
- int parseGroupCiphersMask(const char *buffer, uint32_t *mask);
- void createProperties();
-};
-
-typedef android::List<WifiNetwork *> WifiNetworkCollection;
-
-#endif
diff --git a/nexus/WifiScanner.cpp b/nexus/WifiScanner.cpp
deleted file mode 100644
index 4c956ac..0000000
--- a/nexus/WifiScanner.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <pthread.h>
-
-#define LOG_TAG "WifiScanner"
-#include <cutils/log.h>
-
-#include "WifiScanner.h"
-#include "Supplicant.h"
-
-extern "C" int pthread_cancel(pthread_t thread);
-
-WifiScanner::WifiScanner(Supplicant *suppl, int period) {
- mSuppl = suppl;
- mPeriod = period;
- mActive = false;
-}
-
-int WifiScanner::start(bool active) {
- mActive = active;
-
- if(pipe(mCtrlPipe))
- return -1;
-
- if (pthread_create(&mThread, NULL, WifiScanner::threadStart, this))
- return -1;
- return 0;
-}
-
-void *WifiScanner::threadStart(void *obj) {
- WifiScanner *me = reinterpret_cast<WifiScanner *>(obj);
- me->run();
- pthread_exit(NULL);
- return NULL;
-}
-
-int WifiScanner::stop() {
- char c = 0;
-
- if (write(mCtrlPipe[1], &c, 1) != 1) {
- ALOGE("Error writing to control pipe (%s)", strerror(errno));
- return -1;
- }
-
- void *ret;
- if (pthread_join(mThread, &ret)) {
- ALOGE("Error joining to scanner thread (%s)", strerror(errno));
- return -1;
- }
-
- close(mCtrlPipe[0]);
- close(mCtrlPipe[1]);
- return 0;
-}
-
-void WifiScanner::run() {
- ALOGD("Starting wifi scanner (active = %d)", mActive);
-
- while(1) {
- fd_set read_fds;
- struct timeval to;
- int rc = 0;
-
- to.tv_usec = 0;
- to.tv_sec = mPeriod;
-
- FD_ZERO(&read_fds);
- FD_SET(mCtrlPipe[0], &read_fds);
-
- if (mSuppl->triggerScan(mActive)) {
- ALOGW("Error triggering scan (%s)", strerror(errno));
- }
-
- if ((rc = select(mCtrlPipe[0] + 1, &read_fds, NULL, NULL, &to)) < 0) {
- ALOGE("select failed (%s) - sleeping for one scanner period", strerror(errno));
- sleep(mPeriod);
- continue;
- } else if (!rc) {
- } else if (FD_ISSET(mCtrlPipe[0], &read_fds))
- break;
- } // while
- ALOGD("Stopping wifi scanner");
-}
diff --git a/nexus/WifiScanner.h b/nexus/WifiScanner.h
deleted file mode 100644
index 92822e9..0000000
--- a/nexus/WifiScanner.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _WIFISCANNER_H
-#define _WIFISCANNER_H
-
-#include <pthread.h>
-
-class Supplicant;
-
-class WifiScanner {
- pthread_t mThread;
- int mCtrlPipe[2];
- Supplicant *mSuppl;
- int mPeriod;
- bool mActive;
-
-
-public:
- WifiScanner(Supplicant *suppl, int period);
- virtual ~WifiScanner() {}
-
- int getPeriod() { return mPeriod; }
-
- int start(bool active);
- int stop();
-
-private:
- static void *threadStart(void *obj);
-
- void run();
-};
-
-#endif
diff --git a/nexus/WifiStatusPoller.cpp b/nexus/WifiStatusPoller.cpp
deleted file mode 100644
index 015af5d..0000000
--- a/nexus/WifiStatusPoller.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/un.h>
-
-#define LOG_TAG "WifiStatusPoller"
-#include <cutils/log.h>
-
-#include "WifiStatusPoller.h"
-#include "IWifiStatusPollerHandler.h"
-
-
-WifiStatusPoller::WifiStatusPoller(IWifiStatusPollerHandler *handler) :
- mHandlers(handler) {
- mPollingInterval = 5;
- mStarted = false;
-}
-
-int WifiStatusPoller::start() {
-
- if (pipe(mCtrlPipe))
- return -1;
-
- if (pthread_create(&mThread, NULL, WifiStatusPoller::threadStart, this))
- return -1;
-
- return 0;
-}
-
-int WifiStatusPoller::stop() {
- char c = 0;
-
- if (write(mCtrlPipe[1], &c, 1) != 1) {
- ALOGE("Error writing to control pipe (%s)", strerror(errno));
- return -1;
- }
-
- void *ret;
- if (pthread_join(mThread, &ret)) {
- ALOGE("Error joining to listener thread (%s)", strerror(errno));
- return -1;
- }
- close(mCtrlPipe[0]);
- close(mCtrlPipe[1]);
- return 0;
-}
-
-void *WifiStatusPoller::threadStart(void *obj) {
- WifiStatusPoller *me = reinterpret_cast<WifiStatusPoller *>(obj);
-
- me->mStarted = true;
- ALOGD("Starting");
- me->run();
- me->mStarted = false;
- ALOGD("Stopping");
- pthread_exit(NULL);
- return NULL;
-}
-
-void WifiStatusPoller::run() {
-
- while(1) {
- struct timeval to;
- fd_set read_fds;
- int rc = 0;
- int max = 0;
-
- FD_ZERO(&read_fds);
- to.tv_usec = 0;
- to.tv_sec = mPollingInterval;
-
- FD_SET(mCtrlPipe[0], &read_fds);
- max = mCtrlPipe[0];
-
- if ((rc = select(max + 1, &read_fds, NULL, NULL, &to)) < 0) {
- ALOGE("select failed (%s)", strerror(errno));
- sleep(1);
- continue;
- } else if (!rc) {
- mHandlers->onStatusPollInterval();
- }
- if (FD_ISSET(mCtrlPipe[0], &read_fds))
- break;
- }
-}
diff --git a/nexus/WifiStatusPoller.h b/nexus/WifiStatusPoller.h
deleted file mode 100644
index 202bbbf..0000000
--- a/nexus/WifiStatusPoller.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _WIFI_STATUS_POLLER_H
-#define _WIFI_STATUS_POLLER_H
-
-#include <pthread.h>
-
-class IWifiStatusPollerHandler;
-
-class WifiStatusPoller {
- pthread_t mThread;
- int mCtrlPipe[2];
- int mPollingInterval;
- IWifiStatusPollerHandler *mHandlers;
- bool mStarted;
-
-public:
- WifiStatusPoller(IWifiStatusPollerHandler *handler);
- virtual ~WifiStatusPoller() {}
-
- int start();
- int stop();
- bool isStarted() { return mStarted; }
-
- void setPollingInterval(int interval);
- int getPollingInterval() { return mPollingInterval; }
-
-private:
- static void *threadStart(void *obj);
- void run();
-};
-
-#endif
diff --git a/nexus/main.cpp b/nexus/main.cpp
deleted file mode 100644
index 7d2af02..0000000
--- a/nexus/main.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <errno.h>
-
-#define LOG_TAG "Nexus"
-
-#include "cutils/log.h"
-#include "NetworkManager.h"
-#include "CommandListener.h"
-
-#include "LoopController.h"
-#include "OpenVpnController.h"
-#include "TiwlanWifiController.h"
-
-int main() {
- ALOGI("Nexus version 0.1 firing up");
-
- CommandListener *cl = new CommandListener();
-
- NetworkManager *nm;
- if (!(nm = NetworkManager::Instance())) {
- ALOGE("Unable to create NetworkManager");
- exit (-1);
- };
-
- nm->setBroadcaster((SocketListener *) cl);
-
- nm->attachController(new LoopController(nm->getPropMngr(), nm));
- nm->attachController(new TiwlanWifiController(nm->getPropMngr(), nm, "/system/lib/modules/wlan.ko", "wlan", ""));
-// nm->attachController(new AndroidL2TPVpnController(nm->getPropMngr(), nm));
- nm->attachController(new OpenVpnController(nm->getPropMngr(), nm));
-
-
- if (NetworkManager::Instance()->run()) {
- ALOGE("Unable to Run NetworkManager (%s)", strerror(errno));
- exit (1);
- }
-
- if (cl->startListener()) {
- ALOGE("Unable to start CommandListener (%s)", strerror(errno));
- exit (1);
- }
-
- // XXX: we'll use the main thread for the NetworkManager eventually
-
- while(1) {
- sleep(1000);
- }
-
- ALOGI("Nexus exiting");
- exit(0);
-}
diff --git a/nexus/nexctl.c b/nexus/nexctl.c
deleted file mode 100644
index 8e1d90c..0000000
--- a/nexus/nexctl.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-
-#include <sys/socket.h>
-#include <sys/select.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/un.h>
-
-#include <cutils/sockets.h>
-#include <private/android_filesystem_config.h>
-
-static void usage(char *progname);
-static int do_monitor(int sock, int stop_after_cmd);
-static int do_cmd(int sock, int argc, char **argv);
-
-int main(int argc, char **argv) {
- int sock;
-
- if (argc < 2)
- usage(argv[0]);
-
- if ((sock = socket_local_client("nexus",
- ANDROID_SOCKET_NAMESPACE_RESERVED,
- SOCK_STREAM)) < 0) {
- fprintf(stderr, "Error connecting (%s)\n", strerror(errno));
- exit(4);
- }
-
- if (!strcmp(argv[1], "monitor"))
- exit(do_monitor(sock, 0));
- exit(do_cmd(sock, argc, argv));
-}
-
-static int do_cmd(int sock, int argc, char **argv) {
- char final_cmd[255] = { '\0' };
- int i;
-
- for (i = 1; i < argc; i++) {
- char *cmp;
-
- if (!index(argv[i], ' '))
- asprintf(&cmp, "%s%s", argv[i], (i == (argc -1)) ? "" : " ");
- else
- asprintf(&cmp, "\"%s\"%s", argv[i], (i == (argc -1)) ? "" : " ");
-
- strcat(final_cmd, cmp);
- free(cmp);
- }
-
- if (write(sock, final_cmd, strlen(final_cmd) + 1) < 0) {
- perror("write");
- return errno;
- }
-
- return do_monitor(sock, 1);
-}
-
-static int do_monitor(int sock, int stop_after_cmd) {
- char *buffer = malloc(4096);
-
- if (!stop_after_cmd)
- printf("[Connected to Nexus]\n");
-
- while(1) {
- fd_set read_fds;
- struct timeval to;
- int rc = 0;
-
- to.tv_sec = 10;
- to.tv_usec = 0;
-
- FD_ZERO(&read_fds);
- FD_SET(sock, &read_fds);
-
- if ((rc = select(sock +1, &read_fds, NULL, NULL, &to)) < 0) {
- fprintf(stderr, "Error in select (%s)\n", strerror(errno));
- free(buffer);
- return errno;
- } else if (!rc) {
- continue;
- fprintf(stderr, "[TIMEOUT]\n");
- return ETIMEDOUT;
- } else if (FD_ISSET(sock, &read_fds)) {
- memset(buffer, 0, 4096);
- if ((rc = read(sock, buffer, 4096)) <= 0) {
- if (rc == 0)
- fprintf(stderr, "Lost connection to Nexus - did it crash?\n");
- else
- fprintf(stderr, "Error reading data (%s)\n", strerror(errno));
- free(buffer);
- if (rc == 0)
- return ECONNRESET;
- return errno;
- }
-
- int offset = 0;
- int i = 0;
-
- for (i = 0; i < rc; i++) {
- if (buffer[i] == '\0') {
- int code;
- char tmp[4];
-
- strncpy(tmp, buffer + offset, 3);
- tmp[3] = '\0';
- code = atoi(tmp);
-
- printf("%s\n", buffer + offset);
- if (stop_after_cmd) {
- if (code >= 200 && code < 600)
- return 0;
- }
- offset = i + 1;
- }
- }
- }
- }
- free(buffer);
- return 0;
-}
-
-static void usage(char *progname) {
- fprintf(stderr, "Usage: %s <monitor>|<cmd> [arg1] [arg2...]\n", progname);
- exit(1);
-}
-
diff --git a/toolbox/chown.c b/toolbox/chown.c
index 7b24c52..92efee6 100644
--- a/toolbox/chown.c
+++ b/toolbox/chown.c
@@ -15,7 +15,7 @@
int i;
if (argc < 3) {
- fprintf(stderr, "Usage: chown <USER>[.GROUP] <FILE1> [FILE2] ...\n");
+ fprintf(stderr, "Usage: chown <USER>[:GROUP] <FILE1> [FILE2] ...\n");
return 10;
}
@@ -24,7 +24,9 @@
char user[32];
char *group = NULL;
strncpy(user, argv[1], sizeof(user));
- if ((group = strchr(user, '.')) != NULL) {
+ if ((group = strchr(user, ':')) != NULL) {
+ *group++ = '\0';
+ } else if ((group = strchr(user, '.')) != NULL) {
*group++ = '\0';
}