[SVN-Commit] r1295 - in trunk/www: firefox-nightly/files firefox/files seamonkey/files
svn-freebsd-gecko at chruetertee.ch
svn-freebsd-gecko at chruetertee.ch
Tue Jul 30 09:33:06 UTC 2013
Author: jbeich
Date: Tue Jul 30 09:32:58 2013
New Revision: 1295
Log:
improve style based on review
Submitted by: J.R. Oldroyd <fbsd at opal.com>
Modified:
trunk/www/firefox-nightly/files/patch-bug893397
trunk/www/firefox/files/patch-bug893397
trunk/www/seamonkey/files/patch-bug893397
Modified: trunk/www/firefox-nightly/files/patch-bug893397
==============================================================================
--- trunk/www/firefox-nightly/files/patch-bug893397 Tue Jul 30 09:32:51 2013 (r1294)
+++ trunk/www/firefox-nightly/files/patch-bug893397 Tue Jul 30 09:32:58 2013 (r1295)
@@ -31,191 +31,175 @@
index 0000000..80d4cb6
--- /dev/null
+++ netwerk/wifi/nsWifiScannerFreeBSD.cpp
-@@ -0,0 +1,187 @@
+@@ -0,0 +1,171 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
-+// Developed by J.R. Oldroyd <fbsd at opal.com> and offered to the FreeBSD
-+// www/chromium and www/firefox ports under the terms of each browser's
-+// license.
++// Developed by J.R. Oldroyd <fbsd at opal.com>, December 2012.
+
+// For FreeBSD we use the getifaddrs(3) to obtain the list of interfaces
+// and then check for those with an 802.11 media type and able to return
-+// a list of stations. This is similar to ifconfig(8).
++// a list of stations. This is similar to ifconfig(8).
+
-+#include "nsCOMPtr.h"
-+#include "nsComponentManagerUtils.h"
-+#include "nsServiceManagerUtils.h"
-+#include "nsThreadUtils.h"
-+#include "nsXPCOM.h"
-+#include "nsXPCOMCID.h"
-+#include "nsIObserver.h"
-+#include "nsIObserverService.h"
-+#include "nsWifiMonitor.h"
-+#include "nsWifiAccessPoint.h"
-+
-+#include "nsServiceManagerUtils.h"
-+#include "nsComponentManagerUtils.h"
-+#include "mozilla/Services.h"
-+
-+using namespace mozilla;
-+
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <string.h>
-+#include <unistd.h>
+#include <sys/types.h>
++#include <sys/ioctl.h>
+#include <sys/socket.h>
-+#include <sys/sockio.h>
+#include <net/if.h>
+#include <net/if_media.h>
-+#include <ifaddrs.h>
+#include <net80211/ieee80211_ioctl.h>
-+#include <net/ethernet.h>
+
-+// Convert a wifi frequency to the corresponding channel.
-+// Taken from wifi_data_provider_linux.cc where it says this was
-+// adapted from geolocaiton/wifilib.cc in googleclient (internal to google).
-+int frequency_to_channel(int frequency_Mhz) {
-+ if (frequency_Mhz >= 2412 && frequency_Mhz <= 2472) // Channels 1-13.
-+ return (frequency_Mhz - 2407) / 5;
-+ if (frequency_Mhz == 2484)
-+ return 14;
-+ if (frequency_Mhz > 5000 && frequency_Mhz < 6000) // .11a bands.
-+ return (frequency_Mhz - 5000) / 5;
-+ // Ignore everything else.
-+ return -1; // invalid channel
-+}
++#include <ifaddrs.h>
++#include <string.h>
++#include <unistd.h>
+
-+nsresult
-+FreeBSDGetAccessPointData(nsCOMArray<nsWifiAccessPoint> &accessPoints) {
-+ bool res;
-+ char *dupn;
-+ struct ifaddrs *ifal, *ifa;
-+ struct ifreq ifr;
-+ struct ifmediareq ifmr;
-+ struct ieee80211req i802r;
-+ int s;
-+ char iscanbuf[32*1024], *vsr;
-+ unsigned len;
-+ nsWifiAccessPoint *ap;
-+
-+ if (getifaddrs(&ifal) < 0)
-+ return NS_ERROR_FAILURE;
-+
-+ accessPoints.Clear();
-+
-+ res = false;
-+ dupn = NULL;
-+ for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
-+ memset(&ifr, 0, sizeof(ifr));
-+
-+ if (dupn != NULL && strcmp(dupn, ifa->ifa_name) == 0)
-+ continue;
-+ dupn = ifa->ifa_name;
-+
-+ strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
-+ ifr.ifr_addr.sa_family = AF_LOCAL;
-+
-+ if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
-+ continue;
-+
-+ (void) memset(&ifmr, 0, sizeof(ifmr));
-+ (void) strncpy(ifmr.ifm_name, ifa->ifa_name, sizeof(ifmr.ifm_name));
-+
-+ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
-+ close(s);
-+ continue;
-+ }
-+ if (IFM_TYPE(ifmr.ifm_active) != IFM_IEEE80211) {
-+ close(s);
-+ continue;
-+ }
-+
-+ (void) memset(&i802r, 0, sizeof(i802r));
-+ (void) strncpy(i802r.i_name, ifa->ifa_name, sizeof(i802r.i_name));
-+ i802r.i_type = IEEE80211_IOC_SCAN_RESULTS;
-+ i802r.i_data = iscanbuf;
-+ i802r.i_len = sizeof(iscanbuf);
-+ if (ioctl(s, SIOCG80211, &i802r) < 0) {
-+ close(s);
-+ continue;
-+ }
-+
-+ close(s);
-+
-+ vsr = (char *) i802r.i_data;
-+ len = i802r.i_len;
-+ while (len >= sizeof(struct ieee80211req_scan_result)) {
-+ struct ieee80211req_scan_result *isr;
-+ char *id;
-+ int idlen;
-+ char ssid[IEEE80211_NWID_LEN+1];
-+
-+ isr = (struct ieee80211req_scan_result *) vsr;
-+
-+ if (isr->isr_meshid_len) {
-+ id = vsr + isr->isr_ie_off + isr->isr_ssid_len;
-+ idlen = isr->isr_meshid_len;
-+ }
-+ else {
-+ id = vsr + isr->isr_ie_off;
-+ idlen = isr->isr_ssid_len;
-+ }
-+ strncpy(ssid, id, idlen);
-+ ssid[idlen] = '\0';
-+ ap = new nsWifiAccessPoint();
-+ ap->setSSID(ssid, strlen(ssid));
-+ ap->setMac(isr->isr_bssid);
-+ ap->setSignal(isr->isr_rssi);
-+ // apd.radio_signal_strength = (isr->isr_rssi/2) + isr->isr_noise;
-+ // apd.signal_to_noise = apd.radio_signal_strength - isr->isr_noise;
-+ // apd.channel = frequency_to_channel(isr->isr_freq);
-+ LOG(( "FreeBSD access point: "
-+ << "SSID: " << apd.ssid << ", "
-+ << "MAC: " << apd.mac_address << ", "
-+ << "Strength: " << apd.radio_signal_strength << ":"
-+ << apd.signal_to_noise << ", "
-+ << "Channel: " << apd.channel ));
-+ accessPoints.AppendObject(ap);
-+ res = true;
-+ len -= isr->isr_len;
-+ vsr += isr->isr_len;
-+ }
-+ }
++#include "nsWifiAccessPoint.h"
++
++using namespace mozilla;
++
++static nsresult
++FreeBSDGetAccessPointData(nsCOMArray<nsWifiAccessPoint> &accessPoints)
++{
++ bool res = false;
++ char *dupn = NULL;
++ struct ifaddrs *ifal, *ifa;
++ unsigned len;
++
++ // get list of interfaces
++ if (getifaddrs(&ifal) < 0)
++ return NS_ERROR_FAILURE;
++
++ accessPoints.Clear();
++
++ // loop through the interfaces
++ for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
++ int s;
++ struct ifreq ifr;
++ struct ifmediareq ifmr;
++ struct ieee80211req i802r;
++ char iscanbuf[32*1024], *vsr;
++
++ memset(&ifr, 0, sizeof(ifr));
++
++ // list can contain duplicates, so ignore those
++ if (dupn != NULL && strcmp(dupn, ifa->ifa_name) == 0)
++ continue;
++ dupn = ifa->ifa_name;
++
++ // store interface name in socket structure
++ strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
++ ifr.ifr_addr.sa_family = AF_LOCAL;
++
++ // open socket to interface
++ if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
++ continue;
++
++ // clear interface media structure
++ (void) memset(&ifmr, 0, sizeof(ifmr));
++ (void) strncpy(ifmr.ifm_name, ifa->ifa_name, sizeof(ifmr.ifm_name));
++
++ // get interface media information
++ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
++ close(s);
++ continue;
++ }
++
++ // check interface is a WiFi interface
++ if (IFM_TYPE(ifmr.ifm_active) != IFM_IEEE80211) {
++ close(s);
++ continue;
++ }
++
++ // perform WiFi scan
++ (void) memset(&i802r, 0, sizeof(i802r));
++ (void) strncpy(i802r.i_name, ifa->ifa_name, sizeof(i802r.i_name));
++ i802r.i_type = IEEE80211_IOC_SCAN_RESULTS;
++ i802r.i_data = iscanbuf;
++ i802r.i_len = sizeof(iscanbuf);
++ if (ioctl(s, SIOCG80211, &i802r) < 0) {
++ close(s);
++ continue;
++ }
++
++ // close socket
++ close(s);
++
++ // loop through WiFi networks and build geoloc-lookup structure
++ vsr = (char *) i802r.i_data;
++ len = i802r.i_len;
++ while (len >= sizeof(struct ieee80211req_scan_result)) {
++ struct ieee80211req_scan_result *isr;
++ char *id;
++ int idlen;
++ char ssid[IEEE80211_NWID_LEN+1];
++ nsWifiAccessPoint *ap;
++
++ isr = (struct ieee80211req_scan_result *) vsr;
++
++ // determine size of this entry
++ if (isr->isr_meshid_len) {
++ id = vsr + isr->isr_ie_off + isr->isr_ssid_len;
++ idlen = isr->isr_meshid_len;
++ }
++ else {
++ id = vsr + isr->isr_ie_off;
++ idlen = isr->isr_ssid_len;
++ }
++
++ // copy network data
++ strncpy(ssid, id, idlen);
++ ssid[idlen] = '\0';
++ ap = new nsWifiAccessPoint();
++ ap->setSSID(ssid, strlen(ssid));
++ ap->setMac(isr->isr_bssid);
++ ap->setSignal(isr->isr_rssi);
++ accessPoints.AppendObject(ap);
++ res = true;
++
++ // log the data
++ LOG(( "FreeBSD access point: "
++ << "SSID: " << ssid << ", "
++ << "MAC: " << isr->isr_bssid << ", "
++ << "Strength: " << isr->isr_rssi ", "
++ << "Channel: " << isr->isr_freq << "MHz" ));
++
++ // increment pointers
++ len -= isr->isr_len;
++ vsr += isr->isr_len;
++ }
++ }
+
-+ freeifaddrs(ifal);
++ freeifaddrs(ifal);
+
-+ return res ? NS_OK : NS_ERROR_FAILURE;
++ return res ? NS_OK : NS_ERROR_FAILURE;
+}
+
+nsresult
+nsWifiMonitor::DoScan()
+{
-+ // Regularly get the access point data.
++ // Regularly get the access point data.
+
-+ nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
-+ nsCOMArray<nsWifiAccessPoint> accessPoints;
++ nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
++ nsCOMArray<nsWifiAccessPoint> accessPoints;
+
-+ do {
-+ nsresult rv = FreeBSDGetAccessPointData(accessPoints);
-+ if (NS_FAILED(rv))
-+ return rv;
++ do {
++ nsresult rv = FreeBSDGetAccessPointData(accessPoints);
++ if (NS_FAILED(rv))
++ return rv;
+
-+ bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
-+ ReplaceArray(lastAccessPoints, accessPoints);
++ bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
++ ReplaceArray(lastAccessPoints, accessPoints);
+
-+ rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
-+ NS_ENSURE_SUCCESS(rv, rv);
++ rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
++ NS_ENSURE_SUCCESS(rv, rv);
+
-+ // wait for some reasonable amount of time. pref?
-+ LOG(("waiting on monitor\n"));
++ // wait for some reasonable amount of time. pref?
++ LOG(("waiting on monitor\n"));
+
-+ ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-+ mon.Wait(PR_SecondsToInterval(60));
-+ }
-+ while (mKeepGoing);
++ ReentrantMonitorAutoEnter mon(mReentrantMonitor);
++ mon.Wait(PR_SecondsToInterval(60));
++ }
++ while (mKeepGoing);
+
-+ return NS_OK;
++ return NS_OK;
+}
Modified: trunk/www/firefox/files/patch-bug893397
==============================================================================
--- trunk/www/firefox/files/patch-bug893397 Tue Jul 30 09:32:51 2013 (r1294)
+++ trunk/www/firefox/files/patch-bug893397 Tue Jul 30 09:32:58 2013 (r1295)
@@ -31,191 +31,175 @@
index 0000000..80d4cb6
--- /dev/null
+++ netwerk/wifi/nsWifiScannerFreeBSD.cpp
-@@ -0,0 +1,187 @@
+@@ -0,0 +1,171 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
-+// Developed by J.R. Oldroyd <fbsd at opal.com> and offered to the FreeBSD
-+// www/chromium and www/firefox ports under the terms of each browser's
-+// license.
++// Developed by J.R. Oldroyd <fbsd at opal.com>, December 2012.
+
+// For FreeBSD we use the getifaddrs(3) to obtain the list of interfaces
+// and then check for those with an 802.11 media type and able to return
-+// a list of stations. This is similar to ifconfig(8).
++// a list of stations. This is similar to ifconfig(8).
+
-+#include "nsCOMPtr.h"
-+#include "nsComponentManagerUtils.h"
-+#include "nsServiceManagerUtils.h"
-+#include "nsThreadUtils.h"
-+#include "nsXPCOM.h"
-+#include "nsXPCOMCID.h"
-+#include "nsIObserver.h"
-+#include "nsIObserverService.h"
-+#include "nsWifiMonitor.h"
-+#include "nsWifiAccessPoint.h"
-+
-+#include "nsServiceManagerUtils.h"
-+#include "nsComponentManagerUtils.h"
-+#include "mozilla/Services.h"
-+
-+using namespace mozilla;
-+
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <string.h>
-+#include <unistd.h>
+#include <sys/types.h>
++#include <sys/ioctl.h>
+#include <sys/socket.h>
-+#include <sys/sockio.h>
+#include <net/if.h>
+#include <net/if_media.h>
-+#include <ifaddrs.h>
+#include <net80211/ieee80211_ioctl.h>
-+#include <net/ethernet.h>
+
-+// Convert a wifi frequency to the corresponding channel.
-+// Taken from wifi_data_provider_linux.cc where it says this was
-+// adapted from geolocaiton/wifilib.cc in googleclient (internal to google).
-+int frequency_to_channel(int frequency_Mhz) {
-+ if (frequency_Mhz >= 2412 && frequency_Mhz <= 2472) // Channels 1-13.
-+ return (frequency_Mhz - 2407) / 5;
-+ if (frequency_Mhz == 2484)
-+ return 14;
-+ if (frequency_Mhz > 5000 && frequency_Mhz < 6000) // .11a bands.
-+ return (frequency_Mhz - 5000) / 5;
-+ // Ignore everything else.
-+ return -1; // invalid channel
-+}
++#include <ifaddrs.h>
++#include <string.h>
++#include <unistd.h>
+
-+nsresult
-+FreeBSDGetAccessPointData(nsCOMArray<nsWifiAccessPoint> &accessPoints) {
-+ bool res;
-+ char *dupn;
-+ struct ifaddrs *ifal, *ifa;
-+ struct ifreq ifr;
-+ struct ifmediareq ifmr;
-+ struct ieee80211req i802r;
-+ int s;
-+ char iscanbuf[32*1024], *vsr;
-+ unsigned len;
-+ nsWifiAccessPoint *ap;
-+
-+ if (getifaddrs(&ifal) < 0)
-+ return NS_ERROR_FAILURE;
-+
-+ accessPoints.Clear();
-+
-+ res = false;
-+ dupn = NULL;
-+ for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
-+ memset(&ifr, 0, sizeof(ifr));
-+
-+ if (dupn != NULL && strcmp(dupn, ifa->ifa_name) == 0)
-+ continue;
-+ dupn = ifa->ifa_name;
-+
-+ strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
-+ ifr.ifr_addr.sa_family = AF_LOCAL;
-+
-+ if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
-+ continue;
-+
-+ (void) memset(&ifmr, 0, sizeof(ifmr));
-+ (void) strncpy(ifmr.ifm_name, ifa->ifa_name, sizeof(ifmr.ifm_name));
-+
-+ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
-+ close(s);
-+ continue;
-+ }
-+ if (IFM_TYPE(ifmr.ifm_active) != IFM_IEEE80211) {
-+ close(s);
-+ continue;
-+ }
-+
-+ (void) memset(&i802r, 0, sizeof(i802r));
-+ (void) strncpy(i802r.i_name, ifa->ifa_name, sizeof(i802r.i_name));
-+ i802r.i_type = IEEE80211_IOC_SCAN_RESULTS;
-+ i802r.i_data = iscanbuf;
-+ i802r.i_len = sizeof(iscanbuf);
-+ if (ioctl(s, SIOCG80211, &i802r) < 0) {
-+ close(s);
-+ continue;
-+ }
-+
-+ close(s);
-+
-+ vsr = (char *) i802r.i_data;
-+ len = i802r.i_len;
-+ while (len >= sizeof(struct ieee80211req_scan_result)) {
-+ struct ieee80211req_scan_result *isr;
-+ char *id;
-+ int idlen;
-+ char ssid[IEEE80211_NWID_LEN+1];
-+
-+ isr = (struct ieee80211req_scan_result *) vsr;
-+
-+ if (isr->isr_meshid_len) {
-+ id = vsr + isr->isr_ie_off + isr->isr_ssid_len;
-+ idlen = isr->isr_meshid_len;
-+ }
-+ else {
-+ id = vsr + isr->isr_ie_off;
-+ idlen = isr->isr_ssid_len;
-+ }
-+ strncpy(ssid, id, idlen);
-+ ssid[idlen] = '\0';
-+ ap = new nsWifiAccessPoint();
-+ ap->setSSID(ssid, strlen(ssid));
-+ ap->setMac(isr->isr_bssid);
-+ ap->setSignal(isr->isr_rssi);
-+ // apd.radio_signal_strength = (isr->isr_rssi/2) + isr->isr_noise;
-+ // apd.signal_to_noise = apd.radio_signal_strength - isr->isr_noise;
-+ // apd.channel = frequency_to_channel(isr->isr_freq);
-+ LOG(( "FreeBSD access point: "
-+ << "SSID: " << apd.ssid << ", "
-+ << "MAC: " << apd.mac_address << ", "
-+ << "Strength: " << apd.radio_signal_strength << ":"
-+ << apd.signal_to_noise << ", "
-+ << "Channel: " << apd.channel ));
-+ accessPoints.AppendObject(ap);
-+ res = true;
-+ len -= isr->isr_len;
-+ vsr += isr->isr_len;
-+ }
-+ }
++#include "nsWifiAccessPoint.h"
++
++using namespace mozilla;
++
++static nsresult
++FreeBSDGetAccessPointData(nsCOMArray<nsWifiAccessPoint> &accessPoints)
++{
++ bool res = false;
++ char *dupn = NULL;
++ struct ifaddrs *ifal, *ifa;
++ unsigned len;
++
++ // get list of interfaces
++ if (getifaddrs(&ifal) < 0)
++ return NS_ERROR_FAILURE;
++
++ accessPoints.Clear();
++
++ // loop through the interfaces
++ for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
++ int s;
++ struct ifreq ifr;
++ struct ifmediareq ifmr;
++ struct ieee80211req i802r;
++ char iscanbuf[32*1024], *vsr;
++
++ memset(&ifr, 0, sizeof(ifr));
++
++ // list can contain duplicates, so ignore those
++ if (dupn != NULL && strcmp(dupn, ifa->ifa_name) == 0)
++ continue;
++ dupn = ifa->ifa_name;
++
++ // store interface name in socket structure
++ strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
++ ifr.ifr_addr.sa_family = AF_LOCAL;
++
++ // open socket to interface
++ if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
++ continue;
++
++ // clear interface media structure
++ (void) memset(&ifmr, 0, sizeof(ifmr));
++ (void) strncpy(ifmr.ifm_name, ifa->ifa_name, sizeof(ifmr.ifm_name));
++
++ // get interface media information
++ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
++ close(s);
++ continue;
++ }
++
++ // check interface is a WiFi interface
++ if (IFM_TYPE(ifmr.ifm_active) != IFM_IEEE80211) {
++ close(s);
++ continue;
++ }
++
++ // perform WiFi scan
++ (void) memset(&i802r, 0, sizeof(i802r));
++ (void) strncpy(i802r.i_name, ifa->ifa_name, sizeof(i802r.i_name));
++ i802r.i_type = IEEE80211_IOC_SCAN_RESULTS;
++ i802r.i_data = iscanbuf;
++ i802r.i_len = sizeof(iscanbuf);
++ if (ioctl(s, SIOCG80211, &i802r) < 0) {
++ close(s);
++ continue;
++ }
++
++ // close socket
++ close(s);
++
++ // loop through WiFi networks and build geoloc-lookup structure
++ vsr = (char *) i802r.i_data;
++ len = i802r.i_len;
++ while (len >= sizeof(struct ieee80211req_scan_result)) {
++ struct ieee80211req_scan_result *isr;
++ char *id;
++ int idlen;
++ char ssid[IEEE80211_NWID_LEN+1];
++ nsWifiAccessPoint *ap;
++
++ isr = (struct ieee80211req_scan_result *) vsr;
++
++ // determine size of this entry
++ if (isr->isr_meshid_len) {
++ id = vsr + isr->isr_ie_off + isr->isr_ssid_len;
++ idlen = isr->isr_meshid_len;
++ }
++ else {
++ id = vsr + isr->isr_ie_off;
++ idlen = isr->isr_ssid_len;
++ }
++
++ // copy network data
++ strncpy(ssid, id, idlen);
++ ssid[idlen] = '\0';
++ ap = new nsWifiAccessPoint();
++ ap->setSSID(ssid, strlen(ssid));
++ ap->setMac(isr->isr_bssid);
++ ap->setSignal(isr->isr_rssi);
++ accessPoints.AppendObject(ap);
++ res = true;
++
++ // log the data
++ LOG(( "FreeBSD access point: "
++ << "SSID: " << ssid << ", "
++ << "MAC: " << isr->isr_bssid << ", "
++ << "Strength: " << isr->isr_rssi ", "
++ << "Channel: " << isr->isr_freq << "MHz" ));
++
++ // increment pointers
++ len -= isr->isr_len;
++ vsr += isr->isr_len;
++ }
++ }
+
-+ freeifaddrs(ifal);
++ freeifaddrs(ifal);
+
-+ return res ? NS_OK : NS_ERROR_FAILURE;
++ return res ? NS_OK : NS_ERROR_FAILURE;
+}
+
+nsresult
+nsWifiMonitor::DoScan()
+{
-+ // Regularly get the access point data.
++ // Regularly get the access point data.
+
-+ nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
-+ nsCOMArray<nsWifiAccessPoint> accessPoints;
++ nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
++ nsCOMArray<nsWifiAccessPoint> accessPoints;
+
-+ do {
-+ nsresult rv = FreeBSDGetAccessPointData(accessPoints);
-+ if (NS_FAILED(rv))
-+ return rv;
++ do {
++ nsresult rv = FreeBSDGetAccessPointData(accessPoints);
++ if (NS_FAILED(rv))
++ return rv;
+
-+ bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
-+ ReplaceArray(lastAccessPoints, accessPoints);
++ bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
++ ReplaceArray(lastAccessPoints, accessPoints);
+
-+ rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
-+ NS_ENSURE_SUCCESS(rv, rv);
++ rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
++ NS_ENSURE_SUCCESS(rv, rv);
+
-+ // wait for some reasonable amount of time. pref?
-+ LOG(("waiting on monitor\n"));
++ // wait for some reasonable amount of time. pref?
++ LOG(("waiting on monitor\n"));
+
-+ ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-+ mon.Wait(PR_SecondsToInterval(60));
-+ }
-+ while (mKeepGoing);
++ ReentrantMonitorAutoEnter mon(mReentrantMonitor);
++ mon.Wait(PR_SecondsToInterval(60));
++ }
++ while (mKeepGoing);
+
-+ return NS_OK;
++ return NS_OK;
+}
Modified: trunk/www/seamonkey/files/patch-bug893397
==============================================================================
--- trunk/www/seamonkey/files/patch-bug893397 Tue Jul 30 09:32:51 2013 (r1294)
+++ trunk/www/seamonkey/files/patch-bug893397 Tue Jul 30 09:32:58 2013 (r1295)
@@ -44,191 +44,175 @@
index 0000000..80d4cb6
--- /dev/null
+++ mozilla/netwerk/wifi/nsWifiScannerFreeBSD.cpp
-@@ -0,0 +1,187 @@
+@@ -0,0 +1,171 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
-+// Developed by J.R. Oldroyd <fbsd at opal.com> and offered to the FreeBSD
-+// www/chromium and www/firefox ports under the terms of each browser's
-+// license.
++// Developed by J.R. Oldroyd <fbsd at opal.com>, December 2012.
+
+// For FreeBSD we use the getifaddrs(3) to obtain the list of interfaces
+// and then check for those with an 802.11 media type and able to return
-+// a list of stations. This is similar to ifconfig(8).
++// a list of stations. This is similar to ifconfig(8).
+
-+#include "nsCOMPtr.h"
-+#include "nsComponentManagerUtils.h"
-+#include "nsServiceManagerUtils.h"
-+#include "nsThreadUtils.h"
-+#include "nsXPCOM.h"
-+#include "nsXPCOMCID.h"
-+#include "nsIObserver.h"
-+#include "nsIObserverService.h"
-+#include "nsWifiMonitor.h"
-+#include "nsWifiAccessPoint.h"
-+
-+#include "nsServiceManagerUtils.h"
-+#include "nsComponentManagerUtils.h"
-+#include "mozilla/Services.h"
-+
-+using namespace mozilla;
-+
-+#include <stdio.h>
-+#include <stdlib.h>
-+#include <string.h>
-+#include <unistd.h>
+#include <sys/types.h>
++#include <sys/ioctl.h>
+#include <sys/socket.h>
-+#include <sys/sockio.h>
+#include <net/if.h>
+#include <net/if_media.h>
-+#include <ifaddrs.h>
+#include <net80211/ieee80211_ioctl.h>
-+#include <net/ethernet.h>
+
-+// Convert a wifi frequency to the corresponding channel.
-+// Taken from wifi_data_provider_linux.cc where it says this was
-+// adapted from geolocaiton/wifilib.cc in googleclient (internal to google).
-+int frequency_to_channel(int frequency_Mhz) {
-+ if (frequency_Mhz >= 2412 && frequency_Mhz <= 2472) // Channels 1-13.
-+ return (frequency_Mhz - 2407) / 5;
-+ if (frequency_Mhz == 2484)
-+ return 14;
-+ if (frequency_Mhz > 5000 && frequency_Mhz < 6000) // .11a bands.
-+ return (frequency_Mhz - 5000) / 5;
-+ // Ignore everything else.
-+ return -1; // invalid channel
-+}
++#include <ifaddrs.h>
++#include <string.h>
++#include <unistd.h>
+
-+nsresult
-+FreeBSDGetAccessPointData(nsCOMArray<nsWifiAccessPoint> &accessPoints) {
-+ bool res;
-+ char *dupn;
-+ struct ifaddrs *ifal, *ifa;
-+ struct ifreq ifr;
-+ struct ifmediareq ifmr;
-+ struct ieee80211req i802r;
-+ int s;
-+ char iscanbuf[32*1024], *vsr;
-+ unsigned len;
-+ nsWifiAccessPoint *ap;
-+
-+ if (getifaddrs(&ifal) < 0)
-+ return NS_ERROR_FAILURE;
-+
-+ accessPoints.Clear();
-+
-+ res = false;
-+ dupn = NULL;
-+ for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
-+ memset(&ifr, 0, sizeof(ifr));
-+
-+ if (dupn != NULL && strcmp(dupn, ifa->ifa_name) == 0)
-+ continue;
-+ dupn = ifa->ifa_name;
-+
-+ strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
-+ ifr.ifr_addr.sa_family = AF_LOCAL;
-+
-+ if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
-+ continue;
-+
-+ (void) memset(&ifmr, 0, sizeof(ifmr));
-+ (void) strncpy(ifmr.ifm_name, ifa->ifa_name, sizeof(ifmr.ifm_name));
-+
-+ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
-+ close(s);
-+ continue;
-+ }
-+ if (IFM_TYPE(ifmr.ifm_active) != IFM_IEEE80211) {
-+ close(s);
-+ continue;
-+ }
-+
-+ (void) memset(&i802r, 0, sizeof(i802r));
-+ (void) strncpy(i802r.i_name, ifa->ifa_name, sizeof(i802r.i_name));
-+ i802r.i_type = IEEE80211_IOC_SCAN_RESULTS;
-+ i802r.i_data = iscanbuf;
-+ i802r.i_len = sizeof(iscanbuf);
-+ if (ioctl(s, SIOCG80211, &i802r) < 0) {
-+ close(s);
-+ continue;
-+ }
-+
-+ close(s);
-+
-+ vsr = (char *) i802r.i_data;
-+ len = i802r.i_len;
-+ while (len >= sizeof(struct ieee80211req_scan_result)) {
-+ struct ieee80211req_scan_result *isr;
-+ char *id;
-+ int idlen;
-+ char ssid[IEEE80211_NWID_LEN+1];
-+
-+ isr = (struct ieee80211req_scan_result *) vsr;
-+
-+ if (isr->isr_meshid_len) {
-+ id = vsr + isr->isr_ie_off + isr->isr_ssid_len;
-+ idlen = isr->isr_meshid_len;
-+ }
-+ else {
-+ id = vsr + isr->isr_ie_off;
-+ idlen = isr->isr_ssid_len;
-+ }
-+ strncpy(ssid, id, idlen);
-+ ssid[idlen] = '\0';
-+ ap = new nsWifiAccessPoint();
-+ ap->setSSID(ssid, strlen(ssid));
-+ ap->setMac(isr->isr_bssid);
-+ ap->setSignal(isr->isr_rssi);
-+ // apd.radio_signal_strength = (isr->isr_rssi/2) + isr->isr_noise;
-+ // apd.signal_to_noise = apd.radio_signal_strength - isr->isr_noise;
-+ // apd.channel = frequency_to_channel(isr->isr_freq);
-+ LOG(( "FreeBSD access point: "
-+ << "SSID: " << apd.ssid << ", "
-+ << "MAC: " << apd.mac_address << ", "
-+ << "Strength: " << apd.radio_signal_strength << ":"
-+ << apd.signal_to_noise << ", "
-+ << "Channel: " << apd.channel ));
-+ accessPoints.AppendObject(ap);
-+ res = true;
-+ len -= isr->isr_len;
-+ vsr += isr->isr_len;
-+ }
-+ }
++#include "nsWifiAccessPoint.h"
++
++using namespace mozilla;
++
++static nsresult
++FreeBSDGetAccessPointData(nsCOMArray<nsWifiAccessPoint> &accessPoints)
++{
++ bool res = false;
++ char *dupn = NULL;
++ struct ifaddrs *ifal, *ifa;
++ unsigned len;
++
++ // get list of interfaces
++ if (getifaddrs(&ifal) < 0)
++ return NS_ERROR_FAILURE;
++
++ accessPoints.Clear();
++
++ // loop through the interfaces
++ for (ifa = ifal; ifa; ifa = ifa->ifa_next) {
++ int s;
++ struct ifreq ifr;
++ struct ifmediareq ifmr;
++ struct ieee80211req i802r;
++ char iscanbuf[32*1024], *vsr;
++
++ memset(&ifr, 0, sizeof(ifr));
++
++ // list can contain duplicates, so ignore those
++ if (dupn != NULL && strcmp(dupn, ifa->ifa_name) == 0)
++ continue;
++ dupn = ifa->ifa_name;
++
++ // store interface name in socket structure
++ strncpy(ifr.ifr_name, ifa->ifa_name, sizeof(ifr.ifr_name));
++ ifr.ifr_addr.sa_family = AF_LOCAL;
++
++ // open socket to interface
++ if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
++ continue;
++
++ // clear interface media structure
++ (void) memset(&ifmr, 0, sizeof(ifmr));
++ (void) strncpy(ifmr.ifm_name, ifa->ifa_name, sizeof(ifmr.ifm_name));
++
++ // get interface media information
++ if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
++ close(s);
++ continue;
++ }
++
++ // check interface is a WiFi interface
++ if (IFM_TYPE(ifmr.ifm_active) != IFM_IEEE80211) {
++ close(s);
++ continue;
++ }
++
++ // perform WiFi scan
++ (void) memset(&i802r, 0, sizeof(i802r));
++ (void) strncpy(i802r.i_name, ifa->ifa_name, sizeof(i802r.i_name));
++ i802r.i_type = IEEE80211_IOC_SCAN_RESULTS;
++ i802r.i_data = iscanbuf;
++ i802r.i_len = sizeof(iscanbuf);
++ if (ioctl(s, SIOCG80211, &i802r) < 0) {
++ close(s);
++ continue;
++ }
++
++ // close socket
++ close(s);
++
++ // loop through WiFi networks and build geoloc-lookup structure
++ vsr = (char *) i802r.i_data;
++ len = i802r.i_len;
++ while (len >= sizeof(struct ieee80211req_scan_result)) {
++ struct ieee80211req_scan_result *isr;
++ char *id;
++ int idlen;
++ char ssid[IEEE80211_NWID_LEN+1];
++ nsWifiAccessPoint *ap;
++
++ isr = (struct ieee80211req_scan_result *) vsr;
++
++ // determine size of this entry
++ if (isr->isr_meshid_len) {
++ id = vsr + isr->isr_ie_off + isr->isr_ssid_len;
++ idlen = isr->isr_meshid_len;
++ }
++ else {
++ id = vsr + isr->isr_ie_off;
++ idlen = isr->isr_ssid_len;
++ }
++
++ // copy network data
++ strncpy(ssid, id, idlen);
++ ssid[idlen] = '\0';
++ ap = new nsWifiAccessPoint();
++ ap->setSSID(ssid, strlen(ssid));
++ ap->setMac(isr->isr_bssid);
++ ap->setSignal(isr->isr_rssi);
++ accessPoints.AppendObject(ap);
++ res = true;
++
++ // log the data
++ LOG(( "FreeBSD access point: "
++ << "SSID: " << ssid << ", "
++ << "MAC: " << isr->isr_bssid << ", "
++ << "Strength: " << isr->isr_rssi ", "
++ << "Channel: " << isr->isr_freq << "MHz" ));
++
++ // increment pointers
++ len -= isr->isr_len;
++ vsr += isr->isr_len;
++ }
++ }
+
-+ freeifaddrs(ifal);
++ freeifaddrs(ifal);
+
-+ return res ? NS_OK : NS_ERROR_FAILURE;
++ return res ? NS_OK : NS_ERROR_FAILURE;
+}
+
+nsresult
+nsWifiMonitor::DoScan()
+{
-+ // Regularly get the access point data.
++ // Regularly get the access point data.
+
-+ nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
-+ nsCOMArray<nsWifiAccessPoint> accessPoints;
++ nsCOMArray<nsWifiAccessPoint> lastAccessPoints;
++ nsCOMArray<nsWifiAccessPoint> accessPoints;
+
-+ do {
-+ nsresult rv = FreeBSDGetAccessPointData(accessPoints);
-+ if (NS_FAILED(rv))
-+ return rv;
++ do {
++ nsresult rv = FreeBSDGetAccessPointData(accessPoints);
++ if (NS_FAILED(rv))
++ return rv;
+
-+ bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
-+ ReplaceArray(lastAccessPoints, accessPoints);
++ bool accessPointsChanged = !AccessPointsEqual(accessPoints, lastAccessPoints);
++ ReplaceArray(lastAccessPoints, accessPoints);
+
-+ rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
-+ NS_ENSURE_SUCCESS(rv, rv);
++ rv = CallWifiListeners(lastAccessPoints, accessPointsChanged);
++ NS_ENSURE_SUCCESS(rv, rv);
+
-+ // wait for some reasonable amount of time. pref?
-+ LOG(("waiting on monitor\n"));
++ // wait for some reasonable amount of time. pref?
++ LOG(("waiting on monitor\n"));
+
-+ ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-+ mon.Wait(PR_SecondsToInterval(60));
-+ }
-+ while (mKeepGoing);
++ ReentrantMonitorAutoEnter mon(mReentrantMonitor);
++ mon.Wait(PR_SecondsToInterval(60));
++ }
++ while (mKeepGoing);
+
-+ return NS_OK;
++ return NS_OK;
+}
More information about the freebsd-gecko
mailing list