OSDN Git Service

Update to v30-pre9
[android-x86/external-wireless-tools.git] / wireless_tools / iwlib-private.h
1 /*
2  *      Wireless Tools
3  *
4  *              Jean II - HPLB 97->99 - HPL 99->09
5  *
6  * Private common header for the Wireless Extension library...
7  *
8  * This file is released under the GPL license.
9  *     Copyright (c) 1997-2009 Jean Tourrilhes <jt@hpl.hp.com>
10  */
11
12 #ifndef IWLIB_PRIVATE_H
13 #define IWLIB_PRIVATE_H
14
15 /*#include "CHANGELOG.h"*/
16
17 /***************************** INCLUDES *****************************/
18
19 #include "iwlib.h"              /* Public header */
20
21 /* Make gcc understand that when we say inline, we mean it.
22  * I really hate when the compiler is trying to be more clever than me,
23  * because in this case gcc is not able to figure out functions with a
24  * single call site, so not only I have to tag those functions inline
25  * by hand, but then it refuse to inline them properly.
26  * Total saving for iwevent : 150B = 0.7%.
27  * Fortunately, in gcc 3.4, they now automatically inline static functions
28  * with a single call site. Hurrah !
29  * Jean II */
30 #undef IW_GCC_HAS_BROKEN_INLINE
31 #if __GNUC__ == 3
32 #if __GNUC_MINOR__ >= 1 && __GNUC_MINOR__ < 4
33 #define IW_GCC_HAS_BROKEN_INLINE        1
34 #endif  /* __GNUC_MINOR__ */
35 #endif  /* __GNUC__ */
36 /* However, gcc 4.0 has introduce a new "feature", when compiling with
37  * '-Os', it does not want to inline iw_ether_cmp() and friends.
38  * So, we need to fix inline again !
39  * Jean II */
40 #if __GNUC__ == 4
41 #define IW_GCC_HAS_BROKEN_INLINE        1
42 #endif  /* __GNUC__ */
43 /* Now, really fix the inline */
44 #ifdef IW_GCC_HAS_BROKEN_INLINE
45 #ifdef inline
46 #undef inline
47 #endif  /* inline */
48 #define inline          inline          __attribute__((always_inline))
49 #endif  /* IW_GCC_HAS_BROKEN_INLINE */
50
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54
55 /****************************** DEBUG ******************************/
56
57 //#define DEBUG 1
58
59 /************************ CONSTANTS & MACROS ************************/
60
61 /* Paths */
62 #define PROC_NET_WIRELESS       "/proc/net/wireless"
63 #define PROC_NET_DEV            "/proc/net/dev"
64
65 /* Some usefull constants */
66 #define KILO    1e3
67 #define MEGA    1e6
68 #define GIGA    1e9
69 /* For doing log10/exp10 without libm */
70 #define LOG10_MAGIC     1.25892541179
71
72 /* Backward compatibility for network headers */
73 #ifndef ARPHRD_IEEE80211
74 #define ARPHRD_IEEE80211 801            /* IEEE 802.11                  */
75 #endif /* ARPHRD_IEEE80211 */
76
77 #ifndef IW_EV_LCP_PK_LEN
78 /* Size of the Event prefix when packed in stream */
79 #define IW_EV_LCP_PK_LEN        (4)
80 /* Size of the various events when packed in stream */
81 #define IW_EV_CHAR_PK_LEN       (IW_EV_LCP_PK_LEN + IFNAMSIZ)
82 #define IW_EV_UINT_PK_LEN       (IW_EV_LCP_PK_LEN + sizeof(__u32))
83 #define IW_EV_FREQ_PK_LEN       (IW_EV_LCP_PK_LEN + sizeof(struct iw_freq))
84 #define IW_EV_PARAM_PK_LEN      (IW_EV_LCP_PK_LEN + sizeof(struct iw_param))
85 #define IW_EV_ADDR_PK_LEN       (IW_EV_LCP_PK_LEN + sizeof(struct sockaddr))
86 #define IW_EV_QUAL_PK_LEN       (IW_EV_LCP_PK_LEN + sizeof(struct iw_quality))
87 #define IW_EV_POINT_PK_LEN      (IW_EV_LCP_PK_LEN + 4)
88 #endif  /* IW_EV_LCP_PK_LEN */
89
90 #ifndef IW_EV_LCP_PK2_LEN
91 struct iw_pk_event
92 {
93         __u16           len;                    /* Real lenght of this stuff */
94         __u16           cmd;                    /* Wireless IOCTL */
95         union iwreq_data        u;              /* IOCTL fixed payload */
96 } __attribute__ ((packed));
97 struct  iw_pk_point
98 {
99   void __user   *pointer;       /* Pointer to the data  (in user space) */
100   __u16         length;         /* number of fields or size in bytes */
101   __u16         flags;          /* Optional params */
102 } __attribute__ ((packed));
103
104 #define IW_EV_LCP_PK2_LEN       (sizeof(struct iw_pk_event) - sizeof(union iwreq_data))
105 #define IW_EV_POINT_PK2_LEN     (IW_EV_LCP_PK2_LEN + sizeof(struct iw_pk_point) - IW_EV_POINT_OFF)
106 #endif  /* IW_EV_LCP_PK2_LEN */
107
108 /************************* INLINE FUNTIONS *************************/
109 /*
110  * Functions that are so simple that it's more efficient inlining them
111  * Most inline are private because gcc is fussy about inline...
112  */
113
114 /*------------------------------------------------------------------*/
115 /*
116  * Display an Ethernet Socket Address in readable format.
117  */
118 static inline char *
119 iw_saether_ntop(const struct sockaddr *sap, char* bufp)
120 {
121   iw_ether_ntop((const struct ether_addr *) sap->sa_data, bufp);
122   return bufp;
123 }
124 /*------------------------------------------------------------------*/
125 /*
126  * Input an Ethernet Socket Address and convert to binary.
127  */
128 static inline int
129 iw_saether_aton(const char *bufp, struct sockaddr *sap)
130 {
131   sap->sa_family = ARPHRD_ETHER;
132   return iw_ether_aton(bufp, (struct ether_addr *) sap->sa_data);
133 }
134
135 /*------------------------------------------------------------------*/
136 /*
137  * Create an Ethernet broadcast address
138  */
139 static inline void
140 iw_broad_ether(struct sockaddr *sap)
141 {
142   sap->sa_family = ARPHRD_ETHER;
143   memset((char *) sap->sa_data, 0xFF, ETH_ALEN);
144 }
145
146 /*------------------------------------------------------------------*/
147 /*
148  * Create an Ethernet NULL address
149  */
150 static inline void
151 iw_null_ether(struct sockaddr *sap)
152 {
153   sap->sa_family = ARPHRD_ETHER;
154   memset((char *) sap->sa_data, 0x00, ETH_ALEN);
155 }
156
157 /*------------------------------------------------------------------*/
158 /*
159  * Compare two ethernet addresses
160  */
161 static inline int
162 iw_ether_cmp(const struct ether_addr* eth1, const struct ether_addr* eth2)
163 {
164   return memcmp(eth1, eth2, sizeof(*eth1));
165 }
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #endif  /* IWLIB_PRIVATE_H */