PageRenderTime 64ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/core/data_ctrl/Ctrl/TrafficMonitor/TrafficMonitor.c

http://github.com/CyanogenMod/cm-kernel
C | 1325 lines | 729 code | 219 blank | 377 comment | 189 complexity | c4fd3cac3c259540a5684392897306f1 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /****************************************************************************
  2. **+-----------------------------------------------------------------------+**
  3. **| |**
  4. **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
  5. **| All rights reserved. |**
  6. **| |**
  7. **| Redistribution and use in source and binary forms, with or without |**
  8. **| modification, are permitted provided that the following conditions |**
  9. **| are met: |**
  10. **| |**
  11. **| * Redistributions of source code must retain the above copyright |**
  12. **| notice, this list of conditions and the following disclaimer. |**
  13. **| * Redistributions in binary form must reproduce the above copyright |**
  14. **| notice, this list of conditions and the following disclaimer in |**
  15. **| the documentation and/or other materials provided with the |**
  16. **| distribution. |**
  17. **| * Neither the name Texas Instruments nor the names of its |**
  18. **| contributors may be used to endorse or promote products derived |**
  19. **| from this software without specific prior written permission. |**
  20. **| |**
  21. **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
  22. **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
  23. **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
  24. **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
  25. **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
  26. **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
  27. **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
  28. **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
  29. **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
  30. **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
  31. **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
  32. **| |**
  33. **+-----------------------------------------------------------------------+**
  34. ****************************************************************************/
  35. /***************************************************************************/
  36. /* */
  37. /* MODULE: TrafficMonitor.c */
  38. /* PURPOSE: Traffic Monitor */
  39. /* */
  40. /***************************************************************************/
  41. #include "TrafficMonitorAPI.h"
  42. #include "TrafficMonitor.h"
  43. #include "DataCtrl_Api.h"
  44. #include "osApi.h"
  45. #include "report.h"
  46. /* Percentage of max down events test interval to use in our "traffic down" timer */
  47. #define MIN_INTERVAL_PERCENT 50
  48. /*#define TRAFF_TEST*/
  49. #ifdef TRAFF_TEST
  50. /*for TEST Function*/
  51. TI_HANDLE TestTrafficMonitor;
  52. TI_HANDLE TestEventTimer;
  53. TI_HANDLE Alert1;
  54. TI_HANDLE Alert2;
  55. TI_HANDLE Alert3;
  56. TI_HANDLE Alert4;
  57. VOID PrintElertStus();
  58. VOID TestEventFunc(TI_HANDLE hTrafficMonitor);
  59. #endif
  60. /************************************************************************/
  61. /* Function prototype */
  62. /************************************************************************/
  63. static VOID TimerMonitor_TimeOut(TI_HANDLE hTrafficMonitor);
  64. static void TrafficMonitor_updateBW(BandWidth_t *pBandWidth, UINT32 uCurrentTS);
  65. static UINT32 TrafficMonitor_calcBW(BandWidth_t *pBandWidth, UINT32 uCurrentTS);
  66. static BOOL isThresholdDown(TrafficAlertElement_t *AlertElement,UINT32 CurrentTime);
  67. static BOOL isThresholdUp(TrafficAlertElement_t *AlertElement , UINT32 CurrentTime);
  68. static VOID SimpleByteAggregation(TI_HANDLE TraffElem,int Count);
  69. static VOID SimpleFrameAggregation(TI_HANDLE TraffElem,int Count);
  70. static TI_HANDLE TrafficMonitor_ExitFunc(TrafficMonitor_t *TrafficMonitor,TI_HANDLE hOs);
  71. static TI_STATUS FindRstElemEntryIndex (TrafficMonitor_t *TrafficMonitor,TrafficAlertElement_t *TrafficAlertElement,int *Index);
  72. static TI_STATUS TrafficMonitor_SetMask(TrafficMonitor_t *TrafficMonitor,TrafficAlertElement_t *TrafficAlertElement,TraffEvntOptNum_t MaskType);
  73. static void TrafficMonitor_UpdateDownTrafficTimerState (TI_HANDLE hTrafficMonitor);
  74. static void TrafficMonitor_ChangeDownTimerStatus (TI_HANDLE hTrafficMonitor, UINT32 downEventsFound, UINT32 minIntervalTime);
  75. /************************************************************************/
  76. /* TrafficMonitor_create */
  77. /************************************************************************/
  78. TI_HANDLE TrafficMonitor_create(TI_HANDLE hOs)
  79. {
  80. TrafficMonitor_t *TrafficMonitor;
  81. /* Allocate the data structure TrafficMonitor*/
  82. TrafficMonitor = (TrafficMonitor_t*)os_memoryAlloc(hOs, sizeof(TrafficMonitor_t));
  83. if (TrafficMonitor == NULL)
  84. return NULL;
  85. os_memoryZero(hOs,TrafficMonitor,sizeof(TrafficMonitor_t));
  86. TrafficMonitor->hOs = hOs;
  87. /*Create the base threshold timer that will serve all the down thresholds*/
  88. TrafficMonitor->TrafficMonTimer = os_timerCreate(hOs, TimerMonitor_TimeOut, TrafficMonitor);
  89. if (TrafficMonitor->TrafficMonTimer == NULL)
  90. return TrafficMonitor_ExitFunc(TrafficMonitor,hOs);
  91. /*Creates the list that will hold all the registered alert requests*/
  92. TrafficMonitor->NotificationRegList = List_create(hOs,MAX_MONITORED_REQ,sizeof(TrafficAlertElement_t));
  93. if (TrafficMonitor->NotificationRegList == NULL)
  94. return TrafficMonitor_ExitFunc(TrafficMonitor,hOs);
  95. return (TI_HANDLE)TrafficMonitor;
  96. }
  97. /************************************************************************/
  98. /* TrafficMonitor_ExitFunc */
  99. /************************************************************************/
  100. static TI_HANDLE TrafficMonitor_ExitFunc(TrafficMonitor_t *TrafficMonitor,TI_HANDLE hOs)
  101. {
  102. if (TrafficMonitor)
  103. {
  104. if(TrafficMonitor->TrafficMonTimer)
  105. os_timerDestroy(hOs,TrafficMonitor->TrafficMonTimer);
  106. os_memoryFree(hOs, TrafficMonitor, sizeof(TrafficMonitor_t));
  107. }
  108. return NULL;
  109. }
  110. /************************************************************************/
  111. /* TrafficMonitor_config */
  112. /************************************************************************/
  113. TI_STATUS TrafficMonitor_Init(TI_HANDLE hTrafficMonitor,TI_HANDLE hRxData,TI_HANDLE hTxData)
  114. {
  115. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  116. UINT32 uCurrTS = os_timeStampMs(TrafficMonitor->hOs);
  117. if(TrafficMonitor == NULL)
  118. return NOK;
  119. TrafficMonitor->Active = FALSE;
  120. TrafficMonitor->hRxData = hRxData;
  121. TrafficMonitor->hTxData = hTxData;
  122. /*Init All the bandwidth elements in the system */
  123. os_memoryZero(TrafficMonitor->hOs,&TrafficMonitor->DirectTxFrameBW,sizeof(BandWidth_t));
  124. os_memoryZero(TrafficMonitor->hOs,&TrafficMonitor->DirectRxFrameBW,sizeof(BandWidth_t));
  125. TrafficMonitor->DirectRxFrameBW.auFirstEventsTS[0] = uCurrTS;
  126. TrafficMonitor->DirectTxFrameBW.auFirstEventsTS[0] = uCurrTS;
  127. /*Registering to the RX module for notification.*/
  128. TrafficMonitor->RxRegReqHandle = rxData_RegNotif(hRxData,DIRECTED_FRAMES_RECV,
  129. TrafficMonitor_Event,TrafficMonitor,RX_TRAFF_MODULE);
  130. if (TrafficMonitor->RxRegReqHandle == NULL)
  131. return NOK;
  132. /*Registering to the TX module for notification .*/
  133. TrafficMonitor->TxRegReqHandle = txData_RegNotif(hTxData,DIRECTED_FRAMES_XFER,
  134. TrafficMonitor_Event,TrafficMonitor,TX_TRAFF_MODULE);
  135. if (TrafficMonitor->TxRegReqHandle == NULL)
  136. return NOK;
  137. TrafficMonitor->DownTimerEnabled = FALSE;
  138. TrafficMonitor->trafficDownTestIntervalPercent = MIN_INTERVAL_PERCENT;
  139. #ifdef TRAFF_TEST
  140. TestTrafficMonitor = TrafficMonitor;
  141. TestEventTimer = os_timerCreate(TrafficMonitor->hOs, TestEventFunc, TrafficMonitor);
  142. os_timerStart(TrafficMonitor->hOs,TestEventTimer,5000,TRUE);
  143. #endif
  144. return OK;
  145. }
  146. /************************************************************************/
  147. /* TrafficMonitor_Start */
  148. /************************************************************************/
  149. TI_STATUS TrafficMonitor_Start(TI_HANDLE hTrafficMonitor)
  150. {
  151. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  152. TrafficAlertElement_t *AlertElement;
  153. UINT32 CurentTime;
  154. if(TrafficMonitor == NULL)
  155. return NOK;
  156. /*starts the bandwidth TIMER*/
  157. if(!TrafficMonitor->Active) /*To prevent double call to timer start*/
  158. {
  159. TrafficMonitor_UpdateDownTrafficTimerState (TrafficMonitor);
  160. }
  161. AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  162. CurentTime = os_timeStampMs(TrafficMonitor->hOs);
  163. /* go over all the Down elements and reload the timer*/
  164. while(AlertElement)
  165. {
  166. if(AlertElement->CurrentState != ALERT_WAIT_FOR_RESET)
  167. {
  168. AlertElement->EventCounter = 0;
  169. AlertElement->TimeOut = AlertElement->TimeIntervalMs + CurentTime;
  170. }
  171. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  172. }
  173. TrafficMonitor->Active = TRUE;
  174. return OK;
  175. }
  176. /************************************************************************/
  177. /* TrafficMonitor_Stop */
  178. /************************************************************************/
  179. TI_STATUS TrafficMonitor_Stop(TI_HANDLE hTrafficMonitor)
  180. {
  181. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  182. TrafficAlertElement_t *AlertElement;
  183. if(TrafficMonitor == NULL)
  184. return NOK;
  185. if(TrafficMonitor->Active) /*To prevent double call to timer stop*/
  186. {
  187. TrafficMonitor->Active = FALSE;
  188. TrafficMonitor->DownTimerEnabled = FALSE;
  189. os_timerStop(TrafficMonitor->hOs,TrafficMonitor->TrafficMonTimer);
  190. }
  191. /* Set all events state to ALERT_OFF to enable them to "kick" again once after TrafficMonitor is started */
  192. AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  193. while(AlertElement)
  194. {
  195. AlertElement->CurrentState = ALERT_OFF;
  196. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  197. }
  198. return OK;
  199. }
  200. /************************************************************************/
  201. /* TrafficMonitor_Destroy */
  202. /************************************************************************/
  203. TI_STATUS TrafficMonitor_Destroy(TI_HANDLE hTrafficMonitor)
  204. {
  205. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  206. if (TrafficMonitor)
  207. {
  208. /*Unregister from the RX/TX module for the required notification*/
  209. txData_UnRegNotif(TrafficMonitor->hTxData,TrafficMonitor->TxRegReqHandle);
  210. rxData_UnRegNotif(TrafficMonitor->hRxData,TrafficMonitor->RxRegReqHandle);
  211. if(TrafficMonitor->NotificationRegList)
  212. List_Destroy(TrafficMonitor->NotificationRegList);
  213. if(TrafficMonitor->TrafficMonTimer)
  214. os_timerDestroy(TrafficMonitor->hOs,TrafficMonitor->TrafficMonTimer);
  215. #ifdef TRAFF_TEST
  216. os_timerDestroy(TrafficMonitor->hOs,TestEventTimer);
  217. #endif
  218. os_memoryFree(TrafficMonitor->hOs, TrafficMonitor, sizeof(TrafficMonitor_t));
  219. return OK;
  220. }
  221. return NOK;
  222. }
  223. /***********************************************************************
  224. * TrafficMonitor_RegEvent
  225. ***********************************************************************
  226. DESCRIPTION: Reg event processing function, Perform the following:
  227. INPUT: hTrafficMonitor - Traffic Monitor the object.
  228. TrafficAlertRegParm - structure which include values to set for
  229. the requested Alert event
  230. AutoResetCreate - is only relevant to edge alerts.
  231. If AutoResetCreate flag is set to true then the registration function will create a conjunction reset element automatic
  232. this reset element will be with the same threshold but opposite in direction
  233. If AutoResetCreate flag is set to false then the reset element will be supplied afterward by the user with the function
  234. TrafficMonitor_SetRstCondition() the alert will not be active till the reset function will be set.
  235. OUTPUT:
  236. RETURN: TrafficAlertElement pointer on success, NULL otherwise
  237. ************************************************************************/
  238. TI_HANDLE TrafficMonitor_RegEvent(TI_HANDLE hTrafficMonitor,TrafficAlertRegParm_t *TrafficAlertRegParm,BOOL AutoResetCreate)
  239. {
  240. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  241. TrafficAlertElement_t *TrafficAlertElement;
  242. UINT32 CurentTime ;
  243. if(TrafficMonitor == NULL)
  244. return NULL;
  245. CurentTime = os_timeStampMs(TrafficMonitor->hOs);
  246. /*Gets a TrafficAlertElement_t memory from the list to assign to the registered request*/
  247. TrafficAlertElement = (TrafficAlertElement_t*)List_AllocElement(TrafficMonitor->NotificationRegList);
  248. if (TrafficAlertElement == NULL)
  249. { /* add print*/
  250. return NULL ;
  251. }
  252. /*Init the alert element with the registered parameters.*/
  253. TrafficAlertElement->CallBack = TrafficAlertRegParm->CallBack;
  254. TrafficAlertElement->Context = TrafficAlertRegParm->Context;
  255. TrafficAlertElement->Cookie = TrafficAlertRegParm->Cookie;
  256. TrafficAlertElement->Direction = TrafficAlertRegParm->Direction;
  257. TrafficAlertElement->Threshold = TrafficAlertRegParm->Threshold;
  258. TrafficAlertElement->Trigger = TrafficAlertRegParm->Trigger;
  259. TrafficAlertElement->TimeIntervalMs = TrafficAlertRegParm->TimeIntervalMs;
  260. TrafficAlertElement->TimeOut = CurentTime + TrafficAlertRegParm->TimeIntervalMs;
  261. TrafficAlertElement->EventCounter = 0;
  262. TrafficMonitor_SetMask(TrafficMonitor,TrafficAlertElement,TrafficAlertRegParm->MonitorType);
  263. TrafficAlertElement->CurrentState = ALERT_OFF;
  264. TrafficAlertElement->AutoCreated = FALSE;
  265. TrafficAlertElement->Enabled = FALSE;
  266. /*In case that this is an Edge alert there is a need for a reset condition element*/
  267. /*corresponding to the Alert request but opposite in the direction.*/
  268. /*Note that the reset condition for this (new) reset element, is the Alert Element it self.*/
  269. if(TrafficAlertElement->Trigger == TRAFF_EDGE)
  270. {
  271. if(AutoResetCreate)
  272. {
  273. /*Gets a TrafficAlertElement_t memory from the list to assign to the reset elemnt*/
  274. TrafficAlertElement->ResetElment[0] = (TrafficAlertElement_t*)List_AllocElement(TrafficMonitor->NotificationRegList);
  275. if( TrafficAlertElement->ResetElment[0] == NULL)
  276. {
  277. List_FreeElement(TrafficMonitor->NotificationRegList,TrafficAlertElement);
  278. return NULL;
  279. }
  280. /*
  281. copy the Traffic Element init params to the reset Elemnt Except for
  282. the direction and the call back that is set to null the CurrentState set to disable.
  283. And the reset condition,that points to the muster alert.
  284. */
  285. os_memoryCopy(TrafficMonitor->hOs,TrafficAlertElement->ResetElment[0],TrafficAlertElement,sizeof(TrafficAlertElement_t));
  286. TrafficAlertElement->ResetElment[0]->CallBack = NULL;
  287. /*opposite in the direction from the TrafficAlertElement->Direction*/
  288. if (TrafficAlertRegParm->Direction == TRAFF_UP)
  289. TrafficAlertElement->ResetElment[0]->Direction = TRAFF_DOWN;
  290. else
  291. TrafficAlertElement->ResetElment[0]->Direction = TRAFF_UP;
  292. TrafficAlertElement->ResetElment[0]->CurrentState = ALERT_WAIT_FOR_RESET;
  293. TrafficAlertElement->ResetElment[0]->ResetElment[0] = TrafficAlertElement;
  294. TrafficAlertElement->ResetElment[0]->AutoCreated = TRUE;
  295. TrafficAlertElement->ResetElment[0]->RstWasAssigned = TRUE;
  296. TrafficAlertElement->RstWasAssigned = TRUE;
  297. }
  298. else/* The reset element will be supplied afterward by the user in the meanwhile disable the alert till then*/
  299. {
  300. TrafficAlertElement->RstWasAssigned = FALSE;
  301. TrafficAlertElement->CurrentState = ALERT_WAIT_FOR_RESET;
  302. }
  303. }
  304. TrafficMonitor_UpdateDownTrafficTimerState (TrafficMonitor);
  305. return TrafficAlertElement;
  306. }
  307. /************************************************************************/
  308. /* FindRstElemEntryIndex */
  309. /************************************************************************/
  310. /* Gets a TrafficAlertElement_t memory from the list to assign to the reset elemnt
  311. * for internal use
  312. ************************************************************************/
  313. static TI_STATUS FindRstElemEntryIndex (TrafficMonitor_t *TrafficMonitor,TrafficAlertElement_t *TrafficAlertElement,int *Index)
  314. {
  315. int i;
  316. /*Find an empty Rst element entry*/
  317. for(i=0;(i<MAX_RST_ELMENT_PER_ALERT) && TrafficAlertElement->ResetElment[i];i++);
  318. if(i == MAX_RST_ELMENT_PER_ALERT)
  319. return NOK;
  320. *Index = i;
  321. return OK;
  322. }
  323. /************************************************************************/
  324. /* TrafficMonitor_SetMask */
  325. /************************************************************************/
  326. /*
  327. * Convert the Mask from the types that declared in the
  328. * TrafficMonitorAPI to the types that are used in the Rx Tx modules.
  329. * And update the TX and RX module of the new event req
  330. * Sets the aggregation function that corresponds to the specific mask type
  331. ************************************************************************/
  332. static TI_STATUS TrafficMonitor_SetMask(TrafficMonitor_t *TrafficMonitor,TrafficAlertElement_t *TrafficAlertElement,TraffEvntOptNum_t MaskType)
  333. {
  334. UINT32 TxMask = 0;
  335. UINT32 RxMask = 0;
  336. switch(MaskType) {
  337. case TX_RX_DIRECTED_FRAMES:
  338. TxMask = DIRECTED_FRAMES_XFER;
  339. RxMask = DIRECTED_FRAMES_RECV;
  340. TrafficAlertElement->ActionFunc = SimpleFrameAggregation;
  341. break;
  342. case TX_ALL_MSDU_FRAMES:
  343. TxMask = DIRECTED_FRAMES_XFER|MULTICAST_FRAMES_XFER|BROADCAST_FRAMES_XFER;
  344. TrafficAlertElement->ActionFunc = SimpleFrameAggregation;
  345. break;
  346. case RX_ALL_MSDU_FRAMES:
  347. RxMask = DIRECTED_FRAMES_RECV|MULTICAST_FRAMES_RECV|BROADCAST_FRAMES_RECV;
  348. TrafficAlertElement->ActionFunc = SimpleFrameAggregation;
  349. break;
  350. case TX_RX_ALL_MSDU_FRAMES:
  351. TxMask = DIRECTED_FRAMES_XFER|MULTICAST_FRAMES_XFER|BROADCAST_FRAMES_XFER;
  352. RxMask = DIRECTED_FRAMES_RECV|MULTICAST_FRAMES_RECV|BROADCAST_FRAMES_RECV;
  353. TrafficAlertElement->ActionFunc = SimpleFrameAggregation;
  354. break;
  355. case TX_RX_ALL_MSDU_IN_BYTES:
  356. TxMask = DIRECTED_BYTES_XFER|MULTICAST_BYTES_XFER|BROADCAST_BYTES_XFER;
  357. RxMask = DIRECTED_BYTES_RECV|MULTICAST_BYTES_RECV|BROADCAST_BYTES_RECV;
  358. TrafficAlertElement->ActionFunc = SimpleByteAggregation;
  359. break;
  360. case TX_RX_DIRECTED_IN_BYTES:
  361. TxMask = DIRECTED_BYTES_XFER;
  362. RxMask = DIRECTED_BYTES_RECV;
  363. TrafficAlertElement->ActionFunc = SimpleByteAggregation;
  364. break;
  365. case TX_RX_ALL_802_11_DATA_IN_BYTES:
  366. TxMask = DIRECTED_BYTES_XFER | MULTICAST_BYTES_XFER;
  367. RxMask = DIRECTED_BYTES_RECV | MULTICAST_BYTES_RECV;
  368. TrafficAlertElement->ActionFunc = SimpleByteAggregation;
  369. break;
  370. case TX_RX_ALL_802_11_DATA_FRAMES:
  371. TxMask = DIRECTED_FRAMES_XFER | MULTICAST_FRAMES_XFER;
  372. RxMask = DIRECTED_FRAMES_RECV | MULTICAST_FRAMES_RECV;
  373. TrafficAlertElement->ActionFunc = SimpleFrameAggregation;
  374. break;
  375. default:
  376. WLAN_OS_REPORT(("TrafficMonitor_SetMask - unknown parameter: %d\n", MaskType));
  377. return NOK;
  378. }
  379. if(RxMask)
  380. {
  381. TrafficAlertElement->MonitorMask[RX_TRAFF_MODULE] = RxMask;
  382. if(rxData_AddToNotifMask(TrafficMonitor->hRxData,TrafficMonitor->RxRegReqHandle,RxMask) == NOK)
  383. return NOK;
  384. }
  385. if(TxMask)
  386. {
  387. TrafficAlertElement->MonitorMask[TX_TRAFF_MODULE] = TxMask;
  388. if(txData_AddToNotifMask(TrafficMonitor->hTxData,TrafficMonitor->TxRegReqHandle,TxMask) == NOK)
  389. return NOK;
  390. }
  391. return OK;
  392. }
  393. /***********************************************************************
  394. * TrafficMonitor_SetRstCondition
  395. ***********************************************************************
  396. DESCRIPTION: Reg event processing function, Perform the following:
  397. Sets the given reset element to the Alert element.
  398. if MutualRst is set, then The operation is done vise versa .
  399. INPUT: hTrafficMonitor - Traffic Monitor the object.
  400. EventHandle - Alert event
  401. ResetEventHandle Alert Event that will be used to as the rest for above.
  402. MutualRst - if the 2 elements are used to reset One another.
  403. NOTE If the reset element event condition is the same as the alert element the user
  404. have to check the that threshold is bigger or smaller according to the direction
  405. else it can create a deadlock
  406. OUTPUT:
  407. RETURN: OK on success, NOK otherwise
  408. ************************************************************************/
  409. TI_STATUS TrafficMonitor_SetRstCondition(TI_HANDLE hTrafficMonitor, TI_HANDLE EventHandle,TI_HANDLE ResetEventHandle,BOOL MutualRst)
  410. {
  411. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  412. TrafficAlertElement_t *TrafficAlertElement = (TrafficAlertElement_t*)EventHandle;
  413. TrafficAlertElement_t *TrafficResetAlertElement = (TrafficAlertElement_t*)ResetEventHandle;
  414. int i,x;
  415. UINT32 CurentTime ;
  416. if((TrafficMonitor == NULL) || (EventHandle == NULL) || (TrafficResetAlertElement == NULL))
  417. return NOK;
  418. CurentTime = os_timeStampMs(TrafficMonitor->hOs);
  419. /*
  420. Check that validity of the reset condition
  421. 1.The reset condition is edge.
  422. 2.The direction is opposite from the main alert.
  423. 3.The threshold is bigger or smaller according to the direction
  424. This condition is not checked but the user have check it else it can create a deadlock..
  425. */
  426. if((TrafficResetAlertElement->Trigger != TRAFF_EDGE) || (TrafficAlertElement->Trigger != TRAFF_EDGE))
  427. return NOK;
  428. if(TrafficResetAlertElement->Direction == TrafficAlertElement->Direction)
  429. return NOK;
  430. /*Find an empty Rst element entry*/
  431. if(FindRstElemEntryIndex(TrafficMonitor,TrafficResetAlertElement,&i) == NOK)
  432. return NOK;
  433. TrafficResetAlertElement->ResetElment[i] = TrafficAlertElement;
  434. /*if we know for sure that No Rst Element was assigned
  435. therefore that element was in disable mode and we have to enable it.*/
  436. if (!(TrafficAlertElement->RstWasAssigned))
  437. {
  438. TrafficAlertElement->RstWasAssigned = TRUE;
  439. TrafficAlertElement->CurrentState = ALERT_OFF;
  440. TrafficAlertElement->TimeOut = CurentTime + TrafficAlertElement->TimeIntervalMs;
  441. TrafficAlertElement->EventCounter =0;
  442. }
  443. if(MutualRst)
  444. {
  445. /*Find an empty Rst element entry in the TempRstAlertElement*/
  446. if(FindRstElemEntryIndex(TrafficMonitor,TrafficAlertElement,&x) == NOK)
  447. {
  448. /*this clean up is not complete*/
  449. TrafficResetAlertElement->ResetElment[i] = NULL;
  450. return NOK;
  451. }
  452. TrafficAlertElement->ResetElment[x] = TrafficResetAlertElement;
  453. /*if know for sure that No Rst Element was assigned
  454. therefore that element was in disable mode and we have to enable it.*/
  455. if (!(TrafficResetAlertElement->RstWasAssigned))
  456. {
  457. TrafficResetAlertElement->RstWasAssigned = TRUE;
  458. TrafficResetAlertElement->CurrentState = ALERT_OFF;
  459. TrafficResetAlertElement->TimeOut = CurentTime + TrafficAlertElement->TimeIntervalMs;
  460. TrafficResetAlertElement->EventCounter = 0;
  461. }
  462. }
  463. return OK;
  464. }
  465. /************************************************************************/
  466. /* TrafficMonitor_CleanRelatedRef */
  467. /************************************************************************/
  468. VOID TrafficMonitor_CleanRelatedRef(TrafficMonitor_t *TrafficMonitor,TrafficAlertElement_t *TrafficAlertElement)
  469. {
  470. int i;
  471. TrafficAlertElement_t *AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  472. /* go over all the Down elements and check for alert ResetElment that ref to TrafficAlertElement*/
  473. while(AlertElement)
  474. {
  475. for(i=0;i<MAX_RST_ELMENT_PER_ALERT;i++)
  476. {
  477. if(AlertElement->ResetElment[i] == TrafficAlertElement)
  478. AlertElement->ResetElment[i] = NULL;
  479. }
  480. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  481. }
  482. }
  483. /************************************************************************/
  484. /* TrafficMonitor_StopNotif */
  485. /************************************************************************/
  486. VOID TrafficMonitor_StopEventNotif(TI_HANDLE hTrafficMonitor,TI_HANDLE EventHandle)
  487. {
  488. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  489. TrafficAlertElement_t *TrafficAlertElement = (TrafficAlertElement_t*)EventHandle;
  490. if(TrafficMonitor == NULL)
  491. return ;
  492. if(TrafficAlertElement == NULL)
  493. return ;
  494. TrafficAlertElement->Enabled = FALSE;
  495. TrafficMonitor_UpdateDownTrafficTimerState (hTrafficMonitor);
  496. }
  497. /************************************************************************/
  498. /* TrafficMonitor_StartNotif */
  499. /************************************************************************/
  500. VOID TrafficMonitor_StartEventNotif(TI_HANDLE hTrafficMonitor, TI_HANDLE EventHandle)
  501. {
  502. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  503. TrafficAlertElement_t *TrafficAlertElement = (TrafficAlertElement_t*)EventHandle;
  504. if(TrafficMonitor == NULL)
  505. return ;
  506. if(TrafficAlertElement == NULL)
  507. return ;
  508. TrafficAlertElement->Enabled = TRUE;
  509. TrafficMonitor_UpdateDownTrafficTimerState (hTrafficMonitor);
  510. }
  511. /************************************************************************/
  512. /* TrafficMonitor_StartNotif */
  513. /************************************************************************/
  514. VOID TrafficMonitor_ResetEvent(TI_HANDLE hTrafficMonitor, TI_HANDLE EventHandle)
  515. {
  516. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  517. TrafficAlertElement_t *TrafficAlertElement = (TrafficAlertElement_t*)EventHandle;
  518. if(TrafficMonitor == NULL)
  519. return ;
  520. if(TrafficAlertElement == NULL)
  521. return ;
  522. TrafficAlertElement->CurrentState = ALERT_OFF;
  523. TrafficMonitor_UpdateDownTrafficTimerState (TrafficMonitor);
  524. }
  525. /************************************************************************/
  526. /* TrafficMonitor_UnregEvent */
  527. /************************************************************************/
  528. VOID TrafficMonitor_UnregEvent(TI_HANDLE hTrafficMonitor, TI_HANDLE EventHandle)
  529. {
  530. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  531. TrafficAlertElement_t *TrafficAlertElement = (TrafficAlertElement_t*)EventHandle;
  532. if(TrafficMonitor == NULL)
  533. return ;
  534. /*If it was an edge alert then there can be one more alert element to free.*/
  535. /*one is the alert, and the second is the reset element that corresponds to this alert*/
  536. /*if it was Auto Created*/
  537. if (TrafficAlertElement->ResetElment[0])
  538. if (TrafficAlertElement->ResetElment[0]->AutoCreated)
  539. List_FreeElement(TrafficMonitor->NotificationRegList,TrafficAlertElement->ResetElment);
  540. TrafficMonitor_CleanRelatedRef(TrafficMonitor,TrafficAlertElement);
  541. List_FreeElement(TrafficMonitor->NotificationRegList,EventHandle);
  542. TrafficMonitor_UpdateDownTrafficTimerState (TrafficMonitor);
  543. }
  544. /***********************************************************************
  545. * isThresholdUp
  546. ***********************************************************************
  547. DESCRIPTION: Evaluate if alert element as crossed his threshold
  548. if yes it operate the callback registered for this alert and take care of the alert state.
  549. For alert with UP direction the following algorithm is preformed
  550. If the threshold is passed in the req time interval or less. then
  551. For Level
  552. The alert mode is changed to ON & the next timeout is set to the next interval.
  553. For Edge
  554. The alert mode is changed to wait for reset and the reset element is set to off.
  555. And his timeout is set
  556. INPUT:
  557. EventHandle - Alert event
  558. CurrentTime - the current time Time stamp
  559. OUTPUT:
  560. RETURN: If threshold crossed TRUE else False
  561. ************************************************************************/
  562. static BOOL isThresholdUp(TrafficAlertElement_t *AlertElement , UINT32 CurrentTime)
  563. {
  564. int i;
  565. if (AlertElement->TimeOut < CurrentTime)
  566. {
  567. AlertElement->EventCounter = AlertElement->LastCounte;
  568. AlertElement->TimeOut = CurrentTime + AlertElement->TimeIntervalMs;
  569. }
  570. if (AlertElement->EventCounter > AlertElement->Threshold)
  571. {
  572. AlertElement->EventCounter = 0;
  573. /*Sets the new due time (time out)*/
  574. AlertElement->TimeOut = CurrentTime + AlertElement->TimeIntervalMs;
  575. /*For Edge alert change the alert status to wait for reset and
  576. The corresponding reset element from wait for reset To off.
  577. That way toggling the two elements*/
  578. if(AlertElement->Trigger == TRAFF_EDGE)
  579. {
  580. AlertElement->CurrentState = ALERT_WAIT_FOR_RESET;
  581. for(i=0;i<MAX_RST_ELMENT_PER_ALERT;i++)
  582. {
  583. TrafficAlertElement_t *rstElmt = AlertElement->ResetElment[i];
  584. if(rstElmt != NULL)
  585. if(rstElmt->CurrentState == ALERT_WAIT_FOR_RESET)
  586. {
  587. rstElmt->CurrentState = ALERT_OFF;
  588. rstElmt->EventCounter = 0;
  589. rstElmt->TimeOut = CurrentTime + rstElmt->TimeIntervalMs;
  590. }
  591. }
  592. }
  593. else
  594. AlertElement->CurrentState = ALERT_ON;
  595. /*Call the callback function*/
  596. if((AlertElement->CallBack != NULL) && AlertElement->Enabled)
  597. AlertElement->CallBack(AlertElement->Context,AlertElement->Cookie);
  598. return TRUE;
  599. }
  600. return FALSE;
  601. }
  602. /***********************************************************************
  603. * isThresholdDown
  604. ***********************************************************************
  605. DESCRIPTION: Evaluate if alert element as crossed his threshold
  606. if yes it operate the callback registered for this alert and take care of the alert state.
  607. For alert with DOWN direction the following algorithm is preformed
  608. If the threshold is passed (EventCounter < Threshold) in the req time only. then
  609. For Level
  610. The alert mode is changed to ON & the next timeout is set to the next interval.
  611. If the alert condition will still be on.then the next alert will be in the next time interval
  612. For Edge
  613. The alert mode is changed to wait for reset and the reset element is set to off.
  614. And his timeout is set.
  615. INPUT:
  616. EventHandle - Alert event
  617. CurrentTime - the current time Time stamp
  618. OUTPUT:
  619. RETURN: If threshold crossed TRUE else False
  620. ************************************************************************/
  621. static BOOL isThresholdDown(TrafficAlertElement_t *AlertElement , UINT32 CurrentTime)
  622. {
  623. int i;
  624. BOOL returnVal = FALSE;
  625. /*
  626. if its end of window time.
  627. */
  628. if (AlertElement->TimeOut <= CurrentTime)
  629. {
  630. /*
  631. if there was a down edge event.
  632. */
  633. if (AlertElement->EventCounter <= AlertElement->Threshold)
  634. {
  635. /*For Edge alert change the alert status to wait for reset and
  636. The corresponding reset element from wait for reset To off.
  637. That way toggling the two elements*/
  638. if(AlertElement->Trigger == TRAFF_EDGE)
  639. {
  640. AlertElement->CurrentState = ALERT_WAIT_FOR_RESET;
  641. for(i=0;i<MAX_RST_ELMENT_PER_ALERT;i++)
  642. {
  643. TrafficAlertElement_t *rstElmt = AlertElement->ResetElment[i];
  644. if(rstElmt != NULL)
  645. if(rstElmt->CurrentState == ALERT_WAIT_FOR_RESET)
  646. {
  647. rstElmt->CurrentState = ALERT_OFF;
  648. rstElmt->EventCounter = 0;
  649. rstElmt->TimeOut = CurrentTime + rstElmt->TimeIntervalMs;
  650. }
  651. }
  652. }
  653. else
  654. AlertElement->CurrentState = ALERT_ON;
  655. /*Call the callback function*/
  656. if((AlertElement->CallBack != NULL) && AlertElement->Enabled)
  657. AlertElement->CallBack(AlertElement->Context,AlertElement->Cookie);
  658. returnVal = TRUE;
  659. }
  660. /* end of time window - clear the event counter for the new window.*/
  661. AlertElement->EventCounter = 0;
  662. /*Sets the new due time (time out)*/
  663. AlertElement->TimeOut = CurrentTime + AlertElement->TimeIntervalMs;
  664. }
  665. else
  666. {
  667. /*
  668. In case we find out that the alert condition will not Occur for this frame window,
  669. therefor start a new alert examine cycle (the next farme window).
  670. (Not wait till the timeout of this current frame window)
  671. */
  672. if(AlertElement->EventCounter > AlertElement->Threshold)
  673. {
  674. AlertElement->EventCounter = 0;
  675. AlertElement->TimeOut = CurrentTime + AlertElement->TimeIntervalMs;
  676. }
  677. }
  678. return returnVal;
  679. }
  680. /************************************************************************/
  681. /* TimerMonitor_TimeOut */
  682. /************************************************************************/
  683. /*
  684. * Timer function that is called for every x time interval
  685. * That will invoke a process if any down limit as occurred.
  686. *
  687. ************************************************************************/
  688. static VOID TimerMonitor_TimeOut(TI_HANDLE hTrafficMonitor)
  689. {
  690. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  691. TrafficAlertElement_t *AlertElement;
  692. UINT32 CurentTime;
  693. UINT32 activeTrafDownEventsNum = 0;
  694. UINT32 trafficDownMinTimeout = 0xFFFFFFFF;
  695. if(TrafficMonitor == NULL)
  696. return;
  697. AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  698. CurentTime = os_timeStampMs(TrafficMonitor->hOs);
  699. /* go over all the Down elements and check for alert */
  700. while(AlertElement)
  701. {
  702. if(AlertElement->CurrentState != ALERT_WAIT_FOR_RESET)
  703. {
  704. if (AlertElement->Direction == TRAFF_DOWN)
  705. {
  706. isThresholdDown(AlertElement,CurentTime);
  707. }
  708. }
  709. if ((AlertElement->Direction == TRAFF_DOWN) && (AlertElement->Trigger == TRAFF_EDGE) && (AlertElement->CurrentState == ALERT_OFF) && (AlertElement->Enabled == TRUE))
  710. {
  711. /* Increase counter of active traffic down events */
  712. activeTrafDownEventsNum++;
  713. /* Search for the alert with the most short Interval time - will be used to start timer */
  714. if ((AlertElement->TimeIntervalMs) < (trafficDownMinTimeout))
  715. trafficDownMinTimeout = AlertElement->TimeIntervalMs;
  716. }
  717. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  718. }
  719. TrafficMonitor_ChangeDownTimerStatus (TrafficMonitor,activeTrafDownEventsNum,trafficDownMinTimeout);
  720. }
  721. /***********************************************************************
  722. * TrafficMonitor_IsEventOn
  723. ***********************************************************************
  724. DESCRIPTION: Returns the current status of an event element.
  725. INPUT: TrafficAlertElement_t
  726. OUTPUT: bool
  727. RETURN: True = ON false = OFF
  728. ************************************************************************/
  729. BOOL TrafficMonitor_IsEventOn(TI_HANDLE EventHandle)
  730. {
  731. TrafficAlertElement_t *TrafficAlertElement = (TrafficAlertElement_t*)EventHandle;
  732. if(TrafficAlertElement == NULL)
  733. return FALSE;
  734. if (TrafficAlertElement->CurrentState == ALERT_OFF)
  735. return FALSE;
  736. else
  737. return TRUE;
  738. }
  739. /***********************************************************************
  740. * TrafficMonitor_GetFrameBandwidth
  741. ***********************************************************************
  742. DESCRIPTION: Returns the total direct frames in the Rx and Tx per second.
  743. INPUT: hTrafficMonitor - Traffic Monitor the object.
  744. OUTPUT:
  745. RETURN: Total BW
  746. ************************************************************************/
  747. int TrafficMonitor_GetFrameBandwidth(TI_HANDLE hTrafficMonitor)
  748. {
  749. TrafficMonitor_t *pTrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  750. UINT32 uCurentTS = os_timeStampMs(pTrafficMonitor->hOs);
  751. if(pTrafficMonitor == NULL)
  752. {
  753. return -1; /* return error code */
  754. }
  755. /* Calculate BW for Rx & Tx */
  756. return ( TrafficMonitor_calcBW(&pTrafficMonitor->DirectRxFrameBW, uCurentTS) +
  757. TrafficMonitor_calcBW(&pTrafficMonitor->DirectTxFrameBW, uCurentTS) );
  758. }
  759. /***********************************************************************
  760. * TrafficMonitor_updateBW
  761. ***********************************************************************
  762. DESCRIPTION: Upon receiving an event of Tx/Rx (a packet was sent or received), This function is
  763. called and performs BW calculation.
  764. INPUT:
  765. pBandWidth - BW of Rx or Tx
  766. uCurrentTS - current TS of the recent event
  767. OUTPUT: pBandWidth - updated counters and TS
  768. ************************************************************************/
  769. void TrafficMonitor_updateBW(BandWidth_t *pBandWidth, UINT32 uCurrentTS)
  770. {
  771. /* Check if we should move to the next window */
  772. if ( (uCurrentTS - pBandWidth->auFirstEventsTS[pBandWidth->uCurrentWindow]) < (SIZE_OF_WINDOW_MS) )
  773. {
  774. pBandWidth->auWindowCounter[pBandWidth->uCurrentWindow]++;
  775. }
  776. else /* next window */
  777. {
  778. /* increment current window and mark the first event received */
  779. pBandWidth->uCurrentWindow = (pBandWidth->uCurrentWindow + 1) & CYCLIC_COUNTER_ELEMENT;
  780. pBandWidth->auFirstEventsTS[pBandWidth->uCurrentWindow] = uCurrentTS;
  781. pBandWidth->auWindowCounter[pBandWidth->uCurrentWindow] = 1;
  782. }
  783. }
  784. /***********************************************************************
  785. * TrafficMonitor_calcBW
  786. ***********************************************************************
  787. DESCRIPTION: Returns the total direct frames in Rx or Tx.
  788. It is called when outside module request the BW.
  789. Calculate band width by summing up the sliding windows.
  790. INPUT: pBandWidth - BW of Rx or Tx
  791. uCurrentTS - current TS
  792. RETURN: Total BW
  793. ************************************************************************/
  794. UINT32 TrafficMonitor_calcBW(BandWidth_t *pBandWidth, UINT32 uCurrentTS)
  795. {
  796. UINT32 uTotalTime = uCurrentTS - pBandWidth->auFirstEventsTS[pBandWidth->uCurrentWindow];
  797. UINT32 uTotalBW = 0;
  798. INT32 iter = (INT32)pBandWidth->uCurrentWindow;
  799. INT32 iNextIter = (iter - 1) & CYCLIC_COUNTER_ELEMENT; /* Always one less than i */
  800. /* As long as the summed windows are less than BW_WINDOW_MS and we didn't loop the whole array */
  801. while ( (uTotalTime < BW_WINDOW_MS) && (iNextIter != pBandWidth->uCurrentWindow))
  802. {
  803. uTotalBW += pBandWidth->auWindowCounter[iter];
  804. /* add next window time - next loop will check if we exceeded the BW window */
  805. uTotalTime = uCurrentTS - pBandWidth->auFirstEventsTS[iNextIter];
  806. iter = iNextIter;
  807. iNextIter = (iter - 1) & CYCLIC_COUNTER_ELEMENT;
  808. } ;
  809. /*
  810. * Note that if (iNextIter == pBandWidth->uCurrentWindow) than the calculated BW could be up to
  811. * SIZE_OF_WINDOW_MS less than BW_WINDOW_MS
  812. */
  813. return uTotalBW;
  814. }
  815. /***********************************************************************
  816. * TrafficMonitor_Event
  817. ***********************************************************************
  818. DESCRIPTION: this function is called for every event that was requested from the Tx or Rx
  819. The function preformes update of the all the relevant Alert in the system
  820. that corresponds to the event. checks the Alert Status due to this event.
  821. INPUT: hTrafficMonitor - Traffic Monitor the object.
  822. Count - evnet count.
  823. Mask - the event mask that That triggered this function.
  824. MonitorModuleType Will hold the module type from where this function was called.
  825. OUTPUT:
  826. RETURN:
  827. ************************************************************************/
  828. VOID TrafficMonitor_Event(TI_HANDLE hTrafficMonitor,int Count,UINT16 Mask,UINT32 MonitorModuleType)
  829. {
  830. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  831. TrafficAlertElement_t *AlertElement;
  832. UINT32 activeTrafDownEventsNum = 0;
  833. UINT32 trafficDownMinTimeout = 0xFFFFFFFF;
  834. UINT32 uCurentTS = os_timeStampMs(TrafficMonitor->hOs);
  835. if(TrafficMonitor == NULL)
  836. return;
  837. if(!TrafficMonitor->Active)
  838. return;
  839. /* for BW calculation */
  840. if(MonitorModuleType == RX_TRAFF_MODULE)
  841. {
  842. if(Mask & DIRECTED_FRAMES_RECV)
  843. {
  844. TrafficMonitor_updateBW(&TrafficMonitor->DirectRxFrameBW, uCurentTS);
  845. }
  846. }
  847. else if (MonitorModuleType == TX_TRAFF_MODULE)
  848. {
  849. if(Mask & DIRECTED_FRAMES_XFER)
  850. {
  851. TrafficMonitor_updateBW(&TrafficMonitor->DirectTxFrameBW, uCurentTS);
  852. }
  853. }
  854. else
  855. {
  856. return; /* module type does not exist, error return */
  857. }
  858. AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  859. /* go over all the elements and check for alert */
  860. while(AlertElement)
  861. {
  862. if(AlertElement->CurrentState != ALERT_WAIT_FOR_RESET)
  863. {
  864. if(AlertElement->MonitorMask[MonitorModuleType] & Mask)
  865. {
  866. AlertElement->ActionFunc(AlertElement,Count);
  867. if (AlertElement->Direction == TRAFF_UP)
  868. {
  869. isThresholdUp(AlertElement, uCurentTS);
  870. }
  871. }
  872. if ((AlertElement->Direction == TRAFF_DOWN) && (AlertElement->Trigger == TRAFF_EDGE) && (AlertElement->CurrentState == ALERT_OFF) && (AlertElement->Enabled == TRUE))
  873. {
  874. /* Increase counter of active traffic down events */
  875. activeTrafDownEventsNum++;
  876. /* Search for the alert with the most short Interval time - will be used to start timer */
  877. if ((AlertElement->TimeIntervalMs) < (trafficDownMinTimeout))
  878. trafficDownMinTimeout = AlertElement->TimeIntervalMs;
  879. }
  880. }
  881. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  882. }
  883. TrafficMonitor_ChangeDownTimerStatus (TrafficMonitor,activeTrafDownEventsNum,trafficDownMinTimeout);
  884. }
  885. /*
  886. * Used as the aggregation function that is used by the alerts for counting the events.
  887. */
  888. static VOID SimpleByteAggregation(TI_HANDLE TraffElem,int Count)
  889. {
  890. TrafficAlertElement_t *AlertElement = TraffElem;
  891. AlertElement->EventCounter += Count;
  892. AlertElement->LastCounte = Count;
  893. }
  894. /*
  895. * Used as the aggregation function for frame. (count is not used)
  896. */
  897. static VOID SimpleFrameAggregation(TI_HANDLE TraffElem,int Count)
  898. {
  899. TrafficAlertElement_t *AlertElement = TraffElem;
  900. AlertElement->EventCounter++;
  901. AlertElement->LastCounte = 1;
  902. }
  903. /*-----------------------------------------------------------------------------
  904. Routine Name: TrafficMonitor_UpdateDownTrafficTimerState
  905. Routine Description: called whenever a "down" alert is called, or any other change in the alert list.
  906. used to either start or stop the "traffic down" timer.
  907. loops through alert list, searches for active traffic down events.
  908. Arguments:
  909. Return Value:
  910. -----------------------------------------------------------------------------*/
  911. static void TrafficMonitor_UpdateDownTrafficTimerState (TI_HANDLE hTrafficMonitor)
  912. {
  913. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  914. TrafficAlertElement_t *AlertElement;
  915. UINT32 activeTrafDownEventsNum = 0;
  916. UINT32 trafficDownMinTimeout = 0xFFFFFFFF;
  917. AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  918. while(AlertElement)
  919. {
  920. if ((AlertElement->Direction == TRAFF_DOWN) && (AlertElement->Trigger == TRAFF_EDGE) && (AlertElement->CurrentState == ALERT_OFF) && (AlertElement->Enabled == TRUE))
  921. {
  922. /* Increase counter of active traffic down events */
  923. activeTrafDownEventsNum++;
  924. /* Search for the alert with the most short Interval time - will be used to start timer */
  925. if ((AlertElement->TimeIntervalMs) < (trafficDownMinTimeout))
  926. trafficDownMinTimeout = AlertElement->TimeIntervalMs;
  927. }
  928. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  929. }
  930. TrafficMonitor_ChangeDownTimerStatus (TrafficMonitor,activeTrafDownEventsNum,trafficDownMinTimeout);
  931. }
  932. /*-----------------------------------------------------------------------------
  933. Routine Name: TrafficMonitor_ChangeDownTimerStatus
  934. Routine Description: Start or stop down traffic timer according to number of down events found and minInterval time.
  935. Arguments:
  936. Return Value:
  937. -----------------------------------------------------------------------------*/
  938. static void TrafficMonitor_ChangeDownTimerStatus (TI_HANDLE hTrafficMonitor, UINT32 downEventsFound, UINT32 minIntervalTime)
  939. {
  940. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  941. if ((downEventsFound == 0) && (TrafficMonitor->DownTimerEnabled == TRUE))
  942. {
  943. TrafficMonitor->DownTimerEnabled = FALSE;
  944. os_timerStop(TrafficMonitor->hOs,TrafficMonitor->TrafficMonTimer);
  945. }
  946. else if ((downEventsFound > 0) && (TrafficMonitor->DownTimerEnabled == FALSE))
  947. {
  948. TrafficMonitor->DownTimerEnabled = TRUE;
  949. /* Start the timer with user defined percentage of the the minimum interval discovered earlier */
  950. os_timerStart(TrafficMonitor->hOs,TrafficMonitor->TrafficMonTimer,
  951. ((minIntervalTime * TrafficMonitor->trafficDownTestIntervalPercent) / 100),TRUE);
  952. }
  953. }
  954. #ifdef TI_DBG
  955. /*-----------------------------------------------------------------------------
  956. Routine Name: TrafficMonitor_UpdateActiveEventsCounters
  957. Routine Description:
  958. Arguments:
  959. Return Value:
  960. -----------------------------------------------------------------------------*/
  961. void TrafficMonitor_UpdateActiveEventsCounters (TI_HANDLE hTrafficMonitor)
  962. {
  963. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)hTrafficMonitor;
  964. TrafficAlertElement_t *AlertElement;
  965. UINT32 activeTrafDownEventsNum = 0;
  966. AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  967. while(AlertElement)
  968. {
  969. if ((AlertElement->Direction == TRAFF_DOWN) && (AlertElement->Trigger == TRAFF_EDGE) && (AlertElement->CurrentState == ALERT_OFF) && (AlertElement->Enabled == TRUE))
  970. {
  971. activeTrafDownEventsNum++;
  972. }
  973. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  974. }
  975. }
  976. #endif
  977. #ifdef TRAFF_TEST
  978. /*
  979. * TEST Function
  980. */
  981. VOID func1(TI_HANDLE Context,UINT32 Cookie)
  982. {
  983. switch(Cookie) {
  984. case 1:
  985. WLAN_OS_REPORT(("TRAFF - ALERT UP limit - 50 ON"));
  986. break;
  987. case 2:
  988. WLAN_OS_REPORT(("TRAFF - ALERT UP limit - 30 ON"));
  989. break;
  990. case 3:
  991. WLAN_OS_REPORT(("TRAFF - ALERT DOWN limit - 25 ON"));
  992. break;
  993. case 4:
  994. WLAN_OS_REPORT(("TRAFF - ALERT DOWN limit - 10 ON"));
  995. break;
  996. }
  997. }
  998. VOID PrintElertStus()
  999. {
  1000. TrafficMonitor_t *TrafficMonitor =(TrafficMonitor_t*)TestTrafficMonitor;
  1001. TrafficAlertElement_t *AlertElement = (TrafficAlertElement_t*)List_GetFirst(TrafficMonitor->NotificationRegList);
  1002. /* go over all the Down elements and check for alert ResetElment that ref to TrafficAlertElement*/
  1003. while(AlertElement)
  1004. {
  1005. if(AlertElement->CurrentState == ALERT_WAIT_FOR_RESET)
  1006. WLAN_OS_REPORT(("TRAFF - ALERT ALERT_WAIT_FOR_RESET"));
  1007. else
  1008. WLAN_OS_REPORT(("TRAFF - ALERT ENABLED"));
  1009. AlertElement = (TrafficAlertElement_t*)List_GetNext(TrafficMonitor->NotificationRegList);
  1010. }
  1011. }
  1012. VOID TestEventFunc(TI_HANDLE hTrafficMonitor)
  1013. {
  1014. static flag = TRUE;
  1015. TrafficAlertRegParm_t TrafficAlertRegParm ;
  1016. if(flag)
  1017. {
  1018. TrafficAlertRegParm.CallBack = func1;
  1019. TrafficAlertRegParm.Context = NULL ;
  1020. TrafficAlertRegParm.Cookie = 1 ;
  1021. TrafficAlertRegParm.Direction = TRAFF_UP ;
  1022. TrafficAlertRegParm.Trigger = TRAFF_EDGE;
  1023. TrafficAlertRegParm.TimeIntervalMs = 1000;
  1024. TrafficAlertRegParm.Threshold = 50;
  1025. TrafficAlertRegParm.MonitorType = TX_RX_DIRECTED_FRAMES;
  1026. Alert1 = TrafficMonitor_RegEvent(TestTrafficMonitor,&TrafficAlertRegParm,FALSE);
  1027. TrafficAlertRegParm.CallBack = func1;
  1028. TrafficAlertRegParm.Context = NULL ;
  1029. TrafficAlertRegParm.Cookie = 2 ;
  1030. TrafficAlertRegParm.Direction = TRAFF_UP ;
  1031. TrafficAlertRegParm.Trigger = TRAFF_EDGE;
  1032. TrafficAlertRegParm.TimeIntervalMs = 1000;
  1033. TrafficAlertRegParm.Threshold = 30;
  1034. TrafficAlertRegParm.MonitorType = TX_RX_DIRECTED_FRAMES;
  1035. Alert2 = TrafficMonitor_RegEvent(TestTrafficMonitor,&TrafficAlertRegParm,FALSE);
  1036. TrafficAlertRegParm.CallBack = func1;
  1037. TrafficAlertRegParm.Context = NULL ;
  1038. TrafficAlertRegParm.Cookie = 3 ;
  1039. TrafficAlertRegParm.Direction = TRAFF_DOWN ;
  1040. TrafficAlertRegParm.Trigger = TRAFF_EDGE;
  1041. TrafficAlertRegParm.TimeIntervalMs = 1000;
  1042. TrafficAlertRegParm.Threshold = 25;
  1043. TrafficAlertRegParm.MonitorType = TX_RX_DIRECTED_FRAMES;
  1044. Alert3 = TrafficMonitor_RegEvent(TestTrafficMonitor,&TrafficAlertRegParm,FALSE);
  1045. TrafficAlertRegParm.CallBack = func1;
  1046. TrafficAlertRegParm.Context = NULL ;
  1047. TrafficAlertRegParm.Cookie = 4 ;
  1048. TrafficAlertRegParm.Direction = TRAFF_DOWN ;
  1049. TrafficAlertRegParm.Trigger = TRAFF_LEVEL;
  1050. TrafficAlertRegParm.TimeIntervalMs = 1000;
  1051. TrafficAlertRegParm.Threshold = 10;
  1052. TrafficAlertRegParm.MonitorType = TX_RX_DIRECTED_FRAMES;
  1053. Alert4 = TrafficMonitor_RegEvent(TestTrafficMonitor,&TrafficAlertRegParm,FALSE);
  1054. TrafficMonitor_SetRstCondition(TestTrafficMonitor, Alert1,Alert3,TRUE);
  1055. TrafficMonitor_SetRstCondition(TestTrafficMonitor, Alert2,Alert3,FALSE);
  1056. flag = FALSE;
  1057. }
  1058. PrintElertStus();
  1059. }
  1060. #endif