2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25 *************************************************************************
35 -------- ---------- ----------------------------------------------
36 Fonchi 03-12-2007 created
39 #include "../rt_config.h"
41 typedef struct _RADAR_DURATION_TABLE
44 ULONG RadarSignalDuration
;
46 } RADAR_DURATION_TABLE
, *PRADAR_DURATION_TABLE
;
49 static UCHAR RdIdleTimeTable
[MAX_RD_REGION
][4] =
51 {9, 250, 250, 250}, // CE
52 {4, 250, 250, 250}, // FCC
53 {4, 250, 250, 250}, // JAP
54 {15, 250, 250, 250}, // JAP_W53
55 {4, 250, 250, 250} // JAP_W56
59 ========================================================================
62 Bbp Radar detection routine
65 pAd Pointer to our adapter
69 ========================================================================
71 VOID
BbpRadarDetectionStart(
76 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, 114, 0x02);
77 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, 121, 0x20);
78 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, 122, 0x00);
79 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, 123, 0x08/*0x80*/);
80 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, 124, 0x28);
81 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd
, 125, 0xff);
83 RadarPeriod
= ((UINT
)RdIdleTimeTable
[pAd
->CommonCfg
.RadarDetect
.RDDurRegion
][0] + (UINT
)pAd
->CommonCfg
.RadarDetect
.DfsSessionTime
) < 250 ?
84 (RdIdleTimeTable
[pAd
->CommonCfg
.RadarDetect
.RDDurRegion
][0] + pAd
->CommonCfg
.RadarDetect
.DfsSessionTime
) : 250;
86 RTMP_IO_WRITE8(pAd
, 0x7020, 0x1d);
87 RTMP_IO_WRITE8(pAd
, 0x7021, 0x40);
89 RadarDetectionStart(pAd
, 0, RadarPeriod
);
94 ========================================================================
97 Bbp Radar detection routine
100 pAd Pointer to our adapter
104 ========================================================================
106 VOID
BbpRadarDetectionStop(
107 IN PRTMP_ADAPTER pAd
)
109 RTMP_IO_WRITE8(pAd
, 0x7020, 0x1d);
110 RTMP_IO_WRITE8(pAd
, 0x7021, 0x60);
112 RadarDetectionStop(pAd
);
117 ========================================================================
120 Radar detection routine
123 pAd Pointer to our adapter
127 ========================================================================
129 VOID
RadarDetectionStart(
130 IN PRTMP_ADAPTER pAd
,
131 IN BOOLEAN CTSProtect
,
134 UINT8 DfsActiveTime
= (pAd
->CommonCfg
.RadarDetect
.DfsSessionTime
& 0x1f);
135 UINT8 CtsProtect
= (CTSProtect
== 1) ? 0x02 : 0x01; // CTS protect.
139 switch(pAd
->CommonCfg
.RadarDetect
.RDDurRegion
)
157 // send start-RD with CTS protection command to MCU
158 // highbyte [7] reserve
159 // highbyte [6:5] 0x: stop Carrier/Radar detection
160 // highbyte [10]: Start Carrier/Radar detection without CTS protection, 11: Start Carrier/Radar detection with CTS protection
161 // highbyte [4:0] Radar/carrier detection duration. In 1ms.
163 // lowbyte [7:0] Radar/carrier detection period, in 1ms.
164 AsicSendCommandToMcu(pAd
, 0x60, 0xff, CTSPeriod
, DfsActiveTime
| (CtsProtect
<< 5));
165 //AsicSendCommandToMcu(pAd, 0x63, 0xff, 10, 0);
171 ========================================================================
174 Radar detection routine
177 pAd Pointer to our adapter
180 TRUE Found radar signal
181 FALSE Not found radar signal
183 ========================================================================
185 VOID
RadarDetectionStop(
186 IN PRTMP_ADAPTER pAd
)
188 DBGPRINT(RT_DEBUG_TRACE
,("RadarDetectionStop.\n"));
189 AsicSendCommandToMcu(pAd
, 0x60, 0xff, 0x00, 0x00); // send start-RD with CTS protection command to MCU
195 ========================================================================
198 Radar channel check routine
201 pAd Pointer to our adapter
204 TRUE need to do radar detect
205 FALSE need not to do radar detect
207 ========================================================================
209 BOOLEAN
RadarChannelCheck(
210 IN PRTMP_ADAPTER pAd
,
215 BOOLEAN result
= FALSE
;
217 for (i
=0; i
<pAd
->ChannelListNum
; i
++)
219 if (Ch
== pAd
->ChannelList
[i
].Channel
)
221 result
= pAd
->ChannelList
[i
].DfsReq
;
229 UCHAR Channel
[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
233 if (Ch
== Channel
[i
])
247 IN PRTMP_ADAPTER pAd
)
250 const UCHAR Channel
[15]={52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140};
252 if (pAd
->CommonCfg
.RadarDetect
.RDDurRegion
!= JAP
)
254 return pAd
->CommonCfg
.RadarDetect
.RDDurRegion
;
259 if (pAd
->CommonCfg
.Channel
== Channel
[i
])
274 ULONG
RTMPBbpReadRadarDuration(
275 IN PRTMP_ADAPTER pAd
)
280 BBP_IO_READ8_BY_REG_ID(pAd
, BBP_R115
, &byteValue
);
285 case 1: // radar signal detected by pulse mode.
286 case 2: // radar signal detected by width mode.
287 result
= RTMPReadRadarDuration(pAd
);
290 case 0: // No radar signal.
300 ULONG
RTMPReadRadarDuration(
301 IN PRTMP_ADAPTER pAd
)
309 VOID
RTMPCleanRadarDuration(
310 IN PRTMP_ADAPTER pAd
)
316 ========================================================================
318 Radar wave detection. The API should be invoke each second.
321 pAd - Adapter pointer
326 ========================================================================
328 VOID
ApRadarDetectPeriodic(
329 IN PRTMP_ADAPTER pAd
)
333 pAd
->CommonCfg
.RadarDetect
.InServiceMonitorCount
++;
335 for (i
=0; i
<pAd
->ChannelListNum
; i
++)
337 if (pAd
->ChannelList
[i
].RemainingTimeForUse
> 0)
339 pAd
->ChannelList
[i
].RemainingTimeForUse
--;
340 if ((pAd
->Mlme
.PeriodicRound
%5) == 0)
342 DBGPRINT(RT_DEBUG_TRACE
, ("RadarDetectPeriodic - ch=%d, RemainingTimeForUse=%d\n", pAd
->ChannelList
[i
].Channel
, pAd
->ChannelList
[i
].RemainingTimeForUse
));
348 if ((pAd
->CommonCfg
.Channel
> 14)
349 && (pAd
->CommonCfg
.bIEEE80211H
== 1)
350 && RadarChannelCheck(pAd
, pAd
->CommonCfg
.Channel
))
352 RadarDetectPeriodic(pAd
);
358 // Periodic Radar detection, switch channel will occur in RTMPHandleTBTTInterrupt()
359 // Before switch channel, driver needs doing channel switch announcement.
360 VOID
RadarDetectPeriodic(
361 IN PRTMP_ADAPTER pAd
)
363 // need to check channel availability, after switch channel
364 if (pAd
->CommonCfg
.RadarDetect
.RDMode
!= RD_SILENCE_MODE
)
367 // channel availability check time is 60sec, use 65 for assurance
368 if (pAd
->CommonCfg
.RadarDetect
.RDCount
++ > pAd
->CommonCfg
.RadarDetect
.ChMovingTime
)
370 DBGPRINT(RT_DEBUG_TRACE
, ("Not found radar signal, start send beacon and radar detection in service monitor\n\n"));
371 BbpRadarDetectionStop(pAd
);
372 AsicEnableBssSync(pAd
);
373 pAd
->CommonCfg
.RadarDetect
.RDMode
= RD_NORMAL_MODE
;
384 ==========================================================================
386 change channel moving time for DFS testing.
389 pAdapter Pointer to our adapter
390 wrq Pointer to the ioctl argument
397 1.) iwpriv ra0 set ChMovTime=[value]
398 ==========================================================================
400 INT
Set_ChMovingTime_Proc(
401 IN PRTMP_ADAPTER pAd
,
406 Value
= simple_strtol(arg
, 0, 10);
408 pAd
->CommonCfg
.RadarDetect
.ChMovingTime
= Value
;
410 DBGPRINT(RT_DEBUG_TRACE
, ("%s:: %d\n", __func__
,
411 pAd
->CommonCfg
.RadarDetect
.ChMovingTime
));
416 INT
Set_LongPulseRadarTh_Proc(
417 IN PRTMP_ADAPTER pAd
,
422 Value
= simple_strtol(arg
, 0, 10) > 10 ? 10 : simple_strtol(arg
, 0, 10);
424 pAd
->CommonCfg
.RadarDetect
.LongPulseRadarTh
= Value
;
426 DBGPRINT(RT_DEBUG_TRACE
, ("%s:: %d\n", __func__
,
427 pAd
->CommonCfg
.RadarDetect
.LongPulseRadarTh
));