diff options
author | Henning Rogge <hrogge@googlemail.com> | 2008-12-11 16:04:19 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-12-19 15:04:54 -0500 |
commit | 420e7fabd9c6d907280ed6b3e40eef425c5d8d8d (patch) | |
tree | 6effc9f9386746d1aeb953e32fe82b0a5a5fdf18 /net/wireless/nl80211.c | |
parent | 221b3d60cbb2740ec7d46a4f1ea6d3318a112e51 (diff) |
nl80211: Add signal strength and bandwith to nl80211station info
This patch adds signal strength and transmission bitrate
to the station_info of nl80211.
Signed-off-by: Henning Rogge <rogge@fgan.de>
Acked-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/wireless/nl80211.c')
-rw-r--r-- | net/wireless/nl80211.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 4335f76be71f..93c9b983ce08 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -1091,12 +1091,46 @@ static int parse_station_flags(struct nlattr *nla, u32 *staflags) | |||
1091 | return 0; | 1091 | return 0; |
1092 | } | 1092 | } |
1093 | 1093 | ||
1094 | static u16 nl80211_calculate_bitrate(struct rate_info *rate) | ||
1095 | { | ||
1096 | int modulation, streams, bitrate; | ||
1097 | |||
1098 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) | ||
1099 | return rate->legacy; | ||
1100 | |||
1101 | /* the formula below does only work for MCS values smaller than 32 */ | ||
1102 | if (rate->mcs >= 32) | ||
1103 | return 0; | ||
1104 | |||
1105 | modulation = rate->mcs & 7; | ||
1106 | streams = (rate->mcs >> 3) + 1; | ||
1107 | |||
1108 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? | ||
1109 | 13500000 : 6500000; | ||
1110 | |||
1111 | if (modulation < 4) | ||
1112 | bitrate *= (modulation + 1); | ||
1113 | else if (modulation == 4) | ||
1114 | bitrate *= (modulation + 2); | ||
1115 | else | ||
1116 | bitrate *= (modulation + 3); | ||
1117 | |||
1118 | bitrate *= streams; | ||
1119 | |||
1120 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | ||
1121 | bitrate = (bitrate / 9) * 10; | ||
1122 | |||
1123 | /* do NOT round down here */ | ||
1124 | return (bitrate + 50000) / 100000; | ||
1125 | } | ||
1126 | |||
1094 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | 1127 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
1095 | int flags, struct net_device *dev, | 1128 | int flags, struct net_device *dev, |
1096 | u8 *mac_addr, struct station_info *sinfo) | 1129 | u8 *mac_addr, struct station_info *sinfo) |
1097 | { | 1130 | { |
1098 | void *hdr; | 1131 | void *hdr; |
1099 | struct nlattr *sinfoattr; | 1132 | struct nlattr *sinfoattr, *txrate; |
1133 | u16 bitrate; | ||
1100 | 1134 | ||
1101 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | 1135 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
1102 | if (!hdr) | 1136 | if (!hdr) |
@@ -1126,7 +1160,29 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | |||
1126 | if (sinfo->filled & STATION_INFO_PLINK_STATE) | 1160 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
1127 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, | 1161 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
1128 | sinfo->plink_state); | 1162 | sinfo->plink_state); |
1163 | if (sinfo->filled & STATION_INFO_SIGNAL) | ||
1164 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, | ||
1165 | sinfo->signal); | ||
1166 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { | ||
1167 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); | ||
1168 | if (!txrate) | ||
1169 | goto nla_put_failure; | ||
1170 | |||
1171 | /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ | ||
1172 | bitrate = nl80211_calculate_bitrate(&sinfo->txrate); | ||
1173 | if (bitrate > 0) | ||
1174 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | ||
1129 | 1175 | ||
1176 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) | ||
1177 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, | ||
1178 | sinfo->txrate.mcs); | ||
1179 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) | ||
1180 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); | ||
1181 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) | ||
1182 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); | ||
1183 | |||
1184 | nla_nest_end(msg, txrate); | ||
1185 | } | ||
1130 | nla_nest_end(msg, sinfoattr); | 1186 | nla_nest_end(msg, sinfoattr); |
1131 | 1187 | ||
1132 | return genlmsg_end(msg, hdr); | 1188 | return genlmsg_end(msg, hdr); |