/* * Copyright (c) 2008-2011 Atheros Communications Inc. * Copyright (c) 2011 Neratec Solutions AG * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* min and max gradients for defined FCC chirping pulses, given by * - 20MHz chirp width over a pulse width of 50us * - 5MHz chirp width over a pulse width of 100us
*/ staticconstint BIN_DELTA_MIN = 1; staticconstint BIN_DELTA_MAX = 10;
/* we need at least 3 deltas / 4 samples for a reliable chirp detection */ #define NUM_DIFFS 3 #define FFT_NUM_SAMPLES (NUM_DIFFS + 1)
/* Threshold for difference of delta peaks */ staticconstint MAX_DIFF = 2;
/* width range to be checked for chirping */ staticconstint MIN_CHIRP_PULSE_WIDTH = 20; staticconstint MAX_CHIRP_PULSE_WIDTH = 110;
staticint ath9k_get_max_index_ht40(struct ath9k_dfs_fft_40 *fft, bool is_ctl, bool is_ext)
{ constint DFS_UPPER_BIN_OFFSET = 64; /* if detected radar on both channels, select the significant one */ if (is_ctl && is_ext) { /* first check whether channels have 'strong' bins */
is_ctl = fft_bitmap_weight(fft->lower_bins) != 0;
is_ext = fft_bitmap_weight(fft->upper_bins) != 0;
/* if still unclear, take higher magnitude */ if (is_ctl && is_ext) { int mag_lower = fft_max_magnitude(fft->lower_bins); int mag_upper = fft_max_magnitude(fft->upper_bins); if (mag_upper > mag_lower)
is_ctl = false; else
is_ext = false;
}
} if (is_ctl) return fft_max_index(fft->lower_bins); return fft_max_index(fft->upper_bins) + DFS_UPPER_BIN_OFFSET;
} staticbool ath9k_check_chirping(struct ath_softc *sc, u8 *data, int datalen, bool is_ctl, bool is_ext)
{ int i; int max_bin[FFT_NUM_SAMPLES]; struct ath_hw *ah = sc->sc_ah; struct ath_common *common = ath9k_hw_common(ah); int prev_delta;
if (IS_CHAN_HT40(ah->curchan)) { struct ath9k_dfs_fft_40 *fft = (struct ath9k_dfs_fft_40 *) data; int num_fft_packets = datalen / sizeof(*fft); if (num_fft_packets == 0) returnfalse;
ath_dbg(common, DFS, "HT40: datalen=%d, num_fft_packets=%d\n",
datalen, num_fft_packets); if (num_fft_packets < FFT_NUM_SAMPLES) {
ath_dbg(common, DFS, "not enough packets for chirp\n"); returnfalse;
} /* HW sometimes adds 2 garbage bytes in front of FFT samples */ if ((datalen % sizeof(*fft)) == 2) {
fft = (struct ath9k_dfs_fft_40 *) (data + 2);
ath_dbg(common, DFS, "fixing datalen by 2\n");
} if (IS_CHAN_HT40MINUS(ah->curchan))
swap(is_ctl, is_ext);
for (i = 0; i < FFT_NUM_SAMPLES; i++)
max_bin[i] = ath9k_get_max_index_ht40(fft + i, is_ctl,
is_ext);
} else { struct ath9k_dfs_fft_20 *fft = (struct ath9k_dfs_fft_20 *) data; int num_fft_packets = datalen / sizeof(*fft); if (num_fft_packets == 0) returnfalse;
ath_dbg(common, DFS, "HT20: datalen=%d, num_fft_packets=%d\n",
datalen, num_fft_packets); if (num_fft_packets < FFT_NUM_SAMPLES) {
ath_dbg(common, DFS, "not enough packets for chirp\n"); returnfalse;
} /* in ht20, this is a 6-bit signed number => shift it to 0 */ for (i = 0; i < FFT_NUM_SAMPLES; i++)
max_bin[i] = fft_max_index(fft[i].lower_bins) ^ 0x20;
}
ath_dbg(common, DFS, "bin_max = [%d, %d, %d, %d]\n",
max_bin[0], max_bin[1], max_bin[2], max_bin[3]);
/* Check for chirp attributes within specs * a) delta of adjacent max_bins is within range * b) delta of adjacent deltas are within tolerance
*/
prev_delta = 0; for (i = 0; i < NUM_DIFFS; i++) { int ddelta = -1; int delta = max_bin[i + 1] - max_bin[i];
/* ensure gradient is within valid range */ if (abs(delta) < BIN_DELTA_MIN || abs(delta) > BIN_DELTA_MAX) {
ath_dbg(common, DFS, "CHIRP: invalid delta %d " "in sample %d\n", delta, i); returnfalse;
} if (i == 0) goto done;
ddelta = delta - prev_delta; if (abs(ddelta) > MAX_DIFF) {
ath_dbg(common, DFS, "CHIRP: ddelta %d too high\n",
ddelta); returnfalse;
}
done:
ath_dbg(common, DFS, "CHIRP - %d: delta=%d, ddelta=%d\n",
i, delta, ddelta);
prev_delta = delta;
} returntrue;
} /**** end: CHIRP **************************************************************/
/* * Only the last 2 bits of the BW info are relevant, they indicate * which channel the radar was detected in.
*/
ard->pulse_bw_info &= 0x03;
switch (ard->pulse_bw_info) { case PRI_CH_RADAR_FOUND: /* radar in ctrl channel */
dur = ard->pulse_length_pri;
DFS_STAT_INC(sc, pri_phy_errors); /* * cannot use ctrl channel RSSI * if extension channel is stronger
*/
rssi = (ard->ext_rssi >= (ard->rssi + 3)) ? 0 : ard->rssi; break; case EXT_CH_RADAR_FOUND: /* radar in extension channel */
dur = ard->pulse_length_ext;
DFS_STAT_INC(sc, ext_phy_errors); /* * cannot use extension channel RSSI * if control channel is stronger
*/
rssi = (ard->rssi >= (ard->ext_rssi + 12)) ? 0 : ard->ext_rssi; break; case (PRI_CH_RADAR_FOUND | EXT_CH_RADAR_FOUND): /* * Conducted testing, when pulse is on DC, both pri and ext * durations are reported to be same * * Radiated testing, when pulse is on DC, different pri and * ext durations are reported, so take the larger of the two
*/ if (ard->pulse_length_ext >= ard->pulse_length_pri)
dur = ard->pulse_length_ext; else
dur = ard->pulse_length_pri;
DFS_STAT_INC(sc, dc_phy_errors);
/* when both are present use stronger one */
rssi = max(ard->rssi, ard->ext_rssi); break; default: /* * Bogus bandwidth info was received in descriptor, * so ignore this PHY error
*/
DFS_STAT_INC(sc, bwinfo_discards); returnfalse;
}
if (rssi == 0) {
DFS_STAT_INC(sc, rssi_discards); returnfalse;
}
/* * hardware stores this as 8 bit signed value. * we will cap it at 0 if it is a negative number
*/ if (ard.rssi & 0x80)
ard.rssi = 0; if (ard.ext_rssi & 0x80)
ard.ext_rssi = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.