Xenomai  3.1
rtwlan.h
1 /* rtwlan.h
2  *
3  * This file is a rtnet adaption from ieee80211/ieee80211.h used by the
4  * rt2x00-2.0.0-b3 sourceforge project
5  *
6  * Merged with mainline ieee80211.h in Aug 2004. Original ieee802_11
7  * remains copyright by the original authors
8  *
9  * Portions of the merged code are based on Host AP (software wireless
10  * LAN access point) driver for Intersil Prism2/2.5/3.
11  *
12  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
13  * <jkmaline@cc.hut.fi>
14  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
15  *
16  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
17  * <jketreno@linux.intel.com>
18  * Copyright (c) 2004-2005, Intel Corporation
19  *
20  * Adaption to rtnet
21  * Copyright (c) 2006, Daniel Gregorek <dxg@gmx.de>
22  *
23  * This program is free software; you can redistribute it and/or modify
24  * it under the terms of the GNU General Public License as published by
25  * the Free Software Foundation; either version 2 of the License, or
26  * (at your option) any later version.
27  *
28  * This program is distributed in the hope that it will be useful,
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31  * GNU General Public License for more details.
32  *
33  * You should have received a copy of the GNU General Public License
34  * along with this program; if not, write to the Free Software
35  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36  *
37  */
38 
39 #ifndef RTWLAN_H
40 #define RTWLAN_H
41 
42 #include <linux/if_ether.h> /* ETH_ALEN */
43 #include <linux/kernel.h> /* ARRAY_SIZE */
44 
45 #include <rtskb.h>
46 #include <rtwlan_io.h>
47 
48 #define IEEE80211_1ADDR_LEN 10
49 #define IEEE80211_2ADDR_LEN 16
50 #define IEEE80211_3ADDR_LEN 24
51 #define IEEE80211_4ADDR_LEN 30
52 #define IEEE80211_FCS_LEN 4
53 #define IEEE80211_HLEN (IEEE80211_4ADDR_LEN)
54 #define IEEE80211_FRAME_LEN (IEEE80211_DATA_LEN + IEEE80211_HLEN)
55 
56 #define MIN_FRAG_THRESHOLD 256U
57 #define MAX_FRAG_THRESHOLD 2346U
58 
59 /* Frame control field constants */
60 #define IEEE80211_FCTL_VERS 0x0003
61 #define IEEE80211_FCTL_FTYPE 0x000c
62 #define IEEE80211_FCTL_STYPE 0x00f0
63 #define IEEE80211_FCTL_TODS 0x0100
64 #define IEEE80211_FCTL_FROMDS 0x0200
65 #define IEEE80211_FCTL_MOREFRAGS 0x0400
66 #define IEEE80211_FCTL_RETRY 0x0800
67 #define IEEE80211_FCTL_PM 0x1000
68 #define IEEE80211_FCTL_MOREDATA 0x2000
69 #define IEEE80211_FCTL_PROTECTED 0x4000
70 #define IEEE80211_FCTL_ORDER 0x8000
71 
72 #define IEEE80211_FTYPE_MGMT 0x0000
73 #define IEEE80211_FTYPE_CTL 0x0004
74 #define IEEE80211_FTYPE_DATA 0x0008
75 
76 /* management */
77 #define IEEE80211_STYPE_ASSOC_REQ 0x0000
78 #define IEEE80211_STYPE_ASSOC_RESP 0x0010
79 #define IEEE80211_STYPE_REASSOC_REQ 0x0020
80 #define IEEE80211_STYPE_REASSOC_RESP 0x0030
81 #define IEEE80211_STYPE_PROBE_REQ 0x0040
82 #define IEEE80211_STYPE_PROBE_RESP 0x0050
83 #define IEEE80211_STYPE_BEACON 0x0080
84 #define IEEE80211_STYPE_ATIM 0x0090
85 #define IEEE80211_STYPE_DISASSOC 0x00A0
86 #define IEEE80211_STYPE_AUTH 0x00B0
87 #define IEEE80211_STYPE_DEAUTH 0x00C0
88 #define IEEE80211_STYPE_ACTION 0x00D0
89 
90 /* control */
91 #define IEEE80211_STYPE_PSPOLL 0x00A0
92 #define IEEE80211_STYPE_RTS 0x00B0
93 #define IEEE80211_STYPE_CTS 0x00C0
94 #define IEEE80211_STYPE_ACK 0x00D0
95 #define IEEE80211_STYPE_CFEND 0x00E0
96 #define IEEE80211_STYPE_CFENDACK 0x00F0
97 
98 /* data */
99 #define IEEE80211_STYPE_DATA 0x0000
100 #define IEEE80211_STYPE_DATA_CFACK 0x0010
101 #define IEEE80211_STYPE_DATA_CFPOLL 0x0020
102 #define IEEE80211_STYPE_DATA_CFACKPOLL 0x0030
103 #define IEEE80211_STYPE_NULLFUNC 0x0040
104 #define IEEE80211_STYPE_CFACK 0x0050
105 #define IEEE80211_STYPE_CFPOLL 0x0060
106 #define IEEE80211_STYPE_CFACKPOLL 0x0070
107 #define IEEE80211_STYPE_QOS_DATA 0x0080
108 
109 #define RTWLAN_SCTL_SEQ 0xFFF0
110 
111 #define WLAN_FC_GET_VERS(fc) ((fc)&IEEE80211_FCTL_VERS)
112 #define WLAN_FC_GET_TYPE(fc) ((fc)&IEEE80211_FCTL_FTYPE)
113 #define WLAN_FC_GET_STYPE(fc) ((fc)&IEEE80211_FCTL_STYPE)
114 
115 #define IEEE80211_DSSS_RATE_1MB 0x02
116 #define IEEE80211_DSSS_RATE_2MB 0x04
117 #define IEEE80211_DSSS_RATE_5MB 0x0B
118 #define IEEE80211_DSSS_RATE_11MB 0x16
119 #define IEEE80211_OFDM_RATE_6MB 0x0C
120 #define IEEE80211_OFDM_RATE_9MB 0x12
121 #define IEEE80211_OFDM_RATE_12MB 0x18
122 #define IEEE80211_OFDM_RATE_18MB 0x24
123 #define IEEE80211_OFDM_RATE_24MB 0x30
124 #define IEEE80211_OFDM_RATE_36MB 0x48
125 #define IEEE80211_OFDM_RATE_48MB 0x60
126 #define IEEE80211_OFDM_RATE_54MB 0x6C
127 #define IEEE80211_BASIC_RATE_MASK 0x80
128 
129 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
130 #define MAC_ARG(x) \
131  ((u8 *)(x))[0], ((u8 *)(x))[1], ((u8 *)(x))[2], ((u8 *)(x))[3], \
132  ((u8 *)(x))[4], ((u8 *)(x))[5]
133 
134 #ifdef CONFIG_RTWLAN_DEBUG
135 #define RTWLAN_DEBUG_PRINTK(__message...) \
136  do { \
137  rtdm_printk(__message); \
138  } while (0)
139 #define RTWLAN_DEBUG(__message, __args...) \
140  RTWLAN_DEBUG_PRINTK(KERN_DEBUG "rtwlan->%s: Debug - " __message, \
141  __FUNCTION__, ##__args);
142 #else
143 #define RTWLAN_DEBUG(__message...) \
144  do { \
145  } while (0)
146 #endif
147 
148 struct rtwlan_stats {
149  unsigned long rx_packets; /* total packets received */
150  unsigned long tx_packets; /* total packets transmitted */
151  unsigned long tx_retry; /* total packets transmitted with retry */
152 };
153 
154 struct rtwlan_device {
155  struct rtwlan_stats stats;
156 
157  struct rtskb_pool skb_pool;
158 
159  int mode;
160 
161  int (*hard_start_xmit)(struct rtskb *rtskb,
162  struct rtnet_device *rtnet_dev);
163 
164  /* This must be the last item */
165  u8 priv[0];
166 };
167 
168 /* Minimal header; can be used for passing 802.11 frames with sufficient
169  * information to determine what type of underlying data type is actually
170  * stored in the data. */
171 struct ieee80211_hdr {
172  u16 frame_ctl;
173  u16 duration_id;
174  u8 payload[0];
175 } __attribute__((packed));
176 
177 struct ieee80211_hdr_3addr {
178  u16 frame_ctl;
179  u16 duration_id;
180  u8 addr1[ETH_ALEN];
181  u8 addr2[ETH_ALEN];
182  u8 addr3[ETH_ALEN];
183  u16 seq_ctl;
184  u8 payload[0];
185 } __attribute__((packed));
186 
187 static inline int ieee80211_get_hdrlen(u16 fc)
188 {
189  int hdrlen = IEEE80211_3ADDR_LEN;
190  u16 stype = WLAN_FC_GET_STYPE(fc);
191 
192  switch (WLAN_FC_GET_TYPE(fc)) {
193  case IEEE80211_FTYPE_DATA:
194  if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
195  hdrlen = IEEE80211_4ADDR_LEN;
196  if (stype & IEEE80211_STYPE_QOS_DATA)
197  hdrlen += 2;
198  break;
199 
200  case IEEE80211_FTYPE_CTL:
201  switch (WLAN_FC_GET_STYPE(fc)) {
202  case IEEE80211_STYPE_CTS:
203  case IEEE80211_STYPE_ACK:
204  hdrlen = IEEE80211_1ADDR_LEN;
205  break;
206 
207  default:
208  hdrlen = IEEE80211_2ADDR_LEN;
209  break;
210  }
211  break;
212  }
213 
214  return hdrlen;
215 }
216 
217 static inline int ieee80211_is_ofdm_rate(u8 rate)
218 {
219  switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
220  case IEEE80211_OFDM_RATE_6MB:
221  case IEEE80211_OFDM_RATE_9MB:
222  case IEEE80211_OFDM_RATE_12MB:
223  case IEEE80211_OFDM_RATE_18MB:
224  case IEEE80211_OFDM_RATE_24MB:
225  case IEEE80211_OFDM_RATE_36MB:
226  case IEEE80211_OFDM_RATE_48MB:
227  case IEEE80211_OFDM_RATE_54MB:
228  return 1;
229  }
230  return 0;
231 }
232 
233 static inline int ieee80211_is_dsss_rate(u8 rate)
234 {
235  switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
236  case IEEE80211_DSSS_RATE_1MB:
237  case IEEE80211_DSSS_RATE_2MB:
238  case IEEE80211_DSSS_RATE_5MB:
239  case IEEE80211_DSSS_RATE_11MB:
240  return 1;
241  }
242  return 0;
243 }
244 
245 static inline void *rtwlan_priv(struct rtwlan_device *rtwlan_dev)
246 {
247  return (void *)rtwlan_dev + sizeof(struct rtwlan_device);
248 }
249 
250 struct rtnet_device *rtwlan_alloc_dev(unsigned sizeof_priv,
251  unsigned dev_pool_size);
252 int rtwlan_rx(struct rtskb *rtskb, struct rtnet_device *rtnet_dev);
253 int rtwlan_tx(struct rtskb *rtskb, struct rtnet_device *rtnet_dev);
254 
255 #ifdef CONFIG_XENO_DRIVERS_NET_RTWLAN
256 int __init rtwlan_init(void);
257 void rtwlan_exit(void);
258 #else /* !CONFIG_XENO_DRIVERS_NET_RTWLAN */
259 #define rtwlan_init() 0
260 #define rtwlan_exit()
261 #endif /* CONFIG_XENO_DRIVERS_NET_RTWLAN */
262 
263 #endif
static int __attribute__((cold))
Test if a mutex structure contains a valid autoinitializer.
Definition: mutex.c:177