summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Glocker <mglocker@cvs.openbsd.org>2007-11-14 11:16:28 +0000
committerMarcus Glocker <mglocker@cvs.openbsd.org>2007-11-14 11:16:28 +0000
commitedea1b2e16c69313203de5e153740269790ac992 (patch)
tree7527c012b42fd654acc6ab289bb37ea765bc542b
parent38779f39b59f9a26453e645b156200da5972a779 (diff)
Add ieee80211_rate2plcp() and ieee80211_plcp2rate() functions, which
convert the PLCP header signal field to a rate value and vice versa. This implementation has been discussed with Damien and doesn't change any existing net80211 structures. ok damien@
-rw-r--r--share/man/man9/Makefile6
-rw-r--r--share/man/man9/ieee80211.928
-rw-r--r--sys/net80211/ieee80211.c73
-rw-r--r--sys/net80211/ieee80211_var.h4
4 files changed, 103 insertions, 8 deletions
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 04378adc5f4..6b952a8c0b2 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.135 2007/11/03 14:59:55 mglocker Exp $
+# $OpenBSD: Makefile,v 1.136 2007/11/14 11:16:27 mglocker Exp $
# $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $
# Makefile for section 9 (kernel function and variable) manual pages.
@@ -139,7 +139,9 @@ MLINKS+=ieee80211.9 ieee80211_ifattach.9 \
ieee80211.9 ieee80211_setmode.9 \
ieee80211.9 ieee80211_chan2mode.9 \
ieee80211.9 ieee80211_rate2media.9 \
- ieee80211.9 ieee80211_media2rate.9
+ ieee80211.9 ieee80211_media2rate.9 \
+ ieee80211.9 ieee80211_rate2plcp.9 \
+ ieee80211.9 ieee80211_plcp2rate.9
MLINKS+=ieee80211_crypto.9 ieee80211_crypto_attach.9 \
ieee80211_crypto.9 ieee80211_crypto_detach.9 \
ieee80211_crypto.9 ieee80211_wep_crypt.9
diff --git a/share/man/man9/ieee80211.9 b/share/man/man9/ieee80211.9
index ef1e83f8a44..53fb26fa480 100644
--- a/share/man/man9/ieee80211.9
+++ b/share/man/man9/ieee80211.9
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ieee80211.9,v 1.9 2007/11/03 14:59:55 mglocker Exp $
+.\" $OpenBSD: ieee80211.9,v 1.10 2007/11/14 11:16:27 mglocker Exp $
.\"
.\" Copyright (c) 2004 Bruce M. Simpson <bms@spc.org>
.\" Copyright (c) 2004 Darron Broad <darron@kewl.org>
@@ -26,9 +26,9 @@
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD: src/share/man/man9/ieee80211.9,v 1.3 2004/07/07 12:59:39 ru Exp $
-.\" $Id: ieee80211.9,v 1.9 2007/11/03 14:59:55 mglocker Exp $
+.\" $Id: ieee80211.9,v 1.10 2007/11/14 11:16:27 mglocker Exp $
.\"
-.Dd $Mdocdate: November 3 2007 $
+.Dd $Mdocdate: November 14 2007 $
.Dt IEEE80211 9
.Os
.Sh NAME
@@ -37,7 +37,8 @@
.Nm ieee80211_media_init , ieee80211_media_change , ieee80211_media_status ,
.Nm ieee80211_watchdog ,
.Nm ieee80211_setmode , ieee80211_chan2mode ,
-.Nm ieee80211_rate2media , ieee80211_media2rate
+.Nm ieee80211_rate2media , ieee80211_media2rate ,
+.Nm ieee80211_rate2plcp , ieee80211_plcp2rate
.Nd core 802.11 network stack functions
.Sh SYNOPSIS
.In net80211/ieee80211_var.h
@@ -76,6 +77,10 @@
.Fc
.Ft int
.Fn ieee80211_media2rate "int mword"
+.Ft int
+.Fn ieee80211_rate2plcp "int rate" "enum ieee80211_phymode mode"
+.Ft int
+.Fn ieee80211_plcp2rate "int plcp" "enum ieee80211_phymode mode"
.Sh DESCRIPTION
The
.Nm ieee80211
@@ -237,6 +242,21 @@ performs the reverse of this conversion, returning the bit rate (in 0.5Mbps
units) corresponding to an
.Vt ifmedia
sub-type.
+.Pp
+.\"
+The
+.Fn ieee80211_rate2plcp
+function converts the bit rate
+.Fa rate
+(measured in units of 0.5Mbps) to a
+.Vt plcp
+signal.
+The
+.Fn ieee80211_plcp2rate
+function performs the reverse of this conversion,
+returning the bit rate (in 0.5Mbps units) corresponding to a
+.Vt plcp
+signal.
.\"
.Sh SEE ALSO
.Xr ifmedia 4 ,
diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c
index 51bb6bebe92..3989fe59080 100644
--- a/sys/net80211/ieee80211.c
+++ b/sys/net80211/ieee80211.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ieee80211.c,v 1.27 2007/11/03 14:59:55 mglocker Exp $ */
+/* $OpenBSD: ieee80211.c,v 1.28 2007/11/14 11:16:27 mglocker Exp $ */
/* $NetBSD: ieee80211.c,v 1.19 2004/06/06 05:45:29 dyoung Exp $ */
/*-
@@ -922,3 +922,74 @@ ieee80211_media2rate(int mword)
return 0;
#undef N
}
+
+/*
+ * Convert bit rate (in 0.5Mbps units) to PLCP signal and vice versa.
+ */
+int
+ieee80211_rate2plcp(int rate, enum ieee80211_phymode mode)
+{
+ rate &= IEEE80211_RATE_VAL;
+
+ if (mode == IEEE80211_MODE_11B) {
+ /* IEEE Std 802.11b-1999 page 15, subclause 18.2.3.3 */
+ switch (rate) {
+ case 2: return 10;
+ case 4: return 20;
+ case 11: return 55;
+ case 22: return 110;
+ /* IEEE Std 802.11g-2003 page 19, subclause 19.3.2.1 */
+ case 44: return 220;
+ }
+ } else if (mode == IEEE80211_MODE_11G || mode == IEEE80211_MODE_11A) {
+ /* IEEE Std 802.11a-1999 page 14, subclause 17.3.4.1 */
+ switch (rate) {
+ case 12: return 0x0b;
+ case 18: return 0x0f;
+ case 24: return 0x0a;
+ case 36: return 0x0e;
+ case 48: return 0x09;
+ case 72: return 0x0d;
+ case 96: return 0x08;
+ case 108: return 0x0c;
+ }
+ } else
+ panic("Unexpected mode %u", mode);
+
+ IEEE80211_DPRINTF(("%s: unsupported rate %u\n", __func__, rate));
+
+ return 0;
+}
+
+int
+ieee80211_plcp2rate(int plcp, enum ieee80211_phymode mode)
+{
+ if (mode == IEEE80211_MODE_11B) {
+ /* IEEE Std 802.11g-2003 page 19, subclause 19.3.2.1 */
+ switch (plcp) {
+ case 10: return 2;
+ case 20: return 4;
+ case 55: return 11;
+ case 110: return 22;
+ /* IEEE Std 802.11g-2003 page 19, subclause 19.3.2.1 */
+ case 220: return 44;
+ }
+ } else if (mode == IEEE80211_MODE_11G || mode == IEEE80211_MODE_11A) {
+ /* IEEE Std 802.11a-1999 page 14, subclause 17.3.4.1 */
+ switch (plcp) {
+ case 0x0b: return 12;
+ case 0x0f: return 18;
+ case 0x0a: return 24;
+ case 0x0e: return 36;
+ case 0x09: return 48;
+ case 0x0d: return 72;
+ case 0x08: return 96;
+ case 0x0c: return 108;
+ }
+ } else
+ panic("Unexpected mode %u", mode);
+
+ IEEE80211_DPRINTF(("%s: unsupported plcp %u\n", __func__, plcp));
+
+ return 0;
+}
diff --git a/sys/net80211/ieee80211_var.h b/sys/net80211/ieee80211_var.h
index f086f7eb1ca..b85796beab4 100644
--- a/sys/net80211/ieee80211_var.h
+++ b/sys/net80211/ieee80211_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ieee80211_var.h,v 1.35 2007/11/03 14:59:55 mglocker Exp $ */
+/* $OpenBSD: ieee80211_var.h,v 1.36 2007/11/14 11:16:27 mglocker Exp $ */
/* $NetBSD: ieee80211_var.h,v 1.7 2004/05/06 03:07:10 dyoung Exp $ */
/*-
@@ -313,6 +313,8 @@ int ieee80211_fix_rate(struct ieee80211com *, struct ieee80211_node *, int);
int ieee80211_rate2media(struct ieee80211com *, int,
enum ieee80211_phymode);
int ieee80211_media2rate(int);
+int ieee80211_rate2plcp(int, enum ieee80211_phymode);
+int ieee80211_plcp2rate(int, enum ieee80211_phymode);
u_int ieee80211_mhz2ieee(u_int, u_int);
u_int ieee80211_chan2ieee(struct ieee80211com *,
const struct ieee80211_channel *);