forked from mirrors/gecko-dev
Bug 479898 - Support for wifi scanning. r=dolske/stuart, sr=jst
This commit is contained in:
parent
dffc3962d9
commit
c4b46661bd
27 changed files with 2357 additions and 0 deletions
|
|
@ -147,6 +147,7 @@ bin/components/necko_res.xpt
|
|||
bin/components/necko_socket.xpt
|
||||
bin/components/necko_strconv.xpt
|
||||
bin/components/necko_viewsource.xpt
|
||||
bin/components/necko_wifi.xpt
|
||||
bin/components/necko.xpt
|
||||
#ifdef OJI
|
||||
bin/components/oji.xpt
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@ bin\components\necko_http.xpt
|
|||
bin\components\necko_res.xpt
|
||||
bin\components\necko_socket.xpt
|
||||
bin\components\necko_viewsource.xpt
|
||||
bin\components\necko_wifi.xpt
|
||||
#ifdef OJI
|
||||
bin\components\oji.xpt
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ NECKO_PROTOCOLS = @NECKO_PROTOCOLS@
|
|||
NECKO_DISK_CACHE = @NECKO_DISK_CACHE@
|
||||
NECKO_SMALL_BUFFERS = @NECKO_SMALL_BUFFERS@
|
||||
NECKO_COOKIES = @NECKO_COOKIES@
|
||||
NECKO_WIFI = @NECKO_WIFI@
|
||||
MOZ_AUTH_EXTENSION = @MOZ_AUTH_EXTENSION@
|
||||
|
||||
MOZ_NATIVE_HUNSPELL = @SYSTEM_HUNSPELL@
|
||||
|
|
|
|||
33
configure.in
33
configure.in
|
|
@ -4491,6 +4491,7 @@ MOZ_XTF=1
|
|||
MOZ_XUL=1
|
||||
MOZ_ZIPWRITER=1
|
||||
NS_PRINTING=1
|
||||
NECKO_WIFI=1
|
||||
NECKO_COOKIES=1
|
||||
NECKO_DISK_CACHE=1
|
||||
NECKO_PROTOCOLS_DEFAULT="about data file ftp gopher http res viewsource"
|
||||
|
|
@ -7837,6 +7838,38 @@ if test "$NECKO_DISK_CACHE"; then
|
|||
AC_DEFINE(NECKO_DISK_CACHE)
|
||||
fi
|
||||
|
||||
dnl
|
||||
dnl option to disable necko's wifi scanner
|
||||
dnl
|
||||
MOZ_ARG_DISABLE_BOOL(necko-wifi,
|
||||
[ --disable-necko-wifi Disable necko wifi scanner],
|
||||
NECKO_WIFI=,
|
||||
NECKO_WIFI=1
|
||||
)
|
||||
if test "$NECKO_WIFI"; then
|
||||
NECKO_WIFI=
|
||||
if test "$OS_ARCH" = "Linux"; then
|
||||
AC_CHECK_HEADER([iwlib.h])
|
||||
if test "$ac_cv_header_iwlib_h" = "yes"; then
|
||||
NECKO_WIFI=1
|
||||
fi
|
||||
elif test "$OS_ARCH" = "Darwin"; then
|
||||
NECKO_WIFI=1
|
||||
elif test "$OS_ARCH" = "WINNT"; then
|
||||
NECKO_WIFI=1
|
||||
else
|
||||
AC_MSG_ERROR([Necko WiFi scanning not supported on your platform.])
|
||||
fi
|
||||
AC_SUBST(NECKO_WIFI)
|
||||
|
||||
if test "$NECKO_WIFI"; then
|
||||
AC_DEFINE(NECKO_WIFI)
|
||||
fi
|
||||
|
||||
fi
|
||||
AC_SUBST(NECKO_WIFI)
|
||||
|
||||
|
||||
dnl
|
||||
dnl option to minimize size of necko's i/o buffers
|
||||
dnl
|
||||
|
|
|
|||
|
|
@ -54,6 +54,13 @@ DIRS = \
|
|||
cache \
|
||||
protocol \
|
||||
system \
|
||||
$(NULL)
|
||||
|
||||
ifdef NECKO_WIFI
|
||||
DIRS += wifi
|
||||
endif
|
||||
|
||||
DIRS += \
|
||||
build \
|
||||
locales \
|
||||
$(NULL)
|
||||
|
|
|
|||
|
|
@ -116,6 +116,14 @@ SHARED_LIBRARY_LIBS += \
|
|||
LOCAL_INCLUDES += -I$(srcdir)/../cookie/src
|
||||
endif
|
||||
|
||||
ifdef NECKO_WIFI
|
||||
SHARED_LIBRARY_LIBS += \
|
||||
../wifi/src/$(LIB_PREFIX)neckowifi_s.$(LIB_SUFFIX) \
|
||||
$(NULL)
|
||||
LOCAL_INCLUDES += -I$(srcdir)/../wifi/src
|
||||
endif
|
||||
|
||||
|
||||
ifdef MOZ_STORAGE
|
||||
REQUIRES += storage
|
||||
DEFINES += -DNECKO_OFFLINE_CACHE
|
||||
|
|
|
|||
|
|
@ -810,6 +810,21 @@
|
|||
{ 0xa6, 0x18, 0x00, 0x10, 0xa4, 0x01, 0xeb, 0x10 } \
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* netwerk/wifi classes
|
||||
*/
|
||||
#ifdef NECKO_WIFI
|
||||
#define NS_WIFI_MONITOR_CLASSNAME "WIFI_MONITOR"
|
||||
#define NS_WIFI_MONITOR_CONTRACTID "@mozilla.org/wifi/monitor;1"
|
||||
|
||||
#define NS_WIFI_MONITOR_COMPONENT_CID \
|
||||
{ 0x3FF8FB9F, \
|
||||
0xEE63, \
|
||||
0x48DF, \
|
||||
{ 0x89, 0xF0, 0xDA, 0xCE, 0x02, 0x42, 0xFD, 0x82 } \
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************************************************************************
|
||||
* netwerk/streamconv classes
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -171,6 +171,15 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsStreamListenerTee)
|
|||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsCookieService, nsCookieService::GetSingleton)
|
||||
#endif
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef NECKO_WIFI
|
||||
|
||||
#include "nsWifiMonitor.h"
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWifiMonitor)
|
||||
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// protocols
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -1091,6 +1100,15 @@ static const nsModuleComponentInfo gNetModuleInfo[] = {
|
|||
},
|
||||
#endif
|
||||
|
||||
#ifdef NECKO_WIFI
|
||||
{
|
||||
NS_WIFI_MONITOR_CLASSNAME,
|
||||
NS_WIFI_MONITOR_COMPONENT_CID,
|
||||
NS_WIFI_MONITOR_CONTRACTID,
|
||||
nsWifiMonitorConstructor
|
||||
},
|
||||
#endif
|
||||
|
||||
#ifdef NECKO_PROTOCOL_gopher
|
||||
//gopher:
|
||||
{ "The Gopher Protocol Handler",
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@
|
|||
|
||||
#undef NECKO_COOKIES
|
||||
|
||||
#undef NECKO_WIFI
|
||||
|
||||
#undef NECKO_PROTOCOL_about
|
||||
#undef NECKO_PROTOCOL_data
|
||||
#undef NECKO_PROTOCOL_file
|
||||
|
|
|
|||
48
netwerk/wifi/Makefile.in
Normal file
48
netwerk/wifi/Makefile.in
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (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.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org build system.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Mozilla Corporation
|
||||
# Portions created by the Initial Developer are Copyright (C) 2008
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Doug Turner <dougt@meer.net>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -DIMPL_NS_NET
|
||||
56
netwerk/wifi/public/Makefile.in
Normal file
56
netwerk/wifi/public/Makefile.in
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (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.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org build system.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Mozilla Corporation
|
||||
# Portions created by the Initial Developer are Copyright (C) 2009
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Doug Turner <dougt@meer.net>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
XPIDL_MODULE = necko_wifi
|
||||
GRE_MODULE = 1
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIWifiMonitor.idl \
|
||||
nsIWifiListener.idl \
|
||||
nsIWifiAccessPoint.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -DIMPL_NS_NET
|
||||
73
netwerk/wifi/public/nsIWifiAccessPoint.idl
Normal file
73
netwerk/wifi/public/nsIWifiAccessPoint.idl
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(E28E614F-8F86-44FF-BCF5-5F18225834A0)]
|
||||
interface nsIWifiAccessPoint : nsISupports
|
||||
{
|
||||
|
||||
/*
|
||||
* The mac address of the WiFi node. The format of this string is:
|
||||
* XX-XX-XX-XX-XX-XX
|
||||
*/
|
||||
|
||||
readonly attribute ACString mac;
|
||||
|
||||
/*
|
||||
* Public name of a wireless network. The charset of this string is ASCII.
|
||||
* This string will be null if not available.
|
||||
*
|
||||
* Note that this is a conversion of the SSID which makes it "displayable".
|
||||
* for any comparisons, you want to use the Raw SSID.
|
||||
*/
|
||||
|
||||
readonly attribute AString ssid;
|
||||
|
||||
/*
|
||||
* Public name of a wireless network. These are the bytes that are read off
|
||||
* of the network, may contain nulls, and generally shouldn't be displayed to
|
||||
* the user.
|
||||
*
|
||||
*/
|
||||
|
||||
readonly attribute ACString rawSSID;
|
||||
|
||||
/*
|
||||
* Current signal strength measured in dBm.
|
||||
*/
|
||||
readonly attribute long signal;
|
||||
};
|
||||
62
netwerk/wifi/public/nsIWifiListener.idl
Normal file
62
netwerk/wifi/public/nsIWifiListener.idl
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIArray.idl"
|
||||
|
||||
#include "nsIWifiAccessPoint.idl"
|
||||
|
||||
[scriptable, uuid(BCD4BEDE-F4A5-4A62-9071-D7A60174E376)]
|
||||
interface nsIWifiListener : nsISupports
|
||||
{
|
||||
/*
|
||||
* Called when the list of access points changes.
|
||||
*
|
||||
* @param accessPoints An array of nsIWifiAccessPoint representing all
|
||||
* access points in view.
|
||||
*/
|
||||
|
||||
void onChange([array, size_is(aLen)] in nsIWifiAccessPoint accessPoints, in unsigned long aLen);
|
||||
|
||||
/*
|
||||
* Called when there is a problem with listening to wifi
|
||||
*
|
||||
* @param error the error which caused this event. The
|
||||
* error values will be nsresult codes.
|
||||
*/
|
||||
|
||||
void onError(in long error);
|
||||
};
|
||||
55
netwerk/wifi/public/nsIWifiMonitor.idl
Normal file
55
netwerk/wifi/public/nsIWifiMonitor.idl
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIWifiListener.idl"
|
||||
|
||||
[scriptable, uuid(F289701E-D9AF-4685-BC2F-E4226FF7C018)]
|
||||
interface nsIWifiMonitor : nsISupports
|
||||
{
|
||||
|
||||
/*
|
||||
* startWatching
|
||||
* aListener will be called once, then each time the list of wifi access points change.
|
||||
*/
|
||||
void startWatching(in nsIWifiListener aListener);
|
||||
|
||||
/*
|
||||
* stopWatching
|
||||
* cancels all notifications to the |aListener|.
|
||||
*/
|
||||
void stopWatching(in nsIWifiListener aListener);
|
||||
};
|
||||
74
netwerk/wifi/src/Makefile.in
Normal file
74
netwerk/wifi/src/Makefile.in
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (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.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org build system.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Mozilla Corporation
|
||||
# Portions created by the Initial Developer are Copyright (C) 2009
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Doug Turner <dougt@meer.net>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = neckowifi_s
|
||||
FORCE_STATIC_LIB = 1
|
||||
LIBXUL_LIBRARY = 1
|
||||
|
||||
REQUIRES = \
|
||||
xpcom \
|
||||
string \
|
||||
pref \
|
||||
storage \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = nsWifiMonitor.cpp \
|
||||
nsWifiAccessPoint.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
CPPSRCS += nsWifiScannerMac.cpp
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
|
||||
CPPSRCS += nsWifiScannerWin.cpp
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2)
|
||||
CPPSRCS += nsWifiScannerUnix.cpp
|
||||
endif # gtk
|
||||
endif # windows
|
||||
endif # mac
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
DEFINES += -DIMPL_NS_NET
|
||||
134
netwerk/wifi/src/nsWifiAccessPoint.cpp
Normal file
134
netwerk/wifi/src/nsWifiAccessPoint.cpp
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* This is a derivative of work done by Google under a BSD style License.
|
||||
* See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsWifiAccessPoint.h"
|
||||
#include "nsMemory.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
extern PRLogModuleInfo *gWifiMonitorLog;
|
||||
#endif
|
||||
#define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
|
||||
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsWifiAccessPoint, nsIWifiAccessPoint)
|
||||
|
||||
nsWifiAccessPoint::nsWifiAccessPoint()
|
||||
{
|
||||
// make sure these are null terminated (because we are paranoid)
|
||||
mMac[0] = nsnull;
|
||||
mSsid[0] = nsnull;
|
||||
mSsidLen = 0;
|
||||
}
|
||||
|
||||
nsWifiAccessPoint::~nsWifiAccessPoint()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWifiAccessPoint::GetMac(nsACString& aMac)
|
||||
{
|
||||
aMac.Assign(mMac);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWifiAccessPoint::GetSsid(nsAString& aSsid)
|
||||
{
|
||||
// just assign and embedded nulls will truncate resulting
|
||||
// in a displayable string.
|
||||
|
||||
nsString tempStr;
|
||||
tempStr.AssignWithConversion(mSsid, mSsidLen);
|
||||
aSsid = tempStr;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsWifiAccessPoint::GetRawSSID(nsACString& aRawSsid)
|
||||
{
|
||||
aRawSsid.Assign(mSsid, mSsidLen); // SSIDs are 32 chars long
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWifiAccessPoint::GetSignal(PRInt32 *aSignal)
|
||||
{
|
||||
NS_ENSURE_ARG(aSignal);
|
||||
*aSignal = mSignal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Helper functions:
|
||||
|
||||
PRBool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
|
||||
{
|
||||
if (a.Count() != b.Count()) {
|
||||
LOG(("AccessPoint lists have different lengths\n"));
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
for (PRInt32 i = 0; i < a.Count(); i++) {
|
||||
LOG(("++ Looking for %s\n", a[i]->mSsid));
|
||||
PRBool found = PR_FALSE;
|
||||
for (PRInt32 j = 0; j < b.Count(); j++) {
|
||||
LOG((" %s->%s | %s->%s\n", a[i]->mSsid, b[j]->mSsid, a[i]->mMac, b[j]->mMac));
|
||||
if (!strcmp(a[i]->mSsid, b[j]->mSsid) &&
|
||||
!strcmp(a[i]->mMac, b[j]->mMac)) {
|
||||
found = PR_TRUE;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
return PR_FALSE;
|
||||
}
|
||||
LOG((" match!\n"));
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b)
|
||||
{
|
||||
a.Clear();
|
||||
|
||||
// better way to copy?
|
||||
for (PRInt32 i = 0; i < b.Count(); i++) {
|
||||
a.AppendObject(b[i]);
|
||||
}
|
||||
|
||||
b.Clear();
|
||||
}
|
||||
|
||||
|
||||
103
netwerk/wifi/src/nsWifiAccessPoint.h
Normal file
103
netwerk/wifi/src/nsWifiAccessPoint.h
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* This is a derivative of work done by Google under a BSD style License.
|
||||
* See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsWifiMonitor.h"
|
||||
#include "nsIWifiAccessPoint.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
#ifndef __nsWifiAccessPoint__
|
||||
#define __nsWifiAccessPoint__
|
||||
|
||||
class nsWifiAccessPoint : public nsIWifiAccessPoint
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWIFIACCESSPOINT
|
||||
|
||||
nsWifiAccessPoint();
|
||||
~nsWifiAccessPoint();
|
||||
|
||||
char mMac[18];
|
||||
int mSignal;
|
||||
char mSsid[33];
|
||||
int mSsidLen;
|
||||
|
||||
void setSignal(int signal)
|
||||
{
|
||||
mSignal = signal;
|
||||
};
|
||||
|
||||
void setMac(const uint8 mac_as_int[6])
|
||||
{
|
||||
// mac_as_int is big-endian. Write in byte chunks.
|
||||
// Format is XX-XX-XX-XX-XX-XX.
|
||||
|
||||
static const char *kMacFormatString = ("%02x-%02x-%02x-%02x-%02x-%02x");
|
||||
|
||||
sprintf(mMac, kMacFormatString,
|
||||
mac_as_int[0], mac_as_int[1], mac_as_int[2],
|
||||
mac_as_int[3], mac_as_int[4], mac_as_int[5]);
|
||||
mMac[17] = 0;
|
||||
};
|
||||
|
||||
void setSSID(const char* aSSID, unsigned long len) {
|
||||
if (len < sizeof(mSsid)) {
|
||||
strncpy(mSsid, aSSID, len);
|
||||
mSsid[len] = 0;
|
||||
mSsidLen = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
mSsid[0] = 0;
|
||||
mSsidLen = 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Helper functions
|
||||
|
||||
PRBool AccessPointsEqual(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b);
|
||||
void ReplaceArray(nsCOMArray<nsWifiAccessPoint>& a, nsCOMArray<nsWifiAccessPoint>& b);
|
||||
|
||||
|
||||
#endif
|
||||
181
netwerk/wifi/src/nsWifiMonitor.cpp
Normal file
181
netwerk/wifi/src/nsWifiMonitor.cpp
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* This is a derivative of work done by Google under a BSD style License.
|
||||
* See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsXPCOMCID.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsWifiMonitor.h"
|
||||
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
PRLogModuleInfo *gWifiMonitorLog;
|
||||
#endif
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsWifiMonitor,
|
||||
nsIRunnable,
|
||||
nsIObserver,
|
||||
nsIWifiMonitor)
|
||||
|
||||
nsWifiMonitor::nsWifiMonitor()
|
||||
: mKeepGoing(PR_TRUE)
|
||||
{
|
||||
#if defined(PR_LOGGING)
|
||||
gWifiMonitorLog = PR_NewLogModule("WifiMonitor");
|
||||
#endif
|
||||
|
||||
mMonitor = nsAutoMonitor::NewMonitor("nsWifiMonitor");
|
||||
|
||||
nsCOMPtr<nsIObserverService> obsSvc = do_GetService("@mozilla.org/observer-service;1");
|
||||
if (obsSvc)
|
||||
obsSvc->AddObserver(this, "xpcom-shutdown", PR_FALSE);
|
||||
|
||||
LOG(("@@@@@ wifimonitor created\n"));
|
||||
}
|
||||
|
||||
nsWifiMonitor::~nsWifiMonitor()
|
||||
{
|
||||
if (mMonitor)
|
||||
nsAutoMonitor::DestroyMonitor(mMonitor);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWifiMonitor::Observe(nsISupports *subject, const char *topic,
|
||||
const PRUnichar *data)
|
||||
{
|
||||
if (!strcmp(topic, "xpcom-shutdown")) {
|
||||
LOG(("Shutting down\n"));
|
||||
mKeepGoing = PR_FALSE;
|
||||
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
mon.Notify();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsWifiMonitor::StartWatching(nsIWifiListener *aListener)
|
||||
{
|
||||
if (!aListener)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (!mThread) {
|
||||
rv = NS_NewThread(getter_AddRefs(mThread), this);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
mKeepGoing = PR_TRUE;
|
||||
|
||||
mListeners.AppendElement(nsWifiListener(aListener));
|
||||
|
||||
// tell ourselves that we have a new watcher.
|
||||
mon.Notify();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWifiMonitor::StopWatching(nsIWifiListener *aListener)
|
||||
{
|
||||
if (!aListener)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
LOG(("removing listener\n"));
|
||||
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
|
||||
|
||||
if (mListeners[i].mListener == aListener) {
|
||||
mListeners.RemoveElementAt(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mListeners.Length() == 0) {
|
||||
mKeepGoing = PR_FALSE;
|
||||
mon.Notify();
|
||||
mThread = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsWifiMonitor::Run()
|
||||
{
|
||||
LOG(("@@@@@ wifi monitor run called\n"));
|
||||
|
||||
nsresult rv = DoScan();
|
||||
|
||||
if (mKeepGoing && NS_FAILED(rv)) {
|
||||
|
||||
// send error
|
||||
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
|
||||
|
||||
LOG(("About to send error to a listener\n"));
|
||||
|
||||
nsCOMPtr<nsIWifiListener> proxy;
|
||||
nsCOMPtr<nsIProxyObjectManager> proxyObjMgr = do_GetService("@mozilla.org/xpcomproxy;1");
|
||||
proxyObjMgr->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
|
||||
NS_GET_IID(nsIWifiListener),
|
||||
mListeners[i].mListener,
|
||||
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
|
||||
getter_AddRefs(proxy));
|
||||
|
||||
if (proxy) {
|
||||
nsresult rv = proxy->OnError(rv);
|
||||
LOG( ("... sent %d\n", rv));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
100
netwerk/wifi/src/nsWifiMonitor.h
Normal file
100
netwerk/wifi/src/nsWifiMonitor.h
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* This is a derivative of work done by Google under a BSD style License.
|
||||
* See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIWifiMonitor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsIThread.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsIWifiMonitor.h"
|
||||
#include "prmon.h"
|
||||
#include "prlog.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
#ifndef __nsWifiMonitor__
|
||||
#define __nsWifiMonitor__
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
extern PRLogModuleInfo *gWifiMonitorLog;
|
||||
#endif
|
||||
#define LOG(args) PR_LOG(gWifiMonitorLog, PR_LOG_DEBUG, args)
|
||||
|
||||
class nsWifiListener
|
||||
{
|
||||
public:
|
||||
|
||||
nsWifiListener(nsIWifiListener* aListener)
|
||||
{
|
||||
mListener = aListener;
|
||||
mHasSentData = PR_FALSE;
|
||||
}
|
||||
~nsWifiListener() {}
|
||||
|
||||
nsCOMPtr<nsIWifiListener> mListener;
|
||||
PRBool mHasSentData;
|
||||
};
|
||||
|
||||
class nsWifiMonitor : nsIRunnable, nsIWifiMonitor, nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWIFIMONITOR
|
||||
NS_DECL_NSIRUNNABLE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsWifiMonitor();
|
||||
|
||||
private:
|
||||
~nsWifiMonitor();
|
||||
|
||||
nsresult DoScan();
|
||||
|
||||
PRBool mKeepGoing;
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
|
||||
nsTArray<nsWifiListener> mListeners;
|
||||
|
||||
PRMonitor* mMonitor;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
182
netwerk/wifi/src/nsWifiScannerMac.cpp
Normal file
182
netwerk/wifi/src/nsWifiScannerMac.cpp
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* This is a derivative of work done by Google under a BSD style License.
|
||||
* See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <mach-o/dyld.h>
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "osx_wifi.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsWifiMonitor.h"
|
||||
#include "nsWifiAccessPoint.h"
|
||||
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIMutableArray.h"
|
||||
|
||||
nsresult
|
||||
nsWifiMonitor::DoScan()
|
||||
{
|
||||
void *apple_80211_library = dlopen(
|
||||
"/System/Library/PrivateFrameworks/Apple80211.framework/Apple80211",
|
||||
RTLD_LAZY);
|
||||
|
||||
WirelessContextPtr wifi_context_;
|
||||
|
||||
WirelessAttachFunction WirelessAttach_function_ = reinterpret_cast<WirelessAttachFunction>(dlsym(apple_80211_library, "WirelessAttach"));
|
||||
WirelessScanSplitFunction WirelessScanSplit_function_ = reinterpret_cast<WirelessScanSplitFunction>(dlsym(apple_80211_library, "WirelessScanSplit"));
|
||||
WirelessDetachFunction WirelessDetach_function_ = reinterpret_cast<WirelessDetachFunction>(dlsym(apple_80211_library, "WirelessDetach"));
|
||||
|
||||
if (!WirelessAttach_function_ || !WirelessScanSplit_function_ || !WirelessDetach_function_)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if ((*WirelessAttach_function_)(&wifi_context_, 0) != noErr)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Regularly get the access point data.
|
||||
|
||||
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
|
||||
nsCOMArray<nsWifiAccessPoint> accessPoints;
|
||||
|
||||
do {
|
||||
accessPoints.Clear();
|
||||
|
||||
CFArrayRef managed_access_points = NULL;
|
||||
CFArrayRef adhoc_access_points = NULL;
|
||||
|
||||
if ((*WirelessScanSplit_function_)(wifi_context_,
|
||||
&managed_access_points,
|
||||
&adhoc_access_points,
|
||||
0) != noErr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (managed_access_points == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int accessPointsCount = CFArrayGetCount(managed_access_points);
|
||||
|
||||
for (int i = 0; i < accessPointsCount; ++i) {
|
||||
|
||||
nsWifiAccessPoint* ap = new nsWifiAccessPoint();
|
||||
if (!ap)
|
||||
continue;
|
||||
|
||||
const WirelessNetworkInfo *access_point_info =
|
||||
reinterpret_cast<const WirelessNetworkInfo*>(CFDataGetBytePtr(reinterpret_cast<const CFDataRef>(CFArrayGetValueAtIndex(managed_access_points, i))));
|
||||
|
||||
ap->setMac(access_point_info->macAddress);
|
||||
|
||||
// WirelessNetworkInfo::signal appears to be signal strength in dBm.
|
||||
ap->setSignal(access_point_info->signal);
|
||||
|
||||
ap->setSSID(reinterpret_cast<const char*>(access_point_info->name),
|
||||
access_point_info->nameLen);
|
||||
|
||||
accessPoints.AppendObject(ap);
|
||||
}
|
||||
|
||||
PRBool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
|
||||
nsCOMArray<nsIWifiListener> currentListeners;
|
||||
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
|
||||
if (!mListeners[i].mHasSentData || accessPointsChanged) {
|
||||
mListeners[i].mHasSentData = PR_TRUE;
|
||||
currentListeners.AppendObject(mListeners[i].mListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReplaceArray(lastAccessPoints, accessPoints);
|
||||
|
||||
if (currentListeners.Count() > 0)
|
||||
{
|
||||
PRUint32 resultCount = lastAccessPoints.Count();
|
||||
nsIWifiAccessPoint** result = static_cast<nsIWifiAccessPoint**> (nsMemory::Alloc(sizeof(nsIWifiAccessPoint*) * resultCount));
|
||||
if (!result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
for (PRUint32 i = 0; i < resultCount; i++)
|
||||
result[i] = lastAccessPoints[i];
|
||||
|
||||
for (PRInt32 i = 0; i < currentListeners.Count(); i++) {
|
||||
|
||||
LOG(("About to send data to the wifi listeners\n"));
|
||||
|
||||
nsCOMPtr<nsIWifiListener> proxy;
|
||||
nsCOMPtr<nsIProxyObjectManager> proxyObjMgr = do_GetService("@mozilla.org/xpcomproxy;1");
|
||||
proxyObjMgr->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
|
||||
NS_GET_IID(nsIWifiListener),
|
||||
currentListeners[i],
|
||||
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
|
||||
getter_AddRefs(proxy));
|
||||
if (!proxy) {
|
||||
LOG(("There is no proxy available. this should never happen\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
nsresult rv = proxy->OnChange(result, resultCount);
|
||||
LOG( ("... sent %d\n", rv));
|
||||
}
|
||||
}
|
||||
|
||||
nsMemory::Free(result);
|
||||
}
|
||||
|
||||
// wait for some reasonable amount of time. pref?
|
||||
LOG(("waiting on monitor\n"));
|
||||
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
mon.Wait(PR_SecondsToInterval(60));
|
||||
}
|
||||
while (mKeepGoing == PR_TRUE);
|
||||
|
||||
(*WirelessDetach_function_)(wifi_context_);
|
||||
|
||||
dlclose(apple_80211_library);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
232
netwerk/wifi/src/nsWifiScannerUnix.cpp
Normal file
232
netwerk/wifi/src/nsWifiScannerUnix.cpp
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* This is a derivative of work done by Google under a BSD style License.
|
||||
* See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "iwlib.h"
|
||||
|
||||
#include "dlfcn.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsWifiMonitor.h"
|
||||
#include "nsWifiAccessPoint.h"
|
||||
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIMutableArray.h"
|
||||
|
||||
|
||||
|
||||
|
||||
typedef int (*iw_open_t)(void);
|
||||
|
||||
typedef void (*iw_enum_t)(int skfd,
|
||||
iw_enum_handler fn,
|
||||
char *args[],
|
||||
int count);
|
||||
|
||||
typedef int (*iw_stats_t)(int skfd,
|
||||
const char *ifname,
|
||||
iwstats *stats,
|
||||
const iwrange *range,
|
||||
int has_range);
|
||||
|
||||
|
||||
static iw_open_t iw_open = nsnull;
|
||||
static iw_enum_t iw_enum = nsnull;
|
||||
static iw_stats_t iw_stats = nsnull;
|
||||
|
||||
static int scan_wifi(int skfd, char* ifname, char* args[], int count)
|
||||
{
|
||||
nsCOMArray<nsWifiAccessPoint>* accessPoints = (nsCOMArray<nsWifiAccessPoint>*) args[0];
|
||||
|
||||
struct iwreq wrq;
|
||||
|
||||
int result = iw_get_ext(skfd, ifname, SIOCGIWMODE, &wrq);
|
||||
if (result < 0)
|
||||
return 0;
|
||||
|
||||
// We only cared about "Managed" mode. 2 is the magic number. There isn't a #define for this.
|
||||
if (wrq.u.mode != 2)
|
||||
return 0;
|
||||
|
||||
nsWifiAccessPoint* ap = new nsWifiAccessPoint();
|
||||
if (!ap)
|
||||
return 0;
|
||||
|
||||
char buffer[128];
|
||||
wrq.u.essid.pointer = buffer;
|
||||
wrq.u.essid.length = 128;
|
||||
wrq.u.essid.flags = 0;
|
||||
result = iw_get_ext(skfd, ifname, SIOCGIWESSID, &wrq);
|
||||
if (result < 0) {
|
||||
delete ap;
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer[wrq.u.essid.length] = 0;
|
||||
strncpy(ap->mSsid, buffer, 32);
|
||||
|
||||
result = iw_get_ext(skfd, ifname, SIOCGIWAP, &wrq);
|
||||
if (result < 0) {
|
||||
delete ap;
|
||||
return 0;
|
||||
}
|
||||
ap->setMac( (const uint8*) wrq.u.ap_addr.sa_data );
|
||||
|
||||
iwrange range;
|
||||
iwstats stats;
|
||||
result = (*iw_stats)(skfd, ifname, &stats, &range, 1);
|
||||
if (result < 0) {
|
||||
delete ap;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(stats.qual.level > range.max_qual.level)
|
||||
ap->mSignal = stats.qual.level - 0x100;
|
||||
else
|
||||
ap->mSignal = 0;
|
||||
|
||||
accessPoints->AppendObject(ap);
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWifiMonitor::DoScan()
|
||||
{
|
||||
void* iwlib_handle = dlopen("libiw.so", RTLD_NOW);
|
||||
if (!iwlib_handle) {
|
||||
iwlib_handle = dlopen("libiw.so.29", RTLD_NOW);
|
||||
if (!iwlib_handle) {
|
||||
LOG(("Could not load libiw\n"));
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG(("Loaded libiw\n"));
|
||||
}
|
||||
|
||||
iw_open = (iw_open_t) dlsym(iwlib_handle, "iw_sockets_open");
|
||||
iw_enum = (iw_enum_t) dlsym(iwlib_handle, "iw_enum_devices");
|
||||
iw_stats = (iw_stats_t)dlsym(iwlib_handle, "iw_get_stats");
|
||||
|
||||
if (!iw_open || !iw_enum || !iw_stats) {
|
||||
dlclose(iwlib_handle);
|
||||
LOG(("Could not load a symbol from iwlib.so\n"));
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
int skfd = (*iw_open)();
|
||||
|
||||
if (skfd < 0) {
|
||||
dlclose(iwlib_handle);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
|
||||
nsCOMArray<nsWifiAccessPoint> accessPoints;
|
||||
|
||||
char* args[] = {(char*) &accessPoints, nsnull };
|
||||
|
||||
while (mKeepGoing == PR_TRUE) {
|
||||
|
||||
accessPoints.Clear();
|
||||
|
||||
(*iw_enum)(skfd, &scan_wifi, args, 1);
|
||||
|
||||
PRBool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
|
||||
nsCOMArray<nsIWifiListener> currentListeners;
|
||||
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
|
||||
if (!mListeners[i].mHasSentData || accessPointsChanged) {
|
||||
mListeners[i].mHasSentData = PR_TRUE;
|
||||
currentListeners.AppendObject(mListeners[i].mListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReplaceArray(lastAccessPoints, accessPoints);
|
||||
|
||||
if (currentListeners.Count() > 0)
|
||||
{
|
||||
PRUint32 resultCount = lastAccessPoints.Count();
|
||||
nsIWifiAccessPoint** result = static_cast<nsIWifiAccessPoint**> (nsMemory::Alloc(sizeof(nsIWifiAccessPoint*) * resultCount));
|
||||
if (!result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
for (PRUint32 i = 0; i < resultCount; i++)
|
||||
result[i] = lastAccessPoints[i];
|
||||
|
||||
for (PRInt32 i = 0; i < currentListeners.Count(); i++) {
|
||||
|
||||
LOG(("About to send data to the wifi listeners\n"));
|
||||
|
||||
nsCOMPtr<nsIWifiListener> proxy;
|
||||
nsCOMPtr<nsIProxyObjectManager> proxyObjMgr = do_GetService("@mozilla.org/xpcomproxy;1");
|
||||
proxyObjMgr->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
|
||||
NS_GET_IID(nsIWifiListener),
|
||||
currentListeners[i],
|
||||
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
|
||||
getter_AddRefs(proxy));
|
||||
if (!proxy) {
|
||||
LOG(("There is no proxy available. this should never happen\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
nsresult rv = proxy->OnChange(result, resultCount);
|
||||
LOG( ("... sent %d\n", rv));
|
||||
}
|
||||
}
|
||||
|
||||
nsMemory::Free(result);
|
||||
}
|
||||
|
||||
LOG(("waiting on monitor\n"));
|
||||
|
||||
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
mon.Wait(PR_SecondsToInterval(60));
|
||||
}
|
||||
|
||||
iw_sockets_close(skfd);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
562
netwerk/wifi/src/nsWifiScannerWin.cpp
Normal file
562
netwerk/wifi/src/nsWifiScannerWin.cpp
Normal file
|
|
@ -0,0 +1,562 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Geolocation.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* This is a derivative of work done by Google under a BSD style License.
|
||||
* See: http://gears.googlecode.com/svn/trunk/gears/geolocation/
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@meer.net> (Original Author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "windows.h"
|
||||
#include "wlanapi.h"
|
||||
|
||||
#include <ntddndis.h>
|
||||
#include "winioctl.h"
|
||||
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsWifiMonitor.h"
|
||||
#include "nsWifiAccessPoint.h"
|
||||
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIMutableArray.h"
|
||||
|
||||
|
||||
// Taken from ndis.h
|
||||
#define NDIS_STATUS_INVALID_LENGTH ((NDIS_STATUS)0xC0010014L)
|
||||
#define NDIS_STATUS_BUFFER_TOO_SHORT ((NDIS_STATUS)0xC0010016L)
|
||||
|
||||
static const int kStringLength = 512;
|
||||
|
||||
// The limits on the size of the buffer used for the OID query.
|
||||
static const int kInitialBufferSize = 2 << 12; // Good for about 50 APs.
|
||||
static const int kMaximumBufferSize = 2 << 20; // 2MB
|
||||
|
||||
static int oid_buffer_size_ = kStringLength;
|
||||
|
||||
PRBool ResizeBuffer(int requested_size, BYTE **buffer)
|
||||
{
|
||||
if (requested_size > kMaximumBufferSize) {
|
||||
free(*buffer);
|
||||
*buffer = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
BYTE *new_buffer = reinterpret_cast<BYTE*>(realloc(*buffer, requested_size));
|
||||
if (new_buffer == NULL) {
|
||||
free(*buffer);
|
||||
*buffer = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
*buffer = new_buffer;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int PerformQuery(HANDLE adapter_handle,
|
||||
BYTE *buffer,
|
||||
DWORD buffer_size,
|
||||
DWORD *bytes_out) {
|
||||
|
||||
DWORD oid = OID_802_11_BSSID_LIST;
|
||||
|
||||
if (!DeviceIoControl(adapter_handle,
|
||||
IOCTL_NDIS_QUERY_GLOBAL_STATS,
|
||||
&oid,
|
||||
sizeof(oid),
|
||||
buffer,
|
||||
buffer_size,
|
||||
bytes_out,
|
||||
NULL)) {
|
||||
return GetLastError();
|
||||
}
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
HANDLE GetFileHandle(const unsigned short* device_name) {
|
||||
// We access a device with DOS path \Device\<device_name> at
|
||||
// \\.\<device_name>.
|
||||
|
||||
nsString formatted_device_name;
|
||||
formatted_device_name.Assign(L"\\\\.\\");
|
||||
formatted_device_name.Append(device_name);
|
||||
|
||||
return CreateFileW(formatted_device_name.get(),
|
||||
GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
|
||||
0, // security attributes
|
||||
OPEN_EXISTING,
|
||||
0, // flags and attributes
|
||||
INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
|
||||
bool UndefineDosDevice(const unsigned short* device_name) {
|
||||
// We remove only the mapping we use, that is \Device\<device_name>.
|
||||
nsString target_path;
|
||||
target_path.Assign(L"\\Device\\");
|
||||
target_path.Append(device_name);
|
||||
|
||||
return DefineDosDeviceW(DDD_RAW_TARGET_PATH | DDD_REMOVE_DEFINITION | DDD_EXACT_MATCH_ON_REMOVE,
|
||||
device_name,
|
||||
target_path.get()) == TRUE;
|
||||
}
|
||||
|
||||
bool DefineDosDeviceIfNotExists(unsigned short* device_name) {
|
||||
|
||||
// We create a DOS device name for the device at \Device\<device_name>.
|
||||
nsString target_path;
|
||||
target_path.Assign(L"\\Device\\");
|
||||
target_path.Append(device_name);
|
||||
|
||||
unsigned short target[kStringLength];
|
||||
|
||||
if (QueryDosDeviceW(device_name, target, kStringLength) > 0 && target_path.Equals(target)) {
|
||||
// Device already exists.
|
||||
return true;
|
||||
}
|
||||
|
||||
DWORD error = GetLastError();
|
||||
if (error != ERROR_FILE_NOT_FOUND) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DefineDosDeviceW(DDD_RAW_TARGET_PATH,
|
||||
device_name,
|
||||
target_path.get())) {
|
||||
return false;
|
||||
}
|
||||
// Check that the device is really there.
|
||||
return QueryDosDeviceW(device_name, target, kStringLength) > 0 &&
|
||||
target_path.Equals(target);
|
||||
}
|
||||
|
||||
void GetNetworkInterfacesFromRegistry(nsStringArray& interfaces)
|
||||
{
|
||||
HKEY network_cards_key = NULL;
|
||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||
L"Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards",
|
||||
0,
|
||||
KEY_READ,
|
||||
&network_cards_key) != ERROR_SUCCESS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; ; ++i) {
|
||||
unsigned short name[kStringLength];
|
||||
DWORD name_size = kStringLength;
|
||||
FILETIME time;
|
||||
|
||||
if (RegEnumKeyExW(network_cards_key,
|
||||
i,
|
||||
name,
|
||||
&name_size,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
&time) != ERROR_SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
HKEY hardware_key = NULL;
|
||||
if (RegOpenKeyExW(network_cards_key,
|
||||
name,
|
||||
0,
|
||||
KEY_READ,
|
||||
&hardware_key) != ERROR_SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
unsigned short service_name[kStringLength];
|
||||
DWORD service_name_size = kStringLength;
|
||||
DWORD type = 0;
|
||||
|
||||
if (RegQueryValueExW(hardware_key,
|
||||
L"ServiceName",
|
||||
NULL,
|
||||
&type,
|
||||
reinterpret_cast<LPBYTE>(service_name),
|
||||
&service_name_size) == ERROR_SUCCESS) {
|
||||
|
||||
interfaces.AppendString(nsString(service_name)); // is this allowed?
|
||||
}
|
||||
RegCloseKey(hardware_key);
|
||||
}
|
||||
RegCloseKey(network_cards_key);
|
||||
}
|
||||
|
||||
|
||||
PRBool IsRunningOnVista() {
|
||||
static DWORD os_major_version = 0;
|
||||
static DWORD platform_id = 0;
|
||||
|
||||
if (0 == os_major_version) {
|
||||
OSVERSIONINFO os_version = {0};
|
||||
os_version.dwOSVersionInfoSize = sizeof(os_version);
|
||||
GetVersionEx(&os_version);
|
||||
os_major_version = os_version.dwMajorVersion;
|
||||
platform_id = os_version.dwPlatformId;
|
||||
}
|
||||
|
||||
return (6 == os_major_version) && (VER_PLATFORM_WIN32_NT == platform_id);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsWifiMonitor::DoScan()
|
||||
{
|
||||
if (!IsRunningOnVista()) {
|
||||
|
||||
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
|
||||
nsCOMArray<nsWifiAccessPoint> accessPoints;
|
||||
|
||||
do {
|
||||
accessPoints.Clear();
|
||||
|
||||
nsStringArray interfaces;
|
||||
GetNetworkInterfacesFromRegistry(interfaces);
|
||||
|
||||
for (int i = 0; i < interfaces.Count(); i++) {
|
||||
nsString *s = interfaces.StringAt(i);
|
||||
unsigned short *service_name = (PRUnichar*) s->get();
|
||||
|
||||
if (!DefineDosDeviceIfNotExists(service_name))
|
||||
continue;
|
||||
|
||||
// Get the handle to the device. This will fail if the named device is not
|
||||
// valid.
|
||||
|
||||
HANDLE adapter_handle = GetFileHandle(service_name);
|
||||
if (adapter_handle == INVALID_HANDLE_VALUE)
|
||||
continue;
|
||||
|
||||
// Get the data.
|
||||
|
||||
BYTE *buffer = reinterpret_cast<BYTE*>(malloc(oid_buffer_size_));
|
||||
if (buffer == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
DWORD bytes_out;
|
||||
int result;
|
||||
|
||||
while (true) {
|
||||
bytes_out = 0;
|
||||
result = PerformQuery(adapter_handle, buffer, oid_buffer_size_, &bytes_out);
|
||||
|
||||
if (result == ERROR_GEN_FAILURE || // Returned by some Intel cards.
|
||||
result == ERROR_INSUFFICIENT_BUFFER ||
|
||||
result == ERROR_MORE_DATA ||
|
||||
result == NDIS_STATUS_INVALID_LENGTH ||
|
||||
result == NDIS_STATUS_BUFFER_TOO_SHORT) {
|
||||
|
||||
// The buffer we supplied is too small, so increase it. bytes_out should
|
||||
// provide the required buffer size, but this is not always the case.
|
||||
|
||||
if (bytes_out > static_cast<DWORD>(oid_buffer_size_)) {
|
||||
oid_buffer_size_ = bytes_out;
|
||||
} else {
|
||||
oid_buffer_size_ *= 2;
|
||||
}
|
||||
|
||||
if (!ResizeBuffer(oid_buffer_size_, &buffer)) {
|
||||
oid_buffer_size_ = kInitialBufferSize; // Reset for next time.
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// The buffer is not too small.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (result == ERROR_SUCCESS) {
|
||||
NDIS_802_11_BSSID_LIST* bssid_list = reinterpret_cast<NDIS_802_11_BSSID_LIST*>(buffer);
|
||||
|
||||
// Walk through the BSS IDs.
|
||||
int found = 0;
|
||||
const uint8 *iterator = reinterpret_cast<const uint8*>(&bssid_list->Bssid[0]);
|
||||
const uint8 *end_of_buffer = reinterpret_cast<const uint8*>(&bssid_list) + oid_buffer_size_;
|
||||
for (int i = 0; i < static_cast<int>(bssid_list->NumberOfItems); ++i) {
|
||||
|
||||
const NDIS_WLAN_BSSID *bss_id = reinterpret_cast<const NDIS_WLAN_BSSID*>(iterator);
|
||||
|
||||
// Check that the length of this BSS ID is reasonable.
|
||||
if (bss_id->Length < sizeof(NDIS_WLAN_BSSID) ||
|
||||
iterator + bss_id->Length > end_of_buffer) {
|
||||
break;
|
||||
}
|
||||
|
||||
nsWifiAccessPoint* ap = new nsWifiAccessPoint();
|
||||
if (!ap)
|
||||
continue;
|
||||
|
||||
ap->setMac(bss_id->MacAddress);
|
||||
ap->setSignal(bss_id->Rssi);
|
||||
ap->setSSID((char*) bss_id->Ssid.Ssid, bss_id->Ssid.SsidLength);
|
||||
|
||||
accessPoints.AppendObject(ap);
|
||||
|
||||
// Move to the next BSS ID.
|
||||
iterator += bss_id->Length;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
|
||||
// Clean up.
|
||||
CloseHandle(adapter_handle);
|
||||
}
|
||||
|
||||
UndefineDosDevice(service_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
|
||||
nsCOMArray<nsIWifiListener> currentListeners;
|
||||
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
|
||||
if (!mListeners[i].mHasSentData || accessPointsChanged) {
|
||||
mListeners[i].mHasSentData = PR_TRUE;
|
||||
currentListeners.AppendObject(mListeners[i].mListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReplaceArray(lastAccessPoints, accessPoints);
|
||||
|
||||
if (currentListeners.Count() > 0) {
|
||||
|
||||
PRUint32 resultCount = lastAccessPoints.Count();
|
||||
nsIWifiAccessPoint** result = static_cast<nsIWifiAccessPoint**> (nsMemory::Alloc(sizeof(nsIWifiAccessPoint*) * resultCount));
|
||||
if (!result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
for (PRUint32 i = 0; i < resultCount; i++)
|
||||
result[i] = lastAccessPoints[i];
|
||||
|
||||
for (PRInt32 i = 0; i < currentListeners.Count(); i++) {
|
||||
|
||||
LOG(("About to send data to the wifi listeners\n"));
|
||||
|
||||
nsCOMPtr<nsIWifiListener> proxy;
|
||||
nsCOMPtr<nsIProxyObjectManager> proxyObjMgr = do_GetService("@mozilla.org/xpcomproxy;1");
|
||||
proxyObjMgr->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
|
||||
NS_GET_IID(nsIWifiListener),
|
||||
currentListeners[i],
|
||||
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
|
||||
getter_AddRefs(proxy));
|
||||
if (!proxy) {
|
||||
LOG(("There is no proxy available. this should never happen\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
nsresult rv = proxy->OnChange(result, resultCount);
|
||||
LOG( ("... sent %d\n", rv));
|
||||
}
|
||||
}
|
||||
|
||||
nsMemory::Free(result);
|
||||
}
|
||||
|
||||
// wait for some reasonable amount of time. pref?
|
||||
LOG(("waiting on monitor\n"));
|
||||
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
mon.Wait(PR_SecondsToInterval(60));
|
||||
}
|
||||
while (mKeepGoing == PR_TRUE);
|
||||
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
HINSTANCE wlan_library = LoadLibrary("Wlanapi.dll");
|
||||
if (!wlan_library)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
WlanOpenHandleFunction WlanOpenHandle = (WlanOpenHandleFunction) GetProcAddress(wlan_library, "WlanOpenHandle");
|
||||
WlanEnumInterfacesFunction WlanEnumInterfaces = (WlanEnumInterfacesFunction) GetProcAddress(wlan_library, "WlanEnumInterfaces");
|
||||
WlanGetNetworkBssListFunction WlanGetNetworkBssList = (WlanGetNetworkBssListFunction) GetProcAddress(wlan_library, "WlanGetNetworkBssList");
|
||||
WlanFreeMemoryFunction WlanFreeMemory = (WlanFreeMemoryFunction) GetProcAddress(wlan_library, "WlanFreeMemory");
|
||||
WlanCloseHandleFunction WlanCloseHandle = (WlanCloseHandleFunction) GetProcAddress(wlan_library, "WlanCloseHandle");
|
||||
|
||||
if (!WlanOpenHandle ||
|
||||
!WlanEnumInterfaces ||
|
||||
!WlanGetNetworkBssList ||
|
||||
!WlanFreeMemory ||
|
||||
!WlanCloseHandle)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Regularly get the access point data.
|
||||
|
||||
nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
|
||||
nsCOMArray<nsWifiAccessPoint> accessPoints;
|
||||
|
||||
do {
|
||||
accessPoints.Clear();
|
||||
|
||||
// Get the handle to the WLAN API.
|
||||
DWORD negotiated_version;
|
||||
HANDLE wlan_handle = NULL;
|
||||
// We could be executing on either Windows XP or Windows Vista, so use the
|
||||
// lower version of the client WLAN API. It seems that the negotiated version
|
||||
// is the Vista version irrespective of what we pass!
|
||||
static const int kXpWlanClientVersion = 1;
|
||||
if ((*WlanOpenHandle)(kXpWlanClientVersion,
|
||||
NULL,
|
||||
&negotiated_version,
|
||||
&wlan_handle) != ERROR_SUCCESS) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
// try again later.
|
||||
if (!wlan_handle)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Get the list of interfaces. WlanEnumInterfaces allocates interface_list.
|
||||
WLAN_INTERFACE_INFO_LIST *interface_list = NULL;
|
||||
if ((*WlanEnumInterfaces)(wlan_handle, NULL, &interface_list) != ERROR_SUCCESS) {
|
||||
// try again later
|
||||
(*WlanCloseHandle)(wlan_handle, NULL);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Go through the list of interfaces and get the data for each.
|
||||
for (int i = 0; i < static_cast<int>(interface_list->dwNumberOfItems); ++i) {
|
||||
|
||||
WLAN_BSS_LIST *bss_list;
|
||||
HRESULT rv = (*WlanGetNetworkBssList)(wlan_handle,
|
||||
&interface_list->InterfaceInfo[i].InterfaceGuid,
|
||||
NULL, // Use all SSIDs.
|
||||
DOT11_BSS_TYPE_UNUSED,
|
||||
false, // bSecurityEnabled - unused
|
||||
NULL, // reserved
|
||||
&bss_list);
|
||||
if (rv != ERROR_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 0; j < static_cast<int>(bss_list->dwNumberOfItems); ++j) {
|
||||
|
||||
nsWifiAccessPoint* ap = new nsWifiAccessPoint();
|
||||
if (!ap)
|
||||
continue;
|
||||
|
||||
const WLAN_BSS_ENTRY bss_entry = bss_list->wlanBssEntries[j];
|
||||
|
||||
ap->setMac(bss_entry.dot11Bssid);
|
||||
ap->setSignal(bss_entry.lRssi);
|
||||
ap->setSSID((char*) bss_entry.dot11Ssid.ucSSID,
|
||||
bss_entry.dot11Ssid.uSSIDLength);
|
||||
|
||||
accessPoints.AppendObject(ap);
|
||||
}
|
||||
(*WlanFreeMemory)(bss_list);
|
||||
}
|
||||
|
||||
// Free interface_list.
|
||||
(*WlanFreeMemory)(interface_list);
|
||||
|
||||
// Close the handle.
|
||||
(*WlanCloseHandle)(wlan_handle, NULL);
|
||||
|
||||
|
||||
PRBool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
|
||||
nsCOMArray<nsIWifiListener> currentListeners;
|
||||
|
||||
{
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
|
||||
for (PRUint32 i = 0; i < mListeners.Length(); i++) {
|
||||
if (!mListeners[i].mHasSentData || accessPointsChanged) {
|
||||
mListeners[i].mHasSentData = PR_TRUE;
|
||||
currentListeners.AppendObject(mListeners[i].mListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReplaceArray(lastAccessPoints, accessPoints);
|
||||
|
||||
if (currentListeners.Count() > 0) {
|
||||
PRUint32 resultCount = lastAccessPoints.Count();
|
||||
nsIWifiAccessPoint** result = static_cast<nsIWifiAccessPoint**> (nsMemory::Alloc(sizeof(nsIWifiAccessPoint*) * resultCount));
|
||||
if (!result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
for (PRUint32 i = 0; i < resultCount; i++)
|
||||
result[i] = lastAccessPoints[i];
|
||||
|
||||
for (PRInt32 i = 0; i < currentListeners.Count(); i++) {
|
||||
|
||||
LOG(("About to send data to the wifi listeners\n"));
|
||||
|
||||
nsCOMPtr<nsIWifiListener> proxy;
|
||||
nsCOMPtr<nsIProxyObjectManager> proxyObjMgr = do_GetService("@mozilla.org/xpcomproxy;1");
|
||||
proxyObjMgr->GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
|
||||
NS_GET_IID(nsIWifiListener),
|
||||
currentListeners[i],
|
||||
NS_PROXY_SYNC | NS_PROXY_ALWAYS,
|
||||
getter_AddRefs(proxy));
|
||||
if (!proxy) {
|
||||
LOG(("There is no proxy available. this should never happen\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
nsresult rv = proxy->OnChange(result, resultCount);
|
||||
LOG( ("... sent %d\n", rv));
|
||||
}
|
||||
}
|
||||
|
||||
nsMemory::Free(result);
|
||||
}
|
||||
|
||||
// wait for some reasonable amount of time. pref?
|
||||
LOG(("waiting on monitor\n"));
|
||||
|
||||
nsAutoMonitor mon(mMonitor);
|
||||
mon.Wait(PR_SecondsToInterval(60));
|
||||
}
|
||||
while (mKeepGoing == PR_TRUE);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
120
netwerk/wifi/src/osx_wifi.h
Normal file
120
netwerk/wifi/src/osx_wifi.h
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
// Copyright 2008, Google Inc.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// The contents of this file are taken from Apple80211.h from the iStumbler
|
||||
// project (http://www.istumbler.net). This project is released under the BSD
|
||||
// license with the following restrictions.
|
||||
//
|
||||
// Copyright (c) 02006, Alf Watt (alf@istumbler.net). All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// * Neither the name of iStumbler nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is the reverse engineered header for the Apple80211 private framework.
|
||||
// The framework can be found at
|
||||
// /System/Library/PrivateFrameworks/Apple80211.framework.
|
||||
|
||||
#ifndef GEARS_GEOLOCATION_OSX_WIFI_H__
|
||||
#define GEARS_GEOLOCATION_OSX_WIFI_H__
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
typedef SInt32 WIErr;
|
||||
|
||||
// A WirelessContext should be created using WirelessAttach
|
||||
// before any other Wireless functions are called. WirelessDetach
|
||||
// is used to dispose of a WirelessContext.
|
||||
typedef struct __WirelessContext *WirelessContextPtr;
|
||||
|
||||
// WirelessAttach
|
||||
//
|
||||
// This should be called before all other wireless functions.
|
||||
typedef WIErr (*WirelessAttachFunction)(WirelessContextPtr *outContext,
|
||||
const UInt32);
|
||||
|
||||
// WirelessDetach
|
||||
//
|
||||
// This should be called after all other wireless functions.
|
||||
typedef WIErr (*WirelessDetachFunction)(WirelessContextPtr inContext);
|
||||
|
||||
typedef UInt16 WINetworkInfoFlags;
|
||||
|
||||
struct WirelessNetworkInfo
|
||||
{
|
||||
UInt16 channel; // Channel for the network.
|
||||
SInt16 noise; // Noise for the network. 0 for Adhoc.
|
||||
SInt16 signal; // Signal strength of the network. 0 for Adhoc.
|
||||
UInt8 macAddress[6]; // MAC address of the wireless access point.
|
||||
UInt16 beaconInterval; // Beacon interval in milliseconds
|
||||
WINetworkInfoFlags flags; // Flags for the network
|
||||
UInt16 nameLen;
|
||||
SInt8 name[32];
|
||||
};
|
||||
|
||||
// WirelessScanSplit
|
||||
//
|
||||
// WirelessScanSplit scans for available wireless networks. It will allocate 2
|
||||
// CFArrays to store a list of managed and adhoc networks. The arrays hold
|
||||
// CFData objects which contain WirelessNetworkInfo structures.
|
||||
//
|
||||
// Note: An adhoc network created on the computer the scan is running on will
|
||||
// not be found. WirelessGetInfo can be used to find info about a local adhoc
|
||||
// network.
|
||||
//
|
||||
// If stripDups != 0 only one bases tation for each SSID will be returned.
|
||||
typedef WIErr (*WirelessScanSplitFunction)(WirelessContextPtr inContext,
|
||||
CFArrayRef *apList,
|
||||
CFArrayRef *adhocList,
|
||||
const UInt32 stripDups);
|
||||
|
||||
} // extern "C"
|
||||
|
||||
#endif // GEARS_GEOLOCATION_OSX_WIFI_H__
|
||||
134
netwerk/wifi/src/wlanapi.h
Normal file
134
netwerk/wifi/src/wlanapi.h
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
// Copyright 2008, Google Inc.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of Google Inc. nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without
|
||||
// specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Replicates missing wlanapi.h. Taken from
|
||||
// http://msdn.microsoft.com/en-us/library/bb204766.aspx.
|
||||
|
||||
// TODO(steveblock): Change naming convention to follow correct style.
|
||||
|
||||
|
||||
// WlanOpenHandle
|
||||
|
||||
typedef DWORD (WINAPI *WlanOpenHandleFunction)(DWORD dwClientVersion,
|
||||
PVOID pReserved,
|
||||
PDWORD pdwNegotiatedVersion,
|
||||
PHANDLE phClientHandle);
|
||||
|
||||
// WlanEnumInterfaces
|
||||
|
||||
typedef enum _WLAN_INTERFACE_STATE {
|
||||
WLAN_INTERFACE_STATE_UNUSED,
|
||||
} WLAN_INTERFACE_STATE;
|
||||
|
||||
typedef struct _WLAN_INTERFACE_INFO {
|
||||
GUID InterfaceGuid;
|
||||
WCHAR strInterfaceDescription[256];
|
||||
WLAN_INTERFACE_STATE isState;
|
||||
} WLAN_INTERFACE_INFO, *PWLAN_INTERFACE_INFO;
|
||||
|
||||
typedef struct _WLAN_INTERFACE_INFO_LIST {
|
||||
DWORD dwNumberOfItems;
|
||||
DWORD dwIndex;
|
||||
WLAN_INTERFACE_INFO InterfaceInfo[1];
|
||||
} WLAN_INTERFACE_INFO_LIST, *PWLAN_INTERFACE_INFO_LIST;
|
||||
|
||||
typedef DWORD (WINAPI *WlanEnumInterfacesFunction)(
|
||||
HANDLE hClientHandle,
|
||||
PVOID pReserved,
|
||||
PWLAN_INTERFACE_INFO_LIST *ppInterfaceList);
|
||||
|
||||
// WlanGetNetworkBssList
|
||||
|
||||
#define DOT11_SSID_MAX_LENGTH 32
|
||||
|
||||
typedef struct _DOT11_SSID {
|
||||
ULONG uSSIDLength;
|
||||
UCHAR ucSSID[DOT11_SSID_MAX_LENGTH];
|
||||
} DOT11_SSID, *PDOT11_SSID;
|
||||
|
||||
typedef UCHAR DOT11_MAC_ADDRESS[6];
|
||||
|
||||
typedef enum _DOT11_BSS_TYPE {
|
||||
DOT11_BSS_TYPE_UNUSED,
|
||||
} DOT11_BSS_TYPE;
|
||||
|
||||
typedef enum _DOT11_PHY_TYPE {
|
||||
DOT11_PHY_TYPE_UNUSED,
|
||||
} DOT11_PHY_TYPE;
|
||||
|
||||
#define DOT11_RATE_SET_MAX_LENGTH (126)
|
||||
|
||||
typedef struct _WLAN_RATE_SET {
|
||||
ULONG uRateSetLength;
|
||||
USHORT usRateSet[DOT11_RATE_SET_MAX_LENGTH];
|
||||
} WLAN_RATE_SET, *PWLAN_RATE_SET;
|
||||
|
||||
typedef struct _WLAN_BSS_ENTRY {
|
||||
DOT11_SSID dot11Ssid;
|
||||
ULONG uPhyId;
|
||||
DOT11_MAC_ADDRESS dot11Bssid;
|
||||
DOT11_BSS_TYPE dot11BssType;
|
||||
DOT11_PHY_TYPE dot11BssPhyType;
|
||||
LONG lRssi;
|
||||
ULONG uLinkQuality;
|
||||
BOOLEAN bInRegDomain;
|
||||
USHORT usBeaconPeriod;
|
||||
ULONGLONG ullTimestamp;
|
||||
ULONGLONG ullHostTimestamp;
|
||||
USHORT usCapabilityInformation;
|
||||
ULONG ulChCenterFrequency;
|
||||
WLAN_RATE_SET wlanRateSet;
|
||||
ULONG ulIeOffset;
|
||||
ULONG ulIeSize;
|
||||
} WLAN_BSS_ENTRY, *PWLAN_BSS_ENTRY;
|
||||
|
||||
typedef struct _WLAN_BSS_LIST {
|
||||
DWORD dwTotalSize;
|
||||
DWORD dwNumberOfItems;
|
||||
// Following data is an array of WLAN_BSS_ENTRY objects of length
|
||||
// dwNumberOfItems.
|
||||
WLAN_BSS_ENTRY wlanBssEntries[1];
|
||||
} WLAN_BSS_LIST, *PWLAN_BSS_LIST;
|
||||
|
||||
typedef DWORD (WINAPI *WlanGetNetworkBssListFunction)(
|
||||
HANDLE hClientHandle,
|
||||
const GUID *pInterfaceGuid,
|
||||
const PDOT11_SSID pDot11Ssid,
|
||||
DOT11_BSS_TYPE dot11BssType,
|
||||
BOOL bSecurityEnabled,
|
||||
PVOID pReserved,
|
||||
PWLAN_BSS_LIST *ppWlanBssList
|
||||
);
|
||||
|
||||
// WlanFreeMemory
|
||||
|
||||
typedef VOID (WINAPI *WlanFreeMemoryFunction)(PVOID pMemory);
|
||||
|
||||
// WlanCloseHandle
|
||||
|
||||
typedef DWORD (WINAPI *WlanCloseHandleFunction)(HANDLE hClientHandle,
|
||||
PVOID pReserved);
|
||||
|
||||
|
||||
61
netwerk/wifi/tests/wifi_access_point_test.html
Normal file
61
netwerk/wifi/tests/wifi_access_point_test.html
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>hi</title>
|
||||
<script>
|
||||
|
||||
var count = 0;
|
||||
|
||||
|
||||
function test() {
|
||||
}
|
||||
|
||||
test.prototype =
|
||||
{
|
||||
onChange: function (accessPoints)
|
||||
{
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var d = document.getElementById("d");
|
||||
d.innerHTML = "";
|
||||
|
||||
for (var i=0; i<accessPoints.length; i++) {
|
||||
var a = accessPoints[i];
|
||||
d.innerHTML = d.innerHTML + "<p>" + a.mac + " " + a.ssid + " " + a.signal + "</p>";
|
||||
}
|
||||
|
||||
|
||||
var c = document.getElementById("c");
|
||||
c.innerHTML = "<p>" + count++ + "</p>";
|
||||
|
||||
},
|
||||
|
||||
onError: function (value) {
|
||||
alert("error: " +value);
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
if (iid.equals(Components.interfaces.nsIWifiListener) ||
|
||||
iid.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
var listener = new test();
|
||||
var wifi_service = Components.classes["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);
|
||||
|
||||
wifi_service.startWatching(listener);
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="d"><p></p></div>
|
||||
<div id="c"><p></p></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -2769,6 +2769,97 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
|
||||
|
||||
|
||||
<hr>
|
||||
|
||||
<h1><a name="google-gears"></a>Google Gears</h1>
|
||||
|
||||
<p class="correctme">This license applies to files in the following directories
|
||||
with the specified copyright year ranges:</p>
|
||||
<ul>
|
||||
<li><span class="path">netwerk/wifi/</span>, 2009</li>
|
||||
</ul>
|
||||
|
||||
<pre>
|
||||
Copyright 2008, Google Inc.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
3. Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
The contents of this file are taken from Apple80211.h from
|
||||
the iStumbler project (http://www.istumbler.net). This
|
||||
project is released under the BSD license with the following
|
||||
restrictions.
|
||||
|
||||
Copyright (c) 02006, Alf Watt (alf@istumbler.net). All
|
||||
rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or
|
||||
without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
* Neither the name of iStumbler nor the names of its
|
||||
contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This is the reverse engineered header for the Apple80211
|
||||
private framework. The framework can be found at
|
||||
/System/Library/PrivateFrameworks/Apple80211.framework.
|
||||
|
||||
</pre>
|
||||
|
||||
<hr>
|
||||
|
||||
<h1><a name="other-notices"></a>Other Required Notices</h1>
|
||||
|
|
|
|||
|
|
@ -365,6 +365,9 @@ MAKEFILES_netwerk="
|
|||
netwerk/cookie/Makefile
|
||||
netwerk/cookie/public/Makefile
|
||||
netwerk/cookie/src/Makefile
|
||||
netwerk/wifi/Makefile
|
||||
netwerk/wifi/public/Makefile
|
||||
netwerk/wifi/src/Makefile
|
||||
netwerk/dns/Makefile
|
||||
netwerk/dns/public/Makefile
|
||||
netwerk/dns/src/Makefile
|
||||
|
|
|
|||
Loading…
Reference in a new issue