Commit c515c152 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Fix parsing of kernel frequency information.

The kernel encodes frequency information as a pair of a mantissa and
an exponent.  The previous code only dealt with exponent being 0 or 1.
We now deal with exponents up to 6.
parent 84d7cbbe
...@@ -769,17 +769,21 @@ freq_to_chan(struct iw_freq *freq) ...@@ -769,17 +769,21 @@ freq_to_chan(struct iw_freq *freq)
{ {
int m = freq->m, e = freq->e; int m = freq->m, e = freq->e;
/* Go figure. */ /* If exponent is 0, assume the channel is encoded directly in m. */
if(e == 0 && m > 0 && m < 1000) if(e == 0 && m > 0 && m < 254)
return m; return m;
if(e == 1) { if(e <= 6) {
/* m is in units of 10 Hz, so this encodes 1 MHz */ int mega, step, c, i;
int mega = 100000;
/* This encodes 1 MHz */
mega = 1000000;
for(i = 0; i < e; i++)
mega /= 10;
/* Channels 1 through 13 are 5 MHz apart, with channel 1 at 2412. */ /* Channels 1 through 13 are 5 MHz apart, with channel 1 at 2412. */
int step = 5 * mega; step = 5 * mega;
int c = 1 + (m - 2412 * mega + step / 2) / step; c = 1 + (m - 2412 * mega + step / 2) / step;
if(c >= 1 && c <= 13) if(c >= 1 && c <= 13)
return c; return c;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment