From: Michael Wu <flamingice@sourmilk.net>
To: andy@warmcat.com
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH Try#9 3/4] cfg80211: Radiotap parser
Date: Tue, 12 Jun 2007 01:09:19 -0700 [thread overview]
Message-ID: <200706120109.23291.flamingice@sourmilk.net> (raw)
In-Reply-To: <20070611152210.586082766@warmcat.com>
[-- Attachment #1: Type: text/plain, Size: 5653 bytes --]
On Monday 11 June 2007 08:21, andy@warmcat.com wrote:
> +struct ieee80211_radiotap_iterator {
> + struct ieee80211_radiotap_header *rtheader;
> + int max_length;
> + int this_arg_index;
> + u8 * this_arg;
^
Eliminate the space here between * and this_arg.
> +
> + int arg_index;
> + u8 * arg;
And here. ^
> + __le32 *next_bitmap;
> + u32 bitmap_shifter;
> +};
> +
> +extern int ieee80211_radiotap_iterator_init(
> + struct ieee80211_radiotap_iterator * iterator,
Here. ^
> + struct ieee80211_radiotap_header * radiotap_header,
You get the idea. ^
> Index: wireless-dev/net/wireless/radiotap.c
> ===================================================================
> --- /dev/null
> +++ wireless-dev/net/wireless/radiotap.c
> @@ -0,0 +1,256 @@
> +/*
> + * Radiotap parser
> + *
> + * Copyright 2007 Andy Green <andy@warmcat.com>
> + */
> +
> +#include <linux/if.h>
Don't think anything from here is used.
> +#include <linux/err.h>
> +#include <linux/mutex.h>
We don't touch any mutexes in this file..
> +#include <linux/device.h>
Nor do we care about devices.
> +#include <net/genetlink.h>
Or netlink.
> +#include <net/cfg80211.h>
> +#include <net/wireless.h>
Or wiphys.
> +#include "nl80211.h"
> +#include "core.h"
nl80211.h and core.h seem unnecessary too.
All these includes might be pulling some other header that you do need,
however. (linux/kernel.h probably covers it..)
> +int ieee80211_radiotap_iterator_init(
> + struct ieee80211_radiotap_iterator * iterator,
> + struct ieee80211_radiotap_header * radiotap_header,
> + int max_length)
> +{
> + /* Linux only supports version 0 radiotap format */
> +
I think the code would look better without a blank line following the comment.
> + if (radiotap_header->it_version)
> + return -EINVAL;
> +
> + /* sanity check for allowed length and radiotap length field */
> +
> + if (max_length < (le16_to_cpu(radiotap_header->it_len)))
Unnecessary parenthesis. ^ ^
> + return -EINVAL;
> +
> + iterator->rtheader = radiotap_header;
> + iterator->max_length = le16_to_cpu(radiotap_header->it_len);
> + iterator->arg_index = 0;
> + iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present);
> + iterator->arg = ((u8 *)radiotap_header) +
Ditto. ^ ^
> + sizeof(struct ieee80211_radiotap_header);
I usually like to use sizeof on a variable (eg., sizeof(*radiotap_header))
since it's shorter and doesn't need to be changed if the variable type
changes.
> + iterator->this_arg = 0;
> +
> + /* find payload start allowing for extended bitmap(s) */
> +
> + if (unlikely(iterator->bitmap_shifter &
> + IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) {
+--------^
Indenting this a bit more to the right should look better.
> + while (le32_to_cpu(*((u32 *)iterator->arg)) &
> + IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) {
+--------------^
Ditto.
> + iterator->arg += sizeof(u32);
> +
> + /*
> + * check for insanity where the present bitmaps
> + * keep claiming to extend up to or even beyond the
> + * stated radiotap header length
> + */
> +
> + if ((((int)iterator->arg) - ((int)iterator->rtheader)) >
> + iterator->max_length)
For pointer arithmetic, you should use unsigned long. The parenthesis are a
little too paranoid here too.
> + if ((((int)iterator->arg)-((int)iterator->rtheader)) &
unsigned long for pointer arithmetic and reduce parenthesis, as before. Seems
to be a lot of this, so I won't mention it again.
> + ((rt_sizes[iterator->arg_index] >> 4) - 1))
> + iterator->arg_index +=
> + (rt_sizes[iterator->arg_index] >> 4) -
> + ((((int)iterator->arg) -
> + ((int)iterator->rtheader)) &
> + ((rt_sizes[iterator->arg_index] >> 4) - 1));
> +
> + /*
> + * this is what we will return to user, but we need to
> + * move on first so next call has something fresh to test
> + */
> +
> + iterator->this_arg_index = iterator->arg_index;
> + iterator->this_arg = iterator->arg;
> + hit = 1;
> +
> + /* internally move on the size of this arg */
> +
> + iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
> +
> + /*
> + * check for insanity where we are given a bitmap that
> + * claims to have more arg content than the length of the
> + * radiotap section. We will normally end up equalling this
> + * max_length on the last arg, never exceeding it.
> + */
> +
> + if ((((int)iterator->arg) - ((int)iterator->rtheader)) >
> + iterator->max_length)
> + return -EINVAL;
> +
> + next_entry:
> +
A blank line after a label doesn't look right to me..
> + iterator->arg_index++;
> + if (unlikely((iterator->arg_index & 31) == 0)) {
> + /* completed current u32 bitmap */
> + if (iterator->bitmap_shifter & 1) {
> + /* b31 was set, there is more */
> + /* move to next u32 bitmap */
> + iterator->bitmap_shifter = le32_to_cpu(
> + *iterator->next_bitmap);
Move "le32_to_cpu(" down to the next line.
> + iterator->next_bitmap++;
> + } else {
> + /* no more bitmaps: end */
> + iterator->arg_index = sizeof(rt_sizes);
> + }
> + } else { /* just try the next bit */
> + iterator->bitmap_shifter >>= 1;
> + }
> +
> + /* if we found a valid arg earlier, return it now */
> +
> + if (hit)
> + return iterator->this_arg_index;
> +
Another unnecessary blank line. ;)
Thanks,
-Michael Wu
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
next prev parent reply other threads:[~2007-06-12 8:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-11 15:21 [PATCH Try#9 0/4] Radiotap injection for Monitor Mode andy
2007-06-11 15:21 ` [PATCH Try#9 1/4] mac80211: Monitor mode radiotap injection docs andy
2007-06-11 15:21 ` [PATCH Try#9 2/4] mac80211: Define present bitmap extend bit mask andy
2007-06-11 15:21 ` [PATCH Try#9 3/4] cfg80211: Radiotap parser andy
2007-06-12 8:09 ` Michael Wu [this message]
2007-06-11 15:21 ` [PATCH Try#9 4/4] mac80211: Monitor mode radiotap-based packet injection andy
2007-06-12 8:23 ` Michael Wu
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=200706120109.23291.flamingice@sourmilk.net \
--to=flamingice@sourmilk.net \
--cc=andy@warmcat.com \
--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).