3 * Types and macros to aid in portability
5 * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
6 * --------------------------------------------------------------------
10 * The contents of this file are subject to the Mozilla Public
11 * License Version 1.1 (the "License"); you may not use this file
12 * except in compliance with the License. You may obtain a copy of
13 * the License at http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS
16 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
17 * implied. See the License for the specific language governing
18 * rights and limitations under the License.
20 * Alternatively, the contents of this file may be used under the
21 * terms of the GNU Public License version 2 (the "GPL"), in which
22 * case the provisions of the GPL are applicable instead of the
23 * above. If you wish to allow the use of your version of this file
24 * only under the terms of the GPL and not to allow others to use
25 * your version of this file under the MPL, indicate your decision
26 * by deleting the provisions above and replace them with the notice
27 * and other provisions required by the GPL. If you do not delete
28 * the provisions above, a recipient may use your version of this
29 * file under either the MPL or the GPL.
31 * --------------------------------------------------------------------
33 * Inquiries regarding the linux-wlan Open Source project can be
36 * AbsoluteValue Systems Inc.
38 * http://www.linux-wlan.com
40 * --------------------------------------------------------------------
42 * Portions of the development of this software were funded by
43 * Intersil Corporation as part of PRISM(R) chipset product development.
45 * --------------------------------------------------------------------
48 #ifndef _WLAN_COMPAT_H
49 #define _WLAN_COMPAT_H
51 #if defined(__KERNEL__)
53 #ifndef AUTOCONF_INCLUDED
54 #include <linux/config.h>
59 /*=============================================================*/
60 /*------ Bit settings -----------------------------------------*/
61 /*=============================================================*/
63 #define BIT0 0x00000001
64 #define BIT1 0x00000002
65 #define BIT2 0x00000004
66 #define BIT3 0x00000008
67 #define BIT4 0x00000010
68 #define BIT5 0x00000020
69 #define BIT6 0x00000040
70 #define BIT7 0x00000080
71 #define BIT8 0x00000100
72 #define BIT9 0x00000200
73 #define BIT10 0x00000400
74 #define BIT11 0x00000800
75 #define BIT12 0x00001000
76 #define BIT13 0x00002000
77 #define BIT14 0x00004000
78 #define BIT15 0x00008000
79 #define BIT16 0x00010000
80 #define BIT17 0x00020000
81 #define BIT18 0x00040000
82 #define BIT19 0x00080000
83 #define BIT20 0x00100000
84 #define BIT21 0x00200000
85 #define BIT22 0x00400000
86 #define BIT23 0x00800000
87 #define BIT24 0x01000000
88 #define BIT25 0x02000000
89 #define BIT26 0x04000000
90 #define BIT27 0x08000000
91 #define BIT28 0x10000000
92 #define BIT29 0x20000000
93 #define BIT30 0x40000000
94 #define BIT31 0x80000000
96 #include <linux/types.h>
98 typedef u_int8_t UINT8;
99 typedef u_int16_t UINT16;
100 typedef u_int32_t UINT32;
103 typedef int16_t INT16;
104 typedef int32_t INT32;
106 typedef unsigned int UINT;
107 typedef signed int INT;
109 typedef u_int64_t UINT64;
110 typedef int64_t INT64;
112 #define UINT8_MAX (0xffUL)
113 #define UINT16_MAX (0xffffUL)
114 #define UINT32_MAX (0xffffffffUL)
116 #define INT8_MAX (0x7fL)
117 #define INT16_MAX (0x7fffL)
118 #define INT32_MAX (0x7fffffffL)
120 /*=============================================================*/
121 /*------ Compiler Portability Macros --------------------------*/
122 /*=============================================================*/
123 #define __WLAN_ATTRIB_PACK__ __attribute__ ((packed))
125 /*=============================================================*/
126 /*------ OS Portability Macros --------------------------------*/
127 /*=============================================================*/
130 #define WLAN_DBVAR wlan_debug
133 #ifndef KERNEL_VERSION
134 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
137 #include <linux/hardirq.h>
139 #define WLAN_LOG_ERROR(x,args...) printk(KERN_ERR "%s: " x , __func__ , ##args);
141 #define WLAN_LOG_WARNING(x,args...) printk(KERN_WARNING "%s: " x , __func__ , ##args);
143 #define WLAN_LOG_NOTICE(x,args...) printk(KERN_NOTICE "%s: " x , __func__ , ##args);
145 #define WLAN_LOG_INFO(args... ) printk(KERN_INFO args)
147 #if defined(WLAN_INCLUDE_DEBUG)
148 #define WLAN_ASSERT(c) if ((!(c)) && WLAN_DBVAR >= 1) { \
149 WLAN_LOG_DEBUG(1, "Assertion failure!\n"); }
150 #define WLAN_HEX_DUMP( l, x, p, n) if( WLAN_DBVAR >= (l) ){ \
152 printk(KERN_DEBUG x ":"); \
153 for( __i__=0; __i__ < (n); __i__++) \
154 printk( " %02x", ((UINT8*)(p))[__i__]); \
156 #define DBFENTER { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"---->\n"); } }
157 #define DBFEXIT { if ( WLAN_DBVAR >= 5 ){ WLAN_LOG_DEBUG(3,"<----\n"); } }
159 #define WLAN_LOG_DEBUG(l,x,args...) if ( WLAN_DBVAR >= (l)) printk(KERN_DEBUG "%s(%lu): " x , __func__, (preempt_count() & PREEMPT_MASK), ##args );
161 #define WLAN_ASSERT(c)
162 #define WLAN_HEX_DUMP( l, s, p, n)
166 #define WLAN_LOG_DEBUG(l, s, args...)
173 #if defined(__KERNEL__)
175 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19))
176 #define URB_ONLY_CALLBACK
179 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
180 #define PT_REGS , struct pt_regs *regs
185 #define CONFIG_NETLINK 1
187 #ifndef wait_event_interruptible_timeout
188 // retval == 0; signal met; we're good.
189 // retval < 0; interrupted by signal.
190 // retval > 0; timed out.
192 #define __wait_event_interruptible_timeout(wq, condition, ret) \
194 wait_queue_t __wait; \
195 init_waitqueue_entry(&__wait, current); \
197 add_wait_queue(&wq, &__wait); \
199 set_current_state(TASK_INTERRUPTIBLE); \
202 if (!signal_pending(current)) { \
203 ret = schedule_timeout(ret) ; \
208 ret = -ERESTARTSYS; \
211 set_current_state(TASK_RUNNING); \
212 remove_wait_queue(&wq, &__wait); \
215 #define wait_event_interruptible_timeout(wq, condition, timeout) \
217 long __ret = timeout; \
219 __wait_event_interruptible_timeout(wq, condition, __ret); \
225 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
226 #define INIT_WORK2(_wq, _routine) INIT_WORK(_wq, (void (*)(void *))_routine, _wq)
228 #define INIT_WORK2(_wq, _routine) INIT_WORK(_wq, _routine)
232 typedef struct net_device netdevice_t;
234 /* TODO: Do we care about this? */
235 #ifndef MODULE_DEVICE_TABLE
236 #define MODULE_DEVICE_TABLE(foo,bar)
239 #define wlan_minutes2ticks(a) ((a)*(wlan_ticks_per_sec * 60))
240 #define wlan_seconds2ticks(a) ((a)*(wlan_ticks_per_sec))
243 #define in_atomic() 0
246 #define URB_ASYNC_UNLINK 0
247 #define USB_QUEUE_BULK 0
250 #define might_sleep(a) do { } while (0)
253 /* Apparently 2.4.2 ethtool is quite different, maybe newer too? */
254 #if (defined(SIOETHTOOL) && !defined(ETHTOOL_GDRVINFO))
258 #endif /* __KERNEL__ */
260 /*=============================================================*/
261 /*------ Hardware Portability Macros --------------------------*/
262 /*=============================================================*/
264 #define ieee2host16(n) __le16_to_cpu(n)
265 #define ieee2host32(n) __le32_to_cpu(n)
266 #define host2ieee16(n) __cpu_to_le16(n)
267 #define host2ieee32(n) __cpu_to_le32(n)
269 /*=============================================================*/
270 /*--- General Macros ------------------------------------------*/
271 /*=============================================================*/
273 #define wlan_max(a, b) (((a) > (b)) ? (a) : (b))
274 #define wlan_min(a, b) (((a) < (b)) ? (a) : (b))
276 #define wlan_isprint(c) (((c) > (0x19)) && ((c) < (0x7f)))
278 #define wlan_hexchar(x) (((x) < 0x0a) ? ('0' + (x)) : ('a' + ((x) - 0x0a)))
280 /* Create a string of printable chars from something that might not be */
281 /* It's recommended that the str be 4*len + 1 bytes long */
282 #define wlan_mkprintstr(buf, buflen, str, strlen) \
286 memset(str, 0, (strlen)); \
287 for (i = 0; i < (buflen); i++) { \
288 if ( wlan_isprint((buf)[i]) ) { \
289 (str)[j] = (buf)[i]; \
294 (str)[j+2] = wlan_hexchar(((buf)[i] & 0xf0) >> 4); \
295 (str)[j+3] = wlan_hexchar(((buf)[i] & 0x0f)); \
301 /*=============================================================*/
302 /*--- Variables -----------------------------------------------*/
303 /*=============================================================*/
305 #ifdef WLAN_INCLUDE_DEBUG
306 extern int wlan_debug;
309 extern int wlan_ethconv; /* What's the default ethconv? */
311 /*=============================================================*/
312 /*--- Functions -----------------------------------------------*/
313 /*=============================================================*/
314 #endif /* _WLAN_COMPAT_H */