1 /* Helpers for managing scan queues
3 * See copyright notice in main.c
6 #include <linux/kernel.h>
7 #include <linux/string.h>
8 #include <linux/ieee80211.h>
9 #include <net/cfg80211.h>
17 #define ZERO_DBM_OFFSET 0x95
18 #define MAX_SIGNAL_LEVEL 0x8A
19 #define MIN_SIGNAL_LEVEL 0x2F
21 #define SIGNAL_TO_DBM(x) \
22 (clamp_t(s32, (x), MIN_SIGNAL_LEVEL, MAX_SIGNAL_LEVEL) \
24 #define SIGNAL_TO_MBM(x) (SIGNAL_TO_DBM(x) * 100)
26 static int symbol_build_supp_rates(u8
*buf
, const __le16
*rates
)
31 buf
[0] = WLAN_EID_SUPP_RATES
;
32 for (i
= 0; i
< 5; i
++) {
33 rate
= le16_to_cpu(rates
[i
]);
44 static int prism_build_supp_rates(u8
*buf
, const u8
*rates
)
48 buf
[0] = WLAN_EID_SUPP_RATES
;
49 for (i
= 0; i
< 8; i
++) {
53 buf
[i
+ 2] = rates
[i
];
57 /* We might still have another 2 rates, which need to go in
58 * extended supported rates */
59 if (i
== 8 && rates
[i
] > 0) {
60 buf
[10] = WLAN_EID_EXT_SUPP_RATES
;
65 buf
[i
+ 2] = rates
[i
];
70 return (i
< 8) ? i
+ 2 : i
+ 4;
73 static void orinoco_add_hostscan_result(struct orinoco_private
*priv
,
74 const union hermes_scan_info
*bss
)
76 struct wiphy
*wiphy
= priv_to_wiphy(priv
);
77 struct ieee80211_channel
*channel
;
88 len
= le16_to_cpu(bss
->a
.essid_len
);
90 /* Reconstruct SSID and bitrate IEs to pass up */
91 ie_buf
[0] = WLAN_EID_SSID
;
93 memcpy(&ie_buf
[2], bss
->a
.essid
, len
);
95 ie
= ie_buf
+ len
+ 2;
96 ie_len
= ie_buf
[1] + 2;
97 switch (priv
->firmware_type
) {
98 case FIRMWARE_TYPE_SYMBOL
:
99 ie_len
+= symbol_build_supp_rates(ie
, bss
->s
.rates
);
102 case FIRMWARE_TYPE_INTERSIL
:
103 ie_len
+= prism_build_supp_rates(ie
, bss
->p
.rates
);
106 case FIRMWARE_TYPE_AGERE
:
111 freq
= ieee80211_dsss_chan_to_freq(le16_to_cpu(bss
->a
.channel
));
112 channel
= ieee80211_get_channel(wiphy
, freq
);
114 capability
= le16_to_cpu(bss
->a
.capabilities
);
115 beacon_interval
= le16_to_cpu(bss
->a
.beacon_interv
);
116 signal
= SIGNAL_TO_MBM(le16_to_cpu(bss
->a
.level
));
118 cfg80211_inform_bss(wiphy
, channel
, bss
->a
.bssid
, timestamp
,
119 capability
, beacon_interval
, ie_buf
, ie_len
,
123 void orinoco_add_extscan_result(struct orinoco_private
*priv
,
124 struct agere_ext_scan_info
*bss
,
127 struct wiphy
*wiphy
= priv_to_wiphy(priv
);
128 struct ieee80211_channel
*channel
;
137 ie_len
= len
- sizeof(*bss
);
138 ie
= orinoco_get_ie(bss
->data
, ie_len
, WLAN_EID_DS_PARAMS
);
139 chan
= ie
? ie
[2] : 0;
140 freq
= ieee80211_dsss_chan_to_freq(chan
);
141 channel
= ieee80211_get_channel(wiphy
, freq
);
143 timestamp
= le64_to_cpu(bss
->timestamp
);
144 capability
= le16_to_cpu(bss
->capabilities
);
145 beacon_interval
= le16_to_cpu(bss
->beacon_interval
);
147 signal
= SIGNAL_TO_MBM(bss
->level
);
149 cfg80211_inform_bss(wiphy
, channel
, bss
->bssid
, timestamp
,
150 capability
, beacon_interval
, ie
, ie_len
,
154 void orinoco_add_hostscan_results(struct orinoco_private
*priv
,
158 int offset
; /* In the scan data */
162 switch (priv
->firmware_type
) {
163 case FIRMWARE_TYPE_AGERE
:
164 atom_len
= sizeof(struct agere_scan_apinfo
);
168 case FIRMWARE_TYPE_SYMBOL
:
169 /* Lack of documentation necessitates this hack.
170 * Different firmwares have 68 or 76 byte long atoms.
171 * We try modulo first. If the length divides by both,
172 * we check what would be the channel in the second
173 * frame for a 68-byte atom. 76-byte atoms have 0 there.
174 * Valid channel cannot be 0. */
179 else if (len
>= 1292 && buf
[68] == 0)
186 case FIRMWARE_TYPE_INTERSIL
:
188 if (priv
->has_hostscan
) {
189 atom_len
= le16_to_cpup((__le16
*)buf
);
190 /* Sanity check for atom_len */
191 if (atom_len
< sizeof(struct prism2_scan_apinfo
)) {
192 printk(KERN_ERR
"%s: Invalid atom_len in scan "
193 "data: %zu\n", priv
->ndev
->name
,
199 atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
207 /* Check that we got an whole number of atoms */
208 if ((len
- offset
) % atom_len
) {
209 printk(KERN_ERR
"%s: Unexpected scan data length %zu, "
210 "atom_len %zu, offset %d\n", priv
->ndev
->name
, len
,
216 /* Process the entries one by one */
217 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
218 union hermes_scan_info
*atom
;
220 atom
= (union hermes_scan_info
*) (buf
+ offset
);
222 orinoco_add_hostscan_result(priv
, atom
);
226 if (priv
->scan_request
) {
227 cfg80211_scan_done(priv
->scan_request
, abort
);
228 priv
->scan_request
= NULL
;