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 "hostap_wlan.h"
10 /* Called only as a tasklet (software IRQ) */
11 static void prism2_info_commtallies16(local_info_t
*local
, unsigned char *buf
,
14 struct hfa384x_comm_tallies
*tallies
;
16 if (left
< sizeof(struct hfa384x_comm_tallies
)) {
17 printk(KERN_DEBUG
"%s: too short (len=%d) commtallies "
18 "info frame\n", local
->dev
->name
, left
);
22 tallies
= (struct hfa384x_comm_tallies
*) buf
;
23 #define ADD_COMM_TALLIES(name) \
24 local->comm_tallies.name += le16_to_cpu(tallies->name)
25 ADD_COMM_TALLIES(tx_unicast_frames
);
26 ADD_COMM_TALLIES(tx_multicast_frames
);
27 ADD_COMM_TALLIES(tx_fragments
);
28 ADD_COMM_TALLIES(tx_unicast_octets
);
29 ADD_COMM_TALLIES(tx_multicast_octets
);
30 ADD_COMM_TALLIES(tx_deferred_transmissions
);
31 ADD_COMM_TALLIES(tx_single_retry_frames
);
32 ADD_COMM_TALLIES(tx_multiple_retry_frames
);
33 ADD_COMM_TALLIES(tx_retry_limit_exceeded
);
34 ADD_COMM_TALLIES(tx_discards
);
35 ADD_COMM_TALLIES(rx_unicast_frames
);
36 ADD_COMM_TALLIES(rx_multicast_frames
);
37 ADD_COMM_TALLIES(rx_fragments
);
38 ADD_COMM_TALLIES(rx_unicast_octets
);
39 ADD_COMM_TALLIES(rx_multicast_octets
);
40 ADD_COMM_TALLIES(rx_fcs_errors
);
41 ADD_COMM_TALLIES(rx_discards_no_buffer
);
42 ADD_COMM_TALLIES(tx_discards_wrong_sa
);
43 ADD_COMM_TALLIES(rx_discards_wep_undecryptable
);
44 ADD_COMM_TALLIES(rx_message_in_msg_fragments
);
45 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments
);
46 #undef ADD_COMM_TALLIES
50 /* Called only as a tasklet (software IRQ) */
51 static void prism2_info_commtallies32(local_info_t
*local
, unsigned char *buf
,
54 struct hfa384x_comm_tallies32
*tallies
;
56 if (left
< sizeof(struct hfa384x_comm_tallies32
)) {
57 printk(KERN_DEBUG
"%s: too short (len=%d) commtallies32 "
58 "info frame\n", local
->dev
->name
, left
);
62 tallies
= (struct hfa384x_comm_tallies32
*) buf
;
63 #define ADD_COMM_TALLIES(name) \
64 local->comm_tallies.name += le32_to_cpu(tallies->name)
65 ADD_COMM_TALLIES(tx_unicast_frames
);
66 ADD_COMM_TALLIES(tx_multicast_frames
);
67 ADD_COMM_TALLIES(tx_fragments
);
68 ADD_COMM_TALLIES(tx_unicast_octets
);
69 ADD_COMM_TALLIES(tx_multicast_octets
);
70 ADD_COMM_TALLIES(tx_deferred_transmissions
);
71 ADD_COMM_TALLIES(tx_single_retry_frames
);
72 ADD_COMM_TALLIES(tx_multiple_retry_frames
);
73 ADD_COMM_TALLIES(tx_retry_limit_exceeded
);
74 ADD_COMM_TALLIES(tx_discards
);
75 ADD_COMM_TALLIES(rx_unicast_frames
);
76 ADD_COMM_TALLIES(rx_multicast_frames
);
77 ADD_COMM_TALLIES(rx_fragments
);
78 ADD_COMM_TALLIES(rx_unicast_octets
);
79 ADD_COMM_TALLIES(rx_multicast_octets
);
80 ADD_COMM_TALLIES(rx_fcs_errors
);
81 ADD_COMM_TALLIES(rx_discards_no_buffer
);
82 ADD_COMM_TALLIES(tx_discards_wrong_sa
);
83 ADD_COMM_TALLIES(rx_discards_wep_undecryptable
);
84 ADD_COMM_TALLIES(rx_message_in_msg_fragments
);
85 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments
);
86 #undef ADD_COMM_TALLIES
90 /* Called only as a tasklet (software IRQ) */
91 static void prism2_info_commtallies(local_info_t
*local
, unsigned char *buf
,
95 prism2_info_commtallies32(local
, buf
, left
);
97 prism2_info_commtallies16(local
, buf
, left
);
101 #ifndef PRISM2_NO_STATION_MODES
102 #ifndef PRISM2_NO_DEBUG
103 static const char* hfa384x_linkstatus_str(u16 linkstatus
)
105 switch (linkstatus
) {
106 case HFA384X_LINKSTATUS_CONNECTED
:
108 case HFA384X_LINKSTATUS_DISCONNECTED
:
109 return "Disconnected";
110 case HFA384X_LINKSTATUS_AP_CHANGE
:
111 return "Access point change";
112 case HFA384X_LINKSTATUS_AP_OUT_OF_RANGE
:
113 return "Access point out of range";
114 case HFA384X_LINKSTATUS_AP_IN_RANGE
:
115 return "Access point in range";
116 case HFA384X_LINKSTATUS_ASSOC_FAILED
:
117 return "Association failed";
122 #endif /* PRISM2_NO_DEBUG */
125 /* Called only as a tasklet (software IRQ) */
126 static void prism2_info_linkstatus(local_info_t
*local
, unsigned char *buf
,
132 /* Alloc new JoinRequests to occur since LinkStatus for the previous
133 * has been received */
134 local
->last_join_time
= 0;
137 printk(KERN_DEBUG
"%s: invalid linkstatus info frame "
138 "length %d\n", local
->dev
->name
, left
);
142 non_sta_mode
= local
->iw_mode
== IW_MODE_MASTER
||
143 local
->iw_mode
== IW_MODE_REPEAT
||
144 local
->iw_mode
== IW_MODE_MONITOR
;
146 val
= buf
[0] | (buf
[1] << 8);
147 if (!non_sta_mode
|| val
!= HFA384X_LINKSTATUS_DISCONNECTED
) {
148 PDEBUG(DEBUG_EXTRA
, "%s: LinkStatus=%d (%s)\n",
149 local
->dev
->name
, val
, hfa384x_linkstatus_str(val
));
153 netif_carrier_on(local
->dev
);
154 netif_carrier_on(local
->ddev
);
158 /* Get current BSSID later in scheduled task */
159 set_bit(PRISM2_INFO_PENDING_LINKSTATUS
, &local
->pending_info
);
160 local
->prev_link_status
= val
;
161 schedule_work(&local
->info_queue
);
165 static void prism2_host_roaming(local_info_t
*local
)
167 struct hfa384x_join_request req
;
168 struct net_device
*dev
= local
->dev
;
169 struct hfa384x_hostscan_result
*selected
, *entry
;
173 if (local
->last_join_time
&&
174 time_before(jiffies
, local
->last_join_time
+ 10 * HZ
)) {
175 PDEBUG(DEBUG_EXTRA
, "%s: last join request has not yet been "
176 "completed - waiting for it before issuing new one\n",
181 /* ScanResults are sorted: first ESS results in decreasing signal
182 * quality then IBSS results in similar order.
183 * Trivial roaming policy: just select the first entry.
184 * This could probably be improved by adding hysteresis to limit
185 * number of handoffs, etc.
187 * Could do periodic RID_SCANREQUEST or Inquire F101 to get new
189 spin_lock_irqsave(&local
->lock
, flags
);
190 if (local
->last_scan_results
== NULL
||
191 local
->last_scan_results_count
== 0) {
192 spin_unlock_irqrestore(&local
->lock
, flags
);
193 PDEBUG(DEBUG_EXTRA
, "%s: no scan results for host roaming\n",
198 selected
= &local
->last_scan_results
[0];
200 if (local
->preferred_ap
[0] || local
->preferred_ap
[1] ||
201 local
->preferred_ap
[2] || local
->preferred_ap
[3] ||
202 local
->preferred_ap
[4] || local
->preferred_ap
[5]) {
203 /* Try to find preferred AP */
204 PDEBUG(DEBUG_EXTRA
, "%s: Preferred AP BSSID %pM\n",
205 dev
->name
, local
->preferred_ap
);
206 for (i
= 0; i
< local
->last_scan_results_count
; i
++) {
207 entry
= &local
->last_scan_results
[i
];
208 if (memcmp(local
->preferred_ap
, entry
->bssid
, 6) == 0)
210 PDEBUG(DEBUG_EXTRA
, "%s: using preferred AP "
211 "selection\n", dev
->name
);
218 memcpy(req
.bssid
, selected
->bssid
, 6);
219 req
.channel
= selected
->chid
;
220 spin_unlock_irqrestore(&local
->lock
, flags
);
222 PDEBUG(DEBUG_EXTRA
, "%s: JoinRequest: BSSID=%pM"
224 dev
->name
, req
.bssid
, le16_to_cpu(req
.channel
));
225 if (local
->func
->set_rid(dev
, HFA384X_RID_JOINREQUEST
, &req
,
227 printk(KERN_DEBUG
"%s: JoinRequest failed\n", dev
->name
);
229 local
->last_join_time
= jiffies
;
233 static void hostap_report_scan_complete(local_info_t
*local
)
235 union iwreq_data wrqu
;
237 /* Inform user space about new scan results (just empty event,
238 * SIOCGIWSCAN can be used to fetch data */
239 wrqu
.data
.length
= 0;
241 wireless_send_event(local
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
243 /* Allow SIOCGIWSCAN handling to occur since we have received
245 local
->scan_timestamp
= 0;
249 /* Called only as a tasklet (software IRQ) */
250 static void prism2_info_scanresults(local_info_t
*local
, unsigned char *buf
,
256 struct hfa384x_scan_result
*res
;
257 struct hfa384x_hostscan_result
*results
, *prev
;
260 printk(KERN_DEBUG
"%s: invalid scanresult info frame "
261 "length %d\n", local
->dev
->name
, left
);
270 new_count
= left
/ sizeof(struct hfa384x_scan_result
);
271 results
= kmalloc(new_count
* sizeof(struct hfa384x_hostscan_result
),
276 /* Convert to hostscan result format. */
277 res
= (struct hfa384x_scan_result
*) pos
;
278 for (i
= 0; i
< new_count
; i
++) {
279 memcpy(&results
[i
], &res
[i
],
280 sizeof(struct hfa384x_scan_result
));
284 spin_lock_irqsave(&local
->lock
, flags
);
285 local
->last_scan_type
= PRISM2_SCAN
;
286 prev
= local
->last_scan_results
;
287 local
->last_scan_results
= results
;
288 local
->last_scan_results_count
= new_count
;
289 spin_unlock_irqrestore(&local
->lock
, flags
);
292 hostap_report_scan_complete(local
);
294 /* Perform rest of ScanResults handling later in scheduled task */
295 set_bit(PRISM2_INFO_PENDING_SCANRESULTS
, &local
->pending_info
);
296 schedule_work(&local
->info_queue
);
300 /* Called only as a tasklet (software IRQ) */
301 static void prism2_info_hostscanresults(local_info_t
*local
,
302 unsigned char *buf
, int left
)
304 int i
, result_size
, copy_len
, new_count
;
305 struct hfa384x_hostscan_result
*results
, *prev
;
310 wake_up_interruptible(&local
->hostscan_wq
);
313 printk(KERN_DEBUG
"%s: invalid hostscanresult info frame "
314 "length %d\n", local
->dev
->name
, left
);
318 pos
= (__le16
*) buf
;
319 copy_len
= result_size
= le16_to_cpu(*pos
);
320 if (result_size
== 0) {
321 printk(KERN_DEBUG
"%s: invalid result_size (0) in "
322 "hostscanresults\n", local
->dev
->name
);
325 if (copy_len
> sizeof(struct hfa384x_hostscan_result
))
326 copy_len
= sizeof(struct hfa384x_hostscan_result
);
333 new_count
= left
/ result_size
;
334 results
= kcalloc(new_count
, sizeof(struct hfa384x_hostscan_result
),
339 for (i
= 0; i
< new_count
; i
++) {
340 memcpy(&results
[i
], ptr
, copy_len
);
346 printk(KERN_DEBUG
"%s: short HostScan result entry (%d/%d)\n",
347 local
->dev
->name
, left
, result_size
);
350 spin_lock_irqsave(&local
->lock
, flags
);
351 local
->last_scan_type
= PRISM2_HOSTSCAN
;
352 prev
= local
->last_scan_results
;
353 local
->last_scan_results
= results
;
354 local
->last_scan_results_count
= new_count
;
355 spin_unlock_irqrestore(&local
->lock
, flags
);
358 hostap_report_scan_complete(local
);
360 #endif /* PRISM2_NO_STATION_MODES */
363 /* Called only as a tasklet (software IRQ) */
364 void hostap_info_process(local_info_t
*local
, struct sk_buff
*skb
)
366 struct hfa384x_info_frame
*info
;
369 #ifndef PRISM2_NO_DEBUG
371 #endif /* PRISM2_NO_DEBUG */
373 info
= (struct hfa384x_info_frame
*) skb
->data
;
374 buf
= skb
->data
+ sizeof(*info
);
375 left
= skb
->len
- sizeof(*info
);
377 switch (le16_to_cpu(info
->type
)) {
378 case HFA384X_INFO_COMMTALLIES
:
379 prism2_info_commtallies(local
, buf
, left
);
382 #ifndef PRISM2_NO_STATION_MODES
383 case HFA384X_INFO_LINKSTATUS
:
384 prism2_info_linkstatus(local
, buf
, left
);
387 case HFA384X_INFO_SCANRESULTS
:
388 prism2_info_scanresults(local
, buf
, left
);
391 case HFA384X_INFO_HOSTSCANRESULTS
:
392 prism2_info_hostscanresults(local
, buf
, left
);
394 #endif /* PRISM2_NO_STATION_MODES */
396 #ifndef PRISM2_NO_DEBUG
398 PDEBUG(DEBUG_EXTRA
, "%s: INFO - len=%d type=0x%04x\n",
399 local
->dev
->name
, le16_to_cpu(info
->len
),
400 le16_to_cpu(info
->type
));
401 PDEBUG(DEBUG_EXTRA
, "Unknown info frame:");
402 for (i
= 0; i
< (left
< 100 ? left
: 100); i
++)
403 PDEBUG2(DEBUG_EXTRA
, " %02x", buf
[i
]);
404 PDEBUG2(DEBUG_EXTRA
, "\n");
406 #endif /* PRISM2_NO_DEBUG */
411 #ifndef PRISM2_NO_STATION_MODES
412 static void handle_info_queue_linkstatus(local_info_t
*local
)
414 int val
= local
->prev_link_status
;
416 union iwreq_data wrqu
;
419 val
== HFA384X_LINKSTATUS_CONNECTED
||
420 val
== HFA384X_LINKSTATUS_AP_CHANGE
||
421 val
== HFA384X_LINKSTATUS_AP_IN_RANGE
;
423 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_CURRENTBSSID
,
424 local
->bssid
, ETH_ALEN
, 1) < 0) {
425 printk(KERN_DEBUG
"%s: could not read CURRENTBSSID after "
426 "LinkStatus event\n", local
->dev
->name
);
428 PDEBUG(DEBUG_EXTRA
, "%s: LinkStatus: BSSID=%pM\n",
430 (unsigned char *) local
->bssid
);
431 if (local
->wds_type
& HOSTAP_WDS_AP_CLIENT
)
432 hostap_add_sta(local
->ap
, local
->bssid
);
435 /* Get BSSID if we have a valid AP address */
437 netif_carrier_on(local
->dev
);
438 netif_carrier_on(local
->ddev
);
439 memcpy(wrqu
.ap_addr
.sa_data
, local
->bssid
, ETH_ALEN
);
441 netif_carrier_off(local
->dev
);
442 netif_carrier_off(local
->ddev
);
443 memset(wrqu
.ap_addr
.sa_data
, 0, ETH_ALEN
);
445 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
448 * Filter out sequential disconnect events in order not to cause a
449 * flood of SIOCGIWAP events that have a race condition with EAPOL
450 * frames and can confuse wpa_supplicant about the current association
453 if (connected
|| local
->prev_linkstatus_connected
)
454 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
455 local
->prev_linkstatus_connected
= connected
;
459 static void handle_info_queue_scanresults(local_info_t
*local
)
461 if (local
->host_roaming
== 1 && local
->iw_mode
== IW_MODE_INFRA
)
462 prism2_host_roaming(local
);
464 if (local
->host_roaming
== 2 && local
->iw_mode
== IW_MODE_INFRA
&&
465 memcmp(local
->preferred_ap
, "\x00\x00\x00\x00\x00\x00",
468 * Firmware seems to be getting into odd state in host_roaming
469 * mode 2 when hostscan is used without join command, so try
470 * to fix this by re-joining the current AP. This does not
471 * actually trigger a new association if the current AP is
472 * still in the scan results.
474 prism2_host_roaming(local
);
479 /* Called only as scheduled task after receiving info frames (used to avoid
480 * pending too much time in HW IRQ handler). */
481 static void handle_info_queue(struct work_struct
*work
)
483 local_info_t
*local
= container_of(work
, local_info_t
, info_queue
);
485 if (test_and_clear_bit(PRISM2_INFO_PENDING_LINKSTATUS
,
486 &local
->pending_info
))
487 handle_info_queue_linkstatus(local
);
489 if (test_and_clear_bit(PRISM2_INFO_PENDING_SCANRESULTS
,
490 &local
->pending_info
))
491 handle_info_queue_scanresults(local
);
493 #endif /* PRISM2_NO_STATION_MODES */
496 void hostap_info_init(local_info_t
*local
)
498 skb_queue_head_init(&local
->info_list
);
499 #ifndef PRISM2_NO_STATION_MODES
500 INIT_WORK(&local
->info_queue
, handle_info_queue
);
501 #endif /* PRISM2_NO_STATION_MODES */
505 EXPORT_SYMBOL(hostap_info_init
);
506 EXPORT_SYMBOL(hostap_info_process
);