netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Eremin-Solenikov <dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Alexander Smirnov
	<alex.bluesman.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
	linux-zigbee-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Subject: Re: [PATCH 4/6] [6LoWPAN] UDP header compression
Date: Tue, 8 Nov 2011 18:42:09 +0400	[thread overview]
Message-ID: <CALT56yNoaTxJodbw4eYnShz2-vtSOQqufAM9O0AtNHcFEkyp7w@mail.gmail.com> (raw)
In-Reply-To: <1320251711-2897-1-git-send-email-alex.bluesman.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

On 11/2/11, Alexander Smirnov <alex.bluesman.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> This patch adds support for UDP header compression.
> Derived from Contiki OS.

>From my point of view, this code would also benefit from being refactored
to a separate function.

>
> Signed-off-by: Alexander Smirnov <alex.bluesman.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  net/ieee802154/6lowpan.c |   51
> ++++++++++++++++++++++++++++++++++++++++++---
>  net/ieee802154/6lowpan.h |    5 ++++
>  2 files changed, 52 insertions(+), 4 deletions(-)
>
> diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
> index c4aae4e..6da3357 100644
> --- a/net/ieee802154/6lowpan.c
> +++ b/net/ieee802154/6lowpan.c
> @@ -365,8 +365,6 @@ static int lowpan_header_create(struct sk_buff *skb,
>  	if (hdr->nexthdr == UIP_PROTO_UDP)
>  		iphc0 |= LOWPAN_IPHC_NH_C;
>
> -/* TODO: next header compression */
> -
>  	if ((iphc0 & LOWPAN_IPHC_NH_C) == 0) {
>  		*hc06_ptr = hdr->nexthdr;
>  		hc06_ptr += 1;
> @@ -454,8 +452,53 @@ static int lowpan_header_create(struct sk_buff *skb,
>  		}
>  	}
>
> -	/* TODO: UDP header compression */
> -	/* TODO: Next Header compression */
> +	/* UDP header compression */
> +	if (hdr->nexthdr == UIP_PROTO_UDP) {
> +		struct udphdr *uh = udp_hdr(skb);
> +
> +		pr_debug("(%s): UDP header compression\n", __func__);
> +
> +		if (((uh->source & LOWPAN_NHC_UDP_4BIT_MASK) ==
> +					LOWPAN_NHC_UDP_4BIT_PORT) &&
> +		    ((uh->dest & LOWPAN_NHC_UDP_4BIT_MASK) ==
> +					LOWPAN_NHC_UDP_4BIT_PORT)) {
> +			pr_debug("(%s): both ports compression to 4 bits\n",
> +								__func__);
> +			*hc06_ptr = LOWPAN_NHC_UDP_CS_P_11;
> +			*(hc06_ptr + 1) = /* subtraction is faster */
> +			   (u8)((uh->dest - LOWPAN_NHC_UDP_4BIT_PORT) +
> +			       ((uh->source & LOWPAN_NHC_UDP_4BIT_PORT) << 4));
> +			hc06_ptr += 2;
> +		} else if ((uh->dest & LOWPAN_NHC_UDP_8BIT_MASK) ==
> +				LOWPAN_NHC_UDP_8BIT_PORT) {
> +			pr_debug("(%s): remove 8 bits of dest\n", __func__);
> +			*hc06_ptr = LOWPAN_NHC_UDP_CS_P_01;
> +			memcpy(hc06_ptr + 1, &uh->source, 2);
> +			*(hc06_ptr + 3) =
> +				(u8)(uh->dest - LOWPAN_NHC_UDP_8BIT_PORT);
> +			hc06_ptr += 4;
> +		} else if ((uh->source & LOWPAN_NHC_UDP_8BIT_MASK) ==
> +				LOWPAN_NHC_UDP_8BIT_PORT) {
> +			pr_debug("(%s): remove 8 bits of source\n", __func__);
> +			*hc06_ptr = LOWPAN_NHC_UDP_CS_P_10;
> +			memcpy(hc06_ptr + 1, &uh->dest, 2);
> +			*(hc06_ptr + 3) =
> +				(u8)(uh->source - LOWPAN_NHC_UDP_8BIT_PORT);
> +			hc06_ptr += 4;
> +		} else {
> +			pr_debug("(%s): can't compress header\n", __func__);
> +			*hc06_ptr = LOWPAN_NHC_UDP_CS_P_00;
> +			memcpy(hc06_ptr + 1, &uh->source, 2);
> +			memcpy(hc06_ptr + 3, &uh->dest, 2);
> +			hc06_ptr += 5;
> +		}
> +
> +		/* checksum is always inline */
> +		memcpy(hc06_ptr, &uh->check, 2);
> +		hc06_ptr += 2;
> +	}
> +
> +	/* TODO: other NH types support? */
>
>  	head[0] = iphc0;
>  	head[1] = iphc1;
> diff --git a/net/ieee802154/6lowpan.h b/net/ieee802154/6lowpan.h
> index 5d2e5a0..aeff3f3 100644
> --- a/net/ieee802154/6lowpan.h
> +++ b/net/ieee802154/6lowpan.h
> @@ -219,6 +219,11 @@
>  #define LOWPAN_NHC_UDP_CHECKSUMC	0x04
>  #define LOWPAN_NHC_UDP_CHECKSUMI	0x00
>
> +#define LOWPAN_NHC_UDP_4BIT_PORT	0xF0B0
> +#define LOWPAN_NHC_UDP_4BIT_MASK	0xFFF0
> +#define LOWPAN_NHC_UDP_8BIT_PORT	0xF000
> +#define LOWPAN_NHC_UDP_8BIT_MASK	0xFF00
> +
>  /* values for port compression, _with checksum_ ie bit 5 set to 0 */
>  #define LOWPAN_NHC_UDP_CS_P_00	0xF0 /* all inline */
>  #define LOWPAN_NHC_UDP_CS_P_01	0xF1 /* source 16bit inline,
> --
> 1.7.2.5
>
>


-- 
With best wishes
Dmitry

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1

  parent reply	other threads:[~2011-11-08 14:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-02 16:25 [PATCH series][6LoWPAN] Alexander Smirnov
2011-11-02 16:32 ` [PATCH 1/6] [6LoWPAN] add fragmentation support Alexander Smirnov
2011-11-02 16:34 ` [PATCH 3/6] [6LoWPAN] set proper netdev flags Alexander Smirnov
2011-11-08 14:42   ` Dmitry Eremin-Solenikov
     [not found] ` <20111102162520.GA2669-AUGNqIMGY+bGcXpsla5Oef8+0UxHXcjY@public.gmane.org>
2011-11-02 16:34   ` [PATCH 2/6] [6LoWPAN] disable debugging by default Alexander Smirnov
2011-11-08 14:43     ` Dmitry Eremin-Solenikov
2011-11-02 16:35   ` [PATCH 4/6] [6LoWPAN] UDP header compression Alexander Smirnov
     [not found]     ` <1320251711-2897-1-git-send-email-alex.bluesman.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-11-08 14:42       ` Dmitry Eremin-Solenikov [this message]
2011-11-02 16:35   ` [PATCH 5/6] [6LoWPAN] UDP header decompression Alexander Smirnov
2011-11-08 14:40     ` Dmitry Eremin-Solenikov
2011-11-02 16:35   ` [PATCH 6/6] [6LoWPAN] update documentation Alexander Smirnov
2011-11-08 14:32     ` Dmitry Eremin-Solenikov
     [not found]       ` <CALT56yOb5oZLEuHcM8dM8_gpT7mzV+9_YbsxWL3nU2N3ypCg3w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-11-08 14:42         ` Christophe Aeschlimann
2011-11-02 19:57   ` [PATCH series][6LoWPAN] David Miller
2011-11-04 19:19     ` Alexander Smirnov
2011-11-08 13:34       ` Benjamin Poirier

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=CALT56yNoaTxJodbw4eYnShz2-vtSOQqufAM9O0AtNHcFEkyp7w@mail.gmail.com \
    --to=dbaryshkov-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=alex.bluesman.smirnov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=linux-zigbee-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.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).