[PATCH] softmac: correctly use netif_carrier_{on,off}
[safe/jmp/linux-2.6] / net / ieee80211 / softmac / ieee80211softmac_priv.h
1 #ifndef IEEE80211SOFTMAC_PRIV_H_
2 #define IEEE80211SOFTMAC_PRIV_H_
3
4 #include <net/ieee80211softmac.h>
5 #include <net/ieee80211softmac_wx.h>
6 #include <linux/kernel.h>
7 #include <linux/stringify.h>
8
9
10 #define PFX                             "SoftMAC: "
11
12 #ifdef assert
13 # undef assert
14 #endif
15 #ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
16 #define assert(expr) \
17         do {                                                                            \
18                 if (unlikely(!(expr))) {                                                \
19                 printkl(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", #expr,   \
20                         __FILE__, __LINE__, __FUNCTION__);                              \
21                 }                                                                       \
22         } while (0)
23 #else
24 #define assert(expr) do {} while (0)
25 #endif
26
27 /* rate limited printk(). */
28 #ifdef printkl
29 # undef printkl
30 #endif
31 #define printkl(f, x...)  do { if (printk_ratelimit()) printk(f ,##x); } while (0)
32 /* rate limited printk() for debugging */
33 #ifdef dprintkl
34 # undef dprintkl
35 #endif
36 #ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
37 # define dprintkl               printkl
38 #else
39 # define dprintkl(f, x...)      do { /* nothing */ } while (0)
40 #endif
41
42 /* debugging printk() */
43 #ifdef dprintk
44 # undef dprintk
45 #endif
46 #ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
47 # define dprintk(f, x...)  do { printk(f ,##x); } while (0)
48 #else
49 # define dprintk(f, x...)  do { /* nothing */ } while (0)
50 #endif
51
52 #ifdef function_enter
53 # undef function_enter
54 #endif
55 #ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
56 # define function_enter() do { printk(KERN_DEBUG PFX "%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__); } while (0)
57 #else
58 # define function_enter() do { /* nothing */ } while (0)
59 #endif
60
61 /* private definitions and prototypes */
62
63 /*** prototypes from _scan.c */
64 void ieee80211softmac_scan(void *sm);
65 /* for internal use if scanning is needed */
66 int ieee80211softmac_start_scan(struct ieee80211softmac_device *mac);
67 void ieee80211softmac_stop_scan(struct ieee80211softmac_device *mac);
68 void ieee80211softmac_wait_for_scan(struct ieee80211softmac_device *mac);
69
70 /* for use by _module.c to assign to the callbacks */
71 int ieee80211softmac_start_scan_implementation(struct net_device *dev);
72 void ieee80211softmac_stop_scan_implementation(struct net_device *dev);
73 void ieee80211softmac_wait_for_scan_implementation(struct net_device *dev);
74
75 /*** Network prototypes from _module.c */
76 struct ieee80211softmac_network * ieee80211softmac_create_network(
77         struct ieee80211softmac_device *mac, struct ieee80211_network *net);
78 void ieee80211softmac_add_network_locked(struct ieee80211softmac_device *mac,
79         struct ieee80211softmac_network *net);
80 void ieee80211softmac_add_network(struct ieee80211softmac_device *mac,
81         struct ieee80211softmac_network *net);
82 void ieee80211softmac_del_network_locked(struct ieee80211softmac_device *mac,
83         struct ieee80211softmac_network *net);
84 void ieee80211softmac_del_network(struct ieee80211softmac_device *mac,
85         struct ieee80211softmac_network *net);
86 struct ieee80211softmac_network * ieee80211softmac_get_network_by_bssid_locked(
87         struct ieee80211softmac_device *mac, u8 *ea);
88 struct ieee80211softmac_network * ieee80211softmac_get_network_by_bssid(
89         struct ieee80211softmac_device *mac, u8 *ea);
90 struct ieee80211softmac_network * ieee80211softmac_get_network_by_ssid_locked(
91         struct ieee80211softmac_device *mac, u8 *ssid, u8 ssid_len);
92 struct ieee80211softmac_network * ieee80211softmac_get_network_by_ssid(
93         struct ieee80211softmac_device *mac, u8 *ssid, u8 ssid_len);
94 struct ieee80211softmac_network *
95 ieee80211softmac_get_network_by_essid_locked(struct ieee80211softmac_device *mac,
96         struct ieee80211softmac_essid *essid);
97 struct ieee80211softmac_network *
98 ieee80211softmac_get_network_by_essid(struct ieee80211softmac_device *mac,
99         struct ieee80211softmac_essid *essid);
100
101 /* Rates related */
102 u8 ieee80211softmac_lower_rate_delta(struct ieee80211softmac_device *mac, u8 rate, int delta);
103 static inline u8 lower_rate(struct ieee80211softmac_device *mac, u8 rate) {
104         return ieee80211softmac_lower_rate_delta(mac, rate, 1);
105 }
106
107 static inline u8 get_fallback_rate(struct ieee80211softmac_device *mac, u8 rate)
108 {
109         return ieee80211softmac_lower_rate_delta(mac, rate, 2);
110 }
111                 
112
113 /*** prototypes from _io.c */
114 int ieee80211softmac_send_mgt_frame(struct ieee80211softmac_device *mac,
115         void* ptrarg, u32 type, u32 arg);
116
117 /*** prototypes from _auth.c */
118 /* do these have to go into the public header? */
119 int ieee80211softmac_auth_req(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net);
120 int ieee80211softmac_deauth_req(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net, int reason);
121
122 /* for use by _module.c to assign to the callbacks */
123 int ieee80211softmac_auth_resp(struct net_device *dev, struct ieee80211_auth *auth);
124 int ieee80211softmac_deauth_resp(struct net_device *dev, struct ieee80211_auth *auth);
125
126 /*** prototypes from _assoc.c */
127 void ieee80211softmac_assoc_work(void *d);
128 int ieee80211softmac_handle_assoc_response(struct net_device * dev,
129                                            struct ieee80211_assoc_response * resp,
130                                            struct ieee80211_network * network);
131 int ieee80211softmac_handle_disassoc(struct net_device * dev,
132                                      struct ieee80211_disassoc * disassoc);
133 void ieee80211softmac_assoc_timeout(void *d);
134
135 /* some helper functions */
136 static inline int ieee80211softmac_scan_handlers_check_self(struct ieee80211softmac_device *sm)
137 {
138         return (sm->start_scan == ieee80211softmac_start_scan_implementation) && 
139                 (sm->stop_scan == ieee80211softmac_stop_scan_implementation) && 
140                 (sm->wait_for_scan == ieee80211softmac_wait_for_scan_implementation);
141 }
142
143 static inline int ieee80211softmac_scan_sanity_check(struct ieee80211softmac_device *sm)
144 {
145         return ((sm->start_scan != ieee80211softmac_start_scan_implementation) && 
146                 (sm->stop_scan != ieee80211softmac_stop_scan_implementation) && 
147                 (sm->wait_for_scan != ieee80211softmac_wait_for_scan_implementation)
148                 ) || ieee80211softmac_scan_handlers_check_self(sm);
149 }
150
151 #define IEEE80211SOFTMAC_PROBE_DELAY            HZ/2
152 #define IEEE80211SOFTMAC_WORKQUEUE_NAME_LEN     (17 + IFNAMSIZ)
153
154 struct ieee80211softmac_network {
155         struct list_head                list;   /* List */
156         /* Network information copied from ieee80211_network */
157         u8 bssid[ETH_ALEN];
158         u8 channel;
159         struct ieee80211softmac_essid essid;
160
161         struct ieee80211softmac_ratesinfo supported_rates;
162
163         /* SoftMAC specific */
164         u16 authenticating:1,                   /* Status Flags */
165             authenticated:1,
166             auth_desynced_once:1;
167
168         u16 capabilities;                       /* Capabilities bitfield */
169         u8 challenge_len;                       /* Auth Challenge length */
170         char *challenge;                        /* Challenge Text */
171 };
172
173 /* structure used to keep track of networks we're auth'ing to */
174 struct ieee80211softmac_auth_queue_item {
175         struct list_head                list;   /* List head */
176         struct ieee80211softmac_network *net;   /* Network to auth */
177         struct ieee80211softmac_device  *mac;   /* SoftMAC device */
178         u8 retry;                               /* Retry limit */
179         u8 state;                               /* Auth State */
180         struct work_struct              work;   /* Work queue */
181 };
182
183 /* scanning information */
184 struct ieee80211softmac_scaninfo {
185         u8 current_channel_idx,
186            number_channels;
187         struct ieee80211_channel *channels;
188         u8 started:1,
189            stop:1;
190         u8 skip_flags;
191         struct completion finished;
192         struct work_struct softmac_scan;
193 };
194
195 /* private event struct */
196 struct ieee80211softmac_event {
197         struct list_head list;
198         int event_type;
199         void *event_context;
200         struct work_struct work;
201         notify_function_ptr fun;
202         void *context;
203         struct ieee80211softmac_device *mac;
204 };
205
206 void ieee80211softmac_call_events(struct ieee80211softmac_device *mac, int event, void *event_context);
207 void ieee80211softmac_call_events_locked(struct ieee80211softmac_device *mac, int event, void *event_context);
208 int ieee80211softmac_notify_internal(struct ieee80211softmac_device *mac,
209         int event, void *event_context, notify_function_ptr fun, void *context, gfp_t gfp_mask);
210
211 #endif /* IEEE80211SOFTMAC_PRIV_H_ */