From: "Luis R. Rodriguez" <lrodriguez@atheros.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Luis Rodriguez <Luis.Rodriguez@Atheros.com>,
"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: Re: [PATCH] iw: add get regulatory domain support
Date: Wed, 28 Jan 2009 08:55:42 -0800 [thread overview]
Message-ID: <20090128165542.GA26656@tesla> (raw)
In-Reply-To: <1233137930.3936.5.camel@johannes.local>
On Wed, Jan 28, 2009 at 02:18:50AM -0800, Johannes Berg wrote:
> On Tue, 2009-01-27 at 18:55 -0800, Luis R. Rodriguez wrote:
>
> > +#define FLAG_BUF_LEN 200
> > +#define PARSE_FLAG(nl_flag, string_value, len) do { \
> > + if ((flags & nl_flag)) { \
> > + if (idx + len + 2 > FLAG_BUF_LEN) { \
> > + fprintf(stderr, "flags_buf size limit (%d) reached\n", FLAG_BUF_LEN); \
> > + return NL_STOP; \
> > + } \
> > + sprintf(flags_buf + idx, ", "); \
> > + sprintf(flags_buf + idx + 2, string_value); \
> > + idx += len + 2; \
> > + } \
> > + } while (0)
> > + struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
> > + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
> > + char *alpha2;
> > + struct nlattr *nl_rule;
> > + int rem_rule;
> > + static struct nla_policy reg_rule_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
> > + [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
> > + [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
> > + [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
> > + [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
> > + [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
> > + [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
> > + };
> > +
> > + nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
> > + genlmsg_attrlen(gnlh, 0), NULL);
> > +
> > + if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
> > + printf("No alpha2\n");
> > + return NL_SKIP;
> > + }
> > +
> > + if (!tb_msg[NL80211_ATTR_REG_RULES]) {
> > + printf("No reg rules\n");
> > + return NL_SKIP;
> > + }
> > +
> > + alpha2 = nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]);
> > + printf("country %s:\n", alpha2);
> > +
> > + nla_for_each_nested(nl_rule, tb_msg[NL80211_ATTR_REG_RULES], rem_rule) {
> > + struct nlattr *tb_rule[NL80211_FREQUENCY_ATTR_MAX + 1];
> > + __u32 flags, start_freq_khz, end_freq_khz, max_bw_khz, max_ant_gain_mbi, max_eirp_mbm;
> > + int idx = 0;
> > + char antenna_gain_buf[20];
> > + char flags_buf[200];
> > +
> > + nla_parse(tb_rule, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_rule), nla_len(nl_rule), reg_rule_policy);
> > +
> > + flags = nla_get_u32(tb_rule[NL80211_ATTR_REG_RULE_FLAGS]);
> > + start_freq_khz = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_START]);
> > + end_freq_khz = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_END]);
> > + max_bw_khz = nla_get_u32(tb_rule[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
> > + max_ant_gain_mbi = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
> > + max_eirp_mbm = nla_get_u32(tb_rule[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
> > +
> > + if (MBI_TO_DBI(max_ant_gain_mbi))
> > + sprintf(antenna_gain_buf, "%d", MBI_TO_DBI(max_ant_gain_mbi));
> > + else
> > + sprintf(antenna_gain_buf, "N/A");
> > +
> > + /* Sync this output format to match that of dbparse.py from wireless-regdb.git */
> > + PARSE_FLAG(NL80211_RRF_NO_OFDM, "NO-OFDM", 7);
> > + PARSE_FLAG(NL80211_RRF_NO_CCK, "NO-CCK", 6);
> > + PARSE_FLAG(NL80211_RRF_NO_INDOOR, "NO-INDOOR", 9);
> > + PARSE_FLAG(NL80211_RRF_NO_OUTDOOR, "NO-OUTDOOR", 10);
> > + PARSE_FLAG(NL80211_RRF_DFS, "DFS", 3);
> > + PARSE_FLAG(NL80211_RRF_PTP_ONLY, "PTP-ONLY", 8);
> > + PARSE_FLAG(NL80211_RRF_PASSIVE_SCAN, "PASSIVE-SCAN", 12);
> > + PARSE_FLAG(NL80211_RRF_NO_IBSS, "NO-IBSS", 7);
> > +
> > + printf("\t(%d - %d @ %d), (%s, %d)%s\n",
> > + KHZ_TO_MHZ(start_freq_khz), KHZ_TO_MHZ(end_freq_khz), KHZ_TO_MHZ(max_bw_khz),
> > + antenna_gain_buf, MBM_TO_DBM(max_eirp_mbm), (!idx) ? "" : flags_buf);
>
> All this looks really complicated, why do you need to sprintf everything
> first into a buffer, can't you just print it out in the correct order?
Heh yeah, will resend, thanks.
Luis
prev parent reply other threads:[~2009-01-28 16:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-28 2:55 [PATCH] iw: add get regulatory domain support Luis R. Rodriguez
2009-01-28 10:18 ` Johannes Berg
2009-01-28 16:55 ` Luis R. Rodriguez [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090128165542.GA26656@tesla \
--to=lrodriguez@atheros.com \
--cc=Luis.Rodriguez@Atheros.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).