PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/cyanogenmod/cm-kernel
C | 1043 lines | 608 code | 174 blank | 261 comment | 162 complexity | bbcd5e01ea4c04d03f7957e3ecf2c488 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.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. * file Clsfr.c
  37. */
  38. #include "paramOut.h"
  39. #include "Clsfr.h"
  40. #include "utils.h"
  41. #include "report.h"
  42. #define ETHERNET_HEADER_SIZE 14
  43. static TI_STATUS classifier_getIpAndUdpHeader(classifier_t* pClsfr, mem_MSDU_T *pMsdu, UINT8 **pIpHeader, UINT8 **pUdpHeader);
  44. /*************************************************************************
  45. * Classifier_create *
  46. **************************************************************************
  47. * DESCRIPTION: This function creates the Classifier module.
  48. *
  49. * INPUT: hOs - handle to Os Abstraction Layer
  50. *
  51. * OUTPUT: Pointer to the Classifier module
  52. ************************************************************************/
  53. classifier_t* Classifier_create(TI_HANDLE hOs)
  54. {
  55. classifier_t* pClsfr;
  56. if( hOs == NULL )
  57. return NULL;
  58. /* alocate classifier block */
  59. pClsfr = os_memoryAlloc(hOs, (sizeof(classifier_t)));
  60. if (!pClsfr)
  61. {
  62. utils_nullMemoryFree(hOs, pClsfr, sizeof(classifier_t));
  63. return NULL;
  64. }
  65. /* clear the block */
  66. os_memoryZero(hOs, pClsfr, (sizeof(classifier_t)));
  67. pClsfr->hOs = hOs;
  68. return(pClsfr);
  69. }
  70. /******************************************************************************
  71. * Classifier_config *
  72. *******************************************************************************
  73. * DESCRIPTION: This function configures the Classifier module.
  74. *
  75. * INPUT: hOs, hReport - handle to Os Abstraction Layer and to the Report
  76. *
  77. * OUTPUT: PARAM_VALUE_NOT_VALID in case of problems with input parameters
  78. * and OK otherwise
  79. ********************************************************************************/
  80. TI_STATUS Classifier_config(classifier_t* pClsfr, TI_HANDLE hOs, TI_HANDLE hReport, clsfr_Params_t* ClsfrInitParams)
  81. {
  82. int i,j,actualEntryCount;
  83. BOOL conflictFound;
  84. /* check parameters validity */
  85. if (pClsfr == NULL)
  86. return NOK;
  87. if ( (hOs == NULL) || (hReport == NULL) )
  88. return NOK;
  89. /* set objects handles */
  90. pClsfr->hOs = hOs;
  91. pClsfr->hReport = hReport;
  92. /* Active classification algorithm */
  93. pClsfr->clsfrParameters.clsfrType = ClsfrInitParams->clsfrType;
  94. /* the number of active entries */
  95. if (ClsfrInitParams->NumOfActiveEntries <= NUM_OF_CLSFR_TABLE_ENTRIES)
  96. pClsfr->clsfrParameters.NumOfActiveEntries = ClsfrInitParams->NumOfActiveEntries;
  97. else
  98. pClsfr->clsfrParameters.NumOfActiveEntries = NUM_OF_CLSFR_TABLE_ENTRIES;
  99. /* Initialization of the classification table */
  100. switch (pClsfr->clsfrParameters.clsfrType)
  101. {
  102. case D_TAG_CLSFR:
  103. pClsfr->clsfrParameters.NumOfActiveEntries = 0;
  104. break;
  105. case DSCP_CLSFR:
  106. actualEntryCount=0;
  107. for (i=0; (i < pClsfr->clsfrParameters.NumOfActiveEntries ) ; i++)
  108. {
  109. conflictFound = FALSE;
  110. /* check conflict */
  111. for (j=0;j<i;j++)
  112. {
  113. /* Detect both duplicate and conflicting entries */
  114. if (pClsfr->clsfrParameters.ClsfrTable[j].Dscp.CodePoint == ClsfrInitParams->ClsfrTable[i].Dscp.CodePoint)
  115. {
  116. WLAN_REPORT_WARNING (pClsfr->hReport, CLSFR_MODULE_LOG,("ERROR: Classifier_config(): duplicate/conflicting classifier entries\n"));
  117. conflictFound = TRUE;
  118. }
  119. }
  120. if (conflictFound == FALSE)
  121. {
  122. pClsfr->clsfrParameters.ClsfrTable[actualEntryCount].Dscp.CodePoint = ClsfrInitParams->ClsfrTable[i].Dscp.CodePoint;
  123. pClsfr->clsfrParameters.ClsfrTable[actualEntryCount].DTag = ClsfrInitParams->ClsfrTable[i].DTag;
  124. actualEntryCount++;
  125. }
  126. }
  127. pClsfr->clsfrParameters.NumOfActiveEntries = actualEntryCount;
  128. break;
  129. case PORT_CLSFR:
  130. actualEntryCount=0;
  131. for (i=0; (i < pClsfr->clsfrParameters.NumOfActiveEntries ) ; i++)
  132. {
  133. conflictFound = FALSE;
  134. /* check conflict */
  135. for (j=0;j<i;j++)
  136. {
  137. /* Detect both duplicate and conflicting entries */
  138. if (pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstPortNum == ClsfrInitParams->ClsfrTable[i].Dscp.DstPortNum)
  139. {
  140. WLAN_REPORT_WARNING (pClsfr->hReport, CLSFR_MODULE_LOG,("ERROR: Classifier_config(): classifier entries conflict\n"));
  141. conflictFound = TRUE;
  142. }
  143. }
  144. if (conflictFound == FALSE)
  145. {
  146. pClsfr->clsfrParameters.ClsfrTable[actualEntryCount].Dscp.DstPortNum = ClsfrInitParams->ClsfrTable[i].Dscp.DstPortNum;
  147. pClsfr->clsfrParameters.ClsfrTable[actualEntryCount].DTag = ClsfrInitParams->ClsfrTable[i].DTag;
  148. actualEntryCount++;
  149. }
  150. }
  151. pClsfr->clsfrParameters.NumOfActiveEntries = actualEntryCount;
  152. break;
  153. case IPPORT_CLSFR:
  154. actualEntryCount=0;
  155. for (i=0; (i < pClsfr->clsfrParameters.NumOfActiveEntries ) ; i++)
  156. {
  157. conflictFound = FALSE;
  158. /* check conflict */
  159. for (j=0;j<i;j++)
  160. {
  161. /* Detect both duplicate and conflicting entries */
  162. if ((pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstIPPort.DstIPAddress == ClsfrInitParams->ClsfrTable[i].Dscp.DstIPPort.DstIPAddress)&&
  163. (pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstIPPort.DstPortNum == ClsfrInitParams->ClsfrTable[i].Dscp.DstIPPort.DstPortNum))
  164. {
  165. WLAN_REPORT_WARNING (pClsfr->hReport, CLSFR_MODULE_LOG,("ERROR: Classifier_config(): classifier entries conflict\n"));
  166. conflictFound = TRUE;
  167. }
  168. }
  169. if (conflictFound == FALSE)
  170. {
  171. pClsfr->clsfrParameters.ClsfrTable[actualEntryCount].Dscp.DstIPPort.DstIPAddress = ClsfrInitParams->ClsfrTable[i].Dscp.DstIPPort.DstIPAddress;
  172. pClsfr->clsfrParameters.ClsfrTable[actualEntryCount].Dscp.DstIPPort.DstPortNum = ClsfrInitParams->ClsfrTable[i].Dscp.DstIPPort.DstPortNum;
  173. pClsfr->clsfrParameters.ClsfrTable[actualEntryCount].DTag = ClsfrInitParams->ClsfrTable[i].DTag;
  174. actualEntryCount++;
  175. }
  176. }
  177. pClsfr->clsfrParameters.NumOfActiveEntries = actualEntryCount;
  178. break;
  179. default:
  180. WLAN_REPORT_WARNING (pClsfr->hReport, CLSFR_MODULE_LOG,("ERROR: Classifier_config(): Classifier type -- unknown --> set to D-Tag\n"));
  181. pClsfr->clsfrParameters.clsfrType = D_TAG_CLSFR;
  182. pClsfr->clsfrParameters.NumOfActiveEntries = 0;
  183. }
  184. return OK;
  185. }
  186. /******************************************************************************
  187. * Classifier_destroy *
  188. *******************************************************************************
  189. * DESCRIPTION: This function destroys the Classifier module.
  190. *
  191. * INPUT: the object
  192. *
  193. * OUTPUT: NOK in case of problems with the input parameter
  194. * and OK otherwise
  195. ********************************************************************************/
  196. TI_STATUS Classifier_destroy(classifier_t* pClsfr)
  197. {
  198. /* check parameters validity */
  199. if( pClsfr == NULL )
  200. return NOK;
  201. /* free the classifier memory block */
  202. os_memoryFree(pClsfr->hOs, pClsfr, sizeof(classifier_t));
  203. return OK;
  204. }
  205. /************************************************************************
  206. * Classifier_classifyTxMSDU
  207. ************************************************************************
  208. Input:
  209. * pClsfr: pointer to the classifier
  210. * pMsdu: pointer to the MSDU
  211. * packet_DTag: NDIS Packet 802.1 user priority (UP)
  212. Output:
  213. OK on success and PARAM_VALUE_NOT_VALID in case of input parameters problems.
  214. If the value PARAM_VALUE_NOT_VALID is returned, the MSDU qosTag field is zero.
  215. Description:
  216. This function performs the classification algorithm for the MSDU pointed
  217. by pMsdu, according to the classifier parameters.
  218. It initializes the qosTag field of the MSDU with the classification algorithm
  219. returned value. Note that if the value in the field clsfrType of Clsfr_Params is
  220. D_TAG_CLSFR then it performs the trivial classification algorithm from
  221. D-tag to D-tag. That is, Msdu->qosTag is set to packet_DTag.
  222. For all other classification algorithms, the classification is performed
  223. according to the corresponding classifier table.
  224. ************************************************************************/
  225. TI_STATUS Classifier_classifyTxMSDU(classifier_t* pClsfr, mem_MSDU_T *pMsdu, UINT8 packet_DTag)
  226. {
  227. UINT8 i;
  228. UINT8 *pUdpHeader = NULL;
  229. UINT8 *pIpHeader = NULL;
  230. UINT8 DSCP;
  231. UINT16 dstPortNum;
  232. UINT32 dstIPAdd;
  233. /* Parameters validation */
  234. if (pClsfr == NULL)
  235. return NOK;
  236. if (pMsdu == NULL)
  237. {
  238. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  239. (" Classifier_classifyTxMSDU() : NULL MSDU error \n"));
  240. return PARAM_VALUE_NOT_VALID;
  241. }
  242. if ((packet_DTag > MAX_NUM_OF_802_1d_TAGS) && (pClsfr->clsfrParameters.clsfrType == D_TAG_CLSFR))
  243. {
  244. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  245. (" Classifier_classifyTxMSDU() : packet_DTag error \n"));
  246. pMsdu->qosTag = 0;
  247. return PARAM_VALUE_NOT_VALID;
  248. }
  249. /* Initialization */
  250. pMsdu->qosTag = 0;
  251. switch(pClsfr->clsfrParameters.clsfrType)
  252. {
  253. case D_TAG_CLSFR:
  254. /* Trivial mapping D-tag to D-tag */
  255. pMsdu->qosTag = packet_DTag;
  256. WLAN_REPORT_INFORMATION (pClsfr->hReport, CLSFR_MODULE_LOG, ("Classifier D_TAG_CLSFR. pMsdu->qosTag = %d\n",pMsdu->qosTag));
  257. break;
  258. case DSCP_CLSFR:
  259. if( (classifier_getIpAndUdpHeader(pClsfr, pMsdu, &pIpHeader, &pUdpHeader) != OK) ||
  260. (pIpHeader == NULL) )
  261. {
  262. WLAN_REPORT_INFORMATION(pClsfr->hReport, CLSFR_MODULE_LOG,
  263. (" Classifier_classifyTxMSDU() : DSCP clsfr, getIpAndUdpHeader error\n"));
  264. return PARAM_VALUE_NOT_VALID;
  265. }
  266. /* DSCP to D-tag mapping */
  267. DSCP = *((UINT8 *)(pIpHeader + 1)); /* Fetching the DSCP from the header */
  268. DSCP = (DSCP >> 2);
  269. /* looking for the specific DSCP, if the DSCP is found, its corresponding
  270. D-tag is set to the qosTag */
  271. for(i = 0; i<pClsfr->clsfrParameters.NumOfActiveEntries; i++ )
  272. {
  273. if (pClsfr->clsfrParameters.ClsfrTable[i].Dscp.CodePoint == DSCP)
  274. {
  275. pMsdu->qosTag = pClsfr->clsfrParameters.ClsfrTable[i].DTag;
  276. WLAN_REPORT_INFORMATION (pClsfr->hReport, CLSFR_MODULE_LOG,("Classifier DSCP_CLSFR found match - entry %d - qosTag = %d\n",i,pMsdu->qosTag));
  277. break;
  278. }
  279. }
  280. break;
  281. case PORT_CLSFR:
  282. if( (classifier_getIpAndUdpHeader(pClsfr, pMsdu, &pIpHeader, &pUdpHeader) != OK) ||
  283. (pUdpHeader == NULL) )
  284. {
  285. WLAN_REPORT_INFORMATION(pClsfr->hReport, CLSFR_MODULE_LOG,
  286. (" Classifier_classifyTxMSDU() : DstPort clsfr, getIpAndUdpHeader error\n"));
  287. return PARAM_VALUE_NOT_VALID;
  288. }
  289. /* Port to D-tag mapping */
  290. dstPortNum = *((UINT16 *)(pUdpHeader + 2)); /* Fetching the port number from the header */
  291. dstPortNum = ((dstPortNum >> 8) | (dstPortNum << 8));
  292. /* looking for the specific port number, if the port number is found, its corresponding
  293. D-tag is set to the qosTag */
  294. for(i = 0; i<pClsfr->clsfrParameters.NumOfActiveEntries; i++ )
  295. {
  296. if (pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstPortNum == dstPortNum)
  297. {
  298. pMsdu->qosTag = pClsfr->clsfrParameters.ClsfrTable[i].DTag;
  299. WLAN_REPORT_INFORMATION (pClsfr->hReport, CLSFR_MODULE_LOG,("Classifier PORT_CLSFR found match - entry %d - qosTag = %d\n",i,pMsdu->qosTag));
  300. break;
  301. }
  302. }
  303. break;
  304. case IPPORT_CLSFR:
  305. if( (classifier_getIpAndUdpHeader(pClsfr, pMsdu, &pIpHeader, &pUdpHeader) != OK) ||
  306. (pIpHeader == NULL) || (pUdpHeader == NULL) )
  307. {
  308. WLAN_REPORT_INFORMATION(pClsfr->hReport, CLSFR_MODULE_LOG,
  309. (" Classifier_classifyTxMSDU() : Dst IP&Port clsfr, getIpAndUdpHeader error\n"));
  310. return PARAM_VALUE_NOT_VALID;
  311. }
  312. /* IP&Port to D-tag mapping */
  313. dstPortNum = *((UINT16 *)(pUdpHeader + 2)); /* Fetching the port number from the header */
  314. dstPortNum = ((dstPortNum >> 8) | (dstPortNum << 8));
  315. {
  316. /* Since IP header is 2 bytes aligned we will copy IP as two 16 bits */
  317. /* dstIPAdd = *((UINT32 *)(pIpHeader + 16));*/
  318. UINT16 hiPart, loPart;
  319. hiPart = *((UINT16 *) pIpHeader + 8);
  320. loPart = *((UINT16 *) pIpHeader + 9);
  321. dstIPAdd = (loPart << 16) | hiPart; // account for little endian host and network order
  322. }
  323. /* looking for the specific pair of dst IP address and dst port number, if it is found, its corresponding
  324. D-tag is set to the qosTag */
  325. for(i = 0; i<pClsfr->clsfrParameters.NumOfActiveEntries; i++ )
  326. {
  327. if ((pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstIPAddress == dstIPAdd)&&
  328. ( pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstPortNum == dstPortNum))
  329. {
  330. pMsdu->qosTag = pClsfr->clsfrParameters.ClsfrTable[i].DTag;
  331. WLAN_REPORT_INFORMATION (pClsfr->hReport, CLSFR_MODULE_LOG,("Classifier IPPORT_CLSFR found match - entry %d - qosTag = %d\n",i,pMsdu->qosTag));
  332. break;
  333. }
  334. }
  335. break;
  336. default:
  337. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  338. (" Classifier_classifyTxMSDU(): clsfrType error\n"));
  339. }
  340. return OK;
  341. }
  342. /************************************************************************
  343. * classifier_getIpAndUdpHeader
  344. ************************************************************************
  345. Input:
  346. * pClsfr: pointer to the classifier
  347. * pMsdu: pointer to the MSDU
  348. Output:
  349. * pIpHeader: pointer to the IP header
  350. * pUdpHeader: pointer to the UDP header
  351. Description:
  352. This function fetch the addresses of the IP and UDP headers
  353. ************************************************************************/
  354. static TI_STATUS classifier_getIpAndUdpHeader(classifier_t* pClsfr, mem_MSDU_T *pMsdu, UINT8 **pIpHeader, UINT8 **pUdpHeader)
  355. {
  356. UINT8 ipHeaderLen=0;
  357. mem_BD_T* currBD = NULL;
  358. UINT16 swapedTypeLength=0;
  359. /* Parameters validation */
  360. if (pMsdu == NULL)
  361. {
  362. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  363. (" classifier_getIpAndUdpHeader: NULL MSDU error \n"));
  364. return NOK;
  365. }
  366. currBD = pMsdu->firstBDPtr;
  367. if( currBD == NULL)
  368. {
  369. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  370. (" classifier_getIpAndUdpHeader: first BD is NULL \n"));
  371. return NOK;
  372. }
  373. swapedTypeLength = wlan_htons(*((UINT16*)(currBD->data+currBD->dataOffset+12)) );
  374. /* check if frame is IP according to ether type */
  375. if( swapedTypeLength != 0x0800)
  376. {
  377. WLAN_REPORT_INFORMATION(pClsfr->hReport, CLSFR_MODULE_LOG,
  378. (" classifier_getIpAndUdpHeader: swapedTypeLength is not 0x0800 \n"));
  379. return NOK;
  380. }
  381. /*Ronnie: we could have skipped the NO_COPY_NDIS_BUFFERS ifdef (both cases are the same)*/
  382. #ifdef NO_COPY_NDIS_BUFFERS
  383. /*
  384. in windows - protocols headears are in the same buffer.
  385. Headears can not bu split between 2 buffers
  386. */
  387. /* IP is in first buffer */
  388. *pIpHeader = (UINT8 *)(memMgr_BufData(pMsdu->firstBDPtr)+memMgr_BufOffset(pMsdu->firstBDPtr)) + ETHERNET_HEADER_SIZE;
  389. ipHeaderLen = ((*(unsigned char*)(*pIpHeader) & 0x0f) * 4);
  390. /* UDP/TCP is in first buffer */
  391. *pUdpHeader = *pIpHeader + ipHeaderLen; /* Set the pointer to the begining of the TCP/UDP header */
  392. #else
  393. /* set the pointer to the beginning of the IP header and calculate it's size*/
  394. *pIpHeader = (UINT8 *)(memMgr_BufData(pMsdu->firstBDPtr)+memMgr_BufOffset(pMsdu->firstBDPtr)) + ETHERNET_HEADER_SIZE;
  395. ipHeaderLen = ((*(unsigned char*)(*pIpHeader) & 0x0f) * 4);
  396. *pUdpHeader = *pIpHeader + ipHeaderLen; /* Set the pointer to the beggining of the TCP/UDP header */
  397. #endif
  398. return OK;
  399. }
  400. /************************************************************************
  401. * classifier_InsertClsfrEntry *
  402. ************************************************************************
  403. The following API is used to configure the classifier table. Note that
  404. this API provides only insert to table service (and not delete).
  405. Input:
  406. * pClsfr: pointer to the classifier
  407. * NumberOfEntries: number of entries to insert.
  408. * ConfigBufferPtr: pointer to the data to insert.
  409. Output:
  410. OK on success and PARAM_VALUE_NOT_VALID in case of input parameters problems.
  411. If the value PARAM_VALUE_NOT_VALID is returned, the entries insert operation
  412. on the classifier table is canceled.
  413. The value PARAM_VALUE_NOT_VALID is returned upon the following errors:
  414. -- NumberOfEntries parameter:
  415. a) If it is larger than the available entries in the table.
  416. b) If it is smaller than 1.
  417. c) If an entry creates conflict with another entry.
  418. -- ConfigBufferPtr is pointing on NULL.
  419. ************************************************************************/
  420. TI_STATUS Classifier_InsertClsfrEntry(classifier_t* pClsfr, UINT8 NumberOfEntries, clsfr_tableEntry_t *ConfigBufferPtr)
  421. {
  422. UINT8 avlEntries;
  423. clsfr_tableEntry_t *pSrc;
  424. int i,j;
  425. if(pClsfr == NULL)
  426. return NOK;
  427. if(ConfigBufferPtr == NULL)
  428. {
  429. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  430. ("Classifier_InsertClsfrEntry(): NULL ConfigBuffer pointer Error - Aborting\n"));
  431. return PARAM_VALUE_NOT_VALID;
  432. }
  433. avlEntries = (NUM_OF_CLSFR_TABLE_ENTRIES - (pClsfr->clsfrParameters.NumOfActiveEntries));
  434. if ((NumberOfEntries < 1) || (NumberOfEntries > avlEntries))
  435. {
  436. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  437. ("Classifier_InsertClsfrEntry(): Bad Number Of Entries - Aborting\n"));
  438. return PARAM_VALUE_NOT_VALID;
  439. }
  440. if (pClsfr->clsfrParameters.clsfrType == D_TAG_CLSFR)
  441. {
  442. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  443. ("Classifier_InsertClsfrEntry(): D-Tag classifier - Aborting\n"));
  444. return PARAM_VALUE_NOT_VALID;
  445. }
  446. /* Check conflicts with classifier table entries */
  447. /* check all conflicts, if all entries are OK --> insert to classifier table*/
  448. pSrc = ConfigBufferPtr;
  449. switch (pClsfr->clsfrParameters.clsfrType)
  450. {
  451. case DSCP_CLSFR:
  452. for (i=0; i< NumberOfEntries ; i++)
  453. {
  454. /* Check entry */
  455. if ((pSrc[i].Dscp.CodePoint > CLASSIFIER_CODE_POINT_MAX) || (pSrc[i].DTag > CLASSIFIER_DTAG_MAX))
  456. {
  457. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  458. ("Classifier_InsertClsfrEntry(): bad parameter - Aborting\n"));
  459. return PARAM_VALUE_NOT_VALID;
  460. }
  461. /* Check conflict*/
  462. for (j=0;j<pClsfr->clsfrParameters.NumOfActiveEntries;j++)
  463. {
  464. /* Detect both duplicate and conflicting entries */
  465. if (pClsfr->clsfrParameters.ClsfrTable[j].Dscp.CodePoint == pSrc[i].Dscp.CodePoint)
  466. {
  467. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  468. ("Classifier_InsertClsfrEntry(): classifier entries conflict - Aborting\n"));
  469. return PARAM_VALUE_NOT_VALID;
  470. }
  471. }
  472. }
  473. /* All new entries are valid --> insert to classifier table */
  474. for (i=0; i< NumberOfEntries ; i++)
  475. {
  476. pClsfr->clsfrParameters.ClsfrTable[pClsfr->clsfrParameters.NumOfActiveEntries+i].Dscp.CodePoint = pSrc[i].Dscp.CodePoint;
  477. pClsfr->clsfrParameters.ClsfrTable[pClsfr->clsfrParameters.NumOfActiveEntries+i].DTag = pSrc[i].DTag;
  478. }
  479. break;
  480. case PORT_CLSFR:
  481. for (i=0; i< NumberOfEntries ; i++)
  482. {
  483. /* Check entry */
  484. if ((pSrc[i].DTag > CLASSIFIER_DTAG_MAX) || (pSrc[i].Dscp.DstPortNum > CLASSIFIER_PORT_MAX-1) || (pSrc[i].Dscp.DstPortNum < CLASSIFIER_PORT_MIN) )
  485. {
  486. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  487. ("Classifier_InsertClsfrEntry(): bad parameter - Aborting\n"));
  488. return PARAM_VALUE_NOT_VALID;
  489. }
  490. /* Check conflict*/
  491. for (j=0;j<pClsfr->clsfrParameters.NumOfActiveEntries;j++)
  492. {
  493. /* Detect both duplicate and conflicting entries */
  494. if ((pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstPortNum == pSrc[i].Dscp.DstPortNum))
  495. {
  496. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  497. ("Classifier_InsertClsfrEntry(): classifier entries conflict - Aborting\n"));
  498. return PARAM_VALUE_NOT_VALID;
  499. }
  500. }
  501. }
  502. /* All new entries are valid --> insert to classifier table */
  503. for (i=0; i< NumberOfEntries ; i++)
  504. {
  505. pClsfr->clsfrParameters.ClsfrTable[pClsfr->clsfrParameters.NumOfActiveEntries+i].Dscp.DstPortNum = pSrc[i].Dscp.DstPortNum;
  506. pClsfr->clsfrParameters.ClsfrTable[pClsfr->clsfrParameters.NumOfActiveEntries+i].DTag = pSrc[i].DTag;
  507. }
  508. break;
  509. case IPPORT_CLSFR:
  510. for (i=0; i< NumberOfEntries ; i++)
  511. {
  512. /* Check entry */
  513. if ( (pSrc[i].DTag > CLASSIFIER_DTAG_MAX) || (pSrc[i].Dscp.DstIPPort.DstPortNum > CLASSIFIER_PORT_MAX-1) ||
  514. (pSrc[i].Dscp.DstIPPort.DstPortNum < CLASSIFIER_PORT_MIN) || (pSrc[i].Dscp.DstIPPort.DstIPAddress > CLASSIFIER_IPADDRESS_MAX-1) ||
  515. (pSrc[i].Dscp.DstIPPort.DstIPAddress < CLASSIFIER_IPADDRESS_MIN+1) )
  516. {
  517. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  518. ("Classifier_InsertClsfrEntry(): bad parameter - Aborting\n"));
  519. return PARAM_VALUE_NOT_VALID;
  520. }
  521. /* Check conflict*/
  522. for (j=0;j<pClsfr->clsfrParameters.NumOfActiveEntries;j++)
  523. {
  524. /* Detect both duplicate and conflicting entries */
  525. if ( (pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstIPPort.DstIPAddress == pSrc[i].Dscp.DstIPPort.DstIPAddress) &&
  526. (pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstIPPort.DstPortNum == pSrc[i].Dscp.DstIPPort.DstPortNum))
  527. {
  528. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  529. ("Classifier_InsertClsfrEntry(): classifier entries conflict - Aborting\n"));
  530. return PARAM_VALUE_NOT_VALID;
  531. }
  532. }
  533. }
  534. /* All new entries are valid --> insert to classifier table */
  535. for (i=0; i< NumberOfEntries ; i++)
  536. {
  537. pClsfr->clsfrParameters.ClsfrTable[pClsfr->clsfrParameters.NumOfActiveEntries+i].Dscp.DstIPPort.DstIPAddress = pSrc[i].Dscp.DstIPPort.DstIPAddress;
  538. pClsfr->clsfrParameters.ClsfrTable[pClsfr->clsfrParameters.NumOfActiveEntries+i].Dscp.DstIPPort.DstPortNum = pSrc[i].Dscp.DstIPPort.DstPortNum;
  539. pClsfr->clsfrParameters.ClsfrTable[pClsfr->clsfrParameters.NumOfActiveEntries+i].DTag = pSrc[i].DTag;
  540. }
  541. break;
  542. default:
  543. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  544. ("Classifier_InsertClsfrEntry(): Classifier type -- unknown - Aborting\n"));
  545. }
  546. /* update the number of classifier active entries */
  547. pClsfr->clsfrParameters.NumOfActiveEntries = pClsfr->clsfrParameters.NumOfActiveEntries + NumberOfEntries;
  548. return OK;
  549. }
  550. /************************************************************************
  551. * classifier_RemoveClsfrEntry *
  552. ************************************************************************
  553. The following API is used to remove an entry from the classifier table
  554. Input:
  555. * pClsfr: pointer to the classifier
  556. * ConfigBufferPtr: pointer to the data to remove.
  557. Output:
  558. OK on success and PARAM_VALUE_NOT_VALID in case of input parameters problems.
  559. ************************************************************************/
  560. TI_STATUS classifier_RemoveClsfrEntry(classifier_t* pClsfr, clsfr_tableEntry_t *ConfigBufferPtr)
  561. {
  562. int i,j;
  563. if(pClsfr == NULL)
  564. return NOK;
  565. if(ConfigBufferPtr == NULL)
  566. {
  567. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  568. ("classifier_RemoveClsfrEntry(): NULL ConfigBuffer pointer Error - Aborting\n"));
  569. return PARAM_VALUE_NOT_VALID;
  570. }
  571. if (pClsfr->clsfrParameters.NumOfActiveEntries == 0)
  572. {
  573. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  574. ("classifier_RemoveClsfrEntry(): Classifier table is empty - Aborting\n"));
  575. return PARAM_VALUE_NOT_VALID;
  576. }
  577. if (pClsfr->clsfrParameters.clsfrType == D_TAG_CLSFR)
  578. {
  579. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  580. ("classifier_RemoveClsfrEntry(): D-Tag classifier - Aborting\n"));
  581. return PARAM_VALUE_NOT_VALID;
  582. }
  583. /* Check conflicts with classifier table entries */
  584. /* check all conflicts, if all entries are OK --> insert to classifier table*/
  585. switch (pClsfr->clsfrParameters.clsfrType)
  586. {
  587. case DSCP_CLSFR:
  588. /* Find the classifier entry */
  589. i = 0;
  590. while ((i < pClsfr->clsfrParameters.NumOfActiveEntries) &&
  591. ((pClsfr->clsfrParameters.ClsfrTable[i].Dscp.CodePoint != ConfigBufferPtr->Dscp.CodePoint) ||
  592. (pClsfr->clsfrParameters.ClsfrTable[i].DTag != ConfigBufferPtr->DTag)))
  593. {
  594. i++;
  595. }
  596. /* If we have reached the number of active entries, it means we couldn't find the requested entry */
  597. if (i == pClsfr->clsfrParameters.NumOfActiveEntries)
  598. {
  599. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  600. ("classifier_RemoveClsfrEntry(): Entry not found - Aborting\n"));
  601. return PARAM_VALUE_NOT_VALID;
  602. }
  603. /* If there is more than 1 entry, we need to shift all the entries in the table in order to delete the requested entry */
  604. if (pClsfr->clsfrParameters.NumOfActiveEntries > 1)
  605. {
  606. for (j = i; j < pClsfr->clsfrParameters.NumOfActiveEntries-1; j++)
  607. {
  608. /* Move entries */
  609. pClsfr->clsfrParameters.ClsfrTable[j].Dscp.CodePoint = pClsfr->clsfrParameters.ClsfrTable[j+1].Dscp.CodePoint;
  610. pClsfr->clsfrParameters.ClsfrTable[j].DTag = pClsfr->clsfrParameters.ClsfrTable[j+1].DTag;
  611. }
  612. }
  613. break;
  614. case PORT_CLSFR:
  615. /* Find the classifier entry */
  616. i = 0;
  617. while ((i < pClsfr->clsfrParameters.NumOfActiveEntries) &&
  618. ((pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstPortNum != ConfigBufferPtr->Dscp.DstPortNum) ||
  619. (pClsfr->clsfrParameters.ClsfrTable[i].DTag != ConfigBufferPtr->DTag)))
  620. {
  621. i++;
  622. }
  623. /* If we have reached the number of active entries, it means we couldn't find the requested entry */
  624. if (i == pClsfr->clsfrParameters.NumOfActiveEntries)
  625. {
  626. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  627. ("classifier_RemoveClsfrEntry(): Entry not found - Aborting\n"));
  628. return PARAM_VALUE_NOT_VALID;
  629. }
  630. /* If there is more than 1 entry, we need to shift all the entries in the table in order to delete the requested entry */
  631. if (pClsfr->clsfrParameters.NumOfActiveEntries > 1)
  632. {
  633. for (j = i; j < pClsfr->clsfrParameters.NumOfActiveEntries-1; j++)
  634. {
  635. pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstPortNum = pClsfr->clsfrParameters.ClsfrTable[j+1].Dscp.DstPortNum;
  636. pClsfr->clsfrParameters.ClsfrTable[j].DTag = pClsfr->clsfrParameters.ClsfrTable[j+1].DTag;
  637. }
  638. }
  639. break;
  640. case IPPORT_CLSFR:
  641. /* Find the classifier entry */
  642. i = 0;
  643. while ((i < pClsfr->clsfrParameters.NumOfActiveEntries) &&
  644. ((pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstIPAddress != ConfigBufferPtr->Dscp.DstIPPort.DstIPAddress) ||
  645. (pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstPortNum != ConfigBufferPtr->Dscp.DstIPPort.DstPortNum) ||
  646. (pClsfr->clsfrParameters.ClsfrTable[i].DTag != ConfigBufferPtr->DTag)))
  647. {
  648. i++;
  649. }
  650. /* If we have reached the number of active entries, it means we couldn't find the requested entry */
  651. if (i == pClsfr->clsfrParameters.NumOfActiveEntries)
  652. {
  653. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  654. ("classifier_RemoveClsfrEntry(): Entry not found - Aborting\n"));
  655. return PARAM_VALUE_NOT_VALID;
  656. }
  657. /* If there is more than 1 entry, we need to shift all the entries in the table in order to delete the requested entry */
  658. if (pClsfr->clsfrParameters.NumOfActiveEntries > 1)
  659. {
  660. for (j = i; j < pClsfr->clsfrParameters.NumOfActiveEntries-1; j++)
  661. {
  662. pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstIPPort.DstIPAddress = pClsfr->clsfrParameters.ClsfrTable[j+1].Dscp.DstIPPort.DstIPAddress;
  663. pClsfr->clsfrParameters.ClsfrTable[j].Dscp.DstIPPort.DstPortNum = pClsfr->clsfrParameters.ClsfrTable[j+1].Dscp.DstIPPort.DstPortNum;
  664. pClsfr->clsfrParameters.ClsfrTable[j].DTag = pClsfr->clsfrParameters.ClsfrTable[j+1].DTag;
  665. }
  666. }
  667. break;
  668. default:
  669. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  670. ("classifier_RemoveClsfrEntry(): Classifier type -- unknown - Aborting\n"));
  671. }
  672. /* update the number of classifier active entries */
  673. pClsfr->clsfrParameters.NumOfActiveEntries--;
  674. return OK;
  675. }
  676. /************************************************************************
  677. * classifier_setClsfrType *
  678. ************************************************************************
  679. The following API is used to change the active classifier type.
  680. In addition it empties the classifier table.
  681. Input:
  682. * pClsfr: pointer to the classifier
  683. * newClsfrType: the new classifier type.
  684. Output:
  685. OK on success and PARAM_VALUE_NOT_VALID in case of input parameters problems.
  686. If the value PARAM_VALUE_NOT_VALID is returned, the classifier type and table are not updated.
  687. ************************************************************************/
  688. TI_STATUS Classifier_setClsfrType(classifier_t* pClsfr, clsfr_type_e newClsfrType)
  689. {
  690. if( pClsfr == NULL )
  691. return PARAM_VALUE_NOT_VALID;
  692. if (newClsfrType > CLSFR_TYPE_MAX)
  693. {
  694. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  695. ("Classifier_setClsfrType(): classifier type exceed its MAX \n"));
  696. return PARAM_VALUE_NOT_VALID;
  697. }
  698. if ( pClsfr->clsfrParameters.clsfrType == newClsfrType)
  699. {
  700. WLAN_REPORT_WARNING(pClsfr->hReport, CLSFR_MODULE_LOG,
  701. ("Classifier_setClsfrType(): equal classifier type --> will empty classifier table \n"));
  702. }
  703. /* Update type */
  704. pClsfr->clsfrParameters.clsfrType = newClsfrType;
  705. /* Empty table */
  706. pClsfr->clsfrParameters.NumOfActiveEntries = 0;
  707. return OK;
  708. }
  709. TI_STATUS Classifier_getClsfrType (classifier_t* pClsfr, clsfrTypeAndSupport *newClsfrType)
  710. {
  711. if (pClsfr == NULL)
  712. return NOK;
  713. newClsfrType->ClsfrType = (ULONG)pClsfr->clsfrParameters.clsfrType;
  714. return OK;
  715. }
  716. /************************************************************************
  717. * Classifier_deriveUserPriorityFromStream
  718. ************************************************************************
  719. Input:
  720. * pClsfr: pointer to the classifier
  721. * pStream: pointer to stream properties structure
  722. Output:
  723. userPriority contains the appropriate qosTag that matches the stream properties.
  724. OK on success and PARAM_VALUE_NOT_VALID in case of input parameters problems.
  725. If the value PARAM_VALUE_NOT_VALID is returned, the MSDU qosTag field is zero.
  726. Description:
  727. ************************************************************************/
  728. TI_STATUS Classifier_deriveUserPriorityFromStream (classifier_t* pClsfr, STREAM_TRAFFIC_PROPERTIES *pStream)
  729. {
  730. UINT8 i;
  731. if (pClsfr == NULL)
  732. return NOK;
  733. /* Initialization */
  734. pStream->userPriority = 0;
  735. switch(pClsfr->clsfrParameters.clsfrType)
  736. {
  737. case DSCP_CLSFR:
  738. /* looking for the specific DSCP, if the DSCP is found, its corresponding D-tag is set to the qosTag */
  739. for(i = 0; i<pClsfr->clsfrParameters.NumOfActiveEntries; i++ )
  740. {
  741. if (pClsfr->clsfrParameters.ClsfrTable[i].Dscp.CodePoint == pStream->PktTag)
  742. {
  743. pStream->userPriority = pClsfr->clsfrParameters.ClsfrTable[i].DTag;
  744. return OK;
  745. }
  746. }
  747. break;
  748. case PORT_CLSFR:
  749. /* looking for the specific port number, if the port number is found, its corresponding D-tag is returned */
  750. for(i = 0; i<pClsfr->clsfrParameters.NumOfActiveEntries; i++ )
  751. {
  752. if (pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstPortNum == pStream->dstPort)
  753. {
  754. pStream->userPriority = pClsfr->clsfrParameters.ClsfrTable[i].DTag;
  755. return OK;
  756. }
  757. }
  758. break;
  759. case IPPORT_CLSFR:
  760. /* looking for the specific pair of dst IP address and dst port number, if it is found, its corresponding
  761. D-tag is set to the qosTag */
  762. for(i = 0; i<pClsfr->clsfrParameters.NumOfActiveEntries; i++ )
  763. {
  764. if ((pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstIPAddress == pStream->dstIpAddress)&&
  765. ( pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstPortNum == pStream->dstPort))
  766. {
  767. pStream->userPriority = pClsfr->clsfrParameters.ClsfrTable[i].DTag;
  768. return OK;
  769. }
  770. }
  771. break;
  772. default:
  773. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  774. (" Classifier_deriveUserPriorityFromStream(): clsfrType error\n"));
  775. }
  776. #if 0
  777. WLAN_OS_REPORT (("UserPriority is %d\n",pStream->userPriority));
  778. #endif
  779. return OK;
  780. }
  781. #ifdef TI_DBG
  782. TI_STATUS Classifier_dbgPrintClsfrTable (classifier_t* pClsfr)
  783. {
  784. int i;
  785. UINT32 tmpIpAddr;
  786. if(pClsfr == NULL)
  787. return NOK;
  788. if (pClsfr->clsfrParameters.clsfrType == D_TAG_CLSFR)
  789. {
  790. WLAN_OS_REPORT (("D_TAG classifier type selected...Nothing to print...\n"));
  791. return OK;
  792. }
  793. WLAN_OS_REPORT (("Number of active entries in classifier table : %d\n",pClsfr->clsfrParameters.NumOfActiveEntries));
  794. switch (pClsfr->clsfrParameters.clsfrType)
  795. {
  796. case DSCP_CLSFR:
  797. WLAN_OS_REPORT (("+------+-------+\n"));
  798. WLAN_OS_REPORT (("| Code | D-Tag |\n"));
  799. WLAN_OS_REPORT (("+------+-------+\n"));
  800. for (i=0; i< pClsfr->clsfrParameters.NumOfActiveEntries ; i++)
  801. {
  802. WLAN_OS_REPORT (("| %5d | %5d |\n",pClsfr->clsfrParameters.ClsfrTable[i].Dscp.CodePoint,pClsfr->clsfrParameters.ClsfrTable[i].DTag));
  803. }
  804. WLAN_OS_REPORT (("+-------+-------+\n"));
  805. break;
  806. case PORT_CLSFR:
  807. WLAN_OS_REPORT (("+-------+-------+\n"));
  808. WLAN_OS_REPORT (("| Port | D-Tag |\n"));
  809. WLAN_OS_REPORT (("+-------+-------+\n"));
  810. for (i=0; i< pClsfr->clsfrParameters.NumOfActiveEntries ; i++)
  811. {
  812. WLAN_OS_REPORT (("| %5d | %5d |\n",pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstPortNum,pClsfr->clsfrParameters.ClsfrTable[i].DTag));
  813. }
  814. WLAN_OS_REPORT (("+-------+-------+\n"));
  815. break;
  816. case IPPORT_CLSFR:
  817. WLAN_OS_REPORT (("+-------------+-------+-------+\n"));
  818. WLAN_OS_REPORT (("| IP Address | Port | D-Tag |\n"));
  819. WLAN_OS_REPORT (("+-------------+-------+-------+\n"));
  820. for (i=0; i< pClsfr->clsfrParameters.NumOfActiveEntries ; i++)
  821. {
  822. tmpIpAddr = pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstIPAddress;
  823. WLAN_OS_REPORT (("| %02x.%02x.%02x.%02x | %5d | %5d |\n",(tmpIpAddr & 0xFF),((tmpIpAddr >> 8) & (0xFF)),((tmpIpAddr >> 16) & (0xFF)),((tmpIpAddr >> 24) & (0xFF)),pClsfr->clsfrParameters.ClsfrTable[i].Dscp.DstIPPort.DstPortNum,pClsfr->clsfrParameters.ClsfrTable[i].DTag));
  824. }
  825. WLAN_OS_REPORT (("+-------------+-------+-------+\n"));
  826. break;
  827. default:
  828. WLAN_REPORT_ERROR(pClsfr->hReport, CLSFR_MODULE_LOG,
  829. ("Classifier_InsertClsfrEntry(): Classifier type -- unknown - Aborting\n"));
  830. break;
  831. }
  832. return OK;
  833. }
  834. #endif