From patchwork Wed Nov 11 10:36:34 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Holger Schurig X-Patchwork-Id: 59307 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nABAbQrw028846 for ; Wed, 11 Nov 2009 10:37:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754614AbZKKKhU (ORCPT ); Wed, 11 Nov 2009 05:37:20 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752574AbZKKKhT (ORCPT ); Wed, 11 Nov 2009 05:37:19 -0500 Received: from mx51.mymxserver.com ([85.199.173.110]:44972 "EHLO mx51.mymxserver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751914AbZKKKhS (ORCPT ); Wed, 11 Nov 2009 05:37:18 -0500 Received: from localhost (localhost [127.0.0.1]) by localhost.mx51.mymxserver.com (Postfix) with ESMTP id 56B533A009; Wed, 11 Nov 2009 11:37:23 +0100 (CET) X-Virus-Scanned: by Mittwald Mailscanner Received: from mx51.mymxserver.com ([127.0.0.1]) by localhost (mx51.mymxserver.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id klo84zQ0Ro8D; Wed, 11 Nov 2009 11:37:23 +0100 (CET) Received: from lin01.mn-solutions.de (pD95F8421.dip0.t-ipconnect.de [217.95.132.33]) by mx51.mymxserver.com (Postfix) with ESMTP id 89D233A003; Wed, 11 Nov 2009 11:37:22 +0100 (CET) Received: by lin01.mn-solutions.de (Postfix, from userid 116) id 2D3B21E0050; Wed, 11 Nov 2009 11:37:22 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.1.7-deb3 (2006-10-05) on lin01.mn-logistik.de X-Spam-Level: X-Spam-Status: No, score=-4.4 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.1.7-deb3 Received: from schurig.mn-solutions.de (mnz66.mn-solutions.de [192.168.233.66]) by lin01.mn-solutions.de (Postfix) with ESMTP id 9E7171E0010; Wed, 11 Nov 2009 11:37:12 +0100 (CET) From: Holger Schurig To: linux-wireless@vger.kernel.org, Johannes Berg Subject: [PATCH] iw: display noise level from survey data Date: Wed, 11 Nov 2009 11:36:34 +0100 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200911111136.34949.holgerschurig@gmail.com> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org --- iw.orig/Makefile +++ iw/Makefile @@ -15,7 +15,7 @@ CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration OBJS = iw.o genl.o event.o info.o phy.o \ - interface.o ibss.o station.o util.o \ + interface.o ibss.o station.o survey.o util.o \ mesh.o mpath.o scan.o reg.o version.o \ reason.o status.o connect.o link.o OBJS += sections.o --- /dev/null +++ iw/survey.c @@ -0,0 +1,66 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "nl80211.h" +#include "iw.h" + +SECTION(survey); + +static int print_survey_handler(struct nl_msg *msg, void *arg) +{ + struct nlattr *tb[NL80211_ATTR_MAX + 1]; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; + char dev[20]; + + static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { + [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, + [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, + }; + + nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL); + + if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); + printf("Survey data from %s\n", dev); + + if (!tb[NL80211_ATTR_SURVEY_INFO]) { + fprintf(stderr, "survey data missing!"); + return NL_SKIP; + } + + if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, + tb[NL80211_ATTR_SURVEY_INFO], + survey_policy)) { + fprintf(stderr, "failed to parse nested attributes!\n"); + return NL_SKIP; + } + + if (sinfo[NL80211_SURVEY_INFO_FREQUENCY]) + printf("\tfrequency:\t%u MHz\n", + nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY])); + if (sinfo[NL80211_SURVEY_INFO_NOISE]) + printf("\tnoise:\t\t%d dBm\n", + (int8_t)nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE])); + return NL_SKIP; +} + +static int handle_survey_dump(struct nl80211_state *state, + struct nl_cb *cb, + struct nl_msg *msg, + int argc, char **argv) +{ + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_survey_handler, NULL); + return 0; +} +COMMAND(survey, dump, NULL, + NL80211_CMD_GET_SURVEY, NLM_F_DUMP, CIB_NETDEV, handle_survey_dump, + "List all gathered channel survey data"); + --- iw.orig/nl80211.h +++ iw/nl80211.h @@ -160,6 +160,11 @@ * @NL80211_CMD_SCAN_ABORTED: scan was aborted, for unspecified reasons, * partial scan results may be available * + * @NL80211_CMD_GET_SURVEY: get survey resuls, e.g. channel occupation + * or noise level + * @NL80211_CMD_NEW_SURVEY_RESULTS: survey data notification (as a reply to + * NL80211_CMD_GET_SURVEY and on the "scan" multicast group) + * * @NL80211_CMD_REG_CHANGE: indicates to userspace the regulatory domain * has been changed and provides details of the request information * that caused the change such as who initiated the regulatory request @@ -341,6 +346,9 @@ NL80211_CMD_SET_WIPHY_NETNS, + NL80211_CMD_GET_SURVEY, + NL80211_CMD_NEW_SURVEY_RESULTS, + /* add new commands above here */ /* used to define NL80211_CMD_MAX below */ @@ -584,6 +592,10 @@ * changed then the list changed and the dump should be repeated * completely from scratch. * + * @NL80211_ATTR_SURVEY_INFO: survey information about a channel, part of + * the survey response for %NL80211_CMD_GET_SURVEY, nested attribute + * containing info as possible, see &enum survey_info. + * * @NL80211_ATTR_MAX: highest attribute number currently defined * @__NL80211_ATTR_AFTER_LAST: internal use */ @@ -714,6 +726,8 @@ NL80211_ATTR_PID, + NL80211_ATTR_SURVEY_INFO, + /* add attributes here, update the policy in nl80211.c */ __NL80211_ATTR_AFTER_LAST, @@ -1117,6 +1131,26 @@ }; /** + * enum nl80211_survey_info - survey information + * + * These attribute types are used with %NL80211_ATTR_SURVEY_INFO + * when getting information about a survey. + * + * @__NL80211_SURVEY_INFO_INVALID: attribute number 0 is reserved + * @NL80211_SURVEY_INFO_FREQUENCY: center frequency of channel + * @NL80211_SURVEY_INFO_NOISE: noise level of channel (u8, dBm) + */ +enum nl80211_survey_info { + __NL80211_SURVEY_INFO_INVALID, + NL80211_SURVEY_INFO_FREQUENCY, + NL80211_SURVEY_INFO_NOISE, + + /* keep last */ + __NL80211_SURVEY_INFO_AFTER_LAST, + NL80211_SURVEY_INFO_MAX = __NL80211_SURVEY_INFO_AFTER_LAST - 1 +}; + +/** * enum nl80211_mntr_flags - monitor configuration flags * * Monitor configuration flags.