1 /* Host AP driver Info Frame processing (part of hostap.o module) */
4 /* Called only as a tasklet (software IRQ) */
5 static void prism2_info_commtallies16(local_info_t *local, unsigned char *buf,
8 struct hfa384x_comm_tallies *tallies;
10 if (left < sizeof(struct hfa384x_comm_tallies)) {
11 printk(KERN_DEBUG "%s: too short (len=%d) commtallies "
12 "info frame\n", local->dev->name, left);
16 tallies = (struct hfa384x_comm_tallies *) buf;
17 #define ADD_COMM_TALLIES(name) \
18 local->comm_tallies.name += le16_to_cpu(tallies->name)
19 ADD_COMM_TALLIES(tx_unicast_frames);
20 ADD_COMM_TALLIES(tx_multicast_frames);
21 ADD_COMM_TALLIES(tx_fragments);
22 ADD_COMM_TALLIES(tx_unicast_octets);
23 ADD_COMM_TALLIES(tx_multicast_octets);
24 ADD_COMM_TALLIES(tx_deferred_transmissions);
25 ADD_COMM_TALLIES(tx_single_retry_frames);
26 ADD_COMM_TALLIES(tx_multiple_retry_frames);
27 ADD_COMM_TALLIES(tx_retry_limit_exceeded);
28 ADD_COMM_TALLIES(tx_discards);
29 ADD_COMM_TALLIES(rx_unicast_frames);
30 ADD_COMM_TALLIES(rx_multicast_frames);
31 ADD_COMM_TALLIES(rx_fragments);
32 ADD_COMM_TALLIES(rx_unicast_octets);
33 ADD_COMM_TALLIES(rx_multicast_octets);
34 ADD_COMM_TALLIES(rx_fcs_errors);
35 ADD_COMM_TALLIES(rx_discards_no_buffer);
36 ADD_COMM_TALLIES(tx_discards_wrong_sa);
37 ADD_COMM_TALLIES(rx_discards_wep_undecryptable);
38 ADD_COMM_TALLIES(rx_message_in_msg_fragments);
39 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments);
40 #undef ADD_COMM_TALLIES
44 /* Called only as a tasklet (software IRQ) */
45 static void prism2_info_commtallies32(local_info_t *local, unsigned char *buf,
48 struct hfa384x_comm_tallies32 *tallies;
50 if (left < sizeof(struct hfa384x_comm_tallies32)) {
51 printk(KERN_DEBUG "%s: too short (len=%d) commtallies32 "
52 "info frame\n", local->dev->name, left);
56 tallies = (struct hfa384x_comm_tallies32 *) buf;
57 #define ADD_COMM_TALLIES(name) \
58 local->comm_tallies.name += le32_to_cpu(tallies->name)
59 ADD_COMM_TALLIES(tx_unicast_frames);
60 ADD_COMM_TALLIES(tx_multicast_frames);
61 ADD_COMM_TALLIES(tx_fragments);
62 ADD_COMM_TALLIES(tx_unicast_octets);
63 ADD_COMM_TALLIES(tx_multicast_octets);
64 ADD_COMM_TALLIES(tx_deferred_transmissions);
65 ADD_COMM_TALLIES(tx_single_retry_frames);
66 ADD_COMM_TALLIES(tx_multiple_retry_frames);
67 ADD_COMM_TALLIES(tx_retry_limit_exceeded);
68 ADD_COMM_TALLIES(tx_discards);
69 ADD_COMM_TALLIES(rx_unicast_frames);
70 ADD_COMM_TALLIES(rx_multicast_frames);
71 ADD_COMM_TALLIES(rx_fragments);
72 ADD_COMM_TALLIES(rx_unicast_octets);
73 ADD_COMM_TALLIES(rx_multicast_octets);
74 ADD_COMM_TALLIES(rx_fcs_errors);
75 ADD_COMM_TALLIES(rx_discards_no_buffer);
76 ADD_COMM_TALLIES(tx_discards_wrong_sa);
77 ADD_COMM_TALLIES(rx_discards_wep_undecryptable);
78 ADD_COMM_TALLIES(rx_message_in_msg_fragments);
79 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments);
80 #undef ADD_COMM_TALLIES
84 /* Called only as a tasklet (software IRQ) */
85 static void prism2_info_commtallies(local_info_t *local, unsigned char *buf,
89 prism2_info_commtallies32(local, buf, left);
91 prism2_info_commtallies16(local, buf, left);
95 #ifndef PRISM2_NO_STATION_MODES
96 #ifndef PRISM2_NO_DEBUG
97 static const char* hfa384x_linkstatus_str(u16 linkstatus)
100 case HFA384X_LINKSTATUS_CONNECTED:
102 case HFA384X_LINKSTATUS_DISCONNECTED:
103 return "Disconnected";
104 case HFA384X_LINKSTATUS_AP_CHANGE:
105 return "Access point change";
106 case HFA384X_LINKSTATUS_AP_OUT_OF_RANGE:
107 return "Access point out of range";
108 case HFA384X_LINKSTATUS_AP_IN_RANGE:
109 return "Access point in range";
110 case HFA384X_LINKSTATUS_ASSOC_FAILED:
111 return "Association failed";
116 #endif /* PRISM2_NO_DEBUG */
119 /* Called only as a tasklet (software IRQ) */
120 static void prism2_info_linkstatus(local_info_t *local, unsigned char *buf,
126 /* Alloc new JoinRequests to occur since LinkStatus for the previous
127 * has been received */
128 local->last_join_time = 0;
131 printk(KERN_DEBUG "%s: invalid linkstatus info frame "
132 "length %d\n", local->dev->name, left);
136 non_sta_mode = local->iw_mode == IW_MODE_MASTER ||
137 local->iw_mode == IW_MODE_REPEAT ||
138 local->iw_mode == IW_MODE_MONITOR;
140 val = buf[0] | (buf[1] << 8);
141 if (!non_sta_mode || val != HFA384X_LINKSTATUS_DISCONNECTED) {
142 PDEBUG(DEBUG_EXTRA, "%s: LinkStatus=%d (%s)\n",
143 local->dev->name, val, hfa384x_linkstatus_str(val));
147 netif_carrier_on(local->dev);
148 netif_carrier_on(local->ddev);
152 /* Get current BSSID later in scheduled task */
153 set_bit(PRISM2_INFO_PENDING_LINKSTATUS, &local->pending_info);
154 local->prev_link_status = val;
155 schedule_work(&local->info_queue);
159 static void prism2_host_roaming(local_info_t *local)
161 struct hfa384x_join_request req;
162 struct net_device *dev = local->dev;
163 struct hfa384x_scan_result *selected, *entry;
167 if (local->last_join_time &&
168 time_before(jiffies, local->last_join_time + 10 * HZ)) {
169 PDEBUG(DEBUG_EXTRA, "%s: last join request has not yet been "
170 "completed - waiting for it before issuing new one\n",
175 /* ScanResults are sorted: first ESS results in decreasing signal
176 * quality then IBSS results in similar order.
177 * Trivial roaming policy: just select the first entry.
178 * This could probably be improved by adding hysteresis to limit
179 * number of handoffs, etc.
181 * Could do periodic RID_SCANREQUEST or Inquire F101 to get new
183 spin_lock_irqsave(&local->lock, flags);
184 if (local->last_scan_results == NULL ||
185 local->last_scan_results_count == 0) {
186 spin_unlock_irqrestore(&local->lock, flags);
187 PDEBUG(DEBUG_EXTRA, "%s: no scan results for host roaming\n",
192 selected = &local->last_scan_results[0];
194 if (local->preferred_ap[0] || local->preferred_ap[1] ||
195 local->preferred_ap[2] || local->preferred_ap[3] ||
196 local->preferred_ap[4] || local->preferred_ap[5]) {
197 /* Try to find preferred AP */
198 PDEBUG(DEBUG_EXTRA, "%s: Preferred AP BSSID " MACSTR "\n",
199 dev->name, MAC2STR(local->preferred_ap));
200 for (i = 0; i < local->last_scan_results_count; i++) {
201 entry = &local->last_scan_results[i];
202 if (memcmp(local->preferred_ap, entry->bssid, 6) == 0)
204 PDEBUG(DEBUG_EXTRA, "%s: using preferred AP "
205 "selection\n", dev->name);
212 memcpy(req.bssid, selected->bssid, 6);
213 req.channel = selected->chid;
214 spin_unlock_irqrestore(&local->lock, flags);
216 PDEBUG(DEBUG_EXTRA, "%s: JoinRequest: BSSID=" MACSTR " channel=%d\n",
217 dev->name, MAC2STR(req.bssid), le16_to_cpu(req.channel));
218 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
220 printk(KERN_DEBUG "%s: JoinRequest failed\n", dev->name);
222 local->last_join_time = jiffies;
226 static void hostap_report_scan_complete(local_info_t *local)
228 union iwreq_data wrqu;
230 /* Inform user space about new scan results (just empty event,
231 * SIOCGIWSCAN can be used to fetch data */
232 wrqu.data.length = 0;
234 wireless_send_event(local->dev, SIOCGIWSCAN, &wrqu, NULL);
236 /* Allow SIOCGIWSCAN handling to occur since we have received
238 local->scan_timestamp = 0;
242 /* Called only as a tasklet (software IRQ) */
243 static void prism2_info_scanresults(local_info_t *local, unsigned char *buf,
249 struct hfa384x_scan_result *results, *prev;
252 printk(KERN_DEBUG "%s: invalid scanresult info frame "
253 "length %d\n", local->dev->name, left);
262 new_count = left / sizeof(struct hfa384x_scan_result);
263 results = kmalloc(new_count * sizeof(struct hfa384x_scan_result),
267 memcpy(results, pos, new_count * sizeof(struct hfa384x_scan_result));
269 spin_lock_irqsave(&local->lock, flags);
270 local->last_scan_type = PRISM2_SCAN;
271 prev = local->last_scan_results;
272 local->last_scan_results = results;
273 local->last_scan_results_count = new_count;
274 spin_unlock_irqrestore(&local->lock, flags);
277 hostap_report_scan_complete(local);
279 /* Perform rest of ScanResults handling later in scheduled task */
280 set_bit(PRISM2_INFO_PENDING_SCANRESULTS, &local->pending_info);
281 schedule_work(&local->info_queue);
285 /* Called only as a tasklet (software IRQ) */
286 static void prism2_info_hostscanresults(local_info_t *local,
287 unsigned char *buf, int left)
289 int i, result_size, copy_len, new_count;
290 struct hfa384x_hostscan_result *results, *prev;
295 wake_up_interruptible(&local->hostscan_wq);
298 printk(KERN_DEBUG "%s: invalid hostscanresult info frame "
299 "length %d\n", local->dev->name, left);
304 copy_len = result_size = le16_to_cpu(*pos);
305 if (result_size == 0) {
306 printk(KERN_DEBUG "%s: invalid result_size (0) in "
307 "hostscanresults\n", local->dev->name);
310 if (copy_len > sizeof(struct hfa384x_hostscan_result))
311 copy_len = sizeof(struct hfa384x_hostscan_result);
318 new_count = left / result_size;
319 results = kmalloc(new_count * sizeof(struct hfa384x_hostscan_result),
323 memset(results, 0, new_count * sizeof(struct hfa384x_hostscan_result));
325 for (i = 0; i < new_count; i++) {
326 memcpy(&results[i], ptr, copy_len);
332 printk(KERN_DEBUG "%s: short HostScan result entry (%d/%d)\n",
333 local->dev->name, left, result_size);
336 spin_lock_irqsave(&local->lock, flags);
337 local->last_scan_type = PRISM2_HOSTSCAN;
338 prev = local->last_hostscan_results;
339 local->last_hostscan_results = results;
340 local->last_hostscan_results_count = new_count;
341 spin_unlock_irqrestore(&local->lock, flags);
344 hostap_report_scan_complete(local);
346 #endif /* PRISM2_NO_STATION_MODES */
349 /* Called only as a tasklet (software IRQ) */
350 void hostap_info_process(local_info_t *local, struct sk_buff *skb)
352 struct hfa384x_info_frame *info;
355 #ifndef PRISM2_NO_DEBUG
357 #endif /* PRISM2_NO_DEBUG */
359 info = (struct hfa384x_info_frame *) skb->data;
360 buf = skb->data + sizeof(*info);
361 left = skb->len - sizeof(*info);
363 switch (info->type) {
364 case HFA384X_INFO_COMMTALLIES:
365 prism2_info_commtallies(local, buf, left);
368 #ifndef PRISM2_NO_STATION_MODES
369 case HFA384X_INFO_LINKSTATUS:
370 prism2_info_linkstatus(local, buf, left);
373 case HFA384X_INFO_SCANRESULTS:
374 prism2_info_scanresults(local, buf, left);
377 case HFA384X_INFO_HOSTSCANRESULTS:
378 prism2_info_hostscanresults(local, buf, left);
380 #endif /* PRISM2_NO_STATION_MODES */
382 #ifndef PRISM2_NO_DEBUG
384 PDEBUG(DEBUG_EXTRA, "%s: INFO - len=%d type=0x%04x\n",
385 local->dev->name, info->len, info->type);
386 PDEBUG(DEBUG_EXTRA, "Unknown info frame:");
387 for (i = 0; i < (left < 100 ? left : 100); i++)
388 PDEBUG2(DEBUG_EXTRA, " %02x", buf[i]);
389 PDEBUG2(DEBUG_EXTRA, "\n");
391 #endif /* PRISM2_NO_DEBUG */
396 #ifndef PRISM2_NO_STATION_MODES
397 static void handle_info_queue_linkstatus(local_info_t *local)
399 int val = local->prev_link_status;
401 union iwreq_data wrqu;
404 val == HFA384X_LINKSTATUS_CONNECTED ||
405 val == HFA384X_LINKSTATUS_AP_CHANGE ||
406 val == HFA384X_LINKSTATUS_AP_IN_RANGE;
408 if (local->func->get_rid(local->dev, HFA384X_RID_CURRENTBSSID,
409 local->bssid, ETH_ALEN, 1) < 0) {
410 printk(KERN_DEBUG "%s: could not read CURRENTBSSID after "
411 "LinkStatus event\n", local->dev->name);
413 PDEBUG(DEBUG_EXTRA, "%s: LinkStatus: BSSID=" MACSTR "\n",
415 MAC2STR((unsigned char *) local->bssid));
416 if (local->wds_type & HOSTAP_WDS_AP_CLIENT)
417 hostap_add_sta(local->ap, local->bssid);
420 /* Get BSSID if we have a valid AP address */
422 netif_carrier_on(local->dev);
423 netif_carrier_on(local->ddev);
424 memcpy(wrqu.ap_addr.sa_data, local->bssid, ETH_ALEN);
426 netif_carrier_off(local->dev);
427 netif_carrier_off(local->ddev);
428 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
430 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
433 * Filter out sequential disconnect events in order not to cause a
434 * flood of SIOCGIWAP events that have a race condition with EAPOL
435 * frames and can confuse wpa_supplicant about the current association
438 if (connected || local->prev_linkstatus_connected)
439 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
440 local->prev_linkstatus_connected = connected;
444 static void handle_info_queue_scanresults(local_info_t *local)
446 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA)
447 prism2_host_roaming(local);
451 /* Called only as scheduled task after receiving info frames (used to avoid
452 * pending too much time in HW IRQ handler). */
453 static void handle_info_queue(void *data)
455 local_info_t *local = (local_info_t *) data;
457 if (test_and_clear_bit(PRISM2_INFO_PENDING_LINKSTATUS,
458 &local->pending_info))
459 handle_info_queue_linkstatus(local);
461 if (test_and_clear_bit(PRISM2_INFO_PENDING_SCANRESULTS,
462 &local->pending_info))
463 handle_info_queue_scanresults(local);
465 #endif /* PRISM2_NO_STATION_MODES */
468 void hostap_info_init(local_info_t *local)
470 skb_queue_head_init(&local->info_list);
471 #ifndef PRISM2_NO_STATION_MODES
472 INIT_WORK(&local->info_queue, handle_info_queue, local);
473 #endif /* PRISM2_NO_STATION_MODES */
477 EXPORT_SYMBOL(hostap_info_init);
478 EXPORT_SYMBOL(hostap_info_process);