ARM: AM335x: Fix warning in timer.c
[linux-2.6/btrfs-unstable.git] / drivers / staging / csr / wext_events.c
blob9860ea30da2504ae301d8ff7eb382a60078b8066
1 /*
2 * ---------------------------------------------------------------------------
3 * FILE: wext_events.c
5 * PURPOSE:
6 * Code to generate iwevents.
8 * Copyright (C) 2006-2008 by Cambridge Silicon Radio Ltd.
10 * Refer to LICENSE.txt included with this source code for details on
11 * the license terms.
13 * ---------------------------------------------------------------------------
15 #include <linux/types.h>
16 #include <linux/etherdevice.h>
17 #include <linux/if_arp.h>
18 #include "csr_wifi_hip_unifi.h"
19 #include "unifi_priv.h"
24 * ---------------------------------------------------------------------------
25 * wext_send_assoc_event
27 * Send wireless-extension events up to userland to announce
28 * successful association with an AP.
30 * Arguments:
31 * priv Pointer to driver context.
32 * bssid MAC address of AP we associated with
33 * req_ie, req_ie_len IEs in the original request
34 * resp_ie, resp_ie_len IEs in the response
36 * Returns:
37 * None.
39 * Notes:
40 * This is sent on first successful association, and again if we
41 * roam to another AP.
42 * ---------------------------------------------------------------------------
44 void
45 wext_send_assoc_event(unifi_priv_t *priv, unsigned char *bssid,
46 unsigned char *req_ie, int req_ie_len,
47 unsigned char *resp_ie, int resp_ie_len,
48 unsigned char *scan_ie, unsigned int scan_ie_len)
50 #if WIRELESS_EXT > 17
51 union iwreq_data wrqu;
53 if (req_ie_len == 0) req_ie = NULL;
54 wrqu.data.length = req_ie_len;
55 wrqu.data.flags = 0;
56 wireless_send_event(priv->netdev[CSR_WIFI_INTERFACE_IN_USE], IWEVASSOCREQIE, &wrqu, req_ie);
58 if (resp_ie_len == 0) resp_ie = NULL;
59 wrqu.data.length = resp_ie_len;
60 wrqu.data.flags = 0;
61 wireless_send_event(priv->netdev[CSR_WIFI_INTERFACE_IN_USE], IWEVASSOCRESPIE, &wrqu, resp_ie);
63 if (scan_ie_len > 0) {
64 wrqu.data.length = scan_ie_len;
65 wrqu.data.flags = 0;
66 wireless_send_event(priv->netdev[CSR_WIFI_INTERFACE_IN_USE], IWEVGENIE, &wrqu, scan_ie);
69 memcpy(&wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
70 wireless_send_event(priv->netdev[CSR_WIFI_INTERFACE_IN_USE], SIOCGIWAP, &wrqu, NULL);
71 #endif
72 } /* wext_send_assoc_event() */
77 * ---------------------------------------------------------------------------
78 * wext_send_disassoc_event
80 * Send a wireless-extension event up to userland to announce
81 * that we disassociated from an AP.
83 * Arguments:
84 * priv Pointer to driver context.
86 * Returns:
87 * None.
89 * Notes:
90 * The semantics of wpa_supplicant (the userland SME application) are
91 * that a SIOCGIWAP event with MAC address of all zero means
92 * disassociate.
93 * ---------------------------------------------------------------------------
95 void
96 wext_send_disassoc_event(unifi_priv_t *priv)
98 #if WIRELESS_EXT > 17
99 union iwreq_data wrqu;
101 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
102 wireless_send_event(priv->netdev[CSR_WIFI_INTERFACE_IN_USE], SIOCGIWAP, &wrqu, NULL);
103 #endif
104 } /* wext_send_disassoc_event() */
109 * ---------------------------------------------------------------------------
110 * wext_send_scan_results_event
112 * Send wireless-extension events up to userland to announce
113 * completion of a scan.
115 * Arguments:
116 * priv Pointer to driver context.
118 * Returns:
119 * None.
121 * Notes:
122 * This doesn't actually report the results, they are retrieved
123 * using the SIOCGIWSCAN ioctl command.
124 * ---------------------------------------------------------------------------
126 void
127 wext_send_scan_results_event(unifi_priv_t *priv)
129 #if WIRELESS_EXT > 17
130 union iwreq_data wrqu;
132 wrqu.data.length = 0;
133 wrqu.data.flags = 0;
134 wireless_send_event(priv->netdev[CSR_WIFI_INTERFACE_IN_USE], SIOCGIWSCAN, &wrqu, NULL);
136 #endif
137 } /* wext_send_scan_results_event() */
142 * ---------------------------------------------------------------------------
143 * wext_send_michaelmicfailure_event
145 * Send wireless-extension events up to userland to announce
146 * completion of a scan.
148 * Arguments:
149 * priv Pointer to driver context.
150 * count, macaddr, key_type, key_idx, tsc
151 * Parameters from report from UniFi.
153 * Returns:
154 * None.
155 * ---------------------------------------------------------------------------
157 #if WIRELESS_EXT >= 18
158 static inline void
159 _send_michaelmicfailure_event(struct net_device *dev,
160 int count, const unsigned char *macaddr,
161 int key_type, int key_idx,
162 unsigned char *tsc)
164 union iwreq_data wrqu;
165 struct iw_michaelmicfailure mmf;
167 memset(&mmf, 0, sizeof(mmf));
169 mmf.flags = key_idx & IW_MICFAILURE_KEY_ID;
170 if (key_type == CSR_GROUP) {
171 mmf.flags |= IW_MICFAILURE_GROUP;
172 } else {
173 mmf.flags |= IW_MICFAILURE_PAIRWISE;
175 mmf.flags |= ((count << 5) & IW_MICFAILURE_COUNT);
177 mmf.src_addr.sa_family = ARPHRD_ETHER;
178 memcpy(mmf.src_addr.sa_data, macaddr, ETH_ALEN);
180 memcpy(mmf.tsc, tsc, IW_ENCODE_SEQ_MAX_SIZE);
182 memset(&wrqu, 0, sizeof(wrqu));
183 wrqu.data.length = sizeof(mmf);
185 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&mmf);
187 #elif WIRELESS_EXT >= 15
188 static inline void
189 _send_michaelmicfailure_event(struct net_device *dev,
190 int count, const unsigned char *macaddr,
191 int key_type, int key_idx,
192 unsigned char *tsc)
194 union iwreq_data wrqu;
195 char buf[128];
197 sprintf(buf,
198 "MLME-MICHAELMICFAILURE.indication(keyid=%d %scast addr=%pM)",
199 key_idx, (key_type == CSR_GROUP) ? "broad" : "uni", macaddr);
200 memset(&wrqu, 0, sizeof(wrqu));
201 wrqu.data.length = strlen(buf);
202 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
204 #else /* WIRELESS_EXT >= 15 */
205 static inline void
206 _send_michaelmicfailure_event(struct net_device *dev,
207 int count, const unsigned char *macaddr,
208 int key_type, int key_idx,
209 unsigned char *tsc)
211 /* Not supported before WEXT 15 */
213 #endif /* WIRELESS_EXT >= 15 */
216 void
217 wext_send_michaelmicfailure_event(unifi_priv_t *priv,
218 u16 count,
219 CsrWifiMacAddress address,
220 CsrWifiSmeKeyType keyType,
221 u16 interfaceTag)
223 unsigned char tsc[8] = {0};
225 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
226 unifi_error(priv, "wext_send_michaelmicfailure_event bad interfaceTag\n");
227 return;
230 _send_michaelmicfailure_event(priv->netdev[interfaceTag],
231 count,
232 address.a,
233 keyType,
235 tsc);
236 } /* wext_send_michaelmicfailure_event() */
238 void
239 wext_send_pmkid_candidate_event(unifi_priv_t *priv, CsrWifiMacAddress bssid, u8 preauth_allowed, u16 interfaceTag)
241 #if WIRELESS_EXT > 17
242 union iwreq_data wrqu;
243 struct iw_pmkid_cand pmkid_cand;
245 if (interfaceTag >= CSR_WIFI_NUM_INTERFACES) {
246 unifi_error(priv, "wext_send_pmkid_candidate_event bad interfaceTag\n");
247 return;
250 memset(&pmkid_cand, 0, sizeof(pmkid_cand));
252 if (preauth_allowed) {
253 pmkid_cand.flags |= IW_PMKID_CAND_PREAUTH;
255 pmkid_cand.bssid.sa_family = ARPHRD_ETHER;
256 memcpy(pmkid_cand.bssid.sa_data, bssid.a, ETH_ALEN);
257 /* Used as priority, smaller the number higher the priority, not really used in our case */
258 pmkid_cand.index = 1;
260 memset(&wrqu, 0, sizeof(wrqu));
261 wrqu.data.length = sizeof(pmkid_cand);
263 wireless_send_event(priv->netdev[interfaceTag], IWEVPMKIDCAND, &wrqu, (char *)&pmkid_cand);
264 #endif
265 } /* wext_send_pmkid_candidate_event() */
268 * Send a custom WEXT event to say we have completed initialisation
269 * and are now ready for WEXT ioctls. Used by Android wpa_supplicant.
271 void
272 wext_send_started_event(unifi_priv_t *priv)
274 #if WIRELESS_EXT > 17
275 union iwreq_data wrqu;
276 char data[] = "STARTED";
278 wrqu.data.length = sizeof(data);
279 wrqu.data.flags = 0;
280 wireless_send_event(priv->netdev[CSR_WIFI_INTERFACE_IN_USE], IWEVCUSTOM, &wrqu, data);
281 #endif
282 } /* wext_send_started_event() */