1 /* Host AP driver Info Frame processing (part of hostap.o module) */
3 #include "hostap_wlan.h"
7 /* Called only as a tasklet (software IRQ) */
8 static void prism2_info_commtallies16(local_info_t
*local
, unsigned char *buf
,
11 struct hfa384x_comm_tallies
*tallies
;
13 if (left
< sizeof(struct hfa384x_comm_tallies
)) {
14 printk(KERN_DEBUG
"%s: too short (len=%d) commtallies "
15 "info frame\n", local
->dev
->name
, left
);
19 tallies
= (struct hfa384x_comm_tallies
*) buf
;
20 #define ADD_COMM_TALLIES(name) \
21 local->comm_tallies.name += le16_to_cpu(tallies->name)
22 ADD_COMM_TALLIES(tx_unicast_frames
);
23 ADD_COMM_TALLIES(tx_multicast_frames
);
24 ADD_COMM_TALLIES(tx_fragments
);
25 ADD_COMM_TALLIES(tx_unicast_octets
);
26 ADD_COMM_TALLIES(tx_multicast_octets
);
27 ADD_COMM_TALLIES(tx_deferred_transmissions
);
28 ADD_COMM_TALLIES(tx_single_retry_frames
);
29 ADD_COMM_TALLIES(tx_multiple_retry_frames
);
30 ADD_COMM_TALLIES(tx_retry_limit_exceeded
);
31 ADD_COMM_TALLIES(tx_discards
);
32 ADD_COMM_TALLIES(rx_unicast_frames
);
33 ADD_COMM_TALLIES(rx_multicast_frames
);
34 ADD_COMM_TALLIES(rx_fragments
);
35 ADD_COMM_TALLIES(rx_unicast_octets
);
36 ADD_COMM_TALLIES(rx_multicast_octets
);
37 ADD_COMM_TALLIES(rx_fcs_errors
);
38 ADD_COMM_TALLIES(rx_discards_no_buffer
);
39 ADD_COMM_TALLIES(tx_discards_wrong_sa
);
40 ADD_COMM_TALLIES(rx_discards_wep_undecryptable
);
41 ADD_COMM_TALLIES(rx_message_in_msg_fragments
);
42 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments
);
43 #undef ADD_COMM_TALLIES
47 /* Called only as a tasklet (software IRQ) */
48 static void prism2_info_commtallies32(local_info_t
*local
, unsigned char *buf
,
51 struct hfa384x_comm_tallies32
*tallies
;
53 if (left
< sizeof(struct hfa384x_comm_tallies32
)) {
54 printk(KERN_DEBUG
"%s: too short (len=%d) commtallies32 "
55 "info frame\n", local
->dev
->name
, left
);
59 tallies
= (struct hfa384x_comm_tallies32
*) buf
;
60 #define ADD_COMM_TALLIES(name) \
61 local->comm_tallies.name += le32_to_cpu(tallies->name)
62 ADD_COMM_TALLIES(tx_unicast_frames
);
63 ADD_COMM_TALLIES(tx_multicast_frames
);
64 ADD_COMM_TALLIES(tx_fragments
);
65 ADD_COMM_TALLIES(tx_unicast_octets
);
66 ADD_COMM_TALLIES(tx_multicast_octets
);
67 ADD_COMM_TALLIES(tx_deferred_transmissions
);
68 ADD_COMM_TALLIES(tx_single_retry_frames
);
69 ADD_COMM_TALLIES(tx_multiple_retry_frames
);
70 ADD_COMM_TALLIES(tx_retry_limit_exceeded
);
71 ADD_COMM_TALLIES(tx_discards
);
72 ADD_COMM_TALLIES(rx_unicast_frames
);
73 ADD_COMM_TALLIES(rx_multicast_frames
);
74 ADD_COMM_TALLIES(rx_fragments
);
75 ADD_COMM_TALLIES(rx_unicast_octets
);
76 ADD_COMM_TALLIES(rx_multicast_octets
);
77 ADD_COMM_TALLIES(rx_fcs_errors
);
78 ADD_COMM_TALLIES(rx_discards_no_buffer
);
79 ADD_COMM_TALLIES(tx_discards_wrong_sa
);
80 ADD_COMM_TALLIES(rx_discards_wep_undecryptable
);
81 ADD_COMM_TALLIES(rx_message_in_msg_fragments
);
82 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments
);
83 #undef ADD_COMM_TALLIES
87 /* Called only as a tasklet (software IRQ) */
88 static void prism2_info_commtallies(local_info_t
*local
, unsigned char *buf
,
92 prism2_info_commtallies32(local
, buf
, left
);
94 prism2_info_commtallies16(local
, buf
, left
);
98 #ifndef PRISM2_NO_STATION_MODES
99 #ifndef PRISM2_NO_DEBUG
100 static const char* hfa384x_linkstatus_str(u16 linkstatus
)
102 switch (linkstatus
) {
103 case HFA384X_LINKSTATUS_CONNECTED
:
105 case HFA384X_LINKSTATUS_DISCONNECTED
:
106 return "Disconnected";
107 case HFA384X_LINKSTATUS_AP_CHANGE
:
108 return "Access point change";
109 case HFA384X_LINKSTATUS_AP_OUT_OF_RANGE
:
110 return "Access point out of range";
111 case HFA384X_LINKSTATUS_AP_IN_RANGE
:
112 return "Access point in range";
113 case HFA384X_LINKSTATUS_ASSOC_FAILED
:
114 return "Association failed";
119 #endif /* PRISM2_NO_DEBUG */
122 /* Called only as a tasklet (software IRQ) */
123 static void prism2_info_linkstatus(local_info_t
*local
, unsigned char *buf
,
129 /* Alloc new JoinRequests to occur since LinkStatus for the previous
130 * has been received */
131 local
->last_join_time
= 0;
134 printk(KERN_DEBUG
"%s: invalid linkstatus info frame "
135 "length %d\n", local
->dev
->name
, left
);
139 non_sta_mode
= local
->iw_mode
== IW_MODE_MASTER
||
140 local
->iw_mode
== IW_MODE_REPEAT
||
141 local
->iw_mode
== IW_MODE_MONITOR
;
143 val
= buf
[0] | (buf
[1] << 8);
144 if (!non_sta_mode
|| val
!= HFA384X_LINKSTATUS_DISCONNECTED
) {
145 PDEBUG(DEBUG_EXTRA
, "%s: LinkStatus=%d (%s)\n",
146 local
->dev
->name
, val
, hfa384x_linkstatus_str(val
));
150 netif_carrier_on(local
->dev
);
151 netif_carrier_on(local
->ddev
);
155 /* Get current BSSID later in scheduled task */
156 set_bit(PRISM2_INFO_PENDING_LINKSTATUS
, &local
->pending_info
);
157 local
->prev_link_status
= val
;
158 schedule_work(&local
->info_queue
);
162 static void prism2_host_roaming(local_info_t
*local
)
164 struct hfa384x_join_request req
;
165 struct net_device
*dev
= local
->dev
;
166 struct hfa384x_hostscan_result
*selected
, *entry
;
169 DECLARE_MAC_BUF(mac
);
171 if (local
->last_join_time
&&
172 time_before(jiffies
, local
->last_join_time
+ 10 * HZ
)) {
173 PDEBUG(DEBUG_EXTRA
, "%s: last join request has not yet been "
174 "completed - waiting for it before issuing new one\n",
179 /* ScanResults are sorted: first ESS results in decreasing signal
180 * quality then IBSS results in similar order.
181 * Trivial roaming policy: just select the first entry.
182 * This could probably be improved by adding hysteresis to limit
183 * number of handoffs, etc.
185 * Could do periodic RID_SCANREQUEST or Inquire F101 to get new
187 spin_lock_irqsave(&local
->lock
, flags
);
188 if (local
->last_scan_results
== NULL
||
189 local
->last_scan_results_count
== 0) {
190 spin_unlock_irqrestore(&local
->lock
, flags
);
191 PDEBUG(DEBUG_EXTRA
, "%s: no scan results for host roaming\n",
196 selected
= &local
->last_scan_results
[0];
198 if (local
->preferred_ap
[0] || local
->preferred_ap
[1] ||
199 local
->preferred_ap
[2] || local
->preferred_ap
[3] ||
200 local
->preferred_ap
[4] || local
->preferred_ap
[5]) {
201 /* Try to find preferred AP */
202 PDEBUG(DEBUG_EXTRA
, "%s: Preferred AP BSSID "
204 dev
->name
, print_mac(mac
, local
->preferred_ap
));
205 for (i
= 0; i
< local
->last_scan_results_count
; i
++) {
206 entry
= &local
->last_scan_results
[i
];
207 if (memcmp(local
->preferred_ap
, entry
->bssid
, 6) == 0)
209 PDEBUG(DEBUG_EXTRA
, "%s: using preferred AP "
210 "selection\n", dev
->name
);
217 memcpy(req
.bssid
, selected
->bssid
, 6);
218 req
.channel
= selected
->chid
;
219 spin_unlock_irqrestore(&local
->lock
, flags
);
221 PDEBUG(DEBUG_EXTRA
, "%s: JoinRequest: BSSID=%s"
223 dev
->name
, print_mac(mac
, req
.bssid
), le16_to_cpu(req
.channel
));
224 if (local
->func
->set_rid(dev
, HFA384X_RID_JOINREQUEST
, &req
,
226 printk(KERN_DEBUG
"%s: JoinRequest failed\n", dev
->name
);
228 local
->last_join_time
= jiffies
;
232 static void hostap_report_scan_complete(local_info_t
*local
)
234 union iwreq_data wrqu
;
236 /* Inform user space about new scan results (just empty event,
237 * SIOCGIWSCAN can be used to fetch data */
238 wrqu
.data
.length
= 0;
240 wireless_send_event(local
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
242 /* Allow SIOCGIWSCAN handling to occur since we have received
244 local
->scan_timestamp
= 0;
248 /* Called only as a tasklet (software IRQ) */
249 static void prism2_info_scanresults(local_info_t
*local
, unsigned char *buf
,
255 struct hfa384x_scan_result
*res
;
256 struct hfa384x_hostscan_result
*results
, *prev
;
259 printk(KERN_DEBUG
"%s: invalid scanresult info frame "
260 "length %d\n", local
->dev
->name
, left
);
269 new_count
= left
/ sizeof(struct hfa384x_scan_result
);
270 results
= kmalloc(new_count
* sizeof(struct hfa384x_hostscan_result
),
275 /* Convert to hostscan result format. */
276 res
= (struct hfa384x_scan_result
*) pos
;
277 for (i
= 0; i
< new_count
; i
++) {
278 memcpy(&results
[i
], &res
[i
],
279 sizeof(struct hfa384x_scan_result
));
283 spin_lock_irqsave(&local
->lock
, flags
);
284 local
->last_scan_type
= PRISM2_SCAN
;
285 prev
= local
->last_scan_results
;
286 local
->last_scan_results
= results
;
287 local
->last_scan_results_count
= new_count
;
288 spin_unlock_irqrestore(&local
->lock
, flags
);
291 hostap_report_scan_complete(local
);
293 /* Perform rest of ScanResults handling later in scheduled task */
294 set_bit(PRISM2_INFO_PENDING_SCANRESULTS
, &local
->pending_info
);
295 schedule_work(&local
->info_queue
);
299 /* Called only as a tasklet (software IRQ) */
300 static void prism2_info_hostscanresults(local_info_t
*local
,
301 unsigned char *buf
, int left
)
303 int i
, result_size
, copy_len
, new_count
;
304 struct hfa384x_hostscan_result
*results
, *prev
;
309 wake_up_interruptible(&local
->hostscan_wq
);
312 printk(KERN_DEBUG
"%s: invalid hostscanresult info frame "
313 "length %d\n", local
->dev
->name
, left
);
318 copy_len
= result_size
= le16_to_cpu(*pos
);
319 if (result_size
== 0) {
320 printk(KERN_DEBUG
"%s: invalid result_size (0) in "
321 "hostscanresults\n", local
->dev
->name
);
324 if (copy_len
> sizeof(struct hfa384x_hostscan_result
))
325 copy_len
= sizeof(struct hfa384x_hostscan_result
);
332 new_count
= left
/ result_size
;
333 results
= kcalloc(new_count
, sizeof(struct hfa384x_hostscan_result
),
338 for (i
= 0; i
< new_count
; i
++) {
339 memcpy(&results
[i
], ptr
, copy_len
);
345 printk(KERN_DEBUG
"%s: short HostScan result entry (%d/%d)\n",
346 local
->dev
->name
, left
, result_size
);
349 spin_lock_irqsave(&local
->lock
, flags
);
350 local
->last_scan_type
= PRISM2_HOSTSCAN
;
351 prev
= local
->last_scan_results
;
352 local
->last_scan_results
= results
;
353 local
->last_scan_results_count
= new_count
;
354 spin_unlock_irqrestore(&local
->lock
, flags
);
357 hostap_report_scan_complete(local
);
359 #endif /* PRISM2_NO_STATION_MODES */
362 /* Called only as a tasklet (software IRQ) */
363 void hostap_info_process(local_info_t
*local
, struct sk_buff
*skb
)
365 struct hfa384x_info_frame
*info
;
368 #ifndef PRISM2_NO_DEBUG
370 #endif /* PRISM2_NO_DEBUG */
372 info
= (struct hfa384x_info_frame
*) skb
->data
;
373 buf
= skb
->data
+ sizeof(*info
);
374 left
= skb
->len
- sizeof(*info
);
376 switch (info
->type
) {
377 case HFA384X_INFO_COMMTALLIES
:
378 prism2_info_commtallies(local
, buf
, left
);
381 #ifndef PRISM2_NO_STATION_MODES
382 case HFA384X_INFO_LINKSTATUS
:
383 prism2_info_linkstatus(local
, buf
, left
);
386 case HFA384X_INFO_SCANRESULTS
:
387 prism2_info_scanresults(local
, buf
, left
);
390 case HFA384X_INFO_HOSTSCANRESULTS
:
391 prism2_info_hostscanresults(local
, buf
, left
);
393 #endif /* PRISM2_NO_STATION_MODES */
395 #ifndef PRISM2_NO_DEBUG
397 PDEBUG(DEBUG_EXTRA
, "%s: INFO - len=%d type=0x%04x\n",
398 local
->dev
->name
, info
->len
, info
->type
);
399 PDEBUG(DEBUG_EXTRA
, "Unknown info frame:");
400 for (i
= 0; i
< (left
< 100 ? left
: 100); i
++)
401 PDEBUG2(DEBUG_EXTRA
, " %02x", buf
[i
]);
402 PDEBUG2(DEBUG_EXTRA
, "\n");
404 #endif /* PRISM2_NO_DEBUG */
409 #ifndef PRISM2_NO_STATION_MODES
410 static void handle_info_queue_linkstatus(local_info_t
*local
)
412 int val
= local
->prev_link_status
;
414 union iwreq_data wrqu
;
415 DECLARE_MAC_BUF(mac
);
418 val
== HFA384X_LINKSTATUS_CONNECTED
||
419 val
== HFA384X_LINKSTATUS_AP_CHANGE
||
420 val
== HFA384X_LINKSTATUS_AP_IN_RANGE
;
422 if (local
->func
->get_rid(local
->dev
, HFA384X_RID_CURRENTBSSID
,
423 local
->bssid
, ETH_ALEN
, 1) < 0) {
424 printk(KERN_DEBUG
"%s: could not read CURRENTBSSID after "
425 "LinkStatus event\n", local
->dev
->name
);
427 PDEBUG(DEBUG_EXTRA
, "%s: LinkStatus: BSSID="
430 print_mac(mac
, (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
);