1 /* Host AP driver Info Frame processing (part of hostap.o module) */
3 #include <linux/if_arp.h>
4 #include <linux/sched.h>
5 #include <linux/slab.h>
6 #include <linux/export.h>
7 #include "hostap_wlan.h"
11 /* Called only as a tasklet (software IRQ) */
12 static void prism2_info_commtallies16(local_info_t
*local
, unsigned char *buf
,
15 struct hfa384x_comm_tallies
*tallies
;
17 if (left
< sizeof(struct hfa384x_comm_tallies
)) {
18 printk(KERN_DEBUG
"%s: too short (len=%d) commtallies "
19 "info frame\n", local
->dev
->name
, left
);
23 tallies
= (struct hfa384x_comm_tallies
*) buf
;
24 #define ADD_COMM_TALLIES(name) \
25 local->comm_tallies.name += le16_to_cpu(tallies->name)
26 ADD_COMM_TALLIES(tx_unicast_frames
);
27 ADD_COMM_TALLIES(tx_multicast_frames
);
28 ADD_COMM_TALLIES(tx_fragments
);
29 ADD_COMM_TALLIES(tx_unicast_octets
);
30 ADD_COMM_TALLIES(tx_multicast_octets
);
31 ADD_COMM_TALLIES(tx_deferred_transmissions
);
32 ADD_COMM_TALLIES(tx_single_retry_frames
);
33 ADD_COMM_TALLIES(tx_multiple_retry_frames
);
34 ADD_COMM_TALLIES(tx_retry_limit_exceeded
);
35 ADD_COMM_TALLIES(tx_discards
);
36 ADD_COMM_TALLIES(rx_unicast_frames
);
37 ADD_COMM_TALLIES(rx_multicast_frames
);
38 ADD_COMM_TALLIES(rx_fragments
);
39 ADD_COMM_TALLIES(rx_unicast_octets
);
40 ADD_COMM_TALLIES(rx_multicast_octets
);
41 ADD_COMM_TALLIES(rx_fcs_errors
);
42 ADD_COMM_TALLIES(rx_discards_no_buffer
);
43 ADD_COMM_TALLIES(tx_discards_wrong_sa
);
44 ADD_COMM_TALLIES(rx_discards_wep_undecryptable
);
45 ADD_COMM_TALLIES(rx_message_in_msg_fragments
);
46 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments
);
47 #undef ADD_COMM_TALLIES
51 /* Called only as a tasklet (software IRQ) */
52 static void prism2_info_commtallies32(local_info_t
*local
, unsigned char *buf
,
55 struct hfa384x_comm_tallies32
*tallies
;
57 if (left
< sizeof(struct hfa384x_comm_tallies32
)) {
58 printk(KERN_DEBUG
"%s: too short (len=%d) commtallies32 "
59 "info frame\n", local
->dev
->name
, left
);
63 tallies
= (struct hfa384x_comm_tallies32
*) buf
;
64 #define ADD_COMM_TALLIES(name) \
65 local->comm_tallies.name += le32_to_cpu(tallies->name)
66 ADD_COMM_TALLIES(tx_unicast_frames
);
67 ADD_COMM_TALLIES(tx_multicast_frames
);
68 ADD_COMM_TALLIES(tx_fragments
);
69 ADD_COMM_TALLIES(tx_unicast_octets
);
70 ADD_COMM_TALLIES(tx_multicast_octets
);
71 ADD_COMM_TALLIES(tx_deferred_transmissions
);
72 ADD_COMM_TALLIES(tx_single_retry_frames
);
73 ADD_COMM_TALLIES(tx_multiple_retry_frames
);
74 ADD_COMM_TALLIES(tx_retry_limit_exceeded
);
75 ADD_COMM_TALLIES(tx_discards
);
76 ADD_COMM_TALLIES(rx_unicast_frames
);
77 ADD_COMM_TALLIES(rx_multicast_frames
);
78 ADD_COMM_TALLIES(rx_fragments
);
79 ADD_COMM_TALLIES(rx_unicast_octets
);
80 ADD_COMM_TALLIES(rx_multicast_octets
);
81 ADD_COMM_TALLIES(rx_fcs_errors
);
82 ADD_COMM_TALLIES(rx_discards_no_buffer
);
83 ADD_COMM_TALLIES(tx_discards_wrong_sa
);
84 ADD_COMM_TALLIES(rx_discards_wep_undecryptable
);
85 ADD_COMM_TALLIES(rx_message_in_msg_fragments
);
86 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments
);
87 #undef ADD_COMM_TALLIES
91 /* Called only as a tasklet (software IRQ) */
92 static void prism2_info_commtallies(local_info_t
*local
, unsigned char *buf
,
96 prism2_info_commtallies32(local
, buf
, left
);
98 prism2_info_commtallies16(local
, buf
, left
);
102 #ifndef PRISM2_NO_STATION_MODES
103 #ifndef PRISM2_NO_DEBUG
104 static const char* hfa384x_linkstatus_str(u16 linkstatus
)
106 switch (linkstatus
) {
107 case HFA384X_LINKSTATUS_CONNECTED
:
109 case HFA384X_LINKSTATUS_DISCONNECTED
:
110 return "Disconnected";
111 case HFA384X_LINKSTATUS_AP_CHANGE
:
112 return "Access point change";
113 case HFA384X_LINKSTATUS_AP_OUT_OF_RANGE
:
114 return "Access point out of range";
115 case HFA384X_LINKSTATUS_AP_IN_RANGE
:
116 return "Access point in range";
117 case HFA384X_LINKSTATUS_ASSOC_FAILED
:
118 return "Association failed";
123 #endif /* PRISM2_NO_DEBUG */
126 /* Called only as a tasklet (software IRQ) */
127 static void prism2_info_linkstatus(local_info_t
*local
, unsigned char *buf
,
133 /* Alloc new JoinRequests to occur since LinkStatus for the previous
134 * has been received */
135 local
->last_join_time
= 0;
138 printk(KERN_DEBUG
"%s: invalid linkstatus info frame "
139 "length %d\n", local
->dev
->name
, left
);
143 non_sta_mode
= local
->iw_mode
== IW_MODE_MASTER
||
144 local
->iw_mode
== IW_MODE_REPEAT
||
145 local
->iw_mode
== IW_MODE_MONITOR
;
147 val
= buf
[0] | (buf
[1] << 8);
148 if (!non_sta_mode
|| val
!= HFA384X_LINKSTATUS_DISCONNECTED
) {
149 PDEBUG(DEBUG_EXTRA
, "%s: LinkStatus=%d (%s)\n",
150 local
->dev
->name
, val
, hfa384x_linkstatus_str(val
));
154 netif_carrier_on(local
->dev
);
155 netif_carrier_on(local
->ddev
);
159 /* Get current BSSID later in scheduled task */
160 set_bit(PRISM2_INFO_PENDING_LINKSTATUS
, &local
->pending_info
);
161 local
->prev_link_status
= val
;
162 schedule_work(&local
->info_queue
);
166 static void prism2_host_roaming(local_info_t
*local
)
168 struct hfa384x_join_request req
;
169 struct net_device
*dev
= local
->dev
;
170 struct hfa384x_hostscan_result
*selected
, *entry
;
174 if (local
->last_join_time
&&
175 time_before(jiffies
, local
->last_join_time
+ 10 * HZ
)) {
176 PDEBUG(DEBUG_EXTRA
, "%s: last join request has not yet been "
177 "completed - waiting for it before issuing new one\n",
182 /* ScanResults are sorted: first ESS results in decreasing signal
183 * quality then IBSS results in similar order.
184 * Trivial roaming policy: just select the first entry.
185 * This could probably be improved by adding hysteresis to limit
186 * number of handoffs, etc.
188 * Could do periodic RID_SCANREQUEST or Inquire F101 to get new
190 spin_lock_irqsave(&local
->lock
, flags
);
191 if (local
->last_scan_results
== NULL
||
192 local
->last_scan_results_count
== 0) {
193 spin_unlock_irqrestore(&local
->lock
, flags
);
194 PDEBUG(DEBUG_EXTRA
, "%s: no scan results for host roaming\n",
199 selected
= &local
->last_scan_results
[0];
201 if (local
->preferred_ap
[0] || local
->preferred_ap
[1] ||
202 local
->preferred_ap
[2] || local
->preferred_ap
[3] ||
203 local
->preferred_ap
[4] || local
->preferred_ap
[5]) {
204 /* Try to find preferred AP */
205 PDEBUG(DEBUG_EXTRA
, "%s: Preferred AP BSSID %pM\n",
206 dev
->name
, local
->preferred_ap
);
207 for (i
= 0; i
< local
->last_scan_results_count
; i
++) {
208 entry
= &local
->last_scan_results
[i
];
209 if (memcmp(local
->preferred_ap
, entry
->bssid
, 6) == 0)
211 PDEBUG(DEBUG_EXTRA
, "%s: using preferred AP "
212 "selection\n", dev
->name
);
219 memcpy(req
.bssid
, selected
->bssid
, 6);
220 req
.channel
= selected
->chid
;
221 spin_unlock_irqrestore(&local
->lock
, flags
);
223 PDEBUG(DEBUG_EXTRA
, "%s: JoinRequest: BSSID=%pM"
225 dev
->name
, req
.bssid
, le16_to_cpu(req
.channel
));
226 if (local
->func
->set_rid(dev
, HFA384X_RID_JOINREQUEST
, &req
,
228 printk(KERN_DEBUG
"%s: JoinRequest failed\n", dev
->name
);
230 local
->last_join_time
= jiffies
;
234 static void hostap_report_scan_complete(local_info_t
*local
)
236 union iwreq_data wrqu
;
238 /* Inform user space about new scan results (just empty event,
239 * SIOCGIWSCAN can be used to fetch data */
240 wrqu
.data
.length
= 0;
242 wireless_send_event(local
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
244 /* Allow SIOCGIWSCAN handling to occur since we have received
246 local
->scan_timestamp
= 0;
250 /* Called only as a tasklet (software IRQ) */
251 static void prism2_info_scanresults(local_info_t
*local
, unsigned char *buf
,
257 struct hfa384x_scan_result
*res
;
258 struct hfa384x_hostscan_result
*results
, *prev
;
261 printk(KERN_DEBUG
"%s: invalid scanresult info frame "
262 "length %d\n", local
->dev
->name
, left
);
271 new_count
= left
/ sizeof(struct hfa384x_scan_result
);
272 results
= kmalloc(new_count
* sizeof(struct hfa384x_hostscan_result
),
277 /* Convert to hostscan result format. */
278 res
= (struct hfa384x_scan_result
*) pos
;
279 for (i
= 0; i
< new_count
; i
++) {
280 memcpy(&results
[i
], &res
[i
],
281 sizeof(struct hfa384x_scan_result
));
285 spin_lock_irqsave(&local
->lock
, flags
);
286 local
->last_scan_type
= PRISM2_SCAN
;
287 prev
= local
->last_scan_results
;
288 local
->last_scan_results
= results
;
289 local
->last_scan_results_count
= new_count
;
290 spin_unlock_irqrestore(&local
->lock
, flags
);
293 hostap_report_scan_complete(local
);
295 /* Perform rest of ScanResults handling later in scheduled task */
296 set_bit(PRISM2_INFO_PENDING_SCANRESULTS
, &local
->pending_info
);
297 schedule_work(&local
->info_queue
);
301 /* Called only as a tasklet (software IRQ) */
302 static void prism2_info_hostscanresults(local_info_t
*local
,
303 unsigned char *buf
, int left
)
305 int i
, result_size
, copy_len
, new_count
;
306 struct hfa384x_hostscan_result
*results
, *prev
;
311 wake_up_interruptible(&local
->hostscan_wq
);
314 printk(KERN_DEBUG
"%s: invalid hostscanresult info frame "
315 "length %d\n", local
->dev
->name
, left
);
319 pos
= (__le16
*) buf
;
320 copy_len
= result_size
= le16_to_cpu(*pos
);
321 if (result_size
== 0) {
322 printk(KERN_DEBUG
"%s: invalid result_size (0) in "
323 "hostscanresults\n", local
->dev
->name
);
326 if (copy_len
> sizeof(struct hfa384x_hostscan_result
))
327 copy_len
= sizeof(struct hfa384x_hostscan_result
);
334 new_count
= left
/ result_size
;
335 results
= kcalloc(new_count
, sizeof(struct hfa384x_hostscan_result
),
340 for (i
= 0; i
< new_count
; i
++) {
341 memcpy(&results
[i
], ptr
, copy_len
);
347 printk(KERN_DEBUG
"%s: short HostScan result entry (%d/%d)\n",
348 local
->dev
->name
, left
, result_size
);
351 spin_lock_irqsave(&local
->lock
, flags
);
352 local
->last_scan_type
= PRISM2_HOSTSCAN
;
353 prev
= local
->last_scan_results
;
354 local
->last_scan_results
= results
;
355 local
->last_scan_results_count
= new_count
;
356 spin_unlock_irqrestore(&local
->lock
, flags
);
359 hostap_report_scan_complete(local
);
361 #endif /* PRISM2_NO_STATION_MODES */
364 /* Called only as a tasklet (software IRQ) */
365 void hostap_info_process(local_info_t
*local
, struct sk_buff
*skb
)
367 struct hfa384x_info_frame
*info
;
370 #ifndef PRISM2_NO_DEBUG
372 #endif /* PRISM2_NO_DEBUG */
374 info
= (struct hfa384x_info_frame
*) skb
->data
;
375 buf
= skb
->data
+ sizeof(*info
);
376 left
= skb
->len
- sizeof(*info
);
378 switch (le16_to_cpu(info
->type
)) {
379 case HFA384X_INFO_COMMTALLIES
:
380 prism2_info_commtallies(local
, buf
, left
);
383 #ifndef PRISM2_NO_STATION_MODES
384 case HFA384X_INFO_LINKSTATUS
:
385 prism2_info_linkstatus(local
, buf
, left
);
388 case HFA384X_INFO_SCANRESULTS
:
389 prism2_info_scanresults(local
, buf
, left
);
392 case HFA384X_INFO_HOSTSCANRESULTS
:
393 prism2_info_hostscanresults(local
, buf
, left
);
395 #endif /* PRISM2_NO_STATION_MODES */
397 #ifndef PRISM2_NO_DEBUG
399 PDEBUG(DEBUG_EXTRA
, "%s: INFO - len=%d type=0x%04x\n",
400 local
->dev
->name
, le16_to_cpu(info
->len
),
401 le16_to_cpu(info
->type
));
402 PDEBUG(DEBUG_EXTRA
, "Unknown info frame:");
403 for (i
= 0; i
< (left
< 100 ? left
: 100); i
++)
404 PDEBUG2(DEBUG_EXTRA
, " %02x", buf
[i
]);
405 PDEBUG2(DEBUG_EXTRA
, "\n");
407 #endif /* PRISM2_NO_DEBUG */
412 #ifndef PRISM2_NO_STATION_MODES
413 static void handle_info_queue_linkstatus(local_info_t
*local
)
415 int val
= local
->prev_link_status
;
417 union iwreq_data wrqu
;
420 val
== HFA384X_LINKSTATUS_CONNECTED
||
421 val
== HFA384X_LINKSTATUS_AP_CHANGE
||
422 val
== HFA384X_LINKSTATUS_AP_IN_RANGE
;
424 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_CURRENTBSSID
,
425 local
->bssid
, ETH_ALEN
, 1) < 0) {
426 printk(KERN_DEBUG
"%s: could not read CURRENTBSSID after "
427 "LinkStatus event\n", local
->dev
->name
);
429 PDEBUG(DEBUG_EXTRA
, "%s: LinkStatus: BSSID=%pM\n",
431 (unsigned char *) local
->bssid
);
432 if (local
->wds_type
& HOSTAP_WDS_AP_CLIENT
)
433 hostap_add_sta(local
->ap
, local
->bssid
);
436 /* Get BSSID if we have a valid AP address */
438 if ( val
== HFA384X_LINKSTATUS_CONNECTED
||
439 val
== HFA384X_LINKSTATUS_DISCONNECTED
)
440 hostap_restore_power(local
->dev
);
443 netif_carrier_on(local
->dev
);
444 netif_carrier_on(local
->ddev
);
445 memcpy(wrqu
.ap_addr
.sa_data
, local
->bssid
, ETH_ALEN
);
447 netif_carrier_off(local
->dev
);
448 netif_carrier_off(local
->ddev
);
449 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
451 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
454 * Filter out sequential disconnect events in order not to cause a
455 * flood of SIOCGIWAP events that have a race condition with EAPOL
456 * frames and can confuse wpa_supplicant about the current association
459 if (connected
|| local
->prev_linkstatus_connected
)
460 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
461 local
->prev_linkstatus_connected
= connected
;
465 static void handle_info_queue_scanresults(local_info_t
*local
)
467 if (local
->host_roaming
== 1 && local
->iw_mode
== IW_MODE_INFRA
)
468 prism2_host_roaming(local
);
470 if (local
->host_roaming
== 2 && local
->iw_mode
== IW_MODE_INFRA
&&
471 memcmp(local
->preferred_ap
, "\x00\x00\x00\x00\x00\x00",
474 * Firmware seems to be getting into odd state in host_roaming
475 * mode 2 when hostscan is used without join command, so try
476 * to fix this by re-joining the current AP. This does not
477 * actually trigger a new association if the current AP is
478 * still in the scan results.
480 prism2_host_roaming(local
);
485 /* Called only as scheduled task after receiving info frames (used to avoid
486 * pending too much time in HW IRQ handler). */
487 static void handle_info_queue(struct work_struct
*work
)
489 local_info_t
*local
= container_of(work
, local_info_t
, info_queue
);
491 if (test_and_clear_bit(PRISM2_INFO_PENDING_LINKSTATUS
,
492 &local
->pending_info
))
493 handle_info_queue_linkstatus(local
);
495 if (test_and_clear_bit(PRISM2_INFO_PENDING_SCANRESULTS
,
496 &local
->pending_info
))
497 handle_info_queue_scanresults(local
);
499 #endif /* PRISM2_NO_STATION_MODES */
502 void hostap_info_init(local_info_t
*local
)
504 skb_queue_head_init(&local
->info_list
);
505 #ifndef PRISM2_NO_STATION_MODES
506 INIT_WORK(&local
->info_queue
, handle_info_queue
);
507 #endif /* PRISM2_NO_STATION_MODES */
511 EXPORT_SYMBOL(hostap_info_init
);
512 EXPORT_SYMBOL(hostap_info_process
);