Xenomai  3.0.8
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) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
131 
132 #ifdef CONFIG_RTWLAN_DEBUG
133 #define RTWLAN_DEBUG_PRINTK(__message...) do{ rtdm_printk(__message); }while(0)
134 #define RTWLAN_DEBUG(__message,__args...) RTWLAN_DEBUG_PRINTK(KERN_DEBUG "rtwlan->%s: Debug - " __message,__FUNCTION__,##__args);
135 #else
136 #define RTWLAN_DEBUG(__message...) do{ }while(0)
137 #endif
138 
139 struct rtwlan_stats {
140  unsigned long rx_packets; /* total packets received */
141  unsigned long tx_packets; /* total packets transmitted */
142  unsigned long tx_retry; /* total packets transmitted with retry */
143 };
144 
145 struct rtwlan_device {
146 
147  struct rtwlan_stats stats;
148 
149  struct rtskb_pool skb_pool;
150 
151  int mode;
152 
153  int (*hard_start_xmit)(struct rtskb *rtskb, struct rtnet_device * rtnet_dev);
154 
155  /* This must be the last item */
156  u8 priv[0];
157 };
158 
159 /* Minimal header; can be used for passing 802.11 frames with sufficient
160  * information to determine what type of underlying data type is actually
161  * stored in the data. */
162 struct ieee80211_hdr {
163  u16 frame_ctl;
164  u16 duration_id;
165  u8 payload[0];
166 } __attribute__ ((packed));
167 
168 struct ieee80211_hdr_3addr {
169  u16 frame_ctl;
170  u16 duration_id;
171  u8 addr1[ETH_ALEN];
172  u8 addr2[ETH_ALEN];
173  u8 addr3[ETH_ALEN];
174  u16 seq_ctl;
175  u8 payload[0];
176 } __attribute__ ((packed));
177 
178 
179 static inline int ieee80211_get_hdrlen(u16 fc)
180 {
181  int hdrlen = IEEE80211_3ADDR_LEN;
182  u16 stype = WLAN_FC_GET_STYPE(fc);
183 
184  switch (WLAN_FC_GET_TYPE(fc)) {
185  case IEEE80211_FTYPE_DATA:
186  if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
187  hdrlen = IEEE80211_4ADDR_LEN;
188  if (stype & IEEE80211_STYPE_QOS_DATA)
189  hdrlen += 2;
190  break;
191 
192  case IEEE80211_FTYPE_CTL:
193  switch (WLAN_FC_GET_STYPE(fc)) {
194  case IEEE80211_STYPE_CTS:
195  case IEEE80211_STYPE_ACK:
196  hdrlen = IEEE80211_1ADDR_LEN;
197  break;
198 
199  default:
200  hdrlen = IEEE80211_2ADDR_LEN;
201  break;
202  }
203  break;
204  }
205 
206  return hdrlen;
207 }
208 
209 
210 static inline int ieee80211_is_ofdm_rate(u8 rate)
211 {
212  switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
213  case IEEE80211_OFDM_RATE_6MB:
214  case IEEE80211_OFDM_RATE_9MB:
215  case IEEE80211_OFDM_RATE_12MB:
216  case IEEE80211_OFDM_RATE_18MB:
217  case IEEE80211_OFDM_RATE_24MB:
218  case IEEE80211_OFDM_RATE_36MB:
219  case IEEE80211_OFDM_RATE_48MB:
220  case IEEE80211_OFDM_RATE_54MB:
221  return 1;
222  }
223  return 0;
224 }
225 
226 static inline int ieee80211_is_dsss_rate(u8 rate)
227 {
228  switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
229  case IEEE80211_DSSS_RATE_1MB:
230  case IEEE80211_DSSS_RATE_2MB:
231  case IEEE80211_DSSS_RATE_5MB:
232  case IEEE80211_DSSS_RATE_11MB:
233  return 1;
234  }
235  return 0;
236 }
237 
238 
239 static inline void * rtwlan_priv(struct rtwlan_device *rtwlan_dev)
240 {
241  return (void *)rtwlan_dev + sizeof(struct rtwlan_device);
242 }
243 
244 struct rtnet_device * rtwlan_alloc_dev(unsigned sizeof_priv, unsigned dev_pool_size);
245 int rtwlan_rx(struct rtskb * rtskb, struct rtnet_device * rtnet_dev);
246 int rtwlan_tx(struct rtskb * rtskb, struct rtnet_device * rtnet_dev);
247 
248 #ifdef CONFIG_XENO_DRIVERS_NET_RTWLAN
249 int __init rtwlan_init(void);
250 void rtwlan_exit(void);
251 #else /* !CONFIG_XENO_DRIVERS_NET_RTWLAN */
252 #define rtwlan_init() 0
253 #define rtwlan_exit()
254 #endif /* CONFIG_XENO_DRIVERS_NET_RTWLAN */
255 
256 #endif