1 /*
2 * spectrumMngmntMgr.c
3 *
4 * Copyright(c) 1998 - 2009 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 /** \file spectrumMngmntMgr.c
35 *
36 *
37 * \see spectrumMngmntMgr.h
38 */
39
40 /****************************************************************************************************/
41 /* */
42 /* MODULE: spectrumMngmntMgr.c */
43 /* PURPOSE: */
44 /* */
45 /****************************************************************************************************/
46
47 #define __FILE_ID__ FILE_ID_6
48 #include "report.h"
49 #include "osApi.h"
50 #include "siteMgrApi.h"
51 #include "regulatoryDomainApi.h"
52 #include "mlmeBuilder.h"
53 #include "Ctrl.h"
54 #include "spectrumMngmntMgr.h"
55
56 #define RADAR_THRESHOLD_IN_PRECENTS (5)
57 #define DOT11H_REQUEST_IE_HDR_LEN 3
58 #define DOT11H_REQUEST_IE_LEN 7
59 #define DOT11_MEASUREMENT_REQUEST_ELE_ID (38)
60
61
62 /********************************************************************************/
63 /* Internal functions prototypes. */
64 /********************************************************************************/
65
66 /* The following function uses features from the old Measurement module. */
67 /* It will have to be adapted to using the new Measurement Manager. */
68 #if 0
69
70 static void buildMapSubFieldForBasicReport(TI_HANDLE hMeasurementMgr, TI_UINT8* map);
71
72 #endif
73
74
75 /********************************************************************************/
76 /* Internal Structures. */
77 /********************************************************************************/
78 typedef struct
79 {
80 TI_UINT8 dialogToken;
81 TI_UINT8 activatioDelay;
82 TI_UINT8 measurementOffset;
83 } dot11hFrameReqHdr_t;
84
85 typedef struct
86 {
87 TI_UINT8 IeId;
88 TI_UINT8 Length;
89 TI_UINT8 Token;
90 } dot11hReqIEHdr_t;
91
92 /********************************************************************************/
93 /* Interface functions Implementation. */
94 /********************************************************************************/
95
96 /***************************************************************************
97 * NOTE: The next 3 functions represent the following situations: Receiving
98 * of TPC request, receving Quite IE and receiving Switch Channel IE.
99 * The Measurement SM should be updated to handle this states.
100 ***************************************************************************/
101
102
103 /***********************************************************************
104 * measurementMgr_getBasicMeasurementParam
105 ***********************************************************************
106 DESCRIPTION:
107
108
109 INPUT: hMeasurementMgr - MeasurementMgr Handle
110
111 OUTPUT: pAcxStatisitics -
112 pMediumOccupancy -
113
114 RETURN: TI_OK on success, TI_NOK otherwise
115 ************************************************************************/
116
117 /* The following function uses features from the old Measurement module. */
118 /* It will have to be adapted to using the new Measurement Manager. */
119 #if 0
120
121 TI_STATUS measurementMgr_getBasicMeasurementParam(TI_HANDLE hMeasurementMgr,
122 acxStatisitcs_t* pAcxStatisitics,
123 mediumOccupancy_t* pMediumOccupancy)
124 {
125
126 whalParamInfo_t whalParam;
127 measurementMgr_t *pMeasurementMgr = (measurementMgr_t*)hMeasurementMgr;
128
129 /* getting the ACX statisitc counters by calling the HAL */
130 whalParam.paramType = HAL_CTRL_ACX_STATISTICS_PARAM;
131 if( (status = whalCtrl_GetParam(pMeasurementMgr->hHalCtrl,&whalParam)) == TI_OK)
132 {
133 pAcxStatisitics->FWpacketReceived = whalParam.content.acxStatisitics.FWpacketReceived;
134 pAcxStatisitics->HALpacketReceived = whalParam.content.acxStatisitics.HALpacketReceived;
135 }
136
137 /*FIXME*/
138 WLAN_OS_REPORT(("-------------- FW total---------------, %d\n\n",
139 pAcxStatisitics->FWpacketReceived));
140 WLAN_OS_REPORT(("-------------- Driver Total---------------, %d\n\n",
141 pAcxStatisitics->HALpacketReceived));
142
143 /*******************************************************
144 * NOTE: If not using a call back function the required *
145 * information will not be received *
146 *******************************************************/
147 /* getting the Medium Occupancy by calling the HAL */
148 whalParam.paramType = HAL_CTRL_MEDIUM_OCCUPANCY_PARAM;
149 whalParam.content.interogateCmdCBParams.CB_Func = NULL;
150 whalParam.content.interogateCmdCBParams.CB_handle = hMeasurementMgr;
151 whalParam.content.interogateCmdCBParams.CB_buf = NULL;
152
153 if( (status = whalCtrl_GetParam(pMeasurementMgr->hHalCtrl,&whalParam)) == TI_OK)
154 {
155 return status;
156 }
157
158 return status;
159 }
160
161 #endif
162
163 /***********************************************************************
164 * NOTE: The next 4 functions (dot11h...) should be corrected according
165 * to the 802.11h standered.
166 ***********************************************************************/
167
168 /************************************************************************
169 * measurementMgr_dot11hParserFrameReq *
170 ************************************************************************
171 DESCRIPTION: Frame Request Parser function, called by the Measurement
172 object when a measurement request frame is received.
173 performs the following:
174 - Parsers the received frame request.
175
176 INPUT: hMeasurementMgr - MeasurementMgr Handle
177 pData - The frame request
178 dataLen - The frame'sa length
179
180 OUTPUT: fraemReq - The Parsered Frame Request
181
182 RETURN: TI_OK on success, TI_NOK otherwise
183
184 ************************************************************************/
measurementMgr_dot11hParseFrameReq(TI_HANDLE hMeasurementMgr,TI_UINT8 * pData,TI_INT32 dataLen,TMeasurementFrameRequest * frameReq)185 TI_STATUS measurementMgr_dot11hParseFrameReq(TI_HANDLE hMeasurementMgr,
186 TI_UINT8 *pData, TI_INT32 dataLen,
187 TMeasurementFrameRequest *frameReq)
188 {
189 dot11hFrameReqHdr_t *dot11hFrameReqHdr;
190
191 dot11hFrameReqHdr = (dot11hFrameReqHdr_t*)pData;
192
193 frameReq->hdr->dialogToken = (TI_UINT16)dot11hFrameReqHdr->dialogToken;
194 frameReq->hdr->activatioDelay = dot11hFrameReqHdr->activatioDelay;
195 frameReq->hdr->measurementOffset = dot11hFrameReqHdr->measurementOffset;
196
197 frameReq->requests = pData + DOT11H_REQUEST_IE_HDR_LEN;
198 frameReq->requestsLen = dataLen - DOT11H_REQUEST_IE_HDR_LEN;
199
200 return TI_OK;
201 }
202
203 /************************************************************************
204 * measurementMgr_dot11hParserRequestIEHdr *
205 ************************************************************************
206 DESCRIPTION: Spectrom Manager Request IE Header Parser function,
207 called by the Request Handler object when inserting
208 a request IE to the queue.
209 performs the following:
210 - Parsers the received request IE hdr.
211
212 INPUT: hRequestHandler - Request Handler handle
213 pData - The request IE
214
215 OUTPUT: reqestLen - The Request length
216 measurementToken - The Request IE token
217
218 RETURN: TI_OK on success, TI_NOK otherwise
219
220 ************************************************************************/
measurementMgr_dot11hParseRequestIEHdr(TI_UINT8 * pData,TI_UINT16 * reqestHdrLen,TI_UINT16 * measurementToken)221 TI_STATUS measurementMgr_dot11hParseRequestIEHdr(TI_UINT8 *pData, TI_UINT16 *reqestHdrLen,
222 TI_UINT16 *measurementToken)
223 {
224 dot11hReqIEHdr_t *dot11hReqIEHdr;
225
226 dot11hReqIEHdr = (dot11hReqIEHdr_t*)pData;
227
228 /* checking if received the correct information element ID */
229 if(dot11hReqIEHdr->IeId != DOT11_MEASUREMENT_REQUEST_ELE_ID)
230 return TI_NOK;
231
232 /* checking that len is valid */
233 if(dot11hReqIEHdr->Length != DOT11H_REQUEST_IE_LEN)
234 return TI_NOK;
235
236 *measurementToken = (TI_UINT16)dot11hReqIEHdr->Token;
237
238 *reqestHdrLen = DOT11H_REQUEST_IE_HDR_LEN;
239
240 return TI_OK;
241 }
242
243 /************************************************************************
244 * measurementMgr_dot11hIsTypeValid *
245 ************************************************************************
246 DESCRIPTION: Spectrom Manager function that checks if the given
247 measurement type is valid.
248
249 INPUT: hMeasurementMgr - MeasurementMgr Handle
250 type - The measurement type.
251 scanMode - The Measurement scan Mode.
252
253 OUTPUT:
254
255 RETURN: TI_TRUE if type is valid, TI_FALSE otherwise
256
257 ************************************************************************/
measurementMgr_dot11hIsTypeValid(TI_HANDLE hMeasurementMgr,EMeasurementType type,EMeasurementScanMode scanMode)258 TI_BOOL measurementMgr_dot11hIsTypeValid(TI_HANDLE hMeasurementMgr,
259 EMeasurementType type,
260 EMeasurementScanMode scanMode)
261 {
262 if(type != MSR_TYPE_BASIC_MEASUREMENT)
263 return TI_FALSE;
264
265 return TI_TRUE;
266 }
267
268 /***********************************************************************
269 * measurementMgr_dot11hBuildRejectReport
270 ***********************************************************************
271 DESCRIPTION: Send reject measurement report frame Function.
272 The function does the following:
273 - checking the reason for reject.
274 - builds measurement report Frame.
275 - Calls the mlmeBuolder to allocate a mangement frame
276 and to transmit it.
277
278 INPUT: hMeasurementMgr - MeasurementMgr Handle
279 pRequestArr - Array of pointer to all measurement
280 request that should be rejected.
281 numOfRequestsInParallel - indicates the number of
282 request that should be rejected.
283 rejectReason - Indicated the rejection reason.
284
285 OUTPUT: None
286
287 RETURN: TI_OK on success, TI_NOK otherwise
288 ************************************************************************/
measurementMgr_dot11hBuildRejectReport(TI_HANDLE hMeasurementMgr,MeasurementRequest_t * pRequestArr[],TI_UINT8 numOfRequestsInParallel,EMeasurementRejectReason rejectReason)289 TI_STATUS measurementMgr_dot11hBuildRejectReport(TI_HANDLE hMeasurementMgr,
290 MeasurementRequest_t* pRequestArr[],
291 TI_UINT8 numOfRequestsInParallel,
292 EMeasurementRejectReason rejectReason)
293 {
294 measurementMgr_t *pMeasurementMgr = (measurementMgr_t*)hMeasurementMgr;
295 MeasurementReportFrame_t measurementReport;
296 TI_UINT8 measurementMode = 0;
297
298 /* Building the measurement report frame contents */
299 measurementReport.actionField[0] = CATAGORY_SPECTRUM_MANAGEMENT;
300 measurementReport.actionField[1] = MEASUREMENT_REPORT;
301 measurementReport.dialogToken = (TI_UINT8)pRequestArr[0]->frameToken;
302
303 measurementReport.hdr[0] = DOT11_MEASUREMENT_REPORT_ELE_ID;
304 measurementReport.hdr[1] = DOT11_MIN_MEASUREMENT_REPORT_IE_LEN;
305 measurementReport.measurementToken = (TI_UINT8)pRequestArr[0]->measurementToken;
306 measurementReport.measurementType = pRequestArr[0]->Type;
307
308 /* Building the measurement mode bit field */
309
310 /* setting Parallel Bit */
311 if(numOfRequestsInParallel > 0 )
312 measurementMode |= 0x1;
313
314 /* setting Incapable and Refused bits */
315 switch(rejectReason)
316 {
317 case MSR_REJECT_DTIM_OVERLAP:
318 case MSR_REJECT_DURATION_EXCEED_MAX_DURATION:
319 case MSR_REJECT_TRAFFIC_INTENSITY_TOO_HIGH:
320 case MSR_REJECT_SCR_UNAVAILABLE:
321 case MSR_REJECT_INVALID_CHANNEL:
322 case MSR_REJECT_NOISE_HIST_FAIL:
323 case MSR_REJECT_CHANNEL_LOAD_FAIL:
324 case MSR_REJECT_EMPTY_REPORT:
325 case MSR_REJECT_MAX_DELAY_PASSED:
326 case MSR_REJECT_INVALID_MEASUREMENT_TYPE:
327 {
328 /* Setting the Refused bit */
329 measurementMode |= 0x4;
330 break;
331 }
332
333 default:
334 {
335 TRACE1(pMeasurementMgr->hReport, REPORT_SEVERITY_ERROR, "Reject reason is not supported, %d\n\n", rejectReason);
336
337 break;
338 }
339 }
340
341 measurementReport.measurementMode = measurementMode;
342 TRACE1(pMeasurementMgr->hReport, REPORT_SEVERITY_WARNING, "Measurement was rejected due to %d,\n\n", rejectReason);
343
344 /* Note: The Measurement report reject frame body includes 8 TI_UINT8 */
345 return mlmeBuilder_sendFrame(pMeasurementMgr->hMlme,ACTION,(TI_UINT8*)&measurementReport,8,0);
346 }
347
348
349 /***********************************************************************
350 * measurementMgr_dot11hBuildReport
351 ***********************************************************************
352 DESCRIPTION: build measurement report Function.
353 The function does the following:
354 - builds measurement report IE.
355
356 INPUT: hMeasurementMgr - MeasurementMgr Handle
357 pRequestArr - Array of pointer to all measurement
358 request that should be reported.
359 numOfRequestsInParallel - indicates the number of
360 request that should be reported.
361
362 OUTPUT: None
363
364 RETURN: TI_OK on success, TI_NOK otherwise
365 ************************************************************************/
measurementMgr_dot11hBuildReport(TI_HANDLE hMeasurementMgr,MeasurementRequest_t request,TMeasurementTypeReply * reply)366 TI_STATUS measurementMgr_dot11hBuildReport(TI_HANDLE hMeasurementMgr, MeasurementRequest_t request, TMeasurementTypeReply * reply)
367 {
368 /*measurementMgr_t *pMeasurement = (measurementMgr_t*)hMeasurementMgr;*/
369 MeasurementReportFrame_t measurementReport;
370 TI_UINT8 totalReportLen = 0;
371 TI_UINT8 map = 0;
372 TI_UINT8* pMeasurReport = (TI_UINT8 *)&(measurementReport.measurementReports[0]);
373
374 /* Building the measurement report frame contents */
375 measurementReport.actionField[0] = CATAGORY_SPECTRUM_MANAGEMENT;
376 measurementReport.actionField[1] = MEASUREMENT_REPORT;
377 measurementReport.dialogToken = (TI_UINT8)request.frameToken;
378
379 measurementReport.hdr[0] = DOT11_MEASUREMENT_REPORT_ELE_ID;
380 measurementReport.measurementToken = (TI_UINT8)request.measurementToken;
381
382 /* setting Parallel Bit in the measurement mode */
383 if(request.isParallel)
384 measurementReport.measurementMode = 0x1;
385
386 measurementReport.measurementType = request.Type;
387
388
389 /* Building the reports included in the current measurement report IE */
390 /* Note: The current implementation supports only Basic Report */
391 if(request.Type == MSR_TYPE_BASIC_MEASUREMENT)
392 {
393 *pMeasurReport++ = request.channelNumber;
394 *pMeasurReport++ = (TI_UINT8)request.DurationTime;
395
396 /* The following function uses features from the old Measurement module. */
397 /* It will have to be adapted to using the new Measurement Manager. */
398 #if 0
399 /* building the map subfield */
400 buildMapSubFieldForBasicReport(hMeasurementMgr,&map);
401 #endif /* 0 */
402
403 *pMeasurReport++ = map;
404 totalReportLen += 3;
405 }
406 return TI_OK;
407 }
408
409 /***********************************************************************
410 * measurementMgr_dot11hSendReportAndCleanObject
411 ***********************************************************************
412 DESCRIPTION: Send measurement report frame Function.
413 The function does the following:
414 - Calls the mlmeBuilder to allocate a mangement frame
415 and to transmit it.
416 - Cleans the Measurement Object and reset its Params.
417
418 INPUT: hMeasurementMgr - MeasurementMgr Handle
419
420 OUTPUT: None
421
422 RETURN: TI_OK on success, TI_NOK otherwise
423 ************************************************************************/
measurementMgr_dot11hSendReportAndCleanObject(TI_HANDLE hMeasurementMgr)424 TI_STATUS measurementMgr_dot11hSendReportAndCleanObject(TI_HANDLE hMeasurementMgr)
425 {
426 measurementMgr_t *pMeasurementMgr = (measurementMgr_t*)hMeasurementMgr;
427 TI_STATUS status;
428
429 /* Building the Report Frame Header */
430 /* TO DO */
431
432 if(pMeasurementMgr->frameLength != 0)
433 {
434 /* Setting the IE Length field */
435 /* TO DO */
436
437 /* Sending the Rport Frame */
438 status = mlmeBuilder_sendFrame(pMeasurementMgr->hMlme,ACTION,
439 (TI_UINT8*)&pMeasurementMgr->dot11hFrameReport,
440 sizeof(dot11_ACTION_FIELD_t) + sizeof(TI_UINT8) +
441 sizeof(dot11_eleHdr_t) +
442 DOT11_MIN_MEASUREMENT_REPORT_IE_LEN +
443 pMeasurementMgr->frameLength,0);
444 if(status != TI_OK)
445 return status;
446
447 /* clearing reports data base */
448 os_memoryZero(pMeasurementMgr->hOs,&(pMeasurementMgr->dot11hFrameReport),
449 sizeof(MeasurementReportFrame_t));
450 pMeasurementMgr->frameLength = 0;
451 pMeasurementMgr->nextEmptySpaceInReport = 0;
452 }
453
454 /* Reset the Measurement Object Params */
455 pMeasurementMgr->currentFrameType = MSR_FRAME_TYPE_NO_ACTIVE;
456 requestHandler_clearRequests(pMeasurementMgr->hRequestH);
457
458 return TI_OK;
459 }
460
461
462 /********************************************************************************/
463 /* Internal functions Implementation. */
464 /********************************************************************************/
465
466
467
468 /***********************************************************************
469 * buildMapSubFieldForBasicReport
470 ***********************************************************************
471 DESCRIPTION:
472
473
474 INPUT: hMeasurementMgr - MeasurementMgr Handle
475
476 OUTPUT: map -
477
478 RETURN: None
479 ************************************************************************/
480
481 /* The following function uses features from the old Measurement module. */
482 /* It will have to be adapted to using the new Measurement Manager. */
483 #if 0
484
485 static void buildMapSubFieldForBasicReport(TI_HANDLE hMeasurementMgr,TI_UINT8* map)
486 {
487
488
489 TI_INT32 deltaHALReceivedPacked;
490 TI_INT32 deltaFWReceivedPacked;
491 TI_INT32 deltaFCSError;
492 TI_INT32 periodTimeDelta;
493 TI_INT32 occupancyDelta;
494 measurementMgr_t* pMeasurementMgr = (measurementMgr_t*)hMeasurementMgr;
495
496 /* getting the AcxStatisitcs from the FW */
497 /* NOTE: The medium occupancy will not be updated - FIX */
498
499 /* The following function uses features from the old Measurement module. */
500 /* It will have to be adapted to using the new Measurement Manager. */
501 #if 0
502 measurementMgr_getBasicMeasurementParam(hMeasurementMgr, &pMeasurementMgr->acxStatisticEnd,
503 &pMeasurementMgr->mediumOccupancyEnd);
504 #endif
505
506 /* Calculating the delta for packetReceived from the HAL*/
507 deltaHALReceivedPacked = pMeasurementMgr->acxStatisticEnd.HALpacketReceived -
508 pMeasurementMgr->acxStatisticStart.HALpacketReceived;
509
510 if(deltaHALReceivedPacked < 0)
511 TRACE1(pMeasurementMgr->hReport, REPORT_SEVERITY_ERROR, "HAL delta packets is negative , %d\n\n", deltaHALReceivedPacked);
512
513 if(deltaHALReceivedPacked != 0 )
514 *map = DOT11_BSS_ONLY;
515 else
516 {
517 /* Calculating the delta for FCS Error*/
518 deltaFWReceivedPacked = pMeasurementMgr->acxStatisticEnd.FWpacketReceived -
519 pMeasurementMgr->acxStatisticStart.FWpacketReceived;
520
521 if(deltaFWReceivedPacked < 0)
522 {
523 TRACE1(pMeasurementMgr->hReport, REPORT_SEVERITY_ERROR, "FW delta packets is negative , %d\n\n", deltaFWReceivedPacked);
524 }
525
526 deltaFCSError = deltaFWReceivedPacked - deltaHALReceivedPacked;
527
528 if(deltaFCSError < 0)
529 {
530 TRACE1(pMeasurementMgr->hReport, REPORT_SEVERITY_ERROR, "FCS error is negative , %d\n\n", deltaFCSError);
531 }
532
533 if(deltaFCSError != 0 )
534 *map = DOT11_OFDM_ONLY;
535 else
536 {
537 /* Calculating the delta for Medium occupancy */
538 occupancyDelta = pMeasurementMgr->mediumOccupancyEnd.MediumUsage -
539 pMeasurementMgr->mediumOccupancyStart.MediumUsage;
540
541 if(occupancyDelta < 0)
542 {
543 TRACE1(pMeasurementMgr->hReport, REPORT_SEVERITY_ERROR, "Medium Occupancy is negative , %d\n\n", occupancyDelta);
544 }
545
546 periodTimeDelta = pMeasurementMgr->mediumOccupancyEnd.Period -
547 pMeasurementMgr->mediumOccupancyStart.Period;
548
549 if(periodTimeDelta < 0)
550 {
551 TRACE1(pMeasurementMgr->hReport, REPORT_SEVERITY_ERROR, "Period time delta is negative , %d\n\n", periodTimeDelta);
552 }
553
554 if( ((occupancyDelta * 100) / periodTimeDelta) > RADAR_THRESHOLD_IN_PRECENTS )
555 *map = DOT11_RADAR_AND_UNIDENTIFIED;
556 else
557 *map = 0;
558 }
559 }
560
561 return;
562 }
563
564 #endif /* 0 */
565