aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/zd1211rw/zd_mac.c
diff options
context:
space:
mode:
authorUlrich Kunitz <kune@deine-taler.de>2006-08-29 18:50:29 -0400
committerJohn W. Linville <linville@tuxdriver.com>2006-09-11 16:11:08 -0400
commitdb888aed7e83559d61cff04bf002d0fb80ecbfa7 (patch)
tree4c8795f5924ce440ddc79cf0e2d7ae25d633d5ad /drivers/net/wireless/zd1211rw/zd_mac.c
parent38f5745c5a90641079fd5b48600ae63f7ab6edcd (diff)
[PATCH] zd1211rw: Fix of signal strength and quality measurement
Caused by a documentation issue I mixed up fields of the zd_status structure. This patch fixes it and improves also the average computation, which is now using only measurements of packets sent by the access point. Signed-off-by: Ulrich Kunitz <kune@deine-taler.de> Signed-off-by: Daniel Drake <dsd@gentoo.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/zd1211rw/zd_mac.c')
-rw-r--r--drivers/net/wireless/zd1211rw/zd_mac.c43
1 files changed, 35 insertions, 8 deletions
diff --git a/drivers/net/wireless/zd1211rw/zd_mac.c b/drivers/net/wireless/zd1211rw/zd_mac.c
index d6f3e02a0b54..a9bd80a08613 100644
--- a/drivers/net/wireless/zd1211rw/zd_mac.c
+++ b/drivers/net/wireless/zd1211rw/zd_mac.c
@@ -816,13 +816,25 @@ static int filter_rx(struct ieee80211_device *ieee,
816 return -EINVAL; 816 return -EINVAL;
817} 817}
818 818
819static void update_qual_rssi(struct zd_mac *mac, u8 qual_percent, u8 rssi) 819static void update_qual_rssi(struct zd_mac *mac,
820 const u8 *buffer, unsigned int length,
821 u8 qual_percent, u8 rssi_percent)
820{ 822{
821 unsigned long flags; 823 unsigned long flags;
824 struct ieee80211_hdr_3addr *hdr;
825 int i;
826
827 hdr = (struct ieee80211_hdr_3addr *)buffer;
828 if (length < offsetof(struct ieee80211_hdr_3addr, addr3))
829 return;
830 if (memcmp(hdr->addr2, zd_mac_to_ieee80211(mac)->bssid, ETH_ALEN) != 0)
831 return;
822 832
823 spin_lock_irqsave(&mac->lock, flags); 833 spin_lock_irqsave(&mac->lock, flags);
824 mac->qual_average = (7 * mac->qual_average + qual_percent) / 8; 834 i = mac->stats_count % ZD_MAC_STATS_BUFFER_SIZE;
825 mac->rssi_average = (7 * mac->rssi_average + rssi) / 8; 835 mac->qual_buffer[i] = qual_percent;
836 mac->rssi_buffer[i] = rssi_percent;
837 mac->stats_count++;
826 spin_unlock_irqrestore(&mac->lock, flags); 838 spin_unlock_irqrestore(&mac->lock, flags);
827} 839}
828 840
@@ -853,7 +865,6 @@ static int fill_rx_stats(struct ieee80211_rx_stats *stats,
853 if (stats->rate) 865 if (stats->rate)
854 stats->mask |= IEEE80211_STATMASK_RATE; 866 stats->mask |= IEEE80211_STATMASK_RATE;
855 867
856 update_qual_rssi(mac, stats->signal, stats->rssi);
857 return 0; 868 return 0;
858} 869}
859 870
@@ -877,6 +888,8 @@ int zd_mac_rx(struct zd_mac *mac, const u8 *buffer, unsigned int length)
877 sizeof(struct rx_status); 888 sizeof(struct rx_status);
878 buffer += ZD_PLCP_HEADER_SIZE; 889 buffer += ZD_PLCP_HEADER_SIZE;
879 890
891 update_qual_rssi(mac, buffer, length, stats.signal, stats.rssi);
892
880 r = filter_rx(ieee, buffer, length, &stats); 893 r = filter_rx(ieee, buffer, length, &stats);
881 if (r <= 0) 894 if (r <= 0)
882 return r; 895 return r;
@@ -981,17 +994,31 @@ struct iw_statistics *zd_mac_get_wireless_stats(struct net_device *ndev)
981{ 994{
982 struct zd_mac *mac = zd_netdev_mac(ndev); 995 struct zd_mac *mac = zd_netdev_mac(ndev);
983 struct iw_statistics *iw_stats = &mac->iw_stats; 996 struct iw_statistics *iw_stats = &mac->iw_stats;
997 unsigned int i, count, qual_total, rssi_total;
984 998
985 memset(iw_stats, 0, sizeof(struct iw_statistics)); 999 memset(iw_stats, 0, sizeof(struct iw_statistics));
986 /* We are not setting the status, because ieee->state is not updated 1000 /* We are not setting the status, because ieee->state is not updated
987 * at all and this driver doesn't track authentication state. 1001 * at all and this driver doesn't track authentication state.
988 */ 1002 */
989 spin_lock_irq(&mac->lock); 1003 spin_lock_irq(&mac->lock);
990 iw_stats->qual.qual = mac->qual_average; 1004 count = mac->stats_count < ZD_MAC_STATS_BUFFER_SIZE ?
991 iw_stats->qual.level = mac->rssi_average; 1005 mac->stats_count : ZD_MAC_STATS_BUFFER_SIZE;
992 iw_stats->qual.updated = IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED| 1006 qual_total = rssi_total = 0;
993 IW_QUAL_NOISE_INVALID; 1007 for (i = 0; i < count; i++) {
1008 qual_total += mac->qual_buffer[i];
1009 rssi_total += mac->rssi_buffer[i];
1010 }
994 spin_unlock_irq(&mac->lock); 1011 spin_unlock_irq(&mac->lock);
1012 iw_stats->qual.updated = IW_QUAL_NOISE_INVALID;
1013 if (count > 0) {
1014 iw_stats->qual.qual = qual_total / count;
1015 iw_stats->qual.level = rssi_total / count;
1016 iw_stats->qual.updated |=
1017 IW_QUAL_QUAL_UPDATED|IW_QUAL_LEVEL_UPDATED;
1018 } else {
1019 iw_stats->qual.updated |=
1020 IW_QUAL_QUAL_INVALID|IW_QUAL_LEVEL_INVALID;
1021 }
995 /* TODO: update counter */ 1022 /* TODO: update counter */
996 return iw_stats; 1023 return iw_stats;
997} 1024}