1 /* Helpers for managing scan queues
3 * See copyright notice in main.c
7 #include <linux/kernel.h>
8 #include <linux/string.h>
9 #include <linux/ieee80211.h>
10 #include <net/cfg80211.h>
18 #define ZERO_DBM_OFFSET 0x95
19 #define MAX_SIGNAL_LEVEL 0x8A
20 #define MIN_SIGNAL_LEVEL 0x2F
22 #define SIGNAL_TO_DBM(x) \
23 (clamp_t(s32, (x), MIN_SIGNAL_LEVEL, MAX_SIGNAL_LEVEL) \
25 #define SIGNAL_TO_MBM(x) (SIGNAL_TO_DBM(x) * 100)
27 static int symbol_build_supp_rates(u8
*buf
, const __le16
*rates
)
32 buf
[0] = WLAN_EID_SUPP_RATES
;
33 for (i
= 0; i
< 5; i
++) {
34 rate
= le16_to_cpu(rates
[i
]);
45 static int prism_build_supp_rates(u8
*buf
, const u8
*rates
)
49 buf
[0] = WLAN_EID_SUPP_RATES
;
50 for (i
= 0; i
< 8; i
++) {
54 buf
[i
+ 2] = rates
[i
];
58 /* We might still have another 2 rates, which need to go in
59 * extended supported rates */
60 if (i
== 8 && rates
[i
] > 0) {
61 buf
[10] = WLAN_EID_EXT_SUPP_RATES
;
66 buf
[i
+ 2] = rates
[i
];
71 return (i
< 8) ? i
+ 2 : i
+ 4;
74 static void orinoco_add_hostscan_result(struct orinoco_private
*priv
,
75 const union hermes_scan_info
*bss
)
77 struct wiphy
*wiphy
= priv_to_wiphy(priv
);
78 struct ieee80211_channel
*channel
;
79 struct cfg80211_bss
*cbss
;
90 len
= le16_to_cpu(bss
->a
.essid_len
);
92 /* Reconstruct SSID and bitrate IEs to pass up */
93 ie_buf
[0] = WLAN_EID_SSID
;
95 memcpy(&ie_buf
[2], bss
->a
.essid
, len
);
97 ie
= ie_buf
+ len
+ 2;
98 ie_len
= ie_buf
[1] + 2;
99 switch (priv
->firmware_type
) {
100 case FIRMWARE_TYPE_SYMBOL
:
101 ie_len
+= symbol_build_supp_rates(ie
, bss
->s
.rates
);
104 case FIRMWARE_TYPE_INTERSIL
:
105 ie_len
+= prism_build_supp_rates(ie
, bss
->p
.rates
);
108 case FIRMWARE_TYPE_AGERE
:
113 freq
= ieee80211_channel_to_frequency(
114 le16_to_cpu(bss
->a
.channel
), IEEE80211_BAND_2GHZ
);
115 channel
= ieee80211_get_channel(wiphy
, freq
);
117 printk(KERN_DEBUG
"Invalid channel designation %04X(%04X)",
118 bss
->a
.channel
, freq
);
119 return; /* Then ignore it for now */
122 capability
= le16_to_cpu(bss
->a
.capabilities
);
123 beacon_interval
= le16_to_cpu(bss
->a
.beacon_interv
);
124 signal
= SIGNAL_TO_MBM(le16_to_cpu(bss
->a
.level
));
126 cbss
= cfg80211_inform_bss(wiphy
, channel
, bss
->a
.bssid
, timestamp
,
127 capability
, beacon_interval
, ie_buf
, ie_len
,
129 cfg80211_put_bss(wiphy
, cbss
);
132 void orinoco_add_extscan_result(struct orinoco_private
*priv
,
133 struct agere_ext_scan_info
*bss
,
136 struct wiphy
*wiphy
= priv_to_wiphy(priv
);
137 struct ieee80211_channel
*channel
;
138 struct cfg80211_bss
*cbss
;
147 ie_len
= len
- sizeof(*bss
);
148 ie
= cfg80211_find_ie(WLAN_EID_DS_PARAMS
, bss
->data
, ie_len
);
149 chan
= ie
? ie
[2] : 0;
150 freq
= ieee80211_channel_to_frequency(chan
, IEEE80211_BAND_2GHZ
);
151 channel
= ieee80211_get_channel(wiphy
, freq
);
153 timestamp
= le64_to_cpu(bss
->timestamp
);
154 capability
= le16_to_cpu(bss
->capabilities
);
155 beacon_interval
= le16_to_cpu(bss
->beacon_interval
);
157 signal
= SIGNAL_TO_MBM(bss
->level
);
159 cbss
= cfg80211_inform_bss(wiphy
, channel
, bss
->bssid
, timestamp
,
160 capability
, beacon_interval
, ie
, ie_len
,
162 cfg80211_put_bss(wiphy
, cbss
);
165 void orinoco_add_hostscan_results(struct orinoco_private
*priv
,
169 int offset
; /* In the scan data */
173 switch (priv
->firmware_type
) {
174 case FIRMWARE_TYPE_AGERE
:
175 atom_len
= sizeof(struct agere_scan_apinfo
);
179 case FIRMWARE_TYPE_SYMBOL
:
180 /* Lack of documentation necessitates this hack.
181 * Different firmwares have 68 or 76 byte long atoms.
182 * We try modulo first. If the length divides by both,
183 * we check what would be the channel in the second
184 * frame for a 68-byte atom. 76-byte atoms have 0 there.
185 * Valid channel cannot be 0. */
190 else if (len
>= 1292 && buf
[68] == 0)
197 case FIRMWARE_TYPE_INTERSIL
:
199 if (priv
->has_hostscan
) {
200 atom_len
= le16_to_cpup((__le16
*)buf
);
201 /* Sanity check for atom_len */
202 if (atom_len
< sizeof(struct prism2_scan_apinfo
)) {
203 printk(KERN_ERR
"%s: Invalid atom_len in scan "
204 "data: %zu\n", priv
->ndev
->name
,
210 atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
218 /* Check that we got an whole number of atoms */
219 if ((len
- offset
) % atom_len
) {
220 printk(KERN_ERR
"%s: Unexpected scan data length %zu, "
221 "atom_len %zu, offset %d\n", priv
->ndev
->name
, len
,
227 /* Process the entries one by one */
228 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
229 union hermes_scan_info
*atom
;
231 atom
= (union hermes_scan_info
*) (buf
+ offset
);
233 orinoco_add_hostscan_result(priv
, atom
);
237 if (priv
->scan_request
) {
238 cfg80211_scan_done(priv
->scan_request
, abort
);
239 priv
->scan_request
= NULL
;
243 void orinoco_scan_done(struct orinoco_private
*priv
, bool abort
)
245 if (priv
->scan_request
) {
246 cfg80211_scan_done(priv
->scan_request
, abort
);
247 priv
->scan_request
= NULL
;